@trycourier/courier 4.2.0 → 4.4.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
@@ -25,7 +25,7 @@ v4 uses native fetch client to make requests or falls back to a polyfill if the
25
25
  ## Getting Started
26
26
 
27
27
  ```javascript
28
- import { CourierClient } from "@trycourier/courier";
28
+ const { CourierClient } = require("@trycourier/courier");
29
29
 
30
30
  const courier = CourierClient({ authorizationToken: "<AUTH_TOKEN>" }); // get from the Courier UI
31
31
 
@@ -223,8 +223,7 @@ If you need to use a base url other than the default https://api.courier.com, yo
223
223
  ## Advanced Usage
224
224
 
225
225
  ```javascript
226
- import { CourierClient } from "@trycourier/courier";
227
- // const { CourierClient } = require("@trycourier/courier");
226
+ const { CourierClient } = require("@trycourier/courier");
228
227
 
229
228
  const courier = CourierClient({ authorizationToken: "<AUTH_TOKEN>" });
230
229
 
@@ -691,7 +690,10 @@ All network related promise rejections are not handled in any way. All successfu
691
690
 
692
691
  ```javascript
693
692
  // Error handling example
694
- import { CourierClient, CourierHttpClientError } from "@trycourier/courier";
693
+ const {
694
+ CourierClient,
695
+ CourierHttpClientError,
696
+ } = require("@trycourier/courier");
695
697
 
696
698
  const courier = CourierClient();
697
699
 
@@ -715,7 +717,7 @@ try {
715
717
  For `POST` methods, you can supply an `idempotencyKey` in the config parameter to ensure the idempotency of the API Call. We recommend that you use a `V4 UUID` for the key. Keys are eligible to be removed from the system after they're at least 24 hours old, and a new request is generated if a key is reused after the original has been removed. For more info, see [Idempotent Requests](https://docs.courier.com/reference/idempotent-requests) in the Courier documentation.
716
718
 
717
719
  ```javascript
718
- import { CourierClient } from "@trycourier/courier";
720
+ const { CourierClient } = require("@trycourier/courier");
719
721
  import uuid4 from "uuid4";
720
722
 
721
723
  const courier = CourierClient();
@@ -780,6 +782,47 @@ const { requestId } = await courier.send({
780
782
  });
