@trycourier/courier 5.3.0 → 5.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 +42 -28
- package/lib/users/index.d.ts +4 -1
- package/lib/users/index.js +45 -1
- package/lib/users/types.d.ts +27 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -434,22 +434,6 @@ async function run() {
|
|
|
434
434
|
);
|
|
435
435
|
console.log(items);
|
|
436
436
|
|
|
437
|
-
// Example: Notification Preferences
|
|
438
|
-
await courier.preferences.put(recipientId, {
|
|
439
|
-
notifications: {
|
|
440
|
-
"<NOTIFICATION_ID>": { status: "<OPT_IN_STATUS>" },
|
|
441
|
-
},
|
|
442
|
-
});
|
|
443
|
-
// Where OPT_IN_STATUS = "OPTED_IN" | "OPTED_OUT"
|
|
444
|
-
|
|
445
|
-
// Example: Get a list of existing notifications and categories
|
|
446
|
-
const prefs = await courier.preferences.list();
|
|
447
|
-
console.log(prefs);
|
|
448
|
-
|
|
449
|
-
// Example: Get the preferences stored under a specified recipient ID.
|
|
450
|
-
const profilePrefs = await courier.preferences.get(recipientId);
|
|
451
|
-
console.log(profilePrefs);
|
|
452
|
-
|
|
453
437
|
// Example: Automation Ad-Hoc Invoke
|
|
454
438
|
const { runId } = await courier.automations.invokeAdHocAutomation({
|
|
455
439
|
automation: {
|
|
@@ -782,45 +766,45 @@ const { requestId } = await courier.send({
|
|
|
782
766
|
});
|
|
783
767
|
```
|
|
784
768
|
|
|
785
|
-
###
|
|
769
|
+
### Tenants
|
|
786
770
|
|
|
787
|
-
The
|
|
771
|
+
The Tenants API is designed to enable multi-tenant notification workflows. This is useful for defining user to tenant level relationships, especially in the context of B2B applications.
|
|
788
772
|
|
|
789
773
|
Use Cases:
|
|
790
774
|
|
|
791
775
|
- Sending branded notifications on behalf of an organization
|
|
792
776
|
- Creating slack-bots on behalf of an organization
|
|
793
777
|
|
|
794
|
-
#### Creating
|
|
778
|
+
#### Creating a Tenant
|
|
795
779
|
|
|
796
780
|
```ts
|
|
797
|
-
const {
|
|
798
|
-
id: "<
|
|
781
|
+
const { tenantId } = await courier.tenants.put({
|
|
782
|
+
id: "<TENANT_ID>",
|
|
799
783
|
name: "Courier",
|
|
800
784
|
user_profile: {
|
|
801
785
|
slack: {
|
|
802
|
-
access_token: "<
|
|
786
|
+
access_token: "<SLACK_ACCESS_TOKEN_SCOPED_TO_THE_TENANT>",
|
|
803
787
|
},
|
|
804
788
|
},
|
|
805
789
|
});
|
|
806
790
|
```
|
|
807
791
|
|
|
808
|
-
#### Retrieving
|
|
792
|
+
#### Retrieving a Tenant
|
|
809
793
|
|
|
810
794
|
```ts
|
|
811
|
-
const account = await courier.
|
|
795
|
+
const account = await courier.tenants.get("<TENANT_ID>");
|
|
812
796
|
```
|
|
813
797
|
|
|
814
|
-
#### Deleting
|
|
798
|
+
#### Deleting a Tenant
|
|
815
799
|
|
|
816
800
|
```ts
|
|
817
|
-
await courier.
|
|
801
|
+
await courier.tenants.delete("<TENANT_ID>");
|
|
818
802
|
```
|
|
819
803
|
|
|
820
|
-
#### Listing
|
|
804
|
+
#### Listing Tenants
|
|
821
805
|
|
|
822
806
|
```ts
|
|
823
|
-
const { items:
|
|
807
|
+
const { items: tenants, has_more, next_page } = await courier.tenants.list();
|
|
824
808
|
```
|
|
825
809
|
|
|
826
810
|
### Users
|
|
@@ -842,6 +826,36 @@ await courier.users.putAccounts("<USER_ID>", {
|
|
|
842
826
|
});
|
|
843
827
|
```
|
|
844
828
|
|
|
829
|
+
#### Updating user preferences
|
|
830
|
+
|
|
831
|
+
Courier currently does not allow creating new topics via the API. You must create topics via the Courier UI. Once a topic is created, you can update a user's preferences for that topic via the API.
|
|
832
|
+
|
|
833
|
+
```ts
|
|
834
|
+
await courier.users.putUserPreferenceByTopic(mockUserId, "<VALID_TOPIC_ID>", {
|
|
835
|
+
default_status: "OPTED_IN",
|
|
836
|
+
status: "OPTED_OUT",
|
|
837
|
+
});
|
|
838
|
+
```
|
|
839
|
+
|
|
840
|
+
#### Getting user preferences
|
|
841
|
+
|
|
842
|
+
- Get all topic level preferences for a user
|
|
843
|
+
|
|
844
|
+
```ts
|
|
845
|
+
const { items: userPreferences } = await courier.users.getUserPreferences(
|
|
846
|
+
"<USER_ID>"
|
|
847
|
+
);
|
|
848
|
+
```
|
|
849
|
+
|
|
850
|
+
- Get a specific topic level preference for a user
|
|
851
|
+
|
|
852
|
+
```ts
|
|
853
|
+
const userPreference = await courier.users.getUserPreferenceByTopic(
|
|
854
|
+
"<USER_ID>",
|
|
855
|
+
"<VALID_TOPIC_ID>"
|
|
856
|
+
);
|
|
857
|
+
```
|
|
858
|
+
|
|
845
859
|
## License
|
|
846
860
|
|
|
847
861
|
[MIT License](http://www.opensource.org/licenses/mit-license.php)
|
package/lib/users/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ICourierClientConfiguration } from "../types";
|
|
2
|
-
import { IUser, IUserAccount } from "./types";
|
|
2
|
+
import { ITopicPreference, IUser, IUserAccount } from "./types";
|
|
3
3
|
export declare const users: (options: ICourierClientConfiguration) => {
|
|
4
|
+
getUserPreferenceByTopic: (userId: string, topicId: string) => Promise<ITopicPreference>;
|
|
5
|
+
getUserPreferenceByTopics: (userId: string) => Promise<object>;
|
|
4
6
|
put: (id: string, user: IUser) => Promise<void>;
|
|
5
7
|
putAccounts: (id: string, accounts: IUserAccount[]) => Promise<void>;
|
|
8
|
+
putUserPreferenceByTopic: (userId: string, topicId: string, topic: Omit<ITopicPreference, "topic_id" | "topic_name">) => Promise<void>;
|
|
6
9
|
};
|
package/lib/users/index.js
CHANGED
|
@@ -61,7 +61,51 @@ var putAccounts = function (options) {
|
|
|
61
61
|
});
|
|
62
62
|
}); };
|
|
63
63
|
};
|
|
64
|
+
var putUserPreferenceByTopic = function (options) {
|
|
65
|
+
return function (userId, topicId, topic) { return __awaiter(void 0, void 0, void 0, function () {
|
|
66
|
+
return __generator(this, function (_a) {
|
|
67
|
+
switch (_a.label) {
|
|
68
|
+
case 0: return [4 /*yield*/, options.httpClient.put("/users/" + userId + "/preferences/" + topicId, {
|
|
69
|
+
topic: topic,
|
|
70
|
+
})];
|
|
71
|
+
case 1:
|
|
72
|
+
_a.sent();
|
|
73
|
+
return [2 /*return*/];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}); };
|
|
77
|
+
};
|
|
78
|
+
var getUserPreferenceByTopic = function (options) {
|
|
79
|
+
return function (userId, topicId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
80
|
+
var res;
|
|
81
|
+
var _a;
|
|
82
|
+
return __generator(this, function (_b) {
|
|
83
|
+
switch (_b.label) {
|
|
84
|
+
case 0: return [4 /*yield*/, options.httpClient.get("/users/" + userId + "/preferences/" + topicId)];
|
|
85
|
+
case 1:
|
|
86
|
+
res = _b.sent();
|
|
87
|
+
return [2 /*return*/, (_a = res.data) === null || _a === void 0 ? void 0 : _a.topic];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}); };
|
|
91
|
+
};
|
|
92
|
+
var getUserPreferenceByTopics = function (options) {
|
|
93
|
+
return function (userId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
94
|
+
var res;
|
|
95
|
+
return __generator(this, function (_a) {
|
|
96
|
+
switch (_a.label) {
|
|
97
|
+
case 0: return [4 /*yield*/, options.httpClient.get("/users/" + userId + "/preferences")];
|
|
98
|
+
case 1:
|
|
99
|
+
res = _a.sent();
|
|
100
|
+
return [2 /*return*/, res.data];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}); };
|
|
104
|
+
};
|
|
64
105
|
exports.users = function (options) { return ({
|
|
106
|
+
getUserPreferenceByTopic: getUserPreferenceByTopic(options),
|
|
107
|
+
getUserPreferenceByTopics: getUserPreferenceByTopics(options),
|
|
65
108
|
put: put(options),
|
|
66
|
-
putAccounts: putAccounts(options)
|
|
109
|
+
putAccounts: putAccounts(options),
|
|
110
|
+
putUserPreferenceByTopic: putUserPreferenceByTopic(options),
|
|
67
111
|
}); };
|
package/lib/users/types.d.ts
CHANGED
|
@@ -6,7 +6,34 @@ export interface IUser {
|
|
|
6
6
|
accounts: IUserAccount[];
|
|
7
7
|
profile: Record<string, any>;
|
|
8
8
|
}
|
|
9
|
+
export declare type ChannelClassification = "direct_message" | "email" | "push" | "sms" | "webhook" | "inbox";
|
|
10
|
+
export interface ITopicPreference {
|
|
11
|
+
/**
|
|
12
|
+
* Should contain unique items.
|
|
13
|
+
*/
|
|
14
|
+
custom_routing?: ChannelClassification[];
|
|
15
|
+
default_status: "OPTED_IN" | "OPTED_OUT";
|
|
16
|
+
has_custom_routing?: boolean;
|
|
17
|
+
status: "OPTED_IN" | "OPTED_OUT";
|
|
18
|
+
topic_id: string;
|
|
19
|
+
topic_name: string;
|
|
20
|
+
}
|
|
21
|
+
interface IPagingInfo {
|
|
22
|
+
cursor: string;
|
|
23
|
+
more: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface IGetTopicPreferencesResponse {
|
|
26
|
+
topic: ITopicPreference;
|
|
27
|
+
}
|
|
28
|
+
export interface IGetTopicsResponse {
|
|
29
|
+
paging: IPagingInfo;
|
|
30
|
+
items: ITopicPreference[];
|
|
31
|
+
}
|
|
9
32
|
export interface ICourierClientUsers {
|
|
33
|
+
getUserPreferenceByTopic: (userId: string, topicId: string) => Promise<IGetTopicPreferencesResponse>;
|
|
34
|
+
getUserPreferenceByTopics: (userId: string) => Promise<IGetTopicsResponse>;
|
|
10
35
|
put: (id: string, user: IUser) => Promise<void>;
|
|
11
36
|
putAccounts: (id: string, accounts: IUserAccount[]) => Promise<void>;
|
|
37
|
+
putUserPreferenceByTopic: (userId: string, topicId: string, topic: Omit<ITopicPreference, "topic_id" | "topic_name">) => Promise<void>;
|
|
12
38
|
}
|
|
39
|
+
export {};
|