From 0b62f171f7003a7eb11b78e11b091d15ac868475 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Wed, 5 Feb 2025 13:15:12 -0500 Subject: [PATCH 1/4] wip --- .../actions/create-email/create-email.mjs | 0 components/stripo/package.json | 7 ++- components/stripo/stripo.app.mjs | 52 +++++++++++++++++-- 3 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 components/stripo/actions/create-email/create-email.mjs diff --git a/components/stripo/actions/create-email/create-email.mjs b/components/stripo/actions/create-email/create-email.mjs new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/components/stripo/package.json b/components/stripo/package.json index 445122f4bb721..f4200d7bf8425 100644 --- a/components/stripo/package.json +++ b/components/stripo/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/stripo", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Stripo Components", "main": "stripo.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 +} diff --git a/components/stripo/stripo.app.mjs b/components/stripo/stripo.app.mjs index b50391386481a..f0ec1fed486b2 100644 --- a/components/stripo/stripo.app.mjs +++ b/components/stripo/stripo.app.mjs @@ -1,11 +1,55 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "stripo", - propDefinitions: {}, + propDefinitions: { + templateId: { + type: "string", + label: "Template ID", + description: "An ID of a template with the auto-generated area. Please note that this template should be yours (saved in the project you have access to), not a basic or a public one.", + async options({ page }) { + const { data } = await this.listTemplates({ + params: page, + }); + return data?.map(({ + templateId: value, name: label, + }) => ({ + value, + label, + })) || []; + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://my.stripo.email/emailgeneration/v1"; + }, + _makeRequest({ + $ = this, + path, + ...opts + }) { + return axios($, { + url: `${this._baseUrl()}${path}`, + headers: { + "Stripo-Api-Auth": this.$auth.api_key, + }, + ...opts, + }); + }, + listTemplates(opts = {}) { + return this._makeRequest({ + path: "/templates", + ...opts, + }); + }, + createEmail(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/email", + ...opts, + }); }, }, }; From 6997b04684e2f717bcd5d5d67b0499b139885e48 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Thu, 6 Feb 2025 10:38:00 -0500 Subject: [PATCH 2/4] wip --- .../actions/create-email/create-email.mjs | 0 .../new-email-created/new-email-created.mjs | 84 +++++++++++++++++++ .../sources/new-email-created/test-event.mjs | 11 +++ components/stripo/stripo.app.mjs | 53 ++++++------ 4 files changed, 122 insertions(+), 26 deletions(-) delete mode 100644 components/stripo/actions/create-email/create-email.mjs create mode 100644 components/stripo/sources/new-email-created/new-email-created.mjs create mode 100644 components/stripo/sources/new-email-created/test-event.mjs diff --git a/components/stripo/actions/create-email/create-email.mjs b/components/stripo/actions/create-email/create-email.mjs deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/components/stripo/sources/new-email-created/new-email-created.mjs b/components/stripo/sources/new-email-created/new-email-created.mjs new file mode 100644 index 0000000000000..c182d994aeba0 --- /dev/null +++ b/components/stripo/sources/new-email-created/new-email-created.mjs @@ -0,0 +1,84 @@ +import stripo from "../../stripo.app.mjs"; +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; +import sampleEmit from "./test-event.mjs"; + +export default { + key: "stripo-new-email-created", + name: "New Email Created", + description: "Emit new event when a new email is created in Stripo. [See the documentation](https://api.stripo.email/reference/findemails)", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + stripo, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + query: { + type: "string", + label: "Query", + description: "A query to search for", + optional: true, + }, + }, + methods: { + _getLastTs() { + return this.db.get("lastTs") || 0; + }, + _setLastTs(lastTs) { + this.db.set("lastTs", lastTs); + }, + generateMeta(email) { + return { + id: email.emailId, + summary: `New Email: ${email.name}`, + ts: Date.parse(email.updatedTime), + }; + }, + async processEvent(max) { + const lastTs = this._getLastTs(); + + const results = this.stripo.paginate({ + fn: this.stripo.listEmails, + params: { + queryStr: this.query, + sortingColumn: "createdTime", + sortingAsc: false, + }, + max, + }); + + const emails = []; + for await (const item of results) { + const ts = Date.parse(item.updatedTime); + if (ts >= lastTs) { + emails.push(item); + } + } + + if (!emails.length) { + return; + } + + this._setLastTs(Date.parse(emails[0].updatedTime)); + + emails.reverse().forEach((email) => { + const meta = this.generateMeta(email); + this.$emit(email, meta); + }); + }, + }, + hooks: { + async deploy() { + await this.processEvent(25); + }, + }, + async run() { + await this.processEvent(); + }, + sampleEmit, +}; diff --git a/components/stripo/sources/new-email-created/test-event.mjs b/components/stripo/sources/new-email-created/test-event.mjs new file mode 100644 index 0000000000000..516b4ed70b184 --- /dev/null +++ b/components/stripo/sources/new-email-created/test-event.mjs @@ -0,0 +1,11 @@ +export default { + "emailId": 9031276, + "name": "New Message", + "editorUrl": "https://my.stripo.email/cabinet/#/template-editor/?emailId=9031276&projectId=1189279&type=EMAIL", + "previewUrl": "https://viewstripo.email/575439dc-9d57-4e3f-989e-23a1a63971901738788020521", + "updatedTime": "2025-02-05T20:40:34.46", + "hasAmp": false, + "preheader": null, + "title": "", + "previewImage": "https://doc.stripocdn.email/content/guids/cabinet-icons/87baef10-e401-11ef-a29e-e99b514f747b.png" +} \ No newline at end of file diff --git a/components/stripo/stripo.app.mjs b/components/stripo/stripo.app.mjs index f0ec1fed486b2..dd618c550f864 100644 --- a/components/stripo/stripo.app.mjs +++ b/components/stripo/stripo.app.mjs @@ -3,24 +3,7 @@ import { axios } from "@pipedream/platform"; export default { type: "app", app: "stripo", - propDefinitions: { - templateId: { - type: "string", - label: "Template ID", - description: "An ID of a template with the auto-generated area. Please note that this template should be yours (saved in the project you have access to), not a basic or a public one.", - async options({ page }) { - const { data } = await this.listTemplates({ - params: page, - }); - return data?.map(({ - templateId: value, name: label, - }) => ({ - value, - label, - })) || []; - }, - }, - }, + propDefinitions: {}, methods: { _baseUrl() { return "https://my.stripo.email/emailgeneration/v1"; @@ -34,22 +17,40 @@ export default { url: `${this._baseUrl()}${path}`, headers: { "Stripo-Api-Auth": this.$auth.api_key, + "Content-Type": "application/json", }, ...opts, }); }, - listTemplates(opts = {}) { + listEmails(opts = {}) { return this._makeRequest({ - path: "/templates", + path: "/emails", ...opts, }); }, - createEmail(opts = {}) { - return this._makeRequest({ - method: "POST", - path: "/email", - ...opts, - }); + async *paginate({ + fn, params, max, + }) { + params = { + ...params, + page: 0, + }; + let totalResults, count = 0; + do { + const { + data, total, + } = await fn({ + params, + }); + totalResults = total; + for (const item of data) { + yield item; + count++; + if (max && count >= max) { + return; + } + } + } while (count < totalResults); }, }, }; From 0b6b9896b64270abb295f3e0f73e1a75fd35371c Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Thu, 6 Feb 2025 12:00:07 -0500 Subject: [PATCH 3/4] new components --- .../actions/get-raw-html/get-raw-html.mjs | 26 +++++++++++ .../actions/remove-email/remove-email.mjs | 26 +++++++++++ .../actions/search-emails/search-emails.mjs | 44 +++++++++++++++++++ .../new-email-created/new-email-created.mjs | 8 ++-- components/stripo/stripo.app.mjs | 44 ++++++++++++++++++- 5 files changed, 143 insertions(+), 5 deletions(-) create mode 100644 components/stripo/actions/get-raw-html/get-raw-html.mjs create mode 100644 components/stripo/actions/remove-email/remove-email.mjs create mode 100644 components/stripo/actions/search-emails/search-emails.mjs diff --git a/components/stripo/actions/get-raw-html/get-raw-html.mjs b/components/stripo/actions/get-raw-html/get-raw-html.mjs new file mode 100644 index 0000000000000..f7146d996e402 --- /dev/null +++ b/components/stripo/actions/get-raw-html/get-raw-html.mjs @@ -0,0 +1,26 @@ +import stripo from "../../stripo.app.mjs"; + +export default { + key: "stripo-get-raw-html", + name: "Get Raw HTML & CSS", + description: "Retrieves the HTML and CSS code of the selected email message in Stripo. [See the documentation](https://api.stripo.email/reference/getrawemail)", + version: "0.0.1", + type: "action", + props: { + stripo, + emailId: { + propDefinition: [ + stripo, + "emailId", + ], + }, + }, + async run({ $ }) { + const response = await this.stripo.getRawHtml({ + $, + emailId: this.emailId, + }); + $.export("$summary", `Successfully retrieved HTML & CSS from email with ID: ${this.emailId}`); + return response; + }, +}; diff --git a/components/stripo/actions/remove-email/remove-email.mjs b/components/stripo/actions/remove-email/remove-email.mjs new file mode 100644 index 0000000000000..0572393109732 --- /dev/null +++ b/components/stripo/actions/remove-email/remove-email.mjs @@ -0,0 +1,26 @@ +import stripo from "../../stripo.app.mjs"; + +export default { + key: "stripo-remove-email", + name: "Remove Email", + description: "Removes an existing message from the user's project in Stripo. [See the documentation](https://api.stripo.email/reference/deleteemail)", + version: "0.0.1", + type: "action", + props: { + stripo, + emailId: { + propDefinition: [ + stripo, + "emailId", + ], + }, + }, + async run({ $ }) { + const response = await this.stripo.removeEmail({ + $, + emailId: this.emailId, + }); + $.export("$summary", `Successfully removed email with ID: ${this.emailId}`); + return response; + }, +}; diff --git a/components/stripo/actions/search-emails/search-emails.mjs b/components/stripo/actions/search-emails/search-emails.mjs new file mode 100644 index 0000000000000..b9c2a586cb4a5 --- /dev/null +++ b/components/stripo/actions/search-emails/search-emails.mjs @@ -0,0 +1,44 @@ +import stripo from "../../stripo.app.mjs"; + +export default { + key: "stripo-search-emails", + name: "Search Emails", + description: "Searches existing emails by search query in Stripo. [See the documentation](https://api.stripo.email/reference/findemails)", + version: "0.0.1", + type: "action", + props: { + stripo, + query: { + propDefinition: [ + stripo, + "query", + ], + }, + maxResults: { + type: "integer", + label: "Max Results", + description: "The maximum number of results to return", + default: 100, + optional: true, + }, + }, + async run({ $ }) { + const results = this.stripo.paginate({ + fn: this.stripo.listEmails, + params: { + queryStr: this.query, + }, + max: this.maxResults, + }); + + const emails = []; + for await (const item of results) { + emails.push(item); + } + + $.export("$summary", `Successfully retrieved ${emails.length} email${emails.length === 1 + ? "" + : "s"}`); + return emails; + }, +}; diff --git a/components/stripo/sources/new-email-created/new-email-created.mjs b/components/stripo/sources/new-email-created/new-email-created.mjs index c182d994aeba0..bcca28cca9157 100644 --- a/components/stripo/sources/new-email-created/new-email-created.mjs +++ b/components/stripo/sources/new-email-created/new-email-created.mjs @@ -19,10 +19,10 @@ export default { }, }, query: { - type: "string", - label: "Query", - description: "A query to search for", - optional: true, + propDefinition: [ + stripo, + "query", + ], }, }, methods: { diff --git a/components/stripo/stripo.app.mjs b/components/stripo/stripo.app.mjs index dd618c550f864..433af24ff2f07 100644 --- a/components/stripo/stripo.app.mjs +++ b/components/stripo/stripo.app.mjs @@ -3,7 +3,32 @@ import { axios } from "@pipedream/platform"; export default { type: "app", app: "stripo", - propDefinitions: {}, + propDefinitions: { + emailId: { + type: "string", + label: "Email ID", + description: "The identifier of an email", + async options({ page }) { + const { data } = await this.listEmails({ + params: { + page, + }, + }); + return data?.map(({ + emailId: value, name: label, + }) => ({ + value, + label, + })) || []; + }, + }, + query: { + type: "string", + label: "Query", + description: "The query to search for", + optional: true, + }, + }, methods: { _baseUrl() { return "https://my.stripo.email/emailgeneration/v1"; @@ -28,6 +53,23 @@ export default { ...opts, }); }, + getRawHtml({ + emailId, ...opts + }) { + return this._makeRequest({ + path: `/raw-email/${emailId}`, + ...opts, + }); + }, + removeEmail({ + emailId, ...opts + }) { + return this._makeRequest({ + method: "DELETE", + path: `/emails/${emailId}`, + ...opts, + }); + }, async *paginate({ fn, params, max, }) { From 4aee39c602726ca648b2be765c05d829703c6f89 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Thu, 6 Feb 2025 12:02:30 -0500 Subject: [PATCH 4/4] pnpm-lock.yaml --- pnpm-lock.yaml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d66742efa5ea7..3cceb39e13ddf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1522,8 +1522,7 @@ importers: specifier: ^0.1.4 version: 0.1.6 - components/buysellads: - specifiers: {} + components/buysellads: {} components/bybit: dependencies: @@ -5697,8 +5696,7 @@ importers: specifier: ^3.0.3 version: 3.0.3 - components/klipy: - specifiers: {} + components/klipy: {} components/knack: dependencies: @@ -10367,7 +10365,11 @@ importers: specifier: ^8.168.0 version: 8.222.0 - components/stripo: {} + components/stripo: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/studio_by_ai21_labs: {}