Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,22 @@
"directory_managed": false,
"custom_attributes": {},
"created_at": "2023-07-18T02:07:19.911Z",
"updated_at": "2023-07-18T02:07:19.911Z"
"updated_at": "2023-07-18T02:07:19.911Z",
"user": {
"object": "user",
"id": "user_01H5JQDV7R7ATEYZDEG0W5PRYS",
"email": "test01@example.com",
"name": "Test 01 User",
"first_name": "Test 01",
"last_name": "User",
"created_at": "2023-07-18T02:07:19.911Z",
"updated_at": "2023-07-18T02:07:19.911Z",
"email_verified": true,
"profile_picture_url": "https://example.com/profile_picture.jpg",
"last_sign_in_at": "2023-07-18T02:07:19.911Z",
"locale": "en-US",
"metadata": {
"key": "value"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,24 @@
"directory_managed": false,
"custom_attributes": {},
"created_at": "2023-07-18T02:07:19.911Z",
"updated_at": "2023-07-18T02:07:19.911Z"
"updated_at": "2023-07-18T02:07:19.911Z",
"user": {
"object": "user",
"id": "user_01H5JQDV7R7ATEYZDEG0W5PRYS",
"email": "test01@example.com",
"name": "Test 01 User",
"first_name": "Test 01",
"last_name": "User",
"created_at": "2023-07-18T02:07:19.911Z",
"updated_at": "2023-07-18T02:07:19.911Z",
"email_verified": true,
"profile_picture_url": "https://example.com/profile_picture.jpg",
"last_sign_in_at": "2023-07-18T02:07:19.911Z",
"locale": "en-US",
"metadata": {
"key": "value"
}
}
}
],
"list_metadata": {
Expand Down
19 changes: 18 additions & 1 deletion src/user-management/fixtures/organization-membership.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,22 @@
"directory_managed": false,
"custom_attributes": {},
"created_at": "2023-07-18T02:07:19.911Z",
"updated_at": "2023-07-18T02:07:19.911Z"
"updated_at": "2023-07-18T02:07:19.911Z",
"user": {
"object": "user",
"id": "user_01H5JQDV7R7ATEYZDEG0W5PRYS",
"email": "test01@example.com",
"name": "Test 01 User",
"first_name": "Test 01",
"last_name": "User",
"created_at": "2023-07-18T02:07:19.911Z",
"updated_at": "2023-07-18T02:07:19.911Z",
"email_verified": true,
"profile_picture_url": "https://example.com/profile_picture.jpg",
"last_sign_in_at": "2023-07-18T02:07:19.911Z",
"locale": "en-US",
"metadata": {
"key": "value"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { RoleResponse } from '../../roles/interfaces/';
import { User, UserResponse } from './user.interface';

export type OrganizationMembershipStatus = 'active' | 'inactive' | 'pending';

Expand All @@ -20,6 +21,11 @@ export interface OrganizationMembership extends BaseOrganizationMembership {
/** The primary role assigned to the user within the organization. */
role: RoleResponse;
roles?: RoleResponse[];
/**
* The user who holds this membership. Returned by the Organization
* Membership API endpoints; absent from event and action payloads.
*/
user?: User;
}

export type AuthorizationOrganizationMembership = BaseOrganizationMembership;
Expand All @@ -40,6 +46,7 @@ export interface BaseOrganizationMembershipResponse {
export interface OrganizationMembershipResponse extends BaseOrganizationMembershipResponse {
role: RoleResponse;
roles?: RoleResponse[];
user?: UserResponse;
}

export type AuthorizationOrganizationMembershipResponse =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
OrganizationMembership,
OrganizationMembershipResponse,
} from '../interfaces/organization-membership.interface';
import { deserializeUser } from './user.serializer';

export const deserializeOrganizationMembership = (
organizationMembership: OrganizationMembershipResponse,
Expand All @@ -20,6 +21,9 @@ export const deserializeOrganizationMembership = (
role: organizationMembership.role,
...(organizationMembership.roles && { roles: organizationMembership.roles }),
customAttributes: organizationMembership.custom_attributes ?? {},
...(organizationMembership.user && {
user: deserializeUser(organizationMembership.user),
}),
});

export const deserializeAuthorizationOrganizationMembership = (
Expand Down
24 changes: 24 additions & 0 deletions src/user-management/user-management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2466,8 +2466,28 @@ describe('UserManagement', () => {
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
organizationId: 'organization_01H5JQDV7R7ATEYZDEG0W5PRYS',
status: 'active',
user: {
object: 'user',
id: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
email: 'test01@example.com',
emailVerified: true,
firstName: 'Test 01',
lastName: 'User',
},
});
});

it('omits user when the response does not include one', async () => {
fetchOnce(
{ ...organizationMembershipFixture, user: undefined },
{ status: 200 },
);
const organizationMembership =
await workos.userManagement.getOrganizationMembership(
organizationMembershipId,
);
expect(organizationMembership).not.toHaveProperty('user');
});
});

describe('listOrganizationMemberships', () => {
Expand All @@ -2490,6 +2510,10 @@ describe('UserManagement', () => {
organizationName: 'Example Organization',
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
status: 'active',
user: {
id: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
email: 'test01@example.com',
},
},
],
listMetadata: {
Expand Down
Loading