@workos-inc/node 7.3.0 → 7.5.0-beta.node-compatibility

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.
Files changed (68) hide show
  1. package/README.md +4 -0
  2. package/lib/common/crypto/CryptoProvider.d.ts +32 -0
  3. package/lib/common/crypto/CryptoProvider.js +13 -0
  4. package/lib/common/crypto/NodeCryptoProvider.d.ts +12 -0
  5. package/lib/common/crypto/NodeCryptoProvider.js +73 -0
  6. package/lib/common/crypto/SubtleCryptoProvider.d.ts +15 -0
  7. package/lib/common/crypto/SubtleCryptoProvider.js +75 -0
  8. package/lib/common/crypto/index.d.ts +3 -0
  9. package/lib/common/crypto/index.js +19 -0
  10. package/lib/common/exceptions/bad-request.exception.d.ts +4 -3
  11. package/lib/common/exceptions/generic-server.exception.d.ts +2 -1
  12. package/lib/common/exceptions/index.d.ts +1 -0
  13. package/lib/common/exceptions/index.js +1 -0
  14. package/lib/common/exceptions/no-api-key-provided.exception.d.ts +2 -2
  15. package/lib/common/exceptions/not-found.exception.d.ts +4 -3
  16. package/lib/common/exceptions/oauth.exception.d.ts +3 -2
  17. package/lib/common/exceptions/rate-limit-exceeded.exception.d.ts +13 -0
  18. package/lib/common/exceptions/rate-limit-exceeded.exception.js +20 -0
  19. package/lib/common/exceptions/signature-verification.exception.d.ts +1 -1
  20. package/lib/common/exceptions/unauthorized.exception.d.ts +4 -3
  21. package/lib/common/exceptions/unprocessable-entity.exception.d.ts +4 -3
  22. package/lib/common/interfaces/event.interface.d.ts +1 -1
  23. package/lib/common/interfaces/http-client.interface.d.ts +20 -0
  24. package/lib/common/interfaces/index.d.ts +1 -0
  25. package/lib/common/interfaces/index.js +1 -0
  26. package/lib/common/interfaces/request-exception.interface.d.ts +5 -0
  27. package/lib/common/interfaces/request-exception.interface.js +2 -0
  28. package/lib/common/interfaces/workos-options.interface.d.ts +1 -0
  29. package/lib/common/net/fetch-client.d.ts +22 -0
  30. package/lib/common/net/fetch-client.js +112 -0
  31. package/lib/common/net/http-client.d.ts +39 -0
  32. package/lib/common/net/http-client.js +76 -0
  33. package/lib/common/net/index.d.ts +5 -0
  34. package/lib/common/net/index.js +31 -0
  35. package/lib/common/net/node-client.d.ts +23 -0
  36. package/lib/common/net/node-client.js +155 -0
  37. package/lib/directory-sync/directory-sync.spec.js +61 -0
  38. package/lib/directory-sync/interfaces/directory-user.interface.d.ts +3 -0
  39. package/lib/directory-sync/serializers/directory-user.serializer.js +2 -0
  40. package/lib/events/events.spec.js +88 -0
  41. package/lib/roles/interfaces/index.d.ts +1 -0
  42. package/lib/roles/interfaces/index.js +17 -0
  43. package/lib/roles/interfaces/role.interface.js +2 -0
  44. package/lib/user-management/fixtures/deactivate-organization-membership.json +12 -0
  45. package/lib/user-management/fixtures/invitation.json +1 -0
  46. package/lib/user-management/fixtures/list-invitations.json +1 -0
  47. package/lib/user-management/interfaces/index.d.ts +0 -2
  48. package/lib/user-management/interfaces/index.js +0 -2
  49. package/lib/user-management/interfaces/invitation.interface.d.ts +4 -0
  50. package/lib/user-management/interfaces/list-organization-memberships-options.interface.d.ts +3 -0
  51. package/lib/user-management/interfaces/organization-membership.interface.d.ts +4 -3
  52. package/lib/user-management/serializers/invitation.serializer.js +2 -0
  53. package/lib/user-management/serializers/list-organization-memberships-options.serializer.js +12 -8
  54. package/lib/user-management/serializers/role.serializer.d.ts +1 -1
  55. package/lib/user-management/user-management.d.ts +2 -0
  56. package/lib/user-management/user-management.js +12 -0
  57. package/lib/user-management/user-management.spec.js +40 -5
  58. package/lib/webhooks/webhooks.d.ts +2 -2
  59. package/lib/webhooks/webhooks.js +11 -37
  60. package/lib/webhooks/webhooks.spec.js +29 -0
  61. package/lib/workos.d.ts +1 -1
  62. package/lib/workos.js +22 -12
  63. package/lib/workos.spec.js +69 -3
  64. package/package.json +2 -3
  65. package/lib/common/utils/fetch-client.d.ts +0 -31
  66. package/lib/common/utils/fetch-client.js +0 -108
  67. /package/lib/{user-management/interfaces/role.interface.js → common/interfaces/http-client.interface.js} +0 -0
  68. /package/lib/{user-management → roles}/interfaces/role.interface.d.ts +0 -0
