From c5b32853d0cc90e1f3e27e98d3995208ae2c66b2 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Thu, 23 May 2024 13:00:34 -0300 Subject: [PATCH 1/5] upbooks init --- .../actions/add-employee/add-employee.mjs | 25 ++++ .../create-expense-category.mjs | 33 +++++ .../record-outward-payment.mjs | 48 +++++++ components/upbooks/package.json | 2 +- .../upbooks/sources/new-data/new-data.mjs | 71 ++++++++++ components/upbooks/upbooks.app.mjs | 129 +++++++++++++++++- 6 files changed, 302 insertions(+), 6 deletions(-) create mode 100644 components/upbooks/actions/add-employee/add-employee.mjs create mode 100644 components/upbooks/actions/create-expense-category/create-expense-category.mjs create mode 100644 components/upbooks/actions/record-outward-payment/record-outward-payment.mjs create mode 100644 components/upbooks/sources/new-data/new-data.mjs diff --git a/components/upbooks/actions/add-employee/add-employee.mjs b/components/upbooks/actions/add-employee/add-employee.mjs new file mode 100644 index 0000000000000..b17f8c039da82 --- /dev/null +++ b/components/upbooks/actions/add-employee/add-employee.mjs @@ -0,0 +1,25 @@ +import upbooks from "../../upbooks.app.mjs"; +import { axios } from "@pipedream/platform"; + +export default { + key: "upbooks-add-employee", + name: "Add New Employee", + description: "Adds a new employee to Upbooks. The 'employee details' prop is required, which should include information like full name, job position, and contact details.", + version: "0.0.{{ts}}", + type: "action", + props: { + upbooks, + employeeDetails: { + type: "string", + label: "Employee Details", + description: "Details of the new employee in JSON format including full name, job position, and contact details.", + }, + }, + async run({ $ }) { + const response = await this.upbooks.addNewEmployee({ + employeeDetails: this.employeeDetails, + }); + $.export("$summary", "Successfully added a new employee"); + return response; + }, +}; diff --git a/components/upbooks/actions/create-expense-category/create-expense-category.mjs b/components/upbooks/actions/create-expense-category/create-expense-category.mjs new file mode 100644 index 0000000000000..ed02e2c204da6 --- /dev/null +++ b/components/upbooks/actions/create-expense-category/create-expense-category.mjs @@ -0,0 +1,33 @@ +import upbooks from "../../upbooks.app.mjs"; + +export default { + key: "upbooks-create-expense-category", + name: "Create Expense Category", + description: "Creates a new expense category in UpBooks.", + version: "0.0.1", + type: "action", + props: { + upbooks, + categoryName: { + propDefinition: [ + upbooks, + "categoryName", + ], + }, + description: { + propDefinition: [ + upbooks, + "description", + ], + optional: true, + }, + }, + async run({ $ }) { + const response = await this.upbooks.createExpenseCategory({ + categoryName: this.categoryName, + description: this.description, + }); + $.export("$summary", `Successfully created new expense category: ${this.categoryName}`); + return response; + }, +}; diff --git a/components/upbooks/actions/record-outward-payment/record-outward-payment.mjs b/components/upbooks/actions/record-outward-payment/record-outward-payment.mjs new file mode 100644 index 0000000000000..6dfea73af7311 --- /dev/null +++ b/components/upbooks/actions/record-outward-payment/record-outward-payment.mjs @@ -0,0 +1,48 @@ +import upbooks from "../../upbooks.app.mjs"; +import { axios } from "@pipedream/platform"; + +export default { + key: "upbooks-record-outward-payment", + name: "Record Outward Payment", + description: "Records an outward payment in UpBooks. [See the documentation](https://upbooks.io/docs/api-usage/authentication)", + version: "0.0.${ts}", + type: "action", + props: { + upbooks, + amount: { + propDefinition: [ + upbooks, + "amount", + ], + }, + recipient: { + propDefinition: [ + upbooks, + "recipient", + ], + }, + date: { + propDefinition: [ + upbooks, + "date", + ], + }, + referenceNumber: { + propDefinition: [ + upbooks, + "referenceNumber", + ], + optional: true, + }, + }, + async run({ $ }) { + const response = await this.upbooks.recordOutwardPayment({ + amount: this.amount, + recipient: this.recipient, + date: this.date, + referenceNumber: this.referenceNumber, + }); + $.export("$summary", `Successfully recorded outward payment to ${this.recipient}`); + return response; + }, +}; diff --git a/components/upbooks/package.json b/components/upbooks/package.json index 13a832d4e6cc7..148bf54f98e69 100644 --- a/components/upbooks/package.json +++ b/components/upbooks/package.json @@ -12,4 +12,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} diff --git a/components/upbooks/sources/new-data/new-data.mjs b/components/upbooks/sources/new-data/new-data.mjs new file mode 100644 index 0000000000000..3f2d30d443512 --- /dev/null +++ b/components/upbooks/sources/new-data/new-data.mjs @@ -0,0 +1,71 @@ +import { axios } from "@pipedream/platform"; +import upbooks from "../../upbooks.app.mjs"; + +export default { + key: "upbooks-new-data", + name: "New Data Available", + description: "Emit new event when fresh data is available for a specific collection.", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + upbooks, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: 60 * 15, // 15 minutes + }, + }, + collectionName: { + propDefinition: [ + upbooks, + "collectionName", + ], + }, + timeInterval: { + propDefinition: [ + upbooks, + "timeInterval", + (c) => ({ + optional: true, + default: 60, + }), // Default to 60 minutes if not specified + ], + }, + }, + hooks: { + async deploy() { + // Fetch historical data on deploy + await this.fetchAndEmitData(true); + }, + }, + methods: { + async fetchAndEmitData(isDeploy = false) { + const lastEmittedTimestamp = isDeploy + ? 0 + : this.db.get("lastEmittedTimestamp") || Date.now() - (this.timeInterval * 60 * 1000); + const currentTime = Date.now(); + const newEvents = await this.upbooks.emitNewDataEvent({ + collectionName: this.collectionName, + timeInterval: this.timeInterval, + }); + + newEvents.forEach((event) => { + const eventTimestamp = Date.parse(event.timestamp); + if (eventTimestamp > lastEmittedTimestamp) { + this.$emit(event, { + id: event.id || `${eventTimestamp}-${Math.random()}`, + summary: `New data in ${this.collectionName}`, + ts: eventTimestamp, + }); + } + }); + + this.db.set("lastEmittedTimestamp", currentTime); + }, + }, + async run() { + await this.fetchAndEmitData(); + }, +}; diff --git a/components/upbooks/upbooks.app.mjs b/components/upbooks/upbooks.app.mjs index 29eb7cf9bf334..a6762aaa90409 100644 --- a/components/upbooks/upbooks.app.mjs +++ b/components/upbooks/upbooks.app.mjs @@ -1,11 +1,130 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "upbooks", - propDefinitions: {}, + propDefinitions: { + collectionName: { + type: "string", + label: "Collection Name", + description: "The name of the collection to monitor for new data.", + }, + timeInterval: { + type: "integer", + label: "Time Interval", + description: "Time interval to look back for new data (in minutes).", + optional: true, + }, + amount: { + type: "integer", + label: "Amount", + description: "The amount of the outward payment.", + }, + recipient: { + type: "string", + label: "Recipient", + description: "The recipient of the payment.", + }, + date: { + type: "string", + label: "Date", + description: "The date of the payment.", + }, + referenceNumber: { + type: "string", + label: "Reference Number", + description: "An optional reference number for the payment.", + optional: true, + }, + categoryName: { + type: "string", + label: "Category Name", + description: "The name of the new expense category.", + }, + description: { + type: "string", + label: "Description", + description: "A description for the new expense category.", + optional: true, + }, + employeeDetails: { + type: "string", + label: "Employee Details", + description: "Details of the new employee in JSON format including full name, job position, and contact details.", + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.upbooks.io/v1"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + method = "GET", + path, + data, + params, + headers, + ...otherOpts + } = opts; + return axios($, { + method, + url: this._baseUrl() + path, + headers: { + Authorization: `Bearer ${this.$auth.oauth_access_token}`, + ...headers, + }, + data, + params, + ...otherOpts, + }); + }, + async emitNewDataEvent({ + collectionName, timeInterval, + }) { + return this._makeRequest({ + method: "POST", + path: "/events/new-data", + data: { + collectionName, + timeInterval, + }, + }); + }, + async recordOutwardPayment({ + amount, recipient, date, referenceNumber, + }) { + return this._makeRequest({ + method: "POST", + path: "/payments/outward", + data: { + amount, + recipient, + date, + referenceNumber, + }, + }); + }, + async createExpenseCategory({ + categoryName, description, + }) { + return this._makeRequest({ + method: "POST", + path: "/expense-categories", + data: { + categoryName, + description, + }, + }); + }, + async addNewEmployee({ employeeDetails }) { + const details = JSON.parse(employeeDetails); + return this._makeRequest({ + method: "POST", + path: "/employees", + data: details, + }); }, }, -}; \ No newline at end of file + version: "0.0.1", +}; From 77f92bf26ed24ffcf2da9e34e9175387165211cb Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Fri, 24 May 2024 18:41:19 -0300 Subject: [PATCH 2/5] [Components] upbooks #12071 Sources - New Data Actions - Add Outward Payment - Create Expense Category - Add Employee --- .../actions/add-employee/add-employee.mjs | 111 ++++++++- .../create-expense-category.mjs | 50 ++-- .../record-outward-payment.mjs | 102 ++++++-- components/upbooks/common/utils.mjs | 24 ++ components/upbooks/package.json | 6 +- .../upbooks/sources/new-data/new-data.mjs | 76 +++--- .../upbooks/sources/new-data/test-event.mjs | 31 +++ components/upbooks/upbooks.app.mjs | 219 ++++++++++-------- 8 files changed, 438 insertions(+), 181 deletions(-) create mode 100644 components/upbooks/common/utils.mjs create mode 100644 components/upbooks/sources/new-data/test-event.mjs diff --git a/components/upbooks/actions/add-employee/add-employee.mjs b/components/upbooks/actions/add-employee/add-employee.mjs index b17f8c039da82..4ba176e10ee04 100644 --- a/components/upbooks/actions/add-employee/add-employee.mjs +++ b/components/upbooks/actions/add-employee/add-employee.mjs @@ -1,25 +1,120 @@ import upbooks from "../../upbooks.app.mjs"; -import { axios } from "@pipedream/platform"; export default { key: "upbooks-add-employee", name: "Add New Employee", - description: "Adds a new employee to Upbooks. The 'employee details' prop is required, which should include information like full name, job position, and contact details.", - version: "0.0.{{ts}}", + description: "Adds a new employee to Upbooks. [See the documentation](https://www.postman.com/scrrum/workspace/upbooks-io/request/13284127-a51a907a-0648-477d-96f6-f5a9e79262fd)", + version: "0.0.1", type: "action", props: { upbooks, - employeeDetails: { + name: { type: "string", - label: "Employee Details", - description: "Details of the new employee in JSON format including full name, job position, and contact details.", + label: "Name", + description: "Full name of the employee.", + }, + employeeNumber: { + type: "string", + label: "Employee Number", + description: "The identification number of the employee.", + optional: true, + }, + type: { + type: "string", + label: "Type", + description: "The employee's type.", + options: [ + "full-time", + "part-time", + ], + optional: true, + }, + email: { + type: "string", + label: "Email", + description: "The employee's email.", + optional: true, + }, + phone: { + type: "string", + label: "Phone", + description: "The employee's phone.", + optional: true, + }, + dob: { + type: "string", + label: "DOB", + description: "The employee's date of birth. Format: YYY-MM-DD", + optional: true, + }, + dateOfJoining: { + type: "string", + label: "Date Of Joining", + description: "The employee's start date. Format: YYY-MM-DDTHH:MM:SSZ", + optional: true, + }, + dateOfLeaving: { + type: "string", + label: "Date Of Leaving", + description: "The employee's end date. Format: YYY-MM-DDTHH:MM:SSZ", + optional: true, + }, + ctc: { + type: "integer", + label: "CTC", + description: "Cost to company in cents.", + }, + salaryComponentId: { + propDefinition: [ + upbooks, + "salaryComponentId", + ], + }, + designation: { + type: "string", + label: "Designation", + description: "In which position the employee will work.", + optional: true, + }, + role: { + type: "string", + label: "Role", + description: "The identification of the employee's role.", + options: [ + "staff", + "admin", + "others", + ], + optional: true, }, }, async run({ $ }) { const response = await this.upbooks.addNewEmployee({ - employeeDetails: this.employeeDetails, + $, + data: { + name: this.name, + employeeNumber: this.employeeNumber, + type: this.type, + email: this.email, + phone: this.phone, + dob: this.dob, + employment: [ + { + dateOfJoining: this.dateOfJoining, + dateOfLeaving: this.dateOfLeaving, + salary: { + ctc: (this.ctc / 100).toFixed(2), + componentGroup: { + id: this.salaryComponentId, + }, + }, + designation: this.designation, + role: this.role, + }, + ], + }, }); - $.export("$summary", "Successfully added a new employee"); + $.export("$summary", `Successfully added a new employee with Id: ${response.data._id}`); return response; }, }; diff --git a/components/upbooks/actions/create-expense-category/create-expense-category.mjs b/components/upbooks/actions/create-expense-category/create-expense-category.mjs index ed02e2c204da6..7b2234c62cd20 100644 --- a/components/upbooks/actions/create-expense-category/create-expense-category.mjs +++ b/components/upbooks/actions/create-expense-category/create-expense-category.mjs @@ -3,31 +3,53 @@ import upbooks from "../../upbooks.app.mjs"; export default { key: "upbooks-create-expense-category", name: "Create Expense Category", - description: "Creates a new expense category in UpBooks.", + description: "Creates a new expense category in UpBooks. [See the documentation](https://www.postman.com/scrrum/workspace/upbooks-io/request/13284127-a07ae2fc-f712-42aa-bcf5-6ce63c7a0929)", version: "0.0.1", type: "action", props: { upbooks, - categoryName: { - propDefinition: [ - upbooks, - "categoryName", - ], + title: { + type: "string", + label: "Title", + description: "The expense category's title.", }, - description: { - propDefinition: [ - upbooks, - "description", + subCategory: { + type: "string", + label: "Sub Category", + description: "subCategory", + options: [ + { + label: "Operating Expense", + value: "operating-expense", + }, + { + label: "Non Operating Expense", + value: "non-operating-expense", + }, + { + label: "Cost Of Goods Sold", + value: "cost-of-goods-sold", + }, ], + }, + summary: { + type: "string", + label: "Summary", + description: "summary", optional: true, }, }, async run({ $ }) { - const response = await this.upbooks.createExpenseCategory({ - categoryName: this.categoryName, - description: this.description, + const { + upbooks, + ...data + } = this; + + const response = await upbooks.createExpenseCategory({ + $, + data, }); - $.export("$summary", `Successfully created new expense category: ${this.categoryName}`); + $.export("$summary", `Successfully created new expense category with Id: ${response.data._id}`); return response; }, }; diff --git a/components/upbooks/actions/record-outward-payment/record-outward-payment.mjs b/components/upbooks/actions/record-outward-payment/record-outward-payment.mjs index 6dfea73af7311..69b064f344d15 100644 --- a/components/upbooks/actions/record-outward-payment/record-outward-payment.mjs +++ b/components/upbooks/actions/record-outward-payment/record-outward-payment.mjs @@ -1,48 +1,108 @@ +import { parseObject } from "../../common/utils.mjs"; import upbooks from "../../upbooks.app.mjs"; -import { axios } from "@pipedream/platform"; export default { key: "upbooks-record-outward-payment", name: "Record Outward Payment", - description: "Records an outward payment in UpBooks. [See the documentation](https://upbooks.io/docs/api-usage/authentication)", - version: "0.0.${ts}", + description: "Records an outward payment in UpBooks. [See the documentation](https://www.postman.com/scrrum/workspace/upbooks-io/request/13284127-3fc82d7a-2173-4b3a-a8ec-4c812c928810)", + version: "0.0.1", type: "action", props: { upbooks, - amount: { - propDefinition: [ - upbooks, - "amount", + mode: { + type: "string", + label: "Mode", + description: "The outward payment mode.", + options: [ + { + label: "Cash", + value: "cash", + }, + { + label: "Cheque", + value: "cheque", + }, + { + label: "Neft", + value: "neft", + }, + { + label: "Imps", + value: "imps", + }, + { + label: "Wire Transfer", + value: "wire transfer", + }, ], }, - recipient: { - propDefinition: [ - upbooks, - "recipient", - ], + amount: { + type: "string", + label: "Amount", + description: "The outwart payment amount in cents.", }, date: { + type: "string", + label: "Date", + description: "The date of the outward payment. Format: YYYY-MM-DD", + }, + expenseIds: { propDefinition: [ upbooks, - "date", + "expenseIds", ], }, - referenceNumber: { + account: { propDefinition: [ upbooks, - "referenceNumber", + "accountId", + ], + }, + currency: { + type: "string", + label: "Currency", + description: "The currency of the outward payment.", + withLabel: true, + options: [ + { + label: "Indian Rupees", + value: "INR", + }, + { + label: "US Dollar", + value: "USD", + }, + { + label: "Euro", + value: "EUR", + }, + { + label: "Australian Dollar", + value: "AUD", + }, + { + label: "Emirati Dirham", + value: "AED", + }, ], - optional: true, }, }, async run({ $ }) { const response = await this.upbooks.recordOutwardPayment({ - amount: this.amount, - recipient: this.recipient, - date: this.date, - referenceNumber: this.referenceNumber, + $, + data: { + mode: this.mode, + amount: (this.amount / 100).toFixed(2), + date: this.date, + expenseIds: parseObject(this.expenseIds), + accountId: this.account, + currency: { + name: this.currency.label, + symbol: this.currency.value, + }, + }, }); - $.export("$summary", `Successfully recorded outward payment to ${this.recipient}`); + $.export("$summary", `Successfully recorded outward payment with Id: ${response.data._id}`); return response; }, }; diff --git a/components/upbooks/common/utils.mjs b/components/upbooks/common/utils.mjs new file mode 100644 index 0000000000000..dcc9cc61f6f41 --- /dev/null +++ b/components/upbooks/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/upbooks/package.json b/components/upbooks/package.json index 148bf54f98e69..88d23e10777c5 100644 --- a/components/upbooks/package.json +++ b/components/upbooks/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/upbooks", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream UpBooks Components", "main": "upbooks.app.mjs", "keywords": [ @@ -11,5 +11,9 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^1.6.5" } } + diff --git a/components/upbooks/sources/new-data/new-data.mjs b/components/upbooks/sources/new-data/new-data.mjs index 3f2d30d443512..9a8c97dbf48ed 100644 --- a/components/upbooks/sources/new-data/new-data.mjs +++ b/components/upbooks/sources/new-data/new-data.mjs @@ -1,5 +1,6 @@ -import { axios } from "@pipedream/platform"; +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; import upbooks from "../../upbooks.app.mjs"; +import sampleEmit from "./test-event.mjs"; export default { key: "upbooks-new-data", @@ -14,58 +15,47 @@ export default { timer: { type: "$.interface.timer", default: { - intervalSeconds: 60 * 15, // 15 minutes + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, }, }, - collectionName: { - propDefinition: [ - upbooks, - "collectionName", - ], + }, + methods: { + _getLastDate() { + return this.db.get("lastDate") || "1970-01-01T00:00:00Z"; }, - timeInterval: { - propDefinition: [ - upbooks, - "timeInterval", - (c) => ({ - optional: true, - default: 60, - }), // Default to 60 minutes if not specified - ], + _setLastDate(created) { + this.db.set("lastDate", created); }, - }, - hooks: { - async deploy() { - // Fetch historical data on deploy - await this.fetchAndEmitData(true); + generateMeta(item) { + return { + id: item._id, + summary: `New ${item.title}`, + ts: item.occurredAt, + }; }, - }, - methods: { - async fetchAndEmitData(isDeploy = false) { - const lastEmittedTimestamp = isDeploy - ? 0 - : this.db.get("lastEmittedTimestamp") || Date.now() - (this.timeInterval * 60 * 1000); - const currentTime = Date.now(); - const newEvents = await this.upbooks.emitNewDataEvent({ - collectionName: this.collectionName, - timeInterval: this.timeInterval, + async startEvent(maxResults = 0) { + const lastDate = this._getLastDate(); + const { data } = await this.upbooks.listActivities({ + params: { + fromDate: lastDate, + }, }); - newEvents.forEach((event) => { - const eventTimestamp = Date.parse(event.timestamp); - if (eventTimestamp > lastEmittedTimestamp) { - this.$emit(event, { - id: event.id || `${eventTimestamp}-${Math.random()}`, - summary: `New data in ${this.collectionName}`, - ts: eventTimestamp, - }); - } - }); + if (maxResults && maxResults.length > maxResults) maxResults.length = maxResults; + if (data.length) this._setLastDate(data[0].occurredAt); - this.db.set("lastEmittedTimestamp", currentTime); + for (const item of data.reverse()) { + this.$emit(item, this.generateMeta(item)); + } + }, + }, + hooks: { + async deploy() { + await this.startEvent(25); }, }, async run() { - await this.fetchAndEmitData(); + await this.startEvent(); }, + sampleEmit, }; diff --git a/components/upbooks/sources/new-data/test-event.mjs b/components/upbooks/sources/new-data/test-event.mjs new file mode 100644 index 0000000000000..d0ab64f2805c9 --- /dev/null +++ b/components/upbooks/sources/new-data/test-event.mjs @@ -0,0 +1,31 @@ +export default { + "_id":"0d6f5e4038f7eb902bfa651b", + "user":{ + "_id":"0d6f5e4038f7eb902bfa651b", + "id":"0d6f5e4038f7eb902bfa651b", + "role":"organization-admin", + "name":"Sergio Wong", + "email":"sergio@pipekit.pro", + "ipAddress":"12.345.678.901", + }, + "organization":{ + "_id":"0d6f5e4038f7eb902bfa651b", + "organizationId":"123456" + }, + "occurredAt":"2024-05-24T21:15:59.347Z", + "eventCode":"EV-1234", + "eventCategory":"Outward-Payment", + "actionType":"Create", + "initiator":"User", + "title":"Outward Payment Recorded", + "body":"User recorded outward payment OP12345 of amount 1.00 USD", + "additional":{ + "link":{ + "text":"0d6f5e4038f7eb902bfa651b", + "url":"outward-payment/view/0d6f5e4038f7eb902bfa651b" + } + }, + "createdAt":"2024-05-24T21:15:59.356Z", + "updatedAt":"2024-05-24T21:15:59.356Z", + "__v":0 +} \ No newline at end of file diff --git a/components/upbooks/upbooks.app.mjs b/components/upbooks/upbooks.app.mjs index a6762aaa90409..ad657f1048feb 100644 --- a/components/upbooks/upbooks.app.mjs +++ b/components/upbooks/upbooks.app.mjs @@ -4,127 +4,158 @@ export default { type: "app", app: "upbooks", propDefinitions: { - collectionName: { + salaryComponentId: { type: "string", - label: "Collection Name", - description: "The name of the collection to monitor for new data.", - }, - timeInterval: { - type: "integer", - label: "Time Interval", - description: "Time interval to look back for new data (in minutes).", - optional: true, - }, - amount: { - type: "integer", - label: "Amount", - description: "The amount of the outward payment.", - }, - recipient: { - type: "string", - label: "Recipient", - description: "The recipient of the payment.", - }, - date: { - type: "string", - label: "Date", - description: "The date of the payment.", - }, - referenceNumber: { - type: "string", - label: "Reference Number", - description: "An optional reference number for the payment.", - optional: true, - }, - categoryName: { - type: "string", - label: "Category Name", - description: "The name of the new expense category.", + label: "Salary Component Id", + description: "The identification of the salary component.", + async options({ page }) { + const { data } = await this.listSalaryComponents({ + params: { + page, + }, + }); + + return data.map(({ + _id: value, groupName: label, + }) => ({ + label, + value, + })); + }, }, - description: { - type: "string", - label: "Description", - description: "A description for the new expense category.", - optional: true, + expenseIds: { + type: "string[]", + label: "Expense Ids", + description: "The identification of the expense.", + async options({ page }) { + const { data } = await this.listExpenses({ + params: { + page, + }, + }); + + return data.map(({ + _id: value, title: label, + }) => ({ + label, + value, + })); + }, }, - employeeDetails: { + accountId: { type: "string", - label: "Employee Details", - description: "Details of the new employee in JSON format including full name, job position, and contact details.", + label: "Account Id", + description: "The identification of the account.", + async options({ page }) { + const { data } = await this.listAccounts({ + params: { + page, + }, + }); + + return data.map(({ + _id: value, title, category, + }) => ({ + label: `${title} (${category.charAt(0).toUpperCase() + category.slice(1)})`, + value, + })); + }, }, }, methods: { _baseUrl() { - return "https://api.upbooks.io/v1"; + return "https://api.upbooks.io/api/v1"; }, - async _makeRequest(opts = {}) { - const { - $ = this, - method = "GET", - path, - data, - params, - headers, - ...otherOpts - } = opts; + _headers() { + return { + "Authorization": `Bearer ${this.$auth.oauth_access_token}`, + "API-KEY": `${this.$auth.api_key}`, + "Organization-ID": `${this.$auth.organization_id}`, + }; + }, + _makeRequest({ + $ = this, path, ...opts + }) { return axios($, { - method, url: this._baseUrl() + path, - headers: { - Authorization: `Bearer ${this.$auth.oauth_access_token}`, - ...headers, - }, - data, - params, - ...otherOpts, + headers: this._headers(), + ...opts, }); }, - async emitNewDataEvent({ - collectionName, timeInterval, - }) { + listAccounts(opts = {}) { return this._makeRequest({ - method: "POST", - path: "/events/new-data", - data: { - collectionName, - timeInterval, - }, + path: "/account", + ...opts, }); }, - async recordOutwardPayment({ - amount, recipient, date, referenceNumber, - }) { + listActivities(opts = {}) { + return this._makeRequest({ + path: "/activity-log/all", + ...opts, + }); + }, + listExpenses(opts = {}) { + return this._makeRequest({ + path: "/expense", + ...opts, + }); + }, + listSalaryComponents(opts = {}) { + return this._makeRequest({ + path: "/salary-component", + ...opts, + }); + }, + addNewEmployee(opts = {}) { return this._makeRequest({ method: "POST", - path: "/payments/outward", - data: { - amount, - recipient, - date, - referenceNumber, - }, + path: "/employee", + ...opts, }); }, - async createExpenseCategory({ - categoryName, description, - }) { + createExpenseCategory(opts = {}) { return this._makeRequest({ method: "POST", - path: "/expense-categories", - data: { - categoryName, - description, - }, + path: "/expense-category", + ...opts, }); }, - async addNewEmployee({ employeeDetails }) { - const details = JSON.parse(employeeDetails); + recordOutwardPayment(opts = {}) { return this._makeRequest({ method: "POST", - path: "/employees", - data: details, + path: "/outward-payment", + ...opts, }); }, + async *paginate({ + fn, params = {}, maxResults = null, ...opts + }) { + let hasMore = false; + let count = 0; + let page = 0; + + do { + params.page = ++page; + const { + data, + meta: { + current_page, last_page, + }, + } = await fn({ + params, + ...opts, + }); + for (const d of data) { + yield d; + + if (maxResults && ++count === maxResults) { + return count; + } + } + + hasMore = !(current_page == last_page); + + } while (hasMore); + }, }, - version: "0.0.1", }; From 47e3182117c7e758c5e74e6fb2c5dae4f734e148 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Fri, 24 May 2024 18:43:20 -0300 Subject: [PATCH 3/5] pnpm update --- pnpm-lock.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7de026c90dadb..64607dda3a1a8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9196,7 +9196,10 @@ importers: '@pipedream/platform': 1.6.5 components/upbooks: - specifiers: {} + specifiers: + '@pipedream/platform': ^1.6.5 + dependencies: + '@pipedream/platform': 1.6.5 components/updown_io: specifiers: From 3ccf7d79a3daec6246656b12c8f9536068f7eb7d Mon Sep 17 00:00:00 2001 From: Leo Vu <18277920+vunguyenhung@users.noreply.github.com> Date: Thu, 30 May 2024 10:22:50 +0700 Subject: [PATCH 4/5] Fix prop description --- components/upbooks/actions/add-employee/add-employee.mjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/upbooks/actions/add-employee/add-employee.mjs b/components/upbooks/actions/add-employee/add-employee.mjs index 4ba176e10ee04..3d7e99fd1006b 100644 --- a/components/upbooks/actions/add-employee/add-employee.mjs +++ b/components/upbooks/actions/add-employee/add-employee.mjs @@ -44,19 +44,19 @@ export default { dob: { type: "string", label: "DOB", - description: "The employee's date of birth. Format: YYY-MM-DD", + description: "The employee's date of birth. Format: YYYY-MM-DD", optional: true, }, dateOfJoining: { type: "string", label: "Date Of Joining", - description: "The employee's start date. Format: YYY-MM-DDTHH:MM:SSZ", + description: "The employee's start date. Format: YYYY-MM-DDTHH:MM:SSZ", optional: true, }, dateOfLeaving: { type: "string", label: "Date Of Leaving", - description: "The employee's end date. Format: YYY-MM-DDTHH:MM:SSZ", + description: "The employee's end date. Format: YYYY-MM-DDTHH:MM:SSZ", optional: true, }, ctc: { From 90198cf8fdef99ced79c110c882e0a142359552d Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Fri, 31 May 2024 12:07:52 -0300 Subject: [PATCH 5/5] some adjusts --- .../record-outward-payment.mjs | 30 ++++--------------- components/upbooks/common/constants.mjs | 22 ++++++++++++++ 2 files changed, 27 insertions(+), 25 deletions(-) create mode 100644 components/upbooks/common/constants.mjs diff --git a/components/upbooks/actions/record-outward-payment/record-outward-payment.mjs b/components/upbooks/actions/record-outward-payment/record-outward-payment.mjs index 69b064f344d15..0ce4e31764532 100644 --- a/components/upbooks/actions/record-outward-payment/record-outward-payment.mjs +++ b/components/upbooks/actions/record-outward-payment/record-outward-payment.mjs @@ -1,3 +1,4 @@ +import { CURRENCY_OPTIONS } from "../../common/constants.mjs"; import { parseObject } from "../../common/utils.mjs"; import upbooks from "../../upbooks.app.mjs"; @@ -62,32 +63,11 @@ export default { type: "string", label: "Currency", description: "The currency of the outward payment.", - withLabel: true, - options: [ - { - label: "Indian Rupees", - value: "INR", - }, - { - label: "US Dollar", - value: "USD", - }, - { - label: "Euro", - value: "EUR", - }, - { - label: "Australian Dollar", - value: "AUD", - }, - { - label: "Emirati Dirham", - value: "AED", - }, - ], + options: CURRENCY_OPTIONS, }, }, async run({ $ }) { + const currency = CURRENCY_OPTIONS.filter((item) => item.value === this.currency)[0]; const response = await this.upbooks.recordOutwardPayment({ $, data: { @@ -97,8 +77,8 @@ export default { expenseIds: parseObject(this.expenseIds), accountId: this.account, currency: { - name: this.currency.label, - symbol: this.currency.value, + name: currency.label, + symbol: currency.value, }, }, }); diff --git a/components/upbooks/common/constants.mjs b/components/upbooks/common/constants.mjs new file mode 100644 index 0000000000000..46fd49769bbcd --- /dev/null +++ b/components/upbooks/common/constants.mjs @@ -0,0 +1,22 @@ +export const CURRENCY_OPTIONS = [ + { + label: "Indian Rupees", + value: "INR", + }, + { + label: "US Dollar", + value: "USD", + }, + { + label: "Euro", + value: "EUR", + }, + { + label: "Australian Dollar", + value: "AUD", + }, + { + label: "Emirati Dirham", + value: "AED", + }, +];