@workos-inc/node 7.1.0 → 7.3.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/README.md +13 -0
- package/lib/common/interfaces/event.interface.d.ts +64 -3
- package/lib/common/serializers/event.serializer.js +10 -0
- package/lib/events/events.spec.js +12 -0
- package/lib/events/interfaces/list-events-options.interface.d.ts +2 -0
- package/lib/events/serializers/list-event-options.serializer.js +1 -0
- package/lib/organizations/interfaces/create-organization-options.interface.d.ts +9 -0
- package/lib/organizations/interfaces/domain-data.interface.d.ts +8 -0
- package/lib/organizations/interfaces/domain-data.interface.js +9 -0
- package/lib/organizations/interfaces/index.d.ts +1 -0
- package/lib/organizations/interfaces/index.js +1 -0
- package/lib/organizations/interfaces/update-organization-options.interface.d.ts +9 -0
- package/lib/organizations/organizations.spec.js +71 -29
- package/lib/organizations/serializers/create-organization-options.serializer.js +1 -0
- package/lib/organizations/serializers/update-organization-options.serializer.js +1 -0
- package/lib/user-management/fixtures/invitation.json +1 -0
- package/lib/user-management/fixtures/list-invitations.json +1 -0
- package/lib/user-management/fixtures/magic_auth.json +10 -0
- package/lib/user-management/interfaces/authentication-response.interface.d.ts +4 -0
- package/lib/user-management/interfaces/create-magic-auth-options.interface.d.ts +8 -0
- package/lib/user-management/interfaces/create-magic-auth-options.interface.js +2 -0
- package/lib/user-management/interfaces/index.d.ts +3 -0
- package/lib/user-management/interfaces/index.js +3 -0
- package/lib/user-management/interfaces/invitation.interface.d.ts +26 -0
- package/lib/user-management/interfaces/magic-auth.interface.d.ts +38 -0
- package/lib/user-management/interfaces/magic-auth.interface.js +2 -0
- package/lib/user-management/interfaces/role.interface.d.ts +8 -0
- package/lib/user-management/serializers/authentication-response.serializer.js +2 -2
- package/lib/user-management/serializers/create-magic-auth-options.serializer.d.ts +2 -0
- package/lib/user-management/serializers/create-magic-auth-options.serializer.js +8 -0
- package/lib/user-management/serializers/index.d.ts +3 -0
- package/lib/user-management/serializers/index.js +3 -0
- package/lib/user-management/serializers/invitation.serializer.d.ts +2 -1
- package/lib/user-management/serializers/invitation.serializer.js +15 -1
- package/lib/user-management/serializers/magic-auth.serializer.d.ts +3 -0
- package/lib/user-management/serializers/magic-auth.serializer.js +24 -0
- package/lib/user-management/serializers/role.serializer.d.ts +2 -0
- package/lib/user-management/serializers/role.serializer.js +8 -0
- package/lib/user-management/user-management.d.ts +6 -1
- package/lib/user-management/user-management.js +15 -0
- package/lib/user-management/user-management.spec.js +55 -0
- package/lib/workos.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -37,6 +37,19 @@ const workos = new WorkOS('sk_1234');
|
|
|
37
37
|
|
|
38
38
|
For our SDKs WorkOS follows a Semantic Versioning ([SemVer](https://semver.org/)) process where all releases will have a version X.Y.Z (like 1.0.0) pattern wherein Z would be a bug fix (e.g., 1.0.1), Y would be a minor release (1.1.0) and X would be a major release (2.0.0). We permit any breaking changes to only be released in major versions and strongly recommend reading changelogs before making any major version upgrades.
|
|
39
39
|
|
|
40
|
+
## Beta Releases
|
|
41
|
+
|
|
42
|
+
WorkOS has features in Beta that can be accessed via Beta releases. We would love for you to try these
|
|
43
|
+
and share feedback with us before these features reach general availability (GA). To install a Beta version,
|
|
44
|
+
please follow the [installation steps](#installation) above using the Beta release version.
|
|
45
|
+
|
|
46
|
+
> Note: there can be breaking changes between Beta versions. Therefore, we recommend pinning the package version to a
|
|
47
|
+
> specific version. This way you can install the same version each time without breaking changes unless you are
|
|
48
|
+
> intentionally looking for the latest Beta version.
|
|
49
|
+
|
|
50
|
+
We highly recommend keeping an eye on when the Beta feature you are interested in goes from Beta to stable so that you
|
|
51
|
+
can move to using the stable version.
|
|
52
|
+
|
|
40
53
|
## More Information
|
|
41
54
|
|
|
42
55
|
- [Single Sign-On Guide](https://workos.com/docs/sso/guide)
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { DirectoryUser, DirectoryUserResponse, DirectoryGroup, DirectoryGroupResponse, EventDirectory, EventDirectoryResponse } from '../../directory-sync/interfaces';
|
|
2
2
|
import { Organization, OrganizationResponse } from '../../organizations/interfaces';
|
|
3
3
|
import { Connection, ConnectionResponse } from '../../sso/interfaces';
|
|
4
|
-
import { Session, SessionResponse, User, UserResponse } from '../../user-management/interfaces';
|
|
4
|
+
import { InvitationEvent, InvitationEventResponse, MagicAuthEvent, MagicAuthEventResponse, Session, SessionResponse, User, UserResponse } from '../../user-management/interfaces';
|
|
5
5
|
import { OrganizationMembership, OrganizationMembershipResponse } from '../../user-management/interfaces/organization-membership.interface';
|
|
6
|
+
import { RoleEvent, RoleEventResponse } from '../../user-management/interfaces/role.interface';
|
|
6
7
|
export interface EventBase {
|
|
7
8
|
id: string;
|
|
8
9
|
createdAt: string;
|
|
@@ -139,6 +140,22 @@ export interface DsyncUserUpdatedEventResponse extends EventResponseBase {
|
|
|
139
140
|
event: 'dsync.user.updated';
|
|
140
141
|
data: DirectoryUserResponse & Record<'previous_attributes', any>;
|
|
141
142
|
}
|
|
143
|
+
export interface InvitationCreatedEvent extends EventBase {
|
|
144
|
+
event: 'invitation.created';
|
|
145
|
+
data: InvitationEvent;
|
|
146
|
+
}
|
|
147
|
+
export interface InvitationCreatedEventResponse extends EventResponseBase {
|
|
148
|
+
event: 'invitation.created';
|
|
149
|
+
data: InvitationEventResponse;
|
|
150
|
+
}
|
|
151
|
+
export interface MagicAuthCreatedEvent extends EventBase {
|
|
152
|
+
event: 'magic_auth.created';
|
|
153
|
+
data: MagicAuthEvent;
|
|
154
|
+
}
|
|
155
|
+
export interface MagicAuthCreatedEventResponse extends EventResponseBase {
|
|
156
|
+
event: 'magic_auth.created';
|
|
157
|
+
data: MagicAuthEventResponse;
|
|
158
|
+
}
|
|
142
159
|
export interface UserCreatedEvent extends EventBase {
|
|
143
160
|
event: 'user.created';
|
|
144
161
|
data: User;
|
|
@@ -163,14 +180,36 @@ export interface UserDeletedEventResponse extends EventResponseBase {
|
|
|
163
180
|
event: 'user.deleted';
|
|
164
181
|
data: UserResponse;
|
|
165
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* @deprecated Use OrganizationMembershipCreated instead. Will be removed in a future major version.
|
|
185
|
+
*/
|
|
166
186
|
export interface OrganizationMembershipAdded extends EventBase {
|
|
167
187
|
event: 'organization_membership.added';
|
|
168
188
|
data: OrganizationMembership;
|
|
169
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* @deprecated Use OrganizationMembershipCreatedResponse instead. Will be removed in a future major version.
|
|
192
|
+
*/
|
|
170
193
|
export interface OrganizationMembershipAddedResponse extends EventResponseBase {
|
|
171
194
|
event: 'organization_membership.added';
|
|
172
195
|
data: OrganizationMembershipResponse;
|
|
173
196
|
}
|
|
197
|
+
export interface OrganizationMembershipCreated extends EventBase {
|
|
198
|
+
event: 'organization_membership.created';
|
|
199
|
+
data: OrganizationMembership;
|
|
200
|
+
}
|
|
201
|
+
export interface OrganizationMembershipCreatedResponse extends EventResponseBase {
|
|
202
|
+
event: 'organization_membership.created';
|
|
203
|
+
data: OrganizationMembershipResponse;
|
|
204
|
+
}
|
|
205
|
+
export interface OrganizationMembershipDeleted extends EventBase {
|
|
206
|
+
event: 'organization_membership.deleted';
|
|
207
|
+
data: OrganizationMembership;
|
|
208
|
+
}
|
|
209
|
+
export interface OrganizationMembershipDeletedResponse extends EventResponseBase {
|
|
210
|
+
event: 'organization_membership.deleted';
|
|
211
|
+
data: OrganizationMembershipResponse;
|
|
212
|
+
}
|
|
174
213
|
export interface OrganizationMembershipUpdated extends EventBase {
|
|
175
214
|
event: 'organization_membership.updated';
|
|
176
215
|
data: OrganizationMembership;
|
|
@@ -179,10 +218,16 @@ export interface OrganizationMembershipUpdatedResponse extends EventResponseBase
|
|
|
179
218
|
event: 'organization_membership.updated';
|
|
180
219
|
data: OrganizationMembershipResponse;
|
|
181
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* @deprecated Use OrganizationMembershipDeleted instead. Will be removed in a future major version.
|
|
223
|
+
*/
|
|
182
224
|
export interface OrganizationMembershipRemoved extends EventBase {
|
|
183
225
|
event: 'organization_membership.removed';
|
|
184
226
|
data: OrganizationMembership;
|
|
185
227
|
}
|
|
228
|
+
/**
|
|
229
|
+
* @deprecated Use OrganizationMembershipDeletedResponse instead. Will be removed in a future major version.
|
|
230
|
+
*/
|
|
186
231
|
export interface OrganizationMembershipRemovedResponse extends EventResponseBase {
|
|
187
232
|
event: 'organization_membership.removed';
|
|
188
233
|
data: OrganizationMembershipResponse;
|
|
@@ -211,6 +256,22 @@ export interface OrganizationDeletedResponse extends EventResponseBase {
|
|
|
211
256
|
event: 'organization.deleted';
|
|
212
257
|
data: OrganizationResponse;
|
|
213
258
|
}
|
|
259
|
+
export interface RoleCreatedEvent extends EventBase {
|
|
260
|
+
event: 'role.created';
|
|
261
|
+
data: RoleEvent;
|
|
262
|
+
}
|
|
263
|
+
export interface RoleCreatedEventResponse extends EventResponseBase {
|
|
264
|
+
event: 'role.created';
|
|
265
|
+
data: RoleEventResponse;
|
|
266
|
+
}
|
|
267
|
+
export interface RoleDeletedEvent extends EventBase {
|
|
268
|
+
event: 'role.deleted';
|
|
269
|
+
data: RoleEvent;
|
|
270
|
+
}
|
|
271
|
+
export interface RoleDeletedEventResponse extends EventResponseBase {
|
|
272
|
+
event: 'role.deleted';
|
|
273
|
+
data: RoleEventResponse;
|
|
274
|
+
}
|
|
214
275
|
export interface SessionCreatedEvent extends EventBase {
|
|
215
276
|
event: 'session.created';
|
|
216
277
|
data: Session;
|
|
@@ -219,7 +280,7 @@ export interface SessionCreatedEventResponse extends EventResponseBase {
|
|
|
219
280
|
event: 'session.created';
|
|
220
281
|
data: SessionResponse;
|
|
221
282
|
}
|
|
222
|
-
export type Event = ConnectionActivatedEvent | ConnectionDeactivatedEvent | ConnectionDeletedEvent | DsyncActivatedEvent | DsyncDeactivatedEvent | DsyncDeletedEvent | DsyncGroupCreatedEvent | DsyncGroupUpdatedEvent | DsyncGroupDeletedEvent | DsyncGroupUserAddedEvent | DsyncGroupUserRemovedEvent | DsyncUserCreatedEvent | DsyncUserUpdatedEvent | DsyncUserDeletedEvent | UserCreatedEvent | UserUpdatedEvent | UserDeletedEvent | OrganizationMembershipAdded | OrganizationMembershipUpdated | OrganizationMembershipRemoved | SessionCreatedEvent | OrganizationCreatedEvent | OrganizationUpdatedEvent | OrganizationDeletedEvent;
|
|
223
|
-
export type EventResponse = ConnectionActivatedEventResponse | ConnectionDeactivatedEventResponse | ConnectionDeletedEventResponse | DsyncActivatedEventResponse | DsyncDeactivatedEventResponse | DsyncDeletedEventResponse | DsyncGroupCreatedEventResponse | DsyncGroupUpdatedEventResponse | DsyncGroupDeletedEventResponse | DsyncGroupUserAddedEventResponse | DsyncGroupUserRemovedEventResponse | DsyncUserCreatedEventResponse | DsyncUserUpdatedEventResponse | DsyncUserDeletedEventResponse | UserCreatedEventResponse | UserUpdatedEventResponse | UserDeletedEventResponse | OrganizationMembershipAddedResponse | OrganizationMembershipUpdatedResponse | OrganizationMembershipRemovedResponse | SessionCreatedEventResponse | OrganizationCreatedResponse | OrganizationUpdatedResponse | OrganizationDeletedResponse;
|
|
283
|
+
export type Event = ConnectionActivatedEvent | ConnectionDeactivatedEvent | ConnectionDeletedEvent | DsyncActivatedEvent | DsyncDeactivatedEvent | DsyncDeletedEvent | DsyncGroupCreatedEvent | DsyncGroupUpdatedEvent | DsyncGroupDeletedEvent | DsyncGroupUserAddedEvent | DsyncGroupUserRemovedEvent | DsyncUserCreatedEvent | DsyncUserUpdatedEvent | DsyncUserDeletedEvent | InvitationCreatedEvent | MagicAuthCreatedEvent | UserCreatedEvent | UserUpdatedEvent | UserDeletedEvent | OrganizationMembershipAdded | OrganizationMembershipCreated | OrganizationMembershipDeleted | OrganizationMembershipUpdated | OrganizationMembershipRemoved | RoleCreatedEvent | RoleDeletedEvent | SessionCreatedEvent | OrganizationCreatedEvent | OrganizationUpdatedEvent | OrganizationDeletedEvent;
|
|
284
|
+
export type EventResponse = ConnectionActivatedEventResponse | ConnectionDeactivatedEventResponse | ConnectionDeletedEventResponse | DsyncActivatedEventResponse | DsyncDeactivatedEventResponse | DsyncDeletedEventResponse | DsyncGroupCreatedEventResponse | DsyncGroupUpdatedEventResponse | DsyncGroupDeletedEventResponse | DsyncGroupUserAddedEventResponse | DsyncGroupUserRemovedEventResponse | DsyncUserCreatedEventResponse | DsyncUserUpdatedEventResponse | DsyncUserDeletedEventResponse | InvitationCreatedEventResponse | MagicAuthCreatedEventResponse | UserCreatedEventResponse | UserUpdatedEventResponse | UserDeletedEventResponse | OrganizationMembershipAddedResponse | OrganizationMembershipCreatedResponse | OrganizationMembershipDeletedResponse | OrganizationMembershipUpdatedResponse | OrganizationMembershipRemovedResponse | RoleCreatedEventResponse | RoleDeletedEventResponse | SessionCreatedEventResponse | OrganizationCreatedResponse | OrganizationUpdatedResponse | OrganizationDeletedResponse;
|
|
224
285
|
export type EventName = Event['event'];
|
|
225
286
|
export {};
|
|
@@ -6,6 +6,7 @@ const serializers_2 = require("../../organizations/serializers");
|
|
|
6
6
|
const serializers_3 = require("../../sso/serializers");
|
|
7
7
|
const serializers_4 = require("../../user-management/serializers");
|
|
8
8
|
const organization_membership_serializer_1 = require("../../user-management/serializers/organization-membership.serializer");
|
|
9
|
+
const role_serializer_1 = require("../../user-management/serializers/role.serializer");
|
|
9
10
|
const session_serializer_1 = require("../../user-management/serializers/session.serializer");
|
|
10
11
|
const deserializeEvent = (event) => {
|
|
11
12
|
const eventBase = {
|
|
@@ -39,14 +40,23 @@ const deserializeEvent = (event) => {
|
|
|
39
40
|
return Object.assign(Object.assign({}, eventBase), { event: event.event, data: (0, serializers_1.deserializeDirectoryUser)(event.data) });
|
|
40
41
|
case 'dsync.user.updated':
|
|
41
42
|
return Object.assign(Object.assign({}, eventBase), { event: event.event, data: (0, serializers_1.deserializeUpdatedEventDirectoryUser)(event.data) });
|
|
43
|
+
case 'invitation.created':
|
|
44
|
+
return Object.assign(Object.assign({}, eventBase), { event: event.event, data: (0, serializers_4.deserializeInvitationEvent)(event.data) });
|
|
45
|
+
case 'magic_auth.created':
|
|
46
|
+
return Object.assign(Object.assign({}, eventBase), { event: event.event, data: (0, serializers_4.deserializeMagicAuthEvent)(event.data) });
|
|
42
47
|
case 'user.created':
|
|
43
48
|
case 'user.updated':
|
|
44
49
|
case 'user.deleted':
|
|
45
50
|
return Object.assign(Object.assign({}, eventBase), { event: event.event, data: (0, serializers_4.deserializeUser)(event.data) });
|
|
46
51
|
case 'organization_membership.added':
|
|
52
|
+
case 'organization_membership.created':
|
|
53
|
+
case 'organization_membership.deleted':
|
|
47
54
|
case 'organization_membership.updated':
|
|
48
55
|
case 'organization_membership.removed':
|
|
49
56
|
return Object.assign(Object.assign({}, eventBase), { event: event.event, data: (0, organization_membership_serializer_1.deserializeOrganizationMembership)(event.data) });
|
|
57
|
+
case 'role.created':
|
|
58
|
+
case 'role.deleted':
|
|
59
|
+
return Object.assign(Object.assign({}, eventBase), { event: event.event, data: (0, role_serializer_1.deserializeRole)(event.data) });
|
|
50
60
|
case 'session.created':
|
|
51
61
|
return Object.assign(Object.assign({}, eventBase), { event: event.event, data: (0, session_serializer_1.deserializeSession)(event.data) });
|
|
52
62
|
case 'organization.created':
|
|
@@ -94,5 +94,17 @@ describe('Event', () => {
|
|
|
94
94
|
listMetadata: {},
|
|
95
95
|
});
|
|
96
96
|
}));
|
|
97
|
+
it(`requests Events with a valid organization id`, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
98
|
+
(0, test_utils_1.fetchOnce)(eventsListResponse);
|
|
99
|
+
const list = yield workos.events.listEvents({
|
|
100
|
+
events: ['connection.activated'],
|
|
101
|
+
organizationId: 'org_1234',
|
|
102
|
+
});
|
|
103
|
+
expect(list).toEqual({
|
|
104
|
+
object: 'list',
|
|
105
|
+
data: [event],
|
|
106
|
+
listMetadata: {},
|
|
107
|
+
});
|
|
108
|
+
}));
|
|
97
109
|
});
|
|
98
110
|
});
|
|
@@ -5,6 +5,7 @@ export interface ListEventOptions {
|
|
|
5
5
|
rangeEnd?: string;
|
|
6
6
|
limit?: number;
|
|
7
7
|
after?: string;
|
|
8
|
+
organizationId?: string;
|
|
8
9
|
}
|
|
9
10
|
export interface SerializedListEventOptions {
|
|
10
11
|
events: EventName[];
|
|
@@ -12,4 +13,5 @@ export interface SerializedListEventOptions {
|
|
|
12
13
|
range_end?: string;
|
|
13
14
|
limit?: number;
|
|
14
15
|
after?: string;
|
|
16
|
+
organization_id?: string;
|
|
15
17
|
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.serializeListEventOptions = void 0;
|
|
4
4
|
const serializeListEventOptions = (options) => ({
|
|
5
5
|
events: options.events,
|
|
6
|
+
organization_id: options.organizationId,
|
|
6
7
|
range_start: options.rangeStart,
|
|
7
8
|
range_end: options.rangeEnd,
|
|
8
9
|
limit: options.limit,
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import { PostOptions } from '../../common/interfaces';
|
|
2
|
+
import { DomainData } from './domain-data.interface';
|
|
2
3
|
export interface CreateOrganizationOptions {
|
|
3
4
|
name: string;
|
|
4
5
|
allowProfilesOutsideOrganization?: boolean;
|
|
6
|
+
domainData?: DomainData[];
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use `domain_data` instead.
|
|
9
|
+
*/
|
|
5
10
|
domains?: string[];
|
|
6
11
|
}
|
|
7
12
|
export interface SerializedCreateOrganizationOptions {
|
|
8
13
|
name: string;
|
|
9
14
|
allow_profiles_outside_organization?: boolean;
|
|
15
|
+
domain_data?: DomainData[];
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Use `domain_data` instead.
|
|
18
|
+
*/
|
|
10
19
|
domains?: string[];
|
|
11
20
|
}
|
|
12
21
|
export interface CreateOrganizationRequestOptions extends Pick<PostOptions, 'idempotencyKey'> {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DomainDataState = void 0;
|
|
4
|
+
// These are the only possible states to create an organization domain with
|
|
5
|
+
var DomainDataState;
|
|
6
|
+
(function (DomainDataState) {
|
|
7
|
+
DomainDataState["Verified"] = "verified";
|
|
8
|
+
DomainDataState["Pending"] = "pending";
|
|
9
|
+
})(DomainDataState || (exports.DomainDataState = DomainDataState = {}));
|
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./create-organization-options.interface"), exports);
|
|
18
|
+
__exportStar(require("./domain-data.interface"), exports);
|
|
18
19
|
__exportStar(require("./list-organizations-options.interface"), exports);
|
|
19
20
|
__exportStar(require("./organization-domain.interface"), exports);
|
|
20
21
|
__exportStar(require("./organization.interface"), exports);
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
+
import { DomainData } from './domain-data.interface';
|
|
1
2
|
export interface UpdateOrganizationOptions {
|
|
2
3
|
organization: string;
|
|
3
4
|
name: string;
|
|
4
5
|
allowProfilesOutsideOrganization?: boolean;
|
|
6
|
+
domainData?: DomainData[];
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use `domain_data` instead.
|
|
9
|
+
*/
|
|
5
10
|
domains?: string[];
|
|
6
11
|
}
|
|
7
12
|
export interface SerializedUpdateOrganizationOptions {
|
|
8
13
|
name: string;
|
|
9
14
|
allow_profiles_outside_organization?: boolean;
|
|
15
|
+
domain_data?: DomainData[];
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Use `domain_data` instead.
|
|
18
|
+
*/
|
|
10
19
|
domains?: string[];
|
|
11
20
|
}
|
|
@@ -20,6 +20,7 @@ const create_organization_json_1 = __importDefault(require("./fixtures/create-or
|
|
|
20
20
|
const get_organization_json_1 = __importDefault(require("./fixtures/get-organization.json"));
|
|
21
21
|
const list_organizations_json_1 = __importDefault(require("./fixtures/list-organizations.json"));
|
|
22
22
|
const update_organization_json_1 = __importDefault(require("./fixtures/update-organization.json"));
|
|
23
|
+
const interfaces_1 = require("./interfaces");
|
|
23
24
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
24
25
|
describe('Organizations', () => {
|
|
25
26
|
beforeEach(() => jest_fetch_mock_1.default.resetMocks());
|
|
@@ -116,20 +117,40 @@ describe('Organizations', () => {
|
|
|
116
117
|
}));
|
|
117
118
|
});
|
|
118
119
|
describe('with a valid payload', () => {
|
|
119
|
-
|
|
120
|
-
(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
120
|
+
describe('with `domains`', () => {
|
|
121
|
+
it('creates an organization', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
122
|
+
(0, test_utils_1.fetchOnce)(create_organization_json_1.default, { status: 201 });
|
|
123
|
+
const subject = yield workos.organizations.createOrganization({
|
|
124
|
+
domains: ['example.com'],
|
|
125
|
+
name: 'Test Organization',
|
|
126
|
+
});
|
|
127
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
128
|
+
domains: ['example.com'],
|
|
129
|
+
name: 'Test Organization',
|
|
130
|
+
});
|
|
131
|
+
expect(subject.id).toEqual('org_01EHT88Z8J8795GZNQ4ZP1J81T');
|
|
132
|
+
expect(subject.name).toEqual('Test Organization');
|
|
133
|
+
expect(subject.domains).toHaveLength(1);
|
|
134
|
+
}));
|
|
135
|
+
});
|
|
136
|
+
describe('with `domain_data`', () => {
|
|
137
|
+
it('creates an organization', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
138
|
+
(0, test_utils_1.fetchOnce)(create_organization_json_1.default, { status: 201 });
|
|
139
|
+
const subject = yield workos.organizations.createOrganization({
|
|
140
|
+
domainData: [
|
|
141
|
+
{ domain: 'example.com', state: interfaces_1.DomainDataState.Verified },
|
|
142
|
+
],
|
|
143
|
+
name: 'Test Organization',
|
|
144
|
+
});
|
|
145
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
146
|
+
domain_data: [{ domain: 'example.com', state: 'verified' }],
|
|
147
|
+
name: 'Test Organization',
|
|
148
|
+
});
|
|
149
|
+
expect(subject.id).toEqual('org_01EHT88Z8J8795GZNQ4ZP1J81T');
|
|
150
|
+
expect(subject.name).toEqual('Test Organization');
|
|
151
|
+
expect(subject.domains).toHaveLength(1);
|
|
152
|
+
}));
|
|
153
|
+
});
|
|
133
154
|
});
|
|
134
155
|
describe('with an invalid payload', () => {
|
|
135
156
|
it('returns an error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -170,21 +191,42 @@ describe('Organizations', () => {
|
|
|
170
191
|
});
|
|
171
192
|
describe('updateOrganization', () => {
|
|
172
193
|
describe('with a valid payload', () => {
|
|
173
|
-
|
|
174
|
-
(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
194
|
+
describe('with `domains', () => {
|
|
195
|
+
it('updates an organization', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
196
|
+
(0, test_utils_1.fetchOnce)(update_organization_json_1.default, { status: 201 });
|
|
197
|
+
const subject = yield workos.organizations.updateOrganization({
|
|
198
|
+
organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
|
|
199
|
+
domains: ['example.com'],
|
|
200
|
+
name: 'Test Organization 2',
|
|
201
|
+
});
|
|
202
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
203
|
+
domains: ['example.com'],
|
|
204
|
+
name: 'Test Organization 2',
|
|
205
|
+
});
|
|
206
|
+
expect(subject.id).toEqual('org_01EHT88Z8J8795GZNQ4ZP1J81T');
|
|
207
|
+
expect(subject.name).toEqual('Test Organization 2');
|
|
208
|
+
expect(subject.domains).toHaveLength(1);
|
|
209
|
+
}));
|
|
210
|
+
});
|
|
211
|
+
describe('with `domain_data`', () => {
|
|
212
|
+
it('updates an organization', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
213
|
+
(0, test_utils_1.fetchOnce)(update_organization_json_1.default, { status: 201 });
|
|
214
|
+
const subject = yield workos.organizations.updateOrganization({
|
|
215
|
+
organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
|
|
216
|
+
domainData: [
|
|
217
|
+
{ domain: 'example.com', state: interfaces_1.DomainDataState.Verified },
|
|
218
|
+
],
|
|
219
|
+
name: 'Test Organization 2',
|
|
220
|
+
});
|
|
221
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
222
|
+
domain_data: [{ domain: 'example.com', state: 'verified' }],
|
|
223
|
+
name: 'Test Organization 2',
|
|
224
|
+
});
|
|
225
|
+
expect(subject.id).toEqual('org_01EHT88Z8J8795GZNQ4ZP1J81T');
|
|
226
|
+
expect(subject.name).toEqual('Test Organization 2');
|
|
227
|
+
expect(subject.domains).toHaveLength(1);
|
|
228
|
+
}));
|
|
229
|
+
});
|
|
188
230
|
});
|
|
189
231
|
});
|
|
190
232
|
});
|
|
@@ -4,6 +4,7 @@ exports.serializeCreateOrganizationOptions = void 0;
|
|
|
4
4
|
const serializeCreateOrganizationOptions = (options) => ({
|
|
5
5
|
name: options.name,
|
|
6
6
|
allow_profiles_outside_organization: options.allowProfilesOutsideOrganization,
|
|
7
|
+
domain_data: options.domainData,
|
|
7
8
|
domains: options.domains,
|
|
8
9
|
});
|
|
9
10
|
exports.serializeCreateOrganizationOptions = serializeCreateOrganizationOptions;
|
|
@@ -4,6 +4,7 @@ exports.serializeUpdateOrganizationOptions = void 0;
|
|
|
4
4
|
const serializeUpdateOrganizationOptions = (options) => ({
|
|
5
5
|
name: options.name,
|
|
6
6
|
allow_profiles_outside_organization: options.allowProfilesOutsideOrganization,
|
|
7
|
+
domain_data: options.domainData,
|
|
7
8
|
domains: options.domains,
|
|
8
9
|
});
|
|
9
10
|
exports.serializeUpdateOrganizationOptions = serializeUpdateOrganizationOptions;
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"expires_at": "2023-07-18T02:07:19.911Z",
|
|
9
9
|
"organization_id": "org_01H5JQDV7R7ATEYZDEG0W5PRYS",
|
|
10
10
|
"token": "Z1uX3RbwcIl5fIGJJJCXXisdI",
|
|
11
|
+
"accept_invitation_url": "https://myauthkit.com/invite?invitation_token=Z1uX3RbwcIl5fIGJJJCXXisdI",
|
|
11
12
|
"created_at": "2023-07-18T02:07:19.911Z",
|
|
12
13
|
"updated_at": "2023-07-18T02:07:19.911Z"
|
|
13
14
|
}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"expires_at": "2023-07-18T02:07:19.911Z",
|
|
12
12
|
"organization_id": "org_01H5JQDV7R7ATEYZDEG0W5PRYS",
|
|
13
13
|
"token": "Z1uX3RbwcIl5fIGJJJCXXisdI",
|
|
14
|
+
"accept_invitation_url": "https://myauthkit.com/invite?invitation_token=Z1uX3RbwcIl5fIGJJJCXXisdI",
|
|
14
15
|
"created_at": "2023-07-18T02:07:19.911Z",
|
|
15
16
|
"updated_at": "2023-07-18T02:07:19.911Z"
|
|
16
17
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"object": "magic_auth",
|
|
3
|
+
"id": "magic_auth_01H5JQDV7R7ATEYZDEG0W5PRYS",
|
|
4
|
+
"user_id": "user_01H5JQDV7R7ATEYZDEG0W5PRYS",
|
|
5
|
+
"email": "dane@workos.com",
|
|
6
|
+
"expires_at": "2023-07-18T02:07:19.911Z",
|
|
7
|
+
"code": "123456",
|
|
8
|
+
"created_at": "2023-07-18T02:07:19.911Z",
|
|
9
|
+
"updated_at": "2023-07-18T02:07:19.911Z"
|
|
10
|
+
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Impersonator, ImpersonatorResponse } from './impersonator.interface';
|
|
2
2
|
import { User, UserResponse } from './user.interface';
|
|
3
|
+
type AuthenticationMethod = 'SSO' | 'Password' | 'GitHubOAuth' | 'GoogleOAuth' | 'MicrosoftOAuth' | 'MagicAuth' | 'Impersonation';
|
|
3
4
|
export interface AuthenticationResponse {
|
|
4
5
|
user: User;
|
|
5
6
|
organizationId?: string;
|
|
6
7
|
accessToken: string;
|
|
7
8
|
refreshToken: string;
|
|
8
9
|
impersonator?: Impersonator;
|
|
10
|
+
authenticationMethod?: AuthenticationMethod;
|
|
9
11
|
}
|
|
10
12
|
export interface AuthenticationResponseResponse {
|
|
11
13
|
user: UserResponse;
|
|
@@ -13,6 +15,7 @@ export interface AuthenticationResponseResponse {
|
|
|
13
15
|
access_token: string;
|
|
14
16
|
refresh_token: string;
|
|
15
17
|
impersonator?: ImpersonatorResponse;
|
|
18
|
+
authentication_method?: AuthenticationMethod;
|
|
16
19
|
}
|
|
17
20
|
export interface RefreshAuthenticationResponse {
|
|
18
21
|
accessToken: string;
|
|
@@ -22,3 +25,4 @@ export interface RefreshAuthenticationResponseResponse {
|
|
|
22
25
|
access_token: string;
|
|
23
26
|
refresh_token: string;
|
|
24
27
|
}
|
|
28
|
+
export {};
|
|
@@ -9,6 +9,7 @@ export * from './authenticate-with-password-options.interface';
|
|
|
9
9
|
export * from './authenticate-with-refresh-token-options.interface';
|
|
10
10
|
export * from './authenticate-with-totp-options.interface';
|
|
11
11
|
export * from './authentication-response.interface';
|
|
12
|
+
export * from './create-magic-auth-options.interface';
|
|
12
13
|
export * from './create-organization-membership-options.interface';
|
|
13
14
|
export * from './create-user-options.interface';
|
|
14
15
|
export * from './enroll-auth-factor.interface';
|
|
@@ -19,6 +20,7 @@ export * from './list-auth-factors-options.interface';
|
|
|
19
20
|
export * from './list-invitations-options.interface';
|
|
20
21
|
export * from './list-organization-memberships-options.interface';
|
|
21
22
|
export * from './list-users-options.interface';
|
|
23
|
+
export * from './magic-auth.interface';
|
|
22
24
|
export * from './organization-membership.interface';
|
|
23
25
|
export * from './reset-password-options.interface';
|
|
24
26
|
export * from './revoke-session-options.interface';
|
|
@@ -33,3 +35,4 @@ export * from './update-user-options.interface';
|
|
|
33
35
|
export * from './update-user-password-options.interface';
|
|
34
36
|
export * from './user.interface';
|
|
35
37
|
export * from './verify-email-options.interface';
|
|
38
|
+
export * from './role.interface';
|
|
@@ -25,6 +25,7 @@ __exportStar(require("./authenticate-with-password-options.interface"), exports)
|
|
|
25
25
|
__exportStar(require("./authenticate-with-refresh-token-options.interface"), exports);
|
|
26
26
|
__exportStar(require("./authenticate-with-totp-options.interface"), exports);
|
|
27
27
|
__exportStar(require("./authentication-response.interface"), exports);
|
|
28
|
+
__exportStar(require("./create-magic-auth-options.interface"), exports);
|
|
28
29
|
__exportStar(require("./create-organization-membership-options.interface"), exports);
|
|
29
30
|
__exportStar(require("./create-user-options.interface"), exports);
|
|
30
31
|
__exportStar(require("./enroll-auth-factor.interface"), exports);
|
|
@@ -35,6 +36,7 @@ __exportStar(require("./list-auth-factors-options.interface"), exports);
|
|
|
35
36
|
__exportStar(require("./list-invitations-options.interface"), exports);
|
|
36
37
|
__exportStar(require("./list-organization-memberships-options.interface"), exports);
|
|
37
38
|
__exportStar(require("./list-users-options.interface"), exports);
|
|
39
|
+
__exportStar(require("./magic-auth.interface"), exports);
|
|
38
40
|
__exportStar(require("./organization-membership.interface"), exports);
|
|
39
41
|
__exportStar(require("./reset-password-options.interface"), exports);
|
|
40
42
|
__exportStar(require("./revoke-session-options.interface"), exports);
|
|
@@ -49,3 +51,4 @@ __exportStar(require("./update-user-options.interface"), exports);
|
|
|
49
51
|
__exportStar(require("./update-user-password-options.interface"), exports);
|
|
50
52
|
__exportStar(require("./user.interface"), exports);
|
|
51
53
|
__exportStar(require("./verify-email-options.interface"), exports);
|
|
54
|
+
__exportStar(require("./role.interface"), exports);
|
|
@@ -8,6 +8,19 @@ export interface Invitation {
|
|
|
8
8
|
expiresAt: string;
|
|
9
9
|
organizationId: string | null;
|
|
10
10
|
token: string;
|
|
11
|
+
acceptInvitationUrl: string;
|
|
12
|
+
createdAt: string;
|
|
13
|
+
updatedAt: string;
|
|
14
|
+
}
|
|
15
|
+
export interface InvitationEvent {
|
|
16
|
+
object: 'invitation';
|
|
17
|
+
id: string;
|
|
18
|
+
email: string;
|
|
19
|
+
state: 'pending' | 'accepted' | 'expired' | 'revoked';
|
|
20
|
+
acceptedAt: string | null;
|
|
21
|
+
revokedAt: string | null;
|
|
22
|
+
expiresAt: string;
|
|
23
|
+
organizationId: string | null;
|
|
11
24
|
createdAt: string;
|
|
12
25
|
updatedAt: string;
|
|
13
26
|
}
|
|
@@ -21,6 +34,19 @@ export interface InvitationResponse {
|
|
|
21
34
|
expires_at: string;
|
|
22
35
|
organization_id: string | null;
|
|
23
36
|
token: string;
|
|
37
|
+
accept_invitation_url: string;
|
|
38
|
+
created_at: string;
|
|
39
|
+
updated_at: string;
|
|
40
|
+
}
|
|
41
|
+
export interface InvitationEventResponse {
|
|
42
|
+
object: 'invitation';
|
|
43
|
+
id: string;
|
|
44
|
+
email: string;
|
|
45
|
+
state: 'pending' | 'accepted' | 'expired' | 'revoked';
|
|
46
|
+
accepted_at: string | null;
|
|
47
|
+
revoked_at: string | null;
|
|
48
|
+
expires_at: string;
|
|
49
|
+
organization_id: string | null;
|
|
24
50
|
created_at: string;
|
|
25
51
|
updated_at: string;
|
|
26
52
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface MagicAuth {
|
|
2
|
+
object: 'magic_auth';
|
|
3
|
+
id: string;
|
|
4
|
+
userId: string;
|
|
5
|
+
email: string;
|
|
6
|
+
expiresAt: string;
|
|
7
|
+
code: string;
|
|
8
|
+
createdAt: string;
|
|
9
|
+
updatedAt: string;
|
|
10
|
+
}
|
|
11
|
+
export interface MagicAuthEvent {
|
|
12
|
+
object: 'magic_auth';
|
|
13
|
+
id: string;
|
|
14
|
+
userId: string;
|
|
15
|
+
email: string;
|
|
16
|
+
expiresAt: string;
|
|
17
|
+
createdAt: string;
|
|
18
|
+
updatedAt: string;
|
|
19
|
+
}
|
|
20
|
+
export interface MagicAuthResponse {
|
|
21
|
+
object: 'magic_auth';
|
|
22
|
+
id: string;
|
|
23
|
+
user_id: string;
|
|
24
|
+
email: string;
|
|
25
|
+
expires_at: string;
|
|
26
|
+
code: string;
|
|
27
|
+
created_at: string;
|
|
28
|
+
updated_at: string;
|
|
29
|
+
}
|
|
30
|
+
export interface MagicAuthEventResponse {
|
|
31
|
+
object: 'magic_auth';
|
|
32
|
+
id: string;
|
|
33
|
+
user_id: string;
|
|
34
|
+
email: string;
|
|
35
|
+
expires_at: string;
|
|
36
|
+
created_at: string;
|
|
37
|
+
updated_at: string;
|
|
38
|
+
}
|
|
@@ -14,8 +14,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.deserializeRefreshAuthenticationResponse = exports.deserializeAuthenticationResponse = void 0;
|
|
15
15
|
const user_serializer_1 = require("./user.serializer");
|
|
16
16
|
const deserializeAuthenticationResponse = (authenticationResponse) => {
|
|
17
|
-
const { user, organization_id, access_token, refresh_token, impersonator } = authenticationResponse, rest = __rest(authenticationResponse, ["user", "organization_id", "access_token", "refresh_token", "impersonator"]);
|
|
18
|
-
return Object.assign({ user: (0, user_serializer_1.deserializeUser)(user), organizationId: organization_id, accessToken: access_token, refreshToken: refresh_token, impersonator }, rest);
|
|
17
|
+
const { user, organization_id, access_token, refresh_token, authentication_method, impersonator } = authenticationResponse, rest = __rest(authenticationResponse, ["user", "organization_id", "access_token", "refresh_token", "authentication_method", "impersonator"]);
|
|
18
|
+
return Object.assign({ user: (0, user_serializer_1.deserializeUser)(user), organizationId: organization_id, accessToken: access_token, refreshToken: refresh_token, impersonator, authenticationMethod: authentication_method }, rest);
|
|
19
19
|
};
|
|
20
20
|
exports.deserializeAuthenticationResponse = deserializeAuthenticationResponse;
|
|
21
21
|
const deserializeRefreshAuthenticationResponse = (refreshAuthenticationResponse) => {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeCreateMagicAuthOptions = void 0;
|
|
4
|
+
const serializeCreateMagicAuthOptions = (options) => ({
|
|
5
|
+
email: options.email,
|
|
6
|
+
invitation_token: options.invitationToken,
|
|
7
|
+
});
|
|
8
|
+
exports.serializeCreateMagicAuthOptions = serializeCreateMagicAuthOptions;
|
|
@@ -4,8 +4,11 @@ export * from './authenticate-with-password-options.serializer';
|
|
|
4
4
|
export * from './authenticate-with-refresh-token.options.serializer';
|
|
5
5
|
export * from './authenticate-with-totp-options.serializer';
|
|
6
6
|
export * from './authentication-response.serializer';
|
|
7
|
+
export * from './create-magic-auth-options.serializer';
|
|
7
8
|
export * from './enroll-auth-factor-options.serializer';
|
|
8
9
|
export * from './factor.serializer';
|
|
10
|
+
export * from './invitation.serializer';
|
|
11
|
+
export * from './magic-auth.serializer';
|
|
9
12
|
export * from './reset-password-options.serializer';
|
|
10
13
|
export * from './send-password-reset-email.serializer';
|
|
11
14
|
export * from './create-user-options.serializer';
|
|
@@ -20,8 +20,11 @@ __exportStar(require("./authenticate-with-password-options.serializer"), exports
|
|
|
20
20
|
__exportStar(require("./authenticate-with-refresh-token.options.serializer"), exports);
|
|
21
21
|
__exportStar(require("./authenticate-with-totp-options.serializer"), exports);
|
|
22
22
|
__exportStar(require("./authentication-response.serializer"), exports);
|
|
23
|
+
__exportStar(require("./create-magic-auth-options.serializer"), exports);
|
|
23
24
|
__exportStar(require("./enroll-auth-factor-options.serializer"), exports);
|
|
24
25
|
__exportStar(require("./factor.serializer"), exports);
|
|
26
|
+
__exportStar(require("./invitation.serializer"), exports);
|
|
27
|
+
__exportStar(require("./magic-auth.serializer"), exports);
|
|
25
28
|
__exportStar(require("./reset-password-options.serializer"), exports);
|
|
26
29
|
__exportStar(require("./send-password-reset-email.serializer"), exports);
|
|
27
30
|
__exportStar(require("./create-user-options.serializer"), exports);
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { Invitation, InvitationResponse } from '../interfaces/invitation.interface';
|
|
1
|
+
import { Invitation, InvitationEvent, InvitationEventResponse, InvitationResponse } from '../interfaces/invitation.interface';
|
|
2
2
|
export declare const deserializeInvitation: (invitation: InvitationResponse) => Invitation;
|
|
3
|
+
export declare const deserializeInvitationEvent: (invitation: InvitationEventResponse) => InvitationEvent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deserializeInvitation = void 0;
|
|
3
|
+
exports.deserializeInvitationEvent = exports.deserializeInvitation = void 0;
|
|
4
4
|
const deserializeInvitation = (invitation) => ({
|
|
5
5
|
object: invitation.object,
|
|
6
6
|
id: invitation.id,
|
|
@@ -11,7 +11,21 @@ const deserializeInvitation = (invitation) => ({
|
|
|
11
11
|
expiresAt: invitation.expires_at,
|
|
12
12
|
organizationId: invitation.organization_id,
|
|
13
13
|
token: invitation.token,
|
|
14
|
+
acceptInvitationUrl: invitation.accept_invitation_url,
|
|
14
15
|
createdAt: invitation.created_at,
|
|
15
16
|
updatedAt: invitation.updated_at,
|
|
16
17
|
});
|
|
17
18
|
exports.deserializeInvitation = deserializeInvitation;
|
|
19
|
+
const deserializeInvitationEvent = (invitation) => ({
|
|
20
|
+
object: invitation.object,
|
|
21
|
+
id: invitation.id,
|
|
22
|
+
email: invitation.email,
|
|
23
|
+
state: invitation.state,
|
|
24
|
+
acceptedAt: invitation.accepted_at,
|
|
25
|
+
revokedAt: invitation.revoked_at,
|
|
26
|
+
expiresAt: invitation.expires_at,
|
|
27
|
+
organizationId: invitation.organization_id,
|
|
28
|
+
createdAt: invitation.created_at,
|
|
29
|
+
updatedAt: invitation.updated_at,
|
|
30
|
+
});
|
|
31
|
+
exports.deserializeInvitationEvent = deserializeInvitationEvent;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { MagicAuth, MagicAuthEvent, MagicAuthEventResponse, MagicAuthResponse } from '../interfaces/magic-auth.interface';
|
|
2
|
+
export declare const deserializeMagicAuth: (magicAuth: MagicAuthResponse) => MagicAuth;
|
|
3
|
+
export declare const deserializeMagicAuthEvent: (magicAuth: MagicAuthEventResponse) => MagicAuthEvent;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeMagicAuthEvent = exports.deserializeMagicAuth = void 0;
|
|
4
|
+
const deserializeMagicAuth = (magicAuth) => ({
|
|
5
|
+
object: magicAuth.object,
|
|
6
|
+
id: magicAuth.id,
|
|
7
|
+
userId: magicAuth.user_id,
|
|
8
|
+
email: magicAuth.email,
|
|
9
|
+
expiresAt: magicAuth.expires_at,
|
|
10
|
+
code: magicAuth.code,
|
|
11
|
+
createdAt: magicAuth.created_at,
|
|
12
|
+
updatedAt: magicAuth.updated_at,
|
|
13
|
+
});
|
|
14
|
+
exports.deserializeMagicAuth = deserializeMagicAuth;
|
|
15
|
+
const deserializeMagicAuthEvent = (magicAuth) => ({
|
|
16
|
+
object: magicAuth.object,
|
|
17
|
+
id: magicAuth.id,
|
|
18
|
+
userId: magicAuth.user_id,
|
|
19
|
+
email: magicAuth.email,
|
|
20
|
+
expiresAt: magicAuth.expires_at,
|
|
21
|
+
createdAt: magicAuth.created_at,
|
|
22
|
+
updatedAt: magicAuth.updated_at,
|
|
23
|
+
});
|
|
24
|
+
exports.deserializeMagicAuthEvent = deserializeMagicAuthEvent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WorkOS } from '../workos';
|
|
2
2
|
import { AutoPaginatable } from '../common/utils/pagination';
|
|
3
|
-
import { AuthenticateWithCodeOptions, AuthenticateWithMagicAuthOptions, AuthenticateWithPasswordOptions, AuthenticateWithTotpOptions, AuthenticationResponse, ResetPasswordOptions, SendPasswordResetEmailOptions, CreateUserOptions, EnrollAuthFactorOptions, ListAuthFactorsOptions, ListUsersOptions, SendMagicAuthCodeOptions, SendVerificationEmailOptions, UpdateUserOptions, User, VerifyEmailOptions, AuthenticateWithRefreshTokenOptions, RefreshAuthenticationResponse } from './interfaces';
|
|
3
|
+
import { AuthenticateWithCodeOptions, AuthenticateWithMagicAuthOptions, AuthenticateWithPasswordOptions, AuthenticateWithTotpOptions, AuthenticationResponse, ResetPasswordOptions, SendPasswordResetEmailOptions, CreateUserOptions, EnrollAuthFactorOptions, ListAuthFactorsOptions, ListUsersOptions, SendMagicAuthCodeOptions, SendVerificationEmailOptions, UpdateUserOptions, User, VerifyEmailOptions, AuthenticateWithRefreshTokenOptions, RefreshAuthenticationResponse, MagicAuth, CreateMagicAuthOptions } from './interfaces';
|
|
4
4
|
import { Challenge } from '../mfa/interfaces';
|
|
5
5
|
import { OrganizationMembership } from './interfaces/organization-membership.interface';
|
|
6
6
|
import { ListOrganizationMembershipsOptions } from './interfaces/list-organization-memberships-options.interface';
|
|
@@ -30,6 +30,11 @@ export declare class UserManagement {
|
|
|
30
30
|
sendVerificationEmail({ userId, }: SendVerificationEmailOptions): Promise<{
|
|
31
31
|
user: User;
|
|
32
32
|
}>;
|
|
33
|
+
getMagicAuth(magicAuthId: string): Promise<MagicAuth>;
|
|
34
|
+
createMagicAuth(options: CreateMagicAuthOptions): Promise<MagicAuth>;
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated Please use `createMagicAuth` instead. This method will be removed in a future major version.
|
|
37
|
+
*/
|
|
33
38
|
sendMagicAuthCode(options: SendMagicAuthCodeOptions): Promise<void>;
|
|
34
39
|
verifyEmail({ code, userId, }: VerifyEmailOptions): Promise<{
|
|
35
40
|
user: User;
|
|
@@ -106,6 +106,21 @@ class UserManagement {
|
|
|
106
106
|
return { user: (0, serializers_1.deserializeUser)(data.user) };
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
|
+
getMagicAuth(magicAuthId) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
const { data } = yield this.workos.get(`/user_management/magic_auth/${magicAuthId}`);
|
|
112
|
+
return (0, serializers_1.deserializeMagicAuth)(data);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
createMagicAuth(options) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
const { data } = yield this.workos.post('/user_management/magic_auth', (0, serializers_1.serializeCreateMagicAuthOptions)(Object.assign({}, options)));
|
|
118
|
+
return (0, serializers_1.deserializeMagicAuth)(data);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* @deprecated Please use `createMagicAuth` instead. This method will be removed in a future major version.
|
|
123
|
+
*/
|
|
109
124
|
sendMagicAuthCode(options) {
|
|
110
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
126
|
yield this.workos.post('/user_management/magic_auth/send', (0, serializers_1.serializeSendMagicAuthCodeOptions)(options));
|
|
@@ -22,10 +22,12 @@ const organization_membership_json_1 = __importDefault(require("./fixtures/organ
|
|
|
22
22
|
const list_organization_memberships_json_1 = __importDefault(require("./fixtures/list-organization-memberships.json"));
|
|
23
23
|
const invitation_json_1 = __importDefault(require("./fixtures/invitation.json"));
|
|
24
24
|
const list_invitations_json_1 = __importDefault(require("./fixtures/list-invitations.json"));
|
|
25
|
+
const magic_auth_json_1 = __importDefault(require("./fixtures/magic_auth.json"));
|
|
25
26
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
26
27
|
const userId = 'user_01H5JQDV7R7ATEYZDEG0W5PRYS';
|
|
27
28
|
const organizationMembershipId = 'om_01H5JQDV7R7ATEYZDEG0W5PRYS';
|
|
28
29
|
const invitationId = 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS';
|
|
30
|
+
const magicAuthId = 'magic_auth_01H5JQDV7R7ATEYZDEG0W5PRYS';
|
|
29
31
|
describe('UserManagement', () => {
|
|
30
32
|
beforeEach(() => jest_fetch_mock_1.default.resetMocks());
|
|
31
33
|
describe('getUser', () => {
|
|
@@ -155,6 +157,22 @@ describe('UserManagement', () => {
|
|
|
155
157
|
},
|
|
156
158
|
});
|
|
157
159
|
}));
|
|
160
|
+
it('deserializes authentication_method', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
161
|
+
(0, test_utils_1.fetchOnce)({
|
|
162
|
+
user: user_json_1.default,
|
|
163
|
+
authentication_method: 'Password',
|
|
164
|
+
});
|
|
165
|
+
const resp = yield workos.userManagement.authenticateWithCode({
|
|
166
|
+
clientId: 'proj_whatever',
|
|
167
|
+
code: 'or this',
|
|
168
|
+
});
|
|
169
|
+
expect(resp).toMatchObject({
|
|
170
|
+
user: {
|
|
171
|
+
email: 'test01@example.com',
|
|
172
|
+
},
|
|
173
|
+
authenticationMethod: 'Password',
|
|
174
|
+
});
|
|
175
|
+
}));
|
|
158
176
|
describe('when the code is for an impersonator', () => {
|
|
159
177
|
it('deserializes the impersonator metadata', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
160
178
|
(0, test_utils_1.fetchOnce)({
|
|
@@ -308,6 +326,43 @@ describe('UserManagement', () => {
|
|
|
308
326
|
}));
|
|
309
327
|
});
|
|
310
328
|
});
|
|
329
|
+
describe('getMagicAuth', () => {
|
|
330
|
+
it('sends a Get Magic Auth request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
331
|
+
(0, test_utils_1.fetchOnce)(magic_auth_json_1.default);
|
|
332
|
+
const magicAuth = yield workos.userManagement.getMagicAuth(magicAuthId);
|
|
333
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/magic_auth/${magicAuthId}`);
|
|
334
|
+
expect(magicAuth).toMatchObject({
|
|
335
|
+
id: 'magic_auth_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
336
|
+
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
337
|
+
email: 'dane@workos.com',
|
|
338
|
+
expiresAt: '2023-07-18T02:07:19.911Z',
|
|
339
|
+
code: '123456',
|
|
340
|
+
createdAt: '2023-07-18T02:07:19.911Z',
|
|
341
|
+
updatedAt: '2023-07-18T02:07:19.911Z',
|
|
342
|
+
});
|
|
343
|
+
}));
|
|
344
|
+
});
|
|
345
|
+
describe('createMagicAuth', () => {
|
|
346
|
+
it('sends a Create Magic Auth request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
347
|
+
(0, test_utils_1.fetchOnce)(magic_auth_json_1.default);
|
|
348
|
+
const response = yield workos.userManagement.createMagicAuth({
|
|
349
|
+
email: 'bob.loblaw@example.com',
|
|
350
|
+
});
|
|
351
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/user_management/magic_auth');
|
|
352
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
353
|
+
email: 'bob.loblaw@example.com',
|
|
354
|
+
});
|
|
355
|
+
expect(response).toMatchObject({
|
|
356
|
+
id: 'magic_auth_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
357
|
+
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
358
|
+
email: 'dane@workos.com',
|
|
359
|
+
expiresAt: '2023-07-18T02:07:19.911Z',
|
|
360
|
+
code: '123456',
|
|
361
|
+
createdAt: '2023-07-18T02:07:19.911Z',
|
|
362
|
+
updatedAt: '2023-07-18T02:07:19.911Z',
|
|
363
|
+
});
|
|
364
|
+
}));
|
|
365
|
+
});
|
|
311
366
|
describe('sendMagicAuthCode', () => {
|
|
312
367
|
it('sends a Send Magic Auth Code request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
313
368
|
(0, test_utils_1.fetchOnce)();
|
package/lib/workos.js
CHANGED
|
@@ -24,7 +24,7 @@ const audit_logs_1 = require("./audit-logs/audit-logs");
|
|
|
24
24
|
const user_management_1 = require("./user-management/user-management");
|
|
25
25
|
const bad_request_exception_1 = require("./common/exceptions/bad-request.exception");
|
|
26
26
|
const fetch_client_1 = require("./common/utils/fetch-client");
|
|
27
|
-
const VERSION = '7.
|
|
27
|
+
const VERSION = '7.3.0';
|
|
28
28
|
const DEFAULT_HOSTNAME = 'api.workos.com';
|
|
29
29
|
class WorkOS {
|
|
30
30
|
constructor(key, options = {}) {
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "7.
|
|
2
|
+
"version": "7.3.0",
|
|
3
3
|
"name": "@workos-inc/node",
|
|
4
4
|
"author": "WorkOS",
|
|
5
5
|
"description": "A Node wrapper for the WorkOS API",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"workos"
|
|
10
10
|
],
|
|
11
11
|
"volta": {
|
|
12
|
-
"node": "
|
|
12
|
+
"node": "19.9.0",
|
|
13
13
|
"yarn": "1.22.19"
|
|
14
14
|
},
|
|
15
15
|
"engines": {
|