diff --git a/components/zoho_crm/actions/common/common-objects.mjs b/components/zoho_crm/actions/common/common-objects.mjs index 4079cd9b9cc98..b754d19e2f7a4 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 = {}; @@ -138,12 +148,40 @@ 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, }; + 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] = typeof JSON.parse(value) === "number" + ? value + : 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..bcc73a73b04f6 100644 --- a/components/zoho_crm/actions/create-object/create-object.mjs +++ b/components/zoho_crm/actions/create-object/create-object.mjs @@ -1,11 +1,12 @@ import common from "../common/common-objects.mjs"; +import { ConfigurationError } from "@pipedream/platform"; export default { ...common, 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,12 +54,18 @@ export default { }); const objectData = { data: [ - object, + this.parseFields(object), ], }; 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 67200f81ce3eb..e46dc7ad0c05b 100644 --- a/components/zoho_crm/actions/update-object/update-object.mjs +++ b/components/zoho_crm/actions/update-object/update-object.mjs @@ -1,12 +1,13 @@ import zohoCrm from "../../zoho_crm.app.mjs"; import common from "../common/common-objects.mjs"; +import { ConfigurationError } from "@pipedream/platform"; export default { ...common, 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, @@ -58,13 +59,21 @@ export default { ...otherProps, }); - const response = await zohoCrm.updateObject( + const res = await zohoCrm.updateObject( moduleType, recordId, - object, + 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; }, }; 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" }, 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