@knocklabs/node 0.2.0 → 0.2.4

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 CHANGED
@@ -61,6 +61,8 @@ await knockClient.notify("dinosaurs-loose", {
61
61
  type: "trex",
62
62
  priority: 1,
63
63
  },
64
+ // an optional identifier for the tenant that the notifications belong to
65
+ tenant: "jurassic-park",
64
66
  // an optional key to provide to cancel a notify
65
67
  cancellationKey: triggerAlert.id,
66
68
  });
@@ -115,7 +117,22 @@ await knockClient.preferences.setWorkflow("jhammond", "dinosaurs-loose", {
115
117
  });
116
118
  ```
117
119
 
118
- ### Cancelling workflows
120
+ ### Getting and setting channel data
121
+
122
+ ```javascript
123
+ const { Knock } = require("@knocklabs/node");
124
+ const knockClient = new Knock("sk_12345");
125
+
126
+ // Setting channel data for an APNS
127
+ await knockClient.users.setChannelData("jhammond", KNOCK_APNS_CHANNEL_ID, {
128
+ tokens: [apnsToken],
129
+ });
130
+
131
+ // Getting channel data for the APNS channel
132
+ await knockClient.users.getChannelData("jhammond", KNOCK_APNS_CHANNEL_ID);
133
+ ```
134
+
135
+ ### Canceling workflows
119
136
 
120
137
  ```javascript
121
138
  const { Knock } = require("@knocklabs/node");
@@ -133,7 +150,7 @@ You can use the `jsonwebtoken` package to [sign JWTs easily](https://www.npmjs.c
133
150
  You will need to generate an environment specific signing key, which you can find in the Knock dashboard.
134
151
 
135
152
  If you're using a signing token you will need to pass this to your client to perform authentication.
136
- You can read more about [clientside authentication here](https://docs.knock.app/client-integration/authenticating-users).
153
+ You can read more about [client-side authentication here](https://docs.knock.app/client-integration/authenticating-users).
137
154
 
138
155
  ```javascript
139
156
  const jwt = require("jsonwebtoken");
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knocklabs/node",
3
- "version": "0.2.0",
3
+ "version": "0.2.4",
4
4
  "description": "Library for interacting with the Knock API",
5
5
  "homepage": "https://github.com/knocklabs/knock-node",
6
6
  "author": "@knocklabs",
@@ -3,16 +3,17 @@ 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
+ import { TriggerWorkflowProperties } from "./resources/workflows/interfaces";
6
7
  declare class Knock {
7
8
  readonly key?: string | undefined;
8
9
  readonly options: KnockOptions;
9
10
  readonly host: string;
10
11
  private readonly client;
11
- readonly notify: (workflowKey: string, { actor, recipients, cancellationKey, data: notifyData, }: import(".").TriggerWorkflowProperties) => Promise<import(".").WorkflowRun>;
12
12
  readonly users: Users;
13
13
  readonly preferences: Preferences;
14
14
  readonly workflows: Workflows;
15
15
  constructor(key?: string | undefined, options?: KnockOptions);
16
+ notify(workflowKey: string, properties: TriggerWorkflowProperties): Promise<import("./resources/workflows/interfaces").WorkflowRun>;
16
17
  post(path: string, entity: any, options?: PostAndPutOptions): Promise<AxiosResponse>;
17
18
  put(path: string, entity: any, options?: PostAndPutOptions): Promise<AxiosResponse>;
18
19
  delete(path: string, entity?: any): Promise<AxiosResponse>;
package/dist/src/knock.js CHANGED
@@ -16,7 +16,6 @@ exports.Knock = void 0;
16
16
  const axios_1 = __importDefault(require("axios"));
17
17
  const package_json_1 = require("../package.json");
18
18
  const exceptions_1 = require("./common/exceptions");
19
- const notify_1 = require("./resources/notify");
20
19
  const users_1 = require("./resources/users");
21
20
  const preferences_1 = require("./resources/preferences");
22
21
  const workflows_1 = require("./resources/workflows");
@@ -25,7 +24,6 @@ class Knock {
25
24
  constructor(key, options = {}) {
26
25
  this.key = key;
27
26
  this.options = options;
28
- this.notify = notify_1.notify(this);
29
27
  this.users = new users_1.Users(this);
30
28
  this.preferences = new preferences_1.Preferences(this);
31
29
  this.workflows = new workflows_1.Workflows(this);
@@ -44,6 +42,12 @@ class Knock {
44
42
  },
45
43
  });
46
44
  }
45
+ // Delegate the notify function to the workflows trigger
46
+ notify(workflowKey, properties) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ return this.workflows.trigger(workflowKey, properties);
49
+ });
50
+ }
47
51
  post(path, entity, options = {}) {
48
52
  return __awaiter(this, void 0, void 0, function* () {
49
53
  try {
@@ -11,6 +11,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Preferences = void 0;
13
13
  const DEFAULT_PREFERENCE_SET_ID = "default";
14
+ function buildUpdateParam(param) {
15
+ if (typeof param === "object") {
16
+ return param;
17
+ }
18
+ return { subscribed: param };
19
+ }
14
20
  class Preferences {
15
21
  constructor(knock) {
16
22
  this.knock = knock;
@@ -59,7 +65,7 @@ class Preferences {
59
65
  setWorkflow(userId, workflowKey, setting, options = {}) {
60
66
  return __awaiter(this, void 0, void 0, function* () {
61
67
  const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;
62
- const { data, } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}/workflows/${workflowKey}`, { subscribed: setting });
68
+ const { data } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}/workflows/${workflowKey}`, buildUpdateParam(setting));
63
69
  return data;
64
70
  });
65
71
  }
@@ -73,7 +79,7 @@ class Preferences {
73
79
  setCategory(userId, categoryKey, setting, options = {}) {
74
80
  return __awaiter(this, void 0, void 0, function* () {
75
81
  const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;
76
- const { data, } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}/categories/${categoryKey}`, { subscribed: setting });
82
+ const { data } = yield this.knock.put(`/v1/users/${userId}/preferences/${preferenceSetId}/categories/${categoryKey}`, buildUpdateParam(setting));
77
83
  return data;
78
84
  });
79
85
  }
@@ -1,7 +1,6 @@
1
- export declare type ChannelType = "email" | "in_app_feed";
1
+ export declare type ChannelType = "email" | "in_app_feed" | "sms" | "push";
2
2
  export declare type ChannelTypePreferences = {
3
- email: boolean;
4
- in_app_feed: boolean;
3
+ [K in ChannelType]: boolean;
5
4
  };
6
5
  export declare type WorkflowPreferenceSetting = boolean | {
7
6
  channel_types: ChannelTypePreferences;
@@ -6,4 +6,6 @@ export declare class Users {
6
6
  identify(userId: string, properties?: IdentifyProperties): Promise<any>;
7
7
  get(userId: string): Promise<any>;
8
8
  delete(userId: string): Promise<any>;
9
+ getChannelData(userId: string, channelId: string): Promise<any>;
10
+ setChannelData(userId: string, channelId: string, channelData: Record<string, string>): Promise<any>;
9
11
  }
@@ -41,5 +41,24 @@ class Users {
41
41
  return data;
42
42
  });
43
43
  }
44
+ getChannelData(userId, channelId) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ if (!userId || !channelId) {
47
+ throw new Error(`Incomplete arguments. You must provide a 'userId' and a 'channelId'`);
48
+ }
49
+ const { data } = yield this.knock.get(`/v1/users/${userId}/channel_data/${channelId}`);
50
+ return data;
51
+ });
52
+ }
53
+ setChannelData(userId, channelId, channelData) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ if (!userId || !channelId) {
56
+ throw new Error(`Incomplete arguments. You must provide a 'userId' and a 'channelId'`);
57
+ }
58
+ const args = { data: channelData };
59
+ const { data } = yield this.knock.put(`/v1/users/${userId}/channel_data/${channelId}`, args);
60
+ return data;
61
+ });
62
+ }
44
63
  }
