From ff5366991dd8293a11e90e87d538d7574429bb36 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Mon, 7 Oct 2024 15:10:49 -0400 Subject: [PATCH 1/3] init --- .../actions/get-ref-data/get-ref-data.mjs | 52 +++++++++++++ .../actions/get-settings/get-settings.mjs | 17 +++++ .../cliento/actions/get-slots/get-slots.mjs | 38 ++++++++++ components/cliento/cliento.app.mjs | 74 +++++++++++++++++-- 4 files changed, 176 insertions(+), 5 deletions(-) create mode 100644 components/cliento/actions/get-ref-data/get-ref-data.mjs create mode 100644 components/cliento/actions/get-settings/get-settings.mjs create mode 100644 components/cliento/actions/get-slots/get-slots.mjs diff --git a/components/cliento/actions/get-ref-data/get-ref-data.mjs b/components/cliento/actions/get-ref-data/get-ref-data.mjs new file mode 100644 index 0000000000000..600e296db1643 --- /dev/null +++ b/components/cliento/actions/get-ref-data/get-ref-data.mjs @@ -0,0 +1,52 @@ +import cliento from "../../cliento.app.mjs"; + +export default { + key: "cliento-get-ref-data", + name: "Get Reference Data", + description: "Fetch services, resources and mappings for the booking widget", + version: "0.0.{{ts}}", + type: "action", + props: { + cliento, + fromDate: { + propDefinition: [ + cliento, + "fromDate", + ], + }, + toDate: { + propDefinition: [ + cliento, + "toDate", + ], + }, + resourceIds: { + propDefinition: [ + cliento, + "resourceIds", + ], + }, + serviceIds: { + propDefinition: [ + cliento, + "serviceIds", + ], + }, + }, + async run({ $ }) { + const settings = await this.cliento.fetchSettings(); + const refData = await this.cliento.fetchRefData(); + const slots = await this.cliento.fetchSlots({ + fromDate: this.fromDate, + toDate: this.toDate, + resourceIds: this.resourceIds, + serviceIds: this.serviceIds, + }); + $.export("$summary", "Successfully fetched reference data"); + return { + settings, + refData, + slots, + }; + }, +}; diff --git a/components/cliento/actions/get-settings/get-settings.mjs b/components/cliento/actions/get-settings/get-settings.mjs new file mode 100644 index 0000000000000..3fa511f5062be --- /dev/null +++ b/components/cliento/actions/get-settings/get-settings.mjs @@ -0,0 +1,17 @@ +import cliento from "../../cliento.app.mjs"; + +export default { + key: "cliento-get-settings", + name: "Fetch Settings", + description: "Fetch settings and features for the booking widget", + version: "0.0.{{ts}}", + type: "action", + props: { + cliento, + }, + async run({ $ }) { + const response = await this.cliento.fetchSettings(); + $.export("$summary", "Successfully fetched settings"); + return response; + }, +}; diff --git a/components/cliento/actions/get-slots/get-slots.mjs b/components/cliento/actions/get-slots/get-slots.mjs new file mode 100644 index 0000000000000..443a6a926c5ef --- /dev/null +++ b/components/cliento/actions/get-slots/get-slots.mjs @@ -0,0 +1,38 @@ +import cliento from "../../cliento.app.mjs"; + +export default { + key: "cliento-get-slots", + name: "Get Slots", + description: "Fetch available slots for the given service, resource and dates", + version: "0.0.{{ts}}", + type: "action", + props: { + cliento, + fromDate: { + ...cliento.propDefinitions.fromDate, + description: "The start date for the booking period (format: YYYY-MM-DD)", + }, + toDate: { + ...cliento.propDefinitions.toDate, + description: "The end date for the booking period (format: YYYY-MM-DD)", + }, + resourceIds: { + ...cliento.propDefinitions.resourceIds, + description: "The IDs of the resources for the booking", + }, + serviceIds: { + ...cliento.propDefinitions.serviceIds, + description: "The IDs of the services for the booking", + }, + }, + async run({ $ }) { + const slots = await this.cliento.fetchSlots({ + fromDate: this.fromDate, + toDate: this.toDate, + resourceIds: this.resourceIds, + serviceIds: this.serviceIds, + }); + $.export("$summary", `Successfully fetched ${slots.length} slots`); + return slots; + }, +}; diff --git a/components/cliento/cliento.app.mjs b/components/cliento/cliento.app.mjs index 4b136a1b2203b..70c983fbfe804 100644 --- a/components/cliento/cliento.app.mjs +++ b/components/cliento/cliento.app.mjs @@ -1,11 +1,75 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "cliento", - propDefinitions: {}, + propDefinitions: { + fromDate: { + type: "string", + label: "From Date", + description: "The start date for the booking period (format: YYYY-MM-DD)", + }, + toDate: { + type: "string", + label: "To Date", + description: "The end date for the booking period (format: YYYY-MM-DD)", + }, + resourceIds: { + type: "string[]", + label: "Resource IDs", + description: "The IDs of the resources for the booking", + }, + serviceIds: { + type: "string[]", + label: "Service IDs", + description: "The IDs of the services for the booking", + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.cliento.com"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + method = "GET", + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + method, + url: this._baseUrl() + path, + headers: { + ...headers, + "Authorization": `Bearer ${this.$auth.oauth_access_token}`, + }, + }); + }, + async fetchSettings() { + return this._makeRequest({ + path: "/settings/", + }); + }, + async fetchRefData() { + return this._makeRequest({ + path: "/ref-data/", + }); + }, + async fetchSlots({ + fromDate, toDate, resourceIds, serviceIds, + }) { + const params = { + fromDate, + toDate, + resIds: resourceIds.join(","), + srvIds: serviceIds.join(","), + }; + return this._makeRequest({ + path: "/resources/slots", + params, + }); }, }, -}; \ No newline at end of file +}; From 539ae0cbef5bff6342ceb1cd5b55253cab254a99 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Mon, 7 Oct 2024 15:36:52 -0400 Subject: [PATCH 2/3] new components --- .../actions/get-ref-data/get-ref-data.mjs | 43 ++-------------- .../actions/get-settings/get-settings.mjs | 8 +-- .../cliento/actions/get-slots/get-slots.mjs | 49 ++++++++++++------- components/cliento/cliento.app.mjs | 48 ++++++++++-------- components/cliento/package.json | 7 ++- 5 files changed, 75 insertions(+), 80 deletions(-) diff --git a/components/cliento/actions/get-ref-data/get-ref-data.mjs b/components/cliento/actions/get-ref-data/get-ref-data.mjs index 600e296db1643..393af01511ff5 100644 --- a/components/cliento/actions/get-ref-data/get-ref-data.mjs +++ b/components/cliento/actions/get-ref-data/get-ref-data.mjs @@ -3,50 +3,17 @@ import cliento from "../../cliento.app.mjs"; export default { key: "cliento-get-ref-data", name: "Get Reference Data", - description: "Fetch services, resources and mappings for the booking widget", - version: "0.0.{{ts}}", + description: "Fetch services, resources and mappings for the booking widget. [See the documentation](https://developers.cliento.com/docs/rest-api#fetch-ref-data)", + version: "0.0.1", type: "action", props: { cliento, - fromDate: { - propDefinition: [ - cliento, - "fromDate", - ], - }, - toDate: { - propDefinition: [ - cliento, - "toDate", - ], - }, - resourceIds: { - propDefinition: [ - cliento, - "resourceIds", - ], - }, - serviceIds: { - propDefinition: [ - cliento, - "serviceIds", - ], - }, }, async run({ $ }) { - const settings = await this.cliento.fetchSettings(); - const refData = await this.cliento.fetchRefData(); - const slots = await this.cliento.fetchSlots({ - fromDate: this.fromDate, - toDate: this.toDate, - resourceIds: this.resourceIds, - serviceIds: this.serviceIds, + const response = await this.cliento.fetchRefData({ + $, }); $.export("$summary", "Successfully fetched reference data"); - return { - settings, - refData, - slots, - }; + return response; }, }; diff --git a/components/cliento/actions/get-settings/get-settings.mjs b/components/cliento/actions/get-settings/get-settings.mjs index 3fa511f5062be..9032bb3be361b 100644 --- a/components/cliento/actions/get-settings/get-settings.mjs +++ b/components/cliento/actions/get-settings/get-settings.mjs @@ -3,14 +3,16 @@ import cliento from "../../cliento.app.mjs"; export default { key: "cliento-get-settings", name: "Fetch Settings", - description: "Fetch settings and features for the booking widget", - version: "0.0.{{ts}}", + description: "Fetch settings and features for the booking widget. [See the documentation](https://developers.cliento.com/docs/rest-api#fetch-settings)", + version: "0.0.1", type: "action", props: { cliento, }, async run({ $ }) { - const response = await this.cliento.fetchSettings(); + const response = await this.cliento.fetchSettings({ + $, + }); $.export("$summary", "Successfully fetched settings"); return response; }, diff --git a/components/cliento/actions/get-slots/get-slots.mjs b/components/cliento/actions/get-slots/get-slots.mjs index 443a6a926c5ef..88fbc1845b48c 100644 --- a/components/cliento/actions/get-slots/get-slots.mjs +++ b/components/cliento/actions/get-slots/get-slots.mjs @@ -3,36 +3,51 @@ import cliento from "../../cliento.app.mjs"; export default { key: "cliento-get-slots", name: "Get Slots", - description: "Fetch available slots for the given service, resource and dates", - version: "0.0.{{ts}}", + description: "Fetch available slots for the given service, resource and dates. [See the documentation](https://developers.cliento.com/docs/rest-api#fetch-slots)", + version: "0.0.1", type: "action", props: { cliento, fromDate: { - ...cliento.propDefinitions.fromDate, - description: "The start date for the booking period (format: YYYY-MM-DD)", + propDefinition: [ + cliento, + "fromDate", + ], }, toDate: { - ...cliento.propDefinitions.toDate, - description: "The end date for the booking period (format: YYYY-MM-DD)", + propDefinition: [ + cliento, + "toDate", + ], }, resourceIds: { - ...cliento.propDefinitions.resourceIds, - description: "The IDs of the resources for the booking", + propDefinition: [ + cliento, + "resourceIds", + ], }, serviceIds: { - ...cliento.propDefinitions.serviceIds, - description: "The IDs of the services for the booking", + propDefinition: [ + cliento, + "serviceIds", + ], }, }, async run({ $ }) { - const slots = await this.cliento.fetchSlots({ - fromDate: this.fromDate, - toDate: this.toDate, - resourceIds: this.resourceIds, - serviceIds: this.serviceIds, + const response = await this.cliento.fetchSlots({ + $, + params: { + fromDate: this.fromDate, + toDate: this.toDate, + resIds: this.resourceIds.join(), + srvIds: this.serviceIds.join(), + }, }); - $.export("$summary", `Successfully fetched ${slots.length} slots`); - return slots; + if (response?.length) { + $.export("$summary", `Successfully fetched ${response.length} slot${response.length === 1 + ? "" + : "s"}`); + } + return response; }, }; diff --git a/components/cliento/cliento.app.mjs b/components/cliento/cliento.app.mjs index 70c983fbfe804..7f31a9503ac62 100644 --- a/components/cliento/cliento.app.mjs +++ b/components/cliento/cliento.app.mjs @@ -18,57 +18,65 @@ export default { type: "string[]", label: "Resource IDs", description: "The IDs of the resources for the booking", + async options() { + const { resources } = await this.fetchRefData(); + return resources?.map(({ + id: value, name: label, + }) => ({ + value, + label, + })) || []; + }, }, serviceIds: { type: "string[]", label: "Service IDs", description: "The IDs of the services for the booking", + async options() { + const { services } = await this.fetchRefData(); + return services?.map(({ + serviceId: value, name: label, + }) => ({ + value, + label, + })) || []; + }, }, }, methods: { _baseUrl() { - return "https://api.cliento.com"; + return `https://cliento.com/api/v2/partner/cliento/${this.$auth.account_id}`; }, - async _makeRequest(opts = {}) { + _makeRequest(opts = {}) { const { $ = this, - method = "GET", path, - headers, ...otherOpts } = opts; return axios($, { ...otherOpts, - method, - url: this._baseUrl() + path, + url: `${this._baseUrl()}${path}`, headers: { - ...headers, - "Authorization": `Bearer ${this.$auth.oauth_access_token}`, + Accept: "application/json", }, }); }, - async fetchSettings() { + fetchSettings(opts = {}) { return this._makeRequest({ path: "/settings/", + ...opts, }); }, - async fetchRefData() { + fetchRefData(opts = {}) { return this._makeRequest({ path: "/ref-data/", + ...opts, }); }, - async fetchSlots({ - fromDate, toDate, resourceIds, serviceIds, - }) { - const params = { - fromDate, - toDate, - resIds: resourceIds.join(","), - srvIds: serviceIds.join(","), - }; + fetchSlots(opts = {}) { return this._makeRequest({ path: "/resources/slots", - params, + ...opts, }); }, }, diff --git a/components/cliento/package.json b/components/cliento/package.json index 355064da3081e..0242739d685b9 100644 --- a/components/cliento/package.json +++ b/components/cliento/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/cliento", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Cliento Components", "main": "cliento.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} From ee868be4b6c3a5a76481eb0d52dd6398a035d3b5 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Mon, 7 Oct 2024 15:38:27 -0400 Subject: [PATCH 3/3] pnpm-lock.yaml --- pnpm-lock.yaml | 107 +++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 52 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 52b46f18c0b3d..aa2e0274cb102 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1778,7 +1778,10 @@ importers: specifiers: {} components/cliento: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/clinchpad: specifiers: @@ -12909,55 +12912,6 @@ packages: - aws-crt dev: false - /@aws-sdk/client-sso-oidc/3.600.0_tdq3komn4zwyd65w7klbptsu34: - resolution: {integrity: sha512-7+I8RWURGfzvChyNQSyj5/tKrqRbzRl7H+BnTOf/4Vsw1nFOi5ROhlhD4X/Y0QCTacxnaoNcIrqnY7uGGvVRzw==} - engines: {node: '>=16.0.0'} - dependencies: - '@aws-crypto/sha256-browser': 5.2.0 - '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sts': 3.600.0 - '@aws-sdk/core': 3.598.0 - '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 - '@aws-sdk/middleware-host-header': 3.598.0 - '@aws-sdk/middleware-logger': 3.598.0 - '@aws-sdk/middleware-recursion-detection': 3.598.0 - '@aws-sdk/middleware-user-agent': 3.598.0 - '@aws-sdk/region-config-resolver': 3.598.0 - '@aws-sdk/types': 3.598.0 - '@aws-sdk/util-endpoints': 3.598.0 - '@aws-sdk/util-user-agent-browser': 3.598.0 - '@aws-sdk/util-user-agent-node': 3.598.0 - '@smithy/config-resolver': 3.0.3 - '@smithy/core': 2.2.3 - '@smithy/fetch-http-handler': 3.2.1 - '@smithy/hash-node': 3.0.2 - '@smithy/invalid-dependency': 3.0.2 - '@smithy/middleware-content-length': 3.0.2 - '@smithy/middleware-endpoint': 3.0.4 - '@smithy/middleware-retry': 3.0.6 - '@smithy/middleware-serde': 3.0.3 - '@smithy/middleware-stack': 3.0.3 - '@smithy/node-config-provider': 3.1.3 - '@smithy/node-http-handler': 3.1.2 - '@smithy/protocol-http': 4.0.3 - '@smithy/smithy-client': 3.1.6 - '@smithy/types': 3.3.0 - '@smithy/url-parser': 3.0.3 - '@smithy/util-base64': 3.0.0 - '@smithy/util-body-length-browser': 3.0.0 - '@smithy/util-body-length-node': 3.0.0 - '@smithy/util-defaults-mode-browser': 3.0.6 - '@smithy/util-defaults-mode-node': 3.0.6 - '@smithy/util-endpoints': 2.0.3 - '@smithy/util-middleware': 3.0.3 - '@smithy/util-retry': 3.0.2 - '@smithy/util-utf8': 3.0.0 - tslib: 2.6.3 - transitivePeerDependencies: - - '@aws-sdk/client-sts' - - aws-crt - dev: false - /@aws-sdk/client-sso/3.423.0: resolution: {integrity: sha512-znIufHkwhCIePgaYciIs3x/+BpzR57CZzbCKHR9+oOvGyufEPPpUT5bFLvbwTgfiVkTjuk6sG/ES3U5Bc+xtrA==} engines: {node: '>=14.0.0'} @@ -13193,7 +13147,7 @@ packages: dependencies: '@aws-crypto/sha256-browser': 5.2.0 '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sso-oidc': 3.600.0_tdq3komn4zwyd65w7klbptsu34 + '@aws-sdk/client-sso-oidc': 3.600.0 '@aws-sdk/core': 3.598.0 '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 '@aws-sdk/middleware-host-header': 3.598.0 @@ -13235,6 +13189,55 @@ packages: - aws-crt dev: false + /@aws-sdk/client-sts/3.600.0_dseaa2p5u2yk67qiepewcq3hkq: + resolution: {integrity: sha512-KQG97B7LvTtTiGmjlrG1LRAY8wUvCQzrmZVV5bjrJ/1oXAU7DITYwVbSJeX9NWg6hDuSk0VE3MFwIXS2SvfLIA==} + engines: {node: '>=16.0.0'} + dependencies: + '@aws-crypto/sha256-browser': 5.2.0 + '@aws-crypto/sha256-js': 5.2.0 + '@aws-sdk/client-sso-oidc': 3.600.0 + '@aws-sdk/core': 3.598.0 + '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 + '@aws-sdk/middleware-host-header': 3.598.0 + '@aws-sdk/middleware-logger': 3.598.0 + '@aws-sdk/middleware-recursion-detection': 3.598.0 + '@aws-sdk/middleware-user-agent': 3.598.0 + '@aws-sdk/region-config-resolver': 3.598.0 + '@aws-sdk/types': 3.598.0 + '@aws-sdk/util-endpoints': 3.598.0 + '@aws-sdk/util-user-agent-browser': 3.598.0 + '@aws-sdk/util-user-agent-node': 3.598.0 + '@smithy/config-resolver': 3.0.3 + '@smithy/core': 2.2.3 + '@smithy/fetch-http-handler': 3.2.1 + '@smithy/hash-node': 3.0.2 + '@smithy/invalid-dependency': 3.0.2 + '@smithy/middleware-content-length': 3.0.2 + '@smithy/middleware-endpoint': 3.0.4 + '@smithy/middleware-retry': 3.0.6 + '@smithy/middleware-serde': 3.0.3 + '@smithy/middleware-stack': 3.0.3 + '@smithy/node-config-provider': 3.1.3 + '@smithy/node-http-handler': 3.1.2 + '@smithy/protocol-http': 4.0.3 + '@smithy/smithy-client': 3.1.6 + '@smithy/types': 3.3.0 + '@smithy/url-parser': 3.0.3 + '@smithy/util-base64': 3.0.0 + '@smithy/util-body-length-browser': 3.0.0 + '@smithy/util-body-length-node': 3.0.0 + '@smithy/util-defaults-mode-browser': 3.0.6 + '@smithy/util-defaults-mode-node': 3.0.6 + '@smithy/util-endpoints': 2.0.3 + '@smithy/util-middleware': 3.0.3 + '@smithy/util-retry': 3.0.2 + '@smithy/util-utf8': 3.0.0 + tslib: 2.6.3 + transitivePeerDependencies: + - '@aws-sdk/client-sso-oidc' + - aws-crt + dev: false + /@aws-sdk/core/3.556.0: resolution: {integrity: sha512-vJaSaHw2kPQlo11j/Rzuz0gk1tEaKdz+2ser0f0qZ5vwFlANjt08m/frU17ctnVKC1s58bxpctO/1P894fHLrA==} engines: {node: '>=14.0.0'} @@ -17561,7 +17564,7 @@ packages: '@aws-sdk/client-sns': 3.423.0 '@aws-sdk/client-sqs': 3.423.0 '@aws-sdk/client-ssm': 3.423.0 - '@aws-sdk/client-sts': 3.600.0 + '@aws-sdk/client-sts': 3.600.0_dseaa2p5u2yk67qiepewcq3hkq '@aws-sdk/s3-request-presigner': 3.609.0 '@pipedream/helper_functions': 0.3.12 '@pipedream/platform': 1.6.6