diff --git a/components/google_appsheet/.gitignore b/components/google_appsheet/.gitignore deleted file mode 100644 index ec761ccab7595..0000000000000 --- a/components/google_appsheet/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.js -*.mjs -dist \ No newline at end of file diff --git a/components/google_appsheet/actions/add-row/add-row.mjs b/components/google_appsheet/actions/add-row/add-row.mjs new file mode 100644 index 0000000000000..2b87b541a56e6 --- /dev/null +++ b/components/google_appsheet/actions/add-row/add-row.mjs @@ -0,0 +1,19 @@ +import common from "../common/base.mjs"; + +export default { + ...common, + key: "google_appsheet-add-row", + name: "Add Row", + description: "Adds a new row to a specific table in the AppSheet app. [See the documentation](https://support.google.com/appsheet/answer/10104797?hl=en&ref_topic=10105767&sjid=1665780.0.1444403316-SA#)", + version: "0.0.1", + type: "action", + methods: { + ...common.methods, + getAction() { + return "Add"; + }, + getSummary() { + return "Added a new row successfully"; + }, + }, +}; diff --git a/components/google_appsheet/actions/common/base.mjs b/components/google_appsheet/actions/common/base.mjs new file mode 100644 index 0000000000000..30d5e095636c4 --- /dev/null +++ b/components/google_appsheet/actions/common/base.mjs @@ -0,0 +1,47 @@ +import { parseObject } from "../../common/utils.mjs"; +import appsheet from "../../google_appsheet.app.mjs"; + +export default { + props: { + appsheet, + tableName: { + propDefinition: [ + appsheet, + "tableName", + ], + }, + row: { + propDefinition: [ + appsheet, + "row", + ], + }, + }, + methods: { + getData() { + return {}; + }, + }, + async run({ $ }) { + const dataRow = parseObject(this.row); + const rows = dataRow + ? [ + dataRow, + ] + : []; + + const response = await this.appsheet.post({ + $, + tableName: this.tableName, + data: { + Action: this.getAction(), + Rows: rows, + ...this.getData(), + }, + }); + console.log("response: ", response); + + $.export("$summary", this.getSummary(response)); + return response; + }, +}; diff --git a/components/google_appsheet/actions/delete-row/delete-row.mjs b/components/google_appsheet/actions/delete-row/delete-row.mjs new file mode 100644 index 0000000000000..68d2fd6d6fa3d --- /dev/null +++ b/components/google_appsheet/actions/delete-row/delete-row.mjs @@ -0,0 +1,35 @@ +import common from "../common/base.mjs"; + +export default { + ...common, + key: "google_appsheet-delete-row", + name: "Delete Row", + description: "Deletes a specific row from a table in the AppSheet app. [See the documentation](https://support.google.com/appsheet/answer/10105399?hl=en&ref_topic=10105767&sjid=1665780.0.1444403316-SA)", + version: "0.0.1", + type: "action", + props: { + ...common.props, + alert: { + type: "alert", + alertType: "info", + content: "The `Row` value may contain field values of the key field values of the record to be deleted.", + }, + row: { + propDefinition: [ + common.props.appsheet, + "row", + ], + description: "The `Row` value may contain field values of the key field values of the record to be deleted.", + optional: true, + }, + }, + methods: { + ...common.methods, + getAction() { + return "Delete"; + }, + getSummary(response) { + return `${response.Rows.length} successfully delete!`; + }, + }, +}; diff --git a/components/google_appsheet/actions/get-rows/get-rows.mjs b/components/google_appsheet/actions/get-rows/get-rows.mjs new file mode 100644 index 0000000000000..6b4fc95f7d3f3 --- /dev/null +++ b/components/google_appsheet/actions/get-rows/get-rows.mjs @@ -0,0 +1,45 @@ +import common from "../common/base.mjs"; + +export default { + ...common, + key: "google_appsheet-get-rows", + name: "Get Rows", + description: "Read existing records in a table in the AppSheet app. [See the documentation](https://support.google.com/appsheet/answer/10104797?hl=en&ref_topic=10105767&sjid=1665780.0.1444403316-SA#)", + version: "0.0.1", + type: "action", + props: { + ...common.props, + selector: { + type: "string", + label: "Selector", + description: "You can specify an expression to select and format the rows returned. **Example: Filter(TableName, [Column] = \"Value\")** [See the documentation](https://support.google.com/appsheet/answer/10105770?hl=en&ref_topic=10105767&sjid=3242006823758562345-NC)", + optional: true, + }, + row: { + propDefinition: [ + common.props.appsheet, + "row", + ], + description: "You can also filter the results using the `Row` value. The `Row` value may contain field values of the key field values of the record to be retrieved. **Example:** `{ \"First Name\": \"John\" }`", + optional: true, + }, + }, + methods: { + ...common.methods, + getAction() { + return "Find"; + }, + getData() { + return this.selector + ? { + Properties: { + Selector: this.selector, + }, + } + : {}; + }, + getSummary(response) { + return `Successfully retrieved ${ response.length || 0} rows`; + }, + }, +}; diff --git a/components/google_appsheet/actions/update-row/update-row.mjs b/components/google_appsheet/actions/update-row/update-row.mjs new file mode 100644 index 0000000000000..a8809fab8eb24 --- /dev/null +++ b/components/google_appsheet/actions/update-row/update-row.mjs @@ -0,0 +1,29 @@ +import common from "../common/base.mjs"; + +export default { + ...common, + key: "google_appsheet-update-row", + name: "Update Row", + description: "Updates an existing row in a specific table in the AppSheet app. [See the documentation](https://support.google.com/appsheet/answer/10105002?hl=en&ref_topic=10105767&sjid=1665780.0.1444403316-SA)", + version: "0.0.1", + type: "action", + props: { + ...common.props, + alert: { + type: "alert", + alertType: "info", + content: `The \`Row\` value must include the key field values of the record to be updated. + \nThe \`Row\` value may contain one or more field values of other fields to be updated in the record. + \nIf a field's name is omitted, that field's value is not changed. If the field can be assigned a string value and the field value you specify is "" then the field's value will be cleared.`, + }, + }, + methods: { + ...common.methods, + getAction() { + return "Edit"; + }, + getSummary(response) { + return `${response.Rows.length} successfully updated!`; + }, + }, +}; diff --git a/components/google_appsheet/app/google_appsheet.app.ts b/components/google_appsheet/app/google_appsheet.app.ts deleted file mode 100644 index faa122b0a8bbf..0000000000000 --- a/components/google_appsheet/app/google_appsheet.app.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineApp } from "@pipedream/types"; - -export default defineApp({ - type: "app", - app: "google_appsheet", - propDefinitions: {}, - methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); - }, - }, -}); diff --git a/components/google_appsheet/common/utils.mjs b/components/google_appsheet/common/utils.mjs new file mode 100644 index 0000000000000..dcc9cc61f6f41 --- /dev/null +++ b/components/google_appsheet/common/utils.mjs @@ -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; +}; diff --git a/components/google_appsheet/google_appsheet.app.mjs b/components/google_appsheet/google_appsheet.app.mjs new file mode 100644 index 0000000000000..a69f338378891 --- /dev/null +++ b/components/google_appsheet/google_appsheet.app.mjs @@ -0,0 +1,43 @@ +import { axios } from "@pipedream/platform"; + +export default { + type: "app", + app: "google_appsheet", + propDefinitions: { + tableName: { + type: "string", + label: "Table Name", + description: "Name of the table. **Select Data > Tables** and expand the table details to view the table name.", + }, + row: { + type: "object", + label: "Row", + description: "JSON object representing the row data", + }, + }, + methods: { + _baseUrl(tableName) { + return `https://api.appsheet.com/api/v2/apps/${this.$auth.app_id}/tables/${encodeURIComponent(tableName)}/Action`; + }, + _headers() { + return { + "ApplicationAccessKey": `${this.$auth.api_key}`, + }; + }, + _makeRequest({ + $ = this, tableName, ...opts + }) { + return axios($, { + url: this._baseUrl(tableName), + headers: this._headers(), + ...opts, + }); + }, + post(opts = {}) { + return this._makeRequest({ + method: "POST", + ...opts, + }); + }, + }, +}; diff --git a/components/google_appsheet/package.json b/components/google_appsheet/package.json index c46728211ea7f..662868a02a3a3 100644 --- a/components/google_appsheet/package.json +++ b/components/google_appsheet/package.json @@ -1,18 +1,18 @@ { "name": "@pipedream/google_appsheet", - "version": "0.0.3", + "version": "0.1.0", "description": "Pipedream Google Appsheet Components", - "main": "dist/app/google_appsheet.app.mjs", + "main": "google_appsheet.app.mjs", "keywords": [ "pipedream", "google_appsheet" ], - "files": [ - "dist" - ], "homepage": "https://pipedream.com/apps/google_appsheet", "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 365318da10224..540e2ca7a707a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4301,7 +4301,11 @@ importers: specifier: ^3.0.0 version: 3.0.3 - components/google_appsheet: {} + components/google_appsheet: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/google_calendar: dependencies: @@ -32197,6 +32201,8 @@ snapshots: '@putout/operator-filesystem': 5.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3)) '@putout/operator-json': 2.2.0 putout: 36.13.1(eslint@8.57.1)(typescript@5.6.3) + transitivePeerDependencies: + - supports-color '@putout/operator-regexp@1.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3))': dependencies: