@trycourier/courier 3.5.0 → 3.6.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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
6
  ## [Unreleased][unreleased]
7
7
 
8
+ ## [v3.6.0] - 2022-02-10
9
+
10
+ - adds additional type's for the recipient property (`message.to`)
11
+
8
12
  ## [v3.5.0] - 2022-02-10
9
13
 
10
14
  - adds type for unroutable status
package/README.md CHANGED
@@ -23,29 +23,142 @@ import { CourierClient } from "@trycourier/courier";
23
23
 
24
24
  const courier = CourierClient({ authorizationToken: "<AUTH_TOKEN>" }); // get from the Courier UI
25
25
 
26
+ // Example: send a basic message to an email recipient
27
+ const { requestId } = await courier.send({
28
+ message: {
29
+ to: {
30
+ data: {
31
+ name: "Marty",
32
+ },
33
+ email: "marty_mcfly@email.com",
34
+ },
35
+ content: {
36
+ title: "Back to the Future",
37
+ body: "Oh my {{name}}, we need 1.21 Gigawatts!",
38
+ },
39
+ routing: {
40
+ method: "single",
41
+ channels: ["email"],
42
+ },
43
+ },
44
+ });
45
+
46
+ // Example: send a basic message to an sms recipient
47
+ const { requestId } = await courier.send({
48
+ message: {
49
+ to: {
50
+ data: {
51
+ name: "Jenny",
52
+ },
53
+ phone_number: "8675309",
54
+ },
55
+ content: {
56
+ title: "Back to the Future",
57
+ body: "Oh my {{name}}, we need 1.21 Gigawatts!",
58
+ },
59
+ routing: {
60
+ method: "single",
61
+ channels: ["sms"],
62
+ },
63
+ },
64
+ });
65
+
66
+ // Example: send a message to various recipients
67
+ const { requestId } = await courier.send({
68
+ message: {
69
+ to: [
70
+ {
71
+ user_id: "<USER_ID>", // usually your system's User ID associated to a Courier profile
72
+ email: "test@email.com",
73
+ data: {
74
+ name: "some user's name",
75
+ },
76
+ },
77
+ {
78
+ email: "marty@email.com",
79
+ data: {
80
+ name: "Marty",
81
+ },
82
+ },
83
+ {
84
+ email: "doc_brown@email.com",
85
+ data: {
86
+ name: "Doc",
87
+ },
88
+ },
89
+ {
90
+ phone_number: "8675309",
91
+ data: {
92
+ name: "Jenny",
93
+ },
94
+ },
95
+ ],
96
+ content: {
97
+ title: "Back to the Future",
98
+ body: "Oh my {{name}}, we need 1.21 Gigawatts!",
99
+ },
100
+ routing: {
101
+ method: "all",
102
+ channels: ["sms", "email"],
103
+ },
104
+ },
105
+ });
106
+
26
107
  // Example: send a message supporting email & SMS
