@trycourier/courier 4.4.0 → 4.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/README.md +19 -0
- package/lib/accounts/index.js +3 -3
- package/lib/client.js +18 -2
- package/lib/http-client.js +1 -1
- package/lib/types.d.ts +21 -0
- package/lib/users/index.d.ts +6 -0
- package/lib/users/index.js +67 -0
- package/lib/users/types.d.ts +12 -0
- package/lib/users/types.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -823,6 +823,25 @@ await courier.accounts.delete("<ACCOUNT_ID>");
|
|
|
823
823
|
const { items: accounts, has_more, next_page } = await courier.accounts.list();
|
|
824
824
|
```
|
|
825
825
|
|
|
826
|
+
### Users
|
|
827
|
+
|
|
828
|
+
#### Updating user
|
|
829
|
+
|
|
830
|
+
```ts
|
|
831
|
+
await courier.users.put("<USER_ID>", {
|
|
832
|
+
accounts: [{ account_id: "ACCOUNT_ID", profile: { foo: "bar" } }],
|
|
833
|
+
profile: { name: "John Doe" },
|
|
834
|
+
});
|
|
835
|
+
```
|
|
836
|
+
|
|
837
|
+
#### Updating user accounts
|
|
838
|
+
|
|
839
|
+
```ts
|
|
840
|
+
await courier.users.putAccounts("<USER_ID>", {
|
|
841
|
+
accounts: [{ account_id: "ACCOUNT_ID", profile: { foo: "bar" } }],
|
|
842
|
+
});
|
|
843
|
+
```
|
|
844
|
+
|
|
826
845
|
## License
|
|
827
846
|
|
|
828
847
|
[MIT License](http://www.opensource.org/licenses/mit-license.php)
|
package/lib/accounts/index.js
CHANGED
|
@@ -68,8 +68,8 @@ var listAccounts = function (options) {
|
|
|
68
68
|
case 0: return [4 /*yield*/, options.httpClient.get("/accounts", undefined, {
|
|
69
69
|
params: {
|
|
70
70
|
cursor: (listOptions === null || listOptions === void 0 ? void 0 : listOptions.cursor) || "",
|
|
71
|
-
limit: (listOptions === null || listOptions === void 0 ? void 0 : listOptions.limit) || "20"
|
|
72
|
-
}
|
|
71
|
+
limit: (listOptions === null || listOptions === void 0 ? void 0 : listOptions.limit) || "20"
|
|
72
|
+
}
|
|
73
73
|
})];
|
|
74
74
|
case 1:
|
|
75
75
|
response = _a.sent();
|
|
@@ -95,5 +95,5 @@ exports.accounts = function (options) { return ({
|
|
|
95
95
|
delete: deleteAccount(options),
|
|
96
96
|
get: getAccount(options),
|
|
97
97
|
listAccounts: listAccounts(options),
|
|
98
|
-
put: putAccount(options)
|
|
98
|
+
put: putAccount(options)
|
|
99
99
|
}); };
|
package/lib/client.js
CHANGED
|
@@ -49,6 +49,20 @@ var preferences_1 = require("./preferences");
|
|
|
49
49
|
var profile_1 = require("./profile");
|
|
50
50
|
var send_1 = require("./send");
|
|
51
51
|
var token_management_1 = require("./token-management");
|
|
52
|
+
var users_1 = require("./users");
|
|
53
|
+
var cancelMessage = function (options) {
|
|
54
|
+
return function (messageId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
55
|
+
var res;
|
|
56
|
+
return __generator(this, function (_a) {
|
|
57
|
+
switch (_a.label) {
|
|
58
|
+
case 0: return [4 /*yield*/, options.httpClient.post("/messages/" + messageId + "/cancel")];
|
|
59
|
+
case 1:
|
|
60
|
+
res = _a.sent();
|
|
61
|
+
return [2 /*return*/, res.data];
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}); };
|
|
65
|
+
};
|
|
52
66
|
var getMessage = function (options) {
|
|
53
67
|
return function (messageId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
54
68
|
var res;
|
|
@@ -102,8 +116,8 @@ var getMessages = function (options) {
|
|
|
102
116
|
notification: params === null || params === void 0 ? void 0 : params.notificationId,
|
|
103
117
|
recipient: params === null || params === void 0 ? void 0 : params.recipientId,
|
|
104
118
|
status: params === null || params === void 0 ? void 0 : params.status,
|
|
105
|
-
tags: params === null || params === void 0 ? void 0 : params.tags
|
|
106
|
-
}
|
|
119
|
+
tags: params === null || params === void 0 ? void 0 : params.tags
|
|
120
|
+
}
|
|
107
121
|
})];
|
|
108
122
|
case 1:
|
|
109
123
|
res = _a.sent();
|
|
@@ -120,6 +134,7 @@ exports.client = function (options) {
|
|
|
120
134
|
auditEvents: audit_events_1.auditEvents(options),
|
|
121
135
|
automations: automations_1.automations(options),
|
|
122
136
|
bulk: bulk_1.bulk(options),
|
|
137
|
+
cancelMessage: cancelMessage(options),
|
|
123
138
|
createBrand: brands_1.createBrand(options),
|
|
124
139
|
deleteBrand: brands_1.deleteBrand(options),
|
|
125
140
|
deleteProfile: profile_1.deleteProfile(options),
|
|
@@ -140,5 +155,6 @@ exports.client = function (options) {
|
|
|
140
155
|
replaceProfile: profile_1.replaceProfile(options),
|
|
141
156
|
send: send_1.send(options),
|
|
142
157
|
tokenManagement: token_management_1.tokenManagement(options),
|
|
158
|
+
users: users_1.users(options)
|
|
143
159
|
};
|
|
144
160
|
};
|
package/lib/http-client.js
CHANGED
|
@@ -93,7 +93,7 @@ exports.initHttpClient = function (_a) {
|
|
|
93
93
|
case 0:
|
|
94
94
|
searchParams = String(new URLSearchParams(config === null || config === void 0 ? void 0 : config.params));
|
|
95
95
|
searchQueryString = searchParams && "?" + searchParams;
|
|
96
|
-
fullUrl = encodeURI("" + (baseUrl !== null && baseUrl !== void 0 ? baseUrl :
|
|
96
|
+
fullUrl = encodeURI("" + (baseUrl !== null && baseUrl !== void 0 ? baseUrl : "") + url + searchQueryString);
|
|
97
97
|
contentTypeHeader = body == null ? null : { "Content-Type": "application/json" };
|
|
98
98
|
idempotencyKeyHeader = (config === null || config === void 0 ? void 0 : config.idempotencyKey) ? { "Idempotency-Key": config.idempotencyKey }
|
|
99
99
|
: null;
|
package/lib/types.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { ICourierClientNotifications } from "./notifications/types";
|
|
|
8
8
|
import { ICourierClientPreferences, IRecipientPreferences } from "./preferences/types";
|
|
9
9
|
import { Message } from "./send/types";
|
|
10
10
|
import { tokenManagement } from "./token-management";
|
|
11
|
+
import { users } from "./users";
|
|
11
12
|
export interface IInitHttpClientOptions {
|
|
12
13
|
baseUrl: string;
|
|
13
14
|
version: string;
|
|
@@ -124,6 +125,24 @@ export interface ICourierMessagesGetResponse {
|
|
|
124
125
|
tags?: string[];
|
|
125
126
|
}>;
|
|
126
127
|
}
|
|
128
|
+
export interface ICourierMessageCancelResponse {
|
|
129
|
+
canceledAt: number;
|
|
130
|
+
event: string;
|
|
131
|
+
id: string;
|
|
132
|
+
recipient: string;
|
|
133
|
+
status: string;
|
|
134
|
+
clicked?: number;
|
|
135
|
+
delivered?: number;
|
|
136
|
+
enqueued?: number;
|
|
137
|
+
error?: string;
|
|
138
|
+
jobId?: string;
|
|
139
|
+
listId?: string;
|
|
140
|
+
listMessageId?: string;
|
|
141
|
+
notification?: string;
|
|
142
|
+
opened?: number;
|
|
143
|
+
runId?: string;
|
|
144
|
+
sent?: number;
|
|
145
|
+
}
|
|
127
146
|
export interface ICourierMessageGetResponse {
|
|
128
147
|
clicked?: number;
|
|
129
148
|
delivered?: number;
|
|
@@ -305,6 +324,7 @@ export interface ICourierClient {
|
|
|
305
324
|
auditEvents: ReturnType<typeof auditEvents>;
|
|
306
325
|
automations: ICourierClientAutomations;
|
|
307
326
|
bulk: ICourierClientBulk;
|
|
327
|
+
cancelMessage: (messageId: string) => Promise<ICourierMessageCancelResponse>;
|
|
308
328
|
createBrand: (params: ICourierBrandParameters, config?: ICourierBrandPostConfig) => Promise<ICourierBrand>;
|
|
309
329
|
deleteBrand: (brandId: string) => Promise<void>;
|
|
310
330
|
getBrand: (brandId: string) => Promise<ICourierBrand>;
|
|
@@ -327,5 +347,6 @@ export interface ICourierClient {
|
|
|
327
347
|
replaceProfile: (params: ICourierProfilePutParameters) => Promise<ICourierProfilePutResponse>;
|
|
328
348
|
send: <T extends ICourierSendParameters | ICourierSendMessageParameters>(params: T, config?: ICourierSendConfig) => Promise<SendResponse<T>>;
|
|
329
349
|
tokenManagement: ReturnType<typeof tokenManagement>;
|
|
350
|
+
users: ReturnType<typeof users>;
|
|
330
351
|
}
|
|
331
352
|
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ICourierClientConfiguration } from "../types";
|
|
2
|
+
import { IUser, IUserAccount } from "./types";
|
|
3
|
+
export declare const users: (options: ICourierClientConfiguration) => {
|
|
4
|
+
put: (id: string, user: IUser) => Promise<void>;
|
|
5
|
+
putAccounts: (id: string, accounts: IUserAccount[]) => Promise<void>;
|
|
6
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
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.users = void 0;
|
|
40
|
+
var put = function (options) {
|
|
41
|
+
return function (id, user) { return __awaiter(void 0, void 0, void 0, function () {
|
|
42
|
+
return __generator(this, function (_a) {
|
|
43
|
+
switch (_a.label) {
|
|
44
|
+
case 0: return [4 /*yield*/, options.httpClient.put("/users/" + id, user)];
|
|
45
|
+
case 1:
|
|
46
|
+
_a.sent();
|
|
47
|
+
return [2 /*return*/];
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}); };
|
|
51
|
+
};
|
|
52
|
+
var putAccounts = function (options) {
|
|
53
|
+
return function (id, accounts) { return __awaiter(void 0, void 0, void 0, function () {
|
|
54
|
+
return __generator(this, function (_a) {
|
|
55
|
+
switch (_a.label) {
|
|
56
|
+
case 0: return [4 /*yield*/, options.httpClient.put("/users/" + id + "/accounts", accounts)];
|
|
57
|
+
case 1:
|
|
58
|
+
_a.sent();
|
|
59
|
+
return [2 /*return*/];
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}); };
|
|
63
|
+
};
|
|
64
|
+
exports.users = function (options) { return ({
|
|
65
|
+
put: put(options),
|
|
66
|
+
putAccounts: putAccounts(options),
|
|
67
|
+
}); };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface IUserAccount {
|
|
2
|
+
account_id: string;
|
|
3
|
+
profile: Record<string, any>;
|
|
4
|
+
}
|
|
5
|
+
export interface IUser {
|
|
6
|
+
accounts: IUserAccount[];
|
|
7
|
+
profile: Record<string, any>;
|
|
8
|
+
}
|
|
9
|
+
export interface ICourierClientUsers {
|
|
10
|
+
put: (id: string, user: IUser) => Promise<void>;
|
|
11
|
+
putAccounts: (id: string, accounts: IUserAccount[]) => Promise<void>;
|
|
12
|
+
}
|