@processfocus/runtime-local 0.1.0-next.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 (470) hide show
  1. package/LICENSE.md +28 -0
  2. package/README.md +290 -0
  3. package/dist/authentication-server.mjs +188 -0
  4. package/dist/chunk-2sb4v2sx.js +70 -0
  5. package/dist/chunk-9weqs8n8.js +56031 -0
  6. package/dist/chunk-mvkr77wp.js +54113 -0
  7. package/dist/chunk-tkn4cnc8.js +453 -0
  8. package/dist/chunk-vpsm84e8.js +85 -0
  9. package/dist/dashboard-source/apps/frontend/app/%5Fpf/app-icons/[...path]/route.ts +63 -0
  10. package/dist/dashboard-source/apps/frontend/app/%5Fpf/health/page.tsx +19 -0
  11. package/dist/dashboard-source/apps/frontend/app/%5Fpf/public-form-branding/[...path]/route.ts +95 -0
  12. package/dist/dashboard-source/apps/frontend/app/(protected)/act-on-behalf/actions.ts +248 -0
  13. package/dist/dashboard-source/apps/frontend/app/(protected)/act-on-behalf/delegations-client.tsx +751 -0
  14. package/dist/dashboard-source/apps/frontend/app/(protected)/act-on-behalf/page.tsx +46 -0
  15. package/dist/dashboard-source/apps/frontend/app/(protected)/client-index.tsx +375 -0
  16. package/dist/dashboard-source/apps/frontend/app/(protected)/client.tsx +14 -0
  17. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/(.)[executionId]/client.tsx +73 -0
  18. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/(.)[executionId]/page.tsx +20 -0
  19. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/(.)[executionId]/process-state/page.tsx +22 -0
  20. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/default.tsx +3 -0
  21. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/[executionId]/page.tsx +11 -0
  22. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/[executionId]/process-state/page.tsx +23 -0
  23. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/abandon-execution-dialog.tsx +137 -0
  24. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/execution-card-menu.tsx +233 -0
  25. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/layout.tsx +19 -0
  26. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/page.tsx +1549 -0
  27. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/process-state-dialog.tsx +91 -0
  28. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/process-state-modal-client.tsx +33 -0
  29. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/process-state-page-client.tsx +31 -0
  30. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/process-state-route-fallback.tsx +18 -0
  31. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/restart-execution-feedback.tsx +40 -0
  32. package/dist/dashboard-source/apps/frontend/app/(protected)/layout.tsx +129 -0
  33. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/@modal/(.)item/[id]/client.tsx +215 -0
  34. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/@modal/(.)item/[id]/page.tsx +23 -0
  35. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/@modal/default.tsx +3 -0
  36. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/[...listPath]/list-page-client.tsx +678 -0
  37. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/[...listPath]/loading.tsx +10 -0
  38. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/[...listPath]/page.tsx +228 -0
  39. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-create-form.tsx +147 -0
  40. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-item-edit-form.tsx +246 -0
  41. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/hooks/metric-control-url-state.ts +71 -0
  42. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/hooks/use-list-deleted-callback.ts +22 -0
  43. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/hooks/use-list-item-detail.ts +315 -0
  44. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/item/[id]/client.tsx +259 -0
  45. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/item/[id]/page.tsx +46 -0
  46. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/layout.tsx +14 -0
  47. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/lib/list-detail-title.ts +20 -0
  48. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/lib/list-refresh.ts +26 -0
  49. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/utils.ts +20 -0
  50. package/dist/dashboard-source/apps/frontend/app/(protected)/loading.tsx +5 -0
  51. package/dist/dashboard-source/apps/frontend/app/(protected)/org-chart/org-chart-client.tsx +74 -0
  52. package/dist/dashboard-source/apps/frontend/app/(protected)/org-chart/page.tsx +120 -0
  53. package/dist/dashboard-source/apps/frontend/app/(protected)/page.tsx +13 -0
  54. package/dist/dashboard-source/apps/frontend/app/(protected)/passkeys/actions.ts +188 -0
  55. package/dist/dashboard-source/apps/frontend/app/(protected)/passkeys/page.tsx +33 -0
  56. package/dist/dashboard-source/apps/frontend/app/(protected)/passkeys/passkeys-client.tsx +320 -0
  57. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/@modal/(.)start/[...startStepPath]/client.tsx +152 -0
  58. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/@modal/(.)start/[...startStepPath]/page.tsx +41 -0
  59. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/@modal/default.tsx +3 -0
  60. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/client.tsx +33 -0
  61. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/components/process-form-actions.tsx +105 -0
  62. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/components/process-submit-button.tsx +81 -0
  63. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/components/start-process-form.tsx +282 -0
  64. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/layout.tsx +21 -0
  65. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/lib/mobile-process-catalog.ts +28 -0
  66. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/lib/start-process-actions.ts +13 -0
  67. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/loading.tsx +10 -0
  68. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/page.tsx +5 -0
  69. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/processes-client.tsx +504 -0
  70. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/start/[...startStepPath]/client.tsx +153 -0
  71. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/start/[...startStepPath]/page.tsx +39 -0
  72. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/loading.tsx +20 -0
  73. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/page.tsx +131 -0
  74. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/process-documentation.tsx +209 -0
  75. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/use-workflow-auto-refresh.ts +120 -0
  76. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/workflow-flow.tsx +319 -0
  77. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/workflow-form-preview-sheet.tsx +98 -0
  78. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/[[...tab]]/loading.tsx +1 -0
  79. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/[[...tab]]/page.tsx +100 -0
  80. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/access-handbook.tsx +110 -0
  81. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/authorization-loading.tsx +25 -0
  82. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/authorization-tabs.tsx +47 -0
  83. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/cedar-authorize.ts +261 -0
  84. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/cedar-helpers.ts +17 -0
  85. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/cedar-source.tsx +34 -0
  86. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/cedar-types.ts +79 -0
  87. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/evaluate-cedar.ts +43 -0
  88. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/explorer.tsx +526 -0
  89. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/layout.tsx +23 -0
  90. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/load-cedar.ts +174 -0
  91. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/load-handbook.ts +390 -0
  92. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/org-data.ts +70 -0
  93. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/[invitationId]/page.tsx +22 -0
  94. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/invitation-detail-client.tsx +594 -0
  95. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/invitation-detail-skeleton.tsx +48 -0
  96. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/new/page.tsx +5 -0
  97. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations-table.tsx +186 -0
  98. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/page.tsx +69 -0
  99. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/providers-table.tsx +48 -0
  100. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/roles-table.tsx +62 -0
  101. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/settings-client.tsx +244 -0
  102. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/[userId]/client.tsx +329 -0
  103. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/[userId]/page.tsx +21 -0
  104. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/[userId]/tokens/page.tsx +39 -0
  105. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users-table.tsx +82 -0
  106. package/dist/dashboard-source/apps/frontend/app/(protected)/stats/[...statsPath]/error.tsx +34 -0
  107. package/dist/dashboard-source/apps/frontend/app/(protected)/stats/[...statsPath]/not-found.tsx +13 -0
  108. package/dist/dashboard-source/apps/frontend/app/(protected)/stats/[...statsPath]/page.tsx +84 -0
  109. package/dist/dashboard-source/apps/frontend/app/(protected)/stats/[...statsPath]/stats-data-fetcher.tsx +93 -0
  110. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/@modal/(.)complete/[...stepPath]/client.tsx +143 -0
  111. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/@modal/(.)complete/[...stepPath]/page.tsx +50 -0
  112. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/@modal/default.tsx +3 -0
  113. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/complete/[...stepPath]/client.tsx +131 -0
  114. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/complete/[...stepPath]/page.tsx +50 -0
  115. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/components/complete-todo-form.tsx +172 -0
  116. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/components/public-completion-correction-form.tsx +233 -0
  117. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/components/todo-form-actions.tsx +26 -0
  118. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/correct/[...stepPath]/page.tsx +58 -0
  119. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/layout.tsx +14 -0
  120. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/lib/mobile-todo-list.ts +154 -0
  121. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/page.tsx +1317 -0
  122. package/dist/dashboard-source/apps/frontend/app/api/auth/callback/route.ts +259 -0
  123. package/dist/dashboard-source/apps/frontend/app/api/auth/delegation/route.ts +127 -0
  124. package/dist/dashboard-source/apps/frontend/app/api/auth/login/route.ts +49 -0
  125. package/dist/dashboard-source/apps/frontend/app/api/auth/logout/route.ts +33 -0
  126. package/dist/dashboard-source/apps/frontend/app/api/auth/passkey/auth-options/route.ts +79 -0
  127. package/dist/dashboard-source/apps/frontend/app/api/auth/passkey/auth-verify/route.ts +142 -0
  128. package/dist/dashboard-source/apps/frontend/app/api/auth/passkey/register/route.ts +103 -0
  129. package/dist/dashboard-source/apps/frontend/app/api/auth/passkey/register-verify/route.ts +136 -0
  130. package/dist/dashboard-source/apps/frontend/app/api/auth/passkey/registration-session/route.ts +129 -0
  131. package/dist/dashboard-source/apps/frontend/app/api/auth/passkey/start/route.ts +153 -0
  132. package/dist/dashboard-source/apps/frontend/app/api/auth/refresh/route.ts +122 -0
  133. package/dist/dashboard-source/apps/frontend/app/api/auth/switch-role/route.ts +177 -0
  134. package/dist/dashboard-source/apps/frontend/app/api/dev/import-completed/route.ts +22 -0
  135. package/dist/dashboard-source/apps/frontend/app/api/dev/import-events/route.ts +38 -0
  136. package/dist/dashboard-source/apps/frontend/app/api/embed/lookup/route.ts +266 -0
  137. package/dist/dashboard-source/apps/frontend/app/api/embed/submit/route.ts +118 -0
  138. package/dist/dashboard-source/apps/frontend/app/api/embed/test-host/route.ts +125 -0
  139. package/dist/dashboard-source/apps/frontend/app/api/public/to-dos/calendar-slots/route.ts +44 -0
  140. package/dist/dashboard-source/apps/frontend/app/api/public/to-dos/complete/route.ts +56 -0
  141. package/dist/dashboard-source/apps/frontend/app/api/public/to-dos/lookup/route.ts +61 -0
  142. package/dist/dashboard-source/apps/frontend/app/api/public/to-dos/request-fresh-link/route.ts +41 -0
  143. package/dist/dashboard-source/apps/frontend/app/api/revalidate/route.ts +61 -0
  144. package/dist/dashboard-source/apps/frontend/app/app-shell.tsx +100 -0
  145. package/dist/dashboard-source/apps/frontend/app/cli-auth/route.ts +261 -0
  146. package/dist/dashboard-source/apps/frontend/app/embed/[...startStepPath]/embed-client.tsx +393 -0
  147. package/dist/dashboard-source/apps/frontend/app/embed/[...startStepPath]/loading.tsx +13 -0
  148. package/dist/dashboard-source/apps/frontend/app/embed/[...startStepPath]/page.tsx +51 -0
  149. package/dist/dashboard-source/apps/frontend/app/embed/embedded.css +48 -0
  150. package/dist/dashboard-source/apps/frontend/app/embed/layout.tsx +15 -0
  151. package/dist/dashboard-source/apps/frontend/app/global.css +13 -0
  152. package/dist/dashboard-source/apps/frontend/app/layout.tsx +102 -0
  153. package/dist/dashboard-source/apps/frontend/app/login/layout.tsx +9 -0
  154. package/dist/dashboard-source/apps/frontend/app/login/login-button.tsx +35 -0
  155. package/dist/dashboard-source/apps/frontend/app/login/login-form-content.tsx +117 -0
  156. package/dist/dashboard-source/apps/frontend/app/login/login-form.tsx +30 -0
  157. package/dist/dashboard-source/apps/frontend/app/login/page.tsx +52 -0
  158. package/dist/dashboard-source/apps/frontend/app/login/passkey-button.tsx +226 -0
  159. package/dist/dashboard-source/apps/frontend/app/login/secret-login-form.tsx +91 -0
  160. package/dist/dashboard-source/apps/frontend/app/manifest.ts +7 -0
  161. package/dist/dashboard-source/apps/frontend/app/public/form/[token]/error.tsx +63 -0
  162. package/dist/dashboard-source/apps/frontend/app/public/form/[token]/layout.tsx +34 -0
  163. package/dist/dashboard-source/apps/frontend/app/public/form/[token]/page.tsx +129 -0
  164. package/dist/dashboard-source/apps/frontend/app/public/form/[token]/public-form-branding-card.tsx +42 -0
  165. package/dist/dashboard-source/apps/frontend/app/public/form/[token]/public-form-branding-context.tsx +27 -0
  166. package/dist/dashboard-source/apps/frontend/app/public/form/[token]/public-form-branding-html.tsx +40 -0
  167. package/dist/dashboard-source/apps/frontend/app/public/form/[token]/public-todo-client.tsx +553 -0
  168. package/dist/dashboard-source/apps/frontend/app/public/form/[token]/public-todo-state-content.tsx +27 -0
  169. package/dist/dashboard-source/apps/frontend/app/public.css +33 -0
  170. package/dist/dashboard-source/apps/frontend/app/register/passkey/layout.tsx +49 -0
  171. package/dist/dashboard-source/apps/frontend/app/register/passkey/page.tsx +36 -0
  172. package/dist/dashboard-source/apps/frontend/app/register/passkey/register-passkey-client.tsx +292 -0
  173. package/dist/dashboard-source/apps/frontend/app/theme.css +117 -0
  174. package/dist/dashboard-source/apps/frontend/components/DashboardSection.tsx +693 -0
  175. package/dist/dashboard-source/apps/frontend/components/Header.tsx +481 -0
  176. package/dist/dashboard-source/apps/frontend/components/OrgUnitNode.tsx +41 -0
  177. package/dist/dashboard-source/apps/frontend/components/app-sidebar.tsx +245 -0
  178. package/dist/dashboard-source/apps/frontend/components/auth-provider.tsx +158 -0
  179. package/dist/dashboard-source/apps/frontend/components/collections/collection-table-card.tsx +218 -0
  180. package/dist/dashboard-source/apps/frontend/components/collections/collection-table-header-row.tsx +97 -0
  181. package/dist/dashboard-source/apps/frontend/components/config-provider.tsx +27 -0
  182. package/dist/dashboard-source/apps/frontend/components/copy-button.tsx +40 -0
  183. package/dist/dashboard-source/apps/frontend/components/dashboard-activity.tsx +35 -0
  184. package/dist/dashboard-source/apps/frontend/components/dashboard-skeleton.tsx +17 -0
  185. package/dist/dashboard-source/apps/frontend/components/delegation-expiry.tsx +21 -0
  186. package/dist/dashboard-source/apps/frontend/components/feature-permissions-provider.tsx +28 -0
  187. package/dist/dashboard-source/apps/frontend/components/form-dialog-content.tsx +66 -0
  188. package/dist/dashboard-source/apps/frontend/components/frontend-client-plugin-host.tsx +27 -0
  189. package/dist/dashboard-source/apps/frontend/components/frontend-client-plugin-identify.tsx +33 -0
  190. package/dist/dashboard-source/apps/frontend/components/frontend-client-plugin-provider.tsx +55 -0
  191. package/dist/dashboard-source/apps/frontend/components/journey-timeline.tsx +378 -0
  192. package/dist/dashboard-source/apps/frontend/components/mobile-home-switchboard.tsx +98 -0
  193. package/dist/dashboard-source/apps/frontend/components/mocks-provider.tsx +27 -0
  194. package/dist/dashboard-source/apps/frontend/components/notification-bell.tsx +137 -0
  195. package/dist/dashboard-source/apps/frontend/components/org-settings-provider.tsx +26 -0
  196. package/dist/dashboard-source/apps/frontend/components/process-workflow-link.tsx +36 -0
  197. package/dist/dashboard-source/apps/frontend/components/session-reissue.tsx +48 -0
  198. package/dist/dashboard-source/apps/frontend/components/sidebar-lists.tsx +89 -0
  199. package/dist/dashboard-source/apps/frontend/components/sidebar-stats-views.tsx +65 -0
  200. package/dist/dashboard-source/apps/frontend/components/theme-provider.tsx +132 -0
  201. package/dist/dashboard-source/apps/frontend/components/todo-count-badge.tsx +59 -0
  202. package/dist/dashboard-source/apps/frontend/components/token-refresh-scheduler.tsx +304 -0
  203. package/dist/dashboard-source/apps/frontend/components/ui/checkbox.tsx +31 -0
  204. package/dist/dashboard-source/apps/frontend/components/ui/dialog.tsx +142 -0
  205. package/dist/dashboard-source/apps/frontend/components/ui/dropdown-menu.tsx +256 -0
  206. package/dist/dashboard-source/apps/frontend/components/ui/input.tsx +20 -0
  207. package/dist/dashboard-source/apps/frontend/components/ui/pagination.tsx +59 -0
  208. package/dist/dashboard-source/apps/frontend/components/ui/sheet.tsx +138 -0
  209. package/dist/dashboard-source/apps/frontend/components/ui/sidebar.tsx +741 -0
  210. package/dist/dashboard-source/apps/frontend/components/ui/skeleton.tsx +13 -0
  211. package/dist/dashboard-source/apps/frontend/components/ui/tab-pill.tsx +30 -0
  212. package/dist/dashboard-source/apps/frontend/components/ui/table.tsx +115 -0
  213. package/dist/dashboard-source/apps/frontend/components/ui/tooltip.tsx +60 -0
  214. package/dist/dashboard-source/apps/frontend/components/without-waiting-badge.tsx +24 -0
  215. package/dist/dashboard-source/apps/frontend/components/workflow/step-node.tsx +116 -0
  216. package/dist/dashboard-source/apps/frontend/components/workflow/swimlane-node.tsx +46 -0
  217. package/dist/dashboard-source/apps/frontend/components/workflow/workflow-edge.tsx +172 -0
  218. package/dist/dashboard-source/apps/frontend/hooks/use-draft-process-save.ts +189 -0
  219. package/dist/dashboard-source/apps/frontend/hooks/use-draft-state.ts +79 -0
  220. package/dist/dashboard-source/apps/frontend/hooks/use-form-metadata.ts +74 -0
  221. package/dist/dashboard-source/apps/frontend/hooks/use-mobile.ts +27 -0
  222. package/dist/dashboard-source/apps/frontend/hooks/use-notification-preference.ts +246 -0
  223. package/dist/dashboard-source/apps/frontend/hooks/use-processes-query.ts +56 -0
  224. package/dist/dashboard-source/apps/frontend/hooks/use-weekly-execution-stats.ts +101 -0
  225. package/dist/dashboard-source/apps/frontend/index.d.ts +12 -0
  226. package/dist/dashboard-source/apps/frontend/instrumentation.node.ts +25 -0
  227. package/dist/dashboard-source/apps/frontend/instrumentation.ts +19 -0
  228. package/dist/dashboard-source/apps/frontend/lib/app-icons-metadata.ts +66 -0
  229. package/dist/dashboard-source/apps/frontend/lib/appsync-events/adapter.ts +128 -0
  230. package/dist/dashboard-source/apps/frontend/lib/appsync-events/client.ts +355 -0
  231. package/dist/dashboard-source/apps/frontend/lib/appsync-events/config.ts +18 -0
  232. package/dist/dashboard-source/apps/frontend/lib/appsync-events/reconnect-registry.ts +34 -0
  233. package/dist/dashboard-source/apps/frontend/lib/auth/act-on-behalf-menu.ts +9 -0
  234. package/dist/dashboard-source/apps/frontend/lib/auth/callback-error.ts +26 -0
  235. package/dist/dashboard-source/apps/frontend/lib/auth/client-session.ts +32 -0
  236. package/dist/dashboard-source/apps/frontend/lib/auth/client.ts +46 -0
  237. package/dist/dashboard-source/apps/frontend/lib/auth/config.ts +48 -0
  238. package/dist/dashboard-source/apps/frontend/lib/auth/delegations.ts +62 -0
  239. package/dist/dashboard-source/apps/frontend/lib/auth/issuer.ts +164 -0
  240. package/dist/dashboard-source/apps/frontend/lib/auth/jwt.ts +17 -0
  241. package/dist/dashboard-source/apps/frontend/lib/auth/logout.ts +35 -0
  242. package/dist/dashboard-source/apps/frontend/lib/auth/passkeys-menu.ts +9 -0
  243. package/dist/dashboard-source/apps/frontend/lib/auth/passkeys.ts +117 -0
  244. package/dist/dashboard-source/apps/frontend/lib/auth/providers.ts +52 -0
  245. package/dist/dashboard-source/apps/frontend/lib/auth/realtime-session-token.ts +62 -0
  246. package/dist/dashboard-source/apps/frontend/lib/auth/reauthentication-state.ts +16 -0
  247. package/dist/dashboard-source/apps/frontend/lib/auth/redirect.ts +105 -0
  248. package/dist/dashboard-source/apps/frontend/lib/auth/secret-login-presentation.ts +33 -0
  249. package/dist/dashboard-source/apps/frontend/lib/auth/session-cache-scope.ts +1 -0
  250. package/dist/dashboard-source/apps/frontend/lib/auth/session-role.ts +6 -0
  251. package/dist/dashboard-source/apps/frontend/lib/auth/session.ts +277 -0
  252. package/dist/dashboard-source/apps/frontend/lib/auth/ssr-session.ts +76 -0
  253. package/dist/dashboard-source/apps/frontend/lib/auth/verify-passkey.ts +95 -0
  254. package/dist/dashboard-source/apps/frontend/lib/authorization-tabs.ts +19 -0
  255. package/dist/dashboard-source/apps/frontend/lib/cedar-highlight.ts +116 -0
  256. package/dist/dashboard-source/apps/frontend/lib/client-plugin-error-reporting.ts +28 -0
  257. package/dist/dashboard-source/apps/frontend/lib/collections/collection-provider-factory.tsx +1119 -0
  258. package/dist/dashboard-source/apps/frontend/lib/collections/collection-provider-scope.ts +48 -0
  259. package/dist/dashboard-source/apps/frontend/lib/collections/database-error-ui.tsx +61 -0
  260. package/dist/dashboard-source/apps/frontend/lib/collections/draft-process-execution-collection-provider.tsx +32 -0
  261. package/dist/dashboard-source/apps/frontend/lib/collections/draft-process-execution.ts +161 -0
  262. package/dist/dashboard-source/apps/frontend/lib/collections/execution-collection-provider.tsx +42 -0
  263. package/dist/dashboard-source/apps/frontend/lib/collections/execution.ts +215 -0
  264. package/dist/dashboard-source/apps/frontend/lib/collections/graphql-stream.ts +123 -0
  265. package/dist/dashboard-source/apps/frontend/lib/collections/process-collection-provider.tsx +30 -0
  266. package/dist/dashboard-source/apps/frontend/lib/collections/process.ts +123 -0
  267. package/dist/dashboard-source/apps/frontend/lib/collections/replication-factory.ts +394 -0
  268. package/dist/dashboard-source/apps/frontend/lib/collections/replication-registry.ts +196 -0
  269. package/dist/dashboard-source/apps/frontend/lib/collections/rxdb-database-name.ts +19 -0
  270. package/dist/dashboard-source/apps/frontend/lib/collections/rxdb-lifecycle.ts +368 -0
  271. package/dist/dashboard-source/apps/frontend/lib/collections/rxdb-provider.tsx +577 -0
  272. package/dist/dashboard-source/apps/frontend/lib/collections/todo-collection-provider.tsx +30 -0
  273. package/dist/dashboard-source/apps/frontend/lib/collections/todo.ts +133 -0
  274. package/dist/dashboard-source/apps/frontend/lib/current-provider-user.ts +30 -0
  275. package/dist/dashboard-source/apps/frontend/lib/dev/frontend-port-file.ts +41 -0
  276. package/dist/dashboard-source/apps/frontend/lib/dev/import-completed-events.ts +21 -0
  277. package/dist/dashboard-source/apps/frontend/lib/dev/import-completed-query-invalidation.tsx +62 -0
  278. package/dist/dashboard-source/apps/frontend/lib/dev/import-completed-refresh.ts +40 -0
  279. package/dist/dashboard-source/apps/frontend/lib/effect/error-boundary.tsx +84 -0
  280. package/dist/dashboard-source/apps/frontend/lib/effect/index.ts +31 -0
  281. package/dist/dashboard-source/apps/frontend/lib/effect/params.ts +57 -0
  282. package/dist/dashboard-source/apps/frontend/lib/effect/run-effect.ts +17 -0
  283. package/dist/dashboard-source/apps/frontend/lib/effect/runtime.ts +168 -0
  284. package/dist/dashboard-source/apps/frontend/lib/effect/services/access-token.ts +48 -0
  285. package/dist/dashboard-source/apps/frontend/lib/effect/services/authorization.ts +206 -0
  286. package/dist/dashboard-source/apps/frontend/lib/effect/services/form-validation.ts +36 -0
  287. package/dist/dashboard-source/apps/frontend/lib/effect/services/graphql.ts +94 -0
  288. package/dist/dashboard-source/apps/frontend/lib/effect/services/index.ts +21 -0
  289. package/dist/dashboard-source/apps/frontend/lib/embed-manifest-store.ts +20 -0
  290. package/dist/dashboard-source/apps/frontend/lib/embed-manifest.ts +152 -0
  291. package/dist/dashboard-source/apps/frontend/lib/embed-request-origin.ts +39 -0
  292. package/dist/dashboard-source/apps/frontend/lib/errors/get-display-error-message.ts +22 -0
  293. package/dist/dashboard-source/apps/frontend/lib/execution-menu-actions-registry.ts +26 -0
  294. package/dist/dashboard-source/apps/frontend/lib/feature-permissions.ts +13 -0
  295. package/dist/dashboard-source/apps/frontend/lib/frontend-boot-health.tsx +161 -0
  296. package/dist/dashboard-source/apps/frontend/lib/frontend-client-plugin-registry.ts +45 -0
  297. package/dist/dashboard-source/apps/frontend/lib/frontend-manifest-store.ts +214 -0
  298. package/dist/dashboard-source/apps/frontend/lib/frontend-manifest.ts +74 -0
  299. package/dist/dashboard-source/apps/frontend/lib/frontend-plugin-loaders.ts +191 -0
  300. package/dist/dashboard-source/apps/frontend/lib/generated/gql/fragment-masking.ts +87 -0
  301. package/dist/dashboard-source/apps/frontend/lib/generated/gql/gql.ts +292 -0
  302. package/dist/dashboard-source/apps/frontend/lib/generated/gql/graphql.ts +443 -0
  303. package/dist/dashboard-source/apps/frontend/lib/generated/gql/index.ts +2 -0
  304. package/dist/dashboard-source/apps/frontend/lib/graphql/client-consumer.tsx +23 -0
  305. package/dist/dashboard-source/apps/frontend/lib/graphql/client-error-reporting.ts +268 -0
  306. package/dist/dashboard-source/apps/frontend/lib/graphql/client-provider.tsx +59 -0
  307. package/dist/dashboard-source/apps/frontend/lib/graphql/dashboard-activity.ts +7 -0
  308. package/dist/dashboard-source/apps/frontend/lib/graphql/dependent-lookup-query.ts +78 -0
  309. package/dist/dashboard-source/apps/frontend/lib/graphql/endpoint.ts +26 -0
  310. package/dist/dashboard-source/apps/frontend/lib/graphql/execution-queries.ts +70 -0
  311. package/dist/dashboard-source/apps/frontend/lib/graphql/file-upload-provider.tsx +82 -0
  312. package/dist/dashboard-source/apps/frontend/lib/graphql/graphql-identifiers.ts +10 -0
  313. package/dist/dashboard-source/apps/frontend/lib/graphql/list-queries.ts +327 -0
  314. package/dist/dashboard-source/apps/frontend/lib/graphql/lookup-provider.tsx +81 -0
  315. package/dist/dashboard-source/apps/frontend/lib/graphql/org-chart-operations.ts +63 -0
  316. package/dist/dashboard-source/apps/frontend/lib/graphql/org-chart-queries.ts +67 -0
  317. package/dist/dashboard-source/apps/frontend/lib/graphql/provider-user-queries.ts +65 -0
  318. package/dist/dashboard-source/apps/frontend/lib/graphql/queries.ts +80 -0
  319. package/dist/dashboard-source/apps/frontend/lib/graphql/server-client.ts +15 -0
  320. package/dist/dashboard-source/apps/frontend/lib/graphql/settings-queries.ts +634 -0
  321. package/dist/dashboard-source/apps/frontend/lib/graphql/stats-views-server.ts +16 -0
  322. package/dist/dashboard-source/apps/frontend/lib/graphql/stats-views.ts +33 -0
  323. package/dist/dashboard-source/apps/frontend/lib/graphql/user-queries.ts +138 -0
  324. package/dist/dashboard-source/apps/frontend/lib/graphql/workflow-operations.ts +54 -0
  325. package/dist/dashboard-source/apps/frontend/lib/graphql/workflow-queries.ts +50 -0
  326. package/dist/dashboard-source/apps/frontend/lib/mobile-home-view-model.ts +74 -0
  327. package/dist/dashboard-source/apps/frontend/lib/mobile-shell-policy.ts +124 -0
  328. package/dist/dashboard-source/apps/frontend/lib/mock-data.ts +364 -0
  329. package/dist/dashboard-source/apps/frontend/lib/notifications/notification-preference.ts +251 -0
  330. package/dist/dashboard-source/apps/frontend/lib/notifications/todo-notification-observer.ts +178 -0
  331. package/dist/dashboard-source/apps/frontend/lib/notifications/todo-notifications-runtime.tsx +14 -0
  332. package/dist/dashboard-source/apps/frontend/lib/notifications/use-todo-notifications.tsx +103 -0
  333. package/dist/dashboard-source/apps/frontend/lib/org-chart-data.ts +50 -0
  334. package/dist/dashboard-source/apps/frontend/lib/org-chart-depth-config.ts +71 -0
  335. package/dist/dashboard-source/apps/frontend/lib/org-chart-layout.ts +149 -0
  336. package/dist/dashboard-source/apps/frontend/lib/org-chart-types.ts +17 -0
  337. package/dist/dashboard-source/apps/frontend/lib/org-identity.ts +57 -0
  338. package/dist/dashboard-source/apps/frontend/lib/organisation-plugin-loaders.ts +13 -0
  339. package/dist/dashboard-source/apps/frontend/lib/organisation-plugin-preparation.ts +2 -0
  340. package/dist/dashboard-source/apps/frontend/lib/plugins-client.tsx +99 -0
  341. package/dist/dashboard-source/apps/frontend/lib/plugins.ts +1 -0
  342. package/dist/dashboard-source/apps/frontend/lib/public-todo-form-runtime.ts +9 -0
  343. package/dist/dashboard-source/apps/frontend/lib/public-todo-graphql-errors.ts +45 -0
  344. package/dist/dashboard-source/apps/frontend/lib/public-todo-model.ts +200 -0
  345. package/dist/dashboard-source/apps/frontend/lib/public-todo-server.ts +209 -0
  346. package/dist/dashboard-source/apps/frontend/lib/query-client.ts +41 -0
  347. package/dist/dashboard-source/apps/frontend/lib/restart-execution-action.ts +76 -0
  348. package/dist/dashboard-source/apps/frontend/lib/runtime-config.ts +23 -0
  349. package/dist/dashboard-source/apps/frontend/lib/telemetry/constants.ts +5 -0
  350. package/dist/dashboard-source/apps/frontend/lib/telemetry/otlp-config.ts +16 -0
  351. package/dist/dashboard-source/apps/frontend/lib/telemetry/register-otel.ts +308 -0
  352. package/dist/dashboard-source/apps/frontend/lib/theme.ts +9 -0
  353. package/dist/dashboard-source/apps/frontend/lib/todo-types.ts +64 -0
  354. package/dist/dashboard-source/apps/frontend/lib/todo-utils.ts +144 -0
  355. package/dist/dashboard-source/apps/frontend/lib/types/org-identity.ts +7 -0
  356. package/dist/dashboard-source/apps/frontend/lib/utils.ts +16 -0
  357. package/dist/dashboard-source/apps/frontend/lib/workflow/constants.ts +118 -0
  358. package/dist/dashboard-source/apps/frontend/lib/workflow/edge-routing.ts +195 -0
  359. package/dist/dashboard-source/apps/frontend/lib/workflow/form-preview.ts +8 -0
  360. package/dist/dashboard-source/apps/frontend/lib/workflow/layout.ts +878 -0
  361. package/dist/dashboard-source/apps/frontend/lib/workflow/types.ts +63 -0
  362. package/dist/dashboard-source/apps/frontend/next.config.ts +238 -0
  363. package/dist/dashboard-source/apps/frontend/package.json +71 -0
  364. package/dist/dashboard-source/apps/frontend/postcss.config.mjs +5 -0
  365. package/dist/dashboard-source/apps/frontend/proxy.ts +293 -0
  366. package/dist/dashboard-source/apps/frontend/public/.gitkeep +0 -0
  367. package/dist/dashboard-source/apps/frontend/public/favicon.ico +0 -0
  368. package/dist/dashboard-source/apps/frontend/public/processfocus-embed.js +553 -0
  369. package/dist/dashboard-source/apps/frontend/tsconfig.json +35 -0
  370. package/dist/dashboard-source/modules/auth-local-cedar/src/index.ts +7 -0
  371. package/dist/dashboard-source/modules/auth-local-cedar/src/lib/auth-local-cedar.ts +1397 -0
  372. package/dist/dashboard-source/modules/auth-local-cedar/src/lib/cedar-reload-notifier.ts +18 -0
  373. package/dist/dashboard-source/modules/auth-local-cedar/src/lib/config-base.ts +346 -0
  374. package/dist/dashboard-source/modules/auth-local-cedar/src/lib/policy-watcher.ts +172 -0
  375. package/dist/dashboard-source/modules/auth-policy/src/index.ts +4 -0
  376. package/dist/dashboard-source/modules/auth-policy/src/lib/auth-policy.ts +263 -0
  377. package/dist/dashboard-source/modules/auth-policy/src/lib/current-principal.ts +34 -0
  378. package/dist/dashboard-source/modules/auth-policy/src/lib/errors.ts +47 -0
  379. package/dist/dashboard-source/modules/auth-policy/src/lib/types.ts +595 -0
  380. package/dist/dashboard-source/modules/auth-session/src/index.ts +22 -0
  381. package/dist/dashboard-source/modules/auth-session/src/lib/issuer-url.ts +192 -0
  382. package/dist/dashboard-source/modules/auth-session/src/lib/realtime-recipient.ts +76 -0
  383. package/dist/dashboard-source/modules/auth-session/src/lib/session-cache-scope.ts +24 -0
  384. package/dist/dashboard-source/modules/auth-session/src/lib/subjects.ts +54 -0
  385. package/dist/dashboard-source/modules/auth-session/src/lib/url.ts +2 -0
  386. package/dist/dashboard-source/modules/aws-common/src/index.ts +3 -0
  387. package/dist/dashboard-source/modules/aws-common/src/lib/acm.ts +50 -0
  388. package/dist/dashboard-source/modules/aws-common/src/lib/otlp-config.ts +66 -0
  389. package/dist/dashboard-source/modules/aws-common/src/lib/runtime-ssm.ts +28 -0
  390. package/dist/dashboard-source/modules/effect-json-logger/src/index.ts +1 -0
  391. package/dist/dashboard-source/modules/effect-json-logger/src/lib/effect-json-logger.ts +65 -0
  392. package/dist/dashboard-source/modules/form/src/hooks/use-local-storage.ts +78 -0
  393. package/dist/dashboard-source/modules/form/src/index.ts +20 -0
  394. package/dist/dashboard-source/modules/form/src/lib/ajv-standard-schema.ts +152 -0
  395. package/dist/dashboard-source/modules/form/src/lib/client-components-to-form.tsx +1421 -0
  396. package/dist/dashboard-source/modules/form/src/lib/friendly-validation-message.ts +85 -0
  397. package/dist/dashboard-source/modules/form/src/lib/lookup-context.tsx +58 -0
  398. package/dist/dashboard-source/modules/form/src/lib/plugin-registry.ts +34 -0
  399. package/dist/dashboard-source/modules/form/src/lib/walker.tsx +1554 -0
  400. package/dist/dashboard-source/modules/form-client-representation/src/lib/client-form-definition.ts +440 -0
  401. package/dist/dashboard-source/modules/form-client-representation/src/lib/plugin-registry.ts +13 -0
  402. package/dist/dashboard-source/modules/form-client-representation/src/lib/types.ts +336 -0
  403. package/dist/dashboard-source/modules/form-rule/src/index.ts +21 -0
  404. package/dist/dashboard-source/modules/form-rule/src/lib/evaluator.ts +531 -0
  405. package/dist/dashboard-source/modules/form-rule/src/lib/paths.ts +102 -0
  406. package/dist/dashboard-source/modules/form-rule/src/lib/types.ts +121 -0
  407. package/dist/dashboard-source/modules/form-schema/src/index.ts +8 -0
  408. package/dist/dashboard-source/modules/form-schema/src/lib/annotation-helpers.ts +44 -0
  409. package/dist/dashboard-source/modules/form-schema/src/lib/deferred-value.ts +21 -0
  410. package/dist/dashboard-source/modules/form-schema/src/lib/email.ts +50 -0
  411. package/dist/dashboard-source/modules/form-schema/src/lib/field-count.ts +82 -0
  412. package/dist/dashboard-source/modules/form-schema/src/lib/form-annotations.ts +58 -0
  413. package/dist/dashboard-source/modules/form-schema/src/lib/form-schema.ts +975 -0
  414. package/dist/dashboard-source/modules/form-schema/src/lib/phone.ts +60 -0
  415. package/dist/dashboard-source/modules/form-schema/src/lib/property-signature.ts +45 -0
  416. package/dist/dashboard-source/modules/frontend-endpoints/src/endpoint.ts +137 -0
  417. package/dist/dashboard-source/modules/frontend-endpoints/src/index.ts +11 -0
  418. package/dist/dashboard-source/modules/frontend-endpoints/src/port-files.ts +219 -0
  419. package/dist/dashboard-source/modules/frontend-manifest/src/index.ts +2 -0
  420. package/dist/dashboard-source/modules/frontend-manifest/src/lib/browser-plugin-artifact.ts +201 -0
  421. package/dist/dashboard-source/modules/frontend-manifest/src/lib/frontend-manifest.ts +408 -0
  422. package/dist/dashboard-source/modules/frontend-plugin-host/src/index.ts +29 -0
  423. package/dist/dashboard-source/modules/frontend-plugin-host/src/lib/frontend-plugin-host.ts +288 -0
  424. package/dist/dashboard-source/modules/openauth/src/client.ts +1045 -0
  425. package/dist/dashboard-source/modules/openauth/src/error.ts +140 -0
  426. package/dist/dashboard-source/modules/openauth/src/pkce.ts +40 -0
  427. package/dist/dashboard-source/modules/openauth/src/random.ts +24 -0
  428. package/dist/dashboard-source/modules/openauth/src/subject.ts +132 -0
  429. package/dist/dashboard-source/modules/openauth/src/util.ts +13 -0
  430. package/dist/dashboard-source/modules/request-time/src/index.ts +1 -0
  431. package/dist/dashboard-source/modules/request-time/src/lib/request-time.ts +30 -0
  432. package/dist/dashboard-source/modules/rxdb-collections/generated/draft-process-execution-schema.json +45 -0
  433. package/dist/dashboard-source/modules/rxdb-collections/generated/execution-schema.json +217 -0
  434. package/dist/dashboard-source/modules/rxdb-collections/generated/process-schema.json +77 -0
  435. package/dist/dashboard-source/modules/rxdb-collections/generated/todo-schema.json +94 -0
  436. package/dist/dashboard-source/modules/rxdb-collections/src/index.ts +2 -0
  437. package/dist/dashboard-source/modules/rxdb-collections/src/lib/rxdb-collections.ts +181 -0
  438. package/dist/dashboard-source/modules/rxdb-collections/src/lib/to-rxdb-schema.ts +166 -0
  439. package/dist/dashboard-source/modules/shadcn-components/src/index.ts +60 -0
  440. package/dist/dashboard-source/modules/shadcn-components/src/lib/boolean-field.tsx +73 -0
  441. package/dist/dashboard-source/modules/shadcn-components/src/lib/calendar-slot-field.tsx +808 -0
  442. package/dist/dashboard-source/modules/shadcn-components/src/lib/date-field.tsx +127 -0
  443. package/dist/dashboard-source/modules/shadcn-components/src/lib/field-set.tsx +14 -0
  444. package/dist/dashboard-source/modules/shadcn-components/src/lib/file-field.tsx +321 -0
  445. package/dist/dashboard-source/modules/shadcn-components/src/lib/file-upload-context.tsx +45 -0
  446. package/dist/dashboard-source/modules/shadcn-components/src/lib/form-context.tsx +19 -0
  447. package/dist/dashboard-source/modules/shadcn-components/src/lib/lookup-field.tsx +394 -0
  448. package/dist/dashboard-source/modules/shadcn-components/src/lib/radio-field.tsx +96 -0
  449. package/dist/dashboard-source/modules/shadcn-components/src/lib/select-field.tsx +106 -0
  450. package/dist/dashboard-source/modules/shadcn-components/src/lib/text-field.tsx +245 -0
  451. package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/button.tsx +63 -0
  452. package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/checkbox.tsx +31 -0
  453. package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/command.tsx +101 -0
  454. package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/field.tsx +275 -0
  455. package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/input.tsx +29 -0
  456. package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/label.tsx +23 -0
  457. package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/popover.tsx +31 -0
  458. package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/separator.tsx +27 -0
  459. package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/textarea.tsx +19 -0
  460. package/dist/dashboard-source/modules/shadcn-components/src/lib/utils/utils.ts +4 -0
  461. package/dist/dashboard-source.json +70 -0
  462. package/dist/graphql-server.mjs +1319 -0
  463. package/dist/job-worker.mjs +989 -0
  464. package/dist/main.mjs +495 -0
  465. package/dist/prepare-dashboard.mjs +35 -0
  466. package/dist/resources/cedar/policies.cedar +315 -0
  467. package/dist/resources/cedar/schema.cedarschema +276 -0
  468. package/dist/resources/graphql-schema/rxdb.graphql +401 -0
  469. package/dist/resources/graphql-schema/system.graphql +1200 -0
  470. package/package.json +98 -0
@@ -0,0 +1,1045 @@
1
+ /**
2
+ * Use the OpenAuth client kick off your OAuth flows, exchange tokens, refresh tokens,
3
+ * and verify tokens.
4
+ *
5
+ * First, create a client.
6
+ *
7
+ * ```ts title="client.ts"
8
+ * import { createClient } from "@openauthjs/openauth/client"
9
+ *
10
+ * const client = createClient({
11
+ * clientID: "my-client",
12
+ * issuer: "https://auth.myserver.com"
13
+ * })
14
+ * ```
15
+ *
16
+ * Kick off the OAuth flow by calling `authorize`.
17
+ *
18
+ * ```ts
19
+ * const redirect_uri = "https://myserver.com/callback"
20
+ *
21
+ * const { url } = await client.authorize(
22
+ * redirect_uri,
23
+ * "code"
24
+ * )
25
+ * ```
26
+ *
27
+ * When the user completes the flow, `exchange` the code for tokens.
28
+ *
29
+ * ```ts
30
+ * const tokens = await client.exchange(query.get("code"), redirect_uri)
31
+ * ```
32
+ *
33
+ * And `verify` the tokens.
34
+ *
35
+ * ```ts
36
+ * const verified = await client.verify(subjects, tokens.access)
37
+ * ```
38
+ *
39
+ * @packageDocumentation
40
+ */
41
+
42
+ import type { StandardSchemaV1 } from "@standard-schema/spec"
43
+ import { Either, Schema } from "effect"
44
+ import type { JSONWebKeySet } from "jose"
45
+ import {
46
+ createLocalJWKSet,
47
+ decodeJwt,
48
+ errors,
49
+ jwtVerify,
50
+ } from "jose"
51
+ import {
52
+ InvalidAccessTokenError,
53
+ InvalidAuthorizationCodeError,
54
+ InvalidRefreshTokenError,
55
+ InvalidSubjectError,
56
+ OAuthMetadataFetchError,
57
+ } from "./error.ts"
58
+ import { generatePKCE } from "./pkce.ts"
59
+ import type { SubjectSchema } from "./subject.ts"
60
+
61
+ /**
62
+ * Schema for OAuth token endpoint response.
63
+ * Validates required fields but allows additional properties.
64
+ * @internal
65
+ */
66
+ const TokenResponseSchema = Schema.Struct({
67
+ access_token: Schema.String,
68
+ refresh_token: Schema.String,
69
+ expires_in: Schema.Number,
70
+ refresh_expires_in: Schema.optionalWith(Schema.Number, { exact: true }),
71
+ }).pipe(Schema.extend(Schema.Record({ key: Schema.String, value: Schema.Unknown })))
72
+
73
+ const OAuthErrorResponseSchema = Schema.Struct({
74
+ error: Schema.String,
75
+ error_description: Schema.optionalWith(Schema.String, { exact: true }),
76
+ }).pipe(Schema.extend(Schema.Record({ key: Schema.String, value: Schema.Unknown })))
77
+
78
+ const tokenError = (
79
+ json: unknown,
80
+ ): { readonly code: string; readonly description?: string } | undefined => {
81
+ const result = Schema.decodeUnknownEither(OAuthErrorResponseSchema)(json)
82
+ if (Either.isLeft(result)) return undefined
83
+ const code = result.right.error
84
+ if (code === "") return undefined
85
+ const description = result.right.error_description
86
+ return description ? { code, description } : { code }
87
+ }
88
+
89
+ /**
90
+ * The well-known information for an OAuth 2.0 authorization server.
91
+ * @internal
92
+ */
93
+ export interface WellKnown {
94
+ /**
95
+ * The URI to the JWKS endpoint.
96
+ */
97
+ jwks_uri: string
98
+ /**
99
+ * The URI to the token endpoint.
100
+ */
101
+ token_endpoint: string
102
+ /**
103
+ * The URI to the authorization endpoint.
104
+ */
105
+ authorization_endpoint: string
106
+ }
107
+
108
+ /**
109
+ * The tokens returned by the auth server.
110
+ */
111
+ export interface Tokens {
112
+ /**
113
+ * The access token.
114
+ */
115
+ access: string
116
+ /**
117
+ * The refresh token.
118
+ */
119
+ refresh: string
120
+
121
+ /**
122
+ * The number of seconds until the access token expires.
123
+ */
124
+ expiresIn: number
125
+
126
+ /**
127
+ * The number of seconds until the refresh token expires.
128
+ * This is an extension to OAuth 2.1 (not part of the standard).
129
+ */
130
+ refreshExpiresIn?: number
131
+ }
132
+
133
+ interface ResponseLike {
134
+ json(): Promise<unknown>
135
+ ok: Response["ok"]
136
+ status?: Response["status"]
137
+ }
138
+ type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<ResponseLike>
139
+
140
+ const getErrorMessage = (error: unknown): string => {
141
+ if (error instanceof Error && error.message.length > 0) {
142
+ return error.message
143
+ }
144
+
145
+ return String(error)
146
+ }
147
+
148
+ /**
149
+ * The challenge that you can use to verify the code.
150
+ */
151
+ export type Challenge = {
152
+ /**
153
+ * The state that was sent to the redirect URI.
154
+ */
155
+ state: string
156
+ /**
157
+ * The verifier that was sent to the redirect URI.
158
+ */
159
+ verifier?: string
160
+ }
161
+
162
+ /**
163
+ * Configure the client.
164
+ */
165
+ export interface ClientInput {
166
+ /**
167
+ * The client ID. This is just a string to identify your app.
168
+ *
169
+ * If you have a web app and a mobile app, you want to use different client IDs both.
170
+ *
171
+ * @example
172
+ * ```ts
173
+ * {
174
+ * clientID: "my-client"
175
+ * }
176
+ * ```
177
+ */
178
+ clientID?: string
179
+ /**
180
+ * The client secret for confidential clients.
181
+ *
182
+ * Only use this for server-side applications where the secret can be kept secure.
183
+ * Do not use this for SPAs or mobile apps - use PKCE instead.
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * {
188
+ * clientSecret: process.env.OAUTH_CLIENT_SECRET
189
+ * }
190
+ * ```
191
+ */
192
+ clientSecret?: string | undefined
193
+ /**
194
+ * Machine JWT for confidential server-side clients.
195
+ *
196
+ * When provided, the client uses `Authorization: Bearer <jwt>` for token
197
+ * exchange and refresh calls instead of Basic auth.
198
+ *
199
+ * If `clientID`, `issuer`, or `audience` are omitted, they are inferred from
200
+ * JWT claims:
201
+ * - `properties.clientId` -> `clientID`
202
+ * - `iss` -> `issuer`
203
+ * - `aud` -> `audience`
204
+ */
205
+ jwt?: string | undefined
206
+ /**
207
+ * The URL of your OpenAuth server.
208
+ *
209
+ * @example
210
+ * ```ts
211
+ * {
212
+ * issuer: "https://auth.myserver.com"
213
+ * }
214
+ * ```
215
+ */
216
+ issuer?: string
217
+ /**
218
+ * The default audience for access tokens. This specifies which API/service the tokens
219
+ * are intended for.
220
+ *
221
+ * This will be used as the default audience in all `authorize` calls unless overridden.
222
+ *
223
+ * @example
224
+ * ```ts
225
+ * {
226
+ * audience: "graphql-api"
227
+ * }
228
+ * ```
229
+ */
230
+ audience?: string
231
+ /**
232
+ * Optionally, override the internally used fetch function.
233
+ *
234
+ * This is useful if you are using a polyfilled fetch function in your application and you
235
+ * want the client to use it too.
236
+ */
237
+ fetch?: FetchLike
238
+ }
239
+
240
+ export interface AuthorizeOptions {
241
+ /**
242
+ * Enable the PKCE flow. This is for SPA apps.
243
+ *
244
+ * ```ts
245
+ * {
246
+ * pkce: true
247
+ * }
248
+ * ```
249
+ *
250
+ * @default false
251
+ */
252
+ pkce?: boolean | undefined
253
+ /**
254
+ * The provider you want to use for the OAuth flow.
255
+ *
256
+ * ```ts
257
+ * {
258
+ * provider: "google"
259
+ * }
260
+ * ```
261
+ *
262
+ * If no provider is specified, the user is directed to a page where they can select from the
263
+ * list of configured providers.
264
+ *
265
+ * If there's only one provider configured, the user will be redirected to that.
266
+ */
267
+ provider?: string | undefined
268
+ /**
269
+ * The audience for the access token. This specifies which API/service the token is intended for.
270
+ *
271
+ * ```ts
272
+ * {
273
+ * audience: "graphql-api"
274
+ * }
275
+ * ```
276
+ *
277
+ * If not specified, the issuer will use the client's configured audience or fall back to the client ID.
278
+ * Use this when the frontend needs tokens for a different service than itself.
279
+ */
280
+ audience?: string | undefined
281
+ }
282
+
283
+ export interface AuthorizeResult {
284
+ /**
285
+ * The challenge that you can use to verify the code. This is for the PKCE flow for SPA apps.
286
+ *
287
+ * This is an object that you _stringify_ and store it in session storage.
288
+ *
289
+ * ```ts
290
+ * sessionStorage.setItem("challenge", JSON.stringify(challenge))
291
+ * ```
292
+ */
293
+ challenge: Challenge
294
+ /**
295
+ * The URL to redirect the user to. This starts the OAuth flow.
296
+ *
297
+ * For example, for SPA apps.
298
+ *
299
+ * ```ts
300
+ * location.href = url
301
+ * ```
302
+ */
303
+ url: string
304
+ }
305
+
306
+ /**
307
+ * Returned when the exchange is successful.
308
+ */
309
+ export interface ExchangeSuccess {
310
+ /**
311
+ * This is always `false` when the exchange is successful.
312
+ */
313
+ err: false
314
+ /**
315
+ * The access and refresh tokens.
316
+ */
317
+ tokens: Tokens
318
+ }
319
+
320
+ /**
321
+ * Returned when the exchange fails.
322
+ */
323
+ export interface ExchangeError {
324
+ /**
325
+ * The type of error that occurred. You can handle this by checking the type.
326
+ *
327
+ * @example
328
+ * ```ts
329
+ * import { InvalidAuthorizationCodeError } from "@openauthjs/openauth/error"
330
+ *
331
+ * console.log(err instanceof InvalidAuthorizationCodeError)
332
+ *```
333
+ */
334
+ err: InvalidAuthorizationCodeError
335
+ }
336
+
337
+ export interface RefreshOptions {
338
+ /**
339
+ * Optionally, pass in the access token.
340
+ */
341
+ access?: string
342
+ /**
343
+ * Optionally, pass a scope to request specific roles.
344
+ * Format: "role:RolePath role:AnotherRolePath"
345
+ */
346
+ scope?: string
347
+ }
348
+
349
+ /**
350
+ * Returned when the refresh is successful.
351
+ */
352
+ export interface RefreshSuccess {
353
+ /**
354
+ * This is always `false` when the refresh is successful.
355
+ */
356
+ err: false
357
+ /**
358
+ * Returns the refreshed tokens only if they've been refreshed.
359
+ *
360
+ * If they are still valid, this will be `undefined`.
361
+ */
362
+ tokens?: Tokens
363
+ }
364
+
365
+ /**
366
+ * Returned when the refresh fails.
367
+ */
368
+ export interface RefreshError {
369
+ /**
370
+ * The type of error that occurred. You can handle this by checking the type.
371
+ *
372
+ * @example
373
+ * ```ts
374
+ * import { InvalidRefreshTokenError } from "@openauthjs/openauth/error"
375
+ *
376
+ * console.log(err instanceof InvalidRefreshTokenError)
377
+ *```
378
+ */
379
+ err: InvalidRefreshTokenError | InvalidAccessTokenError
380
+ }
381
+
382
+ export interface VerifyOptions {
383
+ /**
384
+ * Optionally, pass in the refresh token.
385
+ *
386
+ * If passed in, this will automatically refresh the access token if it has expired.
387
+ */
388
+ refresh?: string
389
+ /**
390
+ * @internal
391
+ */
392
+ issuer?: string
393
+ /**
394
+ * @internal
395
+ */
396
+ audience?: string
397
+ /**
398
+ * Optionally, override the internally used fetch function.
399
+ *
400
+ * This is useful if you are using a polyfilled fetch function in your application and you
401
+ * want the client to use it too.
402
+ */
403
+ fetch?: FetchLike
404
+ }
405
+
406
+ export interface VerifyResult<T extends SubjectSchema> {
407
+ /**
408
+ * This is always `undefined` when the verify is successful.
409
+ */
410
+ err?: undefined
411
+ /**
412
+ * Returns the refreshed tokens only if they’ve been refreshed.
413
+ *
414
+ * If they are still valid, this will be undefined.
415
+ */
416
+ tokens?: Tokens
417
+ /**
418
+ * @internal
419
+ */
420
+ aud: string
421
+ /**
422
+ * The decoded subjects from the access token.
423
+ *
424
+ * Has the same shape as the subjects you defined when creating the issuer.
425
+ */
426
+ subject: {
427
+ [type in keyof T]: { type: type; properties: StandardSchemaV1.InferOutput<T[type]> }
428
+ }[keyof T]
429
+ }
430
+
431
+ /**
432
+ * Returned when the verify call fails.
433
+ */
434
+ export interface VerifyError {
435
+ /**
436
+ * The type of error that occurred. You can handle this by checking the type.
437
+ *
438
+ * @example
439
+ * ```ts
440
+ * import { InvalidRefreshTokenError, OAuthMetadataFetchError } from "@openauthjs/openauth/error"
441
+ *
442
+ * console.log(err instanceof InvalidRefreshTokenError)
443
+ * console.log(err instanceof OAuthMetadataFetchError)
444
+ * ```
445
+ */
446
+ err:
447
+ | InvalidRefreshTokenError
448
+ | InvalidAccessTokenError
449
+ | InvalidSubjectError
450
+ | OAuthMetadataFetchError
451
+ }
452
+
453
+ /**
454
+ * An instance of the OpenAuth client contains the following methods.
455
+ */
456
+ export interface Client {
457
+ /**
458
+ * Start the autorization flow. For example, in SSR sites.
459
+ *
460
+ * ```ts
461
+ * const { url } = await client.authorize(<redirect_uri>, "code")
462
+ * ```
463
+ *
464
+ * This takes a redirect URI and the type of flow you want to use. The redirect URI is the
465
+ * location where the user will be redirected to after the flow is complete.
466
+ *
467
+ * Supports both the _code_ and _token_ flows. We recommend using the _code_ flow as it's more
468
+ * secure.
469
+ *
470
+ * :::tip
471
+ * This returns a URL to redirect the user to. This starts the OAuth flow.
472
+ * :::
473
+ *
474
+ * This returns a URL to the auth server. You can redirect the user to the URL to start the
475
+ * OAuth flow.
476
+ *
477
+ * For SPA apps, we recommend using the PKCE flow.
478
+ *
479
+ * ```ts {4}
480
+ * const { challenge, url } = await client.authorize(
481
+ * <redirect_uri>,
482
+ * "code",
483
+ * { pkce: true }
484
+ * )
485
+ * ```
486
+ *
487
+ * This returns a redirect URL and a challenge that you need to use later to verify the code.
488
+ */
489
+ authorize(
490
+ redirectURI: string,
491
+ response?: "code",
492
+ opts?: AuthorizeOptions,
493
+ ): Promise<AuthorizeResult>
494
+ /**
495
+ * Exchange the code for access and refresh tokens.
496
+ *
497
+ * ```ts
498
+ * const exchanged = await client.exchange(<code>, <redirect_uri>)
499
+ * ```
500
+ *
501
+ * You call this after the user has been redirected back to your app after the OAuth flow.
502
+ *
503
+ * :::tip
504
+ * For SSR sites, the code is returned in the query parameter.
505
+ * :::
506
+ *
507
+ * So the code comes from the query parameter in the redirect URI. The redirect URI here is
508
+ * the one that you passed in to the `authorize` call when starting the flow.
509
+ *
510
+ * :::tip
511
+ * For SPA sites, the code is returned through the URL hash.
512
+ * :::
513
+ *
514
+ * If you used the PKCE flow for an SPA app, the code is returned as a part of the redirect URL
515
+ * hash.
516
+ *
517
+ * ```ts {4}
518
+ * const exchanged = await client.exchange(
519
+ * <code>,
520
+ * <redirect_uri>,
521
+ * <challenge.verifier>
522
+ * )
523
+ * ```
524
+ *
525
+ * You also need to pass in the previously stored challenge verifier.
526
+ *
527
+ * This method returns the access and refresh tokens. Or if it fails, it returns an error that
528
+ * you can handle depending on the error.
529
+ *
530
+ * ```ts
531
+ * import { InvalidAuthorizationCodeError } from "@openauthjs/openauth/error"
532
+ *
533
+ * if (exchanged.err) {
534
+ * if (exchanged.err instanceof InvalidAuthorizationCodeError) {
535
+ * // handle invalid code error
536
+ * }
537
+ * else {
538
+ * // handle other errors
539
+ * }
540
+ * }
541
+ *
542
+ * const { access, refresh } = exchanged.tokens
543
+ * ```
544
+ */
545
+ exchange(
546
+ code: string,
547
+ redirectURI: string,
548
+ verifier?: string,
549
+ ): Promise<ExchangeSuccess | ExchangeError>
550
+ /**
551
+ * Refreshes the tokens if they have expired. This is used in an SPA app to maintain the
552
+ * session, without logging the user out.
553
+ *
554
+ * ```ts
555
+ * const next = await client.refresh(<refresh_token>)
556
+ * ```
557
+ *
558
+ * Can optionally take the access token as well. If passed in, this will skip the refresh
559
+ * if the access token is still valid.
560
+ *
561
+ * ```ts
562
+ * const next = await client.refresh(<refresh_token>, { access: <access_token> })
563
+ * ```
564
+ *
565
+ * This returns the refreshed tokens only if they've been refreshed.
566
+ *
567
+ * ```ts
568
+ * if (!next.err) {
569
+ * // tokens are still valid
570
+ * }
571
+ * if (next.tokens) {
572
+ * const { access, refresh } = next.tokens
573
+ * }
574
+ * ```
575
+ *
576
+ * Or if it fails, it returns an error that you can handle depending on the error.
577
+ *
578
+ * ```ts
579
+ * import { InvalidRefreshTokenError } from "@openauthjs/openauth/error"
580
+ *
581
+ * if (next.err) {
582
+ * if (next.err instanceof InvalidRefreshTokenError) {
583
+ * // handle invalid refresh token error
584
+ * }
585
+ * else {
586
+ * // handle other errors
587
+ * }
588
+ * }
589
+ * ```
590
+ */
591
+ refresh(
592
+ refresh: string,
593
+ opts?: RefreshOptions,
594
+ ): Promise<RefreshSuccess | RefreshError>
595
+ /**
596
+ * Verify the token in the incoming request.
597
+ *
598
+ * This is typically used for SSR sites where the token is stored in an HTTP only cookie. And
599
+ * is passed to the server on every request.
600
+ *
601
+ * ```ts
602
+ * const verified = await client.verify(<subjects>, <token>)
603
+ * ```
604
+ *
605
+ * This takes the subjects that you had previously defined when creating the issuer.
606
+ *
607
+ * :::tip
608
+ * If the refresh token is passed in, it'll automatically refresh the access token.
609
+ * :::
610
+ *
611
+ * This can optionally take the refresh token as well. If passed in, it'll automatically
612
+ * refresh the access token if it has expired.
613
+ *
614
+ * ```ts
615
+ * const verified = await client.verify(<subjects>, <token>, { refresh: <refresh_token> })
616
+ * ```
617
+ *
618
+ * This returns the decoded subjects from the access token. And the tokens if they've been
619
+ * refreshed.
620
+ *
621
+ * ```ts
622
+ * // based on the subjects you defined earlier
623
+ * console.log(verified.subject.properties.userID)
624
+ *
625
+ * if (verified.tokens) {
626
+ * const { access, refresh } = verified.tokens
627
+ * }
628
+ * ```
629
+ *
630
+ * Or if it fails, it returns an error that you can handle depending on the error.
631
+ *
632
+ * ```ts
633
+ * import { InvalidRefreshTokenError } from "@openauthjs/openauth/error"
634
+ *
635
+ * if (verified.err) {
636
+ * if (verified.err instanceof InvalidRefreshTokenError) {
637
+ * // handle invalid refresh token error
638
+ * }
639
+ * else {
640
+ * // handle other errors
641
+ * }
642
+ * }
643
+ * ```
644
+ */
645
+ verify<T extends SubjectSchema>(
646
+ subjects: T,
647
+ token: string,
648
+ options?: VerifyOptions,
649
+ ): Promise<VerifyResult<T> | VerifyError>
650
+ /**
651
+ * @deprecated use `authorize` instead, it will do pkce by default unless disabled with `opts.pkce = false`
652
+ */
653
+ pkce(
654
+ redirectURI: string,
655
+ opts?: {
656
+ provider?: string
657
+ },
658
+ ): Promise<string[]>
659
+ /**
660
+ * Logout and invalidate all refresh tokens for the user.
661
+ *
662
+ * This calls the auth server to invalidate all refresh tokens associated with the
663
+ * user's subject. After calling this, the refresh token will no longer be valid
664
+ * for obtaining new access tokens.
665
+ *
666
+ * @param refresh - The refresh token to invalidate
667
+ * @returns A promise resolving to an object indicating success or failure
668
+ *
669
+ * @example
670
+ * ```ts
671
+ * const result = await client.logout(refreshToken)
672
+ * if (result.success) {
673
+ * // Clear local session/cookies
674
+ * }
675
+ * ```
676
+ */
677
+ logout(refresh: string): Promise<{ success: boolean }>
678
+ }
679
+
680
+ /**
681
+ * Create an OpenAuth client.
682
+ *
683
+ * @param input - Configure the client.
684
+ */
685
+ export function createClient(input: ClientInput): Client {
686
+ const shouldDecodeJwt =
687
+ !!input.jwt && (!input.clientID || !input.issuer || !input.audience)
688
+ const decodedJwt = shouldDecodeJwt ? decodeJwt(input.jwt!) : undefined
689
+
690
+ const jwtClientId =
691
+ decodedJwt &&
692
+ typeof decodedJwt === "object" &&
693
+ "properties" in decodedJwt &&
694
+ typeof decodedJwt["properties"] === "object" &&
695
+ decodedJwt["properties"] !== null &&
696
+ "clientId" in decodedJwt["properties"] &&
697
+ typeof decodedJwt["properties"]["clientId"] === "string"
698
+ ? decodedJwt["properties"]["clientId"]
699
+ : undefined
700
+
701
+ const jwtAudience =
702
+ decodedJwt?.aud && typeof decodedJwt.aud === "string"
703
+ ? decodedJwt.aud
704
+ : Array.isArray(decodedJwt?.aud) && typeof decodedJwt.aud[0] === "string"
705
+ ? decodedJwt.aud[0]
706
+ : undefined
707
+
708
+ const clientID = input.clientID ?? jwtClientId
709
+ if (!clientID) throw new Error("No clientID")
710
+
711
+ const issuer = input.issuer ?? decodedJwt?.iss ?? globalThis.process?.env?.["OPENAUTH_ISSUER"]
712
+ if (!issuer) throw new Error("No issuer")
713
+
714
+ const audience = input.audience ?? jwtAudience
715
+
716
+ const jwksCache = new Map<string, ReturnType<typeof createLocalJWKSet>>()
717
+ const issuerCache = new Map<string, WellKnown>()
718
+ const f = input.fetch ?? fetch
719
+
720
+ async function fetchJson<T>(url: string): Promise<T> {
721
+ let response: ResponseLike
722
+ try {
723
+ response = await f(url)
724
+ } catch (error) {
725
+ throw new OAuthMetadataFetchError(url, getErrorMessage(error), error)
726
+ }
727
+
728
+ if (!response.ok) {
729
+ const statusSuffix =
730
+ typeof response.status === "number" ? ` (status ${response.status})` : ""
731
+ throw new OAuthMetadataFetchError(
732
+ url,
733
+ `Unexpected response${statusSuffix}`,
734
+ )
735
+ }
736
+
737
+ try {
738
+ return (await response.json()) as T
739
+ } catch (error) {
740
+ throw new OAuthMetadataFetchError(
741
+ url,
742
+ `Invalid JSON response: ${getErrorMessage(error)}`,
743
+ error,
744
+ )
745
+ }
746
+ }
747
+
748
+ async function getIssuer() {
749
+ const cached = issuerCache.get(issuer!)
750
+ if (cached) return cached
751
+ const wellKnown = await fetchJson<WellKnown>(
752
+ `${issuer}/.well-known/oauth-authorization-server`,
753
+ )
754
+ issuerCache.set(issuer!, wellKnown)
755
+ return wellKnown
756
+ }
757
+
758
+ async function getJWKS() {
759
+ const wk = await getIssuer()
760
+ const cached = jwksCache.get(issuer!)
761
+ if (cached) return cached
762
+ const keyset = await fetchJson<JSONWebKeySet>(wk.jwks_uri)
763
+ const result = createLocalJWKSet(keyset)
764
+ jwksCache.set(issuer!, result)
765
+ return result
766
+ }
767
+
768
+ const result = {
769
+ async authorize(
770
+ redirectURI: string,
771
+ response = "code",
772
+ opts?: AuthorizeOptions,
773
+ ) {
774
+ const result = new URL(`${issuer}/oauth/authorize`)
775
+ const challenge: Challenge = {
776
+ state: crypto.randomUUID(),
777
+ }
778
+ const shouldUsePkce = opts?.pkce ?? true
779
+ result.searchParams.set("client_id", clientID)
780
+ result.searchParams.set("redirect_uri", redirectURI)
781
+ result.searchParams.set("response_type", response)
782
+ result.searchParams.set("state", challenge.state)
783
+ if (opts?.provider) result.searchParams.set("provider", opts.provider)
784
+ const requestedAudience = opts?.audience ?? audience
785
+ if (requestedAudience) result.searchParams.set("audience", requestedAudience)
786
+ if (shouldUsePkce && response === "code") {
787
+ const pkce = await generatePKCE()
788
+ result.searchParams.set("code_challenge_method", "S256")
789
+ result.searchParams.set("code_challenge", pkce.challenge)
790
+ challenge.verifier = pkce.verifier
791
+ }
792
+ return {
793
+ challenge,
794
+ url: result.toString(),
795
+ }
796
+ },
797
+ /**
798
+ * @deprecated use `authorize` instead, it will do pkce by default unless disabled with `opts.pkce = false`
799
+ */
800
+ async pkce(
801
+ redirectURI: string,
802
+ opts?: {
803
+ provider?: string
804
+ },
805
+ ) {
806
+ const result = new URL(`${issuer}/oauth/authorize`)
807
+ if (opts?.provider) result.searchParams.set("provider", opts.provider)
808
+ result.searchParams.set("client_id", clientID)
809
+ result.searchParams.set("redirect_uri", redirectURI)
810
+ result.searchParams.set("response_type", "code")
811
+ const pkce = await generatePKCE()
812
+ result.searchParams.set("code_challenge_method", "S256")
813
+ result.searchParams.set("code_challenge", pkce.challenge)
814
+ return [pkce.verifier, result.toString()]
815
+ },
816
+
817
+ /**
818
+ * Exchanges an authorization code for access and refresh tokens.
819
+ *
820
+ * This is called after the user completes the OAuth flow and is redirected
821
+ * back to your app with a code query parameter. For PKCE flows (SPA apps),
822
+ * you also pass the verifier from the challenge stored during the authorize
823
+ * call.
824
+ */
825
+ async exchange(
826
+ code: string,
827
+ redirectURI: string,
828
+ verifier?: string,
829
+ ): Promise<ExchangeSuccess | ExchangeError> {
830
+ const headers: Record<string, string> = {
831
+ "Content-Type": "application/x-www-form-urlencoded",
832
+ }
833
+ const body: Record<string, string> = {
834
+ code,
835
+ redirect_uri: redirectURI,
836
+ grant_type: "authorization_code",
837
+ }
838
+ if (input.jwt) {
839
+ headers["Authorization"] = `Bearer ${input.jwt}`
840
+ body["client_id"] = clientID
841
+ } else if (input.clientSecret) {
842
+ // Use Basic auth for confidential clients (client_id must not be in body)
843
+ const credentials = Buffer.from(`${clientID}:${input.clientSecret}`).toString("base64")
844
+ headers["Authorization"] = `Basic ${credentials}`
845
+ } else {
846
+ // Public clients include client_id in body
847
+ body["client_id"] = clientID
848
+ }
849
+ if (verifier) {
850
+ body["code_verifier"] = verifier
851
+ }
852
+ const tokens = await f(`${issuer}/oauth/token`, {
853
+ method: "POST",
854
+ headers,
855
+ body: new URLSearchParams(body).toString(),
856
+ })
857
+ const json = await tokens.json()
858
+ if (!tokens.ok) {
859
+ const oauthError = tokenError(json)
860
+ return {
861
+ err: new InvalidAuthorizationCodeError(
862
+ oauthError?.description,
863
+ oauthError?.code,
864
+ ),
865
+ }
866
+ }
867
+ const result = Schema.decodeUnknownEither(TokenResponseSchema)(json)
868
+ if (Either.isLeft(result)) {
869
+ return {
870
+ err: new InvalidAuthorizationCodeError(
871
+ "Token endpoint returned an invalid token response",
872
+ ),
873
+ }
874
+ }
875
+ const parsed = result.right
876
+ const resultTokens: Tokens = {
877
+ access: parsed.access_token,
878
+ refresh: parsed.refresh_token,
879
+ expiresIn: parsed.expires_in,
880
+ }
881
+ if (parsed.refresh_expires_in !== undefined) {
882
+ resultTokens.refreshExpiresIn = parsed.refresh_expires_in
883
+ }
884
+ return {
885
+ err: false,
886
+ tokens: resultTokens,
887
+ }
888
+ },
889
+ async refresh(
890
+ refresh: string,
891
+ opts?: RefreshOptions,
892
+ ): Promise<RefreshSuccess | RefreshError> {
893
+ // Skip early check if we're requesting specific roles (force refresh)
894
+ if (opts?.access && !opts?.scope) {
895
+ const decoded = decodeJwt(opts.access)
896
+ if (!decoded) {
897
+ return {
898
+ err: new InvalidAccessTokenError(),
899
+ }
900
+ }
901
+ // allow 30s window for expiration
902
+ if ((decoded.exp || 0) > Date.now() / 1000 + 30) {
903
+ return {
904
+ err: false,
905
+ }
906
+ }
907
+ }
908
+ const headers: Record<string, string> = {
909
+ "Content-Type": "application/x-www-form-urlencoded",
910
+ }
911
+ const body: Record<string, string> = {
912
+ grant_type: "refresh_token",
913
+ refresh_token: refresh,
914
+ }
915
+ if (input.jwt) {
916
+ headers["Authorization"] = `Bearer ${input.jwt}`
917
+ body["client_id"] = clientID
918
+ } else if (input.clientSecret) {
919
+ // Use Basic auth for confidential clients (client_id must not be in body)
920
+ const credentials = Buffer.from(`${clientID}:${input.clientSecret}`).toString("base64")
921
+ headers["Authorization"] = `Basic ${credentials}`
922
+ } else {
923
+ // Public clients include client_id in body
924
+ body["client_id"] = clientID
925
+ }
926
+ // Add scope parameter if provided (for role switching)
927
+ if (opts?.scope) {
928
+ body["scope"] = opts.scope
929
+ }
930
+ const tokens = await f(`${issuer}/oauth/token`, {
931
+ method: "POST",
932
+ headers,
933
+ body: new URLSearchParams(body).toString(),
934
+ })
935
+ const json = await tokens.json()
936
+ if (!tokens.ok) {
937
+ return {
938
+ err: new InvalidRefreshTokenError(),
939
+ }
940
+ }
941
+ const result = Schema.decodeUnknownEither(TokenResponseSchema)(json)
942
+ if (Either.isLeft(result)) {
943
+ return {
944
+ err: new InvalidRefreshTokenError(),
945
+ }
946
+ }
947
+ const parsed = result.right
948
+ const refreshedTokens: Tokens = {
949
+ access: parsed.access_token,
950
+ refresh: parsed.refresh_token,
951
+ expiresIn: parsed.expires_in,
952
+ }
953
+ if (parsed.refresh_expires_in !== undefined) {
954
+ refreshedTokens.refreshExpiresIn = parsed.refresh_expires_in
955
+ }
956
+ return {
957
+ err: false,
958
+ tokens: refreshedTokens,
959
+ }
960
+ },
961
+ async verify<T extends SubjectSchema>(
962
+ subjects: T,
963
+ token: string,
964
+ options?: VerifyOptions,
965
+ ): Promise<VerifyResult<T> | VerifyError> {
966
+ let jwks: ReturnType<typeof createLocalJWKSet>
967
+ try {
968
+ jwks = await getJWKS()
969
+ } catch (error) {
970
+ if (error instanceof OAuthMetadataFetchError) {
971
+ return {
972
+ err: error,
973
+ }
974
+ }
975
+
976
+ return {
977
+ err: new InvalidAccessTokenError(),
978
+ }
979
+ }
980
+
981
+ try {
982
+ const result = await jwtVerify<{
983
+ mode: "access"
984
+ type: keyof T
985
+ properties: StandardSchemaV1.InferInput<T[keyof T]>
986
+ }>(token, jwks, {
987
+ issuer,
988
+ audience: options?.audience ?? audience ?? clientID,
989
+ })
990
+ const validated = await subjects[result.payload.type]![
991
+ "~standard"
992
+ ].validate(result.payload.properties)
993
+ if (!validated.issues && result.payload.mode === "access")
994
+ return {
995
+ aud: result.payload.aud as string,
996
+ subject: {
997
+ type: result.payload.type,
998
+ properties: validated.value,
999
+ }
1000
+ }
1001
+ return {
1002
+ err: new InvalidSubjectError(),
1003
+ }
1004
+ } catch (e) {
1005
+ if (e instanceof errors.JWTExpired && options?.refresh) {
1006
+ const refreshed = await this.refresh(options.refresh)
1007
+ if (refreshed.err) return refreshed
1008
+ const verified = await result.verify(
1009
+ subjects,
1010
+ refreshed.tokens!.access,
1011
+ {
1012
+ refresh: refreshed.tokens!.refresh,
1013
+ issuer,
1014
+ ...(options?.fetch && { fetch: options.fetch }),
1015
+ },
1016
+ )
1017
+ if (verified.err) return verified
1018
+ verified.tokens = refreshed.tokens!
1019
+ return verified
1020
+ }
1021
+ return {
1022
+ err: new InvalidAccessTokenError(),
1023
+ }
1024
+ }
1025
+ },
1026
+ async logout(refresh: string): Promise<{ success: boolean }> {
1027
+ const response = await f(`${issuer}/oauth/revoke`, {
1028
+ method: "POST",
1029
+ headers: {
1030
+ "Content-Type": "application/x-www-form-urlencoded",
1031
+ },
1032
+ body: new URLSearchParams({
1033
+ token: refresh,
1034
+ }).toString(),
1035
+ })
1036
+
1037
+ if (!response.ok) {
1038
+ return { success: false }
1039
+ }
1040
+
1041
+ return { success: true }
1042
+ },
1043
+ }
1044
+ return result
1045
+ }