@pipedream/rejoiner 0.0.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,117 @@
1
+ import rejoiner from "../../rejoiner.app.mjs";
2
+
3
+ export default {
4
+ key: "rejoiner-add-customer-to-list",
5
+ name: "Add Customer to List",
6
+ 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)",
7
+ version: "0.0.2",
8
+ annotations: {
9
+ destructiveHint: true,
10
+ openWorldHint: true,
11
+ readOnlyHint: false,
12
+ },
13
+ type: "action",
14
+ props: {
15
+ rejoiner,
16
+ listId: {
17
+ propDefinition: [
18
+ rejoiner,
19
+ "listId",
20
+ ],
21
+ },
22
+ email: {
23
+ propDefinition: [
24
+ rejoiner,
25
+ "email",
26
+ ],
27
+ },
28
+ firstName: {
29
+ propDefinition: [
30
+ rejoiner,
31
+ "firstName",
32
+ ],
33
+ },
34
+ lastName: {
35
+ propDefinition: [
36
+ rejoiner,
37
+ "lastName",
38
+ ],
39
+ },
40
+ phone: {
41
+ propDefinition: [
42
+ rejoiner,
43
+ "phone",
44
+ ],
45
+ },
46
+ timezone: {
47
+ propDefinition: [
48
+ rejoiner,
49
+ "timezone",
50
+ ],
51
+ },
52
+ language: {
53
+ propDefinition: [
54
+ rejoiner,
55
+ "language",
56
+ ],
57
+ },
58
+ address1: {
59
+ propDefinition: [
60
+ rejoiner,
61
+ "address1",
62
+ ],
63
+ },
64
+ address2: {
65
+ propDefinition: [
66
+ rejoiner,
67
+ "address2",
68
+ ],
69
+ },
70
+ city: {
71
+ propDefinition: [
72
+ rejoiner,
73
+ "city",
74
+ ],
75
+ },
76
+ state: {
77
+ propDefinition: [
78
+ rejoiner,
79
+ "state",
80
+ ],
81
+ },
82
+ postalCode: {
83
+ propDefinition: [
84
+ rejoiner,
85
+ "postalCode",
86
+ ],
87
+ },
88
+ country: {
89
+ propDefinition: [
90
+ rejoiner,
91
+ "country",
92
+ ],
93
+ },
94
+ },
95
+ async run({ $ }) {
96
+ const response = await this.rejoiner.addCustomerToList({
97
+ $,
98
+ listId: this.listId,
99
+ data: {
100
+ email: this.email,
101
+ first_name: this.firstName,
102
+ last_name: this.lastName,
103
+ phone: this.phone,
104
+ timezone: this.timezone,
105
+ language: this.language,
106
+ address1: this.address1,
107
+ address2: this.address2,
108
+ city: this.city,
109
+ state: this.state,
110
+ postal_code: this.postalCode,
111
+ country: this.country,
112
+ },
113
+ });
114
+ $.export("$summary", `Added customer ${this.email} to list ${this.listId}`);
115
+ return response;
116
+ },
117
+ };
@@ -0,0 +1,26 @@
1
+ import rejoiner from "../../rejoiner.app.mjs";
2
+
3
+ export default {
4
+ key: "rejoiner-list-list-id-options",
5
+ name: "List List ID Options",
6
+ description: "Retrieves available options for the List ID field.",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ annotations: {
10
+ destructiveHint: false,
11
+ openWorldHint: true,
12
+ readOnlyHint: true,
13
+ },
14
+ props: {
15
+ rejoiner,
16
+ },
17
+ async run({ $ }) {
18
+ const options = await rejoiner.propDefinitions.listId.options.call(this.rejoiner, {});
19
+ $.export("$summary", `Successfully retrieved ${options.length} option${
20
+ options.length === 1
21
+ ? ""
22
+ : "s"
23
+ }`);
24
+ return options;
25
+ },
26
+ };
@@ -0,0 +1,51 @@
1
+ import rejoiner from "../../rejoiner.app.mjs";
2
+
3
+ export default {
4
+ key: "rejoiner-start-journey",
5
+ name: "Start Journey",
6
+ description: "Triggers the beginning of a customer journey in Rejoiner. [See the documentation](https://docs.rejoiner.com/reference/trigger-webhook-journey)",
7
+ version: "0.0.2",
8
+ annotations: {
9
+ destructiveHint: false,
10
+ openWorldHint: true,
11
+ readOnlyHint: false,
12
+ },
13
+ type: "action",
14
+ props: {
15
+ rejoiner,
16
+ webhookUrl: {
17
+ type: "string",
18
+ label: "Webhook Endpoint URL",
19
+ description: "Webhook URL of the journey. A webhook-triggered journey will provide an explicit Webhook Endpoint URL to be used for triggering the journey",
20
+ },
21
+ email: {
22
+ propDefinition: [
23
+ rejoiner,
24
+ "email",
25
+ ],
26
+ },
27
+ metadata: {
28
+ type: "object",
29
+ label: "Metadata",
30
+ description: "Metadata to be attached to the customer's journey session metadata",
31
+ optional: true,
32
+ },
33
+ },
34
+ async run({ $ }) {
35
+ const response = await this.rejoiner._makeRequest({
36
+ $,
37
+ method: "POST",
38
+ url: this.webhookUrl,
39
+ data: {
40
+ email: this.email,
41
+ session_data: this.metadata
42
+ ? typeof this.metadata === "string"
43
+ ? JSON.parse(this.metadata)
44
+ : this.metadata
45
+ : undefined,
46
+ },
47
+ });
48
+ $.export("$summary", `Triggered journey for customer ${this.email}`);
49
+ return response;
50
+ },
51
+ };
@@ -0,0 +1,112 @@
1
+ import rejoiner from "../../rejoiner.app.mjs";
2
+
3
+ export default {
4
+ key: "rejoiner-update-customer-profile",
5
+ name: "Update Customer Profile",
6
+ description: "Updates a customer's profile information. [See the documentation](https://docs.rejoiner.com/reference/update-customer-profile)",
7
+ version: "0.0.2",
8
+ annotations: {
9
+ destructiveHint: true,
10
+ openWorldHint: true,
11
+ readOnlyHint: false,
12
+ },
13
+ type: "action",
14
+ props: {
15
+ rejoiner,
16
+ email: {
17
+ propDefinition: [
18
+ rejoiner,
19
+ "email",
20
+ ],
21
+ },
22
+ firstName: {
23
+ propDefinition: [
24
+ rejoiner,
25
+ "firstName",
26
+ ],
27
+ },
28
+ lastName: {
29
+ propDefinition: [
30
+ rejoiner,
31
+ "lastName",
32
+ ],
33
+ },
34
+ phone: {
35
+ propDefinition: [
36
+ rejoiner,
37
+ "phone",
38
+ ],
39
+ },
40
+ timezone: {
41
+ propDefinition: [
42
+ rejoiner,
43
+ "timezone",
44
+ ],
45
+ },
46
+ language: {
47
+ propDefinition: [
48
+ rejoiner,
49
+ "language",
50
+ ],
51
+ },
52
+ address1: {
53
+ propDefinition: [
54
+ rejoiner,
55
+ "address1",
56
+ ],
57
+ },
58
+ address2: {
59
+ propDefinition: [
60
+ rejoiner,
61
+ "address2",
62
+ ],
63
+ },
64
+ city: {
65
+ propDefinition: [
66
+ rejoiner,
67
+ "city",
68
+ ],
69
+ },
70
+ state: {
71
+ propDefinition: [
72
+ rejoiner,
73
+ "state",
74
+ ],
75
+ },
76
+ postalCode: {
77
+ propDefinition: [
78
+ rejoiner,
79
+ "postalCode",
80
+ ],
81
+ },
82
+ country: {
83
+ propDefinition: [
84
+ rejoiner,
85
+ "country",
86
+ ],
87
+ },
88
+ },
89
+ async run({ $ }) {
90
+ const response = await this.rejoiner.updateCustomerProfile({
91
+ $,
92
+ params: {
93
+ email: this.email,
94
+ },
95
+ data: {
96
+ first_name: this.firstName,
97
+ last_name: this.lastName,
98
+ phone: this.phone,
99
+ timezone: this.timezone,
100
+ language: this.language,
101
+ address1: this.address1,
102
+ address2: this.address2,
103
+ city: this.city,
104
+ state: this.state,
105
+ postal_code: this.postalCode,
106
+ country: this.country,
107
+ },
108
+ });
109
+ $.export("$summary", `Updated customer profile for customer ${this.email}`);
110
+ return response;
111
+ },
112
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/rejoiner",
3
- "version": "0.0.1",
3
+ "version": "0.2.0",
4
4
  "description": "Pipedream Rejoiner Components",
5
5
  "main": "rejoiner.app.mjs",
6
6
  "keywords": [
@@ -11,5 +11,8 @@
11
11
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
12
12
  "publishConfig": {
13
13
  "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "@pipedream/platform": "^3.1.1"
14
17
  }
15
18
  }
package/rejoiner.app.mjs CHANGED
@@ -1,11 +1,172 @@
1
+ import { axios } from "@pipedream/platform";
2
+
1
3
  export default {
2
4
  type: "app",
3
5
  app: "rejoiner",
4
- propDefinitions: {},
6
+ propDefinitions: {
7
+ listId: {
8
+ type: "string",
9
+ label: "List ID",
10
+ description: "Unique identifier for the list",
11
+ async options() {
12
+ const lists = await this.listLists();
13
+ return lists?.map(({
14
+ id: value, name: label,
15
+ }) => ({
16
+ value,
17
+ label,
18
+ })) || [];
19
+ },
20
+ },
21
+ email: {
22
+ type: "string",
23
+ label: "Email",
24
+ description: "The email address of the customer",
25
+ },
26
+ firstName: {
27
+ type: "string",
28
+ label: "First Name",
29
+ description: "The first name of the customer",
30
+ optional: true,
31
+ },
32
+ lastName: {
33
+ type: "string",
34
+ label: "Last Name",
35
+ description: "The last name of the customer",
36
+ optional: true,
37
+ },
38
+ phone: {
39
+ type: "string",
40
+ label: "Phone",
41
+ description: "A phone number for the customer",
42
+ optional: true,
43
+ },
44
+ timezone: {
45
+ type: "string",
46
+ label: "Timezone",
47
+ description: "Timezone of customer, should be in list of [TZ database names](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)",
48
+ optional: true,
49
+ },
50
+ language: {
51
+ type: "string",
52
+ label: "Language",
53
+ description: "Two letter [code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) of customers language",
54
+ optional: true,
55
+ },
56
+ address1: {
57
+ type: "string",
58
+ label: "Address Line 1",
59
+ description: "First line of address for customer",
60
+ optional: true,
61
+ },
62
+ address2: {
63
+ type: "string",
64
+ label: "Address Line 2",
65
+ description: "Second line of address for customer",
66
+ optional: true,
67
+ },
68
+ city: {
69
+ type: "string",
70
+ label: "City",
71
+ description: "City where customer lives",
72
+ optional: true,
73
+ },
74
+ state: {
75
+ type: "string",
76
+ label: "State",
77
+ description: "State where customer lives",
78
+ optional: true,
79
+ },
80
+ postalCode: {
81
+ type: "string",
82
+ label: "Postal Code",
83
+ description: "Postal code of customer's address",
84
+ optional: true,
85
+ },
86
+ country: {
87
+ type: "string",
88
+ label: "Country",
89
+ description: "Country where customer lives",
90
+ optional: true,
91
+ },
92
+ },
5
93
  methods: {
6
- // this.$auth contains connected account data
7
- authKeys() {
8
- console.log(Object.keys(this.$auth));
94
+ _baseUrl() {
95
+ return `https://rj2.rejoiner.com/api/v2/${this.$auth.site_id}`;
96
+ },
97
+ _makeRequest(opts = {}) {
98
+ const {
99
+ $ = this,
100
+ path,
101
+ ...otherOpts
102
+ } = opts;
103
+ return axios($, {
104
+ url: `${this._baseUrl()}${path}`,
105
+ headers: {
106
+ "Authorization": `Rejoiner ${this.$auth.api_key}`,
107
+ "Content-Type": "application/json",
108
+ },
109
+ ...otherOpts,
110
+ });
111
+ },
112
+ listLists(opts = {}) {
113
+ return this._makeRequest({
114
+ path: "/lists",
115
+ ...opts,
116
+ });
117
+ },
118
+ listListContacts({
119
+ listId, ...opts
120
+ }) {
121
+ return this._makeRequest({
122
+ path: `/lists/${listId}/contacts/`,
123
+ ...opts,
124
+ });
125
+ },
126
+ addCustomerToList({
127
+ listId, ...opts
128
+ }) {
129
+ return this._makeRequest({
130
+ method: "POST",
131
+ path: `/lists/${listId}/contacts/`,
132
+ ...opts,
133
+ });
134
+ },
135
+ updateCustomerProfile(opts = {}) {
136
+ return this._makeRequest({
137
+ method: "PUT",
138
+ path: "/customers/by_email/",
139
+ ...opts,
140
+ });
141
+ },
142
+ async *paginate({
143
+ fn,
144
+ args,
145
+ max,
146
+ }) {
147
+ args = {
148
+ ...args,
149
+ params: {
150
+ ...args?.params,
151
+ page: 1,
152
+ },
153
+ };
154
+ let total, itemCount = 0;
155
+
156
+ do {
157
+ const {
158
+ results, count,
159
+ } = await fn(args);
160
+ for (const item of results) {
161
+ yield item;
162
+ itemCount++;
163
+ if (max && itemCount >= max) {
164
+ return;
165
+ }
166
+ }
167
+ total = count;
168
+ args.params.page++;
169
+ } while (itemCount < total);
9
170
  },
10
171
  },
11
- };
172
+ };
@@ -0,0 +1,49 @@
1
+ import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2
+ import rejoiner from "../../rejoiner.app.mjs";
3
+
4
+ export default {
5
+ key: "rejoiner-new-contact-in-list",
6
+ name: "New Contact in List",
7
+ description: "Emit new event when a contact is added to the specified list. [See the documentation](https://docs.rejoiner.com/reference/retrieve-list-contacts).",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ props: {
12
+ rejoiner,
13
+ timer: {
14
+ type: "$.interface.timer",
15
+ default: {
16
+ intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
17
+ },
18
+ },
19
+ listId: {
20
+ propDefinition: [
21
+ rejoiner,
22
+ "listId",
23
+ ],
24
+ },
25
+ },
26
+ methods: {
27
+ generateMeta(contact) {
28
+ return {
29
+ id: contact.id,
30
+ summary: contact.email,
31
+ ts: Date.now(),
32
+ };
33
+ },
34
+ },
35
+ async run() {
36
+ const results = this.rejoiner.paginate({
37
+ fn: this.rejoiner.listListContacts,
38
+ args: {
39
+ listId: this.listId,
40
+ },
41
+ });
42
+
43
+ for await (const item of results) {
44
+ const contact = item.customer;
45
+ const meta = this.generateMeta(contact);
46
+ this.$emit(item, meta);
47
+ }
48
+ },
49
+ };