diff --git a/components/setmoreappointments/actions/create-appointment/create-appointment.mjs b/components/setmoreappointments/actions/create-appointment/create-appointment.mjs index aaefca43b0f69..23c657fd67cdf 100644 --- a/components/setmoreappointments/actions/create-appointment/create-appointment.mjs +++ b/components/setmoreappointments/actions/create-appointment/create-appointment.mjs @@ -5,7 +5,7 @@ export default { key: "setmoreappointments-create-appointment", name: "Create Appointment", description: "Create a new appointment in Setmore Appointments. [See the documentation](https://setmore.docs.apiary.io/#introduction/appointments/create-an-appointment)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { setmore, diff --git a/components/setmoreappointments/actions/create-customer/create-customer.mjs b/components/setmoreappointments/actions/create-customer/create-customer.mjs index 5b69f912f38d4..977879ee5b692 100644 --- a/components/setmoreappointments/actions/create-customer/create-customer.mjs +++ b/components/setmoreappointments/actions/create-customer/create-customer.mjs @@ -4,7 +4,7 @@ export default { key: "setmoreappointments-create-customer", name: "Create Customer", description: "Create a new customer in Setmore Appointments. [See the documentation](https://setmore.docs.apiary.io/#introduction/customers/create-a-customer)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { setmore, diff --git a/components/setmoreappointments/package.json b/components/setmoreappointments/package.json index c45b719705ff2..123b8b84031bd 100644 --- a/components/setmoreappointments/package.json +++ b/components/setmoreappointments/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/setmoreappointments", - "version": "0.1.0", + "version": "0.2.0", "description": "Pipedream Setmore Components", "main": "setmoreappointments.app.mjs", "keywords": [ @@ -13,6 +13,6 @@ "access": "public" }, "dependencies": { - "@pipedream/platform": "^1.5.1" + "@pipedream/platform": "^3.0.3" } } diff --git a/components/setmoreappointments/setmoreappointments.app.mjs b/components/setmoreappointments/setmoreappointments.app.mjs index e6a2cc451fa77..329c14654e296 100644 --- a/components/setmoreappointments/setmoreappointments.app.mjs +++ b/components/setmoreappointments/setmoreappointments.app.mjs @@ -89,6 +89,12 @@ export default { ...args, }); }, + listAppointments(args = {}) { + return this._makeRequest({ + path: "/appointments", + ...args, + }); + }, createCustomer(args = {}) { return this._makeRequest({ path: "/customer/create", @@ -103,5 +109,21 @@ export default { ...args, }); }, + async *paginate({ + resourceFn, + params, + resourceKey, + }) { + do { + const { data } = await resourceFn({ + params, + }); + const items = data[resourceKey]; + for (const item of items) { + yield item; + } + params.cursor = data.cursor; + } while (params.cursor); + }, }, }; diff --git a/components/setmoreappointments/sources/new-appointment-created/new-appointment-created.mjs b/components/setmoreappointments/sources/new-appointment-created/new-appointment-created.mjs new file mode 100644 index 0000000000000..e6acf8404d214 --- /dev/null +++ b/components/setmoreappointments/sources/new-appointment-created/new-appointment-created.mjs @@ -0,0 +1,88 @@ +import setmore from "../../setmoreappointments.app.mjs"; +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; +import sampleEmit from "./test-event.mjs"; + +export default { + key: "setmoreappointments-new-appointment-created", + name: "New Appointment Created", + description: "Emit new event when a new appointment is created in Setmore. [See the documentation](https://setmore.docs.apiary.io/#introduction/appointments/fetch-appointments-by-date-range)", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + setmore, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + staffKey: { + propDefinition: [ + setmore, + "staffKey", + ], + optional: true, + }, + }, + methods: { + _getLastDate() { + return this.db.get("lastDate") || this.getMonthAgo(); + }, + _setLastDate(lastDate) { + this.db.set("lastDate", lastDate); + }, + getMonthAgo() { + const now = new Date(); + const oneMonthAgo = new Date(now); + oneMonthAgo.setMonth(oneMonthAgo.getMonth() - 1); + return this.formatDate(oneMonthAgo); + }, + getToday() { + const now = new Date(); + return this.formatDate(now); + }, + getYearFromNow() { + const now = new Date(); + now.setFullYear(now.getFullYear() + 1); + return this.formatDate(now); + }, + formatDate(date) { + const day = String(date.getDate()).padStart(2, "0"); + const month = String(date.getMonth() + 1).padStart(2, "0"); + const year = date.getFullYear(); + return `${day}-${month}-${year}`; + }, + generateMeta(appointment) { + return { + id: appointment.key, + summary: `New Appointment with Key: ${appointment.key}`, + ts: Date.now(), + }; + }, + }, + async run() { + const startDate = this._getLastDate(); + const endDate = this.getYearFromNow(); + + const appointments = this.setmore.paginate({ + resourceFn: this.setmore.listAppointments, + resourceKey: "appointments", + params: { + startDate, + endDate, + staff_key: this.staffKey, + customerDetails: true, + }, + }); + + for await (const appointment of appointments) { + const meta = this.generateMeta(appointment); + this.$emit(appointment, meta); + } + + this._setLastDate(this.getToday()); + }, + sampleEmit, +}; diff --git a/components/setmoreappointments/sources/new-appointment-created/test-event.mjs b/components/setmoreappointments/sources/new-appointment-created/test-event.mjs new file mode 100644 index 0000000000000..cc39503ea6c42 --- /dev/null +++ b/components/setmoreappointments/sources/new-appointment-created/test-event.mjs @@ -0,0 +1,26 @@ +export default { + "key": "94eb4230-40d5-4651-b59a-0cccb7d9ab4d", + "duration": 15, + "customer": { + "key": "c291f522b55b2e4a4a579300cdd57455a4316873d", + "address": "", + "city": "", + "state": "", + "comment": "test", + "company_key": "c5247961-06b5-46e3-9cdb-e5187a02b67f", + "contact_type": "Customer", + "first_name": "Test", + "last_name": "Customer", + "email_id": "test@test.com", + "postal_code": "", + "image_url": "" + }, + "cost": 0, + "currency": "MXN", + "start_time": "2025-01-16T12:00Z", + "end_time": "2025-01-16T12:15Z", + "staff_key": "r91e68f3227a75e4b066822ea7e649709376a8244-d", + "service_key": "s8353404352c72fdc85ae4ebc786e4e74ec5c4e7c", + "customer_key": "c291f522b55b2e4a4a579300cdd57455a4316873d", + "label": "No Label" +} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 591259caf88fe..be71dd6cc52e2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9390,8 +9390,8 @@ importers: components/setmoreappointments: dependencies: '@pipedream/platform': - specifier: ^1.5.1 - version: 1.6.6 + specifier: ^3.0.3 + version: 3.0.3 components/sevdesk: dependencies: