@knocklabs/node 0.4.17 → 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.17",
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;
@@ -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,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.17",
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",