@@ -0,0 +1,39 @@
1
+ import { HttpClientInterface, HttpClientResponseInterface, RequestHeaders, RequestOptions, ResponseHeaders } from '../interfaces/http-client.interface';
2
+ export declare abstract class HttpClient implements HttpClientInterface {
3
+ readonly baseURL: string;
4
+ readonly options?: RequestInit | undefined;
5
+ constructor(baseURL: string, options?: RequestInit | undefined);
6
+ /** The HTTP client name used for diagnotics */
7
+ getClientName(): string;
8
+ abstract get(path: string, options: RequestOptions): Promise<HttpClientResponseInterface>;
9
+ abstract post<Entity = any>(path: string, entity: Entity, options: RequestOptions): Promise<HttpClientResponseInterface>;
10
+ abstract put<Entity = any>(path: string, entity: Entity, options: RequestOptions): Promise<HttpClientResponseInterface>;
11
+ abstract delete(path: string, options: RequestOptions): Promise<HttpClientResponseInterface>;
12
+ addClientToUserAgent(userAgent: string): string;
13
+ static getResourceURL(baseURL: string, path: string, params?: Record<string, any>): string;
14
+ static getQueryString(queryObj?: Record<string, any>): string | undefined;
15
+ static getContentTypeHeader(entity: any): RequestHeaders | undefined;
16
+ static getBody(entity: any): BodyInit | null | undefined;
17
+ }
18
+ export declare abstract class HttpClientResponse implements HttpClientResponseInterface {
19
+ _statusCode: number;
20
+ _headers: ResponseHeaders;
21
+ constructor(statusCode: number, headers: ResponseHeaders);
22
+ getStatusCode(): number;
23
+ getHeaders(): ResponseHeaders;
24
+ abstract getRawResponse(): unknown;
25
+ abstract toJSON(): any | null;
26
+ }
27
+ export declare class HttpClientError<T> extends Error {
28
+ readonly name: string;
29
+ readonly message: string;
30
+ readonly response: {
31
+ status: number;
32
+ headers: any;
33
+ data: T;
34
+ };
35
+ constructor({ message, response, }: {
36
+ message: string;
37
+ readonly response: HttpClientError<T>['response'];
38
+ });
39
+ }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpClientError = exports.HttpClientResponse = exports.HttpClient = void 0;
4
+ class HttpClient {
5
+ constructor(baseURL, options) {
6
+ this.baseURL = baseURL;
7
+ this.options = options;
8
+ }
9
+ /** The HTTP client name used for diagnotics */
10
+ getClientName() {
11
+ throw new Error('getClientName not implemented');
12
+ }
13
+ addClientToUserAgent(userAgent) {
14
+ if (userAgent.indexOf(' ') > -1) {
15
+ return userAgent.replace(/\b\s/, `/${this.getClientName()} `);
16
+ }
17
+ else {
18
+ return (userAgent += `/${this.getClientName()}`);
19
+ }
20
+ }
21
+ static getResourceURL(baseURL, path, params) {
22
+ const queryString = HttpClient.getQueryString(params);
23
+ const url = new URL([path, queryString].filter(Boolean).join('?'), baseURL);
24
+ return url.toString();
25
+ }
26
+ static getQueryString(queryObj) {
27
+ if (!queryObj)
28
+ return undefined;
29
+ const sanitizedQueryObj = {};
30
+ Object.entries(queryObj).forEach(([param, value]) => {
31
+ if (value !== '' && value !== undefined)
32
+ sanitizedQueryObj[param] = value;
33
+ });
34
+ return new URLSearchParams(sanitizedQueryObj).toString();
35
+ }
36
+ static getContentTypeHeader(entity) {
37
+ if (entity instanceof URLSearchParams) {
38
+ return {
39
+ 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
40
+ };
41
+ }
42
+ return undefined;
43
+ }
44
+ static getBody(entity) {
45
+ if (entity === null || entity instanceof URLSearchParams) {
46
+ return entity;
47
+ }
48
+ return JSON.stringify(entity);
49
+ }
50
+ }
51
+ exports.HttpClient = HttpClient;
52
+ // tslint:disable-next-line
53
+ class HttpClientResponse {
54
+ constructor(statusCode, headers) {
55
+ this._statusCode = statusCode;
56
+ this._headers = headers;
57
+ }
58
+ getStatusCode() {
59
+ return this._statusCode;
60
+ }
61
+ getHeaders() {
62
+ return this._headers;
63
+ }
64
+ }
65
+ exports.HttpClientResponse = HttpClientResponse;
66
+ // tslint:disable-next-line
67
+ class HttpClientError extends Error {
68
+ constructor({ message, response, }) {
69
+ super(message);
70
+ this.name = 'HttpClientError';
71
+ this.message = 'The request could not be completed.';
72
+ this.message = message;
73
+ this.response = response;
74
+ }
75
+ }
76
+ exports.HttpClientError = HttpClientError;
@@ -0,0 +1,5 @@
1
+ import { HttpClient } from './http-client';
2
+ export declare function createHttpClient(baseURL: string, options: RequestInit, fetchFn?: typeof fetch): HttpClient;
3
+ export * from './fetch-client';
4
+ export * from './node-client';
5
+ export * from './http-client';
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.createHttpClient = void 0;
18
+ const fetch_client_1 = require("./fetch-client");
19
+ const node_client_1 = require("./node-client");
20
+ function createHttpClient(baseURL, options, fetchFn) {
21
+ if (typeof fetch !== 'undefined' || typeof fetchFn !== 'undefined') {
22
+ return new fetch_client_1.FetchHttpClient(baseURL, options, fetchFn);
23
+ }
24
+ else {
25
+ return new node_client_1.NodeHttpClient(baseURL, options);
26
+ }
27
+ }
28
+ exports.createHttpClient = createHttpClient;
29
+ __exportStar(require("./fetch-client"), exports);
30
+ __exportStar(require("./node-client"), exports);
31
+ __exportStar(require("./http-client"), exports);
@@ -0,0 +1,23 @@
1
+ /// <reference types="node" />
2
+ import { HttpClient, HttpClientResponse } from './http-client';
3
+ import { HttpClientInterface, HttpClientResponseInterface, RequestOptions } from '../interfaces/http-client.interface';
4
+ import * as http_ from 'http';
5
+ export declare class NodeHttpClient extends HttpClient implements HttpClientInterface {
6
+ readonly baseURL: string;
7
+ readonly options?: RequestInit | undefined;
8
+ private httpAgent;
9
+ private httpsAgent;
10
+ constructor(baseURL: string, options?: RequestInit | undefined);
11
+ getClientName(): string;
12
+ get(path: string, options: RequestOptions): Promise<HttpClientResponseInterface>;
13
+ post<Entity = any>(path: string, entity: Entity, options: RequestOptions): Promise<HttpClientResponseInterface>;
14
+ put<Entity = any>(path: string, entity: Entity, options: RequestOptions): Promise<HttpClientResponseInterface>;
15
+ delete(path: string, options: RequestOptions): Promise<HttpClientResponseInterface>;
16
+ private nodeRequest;
17
+ }
18
+ export declare class NodeHttpClientResponse extends HttpClientResponse implements HttpClientResponseInterface {
19
+ _res: http_.IncomingMessage;
20
+ constructor(res: http_.IncomingMessage);
21
+ getRawResponse(): http_.IncomingMessage;
22
+ toJSON(): Promise<any> | any;
23
+ }
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.NodeHttpClientResponse = exports.NodeHttpClient = void 0;
36
+ const http_client_1 = require("./http-client");
37
+ const http_ = __importStar(require("http"));
38
+ const https_ = __importStar(require("https"));
39
+ // `import * as http_ from 'http'` creates a "Module Namespace Exotic Object"
40
+ // which is immune to monkey-patching, whereas http_.default (in an ES Module context)
41
+ // will resolve to the same thing as require('http'), which is
42
+ // monkey-patchable. We care about this because users in their test
43
+ // suites might be using a library like "nock" which relies on the ability
44
+ // to monkey-patch and intercept calls to http.request.
45
+ const http = http_.default || http_;
46
+ const https = https_.default || https_;
47
+ class NodeHttpClient extends http_client_1.HttpClient {
48
+ constructor(baseURL, options) {
49
+ super(baseURL, options);
50
+ this.baseURL = baseURL;
51
+ this.options = options;
52
+ this.httpAgent = new http.Agent({ keepAlive: true });
53
+ this.httpsAgent = new https.Agent({ keepAlive: true });
54
+ }
55
+ getClientName() {
56
+ return 'node';
57
+ }
58
+ get(path, options) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ const resourceURL = http_client_1.HttpClient.getResourceURL(this.baseURL, path, options.params);
61
+ return yield this.nodeRequest(resourceURL, 'GET', null, options.headers);
62
+ });
63
+ }
64
+ post(path, entity, options) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ const resourceURL = http_client_1.HttpClient.getResourceURL(this.baseURL, path, options.params);
67
+ return yield this.nodeRequest(resourceURL, 'POST', http_client_1.HttpClient.getBody(entity), Object.assign(Object.assign({}, http_client_1.HttpClient.getContentTypeHeader(entity)), options.headers));
68
+ });
69
+ }
70
+ put(path, entity, options) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ const resourceURL = http_client_1.HttpClient.getResourceURL(this.baseURL, path, options.params);
73
+ return yield this.nodeRequest(resourceURL, 'PUT', http_client_1.HttpClient.getBody(entity), Object.assign(Object.assign({}, http_client_1.HttpClient.getContentTypeHeader(entity)), options.headers));
74
+ });
75
+ }
76
+ delete(path, options) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ const resourceURL = http_client_1.HttpClient.getResourceURL(this.baseURL, path, options.params);
79
+ return yield this.nodeRequest(resourceURL, 'DELETE', null, options.headers);
80
+ });
81
+ }
82
+ nodeRequest(url, method, body, headers) {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ return new Promise((resolve, reject) => {
85
+ var _a, _b;
86
+ const isSecureConnection = url.startsWith('https');
87
+ const agent = isSecureConnection ? this.httpsAgent : this.httpAgent;
88
+ const lib = isSecureConnection ? https : http;
89
+ const { 'User-Agent': userAgent } = (_a = this.options) === null || _a === void 0 ? void 0 : _a.headers;
90
+ const options = {
91
+ method,
92
+ headers: Object.assign(Object.assign(Object.assign({ Accept: 'application/json, text/plain, */*', 'Content-Type': 'application/json' }, (_b = this.options) === null || _b === void 0 ? void 0 : _b.headers), headers), { 'User-Agent': this.addClientToUserAgent(userAgent.toString()) }),
93
+ agent,
94
+ };
95
+ const req = lib.request(url, options, (res) => __awaiter(this, void 0, void 0, function* () {
96
+ const clientResponse = new NodeHttpClientResponse(res);
97
+ if (res.statusCode && (res.statusCode < 200 || res.statusCode > 299)) {
98
+ reject(new http_client_1.HttpClientError({
99
+ message: res.statusMessage,
100
+ response: {
101
+ status: res.statusCode,
102
+ headers: res.headers,
103
+ data: yield clientResponse.toJSON(),
104
+ },
105
+ }));
106
+ }
107
+ resolve(clientResponse);
108
+ }));
109
+ req.on('error', (err) => {
110
+ reject(new Error(err.message));
111
+ });
112
+ if (body) {
113
+ req.setHeader('Content-Length', Buffer.byteLength(body));
114
+ req.write(body);
115
+ }
116
+ req.end();
117
+ });
118
+ });
119
+ }
120
+ }
121
+ exports.NodeHttpClient = NodeHttpClient;
122
+ // tslint:disable-next-line
123
+ class NodeHttpClientResponse extends http_client_1.HttpClientResponse {
124
+ constructor(res) {
125
+ // @ts-ignore
126
+ super(res.statusCode, res.headers || {});
127
+ this._res = res;
128
+ }
129
+ getRawResponse() {
130
+ return this._res;
131
+ }
132
+ toJSON() {
133
+ return new Promise((resolve, reject) => {
134
+ const contentType = this._res.headers['content-type'];
135
+ const isJsonResponse = contentType === null || contentType === void 0 ? void 0 : contentType.includes('application/json');
136
+ if (!isJsonResponse) {
137
+ resolve(null);
138
+ }
139
+ let response = '';
140
+ this._res.setEncoding('utf8');
141
+ this._res.on('data', (chunk) => {
142
+ response += chunk;
143
+ });
144
+ this._res.once('end', () => {
145
+ try {
146
+ resolve(JSON.parse(response));
147
+ }
148
+ catch (e) {
149
+ reject(e);
150
+ }
151
+ });
152
+ });
153
+ }
154
+ }
155
+ exports.NodeHttpClientResponse = NodeHttpClientResponse;
@@ -118,6 +118,60 @@ describe('DirectorySync', () => {
118
118
  created_at: '2021-10-27 15:21:50.640959',
119
119
  updated_at: '2021-12-13 12:15:45.531847',
120
120
  };
121
+ const userWithRole = {
122
+ object: 'directory_user',
123
+ id: 'directory_user_456',
124
+ customAttributes: {
125
+ custom: true,
126
+ },
127
+ directoryId: 'dir_123',
128
+ organizationId: 'org_123',
129
+ emails: [
130
+ {
131
+ primary: true,
132
+ type: 'type',
133
+ value: 'jonsnow@workos.com',
134
+ },
135
+ ],
136
+ firstName: 'Jon',
137
+ groups: [group],
138
+ idpId: 'idp_foo',
139
+ lastName: 'Snow',
140
+ jobTitle: 'Knight of the Watch',
141
+ rawAttributes: {},
142
+ state: 'active',
143
+ username: 'jonsnow',
144
+ role: { slug: 'super_admin' },
145
+ createdAt: '2021-10-27 15:21:50.640959',
146
+ updatedAt: '2021-12-13 12:15:45.531847',
147
+ };
148
+ const userWithRoleResponse = {
149
+ object: 'directory_user',
150
+ id: 'directory_user_456',
151
+ custom_attributes: {
152
+ custom: true,
153
+ },
154
+ directory_id: 'dir_123',
155
+ organization_id: 'org_123',
156
+ emails: [
157
+ {
158
+ primary: true,
159
+ type: 'type',
160
+ value: 'jonsnow@workos.com',
161
+ },
162
+ ],
163
+ first_name: 'Jon',
164
+ groups: [groupResponse],
165
+ idp_id: 'idp_foo',
166
+ last_name: 'Snow',
167
+ job_title: 'Knight of the Watch',
168
+ raw_attributes: {},
169
+ state: 'active',
170
+ username: 'jonsnow',
171
+ role: { slug: 'super_admin' },
172
+ created_at: '2021-10-27 15:21:50.640959',
173
+ updated_at: '2021-12-13 12:15:45.531847',
174
+ };
121
175
  describe('listDirectories', () => {
122
176
  describe('with options', () => {
123
177
  it('requests Directories with query parameters', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -351,5 +405,12 @@ describe('DirectorySync', () => {
351
405
  const subject = yield workos.directorySync.getUser('dir_usr_123');
352
406
  expect(subject).toEqual(userWithGroup);
353
407
  }));
408
+ describe('with a Role', () => {
409
+ it(`requests a Directory User`, () => __awaiter(void 0, void 0, void 0, function* () {
410
+ (0, test_utils_1.fetchOnce)(userWithRoleResponse);
411
+ const subject = yield workos.directorySync.getUser('directory_user_456');
412
+ expect(subject).toEqual(userWithRole);
413
+ }));
414
+ });
354
415
  });
355
416
  });
@@ -1,3 +1,4 @@
1
+ import { RoleResponse } from '../../roles/interfaces/';
1
2
  import { DirectoryGroup, DirectoryGroupResponse } from './directory-group.interface';
2
3
  export type DefaultCustomAttributes = Record<string, unknown>;
3
4
  export interface DirectoryUser<TCustomAttributes extends object = DefaultCustomAttributes, TRawAttributes = any> {
@@ -18,6 +19,7 @@ export interface DirectoryUser<TCustomAttributes extends object = DefaultCustomA
18
19
  lastName: string | null;
19
20
  jobTitle: string | null;
20
21
  state: 'active' | 'inactive';
22
+ role?: RoleResponse;
21
23
  createdAt: string;
22
24
  updatedAt: string;
23
25
  }
@@ -39,6 +41,7 @@ export interface DirectoryUserResponse<TCustomAttributes extends object = Defaul
39
41
  last_name: string | null;
40
42
  job_title: string | null;
41
43
  state: 'active' | 'inactive';
44
+ role?: RoleResponse;
42
45
  created_at: string;
43
46
  updated_at: string;
44
47
  }
@@ -16,6 +16,7 @@ const deserializeDirectoryUser = (directoryUser) => ({
16
16
  lastName: directoryUser.last_name,
17
17
  jobTitle: directoryUser.job_title,
18
18
  state: directoryUser.state,
19
+ role: directoryUser.role,
19
20
  createdAt: directoryUser.created_at,
20
21
  updatedAt: directoryUser.updated_at,
21
22
  });
@@ -36,6 +37,7 @@ const deserializeUpdatedEventDirectoryUser = (directoryUser) => ({
36
37
  lastName: directoryUser.last_name,
37
38
  jobTitle: directoryUser.job_title,
38
39
  state: directoryUser.state,
40
+ role: directoryUser.role,
39
41
  createdAt: directoryUser.created_at,
40
42
  updatedAt: directoryUser.updated_at,
41
43
  previousAttributes: directoryUser.previous_attributes,
@@ -106,5 +106,93 @@ describe('Event', () => {
106
106
  listMetadata: {},
107
107
  });
108
108
  }));
109
+ describe('directory user updated events', () => {
110
+ describe('with a role', () => {
111
+ const directoryUserUpdated = {
112
+ id: 'event_01234ABCD',
113
+ createdAt: '2020-05-06 04:21:48.649164',
114
+ event: 'dsync.user.updated',
115
+ data: {
116
+ object: 'directory_user',
117
+ id: 'directory_user_456',
118
+ customAttributes: {
119
+ custom: true,
120
+ },
121
+ directoryId: 'dir_123',
122
+ organizationId: 'org_123',
123
+ emails: [
124
+ {
125
+ primary: true,
126
+ type: 'type',
127
+ value: 'jonsnow@workos.com',
128
+ },
129
+ ],
130
+ firstName: 'Jon',
131
+ idpId: 'idp_foo',
132
+ lastName: 'Snow',
133
+ jobTitle: 'Knight of the Watch',
134
+ rawAttributes: {},
135
+ state: 'active',
136
+ username: 'jonsnow',
137
+ role: { slug: 'super_admin' },
138
+ previousAttributes: {
139
+ role: { slug: 'member' },
140
+ },
141
+ createdAt: '2021-10-27 15:21:50.640959',
142
+ updatedAt: '2021-12-13 12:15:45.531847',
143
+ },
144
+ };
145
+ const directoryUserUpdatedResponse = {
146
+ id: 'event_01234ABCD',
147
+ created_at: '2020-05-06 04:21:48.649164',
148
+ event: 'dsync.user.updated',
149
+ data: {
150
+ object: 'directory_user',
151
+ id: 'directory_user_456',
152
+ custom_attributes: {
153
+ custom: true,
154
+ },
155
+ directory_id: 'dir_123',
156
+ organization_id: 'org_123',
157
+ emails: [
158
+ {
159
+ primary: true,
160
+ type: 'type',
161
+ value: 'jonsnow@workos.com',
162
+ },
163
+ ],
164
+ first_name: 'Jon',
165
+ idp_id: 'idp_foo',
166
+ last_name: 'Snow',
167
+ job_title: 'Knight of the Watch',
168
+ raw_attributes: {},
169
+ state: 'active',
170
+ username: 'jonsnow',
171
+ role: { slug: 'super_admin' },
172
+ previous_attributes: {
173
+ role: { slug: 'member' },
174
+ },
175
+ created_at: '2021-10-27 15:21:50.640959',
176
+ updated_at: '2021-12-13 12:15:45.531847',
177
+ },
178
+ };
179
+ const directoryUserEventsListResponse = {
180
+ object: 'list',
181
+ data: [directoryUserUpdatedResponse],
182
+ list_metadata: {},
183
+ };
184
+ it(`returns the role`, () => __awaiter(void 0, void 0, void 0, function* () {
185
+ (0, test_utils_1.fetchOnce)(directoryUserEventsListResponse);
186
+ const list = yield workos.events.listEvents({
187
+ events: ['dsync.user.updated'],
188
+ });
189
+ expect(list).toEqual({
190
+ object: 'list',
191
+ data: [directoryUserUpdated],
192
+ listMetadata: {},
193
+ });
194
+ }));
195
+ });
196
+ });
109
197
  });
110
198
  });
@@ -0,0 +1 @@
1
+ export * from './role.interface';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./role.interface"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ {
2
+ "object": "organization_membership",
3
+ "id": "om_01H5JQDV7R7ATEYZDEG0W5PRYS",
4
+ "user_id": "user_01H5JQDV7R7ATEYZDEG0W5PRYS",
5
+ "organization_id": "organization_01H5JQDV7R7ATEYZDEG0W5PRYS",
6
+ "status": "inactive",
7
+ "role": {
8
+ "slug": "member"
9
+ },
10
+ "created_at": "2023-07-18T02:07:19.911Z",
11
+ "updated_at": "2023-07-18T02:07:19.911Z"
12
+ }
@@ -7,6 +7,7 @@
7
7
  "revoked_at": "2023-07-18T02:07:19.911Z",
8
8
  "expires_at": "2023-07-18T02:07:19.911Z",
9
9
  "organization_id": "org_01H5JQDV7R7ATEYZDEG0W5PRYS",
10
+ "inviter_user_id": null,
10
11
  "token": "Z1uX3RbwcIl5fIGJJJCXXisdI",
11
12
  "accept_invitation_url": "https://myauthkit.com/invite?invitation_token=Z1uX3RbwcIl5fIGJJJCXXisdI",