45
64
  exports.Users = Users;
@@ -3,6 +3,6 @@ import { CancelWorkflowProperties, TriggerWorkflowProperties, WorkflowRun } from
3
3
  export declare class Workflows {
4
4
  readonly knock: Knock;
5
5
  constructor(knock: Knock);
6
- trigger(workflowKey: string, { actor, recipients, cancellationKey, data: notifyData, }: TriggerWorkflowProperties): Promise<WorkflowRun>;
6
+ trigger(workflowKey: string, { actor, recipients, cancellationKey, tenant, data: notifyData, }: TriggerWorkflowProperties): Promise<WorkflowRun>;
7
7
  cancel(workflowKey: string, cancellationKey: string, { recipients }?: CancelWorkflowProperties): Promise<any>;
8
8
  }
@@ -14,7 +14,7 @@ class Workflows {
14
14
  constructor(knock) {
15
15
  this.knock = knock;
16
16
  }
17
- trigger(workflowKey, { actor, recipients, cancellationKey, data: notifyData, }) {
17
+ trigger(workflowKey, { actor, recipients, cancellationKey, tenant, data: notifyData, }) {
18
18
  return __awaiter(this, void 0, void 0, function* () {
19
19
  if (!workflowKey && !actor && !recipients) {
20
20
  throw new Error(`Incomplete arguments. At a minimum you need to specify 'workflowKey', 'actor', and 'recipients'.`);
@@ -23,6 +23,7 @@ class Workflows {
23
23
  actor,
24
24
  recipients,
25
25
  cancellation_key: cancellationKey,
26
+ tenant,
26
27
  data: notifyData,
27
28
  });
28
29
  return data;
@@ -2,6 +2,7 @@ export interface TriggerWorkflowProperties {
2
2
  actor: string;
3
3
  recipients?: string[];
4
4
  cancellationKey?: string;
5
+ tenant?: string;
5
6
  data?: {
6
7
  [key: string]: any;
7
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knocklabs/node",
3
- "version": "0.2.0",
3
+ "version": "0.2.4",
4
4
  "description": "Library for interacting with the Knock API",
5
5
  "homepage": "https://github.com/knocklabs/knock-node",
6
6
  "author": "@knocklabs",
@@ -1,3 +0,0 @@
1
- import { Knock } from "../../knock";
2
- import { IdentifyProperties } from "./interfaces";
3
- export declare function identify(knock: Knock): (userId: string, properties?: IdentifyProperties) => Promise<any>;
@@ -1,22 +0,0 @@
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.identify = void 0;
13
- function identify(knock) {
14
- return (userId, properties = {}) => __awaiter(this, void 0, void 0, function* () {
15
- if (!userId) {
16
- throw new Error(`Incomplete arguments. At a minimum you need to specify 'userId'.`);
17
- }
18
- const { data } = yield knock.put(`/v1/users/${userId}`, properties);
19
- return data;
20
- });
21
- }
22
- exports.identify = identify;
@@ -1,5 +0,0 @@
1
- export interface IdentifyProperties {
2
- name?: string;
3
- email?: string;
4
- [key: string]: any;
5
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- import { Knock } from "../../knock";
2
- export declare function notify(knock: Knock): (workflowKey: string, { actor, recipients, cancellationKey, data: notifyData, }: import("../..").TriggerWorkflowProperties) => Promise<import("../..").WorkflowRun>;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.notify = void 0;
4
- function notify(knock) {
5
- // This is just an alias to triggering the workflow
6
- return knock.workflows.trigger;
7
- }
8
- exports.notify = notify;
@@ -1,11 +0,0 @@
1
- export interface NotifyProperties {
2
- actor: string;
3
- recipients?: string[];
4
- cancelationKey?: string;
5
- data?: {
6
- [key: string]: any;
7
- };
8
- }
9
- export interface CancelNotifyProperties {
10
- recipients?: string[];
11
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });