Skip to content

New Components - influxdb_cloud #16469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions components/influxdb_cloud/actions/invoke-script/invoke-script.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import influxDbCloud from "../../influxdb_cloud.app.mjs";
import { parseObjectEntries } from "../../common/utils.mjs";

export default {
key: "influxdb_cloud-invoke-script",
name: "Invoke Script",
description: "Runs a script and returns the result. [See the documentation](https://docs.influxdata.com/influxdb3/cloud-serverless/api/v2/#operation/PostScriptsIDInvoke)",
version: "0.0.1",
type: "action",
props: {
influxDbCloud,
scriptId: {
propDefinition: [
influxDbCloud,
"scriptId",
],
},
params: {
type: "object",
label: "Params",
description: "The script parameters. params contains key-value pairs that map values to the params.keys in a script. When you invoke a script with params, InfluxDB passes the values as invocation parameters to the script.",
optional: true,
},
},
async run({ $ }) {
const response = await this.influxDbCloud.invokeScript({
$,
scriptId: this.scriptId,
data: {
params: this.params
? parseObjectEntries(this.params)
: {},
},
});
$.export("$summary", `Successfully invoked script with ID: ${this.scriptId}`);
return response;
},
};
62 changes: 62 additions & 0 deletions components/influxdb_cloud/actions/update-bucket/update-bucket.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import influxDbCloud from "../../influxdb_cloud.app.mjs";

export default {
key: "influxdb_cloud-update-bucket",
name: "Update Bucket",
description: "Updates an existing bucket in InfluxDB Cloud. [See the documentation](https://docs.influxdata.com/influxdb3/cloud-serverless/api/v2/#operation/PatchBucketsID)",
version: "0.0.1",
type: "action",
props: {
influxDbCloud,
bucketId: {
propDefinition: [
influxDbCloud,
"bucketId",
],
},
name: {
type: "string",
label: "Name",
description: "Name of the bucket. Must contain two or more characters. Cannot start with an underscore (_). Cannot contain a double quote (\"). Note: System buckets cannot be renamed.",
optional: true,
},
description: {
type: "string",
label: "Description",
description: "A description of the bucket",
optional: true,
},
everySeconds: {
type: "integer",
label: "Every Seconds",
description: "The duration in seconds for how long data will be kept in the database. The default duration is 2592000 (30 days). 0 represents infinite retention.",
default: 2592000,
optional: true,
},
shardGroupDurationSeconds: {
type: "integer",
label: "Shard Group Duration Seconds",
description: "The shard group duration. The duration or interval (in seconds) that each shard group covers.",
optional: true,
},
},
async run({ $ }) {
const response = await this.influxDbCloud.updateBucket({
$,
bucketId: this.bucketId,
data: {
name: this.name,
description: this.description,
retentionRules: [
{
everySeconds: this.everySeconds,
shardGroupDurationSeconds: this.shardGroupDurationSeconds,
type: "expire",
},
],
},
});
$.export("$summary", `Successfully updated bucket with ID: ${response.id}`);
return response;
},
};
50 changes: 50 additions & 0 deletions components/influxdb_cloud/actions/write-data/write-data.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import influxDbCloud from "../../influxdb_cloud.app.mjs";

export default {
key: "influxdb_cloud-write-data",
name: "Write Data",
description: "Write data to a specific bucket in InfluxDB Cloud. [See the documentation](https://docs.influxdata.com/influxdb3/cloud-serverless/api/v2/#operation/PostWrite)",
version: "0.0.1",
type: "action",
props: {
influxDbCloud,
bucketId: {
propDefinition: [
influxDbCloud,
"bucketId",
],
},
data: {
type: "string",
label: "Data",
description: "Provide data in [line protocol format](https://docs.influxdata.com/influxdb3/cloud-serverless/reference/syntax/line-protocol/). Example: `measurementName fieldKey=\"field string value\" 1795523542833000000`",
},
precision: {
type: "string",
label: "Precision",
description: "The precision for unix timestamps in the line protocol batch",
options: [
"ms",
"s",
"us",
"ns",
],
optional: true,
},
},
async run({ $ }) {
const response = await this.influxDbCloud.writeData({
$,
params: {
bucket: this.bucketId,
precision: this.precision,
},
data: this.data,
headers: {
"Content-Type": "text/plain",
},
});
$.export("$summary", "Successfully wrote data to bucket");
return response;
},
};
22 changes: 22 additions & 0 deletions components/influxdb_cloud/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function optionalParseAsJSON(value) {
try {
return JSON.parse(value);
} catch (e) {
return value;
}
}

export function parseObjectEntries(value) {
const obj = typeof value === "string"
? JSON.parse(value)
: value;
return Object.fromEntries(
Object.entries(obj).map(([
key,
value,
]) => [
key,
optionalParseAsJSON(value),
]),
);
}
148 changes: 144 additions & 4 deletions components/influxdb_cloud/influxdb_cloud.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,151 @@
import { axios } from "@pipedream/platform";
const LIMIT = 50;

export default {
type: "app",
app: "influxdb_cloud",
propDefinitions: {},
propDefinitions: {
bucketId: {
type: "string",
label: "Bucket ID",
description: "The identifier of a bucket",
async options({ page }) {
const { buckets } = await this.listBuckets({
params: {
limit: LIMIT,
offset: page * LIMIT,
},
});
return buckets?.map(({
id: value, name: label,
}) => ({
label,
value,
})) || [];
},
},
scriptId: {
type: "string",
label: "Script ID",
description: "The identifier of a script",
async options({ page }) {
const { scripts } = await this.listScripts({
params: {
limit: LIMIT,
offset: page * LIMIT,
},
});
return scripts?.map(({
id: value, name: label,
}) => ({
label,
value,
})) || [];
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl(version) {
let { url } = this.$auth;
if (version === "v2") {
url += (url.endsWith("/")
? ""
: "/") + "api/v2";
} else {
url = url.endsWith("/")
? url.slice(0, -1)
: url;
}
return url;
},
_makeRequest({
$ = this,
version = "v2",
path,
headers,
...opts
}) {
return axios($, {
url: `${this._baseUrl(version)}${path}`,
headers: {
"Authorization": `Token ${this.$auth.token}`,
"Content-Type": "application/json",
...headers,
},
...opts,
});
},
listBuckets(opts = {}) {
return this._makeRequest({
path: "/buckets",
...opts,
});
},
listScripts(opts = {}) {
return this._makeRequest({
path: "/scripts",
...opts,
});
},
listTasks(opts = {}) {
return this._makeRequest({
path: "/tasks",
...opts,
});
},
updateBucket({
bucketId, ...opts
}) {
return this._makeRequest({
method: "PATCH",
path: `/buckets/${bucketId}`,
...opts,
});
},
writeData(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/write",
...opts,
});
},
invokeScript({
scriptId, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/scripts/${scriptId}/invoke`,
...opts,
});
},
async *paginate({
fn,
resourceKey,
params,
max,
}) {
params = {
...params,
limit: LIMIT,
offset: 0,
};
let total, count = 0;
do {
const response = await fn({
params,
});
const results = resourceKey
? response[resourceKey]
: response;
for (const item of results) {
yield item;
if (max && ++count >= max) {
return;
}
}
total = results?.length;
params.offset += params.limit;
} while (total);
},
},
};
2 changes: 1 addition & 1 deletion components/influxdb_cloud/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/influxdb_cloud",
"version": "0.6.0",
"version": "0.7.0",
"description": "Pipedream influxdb_cloud Components",
"main": "influxdb_cloud.app.mjs",
"keywords": [
Expand Down
Loading
Loading