12
13
  "created_at": "2023-07-18T02:07:19.911Z",
@@ -10,6 +10,7 @@
10
10
  "revoked_at": "2023-07-18T02:07:19.911Z",
11
11
  "expires_at": "2023-07-18T02:07:19.911Z",
12
12
  "organization_id": "org_01H5JQDV7R7ATEYZDEG0W5PRYS",
13
+ "inviter_user_id": null,
13
14
  "token": "Z1uX3RbwcIl5fIGJJJCXXisdI",
14
15
  "accept_invitation_url": "https://myauthkit.com/invite?invitation_token=Z1uX3RbwcIl5fIGJJJCXXisdI",
15
16
  "created_at": "2023-07-18T02:07:19.911Z",
@@ -24,7 +24,6 @@ export * from './magic-auth.interface';
24
24
  export * from './organization-membership.interface';
25
25
  export * from './reset-password-options.interface';
26
26
  export * from './revoke-session-options.interface';
27
- export * from './role.interface';
28
27
  export * from './send-invitation-options.interface';
29
28
  export * from './send-magic-auth-code-options.interface';
30
29
  export * from './send-password-reset-email-options.interface';
@@ -35,4 +34,3 @@ export * from './update-user-options.interface';
35
34
  export * from './update-user-password-options.interface';
