From 6b0363e5b7e24853440df5d5f396e4c9a3791ba7 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Mon, 3 Nov 2025 19:20:35 -0300 Subject: [PATCH 1/4] Update Popupsmart component to version 0.1.0, add new methods for API requests, and introduce a new source for emitting popup form data events. --- components/popupsmart/package.json | 5 +- components/popupsmart/popupsmart.app.mjs | 56 +++++++++++++- .../new-popup-form-data.mjs | 74 +++++++++++++++++++ .../new-popup-form-data/test-event.mjs | 31 ++++++++ 4 files changed, 161 insertions(+), 5 deletions(-) create mode 100644 components/popupsmart/sources/new-popup-form-data/new-popup-form-data.mjs create mode 100644 components/popupsmart/sources/new-popup-form-data/test-event.mjs diff --git a/components/popupsmart/package.json b/components/popupsmart/package.json index eaf6b175c9712..df3ff38c889e0 100644 --- a/components/popupsmart/package.json +++ b/components/popupsmart/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/popupsmart", - "version": "0.0.2", + "version": "0.1.0", "description": "Pipedream Popupsmart Components", "main": "popupsmart.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } } diff --git a/components/popupsmart/popupsmart.app.mjs b/components/popupsmart/popupsmart.app.mjs index 2c948934f121d..88c53e8dfde7b 100644 --- a/components/popupsmart/popupsmart.app.mjs +++ b/components/popupsmart/popupsmart.app.mjs @@ -1,11 +1,59 @@ +import { axios } from "@pipedream/platform"; +const LIMIT = 100; + export default { type: "app", app: "popupsmart", - propDefinitions: {}, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://app.popupsmart.com/api"; + }, + _headers(headers = {}) { + return { + "x-token": this.$auth.api_key, + ...headers, + }; + }, + _makeRequest({ + $ = this, path, headers, ...opts + }) { + return axios($, { + url: `${this._baseUrl()}/${path}`, + headers: this._headers(headers), + ...opts, + }); + }, + listLeads(args = {}) { + return this._makeRequest({ + path: "leads", + ...args, + }); + }, + async *paginate({ + fn, params = {}, maxResults = null, ...opts + }) { + let hasMore = false; + let count = 0; + let page = 0; + + do { + params.take = LIMIT; + params.skip = LIMIT * page++; + const { leads } = await fn({ + params, + ...opts, + }); + for (const d of leads) { + yield d; + + if (maxResults && ++count === maxResults) { + return count; + } + } + + hasMore = leads.length; + + } while (hasMore); }, }, }; diff --git a/components/popupsmart/sources/new-popup-form-data/new-popup-form-data.mjs b/components/popupsmart/sources/new-popup-form-data/new-popup-form-data.mjs new file mode 100644 index 0000000000000..8d9f6ea203abb --- /dev/null +++ b/components/popupsmart/sources/new-popup-form-data/new-popup-form-data.mjs @@ -0,0 +1,74 @@ +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; +import popupsmart from "../../popupsmart.app.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + key: "popupsmart-new-popup-form-data", + name: "New Popup Form Data", + description: "Emit new event when a new popup form data is received. [See the documentation](https://popupsmart.com/help/detail/how-to-auto-download-leads-using-an-api)", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + popupsmart, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + campaignId: { + type: "string", + label: "Campaign ID", + description: "The ID of the campaign to get form data from.", + }, + }, + methods: { + _getLastDate() { + return this.db.get("lastDate") || 0; + }, + _setLastDate(lastDate) { + this.db.set("lastDate", lastDate); + }, + async startEvent(maxResults = 0) { + const lastDate = this._getLastDate(); + let leads = this.popupsmart.paginate({ + maxResults, + fn: this.popupsmart.listLeads, + headers: { + "x-campaign-id": this.campaignId, + }, + }); + + let responseArray = []; + for await (const lead of leads) { + if (Date.parse(lead.date) > lastDate) { + responseArray.push(lead); + } + } + + responseArray = responseArray.filter((item) => Date.parse(item.date) > lastDate); + + if (responseArray.length) { + this._setLastDate(Date.parse(responseArray[0].date)); + } + for (const item of responseArray.reverse()) { + this.$emit(item, { + id: item.id, + summary: `New form data for popup ${this.campaignId}`, + ts: Date.parse(item.date), + }); + } + }, + }, + hooks: { + async deploy() { + await this.startEvent(25); + }, + }, + async run() { + await this.startEvent(); + }, + sampleEmit, +}; diff --git a/components/popupsmart/sources/new-popup-form-data/test-event.mjs b/components/popupsmart/sources/new-popup-form-data/test-event.mjs new file mode 100644 index 0000000000000..28201a7701552 --- /dev/null +++ b/components/popupsmart/sources/new-popup-form-data/test-event.mjs @@ -0,0 +1,31 @@ +export default { + "id":"23839530_099-516c-446-2053fe-9b19-99ff4e267f", + "date":"2025-11-03 21:52:15", + "sessionId":"23839530_099-516c-446-2053fe-9b19-99ff4e267f", + "accountId":1007926, + "url":"https://website.com/", + "page":"/", + "host":"website.com", + "userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36", + "device":"Desktop", + "resolution":"1920x1080", + "os":"Windows", + "browser":"Chrome", + "language":"en-US", + "referrer":"https://website.com/main?post_type=property", + "type":"lead", + "campaignId":1234567890, + "location":"{\"ip\":\"123.456.78.90\",\"countryCode\":\"US\",\"country\":\"United States\",\"region\":\"California\",\"regionCode\":\"CA\",\"city\":\"San Francisco\",\"latitude\":\"37.774929\",\"longitude\":\"-122.419416\",\"timezone\":\"America/Los_Angeles\",\"asOrganization\":\"Google Inc.\",\"postalCode\":\"94107\"}", + "meta":{ + "utm_campaign":null, + "utm_source":null, + "utm_medium":null, + "utm_content":null, + "utm_term":null + }, + "formData":{ + "email_input_3GTXBG":"email@example.com" + }, + "unsubscribed":null, + "triggerIntegrations":null +} \ No newline at end of file From 06a96cd0bd5795ed102b9659f571366059ae68b6 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Mon, 3 Nov 2025 19:21:52 -0300 Subject: [PATCH 2/4] pnpm update --- pnpm-lock.yaml | 74 ++++++++++++++++++++------------------------------ 1 file changed, 29 insertions(+), 45 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 22fd90d844e34..49501a60dd5f0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3414,8 +3414,7 @@ importers: components/cronly: {} - components/cronlytic: - specifiers: {} + components/cronlytic: {} components/crossmint: {} @@ -3624,8 +3623,7 @@ importers: components/data_police_uk: {} - components/data_soap: - specifiers: {} + components/data_soap: {} components/data_stores: dependencies: @@ -3733,13 +3731,11 @@ importers: specifier: ^1.5.1 version: 1.6.6 - components/decodo: - specifiers: {} + components/decodo: {} components/deel: {} - components/deep_tagger: - specifiers: {} + components/deep_tagger: {} components/deepgram: dependencies: @@ -3834,8 +3830,7 @@ importers: specifier: ^0.3.2 version: 0.3.2 - components/deutschlandgpt: - specifiers: {} + components/deutschlandgpt: {} components/dev_to: dependencies: @@ -4110,8 +4105,7 @@ importers: specifier: ^3.1.0 version: 3.1.0 - components/documentero: - specifiers: {} + components/documentero: {} components/documenterra: dependencies: @@ -4365,8 +4359,7 @@ importers: specifier: ^1.5.1 version: 1.6.6 - components/dumplingai: - specifiers: {} + components/dumplingai: {} components/dungeon_fighter_online: {} @@ -4433,8 +4426,7 @@ importers: components/easy_projects: {} - components/easy_redmine: - specifiers: {} + components/easy_redmine: {} components/easybroker: {} @@ -4481,8 +4473,7 @@ importers: components/ebay: {} - components/echowin: - specifiers: {} + components/echowin: {} components/echtpost_postcards: dependencies: @@ -4803,8 +4794,7 @@ importers: specifier: ^1.1.1 version: 1.6.6 - components/evervault: - specifiers: {} + components/evervault: {} components/everwebinar: dependencies: @@ -4871,8 +4861,7 @@ importers: components/extracta_ai: {} - components/extruct_ai: - specifiers: {} + components/extruct_ai: {} components/eyepop_ai: {} @@ -4986,8 +4975,7 @@ importers: specifier: ^3.0.3 version: 3.0.3 - components/featherless: - specifiers: {} + components/featherless: {} components/feathery: dependencies: @@ -5056,8 +5044,7 @@ importers: specifier: ^3.0.0 version: 3.0.3 - components/filescan: - specifiers: {} + components/filescan: {} components/filestack: dependencies: @@ -5290,8 +5277,7 @@ importers: components/form_io: {} - components/form_taxi: - specifiers: {} + components/form_taxi: {} components/formaloo: dependencies: @@ -5998,8 +5984,7 @@ importers: components/google_chat_developer_app: {} - components/google_chat_service_account_key: - specifiers: {} + components/google_chat_service_account_key: {} components/google_classroom: dependencies: @@ -6401,8 +6386,7 @@ importers: components/greenspark: {} - components/greip: - specifiers: {} + components/greip: {} components/greptile: dependencies: @@ -6505,8 +6489,7 @@ importers: components/hana: {} - components/handelsregister_ai: - specifiers: {} + components/handelsregister_ai: {} components/handwrytten: {} @@ -6554,8 +6537,7 @@ importers: specifier: ^2.29.4 version: 2.30.1 - components/hasdata: - specifiers: {} + components/hasdata: {} components/hashnode: {} @@ -7388,8 +7370,7 @@ importers: specifier: ^1.1.1 version: 1.6.6 - components/ipregistry: - specifiers: {} + components/ipregistry: {} components/ipstack: dependencies: @@ -8243,8 +8224,7 @@ importers: specifier: ^1.0.3 version: 1.0.3 - components/linkupapi: - specifiers: {} + components/linkupapi: {} components/linode: dependencies: @@ -11248,7 +11228,11 @@ importers: specifier: ^3.0.0 version: 3.0.3 - components/popupsmart: {} + components/popupsmart: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/portabilling: {} @@ -31548,22 +31532,22 @@ packages: superagent@3.8.1: resolution: {integrity: sha512-VMBFLYgFuRdfeNQSMLbxGSLfmXL/xc+OO+BZp41Za/NRDBet/BNbkRJrYzCUu0u4GU0i/ml2dtT8b9qgkw9z6Q==} engines: {node: '>= 4.0'} - deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@4.1.0: resolution: {integrity: sha512-FT3QLMasz0YyCd4uIi5HNe+3t/onxMyEho7C3PSqmti3Twgy2rXT4fmkTz6wRL6bTF4uzPcfkUCa8u4JWHw8Ag==} engines: {node: '>= 6.0'} - deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@5.3.1: resolution: {integrity: sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==} engines: {node: '>= 7.0.0'} - deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@7.1.6: resolution: {integrity: sha512-gZkVCQR1gy/oUXr+kxJMLDjla434KmSOKbx5iGD30Ql+AkJQ/YlPKECJy2nhqOsHLjGHzoDTXNSjhnvWhzKk7g==} engines: {node: '>=6.4.0 <13 || >=14'} - deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net supports-color@10.0.0: resolution: {integrity: sha512-HRVVSbCCMbj7/kdWF9Q+bbckjBHLtHMEoJWlkmYzzdwhYMkjkOwubLM6t7NbWKjgKamGDrWL1++KrjUO1t9oAQ==} From 1a5abf44ebb8d7da0625f4ddf9078c83290f9e3e Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Mon, 3 Nov 2025 20:02:53 -0300 Subject: [PATCH 3/4] Refactor lead filtering in new-popup-form-data to streamline response handling and improve performance by eliminating unnecessary array creation. --- .../new-popup-form-data/new-popup-form-data.mjs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/components/popupsmart/sources/new-popup-form-data/new-popup-form-data.mjs b/components/popupsmart/sources/new-popup-form-data/new-popup-form-data.mjs index 8d9f6ea203abb..f3fb1d2296f7a 100644 --- a/components/popupsmart/sources/new-popup-form-data/new-popup-form-data.mjs +++ b/components/popupsmart/sources/new-popup-form-data/new-popup-form-data.mjs @@ -41,19 +41,12 @@ export default { }, }); - let responseArray = []; - for await (const lead of leads) { - if (Date.parse(lead.date) > lastDate) { - responseArray.push(lead); - } - } - - responseArray = responseArray.filter((item) => Date.parse(item.date) > lastDate); + leads = leads.filter((item) => Date.parse(item.date) > lastDate); - if (responseArray.length) { - this._setLastDate(Date.parse(responseArray[0].date)); + if (leads.length) { + this._setLastDate(Date.parse(leads[0].date)); } - for (const item of responseArray.reverse()) { + for (const item of leads.reverse()) { this.$emit(item, { id: item.id, summary: `New form data for popup ${this.campaignId}`, From 7978e5112b2ccb72a9b8c6919ee10e6ed7e66bc0 Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Tue, 4 Nov 2025 10:41:07 -0500 Subject: [PATCH 4/4] await paginated results --- .../sources/new-popup-form-data/new-popup-form-data.mjs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/popupsmart/sources/new-popup-form-data/new-popup-form-data.mjs b/components/popupsmart/sources/new-popup-form-data/new-popup-form-data.mjs index f3fb1d2296f7a..8a30d3b494f8a 100644 --- a/components/popupsmart/sources/new-popup-form-data/new-popup-form-data.mjs +++ b/components/popupsmart/sources/new-popup-form-data/new-popup-form-data.mjs @@ -33,7 +33,7 @@ export default { }, async startEvent(maxResults = 0) { const lastDate = this._getLastDate(); - let leads = this.popupsmart.paginate({ + const results = this.popupsmart.paginate({ maxResults, fn: this.popupsmart.listLeads, headers: { @@ -41,6 +41,11 @@ export default { }, }); + let leads = []; + for await (const item of results) { + leads.push(item); + } + leads = leads.filter((item) => Date.parse(item.date) > lastDate); if (leads.length) {