@knocklabs/node 0.4.2 → 0.4.5
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/dist/package.json +1 -1
- package/dist/src/common/interfaces.d.ts +20 -0
- package/dist/src/knock.d.ts +2 -0
- package/dist/src/knock.js +2 -0
- package/dist/src/resources/activities/interfaces.d.ts +11 -0
- package/dist/src/resources/activities/interfaces.js +2 -0
- package/dist/src/resources/messages/index.d.ts +13 -0
- package/dist/src/resources/messages/index.js +60 -0
- package/dist/src/resources/messages/interfaces.d.ts +43 -0
- package/dist/src/resources/messages/interfaces.js +2 -0
- package/dist/src/resources/objects/index.d.ts +18 -1
- package/dist/src/resources/objects/index.js +92 -0
- package/dist/src/resources/preferences/helpers.d.ts +1 -1
- package/dist/src/resources/preferences/interfaces.d.ts +6 -3
- package/dist/src/resources/users/index.d.ts +9 -2
- package/dist/src/resources/users/index.js +29 -0
- package/dist/src/resources/users/interfaces.d.ts +2 -4
- package/dist/src/resources/workflows/interfaces.d.ts +4 -2
- package/package.json +1 -1
package/dist/package.json
CHANGED
|
@@ -23,3 +23,23 @@ export interface ChannelData<T = CommonMetadata> {
|
|
|
23
23
|
}
|
|
24
24
|
export interface SetChannelDataProperties {
|
|
25
25
|
}
|
|
26
|
+
declare type PageInfo = {
|
|
27
|
+
before: string;
|
|
28
|
+
after: string;
|
|
29
|
+
page_size: number;
|
|
30
|
+
};
|
|
31
|
+
export interface PaginatedResponse<T> {
|
|
32
|
+
entries: T[];
|
|
33
|
+
page_info: PageInfo;
|
|
34
|
+
}
|
|
35
|
+
export interface PaginationOptions {
|
|
36
|
+
page_size?: number;
|
|
37
|
+
after?: string;
|
|
38
|
+
before?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface Condition {
|
|
41
|
+
argument: string;
|
|
42
|
+
variable: string;
|
|
43
|
+
operator: string;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
package/dist/src/knock.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { Workflows } from "./resources/workflows";
|
|
|
6
6
|
import { TriggerWorkflowProperties } from "./resources/workflows/interfaces";
|
|
7
7
|
import { BulkOperations } from "./resources/bulk_operations";
|
|
8
8
|
import { Objects } from "./resources/objects";
|
|
9
|
+
import { Messages } from "./resources/messages";
|
|
9
10
|
declare class Knock {
|
|
10
11
|
readonly key?: string | undefined;
|
|
11
12
|
readonly options: KnockOptions;
|
|
@@ -16,6 +17,7 @@ declare class Knock {
|
|
|
16
17
|
readonly workflows: Workflows;
|
|
17
18
|
readonly bulkOperations: BulkOperations;
|
|
18
19
|
readonly objects: Objects;
|
|
20
|
+
readonly messages: Messages;
|
|
19
21
|
constructor(key?: string | undefined, options?: KnockOptions);
|
|
20
22
|
notify(workflowKey: string, properties: TriggerWorkflowProperties): Promise<import("./resources/workflows/interfaces").WorkflowRun>;
|
|
21
23
|
post(path: string, entity: any, options?: PostAndPutOptions): Promise<AxiosResponse>;
|
package/dist/src/knock.js
CHANGED
|
@@ -21,6 +21,7 @@ const preferences_1 = require("./resources/preferences");
|
|
|
21
21
|
const workflows_1 = require("./resources/workflows");
|
|
22
22
|
const bulk_operations_1 = require("./resources/bulk_operations");
|
|
23
23
|
const objects_1 = require("./resources/objects");
|
|
24
|
+
const messages_1 = require("./resources/messages");
|
|
24
25
|
const DEFAULT_HOSTNAME = "https://api.knock.app";
|
|
25
26
|
class Knock {
|
|
26
27
|
constructor(key, options = {}) {
|
|
@@ -32,6 +33,7 @@ class Knock {
|
|
|
32
33
|
this.workflows = new workflows_1.Workflows(this);
|
|
33
34
|
this.bulkOperations = new bulk_operations_1.BulkOperations(this);
|
|
34
35
|
this.objects = new objects_1.Objects(this);
|
|
36
|
+
this.messages = new messages_1.Messages(this);
|
|
35
37
|
if (!key) {
|
|
36
38
|
this.key = process.env.KNOCK_API_KEY;
|
|
37
39
|
if (!this.key) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { User } from "../users/interfaces";
|
|
2
|
+
import { Object } from "../objects/interfaces";
|
|
3
|
+
export interface Activity {
|
|
4
|
+
id: string;
|
|
5
|
+
data: Record<string, any>;
|
|
6
|
+
actor: User | Object;
|
|
7
|
+
recipient: User | Object;
|
|
8
|
+
inserted_at: string;
|
|
9
|
+
updated_at: string;
|
|
10
|
+
__cursor?: string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PaginatedResponse, PaginationOptions } from "../../common/interfaces";
|
|
2
|
+
import { Message, MessageContent, MessageEvent, ListMessagesOptions } from "./interfaces";
|
|
3
|
+
import { Activity } from "../activities/interfaces";
|
|
4
|
+
import { Knock } from "../../knock";
|
|
5
|
+
export declare class Messages {
|
|
6
|
+
readonly knock: Knock;
|
|
7
|
+
constructor(knock: Knock);
|
|
8
|
+
list(filteringOptions?: ListMessagesOptions): Promise<Message>;
|
|
9
|
+
get(messageId: string): Promise<Message>;
|
|
10
|
+
getContent(messageId: string): Promise<MessageContent>;
|
|
11
|
+
getEvents(messageId: string, paginationOptions?: PaginationOptions): Promise<PaginatedResponse<MessageEvent>>;
|
|
12
|
+
getActivities(messageId: string, paginationOptions?: PaginationOptions): Promise<PaginatedResponse<Activity>>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Messages = void 0;
|
|
13
|
+
class Messages {
|
|
14
|
+
constructor(knock) {
|
|
15
|
+
this.knock = knock;
|
|
16
|
+
}
|
|
17
|
+
list(filteringOptions = {}) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const { data } = yield this.knock.get("/v1/messages", filteringOptions);
|
|
20
|
+
return data;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
get(messageId) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
if (!messageId) {
|
|
26
|
+
throw new Error(`Incomplete arguments. You must provide a 'messageId'`);
|
|
27
|
+
}
|
|
28
|
+
const { data } = yield this.knock.get(`/v1/messages/${messageId}`);
|
|
29
|
+
return data;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
getContent(messageId) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
if (!messageId) {
|
|
35
|
+
throw new Error(`Incomplete arguments. You must provide a 'messageId'`);
|
|
36
|
+
}
|
|
37
|
+
const { data } = yield this.knock.get(`/v1/messages/${messageId}/content`);
|
|
38
|
+
return data;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
getEvents(messageId, paginationOptions = {}) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
if (!messageId) {
|
|
44
|
+
throw new Error(`Incomplete arguments. You must provide a 'messageId'`);
|
|
45
|
+
}
|
|
46
|
+
const { data } = yield this.knock.get(`/v1/messages/${messageId}/events`, paginationOptions);
|
|
47
|
+
return data;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
getActivities(messageId, paginationOptions = {}) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
if (!messageId) {
|
|
53
|
+
throw new Error(`Incomplete arguments. You must provide a 'messageId'`);
|
|
54
|
+
}
|
|
55
|
+
const { data } = yield this.knock.get(`/v1/messages/${messageId}/activities`, paginationOptions);
|
|
56
|
+
return data;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.Messages = Messages;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ObjectRef } from "../objects/interfaces";
|
|
2
|
+
import { PaginationOptions } from "../../common/interfaces";
|
|
3
|
+
export interface Message {
|
|
4
|
+
id: string;
|
|
5
|
+
channel_id: string;
|
|
6
|
+
recipient: string | ObjectRef;
|
|
7
|
+
tenant: string | null;
|
|
8
|
+
status: MessageStatus;
|
|
9
|
+
read_at: string | null;
|
|
10
|
+
seen_at: string | null;
|
|
11
|
+
archived_at: string | null;
|
|
12
|
+
inserted_at: string;
|
|
13
|
+
updated_at: string;
|
|
14
|
+
source: WorkflowSource;
|
|
15
|
+
data: any;
|
|
16
|
+
__cursor?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface MessageEvent {
|
|
19
|
+
id: string;
|
|
20
|
+
environment_id: string;
|
|
21
|
+
recipient: string | ObjectRef;
|
|
22
|
+
data: Record<string, any>;
|
|
23
|
+
type: string;
|
|
24
|
+
inserted_at: string;
|
|
25
|
+
__cursor?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface MessageContent {
|
|
28
|
+
id: string;
|
|
29
|
+
data: Record<string, any>;
|
|
30
|
+
inserted_at: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ListMessagesOptions extends PaginationOptions {
|
|
33
|
+
source?: string;
|
|
34
|
+
tenant?: string;
|
|
35
|
+
status?: MessageStatus[];
|
|
36
|
+
channel_id?: string;
|
|
37
|
+
}
|
|
38
|
+
declare type WorkflowSource = {
|
|
39
|
+
version_id: string;
|
|
40
|
+
key: string;
|
|
41
|
+
};
|
|
42
|
+
declare type MessageStatus = "queued" | "sent" | "delivered" | "undelivered" | "not_sent";
|
|
43
|
+
export {};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { ChannelData, CommonMetadata, SetChannelDataProperties } from "../../common/interfaces";
|
|
1
|
+
import { ChannelData, CommonMetadata, SetChannelDataProperties, PaginatedResponse, ChannelType } from "../../common/interfaces";
|
|
2
2
|
import { Knock } from "../../knock";
|
|
3
3
|
import { BulkSetObjectOption, Object, SetObjectProperties } from "./interfaces";
|
|
4
4
|
import { BulkOperation } from "../bulk_operations/interfaces";
|
|
5
|
+
import { ListMessagesOptions, Message } from "../messages/interfaces";
|
|
6
|
+
import { ChannelTypePreferences, PreferenceOptions, PreferenceSet, SetPreferencesProperties, WorkflowPreferences, WorkflowPreferenceSetting } from "../preferences/interfaces";
|
|
5
7
|
export declare class Objects {
|
|
6
8
|
readonly knock: Knock;
|
|
7
9
|
constructor(knock: Knock);
|
|
@@ -12,4 +14,19 @@ export declare class Objects {
|
|
|
12
14
|
bulkDelete(collection: string, objectIds: string[]): Promise<BulkOperation>;
|
|
13
15
|
getChannelData<T = CommonMetadata>(collection: string, id: string, channelId: string): Promise<ChannelData<T>>;
|
|
14
16
|
setChannelData<T = CommonMetadata>(collection: string, id: string, channelId: string, channelData: SetChannelDataProperties): Promise<ChannelData<T>>;
|
|
17
|
+
unsetChannelData(collection: string, id: string, channelId: string): Promise<any>;
|
|
18
|
+
getMessages(collection: string, objectId: string, filteringOptions?: ListMessagesOptions): Promise<PaginatedResponse<Message>>;
|
|
19
|
+
getAllPreferences(collection: string, objectId: string): Promise<PreferenceSet[]>;
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use `objects.getPreferences` instead
|
|
22
|
+
*/
|
|
23
|
+
getPrefences(collection: string, objectId: string, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
24
|
+
getPreferences(collection: string, objectId: string, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
25
|
+
setPreferences(collection: string, objectId: string, preferenceSet: SetPreferencesProperties, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
26
|
+
setChannelTypesPreferences(collection: string, objectId: string, channelTypePreferences: ChannelTypePreferences, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
27
|
+
setChannelTypePreferences(collection: string, objectId: string, channelType: ChannelType, setting: boolean, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
28
|
+
setWorkflowsPreferences(collection: string, objectId: string, workflowPreferences: WorkflowPreferences, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
29
|
+
setWorkflowPreferences(collection: string, objectId: string, workflowKey: string, setting: WorkflowPreferenceSetting, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
30
|
+
setCategoriesPreferences(collection: string, objectId: string, categoryPreferences: WorkflowPreferences, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
31
|
+
setCategoryPreferences(collection: string, objectId: string, categoryKey: string, setting: WorkflowPreferenceSetting, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
15
32
|
}
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Objects = void 0;
|
|
13
|
+
const helpers_1 = require("../preferences/helpers");
|
|
13
14
|
class Objects {
|
|
14
15
|
constructor(knock) {
|
|
15
16
|
this.knock = knock;
|
|
@@ -62,5 +63,96 @@ class Objects {
|
|
|
62
63
|
return data;
|
|
63
64
|
});
|
|
64
65
|
}
|
|
66
|
+
unsetChannelData(collection, id, channelId) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const { data } = yield this.knock.delete(`/v1/objects/${collection}/${id}/channel_data/${channelId}`);
|
|
69
|
+
return data;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
//
|
|
73
|
+
// Messages
|
|
74
|
+
//
|
|
75
|
+
getMessages(collection, objectId, filteringOptions = {}) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
if (!collection || !objectId) {
|
|
78
|
+
throw new Error(`Incomplete arguments. You must provide a 'collection' and 'objectId'`);
|
|
79
|
+
}
|
|
80
|
+
const { data } = yield this.knock.get(`/v1/objects/${collection}/${objectId}/messages`, filteringOptions);
|
|
81
|
+
return data;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
//
|
|
85
|
+
// Preferences
|
|
86
|
+
//
|
|
87
|
+
getAllPreferences(collection, objectId) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
const { data } = yield this.knock.get(`/v1/objects/${collection}/${objectId}/preferences`);
|
|
90
|
+
return data;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* @deprecated Use `objects.getPreferences` instead
|
|
95
|
+
*/
|
|
96
|
+
getPrefences(collection, objectId, options = {}) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
return this.getPreferences(collection, objectId, options);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
getPreferences(collection, objectId, options = {}) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
104
|
+
const { data } = yield this.knock.get(`/v1/objects/${collection}/${objectId}/preferences/${preferenceSetId}`);
|
|
105
|
+
return data;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
setPreferences(collection, objectId, preferenceSet, options = {}) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
111
|
+
const { data } = yield this.knock.put(`/v1/objects/${collection}/${objectId}/preferences/${preferenceSetId}`, preferenceSet);
|
|
112
|
+
return data;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
setChannelTypesPreferences(collection, objectId, channelTypePreferences, options = {}) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
118
|
+
const { data } = yield this.knock.put(`/v1/objects/${collection}/${objectId}/preferences/${preferenceSetId}/channel_types`, channelTypePreferences);
|
|
119
|
+
return data;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
setChannelTypePreferences(collection, objectId, channelType, setting, options = {}) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
125
|
+
const { data, } = yield this.knock.put(`/v1/objects/${collection}/${objectId}/preferences/${preferenceSetId}/channel_types/${channelType}`, { subscribed: setting });
|
|
126
|
+
return data;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
setWorkflowsPreferences(collection, objectId, workflowPreferences, options = {}) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
132
|
+
const { data } = yield this.knock.put(`/v1/objects/${collection}/${objectId}/preferences/${preferenceSetId}/workflows`, workflowPreferences);
|
|
133
|
+
return data;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
setWorkflowPreferences(collection, objectId, workflowKey, setting, options = {}) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
139
|
+
const { data } = yield this.knock.put(`/v1/objects/${collection}/${objectId}/preferences/${preferenceSetId}/workflows/${workflowKey}`, helpers_1.buildUpdateParam(setting));
|
|
140
|
+
return data;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
setCategoriesPreferences(collection, objectId, categoryPreferences, options = {}) {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
146
|
+
const { data } = yield this.knock.put(`/v1/objects/${collection}/${objectId}/preferences/${preferenceSetId}/categories`, categoryPreferences);
|
|
147
|
+
return data;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
setCategoryPreferences(collection, objectId, categoryKey, setting, options = {}) {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
153
|
+
const { data } = yield this.knock.put(`/v1/objects/${collection}/${objectId}/preferences/${preferenceSetId}/categories/${categoryKey}`, helpers_1.buildUpdateParam(setting));
|
|
154
|
+
return data;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
65
157
|
}
|
|
66
158
|
exports.Objects = Objects;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WorkflowPreferenceSetting } from "./interfaces";
|
|
2
|
-
export declare function buildUpdateParam(param: WorkflowPreferenceSetting): {
|
|
2
|
+
export declare function buildUpdateParam(param: WorkflowPreferenceSetting): import("./interfaces").ConditionalPreferenceSettings | {
|
|
3
3
|
channel_types: import("./interfaces").ChannelTypePreferences;
|
|
4
4
|
} | {
|
|
5
5
|
subscribed: boolean;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { ChannelType } from "../../common/interfaces";
|
|
1
|
+
import { ChannelType, Condition } from "../../common/interfaces";
|
|
2
|
+
export declare type ConditionalPreferenceSettings = {
|
|
3
|
+
conditions: Condition[];
|
|
4
|
+
};
|
|
2
5
|
export declare type ChannelTypePreferences = {
|
|
3
|
-
[K in ChannelType]
|
|
6
|
+
[K in ChannelType]?: boolean | ConditionalPreferenceSettings;
|
|
4
7
|
};
|
|
5
8
|
export declare type WorkflowPreferenceSetting = boolean | {
|
|
6
9
|
channel_types: ChannelTypePreferences;
|
|
7
|
-
};
|
|
10
|
+
} | ConditionalPreferenceSettings;
|
|
8
11
|
export interface WorkflowPreferences {
|
|
9
12
|
[key: string]: WorkflowPreferenceSetting;
|
|
10
13
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ChannelData, ChannelType, CommonMetadata } from "../../common/interfaces";
|
|
1
|
+
import { ChannelData, ChannelType, CommonMetadata, PaginatedResponse } from "../../common/interfaces";
|
|
2
2
|
import { BulkOperation } from "../bulk_operations/interfaces";
|
|
3
3
|
import { ChannelTypePreferences, PreferenceOptions, PreferenceSet, SetPreferencesProperties, WorkflowPreferences, WorkflowPreferenceSetting } from "../preferences/interfaces";
|
|
4
|
+
import { ListMessagesOptions, Message } from "../messages/interfaces";
|
|
4
5
|
import { Knock } from "../../knock";
|
|
5
6
|
import { BulkIdentifyUser, IdentifyProperties, User, UserFeedOptions } from "./interfaces";
|
|
6
7
|
export declare class Users {
|
|
@@ -14,7 +15,11 @@ export declare class Users {
|
|
|
14
15
|
merge(toUserId: string, fromUserId: string): Promise<User>;
|
|
15
16
|
getFeed(userId: string, channelId: string, feedOptions?: UserFeedOptions): Promise<any>;
|
|
16
17
|
getAllPreferences(userId: string): Promise<any>;
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Use `users.getPreferences` instead
|
|
20
|
+
*/
|
|
17
21
|
getPrefences(userId: string, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
22
|
+
getPreferences(userId: string, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
18
23
|
setPreferences(userId: string, preferenceSet: SetPreferencesProperties, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
19
24
|
bulkSetPreferences(userIds: string[], preferenceSet: SetPreferencesProperties, options?: PreferenceOptions): Promise<BulkOperation>;
|
|
20
25
|
setChannelTypesPreferences(userId: string, channelTypePreferences: ChannelTypePreferences, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
@@ -24,5 +29,7 @@ export declare class Users {
|
|
|
24
29
|
setCategoriesPreferences(userId: string, categoryPreferences: WorkflowPreferences, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
25
30
|
setCategoryPreferences(userId: string, categoryKey: string, setting: WorkflowPreferenceSetting, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
26
31
|
getChannelData<T = CommonMetadata>(userId: string, channelId: string): Promise<ChannelData<T>>;
|
|
27
|
-
setChannelData<T = CommonMetadata>(userId: string, channelId: string, channelData: Record<string,
|
|
32
|
+
setChannelData<T = CommonMetadata>(userId: string, channelId: string, channelData: Record<string, any>): Promise<ChannelData<T>>;
|
|
33
|
+
unsetChannelData(userId: string, channelId: string): Promise<any>;
|
|
34
|
+
getMessages(userId: string, filteringOptions?: ListMessagesOptions): Promise<PaginatedResponse<Message>>;
|
|
28
35
|
}
|
|
@@ -88,7 +88,15 @@ class Users {
|
|
|
88
88
|
return data;
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* @deprecated Use `users.getPreferences` instead
|
|
93
|
+
*/
|
|
91
94
|
getPrefences(userId, options = {}) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
return this.getPreferences(userId, options);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
getPreferences(userId, options = {}) {
|
|
92
100
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
101
|
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
94
102
|
const { data } = yield this.knock.get(`/v1/users/${userId}/preferences/${preferenceSetId}`);
|
|
@@ -177,5 +185,26 @@ class Users {
|
|
|
177
185
|
return data;
|
|
178
186
|
});
|
|
179
187
|
}
|
|
188
|
+
unsetChannelData(userId, channelId) {
|
|
189
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
+
if (!userId || !channelId) {
|
|
191
|
+
throw new Error(`Incomplete arguments. You must provide a 'userId' and a 'channelId'`);
|
|
192
|
+
}
|
|
193
|
+
const { data } = yield this.knock.delete(`/v1/users/${userId}/channel_data/${channelId}`);
|
|
194
|
+
return data;
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
//
|
|
198
|
+
// Messages
|
|
199
|
+
//
|
|
200
|
+
getMessages(userId, filteringOptions = {}) {
|
|
201
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
202
|
+
if (!userId) {
|
|
203
|
+
throw new Error(`Incomplete arguments. You must provide a 'userId'`);
|
|
204
|
+
}
|
|
205
|
+
const { data } = yield this.knock.get(`/v1/users/${userId}/messages`, filteringOptions);
|
|
206
|
+
return data;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
180
209
|
}
|
|
181
210
|
exports.Users = Users;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PaginationOptions } from "../../common/interfaces";
|
|
1
2
|
export interface IdentifyProperties {
|
|
2
3
|
name?: string;
|
|
3
4
|
email?: string;
|
|
@@ -16,10 +17,7 @@ export interface User {
|
|
|
16
17
|
export interface BulkIdentifyUser extends IdentifyProperties {
|
|
17
18
|
id: string;
|
|
18
19
|
}
|
|
19
|
-
export interface UserFeedOptions {
|
|
20
|
-
page_size?: number;
|
|
21
|
-
after?: string;
|
|
22
|
-
before?: string;
|
|
20
|
+
export interface UserFeedOptions extends PaginationOptions {
|
|
23
21
|
source?: string;
|
|
24
22
|
tenant?: string;
|
|
25
23
|
status?: "unread" | "unseen" | "all";
|
|
@@ -2,8 +2,8 @@ import { ObjectRef } from "../objects/interfaces";
|
|
|
2
2
|
export interface TriggerWorkflowProperties<T = {
|
|
3
3
|
[key: string]: any;
|
|
4
4
|
}> {
|
|
5
|
-
actor?:
|
|
6
|
-
recipients?:
|
|
5
|
+
actor?: Actor;
|
|
6
|
+
recipients?: Recipient[];
|
|
7
7
|
cancellationKey?: string;
|
|
8
8
|
tenant?: string;
|
|
9
9
|
data?: T;
|
|
@@ -14,3 +14,5 @@ export interface CancelWorkflowProperties {
|
|
|
14
14
|
export interface WorkflowRun {
|
|
15
15
|
workflow_run_id: string;
|
|
16
16
|
}
|
|
17
|
+
export declare type Recipient = string | ObjectRef;
|
|
18
|
+
export declare type Actor = Recipient;
|