@trycourier/courier 3.3.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 +15 -1
- package/README.md +150 -32
- package/lib/client.js +2 -33
- package/lib/send/index.d.ts +2 -0
- package/lib/send/index.js +100 -0
- package/lib/send/types.d.ts +334 -0
- package/lib/send/types.js +2 -0
- package/lib/types.d.ts +14 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,18 @@ 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
|
+
|
|
12
|
+
## [v3.5.0] - 2022-02-10
|
|
13
|
+
|
|
14
|
+
- adds type for unroutable status
|
|
15
|
+
|
|
16
|
+
## [v3.4.0] - 2022-01-25
|
|
17
|
+
|
|
18
|
+
- adds support for the send message object in the request body of a `/send` call
|
|
19
|
+
|
|
8
20
|
## [v3.3.0] - 2022-01-25
|
|
9
21
|
|
|
10
22
|
- adds support for bulk processing endpoints
|
|
@@ -193,7 +205,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
193
205
|
|
|
194
206
|
## v1.0.1 - 2019-07-12
|
|
195
207
|
|
|
196
|
-
[unreleased]: https://github.com/trycourier/courier-node/compare/v3.
|
|
208
|
+
[unreleased]: https://github.com/trycourier/courier-node/compare/v3.5.0...HEAD
|
|
209
|
+
[v3.5.0]: https://github.com/trycourier/courier-node/compare/v3.4.0...v3.5.0
|
|
210
|
+
[v3.4.0]: https://github.com/trycourier/courier-node/compare/v3.3.0...v3.4.0
|
|
197
211
|
[v3.3.0]: https://github.com/trycourier/courier-node/compare/v3.2.1...v3.3.0
|
|
198
212
|
[v3.2.1]: https://github.com/trycourier/courier-node/compare/v3.2.0...v3.2.1
|
|
199
213
|
[v3.2.0]: https://github.com/trycourier/courier-node/compare/v3.1.0...v3.2.0
|
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
|
@@ -44,38 +44,7 @@ var lists_1 = require("./lists");
|
|
|
44
44
|
var notifications_1 = require("./notifications");
|
|
45
45
|
var preferences_1 = require("./preferences");
|
|
46
46
|
var profile_1 = require("./profile");
|
|
47
|
-
var
|
|
48
|
-
return function (params, config) { return __awaiter(void 0, void 0, void 0, function () {
|
|
49
|
-
var axiosConfig, res;
|
|
50
|
-
return __generator(this, function (_a) {
|
|
51
|
-
switch (_a.label) {
|
|
52
|
-
case 0:
|
|
53
|
-
axiosConfig = {
|
|
54
|
-
headers: {}
|
|
55
|
-
};
|
|
56
|
-
if (config && config.idempotencyKey) {
|
|
57
|
-
axiosConfig.headers["Idempotency-Key"] = config.idempotencyKey;
|
|
58
|
-
}
|
|
59
|
-
if (config && config.idempotencyExpiry) {
|
|
60
|
-
axiosConfig.headers["x-idempotency-expiration"] =
|
|
61
|
-
config.idempotencyExpiry;
|
|
62
|
-
}
|
|
63
|
-
return [4 /*yield*/, options.httpClient.post("/send", {
|
|
64
|
-
brand: params.brand,
|
|
65
|
-
data: params.data,
|
|
66
|
-
event: params.eventId,
|
|
67
|
-
override: params.override,
|
|
68
|
-
preferences: params.preferences,
|
|
69
|
-
profile: params.profile,
|
|
70
|
-
recipient: params.recipientId
|
|
71
|
-
}, axiosConfig)];
|
|
72
|
-
case 1:
|
|
73
|
-
res = _a.sent();
|
|
74
|
-
return [2 /*return*/, res.data];
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}); };
|
|
78
|
-
};
|
|
47
|
+
var send_1 = require("./send");
|
|
79
48
|
var getMessage = function (options) {
|
|
80
49
|
return function (messageId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
81
50
|
var res;
|
|
@@ -161,6 +130,6 @@ exports.client = function (options) {
|
|
|
161
130
|
removeRecipientFromAllLists: profile_1.removeRecipientFromAllLists(options),
|
|
162
131
|
replaceBrand: brands_1.replaceBrand(options),
|
|
163
132
|
replaceProfile: profile_1.replaceProfile(options),
|
|
164
|
-
send: send(options)
|
|
133
|
+
send: send_1.send(options)
|
|
165
134
|
};
|
|
166
135
|
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { ICourierClientConfiguration, ICourierSendConfig, ICourierSendMessageParameters, ICourierSendParameters, SendResponse } from "../types";
|
|
2
|
+
export declare const send: (options: ICourierClientConfiguration) => <T extends ICourierSendParameters | ICourierSendMessageParameters>(params: T, config?: ICourierSendConfig | undefined) => Promise<SendResponse<T>>;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.send = void 0;
|
|
40
|
+
var sendCall = function (options, config, params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
41
|
+
var res;
|
|
42
|
+
return __generator(this, function (_a) {
|
|
43
|
+
switch (_a.label) {
|
|
44
|
+
case 0: return [4 /*yield*/, options.httpClient.post("/send", {
|
|
45
|
+
brand: params.brand,
|
|
46
|
+
data: params.data,
|
|
47
|
+
event: params.eventId,
|
|
48
|
+
override: params.override,
|
|
49
|
+
preferences: params.preferences,
|
|
50
|
+
profile: params.profile,
|
|
51
|
+
recipient: params.recipientId
|
|
52
|
+
}, config)];
|
|
53
|
+
case 1:
|
|
54
|
+
res = _a.sent();
|
|
55
|
+
return [2 /*return*/, res.data];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}); };
|
|
59
|
+
var sendMessageCall = function (options, config, params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
60
|
+
var res;
|
|
61
|
+
return __generator(this, function (_a) {
|
|
62
|
+
switch (_a.label) {
|
|
63
|
+
case 0: return [4 /*yield*/, options.httpClient.post("/send", {
|
|
64
|
+
message: params.message
|
|
65
|
+
}, config)];
|
|
66
|
+
case 1:
|
|
67
|
+
res = _a.sent();
|
|
68
|
+
return [2 /*return*/, res.data];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}); };
|
|
72
|
+
exports.send = function (options) {
|
|
73
|
+
return function (params, config) { return __awaiter(void 0, void 0, void 0, function () {
|
|
74
|
+
var axiosConfig, v2Response, v1Response;
|
|
75
|
+
return __generator(this, function (_a) {
|
|
76
|
+
switch (_a.label) {
|
|
77
|
+
case 0:
|
|
78
|
+
axiosConfig = {
|
|
79
|
+
headers: {}
|
|
80
|
+
};
|
|
81
|
+
if (config && config.idempotencyKey) {
|
|
82
|
+
axiosConfig.headers["Idempotency-Key"] = config.idempotencyKey;
|
|
83
|
+
}
|
|
84
|
+
if (config && config.idempotencyExpiry) {
|
|
85
|
+
axiosConfig.headers["x-idempotency-expiration"] =
|
|
86
|
+
config.idempotencyExpiry;
|
|
87
|
+
}
|
|
88
|
+
if (!params.message) return [3 /*break*/, 2];
|
|
89
|
+
return [4 /*yield*/, sendMessageCall(options, axiosConfig, params)];
|
|
90
|
+
case 1:
|
|
91
|
+
v2Response = _a.sent();
|
|
92
|
+
return [2 /*return*/, v2Response];
|
|
93
|
+
case 2: return [4 /*yield*/, sendCall(options, axiosConfig, params)];
|
|
94
|
+
case 3:
|
|
95
|
+
v1Response = _a.sent();
|
|
96
|
+
return [2 /*return*/, v1Response];
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}); };
|
|
100
|
+
};
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
export interface IBrandSnippet {
|
|
2
|
+
format: "handlebars";
|
|
3
|
+
name: string;
|
|
4
|
+
value: string;
|
|
5
|
+
}
|
|
6
|
+
export interface IBrandSnippets {
|
|
7
|
+
items: IBrandSnippet[];
|
|
8
|
+
}
|
|
9
|
+
export interface IBrandColors {
|
|
10
|
+
primary?: string;
|
|
11
|
+
secondary?: string;
|
|
12
|
+
tertiary?: string;
|
|
13
|
+
}
|
|
14
|
+
interface IBrandTemplate {
|
|
15
|
+
backgroundColor?: string;
|
|
16
|
+
blocksBackgroundColor?: string;
|
|
17
|
+
enabled: boolean;
|
|
18
|
+
footer?: string;
|
|
19
|
+
head?: string;
|
|
20
|
+
header?: string;
|
|
21
|
+
width?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface IBrandTemplateOverride extends IBrandTemplate {
|
|
24
|
+
mjml?: IBrandTemplate;
|
|
25
|
+
footerBackgroundColor?: string;
|
|
26
|
+
footerFullWidth?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface IBrandSettingsSocialPresence {
|
|
29
|
+
inheritDefault?: boolean;
|
|
30
|
+
facebook?: {
|
|
31
|
+
url: string;
|
|
32
|
+
};
|
|
33
|
+
instagram?: {
|
|
34
|
+
url: string;
|
|
35
|
+
};
|
|
36
|
+
linkedin?: {
|
|
37
|
+
url: string;
|
|
38
|
+
};
|
|
39
|
+
medium?: {
|
|
40
|
+
url: string;
|
|
41
|
+
};
|
|
42
|
+
twitter?: {
|
|
43
|
+
url: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export interface IBrandSettingsEmail {
|
|
47
|
+
templateOverride?: IBrandTemplateOverride;
|
|
48
|
+
head?: {
|
|
49
|
+
inheritDefault: boolean;
|
|
50
|
+
content?: string;
|
|
51
|
+
};
|
|
52
|
+
footer?: {
|
|
53
|
+
content?: object;
|
|
54
|
+
inheritDefault?: boolean;
|
|
55
|
+
markdown?: string;
|
|
56
|
+
social?: IBrandSettingsSocialPresence;
|
|
57
|
+
};
|
|
58
|
+
header?: {
|
|
59
|
+
inheritDefault?: boolean;
|
|
60
|
+
barColor?: string;
|
|
61
|
+
logo?: {
|
|
62
|
+
href?: string;
|
|
63
|
+
image?: string;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export interface IBrandSettingsInApp {
|
|
68
|
+
borderRadius?: string;
|
|
69
|
+
disableMessageIcon?: boolean;
|
|
70
|
+
fontFamily?: string;
|
|
71
|
+
placement?: "top" | "bottom" | "left" | "right";
|
|
72
|
+
widgetBackground?: {
|
|
73
|
+
topColor?: string;
|
|
74
|
+
bottomColor?: string;
|
|
75
|
+
};
|
|
76
|
+
colors?: {
|
|
77
|
+
invertHeader?: boolean;
|
|
78
|
+
invertButtons?: boolean;
|
|
79
|
+
};
|
|
80
|
+
icons?: {
|
|
81
|
+
bell?: string;
|
|
82
|
+
message?: string;
|
|
83
|
+
};
|
|
84
|
+
preferences?: {
|
|
85
|
+
templateIds: string[];
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export declare type IActionButtonStyle = "button" | "link";
|
|
89
|
+
export declare type IAlignment = "center" | "left" | "right" | "full";
|
|
90
|
+
export interface ElementalContent {
|
|
91
|
+
version: "2022-01-01";
|
|
92
|
+
brand?: any;
|
|
93
|
+
elements: ElementalNode[];
|
|
94
|
+
}
|
|
95
|
+
export declare type ElementalNode = ElementalTextNode | ElementalMetaNode | ElementalChannelNode | ElementalImageNode | ElementalActionNode | ElementalDividerNode | ElementalGroupNode | ElementalQuoteNode;
|
|
96
|
+
export interface ElementalTextNode extends ElementalBaseNode {
|
|
97
|
+
type: "text";
|
|
98
|
+
content: string;
|
|
99
|
+
format?: "markdown";
|
|
100
|
+
locales?: {
|
|
101
|
+
[locale: string]: {
|
|
102
|
+
content: string;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export interface ElementalMetaNode extends ElementalBaseNode {
|
|
107
|
+
type: "meta";
|
|
108
|
+
title?: string;
|
|
109
|
+
}
|
|
110
|
+
export interface ElementalChannelNode extends ElementalBaseNode {
|
|
111
|
+
type: "channel";
|
|
112
|
+
channel: string;
|
|
113
|
+
elements?: ElementalNode[];
|
|
114
|
+
raw?: {
|
|
115
|
+
[templateName: string]: any;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
export interface ElementalImageNode extends ElementalBaseNode {
|
|
119
|
+
type: "image";
|
|
120
|
+
src: string;
|
|
121
|
+
href?: string;
|
|
122
|
+
align?: IAlignment;
|
|
123
|
+
altText?: string;
|
|
124
|
+
width?: string;
|
|
125
|
+
}
|
|
126
|
+
export interface ElementalActionNode extends ElementalBaseNode {
|
|
127
|
+
type: "action";
|
|
128
|
+
content: string;
|
|
129
|
+
href: string;
|
|
130
|
+
actionId?: string;
|
|
131
|
+
style?: IActionButtonStyle;
|
|
132
|
+
align?: IAlignment;
|
|
133
|
+
backgroundColor?: string;
|
|
134
|
+
locales?: {
|
|
135
|
+
[locale: string]: {
|
|
136
|
+
content: string;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
export interface ElementalDividerNode extends ElementalBaseNode {
|
|
141
|
+
type: "divider";
|
|
142
|
+
color?: string;
|
|
143
|
+
}
|
|
144
|
+
export interface ElementalGroupNode extends ElementalBaseNode {
|
|
145
|
+
type: "group";
|
|
146
|
+
elements: ElementalNode[];
|
|
147
|
+
}
|
|
148
|
+
export interface ElementalQuoteNode extends ElementalBaseNode {
|
|
149
|
+
type: "quote";
|
|
150
|
+
content: string;
|
|
151
|
+
align?: IAlignment;
|
|
152
|
+
borderColor?: string;
|
|
153
|
+
textStyle?: "text" | "h1" | "h2" | "subtext";
|
|
154
|
+
locales?: {
|
|
155
|
+
[locale: string]: {
|
|
156
|
+
content: string;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
interface ElementalBaseNode {
|
|
161
|
+
type: string;
|
|
162
|
+
channels?: string[];
|
|
163
|
+
ref?: string;
|
|
164
|
+
if?: string;
|
|
165
|
+
loop?: string;
|
|
166
|
+
}
|
|
167
|
+
export interface MessageData extends Record<string, any> {
|
|
168
|
+
}
|
|
169
|
+
export declare type RuleType = "snooze" | "channel_preferences" | "status";
|
|
170
|
+
export interface IRule<T extends RuleType> {
|
|
171
|
+
type: T;
|
|
172
|
+
}
|
|
173
|
+
export interface ISnoozeRule extends IRule<"snooze"> {
|
|
174
|
+
start?: string;
|
|
175
|
+
until: string;
|
|
176
|
+
}
|
|
177
|
+
export declare type Rule = ISnoozeRule;
|
|
178
|
+
export declare type PreferenceStatus = "OPTED_IN" | "OPTED_OUT" | "REQUIRED";
|
|
179
|
+
export declare type ChannelClassification = "direct_message" | "email" | "push";
|
|
180
|
+
export interface IPreference {
|
|
181
|
+
status: PreferenceStatus;
|
|
182
|
+
rules?: Rule[];
|
|
183
|
+
channel_preferences?: Array<{
|
|
184
|
+
channel: ChannelClassification;
|
|
185
|
+
}>;
|
|
186
|
+
source?: "subscription" | "list" | "recipient";
|
|
187
|
+
}
|
|
188
|
+
export interface IPreferences {
|
|
189
|
+
[id: string]: IPreference;
|
|
190
|
+
}
|
|
191
|
+
export interface IProfilePreferences {
|
|
192
|
+
categories?: IPreferences;
|
|
193
|
+
notifications: IPreferences;
|
|
194
|
+
templateId?: string;
|
|
195
|
+
}
|
|
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 {
|
|
226
|
+
data?: MessageData;
|
|
227
|
+
email?: string;
|
|
228
|
+
locale?: string;
|
|
229
|
+
user_id?: string;
|
|
230
|
+
phone_number?: string;
|
|
231
|
+
preferences?: IProfilePreferences;
|
|
232
|
+
}
|
|
233
|
+
export declare type Recipient = ListRecipient | ListPatternRecipient | UserRecipient;
|
|
234
|
+
export declare type MessageRecipient = Recipient | Recipient[];
|
|
235
|
+
export interface ElementalContentSugar {
|
|
236
|
+
body?: string;
|
|
237
|
+
title?: string;
|
|
238
|
+
}
|
|
239
|
+
export declare type Content = ElementalContentSugar | ElementalContent;
|
|
240
|
+
export interface BaseMessage {
|
|
241
|
+
to: MessageRecipient;
|
|
242
|
+
data?: MessageData;
|
|
243
|
+
channels?: MessageChannels;
|
|
244
|
+
providers?: MessageProviders;
|
|
245
|
+
routing?: Routing;
|
|
246
|
+
}
|
|
247
|
+
interface TrackingOverride {
|
|
248
|
+
open: boolean;
|
|
249
|
+
}
|
|
250
|
+
export interface MessageProviders {
|
|
251
|
+
[key: string]: {
|
|
252
|
+
override?: Record<string, any>;
|
|
253
|
+
if?: string;
|
|
254
|
+
timeouts?: number;
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
export interface MessageChannelEmailOverride {
|
|
258
|
+
attachments?: Record<string, any>[];
|
|
259
|
+
bcc?: string;
|
|
260
|
+
brand?: {
|
|
261
|
+
snippets?: IBrandSnippets;
|
|
262
|
+
settings?: {
|
|
263
|
+
colors?: IBrandColors;
|
|
264
|
+
email?: IBrandSettingsEmail;
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
cc?: string;
|
|
268
|
+
from?: string;
|
|
269
|
+
html?: string;
|
|
270
|
+
reply_to?: string;
|
|
271
|
+
subject?: string;
|
|
272
|
+
text?: string;
|
|
273
|
+
tracking?: TrackingOverride;
|
|
274
|
+
}
|
|
275
|
+
export interface MessageChannelPushOverride {
|
|
276
|
+
body?: string;
|
|
277
|
+
brand?: {
|
|
278
|
+
snippets?: IBrandSnippets;
|
|
279
|
+
settings?: {
|
|
280
|
+
colors?: IBrandColors;
|
|
281
|
+
inapp?: IBrandSettingsInApp;
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
click_action?: string;
|
|
285
|
+
data?: Record<string, any>;
|
|
286
|
+
icon?: string;
|
|
287
|
+
title?: string;
|
|
288
|
+
}
|
|
289
|
+
export interface MessageChannels {
|
|
290
|
+
[key: string]: {
|
|
291
|
+
brand_id?: string;
|
|
292
|
+
providers?: string[];
|
|
293
|
+
routing_method?: "all" | "single";
|
|
294
|
+
if?: string;
|
|
295
|
+
timeouts?: {
|
|
296
|
+
provider?: number;
|
|
297
|
+
channel?: number;
|
|
298
|
+
};
|
|
299
|
+
override?: MessageChannelEmailOverride | MessageChannelPushOverride;
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
export interface Routing {
|
|
303
|
+
method: "all" | "single";
|
|
304
|
+
channels: RoutingChannel[];
|
|
305
|
+
}
|
|
306
|
+
export declare type RoutingChannel = RoutingStrategyChannel | RoutingStrategyProvider | string;
|
|
307
|
+
export interface RoutingStrategyChannel<T = Record<string, any>> {
|
|
308
|
+
channel: string;
|
|
309
|
+
config?: T;
|
|
310
|
+
method?: "all" | "single";
|
|
311
|
+
providers?: (RoutingStrategyProvider | string)[];
|
|
312
|
+
if?: string;
|
|
313
|
+
}
|
|
314
|
+
export interface RoutingStrategyProvider<T = Record<string, any>> {
|
|
315
|
+
name: string;
|
|
316
|
+
config?: T;
|
|
317
|
+
if?: string;
|
|
318
|
+
}
|
|
319
|
+
export interface ContentMessageMetadata {
|
|
320
|
+
event?: string;
|
|
321
|
+
}
|
|
322
|
+
export interface ContentMessage extends BaseMessage {
|
|
323
|
+
content: Content;
|
|
324
|
+
metadata?: ContentMessageMetadata;
|
|
325
|
+
}
|
|
326
|
+
export interface TemplateMessage extends BaseMessage {
|
|
327
|
+
brand?: string;
|
|
328
|
+
template: string;
|
|
329
|
+
}
|
|
330
|
+
export declare type Message = ContentMessage | TemplateMessage;
|
|
331
|
+
export interface RequestV2 {
|
|
332
|
+
message: Message;
|
|
333
|
+
}
|
|
334
|
+
export {};
|
package/lib/types.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { ICourierClientBulk } from "./bulk/types";
|
|
|
4
4
|
import { ICourierClientLists, ICourierList, ICourierRecipientSubscriptionsResponse } from "./lists/types";
|
|
5
5
|
import { ICourierClientNotifications } from "./notifications/types";
|
|
6
6
|
import { ICourierClientPreferences, IRecipientPreferences } from "./preferences/types";
|
|
7
|
+
import { Message } from "./send/types";
|
|
7
8
|
export declare type HttpMethodClient = <T>(url: string, body?: object, config?: AxiosRequestConfig) => Promise<{
|
|
8
9
|
data: T;
|
|
9
10
|
}>;
|
|
@@ -30,6 +31,9 @@ export interface ICourierSendParameters {
|
|
|
30
31
|
profile?: object;
|
|
31
32
|
override?: object;
|
|
32
33
|
}
|
|
34
|
+
export interface ICourierSendMessageParameters {
|
|
35
|
+
message: Message;
|
|
36
|
+
}
|
|
33
37
|
export interface ICourierSendConfig {
|
|
34
38
|
idempotencyKey?: string;
|
|
35
39
|
idempotencyExpiry?: number;
|
|
@@ -37,6 +41,9 @@ export interface ICourierSendConfig {
|
|
|
37
41
|
export interface ICourierSendResponse {
|
|
38
42
|
messageId: string;
|
|
39
43
|
}
|
|
44
|
+
export interface ICourierSendMessageResponse {
|
|
45
|
+
requestId: string;
|
|
46
|
+
}
|
|
40
47
|
export interface ICourierSendParams {
|
|
41
48
|
event: string;
|
|
42
49
|
data?: object;
|
|
@@ -138,7 +145,7 @@ export interface ICourierMessageGetResponse {
|
|
|
138
145
|
sent?: number;
|
|
139
146
|
status: MessageStatus;
|
|
140
147
|
}
|
|
141
|
-
export declare type MessageStatus = "CLICKED" | "DELIVERED" | "ENQUEUED" | "FILTERED" | "OPENED" | "SENT" | "SIMULATED" | "UNDELIVERABLE" | "UNMAPPED";
|
|
148
|
+
export declare type MessageStatus = "CLICKED" | "DELIVERED" | "ENQUEUED" | "FILTERED" | "OPENED" | "SENT" | "SIMULATED" | "UNDELIVERABLE" | "UNMAPPED" | "UNROUTABLE";
|
|
142
149
|
export declare type MessageHistoryType = MessageStatus | "DELIVERING" | "FILTERED" | "MAPPED" | "PROFILE_LOADED" | "RENDERED";
|
|
143
150
|
export declare type MessageStatusReason = "BOUNCED" | "FAILED" | "FILTERED" | "NO_CHANNELS" | "NO_PROVIDERS" | "OPT_IN_REQUIRED" | "PROVIDER_ERROR" | "UNPUBLISHED" | "UNSUBSCRIBED";
|
|
144
151
|
export declare type MessageStatusReasonCode = "HARD" | "SOFT";
|
|
@@ -179,6 +186,9 @@ export interface IRenderedMessageHistory extends IRoutedMessageHistory<"RENDERED
|
|
|
179
186
|
[key: string]: string;
|
|
180
187
|
};
|
|
181
188
|
}
|
|
189
|
+
export interface IUnroutableMessageHistory extends IMessageHistory<"UNROUTABLE"> {
|
|
190
|
+
reason: MessageStatusReason;
|
|
191
|
+
}
|
|
182
192
|
export interface IUndeliverableMessageHistory extends IMessageHistory<"UNDELIVERABLE">, Partial<Omit<IRoutedMessageHistory<"UNDELIVERABLE">, "ts" | "type">> {
|
|
183
193
|
reason: MessageStatusReason;
|
|
184
194
|
reasonCode?: MessageStatusReasonCode;
|
|
@@ -203,7 +213,7 @@ export interface IProviderErrorMessageHistory extends IRoutedMessageHistory<"UND
|
|
|
203
213
|
error_message: string;
|
|
204
214
|
}
|
|
205
215
|
export interface ICourierMessageGetHistoryResponse {
|
|
206
|
-
results: Array<IEnqueuedMessageHistory | IMappedMessageHistory | IProfileLoadedMessageHistory | IRenderedMessageHistory | IRoutedMessageHistory<RoutedMessageHistoryTypes> | IDeliveredMessageHistory | IProviderErrorMessageHistory | IUndeliverableMessageHistory>;
|
|
216
|
+
results: Array<IEnqueuedMessageHistory | IMappedMessageHistory | IProfileLoadedMessageHistory | IRenderedMessageHistory | IRoutedMessageHistory<RoutedMessageHistoryTypes> | IDeliveredMessageHistory | IProviderErrorMessageHistory | IUndeliverableMessageHistory | IUnroutableMessageHistory>;
|
|
207
217
|
}
|
|
208
218
|
export interface IApiMessageOutputItem {
|
|
209
219
|
channel: string;
|
|
@@ -271,6 +281,7 @@ export interface ICourierBrandGetAllResponse {
|
|
|
271
281
|
paging: ICourierPaging;
|
|
272
282
|
results: ICourierBrand[];
|
|
273
283
|
}
|
|
284
|
+
export declare type SendResponse<T extends ICourierSendParameters | ICourierSendMessageParameters> = T extends ICourierSendParameters ? ICourierSendResponse : ICourierSendMessageResponse;
|
|
274
285
|
export interface ICourierClient {
|
|
275
286
|
addRecipientToLists: (params: ICourierProfileListsPostParameters) => Promise<ICourierProfilePostResponse>;
|
|
276
287
|
automations: ICourierClientAutomations;
|
|
@@ -295,6 +306,6 @@ export interface ICourierClient {
|
|
|
295
306
|
removeRecipientFromAllLists: (params: ICourierProfileGetParameters) => Promise<ICourierProfilePostResponse>;
|
|
296
307
|
replaceBrand: (params: ICourierBrandPutParameters) => Promise<ICourierBrand>;
|
|
297
308
|
replaceProfile: (params: ICourierProfilePutParameters) => Promise<ICourierProfilePutResponse>;
|
|
298
|
-
send: (params:
|
|
309
|
+
send: <T extends ICourierSendParameters | ICourierSendMessageParameters>(params: T, config?: ICourierSendConfig) => Promise<SendResponse<T>>;
|
|
299
310
|
}
|
|
300
311
|
export {};
|