@knocklabs/node 0.4.0 → 0.4.3

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/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knocklabs/node",
3
- "version": "0.4.0",
3
+ "version": "0.4.3",
4
4
  "description": "Library for interacting with the Knock API",
5
5
  "homepage": "https://github.com/knocklabs/knock-node",
6
6
  "author": "@knocklabs",
@@ -23,3 +23,23 @@ export interface ChannelData<T = CommonMetadata> {
23
23
  }
24
24
  export interface SetChannelDataProperties {
25
25
  }
26
+ declare type PageInfo = {
27
+ before: string;
28
+ after: string;
29
+ page_size: number;
30
+ };
31
+ export interface PaginatedResponse<T> {
32
+ entries: T[];
33
+ page_info: PageInfo;
34
+ }
35
+ export interface PaginationOptions {
36
+ page_size?: number;
37
+ after?: string;
38
+ before?: string;
39
+ }
40
+ export interface Condition {
41
+ argument: string;
42
+ variable: string;
43
+ operator: string;
44
+ }
45
+ export {};
@@ -6,6 +6,7 @@ import { Workflows } from "./resources/workflows";
6
6
  import { TriggerWorkflowProperties } from "./resources/workflows/interfaces";
7
7
  import { BulkOperations } from "./resources/bulk_operations";
8
8
  import { Objects } from "./resources/objects";
9
+ import { Messages } from "./resources/messages";
9
10
  declare class Knock {
10
11
  readonly key?: string | undefined;
11
12
  readonly options: KnockOptions;
@@ -16,6 +17,7 @@ declare class Knock {
16
17
  readonly workflows: Workflows;
17
18
  readonly bulkOperations: BulkOperations;
18
19
  readonly objects: Objects;
20
+ readonly messages: Messages;
19
21
  constructor(key?: string | undefined, options?: KnockOptions);
20
22
  notify(workflowKey: string, properties: TriggerWorkflowProperties): Promise<import("./resources/workflows/interfaces").WorkflowRun>;
21
23
  post(path: string, entity: any, options?: PostAndPutOptions): Promise<AxiosResponse>;
package/dist/src/knock.js CHANGED
@@ -21,6 +21,7 @@ const preferences_1 = require("./resources/preferences");
21
21
  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
+ const messages_1 = require("./resources/messages");
24
25
  const DEFAULT_HOSTNAME = "https://api.knock.app";
25
26
  class Knock {
26
27
  constructor(key, options = {}) {
@@ -32,6 +33,7 @@ class Knock {
32
33
  this.workflows = new workflows_1.Workflows(this);
33
34
  this.bulkOperations = new bulk_operations_1.BulkOperations(this);
34
35
  this.objects = new objects_1.Objects(this);
36
+ this.messages = new messages_1.Messages(this);
35
37
  if (!key) {
36
38
  this.key = process.env.KNOCK_API_KEY;
37
39
  if (!this.key) {
@@ -0,0 +1,11 @@
1
+ import { User } from "../users/interfaces";
2
+ import { Object } from "../objects/interfaces";
3
+ export interface Activity {
4
+ id: string;
5
+ data: Record<string, any>;
6
+ actor: User | Object;
7
+ recipient: User | Object;
8
+ inserted_at: string;
9
+ updated_at: string;
10
+ __cursor?: string;
11
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,13 @@
1
+ import { PaginatedResponse, PaginationOptions } from "../../common/interfaces";
2
+ import { Message, MessageContent, MessageEvent, ListMessagesOptions } from "./interfaces";
3
+ import { Activity } from "../activities/interfaces";
4
+ import { Knock } from "../../knock";
5
+ export declare class Messages {
6
+ readonly knock: Knock;
7
+ constructor(knock: Knock);
8
+ list(filteringOptions?: ListMessagesOptions): Promise<Message>;
9
+ get(messageId: string): Promise<Message>;
10
+ getContent(messageId: string): Promise<MessageContent>;
11
+ getEvents(messageId: string, paginationOptions?: PaginationOptions): Promise<PaginatedResponse<MessageEvent>>;
12
+ getActivities(messageId: string, paginationOptions?: PaginationOptions): Promise<PaginatedResponse<Activity>>;
13
+ }
@@ -0,0 +1,60 @@
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.Messages = void 0;
13
+ class Messages {
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/messages", filteringOptions);
20
+ return data;
21
+ });
22
+ }
23
+ get(messageId) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ if (!messageId) {
26
+ throw new Error(`Incomplete arguments. You must provide a 'messageId'`);
27
+ }
28
+ const { data } = yield this.knock.get(`/v1/messages/${messageId}`);
29
+ return data;
30
+ });
31
+ }
32
+ getContent(messageId) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ if (!messageId) {
35
+ throw new Error(`Incomplete arguments. You must provide a 'messageId'`);
36
+ }
37
+ const { data } = yield this.knock.get(`/v1/messages/${messageId}/content`);
38
+ return data;
39
+ });
40
+ }
41
+ getEvents(messageId, paginationOptions = {}) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ if (!messageId) {
44
+ throw new Error(`Incomplete arguments. You must provide a 'messageId'`);
45
+ }
46
+ const { data } = yield this.knock.get(`/v1/messages/${messageId}/events`, paginationOptions);
47
+ return data;
48
+ });
49
+ }
50
+ getActivities(messageId, paginationOptions = {}) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ if (!messageId) {
53
+ throw new Error(`Incomplete arguments. You must provide a 'messageId'`);
54
+ }
55
+ const { data } = yield this.knock.get(`/v1/messages/${messageId}/activities`, paginationOptions);
56
+ return data;
57
+ });
58
+ }
59
+ }
60
+ exports.Messages = Messages;
@@ -0,0 +1,43 @@
1
+ import { ObjectRef } from "../objects/interfaces";
2
+ import { PaginationOptions } from "../../common/interfaces";
3
+ export interface Message {
4
+ id: string;
5
+ channel_id: string;
6
+ recipient: string | ObjectRef;
7
+ tenant: string | null;
8
+ status: MessageStatus;
9
+ read_at: string | null;
10
+ seen_at: string | null;
11
+ archived_at: string | null;
12
+ inserted_at: string;
13
+ updated_at: string;
14
+ source: WorkflowSource;
15
+ data: any;
16
+ __cursor?: string;
17
+ }
18
+ export interface MessageEvent {
19
+ id: string;
20
+ environment_id: string;
21
+ recipient: string | ObjectRef;
22
+ data: Record<string, any>;
23
+ type: string;
24
+ inserted_at: string;
25
+ __cursor?: string;
26
+ }
27
+ export interface MessageContent {
28
+ id: string;
29
+ data: Record<string, any>;
30
+ inserted_at: string;
31
+ }
32
+ export interface ListMessagesOptions extends PaginationOptions {
33
+ source?: string;
34
+ tenant?: string;
35
+ status?: MessageStatus[];
36
+ channel_id?: string;
37
+ }
38
+ declare type WorkflowSource = {
39
+ version_id: string;
40
+ key: string;
41
+ };
42
+ declare type MessageStatus = "queued" | "sent" | "delivered" | "undelivered" | "not_sent";
43
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +1,8 @@
1
- import { ChannelData, CommonMetadata, SetChannelDataProperties } from "../../common/interfaces";
1
+ import { ChannelData, CommonMetadata, SetChannelDataProperties, PaginatedResponse } from "../../common/interfaces";
2
2
  import { Knock } from "../../knock";
3
3
  import { BulkSetObjectOption, Object, SetObjectProperties } from "./interfaces";
4
4
  import { BulkOperation } from "../bulk_operations/interfaces";
5
+ import { ListMessagesOptions, Message } from "../messages/interfaces";
5
6
  export declare class Objects {
6
7
  readonly knock: Knock;
7
8
  constructor(knock: Knock);
@@ -12,4 +13,5 @@ export declare class Objects {
12
13
  bulkDelete(collection: string, objectIds: string[]): Promise<BulkOperation>;
13
14
  getChannelData<T = CommonMetadata>(collection: string, id: string, channelId: string): Promise<ChannelData<T>>;
14
15
  setChannelData<T = CommonMetadata>(collection: string, id: string, channelId: string, channelData: SetChannelDataProperties): Promise<ChannelData<T>>;
16
+ getMessages(collection: string, objectId: string, filteringOptions?: ListMessagesOptions): Promise<PaginatedResponse<Message>>;
15
17
  }
@@ -62,5 +62,17 @@ class Objects {
62
62
  return data;
63
63
  });
