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..8a30d3b494f8a --- /dev/null +++ b/components/popupsmart/sources/new-popup-form-data/new-popup-form-data.mjs @@ -0,0 +1,72 @@ +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(); + const results = this.popupsmart.paginate({ + maxResults, + fn: this.popupsmart.listLeads, + headers: { + "x-campaign-id": this.campaignId, + }, + }); + + let leads = []; + for await (const item of results) { + leads.push(item); + } + + leads = leads.filter((item) => Date.parse(item.date) > lastDate); + + if (leads.length) { + this._setLastDate(Date.parse(leads[0].date)); + } + for (const item of leads.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 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==}