diff --git a/components/zoho_sheet/.gitignore b/components/zoho_sheet/.gitignore deleted file mode 100644 index ec761ccab7595..0000000000000 --- a/components/zoho_sheet/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.js -*.mjs -dist \ No newline at end of file diff --git a/components/zoho_sheet/actions/create-row/create-row.mjs b/components/zoho_sheet/actions/create-row/create-row.mjs new file mode 100644 index 0000000000000..882a067ba3c02 --- /dev/null +++ b/components/zoho_sheet/actions/create-row/create-row.mjs @@ -0,0 +1,54 @@ +import { parseObject } from "../../common/utils.mjs"; +import zohoSheet from "../../zoho_sheet.app.mjs"; + +export default { + key: "zoho_sheet-create-row", + name: "Create Row", + description: "Creates a new row in the specified worksheet. [See the documentation](https://www.zoho.com/sheet/help/api/v2/)", + version: "0.0.1", + type: "action", + props: { + zohoSheet, + workbookId: { + propDefinition: [ + zohoSheet, + "workbookId", + ], + }, + worksheet: { + propDefinition: [ + zohoSheet, + "worksheet", + ({ workbookId }) => ({ + workbookId, + }), + ], + }, + headerRow: { + type: "integer", + label: "Header Row", + description: "Default value is 1. This can be mentioned if the table header is not in the first row of the worksheet.", + optional: true, + }, + data: { + propDefinition: [ + zohoSheet, + "data", + ], + }, + }, + async run({ $ }) { + const response = await this.zohoSheet.createRow({ + $, + workbookId: this.workbookId, + data: { + worksheet_id: this.worksheet, + header_row: this.headerRow || 1, + json_data: JSON.stringify(parseObject(this.data)), + }, + }); + + $.export("$summary", `Successfully created a row in the worksheet: ${response.sheet_name}`); + return response; + }, +}; diff --git a/components/zoho_sheet/actions/search-delete-row/search-delete-row.mjs b/components/zoho_sheet/actions/search-delete-row/search-delete-row.mjs new file mode 100644 index 0000000000000..da2705b497491 --- /dev/null +++ b/components/zoho_sheet/actions/search-delete-row/search-delete-row.mjs @@ -0,0 +1,88 @@ +import { ConfigurationError } from "@pipedream/platform"; +import { parseObject } from "../../common/utils.mjs"; +import zohoSheet from "../../zoho_sheet.app.mjs"; + +export default { + key: "zoho_sheet-search-delete-row", + name: "Search and Delete Row", + description: "Searches for a row based on provided criteria and deletes it. [See the documentation](https://www.zoho.com/sheet/help/api/v2/)", + version: "0.0.1", + type: "action", + props: { + zohoSheet, + workbookId: { + propDefinition: [ + zohoSheet, + "workbookId", + ], + }, + worksheet: { + propDefinition: [ + zohoSheet, + "worksheet", + ({ workbookId }) => ({ + workbookId, + }), + ], + }, + headerRow: { + propDefinition: [ + zohoSheet, + "headerRow", + ], + optional: true, + }, + criteria: { + propDefinition: [ + zohoSheet, + "criteria", + ], + optional: true, + }, + rowArray: { + type: "integer[]", + label: "Row Array", + description: "Array of row indexs, which needs to be deleted.", + optional: true, + }, + firstMatchOnly: { + propDefinition: [ + zohoSheet, + "firstMatchOnly", + ], + }, + isCaseSensitive: { + propDefinition: [ + zohoSheet, + "isCaseSensitive", + ], + }, + deleteRows: { + type: "boolean", + label: "Delete Rows", + description: "If true it will delete the rows completely, otherwise the records are only erased by default.", + default: false, + }, + }, + async run({ $ }) { + if (!this.criteria && !this.rowArray) { + throw new ConfigurationError("You must provide at least **Criteria** or **Row Array** to process this request."); + } + const response = await this.zohoSheet.deleteRow({ + $, + workbookId: this.workbookId, + data: { + worksheet_id: this.worksheet, + header_row: this.headerRow, + criteria: this.criteria, + row_array: JSON.stringify(parseObject(this.rowArray)), + first_match_only: this.firstMatchOnly, + is_case_sensitive: this.isCaseSensitive, + delete_rows: this.deleteRows, + }, + }); + + $.export("$summary", `Row matching criteria deleted successfully from worksheet ${this.worksheet}`); + return response; + }, +}; diff --git a/components/zoho_sheet/actions/update-row/update-row.mjs b/components/zoho_sheet/actions/update-row/update-row.mjs new file mode 100644 index 0000000000000..4dfd8bdf696e6 --- /dev/null +++ b/components/zoho_sheet/actions/update-row/update-row.mjs @@ -0,0 +1,81 @@ +import { parseObject } from "../../common/utils.mjs"; +import zohoSheet from "../../zoho_sheet.app.mjs"; + +export default { + key: "zoho_sheet-update-row", + name: "Update Row", + description: "Finds a specific row by its index and updates its content. [See the documentation](https://www.zoho.com/sheet/help/api/v2/)", + version: "0.0.1", + type: "action", + props: { + zohoSheet, + workbookId: { + propDefinition: [ + zohoSheet, + "workbookId", + ], + }, + worksheet: { + propDefinition: [ + zohoSheet, + "worksheet", + ({ workbookId }) => ({ + workbookId, + }), + ], + }, + headerRow: { + propDefinition: [ + zohoSheet, + "headerRow", + ], + optional: true, + }, + criteria: { + propDefinition: [ + zohoSheet, + "criteria", + ], + description: "If criteria is not set all available rows will get updated. Mention the criteria as described above.", + optional: true, + }, + firstMatchOnly: { + propDefinition: [ + zohoSheet, + "firstMatchOnly", + ], + description: "If true and if there are multiple records on the specified criteria, records will be updated for first match alone. Otherwise, all the matched records will be updated.", + }, + isCaseSensitive: { + propDefinition: [ + zohoSheet, + "isCaseSensitive", + ], + }, + data: { + propDefinition: [ + zohoSheet, + "data", + ], + type: "object", + description: "The JSON data that needs to be updated. Example:{\"Month\":\"May\",\"Amount\":50}", + }, + }, + async run({ $ }) { + const response = await this.zohoSheet.updateRow({ + $, + workbookId: this.workbookId, + data: { + worksheet_id: this.worksheet, + header_row: this.headerRow, + criteria: this.criteria, + first_match_only: this.firstMatchOnly, + is_case_sensitive: this.isCaseSensitive, + data: JSON.stringify(parseObject(this.data)), + }, + }); + + $.export("$summary", `Successfully updated ${response.no_of_affected_rows} row(s) in worksheet ${this.worksheet}`); + return response; + }, +}; diff --git a/components/zoho_sheet/app/zoho_sheet.app.ts b/components/zoho_sheet/app/zoho_sheet.app.ts deleted file mode 100644 index 7b57f52e4f210..0000000000000 --- a/components/zoho_sheet/app/zoho_sheet.app.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineApp } from "@pipedream/types"; - -export default defineApp({ - type: "app", - app: "zoho_sheet", - propDefinitions: {}, - methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); - }, - }, -}); diff --git a/components/zoho_sheet/common/utils.mjs b/components/zoho_sheet/common/utils.mjs new file mode 100644 index 0000000000000..dcc9cc61f6f41 --- /dev/null +++ b/components/zoho_sheet/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/zoho_sheet/package.json b/components/zoho_sheet/package.json index dd257a1f16d70..7c6ae868bb86f 100644 --- a/components/zoho_sheet/package.json +++ b/components/zoho_sheet/package.json @@ -1,18 +1,18 @@ { "name": "@pipedream/zoho_sheet", - "version": "0.0.3", + "version": "0.1.0", "description": "Pipedream Zoho Sheet Components", - "main": "dist/app/zoho_sheet.app.mjs", + "main": "zoho_sheet.app.mjs", "keywords": [ "pipedream", "zoho_sheet" ], - "files": [ - "dist" - ], "homepage": "https://pipedream.com/apps/zoho_sheet", "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } } diff --git a/components/zoho_sheet/sources/common/base.mjs b/components/zoho_sheet/sources/common/base.mjs new file mode 100644 index 0000000000000..68b830a1fb559 --- /dev/null +++ b/components/zoho_sheet/sources/common/base.mjs @@ -0,0 +1,47 @@ +import zohoSheet from "../../zoho_sheet.app.mjs"; + +export default { + props: { + zohoSheet, + http: "$.interface.http", + db: "$.service.db", + serviceName: { + type: "string", + label: "Service Name", + description: "The name of the webhook.", + }, + }, + methods: { + getExtraData() { + return {}; + }, + }, + hooks: { + async activate() { + await this.zohoSheet.createWebhook({ + data: { + service_name: this.serviceName.replace(/\s/g, ""), + target_url: this.http.endpoint, + event: this.getEvent(), + ...this.getExtraData(), + }, + }); + }, + async deactivate() { + await this.zohoSheet.deleteWebhook({ + data: { + target_url: this.http.endpoint, + ...this.getExtraData(), + }, + }); + }, + }, + async run({ body }) { + const ts = Date.parse(new Date()); + this.$emit(body, { + id: `${ts}`, + summary: this.getSummary(body), + ts: ts, + }); + }, +}; diff --git a/components/zoho_sheet/sources/new-or-updated-row-instant/new-or-updated-row-instant.mjs b/components/zoho_sheet/sources/new-or-updated-row-instant/new-or-updated-row-instant.mjs new file mode 100644 index 0000000000000..645345c7f31e3 --- /dev/null +++ b/components/zoho_sheet/sources/new-or-updated-row-instant/new-or-updated-row-instant.mjs @@ -0,0 +1,54 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "zoho_sheet-new-or-updated-row-instant", + name: "New or Updated Row (Instant)", + description: "Emit new event whenever a row is added or modified.", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + ...common.props, + workbookId: { + propDefinition: [ + common.props.zohoSheet, + "workbookId", + ], + }, + worksheetId: { + propDefinition: [ + common.props.zohoSheet, + "worksheet", + ({ workbookId }) => ({ + workbookId, + }), + ], + withLabel: true, + }, + alert: { + type: "alert", + alertType: "info", + content: "**New row** will be triggered only after the entire row is completed.", + }, + }, + methods: { + ...common.methods, + getEvent() { + return "update_worksheet"; + }, + getExtraData() { + return { + resource_id: this.workbookId, + worksheet_id: this.worksheetId.value, + }; + }, + getSummary({ updated_rows }) { + return `Row ${updated_rows[0].row_type === "NEW" + ? "created" + : "updated"} in worksheet ${this.worksheetId.label}`; + }, + }, + sampleEmit, +}; diff --git a/components/zoho_sheet/sources/new-or-updated-row-instant/test-event.mjs b/components/zoho_sheet/sources/new-or-updated-row-instant/test-event.mjs new file mode 100644 index 0000000000000..23b39924bf5be --- /dev/null +++ b/components/zoho_sheet/sources/new-or-updated-row-instant/test-event.mjs @@ -0,0 +1,17 @@ +export default { + "updated_rows" : [ + { + "Name": "John", + "Age": 24, + "Marks": 34, + "row_index": 3, + "row_type": "update" + } + ], + "header_row_index": 1, + "start_column": 1, + "end_column": 3, + "webhook_id": "", + "service_name": "", + "event": "update_worksheet" +} \ No newline at end of file diff --git a/components/zoho_sheet/sources/new-row-instant/new-row-instant.mjs b/components/zoho_sheet/sources/new-row-instant/new-row-instant.mjs new file mode 100644 index 0000000000000..7502ed121f841 --- /dev/null +++ b/components/zoho_sheet/sources/new-row-instant/new-row-instant.mjs @@ -0,0 +1,47 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "zoho_sheet-new-row-instant", + name: "New Row Created (Instant)", + description: "Emit new event each time a new row is created in a Zoho Sheet worksheet.", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + ...common.props, + workbookId: { + propDefinition: [ + common.props.zohoSheet, + "workbookId", + ], + }, + worksheetId: { + propDefinition: [ + common.props.zohoSheet, + "worksheet", + ({ workbookId }) => ({ + workbookId, + }), + ], + withLabel: true, + }, + }, + methods: { + ...common.methods, + getEvent() { + return "new_row"; + }, + getExtraData() { + return { + resource_id: this.workbookId, + worksheet_id: this.worksheetId.value, + }; + }, + getSummary() { + return `New row in worksheet ${this.worksheetId.label}`; + }, + }, + sampleEmit, +}; diff --git a/components/zoho_sheet/sources/new-row-instant/test-event.mjs b/components/zoho_sheet/sources/new-row-instant/test-event.mjs new file mode 100644 index 0000000000000..42946d13d2528 --- /dev/null +++ b/components/zoho_sheet/sources/new-row-instant/test-event.mjs @@ -0,0 +1,17 @@ +export default { + "updated_rows" : [ + { + "Name": "John", + "Age": 24, + "Marks": 34, + "row_index": 3, + "row_type": "update" + } + ], + "header_row_index": 1, + "start_column": 1, + "end_column": 3, + "webhook_id": "", + "service_name": "", + "event": "new_row" +} \ No newline at end of file diff --git a/components/zoho_sheet/sources/new-workbook-instant/new-workbook-instant.mjs b/components/zoho_sheet/sources/new-workbook-instant/new-workbook-instant.mjs new file mode 100644 index 0000000000000..7de4a80469a0d --- /dev/null +++ b/components/zoho_sheet/sources/new-workbook-instant/new-workbook-instant.mjs @@ -0,0 +1,22 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "zoho_sheet-new-workbook-instant", + name: "New Workbook Created (Instant)", + description: "Emit new event whenever a new workbook is created.", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getEvent() { + return "new_workbook"; + }, + getSummary(event) { + return `New workbook: ${event.workbook_name} (${event.resource_id})`; + }, + }, + sampleEmit, +}; diff --git a/components/zoho_sheet/sources/new-workbook-instant/test-event.mjs b/components/zoho_sheet/sources/new-workbook-instant/test-event.mjs new file mode 100644 index 0000000000000..f591adf0eb33b --- /dev/null +++ b/components/zoho_sheet/sources/new-workbook-instant/test-event.mjs @@ -0,0 +1,8 @@ +export default { + "workbook_url": "", + "resource_id": "", + "workbook_name": "", + "webhook_id": "", + "service_name": "", + "event": "new_workbook" +} \ No newline at end of file diff --git a/components/zoho_sheet/zoho_sheet.app.mjs b/components/zoho_sheet/zoho_sheet.app.mjs new file mode 100644 index 0000000000000..12e2617345c12 --- /dev/null +++ b/components/zoho_sheet/zoho_sheet.app.mjs @@ -0,0 +1,147 @@ +import { axios } from "@pipedream/platform"; + +export default { + type: "app", + app: "zoho_sheet", + propDefinitions: { + workbookId: { + type: "string", + label: "Worksheet", + description: "The ID of the workbook (Spreadsheet)", + async options() { + const { workbooks } = await this.listWorkbooks({}); + return workbooks.map(({ + resource_id: value, workbook_name: label, + }) => ({ + label, + value, + })); + }, + }, + worksheet: { + type: "string", + label: "Worksheet", + description: "The ID of the worksheet (Sheet of the Spreadsheet)", + async options({ workbookId }) { + const { worksheet_names: worksheets } = await this.listWorksheets({ + workbookId, + }); + return worksheets.map(({ + worksheet_id: value, worksheet_name: label, + }) => ({ + label, + value, + })); + }, + }, + data: { + type: "string[]", + label: "JSON Data", + description: "An array of objects of the data for the row content, including the column headers as keys. **Example: {\"Name\":\"Joe\",\"Region\":\"South\",\"Units\":284}**", + }, + headerRow: { + type: "integer", + label: "Header Row", + description: "By default, first row of the worksheet is considered as header row. This can be used if tabular data starts from any row other than the first row..", + }, + criteria: { + type: "string", + label: "Criteria", + description: "Conditions to locate the row to delete. **Example: \"Month\"=\"March\" and \"Amount\">50**", + }, + firstMatchOnly: { + type: "boolean", + label: "First Match Only", + description: "If true and if there are multiple records on the specified criteria, records will be deleted for first match alone. Otherwise, all the matched records will be deleted. This parameter will be ignored if criteria is not mentioned.", + default: false, + }, + isCaseSensitive: { + type: "boolean", + label: "Is Case Sensitive", + description: "Can be set as false for case insensitive search.", + default: true, + }, + }, + methods: { + _baseUrl() { + return `https://sheet.${this.$auth.base_api_uri}/api/v2`; + }, + _headers() { + return { + "Authorization": `Zoho-oauthtoken ${this.$auth.oauth_access_token}`, + "Content-Type": "application/x-www-form-urlencoded", + }; + }, + _makeRequest({ + $ = this, path, data, method, ...opts + }) { + return axios($, { + method: "POST", + url: this._baseUrl() + path, + headers: this._headers(), + data: { + ...data, + method, + }, + ...opts, + }); + }, + listWorkbooks(opts = {}) { + return this._makeRequest({ + path: "/workbooks", + method: "workbook.list", + ...opts, + }); + }, + listWorksheets({ + workbookId, ...opts + }) { + return this._makeRequest({ + path: `/${workbookId}`, + method: "worksheet.list", + ...opts, + }); + }, + createRow({ + workbookId, ...opts + }) { + return this._makeRequest({ + path: `/${workbookId}`, + method: "worksheet.records.add", + ...opts, + }); + }, + deleteRow({ + workbookId, ...opts + }) { + return this._makeRequest({ + path: `/${workbookId}`, + method: "worksheet.records.delete", + ...opts, + }); + }, + updateRow({ + workbookId, ...opts + }) { + return this._makeRequest({ + path: `/${workbookId}`, + method: "worksheet.records.update", + ...opts, + }); + }, + createWebhook(opts = {}) { + return this._makeRequest({ + path: "/webhook", + method: "webhook.subscribe", + ...opts, + }); + }, + deleteWebhook(opts = {}) { + return this._makeRequest({ + path: "/webhook", + method: "webhook.unsubscribe", + ...opts, + }); + }, + }, +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1de3e9243aecc..1bb40f3699cb3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12041,7 +12041,10 @@ importers: '@pipedream/platform': 1.5.1 components/zoho_sheet: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/zoho_sign: specifiers: