Skip to content

Commit d03e135

Browse files
authored
Remove distinction between "Managed" and "Unmanaged" users (#831)
## Description This PR removes the distinction between "Managed" and "Unmanaged" users from the SDK. This concept is being removed from the API in the near future. This is a breaking change to the User Management portion of the SDK. Resolves USRLD-843. ## Documentation Does this require changes to the WorkOS Docs? E.g. the [API Reference](https://workos.com/docs/reference) or code snippets need updates. ``` [ ] Yes ``` If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.
1 parent 61304f1 commit d03e135

File tree

6 files changed

+15
-72
lines changed

6 files changed

+15
-72
lines changed

src/users/exceptions/index.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/users/fixtures/list-users.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"last_name": "User",
1010
"created_at": "2023-07-18T02:07:19.911Z",
1111
"updated_at": "2023-07-18T02:07:19.911Z",
12-
"user_type": "unmanaged",
1312
"email_verified_at": "2023-07-17T20:07:20.055Z"
1413
}
1514
],

src/users/fixtures/user.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
"last_name": "User",
77
"created_at": "2023-07-18T02:07:19.911Z",
88
"updated_at": "2023-07-18T02:07:19.911Z",
9-
"user_type": "unmanaged",
109
"email_verified_at": "2023-07-17T20:07:20.055Z"
1110
}

src/users/interfaces/user.interface.ts

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,19 @@
1-
export type User = ManagedUser | UnmanagedUser;
2-
export type UserResponse = ManagedUserResponse | UnmanagedUserResponse;
3-
4-
interface ManagedUser extends BaseUser {
5-
userType: 'managed';
6-
ssoProfileId: string | null;
7-
}
8-
9-
interface ManagedUserResponse extends BaseUserResponse {
10-
user_type: 'managed';
11-
sso_profile_id: string | null;
12-
}
13-
interface UnmanagedUser extends BaseUser {
14-
userType: 'unmanaged';
15-
emailVerifiedAt: string | null;
16-
googleOauthProfileId: string | null;
17-
microsoftOauthProfileId: string | null;
18-
}
19-
20-
interface UnmanagedUserResponse extends BaseUserResponse {
21-
user_type: 'unmanaged';
22-
email_verified_at: string | null;
23-
google_oauth_profile_id: string | null;
24-
microsoft_oauth_profile_id: string | null;
25-
}
26-
27-
export interface BaseUser {
1+
export interface User {
282
object: 'user';
293
id: string;
304
email: string;
5+
emailVerifiedAt: string | null;
316
firstName: string | null;
327
lastName: string | null;
338
createdAt: string;
349
updatedAt: string;
3510
}
3611

37-
interface BaseUserResponse {
12+
export interface UserResponse {
3813
object: 'user';
3914
id: string;
4015
email: string;
16+
email_verified_at: string | null;
4117
first_name: string | null;
4218
last_name: string | null;
4319
created_at: string;
Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,12 @@
1-
import { UnexpectedUserTypeException } from '../exceptions';
2-
import { BaseUser, User, UserResponse } from '../interfaces';
1+
import { User, UserResponse } from '../interfaces';
32

4-
export const deserializeUser = (user: UserResponse): User => {
5-
const baseUser: BaseUser = {
6-
object: user.object,
7-
id: user.id,
8-
email: user.email,
9-
firstName: user.first_name,
10-
lastName: user.last_name,
11-
createdAt: user.created_at,
12-
updatedAt: user.updated_at,
13-
};
14-
15-
switch (user.user_type) {
16-
case 'managed':
17-
return {
18-
...baseUser,
19-
userType: user.user_type,
20-
ssoProfileId: user.sso_profile_id,
21-
};
22-
case 'unmanaged':
23-
return {
24-
...baseUser,
25-
userType: user.user_type,
26-
emailVerifiedAt: user.email_verified_at,
27-
googleOauthProfileId: user.google_oauth_profile_id,
28-
microsoftOauthProfileId: user.microsoft_oauth_profile_id,
29-
};
30-
default:
31-
throw new UnexpectedUserTypeException(user);
32-
}
33-
};
3+
export const deserializeUser = (user: UserResponse): User => ({
4+
object: user.object,
5+
id: user.id,
6+
email: user.email,
7+
emailVerifiedAt: user.email_verified_at,
8+
firstName: user.first_name,
9+
lastName: user.last_name,
10+
createdAt: user.created_at,
11+
updatedAt: user.updated_at,
12+
});

src/users/users.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ describe('UserManagement', () => {
2323
2424
firstName: 'Test 01',
2525
lastName: 'User',
26-
userType: 'unmanaged',
2726
emailVerifiedAt: '2023-07-17T20:07:20.055Z',
2827
});
2928
});
@@ -87,7 +86,6 @@ describe('UserManagement', () => {
8786
8887
firstName: 'Test 01',
8988
lastName: 'User',
90-
userType: 'unmanaged',
9189
emailVerifiedAt: '2023-07-17T20:07:20.055Z',
9290
createdAt: '2023-07-18T02:07:19.911Z',
9391
updatedAt: '2023-07-18T02:07:19.911Z',

0 commit comments

Comments
 (0)