diff --git a/components/zoho_books/package.json b/components/zoho_books/package.json index 6c5d0cca37ec9..294f04229d8ea 100644 --- a/components/zoho_books/package.json +++ b/components/zoho_books/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/zoho_books", - "version": "0.2.0", + "version": "0.3.0", "description": "Pipedream Zoho Books Components", "main": "zoho_books.app.mjs", "keywords": [ diff --git a/components/zoho_books/sources/common/base.mjs b/components/zoho_books/sources/common/base.mjs index 11929a8bb4406..545668f084a90 100644 --- a/components/zoho_books/sources/common/base.mjs +++ b/components/zoho_books/sources/common/base.mjs @@ -19,32 +19,60 @@ export default { _setLastDate(lastDate) { this.db.set("lastDate", lastDate); }, + getTsField() { + return "created_time"; + }, + getParams() { + return {}; + }, + isSorted() { + return true; + }, + getItemId(item) { + return item[this.getFieldId()]; + }, async emitEvent(maxResults = false) { const lastDate = this._getLastDate(); + let maxDate = lastDate; const response = this.zohoBooks.paginate({ fn: this.getFunction(), fieldName: this.getFieldName(), + params: this.getParams(lastDate), }); let responseArray = []; + const tsField = this.getTsField(); + const isSorted = this.isSorted(); + for await (const item of response) { - if (item.created_time <= lastDate) break; - responseArray.push(item); + const ts = Date.parse(item[tsField]); + if (ts > lastDate) { + responseArray.push(item); + if (!isSorted) { + maxDate = Math.max(maxDate, ts); + } + } else { + if (isSorted) { + break; + } + } } if (responseArray.length) { if (maxResults && (responseArray.length > maxResults)) { responseArray.length = maxResults; } - this._setLastDate(Date.parse(responseArray[0].created_time)); + this._setLastDate(isSorted + ? Date.parse(responseArray[0][tsField]) + : maxDate); } for (const item of responseArray.reverse()) { this.$emit(item, { - id: item[this.getFieldId()], + id: this.getItemId(item), summary: this.getSummary(item), - ts: Date.parse(item.created_time), + ts: Date.parse(item[tsField]), }); } }, diff --git a/components/zoho_books/sources/new-customer/new-customer.mjs b/components/zoho_books/sources/new-customer/new-customer.mjs index 42e7b48b08a30..75541083e2941 100644 --- a/components/zoho_books/sources/new-customer/new-customer.mjs +++ b/components/zoho_books/sources/new-customer/new-customer.mjs @@ -6,7 +6,7 @@ export default { key: "zoho_books-new-customer", name: "New Customer", description: "Emit new event when a new customer is created.", - version: "0.0.1", + version: "0.0.2", type: "source", dedupe: "unique", methods: { diff --git a/components/zoho_books/sources/new-expense/new-expense.mjs b/components/zoho_books/sources/new-expense/new-expense.mjs index 799e4cf4b6cd4..fd4dfa6444498 100644 --- a/components/zoho_books/sources/new-expense/new-expense.mjs +++ b/components/zoho_books/sources/new-expense/new-expense.mjs @@ -6,7 +6,7 @@ export default { key: "zoho_books-new-expense", name: "New Expense", description: "Emit new event when a new expense is created.", - version: "0.0.1", + version: "0.0.2", type: "source", dedupe: "unique", methods: { diff --git a/components/zoho_books/sources/new-or-updated-invoice/new-or-updated-invoice.mjs b/components/zoho_books/sources/new-or-updated-invoice/new-or-updated-invoice.mjs new file mode 100644 index 0000000000000..46fef69941509 --- /dev/null +++ b/components/zoho_books/sources/new-or-updated-invoice/new-or-updated-invoice.mjs @@ -0,0 +1,60 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "zoho_books-new-or-updated-invoice", + name: "New or Updated Invoice", + description: "Emit new event when a new invoice is created or an existing invoice is updated.", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getFunction() { + return this.zohoBooks.listInvoices; + }, + getFieldName() { + return "invoices"; + }, + getFieldId() { + return "invoice_id"; + }, + getTsField() { + return "last_modified_time"; + }, + getParams(lastDate) { + return { + last_modified_time: this.formatTimestamp(lastDate), + }; + }, + formatTimestamp(ts) { + if (!ts) { + return undefined; + } + const date = new Date(ts); + const pad = (n) => n.toString().padStart(2, "0"); + const formatted = `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`; + + const offsetMinutes = date.getTimezoneOffset(); + const sign = offsetMinutes > 0 + ? "-" + : "+"; + const absOffset = Math.abs(offsetMinutes); + const offsetHours = pad(Math.floor(absOffset / 60)); + const offsetMins = pad(absOffset % 60); + + return `${formatted}${sign}${offsetHours}${offsetMins}`; + }, + getItemId(item) { + return `${item.invoice_id}${Date.parse(item[this.getTsField()])}`; + }, + getSummary(item) { + const status = item.created_time === item.last_modified_time + ? "New" + : "Updated"; + return `${status} Invoice: ${item.invoice_id}`; + }, + }, + sampleEmit, +}; diff --git a/components/zoho_books/sources/new-or-updated-invoice/test-event.mjs b/components/zoho_books/sources/new-or-updated-invoice/test-event.mjs new file mode 100644 index 0000000000000..a791d1a606b00 --- /dev/null +++ b/components/zoho_books/sources/new-or-updated-invoice/test-event.mjs @@ -0,0 +1,76 @@ +export default { + "ach_payment_initiated": false, + "invoice_id": "4372460000000650034", + "zcrm_potential_id": "", + "customer_id": "4372460000000084001", + "zcrm_potential_name": "", + "customer_name": "", + "company_name": "", + "status": "draft", + "invoice_number": "INV-000002", + "reference_number": "", + "date": "2025-04-09", + "due_date": "2025-04-09", + "due_days": "", + "email": "", + "project_name": "", + "billing_address": { + "address": "", + "street2": "", + "city": "", + "state": "", + "zipcode": "", + "country": "", + "phone": "", + "fax": "", + "attention": "" + }, + "shipping_address": { + "address": "", + "street2": "", + "city": "", + "state": "", + "zipcode": "", + "country": "", + "phone": "", + "fax": "", + "attention": "" + }, + "country": "", + "phone": "", + "created_by": "", + "total": 0, + "balance": 0, + "payment_expected_date": "", + "custom_fields": [], + "custom_field_hash": {}, + "tags": [], + "salesperson_name": "", + "shipping_charge": 0, + "adjustment": 0, + "created_time": "2025-04-09T11:25:54-0400", + "last_modified_time": "2025-04-09T11:25:54-0400", + "updated_time": "2025-04-09T11:25:54-0400", + "is_viewed_by_client": false, + "has_attachment": false, + "client_viewed_time": "", + "is_emailed": false, + "color_code": "", + "current_sub_status_id": "", + "current_sub_status": "draft", + "currency_id": "4372460000000000097", + "schedule_time": "", + "currency_code": "USD", + "currency_symbol": "$", + "template_type": "standard", + "transaction_type": "renewal", + "reminders_sent": 0, + "last_reminder_sent_date": "", + "last_payment_date": "", + "template_id": "4372460000000017001", + "documents": "", + "salesperson_id": "", + "write_off_amount": 0, + "exchange_rate": 1, + "unprocessed_payment_amount": 0 +} \ No newline at end of file diff --git a/components/zoho_books/sources/new-sales-order/new-sales-order.mjs b/components/zoho_books/sources/new-sales-order/new-sales-order.mjs index 5078c8b6074be..2d499af20fd71 100644 --- a/components/zoho_books/sources/new-sales-order/new-sales-order.mjs +++ b/components/zoho_books/sources/new-sales-order/new-sales-order.mjs @@ -6,7 +6,7 @@ export default { key: "zoho_books-new-sales-order", name: "New Sales Order", description: "Emit new event when a new sales order is created.", - version: "0.0.1", + version: "0.0.2", type: "source", dedupe: "unique", methods: { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b92b51b3d7f64..05fc55a57fa13 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8808,8 +8808,7 @@ importers: specifier: ^3.0.0 version: 3.0.3 - components/onehash: - specifiers: {} + components/onehash: {} components/onelogin: {} @@ -10120,8 +10119,7 @@ importers: specifier: ^1.5.1 version: 1.6.6 - components/public_record: - specifiers: {} + components/public_record: {} components/publisherkit: dependencies: @@ -10171,8 +10169,7 @@ importers: specifier: ^1.5.1 version: 1.6.6 - components/pushengage: - specifiers: {} + components/pushengage: {} components/pusher: dependencies: @@ -27765,22 +27762,22 @@ packages: superagent@3.8.1: resolution: {integrity: sha512-VMBFLYgFuRdfeNQSMLbxGSLfmXL/xc+OO+BZp41Za/NRDBet/BNbkRJrYzCUu0u4GU0i/ml2dtT8b9qgkw9z6Q==} engines: {node: '>= 4.0'} - deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@4.1.0: resolution: {integrity: sha512-FT3QLMasz0YyCd4uIi5HNe+3t/onxMyEho7C3PSqmti3Twgy2rXT4fmkTz6wRL6bTF4uzPcfkUCa8u4JWHw8Ag==} engines: {node: '>= 6.0'} - deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@5.3.1: resolution: {integrity: sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==} engines: {node: '>= 7.0.0'} - deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@7.1.6: resolution: {integrity: sha512-gZkVCQR1gy/oUXr+kxJMLDjla434KmSOKbx5iGD30Ql+AkJQ/YlPKECJy2nhqOsHLjGHzoDTXNSjhnvWhzKk7g==} engines: {node: '>=6.4.0 <13 || >=14'} - deprecated: Please downgrade to v7.1.5 if you need IE/ActiveXObject support OR upgrade to v8.0.0 as we no longer support IE and published an incorrect patch version (see https://github.com/visionmedia/superagent/issues/1731) + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net supports-color@2.0.0: resolution: {integrity: sha512-KKNVtd6pCYgPIKU4cp2733HWYCpplQhddZLBUryaAHou723x+FRzQ5Df824Fj+IyyuiQTRoub4SnIFfIcrp70g==}