@fuzdev/fuz_app 0.1.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/LICENSE +21 -0
- package/README.md +49 -0
- package/dist/actions/action_bridge.d.ts +65 -0
- package/dist/actions/action_bridge.d.ts.map +1 -0
- package/dist/actions/action_bridge.js +76 -0
- package/dist/actions/action_codegen.d.ts +97 -0
- package/dist/actions/action_codegen.d.ts.map +1 -0
- package/dist/actions/action_codegen.js +280 -0
- package/dist/actions/action_registry.d.ts +35 -0
- package/dist/actions/action_registry.d.ts.map +1 -0
- package/dist/actions/action_registry.js +83 -0
- package/dist/actions/action_spec.d.ts +169 -0
- package/dist/actions/action_spec.d.ts.map +1 -0
- package/dist/actions/action_spec.js +76 -0
- package/dist/auth/account_queries.d.ts +96 -0
- package/dist/auth/account_queries.d.ts.map +1 -0
- package/dist/auth/account_queries.js +172 -0
- package/dist/auth/account_routes.d.ts +86 -0
- package/dist/auth/account_routes.d.ts.map +1 -0
- package/dist/auth/account_routes.js +406 -0
- package/dist/auth/account_schema.d.ts +192 -0
- package/dist/auth/account_schema.d.ts.map +1 -0
- package/dist/auth/account_schema.js +105 -0
- package/dist/auth/admin_routes.d.ts +29 -0
- package/dist/auth/admin_routes.d.ts.map +1 -0
- package/dist/auth/admin_routes.js +193 -0
- package/dist/auth/api_token.d.ts +33 -0
- package/dist/auth/api_token.d.ts.map +1 -0
- package/dist/auth/api_token.js +36 -0
- package/dist/auth/api_token_queries.d.ts +80 -0
- package/dist/auth/api_token_queries.d.ts.map +1 -0
- package/dist/auth/api_token_queries.js +116 -0
- package/dist/auth/app_settings_queries.d.ts +33 -0
- package/dist/auth/app_settings_queries.d.ts.map +1 -0
- package/dist/auth/app_settings_queries.js +51 -0
- package/dist/auth/app_settings_routes.d.ts +27 -0
- package/dist/auth/app_settings_routes.d.ts.map +1 -0
- package/dist/auth/app_settings_routes.js +66 -0
- package/dist/auth/app_settings_schema.d.ts +35 -0
- package/dist/auth/app_settings_schema.d.ts.map +1 -0
- package/dist/auth/app_settings_schema.js +22 -0
- package/dist/auth/audit_log_queries.d.ts +90 -0
- package/dist/auth/audit_log_queries.d.ts.map +1 -0
- package/dist/auth/audit_log_queries.js +205 -0
- package/dist/auth/audit_log_routes.d.ts +33 -0
- package/dist/auth/audit_log_routes.d.ts.map +1 -0
- package/dist/auth/audit_log_routes.js +106 -0
- package/dist/auth/audit_log_schema.d.ts +259 -0
- package/dist/auth/audit_log_schema.d.ts.map +1 -0
- package/dist/auth/audit_log_schema.js +123 -0
- package/dist/auth/bearer_auth.d.ts +32 -0
- package/dist/auth/bearer_auth.d.ts.map +1 -0
- package/dist/auth/bearer_auth.js +90 -0
- package/dist/auth/bootstrap_account.d.ts +82 -0
- package/dist/auth/bootstrap_account.d.ts.map +1 -0
- package/dist/auth/bootstrap_account.js +97 -0
- package/dist/auth/bootstrap_routes.d.ts +74 -0
- package/dist/auth/bootstrap_routes.d.ts.map +1 -0
- package/dist/auth/bootstrap_routes.js +154 -0
- package/dist/auth/daemon_token.d.ts +49 -0
- package/dist/auth/daemon_token.d.ts.map +1 -0
- package/dist/auth/daemon_token.js +49 -0
- package/dist/auth/daemon_token_middleware.d.ts +93 -0
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -0
- package/dist/auth/daemon_token_middleware.js +167 -0
- package/dist/auth/ddl.d.ts +27 -0
- package/dist/auth/ddl.d.ts.map +1 -0
- package/dist/auth/ddl.js +111 -0
- package/dist/auth/deps.d.ts +52 -0
- package/dist/auth/deps.d.ts.map +1 -0
- package/dist/auth/deps.js +10 -0
- package/dist/auth/invite_queries.d.ts +68 -0
- package/dist/auth/invite_queries.d.ts.map +1 -0
- package/dist/auth/invite_queries.js +105 -0
- package/dist/auth/invite_routes.d.ts +18 -0
- package/dist/auth/invite_routes.d.ts.map +1 -0
- package/dist/auth/invite_routes.js +129 -0
- package/dist/auth/invite_schema.d.ts +51 -0
- package/dist/auth/invite_schema.d.ts.map +1 -0
- package/dist/auth/invite_schema.js +25 -0
- package/dist/auth/keyring.d.ts +87 -0
- package/dist/auth/keyring.d.ts.map +1 -0
- package/dist/auth/keyring.js +142 -0
- package/dist/auth/middleware.d.ts +40 -0
- package/dist/auth/middleware.d.ts.map +1 -0
- package/dist/auth/middleware.js +64 -0
- package/dist/auth/migrations.d.ts +42 -0
- package/dist/auth/migrations.d.ts.map +1 -0
- package/dist/auth/migrations.js +79 -0
- package/dist/auth/password.d.ts +39 -0
- package/dist/auth/password.d.ts.map +1 -0
- package/dist/auth/password.js +25 -0
- package/dist/auth/password_argon2.d.ts +43 -0
- package/dist/auth/password_argon2.d.ts.map +1 -0
- package/dist/auth/password_argon2.js +76 -0
- package/dist/auth/permit_queries.d.ts +72 -0
- package/dist/auth/permit_queries.d.ts.map +1 -0
- package/dist/auth/permit_queries.js +116 -0
- package/dist/auth/request_context.d.ts +114 -0
- package/dist/auth/request_context.d.ts.map +1 -0
- package/dist/auth/request_context.js +176 -0
- package/dist/auth/require_keeper.d.ts +20 -0
- package/dist/auth/require_keeper.d.ts.map +1 -0
- package/dist/auth/require_keeper.js +35 -0
- package/dist/auth/role_schema.d.ts +69 -0
- package/dist/auth/role_schema.d.ts.map +1 -0
- package/dist/auth/role_schema.js +70 -0
- package/dist/auth/route_guards.d.ts +21 -0
- package/dist/auth/route_guards.d.ts.map +1 -0
- package/dist/auth/route_guards.js +32 -0
- package/dist/auth/session_cookie.d.ts +158 -0
- package/dist/auth/session_cookie.d.ts.map +1 -0
- package/dist/auth/session_cookie.js +135 -0
- package/dist/auth/session_lifecycle.d.ts +35 -0
- package/dist/auth/session_lifecycle.d.ts.map +1 -0
- package/dist/auth/session_lifecycle.js +27 -0
- package/dist/auth/session_middleware.d.ts +33 -0
- package/dist/auth/session_middleware.d.ts.map +1 -0
- package/dist/auth/session_middleware.js +62 -0
- package/dist/auth/session_queries.d.ts +135 -0
- package/dist/auth/session_queries.d.ts.map +1 -0
- package/dist/auth/session_queries.js +186 -0
- package/dist/auth/signup_routes.d.ts +32 -0
- package/dist/auth/signup_routes.d.ts.map +1 -0
- package/dist/auth/signup_routes.js +150 -0
- package/dist/cli/args.d.ts +48 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +76 -0
- package/dist/cli/config.d.ts +48 -0
- package/dist/cli/config.d.ts.map +1 -0
- package/dist/cli/config.js +77 -0
- package/dist/cli/daemon.d.ts +82 -0
- package/dist/cli/daemon.d.ts.map +1 -0
- package/dist/cli/daemon.js +149 -0
- package/dist/cli/help.d.ts +85 -0
- package/dist/cli/help.d.ts.map +1 -0
- package/dist/cli/help.js +138 -0
- package/dist/cli/logger.d.ts +46 -0
- package/dist/cli/logger.d.ts.map +1 -0
- package/dist/cli/logger.js +48 -0
- package/dist/cli/util.d.ts +36 -0
- package/dist/cli/util.d.ts.map +1 -0
- package/dist/cli/util.js +50 -0
- package/dist/crypto.d.ts +13 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +19 -0
- package/dist/db/assert_row.d.ts +18 -0
- package/dist/db/assert_row.d.ts.map +1 -0
- package/dist/db/assert_row.js +24 -0
- package/dist/db/create_db.d.ts +38 -0
- package/dist/db/create_db.d.ts.map +1 -0
- package/dist/db/create_db.js +57 -0
- package/dist/db/db.d.ts +97 -0
- package/dist/db/db.d.ts.map +1 -0
- package/dist/db/db.js +76 -0
- package/dist/db/db_pg.d.ts +21 -0
- package/dist/db/db_pg.d.ts.map +1 -0
- package/dist/db/db_pg.js +45 -0
- package/dist/db/db_pglite.d.ts +21 -0
- package/dist/db/db_pglite.d.ts.map +1 -0
- package/dist/db/db_pglite.js +28 -0
- package/dist/db/migrate.d.ts +67 -0
- package/dist/db/migrate.d.ts.map +1 -0
- package/dist/db/migrate.js +118 -0
- package/dist/db/pg_error.d.ts +16 -0
- package/dist/db/pg_error.d.ts.map +1 -0
- package/dist/db/pg_error.js +15 -0
- package/dist/db/query_deps.d.ts +14 -0
- package/dist/db/query_deps.d.ts.map +1 -0
- package/dist/db/query_deps.js +9 -0
- package/dist/db/sql_identifier.d.ts +27 -0
- package/dist/db/sql_identifier.d.ts.map +1 -0
- package/dist/db/sql_identifier.js +31 -0
- package/dist/db/status.d.ts +62 -0
- package/dist/db/status.d.ts.map +1 -0
- package/dist/db/status.js +116 -0
- package/dist/dev/setup.d.ts +159 -0
- package/dist/dev/setup.d.ts.map +1 -0
- package/dist/dev/setup.js +265 -0
- package/dist/env/dotenv.d.ts +25 -0
- package/dist/env/dotenv.d.ts.map +1 -0
- package/dist/env/dotenv.js +52 -0
- package/dist/env/load.d.ts +52 -0
- package/dist/env/load.d.ts.map +1 -0
- package/dist/env/load.js +79 -0
- package/dist/env/mask.d.ts +19 -0
- package/dist/env/mask.d.ts.map +1 -0
- package/dist/env/mask.js +26 -0
- package/dist/env/resolve.d.ts +126 -0
- package/dist/env/resolve.d.ts.map +1 -0
- package/dist/env/resolve.js +200 -0
- package/dist/hono_context.d.ts +48 -0
- package/dist/hono_context.d.ts.map +1 -0
- package/dist/hono_context.js +22 -0
- package/dist/http/common_routes.d.ts +52 -0
- package/dist/http/common_routes.d.ts.map +1 -0
- package/dist/http/common_routes.js +65 -0
- package/dist/http/db_routes.d.ts +57 -0
- package/dist/http/db_routes.d.ts.map +1 -0
- package/dist/http/db_routes.js +176 -0
- package/dist/http/error_schemas.d.ts +169 -0
- package/dist/http/error_schemas.d.ts.map +1 -0
- package/dist/http/error_schemas.js +178 -0
- package/dist/http/middleware_spec.d.ts +19 -0
- package/dist/http/middleware_spec.d.ts.map +1 -0
- package/dist/http/middleware_spec.js +9 -0
- package/dist/http/origin.d.ts +57 -0
- package/dist/http/origin.d.ts.map +1 -0
- package/dist/http/origin.js +207 -0
- package/dist/http/proxy.d.ts +112 -0
- package/dist/http/proxy.d.ts.map +1 -0
- package/dist/http/proxy.js +240 -0
- package/dist/http/route_spec.d.ts +197 -0
- package/dist/http/route_spec.d.ts.map +1 -0
- package/dist/http/route_spec.js +243 -0
- package/dist/http/schema_helpers.d.ts +64 -0
- package/dist/http/schema_helpers.d.ts.map +1 -0
- package/dist/http/schema_helpers.js +90 -0
- package/dist/http/surface.d.ts +132 -0
- package/dist/http/surface.d.ts.map +1 -0
- package/dist/http/surface.js +156 -0
- package/dist/http/surface_query.d.ts +77 -0
- package/dist/http/surface_query.d.ts.map +1 -0
- package/dist/http/surface_query.js +86 -0
- package/dist/rate_limiter.d.ts +94 -0
- package/dist/rate_limiter.d.ts.map +1 -0
- package/dist/rate_limiter.js +156 -0
- package/dist/realtime/sse.d.ts +80 -0
- package/dist/realtime/sse.d.ts.map +1 -0
- package/dist/realtime/sse.js +109 -0
- package/dist/realtime/sse_auth_guard.d.ts +93 -0
- package/dist/realtime/sse_auth_guard.d.ts.map +1 -0
- package/dist/realtime/sse_auth_guard.js +111 -0
- package/dist/realtime/subscriber_registry.d.ts +85 -0
- package/dist/realtime/subscriber_registry.d.ts.map +1 -0
- package/dist/realtime/subscriber_registry.js +108 -0
- package/dist/runtime/deno.d.ts +21 -0
- package/dist/runtime/deno.d.ts.map +1 -0
- package/dist/runtime/deno.js +83 -0
- package/dist/runtime/deps.d.ts +113 -0
- package/dist/runtime/deps.d.ts.map +1 -0
- package/dist/runtime/deps.js +10 -0
- package/dist/runtime/fs.d.ts +15 -0
- package/dist/runtime/fs.d.ts.map +1 -0
- package/dist/runtime/fs.js +17 -0
- package/dist/runtime/mock.d.ts +81 -0
- package/dist/runtime/mock.d.ts.map +1 -0
- package/dist/runtime/mock.js +195 -0
- package/dist/runtime/node.d.ts +17 -0
- package/dist/runtime/node.d.ts.map +1 -0
- package/dist/runtime/node.js +117 -0
- package/dist/schema_meta.d.ts +16 -0
- package/dist/schema_meta.d.ts.map +1 -0
- package/dist/schema_meta.js +9 -0
- package/dist/sensitivity.d.ts +15 -0
- package/dist/sensitivity.d.ts.map +1 -0
- package/dist/sensitivity.js +9 -0
- package/dist/server/app_backend.d.ts +74 -0
- package/dist/server/app_backend.d.ts.map +1 -0
- package/dist/server/app_backend.js +39 -0
- package/dist/server/app_server.d.ts +201 -0
- package/dist/server/app_server.d.ts.map +1 -0
- package/dist/server/app_server.js +266 -0
- package/dist/server/env.d.ts +68 -0
- package/dist/server/env.d.ts.map +1 -0
- package/dist/server/env.js +95 -0
- package/dist/server/startup.d.ts +22 -0
- package/dist/server/startup.d.ts.map +1 -0
- package/dist/server/startup.js +48 -0
- package/dist/server/static.d.ts +39 -0
- package/dist/server/static.d.ts.map +1 -0
- package/dist/server/static.js +38 -0
- package/dist/server/validate_nginx.d.ts +34 -0
- package/dist/server/validate_nginx.d.ts.map +1 -0
- package/dist/server/validate_nginx.js +118 -0
- package/dist/testing/CLAUDE.md +3 -0
- package/dist/testing/admin_integration.d.ts +45 -0
- package/dist/testing/admin_integration.d.ts.map +1 -0
- package/dist/testing/admin_integration.js +840 -0
- package/dist/testing/adversarial_404.d.ts +15 -0
- package/dist/testing/adversarial_404.d.ts.map +1 -0
- package/dist/testing/adversarial_404.js +118 -0
- package/dist/testing/adversarial_headers.d.ts +36 -0
- package/dist/testing/adversarial_headers.d.ts.map +1 -0
- package/dist/testing/adversarial_headers.js +128 -0
- package/dist/testing/adversarial_input.d.ts +56 -0
- package/dist/testing/adversarial_input.d.ts.map +1 -0
- package/dist/testing/adversarial_input.js +494 -0
- package/dist/testing/app_server.d.ts +169 -0
- package/dist/testing/app_server.d.ts.map +1 -0
- package/dist/testing/app_server.js +240 -0
- package/dist/testing/assert_dev_env.d.ts +10 -0
- package/dist/testing/assert_dev_env.d.ts.map +1 -0
- package/dist/testing/assert_dev_env.js +13 -0
- package/dist/testing/assertions.d.ts +61 -0
- package/dist/testing/assertions.d.ts.map +1 -0
- package/dist/testing/assertions.js +96 -0
- package/dist/testing/attack_surface.d.ts +63 -0
- package/dist/testing/attack_surface.d.ts.map +1 -0
- package/dist/testing/attack_surface.js +224 -0
- package/dist/testing/audit_completeness.d.ts +29 -0
- package/dist/testing/audit_completeness.d.ts.map +1 -0
- package/dist/testing/audit_completeness.js +410 -0
- package/dist/testing/auth_apps.d.ts +55 -0
- package/dist/testing/auth_apps.d.ts.map +1 -0
- package/dist/testing/auth_apps.js +122 -0
- package/dist/testing/data_exposure.d.ts +62 -0
- package/dist/testing/data_exposure.d.ts.map +1 -0
- package/dist/testing/data_exposure.js +297 -0
- package/dist/testing/db.d.ts +111 -0
- package/dist/testing/db.d.ts.map +1 -0
- package/dist/testing/db.js +258 -0
- package/dist/testing/entities.d.ts +21 -0
- package/dist/testing/entities.d.ts.map +1 -0
- package/dist/testing/entities.js +42 -0
- package/dist/testing/error_coverage.d.ts +78 -0
- package/dist/testing/error_coverage.d.ts.map +1 -0
- package/dist/testing/error_coverage.js +135 -0
- package/dist/testing/integration.d.ts +37 -0
- package/dist/testing/integration.d.ts.map +1 -0
- package/dist/testing/integration.js +1139 -0
- package/dist/testing/integration_helpers.d.ts +107 -0
- package/dist/testing/integration_helpers.d.ts.map +1 -0
- package/dist/testing/integration_helpers.js +246 -0
- package/dist/testing/middleware.d.ts +125 -0
- package/dist/testing/middleware.d.ts.map +1 -0
- package/dist/testing/middleware.js +210 -0
- package/dist/testing/rate_limiting.d.ts +43 -0
- package/dist/testing/rate_limiting.d.ts.map +1 -0
- package/dist/testing/rate_limiting.js +216 -0
- package/dist/testing/round_trip.d.ts +37 -0
- package/dist/testing/round_trip.d.ts.map +1 -0
- package/dist/testing/round_trip.js +128 -0
- package/dist/testing/schema_generators.d.ts +33 -0
- package/dist/testing/schema_generators.d.ts.map +1 -0
- package/dist/testing/schema_generators.js +137 -0
- package/dist/testing/standard.d.ts +49 -0
- package/dist/testing/standard.d.ts.map +1 -0
- package/dist/testing/standard.js +16 -0
- package/dist/testing/stubs.d.ts +96 -0
- package/dist/testing/stubs.d.ts.map +1 -0
- package/dist/testing/stubs.js +192 -0
- package/dist/testing/surface_invariants.d.ts +189 -0
- package/dist/testing/surface_invariants.d.ts.map +1 -0
- package/dist/testing/surface_invariants.js +450 -0
- package/dist/ui/AccountSessions.svelte +75 -0
- package/dist/ui/AccountSessions.svelte.d.ts +19 -0
- package/dist/ui/AccountSessions.svelte.d.ts.map +1 -0
- package/dist/ui/AdminAccounts.svelte +107 -0
- package/dist/ui/AdminAccounts.svelte.d.ts +19 -0
- package/dist/ui/AdminAccounts.svelte.d.ts.map +1 -0
- package/dist/ui/AdminAuditLog.svelte +144 -0
- package/dist/ui/AdminAuditLog.svelte.d.ts +4 -0
- package/dist/ui/AdminAuditLog.svelte.d.ts.map +1 -0
- package/dist/ui/AdminInvites.svelte +142 -0
- package/dist/ui/AdminInvites.svelte.d.ts +4 -0
- package/dist/ui/AdminInvites.svelte.d.ts.map +1 -0
- package/dist/ui/AdminOverview.svelte +337 -0
- package/dist/ui/AdminOverview.svelte.d.ts +4 -0
- package/dist/ui/AdminOverview.svelte.d.ts.map +1 -0
- package/dist/ui/AdminPermitHistory.svelte +61 -0
- package/dist/ui/AdminPermitHistory.svelte.d.ts +19 -0
- package/dist/ui/AdminPermitHistory.svelte.d.ts.map +1 -0
- package/dist/ui/AdminSessions.svelte +85 -0
- package/dist/ui/AdminSessions.svelte.d.ts +19 -0
- package/dist/ui/AdminSessions.svelte.d.ts.map +1 -0
- package/dist/ui/AdminSettings.svelte +32 -0
- package/dist/ui/AdminSettings.svelte.d.ts +19 -0
- package/dist/ui/AdminSettings.svelte.d.ts.map +1 -0
- package/dist/ui/AdminSurface.svelte +42 -0
- package/dist/ui/AdminSurface.svelte.d.ts +4 -0
- package/dist/ui/AdminSurface.svelte.d.ts.map +1 -0
- package/dist/ui/AppShell.svelte +93 -0
- package/dist/ui/AppShell.svelte.d.ts +20 -0
- package/dist/ui/AppShell.svelte.d.ts.map +1 -0
- package/dist/ui/BootstrapForm.svelte +105 -0
- package/dist/ui/BootstrapForm.svelte.d.ts +4 -0
- package/dist/ui/BootstrapForm.svelte.d.ts.map +1 -0
- package/dist/ui/ColumnLayout.svelte +46 -0
- package/dist/ui/ColumnLayout.svelte.d.ts +11 -0
- package/dist/ui/ColumnLayout.svelte.d.ts.map +1 -0
- package/dist/ui/ConfirmButton.svelte +125 -0
- package/dist/ui/ConfirmButton.svelte.d.ts +54 -0
- package/dist/ui/ConfirmButton.svelte.d.ts.map +1 -0
- package/dist/ui/Datatable.svelte +185 -0
- package/dist/ui/Datatable.svelte.d.ts +35 -0
- package/dist/ui/Datatable.svelte.d.ts.map +1 -0
- package/dist/ui/LoginForm.svelte +82 -0
- package/dist/ui/LoginForm.svelte.d.ts +8 -0
- package/dist/ui/LoginForm.svelte.d.ts.map +1 -0
- package/dist/ui/LogoutButton.svelte +36 -0
- package/dist/ui/LogoutButton.svelte.d.ts +10 -0
- package/dist/ui/LogoutButton.svelte.d.ts.map +1 -0
- package/dist/ui/MenuLink.svelte +35 -0
- package/dist/ui/MenuLink.svelte.d.ts +12 -0
- package/dist/ui/MenuLink.svelte.d.ts.map +1 -0
- package/dist/ui/OpenSignupToggle.svelte +36 -0
- package/dist/ui/OpenSignupToggle.svelte.d.ts +19 -0
- package/dist/ui/OpenSignupToggle.svelte.d.ts.map +1 -0
- package/dist/ui/PopoverButton.svelte +136 -0
- package/dist/ui/PopoverButton.svelte.d.ts +63 -0
- package/dist/ui/PopoverButton.svelte.d.ts.map +1 -0
- package/dist/ui/SignupForm.svelte +117 -0
- package/dist/ui/SignupForm.svelte.d.ts +7 -0
- package/dist/ui/SignupForm.svelte.d.ts.map +1 -0
- package/dist/ui/SurfaceExplorer.svelte +287 -0
- package/dist/ui/SurfaceExplorer.svelte.d.ts +8 -0
- package/dist/ui/SurfaceExplorer.svelte.d.ts.map +1 -0
- package/dist/ui/account_sessions_state.svelte.d.ts +15 -0
- package/dist/ui/account_sessions_state.svelte.d.ts.map +1 -0
- package/dist/ui/account_sessions_state.svelte.js +45 -0
- package/dist/ui/admin_accounts_state.svelte.d.ts +19 -0
- package/dist/ui/admin_accounts_state.svelte.d.ts.map +1 -0
- package/dist/ui/admin_accounts_state.svelte.js +65 -0
- package/dist/ui/admin_invites_state.svelte.d.ts +19 -0
- package/dist/ui/admin_invites_state.svelte.d.ts.map +1 -0
- package/dist/ui/admin_invites_state.svelte.js +71 -0
- package/dist/ui/admin_sessions_state.svelte.d.ts +18 -0
- package/dist/ui/admin_sessions_state.svelte.d.ts.map +1 -0
- package/dist/ui/admin_sessions_state.svelte.js +62 -0
- package/dist/ui/app_settings_state.svelte.d.ts +14 -0
- package/dist/ui/app_settings_state.svelte.d.ts.map +1 -0
- package/dist/ui/app_settings_state.svelte.js +44 -0
- package/dist/ui/audit_log_state.svelte.d.ts +40 -0
- package/dist/ui/audit_log_state.svelte.d.ts.map +1 -0
- package/dist/ui/audit_log_state.svelte.js +153 -0
- package/dist/ui/auth_state.svelte.d.ts +85 -0
- package/dist/ui/auth_state.svelte.d.ts.map +1 -0
- package/dist/ui/auth_state.svelte.js +238 -0
- package/dist/ui/datatable.d.ts +25 -0
- package/dist/ui/datatable.d.ts.map +1 -0
- package/dist/ui/datatable.js +9 -0
- package/dist/ui/enter_advance.d.ts +13 -0
- package/dist/ui/enter_advance.d.ts.map +1 -0
- package/dist/ui/enter_advance.js +30 -0
- package/dist/ui/loadable.svelte.d.ts +55 -0
- package/dist/ui/loadable.svelte.d.ts.map +1 -0
- package/dist/ui/loadable.svelte.js +75 -0
- package/dist/ui/popover.svelte.d.ts +137 -0
- package/dist/ui/popover.svelte.d.ts.map +1 -0
- package/dist/ui/popover.svelte.js +288 -0
- package/dist/ui/position_helpers.d.ts +27 -0
- package/dist/ui/position_helpers.d.ts.map +1 -0
- package/dist/ui/position_helpers.js +81 -0
- package/dist/ui/sidebar_state.svelte.d.ts +30 -0
- package/dist/ui/sidebar_state.svelte.d.ts.map +1 -0
- package/dist/ui/sidebar_state.svelte.js +39 -0
- package/dist/ui/table_state.svelte.d.ts +63 -0
- package/dist/ui/table_state.svelte.d.ts.map +1 -0
- package/dist/ui/table_state.svelte.js +117 -0
- package/dist/ui/ui_fetch.d.ts +29 -0
- package/dist/ui/ui_fetch.d.ts.map +1 -0
- package/dist/ui/ui_fetch.js +37 -0
- package/dist/ui/ui_format.d.ts +63 -0
- package/dist/ui/ui_format.d.ts.map +1 -0
- package/dist/ui/ui_format.js +196 -0
- package/package.json +121 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* App backend types and factory — database initialization + auth migrations + deps.
|
|
3
|
+
*
|
|
4
|
+
* Provides `AppBackend`, `CreateAppBackendOptions`, and `create_app_backend()`.
|
|
5
|
+
*
|
|
6
|
+
* **Vocabulary**:
|
|
7
|
+
* - `AppDeps` — stateless capabilities: injectable, swappable per environment
|
|
8
|
+
* - `*Options` — static values set at startup, per-factory configuration
|
|
9
|
+
* - Runtime state — mutable values (e.g., `bootstrap_status`) — NOT in deps or options
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import { Logger } from '@fuzdev/fuz_util/log.js';
|
|
14
|
+
import type { AppDeps } from '../auth/deps.js';
|
|
15
|
+
import type { AuditLogEvent } from '../auth/audit_log_schema.js';
|
|
16
|
+
import type { DbType } from '../db/db.js';
|
|
17
|
+
import type { Keyring } from '../auth/keyring.js';
|
|
18
|
+
import type { PasswordHashDeps } from '../auth/password.js';
|
|
19
|
+
import type { StatResult } from '../runtime/deps.js';
|
|
20
|
+
import { type MigrationResult } from '../db/migrate.js';
|
|
21
|
+
/**
|
|
22
|
+
* Result of `create_app_backend()` — database metadata + deps bundle.
|
|
23
|
+
*
|
|
24
|
+
* This is the initialized backend, not the HTTP server.
|
|
25
|
+
* Pass it to `create_app_server()` to assemble the Hono app.
|
|
26
|
+
*/
|
|
27
|
+
export interface AppBackend {
|
|
28
|
+
deps: AppDeps;
|
|
29
|
+
db_type: DbType;
|
|
30
|
+
db_name: string;
|
|
31
|
+
/** Migration results from `create_app_backend` (auth migrations only). */
|
|
32
|
+
readonly migration_results: ReadonlyArray<MigrationResult>;
|
|
33
|
+
/** Close the database connection. Bound to the actual driver. */
|
|
34
|
+
close: () => Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Input for `create_app_backend()`.
|
|
38
|
+
*
|
|
39
|
+
* `keyring` is passed pre-validated — callers handle their own error reporting
|
|
40
|
+
* (e.g., tx uses `runtime.exit(1)` on invalid keys).
|
|
41
|
+
*/
|
|
42
|
+
export interface CreateAppBackendOptions {
|
|
43
|
+
/** Get file/directory stats, or null if path doesn't exist. */
|
|
44
|
+
stat: (path: string) => Promise<StatResult | null>;
|
|
45
|
+
/** Read a file as text. */
|
|
46
|
+
read_file: (path: string) => Promise<string>;
|
|
47
|
+
/** Delete a file. */
|
|
48
|
+
delete_file: (path: string) => Promise<void>;
|
|
49
|
+
/** Database connection URL (`postgres://`, `file://`, or `memory://`). */
|
|
50
|
+
database_url: string;
|
|
51
|
+
/** Validated cookie signing keyring. */
|
|
52
|
+
keyring: Keyring;
|
|
53
|
+
/** Password hashing implementation. Use `argon2_password_deps` in production. */
|
|
54
|
+
password: PasswordHashDeps;
|
|
55
|
+
/** Structured logger instance. Omit for default (`new Logger('server')`). */
|
|
56
|
+
log?: Logger;
|
|
57
|
+
/**
|
|
58
|
+
* Called after each audit log INSERT succeeds.
|
|
59
|
+
* Use to broadcast audit events via SSE. Flows through `AppDeps`
|
|
60
|
+
* to all route factories automatically. Defaults to a noop.
|
|
61
|
+
*/
|
|
62
|
+
on_audit_event?: (event: AuditLogEvent) => void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Initialize the backend: database + auth migrations + deps.
|
|
66
|
+
*
|
|
67
|
+
* Calls `create_db` → `run_migrations` (auth namespace) and bundles
|
|
68
|
+
* the result with the provided keyring and password deps.
|
|
69
|
+
*
|
|
70
|
+
* @param options - keyring, password deps, and optional database URL
|
|
71
|
+
* @returns app backend with deps, database metadata, and migration results
|
|
72
|
+
*/
|
|
73
|
+
export declare const create_app_backend: (options: CreateAppBackendOptions) => Promise<AppBackend>;
|
|
74
|
+
//# sourceMappingURL=app_backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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AwC;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,iFAAiF;IACjF,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,6EAA6E;IAC7E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;CAChD;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAAU,SAAS,uBAAuB,KAAG,OAAO,CAAC,UAAU,CAa7F,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* App backend types and factory — database initialization + auth migrations + deps.
|
|
3
|
+
*
|
|
4
|
+
* Provides `AppBackend`, `CreateAppBackendOptions`, and `create_app_backend()`.
|
|
5
|
+
*
|
|
6
|
+
* **Vocabulary**:
|
|
7
|
+
* - `AppDeps` — stateless capabilities: injectable, swappable per environment
|
|
8
|
+
* - `*Options` — static values set at startup, per-factory configuration
|
|
9
|
+
* - Runtime state — mutable values (e.g., `bootstrap_status`) — NOT in deps or options
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import { Logger } from '@fuzdev/fuz_util/log.js';
|
|
14
|
+
import { run_migrations } from '../db/migrate.js';
|
|
15
|
+
import { AUTH_MIGRATION_NS } from '../auth/migrations.js';
|
|
16
|
+
import { create_db } from '../db/create_db.js';
|
|
17
|
+
/**
|
|
18
|
+
* Initialize the backend: database + auth migrations + deps.
|
|
19
|
+
*
|
|
20
|
+
* Calls `create_db` → `run_migrations` (auth namespace) and bundles
|
|
21
|
+
* the result with the provided keyring and password deps.
|
|
22
|
+
*
|
|
23
|
+
* @param options - keyring, password deps, and optional database URL
|
|
24
|
+
* @returns app backend with deps, database metadata, and migration results
|
|
25
|
+
*/
|
|
26
|
+
export const create_app_backend = async (options) => {
|
|
27
|
+
const { database_url, keyring, password, stat, read_file, delete_file } = options;
|
|
28
|
+
const log = options.log ?? new Logger('server');
|
|
29
|
+
const on_audit_event = options.on_audit_event ?? (() => { }); // eslint-disable-line @typescript-eslint/no-empty-function
|
|
30
|
+
const { db, close, db_type, db_name } = await create_db(database_url);
|
|
31
|
+
const migration_results = await run_migrations(db, [AUTH_MIGRATION_NS]);
|
|
32
|
+
return {
|
|
33
|
+
db_type,
|
|
34
|
+
db_name,
|
|
35
|
+
migration_results,
|
|
36
|
+
close,
|
|
37
|
+
deps: { keyring, password, db, stat, read_file, delete_file, log, on_audit_event },
|
|
38
|
+
};
|
|
39
|
+
};
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server assembly factory.
|
|
3
|
+
*
|
|
4
|
+
* `create_app_server()` eliminates the ~100 lines of duplicated server assembly
|
|
5
|
+
* shared by tx, visiones, and mageguild. Consumers provide a pre-initialized
|
|
6
|
+
* `AppBackend` and options (session, origins, routes); the factory handles
|
|
7
|
+
* middleware, bootstrap status, surface generation, and Hono app assembly.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { Hono, type Context } from 'hono';
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
import { type SessionOptions } from '../auth/session_cookie.js';
|
|
14
|
+
import type { BootstrapAccountSuccess } from '../auth/bootstrap_account.js';
|
|
15
|
+
import type { SseEventSpec } from '../realtime/sse.js';
|
|
16
|
+
import { type AuditLogSse } from '../realtime/sse_auth_guard.js';
|
|
17
|
+
import type { AppSettings } from '../auth/app_settings_schema.js';
|
|
18
|
+
import { type RateLimiter } from '../rate_limiter.js';
|
|
19
|
+
import type { DaemonTokenState } from '../auth/daemon_token.js';
|
|
20
|
+
import { type MigrationNamespace, type MigrationResult } from '../db/migrate.js';
|
|
21
|
+
import type { AppDeps } from '../auth/deps.js';
|
|
22
|
+
import type { AppBackend } from './app_backend.js';
|
|
23
|
+
import '../hono_context.js';
|
|
24
|
+
import { type ServeStaticFactory } from './static.js';
|
|
25
|
+
import { type AppSurfaceSpec } from '../http/surface.js';
|
|
26
|
+
import { type RouteSpec } from '../http/route_spec.js';
|
|
27
|
+
import type { MiddlewareSpec } from '../http/middleware_spec.js';
|
|
28
|
+
import { type BootstrapStatus } from '../auth/bootstrap_routes.js';
|
|
29
|
+
/**
|
|
30
|
+
* Context passed to `on_effect_error` when a pending effect rejects.
|
|
31
|
+
*/
|
|
32
|
+
export interface EffectErrorContext {
|
|
33
|
+
/** HTTP method of the request that spawned the effect. */
|
|
34
|
+
method: string;
|
|
35
|
+
/** URL path of the request that spawned the effect. */
|
|
36
|
+
path: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Configuration for `create_app_server()`.
|
|
40
|
+
*
|
|
41
|
+
* Requires a pre-initialized `AppBackend` from `create_app_backend()`.
|
|
42
|
+
* Two explicit steps: init backend then assemble server.
|
|
43
|
+
*/
|
|
44
|
+
export interface AppServerOptions {
|
|
45
|
+
/** Pre-initialized backend from `create_app_backend()`. */
|
|
46
|
+
backend: AppBackend;
|
|
47
|
+
/** Session options for cookie-based auth. */
|
|
48
|
+
session_options: SessionOptions<string>;
|
|
49
|
+
/** Parsed allowed origin patterns. */
|
|
50
|
+
allowed_origins: Array<RegExp>;
|
|
51
|
+
/** Trusted proxy options. */
|
|
52
|
+
proxy: {
|
|
53
|
+
trusted_proxies: Array<string>;
|
|
54
|
+
get_connection_ip: (c: Context) => string | undefined;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Shared IP rate limiter for login, bootstrap, and bearer auth.
|
|
58
|
+
* Omit or `undefined` to use a default limiter (5 attempts per 15 minutes).
|
|
59
|
+
* Pass `null` to explicitly disable rate limiting.
|
|
60
|
+
* Also available on `AppServerContext` for route factory callbacks.
|
|
61
|
+
*/
|
|
62
|
+
ip_rate_limiter?: RateLimiter | null;
|
|
63
|
+
/**
|
|
64
|
+
* Per-account rate limiter for login attempts.
|
|
65
|
+
* Omit or `undefined` to use a default limiter (10 attempts per 30 minutes).
|
|
66
|
+
* Pass `null` to explicitly disable rate limiting.
|
|
67
|
+
* Also available on `AppServerContext` for route factory callbacks.
|
|
68
|
+
*/
|
|
69
|
+
login_account_rate_limiter?: RateLimiter | null;
|
|
70
|
+
/**
|
|
71
|
+
* Per-account rate limiter for signup attempts, keyed by submitted username.
|
|
72
|
+
* Omit or `undefined` to use a default limiter (10 attempts per 30 minutes).
|
|
73
|
+
* Pass `null` to explicitly disable rate limiting.
|
|
74
|
+
* Also available on `AppServerContext` for route factory callbacks.
|
|
75
|
+
*/
|
|
76
|
+
signup_account_rate_limiter?: RateLimiter | null;
|
|
77
|
+
/**
|
|
78
|
+
* Rate limiter for bearer token auth attempts (per-IP).
|
|
79
|
+
* Omit or `undefined` to use a default limiter (5 attempts per 15 minutes).
|
|
80
|
+
* Pass `null` to explicitly disable rate limiting.
|
|
81
|
+
*/
|
|
82
|
+
bearer_ip_rate_limiter?: RateLimiter | null;
|
|
83
|
+
/**
|
|
84
|
+
* Maximum allowed request body size in bytes.
|
|
85
|
+
* Omit or `undefined` to use the default (1 MiB).
|
|
86
|
+
* Pass `null` to explicitly disable body size limiting.
|
|
87
|
+
*/
|
|
88
|
+
max_body_size?: number | null;
|
|
89
|
+
/** Daemon token state for keeper auth. Omit to disable. */
|
|
90
|
+
daemon_token_state?: DaemonTokenState;
|
|
91
|
+
/** Bootstrap options. Omit to skip bootstrap status check and routes. */
|
|
92
|
+
bootstrap?: {
|
|
93
|
+
token_path: string | null;
|
|
94
|
+
/** Route prefix for bootstrap routes. Default `'/api/account'`. */
|
|
95
|
+
route_prefix?: string;
|
|
96
|
+
/**
|
|
97
|
+
* Called after successful bootstrap (account + session created).
|
|
98
|
+
* Use for app-specific post-bootstrap work like generating API tokens.
|
|
99
|
+
*/
|
|
100
|
+
on_bootstrap?: (result: BootstrapAccountSuccess, c: Context) => Promise<void>;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Set to `false` to disable the auto-created surface route (`GET /api/surface`).
|
|
104
|
+
* Default: auto-created (authenticated).
|
|
105
|
+
*/
|
|
106
|
+
surface_route?: false;
|
|
107
|
+
/** Consumer migration namespaces — run after auth migrations during init. */
|
|
108
|
+
migration_namespaces?: Array<MigrationNamespace>;
|
|
109
|
+
/**
|
|
110
|
+
* Build route specs from the initialized backend.
|
|
111
|
+
* Called after all middleware is ready.
|
|
112
|
+
*/
|
|
113
|
+
create_route_specs: (context: AppServerContext) => Array<RouteSpec>;
|
|
114
|
+
/** Optional: transform middleware specs before applying. */
|
|
115
|
+
transform_middleware?: (specs: Array<MiddlewareSpec>) => Array<MiddlewareSpec>;
|
|
116
|
+
/**
|
|
117
|
+
* Enable factory-managed audit log SSE.
|
|
118
|
+
*
|
|
119
|
+
* When truthy, creates an `AuditLogSse` instance internally, wires `on_audit_event`
|
|
120
|
+
* on the backend deps (composing with any existing callback), and auto-includes
|
|
121
|
+
* `AUDIT_LOG_EVENT_SPECS` in the surface. The result is exposed on `AppServerContext`
|
|
122
|
+
* (for route factories) and `AppServer` (for the caller).
|
|
123
|
+
*
|
|
124
|
+
* Pass `true` for defaults (admin role), or `{role: 'custom'}` for a custom role.
|
|
125
|
+
* Omit to wire audit SSE manually.
|
|
126
|
+
*/
|
|
127
|
+
audit_log_sse?: true | {
|
|
128
|
+
role?: string;
|
|
129
|
+
};
|
|
130
|
+
/** SSE event specs for surface generation. Defaults to `[]` (no SSE events). */
|
|
131
|
+
event_specs?: Array<SseEventSpec>;
|
|
132
|
+
/** Env schema for surface generation. Pass `z.object({})` when there are no env vars beyond `BaseServerEnv`. */
|
|
133
|
+
env_schema: z.ZodObject;
|
|
134
|
+
/** Middleware applied after routes, before static serving. Included in surface. */
|
|
135
|
+
post_route_middleware?: Array<MiddlewareSpec>;
|
|
136
|
+
/** Static file serving. Omit if not serving static files. */
|
|
137
|
+
static_serving?: {
|
|
138
|
+
serve_static: ServeStaticFactory;
|
|
139
|
+
spa_fallback?: string;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Await all pending fire-and-forget effects before returning the response.
|
|
143
|
+
* Use in tests so audit log assertions don't need polling.
|
|
144
|
+
* Default `false` (production: true fire-and-forget).
|
|
145
|
+
*/
|
|
146
|
+
await_pending_effects?: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Called when a pending effect rejects.
|
|
149
|
+
* Use for monitoring, metrics, or alerting in production.
|
|
150
|
+
* Only called when `await_pending_effects` is `false` (production mode).
|
|
151
|
+
*/
|
|
152
|
+
on_effect_error?: (error: unknown, context: EffectErrorContext) => void;
|
|
153
|
+
/** Env values for startup summary logging. */
|
|
154
|
+
env_values?: Record<string, unknown>;
|
|
155
|
+
}
|
|
156
|
+
/** Context passed to `create_route_specs`. */
|
|
157
|
+
export interface AppServerContext {
|
|
158
|
+
deps: AppDeps;
|
|
159
|
+
backend: AppBackend;
|
|
160
|
+
bootstrap_status: BootstrapStatus;
|
|
161
|
+
session_options: SessionOptions<string>;
|
|
162
|
+
/** Shared IP rate limiter (from options). `null` when not configured. */
|
|
163
|
+
ip_rate_limiter: RateLimiter | null;
|
|
164
|
+
/** Per-account login rate limiter (from options). `null` when not configured. */
|
|
165
|
+
login_account_rate_limiter: RateLimiter | null;
|
|
166
|
+
/** Per-account signup rate limiter (from options). `null` when not configured. */
|
|
167
|
+
signup_account_rate_limiter: RateLimiter | null;
|
|
168
|
+
/** Global app settings (mutable ref — mutated by settings admin route). */
|
|
169
|
+
app_settings: AppSettings;
|
|
170
|
+
/** Factory-managed audit log SSE. `null` when `audit_log_sse` option is not set. */
|
|
171
|
+
audit_sse: AuditLogSse | null;
|
|
172
|
+
}
|
|
173
|
+
/** Result of `create_app_server()`. */
|
|
174
|
+
export interface AppServer {
|
|
175
|
+
app: Hono;
|
|
176
|
+
/** Surface spec — serializable surface + raw specs that produced it. */
|
|
177
|
+
surface_spec: AppSurfaceSpec;
|
|
178
|
+
bootstrap_status: BootstrapStatus;
|
|
179
|
+
/** Global app settings (mutable ref — mutated by settings admin route). */
|
|
180
|
+
app_settings: AppSettings;
|
|
181
|
+
/** Combined migration results — auth migrations from `create_app_backend` plus consumer migrations. */
|
|
182
|
+
migration_results: ReadonlyArray<MigrationResult>;
|
|
183
|
+
/** Factory-managed audit log SSE. `null` when `audit_log_sse` option is not set. */
|
|
184
|
+
audit_sse: AuditLogSse | null;
|
|
185
|
+
/** Close the database connection. Propagated from `AppBackend`. */
|
|
186
|
+
close: () => Promise<void>;
|
|
187
|
+
}
|
|
188
|
+
/** Default maximum request body size: 1 MiB. */
|
|
189
|
+
export declare const DEFAULT_MAX_BODY_SIZE: number;
|
|
190
|
+
/**
|
|
191
|
+
* Create a fully assembled Hono app with auth, middleware, and routes.
|
|
192
|
+
*
|
|
193
|
+
* Handles the full lifecycle: consumer migrations → proxy middleware →
|
|
194
|
+
* auth middleware → bootstrap status → route specs → surface generation →
|
|
195
|
+
* Hono app assembly → static serving.
|
|
196
|
+
*
|
|
197
|
+
* @param options - server configuration
|
|
198
|
+
* @returns assembled Hono app, backend, surface build, and bootstrap status
|
|
199
|
+
*/
|
|
200
|
+
export declare const create_app_server: (options: AppServerOptions) => Promise<AppServer>;
|
|
201
|
+
//# sourceMappingURL=app_server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app_server.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/server/app_server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAC,IAAI,EAAE,KAAK,OAAO,EAAC,MAAM,MAAM,CAAC;AAGxC,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,OAAO,EAEN,KAAK,cAAc,EAEnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAC;AAC1E,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAGN,KAAK,WAAW,EAChB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAC,WAAW,EAAC,MAA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gDAAgD;AAChD,eAAO,MAAM,qBAAqB,QAAc,CAAC;AAEjD;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAU,SAAS,gBAAgB,KAAG,OAAO,CAAC,SAAS,CA4PpF,CAAC"}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server assembly factory.
|
|
3
|
+
*
|
|
4
|
+
* `create_app_server()` eliminates the ~100 lines of duplicated server assembly
|
|
5
|
+
* shared by tx, visiones, and mageguild. Consumers provide a pre-initialized
|
|
6
|
+
* `AppBackend` and options (session, origins, routes); the factory handles
|
|
7
|
+
* middleware, bootstrap status, surface generation, and Hono app assembly.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { Hono } from 'hono';
|
|
12
|
+
import { logger } from 'hono/logger';
|
|
13
|
+
import { bodyLimit } from 'hono/body-limit';
|
|
14
|
+
import { z } from 'zod';
|
|
15
|
+
import { SESSION_COOKIE_OPTIONS, } from '../auth/session_cookie.js';
|
|
16
|
+
import { create_audit_log_sse, AUDIT_LOG_EVENT_SPECS, } from '../realtime/sse_auth_guard.js';
|
|
17
|
+
import { query_app_settings_load } from '../auth/app_settings_queries.js';
|
|
18
|
+
import { create_rate_limiter, DEFAULT_LOGIN_ACCOUNT_RATE_LIMIT, } from '../rate_limiter.js';
|
|
19
|
+
import { run_migrations } from '../db/migrate.js';
|
|
20
|
+
import { AUTH_MIGRATION_NAMESPACE } from '../auth/migrations.js';
|
|
21
|
+
// Side-effect import: augments Hono's ContextVariableMap so consumers
|
|
22
|
+
// that import app_server get type-safe c.get('auth_session_id') etc.
|
|
23
|
+
import '../hono_context.js';
|
|
24
|
+
import { create_proxy_middleware_spec } from '../http/proxy.js';
|
|
25
|
+
import { create_static_middleware } from './static.js';
|
|
26
|
+
import { log_startup_summary } from './startup.js';
|
|
27
|
+
import { create_app_surface_spec, } from '../http/surface.js';
|
|
28
|
+
import { apply_middleware_specs, apply_route_specs, prefix_route_specs, } from '../http/route_spec.js';
|
|
29
|
+
import { check_bootstrap_status, create_bootstrap_route_specs, } from '../auth/bootstrap_routes.js';
|
|
30
|
+
import { create_surface_route_spec } from '../http/common_routes.js';
|
|
31
|
+
import { create_auth_middleware_specs } from '../auth/middleware.js';
|
|
32
|
+
import { fuz_auth_guard_resolver } from '../auth/route_guards.js';
|
|
33
|
+
import { ERROR_PAYLOAD_TOO_LARGE } from '../http/error_schemas.js';
|
|
34
|
+
/** Default maximum request body size: 1 MiB. */
|
|
35
|
+
export const DEFAULT_MAX_BODY_SIZE = 1024 * 1024;
|
|
36
|
+
/**
|
|
37
|
+
* Create a fully assembled Hono app with auth, middleware, and routes.
|
|
38
|
+
*
|
|
39
|
+
* Handles the full lifecycle: consumer migrations → proxy middleware →
|
|
40
|
+
* auth middleware → bootstrap status → route specs → surface generation →
|
|
41
|
+
* Hono app assembly → static serving.
|
|
42
|
+
*
|
|
43
|
+
* @param options - server configuration
|
|
44
|
+
* @returns assembled Hono app, backend, surface build, and bootstrap status
|
|
45
|
+
*/
|
|
46
|
+
export const create_app_server = async (options) => {
|
|
47
|
+
const { backend } = options;
|
|
48
|
+
const { log } = backend.deps;
|
|
49
|
+
// 1. Consumer migrations
|
|
50
|
+
let all_migration_results = backend.migration_results;
|
|
51
|
+
if (options.migration_namespaces?.length) {
|
|
52
|
+
// guard against namespace collision with fuz_app's internal migrations
|
|
53
|
+
for (const ns of options.migration_namespaces) {
|
|
54
|
+
if (ns.namespace === AUTH_MIGRATION_NAMESPACE) {
|
|
55
|
+
throw new Error(`Migration namespace "${AUTH_MIGRATION_NAMESPACE}" is reserved by fuz_app — choose a different namespace`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const consumer_results = await run_migrations(backend.deps.db, options.migration_namespaces);
|
|
59
|
+
all_migration_results = [...backend.migration_results, ...consumer_results];
|
|
60
|
+
}
|
|
61
|
+
// 2. Rate limiter defaults (undefined = default, null = disable)
|
|
62
|
+
const ip_rate_limiter = options.ip_rate_limiter === undefined ? create_rate_limiter() : options.ip_rate_limiter;
|
|
63
|
+
const login_account_rate_limiter = options.login_account_rate_limiter === undefined
|
|
64
|
+
? create_rate_limiter(DEFAULT_LOGIN_ACCOUNT_RATE_LIMIT)
|
|
65
|
+
: options.login_account_rate_limiter;
|
|
66
|
+
const signup_account_rate_limiter = options.signup_account_rate_limiter === undefined
|
|
67
|
+
? create_rate_limiter(DEFAULT_LOGIN_ACCOUNT_RATE_LIMIT)
|
|
68
|
+
: options.signup_account_rate_limiter;
|
|
69
|
+
const bearer_ip_rate_limiter = options.bearer_ip_rate_limiter === undefined
|
|
70
|
+
? create_rate_limiter()
|
|
71
|
+
: options.bearer_ip_rate_limiter;
|
|
72
|
+
// 3. Factory-managed audit SSE (shallow copy deps, no mutation of backend.deps)
|
|
73
|
+
const audit_sse = options.audit_log_sse
|
|
74
|
+
? create_audit_log_sse({
|
|
75
|
+
log,
|
|
76
|
+
role: typeof options.audit_log_sse === 'object' ? options.audit_log_sse.role : undefined,
|
|
77
|
+
})
|
|
78
|
+
: null;
|
|
79
|
+
const deps = audit_sse
|
|
80
|
+
? {
|
|
81
|
+
...backend.deps,
|
|
82
|
+
on_audit_event: (event) => {
|
|
83
|
+
audit_sse.on_audit_event(event);
|
|
84
|
+
backend.deps.on_audit_event(event);
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
: backend.deps;
|
|
88
|
+
// 4. Proxy middleware
|
|
89
|
+
const proxy_spec = create_proxy_middleware_spec({ ...options.proxy, log });
|
|
90
|
+
// 5. Auth middleware
|
|
91
|
+
const auth_middleware = await create_auth_middleware_specs(deps, {
|
|
92
|
+
allowed_origins: options.allowed_origins,
|
|
93
|
+
session_options: options.session_options,
|
|
94
|
+
bearer_ip_rate_limiter,
|
|
95
|
+
daemon_token_state: options.daemon_token_state,
|
|
96
|
+
});
|
|
97
|
+
let middleware_specs = [proxy_spec, ...auth_middleware];
|
|
98
|
+
if (options.transform_middleware) {
|
|
99
|
+
middleware_specs = options.transform_middleware(middleware_specs);
|
|
100
|
+
}
|
|
101
|
+
// 6. Bootstrap status + app settings
|
|
102
|
+
const bootstrap_status = options.bootstrap
|
|
103
|
+
? await check_bootstrap_status(deps, { token_path: options.bootstrap.token_path })
|
|
104
|
+
: { available: false, token_path: null };
|
|
105
|
+
const app_settings = await query_app_settings_load({ db: deps.db });
|
|
106
|
+
// 7. Surface route ref — factory manages the circular ref
|
|
107
|
+
const surface_ref = {
|
|
108
|
+
surface: { middleware: [], routes: [], env: [], events: [], diagnostics: [] },
|
|
109
|
+
};
|
|
110
|
+
// 8. Route specs (consumer routes + factory-managed routes)
|
|
111
|
+
const context = {
|
|
112
|
+
deps,
|
|
113
|
+
backend,
|
|
114
|
+
bootstrap_status,
|
|
115
|
+
session_options: options.session_options,
|
|
116
|
+
ip_rate_limiter,
|
|
117
|
+
login_account_rate_limiter,
|
|
118
|
+
signup_account_rate_limiter,
|
|
119
|
+
app_settings,
|
|
120
|
+
audit_sse,
|
|
121
|
+
};
|
|
122
|
+
const consumer_routes = options.create_route_specs(context);
|
|
123
|
+
// Factory-managed routes appended after consumer routes
|
|
124
|
+
const factory_routes = [];
|
|
125
|
+
// Bootstrap routes
|
|
126
|
+
if (options.bootstrap) {
|
|
127
|
+
const bootstrap_routes = create_bootstrap_route_specs(deps, {
|
|
128
|
+
session_options: options.session_options,
|
|
129
|
+
bootstrap_status,
|
|
130
|
+
on_bootstrap: options.bootstrap.on_bootstrap,
|
|
131
|
+
ip_rate_limiter,
|
|
132
|
+
});
|
|
133
|
+
const prefix = options.bootstrap.route_prefix ?? '/api/account';
|
|
134
|
+
factory_routes.push(...prefix_route_specs(prefix, bootstrap_routes));
|
|
135
|
+
}
|
|
136
|
+
// Surface route (default: enabled)
|
|
137
|
+
if (options.surface_route !== false) {
|
|
138
|
+
factory_routes.push(create_surface_route_spec(surface_ref));
|
|
139
|
+
}
|
|
140
|
+
const route_specs = [...consumer_routes, ...factory_routes];
|
|
141
|
+
// 9. Surface + logging
|
|
142
|
+
const surface_middleware = options.post_route_middleware
|
|
143
|
+
? [...middleware_specs, ...options.post_route_middleware]
|
|
144
|
+
: middleware_specs;
|
|
145
|
+
const all_event_specs = [
|
|
146
|
+
...(options.event_specs ?? []),
|
|
147
|
+
...(audit_sse ? AUDIT_LOG_EVENT_SPECS : []),
|
|
148
|
+
];
|
|
149
|
+
const surface_spec = create_app_surface_spec({
|
|
150
|
+
middleware_specs: surface_middleware,
|
|
151
|
+
route_specs,
|
|
152
|
+
env_schema: options.env_schema,
|
|
153
|
+
event_specs: all_event_specs,
|
|
154
|
+
});
|
|
155
|
+
// Config-level diagnostics (concatenated after spec-level from generate_app_surface)
|
|
156
|
+
const config_diagnostics = [];
|
|
157
|
+
const cookie_opts = options.session_options.cookie_options;
|
|
158
|
+
if (cookie_opts) {
|
|
159
|
+
if (cookie_opts.secure === false) {
|
|
160
|
+
config_diagnostics.push({
|
|
161
|
+
level: 'warning',
|
|
162
|
+
category: 'security',
|
|
163
|
+
message: 'Session cookie secure=false — cookies sent over HTTP',
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
if (cookie_opts.sameSite && cookie_opts.sameSite !== SESSION_COOKIE_OPTIONS.sameSite) {
|
|
167
|
+
config_diagnostics.push({
|
|
168
|
+
level: 'warning',
|
|
169
|
+
category: 'security',
|
|
170
|
+
message: `Session cookie sameSite='${cookie_opts.sameSite}' — weakened from default '${SESSION_COOKIE_OPTIONS.sameSite}'`,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
if (cookie_opts.httpOnly === false) {
|
|
174
|
+
config_diagnostics.push({
|
|
175
|
+
level: 'warning',
|
|
176
|
+
category: 'security',
|
|
177
|
+
message: 'Session cookie httpOnly=false — cookie accessible to JavaScript',
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (ip_rate_limiter === null) {
|
|
182
|
+
config_diagnostics.push({
|
|
183
|
+
level: 'warning',
|
|
184
|
+
category: 'config',
|
|
185
|
+
message: 'IP rate limiter explicitly disabled (null)',
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
if (bearer_ip_rate_limiter === null) {
|
|
189
|
+
config_diagnostics.push({
|
|
190
|
+
level: 'warning',
|
|
191
|
+
category: 'config',
|
|
192
|
+
message: 'Bearer IP rate limiter explicitly disabled (null)',
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
if (config_diagnostics.length) {
|
|
196
|
+
surface_spec.surface.diagnostics = [...surface_spec.surface.diagnostics, ...config_diagnostics];
|
|
197
|
+
}
|
|
198
|
+
// Backfill the surface ref — factory owns this lifecycle
|
|
199
|
+
surface_ref.surface = surface_spec.surface;
|
|
200
|
+
log_startup_summary(surface_spec.surface, log, options.env_values);
|
|
201
|
+
// 10. Hono app assembly
|
|
202
|
+
const app = new Hono();
|
|
203
|
+
// Pending effects — collects fire-and-forget promises (audit logs, usage tracking).
|
|
204
|
+
// In test mode, effects are awaited before the response returns.
|
|
205
|
+
// In production, rejected effects are reported via on_effect_error.
|
|
206
|
+
app.use('*', async (c, next) => {
|
|
207
|
+
c.set('pending_effects', []);
|
|
208
|
+
try {
|
|
209
|
+
await next();
|
|
210
|
+
}
|
|
211
|
+
finally {
|
|
212
|
+
const effects = c.var.pending_effects;
|
|
213
|
+
if (effects.length) {
|
|
214
|
+
if (options.await_pending_effects) {
|
|
215
|
+
await Promise.allSettled(effects);
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
const ctx = { method: c.req.method, path: c.req.path };
|
|
219
|
+
const callback = options.on_effect_error;
|
|
220
|
+
void Promise.allSettled(effects).then((results) => {
|
|
221
|
+
for (const result of results) {
|
|
222
|
+
if (result.status === 'rejected') {
|
|
223
|
+
log.error('Pending effect rejected:', result.reason, ctx);
|
|
224
|
+
callback?.(result.reason, ctx);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
if (log.level !== 'off') {
|
|
233
|
+
app.use(logger((msg) => log.info(msg)));
|
|
234
|
+
}
|
|
235
|
+
// Body size limit — rejects oversized payloads before auth/validation.
|
|
236
|
+
// Default 1 MiB; pass null to disable.
|
|
237
|
+
if (options.max_body_size !== null) {
|
|
238
|
+
const max_size = options.max_body_size ?? DEFAULT_MAX_BODY_SIZE;
|
|
239
|
+
app.use(bodyLimit({
|
|
240
|
+
maxSize: max_size,
|
|
241
|
+
onError: (c) => c.json({ error: ERROR_PAYLOAD_TOO_LARGE }, 413),
|
|
242
|
+
}));
|
|
243
|
+
}
|
|
244
|
+
apply_middleware_specs(app, middleware_specs);
|
|
245
|
+
apply_route_specs(app, route_specs, fuz_auth_guard_resolver, log, deps.db);
|
|
246
|
+
// 11. Post-route middleware (before static serving)
|
|
247
|
+
if (options.post_route_middleware) {
|
|
248
|
+
apply_middleware_specs(app, options.post_route_middleware);
|
|
249
|
+
}
|
|
250
|
+
// 12. Static file serving
|
|
251
|
+
if (options.static_serving) {
|
|
252
|
+
const { serve_static, spa_fallback } = options.static_serving;
|
|
253
|
+
for (const mw of create_static_middleware(serve_static, { spa_fallback })) {
|
|
254
|
+
app.use('/*', mw);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
app,
|
|
259
|
+
surface_spec,
|
|
260
|
+
bootstrap_status,
|
|
261
|
+
app_settings,
|
|
262
|
+
migration_results: all_migration_results,
|
|
263
|
+
audit_sse,
|
|
264
|
+
close: backend.close,
|
|
265
|
+
};
|
|
266
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base server environment schema and validation.
|
|
3
|
+
*
|
|
4
|
+
* Provides `BaseServerEnv` — a shared Zod schema for common server env vars
|
|
5
|
+
* that apps can use directly or extend with app-specific fields.
|
|
6
|
+
*
|
|
7
|
+
* Generic env loading lives in `env/load.ts`.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import { type Keyring } from '../auth/keyring.js';
|
|
13
|
+
/**
|
|
14
|
+
* Base Zod schema for server environment variables.
|
|
15
|
+
*
|
|
16
|
+
* Provides the common fields used by fuz apps:
|
|
17
|
+
* server config, database, auth, security, public URLs, and SMTP.
|
|
18
|
+
*
|
|
19
|
+
* Apps can use directly or extend with app-specific fields via `.extend()`.
|
|
20
|
+
*/
|
|
21
|
+
export declare const BaseServerEnv: z.ZodObject<{
|
|
22
|
+
NODE_ENV: z.ZodEnum<{
|
|
23
|
+
development: "development";
|
|
24
|
+
production: "production";
|
|
25
|
+
}>;
|
|
26
|
+
PORT: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
27
|
+
HOST: z.ZodDefault<z.ZodString>;
|
|
28
|
+
DATABASE_URL: z.ZodString;
|
|
29
|
+
SECRET_COOKIE_KEYS: z.ZodString;
|
|
30
|
+
ALLOWED_ORIGINS: z.ZodString;
|
|
31
|
+
PUBLIC_API_URL: z.ZodDefault<z.ZodString>;
|
|
32
|
+
PUBLIC_WEBSOCKET_URL: z.ZodOptional<z.ZodString>;
|
|
33
|
+
PUBLIC_CONTACT_EMAIL: z.ZodOptional<z.ZodUnion<readonly [z.ZodEmail, z.ZodLiteral<"">]>>;
|
|
34
|
+
BOOTSTRAP_TOKEN_PATH: z.ZodOptional<z.ZodString>;
|
|
35
|
+
SMTP_HOST: z.ZodOptional<z.ZodString>;
|
|
36
|
+
SMTP_USER: z.ZodOptional<z.ZodUnion<readonly [z.ZodEmail, z.ZodLiteral<"">]>>;
|
|
37
|
+
SMTP_PASSWORD: z.ZodOptional<z.ZodString>;
|
|
38
|
+
}, z.core.$strict>;
|
|
39
|
+
export type BaseServerEnv = z.infer<typeof BaseServerEnv>;
|
|
40
|
+
/**
|
|
41
|
+
* Validated server env config — the artifacts `create_app_server()` needs.
|
|
42
|
+
*/
|
|
43
|
+
export interface ServerEnvOptions {
|
|
44
|
+
ok: true;
|
|
45
|
+
keyring: Keyring;
|
|
46
|
+
allowed_origins: Array<RegExp>;
|
|
47
|
+
bootstrap_token_path: string | null;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Error from `validate_server_env` — keyring or origin validation failed.
|
|
51
|
+
*/
|
|
52
|
+
export interface ServerEnvOptionsError {
|
|
53
|
+
ok: false;
|
|
54
|
+
field: 'SECRET_COOKIE_KEYS' | 'ALLOWED_ORIGINS';
|
|
55
|
+
errors: Array<string>;
|
|
56
|
+
}
|
|
57
|
+
export type ServerEnvOptionsResult = ServerEnvOptions | ServerEnvOptionsError;
|
|
58
|
+
/**
|
|
59
|
+
* Validate a loaded `BaseServerEnv` and produce the artifacts needed for server init.
|
|
60
|
+
*
|
|
61
|
+
* Handles keyring validation, origin parsing, and bootstrap token path extraction.
|
|
62
|
+
* Returns a Result so callers handle errors their own way (exit, logging, etc).
|
|
63
|
+
*
|
|
64
|
+
* @param env - a loaded and Zod-validated `BaseServerEnv`
|
|
65
|
+
* @returns `{ok: true, keyring, allowed_origins, bootstrap_token_path}` or `{ok: false, field, errors}`
|
|
66
|
+
*/
|
|
67
|
+
export declare const validate_server_env: (env: BaseServerEnv) => ServerEnvOptionsResult;
|
|
68
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/server/env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,OAAO,EAA2B,KAAK,OAAO,EAAC,MAAM,oBAAoB,CAAC;AAG1E;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;kBAkCxB,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,EAAE,EAAE,IAAI,CAAC;IACT,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC/B,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACrC,EAAE,EAAE,KAAK,CAAC;IACV,KAAK,EAAE,oBAAoB,GAAG,iBAAiB,CAAC;IAChD,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACtB;AAED,MAAM,MAAM,sBAAsB,GAAG,gBAAgB,GAAG,qBAAqB,CAAC;AAE9E;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,GAAI,KAAK,aAAa,KAAG,sBA4BxD,CAAC"}
|