@trycourier/courier 3.5.0 → 3.8.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 +13 -0
- package/README.md +150 -32
- package/lib/client.js +3 -2
- package/lib/send/types.d.ts +44 -11
- package/lib/types.d.ts +2 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,19 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased][unreleased]
|
|
7
7
|
|
|
8
|
+
## [3.8.0] - 2022-03-14
|
|
9
|
+
|
|
10
|
+
- adds additional types for utm property (`message.metadata.utm`)
|
|
11
|
+
|
|
12
|
+
## [v3.7.0] - 2022-03-11
|
|
13
|
+
|
|
14
|
+
- adds additional types for the tags property (`message.metadata.tags`)
|
|
15
|
+
- adds support for searching message by tags
|
|
16
|
+
|
|
17
|
+
## [v3.6.0] - 2022-02-10
|
|
18
|
+
|
|
19
|
+
- adds additional types for the recipient property (`message.to`)
|
|
20
|
+
|
|
8
21
|
## [v3.5.0] - 2022-02-10
|
|
9
22
|
|
|
10
23
|
- 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 {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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 {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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 {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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 {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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(
|
|
195
|
+
console.log(requestId);
|
|
78
196
|
|
|
79
197
|
// Example: get a message status
|
|
80
|
-
const messageStatus = await courier.getMessage(
|
|
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(
|
|
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(
|
|
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 {
|
|
554
|
+
const { requestId } = await courier.send(
|
|
437
555
|
{
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
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(
|
|
570
|
+
console.log(requestId);
|
|
453
571
|
}
|
|
454
572
|
|
|
455
573
|
run();
|
package/lib/client.js
CHANGED
|
@@ -97,8 +97,9 @@ var getMessages = function (options) {
|
|
|
97
97
|
messageId: params === null || params === void 0 ? void 0 : params.messageId,
|
|
98
98
|
notification: params === null || params === void 0 ? void 0 : params.notificationId,
|
|
99
99
|
recipient: params === null || params === void 0 ? void 0 : params.recipientId,
|
|
100
|
-
status: params === null || params === void 0 ? void 0 : params.status
|
|
101
|
-
|
|
100
|
+
status: params === null || params === void 0 ? void 0 : params.status,
|
|
101
|
+
tags: params === null || params === void 0 ? void 0 : params.tags,
|
|
102
|
+
},
|
|
102
103
|
})];
|
|
103
104
|
case 1:
|
|
104
105
|
res = _a.sent();
|
package/lib/send/types.d.ts
CHANGED
|
@@ -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
|
-
|
|
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,18 +230,20 @@ export interface UserRecipient extends Record<string, any> {
|
|
|
205
230
|
phone_number?: string;
|
|
206
231
|
preferences?: IProfilePreferences;
|
|
207
232
|
}
|
|
208
|
-
export declare type
|
|
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[];
|
|
216
|
-
data?: MessageData;
|
|
217
241
|
channels?: MessageChannels;
|
|
242
|
+
data?: MessageData;
|
|
243
|
+
metadata?: MessageMetadata;
|
|
218
244
|
providers?: MessageProviders;
|
|
219
245
|
routing?: Routing;
|
|
246
|
+
to: MessageRecipient;
|
|
220
247
|
}
|
|
221
248
|
interface TrackingOverride {
|
|
222
249
|
open: boolean;
|
|
@@ -290,15 +317,21 @@ export interface RoutingStrategyProvider<T = Record<string, any>> {
|
|
|
290
317
|
config?: T;
|
|
291
318
|
if?: string;
|
|
292
319
|
}
|
|
293
|
-
export interface
|
|
320
|
+
export interface MessageMetadata {
|
|
294
321
|
event?: string;
|
|
322
|
+
tags?: string[];
|
|
323
|
+
utm?: {
|
|
324
|
+
source?: string;
|
|
325
|
+
medium?: string;
|
|
326
|
+
campaign?: string;
|
|
327
|
+
term?: string;
|
|
328
|
+
content?: string;
|
|
329
|
+
};
|
|
295
330
|
}
|
|
296
331
|
export interface ContentMessage extends BaseMessage {
|
|
297
332
|
content: Content;
|
|
298
|
-
metadata?: ContentMessageMetadata;
|
|
299
333
|
}
|
|
300
334
|
export interface TemplateMessage extends BaseMessage {
|
|
301
|
-
brand?: string;
|
|
302
335
|
template: string;
|
|
303
336
|
}
|
|
304
337
|
export declare type Message = ContentMessage | TemplateMessage;
|
package/lib/types.d.ts
CHANGED
|
@@ -96,6 +96,7 @@ export interface ICourierMessagesGetParameters {
|
|
|
96
96
|
notificationId?: string;
|
|
97
97
|
recipientId?: string;
|
|
98
98
|
status?: string | string[];
|
|
99
|
+
tags?: string | string[];
|
|
99
100
|
}
|
|
100
101
|
export interface ICourierMessagesGetResponse {
|
|
101
102
|
paging: ICourierPaging;
|
|
@@ -107,6 +108,7 @@ export interface ICourierMessagesGetResponse {
|
|
|
107
108
|
recipient: string;
|
|
108
109
|
sent?: number;
|
|
109
110
|
status: string;
|
|
111
|
+
tags?: string[];
|
|
110
112
|
}>;
|
|
111
113
|
}
|
|
112
114
|
export interface ICourierMessageGetResponse {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trycourier/courier",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.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",
|
|
@@ -33,4 +33,4 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"axios": "^0.21.1"
|
|
35
35
|
}
|
|
36
|
-
}
|
|
36
|
+
}
|