@workos-inc/node 2.9.1 → 2.12.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.
- package/lib/audit-logs/audit-logs.d.ts +4 -0
- package/lib/audit-logs/audit-logs.js +12 -0
- package/lib/audit-logs/audit-logs.spec.js +108 -0
- package/lib/audit-logs/interfaces/audit-log-export-options.interface.d.ts +8 -0
- package/lib/audit-logs/interfaces/audit-log-export-options.interface.js +2 -0
- package/lib/audit-logs/interfaces/audit-log-export.interface.d.ts +8 -0
- package/lib/audit-logs/interfaces/audit-log-export.interface.js +2 -0
- package/lib/audit-logs/interfaces/index.d.ts +3 -1
- package/lib/audit-logs/interfaces/index.js +17 -0
- package/lib/common/interfaces/workos-options.interface.d.ts +2 -0
- package/lib/organizations/interfaces/create-organization-options.interface.d.ts +3 -0
- package/lib/organizations/organizations.d.ts +2 -2
- package/lib/organizations/organizations.js +2 -2
- package/lib/organizations/organizations.spec.js +17 -0
- package/lib/workos.js +3 -8
- package/lib/workos.spec.js +16 -0
- package/package.json +3 -3
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { WorkOS } from '../workos';
|
|
2
2
|
import { CreateAuditLogEventOptions, CreateAuditLogEventRequestOptions } from './interfaces';
|
|
3
|
+
import { AuditLogExportOptions } from './interfaces/audit-log-export-options.interface';
|
|
4
|
+
import { AuditLogExport } from './interfaces/audit-log-export.interface';
|
|
3
5
|
export declare class AuditLogs {
|
|
4
6
|
private readonly workos;
|
|
5
7
|
constructor(workos: WorkOS);
|
|
6
8
|
createEvent(organization: string, event: CreateAuditLogEventOptions, options?: CreateAuditLogEventRequestOptions): Promise<void>;
|
|
9
|
+
createExport(options: AuditLogExportOptions): Promise<AuditLogExport>;
|
|
10
|
+
getExport(auditLogExportId: string): Promise<AuditLogExport>;
|
|
7
11
|
}
|
|
@@ -22,5 +22,17 @@ class AuditLogs {
|
|
|
22
22
|
}, options);
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
+
createExport(options) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const { data } = yield this.workos.post('/audit_logs/exports', options);
|
|
28
|
+
return data;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
getExport(auditLogExportId) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const { data } = yield this.workos.get(`/audit_logs/exports/${auditLogExportId}`);
|
|
34
|
+
return data;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
25
37
|
}
|
|
26
38
|
exports.AuditLogs = AuditLogs;
|
|
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
11
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
24
|
};
|
|
@@ -107,4 +118,101 @@ describe('AuditLogs', () => {
|
|
|
107
118
|
}));
|
|
108
119
|
});
|
|
109
120
|
});
|
|
121
|
+
describe('createExport', () => {
|
|
122
|
+
const serializeExportOptions = (_a) => {
|
|
123
|
+
var { range_end, range_start } = _a, options = __rest(_a, ["range_end", "range_start"]);
|
|
124
|
+
return (Object.assign({ range_start: range_start.toISOString(), range_end: range_end.toISOString() }, options));
|
|
125
|
+
};
|
|
126
|
+
describe('when the api responds with a 201', () => {
|
|
127
|
+
it('returns `audit_log_export`', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
128
|
+
const options = {
|
|
129
|
+
organization_id: 'org_123',
|
|
130
|
+
range_start: new Date(),
|
|
131
|
+
range_end: new Date(),
|
|
132
|
+
};
|
|
133
|
+
const auditLogExport = {
|
|
134
|
+
object: 'audit_log_export',
|
|
135
|
+
id: 'audit_log_export_1234',
|
|
136
|
+
state: 'pending',
|
|
137
|
+
url: undefined,
|
|
138
|
+
created_at: new Date().toISOString(),
|
|
139
|
+
updated_at: new Date().toISOString(),
|
|
140
|
+
};
|
|
141
|
+
mock
|
|
142
|
+
.onPost('/audit_logs/exports', serializeExportOptions(options))
|
|
143
|
+
.replyOnce(201, auditLogExport);
|
|
144
|
+
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
145
|
+
yield expect(workos.auditLogs.createExport(options)).resolves.toEqual(auditLogExport);
|
|
146
|
+
}));
|
|
147
|
+
});
|
|
148
|
+
describe('when additional filters are defined', () => {
|
|
149
|
+
it('returns `audit_log_export`', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
150
|
+
const options = {
|
|
151
|
+
actions: ['foo', 'bar'],
|
|
152
|
+
actors: ['Jon', 'Smith'],
|
|
153
|
+
organization_id: 'org_123',
|
|
154
|
+
range_end: new Date(),
|
|
155
|
+
range_start: new Date(),
|
|
156
|
+
targets: ['user', 'team'],
|
|
157
|
+
};
|
|
158
|
+
const auditLogExport = {
|
|
159
|
+
object: 'audit_log_export',
|
|
160
|
+
id: 'audit_log_export_1234',
|
|
161
|
+
state: 'pending',
|
|
162
|
+
url: undefined,
|
|
163
|
+
created_at: new Date().toISOString(),
|
|
164
|
+
updated_at: new Date().toISOString(),
|
|
165
|
+
};
|
|
166
|
+
mock
|
|
167
|
+
.onPost('/audit_logs/exports', serializeExportOptions(options))
|
|
168
|
+
.replyOnce(201, auditLogExport);
|
|
169
|
+
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
170
|
+
yield expect(workos.auditLogs.createExport(options)).resolves.toEqual(auditLogExport);
|
|
171
|
+
}));
|
|
172
|
+
});
|
|
173
|
+
describe('when the api responds with a 401', () => {
|
|
174
|
+
it('throws an UnauthorizedException', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
175
|
+
const options = {
|
|
176
|
+
organization_id: 'org_123',
|
|
177
|
+
range_start: new Date(),
|
|
178
|
+
range_end: new Date(),
|
|
179
|
+
};
|
|
180
|
+
mock
|
|
181
|
+
.onPost('/audit_logs/exports', serializeExportOptions(options))
|
|
182
|
+
.replyOnce(401, {
|
|
183
|
+
message: 'Unauthorized',
|
|
184
|
+
}, { 'X-Request-ID': 'a-request-id' });
|
|
185
|
+
const workos = new workos_1.WorkOS('invalid apikey');
|
|
186
|
+
yield expect(workos.auditLogs.createExport(options)).rejects.toStrictEqual(new exceptions_1.UnauthorizedException('a-request-id'));
|
|
187
|
+
}));
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
describe('getExport', () => {
|
|
191
|
+
describe('when the api responds with a 201', () => {
|
|
192
|
+
it('returns `audit_log_export`', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
193
|
+
const auditLogExport = {
|
|
194
|
+
object: 'audit_log_export',
|
|
195
|
+
id: 'audit_log_export_1234',
|
|
196
|
+
state: 'pending',
|
|
197
|
+
url: undefined,
|
|
198
|
+
created_at: new Date().toISOString(),
|
|
199
|
+
updated_at: new Date().toISOString(),
|
|
200
|
+
};
|
|
201
|
+
mock
|
|
202
|
+
.onGet(`/audit_logs/exports/${auditLogExport.id}`)
|
|
203
|
+
.replyOnce(200, auditLogExport);
|
|
204
|
+
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
205
|
+
yield expect(workos.auditLogs.getExport(auditLogExport.id)).resolves.toEqual(auditLogExport);
|
|
206
|
+
}));
|
|
207
|
+
});
|
|
208
|
+
describe('when the api responds with a 401', () => {
|
|
209
|
+
it('throws an UnauthorizedException', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
210
|
+
mock.onGet('/audit_logs/exports/audit_log_export_1234').replyOnce(401, {
|
|
211
|
+
message: 'Unauthorized',
|
|
212
|
+
}, { 'X-Request-ID': 'a-request-id' });
|
|
213
|
+
const workos = new workos_1.WorkOS('invalid apikey');
|
|
214
|
+
yield expect(workos.auditLogs.getExport('audit_log_export_1234')).rejects.toStrictEqual(new exceptions_1.UnauthorizedException('a-request-id'));
|
|
215
|
+
}));
|
|
216
|
+
});
|
|
217
|
+
});
|
|
110
218
|
});
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './audit-log-export-options.interface';
|
|
2
|
+
export * from './audit-log-export.interface';
|
|
3
|
+
export * from './create-audit-log-event-options.interface';
|
|
@@ -1,2 +1,19 @@
|
|
|
1
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
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./audit-log-export-options.interface"), exports);
|
|
18
|
+
__exportStar(require("./audit-log-export.interface"), exports);
|
|
19
|
+
__exportStar(require("./create-audit-log-event-options.interface"), exports);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { PostOptions } from '../../common/interfaces';
|
|
1
2
|
export interface CreateOrganizationOptions {
|
|
2
3
|
name: string;
|
|
3
4
|
allow_profiles_outside_organization?: boolean;
|
|
4
5
|
domains?: string[];
|
|
5
6
|
}
|
|
7
|
+
export interface CreateOrganizationRequestOptions extends Pick<PostOptions, 'idempotencyKey'> {
|
|
8
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { List } from '../common/interfaces/list.interface';
|
|
2
2
|
import { WorkOS } from '../workos';
|
|
3
|
-
import { CreateOrganizationOptions, ListOrganizationsOptions, Organization, UpdateOrganizationOptions } from './interfaces';
|
|
3
|
+
import { CreateOrganizationOptions, CreateOrganizationRequestOptions, ListOrganizationsOptions, Organization, UpdateOrganizationOptions } from './interfaces';
|
|
4
4
|
export declare class Organizations {
|
|
5
5
|
private readonly workos;
|
|
6
6
|
constructor(workos: WorkOS);
|
|
7
7
|
listOrganizations(options?: ListOrganizationsOptions): Promise<List<Organization>>;
|
|
8
|
-
createOrganization(payload: CreateOrganizationOptions): Promise<Organization>;
|
|
8
|
+
createOrganization(payload: CreateOrganizationOptions, requestOptions?: CreateOrganizationRequestOptions): Promise<Organization>;
|
|
9
9
|
deleteOrganization(id: string): Promise<void>;
|
|
10
10
|
getOrganization(id: string): Promise<Organization>;
|
|
11
11
|
updateOrganization(options: UpdateOrganizationOptions): Promise<Organization>;
|
|
@@ -33,9 +33,9 @@ class Organizations {
|
|
|
33
33
|
return data;
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
-
createOrganization(payload) {
|
|
36
|
+
createOrganization(payload, requestOptions = {}) {
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const { data } = yield this.workos.post('/organizations', payload);
|
|
38
|
+
const { data } = yield this.workos.post('/organizations', payload, requestOptions);
|
|
39
39
|
return data;
|
|
40
40
|
});
|
|
41
41
|
}
|
|
@@ -108,6 +108,23 @@ describe('Organizations', () => {
|
|
|
108
108
|
});
|
|
109
109
|
});
|
|
110
110
|
describe('createOrganization', () => {
|
|
111
|
+
describe('with an idempotency key', () => {
|
|
112
|
+
it('includes an idempotency key with request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
mock
|
|
114
|
+
.onPost('/organizations', {
|
|
115
|
+
domains: ['example.com'],
|
|
116
|
+
name: 'Test Organization',
|
|
117
|
+
})
|
|
118
|
+
.replyOnce(201, create_organization_json_1.default);
|
|
119
|
+
yield workos.organizations.createOrganization({
|
|
120
|
+
domains: ['example.com'],
|
|
121
|
+
name: 'Test Organization',
|
|
122
|
+
}, {
|
|
123
|
+
idempotencyKey: 'the-idempotency-key',
|
|
124
|
+
});
|
|
125
|
+
expect(mock.history.post[0].headers['Idempotency-Key']).toEqual('the-idempotency-key');
|
|
126
|
+
}));
|
|
127
|
+
});
|
|
111
128
|
describe('with a valid payload', () => {
|
|
112
129
|
it('creates an organization', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
130
|
mock
|
package/lib/workos.js
CHANGED
|
@@ -25,10 +25,11 @@ const webhooks_1 = require("./webhooks/webhooks");
|
|
|
25
25
|
const mfa_1 = require("./mfa/mfa");
|
|
26
26
|
const audit_logs_1 = require("./audit-logs/audit-logs");
|
|
27
27
|
const bad_request_exception_1 = require("./common/exceptions/bad-request.exception");
|
|
28
|
-
const VERSION = '2.
|
|
28
|
+
const VERSION = '2.12.0';
|
|
29
29
|
const DEFAULT_HOSTNAME = 'api.workos.com';
|
|
30
30
|
class WorkOS {
|
|
31
31
|
constructor(key, options = {}) {
|
|
32
|
+
var _a;
|
|
32
33
|
this.key = key;
|
|
33
34
|
this.options = options;
|
|
34
35
|
this.auditLogs = new audit_logs_1.AuditLogs(this);
|
|
@@ -56,13 +57,7 @@ class WorkOS {
|
|
|
56
57
|
if (port) {
|
|
57
58
|
this.baseURL = this.baseURL + `:${port}`;
|
|
58
59
|
}
|
|
59
|
-
this.client = axios_1.default.create({
|
|
60
|
-
baseURL: this.baseURL,
|
|
61
|
-
headers: {
|
|
62
|
-
Authorization: `Bearer ${this.key}`,
|
|
63
|
-
'User-Agent': `workos-node/${VERSION}`,
|
|
64
|
-
},
|
|
65
|
-
});
|
|
60
|
+
this.client = axios_1.default.create(Object.assign(Object.assign({}, options.axios), { baseURL: this.baseURL, headers: Object.assign(Object.assign({}, (_a = options.axios) === null || _a === void 0 ? void 0 : _a.headers), { Authorization: `Bearer ${this.key}`, 'User-Agent': `workos-node/${VERSION}` }) }));
|
|
66
61
|
}
|
|
67
62
|
post(path, entity, options = {}) {
|
|
68
63
|
return __awaiter(this, void 0, void 0, function* () {
|
package/lib/workos.spec.js
CHANGED
|
@@ -65,6 +65,22 @@ describe('WorkOS', () => {
|
|
|
65
65
|
expect(workos.baseURL).toEqual('https://localhost:4000');
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
|
+
describe('when the `axios` option is provided', () => {
|
|
69
|
+
it('applies the configuration to the Axios client', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
+
mock.onPost().reply(200, 'OK', { 'X-Request-ID': 'a-request-id' });
|
|
71
|
+
const workos = new workos_1.WorkOS('sk_test', {
|
|
72
|
+
axios: {
|
|
73
|
+
headers: {
|
|
74
|
+
'X-My-Custom-Header': 'Hey there!',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
yield workos.post('/somewhere', {});
|
|
79
|
+
expect(mock.history.post[0].headers).toMatchObject({
|
|
80
|
+
'X-My-Custom-Header': 'Hey there!',
|
|
81
|
+
});
|
|
82
|
+
}));
|
|
83
|
+
});
|
|
68
84
|
});
|
|
69
85
|
describe('post', () => {
|
|
70
86
|
describe('when the api responds with a 404', () => {
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
2
|
+
"version": "2.12.0",
|
|
3
3
|
"name": "@workos-inc/node",
|
|
4
4
|
"author": "WorkOS",
|
|
5
5
|
"description": "A Node wrapper for the WorkOS API",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/jest": "27.5.2",
|
|
43
|
-
"@types/node": "14.18.
|
|
43
|
+
"@types/node": "14.18.24",
|
|
44
44
|
"@types/pluralize": "0.0.29",
|
|
45
|
-
"axios-mock-adapter": "1.21.
|
|
45
|
+
"axios-mock-adapter": "1.21.2",
|
|
46
46
|
"jest": "27.5.1",
|
|
47
47
|
"prettier": "2.7.1",
|
|
48
48
|
"supertest": "6.2.3",
|