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
4 changes: 2 additions & 2 deletions SUPPORTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ in [Seed data](docs/seeding.md).

<!-- gen:supported:begin -->

The emulator implements **209 of 269** endpoints in the WorkOS OpenAPI spec (`@workos/openapi-spec@0.160.0`) (**77.7%**).
The emulator implements **210 of 269** endpoints in the WorkOS OpenAPI spec (`@workos/openapi-spec@0.160.0`) (**78.1%**).

| Feature | Read | Write | Set up |
| --------------------------------------------------------------------- | -------- | -------- | ------------------------------ |
Expand All @@ -34,7 +34,7 @@ The emulator implements **209 of 269** endpoints in the WorkOS OpenAPI spec (`@w
| [SSO](docs/behavior.md#sso) | ⚠️ 5/8 | ⚠️ 4/11 | ✅ seed `connections` |
| [Directory Sync](docs/behavior.md#directory-sync) | ✅ 6/6 | ⚠️ 1/2 | ✅ seed `directories` |
| [Multi-Factor Auth](docs/behavior.md#multi-factor-auth) | ✅ 2/2 | ✅ 5/5 | ⚠️ API only |
| [FGA / Authorization](docs/behavior.md#fga--authorization) | ✅ 19/19 | ⚠️ 24/27 | ✅ seed `roles`, `permissions` |
| [FGA / Authorization](docs/behavior.md#fga--authorization) | ✅ 19/19 | ⚠️ 25/27 | ✅ seed `roles`, `permissions` |
| [Audit Logs](docs/behavior.md#audit-logs) | ⚠️ 3/4 | ⚠️ 3/4 | ⚠️ API only |
| [Vault](docs/behavior.md#vault) | ✅ 5/5 | ⚠️ 3/6 | ⚠️ API only |
| [Feature Flags](docs/behavior.md#feature-flags) | ✅ 4/4 | ✅ 4/4 | ✅ seed `featureFlags` |
Expand Down
5 changes: 4 additions & 1 deletion docs/behavior.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,10 @@ Deleting a role, group, or resource also removes its group grants. The emulator
role-assignment webhook events. Bulk group assignment replacement is not yet supported.

Resource updates accept the Node SDK's `PATCH` endpoints by ID and by organization, resource type,
and external ID. The earlier `PUT`-by-ID endpoint remains available.
and external ID. The earlier `PUT`-by-ID endpoint remains available. Deletes are served by ID and by
organization, resource type, and external ID, with the same rules: `409` `resource_has_dependents`
for a resource with descendants or role assignments unless `cascade_delete=true`, which deletes them
with it.

## Audit Logs

Expand Down
31 changes: 31 additions & 0 deletions src/workos/routes/authorization-resources.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,37 @@ describe('Authorization resource routes', () => {
expect((await req(`/authorization/resources/${child.id}`)).status).toBe(404);
});

it('deletes a resource by organization, type and external id', async () => {
const org = await createOrg('DelExt Org');
const create = async (body: Record<string, unknown>) =>
json(
await req('/authorization/resources', {
method: 'POST',
body: JSON.stringify({ organization_id: org.id, ...body }),
}),
);
const parent = await create({ resource_type_slug: 'workspace', external_id: 'ext-ws', name: 'ext-ws' });
const child = await create({
resource_type_slug: 'project',
external_id: 'ext-proj',
name: 'ext-proj',
parent_resource_id: parent.id,
});
const path = `/authorization/organizations/${org.id}/resources/workspace/ext-ws`;

const refused = await req(path, { method: 'DELETE' });
expect(refused.status).toBe(409);
expect((await json(refused)).code).toBe('resource_has_dependents');

expect((await req(`${path}?cascade_delete=true`, { method: 'DELETE' })).status).toBe(204);
expect((await req(path)).status).toBe(404);
expect((await req(`/authorization/resources/${child.id}`)).status).toBe(404);

const missing = await req(path, { method: 'DELETE' });
expect(missing.status).toBe(404);
expect((await json(missing)).code).toBe('entity_not_found');
});

it('filters resources by external id and parent', async () => {
const org = await createOrg('ListFilter Org');
const parent = await json(
Expand Down
19 changes: 14 additions & 5 deletions src/workos/routes/authorization-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,9 @@ export function authorizationResourceRoutes(ctx: RouteContext): void {
// Deleting a resource takes its descendants and their role assignments with
// it. Without cascade_delete=true a resource that has either is refused,
// rather than leaving children pointing at an id that no longer resolves.
app.delete('/authorization/resources/:resource_id', (c) => {
const resourceId = c.req.param('resource_id');
const resource = ws.authorizationResources.get(resourceId);
if (!resource) throw notFound('AuthorizationResource', resourceId);
const deleteResource = (c: Context, resource: WorkOSAuthorizationResource | undefined, ref: string) => {
if (!resource) throw notFound('AuthorizationResource', ref);
const resourceId = resource.id;

if (resource.resource_type_slug === 'organization') {
throw new WorkOSApiError(400, 'Cannot mark organization resource as deleting.', 'bad_request');
Expand All @@ -268,7 +267,17 @@ export function authorizationResourceRoutes(ctx: RouteContext): void {
for (const assignment of groupAssignments) ws.groupRoleAssignments.delete(assignment.id);
for (const id of subtree) ws.authorizationResources.delete(id);
return c.body(null, 204);
});
};
app.delete('/authorization/resources/:resource_id', (c) =>
deleteResource(c, ws.authorizationResources.get(c.req.param('resource_id')), c.req.param('resource_id')),
);
app.delete('/authorization/organizations/:orgId/resources/:type_slug/:external_id', (c) =>
deleteResource(
c,
findResourceByExternalId(ws, c.req.param('orgId'), c.req.param('type_slug'), c.req.param('external_id')),
c.req.param('external_id'),
),
);

// Memberships that hold a permission on a resource. Production validates the query before
// it resolves the resource, so a missing permission_slug is a 422 even for an unknown
Expand Down
Loading