36
35
  export * from './user.interface';
37
36
  export * from './verify-email-options.interface';
38
- export * from './role.interface';
@@ -40,7 +40,6 @@ __exportStar(require("./magic-auth.interface"), exports);
40
40
  __exportStar(require("./organization-membership.interface"), exports);
41
41
  __exportStar(require("./reset-password-options.interface"), exports);
42
42
  __exportStar(require("./revoke-session-options.interface"), exports);
43
- __exportStar(require("./role.interface"), exports);
44
43
  __exportStar(require("./send-invitation-options.interface"), exports);
45
44
  __exportStar(require("./send-magic-auth-code-options.interface"), exports);
46
45
  __exportStar(require("./send-password-reset-email-options.interface"), exports);
@@ -51,4 +50,3 @@ __exportStar(require("./update-user-options.interface"), exports);
51
50
  __exportStar(require("./update-user-password-options.interface"), exports);
52
51
  __exportStar(require("./user.interface"), exports);
53
52
  __exportStar(require("./verify-email-options.interface"), exports);
54
- __exportStar(require("./role.interface"), exports);
@@ -7,6 +7,7 @@ export interface Invitation {
7
7
  revokedAt: string | null;
8
8
  expiresAt: string;
9
9
  organizationId: string | null;
10
+ inviterUserId: string | null;
10
11
  token: string;
11
12
  acceptInvitationUrl: string;
12
13
  createdAt: string;
@@ -21,6 +22,7 @@ export interface InvitationEvent {
21
22
  revokedAt: string | null;
22
23
  expiresAt: string;
23
24
  organizationId: string | null;
25
+ inviterUserId: string | null;
24
26
  createdAt: string;
25
27
  updatedAt: string;
26
28
  }
@@ -33,6 +35,7 @@ export interface InvitationResponse {
33
35
  revoked_at: string | null;
34
36
  expires_at: string;
35
37
  organization_id: string | null;
38
+ inviter_user_id: string | null;
36
39
  token: string;
37
40
  accept_invitation_url: string;
38
41
  created_at: string;
@@ -47,6 +50,7 @@ export interface InvitationEventResponse {
47
50
  revoked_at: string | null;
48
51
  expires_at: string;
49
52
  organization_id: string | null;
53
+ inviter_user_id: string | null;
50
54
  created_at: string;
51
55
  updated_at: string;
52
56
  }