@processfocus/runtime-local 0.1.0-next.2 → 0.1.0-next.3
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 +48 -253
- package/dist/authentication-server.mjs +52 -84
- package/dist/{chunk-yhzbn4vx.js → chunk-04r0t2mb.js} +34324 -49067
- package/dist/chunk-727y6qkb.js +156 -0
- package/dist/chunk-bg5r4wpv.js +4755 -0
- package/dist/chunk-cbd36jq1.js +512 -0
- package/dist/chunk-d4ctj079.js +241 -0
- package/dist/{chunk-352j1ayk.js → chunk-r5s2v669.js} +51753 -36263
- 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)/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 +145 -19
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/[...listPath]/page.tsx +10 -2
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-create-form.tsx +29 -13
- 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/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 +11 -4
- 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 +47 -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 +4 -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 +112 -21
- 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/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/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 +169 -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 +900 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/origin.ts +42 -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 +193 -0
- package/dist/dashboard-source/apps/frontend/lib/mcp/todos.ts +237 -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 +48 -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 +272 -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 +48 -47
- package/dist/graphql-server.mjs +245 -200
- package/dist/job-worker-supervisor.mjs +262 -0
- package/dist/job-worker.mjs +234 -133
- package/dist/main.mjs +23 -4
- 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 +190 -51
- package/package.json +64 -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,173 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import type { Collection } from "@tanstack/db"
|
|
4
|
+
import { useCallback, useEffect, useRef, useState } from "react"
|
|
5
|
+
import { ulid } from "ulidx"
|
|
6
|
+
import type { DraftProcessExecutionDocType } from "@/lib/collections/draft-process-execution"
|
|
7
|
+
|
|
8
|
+
type DraftCollection = Collection<DraftProcessExecutionDocType, string>
|
|
9
|
+
const AUTOSAVE_DELAY_MS = 300
|
|
10
|
+
|
|
11
|
+
type PendingEdit = {
|
|
12
|
+
values: Record<string, unknown>
|
|
13
|
+
clearLocalStorage: () => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const pendingByCollection = new WeakMap<
|
|
17
|
+
DraftCollection,
|
|
18
|
+
Map<string, Promise<void>>
|
|
19
|
+
>()
|
|
20
|
+
|
|
21
|
+
function enqueueDraftWrite(
|
|
22
|
+
collection: DraftCollection,
|
|
23
|
+
processId: string,
|
|
24
|
+
write: (isLatest: () => boolean) => Promise<void>,
|
|
25
|
+
) {
|
|
26
|
+
let pending = pendingByCollection.get(collection)
|
|
27
|
+
if (!pending) {
|
|
28
|
+
pending = new Map()
|
|
29
|
+
pendingByCollection.set(collection, pending)
|
|
30
|
+
}
|
|
31
|
+
const writes = pending
|
|
32
|
+
const isLatest = () => writes.get(processId) === current
|
|
33
|
+
const previous = writes.get(processId) ?? Promise.resolve()
|
|
34
|
+
const current = previous.catch(() => {}).then(() => write(isLatest))
|
|
35
|
+
writes.set(processId, current)
|
|
36
|
+
const remove = () => {
|
|
37
|
+
if (isLatest()) writes.delete(processId)
|
|
38
|
+
}
|
|
39
|
+
void current.then(remove, remove)
|
|
40
|
+
return current
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function findProcessDraft(
|
|
44
|
+
collection: DraftCollection,
|
|
45
|
+
processId: string,
|
|
46
|
+
): DraftProcessExecutionDocType | undefined {
|
|
47
|
+
let latest: DraftProcessExecutionDocType | undefined
|
|
48
|
+
for (const draft of collection.values()) {
|
|
49
|
+
if (
|
|
50
|
+
draft.processId === processId &&
|
|
51
|
+
(!latest ||
|
|
52
|
+
draft.updatedAt > latest.updatedAt ||
|
|
53
|
+
(draft.updatedAt === latest.updatedAt && draft.id > latest.id))
|
|
54
|
+
) {
|
|
55
|
+
latest = draft
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return latest
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function useProcessDraft({
|
|
62
|
+
collection,
|
|
63
|
+
processId,
|
|
64
|
+
name,
|
|
65
|
+
startStepPath,
|
|
66
|
+
totalFields,
|
|
67
|
+
}: {
|
|
68
|
+
collection: DraftCollection | undefined
|
|
69
|
+
processId: string
|
|
70
|
+
name: string
|
|
71
|
+
startStepPath: string
|
|
72
|
+
totalFields: number
|
|
73
|
+
}) {
|
|
74
|
+
const [error, setError] = useState<string | null>(null)
|
|
75
|
+
const [isDiscarding, setIsDiscarding] = useState(false)
|
|
76
|
+
const edit = useRef<PendingEdit | null>(null)
|
|
77
|
+
const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
|
|
78
|
+
const clearing = useRef(false)
|
|
79
|
+
|
|
80
|
+
const takeEdit = useCallback(() => {
|
|
81
|
+
clearTimeout(timer.current)
|
|
82
|
+
timer.current = undefined
|
|
83
|
+
const pendingEdit = edit.current
|
|
84
|
+
edit.current = null
|
|
85
|
+
return pendingEdit
|
|
86
|
+
}, [])
|
|
87
|
+
|
|
88
|
+
const flush = useCallback(() => {
|
|
89
|
+
const pendingEdit = takeEdit()
|
|
90
|
+
if (!collection || !pendingEdit) return
|
|
91
|
+
const { values, clearLocalStorage } = pendingEdit
|
|
92
|
+
// Serialize writes across openings of this process in the same browser.
|
|
93
|
+
void enqueueDraftWrite(collection, processId, async (isLatest) => {
|
|
94
|
+
const draft = findProcessDraft(collection, processId)
|
|
95
|
+
const now = new Date()
|
|
96
|
+
const tx = draft
|
|
97
|
+
? collection.update(draft.id, (row) => {
|
|
98
|
+
row.state = values
|
|
99
|
+
row.updatedAt = now.getTime()
|
|
100
|
+
row.lastSaved = now.toISOString()
|
|
101
|
+
})
|
|
102
|
+
: collection.insert({
|
|
103
|
+
id: `pst-${ulid()}`,
|
|
104
|
+
processId,
|
|
105
|
+
name,
|
|
106
|
+
startStepPath,
|
|
107
|
+
state: values,
|
|
108
|
+
fieldsCompleted: 0,
|
|
109
|
+
totalFields,
|
|
110
|
+
updatedAt: now.getTime(),
|
|
111
|
+
lastSaved: now.toISOString(),
|
|
112
|
+
})
|
|
113
|
+
await tx.when("settled")
|
|
114
|
+
if (isLatest() && !edit.current) clearLocalStorage()
|
|
115
|
+
setError(null)
|
|
116
|
+
}).catch((cause: unknown) => {
|
|
117
|
+
setError(
|
|
118
|
+
"Changes couldn't be saved. Your edits are still in this browser.",
|
|
119
|
+
)
|
|
120
|
+
console.error("Draft save failed:", cause)
|
|
121
|
+
})
|
|
122
|
+
}, [collection, processId, name, startStepPath, takeEdit, totalFields])
|
|
123
|
+
|
|
124
|
+
// The renderer stores edits in this browser immediately. Persist the last
|
|
125
|
+
// one on normal navigation rather than waiting for the debounce to expire.
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
window.addEventListener("pagehide", flush)
|
|
128
|
+
return () => {
|
|
129
|
+
window.removeEventListener("pagehide", flush)
|
|
130
|
+
flush()
|
|
131
|
+
}
|
|
132
|
+
}, [flush])
|
|
133
|
+
|
|
134
|
+
const save = useCallback(
|
|
135
|
+
(values: Record<string, unknown>, clearLocalStorage: () => void) => {
|
|
136
|
+
if (!collection || clearing.current) return
|
|
137
|
+
edit.current = { values, clearLocalStorage }
|
|
138
|
+
clearTimeout(timer.current)
|
|
139
|
+
timer.current = setTimeout(flush, AUTOSAVE_DELAY_MS)
|
|
140
|
+
},
|
|
141
|
+
[collection, flush],
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
const clear = useCallback(async () => {
|
|
145
|
+
if (clearing.current) return false
|
|
146
|
+
clearing.current = true
|
|
147
|
+
setIsDiscarding(true)
|
|
148
|
+
const pendingEdit = takeEdit()
|
|
149
|
+
try {
|
|
150
|
+
if (collection) {
|
|
151
|
+
await enqueueDraftWrite(collection, processId, async () => {
|
|
152
|
+
// Clearing a form must not fall back to a pre-existing duplicate.
|
|
153
|
+
const ids = [...collection.values()]
|
|
154
|
+
.filter((draft) => draft.processId === processId)
|
|
155
|
+
.map((draft) => draft.id)
|
|
156
|
+
if (ids.length > 0) await collection.delete(ids).when("settled")
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
// All successful callers leave the form; edits must not recreate it
|
|
160
|
+
// between clearing the saved values and closing the form.
|
|
161
|
+
return true
|
|
162
|
+
} catch (cause) {
|
|
163
|
+
clearing.current = false
|
|
164
|
+
setIsDiscarding(false)
|
|
165
|
+
if (pendingEdit) save(pendingEdit.values, pendingEdit.clearLocalStorage)
|
|
166
|
+
setError("Couldn't clear the saved form. Please try again.")
|
|
167
|
+
console.error("Draft cleanup failed:", cause)
|
|
168
|
+
return false
|
|
169
|
+
}
|
|
170
|
+
}, [collection, processId, save, takeEdit])
|
|
171
|
+
|
|
172
|
+
return { save, clear, error, isDiscarding }
|
|
173
|
+
}
|
|
@@ -6,7 +6,7 @@ import type { ExecutionDocType } from "@/lib/collections/execution-collection-pr
|
|
|
6
6
|
|
|
7
7
|
interface WeeklyStats {
|
|
8
8
|
completed: number
|
|
9
|
-
failed: number
|
|
9
|
+
failed: number
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
interface WeeklyExecutionStats {
|
|
@@ -57,7 +57,6 @@ export function useWeeklyExecutionStats(
|
|
|
57
57
|
}
|
|
58
58
|
}, [startDayOfWeek])
|
|
59
59
|
|
|
60
|
-
// Query this week's completed executions
|
|
61
60
|
const thisWeekQuery = useLiveQuery((q) =>
|
|
62
61
|
q
|
|
63
62
|
.from({ execution: executionsCollection })
|
|
@@ -70,7 +69,6 @@ export function useWeeklyExecutionStats(
|
|
|
70
69
|
.select(({ execution }) => ({ id: execution.id })),
|
|
71
70
|
)
|
|
72
71
|
|
|
73
|
-
// Query last week's completed executions
|
|
74
72
|
const lastWeekQuery = useLiveQuery((q) =>
|
|
75
73
|
q
|
|
76
74
|
.from({ execution: executionsCollection })
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
2
|
+
typeof value === "object" && value !== null && !Array.isArray(value)
|
|
3
|
+
export const publicTodoDefaultValues = (
|
|
4
|
+
defaultValues: unknown,
|
|
5
|
+
): Record<string, unknown> | null =>
|
|
6
|
+
isRecord(defaultValues) ? defaultValues : null
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Schema } from "effect"
|
|
2
|
+
import { getFrontendJwt } from "../../../modules/auth-session/src/index.ts"
|
|
3
|
+
import type { LookupSuggestion } from "../../../modules/form/src/index.ts"
|
|
4
|
+
import { FormRequestData } from "../../../modules/form-schema/src/index.ts"
|
|
5
|
+
import { publicTodoDefaultValues } from "./anonymous-page-form-values.ts"
|
|
6
|
+
import type { AnonymousPageQuery } from "./generated/gql/graphql.ts"
|
|
7
|
+
import {
|
|
8
|
+
anonymousPageLookupQuery,
|
|
9
|
+
anonymousPageQuery,
|
|
10
|
+
submitAnonymousPageMutation,
|
|
11
|
+
} from "./graphql/anonymous-page.ts"
|
|
12
|
+
import { createServerGraphqlClient } from "./graphql/server-client.ts"
|
|
13
|
+
|
|
14
|
+
const client = () => {
|
|
15
|
+
const jwt = getFrontendJwt()
|
|
16
|
+
if (!jwt) throw new Error("FRONTEND_JWT_TOKEN is not configured")
|
|
17
|
+
return createServerGraphqlClient(jwt)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type AnonymousPageData = Omit<
|
|
21
|
+
AnonymousPageQuery["anonymousPage"],
|
|
22
|
+
"requestData" | "defaultValues" | "pluginConfiguration"
|
|
23
|
+
> & {
|
|
24
|
+
requestData: FormRequestData
|
|
25
|
+
defaultValues: Record<string, unknown>
|
|
26
|
+
pluginConfiguration: Readonly<Record<string, unknown>>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function fetchAnonymousPage(
|
|
30
|
+
address: string,
|
|
31
|
+
): Promise<AnonymousPageData> {
|
|
32
|
+
const { anonymousPage: page } = await client().request(anonymousPageQuery, {
|
|
33
|
+
address,
|
|
34
|
+
})
|
|
35
|
+
return {
|
|
36
|
+
...page,
|
|
37
|
+
requestData: Schema.decodeUnknownSync(FormRequestData)(page.requestData),
|
|
38
|
+
pluginConfiguration: Schema.decodeUnknownSync(
|
|
39
|
+
Schema.Record(Schema.String, Schema.Unknown),
|
|
40
|
+
)(page.pluginConfiguration),
|
|
41
|
+
defaultValues: publicTodoDefaultValues(page.defaultValues) ?? {},
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function lookupAnonymousPage(args: {
|
|
46
|
+
address: string
|
|
47
|
+
field: string
|
|
48
|
+
filter: string
|
|
49
|
+
limit: number
|
|
50
|
+
selectedValue?: string
|
|
51
|
+
}): Promise<LookupSuggestion[]> {
|
|
52
|
+
const data = await client().request(anonymousPageLookupQuery, args)
|
|
53
|
+
return data.anonymousPageLookup.map(({ value, label, searchText }) => ({
|
|
54
|
+
value,
|
|
55
|
+
label,
|
|
56
|
+
...(searchText != null && { searchText }),
|
|
57
|
+
}))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function submitAnonymousPage(
|
|
61
|
+
address: string,
|
|
62
|
+
input: Record<string, unknown>,
|
|
63
|
+
): Promise<void> {
|
|
64
|
+
await client().request(submitAnonymousPageMutation, { address, input })
|
|
65
|
+
}
|
|
@@ -33,7 +33,7 @@ export class AppSyncEventsAdapter<
|
|
|
33
33
|
CheckpointType,
|
|
34
34
|
> {
|
|
35
35
|
private pullStream$ = new Subject<
|
|
36
|
-
DocumentsWithCheckpoint<RxDocType, CheckpointType>
|
|
36
|
+
DocumentsWithCheckpoint<RxDocType, CheckpointType> | "RESYNC"
|
|
37
37
|
>()
|
|
38
38
|
private client: AppSyncEventsClient | null = null
|
|
39
39
|
|
|
@@ -53,6 +53,7 @@ export class AppSyncEventsAdapter<
|
|
|
53
53
|
...(this.config.expiresAt !== undefined
|
|
54
54
|
? { expiresAt: this.config.expiresAt }
|
|
55
55
|
: {}),
|
|
56
|
+
onSubscribed: () => this.pullStream$.next("RESYNC"),
|
|
56
57
|
onEvent: (eventData: string) => {
|
|
57
58
|
try {
|
|
58
59
|
// What we possibly should do here is validate input against schema?
|
|
@@ -105,15 +106,20 @@ export class AppSyncEventsAdapter<
|
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
|
|
108
|
-
getStream(): Observable<
|
|
109
|
+
getStream(): Observable<
|
|
110
|
+
DocumentsWithCheckpoint<RxDocType, CheckpointType> | "RESYNC"
|
|
111
|
+
> {
|
|
109
112
|
// Transform documents to use RxDB's _deleted field convention for the stream
|
|
110
113
|
// RxDB will then map _deleted to the configured deletedField ("deleted") in storage
|
|
111
114
|
// Filter out events with null checkpoints (no more documents to sync)
|
|
112
115
|
return this.pullStream$.pipe(
|
|
113
116
|
filter(
|
|
114
|
-
(bulk) =>
|
|
117
|
+
(bulk) =>
|
|
118
|
+
bulk === "RESYNC" ||
|
|
119
|
+
(bulk.checkpoint !== null && bulk.checkpoint !== undefined),
|
|
115
120
|
),
|
|
116
121
|
map((bulk) => {
|
|
122
|
+
if (bulk === "RESYNC") return bulk
|
|
117
123
|
console.log("getStream")
|
|
118
124
|
return {
|
|
119
125
|
documents: bulk.documents.map((doc) => ({
|
|
@@ -1,60 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* AppSync Events WebSocket protocol types
|
|
8
|
-
*/
|
|
9
|
-
type ConnectionInitMessage = { type: "connection_init" }
|
|
10
|
-
type ConnectionAckMessage = {
|
|
11
|
-
type: "connection_ack"
|
|
12
|
-
connectionTimeoutMs: number
|
|
13
|
-
}
|
|
14
|
-
type ConnectionErrorMessage = {
|
|
15
|
-
type: "connection_error"
|
|
16
|
-
errors: Array<{ errorType: string; errorCode: number; message?: string }>
|
|
17
|
-
}
|
|
18
|
-
type SubscribeMessage = {
|
|
19
|
-
type: "subscribe"
|
|
20
|
-
id: string
|
|
21
|
-
channel: string
|
|
22
|
-
authorization: Record<string, string>
|
|
23
|
-
}
|
|
24
|
-
type SubscribeSuccessMessage = { type: "subscribe_success"; id: string }
|
|
25
|
-
type SubscribeErrorMessage = {
|
|
26
|
-
type: "subscribe_error"
|
|
27
|
-
id: string
|
|
28
|
-
errors: Array<{ errorType: string; message: string }>
|
|
29
|
-
}
|
|
30
|
-
type DataMessage = { type: "data"; id: string; event: string }
|
|
31
|
-
type KeepAliveMessage = { type: "ka" }
|
|
32
|
-
type ErrorMessage = {
|
|
33
|
-
type: "error"
|
|
34
|
-
id?: string
|
|
35
|
-
errors: Array<{ message: string }>
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
type ServerMessage =
|
|
39
|
-
| ConnectionAckMessage
|
|
40
|
-
| ConnectionErrorMessage
|
|
41
|
-
| SubscribeSuccessMessage
|
|
42
|
-
| SubscribeErrorMessage
|
|
43
|
-
| DataMessage
|
|
44
|
-
| KeepAliveMessage
|
|
45
|
-
| ErrorMessage
|
|
46
|
-
|
|
47
|
-
interface AppSyncEventsClientConfig {
|
|
48
|
-
realtimeUrl: string
|
|
49
|
-
httpHost: string
|
|
50
|
-
channel: string
|
|
51
|
-
isCurrent?: () => boolean
|
|
52
|
-
expiresAt?: number
|
|
53
|
-
onEvent: (event: string) => void
|
|
54
|
-
onError?: (error: Error) => void
|
|
55
|
-
onConnect?: () => void
|
|
56
|
-
onDisconnect?: () => void
|
|
57
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
type AppSyncEventsClientConfig,
|
|
3
|
+
AppSyncEventsClient as Transport,
|
|
4
|
+
} from "../../../../modules/realtime-client/src/index.ts"
|
|
58
5
|
|
|
59
6
|
/**
|
|
60
7
|
* Get a cookie value by name from document.cookie
|
|
@@ -68,288 +15,8 @@ export const getCookie = (name: string): string | undefined => {
|
|
|
68
15
|
return undefined
|
|
69
16
|
}
|
|
70
17
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const encodeAuthHeader = (auth: Record<string, string>): string => {
|
|
75
|
-
const header = btoa(JSON.stringify(auth))
|
|
76
|
-
.replace(/\+/g, "-")
|
|
77
|
-
.replace(/\//g, "_")
|
|
78
|
-
.replace(/=+$/, "")
|
|
79
|
-
return `header-${header}`
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* AppSync Events WebSocket client using native browser WebSocket API
|
|
84
|
-
*/
|
|
85
|
-
export class AppSyncEventsClient {
|
|
86
|
-
private socket: WebSocket | null = null
|
|
87
|
-
private subscriptionId: string | null = null
|
|
88
|
-
private reconnectAttempts = 0
|
|
89
|
-
private readonly maxReconnectAttempts = 10
|
|
90
|
-
private reconnectTimeout: ReturnType<typeof setTimeout> | null = null
|
|
91
|
-
private keepAliveTimeout: ReturnType<typeof setTimeout> | null = null
|
|
92
|
-
private isManualDisconnect = false
|
|
93
|
-
private isAuthorizationError = false
|
|
94
|
-
private accessToken: string | undefined
|
|
95
|
-
|
|
96
|
-
constructor(private config: AppSyncEventsClientConfig) {}
|
|
97
|
-
|
|
98
|
-
connect(): void {
|
|
99
|
-
if (this.config.isCurrent && !this.config.isCurrent()) return
|
|
100
|
-
if (
|
|
101
|
-
this.config.expiresAt !== undefined &&
|
|
102
|
-
Date.now() >= this.config.expiresAt * 1000
|
|
103
|
-
)
|
|
104
|
-
return
|
|
105
|
-
if (this.socket?.readyState === WebSocket.OPEN) {
|
|
106
|
-
console.warn("Already connected to AppSync Events")
|
|
107
|
-
return
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
this.isManualDisconnect = false
|
|
111
|
-
this.isAuthorizationError = false
|
|
112
|
-
|
|
113
|
-
// Read access token from cookie (now non-HttpOnly so JavaScript can access it)
|
|
114
|
-
const accessToken = getCookie("access_token")
|
|
115
|
-
// A client instance must never adopt credentials from another session.
|
|
116
|
-
if (this.accessToken && this.accessToken !== accessToken) return
|
|
117
|
-
if (!accessToken) {
|
|
118
|
-
console.error(
|
|
119
|
-
"No access_token cookie found - cannot authorize WebSocket connection",
|
|
120
|
-
)
|
|
121
|
-
this.config.onError?.(new Error("No access token available"))
|
|
122
|
-
return
|
|
123
|
-
}
|
|
124
|
-
this.accessToken = accessToken
|
|
125
|
-
|
|
126
|
-
// Build authorization object using provided HTTP host and access token
|
|
127
|
-
const authorization = {
|
|
128
|
-
// We must provide a host for authorization (or possibly anything) to work,
|
|
129
|
-
// else you get "400: Missing host header"
|
|
130
|
-
host: this.config.httpHost,
|
|
131
|
-
// With lambda authorization we need an "authorization" header with the JWT,
|
|
132
|
-
// else we get: "400: Required headers are missing"
|
|
133
|
-
authorization: accessToken,
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Debug logging
|
|
137
|
-
console.log("AppSync Events config:", {
|
|
138
|
-
realtimeUrl: this.config.realtimeUrl,
|
|
139
|
-
httpHost: this.config.httpHost,
|
|
140
|
-
channel: this.config.channel,
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
// Create WebSocket with AppSync Events subprotocol
|
|
144
|
-
const authProtocol = encodeAuthHeader(authorization)
|
|
145
|
-
this.socket = new WebSocket(this.config.realtimeUrl, [
|
|
146
|
-
"aws-appsync-event-ws",
|
|
147
|
-
authProtocol,
|
|
148
|
-
])
|
|
149
|
-
const socket = this.socket
|
|
150
|
-
const isCurrent = () =>
|
|
151
|
-
this.socket === socket &&
|
|
152
|
-
!this.isManualDisconnect &&
|
|
153
|
-
(!this.config.isCurrent || this.config.isCurrent()) &&
|
|
154
|
-
(this.config.expiresAt === undefined ||
|
|
155
|
-
Date.now() < this.config.expiresAt * 1000) &&
|
|
156
|
-
getCookie("access_token") === accessToken
|
|
157
|
-
|
|
158
|
-
this.socket.onopen = () => {
|
|
159
|
-
if (!isCurrent()) return
|
|
160
|
-
console.log("AppSync Events WebSocket connected")
|
|
161
|
-
this.reconnectAttempts = 0
|
|
162
|
-
|
|
163
|
-
// Send connection_init
|
|
164
|
-
this.send({ type: "connection_init" })
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
this.socket.onmessage = (event) => {
|
|
168
|
-
if (!isCurrent()) return
|
|
169
|
-
console.debug("AppSync Events received message:", event.data)
|
|
170
|
-
const message = JSON.parse(event.data) as ServerMessage
|
|
171
|
-
|
|
172
|
-
switch (message.type) {
|
|
173
|
-
case "connection_ack":
|
|
174
|
-
console.log("AppSync Events connection acknowledged")
|
|
175
|
-
this.startKeepAliveMonitor(message.connectionTimeoutMs)
|
|
176
|
-
this.subscribe()
|
|
177
|
-
this.config.onConnect?.()
|
|
178
|
-
break
|
|
179
|
-
|
|
180
|
-
case "connection_error": {
|
|
181
|
-
console.error("AppSync Events connection error:", message.errors)
|
|
182
|
-
const errorMsg = message.errors[0]
|
|
183
|
-
|
|
184
|
-
// Authorization errors (401/403) should not retry - token is invalid
|
|
185
|
-
if (errorMsg?.errorCode === 401 || errorMsg?.errorCode === 403) {
|
|
186
|
-
this.isAuthorizationError = true
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (errorMsg) {
|
|
190
|
-
const errorDetail = `${errorMsg.errorType} (${errorMsg.errorCode}): ${errorMsg.message || "No message"}`
|
|
191
|
-
this.config.onError?.(new Error(errorDetail))
|
|
192
|
-
} else {
|
|
193
|
-
this.config.onError?.(new Error("Connection error with no details"))
|
|
194
|
-
}
|
|
195
|
-
this.socket?.close()
|
|
196
|
-
break
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
case "subscribe_success":
|
|
200
|
-
console.log("Subscribed to channel:", this.config.channel)
|
|
201
|
-
break
|
|
202
|
-
|
|
203
|
-
case "subscribe_error": {
|
|
204
|
-
console.error("AppSync Events subscription error:", message.errors)
|
|
205
|
-
const errMsg = message.errors[0]
|
|
206
|
-
// Treat subscription authorization failures as auth errors - don't retry
|
|
207
|
-
if (
|
|
208
|
-
errMsg?.errorType === "UnauthorizedException" ||
|
|
209
|
-
errMsg?.errorType === "Forbidden"
|
|
210
|
-
) {
|
|
211
|
-
this.isAuthorizationError = true
|
|
212
|
-
}
|
|
213
|
-
this.config.onError?.(
|
|
214
|
-
new Error(
|
|
215
|
-
errMsg
|
|
216
|
-
? `${errMsg.errorType}: ${errMsg.message}`
|
|
217
|
-
: "Subscription error with no details",
|
|
218
|
-
),
|
|
219
|
-
)
|
|
220
|
-
break
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
case "data":
|
|
224
|
-
if (message.id !== this.subscriptionId) return
|
|
225
|
-
// Reset keep-alive timeout on data receipt
|
|
226
|
-
this.resetKeepAliveMonitor()
|
|
227
|
-
this.config.onEvent(message.event)
|
|
228
|
-
break
|
|
229
|
-
|
|
230
|
-
case "ka":
|
|
231
|
-
// Keep-alive message - reset timeout
|
|
232
|
-
this.resetKeepAliveMonitor()
|
|
233
|
-
break
|
|
234
|
-
|
|
235
|
-
case "error":
|
|
236
|
-
console.error("AppSync Events error:", message.errors)
|
|
237
|
-
this.config.onError?.(
|
|
238
|
-
new Error(message.errors[0]?.message || "Unknown error"),
|
|
239
|
-
)
|
|
240
|
-
break
|
|
241
|
-
|
|
242
|
-
default:
|
|
243
|
-
console.warn("Unknown message type:", message)
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
this.socket.onerror = (error) => {
|
|
248
|
-
if (!isCurrent()) return
|
|
249
|
-
console.error("AppSync Events WebSocket error:", error)
|
|
250
|
-
this.config.onError?.(new Error("WebSocket error"))
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
this.socket.onclose = () => {
|
|
254
|
-
if (this.socket !== socket) return
|
|
255
|
-
this.socket = null
|
|
256
|
-
this.subscriptionId = null
|
|
257
|
-
console.log("AppSync Events WebSocket closed")
|
|
258
|
-
this.cleanup()
|
|
259
|
-
this.config.onDisconnect?.()
|
|
260
|
-
|
|
261
|
-
// Attempt reconnection unless manually disconnected or auth failed
|
|
262
|
-
if (!this.isManualDisconnect && !this.isAuthorizationError) {
|
|
263
|
-
this.scheduleReconnect()
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Subscribe via the HTTP endpoint.
|
|
270
|
-
*/
|
|
271
|
-
private subscribe(): void {
|
|
272
|
-
const authorization = {
|
|
273
|
-
host: this.config.httpHost,
|
|
274
|
-
authorization: this.accessToken || "",
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
this.subscriptionId = crypto.randomUUID()
|
|
278
|
-
this.send({
|
|
279
|
-
type: "subscribe",
|
|
280
|
-
id: this.subscriptionId,
|
|
281
|
-
channel: this.config.channel,
|
|
282
|
-
authorization,
|
|
283
|
-
})
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
private send(message: ConnectionInitMessage | SubscribeMessage): void {
|
|
287
|
-
if (this.socket?.readyState === WebSocket.OPEN) {
|
|
288
|
-
this.socket.send(JSON.stringify(message))
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
private startKeepAliveMonitor(timeoutMs: number): void {
|
|
293
|
-
// Set timeout to slightly more than server's keep-alive interval
|
|
294
|
-
// Server sends ka every 60 seconds, timeout is typically 5 minutes
|
|
295
|
-
this.keepAliveTimeout = setTimeout(() => {
|
|
296
|
-
console.warn("Keep-alive timeout - reconnecting")
|
|
297
|
-
this.socket?.close()
|
|
298
|
-
}, timeoutMs)
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
private resetKeepAliveMonitor(): void {
|
|
302
|
-
if (this.keepAliveTimeout) {
|
|
303
|
-
clearTimeout(this.keepAliveTimeout)
|
|
304
|
-
this.keepAliveTimeout = null
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
private scheduleReconnect(): void {
|
|
309
|
-
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
|
|
310
|
-
console.error("Max reconnection attempts reached")
|
|
311
|
-
this.config.onError?.(new Error("Max reconnection attempts reached"))
|
|
312
|
-
return
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
// Exponential backoff: 1s, 2s, 4s, 8s, ..., max 30s
|
|
316
|
-
const delay = Math.min(1000 * 2 ** this.reconnectAttempts, 30000)
|
|
317
|
-
this.reconnectAttempts++
|
|
318
|
-
|
|
319
|
-
console.log(
|
|
320
|
-
`Reconnecting in ${delay}ms (attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts})`,
|
|
321
|
-
)
|
|
322
|
-
this.reconnectTimeout = setTimeout(() => {
|
|
323
|
-
this.connect()
|
|
324
|
-
}, delay)
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
disconnect(): void {
|
|
328
|
-
this.isManualDisconnect = true
|
|
329
|
-
this.cleanup()
|
|
330
|
-
this.socket?.close()
|
|
331
|
-
this.socket = null
|
|
332
|
-
this.subscriptionId = null
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Reconnect to AppSync Events with fresh credentials.
|
|
337
|
-
* Used when token is refreshed to ensure WebSocket uses new auth.
|
|
338
|
-
*/
|
|
339
|
-
reconnect(): void {
|
|
340
|
-
console.log("Reconnecting to AppSync Events with fresh credentials...")
|
|
341
|
-
this.disconnect()
|
|
342
|
-
this.connect() // connect() reads fresh token from cookie
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
private cleanup(): void {
|
|
346
|
-
if (this.reconnectTimeout) {
|
|
347
|
-
clearTimeout(this.reconnectTimeout)
|
|
348
|
-
this.reconnectTimeout = null
|
|
349
|
-
}
|
|
350
|
-
if (this.keepAliveTimeout) {
|
|
351
|
-
clearTimeout(this.keepAliveTimeout)
|
|
352
|
-
this.keepAliveTimeout = null
|
|
353
|
-
}
|
|
18
|
+
export class AppSyncEventsClient extends Transport {
|
|
19
|
+
constructor(config: Omit<AppSyncEventsClientConfig, "getToken">) {
|
|
20
|
+
super({ ...config, getToken: () => getCookie("access_token") })
|
|
354
21
|
}
|
|
355
22
|
}
|
|
@@ -11,6 +11,7 @@ export function toClientSession(session: SessionWithTokenAndExpiry): Session {
|
|
|
11
11
|
orgUnitId: session.orgUnitId,
|
|
12
12
|
orgUnitPath: session.orgUnitPath,
|
|
13
13
|
roles: session.roles,
|
|
14
|
+
...(session.workload ? { workload: session.workload } : {}),
|
|
14
15
|
...(session.delegation ? { delegation: session.delegation } : {}),
|
|
15
16
|
...(session.delegationRoleSelection !== undefined
|
|
16
17
|
? { delegationRoleSelection: session.delegationRoleSelection }
|
|
@@ -21,6 +22,7 @@ export function toClientSession(session: SessionWithTokenAndExpiry): Session {
|
|
|
21
22
|
return {
|
|
22
23
|
userId: session.userId,
|
|
23
24
|
clientId: session.clientId,
|
|
25
|
+
...(session.workload ? { workload: session.workload } : {}),
|
|
24
26
|
...(session.roles ? { roles: session.roles } : {}),
|
|
25
27
|
...(session.orgUnitId !== undefined
|
|
26
28
|
? { orgUnitId: session.orgUnitId }
|