@trycourier/courier 3.0.0 → 3.3.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,22 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
6
  ## [Unreleased][unreleased]
7
7
 
8
+ ## [v3.3.0] - 2022-01-25
9
+
10
+ - adds support for bulk processing endpoints
11
+
12
+ ## [v3.2.1] - 2022-01-13
13
+
14
+ - Fixes `getMessages` query params
15
+
16
+ ## [v3.2.0] - 2021-11-18
17
+
18
+ - adds idempotency expiration support for send and send list endpoints
19
+
20
+ ## [v3.1.0] - 2021-11-16
21
+
22
+ - Expose additional type definitions for `getMessage`
23
+
8
24
  ## [v3.0.0] - 2021-11-02
9
25
 
10
26
  - fixes type definition for `getRecipientSubscriptions`
@@ -177,7 +193,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
177
193
 
178
194
  ## v1.0.1 - 2019-07-12
179
195
 
180
- [unreleased]: https://github.com/trycourier/courier-node/compare/v3.0.0...HEAD
196
+ [unreleased]: https://github.com/trycourier/courier-node/compare/v3.3.0...HEAD
197
+ [v3.3.0]: https://github.com/trycourier/courier-node/compare/v3.2.1...v3.3.0
198
+ [v3.2.1]: https://github.com/trycourier/courier-node/compare/v3.2.0...v3.2.1
199
+ [v3.2.0]: https://github.com/trycourier/courier-node/compare/v3.1.0...v3.2.0
200
+ [v3.1.0]: https://github.com/trycourier/courier-node/compare/v3.0.0...v3.1.0
181
201
  [v3.0.0]: https://github.com/trycourier/courier-node/compare/v2.8.0...v3.0.0
182
202
  [v2.8.0]: https://github.com/trycourier/courier-node/compare/v2.7.0...v2.8.0
183
203
  [v2.7.0]: https://github.com/trycourier/courier-node/compare/v2.6.0...v2.7.0
package/README.md CHANGED
@@ -377,6 +377,45 @@ async function run() {
377
377
 
378
378
  // Example: Cancel notification submission
379
379
  await courier.notifications.cancelSubmission("notification1", "submission1");
380
+
381
+ // Bulk Processing
382
+ // Example: create a job
383
+ const response = await courier.bulk.createJob({
384
+ message: {
385
+ event: "RR4NDQ7NZ24A8TKPWVBEDGE15E9A",
386
+ },
387
+ });
388
+ console.log(response);
389
+
390
+ // Example: get a job
391
+ const response = await courier.bulk.getJob({
392
+ jobId: "1-61efe386-6ff57552409e311b7a1f371f",
393
+ });
394
+ console.log(response);
395
+
396
+ // Example: Ingest users in a job
397
+ const response = await courier.bulk.ingestUsers({
398
+ jobId: "1-61efe386-6ff57552409e311b7a1f371f",
399
+ users: [
400
+ {
401
+ profile: {
402
+ email: "tejas@courier.com",
403
+ },
404
+ },
405
+ ],
406
+ });
407
+ console.log(response);
408
+
409
+ // Example: Run a job
410
+ await courier.bulk.runJob({
411
+ jobId: "1-61efe386-6ff57552409e311b7a1f371f",
412
+ });
413
+
414
+ // Example: Get user details in a job
415
+ const response = await courier.bulk.getJobUsers({
416
+ jobId: "1-61efe386-6ff57552409e311b7a1f371f",
417
+ });
418
+ console.log(response);
380
419
  }
381
420
 
382
421
  run();
