From 33b0ee19922f5fa011fbe498fec032e69a25c7a1 Mon Sep 17 00:00:00 2001 From: Jorge Cortes Date: Wed, 18 Oct 2023 09:23:38 -0500 Subject: [PATCH 1/5] Added untested actions and source components --- .../starloop/actions/list-ids/list-ids.mjs | 18 +++ .../actions/send-invite/send-invite.mjs | 80 ++++++++++++ components/starloop/common/constants.mjs | 13 ++ components/starloop/package.json | 4 +- .../new-profile-created.mjs | 32 +++++ components/starloop/starloop.app.mjs | 120 +++++++++++++++++- 6 files changed, 260 insertions(+), 7 deletions(-) create mode 100644 components/starloop/actions/list-ids/list-ids.mjs create mode 100644 components/starloop/actions/send-invite/send-invite.mjs create mode 100644 components/starloop/common/constants.mjs create mode 100644 components/starloop/sources/new-profile-created/new-profile-created.mjs diff --git a/components/starloop/actions/list-ids/list-ids.mjs b/components/starloop/actions/list-ids/list-ids.mjs new file mode 100644 index 0000000000000..f8cee3c37ddc5 --- /dev/null +++ b/components/starloop/actions/list-ids/list-ids.mjs @@ -0,0 +1,18 @@ +import app from "../../starloop.app.mjs"; + +export default { + key: "starloop-list-ids", + name: "List IDs", + description: "Returns your business id and a list of all profile id’s and names. [See the documentation](https://help.starloop.com/article/46-api-documentation)", + version: "0.0.1", + type: "action", + props: { + app, + }, + run({ $: step }) { + return this.listIds({ + step, + summary: () => "Successfully listed ids", + }); + }, +}; diff --git a/components/starloop/actions/send-invite/send-invite.mjs b/components/starloop/actions/send-invite/send-invite.mjs new file mode 100644 index 0000000000000..6f6d7e6810134 --- /dev/null +++ b/components/starloop/actions/send-invite/send-invite.mjs @@ -0,0 +1,80 @@ +import app from "../../starloop.app.mjs"; + +export default { + key: "starloop-send-invite", + name: "Send Invite", + description: "Creates a new recipient and sends a Starloop invite (Email | SMS | both) to your customer to leave a review. [See the documentation](https://help.starloop.com/article/46-api-documentation)", + version: "0.0.1", + type: "action", + props: { + app, + firstName: { + propDefinition: [ + app, + "firstName", + ], + }, + email: { + propDefinition: [ + app, + "email", + ], + }, + phone: { + propDefinition: [ + app, + "phone", + ], + }, + businessId: { + propDefinition: [ + app, + "businessId", + ], + }, + profileId: { + propDefinition: [ + app, + "profileId", + ], + }, + testMode: { + propDefinition: [ + app, + "testMode", + ], + }, + }, + methods: { + sendInvite(args = {}) { + return this.app.post({ + path: "/send_invite", + ...args, + }); + }, + }, + run({ $: step }) { + const { + sendInvite, + firstName, + email, + phone, + businessId, + profileId, + testMode, + } = this; + + return sendInvite({ + step, + params: { + first_name: firstName, + email, + phone, + business_id: businessId, + profile_id: profileId, + test_mode: testMode, + }, + summary: () => "Successfully sent invite", + }); + }, +}; diff --git a/components/starloop/common/constants.mjs b/components/starloop/common/constants.mjs new file mode 100644 index 0000000000000..ec8ced447a178 --- /dev/null +++ b/components/starloop/common/constants.mjs @@ -0,0 +1,13 @@ +const SUMMARY_LABEL = "$summary"; +const BASE_URL = "https://go.starloop.com"; +const VERSION_PATH = "/api"; +const LAST_CREATED_AT = "lastCreatedAt"; +const DEFAULT_MAX = 600; + +export default { + SUMMARY_LABEL, + BASE_URL, + VERSION_PATH, + DEFAULT_MAX, + LAST_CREATED_AT, +}; diff --git a/components/starloop/package.json b/components/starloop/package.json index b12b6fddb861b..ee41f3e89e267 100644 --- a/components/starloop/package.json +++ b/components/starloop/package.json @@ -1,7 +1,7 @@ { "name": "@pipedream/starloop", "version": "0.0.1", - "description": "Pipedream Starloop Components", + "description": "Pipedream Starloop Components", "main": "starloop.app.mjs", "keywords": [ "pipedream", @@ -12,4 +12,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} diff --git a/components/starloop/sources/new-profile-created/new-profile-created.mjs b/components/starloop/sources/new-profile-created/new-profile-created.mjs new file mode 100644 index 0000000000000..9f34e05262bf0 --- /dev/null +++ b/components/starloop/sources/new-profile-created/new-profile-created.mjs @@ -0,0 +1,32 @@ +import app from "../../starloop.app.mjs"; +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; + +export default { + key: "starloop-new-id", + name: "New Profile Created", + description: "This source triggers when a new profile is created in Starloop.", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + app, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + }, + async run() { + const { profile_ids: profiles } = await this.app.listIds(); + + profiles.forEach((profile) => { + this.$emit(profile, { + id: profile.id, + summary: `New Profile: ${profile.id}`, + ts: Date.now(), + }); + }); + }, +}; diff --git a/components/starloop/starloop.app.mjs b/components/starloop/starloop.app.mjs index 633acfe08d124..51d0e188d0f7a 100644 --- a/components/starloop/starloop.app.mjs +++ b/components/starloop/starloop.app.mjs @@ -1,11 +1,121 @@ +import { + axios, ConfigurationError, +} from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + export default { type: "app", app: "starloop", - propDefinitions: {}, + propDefinitions: { + businessId: { + type: "string", + label: "Business ID", + description: "The ID of the business", + optional: true, + async options() { + const { business_id: businessId } = await this.listIds(); + return [ + businessId, + ]; + }, + }, + profileId: { + type: "string", + label: "Profile ID", + description: "The ID of the profile", + optional: true, + async options() { + const { profile_ids: profileIds } = await this.listIds(); + return profileIds.map(({ + id: value, name: label, + }) => ({ + label, + value, + })); + }, + }, + firstName: { + type: "string", + label: "First Name", + description: "The first name of the recipient", + }, + email: { + type: "string", + label: "Email", + description: "The email of the recipient", + optional: true, + }, + phone: { + type: "string", + label: "Phone", + description: "The phone number of the recipient", + optional: true, + }, + testMode: { + type: "boolean", + label: "Test Mode", + description: "If set to true, the invite will not be sent", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + exportSummary(step) { + if (!step?.export) { + throw new ConfigurationError("The summary method should be bind to the step object aka `$`"); + } + return (msg = "") => step.export(constants.SUMMARY_LABEL, msg); + }, + getUrl(path) { + return `${constants.BASE_URL}${constants.VERSION_PATH}${path}`; + }, + getParams(params = {}) { + return { + token: this.$auth.api_token, + ...params, + }; + }, + getHeaders(headers = {}) { + return { + "Content-Type": "application/x-www-form-urlencoded", + "accept": "application/json", + ...headers, + }; + }, + async makeRequest({ + step = this, path, headers, params, summary, ...args + } = {}) { + const { + getUrl, + getParams, + getHeaders, + } = this; + + const config = { + url: getUrl(path), + params: getParams(params), + headers: getHeaders(headers), + ...args, + }; + + const response = await axios(step, config); + + if (typeof summary === "function") { + this.exportSummary(step)(summary(response)); + } + + return response; + }, + post(args = {}) { + return this.makeRequest({ + method: "post", + ...args, + }); + }, + listIds(args = {}) { + return this.post({ + path: "/list_ids", + ...args, + }); }, }, -}; \ No newline at end of file +}; From d9020b6aac912ddadadd813e166504723144034a Mon Sep 17 00:00:00 2001 From: Jorge Cortes Date: Wed, 18 Oct 2023 09:27:54 -0500 Subject: [PATCH 2/5] Increased version in package.json file --- components/starloop/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/starloop/package.json b/components/starloop/package.json index ee41f3e89e267..f2bd8dfaf2bdc 100644 --- a/components/starloop/package.json +++ b/components/starloop/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/starloop", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Starloop Components", "main": "starloop.app.mjs", "keywords": [ From b5884cf6295f674c38feb1ff6b034d36fb92a0cc Mon Sep 17 00:00:00 2001 From: Jorge Cortes Date: Wed, 18 Oct 2023 09:41:24 -0500 Subject: [PATCH 3/5] Fixed component key --- .../sources/new-profile-created/new-profile-created.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/starloop/sources/new-profile-created/new-profile-created.mjs b/components/starloop/sources/new-profile-created/new-profile-created.mjs index 9f34e05262bf0..25f26f52a952b 100644 --- a/components/starloop/sources/new-profile-created/new-profile-created.mjs +++ b/components/starloop/sources/new-profile-created/new-profile-created.mjs @@ -2,7 +2,7 @@ import app from "../../starloop.app.mjs"; import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; export default { - key: "starloop-new-id", + key: "starloop-new-profile-created", name: "New Profile Created", description: "This source triggers when a new profile is created in Starloop.", version: "0.0.1", From 749da228c239c6076a53df957a3248c7b4cdc22b Mon Sep 17 00:00:00 2001 From: Jorge Cortes Date: Thu, 19 Oct 2023 09:27:33 -0500 Subject: [PATCH 4/5] Fixes addressed by QA --- components/starloop/actions/list-ids/list-ids.mjs | 2 +- components/starloop/starloop.app.mjs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/components/starloop/actions/list-ids/list-ids.mjs b/components/starloop/actions/list-ids/list-ids.mjs index f8cee3c37ddc5..f907ab2a9b3cc 100644 --- a/components/starloop/actions/list-ids/list-ids.mjs +++ b/components/starloop/actions/list-ids/list-ids.mjs @@ -10,7 +10,7 @@ export default { app, }, run({ $: step }) { - return this.listIds({ + return this.app.listIds({ step, summary: () => "Successfully listed ids", }); diff --git a/components/starloop/starloop.app.mjs b/components/starloop/starloop.app.mjs index 51d0e188d0f7a..dce48f4b0d692 100644 --- a/components/starloop/starloop.app.mjs +++ b/components/starloop/starloop.app.mjs @@ -70,7 +70,7 @@ export default { }, getParams(params = {}) { return { - token: this.$auth.api_token, + token: this.$auth.api_key, ...params, }; }, @@ -103,6 +103,10 @@ export default { this.exportSummary(step)(summary(response)); } + if (response.error_msg) { + throw new Error(JSON.stringify(response, null, 2)); + } + return response; }, post(args = {}) { From b268312087332139c1538ee1145fe19afae113c1 Mon Sep 17 00:00:00 2001 From: Jorge Cortes Date: Thu, 19 Oct 2023 09:28:09 -0500 Subject: [PATCH 5/5] pnpm-lock.yaml --- pnpm-lock.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6f67af2b2fc4c..145424c37b7a8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1785,6 +1785,9 @@ importers: components/float: specifiers: {} + components/flodesk: + specifiers: {} + components/fluent_support: specifiers: {}