@trycourier/courier 2.4.0 → 3.0.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,24 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
6
  ## [Unreleased][unreleased]
7
7
 
8
+ ## [v3.0.0] - 2021-11-02
9
+
10
+ - fixes type definition for `getRecipientSubscriptions`
11
+
12
+ ## [v2.8.0] - 2021-10-29
13
+
14
+ - adds GET /messages/{messageId}/output API
15
+
16
+ ## [v2.7.0] - 2021-10-21
17
+
18
+ - adds GET /messages/{messageId}/history API
19
+
20
+ ## [v2.6.0] - 2021-10-07
21
+
22
+ - Add support for DELETE /profiles/{recipient_id} (#58)
23
+ - adds GET /messages API
24
+ - adds idempotencyKey support in automations client
25
+
8
26
  ## [v2.4.0] - 2021-08-23
9
27
 
10
28
  - adds notifications API
@@ -159,7 +177,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
159
177
 
160
178
  ## v1.0.1 - 2019-07-12
161
179
 
162
- [unreleased]: https://github.com/trycourier/courier-node/compare/v2.4.0...HEAD
180
+ [unreleased]: https://github.com/trycourier/courier-node/compare/v3.0.0...HEAD
181
+ [v3.0.0]: https://github.com/trycourier/courier-node/compare/v2.8.0...v3.0.0
182
+ [v2.8.0]: https://github.com/trycourier/courier-node/compare/v2.7.0...v2.8.0
183
+ [v2.7.0]: https://github.com/trycourier/courier-node/compare/v2.6.0...v2.7.0
184
+ [v2.6.0]: https://github.com/trycourier/courier-node/compare/v2.4.0...v2.6.0
163
185
  [v2.4.0]: https://github.com/trycourier/courier-node/compare/v2.3.0...v2.4.0
164
186
  [v2.3.0]: https://github.com/trycourier/courier-node/compare/v2.2.0...v2.3.0
165
187
  [v2.2.0]: https://github.com/trycourier/courier-node/compare/v2.1.0...v2.2.0
package/README.md CHANGED
@@ -80,6 +80,18 @@ async function run() {
80
80
  const messageStatus = await courier.getMessage(messageId);
81
81
  console.log(messageStatus);
82
82
 
83
+ // Example: get a message history
84
+ const { results } = await courier.getMessageHistory(messageId);
85
+ console.log(results);
86
+
87
+ // Example: get a message output
88
+ const { results } = await courier.getMessageOutput(messageId);
89
+ console.log(results);
90
+
91
+ // Example: get all messages
92
+ const { paging, results } = await courier.getMessages();
93
+ console.log(results);
94
+
83
95
  // Example: replace a recipient's profile
84
96
  const { status: replaceStatus } = await courier.replaceProfile({
85
97
  recipientId: "<RECIPIENT_ID>",
@@ -38,18 +38,29 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.automations = void 0;
40
40
  var invokeAdHocAutomation = function (options) {
41
- return function (params) { return __awaiter(void 0, void 0, void 0, function () {
42
- var res;
41
+ return function (params, config) { return __awaiter(void 0, void 0, void 0, function () {
42
+ var axiosConfig, res;
43
43
  return __generator(this, function (_a) {
44
44
  switch (_a.label) {
45
- case 0: return [4 /*yield*/, options.httpClient.post("/automations/invoke", {
46
- automation: params.automation,
47
- brand: params.brand,
48
- data: params.data,
49
- profile: params.profile,
50
- recipient: params.recipient,
51
- template: params.template
52
- })];
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("/automations/invoke", {
57
+ automation: params.automation,
58
+ brand: params.brand,
59
+ data: params.data,
60
+ profile: params.profile,
61
+ recipient: params.recipient,
62
+ template: params.template
63
+ }, axiosConfig)];
53
64
  case 1:
54
65
  res = _a.sent();
55
66
  return [2 /*return*/, res.data];
@@ -58,17 +69,26 @@ var invokeAdHocAutomation = function (options) {
58
69
  }); };
59
70
  };
60
71
  var invokeAutomationTemplate = function (options) {
61
- return function (params) { return __awaiter(void 0, void 0, void 0, function () {
62
- var res;
72
+ return function (params, config) { return __awaiter(void 0, void 0, void 0, function () {
73
+ var axiosConfig, res;
63
74
  return __generator(this, function (_a) {
64
75
  switch (_a.label) {
65
- case 0: return [4 /*yield*/, options.httpClient.post("/automations/" + params.templateId + "/invoke", {
66
- brand: params.brand,
67
- data: params.data,
68
- profile: params.profile,
69
- recipient: params.recipient,
70
- template: params.template
71
- })];
76
+ case 0:
77
+ axiosConfig = {
78
+ headers: {}
79
+ };
80
+ if (config && config.idempotencyKey) {
81
+ axiosConfig.headers["Idempotency-Key"] = config.idempotencyKey;
82
+ axiosConfig.headers["x-idempotency-expiration"] =
83
+ config.idempotencyExpiry;
84
+ }
85
+ return [4 /*yield*/, options.httpClient.post("/automations/" + params.templateId + "/invoke", {
86
+ brand: params.brand,
87
+ data: params.data,
88
+ profile: params.profile,
89
+ recipient: params.recipient,
90
+ template: params.template
91
+ }, axiosConfig)];
72
92
  case 1:
73
93
  res = _a.sent();
74
94
  return [2 /*return*/, res.data];
@@ -52,6 +52,10 @@ export interface ICourierAutomationInvokeParams {
52
52
  export interface ICourierAutomationAdHocInvokeParams extends ICourierAutomationInvokeParams {
53
53
  automation: IAutomation;
54
54
  }
55
+ export interface ICourierAutomationConfig {
56
+ idempotencyKey?: string;
57
+ idempotencyExpiry?: number;
58
+ }
55
59
  export interface ICourierAutomationInvokeTemplateParams extends ICourierAutomationInvokeParams {
56
60
  templateId: string;
57
61
  }
@@ -59,6 +63,6 @@ export interface ICourierAutomationInvokeResponse {
59
63
  runId: string;
60
64
  }
61
65
  export interface ICourierClientAutomations {
62
- invokeAdHocAutomation: (params: ICourierAutomationAdHocInvokeParams) => Promise<ICourierAutomationInvokeResponse>;
63
- invokeAutomationTemplate: (params: ICourierAutomationInvokeTemplateParams) => Promise<ICourierAutomationInvokeResponse>;
66
+ invokeAdHocAutomation: (params: ICourierAutomationAdHocInvokeParams, config?: ICourierAutomationConfig) => Promise<ICourierAutomationInvokeResponse>;
67
+ invokeAutomationTemplate: (params: ICourierAutomationInvokeTemplateParams, config?: ICourierAutomationConfig) => Promise<ICourierAutomationInvokeResponse>;
64
68
  }
package/lib/client.js CHANGED
@@ -84,15 +84,66 @@ var getMessage = function (options) {
84
84
  });
85
85
  }); };
86
86
  };
87
+ var getMessageHistory = function (options) {
88
+ return function (messageId) { return __awaiter(void 0, void 0, void 0, function () {
89
+ var res;
90
+ return __generator(this, function (_a) {
91
+ switch (_a.label) {
92
+ case 0: return [4 /*yield*/, options.httpClient.get("/messages/" + messageId + "/history")];
93
+ case 1:
94
+ res = _a.sent();
95
+ return [2 /*return*/, res.data];
96
+ }
97
+ });
98
+ }); };
99
+ };
100
+ var getMessageOutput = function (options) {
101
+ return function (messageId) { return __awaiter(void 0, void 0, void 0, function () {
102
+ var res;
103
+ return __generator(this, function (_a) {
104
+ switch (_a.label) {
105
+ case 0: return [4 /*yield*/, options.httpClient.get("/messages/" + messageId + "/output")];
106
+ case 1:
107
+ res = _a.sent();
108
+ return [2 /*return*/, res.data];
109
+ }
110
+ });
111
+ }); };
112
+ };
113
+ var getMessages = function (options) {
114
+ return function (params) { return __awaiter(void 0, void 0, void 0, function () {
115
+ var res;
116
+ return __generator(this, function (_a) {
117
+ switch (_a.label) {
118
+ 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
126
+ })];
127
+ case 1:
128
+ res = _a.sent();
129
+ return [2 /*return*/, res.data];
130
+ }
131
+ });
132
+ }); };
133
+ };
87
134
  exports.client = function (options) {
88
135
  return {
89
136
  addRecipientToLists: profile_1.addRecipientToLists(options),
90
137
  automations: automations_1.automations(options),
91
138
  createBrand: brands_1.createBrand(options),
92
139
  deleteBrand: brands_1.deleteBrand(options),
140
+ deleteProfile: profile_1.deleteProfile(options),
93
141
  getBrand: brands_1.getBrand(options),
94
142
  getBrands: brands_1.getBrands(options),
95
143
  getMessage: getMessage(options),
144
+ getMessageHistory: getMessageHistory(options),
145
+ getMessageOutput: getMessageOutput(options),
146
+ getMessages: getMessages(options),
96
147
  getProfile: profile_1.getProfile(options),
97
148
  getRecipientSubscriptions: profile_1.getRecipientSubscriptions(options),
98
149
  lists: lists_1.lists(options),
@@ -6,6 +6,10 @@ export interface ICourierList {
6
6
  name: string;
7
7
  updated?: number;
8
8
  }
9
+ export interface ICourierRecipientSubscriptionsResponse {
10
+ paging: ICourierPaging;
11
+ results: ICourierList[];
12
+ }
9
13
  export interface ICourierListPutParams {
10
14
  name: string;
11
15
  preferences?: {
package/lib/profile.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { ICourierList } from "./lists/types";
2
- import { ICourierClientConfiguration, ICourierProfileGetParameters, ICourierProfileGetResponse, ICourierProfileListsPostParameters, ICourierProfilePostConfig, ICourierProfilePostParameters, ICourierProfilePostResponse, ICourierProfilePutParameters, ICourierProfilePutResponse } from "./types";
1
+ import { ICourierRecipientSubscriptionsResponse } from "./lists/types";
2
+ import { ICourierClientConfiguration, ICourierProfileDeleteParameters, ICourierProfileGetParameters, ICourierProfileGetResponse, ICourierProfileListsPostParameters, ICourierProfilePostConfig, ICourierProfilePostParameters, ICourierProfilePostResponse, ICourierProfilePutParameters, ICourierProfilePutResponse } from "./types";
3
3
  export declare const replaceProfile: (options: ICourierClientConfiguration) => (params: ICourierProfilePutParameters) => Promise<ICourierProfilePutResponse>;
4
4
  export declare const mergeProfile: (options: ICourierClientConfiguration) => (params: ICourierProfilePostParameters, config?: ICourierProfilePostConfig | undefined) => Promise<ICourierProfilePostResponse>;
5
5
  export declare const getProfile: (options: ICourierClientConfiguration) => (params: ICourierProfileGetParameters) => Promise<ICourierProfileGetResponse>;
6
- export declare const getRecipientSubscriptions: (options: ICourierClientConfiguration) => (params: ICourierProfileGetParameters) => Promise<ICourierList[]>;
6
+ export declare const deleteProfile: (options: ICourierClientConfiguration) => (params: ICourierProfileDeleteParameters) => Promise<void>;
7
+ export declare const getRecipientSubscriptions: (options: ICourierClientConfiguration) => (params: ICourierProfileGetParameters) => Promise<ICourierRecipientSubscriptionsResponse>;
7
8
  export declare const addRecipientToLists: (options: ICourierClientConfiguration) => (params: ICourierProfileListsPostParameters) => Promise<ICourierProfilePostResponse>;
8
9
  export declare const removeRecipientFromAllLists: (options: ICourierClientConfiguration) => (params: ICourierProfileGetParameters) => Promise<ICourierProfilePostResponse>;
package/lib/profile.js CHANGED
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.removeRecipientFromAllLists = exports.addRecipientToLists = exports.getRecipientSubscriptions = exports.getProfile = exports.mergeProfile = exports.replaceProfile = void 0;
39
+ exports.removeRecipientFromAllLists = exports.addRecipientToLists = exports.getRecipientSubscriptions = exports.deleteProfile = exports.getProfile = exports.mergeProfile = exports.replaceProfile = void 0;
40
40
  exports.replaceProfile = function (options) {
41
41
  return function (params) { return __awaiter(void 0, void 0, void 0, function () {
42
42
  var res;
@@ -87,6 +87,18 @@ exports.getProfile = function (options) {
87
87
  });
88
88
  }); };
89
89
  };
90
+ exports.deleteProfile = function (options) {
91
+ return function (params) { return __awaiter(void 0, void 0, void 0, function () {
92
+ return __generator(this, function (_a) {
93
+ switch (_a.label) {
94
+ case 0: return [4 /*yield*/, options.httpClient.delete("/profiles/" + params.recipientId)];
95
+ case 1:
96
+ _a.sent();
97
+ return [2 /*return*/];
98
+ }
99
+ });
100
+ }); };
101
+ };
90
102
  exports.getRecipientSubscriptions = function (options) {
91
103
  return function (params) { return __awaiter(void 0, void 0, void 0, function () {
92
104
  var res;
package/lib/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AxiosRequestConfig } from "axios";
2
2
  import { ICourierClientAutomations } from "./automations/types";
3
- import { ICourierClientLists, ICourierList } from "./lists/types";
3
+ import { ICourierClientLists, ICourierList, ICourierRecipientSubscriptionsResponse } from "./lists/types";
4
4
  import { ICourierClientNotifications } from "./notifications/types";
5
5
  import { ICourierClientPreferences, IRecipientPreferences } from "./preferences/types";
6
6
  export declare type HttpMethodClient = <T>(url: string, body?: object, config?: AxiosRequestConfig) => Promise<{
@@ -79,6 +79,27 @@ export interface ICourierProfileGetParameters {
79
79
  export interface ICourierProfileGetResponse {
80
80
  profile: object;
81
81
  }
82
+ export interface ICourierMessagesGetParameters {
83
+ cursor?: string;
84
+ eventId?: string;
85
+ listId?: string;
86
+ messageId?: string;
87
+ notificationId?: string;
88
+ recipientId?: string;
89
+ status?: string | string[];
90
+ }
91
+ export interface ICourierMessagesGetResponse {
92
+ paging: ICourierPaging;
93
+ results: Array<{
94
+ enqueued?: number;
95
+ event?: string;
96
+ id: string;
97
+ notification?: string;
98
+ recipient: string;
99
+ sent?: number;
100
+ status: string;
101
+ }>;
102
+ }
82
103
  export interface ICourierMessageGetResponse {
83
104
  enqueued?: number;
84
105
  event?: string;
@@ -100,6 +121,91 @@ export interface ICourierMessageGetResponse {
100
121
  sent?: number;
101
122
  status: string;
102
123
  }
124
+ export declare type MessageStatus = "CLICKED" | "DELIVERED" | "ENQUEUED" | "FILTERED" | "OPENED" | "SENT" | "SIMULATED" | "UNDELIVERABLE" | "UNMAPPED";
125
+ export declare type MessageHistoryType = MessageStatus | "DELIVERING" | "FILTERED" | "MAPPED" | "PROFILE_LOADED" | "RENDERED";
126
+ export declare type MessageStatusReason = "BOUNCED" | "FAILED" | "FILTERED" | "NO_CHANNELS" | "NO_PROVIDERS" | "OPT_IN_REQUIRED" | "PROVIDER_ERROR" | "UNPUBLISHED" | "UNSUBSCRIBED";
127
+ export declare type MessageStatusReasonCode = "HARD" | "SOFT";
128
+ export interface IMessageHistory<T extends MessageHistoryType> {
129
+ ts: number;
130
+ type: T;
131
+ }
132
+ export interface IEnqueuedMessageHistory extends IMessageHistory<"ENQUEUED"> {
133
+ data?: string | {
134
+ [key: string]: string;
135
+ };
136
+ event: string;
137
+ profile?: {
138
+ [key: string]: any;
139
+ };
140
+ override?: {
141
+ [key: string]: any;
142
+ };
143
+ recipient: string;
144
+ }
145
+ export interface IMappedMessageHistory extends IMessageHistory<"MAPPED"> {
146
+ event_id: string;
147
+ notification_id: string;
148
+ }
149
+ export interface IProfileLoadedMessageHistory extends IMessageHistory<"PROFILE_LOADED"> {
150
+ merged_profile?: {
151
+ [key: string]: any;
152
+ };
153
+ received_profile?: {
154
+ [key: string]: any;
155
+ };
156
+ stored_profile?: {
157
+ [key: string]: any;
158
+ };
159
+ }
160
+ export interface IRenderedMessageHistory extends IRoutedMessageHistory<"RENDERED"> {
161
+ output: {
162
+ [key: string]: string;
163
+ };
164
+ }
165
+ export interface IUndeliverableMessageHistory extends IMessageHistory<"UNDELIVERABLE">, Partial<Omit<IRoutedMessageHistory<"UNDELIVERABLE">, "ts" | "type">> {
166
+ reason: MessageStatusReason;
167
+ reasonCode?: MessageStatusReasonCode;
168
+ }
169
+ export declare type RoutedMessageHistoryTypes = Extract<MessageHistoryType, "CLICKED" | "DELIVERED" | "DELIVERING" | "OPENED" | "RENDERED" | "SENT" | "UNDELIVERABLE">;
170
+ export interface IRoutedMessageHistory<T extends RoutedMessageHistoryTypes> extends IMessageHistory<T> {
171
+ channel: {
172
+ id: string;
173
+ label?: string;
174
+ };
175
+ integration: {
176
+ id: string;
177
+ provider: string;
178
+ };
179
+ }
180
+ export interface IDeliveredMessageHistory extends IRoutedMessageHistory<"DELIVERED"> {
181
+ reference: {
182
+ [key: string]: string;
183
+ };
184
+ }
185
+ export interface IProviderErrorMessageHistory extends IRoutedMessageHistory<"UNDELIVERABLE"> {
186
+ error_message: string;
187
+ }
188
+ export interface ICourierMessageGetHistoryResponse {
189
+ results: Array<IEnqueuedMessageHistory | IMappedMessageHistory | IProfileLoadedMessageHistory | IRenderedMessageHistory | IRoutedMessageHistory<RoutedMessageHistoryTypes> | IDeliveredMessageHistory | IProviderErrorMessageHistory | IUndeliverableMessageHistory>;
190
+ }
191
+ export interface IApiMessageOutputItem {
192
+ channel: string;
193
+ channel_id: string;
194
+ content: {
195
+ html?: string;
196
+ title?: string;
197
+ blocks?: any[];
198
+ body?: string;
199
+ subject?: string;
200
+ text?: string;
201
+ };
202
+ }
203
+ export interface ICourierMessageGetOutputResponse {
204
+ results: IApiMessageOutputItem[];
205
+ }
206
+ export interface ICourierProfileDeleteParameters {
207
+ recipientId: string;
208
+ }
103
209
  interface ICourierBrandSettings {
104
210
  colors?: {
105
211
  primary: string;
@@ -158,8 +264,12 @@ export interface ICourierClient {
158
264
  cursor: string;
159
265
  }) => Promise<ICourierBrandGetAllResponse>;
160
266
  getMessage: (messageId: string) => Promise<ICourierMessageGetResponse>;
267
+ getMessageHistory: (messageId: string) => Promise<ICourierMessageGetHistoryResponse>;
268
+ getMessageOutput: (messageId: string) => Promise<ICourierMessageGetOutputResponse>;
269
+ getMessages: (params?: ICourierMessagesGetParameters) => Promise<ICourierMessagesGetResponse>;
161
270
  getProfile: (params: ICourierProfileGetParameters) => Promise<ICourierProfileGetResponse>;
162
- getRecipientSubscriptions: (params: ICourierProfileGetParameters) => Promise<ICourierList[]>;
271
+ deleteProfile: (params: ICourierProfileDeleteParameters) => Promise<void>;
272
+ getRecipientSubscriptions: (params: ICourierProfileGetParameters) => Promise<ICourierRecipientSubscriptionsResponse>;
163
273
  lists: ICourierClientLists;
164
274
  mergeProfile: (params: ICourierProfilePostParameters, config?: ICourierProfilePostConfig) => Promise<ICourierProfilePostResponse>;
165
275
  notifications: ICourierClientNotifications;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/courier",
3
- "version": "2.4.0",
3
+ "version": "3.0.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",