Authorization Resources (external ID) endpoints and listResources endpoint#1472
Conversation
|
@greptile can you plz do a first pass review |
|
@greptile plz re-review this pr |
Greptile OverviewGreptile SummaryThis PR implements four new authorization resource endpoints that enable operations using external IDs instead of internal resource IDs:
The implementation follows established patterns in the codebase with consistent serialization, proper TypeScript typing, and comprehensive test coverage. All new methods properly handle nullable fields ( Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant SDK as WorkOS SDK
participant Serializer
participant API as WorkOS API
Note over Client,API: List Resources Flow
Client->>SDK: listResources(options)
SDK->>Serializer: serializeListAuthorizationResourcesOptions()
Serializer->>Serializer: Convert arrays to comma-separated strings
Serializer->>Serializer: Convert camelCase to snake_case
Serializer-->>SDK: serialized params
SDK->>API: GET /authorization/resources?params
API-->>SDK: AuthorizationResourceListResponse
SDK->>SDK: deserializeAuthorizationResource() for each item
SDK-->>Client: AuthorizationResourceList
Note over Client,API: Get/Update/Delete by External ID Flow
Client->>SDK: getResourceByExternalId({org, type, externalId})
SDK->>API: GET /authorization/organizations/{org}/resources/{type}/{externalId}
API-->>SDK: AuthorizationResourceResponse
SDK->>SDK: deserializeAuthorizationResource()
SDK-->>Client: AuthorizationResource
Client->>SDK: updateResourceByExternalId(options)
SDK->>Serializer: serializeUpdateResourceByExternalIdOptions()
Serializer->>Serializer: Filter undefined fields
Serializer-->>SDK: serialized body
SDK->>API: PATCH /authorization/organizations/{org}/resources/{type}/{externalId}
API-->>SDK: AuthorizationResourceResponse
SDK->>SDK: deserializeAuthorizationResource()
SDK-->>Client: AuthorizationResource
Client->>SDK: deleteResourceByExternalId({org, type, externalId})
SDK->>API: DELETE /authorization/organizations/{org}/resources/{type}/{externalId}
API-->>SDK: 204 No Content
SDK-->>Client: void
|
src/authorization/serializers/list-authorization-resources-options.serializer.ts
Outdated
Show resolved
Hide resolved
src/authorization/authorization.ts
Outdated
| await this.workos.delete(`/authorization/resources/${resourceId}`); | ||
| } | ||
|
|
||
| // part 2 |
There was a problem hiding this comment.
| // part 2 |
| ): Promise<AuthorizationResource> { | ||
| const { organizationId, resourceTypeSlug, externalId } = options; | ||
| const { data } = await this.workos.get<AuthorizationResourceResponse>( | ||
| `/authorization/organizations/${organizationId}/resources/${resourceTypeSlug}/${externalId}`, |
There was a problem hiding this comment.
suggestion: could externalId contain URL-significant characters? Not sure if this is gated elsewhere but could be good to wrap with encodeURIComponent.
| } | ||
|
|
||
| export interface SerializedListAuthorizationResourcesOptions { | ||
| organization_ids?: string; |
There was a problem hiding this comment.
I have a ticket to change this and slugs to singular organization_id, resource_type_slug
There was a problem hiding this comment.
There was a problem hiding this comment.
I'll update with a change once it is merged
| @@ -31,8 +31,6 @@ export interface CreateAuthorizationResourceOptions { | |||
| resourceTypeSlug: string; | |||
| organizationId: string; | |||
| parentResourceId?: string | null; | |||
There was a problem hiding this comment.
Same comment about type_slug + external_id
4be4df5
into
ENT-4372-base-authorization-branch
Adding these endpoints to the sdk #1471 ``` getResource() ~ GET /authorization/resources/{resource_id} createResource() ~ POST /authorization/resources updateResource() ~ PATCH /authorization/resources/{resource_id} deleteResource() ~ DELETE /authorization/resources/{resource_id} ``` #1473 ``` check() | POST /authorization/organization_memberships/{om_id}/check ``` #1472 ``` listResources() | GET /authorization/organizations/{org_id}/resources getResourceByExternalId() | GET /authorization/organizations/{org_id}/resources/{type}/{external_id} updateResourceByExternalId() | PATCH /authorization/organizations/{org_id}/resources/{type}/{external_id} deleteResourceByExternalId() | DELETE /authorization/organizations/{org_id}/resources/{type}/{external_id} ``` #1474 ``` listRoleAssignments() | GET /authorization/organization_memberships/{om_id}/role_assignments assignRole() | POST /authorization/organization_memberships/{om_id}/role_assignments removeRole() | DELETE /authorization/organization_memberships/{om_id}/role_assignments removeRoleAssignment() | DELETE /authorization/organization_memberships/{om_id}/role_assignments/{ra_id} ``` #1478 ``` listResourcesForMembership() | GET /authorization/organization_memberships/{om_id}/resources listMembershipsForResource() | GET /authorization/resources/{resource_id}/organization_memberships listMembershipsForResourceByExternalId() | GET /authorization/organizations/{org_id}/resources/{type}/{external_id}/organization_memberships ```
linear: https://linear.app/workos/issue/ENT-4372/sdk-updates
I decided to break up the work for ENT-4372 into a smaller pr's that we can be easily reviewed and merge them into ENT-4372-base-authorization-branch. Then we can have one final merge that merges ENT-4372-base-authorization-branch into the main.
desc: the goal of this pr is to implement the following endpoints in the node sdk.
Each one will call the corresponding new fga endpoints within workos repo
listResources() ~ https://github.com/workos/workos/blob/51f5a445c3a247f5f093bfaae8e385629df56d36/packages/api/src/authorization-resources/authorization-resources.controller.ts#L83
getResourceByExternalId() ~ https://github.com/workos/workos/blob/51f5a445c3a247f5f093bfaae8e385629df56d36/packages/api/src/authorization-resources/authorization-resources-by-external-id.controller.ts#L90
updateResourceByExternalId() ~ https://github.com/workos/workos/blob/51f5a445c3a247f5f093bfaae8e385629df56d36/packages/api/src/authorization-resources/authorization-resources-by-external-id.controller.ts#L183
deleteResourceByExternalId() ~ https://github.com/workos/workos/blob/51f5a445c3a247f5f093bfaae8e385629df56d36/packages/api/src/authorization-resources/authorization-resources-by-external-id.controller.ts#L221