@knocklabs/node 0.6.4 → 0.6.6
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 +32 -0
- package/dist/package.json +4 -1
- package/dist/src/common/fetchClient.js +22 -10
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/knock.d.ts +2 -0
- package/dist/src/knock.js +2 -0
- package/dist/src/resources/slack/index.d.ts +9 -0
- package/dist/src/resources/slack/index.js +75 -0
- package/dist/src/resources/slack/interfaces.d.ts +30 -0
- package/dist/src/resources/slack/interfaces.js +2 -0
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -136,6 +136,38 @@ await knockClient.users.setChannelData("jhammond", KNOCK_APNS_CHANNEL_ID, {
|
|
|
136
136
|
await knockClient.users.getChannelData("jhammond", KNOCK_APNS_CHANNEL_ID);
|
|
137
137
|
```
|
|
138
138
|
|
|
139
|
+
### Slack
|
|
140
|
+
|
|
141
|
+
```javascript
|
|
142
|
+
const { Knock } = require("@knocklabs/node");
|
|
143
|
+
const knockClient = new Knock("sk_12345");
|
|
144
|
+
|
|
145
|
+
const tenantId = "tenant-123";
|
|
146
|
+
const knockSlackChannelId = "7c1e0042-5ef2-411a-a43b-e541acb139ed";
|
|
147
|
+
// An optional object containing the query options passed to Slack:
|
|
148
|
+
// https://api.slack.com/methods/conversations.list#arg_cursor
|
|
149
|
+
const queryOptions = {
|
|
150
|
+
cursor: null,
|
|
151
|
+
limit: 200,
|
|
152
|
+
exclude_archived: true,
|
|
153
|
+
team_id: null,
|
|
154
|
+
types: "public_channel",
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
// Retrieve a list of Slack channels
|
|
159
|
+
const channelsInput = { tenant: tenantId, knockChannelId: knockSlackChannelId, queryOptions };
|
|
160
|
+
await knockClient.slack.getChannels(channelsInput);
|
|
161
|
+
|
|
162
|
+
// Check Slack connection
|
|
163
|
+
const authInput = { tenant: tenantId, knockChannelId: knockSlackChannelId }
|
|
164
|
+
await knockClient.slack.authCheck(authInput)
|
|
165
|
+
|
|
166
|
+
// Revoke access token
|
|
167
|
+
const revokeInput = { tenant: tenantId, knockChannelId: knockSlackChannelId }
|
|
168
|
+
await knockClient.slack.revokeAccessToken(revokeInput)
|
|
169
|
+
```
|
|
170
|
+
|
|
139
171
|
### Signing JWTs
|
|
140
172
|
|
|
141
173
|
When using [enhanced security mode](https://docs.knock.app/client-integration/authenticating-users) (recommended in production), you will need to sign JWTs server-side to authenticate your users.
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knocklabs/node",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "Library for interacting with the Knock API",
|
|
5
5
|
"homepage": "https://github.com/knocklabs/knock-node",
|
|
6
6
|
"author": "@knocklabs",
|
|
@@ -41,5 +41,8 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"jose": "^5.2.0"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=17.5.0"
|
|
44
47
|
}
|
|
45
48
|
}
|
|
@@ -69,18 +69,30 @@ class FetchClient {
|
|
|
69
69
|
}
|
|
70
70
|
buildUrl(path, params) {
|
|
71
71
|
const url = new URL(this.config.baseURL + path);
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
function appendParams(key, value, parentKey) {
|
|
73
|
+
const fullKey = parentKey ? `${parentKey}[${key}]` : key;
|
|
74
|
+
if (typeof value === "object" &&
|
|
75
|
+
value !== null &&
|
|
76
|
+
!(value instanceof Date) &&
|
|
77
|
+
!(value instanceof Array)) {
|
|
78
|
+
// If value is an object, recurse
|
|
79
|
+
Object.entries(value).forEach(([nestedKey, nestedValue]) => {
|
|
80
|
+
appendParams(nestedKey, nestedValue, fullKey);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
else if (Array.isArray(value)) {
|
|
74
84
|
// Send array values as individual values instead of a comma separated list
|
|
75
85
|
// e.g. key[]=1&key[]=2&key[]=3 instead of key=1,2,3
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
value.forEach((val) => url.searchParams.append(`${fullKey}[]`, val));
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// For primitive values, simply append them
|
|
90
|
+
url.searchParams.append(fullKey, value);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (params) {
|
|
94
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
95
|
+
appendParams(key, value);
|
|
84
96
|
});
|
|
85
97
|
}
|
|
86
98
|
return url;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./resources/workflows/interfaces";
|
|
2
2
|
export * from "./resources/users/interfaces";
|
|
3
3
|
export * from "./resources/preferences/interfaces";
|
|
4
|
+
export * from "./resources/slack/interfaces";
|
|
4
5
|
export * from "./common/interfaces";
|
|
5
6
|
export { Knock } from "./knock";
|
package/dist/src/index.js
CHANGED
|
@@ -18,6 +18,7 @@ exports.Knock = void 0;
|
|
|
18
18
|
__exportStar(require("./resources/workflows/interfaces"), exports);
|
|
19
19
|
__exportStar(require("./resources/users/interfaces"), exports);
|
|
20
20
|
__exportStar(require("./resources/preferences/interfaces"), exports);
|
|
21
|
+
__exportStar(require("./resources/slack/interfaces"), exports);
|
|
21
22
|
__exportStar(require("./common/interfaces"), exports);
|
|
22
23
|
var knock_1 = require("./knock");
|
|
23
24
|
Object.defineProperty(exports, "Knock", { enumerable: true, get: function () { return knock_1.Knock; } });
|
package/dist/src/knock.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { Messages } from "./resources/messages";
|
|
|
8
8
|
import { Tenants } from "./resources/tenants";
|
|
9
9
|
import { FetchResponse } from "./common/fetchClient";
|
|
10
10
|
import { TokenEntity, TokenGrant, TokenGrantOptions } from "./common/userTokens";
|
|
11
|
+
import { Slack } from "./resources/slack";
|
|
11
12
|
declare class Knock {
|
|
12
13
|
readonly key?: string | undefined;
|
|
13
14
|
readonly options: KnockOptions;
|
|
@@ -19,6 +20,7 @@ declare class Knock {
|
|
|
19
20
|
readonly objects: Objects;
|
|
20
21
|
readonly messages: Messages;
|
|
21
22
|
readonly tenants: Tenants;
|
|
23
|
+
readonly slack: Slack;
|
|
22
24
|
constructor(key?: string | undefined, options?: KnockOptions);
|
|
23
25
|
notify(workflowKey: string, properties: TriggerWorkflowProperties, options?: MethodOptions): Promise<import("./resources/workflows/interfaces").WorkflowRun>;
|
|
24
26
|
/**
|
package/dist/src/knock.js
CHANGED
|
@@ -23,6 +23,7 @@ const objects_1 = require("./resources/objects");
|
|
|
23
23
|
const messages_1 = require("./resources/messages");
|
|
24
24
|
const tenants_1 = require("./resources/tenants");
|
|
25
25
|
const fetchClient_1 = __importDefault(require("./common/fetchClient"));
|
|
26
|
+
const slack_1 = require("./resources/slack");
|
|
26
27
|
const DEFAULT_HOSTNAME = "https://api.knock.app";
|
|
27
28
|
class Knock {
|
|
28
29
|
constructor(key, options = {}) {
|
|
@@ -35,6 +36,7 @@ class Knock {
|
|
|
35
36
|
this.objects = new objects_1.Objects(this);
|
|
36
37
|
this.messages = new messages_1.Messages(this);
|
|
37
38
|
this.tenants = new tenants_1.Tenants(this);
|
|
39
|
+
this.slack = new slack_1.Slack(this);
|
|
38
40
|
if (!key) {
|
|
39
41
|
this.key = process.env.KNOCK_API_KEY;
|
|
40
42
|
if (!this.key) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Knock } from "../../knock";
|
|
2
|
+
import { AuthCheckInput, GetSlackChannelsInput, PaginatedSlackChannelResponse, RevokeAccessTokenInput } from "./interfaces";
|
|
3
|
+
export declare class Slack {
|
|
4
|
+
readonly knock: Knock;
|
|
5
|
+
constructor(knock: Knock);
|
|
6
|
+
getChannels(input: GetSlackChannelsInput): Promise<PaginatedSlackChannelResponse>;
|
|
7
|
+
authCheck({ tenant, knockChannelId }: AuthCheckInput): Promise<any>;
|
|
8
|
+
revokeAccessToken({ tenant, knockChannelId }: RevokeAccessTokenInput): Promise<any>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
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.Slack = void 0;
|
|
13
|
+
const TENANT_COLLECTION = "$tenants";
|
|
14
|
+
function removeNullKeys(obj) {
|
|
15
|
+
Object.keys(obj).forEach((key) => {
|
|
16
|
+
if (obj[key] === null) {
|
|
17
|
+
delete obj[key];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return obj;
|
|
21
|
+
}
|
|
22
|
+
class Slack {
|
|
23
|
+
constructor(knock) {
|
|
24
|
+
this.knock = knock;
|
|
25
|
+
}
|
|
26
|
+
getChannels(input) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const { knockChannelId, tenant } = input;
|
|
29
|
+
const queryOptions = input.queryOptions || {};
|
|
30
|
+
const params = {
|
|
31
|
+
access_token_object: {
|
|
32
|
+
object_id: tenant,
|
|
33
|
+
collection: TENANT_COLLECTION,
|
|
34
|
+
},
|
|
35
|
+
channel_id: knockChannelId,
|
|
36
|
+
query_options: removeNullKeys({
|
|
37
|
+
cursor: queryOptions.cursor || null,
|
|
38
|
+
limit: queryOptions.limit || null,
|
|
39
|
+
exclude_archived: queryOptions.excludeArchived || null,
|
|
40
|
+
team_id: queryOptions.teamId || null,
|
|
41
|
+
types: queryOptions.types || null,
|
|
42
|
+
}),
|
|
43
|
+
};
|
|
44
|
+
const { data } = yield this.knock.get(`/v1/providers/slack/${knockChannelId}/channels`, params);
|
|
45
|
+
return data;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
authCheck({ tenant, knockChannelId }) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const params = {
|
|
51
|
+
access_token_object: {
|
|
52
|
+
object_id: tenant,
|
|
53
|
+
collection: TENANT_COLLECTION,
|
|
54
|
+
},
|
|
55
|
+
channel_id: knockChannelId,
|
|
56
|
+
};
|
|
57
|
+
const { data } = yield this.knock.get(`/v1/providers/slack/${knockChannelId}/auth_check`, params);
|
|
58
|
+
return data;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
revokeAccessToken({ tenant, knockChannelId }) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const params = {
|
|
64
|
+
access_token_object: {
|
|
65
|
+
object_id: tenant,
|
|
66
|
+
collection: TENANT_COLLECTION,
|
|
67
|
+
},
|
|
68
|
+
channel_id: knockChannelId,
|
|
69
|
+
};
|
|
70
|
+
const { data } = yield this.knock.get(`/v1/providers/slack/${knockChannelId}/revoke_access`, params);
|
|
71
|
+
return data;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.Slack = Slack;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type GetSlackChannelsInput = {
|
|
2
|
+
tenant: string;
|
|
3
|
+
knockChannelId: string;
|
|
4
|
+
queryOptions?: {
|
|
5
|
+
limit?: number;
|
|
6
|
+
cursor?: string;
|
|
7
|
+
excludeArchived?: boolean;
|
|
8
|
+
teamId?: string;
|
|
9
|
+
types?: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export type SlackChannel = {
|
|
13
|
+
name: string;
|
|
14
|
+
id: string;
|
|
15
|
+
is_private: boolean;
|
|
16
|
+
is_im: boolean;
|
|
17
|
+
context_team_id: boolean;
|
|
18
|
+
};
|
|
19
|
+
export type PaginatedSlackChannelResponse = {
|
|
20
|
+
slack_channels: SlackChannel[];
|
|
21
|
+
next_cursor: string;
|
|
22
|
+
};
|
|
23
|
+
export type AuthCheckInput = {
|
|
24
|
+
tenant: string;
|
|
25
|
+
knockChannelId: string;
|
|
26
|
+
};
|
|
27
|
+
export type RevokeAccessTokenInput = {
|
|
28
|
+
tenant: string;
|
|
29
|
+
knockChannelId: string;
|
|
30
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knocklabs/node",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "Library for interacting with the Knock API",
|
|
5
5
|
"homepage": "https://github.com/knocklabs/knock-node",
|
|
6
6
|
"author": "@knocklabs",
|
|
@@ -41,5 +41,8 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"jose": "^5.2.0"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=17.5.0"
|
|
44
47
|
}
|
|
45
|
-
}
|
|
48
|
+
}
|