diff --git a/components/rejoiner/actions/add-customer-to-list/add-customer-to-list.mjs b/components/rejoiner/actions/add-customer-to-list/add-customer-to-list.mjs new file mode 100644 index 0000000000000..af3f2989ff67f --- /dev/null +++ b/components/rejoiner/actions/add-customer-to-list/add-customer-to-list.mjs @@ -0,0 +1,112 @@ +import rejoiner from "../../rejoiner.app.mjs"; + +export default { + key: "rejoiner-add-customer-to-list", + name: "Add Customer to List", + description: "Adds a customer to a specific list, or if the customer already exists, will update the record of that customer with the supplied data. [See the documentation](https://docs.rejoiner.com/reference/add-customer-to-list)", + version: "0.0.1", + type: "action", + props: { + rejoiner, + listId: { + propDefinition: [ + rejoiner, + "listId", + ], + }, + email: { + propDefinition: [ + rejoiner, + "email", + ], + }, + firstName: { + propDefinition: [ + rejoiner, + "firstName", + ], + }, + lastName: { + propDefinition: [ + rejoiner, + "lastName", + ], + }, + phone: { + propDefinition: [ + rejoiner, + "phone", + ], + }, + timezone: { + propDefinition: [ + rejoiner, + "timezone", + ], + }, + language: { + propDefinition: [ + rejoiner, + "language", + ], + }, + address1: { + propDefinition: [ + rejoiner, + "address1", + ], + }, + address2: { + propDefinition: [ + rejoiner, + "address2", + ], + }, + city: { + propDefinition: [ + rejoiner, + "city", + ], + }, + state: { + propDefinition: [ + rejoiner, + "state", + ], + }, + postalCode: { + propDefinition: [ + rejoiner, + "postalCode", + ], + }, + country: { + propDefinition: [ + rejoiner, + "country", + ], + }, + }, + async run({ $ }) { + const response = await this.rejoiner.addCustomerToList({ + $, + listId: this.listId, + data: { + email: this.email, + first_name: this.firstName, + last_name: this.lastName, + phone: this.phone, + timezone: this.timezone, + language: this.language, + address1: this.address1, + address2: this.address2, + city: this.city, + state: this.state, + postal_code: this.postalCode, + country: this.country, + }, + }); + $.export("$summary", `Added customer ${this.email} to list ${this.listId}`); + return response; + }, +}; diff --git a/components/rejoiner/actions/start-journey/start-journey.mjs b/components/rejoiner/actions/start-journey/start-journey.mjs new file mode 100644 index 0000000000000..e193ff53ac00e --- /dev/null +++ b/components/rejoiner/actions/start-journey/start-journey.mjs @@ -0,0 +1,46 @@ +import rejoiner from "../../rejoiner.app.mjs"; + +export default { + key: "rejoiner-start-journey", + name: "Start Journey", + description: "Triggers the beginning of a customer journey in Rejoiner. [See the documentation](https://docs.rejoiner.com/reference/trigger-webhook-journey)", + version: "0.0.1", + type: "action", + props: { + rejoiner, + webhookUrl: { + type: "string", + label: "Webhook Endpoint URL", + description: "Webhook URL of the journey. A webhook-triggered journey will provide an explicit Webhook Endpoint URL to be used for triggering the journey", + }, + email: { + propDefinition: [ + rejoiner, + "email", + ], + }, + metadata: { + type: "object", + label: "Metadata", + description: "Metadata to be attached to the customer's journey session metadata", + optional: true, + }, + }, + async run({ $ }) { + const response = await this.rejoiner._makeRequest({ + $, + method: "POST", + url: this.webhookUrl, + data: { + email: this.email, + session_data: this.metadata + ? typeof this.metadata === "string" + ? JSON.parse(this.metadata) + : this.metadata + : undefined, + }, + }); + $.export("$summary", `Triggered journey for customer ${this.email}`); + return response; + }, +}; diff --git a/components/rejoiner/actions/update-customer-profile/update-customer-profile.mjs b/components/rejoiner/actions/update-customer-profile/update-customer-profile.mjs new file mode 100644 index 0000000000000..e1101b0834b75 --- /dev/null +++ b/components/rejoiner/actions/update-customer-profile/update-customer-profile.mjs @@ -0,0 +1,107 @@ +import rejoiner from "../../rejoiner.app.mjs"; + +export default { + key: "rejoiner-update-customer-profile", + name: "Update Customer Profile", + description: "Updates a customer's profile information. [See the documentation](https://docs.rejoiner.com/reference/update-customer-profile)", + version: "0.0.1", + type: "action", + props: { + rejoiner, + email: { + propDefinition: [ + rejoiner, + "email", + ], + }, + firstName: { + propDefinition: [ + rejoiner, + "firstName", + ], + }, + lastName: { + propDefinition: [ + rejoiner, + "lastName", + ], + }, + phone: { + propDefinition: [ + rejoiner, + "phone", + ], + }, + timezone: { + propDefinition: [ + rejoiner, + "timezone", + ], + }, + language: { + propDefinition: [ + rejoiner, + "language", + ], + }, + address1: { + propDefinition: [ + rejoiner, + "address1", + ], + }, + address2: { + propDefinition: [ + rejoiner, + "address2", + ], + }, + city: { + propDefinition: [ + rejoiner, + "city", + ], + }, + state: { + propDefinition: [ + rejoiner, + "state", + ], + }, + postalCode: { + propDefinition: [ + rejoiner, + "postalCode", + ], + }, + country: { + propDefinition: [ + rejoiner, + "country", + ], + }, + }, + async run({ $ }) { + const response = await this.rejoiner.updateCustomerProfile({ + $, + params: { + email: this.email, + }, + data: { + first_name: this.firstName, + last_name: this.lastName, + phone: this.phone, + timezone: this.timezone, + language: this.language, + address1: this.address1, + address2: this.address2, + city: this.city, + state: this.state, + postal_code: this.postalCode, + country: this.country, + }, + }); + $.export("$summary", `Updated customer profile for customer ${this.email}`); + return response; + }, +}; diff --git a/components/rejoiner/package.json b/components/rejoiner/package.json index d1db9bf5f640f..7a44d0c90e943 100644 --- a/components/rejoiner/package.json +++ b/components/rejoiner/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/rejoiner", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Rejoiner Components", "main": "rejoiner.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/rejoiner/rejoiner.app.mjs b/components/rejoiner/rejoiner.app.mjs index 6b7e0ac72eb6b..0a98dd63ff46c 100644 --- a/components/rejoiner/rejoiner.app.mjs +++ b/components/rejoiner/rejoiner.app.mjs @@ -1,11 +1,172 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "rejoiner", - propDefinitions: {}, + propDefinitions: { + listId: { + type: "string", + label: "List ID", + description: "Unique identifier for the list", + async options() { + const lists = await this.listLists(); + return lists?.map(({ + id: value, name: label, + }) => ({ + value, + label, + })) || []; + }, + }, + email: { + type: "string", + label: "Email", + description: "The email address of the customer", + }, + firstName: { + type: "string", + label: "First Name", + description: "The first name of the customer", + optional: true, + }, + lastName: { + type: "string", + label: "Last Name", + description: "The last name of the customer", + optional: true, + }, + phone: { + type: "string", + label: "Phone", + description: "A phone number for the customer", + optional: true, + }, + timezone: { + type: "string", + label: "Timezone", + description: "Timezone of customer, should be in list of [TZ database names](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)", + optional: true, + }, + language: { + type: "string", + label: "Language", + description: "Two letter [code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) of customers language", + optional: true, + }, + address1: { + type: "string", + label: "Address Line 1", + description: "First line of address for customer", + optional: true, + }, + address2: { + type: "string", + label: "Address Line 2", + description: "Second line of address for customer", + optional: true, + }, + city: { + type: "string", + label: "City", + description: "City where customer lives", + optional: true, + }, + state: { + type: "string", + label: "State", + description: "State where customer lives", + optional: true, + }, + postalCode: { + type: "string", + label: "Postal Code", + description: "Postal code of customer's address", + optional: true, + }, + country: { + type: "string", + label: "Country", + description: "Country where customer lives", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return `https://rj2.rejoiner.com/api/v2/${this.$auth.site_id}`; + }, + _makeRequest(opts = {}) { + const { + $ = this, + path, + ...otherOpts + } = opts; + return axios($, { + url: `${this._baseUrl()}${path}`, + headers: { + "Authorization": `Rejoiner ${this.$auth.api_key}`, + "Content-Type": "application/json", + }, + ...otherOpts, + }); + }, + listLists(opts = {}) { + return this._makeRequest({ + path: "/lists", + ...opts, + }); + }, + listListContacts({ + listId, ...opts + }) { + return this._makeRequest({ + path: `/lists/${listId}/contacts/`, + ...opts, + }); + }, + addCustomerToList({ + listId, ...opts + }) { + return this._makeRequest({ + method: "POST", + path: `/lists/${listId}/contacts/`, + ...opts, + }); + }, + updateCustomerProfile(opts = {}) { + return this._makeRequest({ + method: "PUT", + path: "/customers/by_email/", + ...opts, + }); + }, + async *paginate({ + fn, + args, + max, + }) { + args = { + ...args, + params: { + ...args?.params, + page: 1, + }, + }; + let total, itemCount = 0; + + do { + const { + results, count, + } = await fn(args); + for (const item of results) { + yield item; + itemCount++; + if (max && itemCount >= max) { + return; + } + } + total = count; + args.params.page++; + } while (itemCount < total); }, }, }; diff --git a/components/rejoiner/sources/new-contact-in-list/new-contact-in-list.mjs b/components/rejoiner/sources/new-contact-in-list/new-contact-in-list.mjs new file mode 100644 index 0000000000000..5d49aa57d5078 --- /dev/null +++ b/components/rejoiner/sources/new-contact-in-list/new-contact-in-list.mjs @@ -0,0 +1,49 @@ +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; +import rejoiner from "../../rejoiner.app.mjs"; + +export default { + key: "rejoiner-new-contact-in-list", + name: "New Contact in List", + description: "Emit new event when a contact is added to the specified list. [See the documentation](https://docs.rejoiner.com/reference/retrieve-list-contacts).", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + rejoiner, + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + listId: { + propDefinition: [ + rejoiner, + "listId", + ], + }, + }, + methods: { + generateMeta(contact) { + return { + id: contact.id, + summary: contact.email, + ts: Date.now(), + }; + }, + }, + async run() { + const results = this.rejoiner.paginate({ + fn: this.rejoiner.listListContacts, + args: { + listId: this.listId, + }, + }); + + for await (const item of results) { + const contact = item.customer; + const meta = this.generateMeta(contact); + this.$emit(item, meta); + } + }, +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 021684e008992..f3a28652b6515 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8446,7 +8446,11 @@ importers: specifier: ^1.6.2 version: 1.6.6 - components/rejoiner: {} + components/rejoiner: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/relavate: dependencies: @@ -24525,22 +24529,22 @@ packages: superagent@3.8.1: resolution: {integrity: sha512-VMBFLYgFuRdfeNQSMLbxGSLfmXL/xc+OO+BZp41Za/NRDBet/BNbkRJrYzCUu0u4GU0i/ml2dtT8b9qgkw9z6Q==} engines: {node: '>= 4.0'} - 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 + deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . superagent@4.1.0: resolution: {integrity: sha512-FT3QLMasz0YyCd4uIi5HNe+3t/onxMyEho7C3PSqmti3Twgy2rXT4fmkTz6wRL6bTF4uzPcfkUCa8u4JWHw8Ag==} engines: {node: '>= 6.0'} - 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 + deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . superagent@5.3.1: resolution: {integrity: sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==} engines: {node: '>= 7.0.0'} - 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 + deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . superagent@7.1.6: resolution: {integrity: sha512-gZkVCQR1gy/oUXr+kxJMLDjla434KmSOKbx5iGD30Ql+AkJQ/YlPKECJy2nhqOsHLjGHzoDTXNSjhnvWhzKk7g==} engines: {node: '>=6.4.0 <13 || >=14'} - 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 + deprecated: Please downgrade to v7.1.5 if you need IE/ActiveXObject support OR upgrade to v8.0.0 as we no longer support IE and published an incorrect patch version (see https://github.com/visionmedia/superagent/issues/1731) supports-color@2.0.0: resolution: {integrity: sha512-KKNVtd6pCYgPIKU4cp2733HWYCpplQhddZLBUryaAHou723x+FRzQ5Df824Fj+IyyuiQTRoub4SnIFfIcrp70g==}