Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
45 changes: 45 additions & 0 deletions components/glide/actions/add-rows/add-rows.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { parseObject } from "../../common/utils.mjs";
import glide from "../../glide.app.mjs";

export default {
key: "glide-add-rows",
name: "Add Rows to Table",
description: "Add new rows to a specified table. [See the documentation](https://apidocs.glideapps.com/api-reference/v2/tables/post-table-rows)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: false,
},
type: "action",
props: {
glide,
tableId: {
propDefinition: [
glide,
"tableId",
],
},
rows: {
type: "string[]",
label: "Rows",
description: "Array of row objects to add. Each object should contain the column names as keys and their values.",
},
},
async run({ $ }) {
let rowsData = parseObject(this.rows);
const response = await this.glide.addRows({
$,
tableId: this.tableId,
data: rowsData,
});

const addedCount = rowsData.length;
const plural = addedCount === 1
? ""
: "s";
$.export("$summary", `Successfully added ${addedCount} row${plural}`);
return response;
},
};

43 changes: 43 additions & 0 deletions components/glide/actions/delete-row/delete-row.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import glide from "../../glide.app.mjs";

export default {
key: "glide-delete-row",
name: "Delete Row",
description: "Delete an existing row from a table. [See the documentation](https://apidocs.glideapps.com/api-reference/v2/tables/delete-table-row)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: false,
},
type: "action",
props: {
glide,
tableId: {
propDefinition: [
glide,
"tableId",
],
},
rowId: {
propDefinition: [
glide,
"rowId",
({ tableId }) => ({
tableId,
}),
],
},
},
async run({ $ }) {
const response = await this.glide.deleteRow({
$,
tableId: this.tableId,
rowId: this.rowId,
});

$.export("$summary", `Successfully deleted row ${this.rowId}`);
return response;
},
};

59 changes: 59 additions & 0 deletions components/glide/actions/get-rows/get-rows.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import glide from "../../glide.app.mjs";

export default {
key: "glide-get-rows",
name: "Get Rows",
description: "Get rows from a specified table. [See the documentation](https://apidocs.glideapps.com/api-reference/v2/tables/get-table-rows)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
type: "action",
props: {
glide,
tableId: {
propDefinition: [
glide,
"tableId",
],
},
limit: {
type: "integer",
label: "Limit",
description: "Maximum number of rows to return",
optional: true,
default: 100,
},
continuation: {
type: "string",
label: "Continuation Token",
description: "Token for pagination to get the next set of results",
optional: true,
},
},
async run({ $ }) {
const params = {};
if (this.limit) {
params.limit = this.limit;
}
if (this.continuation) {
params.continuation = this.continuation;
}

const response = await this.glide.getRows({
$,
tableId: this.tableId,
params,
});

const rowCount = response.data?.length || 0;
const plural = rowCount === 1
? ""
: "s";
$.export("$summary", `Successfully retrieved ${rowCount} row${plural}`);
return response;
},
};

35 changes: 35 additions & 0 deletions components/glide/actions/list-tables/list-tables.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import glide from "../../glide.app.mjs";

export default {
key: "glide-list-tables",
name: "List Big Tables",
description: "List all Big Tables associated with your Glide team. [See the documentation](https://apidocs.glideapps.com/api-reference/v2/tables/get-tables)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
type: "action",
props: {
glide,
alert: {

Check warning on line 16 in components/glide/actions/list-tables/list-tables.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props

Check warning on line 16 in components/glide/actions/list-tables/list-tables.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props
type: "alert",
alertType: "warning",
content: "This endpoint only retrieves `Big Table` tables. No other table types will be included in the response, even though they are part of your Glide team.",
},
},
async run({ $ }) {
const response = await this.glide.listTables({
$,
});

const count = response.data.length || 0;
const plural = count === 1
? ""
: "s";
$.export("$summary", `Successfully retrieved ${count} Big Table${plural}`);
return response;
},
};

50 changes: 50 additions & 0 deletions components/glide/actions/update-row/update-row.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { parseObject } from "../../common/utils.mjs";
import glide from "../../glide.app.mjs";

export default {
key: "glide-update-row",
name: "Update Row",
description: "Update an existing row in a table. [See the documentation](https://apidocs.glideapps.com/api-reference/v2/tables/patch-update-row)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: false,
},
type: "action",
props: {
glide,
tableId: {
propDefinition: [
glide,
"tableId",
],
},
rowId: {
propDefinition: [
glide,
"rowId",
({ tableId }) => ({
tableId,
}),
],
},
rowData: {
type: "object",
label: "Row Data",
description: "Object containing the column names as keys and their new values.",
},
},
async run({ $ }) {
const response = await this.glide.updateRow({
$,
tableId: this.tableId,
rowId: this.rowId,
data: parseObject(this.rowData),
});

$.export("$summary", `Successfully updated row ${this.rowId}`);
return response;
},
};

24 changes: 24 additions & 0 deletions components/glide/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
93 changes: 88 additions & 5 deletions components/glide/glide.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,94 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "glide",
propDefinitions: {},
propDefinitions: {
tableId: {
type: "string",
label: "Table ID",
description: "The ID of the table",
async options() {
const { data } = await this.listTables();
return data.map(({
id: value, name: label,
}) => ({
label,
value,
}));
},
},
rowId: {
type: "string",
label: "Row ID",
description: "The ID of the row",
async options({ tableId }) {
const { data } = await this.getRows({
tableId,
});
return data.map(({ $rowID }) => $rowID);
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
getBaseUrl() {
return "https://api.glideapps.com";
},
getHeaders() {
return {
"Content-Type": "application/json",
"Authorization": `Bearer ${this.$auth.secret_token}`,
};
},
makeRequest({
$ = this, path, ...args
} = {}) {
return axios($, {
headers: this.getHeaders(),
url: `${this.getBaseUrl()}${path}`,
...args,
});
},
listTables(args = {}) {
return this.makeRequest({
path: "/tables",
...args,
});
},
getRows({
tableId, ...args
} = {}) {
return this.makeRequest({
path: `/tables/${tableId}/rows`,
...args,
});
},
addRows({
tableId, ...args
} = {}) {
return this.makeRequest({
method: "POST",
path: `/tables/${tableId}/rows`,
...args,
});
},
updateRow({
tableId, rowId, ...args
} = {}) {
return this.makeRequest({
method: "PATCH",
path: `/tables/${tableId}/rows/${rowId}`,
...args,
});
},
deleteRow({
tableId, rowId, ...args
} = {}) {
return this.makeRequest({
method: "DELETE",
path: `/tables/${tableId}/rows/${rowId}`,
...args,
});
},
},
};
};
5 changes: 4 additions & 1 deletion components/glide/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/glide",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Glide Components",
"main": "glide.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.1"
}
}
Loading
Loading