workos 0.11.2 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/README.md +165 -6
  2. package/dist/bin.js +22 -1
  3. package/dist/bin.js.map +1 -1
  4. package/dist/check-coverage.ts +237 -0
  5. package/dist/commands/debug.js +0 -1
  6. package/dist/commands/debug.js.map +1 -1
  7. package/dist/commands/dev.d.ts +23 -0
  8. package/dist/commands/dev.js +139 -0
  9. package/dist/commands/dev.js.map +1 -0
  10. package/dist/commands/emulate.d.ts +6 -0
  11. package/dist/commands/emulate.js +64 -0
  12. package/dist/commands/emulate.js.map +1 -0
  13. package/dist/commands/login.js +0 -4
  14. package/dist/commands/login.js.map +1 -1
  15. package/dist/emulate/core/id.d.ts +48 -0
  16. package/dist/emulate/core/id.js +73 -0
  17. package/dist/emulate/core/id.js.map +1 -0
  18. package/dist/emulate/core/index.d.ts +8 -0
  19. package/dist/emulate/core/index.js +8 -0
  20. package/dist/emulate/core/index.js.map +1 -0
  21. package/dist/emulate/core/jwt.d.ts +28 -0
  22. package/dist/emulate/core/jwt.js +78 -0
  23. package/dist/emulate/core/jwt.js.map +1 -0
  24. package/dist/emulate/core/middleware/auth.d.ts +15 -0
  25. package/dist/emulate/core/middleware/auth.js +17 -0
  26. package/dist/emulate/core/middleware/auth.js.map +1 -0
  27. package/dist/emulate/core/middleware/error-handler.d.ts +22 -0
  28. package/dist/emulate/core/middleware/error-handler.js +72 -0
  29. package/dist/emulate/core/middleware/error-handler.js.map +1 -0
  30. package/dist/emulate/core/pagination.d.ts +27 -0
  31. package/dist/emulate/core/pagination.js +43 -0
  32. package/dist/emulate/core/pagination.js.map +1 -0
  33. package/dist/emulate/core/plugin.d.ts +15 -0
  34. package/dist/emulate/core/plugin.js +2 -0
  35. package/dist/emulate/core/plugin.js.map +1 -0
  36. package/dist/emulate/core/server.d.ts +17 -0
  37. package/dist/emulate/core/server.js +90 -0
  38. package/dist/emulate/core/server.js.map +1 -0
  39. package/dist/emulate/core/store.d.ts +44 -0
  40. package/dist/emulate/core/store.js +169 -0
  41. package/dist/emulate/core/store.js.map +1 -0
  42. package/dist/emulate/index.d.ts +25 -0
  43. package/dist/emulate/index.js +47 -0
  44. package/dist/emulate/index.js.map +1 -0
  45. package/dist/emulate/workos/constants.d.ts +56 -0
  46. package/dist/emulate/workos/constants.js +56 -0
  47. package/dist/emulate/workos/constants.js.map +1 -0
  48. package/dist/emulate/workos/entities.d.ts +360 -0
  49. package/dist/emulate/workos/entities.js +2 -0
  50. package/dist/emulate/workos/entities.js.map +1 -0
  51. package/dist/emulate/workos/event-bus.d.ts +17 -0
  52. package/dist/emulate/workos/event-bus.js +70 -0
  53. package/dist/emulate/workos/event-bus.js.map +1 -0
  54. package/dist/emulate/workos/helpers.d.ts +72 -0
  55. package/dist/emulate/workos/helpers.js +211 -0
  56. package/dist/emulate/workos/helpers.js.map +1 -0
  57. package/dist/emulate/workos/index.d.ts +91 -0
  58. package/dist/emulate/workos/index.js +322 -0
  59. package/dist/emulate/workos/index.js.map +1 -0
  60. package/dist/emulate/workos/role-helpers.d.ts +21 -0
  61. package/dist/emulate/workos/role-helpers.js +130 -0
  62. package/dist/emulate/workos/role-helpers.js.map +1 -0
  63. package/dist/emulate/workos/routes/api-keys.d.ts +2 -0
  64. package/dist/emulate/workos/routes/api-keys.js +32 -0
  65. package/dist/emulate/workos/routes/api-keys.js.map +1 -0
  66. package/dist/emulate/workos/routes/audit-logs.d.ts +2 -0
  67. package/dist/emulate/workos/routes/audit-logs.js +104 -0
  68. package/dist/emulate/workos/routes/audit-logs.js.map +1 -0
  69. package/dist/emulate/workos/routes/auth-challenges.d.ts +2 -0
  70. package/dist/emulate/workos/routes/auth-challenges.js +51 -0
  71. package/dist/emulate/workos/routes/auth-challenges.js.map +1 -0
  72. package/dist/emulate/workos/routes/auth-factors.d.ts +2 -0
  73. package/dist/emulate/workos/routes/auth-factors.js +51 -0
  74. package/dist/emulate/workos/routes/auth-factors.js.map +1 -0
  75. package/dist/emulate/workos/routes/auth.d.ts +2 -0
  76. package/dist/emulate/workos/routes/auth.js +350 -0
  77. package/dist/emulate/workos/routes/auth.js.map +1 -0
  78. package/dist/emulate/workos/routes/authorization-checks.d.ts +10 -0
  79. package/dist/emulate/workos/routes/authorization-checks.js +123 -0
  80. package/dist/emulate/workos/routes/authorization-checks.js.map +1 -0
  81. package/dist/emulate/workos/routes/authorization-org-roles.d.ts +2 -0
  82. package/dist/emulate/workos/routes/authorization-org-roles.js +64 -0
  83. package/dist/emulate/workos/routes/authorization-org-roles.js.map +1 -0
  84. package/dist/emulate/workos/routes/authorization-permissions.d.ts +2 -0
  85. package/dist/emulate/workos/routes/authorization-permissions.js +67 -0
  86. package/dist/emulate/workos/routes/authorization-permissions.js.map +1 -0
  87. package/dist/emulate/workos/routes/authorization-resources.d.ts +2 -0
  88. package/dist/emulate/workos/routes/authorization-resources.js +117 -0
  89. package/dist/emulate/workos/routes/authorization-resources.js.map +1 -0
  90. package/dist/emulate/workos/routes/authorization-roles.d.ts +2 -0
  91. package/dist/emulate/workos/routes/authorization-roles.js +13 -0
  92. package/dist/emulate/workos/routes/authorization-roles.js.map +1 -0
  93. package/dist/emulate/workos/routes/config.d.ts +2 -0
  94. package/dist/emulate/workos/routes/config.js +57 -0
  95. package/dist/emulate/workos/routes/config.js.map +1 -0
  96. package/dist/emulate/workos/routes/connect.d.ts +2 -0
  97. package/dist/emulate/workos/routes/connect.js +65 -0
  98. package/dist/emulate/workos/routes/connect.js.map +1 -0
  99. package/dist/emulate/workos/routes/connections.d.ts +2 -0
  100. package/dist/emulate/workos/routes/connections.js +73 -0
  101. package/dist/emulate/workos/routes/connections.js.map +1 -0
  102. package/dist/emulate/workos/routes/data-integrations.d.ts +2 -0
  103. package/dist/emulate/workos/routes/data-integrations.js +55 -0
  104. package/dist/emulate/workos/routes/data-integrations.js.map +1 -0
  105. package/dist/emulate/workos/routes/directories.d.ts +2 -0
  106. package/dist/emulate/workos/routes/directories.js +90 -0
  107. package/dist/emulate/workos/routes/directories.js.map +1 -0
  108. package/dist/emulate/workos/routes/email-verification.d.ts +2 -0
  109. package/dist/emulate/workos/routes/email-verification.js +49 -0
  110. package/dist/emulate/workos/routes/email-verification.js.map +1 -0
  111. package/dist/emulate/workos/routes/events.d.ts +2 -0
  112. package/dist/emulate/workos/routes/events.js +18 -0
  113. package/dist/emulate/workos/routes/events.js.map +1 -0
  114. package/dist/emulate/workos/routes/feature-flags.d.ts +2 -0
  115. package/dist/emulate/workos/routes/feature-flags.js +103 -0
  116. package/dist/emulate/workos/routes/feature-flags.js.map +1 -0
  117. package/dist/emulate/workos/routes/invitations.d.ts +2 -0
  118. package/dist/emulate/workos/routes/invitations.js +122 -0
  119. package/dist/emulate/workos/routes/invitations.js.map +1 -0
  120. package/dist/emulate/workos/routes/legacy-mfa.d.ts +2 -0
  121. package/dist/emulate/workos/routes/legacy-mfa.js +75 -0
  122. package/dist/emulate/workos/routes/legacy-mfa.js.map +1 -0
  123. package/dist/emulate/workos/routes/magic-auth.d.ts +2 -0
  124. package/dist/emulate/workos/routes/magic-auth.js +32 -0
  125. package/dist/emulate/workos/routes/magic-auth.js.map +1 -0
  126. package/dist/emulate/workos/routes/memberships.d.ts +2 -0
  127. package/dist/emulate/workos/routes/memberships.js +114 -0
  128. package/dist/emulate/workos/routes/memberships.js.map +1 -0
  129. package/dist/emulate/workos/routes/organization-domains.d.ts +2 -0
  130. package/dist/emulate/workos/routes/organization-domains.js +58 -0
  131. package/dist/emulate/workos/routes/organization-domains.js.map +1 -0
  132. package/dist/emulate/workos/routes/organizations.d.ts +2 -0
  133. package/dist/emulate/workos/routes/organizations.js +131 -0
  134. package/dist/emulate/workos/routes/organizations.js.map +1 -0
  135. package/dist/emulate/workos/routes/password-reset.d.ts +2 -0
  136. package/dist/emulate/workos/routes/password-reset.js +61 -0
  137. package/dist/emulate/workos/routes/password-reset.js.map +1 -0
  138. package/dist/emulate/workos/routes/pipes.d.ts +2 -0
  139. package/dist/emulate/workos/routes/pipes.js +82 -0
  140. package/dist/emulate/workos/routes/pipes.js.map +1 -0
  141. package/dist/emulate/workos/routes/portal.d.ts +2 -0
  142. package/dist/emulate/workos/routes/portal.js +18 -0
  143. package/dist/emulate/workos/routes/portal.js.map +1 -0
  144. package/dist/emulate/workos/routes/radar.d.ts +2 -0
  145. package/dist/emulate/workos/routes/radar.js +41 -0
  146. package/dist/emulate/workos/routes/radar.js.map +1 -0
  147. package/dist/emulate/workos/routes/sessions.d.ts +2 -0
  148. package/dist/emulate/workos/routes/sessions.js +51 -0
  149. package/dist/emulate/workos/routes/sessions.js.map +1 -0
  150. package/dist/emulate/workos/routes/sso.d.ts +2 -0
  151. package/dist/emulate/workos/routes/sso.js +161 -0
  152. package/dist/emulate/workos/routes/sso.js.map +1 -0
  153. package/dist/emulate/workos/routes/user-features.d.ts +2 -0
  154. package/dist/emulate/workos/routes/user-features.js +50 -0
  155. package/dist/emulate/workos/routes/user-features.js.map +1 -0
  156. package/dist/emulate/workos/routes/users.d.ts +2 -0
  157. package/dist/emulate/workos/routes/users.js +129 -0
  158. package/dist/emulate/workos/routes/users.js.map +1 -0
  159. package/dist/emulate/workos/routes/webhook-endpoints.d.ts +2 -0
  160. package/dist/emulate/workos/routes/webhook-endpoints.js +66 -0
  161. package/dist/emulate/workos/routes/webhook-endpoints.js.map +1 -0
  162. package/dist/emulate/workos/routes/widgets.d.ts +2 -0
  163. package/dist/emulate/workos/routes/widgets.js +27 -0
  164. package/dist/emulate/workos/routes/widgets.js.map +1 -0
  165. package/dist/emulate/workos/store.d.ts +48 -0
  166. package/dist/emulate/workos/store.js +102 -0
  167. package/dist/emulate/workos/store.js.map +1 -0
  168. package/dist/emulate/workos/webhook-signer.d.ts +1 -0
  169. package/dist/emulate/workos/webhook-signer.js +8 -0
  170. package/dist/emulate/workos/webhook-signer.js.map +1 -0
  171. package/dist/gen-routes-lib.spec.ts +659 -0
  172. package/dist/gen-routes-lib.ts +647 -0
  173. package/dist/gen-routes.ts +96 -0
  174. package/dist/lib/dev-command.d.ts +26 -0
  175. package/dist/lib/dev-command.js +122 -0
  176. package/dist/lib/dev-command.js.map +1 -0
  177. package/dist/lib/run-with-core.js +0 -3
  178. package/dist/lib/run-with-core.js.map +1 -1
  179. package/dist/lib/settings.js +1 -1
  180. package/dist/lib/settings.js.map +1 -1
  181. package/dist/utils/help-json.js +1 -0
  182. package/dist/utils/help-json.js.map +1 -1
  183. package/dist/utils/register-subcommand.d.ts +5 -2
  184. package/dist/utils/register-subcommand.js +16 -19
  185. package/dist/utils/register-subcommand.js.map +1 -1
  186. package/package.json +21 -8
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization-org-roles.js","sourceRoot":"","sources":["../../../../src/emulate/workos/routes/authorization-org-roles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAClG,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAErF,MAAM,UAAU,0BAA0B,CAAC,GAAiB;IAC1D,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC;IAC3B,MAAM,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,2CAA2C,CAAC;IAE3D,6DAA6D;IAC7D,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;QACxC,MAAM,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACnC,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,CAAC,CAAC,CAAC;QACpC,MAAM,KAAK,GAAG,IAAI,C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AAC,GAAG;gBAAE,MAAM,QAAQ,CAAC,cAAc,CAAC,CAAC;QAC3C,CAAC;KACF,CAAC,CAAC;IAEH,mDAAmD;IACnD,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,oCAAoC,EAAE,CAAC,CAAC,EAAE,EAAE;QAC9D,MAAM,IAAI,GAAG,cAAc,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QAE3E,MAAM,IAAI,GAAG,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC;QAC7E,IAAI,CAAC,IAAI;YAAE,MAAM,QAAQ,CAAC,YAAY,CAAC,CAAC;QAExC,MAAM,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,aAAa,KAAK,IAAI,CAAC,EAAE,CAAC,CAAC;QACpG,IAAI,CAAC,EAAE;YAAE,MAAM,QAAQ,CAAC,gBAAgB,CAAC,CAAC;QAE1C,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACjC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { type RouteContext, notFound, validationError, parseJsonBody } from '../../core/index.js';\nimport { getWorkOSStore } from '../store.js';\nimport { formatRole } from '../helpers.js';\nimport { findOrgRole, requireOrgRole, registerRoleRoutes } from '../role-helpers.js';\n\nexport function authorizationOrgRoleRoutes(ctx: RouteContext): void {\n const { app, store } = ctx;\n const ws = getWorkOSStore(store);\n const prefix = '/authorization/organizations/:orgId/roles';\n\n // Priority ordering — must be registered before :slug routes\n app.put(`${prefix}/priority`, async (c) => {\n const orgId = c.req.param('orgId');\n const body = await parseJsonBody(c);\n const slugs = body.slugs as string[];\n\n if (!Array.isArray(slugs)) {\n throw validationError('slugs must be an array', [{ field: 'slugs', code: 'invalid' }]);\n }\n\n // Fetch once, build slug map for O(1) lookups\n const orgRoles = ws.roles.findBy('organization_id', orgId).filter((r) => r.type === 'OrganizationRole');\n const rolesBySlug = new Map(orgRoles.map((r) => [r.slug, r]));\n\n for (let i = 0; i < slugs.length; i++) {\n const role = rolesBySlug.get(slugs[i]!);\n if (!role) throw notFound('Role');\n ws.roles.update(role.id, { priority: i });\n }\n\n // Re-fetch for updated priority values\n const updated = ws.roles\n .findBy('organization_id', orgId)\n .filter((r) => r.type === 'OrganizationRole')\n .sort((a, b) => a.priority - b.priority);\n\n return c.json({\n object: 'list',\n data: updated.map(formatRole),\n list_metadata: { before: null, after: null },\n });\n });\n\n registerRoleRoutes(ctx, {\n pathPrefix: prefix,\n roleType: 'OrganizationRole',\n requireRole: (ws, c) => requireOrgRole(ws, c.req.param('orgId'), c.req.param('slug')),\n findRole: (ws, c, slug) => findOrgRole(ws, c.req.param('orgId'), slug),\n listFilter: (c) => (r) => r.organization_id === c.req.param('orgId') && r.type === 'OrganizationRole',\n insertDefaults: (c) => ({ organization_id: c.req.param('orgId') }),\n duplicateMessage: 'Role with this slug already exists in this organization',\n validateBeforeCreate: (ws, c) => {\n const org = ws.organizations.get(c.req.param('orgId'));\n if (!org) throw notFound('Organization');\n },\n });\n\n // Org-specific: delete single permission from role\n app.delete(`${prefix}/:slug/permissions/:permissionSlug`, (c) => {\n const role = requireOrgRole(ws, c.req.param('orgId'), c.req.param('slug'));\n\n const perm = ws.permissions.findOneBy('slug', c.req.param('permissionSlug'));\n if (!perm) throw notFound('Permission');\n\n const rp = ws.rolePermissions.findBy('role_id', role.id).find((rp) => rp.permission_id === perm.id);\n if (!rp) throw notFound('RolePermission');\n\n ws.rolePermissions.delete(rp.id);\n return c.body(null, 204);\n });\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { type RouteContext } from '../../core/index.js';
2
+ export declare function authorizationPermissionRoutes(ctx: RouteContext): void;
@@ -0,0 +1,67 @@
1
+ import { notFound, validationError, parseJsonBody, parseListParams } from '../../core/index.js';
2
+ import { getWorkOSStore } from '../store.js';
3
+ import { formatPermission, formatListResponse } from '../helpers.js';
4
+ export function authorizationPermissionRoutes(ctx) {
5
+ const { app, store } = ctx;
6
+ const ws = getWorkOSStore(store);
7
+ app.post('/authorization/permissions', async (c) => {
8
+ const body = await parseJsonBody(c);
9
+ const slug = body.slug;
10
+ const name = body.name;
11
+ if (!slug || typeof slug !== 'string') {
12
+ throw validationError('slug is required', [{ field: 'slug', code: 'required' }]);
13
+ }
14
+ if (!name || typeof name !== 'string') {
15
+ throw validationError('name is required', [{ field: 'name', code: 'required' }]);
16
+ }
17
+ const existing = ws.permissions.findOneBy('slug', slug);
18
+ if (existing) {
19
+ throw validationError('Permission with this slug already exists', [{ field: 'slug', code: 'duplicate' }]);
20
+ }
21
+ const permission = ws.permissions.insert({
22
+ object: 'permission',
23
+ slug,
24
+ name,
25
+ description: body.description ?? null,
26
+ });
27
+ return c.json(formatPermission(permission), 201);
28
+ });
29
+ app.get('/authorization/permissions', (c) => {
30
+ const url = new URL(c.req.url);
31
+ const params = parseListParams(url);
32
+ const result = ws.permissions.list(params);
33
+ return c.json(formatListResponse(result, formatPermission));
34
+ });
35
+ app.get('/authorization/permissions/:slug', (c) => {
36
+ const slug = c.req.param('slug');
37
+ const permission = ws.permissions.findOneBy('slug', slug);
38
+ if (!permission)
39
+ throw notFound('Permission');
40
+ return c.json(formatPermission(permission));
41
+ });
42
+ app.put('/authorization/permissions/:slug', async (c) => {
43
+ const slug = c.req.param('slug');
44
+ const permission = ws.permissions.findOneBy('slug', slug);
45
+ if (!permission)
46
+ throw notFound('Permission');
47
+ const body = await parseJsonBody(c);
48
+ const updates = {};
49
+ if ('name' in body)
50
+ updates.name = body.name;
51
+ if ('description' in body)
52
+ updates.description = body.description ?? null;
53
+ const updated = ws.permissions.update(permission.id, updates);
54
+ return c.json(formatPermission(updated));
55
+ });
56
+ app.delete('/authorization/permissions/:slug', (c) => {
57
+ const slug = c.req.param('slug');
58
+ const permission = ws.permissions.findOneBy('slug', slug);
59
+ if (!permission)
60
+ throw notFound('Permission');
61
+ // Cascade: remove from all role-permission joins
62
+ ws.rolePermissions.deleteBy('permission_id', permission.id);
63
+ ws.permissions.delete(permission.id);
64
+ return c.body(null, 204);
65
+ });
66
+ }
67
+ //# sourceMappingURL=authorization-permissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization-permissions.js","sourceRoot":"","sources":["../../../../src/emulate/workos/routes/authorization-permissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACnH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAErE,MAAM,UAAU,6BAA6B,CAAC,GAAiB;IAC7D,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC;IAC3B,MAAM,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IAEjC,GAAG,CAAC,IAAI,CAAC,4BAA4B,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;QACjD,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,CAAC,CAAC,CAAC;QACpC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAc,CAAC;QACjC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAc,CAAC;QAEjC,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtC,MAAM,eAAe,CAAC,kBAAkB,EAAE,CAAC,EAAE,KAA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,CAAC,EAAE,EAAE;QACnD,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACjC,MAAM,UAAU,GAAG,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC1D,IAAI,CAAC,UAAU;YAAE,MAAM,QAAQ,CAAC,YAAY,CAAC,CAAC;QAE9C,iDAAiD;QACjD,EAAE,CAAC,eAAe,CAAC,QAAQ,CAAC,eAAe,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC;QAE5D,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QACrC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { type RouteContext, notFound, validationError, parseJsonBody, parseListParams } from '../../core/index.js';\nimport { getWorkOSStore } from '../store.js';\nimport { formatPermission, formatListResponse } from '../helpers.js';\n\nexport function authorizationPermissionRoutes(ctx: RouteContext): void {\n const { app, store } = ctx;\n const ws = getWorkOSStore(store);\n\n app.post('/authorization/permissions', async (c) => {\n const body = await parseJsonBody(c);\n const slug = body.slug as string;\n const name = body.name as string;\n\n if (!slug || typeof slug !== 'string') {\n throw validationError('slug is required', [{ field: 'slug', code: 'required' }]);\n }\n if (!name || typeof name !== 'string') {\n throw validationError('name is required', [{ field: 'name', code: 'required' }]);\n }\n\n const existing = ws.permissions.findOneBy('slug', slug);\n if (existing) {\n throw validationError('Permission with this slug already exists', [{ field: 'slug', code: 'duplicate' }]);\n }\n\n const permission = ws.permissions.insert({\n object: 'permission',\n slug,\n name,\n description: (body.description as string) ?? null,\n });\n\n return c.json(formatPermission(permission), 201);\n });\n\n app.get('/authorization/permissions', (c) => {\n const url = new URL(c.req.url);\n const params = parseListParams(url);\n\n const result = ws.permissions.list(params);\n return c.json(formatListResponse(result, formatPermission));\n });\n\n app.get('/authorization/permissions/:slug', (c) => {\n const slug = c.req.param('slug');\n const permission = ws.permissions.findOneBy('slug', slug);\n if (!permission) throw notFound('Permission');\n return c.json(formatPermission(permission));\n });\n\n app.put('/authorization/permissions/:slug', async (c) => {\n const slug = c.req.param('slug');\n const permission = ws.permissions.findOneBy('slug', slug);\n if (!permission) throw notFound('Permission');\n\n const body = await parseJsonBody(c);\n const updates: Record<string, unknown> = {};\n if ('name' in body) updates.name = body.name;\n if ('description' in body) updates.description = body.description ?? null;\n\n const updated = ws.permissions.update(permission.id, updates);\n return c.json(formatPermission(updated!));\n });\n\n app.delete('/authorization/permissions/:slug', (c) => {\n const slug = c.req.param('slug');\n const permission = ws.permissions.findOneBy('slug', slug);\n if (!permission) throw notFound('Permission');\n\n // Cascade: remove from all role-permission joins\n ws.rolePermissions.deleteBy('permission_id', permission.id);\n\n ws.permissions.delete(permission.id);\n return c.body(null, 204);\n });\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { type RouteContext } from '../../core/index.js';
2
+ export declare function authorizationResourceRoutes(ctx: RouteContext): void;
@@ -0,0 +1,117 @@
1
+ import { notFound, validationError, parseJsonBody, parseListParams } from '../../core/index.js';
2
+ import { getWorkOSStore } from '../store.js';
3
+ import { formatAuthorizationResource, formatMembership, formatListResponse } from '../helpers.js';
4
+ export function authorizationResourceRoutes(ctx) {
5
+ const { app, store } = ctx;
6
+ const ws = getWorkOSStore(store);
7
+ app.post('/authorization/resources', async (c) => {
8
+ const body = await parseJsonBody(c);
9
+ const resourceTypeSlug = body.resource_type_slug;
10
+ const externalId = body.external_id;
11
+ const organizationId = body.organization_id;
12
+ if (!resourceTypeSlug) {
13
+ throw validationError('resource_type_slug is required', [{ field: 'resource_type_slug', code: 'required' }]);
14
+ }
15
+ if (!externalId) {
16
+ throw validationError('external_id is required', [{ field: 'external_id', code: 'required' }]);
17
+ }
18
+ if (!organizationId) {
19
+ throw validationError('organization_id is required', [{ field: 'organization_id', code: 'required' }]);
20
+ }
21
+ const resource = ws.authorizationResources.insert({
22
+ object: 'authorization_resource',
23
+ resource_type_slug: resourceTypeSlug,
24
+ external_id: externalId,
25
+ organization_id: organizationId,
26
+ metadata: body.metadata ?? {},
27
+ });
28
+ return c.json(formatAuthorizationResource(resource), 201);
29
+ });
30
+ app.get('/authorization/resources', (c) => {
31
+ const url = new URL(c.req.url);
32
+ const params = parseListParams(url);
33
+ const organizationId = url.searchParams.get('organization_id') ?? undefined;
34
+ const resourceTypeSlug = url.searchParams.get('resource_type_slug') ?? undefined;
35
+ const result = ws.authorizationResources.list({
36
+ ...params,
37
+ filter: (r) => {
38
+ if (organizationId && r.organization_id !== organizationId)
39
+ return false;
40
+ if (resourceTypeSlug && r.resource_type_slug !== resourceTypeSlug)
41
+ return false;
42
+ return true;
43
+ },
44
+ });
45
+ return c.json(formatListResponse(result, formatAuthorizationResource));
46
+ });
47
+ app.get('/authorization/resources/:resource_id', (c) => {
48
+ const resourceId = c.req.param('resource_id');
49
+ const resource = ws.authorizationResources.get(resourceId);
50
+ if (!resource)
51
+ throw notFound('AuthorizationResource');
52
+ return c.json(formatAuthorizationResource(resource));
53
+ });
54
+ app.put('/authorization/resources/:resource_id', async (c) => {
55
+ const resourceId = c.req.param('resource_id');
56
+ const resource = ws.authorizationResources.get(resourceId);
57
+ if (!resource)
58
+ throw notFound('AuthorizationResource');
59
+ const body = await parseJsonBody(c);
60
+ const updates = {};
61
+ if ('metadata' in body)
62
+ updates.metadata = body.metadata;
63
+ const updated = ws.authorizationResources.update(resourceId, updates);
64
+ return c.json(formatAuthorizationResource(updated));
65
+ });
66
+ app.delete('/authorization/resources/:resource_id', (c) => {
67
+ const resourceId = c.req.param('resource_id');
68
+ const resource = ws.authorizationResources.get(resourceId);
69
+ if (!resource)
70
+ throw notFound('AuthorizationResource');
71
+ ws.authorizationResources.delete(resourceId);
72
+ return c.body(null, 204);
73
+ });
74
+ // Memberships with access to a resource (by resource ID)
75
+ app.get('/authorization/resources/:resource_id/organization_memberships', (c) => {
76
+ const resourceId = c.req.param('resource_id');
77
+ const resource = ws.authorizationResources.get(resourceId);
78
+ if (!resource)
79
+ throw notFound('AuthorizationResource');
80
+ const memberships = ws.organizationMemberships.findBy('organization_id', resource.organization_id);
81
+ return c.json({
82
+ object: 'list',
83
+ data: memberships.map(formatMembership),
84
+ list_metadata: { before: null, after: null },
85
+ });
86
+ });
87
+ // Get resource by type + external ID within an org
88
+ app.get('/authorization/organizations/:orgId/resources/:type_slug/:external_id', (c) => {
89
+ const orgId = c.req.param('orgId');
90
+ const typeSlug = c.req.param('type_slug');
91
+ const externalId = c.req.param('external_id');
92
+ const resource = ws.authorizationResources
93
+ .findBy('organization_id', orgId)
94
+ .find((r) => r.resource_type_slug === typeSlug && r.external_id === externalId);
95
+ if (!resource)
96
+ throw notFound('AuthorizationResource');
97
+ return c.json(formatAuthorizationResource(resource));
98
+ });
99
+ // Memberships for resource by type + external ID within an org
100
+ app.get('/authorization/organizations/:orgId/resources/:type_slug/:external_id/organization_memberships', (c) => {
101
+ const orgId = c.req.param('orgId');
102
+ const typeSlug = c.req.param('type_slug');
103
+ const externalId = c.req.param('external_id');
104
+ const resource = ws.authorizationResources
105
+ .findBy('organization_id', orgId)
106
+ .find((r) => r.resource_type_slug === typeSlug && r.external_id === externalId);
107
+ if (!resource)
108
+ throw notFound('AuthorizationResource');
109
+ const memberships = ws.organizationMemberships.findBy('organization_id', resource.organization_id);
110
+ return c.json({
111
+ object: 'list',
112
+ data: memberships.map(formatMembership),
113
+ list_metadata: { before: null, after: null },
114
+ });
115
+ });
116
+ }
117
+ //# sourceMappingURL=authorization-resources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization-resources.js","sourceRoot":"","sources":["../../../../src/emulate/workos/routes/authorization-resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACnH,OAAO,EAAE,cAAc,EAAE,MA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, validationError, parseJsonBody, parseListParams } from '../../core/index.js';\nimport { getWorkOSStore } from '../store.js';\nimport { formatAuthorizationResource, formatMembership, formatListResponse } from '../helpers.js';\n\nexport function authorizationResourceRoutes(ctx: RouteContext): void {\n const { app, store } = ctx;\n const ws = getWorkOSStore(store);\n\n app.post('/authorization/resources', async (c) => {\n const body = await parseJsonBody(c);\n\n const resourceTypeSlug = body.resource_type_slug as string;\n const externalId = body.external_id as string;\n const organizationId = body.organization_id as string;\n\n if (!resourceTypeSlug) {\n throw validationError('resource_type_slug is required', [{ field: 'resource_type_slug', code: 'required' }]);\n }\n if (!externalId) {\n throw validationError('external_id is required', [{ field: 'external_id', code: 'required' }]);\n }\n if (!organizationId) {\n throw validationError('organization_id is required', [{ field: 'organization_id', code: 'required' }]);\n }\n\n const resource = ws.authorizationResources.insert({\n object: 'authorization_resource',\n resource_type_slug: resourceTypeSlug,\n external_id: externalId,\n organization_id: organizationId,\n metadata: (body.metadata as Record<string, string>) ?? {},\n });\n\n return c.json(formatAuthorizationResource(resource), 201);\n });\n\n app.get('/authorization/resources', (c) => {\n const url = new URL(c.req.url);\n const params = parseListParams(url);\n const organizationId = url.searchParams.get('organization_id') ?? undefined;\n const resourceTypeSlug = url.searchParams.get('resource_type_slug') ?? undefined;\n\n const result = ws.authorizationResources.list({\n ...params,\n filter: (r) => {\n if (organizationId && r.organization_id !== organizationId) return false;\n if (resourceTypeSlug && r.resource_type_slug !== resourceTypeSlug) return false;\n return true;\n },\n });\n\n return c.json(formatListResponse(result, formatAuthorizationResource));\n });\n\n app.get('/authorization/resources/:resource_id', (c) => {\n const resourceId = c.req.param('resource_id');\n const resource = ws.authorizationResources.get(resourceId);\n if (!resource) throw notFound('AuthorizationResource');\n return c.json(formatAuthorizationResource(resource));\n });\n\n app.put('/authorization/resources/:resource_id', async (c) => {\n const resourceId = c.req.param('resource_id');\n const resource = ws.authorizationResources.get(resourceId);\n if (!resource) throw notFound('AuthorizationResource');\n\n const body = await parseJsonBody(c);\n const updates: Record<string, unknown> = {};\n if ('metadata' in body) updates.metadata = body.metadata;\n\n const updated = ws.authorizationResources.update(resourceId, updates);\n return c.json(formatAuthorizationResource(updated!));\n });\n\n app.delete('/authorization/resources/:resource_id', (c) => {\n const resourceId = c.req.param('resource_id');\n const resource = ws.authorizationResources.get(resourceId);\n if (!resource) throw notFound('AuthorizationResource');\n\n ws.authorizationResources.delete(resourceId);\n return c.body(null, 204);\n });\n\n // Memberships with access to a resource (by resource ID)\n app.get('/authorization/resources/:resource_id/organization_memberships', (c) => {\n const resourceId = c.req.param('resource_id');\n const resource = ws.authorizationResources.get(resourceId);\n if (!resource) throw notFound('AuthorizationResource');\n\n const memberships = ws.organizationMemberships.findBy('organization_id', resource.organization_id);\n return c.json({\n object: 'list',\n data: memberships.map(formatMembership),\n list_metadata: { before: null, after: null },\n });\n });\n\n // Get resource by type + external ID within an org\n app.get('/authorization/organizations/:orgId/resources/:type_slug/:external_id', (c) => {\n const orgId = c.req.param('orgId');\n const typeSlug = c.req.param('type_slug');\n const externalId = c.req.param('external_id');\n\n const resource = ws.authorizationResources\n .findBy('organization_id', orgId)\n .find((r) => r.resource_type_slug === typeSlug && r.external_id === externalId);\n if (!resource) throw notFound('AuthorizationResource');\n return c.json(formatAuthorizationResource(resource));\n });\n\n // Memberships for resource by type + external ID within an org\n app.get('/authorization/organizations/:orgId/resources/:type_slug/:external_id/organization_memberships', (c) => {\n const orgId = c.req.param('orgId');\n const typeSlug = c.req.param('type_slug');\n const externalId = c.req.param('external_id');\n\n const resource = ws.authorizationResources\n .findBy('organization_id', orgId)\n .find((r) => r.resource_type_slug === typeSlug && r.external_id === externalId);\n if (!resource) throw notFound('AuthorizationResource');\n\n const memberships = ws.organizationMemberships.findBy('organization_id', resource.organization_id);\n return c.json({\n object: 'list',\n data: memberships.map(formatMembership),\n list_metadata: { before: null, after: null },\n });\n });\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import type { RouteContext } from '../../core/index.js';
2
+ export declare function authorizationRoleRoutes(ctx: RouteContext): void;
@@ -0,0 +1,13 @@
1
+ import { findEnvRole, requireEnvRole, registerRoleRoutes } from '../role-helpers.js';
2
+ export function authorizationRoleRoutes(ctx) {
3
+ registerRoleRoutes(ctx, {
4
+ pathPrefix: '/authorization/roles',
5
+ roleType: 'EnvironmentRole',
6
+ requireRole: (ws, c) => requireEnvRole(ws, c.req.param('slug')),
7
+ findRole: (ws, _c, slug) => findEnvRole(ws, slug),
8
+ listFilter: () => (r) => r.type === 'EnvironmentRole',
9
+ insertDefaults: () => ({ organization_id: null }),
10
+ duplicateMessage: 'Role with this slug already exists',
11
+ });
12
+ }
13
+ //# sourceMappingURL=authorization-roles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization-roles.js","sourceRoot":"","sources":["../../../../src/emulate/workos/routes/authorization-roles.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAErF,MAAM,UAAU,uBAAuB,CAAC,GAAiB;IACvD,kBAAkB,CAAC,GAAG,EAAE;QACtB,UAAU,EAAE,sBAAsB;QAClC,QAAQ,EAAE,iBAAiB;QAC3B,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC/D,QAAQ,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,IAAI,CAAC;QACjD,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,iBAAiB;QACrD,cAAc,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC;QACjD,gBAAgB,EAAE,oCAAoC;KACvD,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { RouteContext } from '../../core/index.js';\nimport { findEnvRole, requireEnvRole, registerRoleRoutes } from '../role-helpers.js';\n\nexport function authorizationRoleRoutes(ctx: RouteContext): void {\n registerRoleRoutes(ctx, {\n pathPrefix: '/authorization/roles',\n roleType: 'EnvironmentRole',\n requireRole: (ws, c) => requireEnvRole(ws, c.req.param('slug')),\n findRole: (ws, _c, slug) => findEnvRole(ws, slug),\n listFilter: () => (r) => r.type === 'EnvironmentRole',\n insertDefaults: () => ({ organization_id: null }),\n duplicateMessage: 'Role with this slug already exists',\n });\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { type RouteContext } from '../../core/index.js';
2
+ export declare function configRoutes(ctx: RouteContext): void;
@@ -0,0 +1,57 @@
1
+ import { parseJsonBody, WorkOSApiError, validationError } from '../../core/index.js';
2
+ import { getWorkOSStore } from '../store.js';
3
+ import { formatRedirectUri, formatCorsOrigin } from '../helpers.js';
4
+ import { STORE_KEYS } from '../constants.js';
5
+ export function configRoutes(ctx) {
6
+ const { app, store } = ctx;
7
+ const ws = getWorkOSStore(store);
8
+ app.post('/user_management/redirect_uris', async (c) => {
9
+ const body = await parseJsonBody(c);
10
+ const uri = body.uri;
11
+ if (!uri) {
12
+ throw validationError('uri is required', [{ field: 'uri', code: 'required' }]);
13
+ }
14
+ const existing = ws.redirectUris.findOneBy('uri', uri);
15
+ if (existing) {
16
+ throw new WorkOSApiError(422, 'Redirect URI already exists', 'redirect_uri_already_exists');
17
+ }
18
+ const redirectUri = ws.redirectUris.insert({
19
+ object: 'redirect_uri',
20
+ uri,
21
+ });
22
+ return c.json(formatRedirectUri(redirectUri), 201);
23
+ });
24
+ app.post('/user_management/cors_origins', async (c) => {
25
+ const body = await parseJsonBody(c);
26
+ const origin = body.origin;
27
+ if (!origin) {
28
+ throw validationError('origin is required', [{ field: 'origin', code: 'required' }]);
29
+ }
30
+ const existing = ws.corsOrigins.findOneBy('origin', origin);
31
+ if (existing) {
32
+ throw new WorkOSApiError(422, 'CORS origin already exists', 'cors_origin_already_exists');
33
+ }
34
+ const corsOrigin = ws.corsOrigins.insert({
35
+ object: 'cors_origin',
36
+ origin,
37
+ });
38
+ return c.json(formatCorsOrigin(corsOrigin), 201);
39
+ });
40
+ app.get('/user_management/jwt_template', (c) => {
41
+ const template = store.getData(STORE_KEYS.jwtTemplate) ?? {
42
+ object: 'jwt_template',
43
+ custom_claims: {},
44
+ };
45
+ return c.json(template);
46
+ });
47
+ app.put('/user_management/jwt_template', async (c) => {
48
+ const body = await parseJsonBody(c);
49
+ const template = {
50
+ object: 'jwt_template',
51
+ custom_claims: body.custom_claims ?? {},
52
+ };
53
+ store.setData(STORE_KEYS.jwtTemplate, template);
54
+ return c.json(template);
55
+ });
56
+ }
57
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../src/emulate/workos/routes/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,aAAa,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACxG,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,MAAM,UAAU,YAAY,CAAC,GAAiB;IAC5C,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC;IAC3B,MAAM,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IAEjC,GAAG,CAAC,IAAI,CAAC,gCAAgC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;QACrD,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,CAAC,CAAC,CAAC;QACpC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAyB,CAAC;QAC3C,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,eAAe,CAAC,iBAAiB,EAAE,CAAC,EAAE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,CAAC,UAAU,CAAC,EAAE,GAAG,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,GAAG,CAAC,GAAG,CAAC,+BAA+B,EAAE,CAAC,CAAC,EAAE,EAAE;QAC7C,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAA0B,UAAU,CAAC,WAAW,CAAC,IAAI;YACjF,MAAM,EAAE,cAAc;YACtB,aAAa,EAAE,EAAE;SAClB,CAAC;QACF,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEH,GAAG,CAAC,GAAG,CAAC,+BAA+B,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;QACnD,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,CAAC,CAAC,CAAC;QACpC,MAAM,QAAQ,GAAG;YACf,MAAM,EAAE,cAAc;YACtB,aAAa,EAAG,IAAI,CAAC,aAAyC,IAAI,EAAE;SACrE,CAAC;QACF,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QAChD,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { type RouteContext, parseJsonBody, WorkOSApiError, validationError } from '../../core/index.js';\nimport { getWorkOSStore } from '../store.js';\nimport { formatRedirectUri, formatCorsOrigin } from '../helpers.js';\nimport { STORE_KEYS } from '../constants.js';\n\nexport function configRoutes(ctx: RouteContext): void {\n const { app, store } = ctx;\n const ws = getWorkOSStore(store);\n\n app.post('/user_management/redirect_uris', async (c) => {\n const body = await parseJsonBody(c);\n const uri = body.uri as string | undefined;\n if (!uri) {\n throw validationError('uri is required', [{ field: 'uri', code: 'required' }]);\n }\n\n const existing = ws.redirectUris.findOneBy('uri', uri);\n if (existing) {\n throw new WorkOSApiError(422, 'Redirect URI already exists', 'redirect_uri_already_exists');\n }\n\n const redirectUri = ws.redirectUris.insert({\n object: 'redirect_uri',\n uri,\n });\n\n return c.json(formatRedirectUri(redirectUri), 201);\n });\n\n app.post('/user_management/cors_origins', async (c) => {\n const body = await parseJsonBody(c);\n const origin = body.origin as string | undefined;\n if (!origin) {\n throw validationError('origin is required', [{ field: 'origin', code: 'required' }]);\n }\n\n const existing = ws.corsOrigins.findOneBy('origin', origin);\n if (existing) {\n throw new WorkOSApiError(422, 'CORS origin already exists', 'cors_origin_already_exists');\n }\n\n const corsOrigin = ws.corsOrigins.insert({\n object: 'cors_origin',\n origin,\n });\n\n return c.json(formatCorsOrigin(corsOrigin), 201);\n });\n\n app.get('/user_management/jwt_template', (c) => {\n const template = store.getData<Record<string, unknown>>(STORE_KEYS.jwtTemplate) ?? {\n object: 'jwt_template',\n custom_claims: {},\n };\n return c.json(template);\n });\n\n app.put('/user_management/jwt_template', async (c) => {\n const body = await parseJsonBody(c);\n const template = {\n object: 'jwt_template',\n custom_claims: (body.custom_claims as Record<string, unknown>) ?? {},\n };\n store.setData(STORE_KEYS.jwtTemplate, template);\n return c.json(template);\n });\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { type RouteContext } from '../../core/index.js';
2
+ export declare function connectRoutes(ctx: RouteContext): void;
@@ -0,0 +1,65 @@
1
+ import { notFound, parseJsonBody, validationError, parseListParams } from '../../core/index.js';
2
+ import { generateId } from '../../core/index.js';
3
+ import { getWorkOSStore } from '../store.js';
4
+ import { formatConnectApplication, formatClientSecret, generateVerificationToken, formatListResponse, } from '../helpers.js';
5
+ export function connectRoutes(ctx) {
6
+ const { app, store } = ctx;
7
+ const ws = getWorkOSStore(store);
8
+ // List applications
9
+ app.get('/connect/applications', (c) => {
10
+ const url = new URL(c.req.url);
11
+ const params = parseListParams(url);
12
+ const result = ws.connectApplications.list({ ...params });
13
+ return c.json(formatListResponse(result, formatConnectApplication));
14
+ });
15
+ // Create application
16
+ app.post('/connect/applications', async (c) => {
17
+ const body = await parseJsonBody(c);
18
+ const name = body.name;
19
+ if (!name || typeof name !== 'string' || name.trim().length === 0) {
20
+ throw validationError('name is required', [{ field: 'name', code: 'required' }]);
21
+ }
22
+ const application = ws.connectApplications.insert({
23
+ object: 'connect_application',
24
+ name: name.trim(),
25
+ redirect_uris: body.redirect_uris ?? [],
26
+ client_id: `client_${generateId('connect')}`,
27
+ logo_url: body.logo_url ?? null,
28
+ });
29
+ return c.json(formatConnectApplication(application), 201);
30
+ });
31
+ // Get application
32
+ app.get('/connect/applications/:id', (c) => {
33
+ const application = ws.connectApplications.get(c.req.param('id'));
34
+ if (!application)
35
+ throw notFound('ConnectApplication');
36
+ return c.json(formatConnectApplication(application));
37
+ });
38
+ // Create client secret
39
+ app.post('/connect/applications/:id/client_secrets', (c) => {
40
+ const application = ws.connectApplications.get(c.req.param('id'));
41
+ if (!application)
42
+ throw notFound('ConnectApplication');
43
+ const value = `secret_${generateVerificationToken()}`;
44
+ const secret = ws.clientSecrets.insert({
45
+ object: 'client_secret',
46
+ application_id: application.id,
47
+ value,
48
+ last_four: value.slice(-4),
49
+ });
50
+ // Return full value only on creation
51
+ return c.json({
52
+ ...formatClientSecret(secret),
53
+ value: secret.value,
54
+ }, 201);
55
+ });
56
+ // Revoke client secret
57
+ app.delete('/connect/client_secrets/:id', (c) => {
58
+ const secret = ws.clientSecrets.get(c.req.param('id'));
59
+ if (!secret)
60
+ throw notFound('ClientSecret');
61
+ ws.clientSecrets.delete(secret.id);
62
+ return c.body(null, 204);
63
+ });
64
+ }
65
+ //# sourceMappingURL=connect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect.js","sourceRoot":"","sources":["../../../../src/emulate/workos/routes/connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACnH,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EACL,wBA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C;QACrC,OAAO,CAAC,CAAC,IAAI,CACX;YACE,GAAG,kBAAkB,CAAC,MAAM,CAAC;YAC7B,KAAK,EAAE,MAAM,CAAC,KAAK;SACpB,EACD,GAAG,CACJ,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,uBAAuB;IACvB,GAAG,CAAC,MAAM,CAAC,6BAA6B,EAAE,CAAC,CAAC,EAAE,EAAE;QAC9C,MAAM,MAAM,GAAG,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QACvD,IAAI,CAAC,MAAM;YAAE,MAAM,QAAQ,CAAC,cAAc,CAAC,CAAC;QAC5C,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACnC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { type RouteContext, notFound, parseJsonBody, validationError, parseListParams } from '../../core/index.js';\nimport { generateId } from '../../core/index.js';\nimport { getWorkOSStore } from '../store.js';\nimport {\n formatConnectApplication,\n formatClientSecret,\n generateVerificationToken,\n formatListResponse,\n} from '../helpers.js';\n\nexport function connectRoutes(ctx: RouteContext): void {\n const { app, store } = ctx;\n const ws = getWorkOSStore(store);\n\n // List applications\n app.get('/connect/applications', (c) => {\n const url = new URL(c.req.url);\n const params = parseListParams(url);\n const result = ws.connectApplications.list({ ...params });\n return c.json(formatListResponse(result, formatConnectApplication));\n });\n\n // Create application\n app.post('/connect/applications', async (c) => {\n const body = await parseJsonBody(c);\n const name = body.name as string | undefined;\n if (!name || typeof name !== 'string' || name.trim().length === 0) {\n throw validationError('name is required', [{ field: 'name', code: 'required' }]);\n }\n\n const application = ws.connectApplications.insert({\n object: 'connect_application',\n name: name.trim(),\n redirect_uris: (body.redirect_uris as string[]) ?? [],\n client_id: `client_${generateId('connect')}`,\n logo_url: (body.logo_url as string) ?? null,\n });\n\n return c.json(formatConnectApplication(application), 201);\n });\n\n // Get application\n app.get('/connect/applications/:id', (c) => {\n const application = ws.connectApplications.get(c.req.param('id'));\n if (!application) throw notFound('ConnectApplication');\n return c.json(formatConnectApplication(application));\n });\n\n // Create client secret\n app.post('/connect/applications/:id/client_secrets', (c) => {\n const application = ws.connectApplications.get(c.req.param('id'));\n if (!application) throw notFound('ConnectApplication');\n\n const value = `secret_${generateVerificationToken()}`;\n const secret = ws.clientSecrets.insert({\n object: 'client_secret',\n application_id: application.id,\n value,\n last_four: value.slice(-4),\n });\n\n // Return full value only on creation\n return c.json(\n {\n ...formatClientSecret(secret),\n value: secret.value,\n },\n 201,\n );\n });\n\n // Revoke client secret\n app.delete('/connect/client_secrets/:id', (c) => {\n const secret = ws.clientSecrets.get(c.req.param('id'));\n if (!secret) throw notFound('ClientSecret');\n ws.clientSecrets.delete(secret.id);\n return c.body(null, 204);\n });\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { type RouteContext } from '../../core/index.js';
2
+ export declare function connectionRoutes(ctx: RouteContext): void;
@@ -0,0 +1,73 @@
1
+ import { notFound, parseJsonBody, generateId, parseListParams } from '../../core/index.js';
2
+ import { getWorkOSStore } from '../store.js';
3
+ import { formatConnection, formatListResponse } from '../helpers.js';
4
+ export function connectionRoutes(ctx) {
5
+ const { app, store } = ctx;
6
+ const ws = getWorkOSStore(store);
7
+ app.post('/connections', async (c) => {
8
+ const body = await parseJsonBody(c);
9
+ const name = body.name;
10
+ const organizationId = body.organization_id;
11
+ const connectionType = body.connection_type ?? 'GenericSAML';
12
+ const domainsList = body.domains ?? [];
13
+ if (!organizationId) {
14
+ throw notFound('Organization');
15
+ }
16
+ const org = ws.organizations.get(organizationId);
17
+ if (!org)
18
+ throw notFound('Organization');
19
+ const domains = domainsList.map((d) => ({
20
+ object: 'connection_domain',
21
+ id: generateId('conn_domain'),
22
+ domain: d,
23
+ }));
24
+ const conn = ws.connections.insert({
25
+ object: 'connection',
26
+ organization_id: organizationId,
27
+ connection_type: connectionType,
28
+ name: name ?? `${org.name} SSO`,
29
+ state: 'active',
30
+ domains,
31
+ });
32
+ return c.json(formatConnection(conn), 201);
33
+ });
34
+ app.get('/connections', (c) => {
35
+ const url = new URL(c.req.url);
36
+ const params = parseListParams(url);
37
+ const orgFilter = url.searchParams.get('organization_id') ?? undefined;
38
+ const typeFilter = url.searchParams.get('connection_type') ?? undefined;
39
+ const domainFilter = url.searchParams.get('domain') ?? undefined;
40
+ const result = ws.connections.list({
41
+ ...params,
42
+ filter: (conn) => {
43
+ if (orgFilter && conn.organization_id !== orgFilter)
44
+ return false;
45
+ if (typeFilter && conn.connection_type !== typeFilter)
46
+ return false;
47
+ if (domainFilter && !conn.domains.some((d) => d.domain === domainFilter))
48
+ return false;
49
+ return true;
50
+ },
51
+ });
52
+ return c.json(formatListResponse(result, formatConnection));
53
+ });
54
+ app.get('/connections/:id', (c) => {
55
+ const conn = ws.connections.get(c.req.param('id'));
56
+ if (!conn)
57
+ throw notFound('Connection');
58
+ return c.json(formatConnection(conn));
59
+ });
60
+ app.delete('/connections/:id', (c) => {
61
+ const conn = ws.connections.get(c.req.param('id'));
62
+ if (!conn)
63
+ throw notFound('Connection');
64
+ for (const auth of ws.ssoAuthorizations.all()) {
65
+ if (auth.connection_id === conn.id) {
66
+ ws.ssoAuthorizations.delete(auth.id);
67
+ }
68
+ }
69
+ ws.connections.delete(conn.id);
70
+ return c.body(null, 204);
71
+ });
72
+ }
73
+ //# sourceMappingURL=connections.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connections.js","sourceRoot":"","sources":["../../../../src/emulate/workos/routes/connections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC9G,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,kB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AkB,EAAE,CAAC,CAAC,EAAE,EAAE;QAChC,MAAM,IAAI,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QACnD,IAAI,CAAC,IAAI;YAAE,MAAM,QAAQ,CAAC,YAAY,CAAC,CAAC;QACxC,OAAO,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,GAAG,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC,CAAC,EAAE,EAAE;QACnC,MAAM,IAAI,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QACnD,IAAI,CAAC,IAAI;YAAE,MAAM,QAAQ,CAAC,YAAY,CAAC,CAAC;QAExC,KAAK,MAAM,IAAI,IAAI,EAAE,CAAC,iBAAiB,CAAC,GAAG,EAAE,EAAE,CAAC;YAC9C,IAAI,IAAI,CAAC,aAAa,KAAK,IAAI,CAAC,EAAE,EAAE,CAAC;gBACnC,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;QAED,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/B,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { type RouteContext, notFound, parseJsonBody, generateId, parseListParams } from '../../core/index.js';\nimport { getWorkOSStore } from '../store.js';\nimport { formatConnection, formatListResponse } from '../helpers.js';\nimport type { WorkOSConnectionType } from '../entities.js';\n\nexport function connectionRoutes(ctx: RouteContext): void {\n const { app, store } = ctx;\n const ws = getWorkOSStore(store);\n\n app.post('/connections', async (c) => {\n const body = await parseJsonBody(c);\n const name = body.name as string;\n const organizationId = body.organization_id as string;\n const connectionType = (body.connection_type as WorkOSConnectionType) ?? 'GenericSAML';\n const domainsList = (body.domains as string[]) ?? [];\n\n if (!organizationId) {\n throw notFound('Organization');\n }\n const org = ws.organizations.get(organizationId);\n if (!org) throw notFound('Organization');\n\n const domains = domainsList.map((d) => ({\n object: 'connection_domain' as const,\n id: generateId('conn_domain'),\n domain: d,\n }));\n\n const conn = ws.connections.insert({\n object: 'connection',\n organization_id: organizationId,\n connection_type: connectionType,\n name: name ?? `${org.name} SSO`,\n state: 'active',\n domains,\n });\n\n return c.json(formatConnection(conn), 201);\n });\n\n app.get('/connections', (c) => {\n const url = new URL(c.req.url);\n const params = parseListParams(url);\n const orgFilter = url.searchParams.get('organization_id') ?? undefined;\n const typeFilter = url.searchParams.get('connection_type') ?? undefined;\n const domainFilter = url.searchParams.get('domain') ?? undefined;\n\n const result = ws.connections.list({\n ...params,\n filter: (conn) => {\n if (orgFilter && conn.organization_id !== orgFilter) return false;\n if (typeFilter && conn.connection_type !== typeFilter) return false;\n if (domainFilter && !conn.domains.some((d) => d.domain === domainFilter)) return false;\n return true;\n },\n });\n\n return c.json(formatListResponse(result, formatConnection));\n });\n\n app.get('/connections/:id', (c) => {\n const conn = ws.connections.get(c.req.param('id'));\n if (!conn) throw notFound('Connection');\n return c.json(formatConnection(conn));\n });\n\n app.delete('/connections/:id', (c) => {\n const conn = ws.connections.get(c.req.param('id'));\n if (!conn) throw notFound('Connection');\n\n for (const auth of ws.ssoAuthorizations.all()) {\n if (auth.connection_id === conn.id) {\n ws.ssoAuthorizations.delete(auth.id);\n }\n }\n\n ws.connections.delete(conn.id);\n return c.body(null, 204);\n });\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { type RouteContext } from '../../core/index.js';
2
+ export declare function dataIntegrationRoutes(ctx: RouteContext): void;
@@ -0,0 +1,55 @@
1
+ import { parseJsonBody, WorkOSApiError } from '../../core/index.js';
2
+ import { getWorkOSStore } from '../store.js';
3
+ import { assertLocalRedirectUri, generateVerificationToken, expiresIn, isExpired } from '../helpers.js';
4
+ export function dataIntegrationRoutes(ctx) {
5
+ const { app, store } = ctx;
6
+ const ws = getWorkOSStore(store);
7
+ // Authorize (public endpoint — no auth required)
8
+ app.get('/data-integrations/:slug/authorize', (c) => {
9
+ const slug = c.req.param('slug');
10
+ const url = new URL(c.req.url);
11
+ const redirectUri = url.searchParams.get('redirect_uri');
12
+ const state = url.searchParams.get('state') ?? null;
13
+ if (!redirectUri) {
14
+ throw new WorkOSApiError(400, 'redirect_uri is required', 'invalid_request');
15
+ }
16
+ assertLocalRedirectUri(redirectUri);
17
+ const code = generateVerificationToken();
18
+ ws.dataIntegrationAuths.insert({
19
+ slug,
20
+ code,
21
+ redirect_uri: redirectUri,
22
+ state,
23
+ expires_at: expiresIn(10),
24
+ });
25
+ const redirect = new URL(redirectUri);
26
+ redirect.searchParams.set('code', code);
27
+ if (state)
28
+ redirect.searchParams.set('state', state);
29
+ return c.redirect(redirect.toString(), 302);
30
+ });
31
+ // Exchange code for token
32
+ app.post('/data-integrations/:slug/token', async (c) => {
33
+ const slug = c.req.param('slug');
34
+ const body = await parseJsonBody(c);
35
+ const code = body.code;
36
+ if (!code) {
37
+ throw new WorkOSApiError(400, 'code is required', 'invalid_request');
38
+ }
39
+ const auth = ws.dataIntegrationAuths.findOneBy('code', code);
40
+ if (!auth || auth.slug !== slug) {
41
+ throw new WorkOSApiError(400, 'Invalid authorization code', 'invalid_grant');
42
+ }
43
+ if (isExpired(auth.expires_at)) {
44
+ ws.dataIntegrationAuths.delete(auth.id);
45
+ throw new WorkOSApiError(400, 'Authorization code has expired', 'invalid_grant');
46
+ }
47
+ ws.dataIntegrationAuths.delete(auth.id);
48
+ return c.json({
49
+ access_token: `di_mock_${slug}_${generateVerificationToken().slice(0, 8)}`,
50
+ token_type: 'bearer',
51
+ expires_in: 3600,
52
+ });
53
+ });
54
+ }
55
+ //# sourceMappingURL=data-integrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-integrations.js","sourceRoot":"","sources":["../../../../src/emulate/workos/routes/data-integrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,aAAa,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACvF,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAExG,MAAM,UAAU,qBAAqB,CAAC,GAAiB;IACrD,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC;IAC3B,MAAM,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IAEjC,iDAAiD;IACjD,GAAG,CAAC,GAAG,CAAC,oCAAoC,EAAE,CAAC,CAAC,EAAE,EAAE;QAClD,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACjC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,WAAW,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QACzD,MAAM,KAAK,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC;QAEpD,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,cAAc,CAAC,GAAG,EAAE,0BAA0B,EAAE,iBAAiB,CAAC,CAAC;QAC/E,CAAC;QACD,sBAAsB,CAAC,WAAW,CAAC,CAAC;QAEpC,MAAM,IAAI,GAAG,yBAAyB,EAAE,CAAC;QACzC,EAAE,CAAC,oBAAoB,CAAC,MAAM,CAAC;YAC7B,IAAI;YACJ,IAAI;YACJ,YAAY,EAAE,WAAW;YACzB,KAAK;YACL,UAAU,EAAE,SAAS,CAAC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AAC;QACnF,CAAC;QAED,EAAE,CAAC,oBAAoB,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAExC,OAAO,CAAC,CAAC,IAAI,CAAC;YACZ,YAAY,EAAE,WAAW,IAAI,IAAI,yBAAyB,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;YAC1E,UAAU,EAAE,QAAQ;YACpB,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { type RouteContext, parseJsonBody, WorkOSApiError } from '../../core/index.js';\nimport { getWorkOSStore } from '../store.js';\nimport { assertLocalRedirectUri, generateVerificationToken, expiresIn, isExpired } from '../helpers.js';\n\nexport function dataIntegrationRoutes(ctx: RouteContext): void {\n const { app, store } = ctx;\n const ws = getWorkOSStore(store);\n\n // Authorize (public endpoint — no auth required)\n app.get('/data-integrations/:slug/authorize', (c) => {\n const slug = c.req.param('slug');\n const url = new URL(c.req.url);\n const redirectUri = url.searchParams.get('redirect_uri');\n const state = url.searchParams.get('state') ?? null;\n\n if (!redirectUri) {\n throw new WorkOSApiError(400, 'redirect_uri is required', 'invalid_request');\n }\n assertLocalRedirectUri(redirectUri);\n\n const code = generateVerificationToken();\n ws.dataIntegrationAuths.insert({\n slug,\n code,\n redirect_uri: redirectUri,\n state,\n expires_at: expiresIn(10),\n });\n\n const redirect = new URL(redirectUri);\n redirect.searchParams.set('code', code);\n if (state) redirect.searchParams.set('state', state);\n\n return c.redirect(redirect.toString(), 302);\n });\n\n // Exchange code for token\n app.post('/data-integrations/:slug/token', async (c) => {\n const slug = c.req.param('slug');\n const body = await parseJsonBody(c);\n const code = body.code as string | undefined;\n\n if (!code) {\n throw new WorkOSApiError(400, 'code is required', 'invalid_request');\n }\n\n const auth = ws.dataIntegrationAuths.findOneBy('code', code);\n if (!auth || auth.slug !== slug) {\n throw new WorkOSApiError(400, 'Invalid authorization code', 'invalid_grant');\n }\n\n if (isExpired(auth.expires_at)) {\n ws.dataIntegrationAuths.delete(auth.id);\n throw new WorkOSApiError(400, 'Authorization code has expired', 'invalid_grant');\n }\n\n ws.dataIntegrationAuths.delete(auth.id);\n\n return c.json({\n access_token: `di_mock_${slug}_${generateVerificationToken().slice(0, 8)}`,\n token_type: 'bearer',\n expires_in: 3600,\n });\n });\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { type RouteContext } from '../../core/index.js';
2
+ export declare function directoryRoutes(ctx: RouteContext): void;