workos 0.18.0 → 0.19.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 (333) hide show
  1. package/README.md +8 -145
  2. package/dist/bin.js +129 -50
  3. package/dist/bin.js.map +1 -1
  4. package/dist/commands/api/index.js +18 -10
  5. package/dist/commands/api/index.js.map +1 -1
  6. package/dist/commands/api/interactive.js +11 -11
  7. package/dist/commands/api/interactive.js.map +1 -1
  8. package/dist/commands/claim.js +28 -16
  9. package/dist/commands/claim.js.map +1 -1
  10. package/dist/commands/connection.js +3 -3
  11. package/dist/commands/connection.js.map +1 -1
  12. package/dist/commands/debug.js +6 -6
  13. package/dist/commands/debug.js.map +1 -1
  14. package/dist/commands/dev.d.ts +7 -8
  15. package/dist/commands/dev.js +14 -14
  16. package/dist/commands/dev.js.map +1 -1
  17. package/dist/commands/directory.js +3 -3
  18. package/dist/commands/directory.js.map +1 -1
  19. package/dist/commands/doctor.js +2 -2
  20. package/dist/commands/doctor.js.map +1 -1
  21. package/dist/commands/emulate.d.ts +1 -0
  22. package/dist/commands/emulate.js +3 -2
  23. package/dist/commands/emulate.js.map +1 -1
  24. package/dist/commands/env.d.ts +10 -0
  25. package/dist/commands/env.js +94 -18
  26. package/dist/commands/env.js.map +1 -1
  27. package/dist/commands/install.js +8 -13
  28. package/dist/commands/install.js.map +1 -1
  29. package/dist/commands/login.d.ts +25 -15
  30. package/dist/commands/login.js +126 -71
  31. package/dist/commands/login.js.map +1 -1
  32. package/dist/commands/logout.js +4 -4
  33. package/dist/commands/logout.js.map +1 -1
  34. package/dist/commands/mcp.js +7 -16
  35. package/dist/commands/mcp.js.map +1 -1
  36. package/dist/commands/migrations.js +2 -1
  37. package/dist/commands/migrations.js.map +1 -1
  38. package/dist/commands/seed.js +5 -4
  39. package/dist/commands/seed.js.map +1 -1
  40. package/dist/commands/setup.d.ts +50 -0
  41. package/dist/commands/setup.js +237 -0
  42. package/dist/commands/setup.js.map +1 -0
  43. package/dist/commands/vault-run.js +3 -2
  44. package/dist/commands/vault-run.js.map +1 -1
  45. package/dist/commands/verify-login.d.ts +25 -0
  46. package/dist/commands/verify-login.js +158 -0
  47. package/dist/commands/verify-login.js.map +1 -0
  48. package/dist/doctor/issues.js +3 -2
  49. package/dist/doctor/issues.js.map +1 -1
  50. package/dist/doctor/output.js +2 -1
  51. package/dist/doctor/output.js.map +1 -1
  52. package/dist/integrations/dotnet/index.js +1 -1
  53. package/dist/integrations/dotnet/index.js.map +1 -1
  54. package/dist/integrations/elixir/index.js +1 -1
  55. package/dist/integrations/elixir/index.js.map +1 -1
  56. package/dist/integrations/go/index.js +1 -1
  57. package/dist/integrations/go/index.js.map +1 -1
  58. package/dist/integrations/nextjs/index.js +8 -5
  59. package/dist/integrations/nextjs/index.js.map +1 -1
  60. package/dist/integrations/nextjs/utils.d.ts +1 -1
  61. package/dist/integrations/nextjs/utils.js +21 -6
  62. package/dist/integrations/nextjs/utils.js.map +1 -1
  63. package/dist/integrations/react-router/index.js +5 -5
  64. package/dist/integrations/react-router/index.js.map +1 -1
  65. package/dist/integrations/react-router/utils.js +28 -12
  66. package/dist/integrations/react-router/utils.js.map +1 -1
  67. package/dist/integrations/ruby/index.js +1 -1
  68. package/dist/integrations/ruby/index.js.map +1 -1
  69. package/dist/lib/adapters/cli-adapter.d.ts +33 -4
  70. package/dist/lib/adapters/cli-adapter.js +251 -135
  71. package/dist/lib/adapters/cli-adapter.js.map +1 -1
  72. package/dist/lib/adapters/dashboard-adapter.js +3 -3
  73. package/dist/lib/adapters/dashboard-adapter.js.map +1 -1
  74. package/dist/lib/adapters/headless-adapter.d.ts +7 -0
  75. package/dist/lib/adapters/headless-adapter.js +42 -5
  76. package/dist/lib/adapters/headless-adapter.js.map +1 -1
  77. package/dist/lib/agent-interface.js +15 -1
  78. package/dist/lib/agent-interface.js.map +1 -1
  79. package/dist/lib/agent-runner.js +1 -1
  80. package/dist/lib/agent-runner.js.map +1 -1
  81. package/dist/lib/api-key.js +2 -1
  82. package/dist/lib/api-key.js.map +1 -1
  83. package/dist/lib/completion-data.d.ts +33 -0
  84. package/dist/lib/completion-data.js +33 -0
  85. package/dist/lib/completion-data.js.map +1 -0
  86. package/dist/lib/config-store.d.ts +13 -0
  87. package/dist/lib/config-store.js +24 -0
  88. package/dist/lib/config-store.js.map +1 -1
  89. package/dist/lib/config.d.ts +1 -1
  90. package/dist/lib/config.js +1 -1
  91. package/dist/lib/config.js.map +1 -1
  92. package/dist/lib/constants.d.ts +8 -0
  93. package/dist/lib/constants.js +8 -0
  94. package/dist/lib/constants.js.map +1 -1
  95. package/dist/lib/events.d.ts +34 -1
  96. package/dist/lib/events.js.map +1 -1
  97. package/dist/lib/framework-config.d.ts +6 -0
  98. package/dist/lib/framework-config.js.map +1 -1
  99. package/dist/lib/installer-core.d.ts +14 -1
  100. package/dist/lib/installer-core.js +24 -5
  101. package/dist/lib/installer-core.js.map +1 -1
  102. package/dist/lib/installer-core.types.d.ts +3 -1
  103. package/dist/lib/installer-core.types.js.map +1 -1
  104. package/dist/lib/mcp-clients.d.ts +6 -0
  105. package/dist/lib/mcp-clients.js +13 -0
  106. package/dist/lib/mcp-clients.js.map +1 -1
  107. package/dist/lib/port-detection.js +19 -13
  108. package/dist/lib/port-detection.js.map +1 -1
  109. package/dist/lib/preferences.d.ts +30 -2
  110. package/dist/lib/preferences.js +34 -8
  111. package/dist/lib/preferences.js.map +1 -1
  112. package/dist/lib/run-with-core.js +40 -3
  113. package/dist/lib/run-with-core.js.map +1 -1
  114. package/dist/lib/telemetry-notice.d.ts +5 -5
  115. package/dist/lib/telemetry-notice.js +7 -8
  116. package/dist/lib/telemetry-notice.js.map +1 -1
  117. package/dist/lib/unclaimed-env-provision.js +15 -12
  118. package/dist/lib/unclaimed-env-provision.js.map +1 -1
  119. package/dist/lib/unclaimed-warning.js +4 -3
  120. package/dist/lib/unclaimed-warning.js.map +1 -1
  121. package/dist/lib/validation/security-checks.js +2 -1
  122. package/dist/lib/validation/security-checks.js.map +1 -1
  123. package/dist/lib/validation/validator.js +30 -3
  124. package/dist/lib/validation/validator.js.map +1 -1
  125. package/dist/lib/workos-management.js +26 -19
  126. package/dist/lib/workos-management.js.map +1 -1
  127. package/dist/run.d.ts +1 -0
  128. package/dist/run.js +5 -1
  129. package/dist/run.js.map +1 -1
  130. package/dist/steps/add-or-update-environment-variables.js +10 -10
  131. package/dist/steps/add-or-update-environment-variables.js.map +1 -1
  132. package/dist/steps/run-prettier.js +3 -3
  133. package/dist/steps/run-prettier.js.map +1 -1
  134. package/dist/steps/upload-environment-variables/index.js +15 -3
  135. package/dist/steps/upload-environment-variables/index.js.map +1 -1
  136. package/dist/steps/upload-environment-variables/providers/vercel.js +2 -2
  137. package/dist/steps/upload-environment-variables/providers/vercel.js.map +1 -1
  138. package/dist/utils/box.d.ts +6 -30
  139. package/dist/utils/box.js +8 -95
  140. package/dist/utils/box.js.map +1 -1
  141. package/dist/utils/cli-symbols.d.ts +14 -2
  142. package/dist/utils/cli-symbols.js +12 -0
  143. package/dist/utils/cli-symbols.js.map +1 -1
  144. package/dist/utils/debug.js +3 -3
  145. package/dist/utils/debug.js.map +1 -1
  146. package/dist/utils/environment.js +1 -1
  147. package/dist/utils/environment.js.map +1 -1
  148. package/dist/utils/help-json.js +115 -4
  149. package/dist/utils/help-json.js.map +1 -1
  150. package/dist/utils/package-manager.js +1 -1
  151. package/dist/utils/package-manager.js.map +1 -1
  152. package/dist/utils/recovery-hints.d.ts +5 -0
  153. package/dist/utils/recovery-hints.js +12 -0
  154. package/dist/utils/recovery-hints.js.map +1 -1
  155. package/dist/utils/summary-box.d.ts +8 -1
  156. package/dist/utils/summary-box.js +67 -4
  157. package/dist/utils/summary-box.js.map +1 -1
  158. package/dist/utils/types.d.ts +10 -0
  159. package/dist/utils/types.js.map +1 -1
  160. package/dist/utils/{clack-utils.d.ts → ui-utils.d.ts} +1 -1
  161. package/dist/utils/{clack-utils.js → ui-utils.js} +64 -37
  162. package/dist/utils/ui-utils.js.map +1 -0
  163. package/dist/utils/ui.d.ts +148 -0
  164. package/dist/utils/ui.js +368 -0
  165. package/dist/utils/ui.js.map +1 -0
  166. package/package.json +5 -13
  167. package/dist/check-coverage.ts +0 -237
  168. package/dist/emulate/core/id.d.ts +0 -48
  169. package/dist/emulate/core/id.js +0 -73
  170. package/dist/emulate/core/id.js.map +0 -1
  171. package/dist/emulate/core/index.d.ts +0 -8
  172. package/dist/emulate/core/index.js +0 -8
  173. package/dist/emulate/core/index.js.map +0 -1
  174. package/dist/emulate/core/jwt.d.ts +0 -28
  175. package/dist/emulate/core/jwt.js +0 -78
  176. package/dist/emulate/core/jwt.js.map +0 -1
  177. package/dist/emulate/core/middleware/auth.d.ts +0 -15
  178. package/dist/emulate/core/middleware/auth.js +0 -17
  179. package/dist/emulate/core/middleware/auth.js.map +0 -1
  180. package/dist/emulate/core/middleware/error-handler.d.ts +0 -22
  181. package/dist/emulate/core/middleware/error-handler.js +0 -72
  182. package/dist/emulate/core/middleware/error-handler.js.map +0 -1
  183. package/dist/emulate/core/pagination.d.ts +0 -27
  184. package/dist/emulate/core/pagination.js +0 -43
  185. package/dist/emulate/core/pagination.js.map +0 -1
  186. package/dist/emulate/core/plugin.d.ts +0 -15
  187. package/dist/emulate/core/plugin.js +0 -2
  188. package/dist/emulate/core/plugin.js.map +0 -1
  189. package/dist/emulate/core/server.d.ts +0 -17
  190. package/dist/emulate/core/server.js +0 -90
  191. package/dist/emulate/core/server.js.map +0 -1
  192. package/dist/emulate/core/store.d.ts +0 -44
  193. package/dist/emulate/core/store.js +0 -169
  194. package/dist/emulate/core/store.js.map +0 -1
  195. package/dist/emulate/index.d.ts +0 -25
  196. package/dist/emulate/index.js +0 -47
  197. package/dist/emulate/index.js.map +0 -1
  198. package/dist/emulate/workos/constants.d.ts +0 -56
  199. package/dist/emulate/workos/constants.js +0 -56
  200. package/dist/emulate/workos/constants.js.map +0 -1
  201. package/dist/emulate/workos/entities.d.ts +0 -360
  202. package/dist/emulate/workos/entities.js +0 -2
  203. package/dist/emulate/workos/entities.js.map +0 -1
  204. package/dist/emulate/workos/event-bus.d.ts +0 -17
  205. package/dist/emulate/workos/event-bus.js +0 -70
  206. package/dist/emulate/workos/event-bus.js.map +0 -1
  207. package/dist/emulate/workos/helpers.d.ts +0 -72
  208. package/dist/emulate/workos/helpers.js +0 -211
  209. package/dist/emulate/workos/helpers.js.map +0 -1
  210. package/dist/emulate/workos/index.d.ts +0 -93
  211. package/dist/emulate/workos/index.js +0 -326
  212. package/dist/emulate/workos/index.js.map +0 -1
  213. package/dist/emulate/workos/role-helpers.d.ts +0 -21
  214. package/dist/emulate/workos/role-helpers.js +0 -130
  215. package/dist/emulate/workos/role-helpers.js.map +0 -1
  216. package/dist/emulate/workos/routes/api-keys.d.ts +0 -2
  217. package/dist/emulate/workos/routes/api-keys.js +0 -32
  218. package/dist/emulate/workos/routes/api-keys.js.map +0 -1
  219. package/dist/emulate/workos/routes/audit-logs.d.ts +0 -2
  220. package/dist/emulate/workos/routes/audit-logs.js +0 -104
  221. package/dist/emulate/workos/routes/audit-logs.js.map +0 -1
  222. package/dist/emulate/workos/routes/auth-challenges.d.ts +0 -2
  223. package/dist/emulate/workos/routes/auth-challenges.js +0 -51
  224. package/dist/emulate/workos/routes/auth-challenges.js.map +0 -1
  225. package/dist/emulate/workos/routes/auth-factors.d.ts +0 -2
  226. package/dist/emulate/workos/routes/auth-factors.js +0 -51
  227. package/dist/emulate/workos/routes/auth-factors.js.map +0 -1
  228. package/dist/emulate/workos/routes/auth.d.ts +0 -2
  229. package/dist/emulate/workos/routes/auth.js +0 -350
  230. package/dist/emulate/workos/routes/auth.js.map +0 -1
  231. package/dist/emulate/workos/routes/authorization-checks.d.ts +0 -10
  232. package/dist/emulate/workos/routes/authorization-checks.js +0 -123
  233. package/dist/emulate/workos/routes/authorization-checks.js.map +0 -1
  234. package/dist/emulate/workos/routes/authorization-org-roles.d.ts +0 -2
  235. package/dist/emulate/workos/routes/authorization-org-roles.js +0 -64
  236. package/dist/emulate/workos/routes/authorization-org-roles.js.map +0 -1
  237. package/dist/emulate/workos/routes/authorization-permissions.d.ts +0 -2
  238. package/dist/emulate/workos/routes/authorization-permissions.js +0 -67
  239. package/dist/emulate/workos/routes/authorization-permissions.js.map +0 -1
  240. package/dist/emulate/workos/routes/authorization-resources.d.ts +0 -2
  241. package/dist/emulate/workos/routes/authorization-resources.js +0 -117
  242. package/dist/emulate/workos/routes/authorization-resources.js.map +0 -1
  243. package/dist/emulate/workos/routes/authorization-roles.d.ts +0 -2
  244. package/dist/emulate/workos/routes/authorization-roles.js +0 -13
  245. package/dist/emulate/workos/routes/authorization-roles.js.map +0 -1
  246. package/dist/emulate/workos/routes/config.d.ts +0 -2
  247. package/dist/emulate/workos/routes/config.js +0 -57
  248. package/dist/emulate/workos/routes/config.js.map +0 -1
  249. package/dist/emulate/workos/routes/connect.d.ts +0 -2
  250. package/dist/emulate/workos/routes/connect.js +0 -65
  251. package/dist/emulate/workos/routes/connect.js.map +0 -1
  252. package/dist/emulate/workos/routes/connections.d.ts +0 -2
  253. package/dist/emulate/workos/routes/connections.js +0 -73
  254. package/dist/emulate/workos/routes/connections.js.map +0 -1
  255. package/dist/emulate/workos/routes/data-integrations.d.ts +0 -2
  256. package/dist/emulate/workos/routes/data-integrations.js +0 -55
  257. package/dist/emulate/workos/routes/data-integrations.js.map +0 -1
  258. package/dist/emulate/workos/routes/directories.d.ts +0 -2
  259. package/dist/emulate/workos/routes/directories.js +0 -90
  260. package/dist/emulate/workos/routes/directories.js.map +0 -1
  261. package/dist/emulate/workos/routes/email-verification.d.ts +0 -2
  262. package/dist/emulate/workos/routes/email-verification.js +0 -49
  263. package/dist/emulate/workos/routes/email-verification.js.map +0 -1
  264. package/dist/emulate/workos/routes/events.d.ts +0 -2
  265. package/dist/emulate/workos/routes/events.js +0 -18
  266. package/dist/emulate/workos/routes/events.js.map +0 -1
  267. package/dist/emulate/workos/routes/feature-flags.d.ts +0 -2
  268. package/dist/emulate/workos/routes/feature-flags.js +0 -103
  269. package/dist/emulate/workos/routes/feature-flags.js.map +0 -1
  270. package/dist/emulate/workos/routes/invitations.d.ts +0 -2
  271. package/dist/emulate/workos/routes/invitations.js +0 -122
  272. package/dist/emulate/workos/routes/invitations.js.map +0 -1
  273. package/dist/emulate/workos/routes/legacy-mfa.d.ts +0 -2
  274. package/dist/emulate/workos/routes/legacy-mfa.js +0 -75
  275. package/dist/emulate/workos/routes/legacy-mfa.js.map +0 -1
  276. package/dist/emulate/workos/routes/magic-auth.d.ts +0 -2
  277. package/dist/emulate/workos/routes/magic-auth.js +0 -32
  278. package/dist/emulate/workos/routes/magic-auth.js.map +0 -1
  279. package/dist/emulate/workos/routes/memberships.d.ts +0 -2
  280. package/dist/emulate/workos/routes/memberships.js +0 -114
  281. package/dist/emulate/workos/routes/memberships.js.map +0 -1
  282. package/dist/emulate/workos/routes/organization-domains.d.ts +0 -2
  283. package/dist/emulate/workos/routes/organization-domains.js +0 -58
  284. package/dist/emulate/workos/routes/organization-domains.js.map +0 -1
  285. package/dist/emulate/workos/routes/organizations.d.ts +0 -2
  286. package/dist/emulate/workos/routes/organizations.js +0 -131
  287. package/dist/emulate/workos/routes/organizations.js.map +0 -1
  288. package/dist/emulate/workos/routes/password-reset.d.ts +0 -2
  289. package/dist/emulate/workos/routes/password-reset.js +0 -61
  290. package/dist/emulate/workos/routes/password-reset.js.map +0 -1
  291. package/dist/emulate/workos/routes/pipes.d.ts +0 -2
  292. package/dist/emulate/workos/routes/pipes.js +0 -82
  293. package/dist/emulate/workos/routes/pipes.js.map +0 -1
  294. package/dist/emulate/workos/routes/portal.d.ts +0 -2
  295. package/dist/emulate/workos/routes/portal.js +0 -18
  296. package/dist/emulate/workos/routes/portal.js.map +0 -1
  297. package/dist/emulate/workos/routes/radar.d.ts +0 -2
  298. package/dist/emulate/workos/routes/radar.js +0 -41
  299. package/dist/emulate/workos/routes/radar.js.map +0 -1
  300. package/dist/emulate/workos/routes/sessions.d.ts +0 -2
  301. package/dist/emulate/workos/routes/sessions.js +0 -51
  302. package/dist/emulate/workos/routes/sessions.js.map +0 -1
  303. package/dist/emulate/workos/routes/sso.d.ts +0 -2
  304. package/dist/emulate/workos/routes/sso.js +0 -161
  305. package/dist/emulate/workos/routes/sso.js.map +0 -1
  306. package/dist/emulate/workos/routes/user-features.d.ts +0 -2
  307. package/dist/emulate/workos/routes/user-features.js +0 -50
  308. package/dist/emulate/workos/routes/user-features.js.map +0 -1
  309. package/dist/emulate/workos/routes/users.d.ts +0 -2
  310. package/dist/emulate/workos/routes/users.js +0 -129
  311. package/dist/emulate/workos/routes/users.js.map +0 -1
  312. package/dist/emulate/workos/routes/webhook-endpoints.d.ts +0 -2
  313. package/dist/emulate/workos/routes/webhook-endpoints.js +0 -67
  314. package/dist/emulate/workos/routes/webhook-endpoints.js.map +0 -1
  315. package/dist/emulate/workos/routes/widgets.d.ts +0 -2
  316. package/dist/emulate/workos/routes/widgets.js +0 -27
  317. package/dist/emulate/workos/routes/widgets.js.map +0 -1
  318. package/dist/emulate/workos/store.d.ts +0 -48
  319. package/dist/emulate/workos/store.js +0 -102
  320. package/dist/emulate/workos/store.js.map +0 -1
  321. package/dist/emulate/workos/webhook-signer.d.ts +0 -1
  322. package/dist/emulate/workos/webhook-signer.js +0 -8
  323. package/dist/emulate/workos/webhook-signer.js.map +0 -1
  324. package/dist/gen-routes-lib.spec.ts +0 -659
  325. package/dist/gen-routes-lib.ts +0 -647
  326. package/dist/gen-routes.ts +0 -96
  327. package/dist/lib/mcp-notice.d.ts +0 -72
  328. package/dist/lib/mcp-notice.js +0 -275
  329. package/dist/lib/mcp-notice.js.map +0 -1
  330. package/dist/utils/clack-utils.js.map +0 -1
  331. package/dist/utils/clack.d.ts +0 -5
  332. package/dist/utils/clack.js +0 -34
  333. package/dist/utils/clack.js.map +0 -1
