@knocklabs/node 0.4.17 → 0.4.19
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/CHANGELOG.md +3 -0
- package/dist/package.json +1 -1
- package/dist/src/common/interfaces.d.ts +6 -0
- package/dist/src/knock.d.ts +2 -2
- package/dist/src/knock.js +3 -2
- package/dist/src/resources/objects/index.d.ts +2 -0
- package/dist/src/resources/objects/index.js +12 -0
- package/dist/src/resources/users/index.d.ts +2 -0
- package/dist/src/resources/users/index.js +12 -0
- package/dist/src/resources/workflows/index.d.ts +7 -2
- package/dist/src/resources/workflows/index.js +27 -2
- package/dist/src/resources/workflows/interfaces.d.ts +59 -0
- package/dist/src/resources/workflows/interfaces.js +18 -0
- package/package.json +1 -1
package/CHANGELOG.md
ADDED
package/dist/package.json
CHANGED
|
@@ -9,6 +9,9 @@ export interface PostAndPutOptions {
|
|
|
9
9
|
query?: {
|
|
10
10
|
[key: string]: any;
|
|
11
11
|
};
|
|
12
|
+
headers?: {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
};
|
|
12
15
|
}
|
|
13
16
|
export interface UnprocessableEntityError {
|
|
14
17
|
message: string;
|
|
@@ -54,4 +57,7 @@ export interface SignUserTokenOptions {
|
|
|
54
57
|
/** The expiration time of the token in seconds. Defaults to 1 hour. */
|
|
55
58
|
expiresInSeconds?: number;
|
|
56
59
|
}
|
|
60
|
+
export interface MethodOptions {
|
|
61
|
+
idempotencyKey?: string;
|
|
62
|
+
}
|
|
57
63
|
export {};
|
package/dist/src/knock.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosResponse } from "axios";
|
|
2
|
-
import { KnockOptions, PostAndPutOptions, SignUserTokenOptions } from "./common/interfaces";
|
|
2
|
+
import { KnockOptions, PostAndPutOptions, SignUserTokenOptions, MethodOptions } from "./common/interfaces";
|
|
3
3
|
import { Users } from "./resources/users";
|
|
4
4
|
import { Preferences } from "./resources/preferences";
|
|
5
5
|
import { Workflows } from "./resources/workflows";
|
|
@@ -21,7 +21,7 @@ declare class Knock {
|
|
|
21
21
|
readonly messages: Messages;
|
|
22
22
|
readonly tenants: Tenants;
|
|
23
23
|
constructor(key?: string | undefined, options?: KnockOptions);
|
|
24
|
-
notify(workflowKey: string, properties: TriggerWorkflowProperties): Promise<import("./resources/workflows/interfaces").WorkflowRun>;
|
|
24
|
+
notify(workflowKey: string, properties: TriggerWorkflowProperties, options?: MethodOptions): Promise<import("./resources/workflows/interfaces").WorkflowRun>;
|
|
25
25
|
/**
|
|
26
26
|
* Generate JWT for authenticating client-side requests (e.g. in-app feeds)
|
|
27
27
|
* For more information, visit https://docs.knock.app/in-app-ui/security-and-authentication#authentication-with-enhanced-security-enabled
|
package/dist/src/knock.js
CHANGED
|
@@ -53,9 +53,9 @@ class Knock {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
// Delegate the notify function to the workflows trigger
|
|
56
|
-
notify(workflowKey, properties) {
|
|
56
|
+
notify(workflowKey, properties, options) {
|
|
57
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
return this.workflows.trigger(workflowKey, properties);
|
|
58
|
+
return this.workflows.trigger(workflowKey, properties, options);
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
@@ -86,6 +86,7 @@ class Knock {
|
|
|
86
86
|
try {
|
|
87
87
|
return yield this.client.post(path, entity, {
|
|
88
88
|
params: options.query,
|
|
89
|
+
headers: options.headers,
|
|
89
90
|
});
|
|
90
91
|
}
|
|
91
92
|
catch (error) {
|
|
@@ -3,6 +3,7 @@ import { Knock } from "../../knock";
|
|
|
3
3
|
import { AddObjectSubscriptionProperties, BulkSetObjectOption, DeleteObjectSubscriptionProperties, ListObjectOptions, ListObjectSubscriptionsOptions, Object, ObjectSubscription, SetObjectProperties } from "./interfaces";
|
|
4
4
|
import { BulkOperation } from "../bulk_operations/interfaces";
|
|
5
5
|
import { ListMessagesOptions, Message } from "../messages/interfaces";
|
|
6
|
+
import { ListSchedulesProps, Schedule } from "../workflows/interfaces";
|
|
6
7
|
import { ChannelTypePreferences, PreferenceOptions, PreferenceSet, SetPreferencesProperties, WorkflowPreferences, WorkflowPreferenceSetting } from "../preferences/interfaces";
|
|
7
8
|
export declare class Objects {
|
|
8
9
|
readonly knock: Knock;
|
|
@@ -33,4 +34,5 @@ export declare class Objects {
|
|
|
33
34
|
listSubscriptions(collection: string, objectId: string, options?: ListObjectSubscriptionsOptions): Promise<PaginatedEntriesResponse<ObjectSubscription>>;
|
|
34
35
|
addSubscriptions(collection: string, objectId: string, properties?: AddObjectSubscriptionProperties): Promise<ObjectSubscription[]>;
|
|
35
36
|
deleteSubscriptions(collection: string, objectId: string, properties?: DeleteObjectSubscriptionProperties): Promise<ObjectSubscription[]>;
|
|
37
|
+
getSchedules(collection: string, objectId: string, filteringOptions?: ListSchedulesProps): Promise<PaginatedEntriesResponse<Schedule>>;
|
|
36
38
|
}
|
|
@@ -181,5 +181,17 @@ class Objects {
|
|
|
181
181
|
return data;
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
|
+
//
|
|
185
|
+
// Schedules
|
|
186
|
+
//
|
|
187
|
+
getSchedules(collection, objectId, filteringOptions = {}) {
|
|
188
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
189
|
+
if (!collection || !objectId) {
|
|
190
|
+
throw new Error(`Incomplete arguments. You must provide a 'collection' and 'objectId'`);
|
|
191
|
+
}
|
|
192
|
+
const { data } = yield this.knock.get(`/v1/objects/${collection}/${objectId}/schedules`, filteringOptions);
|
|
193
|
+
return data;
|
|
194
|
+
});
|
|
195
|
+
}
|
|
184
196
|
}
|
|
185
197
|
exports.Objects = Objects;
|
|
@@ -2,6 +2,7 @@ import { ChannelData, ChannelType, CommonMetadata, PaginatedItemsResponse, Pagin
|
|
|
2
2
|
import { BulkOperation } from "../bulk_operations/interfaces";
|
|
3
3
|
import { ChannelTypePreferences, PreferenceOptions, PreferenceSet, SetPreferencesProperties, WorkflowPreferences, WorkflowPreferenceSetting } from "../preferences/interfaces";
|
|
4
4
|
import { ListMessagesOptions, Message } from "../messages/interfaces";
|
|
5
|
+
import { ListSchedulesProps, Schedule } from "../workflows/interfaces";
|
|
5
6
|
import { Knock } from "../../knock";
|
|
6
7
|
import { BulkIdentifyUser, IdentifyProperties, ListUserOptions, User, UserFeedOptions } from "./interfaces";
|
|
7
8
|
export declare class Users {
|
|
@@ -33,4 +34,5 @@ export declare class Users {
|
|
|
33
34
|
setChannelData<T = CommonMetadata>(userId: string, channelId: string, channelData: Record<string, any>): Promise<ChannelData<T>>;
|
|
34
35
|
unsetChannelData(userId: string, channelId: string): Promise<any>;
|
|
35
36
|
getMessages(userId: string, filteringOptions?: ListMessagesOptions): Promise<PaginatedItemsResponse<Message>>;
|
|
37
|
+
getSchedules(userId: string, filteringOptions?: ListSchedulesProps): Promise<PaginatedEntriesResponse<Schedule>>;
|
|
36
38
|
}
|
|
@@ -212,5 +212,17 @@ class Users {
|
|
|
212
212
|
return data;
|
|
213
213
|
});
|
|
214
214
|
}
|
|
215
|
+
//
|
|
216
|
+
// Schedules
|
|
217
|
+
//
|
|
218
|
+
getSchedules(userId, filteringOptions = {}) {
|
|
219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
if (!userId) {
|
|
221
|
+
throw new Error(`Incomplete arguments. You must provide a 'userId'`);
|
|
222
|
+
}
|
|
223
|
+
const { data } = yield this.knock.get(`/v1/users/${userId}/schedules`, filteringOptions);
|
|
224
|
+
return data;
|
|
225
|
+
});
|
|
226
|
+
}
|
|
215
227
|
}
|
|
216
228
|
exports.Users = Users;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { Knock } from "../../knock";
|
|
2
|
-
import {
|
|
2
|
+
import { MethodOptions, PaginatedEntriesResponse } from "../../common/interfaces";
|
|
3
|
+
import { CancelWorkflowProperties, TriggerWorkflowProperties, CreateSchedulesProps, UpdateSchedulesProps, ListSchedulesProps, DeleteSchedulesProps, Schedule, WorkflowRun } from "./interfaces";
|
|
3
4
|
export declare class Workflows {
|
|
4
5
|
readonly knock: Knock;
|
|
5
6
|
constructor(knock: Knock);
|
|
6
|
-
trigger(workflowKey: string, { actor, recipients, cancellationKey, tenant, data: notifyData, }: TriggerWorkflowProperties): Promise<WorkflowRun>;
|
|
7
|
+
trigger(workflowKey: string, { actor, recipients, cancellationKey, tenant, data: notifyData, }: TriggerWorkflowProperties, { idempotencyKey }?: MethodOptions): Promise<WorkflowRun>;
|
|
7
8
|
cancel(workflowKey: string, cancellationKey: string, { recipients }?: CancelWorkflowProperties): Promise<any>;
|
|
9
|
+
createSchedules(workflowKey: string, params: CreateSchedulesProps): Promise<Schedule[]>;
|
|
10
|
+
updateSchedules(params: UpdateSchedulesProps): Promise<Schedule[]>;
|
|
11
|
+
listSchedules(workflowKey: string, params?: ListSchedulesProps): Promise<PaginatedEntriesResponse<Schedule>>;
|
|
12
|
+
deleteSchedules(params: DeleteSchedulesProps): Promise<Schedule[]>;
|
|
8
13
|
}
|
|
@@ -14,18 +14,19 @@ class Workflows {
|
|
|
14
14
|
constructor(knock) {
|
|
15
15
|
this.knock = knock;
|
|
16
16
|
}
|
|
17
|
-
trigger(workflowKey, { actor, recipients, cancellationKey, tenant, data: notifyData, }) {
|
|
17
|
+
trigger(workflowKey, { actor, recipients, cancellationKey, tenant, data: notifyData, }, { idempotencyKey } = {}) {
|
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
19
|
if (!workflowKey && !recipients) {
|
|
20
20
|
throw new Error(`Incomplete arguments. At a minimum you need to specify 'workflowKey' and 'recipients'.`);
|
|
21
21
|
}
|
|
22
|
+
const options = idempotencyKey ? { headers: { 'Idempotency-Key': idempotencyKey } } : {};
|
|
22
23
|
const { data } = yield this.knock.post(`/v1/workflows/${workflowKey}/trigger`, {
|
|
23
24
|
actor,
|
|
24
25
|
recipients,
|
|
25
26
|
cancellation_key: cancellationKey,
|
|
26
27
|
tenant,
|
|
27
28
|
data: notifyData,
|
|
28
|
-
});
|
|
29
|
+
}, options);
|
|
29
30
|
return data;
|
|
30
31
|
});
|
|
31
32
|
}
|
|
@@ -41,5 +42,29 @@ class Workflows {
|
|
|
41
42
|
return data;
|
|
42
43
|
});
|
|
43
44
|
}
|
|
45
|
+
createSchedules(workflowKey, params) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const { data } = yield this.knock.post("/v1/schedules", Object.assign(Object.assign({}, params), { workflow: workflowKey }));
|
|
48
|
+
return data;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
updateSchedules(params) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const { data } = yield this.knock.put("/v1/schedules", params);
|
|
54
|
+
return data;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
listSchedules(workflowKey, params = {}) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const { data } = yield this.knock.get("/v1/schedules", Object.assign(Object.assign({}, params), { workflow: workflowKey }));
|
|
60
|
+
return data;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
deleteSchedules(params) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
const { data } = yield this.knock.delete("/v1/schedules", params);
|
|
66
|
+
return data;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
44
69
|
}
|
|
45
70
|
exports.Workflows = Workflows;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ObjectRef, SetObjectProperties } from "../objects/interfaces";
|
|
2
2
|
import { IdentifyProperties } from "../users/interfaces";
|
|
3
|
+
import { PaginationOptions } from "../../common/interfaces";
|
|
3
4
|
export interface TriggerWorkflowProperties<T = {
|
|
4
5
|
[key: string]: any;
|
|
5
6
|
}> {
|
|
@@ -15,6 +16,64 @@ export interface CancelWorkflowProperties {
|
|
|
15
16
|
export interface WorkflowRun {
|
|
16
17
|
workflow_run_id: string;
|
|
17
18
|
}
|
|
19
|
+
export declare enum DaysOfWeek {
|
|
20
|
+
Mon = "mon",
|
|
21
|
+
Tue = "tue",
|
|
22
|
+
Wed = "wed",
|
|
23
|
+
Thu = "thu",
|
|
24
|
+
Fri = "fri",
|
|
25
|
+
Sat = "sat",
|
|
26
|
+
Sun = "sun"
|
|
27
|
+
}
|
|
28
|
+
export declare enum RepeatFrequency {
|
|
29
|
+
Monthly = "monthly",
|
|
30
|
+
Weekly = "weekly",
|
|
31
|
+
Daily = "daily",
|
|
32
|
+
Hourly = "hourly"
|
|
33
|
+
}
|
|
34
|
+
export declare type ScheduleRepeatProperties = {
|
|
35
|
+
frequency: RepeatFrequency;
|
|
36
|
+
interval?: number;
|
|
37
|
+
day_of_month?: number;
|
|
38
|
+
days?: DaysOfWeek[] | "weekdays" | "weekends";
|
|
39
|
+
hours?: number;
|
|
40
|
+
minutes?: number;
|
|
41
|
+
};
|
|
42
|
+
export interface CreateSchedulesProps {
|
|
43
|
+
recipients: (Recipient | RecipientWithUpsert)[];
|
|
44
|
+
actor?: Recipient | RecipientWithUpsert | null;
|
|
45
|
+
scheduled_at?: string;
|
|
46
|
+
repeats: ScheduleRepeatProperties[];
|
|
47
|
+
tenant?: string;
|
|
48
|
+
data?: {
|
|
49
|
+
[key: string]: any;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export interface UpdateSchedulesProps extends Omit<CreateSchedulesProps, "recipients"> {
|
|
53
|
+
schedule_ids: string[];
|
|
54
|
+
}
|
|
55
|
+
export interface ListSchedulesProps extends PaginationOptions {
|
|
56
|
+
recipients?: Recipient[];
|
|
57
|
+
tenant?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface DeleteSchedulesProps {
|
|
60
|
+
schedule_ids: string[];
|
|
61
|
+
}
|
|
62
|
+
export interface Schedule {
|
|
63
|
+
id: string;
|
|
64
|
+
recipient: Recipient;
|
|
65
|
+
actor: Recipient | null;
|
|
66
|
+
tenant: string | null;
|
|
67
|
+
workflow: string;
|
|
68
|
+
data: {
|
|
69
|
+
[key: string]: any;
|
|
70
|
+
};
|
|
71
|
+
next_occurrence_at: string;
|
|
72
|
+
inserted_at: string;
|
|
73
|
+
updated_at: string;
|
|
74
|
+
repeats: ScheduleRepeatProperties[];
|
|
75
|
+
__cursor?: string;
|
|
76
|
+
}
|
|
18
77
|
export declare type Recipient = string | ObjectRef;
|
|
19
78
|
export declare type Actor = Recipient;
|
|
20
79
|
export interface UserWithUpsert extends IdentifyProperties {
|
|
@@ -1,2 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RepeatFrequency = exports.DaysOfWeek = void 0;
|
|
4
|
+
var DaysOfWeek;
|
|
5
|
+
(function (DaysOfWeek) {
|
|
6
|
+
DaysOfWeek["Mon"] = "mon";
|
|
7
|
+
DaysOfWeek["Tue"] = "tue";
|
|
8
|
+
DaysOfWeek["Wed"] = "wed";
|
|
9
|
+
DaysOfWeek["Thu"] = "thu";
|
|
10
|
+
DaysOfWeek["Fri"] = "fri";
|
|
11
|
+
DaysOfWeek["Sat"] = "sat";
|
|
12
|
+
DaysOfWeek["Sun"] = "sun";
|
|
13
|
+
})(DaysOfWeek = exports.DaysOfWeek || (exports.DaysOfWeek = {}));
|
|
14
|
+
var RepeatFrequency;
|
|
15
|
+
(function (RepeatFrequency) {
|
|
16
|
+
RepeatFrequency["Monthly"] = "monthly";
|
|
17
|
+
RepeatFrequency["Weekly"] = "weekly";
|
|
18
|
+
RepeatFrequency["Daily"] = "daily";
|
|
19
|
+
RepeatFrequency["Hourly"] = "hourly";
|
|
20
|
+
})(RepeatFrequency = exports.RepeatFrequency || (exports.RepeatFrequency = {}));
|