@knocklabs/node 0.2.4 → 0.4.2
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 +2 -13
- package/dist/package.json +1 -1
- package/dist/src/common/interfaces.d.ts +8 -0
- package/dist/src/knock.d.ts +6 -2
- package/dist/src/knock.js +8 -3
- package/dist/src/resources/bulk_operations/index.d.ts +7 -0
- package/dist/src/resources/bulk_operations/index.js +24 -0
- package/dist/src/resources/bulk_operations/interfaces.d.ts +12 -0
- package/dist/src/resources/bulk_operations/interfaces.js +2 -0
- package/dist/src/resources/objects/index.d.ts +15 -0
- package/dist/src/resources/objects/index.js +66 -0
- package/dist/src/resources/objects/interfaces.d.ts +21 -0
- package/dist/src/resources/objects/interfaces.js +2 -0
- package/dist/src/resources/preferences/helpers.d.ts +7 -0
- package/dist/src/resources/preferences/helpers.js +11 -0
- package/dist/src/resources/preferences/index.d.ts +29 -1
- package/dist/src/resources/preferences/index.js +37 -33
- package/dist/src/resources/preferences/interfaces.d.ts +4 -4
- package/dist/src/resources/users/index.d.ts +23 -6
- package/dist/src/resources/users/index.js +117 -0
- package/dist/src/resources/users/interfaces.d.ts +21 -0
- package/dist/src/resources/workflows/index.js +2 -2
- package/dist/src/resources/workflows/interfaces.d.ts +8 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -93,7 +93,7 @@ const { Knock } = require("@knocklabs/node");
|
|
|
93
93
|
const knockClient = new Knock("sk_12345");
|
|
94
94
|
|
|
95
95
|
// Set an entire preference set
|
|
96
|
-
await knockClient.
|
|
96
|
+
await knockClient.users.setPreferences("jhammond", {
|
|
97
97
|
channel_types: { email: true, sms: false },
|
|
98
98
|
workflows: {
|
|
99
99
|
"dinosaurs-loose": {
|
|
@@ -103,18 +103,7 @@ await knockClient.preferences.set("jhammond", {
|
|
|
103
103
|
});
|
|
104
104
|
|
|
105
105
|
// Retrieve a whole preference set
|
|
106
|
-
const preferences = await knockClient.
|
|
107
|
-
|
|
108
|
-
// Granular preference setting for channel types
|
|
109
|
-
await knockClient.preferences.setChannelType("jhammond", "email", false);
|
|
110
|
-
|
|
111
|
-
// Granular preference setting for workflows
|
|
112
|
-
await knockClient.preferences.setWorkflow("jhammond", "dinosaurs-loose", {
|
|
113
|
-
channel_types: {
|
|
114
|
-
email: true,
|
|
115
|
-
in_app_feed: false,
|
|
116
|
-
},
|
|
117
|
-
});
|
|
106
|
+
const preferences = await knockClient.users.getPreferences("jhammond");
|
|
118
107
|
```
|
|
119
108
|
|
|
120
109
|
### Getting and setting channel data
|
package/dist/package.json
CHANGED
|
@@ -15,3 +15,11 @@ export interface UnprocessableEntityError {
|
|
|
15
15
|
type: string;
|
|
16
16
|
field: string;
|
|
17
17
|
}
|
|
18
|
+
export declare type ChannelType = "email" | "in_app_feed" | "sms" | "push" | "chat";
|
|
19
|
+
export declare type CommonMetadata = Record<string, any>;
|
|
20
|
+
export interface ChannelData<T = CommonMetadata> {
|
|
21
|
+
channel_id: string;
|
|
22
|
+
data: T;
|
|
23
|
+
}
|
|
24
|
+
export interface SetChannelDataProperties {
|
|
25
|
+
}
|
package/dist/src/knock.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
2
|
import { KnockOptions, PostAndPutOptions } from "./common/interfaces";
|
|
3
3
|
import { Users } from "./resources/users";
|
|
4
4
|
import { Preferences } from "./resources/preferences";
|
|
5
5
|
import { Workflows } from "./resources/workflows";
|
|
6
6
|
import { TriggerWorkflowProperties } from "./resources/workflows/interfaces";
|
|
7
|
+
import { BulkOperations } from "./resources/bulk_operations";
|
|
8
|
+
import { Objects } from "./resources/objects";
|
|
7
9
|
declare class Knock {
|
|
8
10
|
readonly key?: string | undefined;
|
|
9
11
|
readonly options: KnockOptions;
|
|
@@ -12,13 +14,15 @@ declare class Knock {
|
|
|
12
14
|
readonly users: Users;
|
|
13
15
|
readonly preferences: Preferences;
|
|
14
16
|
readonly workflows: Workflows;
|
|
17
|
+
readonly bulkOperations: BulkOperations;
|
|
18
|
+
readonly objects: Objects;
|
|
15
19
|
constructor(key?: string | undefined, options?: KnockOptions);
|
|
16
20
|
notify(workflowKey: string, properties: TriggerWorkflowProperties): Promise<import("./resources/workflows/interfaces").WorkflowRun>;
|
|
17
21
|
post(path: string, entity: any, options?: PostAndPutOptions): Promise<AxiosResponse>;
|
|
18
22
|
put(path: string, entity: any, options?: PostAndPutOptions): Promise<AxiosResponse>;
|
|
19
23
|
delete(path: string, entity?: any): Promise<AxiosResponse>;
|
|
20
24
|
get(path: string, query?: any): Promise<AxiosResponse>;
|
|
21
|
-
handleErrorResponse(path: string,
|
|
25
|
+
handleErrorResponse(path: string, error: any): void;
|
|
22
26
|
emitWarning(warning: string): void;
|
|
23
27
|
}
|
|
24
28
|
export { Knock };
|
package/dist/src/knock.js
CHANGED
|
@@ -19,14 +19,19 @@ const exceptions_1 = require("./common/exceptions");
|
|
|
19
19
|
const users_1 = require("./resources/users");
|
|
20
20
|
const preferences_1 = require("./resources/preferences");
|
|
21
21
|
const workflows_1 = require("./resources/workflows");
|
|
22
|
+
const bulk_operations_1 = require("./resources/bulk_operations");
|
|
23
|
+
const objects_1 = require("./resources/objects");
|
|
22
24
|
const DEFAULT_HOSTNAME = "https://api.knock.app";
|
|
23
25
|
class Knock {
|
|
24
26
|
constructor(key, options = {}) {
|
|
25
27
|
this.key = key;
|
|
26
28
|
this.options = options;
|
|
29
|
+
// Service accessors
|
|
27
30
|
this.users = new users_1.Users(this);
|
|
28
31
|
this.preferences = new preferences_1.Preferences(this);
|
|
29
32
|
this.workflows = new workflows_1.Workflows(this);
|
|
33
|
+
this.bulkOperations = new bulk_operations_1.BulkOperations(this);
|
|
34
|
+
this.objects = new objects_1.Objects(this);
|
|
30
35
|
if (!key) {
|
|
31
36
|
this.key = process.env.KNOCK_API_KEY;
|
|
32
37
|
if (!this.key) {
|
|
@@ -100,9 +105,9 @@ class Knock {
|
|
|
100
105
|
}
|
|
101
106
|
});
|
|
102
107
|
}
|
|
103
|
-
handleErrorResponse(path,
|
|
104
|
-
if (response) {
|
|
105
|
-
const { status, data, headers } = response;
|
|
108
|
+
handleErrorResponse(path, error) {
|
|
109
|
+
if (axios_1.default.isAxiosError(error) && error.response) {
|
|
110
|
+
const { status, data, headers } = error.response;
|
|
106
111
|
const requestID = headers["X-Request-ID"];
|
|
107
112
|
switch (status) {
|
|
108
113
|
case 401: {
|
|
@@ -0,0 +1,24 @@
|
|
|
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.BulkOperations = void 0;
|
|
13
|
+
class BulkOperations {
|
|
14
|
+
constructor(knock) {
|
|
15
|
+
this.knock = knock;
|
|
16
|
+
}
|
|
17
|
+
get(id) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const { data } = yield this.knock.get(`/v1/bulk_operations/${id}`);
|
|
20
|
+
return data;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.BulkOperations = BulkOperations;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface BulkOperation {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
status: "queued" | "processing" | "completed" | "failed";
|
|
5
|
+
processed_rows: number;
|
|
6
|
+
estimated_total_rows: number;
|
|
7
|
+
started_at?: string;
|
|
8
|
+
completed_at?: string;
|
|
9
|
+
failed_at?: string;
|
|
10
|
+
inserted_at: string;
|
|
11
|
+
updated_at: string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ChannelData, CommonMetadata, SetChannelDataProperties } from "../../common/interfaces";
|
|
2
|
+
import { Knock } from "../../knock";
|
|
3
|
+
import { BulkSetObjectOption, Object, SetObjectProperties } from "./interfaces";
|
|
4
|
+
import { BulkOperation } from "../bulk_operations/interfaces";
|
|
5
|
+
export declare class Objects {
|
|
6
|
+
readonly knock: Knock;
|
|
7
|
+
constructor(knock: Knock);
|
|
8
|
+
get<T = CommonMetadata>(collection: string, id: string): Promise<Object<T>>;
|
|
9
|
+
set<T = CommonMetadata>(collection: string, id: string, properties: SetObjectProperties): Promise<Object<T>>;
|
|
10
|
+
bulkSet(collection: string, objects: BulkSetObjectOption[]): Promise<BulkOperation>;
|
|
11
|
+
delete(collection: string, id: string): Promise<null>;
|
|
12
|
+
bulkDelete(collection: string, objectIds: string[]): Promise<BulkOperation>;
|
|
13
|
+
getChannelData<T = CommonMetadata>(collection: string, id: string, channelId: string): Promise<ChannelData<T>>;
|
|
14
|
+
setChannelData<T = CommonMetadata>(collection: string, id: string, channelId: string, channelData: SetChannelDataProperties): Promise<ChannelData<T>>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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.Objects = void 0;
|
|
13
|
+
class Objects {
|
|
14
|
+
constructor(knock) {
|
|
15
|
+
this.knock = knock;
|
|
16
|
+
}
|
|
17
|
+
get(collection, id) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const { data } = yield this.knock.get(`/v1/objects/${collection}/${id}`);
|
|
20
|
+
return data;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
set(collection, id, properties) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const { data } = yield this.knock.put(`/v1/objects/${collection}/${id}`, properties);
|
|
26
|
+
return data;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
bulkSet(collection, objects) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const attrs = { objects };
|
|
32
|
+
const { data } = yield this.knock.post(`/v1/objects/${collection}/bulk/set`, attrs);
|
|
33
|
+
return data;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
delete(collection, id) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const { data } = yield this.knock.delete(`/v1/objects/${collection}/${id}`);
|
|
39
|
+
return data;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
bulkDelete(collection, objectIds) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const attrs = {
|
|
45
|
+
object_ids: objectIds,
|
|
46
|
+
};
|
|
47
|
+
const { data } = yield this.knock.post(`/v1/objects/${collection}/bulk/delete`, attrs);
|
|
48
|
+
return data;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
// Channel data
|
|
52
|
+
getChannelData(collection, id, channelId) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const { data } = yield this.knock.get(`/v1/objects/${collection}/${id}/channel_data/${channelId}`);
|
|
55
|
+
return data;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
setChannelData(collection, id, channelId, channelData) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const attrs = { data: channelData };
|
|
61
|
+
const { data } = yield this.knock.put(`/v1/objects/${collection}/${id}/channel_data/${channelId}`, attrs);
|
|
62
|
+
return data;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.Objects = Objects;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CommonMetadata } from "../../common/interfaces";
|
|
2
|
+
export interface ObjectRef {
|
|
3
|
+
collection: string;
|
|
4
|
+
id: string;
|
|
5
|
+
}
|
|
6
|
+
export interface Object<T = CommonMetadata> {
|
|
7
|
+
id: string;
|
|
8
|
+
collection: string;
|
|
9
|
+
properties: T;
|
|
10
|
+
created_at?: string;
|
|
11
|
+
updated_at: string;
|
|
12
|
+
}
|
|
13
|
+
export interface SetObjectProperties {
|
|
14
|
+
name?: string;
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
}
|
|
17
|
+
export interface BulkSetObjectOption {
|
|
18
|
+
id: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WorkflowPreferenceSetting } from "./interfaces";
|
|
2
|
+
export declare function buildUpdateParam(param: WorkflowPreferenceSetting): {
|
|
3
|
+
channel_types: import("./interfaces").ChannelTypePreferences;
|
|
4
|
+
} | {
|
|
5
|
+
subscribed: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const DEFAULT_PREFERENCE_SET_ID = "default";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_PREFERENCE_SET_ID = exports.buildUpdateParam = void 0;
|
|
4
|
+
function buildUpdateParam(param) {
|
|
5
|
+
if (typeof param === "object") {
|
|
6
|
+
return param;
|
|
7
|
+
}
|
|
8
|
+
return { subscribed: param };
|
|
9
|
+
}
|
|
10
|
+
exports.buildUpdateParam = buildUpdateParam;
|
|
11
|
+
exports.DEFAULT_PREFERENCE_SET_ID = "default";
|
|
@@ -1,15 +1,43 @@
|
|
|
1
|
+
import { ChannelType } from "../../common/interfaces";
|
|
1
2
|
import { Knock } from "../../knock";
|
|
2
|
-
import {
|
|
3
|
+
import { ChannelTypePreferences, WorkflowPreferenceSetting, WorkflowPreferences, PreferenceOptions, SetPreferencesProperties, PreferenceSet } from "./interfaces";
|
|
3
4
|
export declare class Preferences {
|
|
4
5
|
readonly knock: Knock;
|
|
5
6
|
constructor(knock: Knock);
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use `users.getAllPreferences` instead
|
|
9
|
+
*/
|
|
6
10
|
getAll(userId: string): Promise<PreferenceSet[]>;
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Use `users.getPreferences` instead
|
|
13
|
+
*/
|
|
7
14
|
get(userId: string, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use `users.setPreferences` instead
|
|
17
|
+
*/
|
|
8
18
|
set(userId: string, preferenceSet: SetPreferencesProperties, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Use `users.setChannelTypesPreferences` instead
|
|
21
|
+
*/
|
|
9
22
|
setChannelTypes(userId: string, channelTypePreferences: ChannelTypePreferences, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated Use `users.setChannelTypePreferences` instead
|
|
25
|
+
*/
|
|
10
26
|
setChannelType(userId: string, channelType: ChannelType, setting: boolean, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated Use `users.setWorkflowsPreferences` instead
|
|
29
|
+
*/
|
|
11
30
|
setWorkflows(userId: string, workflowPreferences: WorkflowPreferences, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Use `users.setWorkflowPreferences` instead
|
|
33
|
+
*/
|
|
12
34
|
setWorkflow(userId: string, workflowKey: string, setting: WorkflowPreferenceSetting, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated Use `users.setCategoriesPreferences` instead
|
|
37
|
+
*/
|
|
13
38
|
setCategories(userId: string, categoryPreferences: WorkflowPreferences, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use `users.setCategoryPreferences` instead
|
|
41
|
+
*/
|
|
14
42
|
setCategory(userId: string, categoryKey: string, setting: WorkflowPreferenceSetting, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
15
43
|
}
|
|
@@ -10,77 +10,81 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Preferences = void 0;
|
|
13
|
-
|
|
14
|
-
function buildUpdateParam(param) {
|
|
15
|
-
if (typeof param === "object") {
|
|
16
|
-
return param;
|
|
17
|
-
}
|
|
18
|
-
return { subscribed: param };
|
|
19
|
-
}
|
|
13
|
+
// Deprecated all of the methods in this to be removed in `0.5.0`
|
|
20
14
|
class Preferences {
|
|
21
15
|
constructor(knock) {
|
|
22
16
|
this.knock = knock;
|
|
23
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Use `users.getAllPreferences` instead
|
|
20
|
+
*/
|
|
24
21
|
getAll(userId) {
|
|
25
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
|
|
27
|
-
return data;
|
|
23
|
+
return this.knock.users.getAllPreferences(userId);
|
|
28
24
|
});
|
|
29
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Use `users.getPreferences` instead
|
|
28
|
+
*/
|
|
30
29
|
get(userId, options = {}) {
|
|
31
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
|
|
33
|
-
const { data } = yield this.knock.get(`/v1/users/${userId}/preferences/${preferenceSetId}`);
|
|
34
|
-
return data;
|
|
31
|
+
return this.knock.users.getPrefences(userId, options);
|
|
35
32
|
});
|
|
36
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated Use `users.setPreferences` instead
|
|
36
|
+
*/
|
|
37
37
|
set(userId, preferenceSet, options = {}) {
|
|
38
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
|
|
40
|
-
const { data } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}`, preferenceSet);
|
|
41
|
-
return data;
|
|
39
|
+
return this.knock.users.setPreferences(userId, preferenceSet, options);
|
|
42
40
|
});
|
|
43
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated Use `users.setChannelTypesPreferences` instead
|
|
44
|
+
*/
|
|
44
45
|
setChannelTypes(userId, channelTypePreferences, options = {}) {
|
|
45
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
|
|
47
|
-
const { data } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}/channel_types`, channelTypePreferences);
|
|
48
|
-
return data;
|
|
47
|
+
return this.knock.users.setChannelTypesPreferences(userId, channelTypePreferences, options);
|
|
49
48
|
});
|
|
50
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated Use `users.setChannelTypePreferences` instead
|
|
52
|
+
*/
|
|
51
53
|
setChannelType(userId, channelType, setting, options = {}) {
|
|
52
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
|
|
54
|
-
const { data, } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}/channel_types/${channelType}`, { subscribed: setting });
|
|
55
|
-
return data;
|
|
55
|
+
return this.knock.users.setChannelTypePreferences(userId, channelType, setting, options);
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated Use `users.setWorkflowsPreferences` instead
|
|
60
|
+
*/
|
|
58
61
|
setWorkflows(userId, workflowPreferences, options = {}) {
|
|
59
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
|
|
61
|
-
const { data } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}/workflows`, workflowPreferences);
|
|
62
|
-
return data;
|
|
63
|
+
return this.knock.users.setWorkflowsPreferences(userId, workflowPreferences, options);
|
|
63
64
|
});
|
|
64
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* @deprecated Use `users.setWorkflowPreferences` instead
|
|
68
|
+
*/
|
|
65
69
|
setWorkflow(userId, workflowKey, setting, options = {}) {
|
|
66
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
|
|
68
|
-
const { data } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}/workflows/${workflowKey}`, buildUpdateParam(setting));
|
|
69
|
-
return data;
|
|
71
|
+
return this.knock.users.setWorkflowPreferences(userId, workflowKey, setting, options);
|
|
70
72
|
});
|
|
71
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* @deprecated Use `users.setCategoriesPreferences` instead
|
|
76
|
+
*/
|
|
72
77
|
setCategories(userId, categoryPreferences, options = {}) {
|
|
73
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
|
|
75
|
-
const { data } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}/categories`, categoryPreferences);
|
|
76
|
-
return data;
|
|
79
|
+
return this.knock.users.setCategoriesPreferences(userId, categoryPreferences, options);
|
|
77
80
|
});
|
|
78
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* @deprecated Use `users.setCategoryPreferences` instead
|
|
84
|
+
*/
|
|
79
85
|
setCategory(userId, categoryKey, setting, options = {}) {
|
|
80
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
|
|
82
|
-
const { data } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}/categories/${categoryKey}`, buildUpdateParam(setting));
|
|
83
|
-
return data;
|
|
87
|
+
return this.knock.users.setCategoryPreferences(userId, categoryKey, setting, options);
|
|
84
88
|
});
|
|
85
89
|
}
|
|
86
90
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { ChannelType } from "../../common/interfaces";
|
|
2
2
|
export declare type ChannelTypePreferences = {
|
|
3
3
|
[K in ChannelType]: boolean;
|
|
4
4
|
};
|
|
@@ -9,9 +9,9 @@ export interface WorkflowPreferences {
|
|
|
9
9
|
[key: string]: WorkflowPreferenceSetting;
|
|
10
10
|
}
|
|
11
11
|
export interface SetPreferencesProperties {
|
|
12
|
-
workflows
|
|
13
|
-
categories
|
|
14
|
-
channel_types
|
|
12
|
+
workflows?: WorkflowPreferences;
|
|
13
|
+
categories?: WorkflowPreferences;
|
|
14
|
+
channel_types?: ChannelTypePreferences;
|
|
15
15
|
}
|
|
16
16
|
export interface PreferenceSet {
|
|
17
17
|
id: string;
|
|
@@ -1,11 +1,28 @@
|
|
|
1
|
+
import { ChannelData, ChannelType, CommonMetadata } from "../../common/interfaces";
|
|
2
|
+
import { BulkOperation } from "../bulk_operations/interfaces";
|
|
3
|
+
import { ChannelTypePreferences, PreferenceOptions, PreferenceSet, SetPreferencesProperties, WorkflowPreferences, WorkflowPreferenceSetting } from "../preferences/interfaces";
|
|
1
4
|
import { Knock } from "../../knock";
|
|
2
|
-
import { IdentifyProperties } from "./interfaces";
|
|
5
|
+
import { BulkIdentifyUser, IdentifyProperties, User, UserFeedOptions } from "./interfaces";
|
|
3
6
|
export declare class Users {
|
|
4
7
|
readonly knock: Knock;
|
|
5
8
|
constructor(knock: Knock);
|
|
6
|
-
identify(userId: string, properties?: IdentifyProperties): Promise<
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
identify(userId: string, properties?: IdentifyProperties): Promise<User>;
|
|
10
|
+
bulkIdentify(users: BulkIdentifyUser[]): Promise<BulkOperation>;
|
|
11
|
+
get(userId: string): Promise<User>;
|
|
12
|
+
delete(userId: string): Promise<null>;
|
|
13
|
+
bulkDelete(userIds: string[]): Promise<BulkOperation>;
|
|
14
|
+
merge(toUserId: string, fromUserId: string): Promise<User>;
|
|
15
|
+
getFeed(userId: string, channelId: string, feedOptions?: UserFeedOptions): Promise<any>;
|
|
16
|
+
getAllPreferences(userId: string): Promise<any>;
|
|
17
|
+
getPrefences(userId: string, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
18
|
+
setPreferences(userId: string, preferenceSet: SetPreferencesProperties, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
19
|
+
bulkSetPreferences(userIds: string[], preferenceSet: SetPreferencesProperties, options?: PreferenceOptions): Promise<BulkOperation>;
|
|
20
|
+
setChannelTypesPreferences(userId: string, channelTypePreferences: ChannelTypePreferences, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
21
|
+
setChannelTypePreferences(userId: string, channelType: ChannelType, setting: boolean, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
22
|
+
setWorkflowsPreferences(userId: string, workflowPreferences: WorkflowPreferences, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
23
|
+
setWorkflowPreferences(userId: string, workflowKey: string, setting: WorkflowPreferenceSetting, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
24
|
+
setCategoriesPreferences(userId: string, categoryPreferences: WorkflowPreferences, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
25
|
+
setCategoryPreferences(userId: string, categoryKey: string, setting: WorkflowPreferenceSetting, options?: PreferenceOptions): Promise<PreferenceSet>;
|
|
26
|
+
getChannelData<T = CommonMetadata>(userId: string, channelId: string): Promise<ChannelData<T>>;
|
|
27
|
+
setChannelData<T = CommonMetadata>(userId: string, channelId: string, channelData: Record<string, string>): Promise<ChannelData<T>>;
|
|
11
28
|
}
|
|
@@ -10,10 +10,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Users = void 0;
|
|
13
|
+
const helpers_1 = require("../preferences/helpers");
|
|
13
14
|
class Users {
|
|
14
15
|
constructor(knock) {
|
|
15
16
|
this.knock = knock;
|
|
16
17
|
}
|
|
18
|
+
//
|
|
19
|
+
// User management
|
|
20
|
+
//
|
|
17
21
|
identify(userId, properties = {}) {
|
|
18
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
23
|
if (!userId) {
|
|
@@ -23,6 +27,13 @@ class Users {
|
|
|
23
27
|
return data;
|
|
24
28
|
});
|
|
25
29
|
}
|
|
30
|
+
bulkIdentify(users) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const attrs = { users };
|
|
33
|
+
const { data } = yield this.knock.post(`/v1/users/bulk/identify`, attrs);
|
|
34
|
+
return data;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
26
37
|
get(userId) {
|
|
27
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
39
|
if (!userId) {
|
|
@@ -41,6 +52,112 @@ class Users {
|
|
|
41
52
|
return data;
|
|
42
53
|
});
|
|
43
54
|
}
|
|
55
|
+
bulkDelete(userIds) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const attrs = { user_ids: userIds };
|
|
58
|
+
const { data } = yield this.knock.post(`/v1/users/bulk/delete`, attrs);
|
|
59
|
+
return data;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
merge(toUserId, fromUserId) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
if (!toUserId || !fromUserId) {
|
|
65
|
+
throw new Error(`Incomplete arguments. You must provide both a 'toUserId' and a 'fromUserId'.`);
|
|
66
|
+
}
|
|
67
|
+
const { data } = yield this.knock.post(`/v1/users/${toUserId}/merge`, {
|
|
68
|
+
from_user_id: fromUserId,
|
|
69
|
+
});
|
|
70
|
+
return data;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
//
|
|
74
|
+
// Feeds
|
|
75
|
+
//
|
|
76
|
+
getFeed(userId, channelId, feedOptions = {}) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
const { data } = yield this.knock.get(`/v1/users/${userId}/feeds/${channelId}`, feedOptions);
|
|
79
|
+
return data;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
//
|
|
83
|
+
// Preferences
|
|
84
|
+
//
|
|
85
|
+
getAllPreferences(userId) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
const { data } = yield this.knock.get(`/v1/users/${userId}/preferences`);
|
|
88
|
+
return data;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
getPrefences(userId, options = {}) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
94
|
+
const { data } = yield this.knock.get(`/v1/users/${userId}/preferences/${preferenceSetId}`);
|
|
95
|
+
return data;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
setPreferences(userId, preferenceSet, options = {}) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
101
|
+
const { data } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}`, preferenceSet);
|
|
102
|
+
return data;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
bulkSetPreferences(userIds, preferenceSet, options = {}) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
108
|
+
const attrs = {
|
|
109
|
+
user_ids: userIds,
|
|
110
|
+
preferences: Object.assign(Object.assign({}, preferenceSet), { id: preferenceSetId }),
|
|
111
|
+
};
|
|
112
|
+
const { data } = yield this.knock.post(`/v1/users/bulk/preferences`, attrs);
|
|
113
|
+
return data;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
setChannelTypesPreferences(userId, channelTypePreferences, options = {}) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
119
|
+
const { data } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}/channel_types`, channelTypePreferences);
|
|
120
|
+
return data;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
setChannelTypePreferences(userId, channelType, setting, options = {}) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
126
|
+
const { data, } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}/channel_types/${channelType}`, { subscribed: setting });
|
|
127
|
+
return data;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
setWorkflowsPreferences(userId, workflowPreferences, options = {}) {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
133
|
+
const { data } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}/workflows`, workflowPreferences);
|
|
134
|
+
return data;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
setWorkflowPreferences(userId, workflowKey, setting, options = {}) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
140
|
+
const { data } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}/workflows/${workflowKey}`, helpers_1.buildUpdateParam(setting));
|
|
141
|
+
return data;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
setCategoriesPreferences(userId, categoryPreferences, options = {}) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
147
|
+
const { data } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}/categories`, categoryPreferences);
|
|
148
|
+
return data;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
setCategoryPreferences(userId, categoryKey, setting, options = {}) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
154
|
+
const { data } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}/categories/${categoryKey}`, helpers_1.buildUpdateParam(setting));
|
|
155
|
+
return data;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
//
|
|
159
|
+
// Channel data
|
|
160
|
+
//
|
|
44
161
|
getChannelData(userId, channelId) {
|
|
45
162
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
163
|
if (!userId || !channelId) {
|
|
@@ -3,3 +3,24 @@ export interface IdentifyProperties {
|
|
|
3
3
|
email?: string;
|
|
4
4
|
[key: string]: any;
|
|
5
5
|
}
|
|
6
|
+
export interface User {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
email: string;
|
|
10
|
+
phone_number?: string;
|
|
11
|
+
avatar?: string;
|
|
12
|
+
created_at?: string;
|
|
13
|
+
updated_at?: string;
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}
|
|
16
|
+
export interface BulkIdentifyUser extends IdentifyProperties {
|
|
17
|
+
id: string;
|
|
18
|
+
}
|
|
19
|
+
export interface UserFeedOptions {
|
|
20
|
+
page_size?: number;
|
|
21
|
+
after?: string;
|
|
22
|
+
before?: string;
|
|
23
|
+
source?: string;
|
|
24
|
+
tenant?: string;
|
|
25
|
+
status?: "unread" | "unseen" | "all";
|
|
26
|
+
}
|
|
@@ -16,8 +16,8 @@ class Workflows {
|
|
|
16
16
|
}
|
|
17
17
|
trigger(workflowKey, { actor, recipients, cancellationKey, tenant, data: notifyData, }) {
|
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
if (!workflowKey && !
|
|
20
|
-
throw new Error(`Incomplete arguments. At a minimum you need to specify 'workflowKey'
|
|
19
|
+
if (!workflowKey && !recipients) {
|
|
20
|
+
throw new Error(`Incomplete arguments. At a minimum you need to specify 'workflowKey' and 'recipients'.`);
|
|
21
21
|
}
|
|
22
22
|
const { data } = yield this.knock.post(`/v1/workflows/${workflowKey}/trigger`, {
|
|
23
23
|
actor,
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ObjectRef } from "../objects/interfaces";
|
|
2
|
+
export interface TriggerWorkflowProperties<T = {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
}> {
|
|
5
|
+
actor?: string | ObjectRef;
|
|
6
|
+
recipients?: string[] | ObjectRef[];
|
|
4
7
|
cancellationKey?: string;
|
|
5
8
|
tenant?: string;
|
|
6
|
-
data?:
|
|
7
|
-
[key: string]: any;
|
|
8
|
-
};
|
|
9
|
+
data?: T;
|
|
9
10
|
}
|
|
10
11
|
export interface CancelWorkflowProperties {
|
|
11
|
-
recipients?: string[];
|
|
12
|
+
recipients?: string[] | ObjectRef;
|
|
12
13
|
}
|
|
13
14
|
export interface WorkflowRun {
|
|
14
15
|
workflow_run_id: string;
|