@knocklabs/node 0.5.1 → 0.6.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/CHANGELOG.md +11 -1
- package/README.md +2 -2
- package/dist/package.json +3 -6
- package/dist/src/common/fetchClient.d.ts +28 -0
- package/dist/src/common/fetchClient.js +103 -0
- package/dist/src/common/interfaces.d.ts +3 -3
- package/dist/src/index.js +5 -1
- package/dist/src/knock.d.ts +7 -7
- package/dist/src/knock.js +26 -20
- package/dist/src/resources/messages/interfaces.d.ts +3 -3
- package/dist/src/resources/objects/index.js +2 -2
- package/dist/src/resources/preferences/interfaces.d.ts +3 -3
- package/dist/src/resources/users/index.js +2 -2
- package/dist/src/resources/workflows/interfaces.d.ts +6 -6
- package/dist/src/resources/workflows/interfaces.js +2 -2
- package/package.json +4 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## v0.6.0
|
|
2
|
+
|
|
3
|
+
### Major Changes
|
|
4
|
+
|
|
5
|
+
- Add Vercel Edge runtime compatibility
|
|
6
|
+
|
|
7
|
+
### Breaking Changes
|
|
8
|
+
|
|
9
|
+
- `Knock.signUserToken` is now asynchronous and returns `Promise<string>` instead of `string`
|
|
10
|
+
|
|
1
11
|
## v0.4.18
|
|
2
12
|
|
|
3
|
-
|
|
13
|
+
- Introduce "Idempotency-Key" header for workflow triggers
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Knock Node.js library
|
|
2
2
|
|
|
3
|
-
Knock API access for applications written in server-side Javascript.
|
|
3
|
+
Knock API access for applications written in server-side Javascript. This package is compatible with the Vercel Edge runtime.
|
|
4
4
|
|
|
5
5
|
## Documentation
|
|
6
6
|
|
|
@@ -148,7 +148,7 @@ const { Knock } = require("@knocklabs/node");
|
|
|
148
148
|
// When signing user tokens, you do not need to instantiate a Knock client.
|
|
149
149
|
|
|
150
150
|
// jhammond is the user id for which to sign this token
|
|
151
|
-
const token = Knock.signUserToken("jhammond", {
|
|
151
|
+
const token = await Knock.signUserToken("jhammond", {
|
|
152
152
|
// The signing key from the Knock Dashboard in base-64 or PEM-encoded format.
|
|
153
153
|
// If not provided, the key will be read from the KNOCK_SIGNING_KEY environment variable.
|
|
154
154
|
signingKey: "S25vY2sga25vY2sh...",
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knocklabs/node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Library for interacting with the Knock API",
|
|
5
5
|
"homepage": "https://github.com/knocklabs/knock-node",
|
|
6
6
|
"author": "@knocklabs",
|
|
@@ -32,19 +32,16 @@
|
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/jest": "26.0.23",
|
|
35
|
-
"@types/jsonwebtoken": "^9.0.1",
|
|
36
35
|
"@types/node": "^15.0.1",
|
|
37
36
|
"@types/pluralize": "0.0.29",
|
|
38
|
-
"axios-mock-adapter": "^1.22.0",
|
|
39
37
|
"jest": "26.6.3",
|
|
40
38
|
"prettier": "2.2.1",
|
|
41
39
|
"supertest": "6.1.3",
|
|
42
40
|
"ts-jest": "26.5.5",
|
|
43
41
|
"tslint": "6.1.3",
|
|
44
|
-
"typescript": "
|
|
42
|
+
"typescript": "^5.3.3"
|
|
45
43
|
},
|
|
46
44
|
"dependencies": {
|
|
47
|
-
"
|
|
48
|
-
"jsonwebtoken": "^9.0.0"
|
|
45
|
+
"jose": "^5.2.0"
|
|
49
46
|
}
|
|
50
47
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface FetchClientConfig {
|
|
2
|
+
baseURL?: string;
|
|
3
|
+
headers?: Record<string, string>;
|
|
4
|
+
}
|
|
5
|
+
export interface FetchRequestConfig<D = any> {
|
|
6
|
+
params?: Record<string, string>;
|
|
7
|
+
headers?: Record<string, string>;
|
|
8
|
+
body?: D;
|
|
9
|
+
}
|
|
10
|
+
export interface FetchResponse<T = any> extends Response {
|
|
11
|
+
data: T;
|
|
12
|
+
}
|
|
13
|
+
export declare class FetchResponseError extends Error {
|
|
14
|
+
readonly response: FetchResponse;
|
|
15
|
+
constructor(response: FetchResponse);
|
|
16
|
+
}
|
|
17
|
+
export default class FetchClient {
|
|
18
|
+
config: FetchClientConfig;
|
|
19
|
+
constructor(config?: FetchClientConfig);
|
|
20
|
+
get(path: string, config: FetchRequestConfig): Promise<FetchResponse>;
|
|
21
|
+
post(path: string, config: FetchRequestConfig): Promise<FetchResponse>;
|
|
22
|
+
put(path: string, config: FetchRequestConfig): Promise<FetchResponse>;
|
|
23
|
+
delete(path: string, config: FetchRequestConfig): Promise<FetchResponse>;
|
|
24
|
+
private request;
|
|
25
|
+
private buildUrl;
|
|
26
|
+
private prepareRequestBody;
|
|
27
|
+
private getResponseData;
|
|
28
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
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.FetchResponseError = void 0;
|
|
13
|
+
class FetchResponseError extends Error {
|
|
14
|
+
constructor(response) {
|
|
15
|
+
super();
|
|
16
|
+
this.response = response;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.FetchResponseError = FetchResponseError;
|
|
20
|
+
const defaultConfig = {
|
|
21
|
+
baseURL: "",
|
|
22
|
+
headers: {},
|
|
23
|
+
};
|
|
24
|
+
class FetchClient {
|
|
25
|
+
constructor(config) {
|
|
26
|
+
this.config = Object.assign(Object.assign({}, defaultConfig), config);
|
|
27
|
+
}
|
|
28
|
+
get(path, config) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
return this.request("GET", path, config);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
post(path, config) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
return this.request("POST", path, config);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
put(path, config) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
return this.request("PUT", path, config);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
delete(path, config) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
return this.request("DELETE", path, config);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
request(method, path, config = {}) {
|
|
49
|
+
var _a;
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const url = this.buildUrl(path, config.params);
|
|
52
|
+
const headers = Object.assign(Object.assign({}, this.config.headers), ((_a = config.headers) !== null && _a !== void 0 ? _a : {}));
|
|
53
|
+
const response = yield fetch(url, {
|
|
54
|
+
method,
|
|
55
|
+
headers,
|
|
56
|
+
body: config.body ? this.prepareRequestBody(config.body) : undefined,
|
|
57
|
+
});
|
|
58
|
+
const data = yield this.getResponseData(response);
|
|
59
|
+
// Assign data to the response as other methods of returning the response
|
|
60
|
+
// like return { ...response, data } drop the response methods
|
|
61
|
+
const fetchResponse = Object.assign(response, {
|
|
62
|
+
data,
|
|
63
|
+
});
|
|
64
|
+
if (!response.ok) {
|
|
65
|
+
throw new FetchResponseError(fetchResponse);
|
|
66
|
+
}
|
|
67
|
+
return fetchResponse;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
buildUrl(path, params) {
|
|
71
|
+
const url = new URL(this.config.baseURL + path);
|
|
72
|
+
if (params) {
|
|
73
|
+
Object.entries(params).forEach(([key, value]) => url.searchParams.append(key, value));
|
|
74
|
+
}
|
|
75
|
+
return url;
|
|
76
|
+
}
|
|
77
|
+
prepareRequestBody(data) {
|
|
78
|
+
if (typeof data === "string" || data instanceof FormData) {
|
|
79
|
+
return data;
|
|
80
|
+
}
|
|
81
|
+
return JSON.stringify(data);
|
|
82
|
+
}
|
|
83
|
+
getResponseData(response) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
if (!response.body) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
let data;
|
|
89
|
+
const contentType = response.headers.get("content-type");
|
|
90
|
+
if (contentType && contentType.includes("application/json")) {
|
|
91
|
+
data = yield response.json();
|
|
92
|
+
}
|
|
93
|
+
else if (contentType && contentType.includes("text")) {
|
|
94
|
+
data = yield response.text();
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
data = yield response.blob();
|
|
98
|
+
}
|
|
99
|
+
return data;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.default = FetchClient;
|
|
@@ -18,15 +18,15 @@ export interface UnprocessableEntityError {
|
|
|
18
18
|
type: string;
|
|
19
19
|
field: string;
|
|
20
20
|
}
|
|
21
|
-
export
|
|
22
|
-
export
|
|
21
|
+
export type ChannelType = "email" | "in_app_feed" | "sms" | "push" | "chat" | "http";
|
|
22
|
+
export type CommonMetadata = Record<string, any>;
|
|
23
23
|
export interface ChannelData<T = CommonMetadata> {
|
|
24
24
|
channel_id: string;
|
|
25
25
|
data: T;
|
|
26
26
|
}
|
|
27
27
|
export interface SetChannelDataProperties {
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
type PageInfo = {
|
|
30
30
|
before: string;
|
|
31
31
|
after: string;
|
|
32
32
|
page_size: number;
|
package/dist/src/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/dist/src/knock.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AxiosResponse } from "axios";
|
|
2
1
|
import { KnockOptions, PostAndPutOptions, SignUserTokenOptions, MethodOptions } from "./common/interfaces";
|
|
3
2
|
import { Users } from "./resources/users";
|
|
4
3
|
import { Workflows } from "./resources/workflows";
|
|
@@ -7,6 +6,7 @@ import { BulkOperations } from "./resources/bulk_operations";
|
|
|
7
6
|
import { Objects } from "./resources/objects";
|
|
8
7
|
import { Messages } from "./resources/messages";
|
|
9
8
|
import { Tenants } from "./resources/tenants";
|
|
9
|
+
import { FetchResponse } from "./common/fetchClient";
|
|
10
10
|
declare class Knock {
|
|
11
11
|
readonly key?: string | undefined;
|
|
12
12
|
readonly options: KnockOptions;
|
|
@@ -26,13 +26,13 @@ declare class Knock {
|
|
|
26
26
|
*
|
|
27
27
|
* @param userId {string} The ID of the user that needs a token, e.g. the user viewing an in-app feed.
|
|
28
28
|
* @param options Optionally specify the signing key to use (in PEM or base-64 encoded format), and how long the token should be valid for in seconds
|
|
29
|
-
* @returns {string} A JWT token that can be used to authenticate requests to the Knock API (e.g. by passing into the <KnockFeedProvider /> component)
|
|
29
|
+
* @returns {Promise<string>} A JWT token that can be used to authenticate requests to the Knock API (e.g. by passing into the <KnockFeedProvider /> component)
|
|
30
30
|
*/
|
|
31
|
-
static signUserToken(userId: string, options?: SignUserTokenOptions): string
|
|
32
|
-
post(path: string, entity: any, options?: PostAndPutOptions): Promise<
|
|
33
|
-
put(path: string, entity: any, options?: PostAndPutOptions): Promise<
|
|
34
|
-
delete(path: string, entity?: any): Promise<
|
|
35
|
-
get(path: string, query?: any): Promise<
|
|
31
|
+
static signUserToken(userId: string, options?: SignUserTokenOptions): Promise<string>;
|
|
32
|
+
post(path: string, entity: any, options?: PostAndPutOptions): Promise<FetchResponse>;
|
|
33
|
+
put(path: string, entity: any, options?: PostAndPutOptions): Promise<FetchResponse>;
|
|
34
|
+
delete(path: string, entity?: any): Promise<FetchResponse>;
|
|
35
|
+
get(path: string, query?: any): Promise<FetchResponse>;
|
|
36
36
|
handleErrorResponse(path: string, error: any): void;
|
|
37
37
|
emitWarning(warning: string): void;
|
|
38
38
|
}
|
package/dist/src/knock.js
CHANGED
|
@@ -13,8 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.Knock = void 0;
|
|
16
|
-
const
|
|
17
|
-
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
16
|
+
const jose_1 = require("jose");
|
|
18
17
|
const package_json_1 = require("../package.json");
|
|
19
18
|
const exceptions_1 = require("./common/exceptions");
|
|
20
19
|
const users_1 = require("./resources/users");
|
|
@@ -23,6 +22,7 @@ const bulk_operations_1 = require("./resources/bulk_operations");
|
|
|
23
22
|
const objects_1 = require("./resources/objects");
|
|
24
23
|
const messages_1 = require("./resources/messages");
|
|
25
24
|
const tenants_1 = require("./resources/tenants");
|
|
25
|
+
const fetchClient_1 = __importDefault(require("./common/fetchClient"));
|
|
26
26
|
const DEFAULT_HOSTNAME = "https://api.knock.app";
|
|
27
27
|
class Knock {
|
|
28
28
|
constructor(key, options = {}) {
|
|
@@ -42,7 +42,7 @@ class Knock {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
this.host = options.host || DEFAULT_HOSTNAME;
|
|
45
|
-
this.client =
|
|
45
|
+
this.client = new fetchClient_1.default({
|
|
46
46
|
baseURL: this.host,
|
|
47
47
|
headers: {
|
|
48
48
|
Authorization: `Bearer ${this.key}`,
|
|
@@ -62,29 +62,34 @@ class Knock {
|
|
|
62
62
|
*
|
|
63
63
|
* @param userId {string} The ID of the user that needs a token, e.g. the user viewing an in-app feed.
|
|
64
64
|
* @param options Optionally specify the signing key to use (in PEM or base-64 encoded format), and how long the token should be valid for in seconds
|
|
65
|
-
* @returns {string} A JWT token that can be used to authenticate requests to the Knock API (e.g. by passing into the <KnockFeedProvider /> component)
|
|
65
|
+
* @returns {Promise<string>} A JWT token that can be used to authenticate requests to the Knock API (e.g. by passing into the <KnockFeedProvider /> component)
|
|
66
66
|
*/
|
|
67
67
|
static signUserToken(userId, options) {
|
|
68
68
|
var _a;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const signingKey = prepareSigningKey(options === null || options === void 0 ? void 0 : options.signingKey);
|
|
71
|
+
// JWT NumericDates specified in seconds:
|
|
72
|
+
const currentTime = Math.floor(Date.now() / 1000);
|
|
73
|
+
// Default to 1 hour from now
|
|
74
|
+
const expireInSeconds = (_a = options === null || options === void 0 ? void 0 : options.expiresInSeconds) !== null && _a !== void 0 ? _a : 60 * 60;
|
|
75
|
+
// Convert string key to a Crypto-API compatible KeyLike
|
|
76
|
+
const keyLike = yield (0, jose_1.importPKCS8)(signingKey, "RS256");
|
|
77
|
+
return yield new jose_1.SignJWT({
|
|
78
|
+
sub: userId,
|
|
79
|
+
iat: currentTime,
|
|
80
|
+
exp: currentTime + expireInSeconds,
|
|
81
|
+
})
|
|
82
|
+
.setProtectedHeader({ alg: "RS256", typ: "JWT" })
|
|
83
|
+
.sign(keyLike);
|
|
80
84
|
});
|
|
81
85
|
}
|
|
82
86
|
post(path, entity, options = {}) {
|
|
83
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
88
|
try {
|
|
85
|
-
return yield this.client.post(path,
|
|
89
|
+
return yield this.client.post(path, {
|
|
86
90
|
params: options.query,
|
|
87
|
-
headers: options.headers,
|
|
91
|
+
headers: Object.assign({ "Content-Type": "application/json", Accept: "application/json" }, options.headers),
|
|
92
|
+
body: entity,
|
|
88
93
|
});
|
|
89
94
|
}
|
|
90
95
|
catch (error) {
|
|
@@ -96,8 +101,9 @@ class Knock {
|
|
|
96
101
|
put(path, entity, options = {}) {
|
|
97
102
|
return __awaiter(this, void 0, void 0, function* () {
|
|
98
103
|
try {
|
|
99
|
-
return yield this.client.put(path,
|
|
104
|
+
return yield this.client.put(path, {
|
|
100
105
|
params: options.query,
|
|
106
|
+
body: entity,
|
|
101
107
|
});
|
|
102
108
|
}
|
|
103
109
|
catch (error) {
|
|
@@ -133,9 +139,9 @@ class Knock {
|
|
|
133
139
|
});
|
|
134
140
|
}
|
|
135
141
|
handleErrorResponse(path, error) {
|
|
136
|
-
if (
|
|
142
|
+
if (error.response) {
|
|
137
143
|
const { status, data, headers } = error.response;
|
|
138
|
-
const requestID = headers
|
|
144
|
+
const requestID = headers.get("X-Request-ID");
|
|
139
145
|
switch (status) {
|
|
140
146
|
case 401: {
|
|
141
147
|
const { message, code } = data;
|
|
@@ -39,10 +39,10 @@ export interface ListMessagesOptions extends PaginationOptions {
|
|
|
39
39
|
export interface ListMessageActivitiesOptions extends PaginationOptions {
|
|
40
40
|
trigger_data?: Record<string, any>;
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
type WorkflowSource = {
|
|
43
43
|
version_id: string;
|
|
44
44
|
key: string;
|
|
45
45
|
};
|
|
46
|
-
|
|
47
|
-
export
|
|
46
|
+
type MessageStatus = "queued" | "sent" | "delivered" | "undelivered" | "not_sent";
|
|
47
|
+
export type MessageEngagementStatus = "seen" | "read" | "archived";
|
|
48
48
|
export {};
|
|
@@ -142,7 +142,7 @@ class Objects {
|
|
|
142
142
|
setWorkflowPreferences(collection, objectId, workflowKey, setting, options = {}) {
|
|
143
143
|
return __awaiter(this, void 0, void 0, function* () {
|
|
144
144
|
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
145
|
-
const { data } = yield this.knock.put(`/v1/objects/${collection}/${objectId}/preferences/${preferenceSetId}/workflows/${workflowKey}`, helpers_1.buildUpdateParam(setting));
|
|
145
|
+
const { data } = yield this.knock.put(`/v1/objects/${collection}/${objectId}/preferences/${preferenceSetId}/workflows/${workflowKey}`, (0, helpers_1.buildUpdateParam)(setting));
|
|
146
146
|
return data;
|
|
147
147
|
});
|
|
148
148
|
}
|
|
@@ -156,7 +156,7 @@ class Objects {
|
|
|
156
156
|
setCategoryPreferences(collection, objectId, categoryKey, setting, options = {}) {
|
|
157
157
|
return __awaiter(this, void 0, void 0, function* () {
|
|
158
158
|
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
159
|
-
const { data } = yield this.knock.put(`/v1/objects/${collection}/${objectId}/preferences/${preferenceSetId}/categories/${categoryKey}`, helpers_1.buildUpdateParam(setting));
|
|
159
|
+
const { data } = yield this.knock.put(`/v1/objects/${collection}/${objectId}/preferences/${preferenceSetId}/categories/${categoryKey}`, (0, helpers_1.buildUpdateParam)(setting));
|
|
160
160
|
return data;
|
|
161
161
|
});
|
|
162
162
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ChannelType, Condition } from "../../common/interfaces";
|
|
2
|
-
export
|
|
2
|
+
export type ConditionalPreferenceSettings = {
|
|
3
3
|
conditions: Condition[];
|
|
4
4
|
};
|
|
5
|
-
export
|
|
5
|
+
export type ChannelTypePreferences = {
|
|
6
6
|
[K in ChannelType]?: boolean | ConditionalPreferenceSettings;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
8
|
+
export type WorkflowPreferenceSetting = boolean | {
|
|
9
9
|
channel_types: ChannelTypePreferences;
|
|
10
10
|
} | ConditionalPreferenceSettings;
|
|
11
11
|
export interface WorkflowPreferences {
|
|
@@ -143,7 +143,7 @@ class Users {
|
|
|
143
143
|
setWorkflowPreferences(userId, workflowKey, setting, options = {}) {
|
|
144
144
|
return __awaiter(this, void 0, void 0, function* () {
|
|
145
145
|
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
146
|
-
const { data } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}/workflows/${workflowKey}`, helpers_1.buildUpdateParam(setting));
|
|
146
|
+
const { data } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}/workflows/${workflowKey}`, (0, helpers_1.buildUpdateParam)(setting));
|
|
147
147
|
return data;
|
|
148
148
|
});
|
|
149
149
|
}
|
|
@@ -157,7 +157,7 @@ class Users {
|
|
|
157
157
|
setCategoryPreferences(userId, categoryKey, setting, options = {}) {
|
|
158
158
|
return __awaiter(this, void 0, void 0, function* () {
|
|
159
159
|
const preferenceSetId = options.preferenceSet || helpers_1.DEFAULT_PREFERENCE_SET_ID;
|
|
160
|
-
const { data } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}/categories/${categoryKey}`, helpers_1.buildUpdateParam(setting));
|
|
160
|
+
const { data } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}/categories/${categoryKey}`, (0, helpers_1.buildUpdateParam)(setting));
|
|
161
161
|
return data;
|
|
162
162
|
});
|
|
163
163
|
}
|
|
@@ -31,7 +31,7 @@ export declare enum RepeatFrequency {
|
|
|
31
31
|
Daily = "daily",
|
|
32
32
|
Hourly = "hourly"
|
|
33
33
|
}
|
|
34
|
-
export
|
|
34
|
+
export type ScheduleRepeatProperties = {
|
|
35
35
|
frequency: RepeatFrequency;
|
|
36
36
|
interval?: number;
|
|
37
37
|
day_of_month?: number;
|
|
@@ -75,11 +75,11 @@ export interface Schedule {
|
|
|
75
75
|
repeats: ScheduleRepeatProperties[];
|
|
76
76
|
__cursor?: string;
|
|
77
77
|
}
|
|
78
|
-
export
|
|
79
|
-
export
|
|
78
|
+
export type Recipient = string | ObjectRef;
|
|
79
|
+
export type Actor = Recipient;
|
|
80
80
|
export interface UserWithUpsert extends IdentifyProperties {
|
|
81
81
|
id: string;
|
|
82
82
|
}
|
|
83
|
-
export
|
|
84
|
-
export
|
|
85
|
-
export
|
|
83
|
+
export type ObjectWithUpsert = ObjectRef & SetObjectProperties;
|
|
84
|
+
export type RecipientWithUpsert = UserWithUpsert | ObjectWithUpsert;
|
|
85
|
+
export type ActorWithUpsert = RecipientWithUpsert;
|
|
@@ -10,11 +10,11 @@ var DaysOfWeek;
|
|
|
10
10
|
DaysOfWeek["Fri"] = "fri";
|
|
11
11
|
DaysOfWeek["Sat"] = "sat";
|
|
12
12
|
DaysOfWeek["Sun"] = "sun";
|
|
13
|
-
})(DaysOfWeek
|
|
13
|
+
})(DaysOfWeek || (exports.DaysOfWeek = DaysOfWeek = {}));
|
|
14
14
|
var RepeatFrequency;
|
|
15
15
|
(function (RepeatFrequency) {
|
|
16
16
|
RepeatFrequency["Monthly"] = "monthly";
|
|
17
17
|
RepeatFrequency["Weekly"] = "weekly";
|
|
18
18
|
RepeatFrequency["Daily"] = "daily";
|
|
19
19
|
RepeatFrequency["Hourly"] = "hourly";
|
|
20
|
-
})(RepeatFrequency
|
|
20
|
+
})(RepeatFrequency || (exports.RepeatFrequency = RepeatFrequency = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knocklabs/node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Library for interacting with the Knock API",
|
|
5
5
|
"homepage": "https://github.com/knocklabs/knock-node",
|
|
6
6
|
"author": "@knocklabs",
|
|
@@ -32,19 +32,16 @@
|
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/jest": "26.0.23",
|
|
35
|
-
"@types/jsonwebtoken": "^9.0.1",
|
|
36
35
|
"@types/node": "^15.0.1",
|
|
37
36
|
"@types/pluralize": "0.0.29",
|
|
38
|
-
"axios-mock-adapter": "^1.22.0",
|
|
39
37
|
"jest": "26.6.3",
|
|
40
38
|
"prettier": "2.2.1",
|
|
41
39
|
"supertest": "6.1.3",
|
|
42
40
|
"ts-jest": "26.5.5",
|
|
43
41
|
"tslint": "6.1.3",
|
|
44
|
-
"typescript": "
|
|
42
|
+
"typescript": "^5.3.3"
|
|
45
43
|
},
|
|
46
44
|
"dependencies": {
|
|
47
|
-
"
|
|
48
|
-
"jsonwebtoken": "^9.0.0"
|
|
45
|
+
"jose": "^5.2.0"
|
|
49
46
|
}
|
|
50
|
-
}
|
|
47
|
+
}
|