@@ -0,0 +1,3 @@
1
+ import { ICourierClientConfiguration } from "../types";
2
+ import { ICourierClientBulk } from "./types";
3
+ export declare const bulk: (options: ICourierClientConfiguration) => ICourierClientBulk;
@@ -0,0 +1,154 @@
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.bulk = void 0;
40
+ var createJob = function (options) {
41
+ return function (params, config) { return __awaiter(void 0, void 0, void 0, function () {
42
+ var axiosConfig, res;
43
+ return __generator(this, function (_a) {
44
+ switch (_a.label) {
45
+ case 0:
46
+ axiosConfig = {
47
+ headers: {}
48
+ };
49
+ if (config && config.idempotencyKey) {
50
+ axiosConfig.headers["Idempotency-Key"] = config.idempotencyKey;
51
+ }
52
+ if (config && config.idempotencyExpiry) {
53
+ axiosConfig.headers["x-idempotency-expiration"] =
54
+ config.idempotencyExpiry;
55
+ }
56
+ return [4 /*yield*/, options.httpClient.post("/bulk", {
57
+ message: params.message
58
+ }, axiosConfig)];
59
+ case 1:
60
+ res = _a.sent();
61
+ return [2 /*return*/, res.data];
62
+ }
63
+ });
64
+ }); };
65
+ };
66
+ var ingestUsers = function (options) {
67
+ return function (params, config) { return __awaiter(void 0, void 0, void 0, function () {
68
+ var axiosConfig, res;
69
+ return __generator(this, function (_a) {
70
+ switch (_a.label) {
71
+ case 0:
72
+ axiosConfig = {
73
+ headers: {}
74
+ };
75
+ if (config && config.idempotencyKey) {
76
+ axiosConfig.headers["Idempotency-Key"] = config.idempotencyKey;
77
+ }
78
+ if (config && config.idempotencyExpiry) {
79
+ axiosConfig.headers["x-idempotency-expiration"] =
80
+ config.idempotencyExpiry;
81
+ }
82
+ return [4 /*yield*/, options.httpClient.post("/bulk/" + params.jobId, {
83
+ users: params.users
84
+ }, axiosConfig)];
85
+ case 1:
86
+ res = _a.sent();
87
+ return [2 /*return*/, res.data];
88
+ }
89
+ });
90
+ }); };
91
+ };
92
+ var runJob = function (options) {
93
+ return function (params, config) { return __awaiter(void 0, void 0, void 0, function () {
94
+ var axiosConfig;
95
+ return __generator(this, function (_a) {
96
+ switch (_a.label) {
97
+ case 0:
98
+ axiosConfig = {
99
+ headers: {}
100
+ };
101
+ if (config && config.idempotencyKey) {
102
+ axiosConfig.headers["Idempotency-Key"] = config.idempotencyKey;
103
+ }
104
+ if (config && config.idempotencyExpiry) {
105
+ axiosConfig.headers["x-idempotency-expiration"] =
106
+ config.idempotencyExpiry;
107
+ }
108
+ return [4 /*yield*/, options.httpClient.post("/bulk/" + params.jobId + "/run", {}, axiosConfig)];
109
+ case 1:
110
+ _a.sent();
111
+ return [2 /*return*/];
112
+ }
113
+ });
114
+ }); };
115
+ };
116
+ var getJob = function (options) {
117
+ return function (params) { return __awaiter(void 0, void 0, void 0, function () {
118
+ var res;
119
+ return __generator(this, function (_a) {
120
+ switch (_a.label) {
121
+ case 0: return [4 /*yield*/, options.httpClient.get("/bulk/" + params.jobId)];
122
+ case 1:
123
+ res = _a.sent();
124
+ return [2 /*return*/, res.data];
125
+ }
126
+ });
127
+ }); };
128
+ };
129
+ var getJobUsers = function (options) {
130
+ return function (params) { return __awaiter(void 0, void 0, void 0, function () {
131
+ var res;
132
+ return __generator(this, function (_a) {
133
+ switch (_a.label) {
134
+ case 0: return [4 /*yield*/, options.httpClient.get("/bulk/" + params.jobId + "/users", {
135
+ params: {
136
+ cursor: params.cursor
137
+ }
138
+ })];
139
+ case 1:
140
+ res = _a.sent();
141
+ return [2 /*return*/, res.data];
142
+ }
143
+ });
144
+ }); };
145
+ };
146
+ exports.bulk = function (options) {
147
+ return {
148
+ createJob: createJob(options),
149
+ getJob: getJob(options),
150
+ getJobUsers: getJobUsers(options),
151
+ ingestUsers: ingestUsers(options),
152
+ runJob: runJob(options)
153
+ };
154
+ };
@@ -0,0 +1,76 @@
1
+ import { IRecipientPreferences } from "../preferences/types";
2
+ export interface IInboundBulkMessage {
3
+ brand?: string;
4
+ data?: object;
5
+ event: string;
6
+ locale?: string;
7
+ override?: object;
8
+ }
9
+ export interface ICourierBulkConfig {
10
+ idempotencyKey?: string;
11
+ idempotencyExpiry?: number;
12
+ }
13
+ export interface ICourierBulkCreateJobParams {
14
+ message: IInboundBulkMessage;
15
+ }
16
+ export interface ICourierBulkCreateJobResponse {
17
+ jobId: string;
18
+ }
19
+ export interface IInboundBulkMessageUser {
20
+ preferences?: IRecipientPreferences;
21
+ profile?: object;
22
+ recipient?: string;
23
+ data?: object;
24
+ }
25
+ export declare type InboundBulkMessageUser = IInboundBulkMessageUser;
26
+ export interface ICourierBulkIngestUsersParams {
27
+ jobId: string;
28
+ users: InboundBulkMessageUser[];
29
+ }
30
+ export interface ICourierBulkIngestError {
31
+ user: any;
32
+ error: any;
33
+ }
34
+ export interface ICourierBulkIngestUsersResponse {
35
+ total: number;
36
+ errors?: ICourierBulkIngestError[];
37
+ }
38
+ export interface ICourierBulkRunJobParams {
39
+ jobId: string;
40
+ }
41
+ export interface ICourierBulkGetJobParams {
42
+ jobId: string;
43
+ }
44
+ export declare type BulkJobStatus = "CREATED" | "PROCESSING" | "COMPLETED" | "ERROR";
45
+ export declare type BulkJobUserStatus = "PENDING" | "ENQUEUED" | "ERROR";
46
+ export interface ICourierBulkGetJobResponse {
47
+ job: {
48
+ definition: IInboundBulkMessage;
49
+ enqueued: number;
50
+ failures: number;
51
+ received: number;
52
+ status: BulkJobStatus;
53
+ };
54
+ }
55
+ export interface ICourierBulkGetJobUsersParams {
56
+ jobId: string;
57
+ cursor?: string;
58
+ }
59
+ export interface ICourierBulkMessageUserResponse extends InboundBulkMessageUser {
60
+ status: BulkJobUserStatus;
61
+ messageId?: string;
62
+ }
63
+ export interface ICourierBulkGetJobUsersResponse {
64
+ items: ICourierBulkMessageUserResponse[];
65
+ paging: {
66
+ cursor?: string;
67
+ more: boolean;
68
+ };
69
+ }
70
+ export interface ICourierClientBulk {
71
+ createJob: (params: ICourierBulkCreateJobParams, config?: ICourierBulkConfig) => Promise<ICourierBulkCreateJobResponse>;
72
+ ingestUsers: (params: ICourierBulkIngestUsersParams, config?: ICourierBulkConfig) => Promise<ICourierBulkIngestUsersResponse>;
73
+ runJob: (params: ICourierBulkRunJobParams, config?: ICourierBulkConfig) => Promise<void>;
74
+ getJob: (params: ICourierBulkGetJobParams) => Promise<ICourierBulkGetJobResponse>;
75
+ getJobUsers: (params: ICourierBulkGetJobUsersParams) => Promise<ICourierBulkGetJobUsersResponse>;
76
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/lib/client.js CHANGED
@@ -39,6 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.client = void 0;
40
40
  var automations_1 = require("./automations");
41
41
  var brands_1 = require("./brands");
42
+ var bulk_1 = require("./bulk");
42
43
  var lists_1 = require("./lists");
43
44
  var notifications_1 = require("./notifications");
44
45
  var preferences_1 = require("./preferences");
@@ -55,6 +56,10 @@ var send = function (options) {
55
56
  if (config && config.idempotencyKey) {
56
57
  axiosConfig.headers["Idempotency-Key"] = config.idempotencyKey;
57
58
  }
59
+ if (config && config.idempotencyExpiry) {
60
+ axiosConfig.headers["x-idempotency-expiration"] =
61
+ config.idempotencyExpiry;
62
+ }
58
63
  return [4 /*yield*/, options.httpClient.post("/send", {
59
64
  brand: params.brand,
60
65
  data: params.data,
@@ -116,13 +121,15 @@ var getMessages = function (options) {
116
121
  return __generator(this, function (_a) {
117
122
  switch (_a.label) {
118
123
  case 0: return [4 /*yield*/, options.httpClient.get("/messages", {
119
- cursor: params === null || params === void 0 ? void 0 : params.cursor,
120
- event: params === null || params === void 0 ? void 0 : params.eventId,
121
- list: params === null || params === void 0 ? void 0 : params.listId,
122
- messageId: params === null || params === void 0 ? void 0 : params.messageId,
123
- notification: params === null || params === void 0 ? void 0 : params.notificationId,
124
- recipient: params === null || params === void 0 ? void 0 : params.recipientId,
125
- status: params === null || params === void 0 ? void 0 : params.status
124
+ params: {
125
+ cursor: params === null || params === void 0 ? void 0 : params.cursor,
126
+ event: params === null || params === void 0 ? void 0 : params.eventId,
127
+ list: params === null || params === void 0 ? void 0 : params.listId,
128
+ messageId: params === null || params === void 0 ? void 0 : params.messageId,
129
+ notification: params === null || params === void 0 ? void 0 : params.notificationId,
130
+ recipient: params === null || params === void 0 ? void 0 : params.recipientId,
131
+ status: params === null || params === void 0 ? void 0 : params.status
132
+ }
126
133
  })];
127
134
  case 1:
128
135
  res = _a.sent();
@@ -135,6 +142,7 @@ exports.client = function (options) {
135
142
  return {
136
143
  addRecipientToLists: profile_1.addRecipientToLists(options),
137
144
  automations: automations_1.automations(options),
145
+ bulk: bulk_1.bulk(options),
138
146
  createBrand: brands_1.createBrand(options),
139
147
  deleteBrand: brands_1.deleteBrand(options),
140
148
  deleteProfile: profile_1.deleteProfile(options),
@@ -192,6 +192,10 @@ var send = function (options) {
192
192
  if (config && config.idempotencyKey) {
193
193
  axiosConfig.headers["Idempotency-Key"] = config.idempotencyKey;
194
194
  }
195
+ if (config && config.idempotencyExpiry) {
196
+ axiosConfig.headers["x-idempotency-expiration"] =
197
+ config.idempotencyExpiry;
198
+ }
195
199
  return [4 /*yield*/, options.httpClient.post("/send/list", params, axiosConfig)];
196
200
  case 1:
197
201
  res = _a.sent();
package/lib/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { AxiosRequestConfig } from "axios";
2
2
  import { ICourierClientAutomations } from "./automations/types";
3
+ import { ICourierClientBulk } from "./bulk/types";
3
4
  import { ICourierClientLists, ICourierList, ICourierRecipientSubscriptionsResponse } from "./lists/types";
4
5
  import { ICourierClientNotifications } from "./notifications/types";
5
6
  import { ICourierClientPreferences, IRecipientPreferences } from "./preferences/types";
@@ -31,6 +32,7 @@ export interface ICourierSendParameters {
31
32
  }
32
33
  export interface ICourierSendConfig {
33
34
  idempotencyKey?: string;
35
+ idempotencyExpiry?: number;
34
36
  }
35
37
  export interface ICourierSendResponse {
36
38
  messageId: string;
@@ -101,25 +103,40 @@ export interface ICourierMessagesGetResponse {
101
103
  }>;
102
104
  }
103
105
  export interface ICourierMessageGetResponse {
106
+ clicked?: number;
107
+ delivered?: number;
104
108
  enqueued?: number;
109
+ error?: string;
105
110
  event?: string;
106
111
  id: string;
112
+ idempotencyKey?: string;
113
+ listId?: string;
114
+ listMessageId?: string;
107
115
  notification?: string;
116
+ opened?: number;
108
117
  providers?: Array<{
109
118
  channel: {
110
- name: string;
119
+ key?: string;
120
+ name?: string;
111
121
  template: string;
112
122
  };
123
+ clicked?: number;
124
+ delivered?: number;
125
+ error?: string;
113
126
  provider: string;
114
- reference: {
115
- "x-message-id": string;
127
+ reference?: {
128
+ [key: string]: string | number;
116
129
  };
117
130
  sent: number;
118
- status: string;
131
+ status: MessageStatus;
119
132
  }>;
133
+ reason?: MessageStatusReason;
134
+ reasonCode?: MessageStatusReasonCode;
135
+ reasonDetails?: string;
120
136
  recipient: string;
137
+ runId?: string;
121
138
  sent?: number;
122
- status: string;
139
+ status: MessageStatus;
123
140
  }
124
141
  export declare type MessageStatus = "CLICKED" | "DELIVERED" | "ENQUEUED" | "FILTERED" | "OPENED" | "SENT" | "SIMULATED" | "UNDELIVERABLE" | "UNMAPPED";
125
142
  export declare type MessageHistoryType = MessageStatus | "DELIVERING" | "FILTERED" | "MAPPED" | "PROFILE_LOADED" | "RENDERED";
@@ -257,6 +274,7 @@ export interface ICourierBrandGetAllResponse {
257
274
  export interface ICourierClient {
258
275
  addRecipientToLists: (params: ICourierProfileListsPostParameters) => Promise<ICourierProfilePostResponse>;
259
276
  automations: ICourierClientAutomations;
277
+ bulk: ICourierClientBulk;
260
278
  createBrand: (params: ICourierBrandParameters, config?: ICourierBrandPostConfig) => Promise<ICourierBrand>;
261
279
  deleteBrand: (brandId: string) => Promise<void>;
262
280
  getBrand: (brandId: string) => Promise<ICourierBrand>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/courier",
3
- "version": "3.0.0",
3
+ "version": "3.3.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",