@workos-inc/node 1.6.0 → 2.2.0

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.
@@ -127,7 +127,7 @@ describe('AuditTrail', () => {
127
127
  },
128
128
  },
129
129
  ],
130
- listMetadata: { before: null, after: null },
130
+ list_metadata: { before: null, after: null },
131
131
  });
132
132
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
133
133
  const events = yield workos.auditTrail.listEvents();
@@ -159,7 +159,7 @@ describe('AuditTrail', () => {
159
159
  },
160
160
  },
161
161
  ],
162
- listMetadata: { before: null, after: null },
162
+ list_metadata: { before: null, after: null },
163
163
  });
164
164
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
165
165
  const events = yield workos.auditTrail.listEvents({
@@ -1,6 +1,7 @@
1
1
  export interface List<T> {
2
+ readonly object: 'list';
2
3
  data: T[];
3
- listMetadata: {
4
+ list_metadata: {
4
5
  before?: string;
5
6
  after?: string;
6
7
  };
@@ -10,6 +10,7 @@ export declare class DirectorySync {
10
10
  private readonly workos;
11
11
  constructor(workos: WorkOS);
12
12
  listDirectories(options?: ListDirectoriesOptions): Promise<List<Directory>>;
13
+ getDirectory(id: string): Promise<Directory>;
13
14
  deleteDirectory(id: string): Promise<void>;
14
15
  listGroups(options: ListGroupsOptions): Promise<List<Group>>;
15
16
  listUsers<TCustomAttributes extends object = DefaultCustomAttributes>(options: ListUsersOptions): Promise<List<UserWithGroups<TCustomAttributes>>>;
@@ -22,6 +22,12 @@ class DirectorySync {
22
22
  return data;
23
23
  });
24
24
  }
25
+ getDirectory(id) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const { data } = yield this.workos.get(`/directories/${id}`);
28
+ return data;
29
+ });
30
+ }
25
31
  deleteDirectory(id) {
26
32
  return __awaiter(this, void 0, void 0, function* () {
27
33
  yield this.workos.delete(`/directories/${id}`);
@@ -33,6 +33,14 @@ describe('DirectorySync', () => {
33
33
  }));
34
34
  });
35
35
  });
