@knocklabs/node 0.4.16 → 0.4.18

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 ADDED
@@ -0,0 +1,3 @@
1
+ ## v0.4.18
2
+
3
+ * Introduce "Idempotency-Key" header for workflow triggers
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knocklabs/node",
3
- "version": "0.4.16",
3
+ "version": "0.4.18",
4
4
  "description": "Library for interacting with the Knock API",
5
5
  "homepage": "https://github.com/knocklabs/knock-node",
6
6
  "author": "@knocklabs",
@@ -9,6 +9,9 @@ export interface PostAndPutOptions {
9
9
  query?: {
10
10
  [key: string]: any;
11
11
  };
12
+ headers?: {
13
+ [key: string]: any;
14
+ };
12
15
  }
13
16
  export interface UnprocessableEntityError {
14
17
  message: string;
@@ -28,11 +31,11 @@ declare type PageInfo = {
28
31
  after: string;
29
32
  page_size: number;
30
33
  };
31
- export interface PaginatedFeedResponse<T> {
34
+ export interface PaginatedEntriesResponse<T> {
32
35
  entries: T[];
33
36
  page_info: PageInfo;
34
37
  }
35
- export interface PaginatedResponse<T> {
38
+ export interface PaginatedItemsResponse<T> {
36
39
  items: T[];
37
40
  page_info: PageInfo;
38
41
  }
@@ -54,4 +57,7 @@ export interface SignUserTokenOptions {
54
57
  /** The expiration time of the token in seconds. Defaults to 1 hour. */
55
58
  expiresInSeconds?: number;
56
59
  }
60
+ export interface MethodOptions {
61
+ idempotencyKey?: string;
62
+ }
57
63
  export {};
@@ -1,5 +1,5 @@
1
1
  import { AxiosResponse } from "axios";
2
- import { KnockOptions, PostAndPutOptions, SignUserTokenOptions } from "./common/interfaces";
2
+ import { KnockOptions, PostAndPutOptions, SignUserTokenOptions, MethodOptions } from "./common/interfaces";
3
3
  import { Users } from "./resources/users";
4
4
  import { Preferences } from "./resources/preferences";
5
5
  import { Workflows } from "./resources/workflows";
@@ -21,7 +21,7 @@ declare class Knock {
21
21
  readonly messages: Messages;
22
22
  readonly tenants: Tenants;
23
23
  constructor(key?: string | undefined, options?: KnockOptions);
24
- notify(workflowKey: string, properties: TriggerWorkflowProperties): Promise<import("./resources/workflows/interfaces").WorkflowRun>;
24
+ notify(workflowKey: string, properties: TriggerWorkflowProperties, options?: MethodOptions): Promise<import("./resources/workflows/interfaces").WorkflowRun>;
25
25
  /**
26
26
  * Generate JWT for authenticating client-side requests (e.g. in-app feeds)
27
27
  * For more information, visit https://docs.knock.app/in-app-ui/security-and-authentication#authentication-with-enhanced-security-enabled
package/dist/src/knock.js CHANGED
@@ -53,9 +53,9 @@ class Knock {
53
53
  });
54
54
  }
55
55
  // Delegate the notify function to the workflows trigger
56
- notify(workflowKey, properties) {
56
+ notify(workflowKey, properties, options) {
57
57
  return __awaiter(this, void 0, void 0, function* () {
58
- return this.workflows.trigger(workflowKey, properties);
58
+ return this.workflows.trigger(workflowKey, properties, options);
59
59
  });
60
60
  }
61
61
  /**
@@ -86,6 +86,7 @@ class Knock {
86
86
  try {
87
87
  return yield this.client.post(path, entity, {
88
88
  params: options.query,
89
+ headers: options.headers,
89
90
  });
90
91
  }
91
92
  catch (error) {
@@ -1,15 +1,15 @@
1
- import { PaginatedResponse, PaginationOptions } from "../../common/interfaces";
1
+ import { PaginatedItemsResponse, PaginationOptions } from "../../common/interfaces";
2
2
  import { Message, MessageContent, MessageEvent, ListMessageActivitiesOptions, ListMessagesOptions, MessageEngagementStatus } from "./interfaces";
3
3
  import { Activity } from "../activities/interfaces";
4
4
  import { Knock } from "../../knock";
5
5
  export declare class Messages {
6
6
  readonly knock: Knock;
7
7
  constructor(knock: Knock);
8
- list(filteringOptions?: ListMessagesOptions): Promise<PaginatedResponse<Message>>;
8
+ list(filteringOptions?: ListMessagesOptions): Promise<PaginatedItemsResponse<Message>>;
9
9
  get(messageId: string): Promise<Message>;
10
10
  getContent(messageId: string): Promise<MessageContent>;
11
- getEvents(messageId: string, paginationOptions?: PaginationOptions): Promise<PaginatedResponse<MessageEvent>>;
12
- getActivities(messageId: string, filteringOptions?: ListMessageActivitiesOptions): Promise<PaginatedResponse<Activity>>;
11
+ getEvents(messageId: string, paginationOptions?: PaginationOptions): Promise<PaginatedItemsResponse<MessageEvent>>;
12
+ getActivities(messageId: string, filteringOptions?: ListMessageActivitiesOptions): Promise<PaginatedItemsResponse<Activity>>;
13
13
  setStatus(messageId: string, status: MessageEngagementStatus): Promise<Message>;
14
14
  deleteStatus(messageId: string, status: MessageEngagementStatus): Promise<Message>;
15
15
  batchSetStatus(messageIds: string[], status: MessageEngagementStatus | "unseen" | "unread" | "unarchived"): Promise<Message[]>;
@@ -1,4 +1,4 @@
1
- import { ChannelData, CommonMetadata, SetChannelDataProperties, PaginatedResponse, ChannelType } from "../../common/interfaces";
1
+ import { ChannelData, CommonMetadata, SetChannelDataProperties, PaginatedEntriesResponse, ChannelType, PaginatedItemsResponse } from "../../common/interfaces";
2
2
  import { Knock } from "../../knock";
3
3
  import { AddObjectSubscriptionProperties, BulkSetObjectOption, DeleteObjectSubscriptionProperties, ListObjectOptions, ListObjectSubscriptionsOptions, Object, ObjectSubscription, SetObjectProperties } from "./interfaces";
4
4
  import { BulkOperation } from "../bulk_operations/interfaces";
@@ -9,14 +9,14 @@ export declare class Objects {
9
9
  constructor(knock: Knock);
10
10
  get<T = CommonMetadata>(collection: string, id: string): Promise<Object<T>>;
11
11
  set<T = CommonMetadata>(collection: string, id: string, properties: SetObjectProperties): Promise<Object<T>>;
12
- list<T = CommonMetadata>(collection: string, filteringOptions?: ListObjectOptions): Promise<PaginatedResponse<Object<T>>>;
12
+ list<T = CommonMetadata>(collection: string, filteringOptions?: ListObjectOptions): Promise<PaginatedEntriesResponse<Object<T>>>;
13
13
  bulkSet(collection: string, objects: BulkSetObjectOption[]): Promise<BulkOperation>;
14
14
  delete(collection: string, id: string): Promise<null>;
15
15
  bulkDelete(collection: string, objectIds: string[]): Promise<BulkOperation>;
16
16
  getChannelData<T = CommonMetadata>(collection: string, id: string, channelId: string): Promise<ChannelData<T>>;
17
17
  setChannelData<T = CommonMetadata>(collection: string, id: string, channelId: string, channelData: SetChannelDataProperties): Promise<ChannelData<T>>;
18
18
  unsetChannelData(collection: string, id: string, channelId: string): Promise<any>;
19
- getMessages(collection: string, objectId: string, filteringOptions?: ListMessagesOptions): Promise<PaginatedResponse<Message>>;
19
+ getMessages(collection: string, objectId: string, filteringOptions?: ListMessagesOptions): Promise<PaginatedItemsResponse<Message>>;
20
20
  getAllPreferences(collection: string, objectId: string): Promise<PreferenceSet[]>;
21
21
  /**
22
22
  * @deprecated Use `objects.getPreferences` instead
@@ -30,7 +30,7 @@ export declare class Objects {
30
30
  setWorkflowPreferences(collection: string, objectId: string, workflowKey: string, setting: WorkflowPreferenceSetting, options?: PreferenceOptions): Promise<PreferenceSet>;
31
31
  setCategoriesPreferences(collection: string, objectId: string, categoryPreferences: WorkflowPreferences, options?: PreferenceOptions): Promise<PreferenceSet>;
32
32
  setCategoryPreferences(collection: string, objectId: string, categoryKey: string, setting: WorkflowPreferenceSetting, options?: PreferenceOptions): Promise<PreferenceSet>;
33
- listSubscriptions(collection: string, objectId: string, options?: ListObjectSubscriptionsOptions): Promise<PaginatedResponse<ObjectSubscription>>;
33
+ listSubscriptions(collection: string, objectId: string, options?: ListObjectSubscriptionsOptions): Promise<PaginatedEntriesResponse<ObjectSubscription>>;
34
34
  addSubscriptions(collection: string, objectId: string, properties?: AddObjectSubscriptionProperties): Promise<ObjectSubscription[]>;
35
35
  deleteSubscriptions(collection: string, objectId: string, properties?: DeleteObjectSubscriptionProperties): Promise<ObjectSubscription[]>;
36
36
  }
@@ -1,10 +1,10 @@
1
- import { CommonMetadata, PaginatedResponse } from "../../common/interfaces";
1
+ import { CommonMetadata, PaginatedEntriesResponse } from "../../common/interfaces";
2
2
  import { Knock } from "../../knock";
3
3
  import { Tenant, SetTenant, ListTenantsOptions } from "./interfaces";
4
4
  export declare class Tenants {
5
5
  readonly knock: Knock;
6
6
  constructor(knock: Knock);
7
- list(filteringOptions?: ListTenantsOptions): Promise<PaginatedResponse<Tenant>>;
7
+ list(filteringOptions?: ListTenantsOptions): Promise<PaginatedEntriesResponse<Tenant>>;
8
8
  get<T = CommonMetadata>(id: string): Promise<Tenant<T>>;
9
9
  set<T = CommonMetadata>(id: string, tenantData: SetTenant): Promise<Tenant<T>>;
10
10
  delete(id: string): Promise<null>;
@@ -1,4 +1,4 @@
1
- import { ChannelData, ChannelType, CommonMetadata, PaginatedFeedResponse, PaginatedResponse } from "../../common/interfaces";
1
+ import { ChannelData, ChannelType, CommonMetadata, PaginatedItemsResponse, PaginatedEntriesResponse } from "../../common/interfaces";
2
2
  import { BulkOperation } from "../bulk_operations/interfaces";
3
3
  import { ChannelTypePreferences, PreferenceOptions, PreferenceSet, SetPreferencesProperties, WorkflowPreferences, WorkflowPreferenceSetting } from "../preferences/interfaces";
4
4
  import { ListMessagesOptions, Message } from "../messages/interfaces";
@@ -10,11 +10,11 @@ export declare class Users {
10
10
  identify(userId: string, properties?: IdentifyProperties): Promise<User>;
11
11
  bulkIdentify(users: BulkIdentifyUser[]): Promise<BulkOperation>;
12
12
  get(userId: string): Promise<User>;
13
- list(filteringOptions?: ListUserOptions): Promise<PaginatedResponse<User>>;
13
+ list(filteringOptions?: ListUserOptions): Promise<PaginatedEntriesResponse<User>>;
14
14
  delete(userId: string): Promise<null>;
15
15
  bulkDelete(userIds: string[]): Promise<BulkOperation>;
16
16
  merge(toUserId: string, fromUserId: string): Promise<User>;
17
- getFeed(userId: string, channelId: string, feedOptions?: UserFeedOptions): Promise<PaginatedFeedResponse<any>>;
17
+ getFeed(userId: string, channelId: string, feedOptions?: UserFeedOptions): Promise<PaginatedEntriesResponse<any>>;
18
18
  getAllPreferences(userId: string): Promise<any>;
19
19
  /**
20
20
  * @deprecated Use `users.getPreferences` instead
@@ -32,5 +32,5 @@ export declare class Users {
32
32
  getChannelData<T = CommonMetadata>(userId: string, channelId: string): Promise<ChannelData<T>>;
33
33
  setChannelData<T = CommonMetadata>(userId: string, channelId: string, channelData: Record<string, any>): Promise<ChannelData<T>>;
34
34
  unsetChannelData(userId: string, channelId: string): Promise<any>;
35
- getMessages(userId: string, filteringOptions?: ListMessagesOptions): Promise<PaginatedResponse<Message>>;
35
+ getMessages(userId: string, filteringOptions?: ListMessagesOptions): Promise<PaginatedItemsResponse<Message>>;
36
36
  }
@@ -1,8 +1,9 @@
1
1
  import { Knock } from "../../knock";
2
+ import { MethodOptions } from "../../common/interfaces";
2
3
  import { CancelWorkflowProperties, TriggerWorkflowProperties, WorkflowRun } from "./interfaces";
3
4
  export declare class Workflows {
4
5
  readonly knock: Knock;
5
6
  constructor(knock: Knock);
6
- trigger(workflowKey: string, { actor, recipients, cancellationKey, tenant, data: notifyData, }: TriggerWorkflowProperties): Promise<WorkflowRun>;
7
+ trigger(workflowKey: string, { actor, recipients, cancellationKey, tenant, data: notifyData, }: TriggerWorkflowProperties, { idempotencyKey }?: MethodOptions): Promise<WorkflowRun>;
7
8
  cancel(workflowKey: string, cancellationKey: string, { recipients }?: CancelWorkflowProperties): Promise<any>;
8
9
  }
@@ -14,18 +14,19 @@ class Workflows {
14
14
  constructor(knock) {
15
15
  this.knock = knock;
16
16
  }
17
- trigger(workflowKey, { actor, recipients, cancellationKey, tenant, data: notifyData, }) {
17
+ trigger(workflowKey, { actor, recipients, cancellationKey, tenant, data: notifyData, }, { idempotencyKey } = {}) {
18
18
  return __awaiter(this, void 0, void 0, function* () {
19
19
  if (!workflowKey && !recipients) {
20
20
  throw new Error(`Incomplete arguments. At a minimum you need to specify 'workflowKey' and 'recipients'.`);
21
21
  }
22
+ const options = idempotencyKey ? { headers: { 'Idempotency-Key': idempotencyKey } } : {};
22
23
  const { data } = yield this.knock.post(`/v1/workflows/${workflowKey}/trigger`, {
23
24
  actor,
24
25
  recipients,
25
26
  cancellation_key: cancellationKey,
26
27
  tenant,
27
28
  data: notifyData,
28
- });
29
+ }, options);
29
30
  return data;
30
31
  });
31
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knocklabs/node",
3
- "version": "0.4.16",
3
+ "version": "0.4.18",
4
4
  "description": "Library for interacting with the Knock API",
5
5
  "homepage": "https://github.com/knocklabs/knock-node",
6
6
  "author": "@knocklabs",