27
- const { messageId } = await courier.send({
28
- eventId: "<EVENT_ID>", // get from the Courier UI
29
- recipientId: "<RECIPIENT_ID>", // usually your system's User ID
30
- profile: {
31
- email: "example@example.com",
32
- phone_number: "555-228-3890",
108
+ const { requestId } = await courier.send({
109
+ message: {
110
+ template: "<TEMPLATE_OR_EVENT_ID>", // get from the Courier UI
111
+ to: {
112
+ user_Id: "<USER_ID>", // usually your system's User ID
113
+ email: "example@example.com",
114
+ phone_number: "555-228-3890",
115
+ },
116
+ data: {}, // optional variables for merging into templates
33
117
  },
34
- data: {}, // optional variables for merging into templates
35
118
  });
36
119
 
37
120
  // Example: send a message to a list
38
- const { messageId } = await courier.lists.send({
39
- event: "<EVENT_ID>", // get from the Courier UI
40
- list: "<LIST_ID>", // e.g. example.list.id
41
- data: {}, // optional variables for merging into templates
121
+ const { requestId } = await courier.send({
122
+ message: {
123
+ template: "<TEMPLATE_OR_EVENT_ID>", // get from the Courier UI
124
+ to: {
125
+ list_id: "<LIST_ID>", // e.g. your Courier List Id
126
+ },
127
+ data: {}, // optional variables for merging into templates
128
+ },
42
129
  });
43
130
 
44
131
  // Example: send a message to a pattern
45
- const { messageId } = await courier.lists.send({
46
- event: "<EVENT_ID>", // get from the Courier UI
47
- pattern: "<PATTERN>", // e.g. example.list.*
48
- data: {}, // optional variables for merging into templates
132
+ const { requestId } = await courier.send({
133
+ message: {
134
+ template: "<TEMPLATE_OR_EVENT_ID>", // get from the Courier UI
135
+ to: {
136
+ list_pattern: "<PATTERN>", // e.g. example.list.*
137
+ },
138
+ data: {}, // optional variables for merging into templates
139
+ },
140
+ });
141
+
142
+ // Example: send a message to a list, pattern and user
143
+ const { requestId } = await courier.send({
144
+ message: {
145
+ to: [
146
+ {
147
+ list_pattern: "<PATTERN>", // e.g. example.list.*
148
+ },
149
+ {
150
+ list_id: "<LIST_ID>", // e.g. your Courier List Id
151
+ },
152
+ {
153
+ email: "test@email.com"
154
+ }
155
+ ]
156
+ },
157
+ routing: {
158
+ method: "single",
159
+ channels: ["email"],
160
+ },
161
+ },
49
162
  });
50
163
  ```
51
164
 
@@ -65,27 +178,32 @@ const courier = CourierClient({ authorizationToken: "<AUTH_TOKEN>" });
65
178
 
66
179
  async function run() {
67
180
  // Example: send a message
68
- const { messageId } = await courier.send({
69
- eventId: "<EVENT_ID>",
70
- recipientId: "<RECIPIENT_ID>",
71
- profile: {}, // optional
72
- data: {}, // optional
73
- brand: "<BRAND_ID>", //optional
74
- preferences: {}, // optional
75
- override: {}, // optional
181
+ const { requestId } = await courier.send({
182
+ message: {
183
+ template: "<TEMPLATE_OR_EVENT_ID>",
184
+ to: {
185
+ // optional
186
+ user_id: "<RECIPIENT_ID>",
187
+ },
188
+ data: {}, // optional
189
+ brand_id: "<BRAND_ID>", //optional
190
+ routing: {},
191
+ channels: {}, // optional
192
+ providers: {}, // optional
193
+ },
76
194
  });
77
- console.log(messageId);
195
+ console.log(requestId);
78
196
 
79
197
  // Example: get a message status
80
- const messageStatus = await courier.getMessage(messageId);
198
+ const messageStatus = await courier.getMessage(requestId);
81
199
  console.log(messageStatus);
82
200
 
83
201
  // Example: get a message history
84
- const { results } = await courier.getMessageHistory(messageId);
202
+ const { results } = await courier.getMessageHistory(requestId);
85
203
  console.log(results);
86
204
 
87
205
  // Example: get a message output
88
- const { results } = await courier.getMessageOutput(messageId);
206
+ const { results } = await courier.getMessageOutput(requestId);
89
207
  console.log(results);
90
208
 
91
209
  // Example: get all messages
@@ -433,11 +551,11 @@ const courier = CourierClient();
433
551
  const idempotencyKey = uuid4();
434
552
 
435
553
  async function run() {
436
- const { messageId } = await courier.send(
554
+ const { requestId } = await courier.send(
437
555
  {
438
- eventId: "<EVENT_ID>",
439
- recipientId: "<RECIPIENT_ID>",
440
- profile: {
556
+ template: "<TEMPLATE_OR_EVENT_ID>",
557
+ to: {
558
+ user_id: "<USER_ID>",
441
559
  email: "example@example.com",
442
560
  phone_number: "555-867-5309",
443
561
  },
@@ -449,7 +567,7 @@ async function run() {
449
567
  idempotencyKey,
450
568
  }
451
569
  );
452
- console.log(messageId);
570
+ console.log(requestId);
453
571
  }
454
572
 
455
573
  run();
@@ -166,10 +166,6 @@ interface ElementalBaseNode {
166
166
  }
167
167
  export interface MessageData extends Record<string, any> {
168
168
  }
169
- interface ListRecipient {
170
- list_id: string;
171
- pattern?: string;
172
- }
173
169
  export declare type RuleType = "snooze" | "channel_preferences" | "status";
174
170
  export interface IRule<T extends RuleType> {
175
171
  type: T;
@@ -197,7 +193,36 @@ export interface IProfilePreferences {
197
193
  notifications: IPreferences;
198
194
  templateId?: string;
199
195
  }
200
- export interface UserRecipient extends Record<string, any> {
196
+ interface InvalidListRecipient {
197
+ user_id: string;
198
+ list_pattern: string;
199
+ }
200
+ declare type ListRecipientType = Record<string, unknown> & {
201
+ [key in keyof InvalidListRecipient]?: never;
202
+ };
203
+ export interface ListRecipient extends ListRecipientType {
204
+ list_id?: string;
205
+ data?: MessageData;
206
+ }
207
+ interface InvalidListPatternRecipient {
208
+ user_id: string;
209
+ list_id: string;
210
+ }
211
+ declare type ListPatternRecipientType = Record<string, unknown> & {
212
+ [key in keyof InvalidListPatternRecipient]?: never;
213
+ };
214
+ export interface ListPatternRecipient extends ListPatternRecipientType {
215
+ list_pattern?: string;
216
+ data?: MessageData;
217
+ }
218
+ interface InvalidUserRecipient {
219
+ list_id: string;
220
+ list_pattern: string;
221
+ }
222
+ declare type UserRecipientType = Record<string, unknown> & {
223
+ [key in keyof InvalidUserRecipient]?: never;
224
+ };
225
+ export interface UserRecipient extends UserRecipientType {
201
226
  data?: MessageData;
202
227
  email?: string;
203
228
  locale?: string;
@@ -205,14 +230,15 @@ export interface UserRecipient extends Record<string, any> {
205
230
  phone_number?: string;
206
231
  preferences?: IProfilePreferences;
207
232
  }
208
- export declare type MessageRecipient = ListRecipient | UserRecipient;
233
+ export declare type Recipient = ListRecipient | ListPatternRecipient | UserRecipient;
234
+ export declare type MessageRecipient = Recipient | Recipient[];
209
235
  export interface ElementalContentSugar {
210
236
  body?: string;
211
237
  title?: string;
212
238
  }
213
239
  export declare type Content = ElementalContentSugar | ElementalContent;
214
240
  export interface BaseMessage {
215
- to: MessageRecipient | MessageRecipient[];
241
+ to: MessageRecipient;
216
242
  data?: MessageData;
217
243
  channels?: MessageChannels;
218
244
  providers?: MessageProviders;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/courier",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "description": "A node.js module for communicating with the Courier REST API.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",