Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/zoho_books/package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
38 changes: 33 additions & 5 deletions components/zoho_books/sources/common/base.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
});
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion components/zoho_books/sources/new-expense/new-expense.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
};
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
17 changes: 7 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading