@knocklabs/node 0.6.0 → 0.6.2

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
@@ -154,7 +154,7 @@ const token = await Knock.signUserToken("jhammond", {
154
154
  signingKey: "S25vY2sga25vY2sh...",
155
155
  // Optional: How long the token should be valid for, in seconds (default 1 hour)
156
156
  // For long-lived connections, you will need to refresh the token before it expires.
157
- expiresIn: 60 * 60,
157
+ expiresInSeconds: 60 * 60,
158
158
  });
159
159
 
160
160
  // This token can now be safely passed to your client e.g. in a cookie or API response.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knocklabs/node",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Library for interacting with the Knock API",
5
5
  "homepage": "https://github.com/knocklabs/knock-node",
6
6
  "author": "@knocklabs",
@@ -24,22 +24,20 @@
24
24
  "scripts": {
25
25
  "build": "tsc -p tsconfig.json",
26
26
  "lint": "tslint -p tsconfig.json -c tslint.json",
27
- "test": "jest",
28
- "test:watch": "jest --watch",
29
- "prettier": "prettier \"src/**/*.{js,ts,tsx}\" --check",
30
27
  "format": "prettier \"src/**/*.{js,ts,tsx}\" --write",
28
+ "format:check": "prettier \"src/**/*.{js,ts,tsx}\" --check",
29
+ "test": "vitest",
30
+ "coverage": "vitest run --coverage",
31
31
  "prepublishOnly": "npm run build"
32
32
  },
33
33
  "devDependencies": {
34
- "@types/jest": "26.0.23",
35
34
  "@types/node": "^15.0.1",
36
35
  "@types/pluralize": "0.0.29",
37
- "jest": "26.6.3",
36
+ "msw": "^2.1.5",
38
37
  "prettier": "2.2.1",
39
- "supertest": "6.1.3",
40
- "ts-jest": "26.5.5",
41
38
  "tslint": "6.1.3",
42
- "typescript": "^5.3.3"
39
+ "typescript": "^5.3.3",
40
+ "vitest": "^1.2.1"
43
41
  },
44
42
  "dependencies": {
45
43
  "jose": "^5.2.0"
@@ -70,7 +70,18 @@ class FetchClient {
70
70
  buildUrl(path, params) {
71
71
  const url = new URL(this.config.baseURL + path);
72
72
  if (params) {
73
- Object.entries(params).forEach(([key, value]) => url.searchParams.append(key, value));
73
+ Object.entries(params).forEach(([key, value]) => {
74
+ // Send array values as individual values instead of a comma separated list
75
+ // e.g. key[]=1&key[]=2&key[]=3 instead of key=1,2,3
76
+ if (Array.isArray(value)) {
77
+ for (const val of value) {
78
+ url.searchParams.append(`${key}[]`, val);
79
+ }
80
+ }
81
+ else {
82
+ url.searchParams.append(key, value);
83
+ }
84
+ });
74
85
  }
75
86
  return url;
76
87
  }
package/dist/src/knock.js CHANGED
@@ -47,6 +47,8 @@ class Knock {
47
47
  headers: {
48
48
  Authorization: `Bearer ${this.key}`,
49
49
  "User-Agent": `knocklabs/node@${package_json_1.version}`,
50
+ "Content-Type": "application/json",
51
+ Accept: "application/json",
50
52
  },
51
53
  });
52
54
  }
@@ -88,7 +90,7 @@ class Knock {
88
90
  try {
89
91
  return yield this.client.post(path, {
90
92
  params: options.query,
91
- headers: Object.assign({ "Content-Type": "application/json", Accept: "application/json" }, options.headers),
93
+ headers: Object.assign({}, options.headers),
92
94
  body: entity,
93
95
  });
94
96
  }
@@ -103,6 +105,7 @@ class Knock {
103
105
  try {
104
106
  return yield this.client.put(path, {
105
107
  params: options.query,
108
+ headers: Object.assign({}, options.headers),
106
109
  body: entity,
107
110
  });
108
111
  }
@@ -152,7 +155,12 @@ class Knock {
152
155
  throw new exceptions_1.BadRequestException(code, message, requestID);
153
156
  }
154
157
  case 422: {
155
- const { errors } = data;
158
+ // Format errors as an array before passing to exception constructor
159
+ const errors = !data.errors
160
+ ? []
161
+ : Array.isArray(data.errors)
162
+ ? data.errors
163
+ : [data.errors];
156
164
  throw new exceptions_1.UnprocessableEntityException(errors, requestID);
157
165
  }
158
166
  case 404: {
@@ -1,11 +1,11 @@
1
1
  import { CommonMetadata, PaginatedEntriesResponse } from "../../common/interfaces";
2
2
  import { Knock } from "../../knock";
3
- import { Tenant, SetTenant, ListTenantsOptions } from "./interfaces";
3
+ import { Tenant, ListTenantsOptions, SetTenantProperties } from "./interfaces";
4
4
  export declare class Tenants {
5
5
  readonly knock: Knock;
6
6
  constructor(knock: Knock);
7
7
  list(filteringOptions?: ListTenantsOptions): Promise<PaginatedEntriesResponse<Tenant>>;
8
8
  get<T = CommonMetadata>(id: string): Promise<Tenant<T>>;
9
- set<T = CommonMetadata>(id: string, tenantData: SetTenant): Promise<Tenant<T>>;
9
+ set<T = CommonMetadata>(id: string, tenantData: SetTenantProperties): Promise<Tenant<T>>;
10
10
  delete(id: string): Promise<null>;
11
11
  }
@@ -1,4 +1,4 @@
1
- import { CommonMetadata, PaginationOptions } from "../../common/interfaces";
1
+ import { CommonMetadata, PaginationOptions, SetChannelDataProperties } from "../../common/interfaces";
2
2
  import { SetPreferencesProperties } from "../preferences/interfaces";
3
3
  export interface TenantRef {
4
4
  id: string;
@@ -20,9 +20,11 @@ export interface Tenant<T = CommonMetadata> {
20
20
  created_at?: string;
21
21
  updated_at: string;
22
22
  }
23
- export interface SetTenant {
23
+ export interface SetTenantProperties {
24
24
  name?: string;
25
+ channelData?: SetChannelDataProperties;
25
26
  settings?: TenantSettings;
27
+ [key: string]: any;
26
28
  }
27
29
  export interface ListTenantsOptions extends PaginationOptions {
28
30
  tenant_id?: string;
@@ -1,13 +1,14 @@
1
1
  import { ObjectRef, SetObjectProperties } from "../objects/interfaces";
2
2
  import { IdentifyProperties } from "../users/interfaces";
3
3
  import { PaginationOptions } from "../../common/interfaces";
4
+ import { SetTenantProperties, TenantRef } from "../tenants/interfaces";
4
5
  export interface TriggerWorkflowProperties<T = {
5
6
  [key: string]: any;
6
7
  }> {
7
8
  actor?: Actor | ActorWithUpsert;
8
9
  recipients?: (Recipient | RecipientWithUpsert)[];
9
10
  cancellationKey?: string;
10
- tenant?: string;
11
+ tenant?: Tenant | TenantWithUpsert;
11
12
  data?: T;
12
13
  }
13
14
  export interface CancelWorkflowProperties {
@@ -44,7 +45,7 @@ export interface CreateSchedulesProps {
44
45
  actor?: Recipient | RecipientWithUpsert | null;
45
46
  scheduled_at?: string;
46
47
  repeats?: ScheduleRepeatProperties[];
47
- tenant?: string;
48
+ tenant?: Tenant | TenantWithUpsert | null;
48
49
  data?: {
49
50
  [key: string]: any;
50
51
  };
@@ -77,9 +78,11 @@ export interface Schedule {
77
78
  }
78
79
  export type Recipient = string | ObjectRef;
79
80
  export type Actor = Recipient;
81
+ export type Tenant = string | TenantRef;
80
82
  export interface UserWithUpsert extends IdentifyProperties {
81
83
  id: string;
82
84
  }
83
85
  export type ObjectWithUpsert = ObjectRef & SetObjectProperties;
86
+ export type TenantWithUpsert = TenantRef & SetTenantProperties;
84
87
  export type RecipientWithUpsert = UserWithUpsert | ObjectWithUpsert;
85
88
  export type ActorWithUpsert = RecipientWithUpsert;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knocklabs/node",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Library for interacting with the Knock API",
5
5
  "homepage": "https://github.com/knocklabs/knock-node",
6
6
  "author": "@knocklabs",
@@ -24,22 +24,20 @@
24
24
  "scripts": {
25
25
  "build": "tsc -p tsconfig.json",
26
26
  "lint": "tslint -p tsconfig.json -c tslint.json",
27
- "test": "jest",
28
- "test:watch": "jest --watch",
29
- "prettier": "prettier \"src/**/*.{js,ts,tsx}\" --check",
30
27
  "format": "prettier \"src/**/*.{js,ts,tsx}\" --write",
28
+ "format:check": "prettier \"src/**/*.{js,ts,tsx}\" --check",
29
+ "test": "vitest",
30
+ "coverage": "vitest run --coverage",
31
31
  "prepublishOnly": "npm run build"
32
32
  },
33
33
  "devDependencies": {
34
- "@types/jest": "26.0.23",
35
34
  "@types/node": "^15.0.1",
36
35
  "@types/pluralize": "0.0.29",
37
- "jest": "26.6.3",
36
+ "msw": "^2.1.5",
38
37
  "prettier": "2.2.1",
39
- "supertest": "6.1.3",
40
- "ts-jest": "26.5.5",
41
38
  "tslint": "6.1.3",
42
- "typescript": "^5.3.3"
39
+ "typescript": "^5.3.3",
40
+ "vitest": "^1.2.1"
43
41
  },
44
42
  "dependencies": {
45
43
  "jose": "^5.2.0"