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,2 @@
1
+ import { type RouteContext } from '../../core/index.js';
2
+ export declare function membershipRoutes(ctx: RouteContext): void;
@@ -0,0 +1,114 @@
1
+ import { notFound, validationError, parseJsonBody, WorkOSApiError, parseListParams, } from '../../core/index.js';
2
+ import { getWorkOSStore } from '../store.js';
3
+ import { formatMembership, formatListResponse } from '../helpers.js';
4
+ export function membershipRoutes(ctx) {
5
+ const { app, store } = ctx;
6
+ const ws = getWorkOSStore(store);
7
+ app.post('/user_management/organization_memberships', async (c) => {
8
+ const body = await parseJsonBody(c);
9
+ const organizationId = body.organization_id;
10
+ const userId = body.user_id;
11
+ if (!organizationId) {
12
+ throw validationError('organization_id is required', [{ field: 'organization_id', code: 'required' }]);
13
+ }
14
+ if (!userId) {
15
+ throw validationError('user_id is required', [{ field: 'user_id', code: 'required' }]);
16
+ }
17
+ const org = ws.organizations.get(organizationId);
18
+ if (!org)
19
+ throw notFound('Organization');
20
+ const existing = ws.organizationMemberships
21
+ .findBy('organization_id', organizationId)
22
+ .find((m) => m.user_id === userId && m.status !== 'inactive');
23
+ if (existing) {
24
+ throw new WorkOSApiError(409, 'Membership already exists', 'conflict');
25
+ }
26
+ const roleSlug = body.role_slug ?? 'member';
27
+ const membership = ws.organizationMemberships.insert({
28
+ object: 'organization_membership',
29
+ organization_id: organizationId,
30
+ user_id: userId,
31
+ role: { slug: roleSlug },
32
+ status: 'active',
33
+ external_id: body.external_id ?? null,
34
+ metadata: body.metadata ?? {},
35
+ });
36
+ return c.json(formatMembership(membership), 201);
37
+ });
38
+ app.get('/user_management/organization_memberships', (c) => {
39
+ const url = new URL(c.req.url);
40
+ const params = parseListParams(url);
41
+ const orgFilter = url.searchParams.get('organization_id') ?? undefined;
42
+ const userFilter = url.searchParams.get('user_id') ?? undefined;
43
+ const statusesParam = url.searchParams.getAll('statuses[]');
44
+ const result = ws.organizationMemberships.list({
45
+ ...params,
46
+ filter: (m) => {
47
+ if (orgFilter && m.organization_id !== orgFilter)
48
+ return false;
49
+ if (userFilter && m.user_id !== userFilter)
50
+ return false;
51
+ if (statusesParam.length > 0 && !statusesParam.includes(m.status))
52
+ return false;
53
+ return true;
54
+ },
55
+ });
56
+ return c.json(formatListResponse(result, formatMembership));
57
+ });
58
+ app.get('/user_management/organization_memberships/:id', (c) => {
59
+ const m = ws.organizationMemberships.get(c.req.param('id'));
60
+ if (!m)
61
+ throw notFound('Organization Membership');
62
+ return c.json(formatMembership(m));
63
+ });
64
+ app.put('/user_management/organization_memberships/:id', async (c) => {
65
+ const m = ws.organizationMemberships.get(c.req.param('id'));
66
+ if (!m)
67
+ throw notFound('Organization Membership');
68
+ const body = await parseJsonBody(c);
69
+ const updates = {};
70
+ if ('role_slug' in body) {
71
+ updates.role = { slug: body.role_slug };
72
+ }
73
+ if ('external_id' in body) {
74
+ updates.external_id = body.external_id ?? null;
75
+ }
76
+ if ('metadata' in body) {
77
+ updates.metadata = body.metadata ?? {};
78
+ }
79
+ const updated = ws.organizationMemberships.update(m.id, updates);
80
+ return c.json(formatMembership(updated));
81
+ });
82
+ app.delete('/user_management/organization_memberships/:id', (c) => {
83
+ const m = ws.organizationMemberships.get(c.req.param('id'));
84
+ if (!m)
85
+ throw notFound('Organization Membership');
86
+ ws.organizationMemberships.delete(m.id);
87
+ return c.body(null, 204);
88
+ });
89
+ app.put('/user_management/organization_memberships/:id/deactivate', (c) => {
90
+ const m = ws.organizationMemberships.get(c.req.param('id'));
91
+ if (!m)
92
+ throw notFound('Organization Membership');
93
+ if (m.status === 'inactive') {
94
+ throw validationError('Membership is already inactive');
95
+ }
96
+ const updated = ws.organizationMemberships.update(m.id, {
97
+ status: 'inactive',
98
+ });
99
+ return c.json(formatMembership(updated));
100
+ });
101
+ app.put('/user_management/organization_memberships/:id/reactivate', (c) => {
102
+ const m = ws.organizationMemberships.get(c.req.param('id'));
103
+ if (!m)
104
+ throw notFound('Organization Membership');
105
+ if (m.status === 'active') {
106
+ throw validationError('Membership is already active');
107
+ }
108
+ const updated = ws.organizationMemberships.update(m.id, {
109
+ status: 'active',
110
+ });
111
+ return c.json(formatMembership(updated));
112
+ });
113
+ }
114
+ //# sourceMappingURL=memberships.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memberships.js","sourceRoot":"","sources":["../../../../src/emulate/workos/routes/memberships.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EACR,eAAe,EACf,aAAa,EACb,cAAc,EACd,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAErE,MAAM,UAAU,gBAAgB,CAAC,GAAiB;IAChD,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC;IAC3B,MAAM,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IAEjC,GAAG,CAAC,IAAI,CAAC,2CAA2C,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;QAChE,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,CAAC,CAAC,CAAC;QACpC,MAAM,cAAc,GAAG,IAAI,CAAC,eAAqC,CAAC;QAClE,MAAM,MAAM,GAAG,IAAI,CAAC,OAA6B,CAAC;QAElD,IAAI,CAAC,cAAc,EAAE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CAAC,CAAC;QAClD,IAAI,CAAC,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC1B,MAAM,eAAe,CAAC,8BAA8B,CAAC,CAAC;QACxD,CAAC;QACD,MAAM,OAAO,GAAG,EAAE,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;YACtD,MAAM,EAAE,QAAQ;SACjB,CAAC,CAAC;QACH,OAAO,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAQ,CAAC,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type RouteContext,\n notFound,\n validationError,\n parseJsonBody,\n WorkOSApiError,\n parseListParams,\n} from '../../core/index.js';\nimport { getWorkOSStore } from '../store.js';\nimport { formatMembership, formatListResponse } from '../helpers.js';\n\nexport function membershipRoutes(ctx: RouteContext): void {\n const { app, store } = ctx;\n const ws = getWorkOSStore(store);\n\n app.post('/user_management/organization_memberships', async (c) => {\n const body = await parseJsonBody(c);\n const organizationId = body.organization_id as string | undefined;\n const userId = body.user_id as string | undefined;\n\n if (!organizationId) {\n throw validationError('organization_id is required', [{ field: 'organization_id', code: 'required' }]);\n }\n if (!userId) {\n throw validationError('user_id is required', [{ field: 'user_id', code: 'required' }]);\n }\n\n const org = ws.organizations.get(organizationId);\n if (!org) throw notFound('Organization');\n\n const existing = ws.organizationMemberships\n .findBy('organization_id', organizationId)\n .find((m) => m.user_id === userId && m.status !== 'inactive');\n if (existing) {\n throw new WorkOSApiError(409, 'Membership already exists', 'conflict');\n }\n\n const roleSlug = (body.role_slug as string) ?? 'member';\n\n const membership = ws.organizationMemberships.insert({\n object: 'organization_membership',\n organization_id: organizationId,\n user_id: userId,\n role: { slug: roleSlug },\n status: 'active',\n external_id: (body.external_id as string) ?? null,\n metadata: (body.metadata as Record<string, string>) ?? {},\n });\n\n return c.json(formatMembership(membership), 201);\n });\n\n app.get('/user_management/organization_memberships', (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 userFilter = url.searchParams.get('user_id') ?? undefined;\n const statusesParam = url.searchParams.getAll('statuses[]');\n\n const result = ws.organizationMemberships.list({\n ...params,\n filter: (m) => {\n if (orgFilter && m.organization_id !== orgFilter) return false;\n if (userFilter && m.user_id !== userFilter) return false;\n if (statusesParam.length > 0 && !statusesParam.includes(m.status)) return false;\n return true;\n },\n });\n\n return c.json(formatListResponse(result, formatMembership));\n });\n\n app.get('/user_management/organization_memberships/:id', (c) => {\n const m = ws.organizationMemberships.get(c.req.param('id'));\n if (!m) throw notFound('Organization Membership');\n return c.json(formatMembership(m));\n });\n\n app.put('/user_management/organization_memberships/:id', async (c) => {\n const m = ws.organizationMemberships.get(c.req.param('id'));\n if (!m) throw notFound('Organization Membership');\n\n const body = await parseJsonBody(c);\n const updates: Record<string, unknown> = {};\n\n if ('role_slug' in body) {\n updates.role = { slug: body.role_slug as string };\n }\n if ('external_id' in body) {\n updates.external_id = body.external_id ?? null;\n }\n if ('metadata' in body) {\n updates.metadata = body.metadata ?? {};\n }\n\n const updated = ws.organizationMemberships.update(m.id, updates);\n return c.json(formatMembership(updated!));\n });\n\n app.delete('/user_management/organization_memberships/:id', (c) => {\n const m = ws.organizationMemberships.get(c.req.param('id'));\n if (!m) throw notFound('Organization Membership');\n ws.organizationMemberships.delete(m.id);\n return c.body(null, 204);\n });\n\n app.put('/user_management/organization_memberships/:id/deactivate', (c) => {\n const m = ws.organizationMemberships.get(c.req.param('id'));\n if (!m) throw notFound('Organization Membership');\n if (m.status === 'inactive') {\n throw validationError('Membership is already inactive');\n }\n const updated = ws.organizationMemberships.update(m.id, {\n status: 'inactive',\n });\n return c.json(formatMembership(updated!));\n });\n\n app.put('/user_management/organization_memberships/:id/reactivate', (c) => {\n const m = ws.organizationMemberships.get(c.req.param('id'));\n if (!m) throw notFound('Organization Membership');\n if (m.status === 'active') {\n throw validationError('Membership is already active');\n }\n const updated = ws.organizationMemberships.update(m.id, {\n status: 'active',\n });\n return c.json(formatMembership(updated!));\n });\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { type RouteContext } from '../../core/index.js';
2
+ export declare function organizationDomainRoutes(ctx: RouteContext): void;
@@ -0,0 +1,58 @@
1
+ import { notFound, validationError, parseJsonBody, WorkOSApiError } from '../../core/index.js';
2
+ import { getWorkOSStore } from '../store.js';
3
+ import { formatDomain, generateVerificationToken } from '../helpers.js';
4
+ export function organizationDomainRoutes(ctx) {
5
+ const { app, store } = ctx;
6
+ const ws = getWorkOSStore(store);
7
+ app.post('/organization_domains', async (c) => {
8
+ const body = await parseJsonBody(c);
9
+ const organizationId = body.organization_id;
10
+ const domain = body.domain;
11
+ if (!organizationId) {
12
+ throw validationError('organization_id is required', [{ field: 'organization_id', code: 'required' }]);
13
+ }
14
+ if (!domain) {
15
+ throw validationError('domain is required', [{ field: 'domain', code: 'required' }]);
16
+ }
17
+ const org = ws.organizations.get(organizationId);
18
+ if (!org)
19
+ throw notFound('Organization');
20
+ const existing = ws.organizationDomains.findBy('organization_id', organizationId).find((d) => d.domain === domain);
21
+ if (existing) {
22
+ throw new WorkOSApiError(409, 'Domain already exists for this organization', 'conflict');
23
+ }
24
+ const domainEntity = ws.organizationDomains.insert({
25
+ object: 'organization_domain',
26
+ organization_id: organizationId,
27
+ domain,
28
+ state: 'pending',
29
+ verification_strategy: body.verification_strategy ?? 'manual',
30
+ verification_token: generateVerificationToken(),
31
+ verification_prefix: 'workos-verify',
32
+ });
33
+ return c.json(formatDomain(domainEntity), 201);
34
+ });
35
+ app.get('/organization_domains/:id', (c) => {
36
+ const domain = ws.organizationDomains.get(c.req.param('id'));
37
+ if (!domain)
38
+ throw notFound('Organization Domain');
39
+ return c.json(formatDomain(domain));
40
+ });
41
+ app.delete('/organization_domains/:id', (c) => {
42
+ const domain = ws.organizationDomains.get(c.req.param('id'));
43
+ if (!domain)
44
+ throw notFound('Organization Domain');
45
+ ws.organizationDomains.delete(domain.id);
46
+ return c.body(null, 204);
47
+ });
48
+ app.post('/organization_domains/:id/verify', (c) => {
49
+ const domain = ws.organizationDomains.get(c.req.param('id'));
50
+ if (!domain)
51
+ throw notFound('Organization Domain');
52
+ const updated = ws.organizationDomains.update(domain.id, {
53
+ state: 'verified',
54
+ });
55
+ return c.json(formatDomain(updated));
56
+ });
57
+ }
58
+ //# sourceMappingURL=organization-domains.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"organization-domains.js","sourceRoot":"","sources":["../../../../src/emulate/workos/routes/organization-domains.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAClH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAExE,MAAM,UAAU,wBAAwB,CAAC,GAAiB;IACxD,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC;IAC3B,MAAM,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IAEjC,GAAG,CAAC,IAAI,CAAC,uBAAuB,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;QAC5C,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,CAAC,CAAC,CAAC;QACpC,MAAM,cAAc,GAAG,IAAI,CAAC,eAAqC,CAAC;QAClE,MAAM,MAAM,GAAG,IAAI,CAAC,MAA4B,CAAC;QAEjD,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,MAAM,eAAe,CAAC,6BAA6B,EAAE,CAAC,EAAE,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;QACzG,CAAC;QACD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,eAAe,CAAC,oBAAoB,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,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AAC;IAEH,GAAG,CAAC,MAAM,CAAC,2BAA2B,EAAE,CAAC,CAAC,EAAE,EAAE;QAC5C,MAAM,MAAM,GAAG,EAAE,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7D,IAAI,CAAC,MAAM;YAAE,MAAM,QAAQ,CAAC,qBAAqB,CAAC,CAAC;QACnD,EAAE,CAAC,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACzC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,GAAG,CAAC,IAAI,CAAC,kCAAkC,EAAE,CAAC,CAAC,EAAE,EAAE;QACjD,MAAM,MAAM,GAAG,EAAE,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7D,IAAI,CAAC,MAAM;YAAE,MAAM,QAAQ,CAAC,qBAAqB,CAAC,CAAC;QAEnD,MAAM,OAAO,GAAG,EAAE,CAAC,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE;YACvD,KAAK,EAAE,UAAU;SAClB,CAAC,CAAC;QACH,OAAO,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,OAAQ,CAAC,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { type RouteContext, notFound, validationError, parseJsonBody, WorkOSApiError } from '../../core/index.js';\nimport { getWorkOSStore } from '../store.js';\nimport { formatDomain, generateVerificationToken } from '../helpers.js';\n\nexport function organizationDomainRoutes(ctx: RouteContext): void {\n const { app, store } = ctx;\n const ws = getWorkOSStore(store);\n\n app.post('/organization_domains', async (c) => {\n const body = await parseJsonBody(c);\n const organizationId = body.organization_id as string | undefined;\n const domain = body.domain as string | undefined;\n\n if (!organizationId) {\n throw validationError('organization_id is required', [{ field: 'organization_id', code: 'required' }]);\n }\n if (!domain) {\n throw validationError('domain is required', [{ field: 'domain', code: 'required' }]);\n }\n\n const org = ws.organizations.get(organizationId);\n if (!org) throw notFound('Organization');\n\n const existing = ws.organizationDomains.findBy('organization_id', organizationId).find((d) => d.domain === domain);\n if (existing) {\n throw new WorkOSApiError(409, 'Domain already exists for this organization', 'conflict');\n }\n\n const domainEntity = ws.organizationDomains.insert({\n object: 'organization_domain',\n organization_id: organizationId,\n domain,\n state: 'pending',\n verification_strategy: (body.verification_strategy as 'manual' | 'dns') ?? 'manual',\n verification_token: generateVerificationToken(),\n verification_prefix: 'workos-verify',\n });\n\n return c.json(formatDomain(domainEntity), 201);\n });\n\n app.get('/organization_domains/:id', (c) => {\n const domain = ws.organizationDomains.get(c.req.param('id'));\n if (!domain) throw notFound('Organization Domain');\n return c.json(formatDomain(domain));\n });\n\n app.delete('/organization_domains/:id', (c) => {\n const domain = ws.organizationDomains.get(c.req.param('id'));\n if (!domain) throw notFound('Organization Domain');\n ws.organizationDomains.delete(domain.id);\n return c.body(null, 204);\n });\n\n app.post('/organization_domains/:id/verify', (c) => {\n const domain = ws.organizationDomains.get(c.req.param('id'));\n if (!domain) throw notFound('Organization Domain');\n\n const updated = ws.organizationDomains.update(domain.id, {\n state: 'verified',\n });\n return c.json(formatDomain(updated!));\n });\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { type RouteContext } from '../../core/index.js';
2
+ export declare function organizationRoutes(ctx: RouteContext): void;
@@ -0,0 +1,131 @@
1
+ import { notFound, validationError, parseJsonBody, parseListParams } from '../../core/index.js';
2
+ import { getWorkOSStore } from '../store.js';
3
+ import { formatOrganization, generateVerificationToken, formatListResponse } from '../helpers.js';
4
+ export function organizationRoutes(ctx) {
5
+ const { app, store } = ctx;
6
+ const ws = getWorkOSStore(store);
7
+ app.post('/organizations', async (c) => {
8
+ const body = await parseJsonBody(c);
9
+ const name = body.name;
10
+ if (!name || typeof name !== 'string' || name.trim().length === 0) {
11
+ throw validationError('Name is required', [{ field: 'name', code: 'required' }]);
12
+ }
13
+ const org = ws.organizations.insert({
14
+ object: 'organization',
15
+ name: name.trim(),
16
+ external_id: body.external_id ?? null,
17
+ metadata: body.metadata ?? {},
18
+ stripe_customer_id: null,
19
+ });
20
+ const domainData = body.domain_data;
21
+ if (domainData && Array.isArray(domainData)) {
22
+ for (const dd of domainData) {
23
+ ws.organizationDomains.insert({
24
+ object: 'organization_domain',
25
+ organization_id: org.id,
26
+ domain: dd.domain,
27
+ state: dd.state === 'verified' ? 'verified' : 'pending',
28
+ verification_strategy: 'manual',
29
+ verification_token: generateVerificationToken(),
30
+ verification_prefix: 'workos-verify',
31
+ });
32
+ }
33
+ }
34
+ return c.json(formatOrganization(org, ws), 201);
35
+ });
36
+ app.get('/organizations', (c) => {
37
+ const url = new URL(c.req.url);
38
+ const params = parseListParams(url);
39
+ const nameFilter = url.searchParams.get('name') ?? undefined;
40
+ const domainsFilter = url.searchParams.get('domains') ?? undefined;
41
+ const result = ws.organizations.list({
42
+ ...params,
43
+ filter: (org) => {
44
+ if (nameFilter && !org.name.toLowerCase().includes(nameFilter.toLowerCase())) {
45
+ return false;
46
+ }
47
+ if (domainsFilter) {
48
+ const orgDomains = ws.organizationDomains.findBy('organization_id', org.id);
49
+ if (!orgDomains.some((d) => d.domain === domainsFilter)) {
50
+ return false;
51
+ }
52
+ }
53
+ return true;
54
+ },
55
+ });
56
+ // Pre-fetch all domains once to avoid N+1 lookups per org
57
+ const allDomains = ws.organizationDomains.all();
58
+ const domainsByOrg = new Map();
59
+ for (const d of allDomains) {
60
+ const list = domainsByOrg.get(d.organization_id) ?? [];
61
+ list.push(d);
62
+ domainsByOrg.set(d.organization_id, list);
63
+ }
64
+ return c.json(formatListResponse(result, (org) => formatOrganization(org, ws, { domains: domainsByOrg.get(org.id) ?? [] })));
65
+ });
66
+ app.get('/organizations/:id', (c) => {
67
+ const org = ws.organizations.get(c.req.param('id'));
68
+ if (!org)
69
+ throw notFound('Organization');
70
+ return c.json(formatOrganization(org, ws));
71
+ });
72
+ app.get('/organizations/external_id/:external_id', (c) => {
73
+ const org = ws.organizations.findOneBy('external_id', c.req.param('external_id'));
74
+ if (!org)
75
+ throw notFound('Organization');
76
+ return c.json(formatOrganization(org, ws));
77
+ });
78
+ app.put('/organizations/:id', async (c) => {
79
+ const org = ws.organizations.get(c.req.param('id'));
80
+ if (!org)
81
+ throw notFound('Organization');
82
+ const body = await parseJsonBody(c);
83
+ const updates = {};
84
+ if ('name' in body) {
85
+ if (!body.name || typeof body.name !== 'string' || body.name.trim().length === 0) {
86
+ throw validationError('Name is required', [{ field: 'name', code: 'required' }]);
87
+ }
88
+ updates.name = body.name.trim();
89
+ }
90
+ if ('external_id' in body)
91
+ updates.external_id = body.external_id ?? null;
92
+ if ('metadata' in body)
93
+ updates.metadata = body.metadata ?? {};
94
+ if ('domain_data' in body && Array.isArray(body.domain_data)) {
95
+ const existing = ws.organizationDomains.findBy('organization_id', org.id);
96
+ const incoming = body.domain_data;
97
+ const incomingDomains = new Set(incoming.map((d) => d.domain));
98
+ for (const d of existing) {
99
+ if (!incomingDomains.has(d.domain)) {
100
+ ws.organizationDomains.delete(d.id);
101
+ }
102
+ }
103
+ const existingDomains = new Set(existing.map((d) => d.domain));
104
+ for (const dd of incoming) {
105
+ if (!existingDomains.has(dd.domain)) {
106
+ ws.organizationDomains.insert({
107
+ object: 'organization_domain',
108
+ organization_id: org.id,
109
+ domain: dd.domain,
110
+ state: dd.state === 'verified' ? 'verified' : 'pending',
111
+ verification_strategy: 'manual',
112
+ verification_token: generateVerificationToken(),
113
+ verification_prefix: 'workos-verify',
114
+ });
115
+ }
116
+ }
117
+ }
118
+ const updated = ws.organizations.update(org.id, updates);
119
+ return c.json(formatOrganization(updated, ws));
120
+ });
121
+ app.delete('/organizations/:id', (c) => {
122
+ const org = ws.organizations.get(c.req.param('id'));
123
+ if (!org)
124
+ throw notFound('Organization');
125
+ ws.organizationDomains.deleteBy('organization_id', org.id);
126
+ ws.organizationMemberships.deleteBy('organization_id', org.id);
127
+ ws.organizations.delete(org.id);
128
+ return c.body(null, 204);
129
+ });
130
+ }
131
+ //# sourceMappingURL=organizations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"organizations.js","sourceRoot":"","sources":["../../../../src/emulate/workos/routes/organizations.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,kBAAkB,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGlG,MAAM,UAAU,kBAAkB,CAAC,GAAiB;IAClD,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC;IAC3B,MAAM,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IAEjC,GAAG,CAAC,IAAI,CAAC,gBAAgB,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;QACrC,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,CAAC,CAAC,CAAC;QACpC,MAAM,IAAI,GAAG,IAAI,CAAC,IAA0B,CAAC;QAC7C,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClE,MAAM,eAAe,CAAC,kBAAkB,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;QACnF,CAAC;QAED,MAAM,GAAG,GAAG,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC;YAClC,MAAM,EAAE,cAAc;YACtB,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE;YACjB,WAAW,EAAG,IAAI,CAAC,WAAsB,IAAI,IAAI;YACjD,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,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChC,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 { formatOrganization, generateVerificationToken, formatListResponse } from '../helpers.js';\nimport type { WorkOSOrganizationDomain } from '../entities.js';\n\nexport function organizationRoutes(ctx: RouteContext): void {\n const { app, store } = ctx;\n const ws = getWorkOSStore(store);\n\n app.post('/organizations', 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 org = ws.organizations.insert({\n object: 'organization',\n name: name.trim(),\n external_id: (body.external_id as string) ?? null,\n metadata: (body.metadata as Record<string, string>) ?? {},\n stripe_customer_id: null,\n });\n\n const domainData = body.domain_data as Array<{ domain: string; state?: string }> | undefined;\n if (domainData && Array.isArray(domainData)) {\n for (const dd of domainData) {\n ws.organizationDomains.insert({\n object: 'organization_domain',\n organization_id: org.id,\n domain: dd.domain,\n state: dd.state === 'verified' ? 'verified' : 'pending',\n verification_strategy: 'manual',\n verification_token: generateVerificationToken(),\n verification_prefix: 'workos-verify',\n });\n }\n }\n\n return c.json(formatOrganization(org, ws), 201);\n });\n\n app.get('/organizations', (c) => {\n const url = new URL(c.req.url);\n const params = parseListParams(url);\n const nameFilter = url.searchParams.get('name') ?? undefined;\n const domainsFilter = url.searchParams.get('domains') ?? undefined;\n\n const result = ws.organizations.list({\n ...params,\n filter: (org) => {\n if (nameFilter && !org.name.toLowerCase().includes(nameFilter.toLowerCase())) {\n return false;\n }\n if (domainsFilter) {\n const orgDomains = ws.organizationDomains.findBy('organization_id', org.id);\n if (!orgDomains.some((d) => d.domain === domainsFilter)) {\n return false;\n }\n }\n return true;\n },\n });\n\n // Pre-fetch all domains once to avoid N+1 lookups per org\n const allDomains = ws.organizationDomains.all();\n const domainsByOrg = new Map<string, WorkOSOrganizationDomain[]>();\n for (const d of allDomains) {\n const list = domainsByOrg.get(d.organization_id) ?? [];\n list.push(d);\n domainsByOrg.set(d.organization_id, list);\n }\n\n return c.json(\n formatListResponse(result, (org) => formatOrganization(org, ws, { domains: domainsByOrg.get(org.id) ?? [] })),\n );\n });\n\n app.get('/organizations/:id', (c) => {\n const org = ws.organizations.get(c.req.param('id'));\n if (!org) throw notFound('Organization');\n return c.json(formatOrganization(org, ws));\n });\n\n app.get('/organizations/external_id/:external_id', (c) => {\n const org = ws.organizations.findOneBy('external_id', c.req.param('external_id'));\n if (!org) throw notFound('Organization');\n return c.json(formatOrganization(org, ws));\n });\n\n app.put('/organizations/:id', async (c) => {\n const org = ws.organizations.get(c.req.param('id'));\n if (!org) throw notFound('Organization');\n\n const body = await parseJsonBody(c);\n const updates: Record<string, unknown> = {};\n\n if ('name' in body) {\n if (!body.name || typeof body.name !== 'string' || (body.name as string).trim().length === 0) {\n throw validationError('Name is required', [{ field: 'name', code: 'required' }]);\n }\n updates.name = (body.name as string).trim();\n }\n if ('external_id' in body) updates.external_id = body.external_id ?? null;\n if ('metadata' in body) updates.metadata = body.metadata ?? {};\n\n if ('domain_data' in body && Array.isArray(body.domain_data)) {\n const existing = ws.organizationDomains.findBy('organization_id', org.id);\n const incoming = body.domain_data as Array<{ domain: string; state?: string }>;\n const incomingDomains = new Set(incoming.map((d) => d.domain));\n\n for (const d of existing) {\n if (!incomingDomains.has(d.domain)) {\n ws.organizationDomains.delete(d.id);\n }\n }\n\n const existingDomains = new Set(existing.map((d) => d.domain));\n for (const dd of incoming) {\n if (!existingDomains.has(dd.domain)) {\n ws.organizationDomains.insert({\n object: 'organization_domain',\n organization_id: org.id,\n domain: dd.domain,\n state: dd.state === 'verified' ? 'verified' : 'pending',\n verification_strategy: 'manual',\n verification_token: generateVerificationToken(),\n verification_prefix: 'workos-verify',\n });\n }\n }\n }\n\n const updated = ws.organizations.update(org.id, updates);\n return c.json(formatOrganization(updated!, ws));\n });\n\n app.delete('/organizations/:id', (c) => {\n const org = ws.organizations.get(c.req.param('id'));\n if (!org) throw notFound('Organization');\n\n ws.organizationDomains.deleteBy('organization_id', org.id);\n ws.organizationMemberships.deleteBy('organization_id', org.id);\n\n ws.organizations.delete(org.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 passwordResetRoutes(ctx: RouteContext): void;
@@ -0,0 +1,61 @@
1
+ import { notFound, parseJsonBody, WorkOSApiError } from '../../core/index.js';
2
+ import { getWorkOSStore } from '../store.js';
3
+ import { formatPasswordReset, generateVerificationToken, hashPassword, expiresIn, isExpired } from '../helpers.js';
4
+ export function passwordResetRoutes(ctx) {
5
+ const { app, store } = ctx;
6
+ const ws = getWorkOSStore(store);
7
+ app.get('/user_management/password_reset/:id', (c) => {
8
+ const pr = ws.passwordResets.get(c.req.param('id'));
9
+ if (!pr)
10
+ throw notFound('Password Reset');
11
+ return c.json(formatPasswordReset(pr));
12
+ });
13
+ app.post('/user_management/password_reset', async (c) => {
14
+ const body = await parseJsonBody(c);
15
+ const email = body.email;
16
+ if (!email) {
17
+ throw new WorkOSApiError(400, 'email is required', 'invalid_request');
18
+ }
19
+ const user = ws.users.findOneBy('email', email);
20
+ if (!user)
21
+ throw notFound('User');
22
+ const pr = ws.passwordResets.insert({
23
+ object: 'password_reset',
24
+ user_id: user.id,
25
+ email: user.email,
26
+ token: generateVerificationToken(),
27
+ expires_at: expiresIn(60),
28
+ });
29
+ return c.json(formatPasswordReset(pr), 201);
30
+ });
31
+ app.post('/user_management/password_reset/confirm', async (c) => {
32
+ const body = await parseJsonBody(c);
33
+ const token = body.token;
34
+ const newPassword = body.new_password;
35
+ if (!token) {
36
+ throw new WorkOSApiError(400, 'token is required', 'invalid_request');
37
+ }
38
+ if (!newPassword) {
39
+ throw new WorkOSApiError(400, 'new_password is required', 'invalid_request');
40
+ }
41
+ const resets = ws.passwordResets.all();
42
+ const pr = resets.find((r) => r.token === token);
43
+ if (!pr) {
44
+ throw new WorkOSApiError(400, 'Invalid token', 'invalid_token');
45
+ }
46
+ if (isExpired(pr.expires_at)) {
47
+ throw new WorkOSApiError(400, 'Token has expired', 'expired_token');
48
+ }
49
+ const user = ws.users.get(pr.user_id);
50
+ if (!user) {
51
+ ws.passwordResets.delete(pr.id);
52
+ throw notFound('User');
53
+ }
54
+ ws.users.update(pr.user_id, {
55
+ password_hash: hashPassword(newPassword),
56
+ });
57
+ ws.passwordResets.delete(pr.id);
58
+ return c.json({ user: { object: 'user', id: user.id, email: user.email } });
59
+ });
60
+ }
61
+ //# sourceMappingURL=password-reset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-reset.js","sourceRoot":"","sources":["../../../../src/emulate/workos/routes/password-reset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACjG,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEnH,MAAM,UAAU,mBAAmB,CAAC,GAAiB;IACnD,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC;IAC3B,MAAM,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IAEjC,GAAG,CAAC,GAAG,CAAC,qCAAqC,EAAE,CAAC,CAAC,EAAE,EAAE;QACnD,MAAM,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QACpD,IAAI,CAAC,EAAE;YAAE,MAAM,QAAQ,CAAC,gBAAgB,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AI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { type RouteContext, notFound, parseJsonBody, WorkOSApiError } from '../../core/index.js';\nimport { getWorkOSStore } from '../store.js';\nimport { formatPasswordReset, generateVerificationToken, hashPassword, expiresIn, isExpired } from '../helpers.js';\n\nexport function passwordResetRoutes(ctx: RouteContext): void {\n const { app, store } = ctx;\n const ws = getWorkOSStore(store);\n\n app.get('/user_management/password_reset/:id', (c) => {\n const pr = ws.passwordResets.get(c.req.param('id'));\n if (!pr) throw notFound('Password Reset');\n return c.json(formatPasswordReset(pr));\n });\n\n app.post('/user_management/password_reset', async (c) => {\n const body = await parseJsonBody(c);\n const email = body.email as string | undefined;\n if (!email) {\n throw new WorkOSApiError(400, 'email is required', 'invalid_request');\n }\n\n const user = ws.users.findOneBy('email', email);\n if (!user) throw notFound('User');\n\n const pr = ws.passwordResets.insert({\n object: 'password_reset',\n user_id: user.id,\n email: user.email,\n token: generateVerificationToken(),\n expires_at: expiresIn(60),\n });\n\n return c.json(formatPasswordReset(pr), 201);\n });\n\n app.post('/user_management/password_reset/confirm', async (c) => {\n const body = await parseJsonBody(c);\n const token = body.token as string | undefined;\n const newPassword = body.new_password as string | undefined;\n\n if (!token) {\n throw new WorkOSApiError(400, 'token is required', 'invalid_request');\n }\n if (!newPassword) {\n throw new WorkOSApiError(400, 'new_password is required', 'invalid_request');\n }\n\n const resets = ws.passwordResets.all();\n const pr = resets.find((r) => r.token === token);\n if (!pr) {\n throw new WorkOSApiError(400, 'Invalid token', 'invalid_token');\n }\n if (isExpired(pr.expires_at)) {\n throw new WorkOSApiError(400, 'Token has expired', 'expired_token');\n }\n\n const user = ws.users.get(pr.user_id);\n if (!user) {\n ws.passwordResets.delete(pr.id);\n throw notFound('User');\n }\n\n ws.users.update(pr.user_id, {\n password_hash: hashPassword(newPassword),\n });\n ws.passwordResets.delete(pr.id);\n\n return c.json({ user: { object: 'user', id: user.id, email: user.email } });\n });\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { type RouteContext } from '../../core/index.js';
2
+ export declare function pipeRoutes(ctx: RouteContext): void;
@@ -0,0 +1,82 @@
1
+ import { notFound, validationError, parseJsonBody, parseListParams } from '../../core/index.js';
2
+ import { getWorkOSStore } from '../store.js';
3
+ import { formatPipeConnection, formatListResponse } from '../helpers.js';
4
+ const VALID_PROVIDERS = ['github', 'slack', 'google', 'salesforce'];
5
+ export function pipeRoutes(ctx) {
6
+ const { app, store } = ctx;
7
+ const ws = getWorkOSStore(store);
8
+ app.post('/pipes/connections', async (c) => {
9
+ const body = await parseJsonBody(c);
10
+ const userId = body.user_id;
11
+ const provider = body.provider;
12
+ const scopes = body.scopes ?? [];
13
+ if (!userId) {
14
+ throw validationError('user_id is required', [{ field: 'user_id', code: 'required' }]);
15
+ }
16
+ if (!provider) {
17
+ throw validationError('provider is required', [{ field: 'provider', code: 'required' }]);
18
+ }
19
+ if (!VALID_PROVIDERS.includes(provider)) {
20
+ throw validationError(`provider must be one of: ${VALID_PROVIDERS.join(', ')}`, [
21
+ { field: 'provider', code: 'invalid' },
22
+ ]);
23
+ }
24
+ const conn = ws.pipeConnections.insert({
25
+ object: 'pipe_connection',
26
+ user_id: userId,
27
+ provider,
28
+ scopes,
29
+ status: 'connected',
30
+ external_account_id: body.external_account_id ?? null,
31
+ });
32
+ return c.json(formatPipeConnection(conn), 201);
33
+ });
34
+ app.get('/pipes/connections', (c) => {
35
+ const url = new URL(c.req.url);
36
+ const params = parseListParams(url);
37
+ const userIdFilter = url.searchParams.get('user_id') ?? undefined;
38
+ const providerFilter = url.searchParams.get('provider') ?? undefined;
39
+ const result = ws.pipeConnections.list({
40
+ ...params,
41
+ filter: (pc) => {
42
+ if (userIdFilter && pc.user_id !== userIdFilter)
43
+ return false;
44
+ if (providerFilter && pc.provider !== providerFilter)
45
+ return false;
46
+ return true;
47
+ },
48
+ });
49
+ return c.json(formatListResponse(result, formatPipeConnection));
50
+ });
51
+ app.get('/pipes/connections/:id', (c) => {
52
+ const conn = ws.pipeConnections.get(c.req.param('id'));
53
+ if (!conn)
54
+ throw notFound('Pipe connection');
55
+ return c.json(formatPipeConnection(conn));
56
+ });
57
+ app.delete('/pipes/connections/:id', (c) => {
58
+ const conn = ws.pipeConnections.get(c.req.param('id'));
59
+ if (!conn)
60
+ throw notFound('Pipe connection');
61
+ ws.pipeConnections.delete(conn.id);
62
+ return c.body(null, 204);
63
+ });
64
+ app.post('/pipes/connections/:id/access_token', (c) => {
65
+ const conn = ws.pipeConnections.get(c.req.param('id'));
66
+ if (!conn)
67
+ throw notFound('Pipe connection');
68
+ if (conn.status !== 'connected') {
69
+ return c.json({
70
+ error: 'connection_inactive',
71
+ message: `Connection is ${conn.status}`,
72
+ }, 400);
73
+ }
74
+ return c.json({
75
+ access_token: `pipes_mock_${conn.provider}_${conn.user_id}`,
76
+ token_type: 'bearer',
77
+ scopes: conn.scopes,
78
+ expires_in: 3600,
79
+ });
80
+ });
81
+ }
82
+ //# sourceMappingURL=pipes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipes.js","sourceRoot":"","sources":["../../../../src/emulate/workos/routes/pipes.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,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGzE,MAAM,eAAe,GAAmB,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;AAEpF,MAAM,UAAU,UAAU,CAAC,GAAiB;IAC1C,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC;IAC3B,MAAM,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IAEjC,GAAG,CAAC,IAAI,CAAC,o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AE,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QACvD,IAAI,CAAC,IAAI;YAAE,MAAM,QAAQ,CAAC,iBAAiB,CAAC,CAAC;QAC7C,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACnC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,GAAG,CAAC,IAAI,CAAC,qCAAqC,EAAE,CAAC,CAAC,EAAE,EAAE;QACpD,MAAM,IAAI,GAAG,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QACvD,IAAI,CAAC,IAAI;YAAE,MAAM,QAAQ,CAAC,iBAAiB,CAAC,CAAC;QAC7C,IAAI,IAAI,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;YAChC,OAAO,CAAC,CAAC,IAAI,CACX;gBACE,KAAK,EAAE,qBAAqB;gBAC5B,OAAO,EAAE,iBAAiB,IAAI,CAAC,MAAM,EAAE;aACxC,EACD,GAAG,CACJ,CAAC;QACJ,CAAC;QAED,OAAO,CAAC,CAAC,IAAI,CAAC;YACZ,YAAY,EAAE,cAAc,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,OAAO,EAAE;YAC3D,UAAU,EAAE,QAAQ;YACpB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { type RouteContext, notFound, validationError, parseJsonBody, parseListParams } from '../../core/index.js';\nimport { getWorkOSStore } from '../store.js';\nimport { formatPipeConnection, formatListResponse } from '../helpers.js';\nimport type { PipeProvider } from '../entities.js';\n\nconst VALID_PROVIDERS: PipeProvider[] = ['github', 'slack', 'google', 'salesforce'];\n\nexport function pipeRoutes(ctx: RouteContext): void {\n const { app, store } = ctx;\n const ws = getWorkOSStore(store);\n\n app.post('/pipes/connections', async (c) => {\n const body = await parseJsonBody(c);\n const userId = body.user_id as string | undefined;\n const provider = body.provider as PipeProvider | undefined;\n const scopes = (body.scopes as string[]) ?? [];\n\n if (!userId) {\n throw validationError('user_id is required', [{ field: 'user_id', code: 'required' }]);\n }\n if (!provider) {\n throw validationError('provider is required', [{ field: 'provider', code: 'required' }]);\n }\n if (!VALID_PROVIDERS.includes(provider)) {\n throw validationError(`provider must be one of: ${VALID_PROVIDERS.join(', ')}`, [\n { field: 'provider', code: 'invalid' },\n ]);\n }\n\n const conn = ws.pipeConnections.insert({\n object: 'pipe_connection',\n user_id: userId,\n provider,\n scopes,\n status: 'connected',\n external_account_id: (body.external_account_id as string) ?? null,\n });\n\n return c.json(formatPipeConnection(conn), 201);\n });\n\n app.get('/pipes/connections', (c) => {\n const url = new URL(c.req.url);\n const params = parseListParams(url);\n const userIdFilter = url.searchParams.get('user_id') ?? undefined;\n const providerFilter = url.searchParams.get('provider') ?? undefined;\n\n const result = ws.pipeConnections.list({\n ...params,\n filter: (pc) => {\n if (userIdFilter && pc.user_id !== userIdFilter) return false;\n if (providerFilter && pc.provider !== providerFilter) return false;\n return true;\n },\n });\n\n return c.json(formatListResponse(result, formatPipeConnection));\n });\n\n app.get('/pipes/connections/:id', (c) => {\n const conn = ws.pipeConnections.get(c.req.param('id'));\n if (!conn) throw notFound('Pipe connection');\n return c.json(formatPipeConnection(conn));\n });\n\n app.delete('/pipes/connections/:id', (c) => {\n const conn = ws.pipeConnections.get(c.req.param('id'));\n if (!conn) throw notFound('Pipe connection');\n ws.pipeConnections.delete(conn.id);\n return c.body(null, 204);\n });\n\n app.post('/pipes/connections/:id/access_token', (c) => {\n const conn = ws.pipeConnections.get(c.req.param('id'));\n if (!conn) throw notFound('Pipe connection');\n if (conn.status !== 'connected') {\n return c.json(\n {\n error: 'connection_inactive',\n message: `Connection is ${conn.status}`,\n },\n 400,\n );\n }\n\n return c.json({\n access_token: `pipes_mock_${conn.provider}_${conn.user_id}`,\n token_type: 'bearer',\n scopes: conn.scopes,\n expires_in: 3600,\n });\n });\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { type RouteContext } from '../../core/index.js';
2
+ export declare function portalRoutes(ctx: RouteContext): void;
@@ -0,0 +1,18 @@
1
+ import { parseJsonBody, validationError } from '../../core/index.js';
2
+ export function portalRoutes(ctx) {
3
+ const { app } = ctx;
4
+ app.post('/portal/generate_link', async (c) => {
5
+ const body = await parseJsonBody(c);
6
+ const intent = body.intent;
7
+ const organization = body.organization;
8
+ if (!intent) {
9
+ throw validationError('intent is required', [{ field: 'intent', code: 'required' }]);
10
+ }
11
+ if (!organization) {
12
+ throw validationError('organization is required', [{ field: 'organization', code: 'required' }]);
13
+ }
14
+ const baseUrl = new URL(c.req.url).origin;
15
+ return c.json({ link: `${baseUrl}/portal/${intent}/${organization}` });
16
+ });
17
+ }
18
+ //# sourceMappingURL=portal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portal.js","sourceRoot":"","sources":["../../../../src/emulate/workos/routes/portal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAExF,MAAM,UAAU,YAAY,CAAC,GAAiB;IAC5C,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC;IAEpB,GAAG,CAAC,IAAI,CAAC,uBAAuB,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;QAC5C,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,CAAC,CAAC,CAAC;QACpC,MAAM,MAAM,GAAG,IAAI,CAAC,MAA4B,CAAC;QACjD,MAAM,YAAY,GAAG,IAAI,CAAC,YAAkC,CAAC;QAE7D,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,eAAe,CAAC,oBAAoB,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;QACvF,CAAC;QACD,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,MAAM,eAAe,CAAC,0BAA0B,EAAE,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;QACnG,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;QAC1C,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,OAAO,WAAW,MAAM,IAAI,YAAY,EAAE,EAAE,CAAC,CAAC;IACzE,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { type RouteContext, parseJsonBody, validationError } from '../../core/index.js';\n\nexport function portalRoutes(ctx: RouteContext): void {\n const { app } = ctx;\n\n app.post('/portal/generate_link', async (c) => {\n const body = await parseJsonBody(c);\n const intent = body.intent as string | undefined;\n const organization = body.organization as string | undefined;\n\n if (!intent) {\n throw validationError('intent is required', [{ field: 'intent', code: 'required' }]);\n }\n if (!organization) {\n throw validationError('organization is required', [{ field: 'organization', code: 'required' }]);\n }\n\n const baseUrl = new URL(c.req.url).origin;\n return c.json({ link: `${baseUrl}/portal/${intent}/${organization}` });\n });\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { type RouteContext } from '../../core/index.js';
2
+ export declare function radarRoutes(ctx: RouteContext): void;