Skip to content

Commit

Permalink
Remove distinction between "Managed" and "Unmanaged" users (#831)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
maxdeviant authored Aug 21, 2023
1 parent 61304f1 commit d03e135
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 72 deletions.
8 changes: 0 additions & 8 deletions src/users/exceptions/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/users/fixtures/list-users.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"last_name": "User",
"created_at": "2023-07-18T02:07:19.911Z",
"updated_at": "2023-07-18T02:07:19.911Z",
"user_type": "unmanaged",
"email_verified_at": "2023-07-17T20:07:20.055Z"
}
],
Expand Down
1 change: 0 additions & 1 deletion src/users/fixtures/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
"last_name": "User",
"created_at": "2023-07-18T02:07:19.911Z",
"updated_at": "2023-07-18T02:07:19.911Z",
"user_type": "unmanaged",
"email_verified_at": "2023-07-17T20:07:20.055Z"
}
32 changes: 4 additions & 28 deletions src/users/interfaces/user.interface.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,19 @@
export type User = ManagedUser | UnmanagedUser;
export type UserResponse = ManagedUserResponse | UnmanagedUserResponse;

interface ManagedUser extends BaseUser {
userType: 'managed';
ssoProfileId: string | null;
}

interface ManagedUserResponse extends BaseUserResponse {
user_type: 'managed';
sso_profile_id: string | null;
}
interface UnmanagedUser extends BaseUser {
userType: 'unmanaged';
emailVerifiedAt: string | null;
googleOauthProfileId: string | null;
microsoftOauthProfileId: string | null;
}

interface UnmanagedUserResponse extends BaseUserResponse {
user_type: 'unmanaged';
email_verified_at: string | null;
google_oauth_profile_id: string | null;
microsoft_oauth_profile_id: string | null;
}

export interface BaseUser {
export interface User {
object: 'user';
id: string;
email: string;
emailVerifiedAt: string | null;
firstName: string | null;
lastName: string | null;
createdAt: string;
updatedAt: string;
}

interface BaseUserResponse {
export interface UserResponse {
object: 'user';
id: string;
email: string;
email_verified_at: string | null;
first_name: string | null;
last_name: string | null;
created_at: string;
Expand Down
43 changes: 11 additions & 32 deletions src/users/serializers/user.serializer.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
import { UnexpectedUserTypeException } from '../exceptions';
import { BaseUser, User, UserResponse } from '../interfaces';
import { User, UserResponse } from '../interfaces';

export const deserializeUser = (user: UserResponse): User => {
const baseUser: BaseUser = {
object: user.object,
id: user.id,
email: user.email,
firstName: user.first_name,
lastName: user.last_name,
createdAt: user.created_at,
updatedAt: user.updated_at,
};

switch (user.user_type) {
case 'managed':
return {
...baseUser,
userType: user.user_type,
ssoProfileId: user.sso_profile_id,
};
case 'unmanaged':
return {
...baseUser,
userType: user.user_type,
emailVerifiedAt: user.email_verified_at,
googleOauthProfileId: user.google_oauth_profile_id,
microsoftOauthProfileId: user.microsoft_oauth_profile_id,
};
default:
throw new UnexpectedUserTypeException(user);
}
};
export const deserializeUser = (user: UserResponse): User => ({
object: user.object,
id: user.id,
email: user.email,
emailVerifiedAt: user.email_verified_at,
firstName: user.first_name,
lastName: user.last_name,
createdAt: user.created_at,
updatedAt: user.updated_at,
});
2 changes: 0 additions & 2 deletions src/users/users.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ describe('UserManagement', () => {
email: '[email protected]',
firstName: 'Test 01',
lastName: 'User',
userType: 'unmanaged',
emailVerifiedAt: '2023-07-17T20:07:20.055Z',
});
});
Expand Down Expand Up @@ -87,7 +86,6 @@ describe('UserManagement', () => {
email: '[email protected]',
firstName: 'Test 01',
lastName: 'User',
userType: 'unmanaged',
emailVerifiedAt: '2023-07-17T20:07:20.055Z',
createdAt: '2023-07-18T02:07:19.911Z',
updatedAt: '2023-07-18T02:07:19.911Z',
Expand Down

0 comments on commit d03e135

Please sign in to comment.