@trycourier/courier 4.5.0 → 4.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/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)
@@ -3,6 +3,12 @@ export interface IAccount {
3
3
  id: string;
4
4
  name: string;
5
5
  parent_account_id?: string;
6
+ preferences?: {
7
+ topics: Array<{
8
+ defaultStatus: "OPTED_IN" | "OPTED_OUT" | "REQUIRED";
9
+ id: string;
10
+ }>;
11
+ };
6
12
  properties?: {
7
13
  [key: string]: any;
8
14
  };
package/lib/client.js CHANGED
@@ -49,6 +49,7 @@ 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");
52
53
  var cancelMessage = function (options) {
53
54
  return function (messageId) { return __awaiter(void 0, void 0, void 0, function () {
54
55
  var res;
@@ -153,6 +154,7 @@ exports.client = function (options) {
153
154
  replaceBrand: brands_1.replaceBrand(options),
154
155
  replaceProfile: profile_1.replaceProfile(options),
155
156
  send: send_1.send(options),
156
- tokenManagement: token_management_1.tokenManagement(options)
157
+ tokenManagement: token_management_1.tokenManagement(options),
158
+ users: users_1.users(options)
157
159
  };
158
160
  };
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;
@@ -346,5 +347,6 @@ export interface ICourierClient {
346
347
  replaceProfile: (params: ICourierProfilePutParameters) => Promise<ICourierProfilePutResponse>;
347
348
  send: <T extends ICourierSendParameters | ICourierSendMessageParameters>(params: T, config?: ICourierSendConfig) => Promise<SendResponse<T>>;
348
349
  tokenManagement: ReturnType<typeof tokenManagement>;
350
+ users: ReturnType<typeof users>;
349
351
  }
350
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
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/courier",
3
- "version": "4.5.0",
3
+ "version": "4.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",