64
64
  }
65
+ //
66
+ // Messages
67
+ //
68
+ getMessages(collection, objectId, filteringOptions = {}) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ if (!collection || !objectId) {
71
+ throw new Error(`Incomplete arguments. You must provide a 'collection' and 'objectId'`);
72
+ }
73
+ const { data } = yield this.knock.get(`/v1/objects/${collection}/${objectId}/messages`, filteringOptions);
74
+ return data;
75
+ });
76
+ }
65
77
  }
66
78
  exports.Objects = Objects;
@@ -1,5 +1,5 @@
1
1
  import { WorkflowPreferenceSetting } from "./interfaces";
2
- export declare function buildUpdateParam(param: WorkflowPreferenceSetting): {
2
+ export declare function buildUpdateParam(param: WorkflowPreferenceSetting): import("./interfaces").ConditionalPreferenceSettings | {
3
3
  channel_types: import("./interfaces").ChannelTypePreferences;
4
4
  } | {
5
5
  subscribed: boolean;
@@ -1,10 +1,13 @@
1
- import { ChannelType } from "../../common/interfaces";
1
+ import { ChannelType, Condition } from "../../common/interfaces";
2
+ export declare type ConditionalPreferenceSettings = {
3
+ conditions: Condition[];
4
+ };
2
5
  export declare type ChannelTypePreferences = {
3
- [K in ChannelType]: boolean;
6
+ [K in ChannelType]?: boolean | ConditionalPreferenceSettings;
4
7
  };
5
8
  export declare type WorkflowPreferenceSetting = boolean | {
6
9
  channel_types: ChannelTypePreferences;
7
- };
10
+ } | ConditionalPreferenceSettings;
8
11
  export interface WorkflowPreferences {
9
12
  [key: string]: WorkflowPreferenceSetting;
10
13
  }
@@ -1,6 +1,7 @@
1
- import { ChannelData, ChannelType, CommonMetadata } from "../../common/interfaces";
1
+ import { ChannelData, ChannelType, CommonMetadata, PaginatedResponse } from "../../common/interfaces";
2
2
  import { BulkOperation } from "../bulk_operations/interfaces";
3
3
  import { ChannelTypePreferences, PreferenceOptions, PreferenceSet, SetPreferencesProperties, WorkflowPreferences, WorkflowPreferenceSetting } from "../preferences/interfaces";
4
+ import { ListMessagesOptions, Message } from "../messages/interfaces";
4
5
  import { Knock } from "../../knock";
5
6
  import { BulkIdentifyUser, IdentifyProperties, User, UserFeedOptions } from "./interfaces";
6
7
  export declare class Users {
@@ -11,6 +12,7 @@ export declare class Users {
11
12
  get(userId: string): Promise<User>;
12
13
  delete(userId: string): Promise<null>;
13
14
  bulkDelete(userIds: string[]): Promise<BulkOperation>;
15
+ merge(toUserId: string, fromUserId: string): Promise<User>;
14
16
  getFeed(userId: string, channelId: string, feedOptions?: UserFeedOptions): Promise<any>;
15
17
  getAllPreferences(userId: string): Promise<any>;
16
18
  getPrefences(userId: string, options?: PreferenceOptions): Promise<PreferenceSet>;
@@ -23,5 +25,6 @@ export declare class Users {
23
25
  setCategoriesPreferences(userId: string, categoryPreferences: WorkflowPreferences, options?: PreferenceOptions): Promise<PreferenceSet>;
24
26
  setCategoryPreferences(userId: string, categoryKey: string, setting: WorkflowPreferenceSetting, options?: PreferenceOptions): Promise<PreferenceSet>;
25
27
  getChannelData<T = CommonMetadata>(userId: string, channelId: string): Promise<ChannelData<T>>;
26
- setChannelData<T = CommonMetadata>(userId: string, channelId: string, channelData: Record<string, string>): Promise<ChannelData<T>>;
28
+ setChannelData<T = CommonMetadata>(userId: string, channelId: string, channelData: Record<string, any>): Promise<ChannelData<T>>;
29
+ getMessages(userId: string, filteringOptions?: ListMessagesOptions): Promise<PaginatedResponse<Message>>;
27
30
  }
@@ -59,6 +59,17 @@ class Users {
59
59
  return data;
60
60
  });
61
61
  }
62
+ merge(toUserId, fromUserId) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ if (!toUserId || !fromUserId) {
65
+ throw new Error(`Incomplete arguments. You must provide both a 'toUserId' and a 'fromUserId'.`);
66
+ }
67
+ const { data } = yield this.knock.post(`/v1/users/${toUserId}/merge`, {
68
+ from_user_id: fromUserId,
69
+ });
70
+ return data;
71
+ });
72
+ }
62
73
  //
