Skip to content

Commit b622715

Browse files
committed
keboola init
1 parent feac320 commit b622715

File tree

8 files changed

+282
-3
lines changed

8 files changed

+282
-3
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import keboola from "../../keboola.app.mjs";
2+
3+
export default {
4+
key: "keboola-get-bucket-detail",
5+
name: "Get Bucket Detail",
6+
description: "Get detailed information about a specific bucket in Keboola. [See the documentation](https://keboola.docs.apiary.io/#reference/buckets/buckets-collection/details-of-a-bucket)",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
keboola,
11+
bucketId: {
12+
propDefinition: [
13+
keboola,
14+
"bucketId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.keboola.getBucketDetails({
20+
bucketId: this.bucketId,
21+
});
22+
23+
$.export("$summary", `Successfully retrieved bucket details for bucket ID: ${this.bucketId}`);
24+
return response;
25+
},
26+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import keboola from "../../keboola.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "keboola-get-table-detail",
6+
name: "Get Table Detail",
7+
description: "Get detailed information about a specific table. [See the documentation](https://keboola.docs.apiary.io/)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
keboola,
12+
bucketId: {
13+
propDefinition: [
14+
keboola,
15+
"bucketId",
16+
],
17+
},
18+
tableId: {
19+
propDefinition: [
20+
keboola,
21+
"tableId",
22+
(c) => ({
23+
bucketId: c.bucketId,
24+
}),
25+
],
26+
},
27+
},
28+
async run({ $ }) {
29+
const response = await this.keboola.getTableDetails({
30+
tableId: this.tableId,
31+
});
32+
$.export("$summary", `Successfully retrieved details for table ID: ${this.tableId}`);
33+
return response;
34+
},
35+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import keboola from "../../keboola.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "keboola-retrieve-bucket-tables",
6+
name: "List Tables In Bucket",
7+
description: "Lists all tables in a specified bucket. [See the documentation](https://keboola.docs.apiary.io/)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
keboola,
12+
bucketId: {
13+
propDefinition: [
14+
keboola,
15+
"bucketId",
16+
],
17+
},
18+
},
19+
async run({ $ }) {
20+
const tables = await this.keboola.listTablesInBucket({
21+
bucketId: this.bucketId,
22+
});
23+
$.export("$summary", `Successfully retrieved ${tables.length} tables from bucket ${this.bucketId}.`);
24+
return tables;
25+
},
26+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import keboola from "../../keboola.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "keboola-retrieve-buckets",
6+
name: "Retrieve Buckets",
7+
description: "Lists all buckets in your Keboola project. [See the documentation](https://keboola.docs.apiary.io/)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
keboola,
12+
},
13+
async run({ $ }) {
14+
const buckets = await this.keboola.listBuckets();
15+
$.export("$summary", `Successfully retrieved ${buckets.length} buckets.`);
16+
return buckets;
17+
},
18+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import keboola from "../../keboola.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "keboola-update-bucket",
6+
name: "Update Bucket",
7+
description: "Updates a bucket with a new display name in Keboola. [See the documentation](https://keboola.docs.apiary.io/)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
keboola,
12+
bucketId: {
13+
propDefinition: [
14+
keboola,
15+
"bucketId",
16+
],
17+
},
18+
displayName: {
19+
type: "string",
20+
label: "Display Name",
21+
description: "The new display name for the bucket",
22+
},
23+
},
24+
async run({ $ }) {
25+
const response = await this.keboola.updateBucket({
26+
bucketId: this.bucketId,
27+
displayName: this.displayName,
28+
});
29+
30+
$.export("$summary", `Successfully updated bucket with ID ${this.bucketId} to have new display name: "${this.displayName}"`);
31+
return response;
32+
},
33+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import keboola from "../../keboola.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "keboola-update-table-name",
6+
name: "Update Table Name",
7+
description: "Update the name of a table. [See the documentation](https://keboola.docs.apiary.io/)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
keboola,
12+
tableId: {
13+
propDefinition: [
14+
keboola,
15+
"tableId",
16+
],
17+
},
18+
name: {
19+
type: "string",
20+
label: "New Table Name",
21+
description: "The new name for the table",
22+
},
23+
},
24+
async run({ $ }) {
25+
const response = await this.keboola.updateTableName({
26+
tableId: this.tableId,
27+
name: this.name,
28+
});
29+
$.export("$summary", `Successfully updated table name to ${this.name}`);
30+
return response;
31+
},
32+
};

components/keboola/keboola.app.mjs

Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,118 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "keboola",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
bucketId: {
8+
type: "string",
9+
label: "Bucket ID",
10+
description: "Select a bucket",
11+
async options() {
12+
const buckets = await this.listBuckets();
13+
return buckets.map((bucket) => ({
14+
label: bucket.name,
15+
value: bucket.id,
16+
}));
17+
},
18+
},
19+
tableId: {
20+
type: "string",
21+
label: "Table ID",
22+
description: "Select a table",
23+
async options({ bucketId }) {
24+
const tables = await this.listTablesInBucket({
25+
bucketId,
26+
});
27+
return tables.map((table) => ({
28+
label: table.name,
29+
value: table.id,
30+
}));
31+
},
32+
},
33+
displayName: {
34+
type: "string",
35+
label: "Display Name",
36+
description: "The new display name for the bucket",
37+
},
38+
name: {
39+
type: "string",
40+
label: "Name",
41+
description: "The new name for the table",
42+
},
43+
},
544
methods: {
6-
// this.$auth contains connected account data
45+
_baseUrl() {
46+
return "https://connection.keboola.com/v2/storage";
47+
},
48+
async _makeRequest(opts = {}) {
49+
const {
50+
$ = this, method = "GET", path = "/", headers, ...otherOpts
51+
} = opts;
52+
return axios($, {
53+
...otherOpts,
54+
method,
55+
url: this._baseUrl() + path,
56+
headers: {
57+
...headers,
58+
"X-StorageApi-Token": this.$auth.api_key,
59+
},
60+
});
61+
},
62+
async listBuckets(opts = {}) {
63+
return this._makeRequest({
64+
path: "/buckets",
65+
...opts,
66+
});
67+
},
68+
async getBucketDetails({
69+
bucketId, ...opts
70+
}) {
71+
return this._makeRequest({
72+
path: `/buckets/${bucketId}`,
73+
...opts,
74+
});
75+
},
76+
async listTablesInBucket({
77+
bucketId, ...opts
78+
}) {
79+
return this._makeRequest({
80+
path: `/buckets/${bucketId}/tables`,
81+
...opts,
82+
});
83+
},
84+
async getTableDetails({
85+
tableId, ...opts
86+
}) {
87+
return this._makeRequest({
88+
path: `/tables/${tableId}`,
89+
...opts,
90+
});
91+
},
92+
async updateBucket({
93+
bucketId, displayName, ...opts
94+
}) {
95+
return this._makeRequest({
96+
method: "PUT",
97+
path: `/buckets/${bucketId}`,
98+
data: {
99+
displayName,
100+
},
101+
...opts,
102+
});
103+
},
104+
async updateTableName({
105+
tableId, name, ...opts
106+
}) {
107+
return this._makeRequest({
108+
method: "PUT",
109+
path: `/tables/${tableId}`,
110+
data: {
111+
name,
112+
},
113+
...opts,
114+
});
115+
},
7116
authKeys() {
8117
console.log(Object.keys(this.$auth));
9118
},

components/keboola/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}

0 commit comments

Comments
 (0)