@workos-inc/node 7.4.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.
- package/README.md +4 -0
- package/lib/common/crypto/CryptoProvider.d.ts +32 -0
- package/lib/common/crypto/CryptoProvider.js +13 -0
- package/lib/common/crypto/NodeCryptoProvider.d.ts +12 -0
- package/lib/common/crypto/NodeCryptoProvider.js +73 -0
- package/lib/common/crypto/SubtleCryptoProvider.d.ts +15 -0
- package/lib/common/crypto/SubtleCryptoProvider.js +75 -0
- package/lib/common/crypto/index.d.ts +3 -0
- package/lib/common/crypto/index.js +19 -0
- package/lib/common/interfaces/event.interface.d.ts +1 -1
- package/lib/common/interfaces/http-client.interface.d.ts +20 -0
- package/lib/common/interfaces/index.d.ts +1 -0
- package/lib/common/interfaces/index.js +1 -0
- package/lib/common/interfaces/workos-options.interface.d.ts +1 -0
- package/lib/common/net/fetch-client.d.ts +22 -0
- package/lib/common/net/fetch-client.js +112 -0
- package/lib/common/net/http-client.d.ts +39 -0
- package/lib/common/net/http-client.js +76 -0
- package/lib/common/net/index.d.ts +5 -0
- package/lib/common/net/index.js +31 -0
- package/lib/common/net/node-client.d.ts +23 -0
- package/lib/common/net/node-client.js +155 -0
- package/lib/directory-sync/directory-sync.spec.js +61 -0
- package/lib/directory-sync/interfaces/directory-user.interface.d.ts +3 -0
- package/lib/directory-sync/serializers/directory-user.serializer.js +2 -0
- package/lib/events/events.spec.js +88 -0
- package/lib/roles/interfaces/index.d.ts +1 -0
- package/lib/roles/interfaces/index.js +17 -0
- package/lib/roles/interfaces/role.interface.js +2 -0
- package/lib/user-management/fixtures/deactivate-organization-membership.json +12 -0
- package/lib/user-management/interfaces/index.d.ts +0 -2
- package/lib/user-management/interfaces/index.js +0 -2
- package/lib/user-management/interfaces/list-organization-memberships-options.interface.d.ts +3 -0
- package/lib/user-management/interfaces/organization-membership.interface.d.ts +4 -3
- package/lib/user-management/serializers/list-organization-memberships-options.serializer.js +12 -8
- package/lib/user-management/serializers/role.serializer.d.ts +1 -1
- package/lib/user-management/user-management.d.ts +2 -0
- package/lib/user-management/user-management.js +12 -0
- package/lib/user-management/user-management.spec.js +40 -5
- package/lib/webhooks/webhooks.d.ts +2 -2
- package/lib/webhooks/webhooks.js +11 -37
- package/lib/webhooks/webhooks.spec.js +29 -0
- package/lib/workos.d.ts +1 -1
- package/lib/workos.js +18 -12
- package/lib/workos.spec.js +56 -3
- package/package.json +2 -3
- package/lib/common/utils/fetch-client.d.ts +0 -31
- package/lib/common/utils/fetch-client.js +0 -108
- /package/lib/{user-management/interfaces/role.interface.js → common/interfaces/http-client.interface.js} +0 -0
- /package/lib/{user-management → roles}/interfaces/role.interface.d.ts +0 -0
|
@@ -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,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
|
+
}
|
|
@@ -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);
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { PaginationOptions } from '../../common/interfaces';
|
|
2
|
+
import { OrganizationMembershipStatus } from './organization-membership.interface';
|
|
2
3
|
export interface ListOrganizationMembershipsOptions extends PaginationOptions {
|
|
3
4
|
organizationId?: string;
|
|
4
5
|
userId?: string;
|
|
6
|
+
statuses?: OrganizationMembershipStatus[];
|
|
5
7
|
}
|
|
6
8
|
export interface SerializedListOrganizationMembershipsOptions extends PaginationOptions {
|
|
7
9
|
organization_id?: string;
|
|
8
10
|
user_id?: string;
|
|
11
|
+
statuses?: string;
|
|
9
12
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { RoleResponse } from '
|
|
1
|
+
import { RoleResponse } from '../../roles/interfaces/';
|
|
2
|
+
export type OrganizationMembershipStatus = 'active' | 'inactive' | 'pending';
|
|
2
3
|
export interface OrganizationMembership {
|
|
3
4
|
object: 'organization_membership';
|
|
4
5
|
id: string;
|
|
5
6
|
organizationId: string;
|
|
6
|
-
status:
|
|
7
|
+
status: OrganizationMembershipStatus;
|
|
7
8
|
userId: string;
|
|
8
9
|
createdAt: string;
|
|
9
10
|
updatedAt: string;
|
|
@@ -13,7 +14,7 @@ export interface OrganizationMembershipResponse {
|
|
|
13
14
|
object: 'organization_membership';
|
|
14
15
|
id: string;
|
|
15
16
|
organization_id: string;
|
|
16
|
-
status:
|
|
17
|
+
status: OrganizationMembershipStatus;
|
|
17
18
|
user_id: string;
|
|
18
19
|
created_at: string;
|
|
19
20
|
updated_at: string;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.serializeListOrganizationMembershipsOptions = void 0;
|
|
4
|
-
const serializeListOrganizationMembershipsOptions = (options) =>
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
const serializeListOrganizationMembershipsOptions = (options) => {
|
|
5
|
+
var _a;
|
|
6
|
+
return ({
|
|
7
|
+
user_id: options.userId,
|
|
8
|
+
organization_id: options.organizationId,
|
|
9
|
+
statuses: (_a = options.statuses) === null || _a === void 0 ? void 0 : _a.join(','),
|
|
10
|
+
limit: options.limit,
|
|
11
|
+
before: options.before,
|
|
12
|
+
after: options.after,
|
|
13
|
+
order: options.order,
|
|
14
|
+
});
|
|
15
|
+
};
|
|
12
16
|
exports.serializeListOrganizationMembershipsOptions = serializeListOrganizationMembershipsOptions;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RoleEvent, RoleEventResponse } from '
|
|
1
|
+
import { RoleEvent, RoleEventResponse } from '../../roles/interfaces';
|
|
2
2
|
export declare const deserializeRole: (role: RoleEventResponse) => RoleEvent;
|
|
@@ -55,6 +55,8 @@ export declare class UserManagement {
|
|
|
55
55
|
createOrganizationMembership(options: CreateOrganizationMembershipOptions): Promise<OrganizationMembership>;
|
|
56
56
|
updateOrganizationMembership(organizationMembershipId: string, options: UpdateOrganizationMembershipOptions): Promise<OrganizationMembership>;
|
|
57
57
|
deleteOrganizationMembership(organizationMembershipId: string): Promise<void>;
|
|
58
|
+
deactivateOrganizationMembership(organizationMembershipId: string): Promise<OrganizationMembership>;
|
|
59
|
+
reactivateOrganizationMembership(organizationMembershipId: string): Promise<OrganizationMembership>;
|
|
58
60
|
getInvitation(invitationId: string): Promise<Invitation>;
|
|
59
61
|
listInvitations(options: ListInvitationsOptions): Promise<AutoPaginatable<Invitation>>;
|
|
60
62
|
sendInvitation(payload: SendInvitationOptions): Promise<Invitation>;
|
|
@@ -202,6 +202,18 @@ class UserManagement {
|
|
|
202
202
|
yield this.workos.delete(`/user_management/organization_memberships/${organizationMembershipId}`);
|
|
203
203
|
});
|
|
204
204
|
}
|
|
205
|
+
deactivateOrganizationMembership(organizationMembershipId) {
|
|
206
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
207
|
+
const { data } = yield this.workos.put(`/user_management/organization_memberships/${organizationMembershipId}/deactivate`, {});
|
|
208
|
+
return (0, organization_membership_serializer_1.deserializeOrganizationMembership)(data);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
reactivateOrganizationMembership(organizationMembershipId) {
|
|
212
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
213
|
+
const { data } = yield this.workos.put(`/user_management/organization_memberships/${organizationMembershipId}/reactivate`, {});
|
|
214
|
+
return (0, organization_membership_serializer_1.deserializeOrganizationMembership)(data);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
205
217
|
getInvitation(invitationId) {
|
|
206
218
|
return __awaiter(this, void 0, void 0, function* () {
|
|
207
219
|
const { data } = yield this.workos.get(`/user_management/invitations/${invitationId}`);
|
|
@@ -15,14 +15,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const jest_fetch_mock_1 = __importDefault(require("jest-fetch-mock"));
|
|
16
16
|
const test_utils_1 = require("../common/utils/test-utils");
|
|
17
17
|
const workos_1 = require("../workos");
|
|
18
|
-
const
|
|
19
|
-
const list_users_json_1 = __importDefault(require("./fixtures/list-users.json"));
|
|
20
|
-
const list_factors_json_1 = __importDefault(require("./fixtures/list-factors.json"));
|
|
21
|
-
const organization_membership_json_1 = __importDefault(require("./fixtures/organization-membership.json"));
|
|
22
|
-
const list_organization_memberships_json_1 = __importDefault(require("./fixtures/list-organization-memberships.json"));
|
|
18
|
+
const deactivate_organization_membership_json_1 = __importDefault(require("./fixtures/deactivate-organization-membership.json"));
|
|
23
19
|
const invitation_json_1 = __importDefault(require("./fixtures/invitation.json"));
|
|
20
|
+
const list_factors_json_1 = __importDefault(require("./fixtures/list-factors.json"));
|
|
24
21
|
const list_invitations_json_1 = __importDefault(require("./fixtures/list-invitations.json"));
|
|
22
|
+
const list_organization_memberships_json_1 = __importDefault(require("./fixtures/list-organization-memberships.json"));
|
|
23
|
+
const list_users_json_1 = __importDefault(require("./fixtures/list-users.json"));
|
|
25
24
|
const magic_auth_json_1 = __importDefault(require("./fixtures/magic_auth.json"));
|
|
25
|
+
const organization_membership_json_1 = __importDefault(require("./fixtures/organization-membership.json"));
|
|
26
|
+
const user_json_1 = __importDefault(require("./fixtures/user.json"));
|
|
26
27
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
27
28
|
const userId = 'user_01H5JQDV7R7ATEYZDEG0W5PRYS';
|
|
28
29
|
const organizationMembershipId = 'om_01H5JQDV7R7ATEYZDEG0W5PRYS';
|
|
@@ -583,12 +584,14 @@ describe('UserManagement', () => {
|
|
|
583
584
|
yield workos.userManagement.listOrganizationMemberships({
|
|
584
585
|
userId: 'user_someuser',
|
|
585
586
|
organizationId: 'org_someorg',
|
|
587
|
+
statuses: ['active', 'inactive'],
|
|
586
588
|
after: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
587
589
|
limit: 10,
|
|
588
590
|
});
|
|
589
591
|
expect((0, test_utils_1.fetchSearchParams)()).toEqual({
|
|
590
592
|
user_id: 'user_someuser',
|
|
591
593
|
organization_id: 'org_someorg',
|
|
594
|
+
statuses: 'active,inactive',
|
|
592
595
|
after: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
593
596
|
limit: '10',
|
|
594
597
|
order: 'desc',
|
|
@@ -644,6 +647,38 @@ describe('UserManagement', () => {
|
|
|
644
647
|
expect(resp).toBeUndefined();
|
|
645
648
|
}));
|
|
646
649
|
});
|
|
650
|
+
describe('deactivateOrganizationMembership', () => {
|
|
651
|
+
it('sends a deactivateOrganizationMembership request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
652
|
+
(0, test_utils_1.fetchOnce)(deactivate_organization_membership_json_1.default);
|
|
653
|
+
const organizationMembership = yield workos.userManagement.deactivateOrganizationMembership(organizationMembershipId);
|
|
654
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/organization_memberships/${organizationMembershipId}/deactivate`);
|
|
655
|
+
expect(organizationMembership).toMatchObject({
|
|
656
|
+
object: 'organization_membership',
|
|
657
|
+
organizationId: 'organization_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
658
|
+
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
659
|
+
status: 'inactive',
|
|
660
|
+
role: {
|
|
661
|
+
slug: 'member',
|
|
662
|
+
},
|
|
663
|
+
});
|
|
664
|
+
}));
|
|
665
|
+
});
|
|
666
|
+
describe('reactivateOrganizationMembership', () => {
|
|
667
|
+
it('sends a reactivateOrganizationMembership request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
668
|
+
(0, test_utils_1.fetchOnce)(organization_membership_json_1.default);
|
|
669
|
+
const organizationMembership = yield workos.userManagement.reactivateOrganizationMembership(organizationMembershipId);
|
|
670
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/organization_memberships/${organizationMembershipId}/reactivate`);
|
|
671
|
+
expect(organizationMembership).toMatchObject({
|
|
672
|
+
object: 'organization_membership',
|
|
673
|
+
organizationId: 'organization_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
674
|
+
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
675
|
+
status: 'active',
|
|
676
|
+
role: {
|
|
677
|
+
slug: 'member',
|
|
678
|
+
},
|
|
679
|
+
});
|
|
680
|
+
}));
|
|
681
|
+
});
|
|
647
682
|
describe('getInvitation', () => {
|
|
648
683
|
it('sends a Get Invitation request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
649
684
|
(0, test_utils_1.fetchOnce)(invitation_json_1.default);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Event } from '../common/interfaces';
|
|
2
2
|
export declare class Webhooks {
|
|
3
|
-
private
|
|
3
|
+
private cryptoProvider;
|
|
4
|
+
constructor(subtleCrypto?: typeof crypto.subtle);
|
|
4
5
|
constructEvent({ payload, sigHeader, secret, tolerance, }: {
|
|
5
6
|
payload: unknown;
|
|
6
7
|
sigHeader: string;
|
|
@@ -15,5 +16,4 @@ export declare class Webhooks {
|
|
|
15
16
|
}): Promise<boolean>;
|
|
16
17
|
getTimestampAndSignatureHash(sigHeader: string): [string, string];
|
|
17
18
|
computeSignature(timestamp: any, payload: any, secret: string): Promise<string>;
|
|
18
|
-
secureCompare(stringA: string, stringB: string): Promise<boolean>;
|
|
19
19
|
}
|