63
74
  // Feeds
64
75
  //
@@ -166,5 +177,17 @@ class Users {
166
177
  return data;
167
178
  });
168
179
  }
180
+ //
181
+ // Messages
182
+ //
183
+ getMessages(userId, filteringOptions = {}) {
184
+ return __awaiter(this, void 0, void 0, function* () {
185
+ if (!userId) {
186
+ throw new Error(`Incomplete arguments. You must provide a 'userId'`);
187
+ }
188
+ const { data } = yield this.knock.get(`/v1/users/${userId}/messages`, filteringOptions);
189
+ return data;
190
+ });
191
+ }
169
192
  }
170
193
  exports.Users = Users;
@@ -1,3 +1,4 @@
1
+ import { PaginationOptions } from "../../common/interfaces";
1
2
  export interface IdentifyProperties {
2
3
  name?: string;
3
4
  email?: string;
@@ -16,10 +17,7 @@ export interface User {
16
17
  export interface BulkIdentifyUser extends IdentifyProperties {
17
18
  id: string;
18
19
  }
19
- export interface UserFeedOptions {
20
- page_size?: number;
21
- after?: string;
22
- before?: string;
20
+ export interface UserFeedOptions extends PaginationOptions {
23
21
  source?: string;
24
22
  tenant?: string;
25
23
  status?: "unread" | "unseen" | "all";
@@ -16,8 +16,8 @@ class Workflows {
16
16
  }
17
17
  trigger(workflowKey, { actor, recipients, cancellationKey, tenant, data: notifyData, }) {
18
18
  return __awaiter(this, void 0, void 0, function* () {
19
- if (!workflowKey && !actor && !recipients) {
20
- throw new Error(`Incomplete arguments. At a minimum you need to specify 'workflowKey', 'actor', and 'recipients'.`);
19
+ if (!workflowKey && !recipients) {
20
+ throw new Error(`Incomplete arguments. At a minimum you need to specify 'workflowKey' and 'recipients'.`);
21
21
  }
22
22
  const { data } = yield this.knock.post(`/v1/workflows/${workflowKey}/trigger`, {
23
23
  actor,
@@ -1,12 +1,12 @@
1
1
  import { ObjectRef } from "../objects/interfaces";
2
- export interface TriggerWorkflowProperties {
2
+ export interface TriggerWorkflowProperties<T = {
3
+ [key: string]: any;
4
+ }> {
3
5
  actor?: string | ObjectRef;
4
6
  recipients?: string[] | ObjectRef[];
5
7
  cancellationKey?: string;
6
8
  tenant?: string;
7
- data?: {
8
- [key: string]: any;
9
- };
9
+ data?: T;
10
10
  }
11
11
  export interface CancelWorkflowProperties {
12
12
  recipients?: string[] | ObjectRef;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knocklabs/node",
3
- "version": "0.4.0",
3
+ "version": "0.4.3",
4
4
  "description": "Library for interacting with the Knock API",
5
5
  "homepage": "https://github.com/knocklabs/knock-node",
6
6
  "author": "@knocklabs",