781
783
  ```
782
784
 
785
+ ### Accounts
786
+
787
+ The Accounts API is designed to enable multi-tenant notification workflows. This is useful for defining user to account level relationships, especially in the context of B2B applications.
788
+
789
+ Use Cases:
790
+
791
+ - Sending branded notifications on behalf of an organization
792
+ - Creating slack-bots on behalf of an organization
793
+
794
+ #### Creating an Account
795
+
796
+ ```ts
797
+ const { accountId } = await courier.accounts.put({
798
+ id: "<ACCOUNT_ID>",
799
+ name: "Courier",
800
+ user_profile: {
801
+ slack: {
802
+ access_token: "<SLACK_ACCESS_TOKEN_SCOPED_TO_THE_ACCOUNT>",
803
+ },
804
+ },
805
+ });
806
+ ```
807
+
808
+ #### Retrieving an Account
809
+
810
+ ```ts
811
+ const account = await courier.accounts.get("<ACCOUNT_ID>");
812
+ ```
813
+
814
+ #### Deleting an Account
815
+
816
+ ```ts
817
+ await courier.accounts.delete("<ACCOUNT_ID>");
818
+ ```
819
+
820
+ #### Listing Accounts
821
+
822
+ ```ts
823
+ const { items: accounts, has_more, next_page } = await courier.accounts.list();
824
+ ```
825
+
783
826
  ## License
784
827
 
785
828
  [MIT License](http://www.opensource.org/licenses/mit-license.php)
@@ -0,0 +1,8 @@
1
+ import { ICourierClientConfiguration } from "../types";
2
+ import * as AccountTypes from "./types";
3
+ export declare const accounts: (options: ICourierClientConfiguration) => {
4
+ delete: (accountId: string) => Promise<void>;
5
+ get: (accountId: string) => Promise<AccountTypes.IAccount>;
6
+ listAccounts: (listOptions?: AccountTypes.IAccountListOptions | undefined) => Promise<AccountTypes.IPaginatedResult<AccountTypes.IAccount>>;
7
+ put: (account: Omit<AccountTypes.IAccount, "type">) => Promise<AccountTypes.IAccount>;
8
+ };
@@ -0,0 +1,99 @@
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.accounts = void 0;
40
+ var deleteAccount = function (options) { return function (accountId) { return __awaiter(void 0, void 0, void 0, function () {
41
+ return __generator(this, function (_a) {
42
+ switch (_a.label) {
43
+ case 0: return [4 /*yield*/, options.httpClient.delete("/accounts/" + accountId)];
44
+ case 1:
45
+ _a.sent();
46
+ return [2 /*return*/];
47
+ }
48
+ });
49
+ }); }; };
50
+ var getAccount = function (options) {
51
+ return function (accountId) { return __awaiter(void 0, void 0, void 0, function () {
52
+ var response;
53
+ return __generator(this, function (_a) {
54
+ switch (_a.label) {
55
+ case 0: return [4 /*yield*/, options.httpClient.get("/accounts/" + accountId)];
56
+ case 1:
57
+ response = _a.sent();
58
+ return [2 /*return*/, response.data];
59
+ }
60
+ });
61
+ }); };
62
+ };
63
+ var listAccounts = function (options) {
64
+ return function (listOptions) { return __awaiter(void 0, void 0, void 0, function () {
65
+ var response;
66
+ return __generator(this, function (_a) {
67
+ switch (_a.label) {
68
+ case 0: return [4 /*yield*/, options.httpClient.get("/accounts", undefined, {
69
+ params: {
70
+ cursor: (listOptions === null || listOptions === void 0 ? void 0 : listOptions.cursor) || "",
71
+ limit: (listOptions === null || listOptions === void 0 ? void 0 : listOptions.limit) || "20",
72
+ },
73
+ })];
74
+ case 1:
75
+ response = _a.sent();
76
+ return [2 /*return*/, response.data];
77
+ }
78
+ });
79
+ }); };
80
+ };
81
+ var putAccount = function (options) {
82
+ return function (account) { return __awaiter(void 0, void 0, void 0, function () {
83
+ var response;
84
+ return __generator(this, function (_a) {
85
+ switch (_a.label) {
86
+ case 0: return [4 /*yield*/, options.httpClient.put("/accounts/" + account.id, account)];
87
+ case 1:
88
+ response = _a.sent();
89
+ return [2 /*return*/, response.data];
90
+ }
91
+ });
92
+ }); };
93
+ };
94
+ exports.accounts = function (options) { return ({
95
+ delete: deleteAccount(options),
96
+ get: getAccount(options),
97
+ listAccounts: listAccounts(options),
98
+ put: putAccount(options),
99
+ }); };
@@ -0,0 +1,27 @@
1
+ export interface IAccount {
2
+ brand_id?: string;
3
+ id: string;
4
+ name: string;
5
+ parent_account_id?: string;
6
+ properties?: {
7
+ [key: string]: any;
8
+ };
9
+ user_profile?: Record<string, any>;
10
+ type: "account";
11
+ }
12
+ export interface IPaginatedResult<T> {
13
+ cursor?: string;
14
+ has_more: boolean;
15
+ items: T[];
16
+ type: "list";
17
+ }
18
+ export interface IAccountListOptions {
19
+ cursor?: string;
20
+ limit?: string;
21
+ }
22
+ export interface ICourierClientAccounts {
23
+ delete: (id: string) => Promise<void>;
24
+ get: (id: string) => Promise<IAccount>;
25
+ listAccounts: (options?: IAccountListOptions) => Promise<IPaginatedResult<IAccount>>;
26
+ put: (account: Omit<IAccount, "type">) => Promise<IAccount>;
27
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/lib/client.js CHANGED
@@ -37,6 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.client = void 0;
40
+ var accounts_1 = require("./accounts");
40
41
  var audiences_1 = require("./audiences");
41
42
  var audit_events_1 = require("./audit-events");
42
43
  var automations_1 = require("./automations");
@@ -101,8 +102,8 @@ var getMessages = function (options) {
101
102
  notification: params === null || params === void 0 ? void 0 : params.notificationId,
102
103
  recipient: params === null || params === void 0 ? void 0 : params.recipientId,
103
104
  status: params === null || params === void 0 ? void 0 : params.status,
104
- tags: params === null || params === void 0 ? void 0 : params.tags
105
- }
105
+ tags: params === null || params === void 0 ? void 0 : params.tags,
106
+ },
106
107
  })];
107
108
  case 1:
108
109
  res = _a.sent();
@@ -113,6 +114,7 @@ var getMessages = function (options) {
113
114
  };
114
115
  exports.client = function (options) {
115
116
  return {
117
+ accounts: accounts_1.accounts(options),
116
118
  addRecipientToLists: profile_1.addRecipientToLists(options),
117
119
  audiences: audiences_1.audiences(options),
118
120
  auditEvents: audit_events_1.auditEvents(options),
@@ -137,6 +139,6 @@ exports.client = function (options) {
137
139
  replaceBrand: brands_1.replaceBrand(options),
138
140
  replaceProfile: profile_1.replaceProfile(options),
139
141
  send: send_1.send(options),
140
- tokenManagement: token_management_1.tokenManagement(options)
142
+ tokenManagement: token_management_1.tokenManagement(options),
141
143
  };
142
144
  };
@@ -227,6 +227,7 @@ export interface AudienceRecipient {
227
227
  data?: MessageData;
228
228
  }
229
229
  export interface UserRecipient extends UserRecipientType {
230
+ account_id?: string;
230
231
  data?: MessageData;
231
232
  email?: string;
232
233
  locale?: string;
package/lib/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ICourierClientAccounts } from "./accounts/types";
1
2
  import { ICourierClientAudiences } from "./audiences/types";
2
3
  import { auditEvents } from "./audit-events";
3
4
  import { ICourierClientAutomations } from "./automations/types";
@@ -299,6 +300,7 @@ export interface ICourierBrandGetAllResponse {
299
300
  export declare type SendResponse<T extends ICourierSendParameters | ICourierSendMessageParameters> = T extends ICourierSendParameters ? ICourierSendResponse : ICourierSendMessageResponse;
300
301
  export interface ICourierClient {
301
302
  addRecipientToLists: (params: ICourierProfileListsPostParameters) => Promise<ICourierProfilePostResponse>;
303
+ accounts: ICourierClientAccounts;
302
304
  audiences: ICourierClientAudiences;
303
305
  auditEvents: ReturnType<typeof auditEvents>;
304
306
  automations: ICourierClientAutomations;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/courier",
3
- "version": "4.2.0",
3
+ "version": "4.4.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",