@cosmicdrift/kumiko-framework 0.387.0 → 0.389.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +9 -1
- package/agents/examples/anonymous-access.md +1 -1
- package/agents/examples/apex-landing.md +204 -0
- package/agents/examples/api-worker-split.md +64 -0
- package/agents/examples/app-config.md +14 -0
- package/agents/examples/auth-mfa.md +115 -0
- package/agents/examples/env-composition.md +28 -1
- package/agents/examples/golden-path.md +13 -1
- package/agents/examples/legal-pages.md +1 -1
- package/agents/examples/lifecycle-hooks.md +55 -2
- package/agents/examples/list-table-options.md +466 -0
- package/agents/examples/pdf-audit-export.md +4 -2
- package/agents/examples/prod-boot-options.md +16 -0
- package/agents/examples/rate-limiting.md +48 -0
- package/agents/examples/record-detail-layout.md +692 -0
- package/agents/examples/seed-migration.md +212 -0
- package/agents/examples/state-machine.md +3 -2
- package/agents/examples/tenant-isolation.md +73 -1
- package/agents/examples/wizard-form.md +941 -0
- package/agents/examples/writeform-section.md +548 -0
- package/agents/examples.md +1 -0
- package/agents/features.md +19 -2
- package/agents/widgets.md +2 -0
- package/dist/api/api-constants.d.ts +1 -0
- package/dist/api/api-constants.js +2 -0
- package/dist/api/auth-routes-shared.d.ts +2 -0
- package/dist/api/auth-routes-shared.js +5 -0
- package/dist/api/client-error-route.js +10 -5
- package/dist/api/entity-read-access.d.ts +2 -1
- package/dist/api/entity-read-access.js +14 -0
- package/dist/api/export/export-cells-reference.d.ts +9 -0
- package/dist/api/export/export-cells-reference.js +21 -0
- package/dist/api/export/export-cells.d.ts +11 -0
- package/dist/api/export/export-cells.js +136 -0
- package/dist/api/export/export-ciphertext-guard.d.ts +2 -0
- package/dist/api/export/export-ciphertext-guard.js +27 -0
- package/dist/api/export/export-columns.d.ts +29 -0
- package/dist/api/export/export-columns.js +85 -0
- package/dist/api/export/export-errors.d.ts +4 -0
- package/dist/api/export/export-errors.js +14 -0
- package/dist/api/export/export-route.d.ts +4 -0
- package/dist/api/export/export-route.js +74 -0
- package/dist/api/export/export-rows.d.ts +13 -0
- package/dist/api/export/export-rows.js +62 -0
- package/dist/api/export/export-screen.d.ts +12 -0
- package/dist/api/export/export-screen.js +47 -0
- package/dist/api/export/export-xlsx-writer.d.ts +4 -0
- package/dist/api/export/export-xlsx-writer.js +21 -0
- package/dist/api/extra-route.d.ts +4 -0
- package/dist/api/index.d.ts +3 -1
- package/dist/api/index.js +3 -1
- package/dist/api/pii-leak-guard.d.ts +3 -0
- package/dist/api/pii-leak-guard.js +3 -2
- package/dist/api/request-context.d.ts +1 -1
- package/dist/api/request-context.js +1 -1
- package/dist/api/routes.d.ts +16 -0
- package/dist/api/routes.js +2 -2
- package/dist/api/server-boot-checks.d.ts +10 -0
- package/dist/api/server-boot-checks.js +157 -0
- package/dist/api/server-event-dispatcher.d.ts +26 -0
- package/dist/api/server-event-dispatcher.js +208 -0
- package/dist/api/server-extra-routes.d.ts +11 -0
- package/dist/api/server-extra-routes.js +206 -0
- package/dist/api/server-middleware.d.ts +20 -0
- package/dist/api/server-middleware.js +211 -0
- package/dist/api/server-routes.d.ts +19 -0
- package/dist/api/server-routes.js +299 -0
- package/dist/api/server-websocket-routes.d.ts +4 -0
- package/dist/api/server-websocket-routes.js +108 -0
- package/dist/api/server-wiring.d.ts +32 -0
- package/dist/api/server-wiring.js +238 -0
- package/dist/api/server.d.ts +10 -15
- package/dist/api/server.js +48 -1251
- package/dist/api/session-cookies.js +4 -4
- package/dist/api/sse-route.d.ts +2 -1
- package/dist/api/sse-route.js +27 -13
- package/dist/config/index.d.ts +3 -1
- package/dist/crypto/owner-transition-rekey.d.ts +5 -1
- package/dist/crypto/owner-transition-rekey.js +1 -1
- package/dist/crypto/pg-kms-adapter.d.ts +1 -0
- package/dist/crypto/pg-kms-adapter.js +12 -18
- package/dist/crypto/pii-field-encryption.d.ts +5 -1
- package/dist/crypto/pii-field-encryption.js +3 -1
- package/dist/db/aggregate-sql.d.ts +23 -0
- package/dist/db/aggregate-sql.js +165 -0
- package/dist/db/closed-connection.d.ts +9 -0
- package/dist/db/closed-connection.js +88 -0
- package/dist/db/connection.d.ts +4 -5
- package/dist/db/connection.js +29 -20
- package/dist/db/dialect.js +1 -1
- package/dist/db/distinct-on.d.ts +1 -1
- package/dist/db/driver-row-coercion.d.ts +2 -0
- package/dist/db/driver-row-coercion.js +186 -0
- package/dist/db/driver-value-preparation.d.ts +16 -0
- package/dist/db/driver-value-preparation.js +101 -0
- package/dist/db/entity-field-encryption.d.ts +1 -0
- package/dist/db/entity-field-encryption.js +1 -1
- package/dist/db/entity-table-meta.js +103 -110
- package/dist/db/event-store-executor-context.d.ts +2 -1
- package/dist/db/event-store-executor-read-aggregate-currencies.d.ts +17 -0
- package/dist/db/event-store-executor-read-aggregate-currencies.js +40 -0
- package/dist/db/event-store-executor-read-aggregate.d.ts +8 -0
- package/dist/db/event-store-executor-read-aggregate.js +143 -0
- package/dist/db/event-store-executor-read-filter.d.ts +31 -0
- package/dist/db/event-store-executor-read-filter.js +206 -0
- package/dist/db/event-store-executor-read-paging.d.ts +14 -0
- package/dist/db/event-store-executor-read-paging.js +99 -0
- package/dist/db/event-store-executor-read-rows.d.ts +6 -0
- package/dist/db/event-store-executor-read-rows.js +32 -0
- package/dist/db/event-store-executor-read-search.d.ts +28 -0
- package/dist/db/event-store-executor-read-search.js +221 -0
- package/dist/db/event-store-executor-read-sort.d.ts +41 -0
- package/dist/db/event-store-executor-read-sort.js +130 -0
- package/dist/db/event-store-executor-read-where.d.ts +24 -0
- package/dist/db/event-store-executor-read-where.js +81 -0
- package/dist/db/event-store-executor-read.d.ts +2 -9
- package/dist/db/event-store-executor-read.js +48 -701
- package/dist/db/event-store-executor-write-atomic.d.ts +4 -0
- package/dist/db/event-store-executor-write-atomic.js +41 -0
- package/dist/db/event-store-executor-write-steps.d.ts +17 -0
- package/dist/db/event-store-executor-write-steps.js +95 -0
- package/dist/db/event-store-executor-write.js +405 -509
- package/dist/db/event-store-executor.js +2 -1
- package/dist/db/executor-managed-tables.js +1 -1
- package/dist/db/index.d.ts +7 -3
- package/dist/db/index.js +6 -2
- package/dist/db/list-aggregate-labels.d.ts +14 -0
- package/dist/db/list-aggregate-labels.js +26 -0
- package/dist/db/migrate-generator.js +71 -86
- package/dist/db/migrate-runner.js +7 -4
- package/dist/db/pg-error.js +26 -21
- package/dist/db/queries/backfill-pii.js +3 -6
- package/dist/db/queries/database-now.js +2 -1
- package/dist/db/queries/shadow-swap.js +2 -3
- package/dist/db/query.d.ts +16 -15
- package/dist/db/query.js +76 -804
- package/dist/db/reference-data.js +19 -2
- package/dist/db/statement-timeout.js +2 -1
- package/dist/db/table-builder.js +113 -166
- package/dist/db/table-info.d.ts +10 -0
- package/dist/db/table-info.js +45 -0
- package/dist/db/temporal-value-guards.d.ts +6 -0
- package/dist/db/temporal-value-guards.js +15 -0
- package/dist/db/tenant-db-runner.d.ts +1 -0
- package/dist/db/tenant-db-runner.js +3 -0
- package/dist/db/tenant-db-upsert.d.ts +5 -0
- package/dist/db/tenant-db-upsert.js +91 -0
- package/dist/db/tenant-db.js +50 -10
- package/dist/db/where-clause.d.ts +6 -0
- package/dist/db/where-clause.js +236 -0
- package/dist/derivatives/delete-stored-file.js +2 -1
- package/dist/engine/boot-validator/boot-check.js +1 -1
- package/dist/engine/boot-validator/bundled-lists-table.d.ts +2 -0
- package/dist/engine/boot-validator/bundled-lists-table.js +36 -0
- package/dist/engine/boot-validator/detail-screens.js +2 -2
- package/dist/engine/boot-validator/entity-handler.d.ts +1 -0
- package/dist/engine/boot-validator/entity-handler.js +17 -0
- package/dist/engine/boot-validator/entity-list-aggregate-options.d.ts +3 -0
- package/dist/engine/boot-validator/entity-list-aggregate-options.js +23 -0
- package/dist/engine/boot-validator/form-derivations.js +35 -1
- package/dist/engine/boot-validator/i18n-keys.js +5 -3
- package/dist/engine/boot-validator/index.js +2 -0
- package/dist/engine/boot-validator/list-bulk-actions.d.ts +3 -0
- package/dist/engine/boot-validator/list-bulk-actions.js +49 -0
- package/dist/engine/boot-validator/list-column-layout.d.ts +8 -0
- package/dist/engine/boot-validator/list-column-layout.js +41 -0
- package/dist/engine/boot-validator/list-table-aggregate-options.d.ts +24 -0
- package/dist/engine/boot-validator/list-table-aggregate-options.js +145 -0
- package/dist/engine/boot-validator/list-table-aggregate-query.d.ts +10 -0
- package/dist/engine/boot-validator/list-table-aggregate-query.js +31 -0
- package/dist/engine/boot-validator/list-table-export-options.d.ts +1 -0
- package/dist/engine/boot-validator/list-table-export-options.js +27 -0
- package/dist/engine/boot-validator/list-table-options.d.ts +3 -0
- package/dist/engine/boot-validator/list-table-options.js +77 -0
- package/dist/engine/boot-validator/list-table-reject-unknown-keys.d.ts +1 -0
- package/dist/engine/boot-validator/list-table-reject-unknown-keys.js +7 -0
- package/dist/engine/boot-validator/pii-retention.js +233 -155
- package/dist/engine/boot-validator/projection-list-screens.d.ts +1 -1
- package/dist/engine/boot-validator/projection-list-screens.js +3 -13
- package/dist/engine/boot-validator/related-list-table-rules.d.ts +4 -0
- package/dist/engine/boot-validator/related-list-table-rules.js +42 -0
- package/dist/engine/boot-validator/screens-actions.d.ts +1 -0
- package/dist/engine/boot-validator/screens-actions.js +8 -1
- package/dist/engine/boot-validator/screens-dashboard.js +2 -5
- package/dist/engine/boot-validator/screens-forms.js +2 -6
- package/dist/engine/boot-validator/screens-kind-config-edit.d.ts +3 -0
- package/dist/engine/boot-validator/screens-kind-config-edit.js +88 -0
- package/dist/engine/boot-validator/screens-kind-entity-edit.d.ts +3 -0
- package/dist/engine/boot-validator/screens-kind-entity-edit.js +55 -0
- package/dist/engine/boot-validator/screens-kind-entity-list.d.ts +3 -0
- package/dist/engine/boot-validator/screens-kind-entity-list.js +235 -0
- package/dist/engine/boot-validator/screens-kind-projection-detail.d.ts +3 -0
- package/dist/engine/boot-validator/screens-kind-projection-detail.js +235 -0
- package/dist/engine/boot-validator/screens-kind-projection-list.d.ts +3 -0
- package/dist/engine/boot-validator/screens-kind-projection-list.js +56 -0
- package/dist/engine/boot-validator/screens-kind-secret-mint.d.ts +3 -0
- package/dist/engine/boot-validator/screens-kind-secret-mint.js +28 -0
- package/dist/engine/boot-validator/screens-kind-shared.d.ts +37 -0
- package/dist/engine/boot-validator/screens-kind-shared.js +142 -0
- package/dist/engine/boot-validator/screens-lists.d.ts +2 -1
- package/dist/engine/boot-validator/screens-lists.js +24 -11
- package/dist/engine/boot-validator/screens.d.ts +0 -2
- package/dist/engine/boot-validator/screens.js +99 -860
- package/dist/engine/build-app-schema.d.ts +2 -1
- package/dist/engine/build-app-schema.js +65 -97
- package/dist/engine/build-config-feature-schema.js +6 -1
- package/dist/engine/define-feature.js +13 -2
- package/dist/engine/define-handler.js +1 -0
- package/dist/engine/entity-handlers.d.ts +13 -0
- package/dist/engine/entity-handlers.js +10 -21
- package/dist/engine/entity-list-runtime-options.d.ts +8 -0
- package/dist/engine/entity-list-runtime-options.js +18 -0
- package/dist/engine/feature-ast/extractors/handlers.js +1 -0
- package/dist/engine/feature-ast/extractors/index.d.ts +1 -1
- package/dist/engine/feature-ast/extractors/index.js +1 -1
- package/dist/engine/feature-ast/extractors/round1.d.ts +2 -1
- package/dist/engine/feature-ast/extractors/round1.js +6 -0
- package/dist/engine/feature-ast/extractors/round2.js +25 -6
- package/dist/engine/feature-ast/index.d.ts +1 -1
- package/dist/engine/feature-ast/parse.js +3 -1
- package/dist/engine/feature-ast/patch.d.ts +2 -0
- package/dist/engine/feature-ast/patch.js +5 -182
- package/dist/engine/feature-ast/pattern-change-schema.d.ts +10 -245
- package/dist/engine/feature-ast/pattern-change-schema.js +10 -163
- package/dist/engine/feature-ast/pattern-id-matchers.d.ts +7 -0
- package/dist/engine/feature-ast/pattern-id-matchers.js +211 -0
- package/dist/engine/feature-ast/pattern-id-schema.d.ts +251 -0
- package/dist/engine/feature-ast/pattern-id-schema.js +166 -0
- package/dist/engine/feature-ast/patterns.d.ts +14 -1
- package/dist/engine/feature-ast/patterns.js +44 -51
- package/dist/engine/feature-ast/render.js +52 -87
- package/dist/engine/feature-builder-state.d.ts +1 -0
- package/dist/engine/feature-builder-state.js +1 -0
- package/dist/engine/feature-entity-handlers.js +3 -0
- package/dist/engine/feature-manifest.d.ts +1 -0
- package/dist/engine/feature-manifest.js +1 -0
- package/dist/engine/field-access.d.ts +1 -0
- package/dist/engine/field-access.js +12 -0
- package/dist/engine/form-derivations.js +18 -7
- package/dist/engine/handler-field-references.js +1 -1
- package/dist/engine/index.d.ts +2 -2
- package/dist/engine/index.js +1 -1
- package/dist/engine/pattern-library/library.js +2 -1
- package/dist/engine/pattern-library/static-schemas.d.ts +1 -0
- package/dist/engine/pattern-library/static-schemas.js +9 -0
- package/dist/engine/project-app-schema-for-roles.d.ts +2 -0
- package/dist/engine/project-app-schema-for-roles.js +6 -4
- package/dist/engine/registry-ingest.js +1 -1
- package/dist/engine/schema-builder.js +228 -212
- package/dist/engine/screen-filter-ops.js +2 -0
- package/dist/engine/screen-helpers.js +1 -1
- package/dist/engine/screen-kind.d.ts +7 -0
- package/dist/engine/screen-kind.js +1 -0
- package/dist/engine/strip-disabled-features-from-app-schema.js +58 -17
- package/dist/engine/types/feature.d.ts +1 -0
- package/dist/engine/types/index.d.ts +4 -3
- package/dist/engine/types/screen.d.ts +1 -1
- package/dist/engine/types/screen.js +1 -1
- package/dist/engine/validate-projection-allowlist.js +2 -1
- package/dist/entrypoint/index.d.ts +6 -1
- package/dist/entrypoint/index.js +10 -1
- package/dist/errors/docs-url.d.ts +1 -1
- package/dist/errors/docs-url.js +22 -2
- package/dist/es-ops/context.js +1 -1
- package/dist/event-store/admin-api.js +1 -1
- package/dist/event-store/event-store.d.ts +1 -0
- package/dist/event-store/event-store.js +17 -8
- package/dist/event-store/provenance-append.js +1 -1
- package/dist/files/bind-pending-file-refs.js +3 -3
- package/dist/files/create-file-ref-from-bytes.js +7 -1
- package/dist/files/create-file-ref.d.ts +3 -0
- package/dist/files/create-file-ref.js +11 -2
- package/dist/files/file-handle.js +2 -3
- package/dist/files/file-routes.d.ts +2 -0
- package/dist/files/file-routes.js +40 -10
- package/dist/files/provider-resolver.d.ts +1 -0
- package/dist/files/provider-resolver.js +1 -1
- package/dist/files/record-write-check.d.ts +6 -0
- package/dist/files/record-write-check.js +13 -0
- package/dist/files/resolve-content-type.js +43 -0
- package/dist/files/upload-ledger.d.ts +2 -2
- package/dist/files/upload-ledger.js +11 -4
- package/dist/i18n/required-surface-keys.js +189 -208
- package/dist/internal/stack-support.d.ts +2 -1
- package/dist/internal/stack-support.js +1 -1
- package/dist/internal/testing.js +1 -1
- package/dist/jobs/job-runner-context.d.ts +32 -0
- package/dist/jobs/job-runner-context.js +305 -0
- package/dist/jobs/job-runner-execution.d.ts +7 -0
- package/dist/jobs/job-runner-execution.js +160 -0
- package/dist/jobs/job-runner-gates.d.ts +19 -0
- package/dist/jobs/job-runner-gates.js +198 -0
- package/dist/jobs/job-runner-helpers.d.ts +17 -3
- package/dist/jobs/job-runner-helpers.js +61 -2
- package/dist/jobs/job-runner-scope.d.ts +44 -0
- package/dist/jobs/job-runner-scope.js +102 -0
- package/dist/jobs/job-runner-types.d.ts +12 -0
- package/dist/jobs/job-runner.d.ts +0 -1
- package/dist/jobs/job-runner.js +50 -657
- package/dist/observability/escape-hatch-report.d.ts +3 -0
- package/dist/observability/escape-hatch-report.js +21 -3
- package/dist/pipeline/after-rollback-sink.d.ts +6 -0
- package/dist/pipeline/after-rollback-sink.js +32 -0
- package/dist/pipeline/cascade-handler.js +165 -138
- package/dist/pipeline/dispatch-batch.js +8 -1
- package/dist/pipeline/dispatch-query.js +10 -3
- package/dist/pipeline/dispatch-shared.d.ts +13 -3
- package/dist/pipeline/dispatch-shared.js +62 -710
- package/dist/pipeline/dispatch-write.js +296 -189
- package/dist/pipeline/event-dispatcher-admin.js +2 -1
- package/dist/pipeline/event-dispatcher-delivery.js +6 -6
- package/dist/pipeline/event-dispatcher.d.ts +1 -0
- package/dist/pipeline/event-dispatcher.js +6 -9
- package/dist/pipeline/handler-context-auth.d.ts +9 -0
- package/dist/pipeline/handler-context-auth.js +54 -0
- package/dist/pipeline/handler-context-config.d.ts +14 -0
- package/dist/pipeline/handler-context-config.js +113 -0
- package/dist/pipeline/handler-context-db.d.ts +24 -0
- package/dist/pipeline/handler-context-db.js +149 -0
- package/dist/pipeline/handler-context-dispatch.d.ts +23 -0
- package/dist/pipeline/handler-context-dispatch.js +101 -0
- package/dist/pipeline/handler-context-events.d.ts +41 -0
- package/dist/pipeline/handler-context-events.js +239 -0
- package/dist/pipeline/handler-context-notify.d.ts +12 -0
- package/dist/pipeline/handler-context-notify.js +55 -0
- package/dist/pipeline/handler-context-observability.d.ts +7 -0
- package/dist/pipeline/handler-context-observability.js +21 -0
- package/dist/pipeline/handler-context-scope.d.ts +48 -0
- package/dist/pipeline/handler-context-scope.js +88 -0
- package/dist/pipeline/notify-scope.js +12 -1
- package/dist/pipeline/pre-handler-gates.js +20 -4
- package/dist/pipeline/pre-transaction-reservations.d.ts +1 -0
- package/dist/pipeline/pre-transaction-reservations.js +9 -3
- package/dist/pipeline/projection-rebuild.js +2 -1
- package/dist/pipeline/system-hooks.d.ts +3 -1
- package/dist/pipeline/system-hooks.js +55 -6
- package/dist/pipeline/write-result-masking.js +13 -10
- package/dist/schema-cli/apply-command.d.ts +2 -0
- package/dist/schema-cli/apply-command.js +97 -0
- package/dist/schema-cli/baseline-command.d.ts +2 -0
- package/dist/schema-cli/baseline-command.js +33 -0
- package/dist/schema-cli/generate-command.d.ts +2 -0
- package/dist/schema-cli/generate-command.js +90 -0
- package/dist/schema-cli/shared.d.ts +39 -0
- package/dist/schema-cli/shared.js +95 -0
- package/dist/schema-cli/status-command.d.ts +2 -0
- package/dist/schema-cli/status-command.js +73 -0
- package/dist/schema-cli/validate-boot-input.d.ts +5 -0
- package/dist/schema-cli/validate-boot-input.js +130 -0
- package/dist/schema-cli/validate-command.d.ts +2 -0
- package/dist/schema-cli/validate-command.js +130 -0
- package/dist/schema-cli.d.ts +2 -18
- package/dist/schema-cli.js +47 -604
- package/dist/search/meilisearch-adapter.js +2 -1
- package/dist/search/reindex-entity.js +15 -5
- package/dist/ui-types/index.d.ts +2 -2
- package/dist/ui-types/index.js +1 -1
- package/dist/upgrade-changelog.d.ts +2 -0
- package/dist/upgrade-changelog.js +14 -0
- package/dist/upgrade-cli.d.ts +3 -12
- package/dist/upgrade-cli.js +171 -197
- package/dist/upgrade-marker-parse.d.ts +32 -0
- package/dist/upgrade-marker-parse.js +73 -0
- package/package.json +9 -6
- package/src/changes.json +555 -0
- package/src/scripts/codemod/codemod-support.ts +1 -1
- package/src/scripts/codemod/db-factory.ts +1 -1
- package/src/scripts/codemod/feature-layout.ts +10 -2
- package/src/scripts/codemod/object-form.ts +41 -4
- package/src/scripts/codemod/package-merge.ts +58 -8
- package/src/scripts/codemod/pii-personal-migration.ts +175 -145
- package/src/scripts/codemod/testing-injection.ts +122 -42
- package/src/scripts/codemod/testing-move.ts +29 -7
- package/dist/engine/provider-plugin-context.d.ts +0 -3
- package/dist/engine/provider-plugin-context.js +0 -28
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { createProjectingTenantDb } from "../db/tenant-db.js";
|
|
2
|
+
import { buildAppSchema } from "../engine/build-app-schema.js";
|
|
3
|
+
import { projectAppSchemaForRoles } from "../engine/project-app-schema-for-roles.js";
|
|
4
|
+
import { resolveDisabledFeatureNames, stripDisabledFeaturesFromAppSchema, } from "../engine/strip-disabled-features-from-app-schema.js";
|
|
5
|
+
import { createAnonymousUser, isAnonymousSessionUser } from "../engine/system-user.js";
|
|
6
|
+
import { createFileRoutes, readFilesRouteOptions } from "../files/file-routes.js";
|
|
7
|
+
import { createRecordReadCheck } from "../files/record-read-check.js";
|
|
8
|
+
import { createRecordWriteCheck } from "../files/record-write-check.js";
|
|
9
|
+
import { createRateLimitResolver, httpRouteRateLimit } from "../rate-limit/index.js";
|
|
10
|
+
import { assertUnreachable } from "../utils/index.js";
|
|
11
|
+
import { collectAnonymousLiveEntities } from "./anonymous-live-entities.js";
|
|
12
|
+
import { NO_ROUTE_MATCH_HEADER_NAME, Routes } from "./api-constants.js";
|
|
13
|
+
import { getUser, identifyOptionalSession } from "./auth-middleware.js";
|
|
14
|
+
import { createAuthRoutes } from "./auth-routes.js";
|
|
15
|
+
import { createClientErrorRoute } from "./client-error-route.js";
|
|
16
|
+
import { clientIpSourceFromHonoContext } from "./client-ip.js";
|
|
17
|
+
import { collectEntityReadAccess, collectEntityRowReadMaps } from "./entity-read-access.js";
|
|
18
|
+
import { createExportRoutes } from "./export/export-route.js";
|
|
19
|
+
import { computeStrongEtag, etagMatches } from "./http-cache.js";
|
|
20
|
+
import { requestContext } from "./request-context.js";
|
|
21
|
+
import { buildRequestContextData } from "./request-id-middleware.js";
|
|
22
|
+
import { registerHealthRoutes, registerMetricsRoute } from "./route-registrars.js";
|
|
23
|
+
import { createApiRoutes } from "./routes.js";
|
|
24
|
+
import { assertSinglePrincipalStatusProvider } from "./server-boot-checks.js";
|
|
25
|
+
import { createSseRoute } from "./sse-route.js";
|
|
26
|
+
export function mountOperationalRoutes(app, wiring) {
|
|
27
|
+
const { options, baseDb, eventConsumers, observability, bootLog } = wiring;
|
|
28
|
+
registerHealthRoutes(app, {
|
|
29
|
+
lifecycle: options.lifecycle,
|
|
30
|
+
readiness: {
|
|
31
|
+
db: baseDb,
|
|
32
|
+
redis: options.context.redis,
|
|
33
|
+
consumers: eventConsumers,
|
|
34
|
+
...(options.readiness ?? {}),
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
if (options.metrics) {
|
|
38
|
+
registerMetricsRoute(app, observability.meter, options.metrics);
|
|
39
|
+
}
|
|
40
|
+
else if (process.env["NODE_ENV"] === "production") {
|
|
41
|
+
bootLog.warn("/metrics is off: no `metrics` option, so nothing is measured or scraped. " +
|
|
42
|
+
"Set PROMETHEUS_METRICS_TOKEN (min 32 chars) and spread resolveObservabilityWiring(token) into the server options.");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export function mountAuthRoutes(app, wiring, sessionCookies) {
|
|
46
|
+
const { options, dispatcher, jwt, clientIpResolver } = wiring;
|
|
47
|
+
if (options.auth) {
|
|
48
|
+
assertSinglePrincipalStatusProvider(options.registry, options.auth);
|
|
49
|
+
app.route("/api", createAuthRoutes(dispatcher, jwt, {
|
|
50
|
+
...options.auth,
|
|
51
|
+
secureCookies: sessionCookies.secure,
|
|
52
|
+
resolver: clientIpResolver,
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export function mountClientErrorRoute(app, wiring) {
|
|
57
|
+
const { rateLimitResolver, tracedRedis, clientIpResolver, observability, jwt } = wiring;
|
|
58
|
+
app.route("/api", createClientErrorRoute({
|
|
59
|
+
resolver: rateLimitResolver ??
|
|
60
|
+
(tracedRedis ? createRateLimitResolver({ redis: tracedRedis }) : undefined),
|
|
61
|
+
clientIpResolver,
|
|
62
|
+
meter: observability.meter,
|
|
63
|
+
identifySession: (c) => identifyOptionalSession(c, jwt),
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
export function mountDispatcherRoutes(app, wiring) {
|
|
67
|
+
const { options, dispatcher, sseBroker } = wiring;
|
|
68
|
+
app.route("/api", createApiRoutes(dispatcher, {
|
|
69
|
+
...(options.sseHeartbeatMs !== undefined ? { sseHeartbeatMs: options.sseHeartbeatMs } : {}),
|
|
70
|
+
}));
|
|
71
|
+
app.route("/api", createExportRoutes(dispatcher, options.registry));
|
|
72
|
+
app.route("/api", createSseRoute(sseBroker, {
|
|
73
|
+
anonymousLiveEntities: collectAnonymousLiveEntities(options.registry),
|
|
74
|
+
entityReadAccess: collectEntityReadAccess(options.registry),
|
|
75
|
+
entityRowReadMaps: collectEntityRowReadMaps(options.registry),
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
export function mountSchemaRoute(app, options) {
|
|
79
|
+
// GET /api/schema — the only way a client obtains the AppSchema. Behind
|
|
80
|
+
// jwtGuard (NON_PUBLIC_API_PATHS), so anonymousAccess's synthesised user
|
|
81
|
+
// also gets rejected below — the schema never reaches an unauthenticated
|
|
82
|
+
// caller. The FULL schema is built lazily once — the registry is
|
|
83
|
+
// immutable for this server's lifetime, so it's the same on every
|
|
84
|
+
// request — then projected per caller-role-set (a role only
|
|
85
|
+
// sees the screens/navs/workspaces/content-collections it may reach,
|
|
86
|
+
// not the whole app's schema) and cached per role key. Tenant is
|
|
87
|
+
// deliberately NOT part of the key: the projection depends only on
|
|
88
|
+
// roles, and per-tenant caching would grow unboundedly across tenants
|
|
89
|
+
// that share the same role set. What IS part of the key: the sorted set of
|
|
90
|
+
// features the caller's tenant has switched off (r.toggleable) — few
|
|
91
|
+
// distinct sets, so the cache stays small. The resolver is read per request
|
|
92
|
+
// because run{Dev,Prod}App fill it in after the server is built.
|
|
93
|
+
let fullSchema;
|
|
94
|
+
const projectedSchemaCache = new Map();
|
|
95
|
+
app.get(`/api${Routes.schema}`, async (c) => {
|
|
96
|
+
const user = getUser(c);
|
|
97
|
+
if (isMissingOrAnonymousUser(user)) {
|
|
98
|
+
return unauthenticatedResponse(c);
|
|
99
|
+
}
|
|
100
|
+
const effectiveFeatures = options.dispatcherOptions?.effectiveFeatures;
|
|
101
|
+
const disabledFeatureNames = effectiveFeatures === undefined
|
|
102
|
+
? []
|
|
103
|
+
: await resolveDisabledFeatureNames(options.registry, effectiveFeatures, user.tenantId);
|
|
104
|
+
const roleKey = JSON.stringify([[...new Set(user?.roles ?? [])].sort(), disabledFeatureNames]);
|
|
105
|
+
let cached = projectedSchemaCache.get(roleKey);
|
|
106
|
+
if (cached === undefined) {
|
|
107
|
+
if (fullSchema === undefined) {
|
|
108
|
+
fullSchema = buildAppSchema(options.registry, {
|
|
109
|
+
searchAdapterMissing: !options.context.searchAdapter,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const projected = projectAppSchemaForRoles(stripDisabledFeaturesFromAppSchema(fullSchema, options.registry, disabledFeatureNames), user?.roles ?? []);
|
|
113
|
+
const json = JSON.stringify(projected);
|
|
114
|
+
cached = { json, etag: computeStrongEtag(json) };
|
|
115
|
+
projectedSchemaCache.set(roleKey, cached);
|
|
116
|
+
}
|
|
117
|
+
const cacheHeaders = { "Cache-Control": "private, no-cache", ETag: cached.etag };
|
|
118
|
+
if (etagMatches(c.req.header("If-None-Match") ?? null, cached.etag)) {
|
|
119
|
+
return c.body(null, 304, cacheHeaders);
|
|
120
|
+
}
|
|
121
|
+
return c.body(cached.json, 200, {
|
|
122
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
123
|
+
...cacheHeaders,
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
export function mountFileRoutes(app, wiring) {
|
|
128
|
+
const { options, dispatcher, fileProviderResolver, rateLimitResolver, tracedRedis } = wiring;
|
|
129
|
+
const metaBatchRateLimitResolver = rateLimitResolver ??
|
|
130
|
+
(tracedRedis ? createRateLimitResolver({ redis: tracedRedis }) : undefined);
|
|
131
|
+
// Mount upload/download routes whenever a file provider is resolvable (a
|
|
132
|
+
// file-provider plugin is mounted, or a resolver was injected). They resolve
|
|
133
|
+
// the provider per-tenant through file-foundation — no `files` option; route
|
|
134
|
+
// policy comes from createFilesFeature(opts?). Gating on the resolver (not on
|
|
135
|
+
// declared file fields) keeps unattached uploads working and matches the old
|
|
136
|
+
// "files option present → routes" behavior.
|
|
137
|
+
if (fileProviderResolver) {
|
|
138
|
+
const fileDb = options.context.db; // @cast-boundary engine-bridge
|
|
139
|
+
if (!fileDb)
|
|
140
|
+
throw new Error("file routes require db in context");
|
|
141
|
+
const routeOptions = readFilesRouteOptions(options.registry);
|
|
142
|
+
const canReadRecord = createRecordReadCheck(options.registry, dispatcher.query);
|
|
143
|
+
app.route("/api", createFileRoutes({
|
|
144
|
+
db: fileDb,
|
|
145
|
+
registry: options.registry,
|
|
146
|
+
resolveProvider: fileProviderResolver,
|
|
147
|
+
...(metaBatchRateLimitResolver ? { metaBatchRateLimitResolver } : {}),
|
|
148
|
+
canReadRecord,
|
|
149
|
+
canWriteRecord: createRecordWriteCheck({
|
|
150
|
+
registry: options.registry,
|
|
151
|
+
canReadRecord,
|
|
152
|
+
tenantDbFor: (tenantId) => createProjectingTenantDb(fileDb, tenantId, options.registry),
|
|
153
|
+
}),
|
|
154
|
+
...(routeOptions.accessGuard ? { accessGuard: routeOptions.accessGuard } : {}),
|
|
155
|
+
...(routeOptions.privilegedRoles ? { privilegedRoles: routeOptions.privilegedRoles } : {}),
|
|
156
|
+
...(routeOptions.unclaimedUploadReaders
|
|
157
|
+
? { unclaimedUploadReaders: routeOptions.unclaimedUploadReaders }
|
|
158
|
+
: {}),
|
|
159
|
+
...(routeOptions.maxUploadSize ? { maxUploadSize: routeOptions.maxUploadSize } : {}),
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export function mountFeatureHttpRoutes(app, wiring, sessionOnlyHttpRouteGuards) {
|
|
164
|
+
// Feature-declared HTTP routes (r.httpRoute). Mount after /api/* so /api/* always
|
|
165
|
+
// takes precedence; feature routes must be outside that prefix (the boot validator
|
|
166
|
+
// enforces this). deps.app is the outer app, so the handler can call /api/query
|
|
167
|
+
// internally through app.fetch(...) and use the same auth path as a real HTTP call.
|
|
168
|
+
// deps.systemQuery deliberately bypasses that path for routes that must enforce a
|
|
169
|
+
// FIXED tenant (for example, legal-pages always uses SYSTEM_TENANT_ID), rather than
|
|
170
|
+
// spoofing it through the X-Tenant header. That header looks like a normal client
|
|
171
|
+
// header to anonymousAccess resolution, so resolverTrust: "authoritative" configs
|
|
172
|
+
// correctly reject it as a tenant override.
|
|
173
|
+
for (const feature of wiring.options.registry.features.values()) {
|
|
174
|
+
for (const route of Object.values(feature.httpRoutes)) {
|
|
175
|
+
mountFeatureHttpRoute(app, route, wiring, sessionOnlyHttpRouteGuards);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function mountFeatureHttpRoute(app, route, wiring, sessionOnlyHttpRouteGuards) {
|
|
180
|
+
const { dispatcher, clientIpResolver, rateLimitResolver, observability } = wiring;
|
|
181
|
+
// @wrapper-known semantic-alias
|
|
182
|
+
const honoHandler = async (c) => route.handler(c, {
|
|
183
|
+
app,
|
|
184
|
+
// createAnonymousUser, NOT createSystemUser: systemQuery's
|
|
185
|
+
// synthesized user must clear the SAME access gate a real
|
|
186
|
+
// anonymous visitor would, no more — regardless of the route's
|
|
187
|
+
// own `anonymous` mode. The system role would ALSO satisfy that
|
|
188
|
+
// gate here, but it can read fields gated to "system" that
|
|
189
|
+
// "anonymous" can't (filterReadFields is a plain role-in-map
|
|
190
|
+
// check) — a systemQuery caller reading a system-gated field
|
|
191
|
+
// would leak it into the response. The forced tenant already
|
|
192
|
+
// comes from bypassing the HTTP layer entirely; no elevated
|
|
193
|
+
// role is needed or wanted on top of that.
|
|
194
|
+
systemQuery: makeSystemQuery(c, dispatcher, clientIpResolver),
|
|
195
|
+
clientIp: clientIpResolver.resolve(clientIpSourceFromHonoContext(c)),
|
|
196
|
+
});
|
|
197
|
+
// Without a resolver (no Redis in the context — dev/test stacks) the
|
|
198
|
+
// declared limit is skipped rather than failing the boot of every app
|
|
199
|
+
// that mounts a bundled feature whose routes carry a default limit.
|
|
200
|
+
const routeLimit = route.rateLimit && rateLimitResolver
|
|
201
|
+
? [
|
|
202
|
+
httpRouteRateLimit({
|
|
203
|
+
resolver: rateLimitResolver,
|
|
204
|
+
rateLimit: route.rateLimit,
|
|
205
|
+
routeKey: `${route.method} ${route.path}`,
|
|
206
|
+
clientIpResolver,
|
|
207
|
+
meter: observability.meter,
|
|
208
|
+
}),
|
|
209
|
+
]
|
|
210
|
+
: [];
|
|
211
|
+
mountHonoRoute(app, route.method, route.path, honoHandler, [
|
|
212
|
+
...routeLimit,
|
|
213
|
+
...(route.anonymous ? [] : sessionOnlyHttpRouteGuards),
|
|
214
|
+
]);
|
|
215
|
+
}
|
|
216
|
+
export function installNoRouteMatchMarker(app) {
|
|
217
|
+
// Marks "no route matched this path" so tryHonoFirst (server-runtime)
|
|
218
|
+
// can tell it apart from a matched route's OWN deliberate 404 (e.g.
|
|
219
|
+
// default-deny reads like file-derivatives' public-variant route) —
|
|
220
|
+
// without this, tryHonoFirst's only signal was the status code, and a
|
|
221
|
+
// matched route answering 404 got silently rewritten to the SPA shell
|
|
222
|
+
// with status 200. Must be the LAST thing wired
|
|
223
|
+
// on `app`: this only fires when the router found no handler at all, so
|
|
224
|
+
// a route's own `c.text(..., 404)` never passes through here. A handler
|
|
225
|
+
// that calls `c.notFound()` instead of building its own Response DOES
|
|
226
|
+
// route through this same handler and stays indistinguishable from a
|
|
227
|
+
// routing miss — pre-existing Hono semantics, not something this fix
|
|
228
|
+
// changes; deliberate 404s must build their own Response.
|
|
229
|
+
// The header is an internal signal only — tryHonoFirst and every direct
|
|
230
|
+
// app.fetch() passthrough strip it before a response reaches a client.
|
|
231
|
+
app.notFound((c) => c.text("Not Found", 404, { [NO_ROUTE_MATCH_HEADER_NAME]: "1" }));
|
|
232
|
+
}
|
|
233
|
+
// Method-switch shared by r.httpRoute and extraRoutes — one place to keep
|
|
234
|
+
// the two mounting paths from drifting on which Hono methods get a
|
|
235
|
+
// convenience-call vs. app.on().
|
|
236
|
+
export function mountHonoRoute(app, method, path,
|
|
237
|
+
// biome-ignore lint/suspicious/noExplicitAny: Hono context generics are invisible at the framework boundary
|
|
238
|
+
handler, middlewares = []) {
|
|
239
|
+
// Guards go into the route's own handler chain, never a method-gated
|
|
240
|
+
// app.use: Hono serves HEAD through the GET route with c.req.method still
|
|
241
|
+
// "HEAD", so a `method === c.req.method` gate would skip them for HEAD.
|
|
242
|
+
if (middlewares.length > 0) {
|
|
243
|
+
// [path]: only Hono's array-path overload accepts a variable-length handler spread.
|
|
244
|
+
app.on(method, [path], ...middlewares, handler);
|
|
245
|
+
// skip: guarded route already mounted with its guard chain
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
switch (method) {
|
|
249
|
+
case "GET":
|
|
250
|
+
app.get(path, handler);
|
|
251
|
+
break;
|
|
252
|
+
case "POST":
|
|
253
|
+
app.post(path, handler);
|
|
254
|
+
break;
|
|
255
|
+
case "PUT":
|
|
256
|
+
app.put(path, handler);
|
|
257
|
+
break;
|
|
258
|
+
case "PATCH":
|
|
259
|
+
app.patch(path, handler);
|
|
260
|
+
break;
|
|
261
|
+
case "DELETE":
|
|
262
|
+
app.delete(path, handler);
|
|
263
|
+
break;
|
|
264
|
+
case "OPTIONS":
|
|
265
|
+
case "HEAD":
|
|
266
|
+
// Hono's on() for the methods without a convenience method.
|
|
267
|
+
app.on(method, path, handler);
|
|
268
|
+
break;
|
|
269
|
+
default:
|
|
270
|
+
assertUnreachable(method, "http method");
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
// Shared systemQuery builder for r.httpRoute and extraRoutes (anonymous +
|
|
274
|
+
// signature entries). requestContext.run must wrap the dispatcher call —
|
|
275
|
+
// both route kinds run outside the requestIdMiddleware chain that normally
|
|
276
|
+
// populates it, and `rateLimit: {per: "ip", ...}` on a handler invoked
|
|
277
|
+
// through systemQuery is otherwise silent dead-code (enforceRateLimit reads
|
|
278
|
+
// requestContext.get()?.ip, undefined without this wrap).
|
|
279
|
+
export function makeSystemQuery(
|
|
280
|
+
// biome-ignore lint/suspicious/noExplicitAny: Hono context generics are invisible at the framework boundary
|
|
281
|
+
c, dispatcher, clientIpResolver) {
|
|
282
|
+
return (type, payload, tenantId) => requestContext.run(requestContext.get() ?? buildRequestContextData(c, clientIpResolver), () => dispatcher.query(type, payload, createAnonymousUser(tenantId)));
|
|
283
|
+
}
|
|
284
|
+
// Shared by entry:"user" extra routes and GET /api/schema — both require a
|
|
285
|
+
// real, signed-in principal and reject the synthesised anonymousAccess user
|
|
286
|
+
// (SessionUser.roles includes ANONYMOUS_ROLE) the same way.
|
|
287
|
+
export function isMissingOrAnonymousUser(user) {
|
|
288
|
+
return !user || isAnonymousSessionUser(user);
|
|
289
|
+
}
|
|
290
|
+
export function unauthenticatedResponse(c) {
|
|
291
|
+
return c.json({
|
|
292
|
+
error: {
|
|
293
|
+
code: "unauthenticated",
|
|
294
|
+
httpStatus: 401,
|
|
295
|
+
message: "this route requires a signed-in user",
|
|
296
|
+
i18nKey: "auth.errors.missingToken",
|
|
297
|
+
},
|
|
298
|
+
}, 401);
|
|
299
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Hono } from "hono";
|
|
2
|
+
import { type TenantLifecycleStatusResolver } from "./auth-middleware.ts";
|
|
3
|
+
import type { ServerWiring } from "./server-wiring.ts";
|
|
4
|
+
export declare function mountWebSocketRoutes(app: Hono, wiring: Pick<ServerWiring, "options" | "dispatcher" | "clientIpResolver">, tenantLifecycleResolver: TenantLifecycleStatusResolver | undefined): void;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { createFallbackLogger } from "../logging/index.js";
|
|
2
|
+
import { getAuthTokenExpiry, getUser, } from "./auth-middleware.js";
|
|
3
|
+
import { clientIpSourceFromHonoContext } from "./client-ip.js";
|
|
4
|
+
import { isWebSocketOriginAllowed, normalizeOrigin, rejectOrigin } from "./origin-middleware.js";
|
|
5
|
+
import { requestContext } from "./request-context.js";
|
|
6
|
+
import { isMissingOrAnonymousUser, unauthenticatedResponse } from "./server-routes.js";
|
|
7
|
+
import { buildWebSocketSessionRevalidator, createWebSocketConnectionLimiter, hasWebSocketUpgradeServer, isWebSocketUpgradeRequest, WEBSOCKET_DEFAULT_MAX_CONNECTIONS_PER_USER, WEBSOCKET_DEFAULT_MAX_MESSAGE_BYTES, } from "./websocket-route.js";
|
|
8
|
+
export function mountWebSocketRoutes(app, wiring, tenantLifecycleResolver) {
|
|
9
|
+
const { options, dispatcher, clientIpResolver } = wiring;
|
|
10
|
+
// r.webSocketRoute — GET routes under /api/ws/*, so the jwt/pat/rate-limit
|
|
11
|
+
// chain above already ran. Origin/CSRF guards skip GETs, hence the own check.
|
|
12
|
+
const webSocketOriginAllowlist = options.auth?.allowedOrigins?.length
|
|
13
|
+
? new Set(options.auth.allowedOrigins.map(normalizeOrigin))
|
|
14
|
+
: undefined;
|
|
15
|
+
const webSocketRoutePaths = new Map();
|
|
16
|
+
const webSocketConnectionLimiter = createWebSocketConnectionLimiter();
|
|
17
|
+
for (const feature of options.registry.features.values()) {
|
|
18
|
+
for (const route of Object.values(feature.webSocketRoutes)) {
|
|
19
|
+
const owner = webSocketRoutePaths.get(route.path);
|
|
20
|
+
if (owner !== undefined) {
|
|
21
|
+
throw new Error(`[kumiko] WebSocket route "${route.path}" is declared by both feature "${owner}" and ` +
|
|
22
|
+
`"${feature.name}" — paths must be unique across features.`);
|
|
23
|
+
}
|
|
24
|
+
webSocketRoutePaths.set(route.path, feature.name);
|
|
25
|
+
app.get(route.path, buildWebSocketRouteHandler(route, {
|
|
26
|
+
dispatcher,
|
|
27
|
+
clientIpResolver,
|
|
28
|
+
originAllowlist: webSocketOriginAllowlist,
|
|
29
|
+
...(options.auth?.sessionChecker ? { sessionChecker: options.auth.sessionChecker } : {}),
|
|
30
|
+
...(tenantLifecycleResolver
|
|
31
|
+
? { resolveTenantLifecycleStatus: tenantLifecycleResolver }
|
|
32
|
+
: {}),
|
|
33
|
+
connectionLimiter: webSocketConnectionLimiter,
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const webSocketLog = createFallbackLogger("websocket");
|
|
39
|
+
function webSocketErrorResponse(c, status, code, message) {
|
|
40
|
+
return c.json({ error: { code, httpStatus: status, message } }, status);
|
|
41
|
+
}
|
|
42
|
+
function buildWebSocketRouteHandler(route, shared) {
|
|
43
|
+
return async (c) => {
|
|
44
|
+
if (!isWebSocketOriginAllowed(c, shared.originAllowlist))
|
|
45
|
+
return rejectOrigin(c);
|
|
46
|
+
const user = getUser(c);
|
|
47
|
+
if (isMissingOrAnonymousUser(user))
|
|
48
|
+
return unauthenticatedResponse(c);
|
|
49
|
+
if (!isWebSocketUpgradeRequest(c.req.raw)) {
|
|
50
|
+
return webSocketErrorResponse(c, 426, "websocket_upgrade_required", "this route only accepts WebSocket upgrade requests");
|
|
51
|
+
}
|
|
52
|
+
const honoEnv = c.env;
|
|
53
|
+
if (!hasWebSocketUpgradeServer(honoEnv)) {
|
|
54
|
+
const message = "webSocketUpgradeFetch not wired: pass it to buildBunServeOptions";
|
|
55
|
+
webSocketLog.error(message, { path: route.path });
|
|
56
|
+
return webSocketErrorResponse(c, 501, "websocket_upgrade_not_wired", message);
|
|
57
|
+
}
|
|
58
|
+
// The slot is taken before connect (a refused attempt must not run it) and stays synchronous with
|
|
59
|
+
// the check, so concurrent upgrades can't overshoot the cap. Every path without a live socket frees it.
|
|
60
|
+
const releaseConnectionSlot = shared.connectionLimiter.tryAcquire(`${route.path}\n${user.tenantId}\n${user.id}`, route.maxConnectionsPerUser ?? WEBSOCKET_DEFAULT_MAX_CONNECTIONS_PER_USER);
|
|
61
|
+
if (!releaseConnectionSlot) {
|
|
62
|
+
return webSocketErrorResponse(c, 429, "websocket_connection_limit", "too many open WebSocket connections for this user");
|
|
63
|
+
}
|
|
64
|
+
let upgraded = false;
|
|
65
|
+
try {
|
|
66
|
+
const handlers = await route.connect(c, {
|
|
67
|
+
user,
|
|
68
|
+
query: (type, payload) => shared.dispatcher.query(type, payload, user),
|
|
69
|
+
write: (type, payload) => shared.dispatcher.write(type, payload, user),
|
|
70
|
+
clientIp: shared.clientIpResolver.resolve(clientIpSourceFromHonoContext(c)),
|
|
71
|
+
});
|
|
72
|
+
if (handlers instanceof Response)
|
|
73
|
+
return handlers;
|
|
74
|
+
const captured = requestContext.get();
|
|
75
|
+
const requestContextData = captured ? withoutAbortSignal(captured) : undefined;
|
|
76
|
+
const revalidateSession = buildWebSocketSessionRevalidator({
|
|
77
|
+
user,
|
|
78
|
+
sessionChecker: shared.sessionChecker,
|
|
79
|
+
resolveTenantLifecycleStatus: shared.resolveTenantLifecycleStatus,
|
|
80
|
+
tokenExpiresAtSec: getAuthTokenExpiry(c),
|
|
81
|
+
});
|
|
82
|
+
upgraded = honoEnv.server.upgrade(c.req.raw, {
|
|
83
|
+
data: {
|
|
84
|
+
handlers,
|
|
85
|
+
maxMessageBytes: route.maxMessageBytes ?? WEBSOCKET_DEFAULT_MAX_MESSAGE_BYTES,
|
|
86
|
+
requestContextData,
|
|
87
|
+
revalidateSession,
|
|
88
|
+
releaseConnectionSlot,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
if (!upgraded) {
|
|
92
|
+
return webSocketErrorResponse(c, 400, "websocket_upgrade_failed", "the WebSocket upgrade was rejected");
|
|
93
|
+
}
|
|
94
|
+
// Bun ignores the returned Response after a successful upgrade.
|
|
95
|
+
return new Response(null);
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
if (!upgraded)
|
|
99
|
+
releaseConnectionSlot();
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
// The request's AbortSignal fires when the upgrade request ends, which would
|
|
104
|
+
// abort every later handler running under the captured context.
|
|
105
|
+
function withoutAbortSignal(data) {
|
|
106
|
+
const { signal: _signal, ...rest } = data;
|
|
107
|
+
return rest;
|
|
108
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CacheSyncBus } from "@cosmicdrift/kumiko-types/cache-sync-types";
|
|
2
|
+
import type { DbConnection } from "../db/connection.ts";
|
|
3
|
+
import type { AppContext, Registry } from "../engine/types/index.ts";
|
|
4
|
+
import { type ObservabilityProvider } from "../observability/index.ts";
|
|
5
|
+
import { type Dispatcher } from "../pipeline/dispatcher.ts";
|
|
6
|
+
import type { EventConsumer, EventDispatcher } from "../pipeline/event-dispatcher.ts";
|
|
7
|
+
import { type LifecycleHooks } from "../pipeline/lifecycle-pipeline.ts";
|
|
8
|
+
import { type ClientIpResolver } from "./client-ip.ts";
|
|
9
|
+
import { type JwtHelper } from "./jwt.ts";
|
|
10
|
+
import type { ServerOptions } from "./server.ts";
|
|
11
|
+
import { type BootLogger } from "./server-boot-checks.ts";
|
|
12
|
+
import type { SseBroker } from "./sse-broker.ts";
|
|
13
|
+
export declare function withFileProviderResolver(registry: Registry, context: AppContext, cacheSync?: CacheSyncBus): AppContext;
|
|
14
|
+
export type ServerWiring = {
|
|
15
|
+
readonly options: ServerOptions;
|
|
16
|
+
readonly bootLog: BootLogger;
|
|
17
|
+
readonly clientIpResolver: ClientIpResolver;
|
|
18
|
+
readonly jwt: JwtHelper;
|
|
19
|
+
readonly sseBroker: SseBroker;
|
|
20
|
+
readonly observability: ObservabilityProvider;
|
|
21
|
+
readonly tracedRedis: AppContext["redis"];
|
|
22
|
+
readonly rateLimitResolver: AppContext["rateLimit"];
|
|
23
|
+
readonly rateLimitMiddlewareRequested: boolean;
|
|
24
|
+
readonly context: AppContext;
|
|
25
|
+
readonly fileProviderResolver: AppContext["_fileProviderResolver"];
|
|
26
|
+
readonly dispatcher: Dispatcher;
|
|
27
|
+
readonly lifecycleHooks: LifecycleHooks;
|
|
28
|
+
readonly baseDb: DbConnection | undefined;
|
|
29
|
+
readonly eventConsumers: readonly EventConsumer[];
|
|
30
|
+
readonly eventDispatcher: EventDispatcher | undefined;
|
|
31
|
+
};
|
|
32
|
+
export declare function resolveServerWiring(options: ServerOptions): ServerWiring;
|