@knocklabs/node 0.4.9 → 0.4.11
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 +27 -27
- package/dist/package.json +1 -1
- package/dist/src/knock.d.ts +2 -0
- package/dist/src/knock.js +2 -0
- package/dist/src/resources/tenants/index.d.ts +11 -0
- package/dist/src/resources/tenants/index.js +42 -0
- package/dist/src/resources/tenants/interfaces.d.ts +30 -0
- package/dist/src/resources/tenants/interfaces.js +2 -0
- package/dist/src/resources/workflows/interfaces.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,19 +32,7 @@ const knockClient = new Knock("sk_12345");
|
|
|
32
32
|
|
|
33
33
|
## Usage
|
|
34
34
|
|
|
35
|
-
###
|
|
36
|
-
|
|
37
|
-
```javascript
|
|
38
|
-
const { Knock } = require("@knocklabs/node");
|
|
39
|
-
const knockClient = new Knock("sk_12345");
|
|
40
|
-
|
|
41
|
-
await knockClient.users.identify("jhammond", {
|
|
42
|
-
name: "John Hammond",
|
|
43
|
-
email: "jhammond@ingen.net",
|
|
44
|
-
});
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### Sending notifies (triggering workflows)
|
|
35
|
+
### Sending notifications (triggering workflows)
|
|
48
36
|
|
|
49
37
|
```javascript
|
|
50
38
|
const { Knock } = require("@knocklabs/node");
|
|
@@ -54,7 +42,7 @@ const knockClient = new Knock("sk_12345");
|
|
|
54
42
|
await knockClient.notify("dinosaurs-loose", {
|
|
55
43
|
// user id of who performed the action
|
|
56
44
|
actor: "dnedry",
|
|
57
|
-
// list of user ids for who should receive the
|
|
45
|
+
// list of user ids for who should receive the notification
|
|
58
46
|
recipients: ["jhammond", "agrant", "imalcolm", "esattler"],
|
|
59
47
|
// data payload to send through
|
|
60
48
|
data: {
|
|
@@ -63,11 +51,35 @@ await knockClient.notify("dinosaurs-loose", {
|
|
|
63
51
|
},
|
|
64
52
|
// an optional identifier for the tenant that the notifications belong to
|
|
65
53
|
tenant: "jurassic-park",
|
|
66
|
-
// an optional key to provide to cancel a
|
|
54
|
+
// an optional key to provide to cancel a workflow
|
|
67
55
|
cancellationKey: triggerAlert.id,
|
|
68
56
|
});
|
|
69
57
|
```
|
|
70
58
|
|
|
59
|
+
### Canceling workflows
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
const { Knock } = require("@knocklabs/node");
|
|
63
|
+
const knockClient = new Knock("sk_12345");
|
|
64
|
+
|
|
65
|
+
await knockClient.workflows.cancel("dinosaurs-loose", triggerAlert.id, {
|
|
66
|
+
// optionally you can specify recipients here
|
|
67
|
+
recipients: ["jhammond"],
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Identifying users
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
const { Knock } = require("@knocklabs/node");
|
|
75
|
+
const knockClient = new Knock("sk_12345");
|
|
76
|
+
|
|
77
|
+
await knockClient.users.identify("jhammond", {
|
|
78
|
+
name: "John Hammond",
|
|
79
|
+
email: "jhammond@ingen.net",
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
71
83
|
### Retrieving users
|
|
72
84
|
|
|
73
85
|
```javascript
|
|
@@ -121,18 +133,6 @@ await knockClient.users.setChannelData("jhammond", KNOCK_APNS_CHANNEL_ID, {
|
|
|
121
133
|
await knockClient.users.getChannelData("jhammond", KNOCK_APNS_CHANNEL_ID);
|
|
122
134
|
```
|
|
123
135
|
|
|
124
|
-
### Canceling workflows
|
|
125
|
-
|
|
126
|
-
```javascript
|
|
127
|
-
const { Knock } = require("@knocklabs/node");
|
|
128
|
-
const knockClient = new Knock("sk_12345");
|
|
129
|
-
|
|
130
|
-
await knockClient.workflows.cancel("dinosaurs-loose", triggerAlert.id, {
|
|
131
|
-
// optionally you can specify recipients here
|
|
132
|
-
recipients: ["jhammond"],
|
|
133
|
-
});
|
|
134
|
-
```
|
|
135
|
-
|
|
136
136
|
### Signing JWTs
|
|
137
137
|
|
|
138
138
|
You can use the `jsonwebtoken` package to [sign JWTs easily](https://www.npmjs.com/package/jsonwebtoken#jwtsignpayload-secretorprivatekey-options-callback).
|
package/dist/package.json
CHANGED
package/dist/src/knock.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { TriggerWorkflowProperties } from "./resources/workflows/interfaces";
|
|
|
7
7
|
import { BulkOperations } from "./resources/bulk_operations";
|
|
8
8
|
import { Objects } from "./resources/objects";
|
|
9
9
|
import { Messages } from "./resources/messages";
|
|
10
|
+
import { Tenants } from "./resources/tenants";
|
|
10
11
|
declare class Knock {
|
|
11
12
|
readonly key?: string | undefined;
|
|
12
13
|
readonly options: KnockOptions;
|
|
@@ -18,6 +19,7 @@ declare class Knock {
|
|
|
18
19
|
readonly bulkOperations: BulkOperations;
|
|
19
20
|
readonly objects: Objects;
|
|
20
21
|
readonly messages: Messages;
|
|
22
|
+
readonly tenants: Tenants;
|
|
21
23
|
constructor(key?: string | undefined, options?: KnockOptions);
|
|
22
24
|
notify(workflowKey: string, properties: TriggerWorkflowProperties): Promise<import("./resources/workflows/interfaces").WorkflowRun>;
|
|
23
25
|
post(path: string, entity: any, options?: PostAndPutOptions): Promise<AxiosResponse>;
|
package/dist/src/knock.js
CHANGED
|
@@ -22,6 +22,7 @@ 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
24
|
const messages_1 = require("./resources/messages");
|
|
25
|
+
const tenants_1 = require("./resources/tenants");
|
|
25
26
|
const DEFAULT_HOSTNAME = "https://api.knock.app";
|
|
26
27
|
class Knock {
|
|
27
28
|
constructor(key, options = {}) {
|
|
@@ -34,6 +35,7 @@ class Knock {
|
|
|
34
35
|
this.bulkOperations = new bulk_operations_1.BulkOperations(this);
|
|
35
36
|
this.objects = new objects_1.Objects(this);
|
|
36
37
|
this.messages = new messages_1.Messages(this);
|
|
38
|
+
this.tenants = new tenants_1.Tenants(this);
|
|
37
39
|
if (!key) {
|
|
38
40
|
this.key = process.env.KNOCK_API_KEY;
|
|
39
41
|
if (!this.key) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CommonMetadata, PaginatedResponse } from "../../common/interfaces";
|
|
2
|
+
import { Knock } from "../../knock";
|
|
3
|
+
import { Tenant, SetTenant, ListTenantsOptions } from "./interfaces";
|
|
4
|
+
export declare class Tenants {
|
|
5
|
+
readonly knock: Knock;
|
|
6
|
+
constructor(knock: Knock);
|
|
7
|
+
list(filteringOptions?: ListTenantsOptions): Promise<PaginatedResponse<Tenant>>;
|
|
8
|
+
get<T = CommonMetadata>(id: string): Promise<Tenant<T>>;
|
|
9
|
+
set<T = CommonMetadata>(id: string, tenantData: SetTenant): Promise<Tenant<T>>;
|
|
10
|
+
delete(id: string): Promise<null>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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.Tenants = void 0;
|
|
13
|
+
class Tenants {
|
|
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/tenants", filteringOptions);
|
|
20
|
+
return data;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
get(id) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const { data } = yield this.knock.get(`/v1/tenants/${id}`);
|
|
26
|
+
return data;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
set(id, tenantData) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const { data } = yield this.knock.put(`/v1/tenants/${id}`, tenantData);
|
|
32
|
+
return data;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
delete(id) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const { data } = yield this.knock.delete(`/v1/tenants/${id}`);
|
|
38
|
+
return data;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.Tenants = Tenants;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CommonMetadata, PaginationOptions } from "../../common/interfaces";
|
|
2
|
+
import { SetPreferencesProperties } from "../preferences/interfaces";
|
|
3
|
+
export interface TenantRef {
|
|
4
|
+
id: string;
|
|
5
|
+
}
|
|
6
|
+
export interface TenantBrandingSettings {
|
|
7
|
+
primary_color?: string;
|
|
8
|
+
primary_color_contrast?: string;
|
|
9
|
+
logo_url?: string;
|
|
10
|
+
icon_url?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface TenantSettings {
|
|
13
|
+
branding?: TenantBrandingSettings;
|
|
14
|
+
preference_set?: SetPreferencesProperties;
|
|
15
|
+
}
|
|
16
|
+
export interface Tenant<T = CommonMetadata> {
|
|
17
|
+
id: string;
|
|
18
|
+
properties: T;
|
|
19
|
+
settings?: TenantSettings;
|
|
20
|
+
created_at?: string;
|
|
21
|
+
updated_at: string;
|
|
22
|
+
}
|
|
23
|
+
export interface SetTenant {
|
|
24
|
+
name?: string;
|
|
25
|
+
settings?: TenantSettings;
|
|
26
|
+
}
|
|
27
|
+
export interface ListTenantsOptions extends PaginationOptions {
|
|
28
|
+
tenant_id?: string;
|
|
29
|
+
name?: string;
|
|
30
|
+
}
|
|
@@ -4,7 +4,7 @@ export interface TriggerWorkflowProperties<T = {
|
|
|
4
4
|
[key: string]: any;
|
|
5
5
|
}> {
|
|
6
6
|
actor?: Actor | ActorWithUpsert;
|
|
7
|
-
recipients?:
|
|
7
|
+
recipients?: (Recipient | RecipientWithUpsert)[];
|
|
8
8
|
cancellationKey?: string;
|
|
9
9
|
tenant?: string;
|
|
10
10
|
data?: T;
|