@processfocus/runtime-local 0.1.0-next.2 → 0.1.0-next.4
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.
- package/README.md +51 -253
- package/dist/authentication-server.mjs +52 -84
- package/dist/chunk-3wzp2sax.js +4806 -0
- package/dist/chunk-5kjvzbwr.js +512 -0
- package/dist/chunk-egeb4821.js +156 -0
- package/dist/chunk-q5v72erd.js +241 -0
- package/dist/{chunk-yhzbn4vx.js → chunk-wvbz0nmd.js} +19485 -34180
- package/dist/{chunk-352j1ayk.js → chunk-y8fnwbx0.js} +51781 -36259
- package/dist/dashboard-source/apps/frontend/app/(protected)/act-on-behalf/actions.ts +12 -12
- package/dist/dashboard-source/apps/frontend/app/(protected)/act-on-behalf/delegations-client.tsx +31 -21
- package/dist/dashboard-source/apps/frontend/app/(protected)/act-on-behalf/page.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/client-index.tsx +1 -12
- package/dist/dashboard-source/apps/frontend/app/(protected)/connected-apps/disconnect-form.tsx +57 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/connected-apps/page.tsx +97 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/(.)[executionId]/client.tsx +1 -1
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/(.)[executionId]/page.tsx +2 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/(.)[executionId]/process-state/page.tsx +2 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/default.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/[executionId]/page.tsx +3 -1
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/[executionId]/process-state/page.tsx +2 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/client-layout.tsx +19 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/default.tsx +6 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/executions-client.tsx +1637 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/layout.tsx +5 -7
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/page.tsx +4 -1589
- package/dist/dashboard-source/apps/frontend/app/(protected)/executions/process-state-page-client.tsx +1 -1
- package/dist/dashboard-source/apps/frontend/app/(protected)/layout.tsx +41 -33
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/@modal/(.)item/[id]/client.tsx +11 -17
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/@modal/(.)item/[id]/page.tsx +2 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/@modal/default.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/[...listPath]/list-page-client.tsx +169 -18
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/[...listPath]/page.tsx +21 -14
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-create-form.tsx +36 -18
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-item-edit-form.tsx +22 -28
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-item-load-error.tsx +49 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-schema-form.tsx +28 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/default.tsx +6 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/hooks/metric-control-url-state.ts +7 -16
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/hooks/use-list-deleted-callback.ts +4 -6
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/hooks/use-list-item-detail.ts +45 -142
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/item/[id]/client.tsx +10 -20
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/item/[id]/page.tsx +2 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/layout.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/lib/list-process-dialog.tsx +72 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/lib/list-refresh-provider.tsx +65 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/lib/list-refresh.ts +162 -16
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/utils.tsx +19 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/org-chart/page.tsx +4 -9
- package/dist/dashboard-source/apps/frontend/app/(protected)/page.tsx +4 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/passkeys/actions.ts +15 -18
- package/dist/dashboard-source/apps/frontend/app/(protected)/passkeys/page.tsx +12 -6
- package/dist/dashboard-source/apps/frontend/app/(protected)/passkeys/passkeys-client.tsx +7 -16
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/@modal/(.)start/[...startStepPath]/client.tsx +26 -48
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/@modal/(.)start/[...startStepPath]/page.tsx +4 -7
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/@modal/default.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/client-layout.tsx +28 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/client.tsx +1 -3
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/components/start-process-form.tsx +193 -117
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/default.tsx +6 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/layout.tsx +7 -9
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/page.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/processes-client.tsx +60 -204
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/start/[...startStepPath]/client.tsx +12 -51
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/start/[...startStepPath]/page.tsx +27 -4
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/page.tsx +5 -4
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/workflow-flow.tsx +0 -5
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/workflow-form-preview-sheet.tsx +26 -19
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/[[...tab]]/page.tsx +5 -2
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/cedar-authorize.ts +85 -9
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/cedar-types.ts +12 -1
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/explorer.tsx +66 -4
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/layout.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/load-handbook.ts +41 -13
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/[invitationId]/page.tsx +2 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/invitation-detail-client.tsx +442 -365
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/new/page.tsx +8 -2
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/page.tsx +7 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations-table.tsx +61 -43
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/page.tsx +6 -67
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/providers/page.tsx +7 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/roles/page.tsx +7 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/settings-client.tsx +111 -189
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/settings-page.tsx +86 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/[userId]/client.tsx +141 -256
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/[userId]/page.tsx +2 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/[userId]/tokens/page.tsx +2 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/page.tsx +7 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users-table.tsx +6 -4
- package/dist/dashboard-source/apps/frontend/app/(protected)/stats/[...statsPath]/page.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/@modal/(.)complete/[...stepPath]/client.tsx +30 -9
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/@modal/(.)complete/[...stepPath]/page.tsx +3 -1
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/@modal/default.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/complete/[...stepPath]/client.tsx +2 -4
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/complete/[...stepPath]/page.tsx +3 -1
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/components/complete-todo-form.tsx +47 -54
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/components/public-completion-correction-form.tsx +37 -54
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/components/todo-form-actions.tsx +1 -1
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/correct/[...stepPath]/page.tsx +3 -1
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/default.tsx +6 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/layout.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/lib/mobile-todo-list.ts +4 -25
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/page.tsx +4 -1315
- package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/to-dos-client.tsx +1282 -0
- package/dist/dashboard-source/apps/frontend/app/api/auth/callback/route.ts +81 -65
- package/dist/dashboard-source/apps/frontend/app/api/auth/delegation/route.ts +8 -2
- package/dist/dashboard-source/apps/frontend/app/api/auth/login/route.ts +0 -1
- package/dist/dashboard-source/apps/frontend/app/api/auth/logout/route.ts +10 -5
- package/dist/dashboard-source/apps/frontend/app/api/auth/passkey/start/route.ts +1 -3
- package/dist/dashboard-source/apps/frontend/app/api/auth/refresh/route.ts +0 -1
- package/dist/dashboard-source/apps/frontend/app/api/auth/revalidate-google/route.ts +68 -0
- package/dist/dashboard-source/apps/frontend/app/api/auth/switch-role/route.ts +1 -3
- package/dist/dashboard-source/apps/frontend/app/api/dev/import-events/route.ts +69 -1
- package/dist/dashboard-source/apps/frontend/app/api/embed/lookup/route.ts +25 -7
- package/dist/dashboard-source/apps/frontend/app/api/embed/submit/route.ts +1 -2
- package/dist/dashboard-source/apps/frontend/app/api/public/start/[address]/route.ts +49 -0
- package/dist/dashboard-source/apps/frontend/app/api/public/to-dos/lookup/route.ts +4 -3
- package/dist/dashboard-source/apps/frontend/app/api/revalidate/route.ts +15 -4
- package/dist/dashboard-source/apps/frontend/app/app-shell.tsx +14 -6
- package/dist/dashboard-source/apps/frontend/app/cli-auth/route.ts +2 -1
- package/dist/dashboard-source/apps/frontend/app/embed/[...startStepPath]/embed-client.tsx +31 -18
- package/dist/dashboard-source/apps/frontend/app/embed/[...startStepPath]/page.tsx +5 -1
- package/dist/dashboard-source/apps/frontend/app/login/page.tsx +4 -4
- package/dist/dashboard-source/apps/frontend/app/login/passkey-button.tsx +11 -6
- package/dist/dashboard-source/apps/frontend/app/login/passkey-help/page.tsx +67 -0
- package/dist/dashboard-source/apps/frontend/app/mcp/[[...endpoint]]/route.ts +44 -0
- package/dist/dashboard-source/apps/frontend/app/public/form/[token]/public-todo-client.tsx +44 -25
- package/dist/dashboard-source/apps/frontend/app/public/start/[address]/form/page.tsx +10 -0
- package/dist/dashboard-source/apps/frontend/app/public/start/[address]/layout.tsx +32 -0
- package/dist/dashboard-source/apps/frontend/app/public/start/[address]/page-client.tsx +319 -0
- package/dist/dashboard-source/apps/frontend/app/public/start/[address]/page-content.tsx +41 -0
- package/dist/dashboard-source/apps/frontend/app/public/start/[address]/page.tsx +10 -0
- package/dist/dashboard-source/apps/frontend/app/public.css +1 -1
- package/dist/dashboard-source/apps/frontend/app/register/passkey/register-passkey-client.tsx +17 -0
- package/dist/dashboard-source/apps/frontend/components/DashboardSection.tsx +9 -15
- package/dist/dashboard-source/apps/frontend/components/Header.tsx +14 -8
- package/dist/dashboard-source/apps/frontend/components/anonymous-page-link.tsx +57 -0
- package/dist/dashboard-source/apps/frontend/components/anonymous-start-form.tsx +24 -0
- package/dist/dashboard-source/apps/frontend/components/app-sidebar.tsx +21 -7
- package/dist/dashboard-source/apps/frontend/components/auth-provider.tsx +12 -7
- package/dist/dashboard-source/apps/frontend/components/browser-only.tsx +19 -0
- package/dist/dashboard-source/apps/frontend/components/config-provider.tsx +0 -1
- package/dist/dashboard-source/apps/frontend/components/delegation-expiry.tsx +24 -13
- package/dist/dashboard-source/apps/frontend/components/form-dialog-content.tsx +22 -2
- package/dist/dashboard-source/apps/frontend/components/journey-timeline.tsx +52 -45
- package/dist/dashboard-source/apps/frontend/components/notification-bell.tsx +0 -1
- package/dist/dashboard-source/apps/frontend/components/sidebar-lists.tsx +0 -1
- package/dist/dashboard-source/apps/frontend/components/token-refresh-scheduler.tsx +38 -11
- package/dist/dashboard-source/apps/frontend/components/ui/sidebar.tsx +0 -1
- package/dist/dashboard-source/apps/frontend/components/ui/tab-pill.tsx +26 -15
- package/dist/dashboard-source/apps/frontend/components/workflow/step-node.tsx +0 -1
- package/dist/dashboard-source/apps/frontend/components/workflow/workflow-edge.tsx +5 -0
- package/dist/dashboard-source/apps/frontend/hooks/use-form-metadata.ts +21 -10
- package/dist/dashboard-source/apps/frontend/hooks/use-process-draft.ts +173 -0
- package/dist/dashboard-source/apps/frontend/hooks/use-weekly-execution-stats.ts +1 -3
- package/dist/dashboard-source/apps/frontend/lib/anonymous-page-form-values.ts +6 -0
- package/dist/dashboard-source/apps/frontend/lib/anonymous-page-server.ts +65 -0
- package/dist/dashboard-source/apps/frontend/lib/appsync-events/adapter.ts +9 -3
- package/dist/dashboard-source/apps/frontend/lib/appsync-events/client.ts +7 -340
- package/dist/dashboard-source/apps/frontend/lib/auth/client-session.ts +2 -0
- package/dist/dashboard-source/apps/frontend/lib/auth/delegations.ts +9 -7
- package/dist/dashboard-source/apps/frontend/lib/auth/google-revalidation.ts +111 -0
- package/dist/dashboard-source/apps/frontend/lib/auth/logout.ts +1 -1
- package/dist/dashboard-source/apps/frontend/lib/auth/passkeys.ts +28 -30
- package/dist/dashboard-source/apps/frontend/lib/auth/providers.ts +10 -0
- package/dist/dashboard-source/apps/frontend/lib/auth/realtime-session-token.ts +1 -0
- package/dist/dashboard-source/apps/frontend/lib/auth/reauthentication-state.ts +4 -4
- package/dist/dashboard-source/apps/frontend/lib/auth/session-admission.ts +11 -7
- package/dist/dashboard-source/apps/frontend/lib/auth/session.ts +27 -10
- package/dist/dashboard-source/apps/frontend/lib/auth/ssr-session.ts +76 -9
- package/dist/dashboard-source/apps/frontend/lib/auth/verify-passkey.ts +25 -3
- package/dist/dashboard-source/apps/frontend/lib/collections/collection-provider-factory.tsx +115 -23
- package/dist/dashboard-source/apps/frontend/lib/collections/draft-process-execution.ts +1 -8
- package/dist/dashboard-source/apps/frontend/lib/collections/execution.ts +6 -2
- package/dist/dashboard-source/apps/frontend/lib/collections/graphql-stream.ts +21 -1
- package/dist/dashboard-source/apps/frontend/lib/collections/process-collection-provider.tsx +3 -0
- package/dist/dashboard-source/apps/frontend/lib/collections/process.ts +8 -2
- package/dist/dashboard-source/apps/frontend/lib/collections/replication-factory.ts +16 -4
- package/dist/dashboard-source/apps/frontend/lib/collections/todo.ts +1 -1
- package/dist/dashboard-source/apps/frontend/lib/dev/import-completed-query-invalidation.tsx +66 -9
- package/dist/dashboard-source/apps/frontend/lib/dev/import-completed-refresh.ts +10 -6
- package/dist/dashboard-source/apps/frontend/lib/effect/navigation.ts +4 -0
- package/dist/dashboard-source/apps/frontend/lib/effect/page-runtime.ts +29 -0
- package/dist/dashboard-source/apps/frontend/lib/effect/params.ts +18 -12
- package/dist/dashboard-source/apps/frontend/lib/effect/run-effect.ts +1 -1
- package/dist/dashboard-source/apps/frontend/lib/effect/runtime.ts +19 -23
- package/dist/dashboard-source/apps/frontend/lib/effect/services/access-token.ts +9 -12
- package/dist/dashboard-source/apps/frontend/lib/effect/services/authorization.ts +12 -12
- package/dist/dashboard-source/apps/frontend/lib/effect/services/form-validation.ts +20 -18
- package/dist/dashboard-source/apps/frontend/lib/effect/services/graphql.ts +32 -16
- package/dist/dashboard-source/apps/frontend/lib/embed-form-server.ts +35 -0
- package/dist/dashboard-source/apps/frontend/lib/embed-manifest.ts +10 -103
- package/dist/dashboard-source/apps/frontend/lib/forms/invitation.ts +43 -0
- package/dist/dashboard-source/apps/frontend/lib/forms/provider-user.ts +64 -0
- package/dist/dashboard-source/apps/frontend/lib/frontend-form-loaders.ts +40 -0
- package/dist/dashboard-source/apps/frontend/lib/frontend-manifest.ts +1 -33
- package/dist/dashboard-source/apps/frontend/lib/generated/gql/gql.ts +123 -33
- package/dist/dashboard-source/apps/frontend/lib/generated/gql/graphql.ts +168 -30
- package/dist/dashboard-source/apps/frontend/lib/generated/gql/index.ts +1 -0
- package/dist/dashboard-source/apps/frontend/lib/graphql/anonymous-page.ts +27 -0
- package/dist/dashboard-source/apps/frontend/lib/graphql/dependent-lookup-query.ts +1 -0
- package/dist/dashboard-source/apps/frontend/lib/graphql/list-queries.ts +34 -29
- package/dist/dashboard-source/apps/frontend/lib/graphql/lookup-provider.tsx +82 -10
- package/dist/dashboard-source/apps/frontend/lib/graphql/org-chart-operations.ts +2 -5
- package/dist/dashboard-source/apps/frontend/lib/graphql/queries.ts +25 -4
- package/dist/dashboard-source/apps/frontend/lib/graphql/server-client.ts +11 -0
- package/dist/dashboard-source/apps/frontend/lib/graphql/settings-queries.ts +13 -104
- package/dist/dashboard-source/apps/frontend/lib/graphql/user-queries.ts +11 -4
- package/dist/dashboard-source/apps/frontend/lib/graphql/workflow-operations.ts +1 -3
- package/dist/dashboard-source/apps/frontend/lib/graphql/workflow-queries.ts +1 -0
- package/dist/dashboard-source/apps/frontend/lib/list-detail-selection.ts +54 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/executions.ts +110 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/list-writes.ts +395 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/lists.ts +263 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/oauth.ts +889 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/origin.ts +50 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/processes.ts +436 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/read-tool.ts +72 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/result.ts +4 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/server.ts +71 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/store.ts +107 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/todos.ts +260 -0
- package/dist/dashboard-source/apps/frontend/lib/notifications/notification-preference.ts +0 -1
- package/dist/dashboard-source/apps/frontend/lib/notifications/todo-notification-observer.ts +0 -5
- package/dist/dashboard-source/apps/frontend/lib/org-chart-data.ts +0 -2
- package/dist/dashboard-source/apps/frontend/lib/org-identity.ts +6 -4
- package/dist/dashboard-source/apps/frontend/lib/organisation-form-loaders.ts +4 -0
- package/dist/dashboard-source/apps/frontend/lib/public-todo-form-runtime.ts +0 -1
- package/dist/dashboard-source/apps/frontend/lib/public-todo-model.ts +39 -139
- package/dist/dashboard-source/apps/frontend/lib/public-todo-server.ts +17 -16
- package/dist/dashboard-source/apps/frontend/lib/query-client.ts +0 -1
- package/dist/dashboard-source/apps/frontend/lib/todo-utils.ts +1 -77
- package/dist/dashboard-source/apps/frontend/lib/workflow/layout.ts +3 -7
- package/dist/dashboard-source/apps/frontend/next.config.ts +33 -13
- package/dist/dashboard-source/apps/frontend/package.json +47 -47
- package/dist/dashboard-source/apps/frontend/proxy.ts +72 -14
- package/dist/dashboard-source/modules/auth-local-cedar/src/index.ts +0 -3
- package/dist/dashboard-source/modules/auth-local-cedar/src/lib/auth-local-cedar.ts +165 -233
- package/dist/dashboard-source/modules/auth-local-cedar/src/lib/cedar-reload-notifier.ts +4 -3
- package/dist/dashboard-source/modules/auth-local-cedar/src/lib/config-base.ts +111 -75
- package/dist/dashboard-source/modules/auth-local-cedar/src/lib/policy-watcher.ts +14 -18
- package/dist/dashboard-source/modules/auth-policy/src/index.ts +1 -0
- package/dist/dashboard-source/modules/auth-policy/src/lib/auth-policy.ts +19 -37
- package/dist/dashboard-source/modules/auth-policy/src/lib/current-principal.ts +33 -29
- package/dist/dashboard-source/modules/auth-policy/src/lib/policy-revision.ts +23 -0
- package/dist/dashboard-source/modules/auth-policy/src/lib/types.ts +24 -49
- package/dist/dashboard-source/modules/auth-session/src/index.ts +4 -0
- package/dist/dashboard-source/modules/auth-session/src/lib/project-subscription.ts +13 -0
- package/dist/dashboard-source/modules/auth-session/src/lib/realtime-recipient.ts +10 -2
- package/dist/dashboard-source/modules/auth-session/src/lib/subjects.ts +82 -8
- package/dist/dashboard-source/modules/auth-session/src/lib/workload-access.ts +48 -0
- package/dist/dashboard-source/modules/auth-session/src/lib/workload-audit.ts +52 -0
- package/dist/dashboard-source/modules/aws-common/src/index.ts +0 -1
- package/dist/dashboard-source/modules/effect-json-logger/src/lib/effect-json-logger.ts +6 -9
- package/dist/dashboard-source/modules/form/src/hooks/use-local-storage.ts +5 -3
- package/dist/dashboard-source/modules/form/src/index.ts +1 -10
- package/dist/dashboard-source/modules/form/src/lib/effect-schema-form.tsx +1271 -0
- package/dist/dashboard-source/modules/form/src/lib/form-actions.ts +26 -0
- package/dist/dashboard-source/modules/form/src/lib/form-prefill.tsx +79 -0
- package/dist/dashboard-source/modules/form/src/lib/initial-focus.ts +31 -0
- package/dist/dashboard-source/modules/form/src/lib/lookup-context.tsx +18 -0
- package/dist/dashboard-source/modules/form/src/lib/plugin-registry.ts +4 -0
- package/dist/dashboard-source/modules/form/src/lib/plugin-scripts.ts +26 -0
- package/dist/dashboard-source/modules/form/src/lib/registered-plugin-field.tsx +57 -0
- package/dist/dashboard-source/modules/form/src/lib/schema-lookup.tsx +124 -0
- package/dist/dashboard-source/modules/form/src/lib/schema-typeahead.tsx +522 -0
- package/dist/dashboard-source/modules/form/src/lib/validation-logic.ts +172 -0
- package/dist/dashboard-source/modules/form-schema/src/index.ts +4 -1
- package/dist/dashboard-source/modules/form-schema/src/lib/annotation-helpers.ts +19 -14
- package/dist/dashboard-source/modules/form-schema/src/lib/email.ts +13 -11
- package/dist/dashboard-source/modules/form-schema/src/lib/field-count.ts +15 -13
- package/dist/dashboard-source/modules/form-schema/src/lib/form-annotations.ts +14 -0
- package/dist/dashboard-source/modules/form-schema/src/lib/form-presentation.ts +33 -0
- package/dist/dashboard-source/modules/form-schema/src/lib/form-schema.ts +186 -80
- package/dist/dashboard-source/modules/form-schema/src/lib/number-from-string.ts +26 -0
- package/dist/dashboard-source/modules/form-schema/src/lib/phone.ts +8 -7
- package/dist/dashboard-source/modules/form-schema/src/lib/public-completion-correction.ts +7 -0
- package/dist/dashboard-source/modules/form-schema/src/lib/search-lookup-items.ts +27 -0
- package/dist/dashboard-source/modules/form-submission-schema/src/index.ts +5 -0
- package/dist/dashboard-source/modules/form-submission-schema/src/lib/executable-rules.ts +379 -0
- package/dist/dashboard-source/modules/form-submission-schema/src/lib/form-submission-schema.ts +475 -0
- package/dist/dashboard-source/modules/form-submission-schema/src/lib/json-schema.ts +58 -0
- package/dist/dashboard-source/modules/form-submission-schema/src/lib/schema-defaults.ts +158 -0
- package/dist/dashboard-source/modules/form-submission-schema/src/lib/submission-utils.ts +75 -0
- package/dist/dashboard-source/modules/frontend-manifest/src/lib/browser-plugin-artifact.ts +46 -0
- package/dist/dashboard-source/modules/frontend-manifest/src/lib/frontend-manifest.ts +37 -30
- package/dist/dashboard-source/modules/frontend-plugin-host/src/lib/frontend-plugin-host.ts +9 -1
- package/dist/dashboard-source/modules/openauth/src/client.ts +25 -17
- package/dist/dashboard-source/modules/openauth/src/util.ts +16 -0
- package/dist/dashboard-source/modules/{aws-common/src/lib/project-balance-admission.ts → project-accounting/src/admission.ts} +4 -8
- package/dist/dashboard-source/modules/realtime-client/src/appsync-client.ts +377 -0
- package/dist/dashboard-source/modules/realtime-client/src/index.ts +5 -0
- package/dist/dashboard-source/modules/realtime-client/src/subscription-presence.ts +163 -0
- package/dist/dashboard-source/modules/request-time/src/lib/request-time.ts +6 -24
- package/dist/dashboard-source/modules/rxdb-collections/generated/execution-schema.json +28 -21
- package/dist/dashboard-source/modules/rxdb-collections/src/lib/rxdb-collections.ts +25 -18
- package/dist/dashboard-source/modules/rxdb-collections/src/lib/to-rxdb-schema.ts +60 -10
- package/dist/dashboard-source/modules/shadcn-components/src/index.ts +18 -2
- package/dist/dashboard-source/modules/shadcn-components/src/lib/date-calendar.tsx +93 -0
- package/dist/dashboard-source/modules/shadcn-components/src/lib/date-field.tsx +147 -48
- package/dist/dashboard-source/modules/shadcn-components/src/lib/date-time-display.tsx +273 -0
- package/dist/dashboard-source/modules/shadcn-components/src/lib/local-date-time-input.tsx +108 -0
- package/dist/dashboard-source/modules/shadcn-components/src/lib/lookup-field.tsx +237 -351
- package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/popover.tsx +2 -1
- package/dist/dashboard-source.json +47 -47
- package/dist/graphql-server.mjs +272 -200
- package/dist/job-worker-supervisor.mjs +262 -0
- package/dist/job-worker.mjs +234 -133
- package/dist/main.mjs +30 -6
- package/dist/prepare-dashboard.mjs +8 -8
- package/dist/resources/cedar/policies.cedar +80 -38
- package/dist/resources/cedar/schema.cedarschema +39 -21
- package/dist/resources/graphql-schema/rxdb.graphql +2 -0
- package/dist/resources/graphql-schema/system.graphql +191 -51
- package/package.json +63 -62
- package/dist/chunk-6ntmymmx.js +0 -85
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/utils.ts +0 -20
- package/dist/dashboard-source/apps/frontend/app/(protected)/processes/components/process-form-actions.tsx +0 -105
- package/dist/dashboard-source/apps/frontend/hooks/use-draft-process-save.ts +0 -189
- package/dist/dashboard-source/apps/frontend/hooks/use-draft-state.ts +0 -79
- package/dist/dashboard-source/apps/frontend/hooks/use-processes-query.ts +0 -56
- package/dist/dashboard-source/modules/form/src/lib/ajv-standard-schema.ts +0 -152
- package/dist/dashboard-source/modules/form/src/lib/client-components-to-form.tsx +0 -1421
- package/dist/dashboard-source/modules/form/src/lib/friendly-validation-message.ts +0 -85
- package/dist/dashboard-source/modules/form/src/lib/walker.tsx +0 -1549
- package/dist/dashboard-source/modules/form-client-representation/src/lib/client-form-definition.ts +0 -440
- package/dist/dashboard-source/modules/form-client-representation/src/lib/plugin-registry.ts +0 -13
- package/dist/dashboard-source/modules/form-client-representation/src/lib/types.ts +0 -336
- package/dist/dashboard-source/modules/form-rule/src/index.ts +0 -21
- package/dist/dashboard-source/modules/form-rule/src/lib/evaluator.ts +0 -531
- package/dist/dashboard-source/modules/form-rule/src/lib/paths.ts +0 -102
- package/dist/dashboard-source/modules/form-rule/src/lib/types.ts +0 -121
- package/dist/dashboard-source/modules/form-schema/src/lib/property-signature.ts +0 -45
|
@@ -0,0 +1,889 @@
|
|
|
1
|
+
import "server-only"
|
|
2
|
+
import { createHash, randomBytes, timingSafeEqual } from "node:crypto"
|
|
3
|
+
import { DateTime, Result, Schema } from "effect"
|
|
4
|
+
import { type NextRequest, NextResponse } from "next/server"
|
|
5
|
+
import { type ProviderUserSession, subjects } from "../../../../modules/auth-session/src/index.ts"
|
|
6
|
+
import { type Tokens, createClient } from "../../../../modules/openauth/src/client.ts"
|
|
7
|
+
import { OAuthMetadataFetchError } from "../../../../modules/openauth/src/error.ts"
|
|
8
|
+
import {
|
|
9
|
+
connectedAppsPath,
|
|
10
|
+
consentPath,
|
|
11
|
+
cookieName,
|
|
12
|
+
loopback,
|
|
13
|
+
mcpOrigin,
|
|
14
|
+
opaque,
|
|
15
|
+
} from "./origin.ts"
|
|
16
|
+
import { bucket } from "./store.ts"
|
|
17
|
+
import { getAuthClient } from "@/lib/auth/client"
|
|
18
|
+
import { getFrontendAuthClientConfig } from "@/lib/auth/issuer"
|
|
19
|
+
import { decodeJwtPayload } from "@/lib/auth/jwt"
|
|
20
|
+
import { acceptVerifiedSession } from "@/lib/auth/ssr-session"
|
|
21
|
+
import { getFrontendManifest } from "@/lib/frontend-manifest-store"
|
|
22
|
+
|
|
23
|
+
const VIEW = "work:read"
|
|
24
|
+
const ACT = "work:act"
|
|
25
|
+
const pendingLifetime = 600_000
|
|
26
|
+
const codeLifetime = 60_000
|
|
27
|
+
const registrationLifetime = 3_600_000
|
|
28
|
+
// Outlast the serving Lambda's 20-second timeout but release after a cold exit.
|
|
29
|
+
const renewalLease = 30_000
|
|
30
|
+
const headers = {
|
|
31
|
+
"Cache-Control": "no-store",
|
|
32
|
+
"Referrer-Policy": "no-referrer",
|
|
33
|
+
"Content-Security-Policy":
|
|
34
|
+
"default-src 'none'; frame-ancestors 'none'; form-action 'self'; base-uri 'none'",
|
|
35
|
+
"X-Content-Type-Options": "nosniff",
|
|
36
|
+
}
|
|
37
|
+
const random = () => randomBytes(32).toString("base64url")
|
|
38
|
+
const hash = (text: string) =>
|
|
39
|
+
createHash("sha256").update(text).digest("base64url")
|
|
40
|
+
const Grant = Schema.Struct({
|
|
41
|
+
id: Schema.String,
|
|
42
|
+
clientId: Schema.String,
|
|
43
|
+
userId: Schema.String,
|
|
44
|
+
scope: Schema.Literals([VIEW, `${VIEW} ${ACT}`]),
|
|
45
|
+
authorisedAt: Schema.Int,
|
|
46
|
+
})
|
|
47
|
+
type Grant = typeof Grant.Type
|
|
48
|
+
const Client = Schema.Struct({
|
|
49
|
+
name: Schema.String,
|
|
50
|
+
redirects: Schema.Array(Schema.String),
|
|
51
|
+
grants: Schema.Array(Grant),
|
|
52
|
+
})
|
|
53
|
+
const authFields = {
|
|
54
|
+
clientId: Schema.String,
|
|
55
|
+
redirect: Schema.String,
|
|
56
|
+
challenge: Schema.String,
|
|
57
|
+
state: Schema.String,
|
|
58
|
+
}
|
|
59
|
+
const Human = Schema.Struct({
|
|
60
|
+
email: Schema.String,
|
|
61
|
+
userId: Schema.String,
|
|
62
|
+
tokens: Schema.Struct({
|
|
63
|
+
access: Schema.String,
|
|
64
|
+
refresh: Schema.String,
|
|
65
|
+
expiresIn: Schema.Number,
|
|
66
|
+
refreshExpiresIn: Schema.optional(Schema.Number),
|
|
67
|
+
}),
|
|
68
|
+
expires: Schema.Number,
|
|
69
|
+
ssoDeadline: Schema.optional(Schema.Number),
|
|
70
|
+
})
|
|
71
|
+
type Human = typeof Human.Type
|
|
72
|
+
const Pending = Schema.Struct({
|
|
73
|
+
...authFields,
|
|
74
|
+
browser: Schema.String,
|
|
75
|
+
expires: Schema.Number,
|
|
76
|
+
grantsAtStart: Schema.Array(Grant),
|
|
77
|
+
human: Schema.optional(Human),
|
|
78
|
+
})
|
|
79
|
+
const Code = Schema.Struct({ ...authFields, grant: Grant, human: Human })
|
|
80
|
+
type Code = typeof Code.Type
|
|
81
|
+
const Access = Schema.Struct({ grant: Grant, token: Schema.String })
|
|
82
|
+
const Renewal = Schema.Struct({
|
|
83
|
+
grant: Grant,
|
|
84
|
+
expires: Schema.Number,
|
|
85
|
+
ssoDeadline: Schema.optional(Schema.Number),
|
|
86
|
+
issuerRefreshToken: Schema.String,
|
|
87
|
+
lockedUntil: Schema.Number,
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const clients = (origin: string) => bucket(origin, "client", Client)
|
|
91
|
+
const pending = (origin: string) => bucket(origin, "pending", Pending)
|
|
92
|
+
const codes = (origin: string) => bucket(origin, "code", Code)
|
|
93
|
+
const access = (origin: string) => bucket(origin, "access", Access)
|
|
94
|
+
const refresh = (origin: string) => bucket(origin, "refresh", Renewal)
|
|
95
|
+
|
|
96
|
+
const registeredClient = (origin: string, clientId: string) =>
|
|
97
|
+
opaque.test(clientId) ? clients(origin).get(clientId) : undefined
|
|
98
|
+
|
|
99
|
+
const activeGrant = async (origin: string, grant: Grant) =>
|
|
100
|
+
(await registeredClient(origin, grant.clientId))?.value.grants.some(
|
|
101
|
+
(current) => current.id === grant.id,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
const location = (url: URL, status = 303) =>
|
|
105
|
+
new NextResponse(null, {
|
|
106
|
+
status,
|
|
107
|
+
headers: { ...headers, Location: url.href },
|
|
108
|
+
})
|
|
109
|
+
const oauthError = (error: string, status = 400) =>
|
|
110
|
+
Response.json({ error }, { status, headers })
|
|
111
|
+
|
|
112
|
+
const resourceUrl = (origin: string) => `${origin}/mcp`
|
|
113
|
+
const issuerUrl = (origin: string) =>
|
|
114
|
+
process.env["PF_RUNTIME_MODE"] === "deployed" ? resourceUrl(origin) : origin
|
|
115
|
+
export const resourceMetadata = (origin: string): Response =>
|
|
116
|
+
Response.json(
|
|
117
|
+
{
|
|
118
|
+
resource: resourceUrl(origin),
|
|
119
|
+
authorization_servers: [issuerUrl(origin)],
|
|
120
|
+
scopes_supported: [VIEW, ACT],
|
|
121
|
+
bearer_methods_supported: ["header"],
|
|
122
|
+
},
|
|
123
|
+
{ headers },
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
export const authMetadata = (origin: string): Response =>
|
|
127
|
+
Response.json(
|
|
128
|
+
{
|
|
129
|
+
issuer: issuerUrl(origin),
|
|
130
|
+
authorization_endpoint: `${origin}/mcp/authorize`,
|
|
131
|
+
token_endpoint: `${origin}/mcp/token`,
|
|
132
|
+
registration_endpoint: `${origin}/mcp/register`,
|
|
133
|
+
response_types_supported: ["code"],
|
|
134
|
+
code_challenge_methods_supported: ["S256"],
|
|
135
|
+
grant_types_supported: ["authorization_code", "refresh_token"],
|
|
136
|
+
token_endpoint_auth_methods_supported: ["none"],
|
|
137
|
+
scopes_supported: [VIEW, ACT],
|
|
138
|
+
},
|
|
139
|
+
{ headers },
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
const Registration = Schema.Struct({
|
|
143
|
+
client_name: Schema.NonEmptyString.check(Schema.isMaxLength(100)),
|
|
144
|
+
redirect_uris: Schema.NonEmptyArray(
|
|
145
|
+
Schema.String.check(Schema.isMaxLength(2048)),
|
|
146
|
+
).check(Schema.isMaxLength(5)),
|
|
147
|
+
token_endpoint_auth_method: Schema.optional(Schema.Literal("none")),
|
|
148
|
+
})
|
|
149
|
+
const validRedirect = (uri: string) => {
|
|
150
|
+
try {
|
|
151
|
+
const url = new URL(uri)
|
|
152
|
+
return (
|
|
153
|
+
!uri.includes("#") &&
|
|
154
|
+
((loopback(url) && Boolean(url.port)) ||
|
|
155
|
+
(process.env["PF_RUNTIME_MODE"] === "deployed" &&
|
|
156
|
+
url.protocol === "https:" &&
|
|
157
|
+
!url.username &&
|
|
158
|
+
!url.password))
|
|
159
|
+
)
|
|
160
|
+
} catch {
|
|
161
|
+
return false
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export const register = async (
|
|
166
|
+
request: Request,
|
|
167
|
+
origin: string,
|
|
168
|
+
): Promise<Response> => {
|
|
169
|
+
const body = await request.json().catch(() => null)
|
|
170
|
+
const parsed = Schema.decodeUnknownResult(Registration)(body)
|
|
171
|
+
if (Result.isFailure(parsed)) return oauthError("invalid_client_metadata")
|
|
172
|
+
const { client_name, redirect_uris } = parsed.success
|
|
173
|
+
if (!redirect_uris.every(validRedirect))
|
|
174
|
+
return oauthError("invalid_redirect_uri")
|
|
175
|
+
const store = clients(origin)
|
|
176
|
+
if (process.env["PF_RUNTIME_MODE"] !== "deployed") {
|
|
177
|
+
let count = 0
|
|
178
|
+
for await (const _ of store.entries()) {
|
|
179
|
+
if (++count >= 1024) return oauthError("temporarily_unavailable", 503)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const id = random()
|
|
183
|
+
const saved = await store.put(
|
|
184
|
+
id,
|
|
185
|
+
{
|
|
186
|
+
name: client_name,
|
|
187
|
+
redirects: redirect_uris,
|
|
188
|
+
grants: [],
|
|
189
|
+
},
|
|
190
|
+
Date.now() + registrationLifetime,
|
|
191
|
+
)
|
|
192
|
+
if (!saved) return oauthError("temporarily_unavailable", 503)
|
|
193
|
+
return Response.json(
|
|
194
|
+
{
|
|
195
|
+
client_id: id,
|
|
196
|
+
client_name,
|
|
197
|
+
redirect_uris,
|
|
198
|
+
token_endpoint_auth_method: "none",
|
|
199
|
+
grant_types: ["authorization_code", "refresh_token"],
|
|
200
|
+
response_types: ["code"],
|
|
201
|
+
},
|
|
202
|
+
{ status: 201, headers },
|
|
203
|
+
)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const readAuthorization = (origin: string, query: URLSearchParams) => {
|
|
207
|
+
const clientId = query.get("client_id") ?? ""
|
|
208
|
+
const redirect = query.get("redirect_uri") ?? ""
|
|
209
|
+
const challenge = query.get("code_challenge") ?? ""
|
|
210
|
+
const state = query.get("state") ?? ""
|
|
211
|
+
const resource = query.get("resource")
|
|
212
|
+
if (
|
|
213
|
+
query.get("response_type") !== "code" ||
|
|
214
|
+
query.get("code_challenge_method") !== "S256" ||
|
|
215
|
+
!opaque.test(challenge) ||
|
|
216
|
+
state.length > 512 ||
|
|
217
|
+
(resource !== null && resource !== resourceUrl(origin))
|
|
218
|
+
)
|
|
219
|
+
return undefined
|
|
220
|
+
return { clientId, redirect, challenge, state }
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const consentUrl = (origin: string, id: string) =>
|
|
224
|
+
new URL(`${consentPath}?id=${id}`, origin)
|
|
225
|
+
const cookieOptions = (origin: string) =>
|
|
226
|
+
({
|
|
227
|
+
httpOnly: true,
|
|
228
|
+
sameSite: "lax",
|
|
229
|
+
path: "/",
|
|
230
|
+
secure: origin.startsWith("https:"),
|
|
231
|
+
}) as const
|
|
232
|
+
|
|
233
|
+
export const authorize = async (
|
|
234
|
+
request: NextRequest,
|
|
235
|
+
origin: string,
|
|
236
|
+
): Promise<Response> => {
|
|
237
|
+
const authorization = readAuthorization(origin, request.nextUrl.searchParams)
|
|
238
|
+
if (!authorization) return oauthError("invalid_request")
|
|
239
|
+
const client = await registeredClient(origin, authorization.clientId)
|
|
240
|
+
if (!client?.value.redirects.includes(authorization.redirect))
|
|
241
|
+
return oauthError("invalid_request")
|
|
242
|
+
const store = pending(origin)
|
|
243
|
+
if (process.env["PF_RUNTIME_MODE"] !== "deployed") {
|
|
244
|
+
let count = 0
|
|
245
|
+
for await (const _ of store.entries()) {
|
|
246
|
+
if (++count >= 256) return oauthError("temporarily_unavailable", 503)
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const id = random()
|
|
250
|
+
const browser = random()
|
|
251
|
+
const expires = Date.now() + pendingLifetime
|
|
252
|
+
const saved = await store.put(
|
|
253
|
+
id,
|
|
254
|
+
{
|
|
255
|
+
...authorization,
|
|
256
|
+
// Resolve the grant after sign-in, but do not revive one disconnected
|
|
257
|
+
// while this authorization was in flight.
|
|
258
|
+
grantsAtStart: client.value.grants,
|
|
259
|
+
browser,
|
|
260
|
+
expires,
|
|
261
|
+
},
|
|
262
|
+
expires,
|
|
263
|
+
)
|
|
264
|
+
if (!saved) return oauthError("temporarily_unavailable", 503)
|
|
265
|
+
const consent = consentUrl(origin, id)
|
|
266
|
+
const login = new URL("/login", origin)
|
|
267
|
+
login.searchParams.set("redirect", `${consent.pathname}${consent.search}`)
|
|
268
|
+
const response = location(login)
|
|
269
|
+
response.cookies.set(cookieName(origin, id), browser, {
|
|
270
|
+
...cookieOptions(origin),
|
|
271
|
+
maxAge: pendingLifetime / 1000,
|
|
272
|
+
})
|
|
273
|
+
return response
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const browserPending = async (request: NextRequest, target: string | null) => {
|
|
277
|
+
const origin = mcpOrigin(request)
|
|
278
|
+
if (!origin || !target?.startsWith(`${consentPath}?`)) return undefined
|
|
279
|
+
const id = new URL(target, origin).searchParams.get("id") ?? ""
|
|
280
|
+
if (!opaque.test(id)) return undefined
|
|
281
|
+
const browser = request.cookies.get(cookieName(origin, id))?.value
|
|
282
|
+
if (!browser) return undefined
|
|
283
|
+
const record = await pending(origin).get(id)
|
|
284
|
+
if (!record || browser !== record.value.browser) return undefined
|
|
285
|
+
return { record, origin, id }
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const verifyHuman = async (
|
|
289
|
+
tokens: Tokens,
|
|
290
|
+
): Promise<{ human: Human; session: ProviderUserSession } | undefined> => {
|
|
291
|
+
const verified = await getAuthClient().verify(
|
|
292
|
+
subjects,
|
|
293
|
+
tokens.access,
|
|
294
|
+
undefined,
|
|
295
|
+
)
|
|
296
|
+
if (verified.err instanceof OAuthMetadataFetchError) throw verified.err
|
|
297
|
+
if (verified.err) return undefined
|
|
298
|
+
const session = verified.subject.properties
|
|
299
|
+
if (!("email" in session) || !session.humanSession || session.delegation)
|
|
300
|
+
return undefined
|
|
301
|
+
const expiry = decodeJwtPayload(tokens.access)?.exp
|
|
302
|
+
const ssoDeadline = session.sso?.expiresAt
|
|
303
|
+
const expires = Math.min((expiry ?? 0) * 1000, ssoDeadline ?? Infinity)
|
|
304
|
+
if (expires <= Date.now()) return undefined
|
|
305
|
+
return {
|
|
306
|
+
session,
|
|
307
|
+
human: {
|
|
308
|
+
email: session.email,
|
|
309
|
+
userId: session.userId,
|
|
310
|
+
tokens,
|
|
311
|
+
expires,
|
|
312
|
+
ssoDeadline,
|
|
313
|
+
},
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export const finishMcpLogin = async (
|
|
318
|
+
request: NextRequest,
|
|
319
|
+
redirect: string | null,
|
|
320
|
+
tokens: Tokens,
|
|
321
|
+
): Promise<NextResponse | undefined> => {
|
|
322
|
+
if (!redirect?.startsWith(`${consentPath}?`)) return undefined
|
|
323
|
+
const flow = await browserPending(request, redirect)
|
|
324
|
+
if (!flow || flow.record.value.human)
|
|
325
|
+
return NextResponse.json(
|
|
326
|
+
{ error: "Restart the MCP connection." },
|
|
327
|
+
{ status: 400, headers },
|
|
328
|
+
)
|
|
329
|
+
const verified = await verifyHuman(tokens).catch(() => undefined)
|
|
330
|
+
if (
|
|
331
|
+
!verified ||
|
|
332
|
+
!(await acceptVerifiedSession(verified.session, tokens.access).catch(
|
|
333
|
+
() => null,
|
|
334
|
+
))
|
|
335
|
+
)
|
|
336
|
+
return NextResponse.json(
|
|
337
|
+
{ error: "MCP requires a human sign-in." },
|
|
338
|
+
{ status: 403, headers },
|
|
339
|
+
)
|
|
340
|
+
const entry = flow.record.value
|
|
341
|
+
if (
|
|
342
|
+
entry.expires <= Date.now() ||
|
|
343
|
+
!(await pending(flow.origin).put(
|
|
344
|
+
flow.id,
|
|
345
|
+
{ ...entry, human: verified.human },
|
|
346
|
+
entry.expires,
|
|
347
|
+
flow.record,
|
|
348
|
+
))
|
|
349
|
+
)
|
|
350
|
+
return NextResponse.json(
|
|
351
|
+
{ error: "Restart the MCP connection." },
|
|
352
|
+
{ status: 400, headers },
|
|
353
|
+
)
|
|
354
|
+
return location(consentUrl(flow.origin, flow.id))
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const escapeHtml = (text: string) =>
|
|
358
|
+
text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">")
|
|
359
|
+
|
|
360
|
+
const finishAuthorization = async (
|
|
361
|
+
{
|
|
362
|
+
record: { value: entry },
|
|
363
|
+
origin,
|
|
364
|
+
id,
|
|
365
|
+
}: NonNullable<Awaited<ReturnType<typeof browserPending>>>,
|
|
366
|
+
approved?: Pick<Code, "grant" | "human">,
|
|
367
|
+
): Promise<Response> => {
|
|
368
|
+
const redirect = new URL(entry.redirect)
|
|
369
|
+
if (entry.state) redirect.searchParams.set("state", entry.state)
|
|
370
|
+
if (approved) {
|
|
371
|
+
const code = random()
|
|
372
|
+
const saved = await codes(origin).put(
|
|
373
|
+
hash(code),
|
|
374
|
+
{
|
|
375
|
+
clientId: entry.clientId,
|
|
376
|
+
challenge: entry.challenge,
|
|
377
|
+
redirect: entry.redirect,
|
|
378
|
+
state: entry.state,
|
|
379
|
+
...approved,
|
|
380
|
+
},
|
|
381
|
+
Date.now() + codeLifetime,
|
|
382
|
+
)
|
|
383
|
+
if (!saved) return oauthError("temporarily_unavailable", 503)
|
|
384
|
+
redirect.searchParams.set("code", code)
|
|
385
|
+
} else {
|
|
386
|
+
redirect.searchParams.set("error", "access_denied")
|
|
387
|
+
}
|
|
388
|
+
const response = location(redirect)
|
|
389
|
+
response.cookies.set(cookieName(origin, id), "", {
|
|
390
|
+
...cookieOptions(origin),
|
|
391
|
+
maxAge: 0,
|
|
392
|
+
})
|
|
393
|
+
return response
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
const sameOriginForm = (request: Request, origin: string) =>
|
|
397
|
+
request.headers.get("origin") === origin &&
|
|
398
|
+
request.headers.get("content-type")?.split(";")[0] ===
|
|
399
|
+
"application/x-www-form-urlencoded"
|
|
400
|
+
|
|
401
|
+
export const listConnections = async (origin: string, userId: string) => {
|
|
402
|
+
const connections = []
|
|
403
|
+
for await (const { value } of clients(origin).entries()) {
|
|
404
|
+
const grant = value.grants.find((grant) => grant.userId === userId)
|
|
405
|
+
if (grant) {
|
|
406
|
+
connections.push({
|
|
407
|
+
id: grant.id,
|
|
408
|
+
clientId: grant.clientId,
|
|
409
|
+
name: value.name,
|
|
410
|
+
access: grant.scope === VIEW ? "View work" : "View and act",
|
|
411
|
+
authorisedAt: grant.authorisedAt,
|
|
412
|
+
})
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
return connections
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
export const disconnectConnection = async ({
|
|
419
|
+
origin,
|
|
420
|
+
userId,
|
|
421
|
+
clientId,
|
|
422
|
+
grantId,
|
|
423
|
+
}: {
|
|
424
|
+
origin: string
|
|
425
|
+
userId: string
|
|
426
|
+
clientId: string
|
|
427
|
+
grantId: string
|
|
428
|
+
}): Promise<boolean> => {
|
|
429
|
+
const client = await registeredClient(origin, clientId)
|
|
430
|
+
if (
|
|
431
|
+
!client?.value.grants.some(
|
|
432
|
+
(grant) => grant.userId === userId && grant.id === grantId,
|
|
433
|
+
)
|
|
434
|
+
)
|
|
435
|
+
return false
|
|
436
|
+
const grants = client.value.grants.filter((grant) => grant.id !== grantId)
|
|
437
|
+
// Codes and tokens check the current grant ID, not just the registration.
|
|
438
|
+
// Revoking it invalidates every credential without touching Dashboard cookies.
|
|
439
|
+
return Boolean(
|
|
440
|
+
await clients(origin).put(
|
|
441
|
+
clientId,
|
|
442
|
+
{ ...client.value, grants },
|
|
443
|
+
grants.length === 0 ? Date.now() + registrationLifetime : undefined,
|
|
444
|
+
client,
|
|
445
|
+
),
|
|
446
|
+
)
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const consentStyles = `
|
|
450
|
+
* { box-sizing: border-box; }
|
|
451
|
+
body {
|
|
452
|
+
margin: 0;
|
|
453
|
+
padding: clamp(0.75rem, 4vw, 3rem);
|
|
454
|
+
background: #f8fafc;
|
|
455
|
+
color: #0f172a;
|
|
456
|
+
font: 1rem/1.5 system-ui, sans-serif;
|
|
457
|
+
}
|
|
458
|
+
main {
|
|
459
|
+
max-width: 36rem;
|
|
460
|
+
margin-inline: auto;
|
|
461
|
+
padding: clamp(1rem, 5vw, 2rem);
|
|
462
|
+
border: 1px solid #e2e8f0;
|
|
463
|
+
border-radius: 1.5rem;
|
|
464
|
+
background: #fff;
|
|
465
|
+
box-shadow: 0 1px 3px #0f172a14;
|
|
466
|
+
overflow-wrap: anywhere;
|
|
467
|
+
}
|
|
468
|
+
.brand { display: flex; align-items: center; gap: 0.625rem; font-weight: 700; }
|
|
469
|
+
.mark {
|
|
470
|
+
display: grid;
|
|
471
|
+
place-items: center;
|
|
472
|
+
inline-size: 2.25rem;
|
|
473
|
+
block-size: 2.25rem;
|
|
474
|
+
border-radius: 0.625rem;
|
|
475
|
+
background: #065f46;
|
|
476
|
+
color: #fff;
|
|
477
|
+
font-size: 0.875rem;
|
|
478
|
+
}
|
|
479
|
+
.eyebrow {
|
|
480
|
+
margin: 1.5rem 0 0.25rem;
|
|
481
|
+
color: #065f46;
|
|
482
|
+
font-size: 0.75rem;
|
|
483
|
+
font-weight: 700;
|
|
484
|
+
letter-spacing: 0.08em;
|
|
485
|
+
text-transform: uppercase;
|
|
486
|
+
}
|
|
487
|
+
h1 { margin: 0; font-size: clamp(1.5rem, 5vw, 2rem); line-height: 1.2; }
|
|
488
|
+
.details {
|
|
489
|
+
margin: 1.25rem 0;
|
|
490
|
+
padding: 0.875rem 1rem;
|
|
491
|
+
border-radius: 0.875rem;
|
|
492
|
+
background: #f1f5f9;
|
|
493
|
+
}
|
|
494
|
+
.details p { margin: 0; }
|
|
495
|
+
.details p + p { margin-block-start: 0.375rem; }
|
|
496
|
+
.notice, .description { color: #475569; font-size: 0.9375rem; }
|
|
497
|
+
fieldset { min-inline-size: 0; margin: 1.25rem 0 0; padding: 0; border: 0; }
|
|
498
|
+
legend { padding: 0; font-weight: 700; }
|
|
499
|
+
.option {
|
|
500
|
+
display: grid;
|
|
501
|
+
grid-template-columns: auto minmax(0, 1fr);
|
|
502
|
+
align-items: start;
|
|
503
|
+
gap: 0.75rem;
|
|
504
|
+
margin-block-start: 0.5rem;
|
|
505
|
+
padding: 0.75rem;
|
|
506
|
+
border: 1px solid #cbd5e1;
|
|
507
|
+
border-radius: 0.875rem;
|
|
508
|
+
cursor: pointer;
|
|
509
|
+
}
|
|
510
|
+
.option:has(input:checked) { border-color: #047857; background: #ecfdf5; }
|
|
511
|
+
input[type="radio"] { margin: 0.2rem 0 0; inline-size: 1.125rem; block-size: 1.125rem; }
|
|
512
|
+
.description { display: block; }
|
|
513
|
+
.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-block-start: 1.5rem; }
|
|
514
|
+
button {
|
|
515
|
+
min-block-size: 3rem;
|
|
516
|
+
padding: 0.625rem 1.25rem;
|
|
517
|
+
border: 1px solid #64748b;
|
|
518
|
+
border-radius: 999px;
|
|
519
|
+
background: #fff;
|
|
520
|
+
color: #0f172a;
|
|
521
|
+
font: inherit;
|
|
522
|
+
font-weight: 600;
|
|
523
|
+
cursor: pointer;
|
|
524
|
+
}
|
|
525
|
+
button:hover { background: #f1f5f9; }
|
|
526
|
+
.primary { border-color: #065f46; background: #065f46; color: #fff; }
|
|
527
|
+
.primary:hover { background: #064e3b; }
|
|
528
|
+
.manage { margin: 1.25rem 0 0; }
|
|
529
|
+
a { color: #065f46; text-underline-offset: 0.15em; }
|
|
530
|
+
:focus-visible { outline: 3px solid #0f766e; outline-offset: 3px; }
|
|
531
|
+
`
|
|
532
|
+
const consentStyleHash = createHash("sha256")
|
|
533
|
+
.update(consentStyles)
|
|
534
|
+
.digest("base64")
|
|
535
|
+
|
|
536
|
+
export const consent = async (request: NextRequest): Promise<Response> => {
|
|
537
|
+
const flow = await browserPending(
|
|
538
|
+
request,
|
|
539
|
+
`${request.nextUrl.pathname}${request.nextUrl.search}`,
|
|
540
|
+
)
|
|
541
|
+
const human = flow?.record.value.human
|
|
542
|
+
if (!flow || !human) return oauthError("invalid_request")
|
|
543
|
+
const { record, origin, id } = flow
|
|
544
|
+
const entry = record.value
|
|
545
|
+
const client = await registeredClient(origin, entry.clientId)
|
|
546
|
+
if (!client) return oauthError("invalid_client")
|
|
547
|
+
const existing = entry.grantsAtStart.find(
|
|
548
|
+
(grant) => grant.userId === human.userId,
|
|
549
|
+
)
|
|
550
|
+
if (
|
|
551
|
+
client.value.grants.find((grant) => grant.userId === human.userId)?.id !==
|
|
552
|
+
existing?.id ||
|
|
553
|
+
human.expires <= Date.now()
|
|
554
|
+
)
|
|
555
|
+
return oauthError("invalid_request")
|
|
556
|
+
if (request.method === "GET") {
|
|
557
|
+
const clientName = escapeHtml(client.value.name)
|
|
558
|
+
const { organisation } = getFrontendManifest()
|
|
559
|
+
const organisationName = escapeHtml(
|
|
560
|
+
organisation.acronym ?? organisation.name,
|
|
561
|
+
)
|
|
562
|
+
const accessDetails = existing
|
|
563
|
+
? `<p>Existing access: ${existing.scope === VIEW ? "View work" : "View and act"}.</p>
|
|
564
|
+
<p class="notice">Reconnecting only restores access. It does not run an interrupted action.</p>`
|
|
565
|
+
: `<fieldset>
|
|
566
|
+
<legend>Choose access</legend>
|
|
567
|
+
<label class="option">
|
|
568
|
+
<input type="radio" name="access" value="read" aria-labelledby="read-title" aria-describedby="read-description" checked>
|
|
569
|
+
<span><strong id="read-title">View work</strong>
|
|
570
|
+
<span class="description" id="read-description">Read-only access to work and forms.</span>
|
|
571
|
+
</span>
|
|
572
|
+
</label>
|
|
573
|
+
<label class="option">
|
|
574
|
+
<input type="radio" name="access" value="act" aria-labelledby="act-title" aria-describedby="act-description">
|
|
575
|
+
<span><strong id="act-title">View and act</strong>
|
|
576
|
+
<span class="description" id="act-description">View work, start Processes, complete To-Dos, and create, edit, or delete List records where your runtime permissions allow.</span>
|
|
577
|
+
</span>
|
|
578
|
+
</label>
|
|
579
|
+
</fieldset>`
|
|
580
|
+
const approve = existing
|
|
581
|
+
? `<button class="primary" type="submit" name="action" value="reconnect">Reconnect</button>`
|
|
582
|
+
: `<button class="primary" type="submit">Allow access</button>`
|
|
583
|
+
return new Response(
|
|
584
|
+
`<!doctype html>
|
|
585
|
+
<html lang="en">
|
|
586
|
+
<head>
|
|
587
|
+
<meta charset="utf-8">
|
|
588
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
589
|
+
<title>${existing ? "Reconnect" : "Connect"} to Process Focus</title>
|
|
590
|
+
<style>${consentStyles}</style>
|
|
591
|
+
</head>
|
|
592
|
+
<body>
|
|
593
|
+
<main>
|
|
594
|
+
<header>
|
|
595
|
+
<div class="brand"><span class="mark" aria-hidden="true">PF</span> Process Focus</div>
|
|
596
|
+
<p class="eyebrow">MCP connection</p>
|
|
597
|
+
<h1>${existing ? "Reconnect" : "Connect"} ${clientName} to ${organisationName}?</h1>
|
|
598
|
+
</header>
|
|
599
|
+
<div class="details">
|
|
600
|
+
<p><strong>Environment:</strong> ${escapeHtml(origin)}</p>
|
|
601
|
+
<p><strong>Signed in as</strong> ${escapeHtml(human.email)}</p>
|
|
602
|
+
</div>
|
|
603
|
+
<p class="notice">Only approve a connection you just started in this client.</p>
|
|
604
|
+
<form method="post" action="${consentPath}?id=${id}">
|
|
605
|
+
${accessDetails}
|
|
606
|
+
<div class="actions">
|
|
607
|
+
${approve}
|
|
608
|
+
<button type="submit" name="action" value="deny">Deny</button>
|
|
609
|
+
</div>
|
|
610
|
+
</form>
|
|
611
|
+
<p class="manage"><a href="${connectedAppsPath}">Manage MCP connections</a></p>
|
|
612
|
+
</main>
|
|
613
|
+
</body>
|
|
614
|
+
</html>`,
|
|
615
|
+
{
|
|
616
|
+
headers: {
|
|
617
|
+
...headers,
|
|
618
|
+
// Keep Origin on the same-origin POST without disclosing the consent URL to the client.
|
|
619
|
+
"Referrer-Policy": "same-origin",
|
|
620
|
+
// Browsers can apply form-action to the OAuth redirect after POST.
|
|
621
|
+
"Content-Security-Policy": `default-src 'none'; frame-ancestors 'none'; form-action 'self' ${new URL(entry.redirect).origin}; base-uri 'none'; style-src 'sha256-${consentStyleHash}'`,
|
|
622
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
623
|
+
},
|
|
624
|
+
},
|
|
625
|
+
)
|
|
626
|
+
}
|
|
627
|
+
if (!sameOriginForm(request, origin))
|
|
628
|
+
return oauthError("invalid_request", 403)
|
|
629
|
+
const form = await request.formData().catch(() => null)
|
|
630
|
+
if (!form || entry.expires <= Date.now() || human.expires <= Date.now())
|
|
631
|
+
return oauthError("invalid_request")
|
|
632
|
+
const denied = form.get("action") === "deny"
|
|
633
|
+
const choice = form.get("access")
|
|
634
|
+
if (
|
|
635
|
+
!denied &&
|
|
636
|
+
(existing
|
|
637
|
+
? form.get("action") !== "reconnect"
|
|
638
|
+
: choice !== "read" && choice !== "act")
|
|
639
|
+
)
|
|
640
|
+
return oauthError("invalid_request")
|
|
641
|
+
if (!(await pending(origin).remove(id, record)))
|
|
642
|
+
return oauthError("invalid_request")
|
|
643
|
+
if (denied) return finishAuthorization(flow)
|
|
644
|
+
if (existing) {
|
|
645
|
+
// Resume the existing scope; the OAuth flow never carries an MCP request.
|
|
646
|
+
return (await activeGrant(origin, existing))
|
|
647
|
+
? finishAuthorization(flow, { grant: existing, human })
|
|
648
|
+
: oauthError("invalid_request")
|
|
649
|
+
}
|
|
650
|
+
const grant: Grant = {
|
|
651
|
+
id: random(),
|
|
652
|
+
clientId: entry.clientId,
|
|
653
|
+
userId: human.userId,
|
|
654
|
+
scope: choice === "act" ? `${VIEW} ${ACT}` : VIEW,
|
|
655
|
+
authorisedAt: DateTime.toEpochMillis(DateTime.nowUnsafe()),
|
|
656
|
+
}
|
|
657
|
+
if (
|
|
658
|
+
!(await clients(origin).put(
|
|
659
|
+
entry.clientId,
|
|
660
|
+
{
|
|
661
|
+
...client.value,
|
|
662
|
+
grants: [...client.value.grants, grant],
|
|
663
|
+
},
|
|
664
|
+
undefined,
|
|
665
|
+
client,
|
|
666
|
+
))
|
|
667
|
+
)
|
|
668
|
+
return oauthError("invalid_request")
|
|
669
|
+
return finishAuthorization(flow, { grant, human })
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
const issueTokens = async (
|
|
673
|
+
origin: string,
|
|
674
|
+
grant: Grant,
|
|
675
|
+
human: Human,
|
|
676
|
+
): Promise<Response> => {
|
|
677
|
+
if (!(await activeGrant(origin, grant))) return oauthError("invalid_grant")
|
|
678
|
+
const token = random()
|
|
679
|
+
const renewal = random()
|
|
680
|
+
const now = Date.now()
|
|
681
|
+
const expiresIn = Math.min(300, Math.floor((human.expires - now) / 1000))
|
|
682
|
+
if (expiresIn <= 0) return oauthError("invalid_grant")
|
|
683
|
+
const refreshExpires = Math.min(
|
|
684
|
+
now + (human.tokens.refreshExpiresIn ?? 86_400) * 1000,
|
|
685
|
+
human.ssoDeadline ?? Infinity,
|
|
686
|
+
)
|
|
687
|
+
const savedAccess = await access(origin).put(
|
|
688
|
+
hash(token),
|
|
689
|
+
{
|
|
690
|
+
grant,
|
|
691
|
+
token: human.tokens.access,
|
|
692
|
+
},
|
|
693
|
+
now + expiresIn * 1000,
|
|
694
|
+
)
|
|
695
|
+
const savedRefresh = await refresh(origin).put(
|
|
696
|
+
hash(renewal),
|
|
697
|
+
{
|
|
698
|
+
grant,
|
|
699
|
+
expires: refreshExpires,
|
|
700
|
+
ssoDeadline: human.ssoDeadline,
|
|
701
|
+
issuerRefreshToken: human.tokens.refresh,
|
|
702
|
+
lockedUntil: 0,
|
|
703
|
+
},
|
|
704
|
+
refreshExpires,
|
|
705
|
+
)
|
|
706
|
+
if (!savedAccess || !savedRefresh)
|
|
707
|
+
return oauthError("temporarily_unavailable", 503)
|
|
708
|
+
return Response.json(
|
|
709
|
+
{
|
|
710
|
+
access_token: token,
|
|
711
|
+
refresh_token: renewal,
|
|
712
|
+
expires_in: expiresIn,
|
|
713
|
+
token_type: "Bearer",
|
|
714
|
+
scope: grant.scope,
|
|
715
|
+
},
|
|
716
|
+
{ headers },
|
|
717
|
+
)
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
export const token = async (
|
|
721
|
+
request: Request,
|
|
722
|
+
origin: string,
|
|
723
|
+
): Promise<Response> => {
|
|
724
|
+
if (
|
|
725
|
+
request.headers.get("content-type")?.split(";")[0] !==
|
|
726
|
+
"application/x-www-form-urlencoded"
|
|
727
|
+
)
|
|
728
|
+
return oauthError("invalid_request")
|
|
729
|
+
const form = await request.formData().catch(() => null)
|
|
730
|
+
if (!form) return oauthError("invalid_request")
|
|
731
|
+
const clientId = form.get("client_id")
|
|
732
|
+
if (
|
|
733
|
+
typeof clientId !== "string" ||
|
|
734
|
+
!(await registeredClient(origin, clientId))
|
|
735
|
+
)
|
|
736
|
+
return oauthError("invalid_client")
|
|
737
|
+
const resource = form.get("resource")
|
|
738
|
+
if (resource !== null && resource !== resourceUrl(origin))
|
|
739
|
+
return oauthError("invalid_target")
|
|
740
|
+
if (form.get("grant_type") === "authorization_code") {
|
|
741
|
+
const raw = form.get("code")
|
|
742
|
+
const verifier = form.get("code_verifier")
|
|
743
|
+
if (
|
|
744
|
+
typeof raw !== "string" ||
|
|
745
|
+
!opaque.test(raw) ||
|
|
746
|
+
typeof verifier !== "string" ||
|
|
747
|
+
!/^[A-Za-z0-9._~-]{43,128}$/.test(verifier)
|
|
748
|
+
)
|
|
749
|
+
return oauthError("invalid_grant")
|
|
750
|
+
const id = hash(raw)
|
|
751
|
+
const store = codes(origin)
|
|
752
|
+
const record = await store.get(id)
|
|
753
|
+
const code = record?.value
|
|
754
|
+
if (
|
|
755
|
+
!record ||
|
|
756
|
+
!code ||
|
|
757
|
+
code.clientId !== clientId ||
|
|
758
|
+
code.redirect !== form.get("redirect_uri") ||
|
|
759
|
+
!timingSafeEqual(
|
|
760
|
+
Buffer.from(code.challenge),
|
|
761
|
+
Buffer.from(hash(verifier)),
|
|
762
|
+
) ||
|
|
763
|
+
!(await store.remove(id, record))
|
|
764
|
+
)
|
|
765
|
+
return oauthError("invalid_grant")
|
|
766
|
+
return issueTokens(origin, code.grant, code.human)
|
|
767
|
+
}
|
|
768
|
+
if (form.get("grant_type") === "refresh_token") {
|
|
769
|
+
const raw = form.get("refresh_token")
|
|
770
|
+
if (typeof raw !== "string" || !opaque.test(raw))
|
|
771
|
+
return oauthError("invalid_grant")
|
|
772
|
+
const id = hash(raw)
|
|
773
|
+
const store = refresh(origin)
|
|
774
|
+
const original = await store.get(id)
|
|
775
|
+
const entry = original?.value
|
|
776
|
+
if (
|
|
777
|
+
!original ||
|
|
778
|
+
!entry ||
|
|
779
|
+
entry.grant.clientId !== clientId ||
|
|
780
|
+
!(await activeGrant(origin, entry.grant))
|
|
781
|
+
)
|
|
782
|
+
return oauthError("invalid_grant")
|
|
783
|
+
const scope = form.get("scope")
|
|
784
|
+
if (scope !== null && scope !== entry.grant.scope)
|
|
785
|
+
return oauthError("invalid_scope")
|
|
786
|
+
const now = Date.now()
|
|
787
|
+
if (entry.lockedUntil > now)
|
|
788
|
+
return oauthError("temporarily_unavailable", 503)
|
|
789
|
+
let locked = await store.put(
|
|
790
|
+
id,
|
|
791
|
+
{ ...entry, lockedUntil: now + renewalLease },
|
|
792
|
+
entry.expires,
|
|
793
|
+
original,
|
|
794
|
+
)
|
|
795
|
+
if (!locked) return oauthError("temporarily_unavailable", 503)
|
|
796
|
+
try {
|
|
797
|
+
const result = await createClient({
|
|
798
|
+
...getFrontendAuthClientConfig(),
|
|
799
|
+
fetch: async (input, init) => {
|
|
800
|
+
const response = await fetch(input, init)
|
|
801
|
+
// OpenAuth maps other HTTP failures to InvalidRefreshTokenError.
|
|
802
|
+
if (response.status === 429 || response.status >= 500)
|
|
803
|
+
throw new Error("Issuer temporarily unavailable")
|
|
804
|
+
return response
|
|
805
|
+
},
|
|
806
|
+
}).refresh(entry.issuerRefreshToken)
|
|
807
|
+
if (result.err || !result.tokens) return oauthError("invalid_grant")
|
|
808
|
+
// The issuer has rotated its token. Keep that rotation even if
|
|
809
|
+
// signature verification cannot reach the issuer's metadata.
|
|
810
|
+
const rotated = await store.put(
|
|
811
|
+
id,
|
|
812
|
+
{
|
|
813
|
+
...locked.value,
|
|
814
|
+
issuerRefreshToken: result.tokens.refresh,
|
|
815
|
+
},
|
|
816
|
+
entry.expires,
|
|
817
|
+
locked,
|
|
818
|
+
)
|
|
819
|
+
if (!rotated) return oauthError("invalid_grant")
|
|
820
|
+
locked = rotated
|
|
821
|
+
// The issuer renews the human session. GraphQL rechecks current
|
|
822
|
+
// runtime authority on each tool call, not when rotating credentials.
|
|
823
|
+
const verified = await verifyHuman(result.tokens)
|
|
824
|
+
if (
|
|
825
|
+
!verified ||
|
|
826
|
+
verified.human.userId !== entry.grant.userId ||
|
|
827
|
+
verified.human.ssoDeadline !== entry.ssoDeadline ||
|
|
828
|
+
entry.expires <= Date.now()
|
|
829
|
+
)
|
|
830
|
+
return oauthError("invalid_grant")
|
|
831
|
+
const response = await issueTokens(origin, entry.grant, verified.human)
|
|
832
|
+
if (response.ok) {
|
|
833
|
+
if (!(await store.remove(id, locked)))
|
|
834
|
+
return oauthError("invalid_grant")
|
|
835
|
+
locked = undefined
|
|
836
|
+
}
|
|
837
|
+
return response
|
|
838
|
+
} catch {
|
|
839
|
+
return oauthError("temporarily_unavailable", 503)
|
|
840
|
+
} finally {
|
|
841
|
+
if (locked)
|
|
842
|
+
await store.put(
|
|
843
|
+
id,
|
|
844
|
+
{ ...locked.value, lockedUntil: 0 },
|
|
845
|
+
entry.expires,
|
|
846
|
+
locked,
|
|
847
|
+
)
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
return oauthError("unsupported_grant_type")
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
export type McpAccess = {
|
|
854
|
+
readonly accessToken: string
|
|
855
|
+
readonly userId: string
|
|
856
|
+
readonly canAct: boolean
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
export const readMcpAccess = async (
|
|
860
|
+
request: Request,
|
|
861
|
+
origin: string,
|
|
862
|
+
): Promise<McpAccess | undefined> => {
|
|
863
|
+
const authorization = /^Bearer ([A-Za-z0-9_-]{43})$/i.exec(
|
|
864
|
+
request.headers.get("authorization") ?? "",
|
|
865
|
+
)
|
|
866
|
+
const value = authorization?.[1]
|
|
867
|
+
if (!value) return undefined
|
|
868
|
+
const entry = (await access(origin).get(hash(value)))?.value
|
|
869
|
+
if (
|
|
870
|
+
!entry ||
|
|
871
|
+
!(await activeGrant(origin, entry.grant)) ||
|
|
872
|
+
!entry.grant.scope.split(" ").includes(VIEW)
|
|
873
|
+
)
|
|
874
|
+
return undefined
|
|
875
|
+
return {
|
|
876
|
+
accessToken: entry.token,
|
|
877
|
+
userId: entry.grant.userId,
|
|
878
|
+
canAct: entry.grant.scope.split(" ").includes(ACT),
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
export const challenge = (origin: string): Response =>
|
|
883
|
+
new Response(null, {
|
|
884
|
+
status: 401,
|
|
885
|
+
headers: {
|
|
886
|
+
...headers,
|
|
887
|
+
"WWW-Authenticate": `Bearer resource_metadata="${origin}/.well-known/oauth-protected-resource/mcp"`,
|
|
888
|
+
},
|
|
889
|
+
})
|