From be042cb318b282b3dbea67ae49a8dddaf215f712 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Fri, 13 Dec 2024 12:38:34 -0500 Subject: [PATCH 1/4] allow picklist fields --- .../actions/common/common-objects.mjs | 48 ++++++++++++++++--- .../actions/create-object/create-object.mjs | 4 +- .../actions/update-object/update-object.mjs | 4 +- components/zoho_crm/package.json | 4 +- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/components/zoho_crm/actions/common/common-objects.mjs b/components/zoho_crm/actions/common/common-objects.mjs index 4079cd9b9cc98..9c2ff34a54a95 100644 --- a/components/zoho_crm/actions/common/common-objects.mjs +++ b/components/zoho_crm/actions/common/common-objects.mjs @@ -28,23 +28,33 @@ export default { && !field.system_mandatory && field.operation_type[`api_${type}`] && ![ - "picklist", "lookup", "ownerlookup", "profileimage", ].includes(field.data_type)); }, - getType(dataType) { + getType({ + data_type: dataType, json_type: jsonType, + }) { + let type; switch (dataType) { case "boolean": - return "boolean"; + type = "boolean"; + break; case "integer": - return "integer"; + type = "integer"; + break; case "bigint": - return "integer"; + type = "integer"; + break; default: - return "string"; + type = "string"; + break; + }; + if (jsonType === "jsonarray") { + return `${type}[]`; } + return type; }, getRequiredProps(moduleType, type = "create") { let props = {}; @@ -142,8 +152,34 @@ export default { label: field.display_label, optional: true, }; + if (field.pick_list_values?.length) { + props[field.api_name].options = field.pick_list_values.map(({ + display_value: label, actual_value: value, + }) => ({ + value, + label, + })); + } } return props; }, + parseFields(fields) { + if (!fields) { + return; + } + for (const [ + key, + value, + ] of Object.entries(fields)) { + try { + if (typeof value === "string") { + fields[key] = JSON.parse(value); + } + } catch { + fields[key] = value; + } + } + return fields; + }, }, }; diff --git a/components/zoho_crm/actions/create-object/create-object.mjs b/components/zoho_crm/actions/create-object/create-object.mjs index ec29e8c3f4c38..2fb106b486237 100644 --- a/components/zoho_crm/actions/create-object/create-object.mjs +++ b/components/zoho_crm/actions/create-object/create-object.mjs @@ -5,7 +5,7 @@ export default { key: "zoho_crm-create-object", name: "Create Object", description: "Create a new object/module entry. [See the documentation](https://www.zoho.com/crm/developer/docs/api/v2/insert-records.html)", - version: "0.3.2", + version: "0.3.3", type: "action", async additionalProps() { const requiredProps = this.getRequiredProps(this.moduleType); @@ -53,7 +53,7 @@ export default { }); const objectData = { data: [ - object, + this.parseFields(object), ], }; const res = await zohoCrm.createObject(moduleType, objectData, $); diff --git a/components/zoho_crm/actions/update-object/update-object.mjs b/components/zoho_crm/actions/update-object/update-object.mjs index 67200f81ce3eb..f9c80b24e837e 100644 --- a/components/zoho_crm/actions/update-object/update-object.mjs +++ b/components/zoho_crm/actions/update-object/update-object.mjs @@ -6,7 +6,7 @@ export default { key: "zoho_crm-update-object", name: "Update Object", description: "Updates existing entities in the module. [See the documentation](https://www.zoho.com/crm/developer/docs/api/v2/update-records.html)", - version: "0.3.2", + version: "0.3.3", type: "action", props: { ...common.props, @@ -61,7 +61,7 @@ export default { const response = await zohoCrm.updateObject( moduleType, recordId, - object, + this.parseFields(object), $, ); $.export("$summary", `Successfully updated object with ID ${recordId}.`); diff --git a/components/zoho_crm/package.json b/components/zoho_crm/package.json index 24b380430bc5d..5354b3dc2d8c2 100644 --- a/components/zoho_crm/package.json +++ b/components/zoho_crm/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/zoho_crm", - "version": "0.5.2", + "version": "0.5.3", "description": "Pipedream Zoho CRM Components", "main": "zoho_crm.app.mjs", "keywords": [ @@ -10,7 +10,7 @@ "homepage": "https://pipedream.com/apps/zoho_crm", "author": "Pipedream (https://pipedream.com/)", "dependencies": { - "@pipedream/platform": "^1.2.0", + "@pipedream/platform": "^3.0.3", "crypto": "^1.0.1", "lodash.sortby": "^4.7.0" }, From 528792657689532b7e556296bd01f3dfdb582162 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Fri, 13 Dec 2024 12:41:52 -0500 Subject: [PATCH 2/4] pnpm-lock.yaml --- pnpm-lock.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 45106c07c1224..bc4068165bf03 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11963,8 +11963,8 @@ importers: components/zoho_crm: dependencies: '@pipedream/platform': - specifier: ^1.2.0 - version: 1.6.6 + specifier: ^3.0.3 + version: 3.0.3 crypto: specifier: ^1.0.1 version: 1.0.1 From 62b85464266763724818ab38f1e2e822bec95721 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Fri, 13 Dec 2024 13:02:56 -0500 Subject: [PATCH 3/4] update --- components/zoho_crm/actions/common/common-objects.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/zoho_crm/actions/common/common-objects.mjs b/components/zoho_crm/actions/common/common-objects.mjs index 9c2ff34a54a95..872fa7468df8c 100644 --- a/components/zoho_crm/actions/common/common-objects.mjs +++ b/components/zoho_crm/actions/common/common-objects.mjs @@ -148,7 +148,7 @@ export default { const { fields } = await this.listFields(moduleType); for (const field of this.filterFields(fields, type)) { props[field.api_name] = { - type: this.getType(field.data_type), + type: this.getType(field), label: field.display_label, optional: true, }; From 28c490bc3583cc317a231a438e81903363a47de8 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Mon, 16 Dec 2024 11:22:00 -0500 Subject: [PATCH 4/4] updates --- .../zoho_crm/actions/common/common-objects.mjs | 4 +++- .../actions/create-object/create-object.mjs | 9 ++++++++- .../actions/update-object/update-object.mjs | 15 ++++++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/components/zoho_crm/actions/common/common-objects.mjs b/components/zoho_crm/actions/common/common-objects.mjs index 872fa7468df8c..b754d19e2f7a4 100644 --- a/components/zoho_crm/actions/common/common-objects.mjs +++ b/components/zoho_crm/actions/common/common-objects.mjs @@ -173,7 +173,9 @@ export default { ] of Object.entries(fields)) { try { if (typeof value === "string") { - fields[key] = JSON.parse(value); + fields[key] = typeof JSON.parse(value) === "number" + ? value + : JSON.parse(value); } } catch { fields[key] = value; diff --git a/components/zoho_crm/actions/create-object/create-object.mjs b/components/zoho_crm/actions/create-object/create-object.mjs index 2fb106b486237..bcc73a73b04f6 100644 --- a/components/zoho_crm/actions/create-object/create-object.mjs +++ b/components/zoho_crm/actions/create-object/create-object.mjs @@ -1,4 +1,5 @@ import common from "../common/common-objects.mjs"; +import { ConfigurationError } from "@pipedream/platform"; export default { ...common, @@ -57,8 +58,14 @@ export default { ], }; const res = await zohoCrm.createObject(moduleType, objectData, $); - if (res.data[0].details.id) { + + if (res.data[0].code === "SUCCESS") { $.export("$summary", `Successfully created new object with ID ${res.data[0].details.id}.`); + } else { + if (res.data[0].code === "INVALID_DATA") { + throw new ConfigurationError(`Error: Invalid data for field '${res.data[0].details.api_name}'. Expected data type: ${res.data[0].details.expected_data_type}`); + } + throw new ConfigurationError(res.data[0].message); } return res; }, diff --git a/components/zoho_crm/actions/update-object/update-object.mjs b/components/zoho_crm/actions/update-object/update-object.mjs index f9c80b24e837e..e46dc7ad0c05b 100644 --- a/components/zoho_crm/actions/update-object/update-object.mjs +++ b/components/zoho_crm/actions/update-object/update-object.mjs @@ -1,5 +1,6 @@ import zohoCrm from "../../zoho_crm.app.mjs"; import common from "../common/common-objects.mjs"; +import { ConfigurationError } from "@pipedream/platform"; export default { ...common, @@ -58,13 +59,21 @@ export default { ...otherProps, }); - const response = await zohoCrm.updateObject( + const res = await zohoCrm.updateObject( moduleType, recordId, this.parseFields(object), $, ); - $.export("$summary", `Successfully updated object with ID ${recordId}.`); - return response; + + if (res.data[0].code === "SUCCESS") { + $.export("$summary", `Successfully updated object with ID ${recordId}.`); + } else { + if (res.data[0].code === "INVALID_DATA") { + throw new ConfigurationError(`Error: Invalid data for field '${res.data[0].details.api_name}'. Expected data type: ${res.data[0].details.expected_data_type}`); + } + throw new ConfigurationError(res.data[0].message); + } + return res; }, };