36
+ describe('getDirectory', () => {
37
+ it(`requests a Directory`, () => __awaiter(void 0, void 0, void 0, function* () {
38
+ mock.onGet().reply(200, {});
39
+ const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
40
+ yield workos.directorySync.getDirectory('directory_123');
41
+ expect(mock.history.get[0].url).toEqual('/directories/directory_123');
42
+ }));
43
+ });
36
44
  describe('deleteDirectory', () => {
37
45
  it('sends a request to delete the directory', () => __awaiter(void 0, void 0, void 0, function* () {
38
46
  mock.onDelete().reply(202, {});
@@ -5,7 +5,7 @@ export interface Directory {
5
5
  external_key: string;
6
6
  name: string;
7
7
  environment_id: string;
8
- organization_id: string;
8
+ organization_id?: string;
9
9
  state: 'unlinked' | 'linked' | 'invalid_credentials';
10
10
  type: string;
11
11
  created_at: string;
@@ -1,5 +1,6 @@
1
1
  export interface Group {
2
2
  id: string;
3
+ directory_id: string;
3
4
  name: string;
4
5
  raw_attributes: any;
5
6
  }
@@ -2,6 +2,7 @@ import { Group } from './group.interface';
2
2
  export declare type DefaultCustomAttributes = Record<string, unknown>;
3
3
  export interface User<TCustomAttributes extends object = DefaultCustomAttributes> {
4
4
  id: string;
5
+ directory_id: string;
5
6
  raw_attributes: any;
6
7
  custom_attributes: TCustomAttributes;
7
8
  idp_id: string;
@@ -13,7 +14,7 @@ export interface User<TCustomAttributes extends object = DefaultCustomAttributes
13
14
  }[];
14
15
  username: string;
15
16
  last_name: string;
16
- state: 'active' | 'suspended';
17
+ state: 'active' | 'inactive' | 'suspended';
17
18
  }
18
19
  export interface UserWithGroups<TCustomAttributes extends object = DefaultCustomAttributes> extends User<TCustomAttributes> {
19
20
  groups: Group[];
@@ -93,5 +93,5 @@
93
93
  ]
94
94
  }
95
95
  ],
96
- "listMetadata": { "before": "before-id", "after": null }
96
+ "list_metadata": { "before": "before-id", "after": null }
97
97
  }
@@ -28,7 +28,7 @@ describe('Organizations', () => {
28
28
  describe('without any options', () => {
29
29
  it('returns organizations and metadata', () => __awaiter(void 0, void 0, void 0, function* () {
30
30
  mock.onGet().reply(200, list_organizations_json_1.default);
31
- const { data, listMetadata } = yield workos.organizations.listOrganizations();
31
+ const { data, list_metadata: listMetadata } = yield workos.organizations.listOrganizations();
32
32
  expect(mock.history.get[0].params).toBeUndefined();
33
33
  expect(mock.history.get[0].url).toEqual('/organizations');
34
34
  expect(data).toHaveLength(7);
@@ -7,7 +7,7 @@ export interface ConnectionDomain {
7
7
  export interface Connection {
8
8
  object: 'connection';
9
9
  id: string;
10
- organization_id: string;
10
+ organization_id?: string;
11
11
  name: string;
12
12
  connection_type: ConnectionType;
13
13
  state: 'draft' | 'active' | 'inactive';
@@ -2,7 +2,7 @@ import { ConnectionType } from './connection-type.enum';
2
2
  export interface Profile {
3
3
  id: string;
4
4
  idp_id: string;
5
- organization_id: string;
5
+ organization_id?: string;
6
6
  connection_id: string;
7
7
  connection_type: ConnectionType;
8
8
  email: string;
@@ -1 +1,2 @@
1
1
  export * from './webhook.interface';
2
+ export * from './webhook-directory.interface';
@@ -11,3 +11,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./webhook.interface"), exports);
14
+ __exportStar(require("./webhook-directory.interface"), exports);
@@ -0,0 +1,4 @@
1
+ import { Directory } from '../../directory-sync/interfaces';
2
+ export interface WebhookDirectory extends Omit<Directory, 'state'> {
3
+ state: 'active' | 'validating' | 'invalid_credentials' | 'inactive' | 'deleting';
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,72 @@
1
- export interface Webhook {
1
+ import { Group, User } from '../../directory-sync/interfaces';
2
+ import { Connection } from '../../sso/interfaces';
3
+ import { WebhookDirectory as Directory } from './webhook-directory.interface';
4
+ interface WebhookBase {
2
5
  id: string;
3
- event: string;
4
- data: Record<string, any>;
5
6
  }
7
+ export interface ConnectionActivatedWebhook extends WebhookBase {
8
+ event: 'connection.activated';
9
+ data: Connection;
10
+ }
11
+ export interface ConnectionDeactivatedWebhook extends WebhookBase {
12
+ event: 'connection.deactivated';
13
+ data: Connection;
14
+ }
15
+ export interface ConnectionDeletedWebhook extends WebhookBase {
16
+ event: 'connection.deleted';
17
+ data: Connection;
18
+ }
19
+ export interface DsyncActivatedWebhook extends WebhookBase {
20
+ event: 'dsync.activated';
21
+ data: Directory;
22
+ }
23
+ export interface DsyncDeactivatedWebhook extends WebhookBase {
24
+ event: 'dsync.deactivated';
25
+ data: Directory;
26
+ }
27
+ export interface DsyncDeletedWebhook extends WebhookBase {
28
+ event: 'dsync.deleted';
29
+ data: Directory;
30
+ }
31
+ export interface DsyncGroupCreatedWebhook extends WebhookBase {
32
+ event: 'dsync.group.created';
33
+ data: Group;
34
+ }
35
+ export interface DsyncGroupDeletedWebhook extends WebhookBase {
36
+ event: 'dsync.group.deleted';
37
+ data: Group;
38
+ }
39
+ export interface DsyncGroupUpdatedWebhook extends WebhookBase {
40
+ event: 'dsync.group.updated';
41
+ data: Group;
42
+ }
43
+ export interface DsyncGroupUserAddedWebhook extends WebhookBase {
44
+ event: 'dsync.group.user_added';
45
+ data: {
46
+ directory_id: string;
47
+ user: User;
48
+ group: Group;
49
+ };
50
+ }
51
+ export interface DsyncGroupUserRemovedWebhook extends WebhookBase {
52
+ event: 'dsync.group.user_removed';
53
+ data: {
54
+ directory_id: string;
55
+ user: User;
56
+ group: Group;
57
+ };
58
+ }
59
+ export interface DsyncUserCreatedWebhook extends WebhookBase {
60
+ event: 'dsync.user.created';
61
+ data: User;
62
+ }
63
+ export interface DsyncUserDeletedWebhook extends WebhookBase {
64
+ event: 'dsync.user.deleted';
65
+ data: User;
66
+ }
67
+ export interface DsyncUserUpdatedWebhook extends WebhookBase {
68
+ event: 'dsync.user.updated';
69
+ data: User;
70
+ }
71
+ export declare type Webhook = ConnectionActivatedWebhook | ConnectionDeactivatedWebhook | ConnectionDeletedWebhook | DsyncActivatedWebhook | DsyncDeactivatedWebhook | DsyncDeletedWebhook | DsyncGroupCreatedWebhook | DsyncGroupUpdatedWebhook | DsyncGroupDeletedWebhook | DsyncGroupUserAddedWebhook | DsyncGroupUserRemovedWebhook | DsyncUserCreatedWebhook | DsyncUserUpdatedWebhook | DsyncUserDeletedWebhook;
72
+ export {};
@@ -38,6 +38,7 @@ class Webhooks {
38
38
  return [timestamp, signatureHash];
39
39
  }
40
40
  computeSignature(timestamp, payload, secret) {
41
+ payload = JSON.stringify(payload);
41
42
  const signedPayload = `${timestamp}.${payload}`;
42
43
  const expectedSignature = crypto_1.default
43
44
  .createHmac('sha256', secret)
@@ -19,7 +19,7 @@ describe('Webhooks', () => {
19
19
  payload = webhook_json_1.default;
20
20
  secret = 'secret';
21
21
  timestamp = Date.now() * 1000;
22
- unhashedString = `${timestamp}.${payload}`;
22
+ unhashedString = `${timestamp}.${JSON.stringify(payload)}`;
23
23
  signatureHash = crypto_1.default
24
24
  .createHmac('sha256', secret)
25
25
  .update(unhashedString)
package/lib/workos.js CHANGED
@@ -22,7 +22,7 @@ const passwordless_1 = require("./passwordless/passwordless");
22
22
  const portal_1 = require("./portal/portal");
23
23
  const sso_1 = require("./sso/sso");
24
24
  const webhooks_1 = require("./webhooks/webhooks");
25
- const VERSION = '1.6.0';
25
+ const VERSION = '2.2.0';
26
26
  const DEFAULT_HOSTNAME = 'api.workos.com';
27
27
  class WorkOS {
28
28
  constructor(key, options = {}) {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.6.0",
2
+ "version": "2.2.0",
3
3
  "name": "@workos-inc/node",
4
4
  "author": "WorkOS",
5
5
  "description": "A Node wrapper for the WorkOS API",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/jest": "27.0.2",
43
- "@types/node": "14.17.32",
43
+ "@types/node": "14.17.33",
44
44
  "@types/pluralize": "0.0.29",
45
45
  "axios-mock-adapter": "1.20.0",
46
46
  "jest": "27.3.1",