@trycourier/courier 3.4.0 → 3.7.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 +15 -1
- package/README.md +150 -32
- package/lib/client.js +3 -2
- package/lib/send/types.d.ts +38 -8
- package/lib/types.d.ts +7 -2
- 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
|
+
## [v3.7.0] - 2022-03-11
|
|
9
|
+
|
|
10
|
+
- adds additional types for the tags property (`message.tags`)
|
|
11
|
+
- adds support for searching message by tags
|
|
12
|
+
|
|
13
|
+
## [v3.6.0] - 2022-02-10
|
|
14
|
+
|
|
15
|
+
- adds additional types for the recipient property (`message.to`)
|
|
16
|
+
|
|
17
|
+
## [v3.5.0] - 2022-02-10
|
|
18
|
+
|
|
19
|
+
- adds type for unroutable status
|
|
20
|
+
|
|
8
21
|
## [v3.4.0] - 2022-01-25
|
|
9
22
|
|
|
10
23
|
- adds support for the send message object in the request body of a `/send` call
|
|
@@ -197,7 +210,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
197
210
|
|
|
198
211
|
## v1.0.1 - 2019-07-12
|
|
199
212
|
|
|
200
|
-
[unreleased]: https://github.com/trycourier/courier-node/compare/v3.
|
|
213
|
+
[unreleased]: https://github.com/trycourier/courier-node/compare/v3.5.0...HEAD
|
|
214
|
+
[v3.5.0]: https://github.com/trycourier/courier-node/compare/v3.4.0...v3.5.0
|
|
201
215
|
[v3.4.0]: https://github.com/trycourier/courier-node/compare/v3.3.0...v3.4.0
|
|
202
216
|
[v3.3.0]: https://github.com/trycourier/courier-node/compare/v3.2.1...v3.3.0
|
|
203
217
|
[v3.2.1]: https://github.com/trycourier/courier-node/compare/v3.2.0...v3.2.1
|
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,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
|
|
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
|
|
241
|
+
to: MessageRecipient;
|
|
216
242
|
data?: MessageData;
|
|
217
243
|
channels?: MessageChannels;
|
|
218
244
|
providers?: MessageProviders;
|
|
@@ -290,7 +316,10 @@ export interface RoutingStrategyProvider<T = Record<string, any>> {
|
|
|
290
316
|
config?: T;
|
|
291
317
|
if?: string;
|
|
292
318
|
}
|
|
293
|
-
export interface
|
|
319
|
+
export interface BaseMessageMetadata {
|
|
320
|
+
tags?: [string?, string?, string?, string?, string?, string?, string?, string?, string?];
|
|
321
|
+
}
|
|
322
|
+
export interface ContentMessageMetadata extends BaseMessageMetadata {
|
|
294
323
|
event?: string;
|
|
295
324
|
}
|
|
296
325
|
export interface ContentMessage extends BaseMessage {
|
|
@@ -299,6 +328,7 @@ export interface ContentMessage extends BaseMessage {
|
|
|
299
328
|
}
|
|
300
329
|
export interface TemplateMessage extends BaseMessage {
|
|
301
330
|
brand?: string;
|
|
331
|
+
metadata?: BaseMessageMetadata;
|
|
302
332
|
template: string;
|
|
303
333
|
}
|
|
304
334
|
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 {
|
|
@@ -145,7 +147,7 @@ export interface ICourierMessageGetResponse {
|
|
|
145
147
|
sent?: number;
|
|
146
148
|
status: MessageStatus;
|
|
147
149
|
}
|
|
148
|
-
export declare type MessageStatus = "CLICKED" | "DELIVERED" | "ENQUEUED" | "FILTERED" | "OPENED" | "SENT" | "SIMULATED" | "UNDELIVERABLE" | "UNMAPPED";
|
|
150
|
+
export declare type MessageStatus = "CLICKED" | "DELIVERED" | "ENQUEUED" | "FILTERED" | "OPENED" | "SENT" | "SIMULATED" | "UNDELIVERABLE" | "UNMAPPED" | "UNROUTABLE";
|
|
149
151
|
export declare type MessageHistoryType = MessageStatus | "DELIVERING" | "FILTERED" | "MAPPED" | "PROFILE_LOADED" | "RENDERED";
|
|
150
152
|
export declare type MessageStatusReason = "BOUNCED" | "FAILED" | "FILTERED" | "NO_CHANNELS" | "NO_PROVIDERS" | "OPT_IN_REQUIRED" | "PROVIDER_ERROR" | "UNPUBLISHED" | "UNSUBSCRIBED";
|
|
151
153
|
export declare type MessageStatusReasonCode = "HARD" | "SOFT";
|
|
@@ -186,6 +188,9 @@ export interface IRenderedMessageHistory extends IRoutedMessageHistory<"RENDERED
|
|
|
186
188
|
[key: string]: string;
|
|
187
189
|
};
|
|
188
190
|
}
|
|
191
|
+
export interface IUnroutableMessageHistory extends IMessageHistory<"UNROUTABLE"> {
|
|
192
|
+
reason: MessageStatusReason;
|
|
193
|
+
}
|
|
189
194
|
export interface IUndeliverableMessageHistory extends IMessageHistory<"UNDELIVERABLE">, Partial<Omit<IRoutedMessageHistory<"UNDELIVERABLE">, "ts" | "type">> {
|
|
190
195
|
reason: MessageStatusReason;
|
|
191
196
|
reasonCode?: MessageStatusReasonCode;
|
|
@@ -210,7 +215,7 @@ export interface IProviderErrorMessageHistory extends IRoutedMessageHistory<"UND
|
|
|
210
215
|
error_message: string;
|
|
211
216
|
}
|
|
212
217
|
export interface ICourierMessageGetHistoryResponse {
|
|
213
|
-
results: Array<IEnqueuedMessageHistory | IMappedMessageHistory | IProfileLoadedMessageHistory | IRenderedMessageHistory | IRoutedMessageHistory<RoutedMessageHistoryTypes> | IDeliveredMessageHistory | IProviderErrorMessageHistory | IUndeliverableMessageHistory>;
|
|
218
|
+
results: Array<IEnqueuedMessageHistory | IMappedMessageHistory | IProfileLoadedMessageHistory | IRenderedMessageHistory | IRoutedMessageHistory<RoutedMessageHistoryTypes> | IDeliveredMessageHistory | IProviderErrorMessageHistory | IUndeliverableMessageHistory | IUnroutableMessageHistory>;
|
|
214
219
|
}
|
|
215
220
|
export interface IApiMessageOutputItem {
|
|
216
221
|
channel: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trycourier/courier",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.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
|
+
}
|