@@ -1,41 +0,0 @@
1
- import { notFound, parseJsonBody, parseListParams } from '../../core/index.js';
2
- import { getWorkOSStore } from '../store.js';
3
- import { formatRadarAttempt, formatListResponse } from '../helpers.js';
4
- export function radarRoutes(ctx) {
5
- const { app, store } = ctx;
6
- const ws = getWorkOSStore(store);
7
- // List attempts
8
- app.get('/radar/attempts', (c) => {
9
- const url = new URL(c.req.url);
10
- const params = parseListParams(url);
11
- const result = ws.radarAttempts.list({ ...params });
12
- return c.json(formatListResponse(result, formatRadarAttempt));
13
- });
14
- // Get attempt
15
- app.get('/radar/attempts/:id', (c) => {
16
- const attempt = ws.radarAttempts.get(c.req.param('id'));
17
- if (!attempt)
18
- throw notFound('RadarAttempt');
19
- return c.json(formatRadarAttempt(attempt));
20
- });
21
- // Manage allow/deny lists
22
- app.post('/radar/lists/:type/:action', async (c) => {
23
- const listType = c.req.param('type');
24
- const action = c.req.param('action');
25
- const body = await parseJsonBody(c);
26
- const entries = body.entries ?? [];
27
- const key = `radar_${listType}_list`;
28
- const existing = store.getData(key) ?? new Set();
29
- if (action === 'add') {
30
- for (const entry of entries)
31
- existing.add(entry);
32
- }
33
- else if (action === 'remove') {
34
- for (const entry of entries)
35
- existing.delete(entry);
36
- }
37
- store.setData(key, existing);
38
- return c.json({ success: true });
39
- });
40
- }
41
- //# sourceMappingURL=radar.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"radar.js","sourceRoot":"","sources":["../../../../src/emulate/workos/routes/radar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAClG,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEvE,MAAM,UAAU,WAAW,CAAC,GAAiB;IAC3C,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC;IAC3B,MAAM,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IAEjC,gBAAgB;IAChB,GAAG,CAAC,GAAG,CAAC,iB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AAC,IAAI,IAAI,GAAG,EAAU,CAAC;QAEtE,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;YACrB,KAAK,MAAM,KAAK,IAAI,OAAO;gBAAE,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnD,CAAC;aAAM,IAAI,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,KAAK,MAAM,KAAK,IAAI,OAAO;gBAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACtD,CAAC;QAED,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAC7B,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { type RouteContext, notFound, parseJsonBody, parseListParams } from '../../core/index.js';\nimport { getWorkOSStore } from '../store.js';\nimport { formatRadarAttempt, formatListResponse } from '../helpers.js';\n\nexport function radarRoutes(ctx: RouteContext): void {\n const { app, store } = ctx;\n const ws = getWorkOSStore(store);\n\n // List attempts\n app.get('/radar/attempts', (c) => {\n const url = new URL(c.req.url);\n const params = parseListParams(url);\n const result = ws.radarAttempts.list({ ...params });\n return c.json(formatListResponse(result, formatRadarAttempt));\n });\n\n // Get attempt\n app.get('/radar/attempts/:id', (c) => {\n const attempt = ws.radarAttempts.get(c.req.param('id'));\n if (!attempt) throw notFound('RadarAttempt');\n return c.json(formatRadarAttempt(attempt));\n });\n\n // Manage allow/deny lists\n app.post('/radar/lists/:type/:action', async (c) => {\n const listType = c.req.param('type');\n const action = c.req.param('action');\n const body = await parseJsonBody(c);\n const entries = (body.entries as string[]) ?? [];\n\n const key = `radar_${listType}_list`;\n const existing = store.getData<Set<string>>(key) ?? new Set<string>();\n\n if (action === 'add') {\n for (const entry of entries) existing.add(entry);\n } else if (action === 'remove') {\n for (const entry of entries) existing.delete(entry);\n }\n\n store.setData(key, existing);\n return c.json({ success: true });\n });\n}\n"]}
@@ -1,2 +0,0 @@
1
- import { type RouteContext } from '../../core/index.js';
2
- export declare function sessionRoutes(ctx: RouteContext): void;
@@ -1,51 +0,0 @@
1
- import { notFound, parseJsonBody, WorkOSApiError } from '../../core/index.js';
2
- import { getWorkOSStore } from '../store.js';
3
- import { formatSession, assertLocalRedirectUri } from '../helpers.js';
4
- export function sessionRoutes(ctx) {
5
- const { app, store, jwt } = ctx;
6
- const ws = getWorkOSStore(store);
7
- app.get('/user_management/users/:id/sessions', (c) => {
8
- const user = ws.users.get(c.req.param('id'));
9
- if (!user)
10
- throw notFound('User');
11
- const sessions = ws.sessions.findBy('user_id', user.id);
12
- return c.json({
13
- object: 'list',
14
- data: sessions.map(formatSession),
15
- list_metadata: { before: null, after: null },
16
- });
17
- });
18
- app.post('/user_management/sessions/revoke', async (c) => {
19
- const body = await parseJsonBody(c);
20
- const sessionId = body.session_id;
21
- if (!sessionId) {
22
- throw new WorkOSApiError(400, 'session_id is required', 'invalid_request');
23
- }
24
- const session = ws.sessions.get(sessionId);
25
- if (!session)
26
- throw notFound('Session');
27
- ws.sessions.delete(session.id);
28
- return c.json({ success: true });
29
- });
30
- // Public endpoint — no auth required (security: [])
31
- app.get('/user_management/sessions/logout', (c) => {
32
- const url = new URL(c.req.url);
33
- const sessionId = url.searchParams.get('session_id');
34
- const returnTo = url.searchParams.get('return_to');
35
- if (!sessionId) {
36
- throw new WorkOSApiError(422, 'session_id is required', 'invalid_request');
37
- }
38
- const session = ws.sessions.get(sessionId);
39
- if (session)
40
- ws.sessions.delete(session.id);
41
- if (returnTo) {
42
- assertLocalRedirectUri(returnTo);
43
- return c.redirect(returnTo);
44
- }
45
- return c.json({ success: true });
46
- });
47
- app.get('/user_management/sessions/jwks/:clientId', (c) => {
48
- return c.json(jwt.getJWKS());
49
- });
50
- }
51
- //# sourceMappingURL=sessions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sessions.js","sourceRoot":"","sources":["../../../../src/emulate/workos/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,CAAC;IAEH,GAAG,CAAC,GAAG,CAAC,0CAA0C,EAAE,CAAC,CAAC,EAAE,EAAE;QACxD,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { type RouteContext, notFound, parseJsonBody, WorkOSApiError } from '../../core/index.js';\nimport { getWorkOSStore } from '../store.js';\nimport { formatSession, assertLocalRedirectUri } from '../helpers.js';\n\nexport function sessionRoutes(ctx: RouteContext): void {\n const { app, store, jwt } = ctx;\n const ws = getWorkOSStore(store);\n\n app.get('/user_management/users/:id/sessions', (c) => {\n const user = ws.users.get(c.req.param('id'));\n if (!user) throw notFound('User');\n\n const sessions = ws.sessions.findBy('user_id', user.id);\n return c.json({\n object: 'list',\n data: sessions.map(formatSession),\n list_metadata: { before: null, after: null },\n });\n });\n\n app.post('/user_management/sessions/revoke', async (c) => {\n const body = await parseJsonBody(c);\n const sessionId = body.session_id as string | undefined;\n if (!sessionId) {\n throw new WorkOSApiError(400, 'session_id is required', 'invalid_request');\n }\n\n const session = ws.sessions.get(sessionId);\n if (!session) throw notFound('Session');\n\n ws.sessions.delete(session.id);\n return c.json({ success: true });\n });\n\n // Public endpoint — no auth required (security: [])\n app.get('/user_management/sessions/logout', (c) => {\n const url = new URL(c.req.url);\n const sessionId = url.searchParams.get('session_id');\n const returnTo = url.searchParams.get('return_to');\n\n if (!sessionId) {\n throw new WorkOSApiError(422, 'session_id is required', 'invalid_request');\n }\n\n const session = ws.sessions.get(sessionId);\n if (session) ws.sessions.delete(session.id);\n\n if (returnTo) {\n assertLocalRedirectUri(returnTo);\n return c.redirect(returnTo);\n }\n return c.json({ success: true });\n });\n\n app.get('/user_management/sessions/jwks/:clientId', (c) => {\n return c.json(jwt.getJWKS());\n });\n}\n"]}
@@ -1,2 +0,0 @@
1
- import { type RouteContext } from '../../core/index.js';
2
- export declare function ssoRoutes(ctx: RouteContext): void;
@@ -1,161 +0,0 @@
1
- import { parseJsonBody, WorkOSApiError, generateId } from '../../core/index.js';
2
- import { getWorkOSStore } from '../store.js';
3
- import { formatSSOProfile, expiresIn, isExpired, assertLocalRedirectUri } from '../helpers.js';
4
- import { STORE_KEY_PREFIXES } from '../constants.js';
5
- export function ssoRoutes(ctx) {
6
- const { app, store, jwt } = ctx;
7
- const ws = getWorkOSStore(store);
8
- app.get('/sso/authorize', (c) => {
9
- const url = new URL(c.req.url);
10
- const redirectUri = url.searchParams.get('redirect_uri');
11
- const state = url.searchParams.get('state');
12
- const connectionId = url.searchParams.get('connection');
13
- const organizationId = url.searchParams.get('organization');
14
- const domainHint = url.searchParams.get('domain_hint');
15
- const loginHint = url.searchParams.get('login_hint');
16
- if (!redirectUri) {
17
- throw new WorkOSApiError(400, 'Missing required parameter: redirect_uri', 'invalid_request');
18
- }
19
- assertLocalRedirectUri(redirectUri);
20
- let connection;
21
- if (connectionId) {
22
- connection = ws.connections.get(connectionId);
23
- }
24
- else if (organizationId) {
25
- connection = ws.connections.findBy('organization_id', organizationId).find((c) => c.state === 'active');
26
- }
27
- else if (domainHint) {
28
- connection = ws.connections
29
- .all()
30
- .find((c) => c.state === 'active' && c.domains.some((d) => d.domain === domainHint));
31
- }
32
- if (!connection || connection.state !== 'active') {
33
- throw new WorkOSApiError(404, 'No active connection found', 'connection_not_found');
34
- }
35
- const email = loginHint ?? `user@${connection.domains[0]?.domain ?? 'example.com'}`;
36
- let profile = ws.ssoProfiles.findOneBy('email', email);
37
- if (!profile || profile.connection_id !== connection.id) {
38
- profile = ws.ssoProfiles.insert({
39
- object: 'profile',
40
- connection_id: connection.id,
41
- connection_type: connection.connection_type,
42
- organization_id: connection.organization_id,
43
- idp_id: `idp_${generateId('usr')}`,
44
- email,
45
- first_name: email.split('@')[0],
46
- last_name: null,
47
- groups: [],
48
- raw_attributes: { email },
49
- });
50
- }
51
- const authCode = ws.ssoAuthorizations.insert({
52
- code: generateId('sso_code'),
53
- connection_id: connection.id,
54
- organization_id: connection.organization_id,
55
- profile_id: profile.id,
56
- redirect_uri: redirectUri,
57
- state,
58
- expires_at: expiresIn(10),
59
- });
60
- const redirect = new URL(redirectUri);
61
- redirect.searchParams.set('code', authCode.code);
62
- if (state)
63
- redirect.searchParams.set('state', state);
64
- return c.redirect(redirect.toString());
65
- });
66
- app.post('/sso/token', async (c) => {
67
- const body = await parseJsonBody(c);
68
- const grantType = body.grant_type;
69
- const code = body.code;
70
- if (grantType !== 'authorization_code') {
71
- throw new WorkOSApiError(400, 'Unsupported grant_type', 'invalid_request');
72
- }
73
- if (!code) {
74
- throw new WorkOSApiError(400, 'code is required', 'invalid_request');
75
- }
76
- const auth = ws.ssoAuthorizations.findOneBy('code', code);
77
- if (!auth) {
78
- throw new WorkOSApiError(400, 'Invalid authorization code', 'invalid_code');
79
- }
80
- if (isExpired(auth.expires_at)) {
81
- ws.ssoAuthorizations.delete(auth.id);
82
- throw new WorkOSApiError(400, 'Authorization code has expired', 'expired_code');
83
- }
84
- const profile = ws.ssoProfiles.get(auth.profile_id);
85
- if (!profile) {
86
- throw new WorkOSApiError(500, 'Profile not found', 'server_error');
87
- }
88
- ws.ssoAuthorizations.delete(auth.id);
89
- const accessToken = jwt.sign({
90
- sub: profile.id,
91
- aud: body.client_id ?? 'workos-emulate',
92
- org_id: auth.organization_id,
93
- });
94
- store.setData(`${STORE_KEY_PREFIXES.ssoToken}${accessToken}`, profile.id);
95
- return c.json({
96
- profile: formatSSOProfile(profile),
97
- access_token: accessToken,
98
- });
99
- });
100
- app.get('/sso/profile', (c) => {
101
- const authHeader = c.req.header('Authorization');
102
- if (!authHeader) {
103
- throw new WorkOSApiError(401, 'Unauthorized', 'unauthorized');
104
- }
105
- const token = authHeader.replace(/^Bearer\s+/i, '').trim();
106
- const profileId = store.getData(`${STORE_KEY_PREFIXES.ssoToken}${token}`);
107
- if (!profileId) {
108
- try {
109
- const payload = jwt.verify(token);
110
- const profile = ws.ssoProfiles.get(payload.sub);
111
- if (profile)
112
- return c.json(formatSSOProfile(profile));
113
- }
114
- catch {
115
- // fall through
116
- }
117
- throw new WorkOSApiError(401, 'Invalid access token', 'unauthorized');
118
- }
119
- const profile = ws.ssoProfiles.get(profileId);
120
- if (!profile) {
121
- throw new WorkOSApiError(404, 'Profile not found', 'not_found');
122
- }
123
- return c.json(formatSSOProfile(profile));
124
- });
125
- app.get('/sso/jwks', (c) => {
126
- return c.json(jwt.getJWKS());
127
- });
128
- // SSO Single Logout — generate logout token
129
- app.post('/sso/logout/authorize', async (c) => {
130
- const body = await parseJsonBody(c);
131
- const profileId = body.profile_id;
132
- if (!profileId) {
133
- throw new WorkOSApiError(400, 'profile_id is required', 'invalid_request');
134
- }
135
- const profile = ws.ssoProfiles.get(profileId);
136
- if (!profile) {
137
- throw new WorkOSApiError(404, 'Profile not found', 'not_found');
138
- }
139
- const logoutToken = generateId('sso_logout');
140
- store.setData(`${STORE_KEY_PREFIXES.ssoLogout}${logoutToken}`, profile.id);
141
- return c.json({
142
- logout_token: logoutToken,
143
- logout_url: `${ctx.baseUrl}/sso/logout?logout_token=${logoutToken}`,
144
- });
145
- });
146
- // SSO Single Logout — redirect (public, no auth)
147
- app.get('/sso/logout', (c) => {
148
- const url = new URL(c.req.url);
149
- const logoutToken = url.searchParams.get('logout_token');
150
- if (!logoutToken) {
151
- throw new WorkOSApiError(400, 'logout_token is required', 'invalid_request');
152
- }
153
- const profileId = store.getData(`${STORE_KEY_PREFIXES.ssoLogout}${logoutToken}`);
154
- if (!profileId) {
155
- throw new WorkOSApiError(400, 'Invalid logout token', 'invalid_logout_token');
156
- }
157
- store.setData(`${STORE_KEY_PREFIXES.ssoLogout}${logoutToken}`, undefined);
158
- return c.json({ success: true });
159
- });
160
- }
161
- //# sourceMappingURL=sso.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sso.js","sourceRoot":"","sources":["../../../../src/emulate/workos/routes/sso.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,aAAa,EAAE,cAAc,EAAE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,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,WAAW,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAEzD,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,cAAc,CAAC,GAAG,EAAE,0BAA0B,EAAE,iBAAiB,CAAC,CAAC;QAC/E,CAAC;QAED,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAS,GAAG,kBAAkB,CAAC,SAAS,GAAG,WAAW,EAAE,CAAC,CAAC;QACzF,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,cAAc,CAAC,GAAG,EAAE,sBAAsB,EAAE,sBAAsB,CAAC,CAAC;QAChF,CAAC;QAED,KAAK,CAAC,OAAO,CAAC,GAAG,kBAAkB,CAAC,SAAS,GAAG,WAAW,EAAE,EAAE,SAAS,CAAC,CAAC;QAC1E,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { type RouteContext, parseJsonBody, WorkOSApiError, generateId } from '../../core/index.js';\nimport { getWorkOSStore } from '../store.js';\nimport { formatSSOProfile, expiresIn, isExpired, assertLocalRedirectUri } from '../helpers.js';\nimport type { WorkOSConnection } from '../entities.js';\nimport { STORE_KEY_PREFIXES } from '../constants.js';\n\nexport function ssoRoutes(ctx: RouteContext): void {\n const { app, store, jwt } = ctx;\n const ws = getWorkOSStore(store);\n\n app.get('/sso/authorize', (c) => {\n const url = new URL(c.req.url);\n const redirectUri = url.searchParams.get('redirect_uri');\n const state = url.searchParams.get('state');\n const connectionId = url.searchParams.get('connection');\n const organizationId = url.searchParams.get('organization');\n const domainHint = url.searchParams.get('domain_hint');\n const loginHint = url.searchParams.get('login_hint');\n\n if (!redirectUri) {\n throw new WorkOSApiError(400, 'Missing required parameter: redirect_uri', 'invalid_request');\n }\n assertLocalRedirectUri(redirectUri);\n\n let connection: WorkOSConnection | undefined;\n\n if (connectionId) {\n connection = ws.connections.get(connectionId);\n } else if (organizationId) {\n connection = ws.connections.findBy('organization_id', organizationId).find((c) => c.state === 'active');\n } else if (domainHint) {\n connection = ws.connections\n .all()\n .find((c) => c.state === 'active' && c.domains.some((d) => d.domain === domainHint));\n }\n\n if (!connection || connection.state !== 'active') {\n throw new WorkOSApiError(404, 'No active connection found', 'connection_not_found');\n }\n\n const email = loginHint ?? `user@${connection.domains[0]?.domain ?? 'example.com'}`;\n let profile = ws.ssoProfiles.findOneBy('email', email);\n if (!profile || profile.connection_id !== connection.id) {\n profile = ws.ssoProfiles.insert({\n object: 'profile',\n connection_id: connection.id,\n connection_type: connection.connection_type,\n organization_id: connection.organization_id,\n idp_id: `idp_${generateId('usr')}`,\n email,\n first_name: email.split('@')[0],\n last_name: null,\n groups: [],\n raw_attributes: { email },\n });\n }\n\n const authCode = ws.ssoAuthorizations.insert({\n code: generateId('sso_code'),\n connection_id: connection.id,\n organization_id: connection.organization_id,\n profile_id: profile.id,\n redirect_uri: redirectUri,\n state,\n expires_at: expiresIn(10),\n });\n\n const redirect = new URL(redirectUri);\n redirect.searchParams.set('code', authCode.code);\n if (state) redirect.searchParams.set('state', state);\n return c.redirect(redirect.toString());\n });\n\n app.post('/sso/token', async (c) => {\n const body = await parseJsonBody(c);\n const grantType = body.grant_type as string;\n const code = body.code as string;\n\n if (grantType !== 'authorization_code') {\n throw new WorkOSApiError(400, 'Unsupported grant_type', 'invalid_request');\n }\n if (!code) {\n throw new WorkOSApiError(400, 'code is required', 'invalid_request');\n }\n\n const auth = ws.ssoAuthorizations.findOneBy('code', code);\n if (!auth) {\n throw new WorkOSApiError(400, 'Invalid authorization code', 'invalid_code');\n }\n if (isExpired(auth.expires_at)) {\n ws.ssoAuthorizations.delete(auth.id);\n throw new WorkOSApiError(400, 'Authorization code has expired', 'expired_code');\n }\n\n const profile = ws.ssoProfiles.get(auth.profile_id);\n if (!profile) {\n throw new WorkOSApiError(500, 'Profile not found', 'server_error');\n }\n\n ws.ssoAuthorizations.delete(auth.id);\n\n const accessToken = jwt.sign({\n sub: profile.id,\n aud: (body.client_id as string) ?? 'workos-emulate',\n org_id: auth.organization_id,\n });\n\n store.setData(`${STORE_KEY_PREFIXES.ssoToken}${accessToken}`, profile.id);\n\n return c.json({\n profile: formatSSOProfile(profile),\n access_token: accessToken,\n });\n });\n\n app.get('/sso/profile', (c) => {\n const authHeader = c.req.header('Authorization');\n if (!authHeader) {\n throw new WorkOSApiError(401, 'Unauthorized', 'unauthorized');\n }\n const token = authHeader.replace(/^Bearer\\s+/i, '').trim();\n\n const profileId = store.getData<string>(`${STORE_KEY_PREFIXES.ssoToken}${token}`);\n if (!profileId) {\n try {\n const payload = jwt.verify(token);\n const profile = ws.ssoProfiles.get(payload.sub);\n if (profile) return c.json(formatSSOProfile(profile));\n } catch {\n // fall through\n }\n throw new WorkOSApiError(401, 'Invalid access token', 'unauthorized');\n }\n\n const profile = ws.ssoProfiles.get(profileId);\n if (!profile) {\n throw new WorkOSApiError(404, 'Profile not found', 'not_found');\n }\n\n return c.json(formatSSOProfile(profile));\n });\n\n app.get('/sso/jwks', (c) => {\n return c.json(jwt.getJWKS());\n });\n\n // SSO Single Logout — generate logout token\n app.post('/sso/logout/authorize', async (c) => {\n const body = await parseJsonBody(c);\n const profileId = body.profile_id as string;\n if (!profileId) {\n throw new WorkOSApiError(400, 'profile_id is required', 'invalid_request');\n }\n\n const profile = ws.ssoProfiles.get(profileId);\n if (!profile) {\n throw new WorkOSApiError(404, 'Profile not found', 'not_found');\n }\n\n const logoutToken = generateId('sso_logout');\n store.setData(`${STORE_KEY_PREFIXES.ssoLogout}${logoutToken}`, profile.id);\n\n return c.json({\n logout_token: logoutToken,\n logout_url: `${ctx.baseUrl}/sso/logout?logout_token=${logoutToken}`,\n });\n });\n\n // SSO Single Logout — redirect (public, no auth)\n app.get('/sso/logout', (c) => {\n const url = new URL(c.req.url);\n const logoutToken = url.searchParams.get('logout_token');\n\n if (!logoutToken) {\n throw new WorkOSApiError(400, 'logout_token is required', 'invalid_request');\n }\n\n const profileId = store.getData<string>(`${STORE_KEY_PREFIXES.ssoLogout}${logoutToken}`);\n if (!profileId) {\n throw new WorkOSApiError(400, 'Invalid logout token', 'invalid_logout_token');\n }\n\n store.setData(`${STORE_KEY_PREFIXES.ssoLogout}${logoutToken}`, undefined);\n return c.json({ success: true });\n });\n}\n"]}
@@ -1,2 +0,0 @@
1
- import { type RouteContext } from '../../core/index.js';
2
- export declare function userFeatureRoutes(ctx: RouteContext): void;
@@ -1,50 +0,0 @@
1
- import { notFound } from '../../core/index.js';
2
- import { getWorkOSStore } from '../store.js';
3
- import { formatAuthorizedApplication, formatConnectedAccount, formatPipeConnection } from '../helpers.js';
4
- export function userFeatureRoutes(ctx) {
5
- const { app, store } = ctx;
6
- const ws = getWorkOSStore(store);
7
- app.get('/user_management/users/:user_id/authorized_applications', (c) => {
8
- const user = ws.users.get(c.req.param('user_id'));
9
- if (!user)
10
- throw notFound('User');
11
- const apps = ws.authorizedApplications.findBy('user_id', user.id);
12
- return c.json({
13
- object: 'list',
14
- data: apps.map(formatAuthorizedApplication),
15
- list_metadata: { before: null, after: null },
16
- });
17
- });
18
- app.delete('/user_management/users/:user_id/authorized_applications/:application_id', (c) => {
19
- const user = ws.users.get(c.req.param('user_id'));
20
- if (!user)
21
- throw notFound('User');
22
- const appItem = ws.authorizedApplications.get(c.req.param('application_id'));
23
- if (!appItem || appItem.user_id !== user.id)
24
- throw notFound('Authorized Application');
25
- ws.authorizedApplications.delete(appItem.id);
26
- return c.body(null, 204);
27
- });
28
- app.get('/user_management/users/:user_id/connected_accounts/:slug', (c) => {
29
- const user = ws.users.get(c.req.param('user_id'));
30
- if (!user)
31
- throw notFound('User');
32
- const slug = c.req.param('slug');
33
- const account = ws.connectedAccounts.findBy('user_id', user.id).find((a) => a.provider === slug);
34
- if (!account)
35
- throw notFound('Connected Account');
36
- return c.json(formatConnectedAccount(account));
37
- });
38
- app.get('/user_management/users/:user_id/data_providers', (c) => {
39
- const user = ws.users.get(c.req.param('user_id'));
40
- if (!user)
41
- throw notFound('User');
42
- const pipes = ws.pipeConnections.findBy('user_id', user.id);
43
- return c.json({
44
- object: 'list',
45
- data: pipes.map(formatPipeConnection),
46
- list_metadata: { before: null, after: null },
47
- });
48
- });
49
- }
50
- //# sourceMappingURL=user-features.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"user-features.js","sourceRoot":"","sources":["../../../../src/emulate/workos/routes/user-features.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAE1G,MAAM,UAAU,iBAAiB,CAAC,GAAiB;IACjD,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC;IAC3B,MAAM,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IAEjC,GAAG,CAAC,GAAG,CAAC,yDAAyD,EAAE,CAAC,CAAC,EAAE,EAAE;QACvE,MAAM,IAAI,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI;YAAE,MAAM,QAAQ,CAAC,MAAM,CAAC,CAAC;QAElC,MAAM,IAAI,GAAG,EAAE,CAAC,sBAAsB,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QAClE,OAAO,CAAC,CAAC,IAAI,CAAC;YACZ,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,2BAA2B,CAAC;YAC3C,aAAa,EAAE,EAAE,MAAM,E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C,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC;QAEjG,IAAI,CAAC,OAAO;YAAE,MAAM,QAAQ,CAAC,mBAAmB,CAAC,CAAC;QAClD,OAAO,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;IAEH,GAAG,CAAC,GAAG,CAAC,gDAAgD,EAAE,CAAC,CAAC,EAAE,EAAE;QAC9D,MAAM,IAAI,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI;YAAE,MAAM,QAAQ,CAAC,MAAM,CAAC,CAAC;QAElC,MAAM,KAAK,GAAG,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QAC5D,OAAO,CAAC,CAAC,IAAI,CAAC;YACZ,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,oBAAoB,CAAC;YACrC,aAAa,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;SAC7C,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { type RouteContext, notFound } from '../../core/index.js';\nimport { getWorkOSStore } from '../store.js';\nimport { formatAuthorizedApplication, formatConnectedAccount, formatPipeConnection } from '../helpers.js';\n\nexport function userFeatureRoutes(ctx: RouteContext): void {\n const { app, store } = ctx;\n const ws = getWorkOSStore(store);\n\n app.get('/user_management/users/:user_id/authorized_applications', (c) => {\n const user = ws.users.get(c.req.param('user_id'));\n if (!user) throw notFound('User');\n\n const apps = ws.authorizedApplications.findBy('user_id', user.id);\n return c.json({\n object: 'list',\n data: apps.map(formatAuthorizedApplication),\n list_metadata: { before: null, after: null },\n });\n });\n\n app.delete('/user_management/users/:user_id/authorized_applications/:application_id', (c) => {\n const user = ws.users.get(c.req.param('user_id'));\n if (!user) throw notFound('User');\n\n const appItem = ws.authorizedApplications.get(c.req.param('application_id'));\n if (!appItem || appItem.user_id !== user.id) throw notFound('Authorized Application');\n\n ws.authorizedApplications.delete(appItem.id);\n return c.body(null, 204);\n });\n\n app.get('/user_management/users/:user_id/connected_accounts/:slug', (c) => {\n const user = ws.users.get(c.req.param('user_id'));\n if (!user) throw notFound('User');\n\n const slug = c.req.param('slug');\n const account = ws.connectedAccounts.findBy('user_id', user.id).find((a) => a.provider === slug);\n\n if (!account) throw notFound('Connected Account');\n return c.json(formatConnectedAccount(account));\n });\n\n app.get('/user_management/users/:user_id/data_providers', (c) => {\n const user = ws.users.get(c.req.param('user_id'));\n if (!user) throw notFound('User');\n\n const pipes = ws.pipeConnections.findBy('user_id', user.id);\n return c.json({\n object: 'list',\n data: pipes.map(formatPipeConnection),\n list_metadata: { before: null, after: null },\n });\n });\n}\n"]}
@@ -1,2 +0,0 @@
1
- import { type RouteContext } from '../../core/index.js';
2
- export declare function userRoutes(ctx: RouteContext): void;
@@ -1,129 +0,0 @@
1
- import { notFound, validationError, parseJsonBody, WorkOSApiError, parseListParams, } from '../../core/index.js';
2
- import { getWorkOSStore } from '../store.js';
3
- import { formatUser, formatIdentity, hashPassword, formatListResponse } from '../helpers.js';
4
- export function userRoutes(ctx) {
5
- const { app, store } = ctx;
6
- const ws = getWorkOSStore(store);
7
- app.post('/user_management/users', async (c) => {
8
- const body = await parseJsonBody(c);
9
- const email = body.email;
10
- if (!email) {
11
- throw validationError('email is required', [{ field: 'email', code: 'required' }]);
12
- }
13
- const existing = ws.users.findOneBy('email', email);
14
- if (existing) {
15
- throw new WorkOSApiError(409, 'A user with this email already exists', 'user_already_exists');
16
- }
17
- const password = body.password;
18
- const user = ws.users.insert({
19
- object: 'user',
20
- email,
21
- first_name: body.first_name ?? null,
22
- last_name: body.last_name ?? null,
23
- email_verified: body.email_verified ?? false,
24
- profile_picture_url: null,
25
- last_sign_in_at: null,
26
- external_id: body.external_id ?? null,
27
- metadata: body.metadata ?? {},
28
- locale: null,
29
- password_hash: password ? hashPassword(password) : null,
30
- impersonator: null,
31
- });
32
- return c.json(formatUser(user), 201);
33
- });
34
- app.get('/user_management/users', (c) => {
35
- const url = new URL(c.req.url);
36
- const params = parseListParams(url);
37
- const emailFilter = url.searchParams.get('email') ?? undefined;
38
- const orgFilter = url.searchParams.get('organization_id') ?? undefined;
39
- let orgUserIds;
40
- if (orgFilter) {
41
- orgUserIds = new Set(ws.organizationMemberships.findBy('organization_id', orgFilter).map((m) => m.user_id));
42
- }
43
- const result = ws.users.list({
44
- ...params,
45
- filter: (user) => {
46
- if (emailFilter && user.email !== emailFilter)
47
- return false;
48
- if (orgUserIds && !orgUserIds.has(user.id))
49
- return false;
50
- return true;
51
- },
52
- });
53
- return c.json(formatListResponse(result, formatUser));
54
- });
55
- app.get('/user_management/users/:id', (c) => {
56
- const user = ws.users.get(c.req.param('id'));
57
- if (!user)
58
- throw notFound('User');
59
- return c.json(formatUser(user));
60
- });
61
- app.get('/user_management/users/external_id/:external_id', (c) => {
62
- const user = ws.users.findOneBy('external_id', c.req.param('external_id'));
63
- if (!user)
64
- throw notFound('User');
65
- return c.json(formatUser(user));
66
- });
67
- app.put('/user_management/users/:id', async (c) => {
68
- const user = ws.users.get(c.req.param('id'));
69
- if (!user)
70
- throw notFound('User');
71
- const body = await parseJsonBody(c);
72
- const updates = {};
73
- if ('first_name' in body)
74
- updates.first_name = body.first_name ?? null;
75
- if ('last_name' in body)
76
- updates.last_name = body.last_name ?? null;
77
- if ('email_verified' in body)
78
- updates.email_verified = body.email_verified;
79
- if ('external_id' in body)
80
- updates.external_id = body.external_id ?? null;
81
- if ('metadata' in body)
82
- updates.metadata = body.metadata ?? {};
83
- if ('password' in body && body.password) {
84
- updates.password_hash = hashPassword(body.password);
85
- }
86
- const updated = ws.users.update(user.id, updates);
87
- return c.json(formatUser(updated));
88
- });
89
- app.delete('/user_management/users/:id', (c) => {
90
- const user = ws.users.get(c.req.param('id'));
91
- if (!user)
92
- throw notFound('User');
93
- for (const s of ws.sessions.findBy('user_id', user.id)) {
94
- ws.sessions.delete(s.id);
95
- }
96
- for (const m of ws.organizationMemberships.findBy('user_id', user.id)) {
97
- ws.organizationMemberships.delete(m.id);
98
- }
99
- for (const f of ws.authFactors.findBy('user_id', user.id)) {
100
- ws.authFactors.delete(f.id);
101
- }
102
- for (const i of ws.identities.findBy('user_id', user.id)) {
103
- ws.identities.delete(i.id);
104
- }
105
- for (const pr of ws.passwordResets.findBy('user_id', user.id)) {
106
- ws.passwordResets.delete(pr.id);
107
- }
108
- for (const ev of ws.emailVerifications.findBy('user_id', user.id)) {
109
- ws.emailVerifications.delete(ev.id);
110
- }
111
- for (const ma of ws.magicAuths.findBy('user_id', user.id)) {
112
- ws.magicAuths.delete(ma.id);
113
- }
114
- ws.users.delete(user.id);
115
- return c.body(null, 204);
116
- });
117
- app.get('/user_management/users/:id/identities', (c) => {
118
- const user = ws.users.get(c.req.param('id'));
119
- if (!user)
120
- throw notFound('User');
121
- const identities = ws.identities.findBy('user_id', user.id);
122
- return c.json({
123
- object: 'list',
124
- data: identities.map(formatIdentity),
125
- list_metadata: { before: null, after: null },
126
- });
127
- });
128
- }
129
- //# sourceMappingURL=users.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"users.js","sourceRoot":"","sources":["../../../../src/emulate/workos/routes/users.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,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAE7F,MAAM,UAAU,UAAU,CAAC,GAAiB;IAC1C,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,CAA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C3B,CAAC,CAAC,CAAC;IAEH,GAAG,CAAC,GAAG,CAAC,uCAAuC,EAAE,CAAC,CAAC,EAAE,EAAE;QACrD,MAAM,IAAI,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7C,IAAI,CAAC,IAAI;YAAE,MAAM,QAAQ,CAAC,MAAM,CAAC,CAAC;QAElC,MAAM,UAAU,GAAG,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QAC5D,OAAO,CAAC,CAAC,IAAI,CAAC;YACZ,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,cAAc,CAAC;YACpC,aAAa,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;SAC7C,CAAC,CAAC;IACL,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 { formatUser, formatIdentity, hashPassword, formatListResponse } from '../helpers.js';\n\nexport function userRoutes(ctx: RouteContext): void {\n const { app, store } = ctx;\n const ws = getWorkOSStore(store);\n\n app.post('/user_management/users', async (c) => {\n const body = await parseJsonBody(c);\n const email = body.email as string | undefined;\n if (!email) {\n throw validationError('email is required', [{ field: 'email', code: 'required' }]);\n }\n\n const existing = ws.users.findOneBy('email', email);\n if (existing) {\n throw new WorkOSApiError(409, 'A user with this email already exists', 'user_already_exists');\n }\n\n const password = body.password as string | undefined;\n const user = ws.users.insert({\n object: 'user',\n email,\n first_name: (body.first_name as string) ?? null,\n last_name: (body.last_name as string) ?? null,\n email_verified: (body.email_verified as boolean) ?? false,\n profile_picture_url: null,\n last_sign_in_at: null,\n external_id: (body.external_id as string) ?? null,\n metadata: (body.metadata as Record<string, string>) ?? {},\n locale: null,\n password_hash: password ? hashPassword(password) : null,\n impersonator: null,\n });\n\n return c.json(formatUser(user), 201);\n });\n\n app.get('/user_management/users', (c) => {\n const url = new URL(c.req.url);\n const params = parseListParams(url);\n const emailFilter = url.searchParams.get('email') ?? undefined;\n const orgFilter = url.searchParams.get('organization_id') ?? undefined;\n\n let orgUserIds: Set<string> | undefined;\n if (orgFilter) {\n orgUserIds = new Set(ws.organizationMemberships.findBy('organization_id', orgFilter).map((m) => m.user_id));\n }\n\n const result = ws.users.list({\n ...params,\n filter: (user) => {\n if (emailFilter && user.email !== emailFilter) return false;\n if (orgUserIds && !orgUserIds.has(user.id)) return false;\n return true;\n },\n });\n\n return c.json(formatListResponse(result, formatUser));\n });\n\n app.get('/user_management/users/:id', (c) => {\n const user = ws.users.get(c.req.param('id'));\n if (!user) throw notFound('User');\n return c.json(formatUser(user));\n });\n\n app.get('/user_management/users/external_id/:external_id', (c) => {\n const user = ws.users.findOneBy('external_id', c.req.param('external_id'));\n if (!user) throw notFound('User');\n return c.json(formatUser(user));\n });\n\n app.put('/user_management/users/:id', async (c) => {\n const user = ws.users.get(c.req.param('id'));\n if (!user) throw notFound('User');\n\n const body = await parseJsonBody(c);\n const updates: Record<string, unknown> = {};\n\n if ('first_name' in body) updates.first_name = body.first_name ?? null;\n if ('last_name' in body) updates.last_name = body.last_name ?? null;\n if ('email_verified' in body) updates.email_verified = body.email_verified;\n if ('external_id' in body) updates.external_id = body.external_id ?? null;\n if ('metadata' in body) updates.metadata = body.metadata ?? {};\n if ('password' in body && body.password) {\n updates.password_hash = hashPassword(body.password as string);\n }\n\n const updated = ws.users.update(user.id, updates);\n return c.json(formatUser(updated!));\n });\n\n app.delete('/user_management/users/:id', (c) => {\n const user = ws.users.get(c.req.param('id'));\n if (!user) throw notFound('User');\n\n for (const s of ws.sessions.findBy('user_id', user.id)) {\n ws.sessions.delete(s.id);\n }\n for (const m of ws.organizationMemberships.findBy('user_id', user.id)) {\n ws.organizationMemberships.delete(m.id);\n }\n for (const f of ws.authFactors.findBy('user_id', user.id)) {\n ws.authFactors.delete(f.id);\n }\n for (const i of ws.identities.findBy('user_id', user.id)) {\n ws.identities.delete(i.id);\n }\n for (const pr of ws.passwordResets.findBy('user_id', user.id)) {\n ws.passwordResets.delete(pr.id);\n }\n for (const ev of ws.emailVerifications.findBy('user_id', user.id)) {\n ws.emailVerifications.delete(ev.id);\n }\n for (const ma of ws.magicAuths.findBy('user_id', user.id)) {\n ws.magicAuths.delete(ma.id);\n }\n\n ws.users.delete(user.id);\n return c.body(null, 204);\n });\n\n app.get('/user_management/users/:id/identities', (c) => {\n const user = ws.users.get(c.req.param('id'));\n if (!user) throw notFound('User');\n\n const identities = ws.identities.findBy('user_id', user.id);\n return c.json({\n object: 'list',\n data: identities.map(formatIdentity),\n list_metadata: { before: null, after: null },\n });\n });\n}\n"]}
@@ -1,2 +0,0 @@
1
- import { type RouteContext } from '../../core/index.js';
2
- export declare function webhookEndpointRoutes(ctx: RouteContext): void;
@@ -1,67 +0,0 @@
1
- import { randomBytes } from 'node:crypto';
2
- import { notFound, validationError, parseJsonBody, parseListParams } from '../../core/index.js';
3
- import { getWorkOSStore } from '../store.js';
4
- import { formatWebhookEndpoint, formatListResponse } from '../helpers.js';
5
- export function webhookEndpointRoutes(ctx) {
6
- const { app, store } = ctx;
7
- const ws = getWorkOSStore(store);
8
- app.post('/webhook_endpoints', async (c) => {
9
- const body = await parseJsonBody(c);
10
- const endpointUrl = (body.endpoint_url ?? body.url);
11
- if (!endpointUrl || typeof endpointUrl !== 'string') {
12
- throw validationError('endpoint_url is required', [{ field: 'endpoint_url', code: 'required' }]);
13
- }
14
- const secret = body.secret ?? randomBytes(32).toString('hex');
15
- const endpoint = ws.webhookEndpoints.insert({
16
- object: 'webhook_endpoint',
17
- endpoint_url: endpointUrl,
18
- secret,
19
- enabled: body.enabled !== false,
20
- events: Array.isArray(body.events) ? body.events : [],
21
- description: body.description ?? null,
22
- });
23
- return c.json(formatWebhookEndpoint(endpoint, { includeSecret: true }), 201);
24
- });
25
- app.get('/webhook_endpoints', (c) => {
26
- const url = new URL(c.req.url);
27
- const params = parseListParams(url);
28
- const result = ws.webhookEndpoints.list(params);
29
- return c.json(formatListResponse(result, (ep) => formatWebhookEndpoint(ep)));
30
- });
31
- app.get('/webhook_endpoints/:id', (c) => {
32
- const ep = ws.webhookEndpoints.get(c.req.param('id'));
33
- if (!ep)
34
- throw notFound('WebhookEndpoint');
35
- return c.json(formatWebhookEndpoint(ep));
36
- });
37
- app.put('/webhook_endpoints/:id', async (c) => {
38
- const ep = ws.webhookEndpoints.get(c.req.param('id'));
39
- if (!ep)
40
- throw notFound('WebhookEndpoint');
41
- const body = await parseJsonBody(c);
42
- const updates = {};
43
- if ('endpoint_url' in body || 'url' in body) {
44
- const newUrl = (body.endpoint_url ?? body.url);
45
- if (!newUrl || typeof newUrl !== 'string') {
46
- throw validationError('endpoint_url is required', [{ field: 'endpoint_url', code: 'required' }]);
47
- }
48
- updates.endpoint_url = newUrl;
49
- }
50
- if ('enabled' in body)
51
- updates.enabled = !!body.enabled;
52
- if ('events' in body)
53
- updates.events = Array.isArray(body.events) ? body.events : [];
54
- if ('description' in body)
55
- updates.description = body.description ?? null;
56
- const updated = ws.webhookEndpoints.update(ep.id, updates);
57
- return c.json(formatWebhookEndpoint(updated));
58
- });
59
- app.delete('/webhook_endpoints/:id', (c) => {
60
- const ep = ws.webhookEndpoints.get(c.req.param('id'));
61
- if (!ep)
62
- throw notFound('WebhookEndpoint');
63
- ws.webhookEndpoints.delete(ep.id);
64
- return c.body(null, 204);
65
- });
66
- }
67
- //# sourceMappingURL=webhook-endpoints.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"webhook-endpoints.js","sourceRoot":"","sources":["../../../../src/emulate/workos/routes/webhook-endpoints.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAqB,QAAQ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AAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QACtD,IAAI,CAAC,EAAE;YAAE,MAAM,QAAQ,CAAC,iBAAiB,CAAC,CAAC;QAC3C,EAAE,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QAClC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { randomBytes } from 'node:crypto';\nimport { type RouteContext, notFound, validationError, parseJsonBody, parseListParams } from '../../core/index.js';\nimport { getWorkOSStore } from '../store.js';\nimport { formatWebhookEndpoint, formatListResponse } from '../helpers.js';\n\nexport function webhookEndpointRoutes(ctx: RouteContext): void {\n const { app, store } = ctx;\n const ws = getWorkOSStore(store);\n\n app.post('/webhook_endpoints', async (c) => {\n const body = await parseJsonBody(c);\n const endpointUrl = (body.endpoint_url ?? body.url) as string | undefined;\n if (!endpointUrl || typeof endpointUrl !== 'string') {\n throw validationError('endpoint_url is required', [{ field: 'endpoint_url', code: 'required' }]);\n }\n\n const secret = (body.secret as string) ?? randomBytes(32).toString('hex');\n\n const endpoint = ws.webhookEndpoints.insert({\n object: 'webhook_endpoint',\n endpoint_url: endpointUrl,\n secret,\n enabled: body.enabled !== false,\n events: Array.isArray(body.events) ? (body.events as string[]) : [],\n description: (body.description as string) ?? null,\n });\n\n return c.json(formatWebhookEndpoint(endpoint, { includeSecret: true }), 201);\n });\n\n app.get('/webhook_endpoints', (c) => {\n const url = new URL(c.req.url);\n const params = parseListParams(url);\n\n const result = ws.webhookEndpoints.list(params);\n return c.json(formatListResponse(result, (ep) => formatWebhookEndpoint(ep)));\n });\n\n app.get('/webhook_endpoints/:id', (c) => {\n const ep = ws.webhookEndpoints.get(c.req.param('id'));\n if (!ep) throw notFound('WebhookEndpoint');\n return c.json(formatWebhookEndpoint(ep));\n });\n\n app.put('/webhook_endpoints/:id', async (c) => {\n const ep = ws.webhookEndpoints.get(c.req.param('id'));\n if (!ep) throw notFound('WebhookEndpoint');\n\n const body = await parseJsonBody(c);\n const updates: Record<string, unknown> = {};\n\n if ('endpoint_url' in body || 'url' in body) {\n const newUrl = (body.endpoint_url ?? body.url) as string | undefined;\n if (!newUrl || typeof newUrl !== 'string') {\n throw validationError('endpoint_url is required', [{ field: 'endpoint_url', code: 'required' }]);\n }\n updates.endpoint_url = newUrl;\n }\n if ('enabled' in body) updates.enabled = !!body.enabled;\n if ('events' in body) updates.events = Array.isArray(body.events) ? body.events : [];\n if ('description' in body) updates.description = body.description ?? null;\n\n const updated = ws.webhookEndpoints.update(ep.id, updates);\n return c.json(formatWebhookEndpoint(updated!));\n });\n\n app.delete('/webhook_endpoints/:id', (c) => {\n const ep = ws.webhookEndpoints.get(c.req.param('id'));\n if (!ep) throw notFound('WebhookEndpoint');\n ws.webhookEndpoints.delete(ep.id);\n return c.body(null, 204);\n });\n}\n"]}
@@ -1,2 +0,0 @@
1
- import { type RouteContext } from '../../core/index.js';
2
- export declare function widgetRoutes(ctx: RouteContext): void;