zitejs 0.9.152 → 0.9.154
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/dist/cjs/auth/actions.d.ts +28 -0
- package/dist/cjs/auth/actions.js +93 -0
- package/dist/cjs/auth/client.d.ts +357 -0
- package/dist/cjs/auth/client.js +66 -0
- package/dist/cjs/auth/config.js +9 -3
- package/dist/cjs/auth/index.d.ts +2 -249
- package/dist/cjs/auth/index.js +11 -108
- package/dist/cjs/auth/index.test.js +60 -0
- package/dist/cjs/auth/previewClaim.d.ts +7 -0
- package/dist/cjs/auth/previewClaim.js +16 -0
- package/dist/cjs/auth/profileUpdates.d.ts +9 -0
- package/dist/cjs/auth/profileUpdates.js +11 -0
- package/dist/cjs/backend/index.d.ts +6 -6
- package/dist/cjs/backend/index.js +13 -13
- package/dist/cjs/backend/index.test.js +102 -102
- package/dist/cjs/bundle/index.js +29 -16
- package/dist/cjs/caller/index.js +43 -43
- package/dist/cjs/check/index.d.ts +44 -1
- package/dist/cjs/check/index.js +198 -61
- package/dist/cjs/check/start/routeTree.d.ts +8 -0
- package/dist/cjs/check/start/routeTree.js +118 -0
- package/dist/cjs/check/start/tsgo.d.ts +2 -0
- package/dist/cjs/check/start/tsgo.js +35 -0
- package/dist/cjs/cli.js +19 -6
- package/dist/cjs/client/index.d.ts +2 -2
- package/dist/cjs/client/index.js +25 -25
- package/dist/cjs/dev/index.js +81 -53
- package/dist/cjs/dev/signin.d.ts +16 -0
- package/dist/cjs/dev/signin.js +84 -0
- package/dist/cjs/index.d.ts +5 -5
- package/dist/cjs/integrations/client.d.ts +3 -3
- package/dist/cjs/integrations/client.js +5 -4
- package/dist/cjs/integrations/client.test-d.js +15 -15
- package/dist/cjs/integrations/index.d.ts +2 -2
- package/dist/cjs/integrations/rules.d.ts +1 -0
- package/dist/cjs/integrations/rules.js +44 -41
- package/dist/cjs/integrations/rules.test.js +60 -54
- package/dist/cjs/internal/appMode.d.ts +14 -0
- package/dist/cjs/internal/appMode.js +19 -0
- package/dist/cjs/internal/env.js +3 -2
- package/dist/cjs/internal/platformFetch.d.ts +2 -0
- package/dist/cjs/internal/platformFetch.js +14 -0
- package/dist/cjs/internal/reservedIds.d.ts +8 -0
- package/dist/cjs/internal/reservedIds.js +14 -0
- package/dist/cjs/internal/serviceUrls.d.ts +5 -0
- package/dist/cjs/internal/serviceUrls.js +14 -0
- package/dist/cjs/pdf/index.js +2 -1
- package/dist/cjs/runtime/filterConditionTypes.test-d.js +11 -11
- package/dist/cjs/runtime/index.d.ts +69 -21
- package/dist/cjs/runtime/index.js +32 -26
- package/dist/cjs/runtime/index.test.js +34 -34
- package/dist/cjs/runtime/sendEmailParamsTypes.test-d.js +35 -18
- package/dist/cjs/runtime/writeResultTypes.test-d.js +8 -8
- package/dist/cjs/sourceRoots.js +15 -15
- package/dist/cjs/sourceRoots.test.js +29 -27
- package/dist/cjs/start/build/entries.d.ts +25 -0
- package/dist/cjs/start/build/entries.js +121 -0
- package/dist/cjs/start/build/placeholders/devApp.d.ts +1 -0
- package/dist/cjs/start/build/placeholders/devApp.js +6 -0
- package/dist/cjs/start/describe/describeBuilt.d.ts +5 -0
- package/dist/cjs/start/describe/describeBuilt.js +144 -0
- package/dist/cjs/start/platform/aiUsage.d.ts +29 -0
- package/dist/cjs/start/platform/aiUsage.js +215 -0
- package/dist/cjs/start/platform/airtable/cache.d.ts +17 -0
- package/dist/cjs/start/platform/airtable/cache.js +93 -0
- package/dist/cjs/start/protocol.d.ts +19 -0
- package/dist/cjs/start/protocol.js +33 -0
- package/dist/cjs/start/serve/local/provider.d.ts +25 -0
- package/dist/cjs/start/serve/local/provider.js +196 -0
- package/dist/cjs/start/serve/provider.d.ts +19 -0
- package/dist/cjs/start/serve/provider.js +86 -0
- package/dist/cjs/start/types.d.ts +373 -0
- package/dist/cjs/start/types.js +2 -0
- package/dist/cjs/steps/index.d.ts +8 -8
- package/dist/cjs/steps/index.js +53 -53
- package/dist/cjs/steps/index.test.js +218 -218
- package/dist/cjs/sync/index.d.ts +1 -1
- package/dist/cjs/sync/index.js +28 -27
- package/dist/cjs/sync/lib.d.ts +15 -8
- package/dist/cjs/sync/lib.js +652 -661
- package/dist/cjs/sync/lib.test.js +81 -14
- package/dist/cjs/sync/sdkNames.d.ts +67 -9
- package/dist/cjs/sync/sdkNames.js +97 -31
- package/dist/cjs/sync/sdkNames.test.js +189 -113
- package/dist/cjs/types/fields.d.ts +1 -1
- package/dist/cjs/types/fields.js +105 -97
- package/dist/cjs/types/index.d.ts +2 -2
- package/dist/cjs/types/tables.d.ts +1 -1
- package/dist/cjs/upload/index.js +89 -24
- package/dist/cjs/upload/index.test.js +104 -1
- package/dist/cjs/vite/domTagNames.js +252 -252
- package/dist/cjs/vite/index.d.ts +1 -1
- package/dist/cjs/vite/index.js +51 -42
- package/dist/cjs/vite/index.test.js +10 -2
- package/dist/esm/auth/actions.d.ts +28 -0
- package/dist/esm/auth/actions.js +55 -0
- package/dist/esm/auth/client.d.ts +357 -0
- package/dist/esm/auth/client.js +62 -0
- package/dist/esm/auth/config.js +9 -3
- package/dist/esm/auth/index.d.ts +2 -249
- package/dist/esm/auth/index.js +2 -103
- package/dist/esm/auth/index.test.js +60 -0
- package/dist/esm/auth/previewClaim.d.ts +7 -0
- package/dist/esm/auth/previewClaim.js +12 -0
- package/dist/esm/auth/profileUpdates.d.ts +9 -0
- package/dist/esm/auth/profileUpdates.js +6 -0
- package/dist/esm/backend/index.d.ts +6 -6
- package/dist/esm/backend/index.js +13 -13
- package/dist/esm/backend/index.test.js +106 -106
- package/dist/esm/bundle/index.js +29 -16
- package/dist/esm/caller/index.js +44 -44
- package/dist/esm/check/index.d.ts +44 -1
- package/dist/esm/check/index.js +194 -61
- package/dist/esm/check/start/routeTree.d.ts +8 -0
- package/dist/esm/check/start/routeTree.js +77 -0
- package/dist/esm/check/start/tsgo.d.ts +2 -0
- package/dist/esm/check/start/tsgo.js +29 -0
- package/dist/esm/cli.js +19 -6
- package/dist/esm/client/index.d.ts +2 -2
- package/dist/esm/client/index.js +25 -25
- package/dist/esm/dev/index.js +88 -60
- package/dist/esm/dev/signin.d.ts +16 -0
- package/dist/esm/dev/signin.js +80 -0
- package/dist/esm/index.d.ts +5 -5
- package/dist/esm/index.js +3 -3
- package/dist/esm/integrations/client.d.ts +3 -3
- package/dist/esm/integrations/client.js +6 -5
- package/dist/esm/integrations/client.test-d.js +19 -19
- package/dist/esm/integrations/index.d.ts +2 -2
- package/dist/esm/integrations/index.js +1 -1
- package/dist/esm/integrations/rules.d.ts +1 -0
- package/dist/esm/integrations/rules.js +44 -41
- package/dist/esm/integrations/rules.test.js +62 -56
- package/dist/esm/internal/appMode.d.ts +14 -0
- package/dist/esm/internal/appMode.js +13 -0
- package/dist/esm/internal/env.js +3 -2
- package/dist/esm/internal/platformFetch.d.ts +2 -0
- package/dist/esm/internal/platformFetch.js +9 -0
- package/dist/esm/internal/reservedIds.d.ts +8 -0
- package/dist/esm/internal/reservedIds.js +10 -0
- package/dist/esm/internal/serviceUrls.d.ts +5 -0
- package/dist/esm/internal/serviceUrls.js +10 -0
- package/dist/esm/pdf/index.js +2 -1
- package/dist/esm/runtime/filterConditionTypes.test-d.js +12 -12
- package/dist/esm/runtime/index.d.ts +69 -21
- package/dist/esm/runtime/index.js +35 -29
- package/dist/esm/runtime/index.test.js +36 -36
- package/dist/esm/runtime/sendEmailParamsTypes.test-d.js +36 -19
- package/dist/esm/runtime/writeResultTypes.test-d.js +9 -9
- package/dist/esm/signin/conformance.d.ts +100 -0
- package/dist/esm/signin/conformance.js +616 -0
- package/dist/esm/signin/cookies.d.ts +28 -0
- package/dist/esm/signin/cookies.js +67 -0
- package/dist/esm/signin/encoding.d.ts +1 -0
- package/dist/esm/signin/encoding.js +12 -0
- package/dist/esm/signin/endpoints.d.ts +12 -0
- package/dist/esm/signin/endpoints.js +32 -0
- package/dist/esm/signin/http.d.ts +25 -0
- package/dist/esm/signin/http.js +106 -0
- package/dist/esm/signin/index.d.ts +8 -0
- package/dist/esm/signin/index.js +9 -0
- package/dist/esm/signin/keys.d.ts +35 -0
- package/dist/esm/signin/keys.js +230 -0
- package/dist/esm/signin/paths.d.ts +2 -0
- package/dist/esm/signin/paths.js +5 -0
- package/dist/esm/signin/seal.d.ts +19 -0
- package/dist/esm/signin/seal.js +47 -0
- package/dist/esm/signin/signin.d.ts +60 -0
- package/dist/esm/signin/signin.js +447 -0
- package/dist/esm/signin/transport.d.ts +112 -0
- package/dist/esm/signin/transport.js +1 -0
- package/dist/esm/signin/verifier.d.ts +2 -0
- package/dist/esm/signin/verifier.js +4 -0
- package/dist/esm/signin/verify.d.ts +83 -0
- package/dist/esm/signin/verify.js +142 -0
- package/dist/esm/sourceRoots.js +17 -17
- package/dist/esm/sourceRoots.test.js +34 -32
- package/dist/esm/start/access.d.ts +19 -0
- package/dist/esm/start/access.js +43 -0
- package/dist/esm/start/auth.d.ts +28 -0
- package/dist/esm/start/auth.js +33 -0
- package/dist/esm/start/automations/quiet.d.ts +2 -0
- package/dist/esm/start/automations/quiet.js +36 -0
- package/dist/esm/start/automations/registration.d.ts +13 -0
- package/dist/esm/start/automations/registration.js +25 -0
- package/dist/esm/start/automations/steps.d.ts +29 -0
- package/dist/esm/start/automations/steps.js +95 -0
- package/dist/esm/start/automations/workflow.d.ts +83 -0
- package/dist/esm/start/automations/workflow.js +36 -0
- package/dist/esm/start/automations/workflow.test-d.d.ts +1 -0
- package/dist/esm/start/automations/workflow.test-d.js +130 -0
- package/dist/esm/start/automations/workflowRun.d.ts +130 -0
- package/dist/esm/start/automations/workflowRun.js +185 -0
- package/dist/esm/start/barrel.test-d.d.ts +10 -0
- package/dist/esm/start/barrel.test-d.js +6 -0
- package/dist/esm/start/build/entries.d.ts +25 -0
- package/dist/esm/start/build/entries.js +109 -0
- package/dist/esm/start/build/placeholders/authHooksModule.d.ts +1 -0
- package/dist/esm/start/build/placeholders/authHooksModule.js +3 -0
- package/dist/esm/start/build/placeholders/devApp.d.ts +1 -0
- package/dist/esm/start/build/placeholders/devApp.js +3 -0
- package/dist/esm/start/build/placeholders/devSignIn.d.ts +1 -0
- package/dist/esm/start/build/placeholders/devSignIn.js +3 -0
- package/dist/esm/start/build/placeholders/siteHead.d.ts +2 -0
- package/dist/esm/start/build/placeholders/siteHead.js +3 -0
- package/dist/esm/start/build/placeholders/workflowModules.d.ts +1 -0
- package/dist/esm/start/build/placeholders/workflowModules.js +3 -0
- package/dist/esm/start/build/placeholders/workspaceSchema.d.ts +2 -0
- package/dist/esm/start/build/placeholders/workspaceSchema.js +3 -0
- package/dist/esm/start/build/registrationHash.d.ts +11 -0
- package/dist/esm/start/build/registrationHash.js +88 -0
- package/dist/esm/start/build/sdk/axios.d.ts +76 -0
- package/dist/esm/start/build/sdk/axios.js +253 -0
- package/dist/esm/start/build/sdk/nodeFetch.d.ts +41 -0
- package/dist/esm/start/build/sdk/nodeFetch.js +35 -0
- package/dist/esm/start/build/sdk/undici.d.ts +34 -0
- package/dist/esm/start/build/sdk/undici.js +18 -0
- package/dist/esm/start/build/sdkPatches.d.ts +22 -0
- package/dist/esm/start/build/sdkPatches.js +430 -0
- package/dist/esm/start/build/siteHead.d.ts +26 -0
- package/dist/esm/start/build/siteHead.js +88 -0
- package/dist/esm/start/build/vite.d.ts +50 -0
- package/dist/esm/start/build/vite.js +487 -0
- package/dist/esm/start/classicOnly.d.ts +1 -0
- package/dist/esm/start/classicOnly.js +4 -0
- package/dist/esm/start/clientErrorMessage.test.d.ts +1 -0
- package/dist/esm/start/clientErrorMessage.test.js +105 -0
- package/dist/esm/start/describe/describe.d.ts +120 -0
- package/dist/esm/start/describe/describe.js +372 -0
- package/dist/esm/start/describe/describeBuilt.d.ts +5 -0
- package/dist/esm/start/describe/describeBuilt.js +102 -0
- package/dist/esm/start/describe/descriptions.d.ts +4 -0
- package/dist/esm/start/describe/descriptions.js +54 -0
- package/dist/esm/start/errors.d.ts +62 -0
- package/dist/esm/start/errors.js +163 -0
- package/dist/esm/start/errors.test.d.ts +1 -0
- package/dist/esm/start/errors.test.js +54 -0
- package/dist/esm/start/factories.d.ts +14 -0
- package/dist/esm/start/factories.js +23 -0
- package/dist/esm/start/factories.test-d.d.ts +2 -0
- package/dist/esm/start/factories.test-d.js +60 -0
- package/dist/esm/start/failures.d.ts +7 -0
- package/dist/esm/start/failures.js +62 -0
- package/dist/esm/start/fnFactory.d.ts +16 -0
- package/dist/esm/start/fnFactory.js +1 -0
- package/dist/esm/start/host.d.ts +3 -0
- package/dist/esm/start/host.js +4 -0
- package/dist/esm/start/index.d.ts +10 -0
- package/dist/esm/start/index.js +7 -0
- package/dist/esm/start/login.d.ts +5 -0
- package/dist/esm/start/login.js +29 -0
- package/dist/esm/start/middlewareKind.d.ts +13 -0
- package/dist/esm/start/middlewareKind.js +9 -0
- package/dist/esm/start/platform/aiUsage.d.ts +29 -0
- package/dist/esm/start/platform/aiUsage.js +210 -0
- package/dist/esm/start/platform/airtable/arrayFields.d.ts +10 -0
- package/dist/esm/start/platform/airtable/arrayFields.js +30 -0
- package/dist/esm/start/platform/airtable/built.d.ts +2 -0
- package/dist/esm/start/platform/airtable/built.js +3 -0
- package/dist/esm/start/platform/airtable/cache.d.ts +17 -0
- package/dist/esm/start/platform/airtable/cache.js +89 -0
- package/dist/esm/start/platform/airtable/dispatch.d.ts +57 -0
- package/dist/esm/start/platform/airtable/dispatch.js +541 -0
- package/dist/esm/start/platform/airtable/formulas.d.ts +70 -0
- package/dist/esm/start/platform/airtable/formulas.js +261 -0
- package/dist/esm/start/platform/airtable/index.d.ts +6 -0
- package/dist/esm/start/platform/airtable/index.js +51 -0
- package/dist/esm/start/platform/airtable/settings.d.ts +37 -0
- package/dist/esm/start/platform/airtable/settings.js +138 -0
- package/dist/esm/start/platform/analytics.d.ts +3 -0
- package/dist/esm/start/platform/analytics.js +59 -0
- package/dist/esm/start/platform/calls.d.ts +5 -0
- package/dist/esm/start/platform/calls.js +104 -0
- package/dist/esm/start/platform/caps.d.ts +9 -0
- package/dist/esm/start/platform/caps.js +35 -0
- package/dist/esm/start/platform/connections.d.ts +25 -0
- package/dist/esm/start/platform/connections.js +198 -0
- package/dist/esm/start/platform/data/baseRunner.d.ts +97 -0
- package/dist/esm/start/platform/data/baseRunner.js +117 -0
- package/dist/esm/start/platform/data/dispatch.d.ts +17 -0
- package/dist/esm/start/platform/data/dispatch.js +216 -0
- package/dist/esm/start/platform/data/fetch.d.ts +7 -0
- package/dist/esm/start/platform/data/fetch.js +9 -0
- package/dist/esm/start/platform/data/index.d.ts +27 -0
- package/dist/esm/start/platform/data/index.js +75 -0
- package/dist/esm/start/platform/data/names.d.ts +7 -0
- package/dist/esm/start/platform/data/names.js +18 -0
- package/dist/esm/start/platform/data/sqlNameMappings.d.ts +58 -0
- package/dist/esm/start/platform/data/sqlNameMappings.js +92 -0
- package/dist/esm/start/platform/data/transformations.d.ts +97 -0
- package/dist/esm/start/platform/data/transformations.js +262 -0
- package/dist/esm/start/platform/data/types.d.ts +94 -0
- package/dist/esm/start/platform/data/types.js +14 -0
- package/dist/esm/start/platform/local.d.ts +6 -0
- package/dist/esm/start/platform/local.js +18 -0
- package/dist/esm/start/platform/meta.d.ts +3 -0
- package/dist/esm/start/platform/meta.js +33 -0
- package/dist/esm/start/platform/outbound.d.ts +17 -0
- package/dist/esm/start/platform/outbound.js +510 -0
- package/dist/esm/start/platform/redactSecrets.d.ts +13 -0
- package/dist/esm/start/platform/redactSecrets.js +156 -0
- package/dist/esm/start/platform/redactSecrets.test.d.ts +1 -0
- package/dist/esm/start/platform/redactSecrets.test.js +151 -0
- package/dist/esm/start/platform/requestSecrets.d.ts +15 -0
- package/dist/esm/start/platform/requestSecrets.js +41 -0
- package/dist/esm/start/platform/runLog.d.ts +40 -0
- package/dist/esm/start/platform/runLog.js +149 -0
- package/dist/esm/start/platform/services.d.ts +7 -0
- package/dist/esm/start/platform/services.js +46 -0
- package/dist/esm/start/platform/steps.d.ts +9 -0
- package/dist/esm/start/platform/steps.js +60 -0
- package/dist/esm/start/platform/telemetry.d.ts +13 -0
- package/dist/esm/start/platform/telemetry.js +71 -0
- package/dist/esm/start/platform/transport.d.ts +28 -0
- package/dist/esm/start/platform/transport.js +59 -0
- package/dist/esm/start/platformHead.d.ts +23 -0
- package/dist/esm/start/platformHead.js +133 -0
- package/dist/esm/start/previewClaim.d.ts +6 -0
- package/dist/esm/start/previewClaim.js +24 -0
- package/dist/esm/start/protocol.d.ts +19 -0
- package/dist/esm/start/protocol.js +27 -0
- package/dist/esm/start/roles.d.ts +12 -0
- package/dist/esm/start/roles.js +27 -0
- package/dist/esm/start/router.d.ts +44 -0
- package/dist/esm/start/router.js +280 -0
- package/dist/esm/start/serve/authHooks.d.ts +7 -0
- package/dist/esm/start/serve/authHooks.js +18 -0
- package/dist/esm/start/serve/demo.d.ts +9 -0
- package/dist/esm/start/serve/demo.js +24 -0
- package/dist/esm/start/serve/fetch.d.ts +1 -0
- package/dist/esm/start/serve/fetch.js +6 -0
- package/dist/esm/start/serve/instance.d.ts +12 -0
- package/dist/esm/start/serve/instance.js +134 -0
- package/dist/esm/start/serve/invoke.d.ts +13 -0
- package/dist/esm/start/serve/invoke.js +126 -0
- package/dist/esm/start/serve/local/load.d.ts +8 -0
- package/dist/esm/start/serve/local/load.js +44 -0
- package/dist/esm/start/serve/local/provider.d.ts +25 -0
- package/dist/esm/start/serve/local/provider.js +188 -0
- package/dist/esm/start/serve/local/signIn.d.ts +28 -0
- package/dist/esm/start/serve/local/signIn.js +123 -0
- package/dist/esm/start/serve/pageHead.d.ts +20 -0
- package/dist/esm/start/serve/pageHead.js +34 -0
- package/dist/esm/start/serve/provider.d.ts +19 -0
- package/dist/esm/start/serve/provider.js +78 -0
- package/dist/esm/start/serve/requestEnv.d.ts +2 -0
- package/dist/esm/start/serve/requestEnv.js +84 -0
- package/dist/esm/start/serve/scope.d.ts +18 -0
- package/dist/esm/start/serve/scope.js +67 -0
- package/dist/esm/start/serve/server.d.ts +56 -0
- package/dist/esm/start/serve/server.js +297 -0
- package/dist/esm/start/serve/uploads.d.ts +2 -0
- package/dist/esm/start/serve/uploads.js +49 -0
- package/dist/esm/start/serve/worker.d.ts +6 -0
- package/dist/esm/start/serve/worker.js +12 -0
- package/dist/esm/start/types.d.ts +373 -0
- package/dist/esm/start/types.js +1 -0
- package/dist/esm/start/version.d.ts +1 -0
- package/dist/esm/start/version.js +2 -0
- package/dist/esm/steps/index.d.ts +8 -8
- package/dist/esm/steps/index.js +54 -54
- package/dist/esm/steps/index.test.js +220 -220
- package/dist/esm/sync/index.d.ts +1 -1
- package/dist/esm/sync/index.js +32 -31
- package/dist/esm/sync/lib.d.ts +15 -8
- package/dist/esm/sync/lib.js +656 -665
- package/dist/esm/sync/lib.test.js +81 -14
- package/dist/esm/sync/sdkNames.d.ts +67 -9
- package/dist/esm/sync/sdkNames.js +94 -30
- package/dist/esm/sync/sdkNames.test.js +192 -116
- package/dist/esm/types/fields.d.ts +1 -1
- package/dist/esm/types/fields.js +106 -98
- package/dist/esm/types/index.d.ts +2 -2
- package/dist/esm/types/index.js +2 -2
- package/dist/esm/types/tables.d.ts +1 -1
- package/dist/esm/types/tables.js +2 -2
- package/dist/esm/upload/index.js +89 -24
- package/dist/esm/upload/index.test.js +104 -1
- package/dist/esm/vite/domTagNames.js +252 -252
- package/dist/esm/vite/index.d.ts +1 -1
- package/dist/esm/vite/index.js +56 -47
- package/dist/esm/vite/index.test.js +10 -2
- package/package.json +129 -16
- package/dist/cjs/auth-server/index.d.ts +0 -369
- package/dist/cjs/auth-server/index.js +0 -119
- package/dist/cjs/meta/index.d.ts +0 -14
- package/dist/cjs/meta/index.js +0 -12
- package/dist/cjs/notifications/index.d.ts +0 -25
- package/dist/cjs/notifications/index.js +0 -12
- package/dist/esm/auth-server/index.d.ts +0 -369
- package/dist/esm/auth-server/index.js +0 -116
- package/dist/esm/meta/index.d.ts +0 -14
- package/dist/esm/meta/index.js +0 -8
- package/dist/esm/notifications/index.d.ts +0 -25
- package/dist/esm/notifications/index.js +0 -8
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const AUTH_HOOK_NAMES: readonly ["beforeSignUp", "beforeSignIn", "afterSignUp", "afterSignIn", "verifySession"];
|
|
2
|
+
export type AuthHookName = (typeof AUTH_HOOK_NAMES)[number];
|
|
3
|
+
type AuthHook = (input: unknown) => unknown;
|
|
4
|
+
export declare const isAuthHookName: (name: string) => name is AuthHookName;
|
|
5
|
+
/** The hooks the app's `zite.auth.ts` defines, by name. */
|
|
6
|
+
export declare function loadAuthHooks(): Promise<Partial<Record<AuthHookName, AuthHook>>>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { authHooksModule } from '../build/placeholders/authHooksModule.js';
|
|
2
|
+
export const AUTH_HOOK_NAMES = [
|
|
3
|
+
'beforeSignUp',
|
|
4
|
+
'beforeSignIn',
|
|
5
|
+
'afterSignUp',
|
|
6
|
+
'afterSignIn',
|
|
7
|
+
'verifySession',
|
|
8
|
+
];
|
|
9
|
+
export const isAuthHookName = (name) => AUTH_HOOK_NAMES.includes(name);
|
|
10
|
+
/** The hooks the app's `zite.auth.ts` defines, by name. */
|
|
11
|
+
export async function loadAuthHooks() {
|
|
12
|
+
if (!authHooksModule)
|
|
13
|
+
return {};
|
|
14
|
+
const hooks = (await authHooksModule()).default?.hooks ?? {};
|
|
15
|
+
return Object.fromEntries(AUTH_HOOK_NAMES.flatMap(name => typeof hooks[name] === 'function'
|
|
16
|
+
? [[name, hooks[name]]]
|
|
17
|
+
: []));
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HostRequestState } from '../types.js';
|
|
2
|
+
/** A platform call a demo refused, which then decides how the request's failure answers. */
|
|
3
|
+
export declare const noteDemoRefusal: (host: HostRequestState | undefined, error: unknown) => void;
|
|
4
|
+
/**
|
|
5
|
+
* As classic's executor outcome: a demo's failure after a refusal is the refusal, and so is a 5xx after the app called
|
|
6
|
+
* out, since a demo holds no account to call with.
|
|
7
|
+
*/
|
|
8
|
+
export declare const failedOnDemo: (host: HostRequestState, response: Response) => boolean;
|
|
9
|
+
export declare const asDemoRefusal: (response: Response) => Response;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Classic's demo answers a call the demo refused with 403 `DEMO_READ_ONLY`, on which the platform's runtime shows the
|
|
2
|
+
// visitor its "not available in the demo" notice (restly's app-runtime demo.ts). A refused call reaches a Start app as
|
|
3
|
+
// an error it may catch or rethrow, so the answer keeps its body and says so in a header.
|
|
4
|
+
import { DEMO_UNAVAILABLE_MESSAGE } from '../platform/data/dispatch.js';
|
|
5
|
+
import { DEMO_READ_ONLY_CODE, ERROR_CODE_HEADER } from '../protocol.js';
|
|
6
|
+
/** A platform call a demo refused, which then decides how the request's failure answers. */
|
|
7
|
+
export const noteDemoRefusal = (host, error) => {
|
|
8
|
+
if (host?.mode === 'demo' &&
|
|
9
|
+
error instanceof Error &&
|
|
10
|
+
error.message.includes(DEMO_UNAVAILABLE_MESSAGE))
|
|
11
|
+
host.demoRefused = true;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* As classic's executor outcome: a demo's failure after a refusal is the refusal, and so is a 5xx after the app called
|
|
15
|
+
* out, since a demo holds no account to call with.
|
|
16
|
+
*/
|
|
17
|
+
export const failedOnDemo = (host, response) => host.mode === 'demo' &&
|
|
18
|
+
response.status >= 400 &&
|
|
19
|
+
(!!host.demoRefused || (response.status >= 500 && !!host.fetches?.length));
|
|
20
|
+
export const asDemoRefusal = (response) => {
|
|
21
|
+
const headers = new Headers(response.headers);
|
|
22
|
+
headers.set(ERROR_CODE_HEADER, DEMO_READ_ONLY_CODE);
|
|
23
|
+
return new Response(response.body, { status: 403, headers });
|
|
24
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The generated server entry's first import: an SDK client an app builds at load (`new OpenAI()` at a module's top
|
|
2
|
+
// level) keeps the fetch it found then, so the wrapper must already be in place, and so must process.env's view.
|
|
3
|
+
import { watchOutboundFetches } from '../platform/outbound.js';
|
|
4
|
+
import { installRequestEnv } from './requestEnv.js';
|
|
5
|
+
watchOutboundFetches();
|
|
6
|
+
installRequestEnv();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type AnySerializationAdapter } from '@tanstack/react-router';
|
|
2
|
+
import type { SSROption } from '@tanstack/router-core';
|
|
3
|
+
import type { AnyFunctionMiddleware, AnyRequestMiddleware, StartInstance } from '@tanstack/start-client-core';
|
|
4
|
+
/**
|
|
5
|
+
* The start instance every Start app builds with: the platform's middleware and
|
|
6
|
+
* adapters first, then whatever the app's own `src/start.ts` sets.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createZiteStart<const TAdapters extends ReadonlyArray<AnySerializationAdapter> = [], TDefaultSsr extends SSROption = SSROption, const TRequest extends ReadonlyArray<AnyRequestMiddleware> = [], const TFunction extends ReadonlyArray<AnyFunctionMiddleware> = []>(app?: StartInstance<TAdapters, TDefaultSsr, TRequest, TFunction>): StartInstance<readonly [import("@tanstack/react-router").SerializationAdapter<Error, {
|
|
9
|
+
stack?: string | undefined;
|
|
10
|
+
code: "BAD_REQUEST" | "UNAUTHORIZED" | "FORBIDDEN" | "NOT_FOUND" | "CONFLICT" | "RATE_LIMITED" | "INTERNAL_ERROR";
|
|
11
|
+
message: string;
|
|
12
|
+
}, never>, ...TAdapters], TDefaultSsr, readonly [import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, undefined, undefined>, import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, undefined, undefined>, ...TRequest], readonly [import("@tanstack/react-start").FunctionMiddlewareAfterClient<{}, unknown, undefined, undefined, undefined>, import("@tanstack/react-start").FunctionMiddlewareAfterServer<{}, unknown, undefined, undefined, undefined, undefined, undefined>, ...TFunction]>;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// For the generated `.zite/start.ts` only: TanStack's start-instance file, the only place Start 1.169 registers global
|
|
2
|
+
// middleware. Generated, so an app can't drop the CSRF check or the run log below; its own `src/start.ts` options compose
|
|
3
|
+
// after the platform's.
|
|
4
|
+
import { createCsrfMiddleware, createMiddleware, createStart, } from '@tanstack/react-start';
|
|
5
|
+
import { createSerializationAdapter, redirect, } from '@tanstack/react-router';
|
|
6
|
+
import { getStartContext } from '@tanstack/start-storage-context';
|
|
7
|
+
import { asCrossed, errorFromThrown, isSignInRequired, toClientError, withThrownRejections, ZiteError, } from '../errors.js';
|
|
8
|
+
import { setFailedStatus } from '../failures.js';
|
|
9
|
+
import { loginHref } from '../login.js';
|
|
10
|
+
import { preview, ranTo, recordRun } from '../platform/runLog.js';
|
|
11
|
+
import { currentHost } from '../host.js';
|
|
12
|
+
import { getHost, inScope } from './scope.js';
|
|
13
|
+
// TanStack drops its default CSRF check once an app has a start instance. Server functions, and every other unsafe
|
|
14
|
+
// request a browser's cookies ride on: the app's own routes too, as Zite's front checks them.
|
|
15
|
+
const SAFE_METHODS = new Set(['GET', 'HEAD', 'OPTIONS']);
|
|
16
|
+
const csrf = createCsrfMiddleware({
|
|
17
|
+
filter: ctx => ctx.handlerType === 'serverFn' ||
|
|
18
|
+
(!SAFE_METHODS.has(ctx.request.method) &&
|
|
19
|
+
ctx.request.headers.has('cookie')),
|
|
20
|
+
});
|
|
21
|
+
// The app's own request middleware runs inside this one. On a server-function request
|
|
22
|
+
// what it throws crosses to the browser as thrown, and only an Error goes through the
|
|
23
|
+
// zite-error adapter.
|
|
24
|
+
const thrownAsErrors = createMiddleware().server(async ({ next }) => {
|
|
25
|
+
try {
|
|
26
|
+
return await next();
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
throw errorFromThrown(error);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
// The host answers a signed-out call with a plain 401, the app with a ZiteError;
|
|
33
|
+
// either way the browser goes to sign in rather than showing an error.
|
|
34
|
+
const signInOn401 = createMiddleware({ type: 'function' }).client(async ({ next }) => {
|
|
35
|
+
try {
|
|
36
|
+
return await next();
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (!isSignInRequired(error))
|
|
40
|
+
throw error;
|
|
41
|
+
const href = loginHref();
|
|
42
|
+
if (typeof window !== 'undefined')
|
|
43
|
+
window.location.assign(href);
|
|
44
|
+
throw redirect({ href, reloadDocument: true });
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
// Records each call for the run log. The host's own record of the request is the
|
|
48
|
+
// floor; this adds what only the app sees: decoded input, output and errors. The
|
|
49
|
+
// app's own function middleware runs inside it, outside the access middleware, so
|
|
50
|
+
// what it throws, and what a promise in the result rejects with, is normalized here
|
|
51
|
+
// on its way to the browser. A call made in-process while a page renders gets the
|
|
52
|
+
// error the browser would: its caller may put the message into the page.
|
|
53
|
+
const runCapture = createMiddleware({ type: 'function' }).server(async ({ next, data, serverFnMeta }) => {
|
|
54
|
+
const host = getHost();
|
|
55
|
+
const run = {
|
|
56
|
+
fn: serverFnMeta.id,
|
|
57
|
+
name: serverFnMeta.name,
|
|
58
|
+
nested: inScope(),
|
|
59
|
+
startedAt: Date.now(),
|
|
60
|
+
input: preview(data),
|
|
61
|
+
};
|
|
62
|
+
const record = (outcome) => recordRun(host, { ...run, ...ranTo(outcome) });
|
|
63
|
+
const inProcess = !inScope() &&
|
|
64
|
+
getStartContext({ throwIfNotFound: false })?.handlerType !== 'serverFn';
|
|
65
|
+
const crossed = (error) => inProcess && error instanceof Error ? asCrossed(error) : error;
|
|
66
|
+
const fail = (error) => {
|
|
67
|
+
const failure = errorFromThrown(error);
|
|
68
|
+
record({ error: failure });
|
|
69
|
+
setFailedStatus(failure);
|
|
70
|
+
return crossed(failure);
|
|
71
|
+
};
|
|
72
|
+
try {
|
|
73
|
+
const out = await next();
|
|
74
|
+
const failed = out.error;
|
|
75
|
+
if (failed !== undefined)
|
|
76
|
+
return { ...out, error: fail(failed) };
|
|
77
|
+
const { result } = out;
|
|
78
|
+
record({ output: result });
|
|
79
|
+
const settled = withThrownRejections(result, crossed);
|
|
80
|
+
return settled === result ? out : { ...out, result: settled };
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
throw fail(error);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
/**
|
|
87
|
+
* Every error a server function or a page's loader sends the browser arrives as a ZiteError, with its code and the
|
|
88
|
+
* message classic would show. Anything else on it, an SDK's request, stays on the server; its stack goes only to the
|
|
89
|
+
* editor's preview, for "Fix it for me".
|
|
90
|
+
*/
|
|
91
|
+
const ziteErrorAdapter = createSerializationAdapter({
|
|
92
|
+
key: 'zite-error',
|
|
93
|
+
test: (value) => value instanceof Error,
|
|
94
|
+
toSerializable: error => {
|
|
95
|
+
const { code, message } = toClientError(error);
|
|
96
|
+
// `currentHost`, not `getHost`: this adapter ships to the browser, which mustn't bundle the request scope.
|
|
97
|
+
const stack = currentHost()?.mode === 'preview' ? error.stack : undefined;
|
|
98
|
+
return { code, message, ...(stack && { stack }) };
|
|
99
|
+
},
|
|
100
|
+
fromSerializable: ({ code, message, stack, }) => {
|
|
101
|
+
const error = new ZiteError(code, message);
|
|
102
|
+
if (stack)
|
|
103
|
+
error.stack = stack;
|
|
104
|
+
return error;
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
/**
|
|
108
|
+
* The start instance every Start app builds with: the platform's middleware and
|
|
109
|
+
* adapters first, then whatever the app's own `src/start.ts` sets.
|
|
110
|
+
*/
|
|
111
|
+
export function createZiteStart(app) {
|
|
112
|
+
return createStart(async () => {
|
|
113
|
+
const own = app ? await app.getOptions() : undefined;
|
|
114
|
+
// Spreading the app's optional arrays loses their tuple types, which the
|
|
115
|
+
// route tree registers for typed context and serialization.
|
|
116
|
+
return {
|
|
117
|
+
...own,
|
|
118
|
+
requestMiddleware: [
|
|
119
|
+
csrf,
|
|
120
|
+
thrownAsErrors,
|
|
121
|
+
...(own?.requestMiddleware ?? []),
|
|
122
|
+
],
|
|
123
|
+
functionMiddleware: [
|
|
124
|
+
signInOn401,
|
|
125
|
+
runCapture,
|
|
126
|
+
...(own?.functionMiddleware ?? []),
|
|
127
|
+
],
|
|
128
|
+
serializationAdapters: [
|
|
129
|
+
ziteErrorAdapter,
|
|
130
|
+
...(own?.serializationAdapters ?? []),
|
|
131
|
+
],
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type LoadedWorkflow } from '../automations/workflowRun.js';
|
|
2
|
+
import type { HostInvoke, HostRequestState } from '../types.js';
|
|
3
|
+
/** A request's `warm` or `describe`, from its header; null for anything else, which only props invoke. */
|
|
4
|
+
export declare const headerInvoke: (headers: Headers) => HostInvoke | null;
|
|
5
|
+
export type InvokeDeps = {
|
|
6
|
+
workflows: () => Promise<LoadedWorkflow[]>;
|
|
7
|
+
functionIds: () => string[];
|
|
8
|
+
handler: {
|
|
9
|
+
fetch(request: Request): Promise<Response> | Response;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
/** Answers the invokes the host POSTs; undefined for any other request, which the app serves. */
|
|
13
|
+
export declare const createInvoker: (deps: InvokeDeps) => (host: HostRequestState, request: Request) => Promise<Response> | undefined;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Server-only: what the host invokes beside serving pages. `warm` and `describe` come without props, by header; a
|
|
2
|
+
// webhook is the app's own route; the rest the host POSTs to the invoke path with props and `{ input }`.
|
|
3
|
+
import { createSsrRpc } from '@tanstack/react-start/ssr-rpc';
|
|
4
|
+
import { withoutConsole } from '../automations/quiet.js';
|
|
5
|
+
import { runRegistration } from '../automations/registration.js';
|
|
6
|
+
import { loggedInput, runWorkflow, } from '../automations/workflowRun.js';
|
|
7
|
+
import { errorOf, preview, ranTo, recordRun } from '../platform/runLog.js';
|
|
8
|
+
import { INVOKE_HEADER, INVOKE_PATH, isInvokeKind, } from '../protocol.js';
|
|
9
|
+
import { isAuthHookName, loadAuthHooks } from './authHooks.js';
|
|
10
|
+
import { runInScope } from './scope.js';
|
|
11
|
+
// Neither runs app code on anyone's behalf, so a request without props may ask for them.
|
|
12
|
+
const HEADER_INVOKE_KINDS = new Set([
|
|
13
|
+
'warm',
|
|
14
|
+
'describe',
|
|
15
|
+
]);
|
|
16
|
+
/** A request's `warm` or `describe`, from its header; null for anything else, which only props invoke. */
|
|
17
|
+
export const headerInvoke = (headers) => {
|
|
18
|
+
const [kind, name = ''] = headers.get(INVOKE_HEADER)?.split(':') ?? [];
|
|
19
|
+
return isInvokeKind(kind) && HEADER_INVOKE_KINDS.has(kind)
|
|
20
|
+
? { kind, name }
|
|
21
|
+
: null;
|
|
22
|
+
};
|
|
23
|
+
const POSTED = ['workflow', 'register', 'authHook', 'function'];
|
|
24
|
+
const isPosted = (kind) => POSTED.includes(kind);
|
|
25
|
+
const notFound = (message) => Response.json({ ok: false, error: { code: 'NOT_FOUND', message } }, { status: 404 });
|
|
26
|
+
const handlersOf = ({ workflows, functionIds, handler, }) => ({
|
|
27
|
+
// A platform-fired run's input carries the runner's `__cron`, `__poll` or `__webhook` state, as classic endpoints get.
|
|
28
|
+
workflow: async ({ name, body, host }) => {
|
|
29
|
+
const found = (await workflows()).find(w => w.id === name);
|
|
30
|
+
if (!found)
|
|
31
|
+
return notFound(`No workflow named ${name}`);
|
|
32
|
+
const startedAt = Date.now();
|
|
33
|
+
const result = await runWorkflow(found.workflow, body.input, {
|
|
34
|
+
resuming: host.runRoot !== undefined,
|
|
35
|
+
durable: host.durable,
|
|
36
|
+
});
|
|
37
|
+
recordRun(host, {
|
|
38
|
+
fn: `workflow:${name}`,
|
|
39
|
+
name,
|
|
40
|
+
nested: false,
|
|
41
|
+
startedAt,
|
|
42
|
+
input: preview(loggedInput(body.input)),
|
|
43
|
+
...(result.stop === 'finished'
|
|
44
|
+
? { output: preview(result.output) }
|
|
45
|
+
: result.stop === 'suspended'
|
|
46
|
+
? { suspended: result.suspension }
|
|
47
|
+
: { error: result.error }),
|
|
48
|
+
...(result.steps && { steps: result.steps }),
|
|
49
|
+
...(!result.ok &&
|
|
50
|
+
result.failedStep !== undefined && { failedStep: result.failedStep }),
|
|
51
|
+
});
|
|
52
|
+
return Response.json(result, { status: result.ok ? 200 : 500 });
|
|
53
|
+
},
|
|
54
|
+
// `{ op, input }`: `subscribe` with the platform's notification URL and secret, or `unsubscribe` with what
|
|
55
|
+
// `subscribe` returned.
|
|
56
|
+
register: ({ name, body }) => withoutConsole(async () => {
|
|
57
|
+
const result = await runRegistration(await workflows(), name, body.op, body.input);
|
|
58
|
+
if (!result)
|
|
59
|
+
return notFound(`${name} has no ${String(body.op)}`);
|
|
60
|
+
return Response.json(result, { status: result.ok ? 200 : 500 });
|
|
61
|
+
}),
|
|
62
|
+
// The fields classic hooks get. A hook runs as a workflow does: no user, and the app's platform.
|
|
63
|
+
authHook: async ({ name, body, host }) => {
|
|
64
|
+
const hook = isAuthHookName(name)
|
|
65
|
+
? (await loadAuthHooks())[name]
|
|
66
|
+
: undefined;
|
|
67
|
+
if (!hook)
|
|
68
|
+
return notFound(`No auth hook named ${name}`);
|
|
69
|
+
const input = body.input ?? {};
|
|
70
|
+
const run = {
|
|
71
|
+
fn: `authHook:${name}`,
|
|
72
|
+
name,
|
|
73
|
+
nested: false,
|
|
74
|
+
startedAt: Date.now(),
|
|
75
|
+
input: preview(input),
|
|
76
|
+
};
|
|
77
|
+
try {
|
|
78
|
+
const output = await runInScope({ kind: 'workflow', user: null }, () => hook(input));
|
|
79
|
+
recordRun(host, { ...run, ...ranTo({ output }) });
|
|
80
|
+
return Response.json({ ok: true, output: output ?? null });
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
recordRun(host, { ...run, ...ranTo({ error }) });
|
|
84
|
+
return Response.json({ ok: false, error: errorOf(error) }, { status: 500 });
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
// An editor's test run, as a page's call runs on the server: in TanStack's own request, where the router answers the
|
|
88
|
+
// invoke path, so the function's middleware decides access for the dispatched user, validates and records it.
|
|
89
|
+
function: async ({ name, body, host, request }) => {
|
|
90
|
+
if (!functionIds().includes(name))
|
|
91
|
+
return notFound(`No server function ${name}`);
|
|
92
|
+
host.functionRun = async () => {
|
|
93
|
+
try {
|
|
94
|
+
const answer = (await createSsrRpc(name)({
|
|
95
|
+
data: body.input,
|
|
96
|
+
context: {},
|
|
97
|
+
}));
|
|
98
|
+
if ('error' in answer)
|
|
99
|
+
throw answer.error;
|
|
100
|
+
return Response.json({ ok: true, output: answer.result ?? null });
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
return Response.json({ ok: false, error: errorOf(error) }, { status: 500 });
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
return handler.fetch(new Request(request.url, { method: 'POST', headers: request.headers }));
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
/** Answers the invokes the host POSTs; undefined for any other request, which the app serves. */
|
|
110
|
+
export const createInvoker = (deps) => {
|
|
111
|
+
const handlers = handlersOf(deps);
|
|
112
|
+
return (host, request) => {
|
|
113
|
+
const invoke = host.invoke;
|
|
114
|
+
if (!invoke || !isPosted(invoke.kind))
|
|
115
|
+
return undefined;
|
|
116
|
+
const handle = handlers[invoke.kind];
|
|
117
|
+
return (async () => {
|
|
118
|
+
if (request.method !== 'POST' ||
|
|
119
|
+
new URL(request.url).pathname !== INVOKE_PATH)
|
|
120
|
+
return new Response('Not found', { status: 404 });
|
|
121
|
+
const parsed = await request.json().catch(() => null);
|
|
122
|
+
const body = parsed && typeof parsed === 'object' ? parsed : {};
|
|
123
|
+
return handle({ name: invoke.name, body, host, request });
|
|
124
|
+
})();
|
|
125
|
+
};
|
|
126
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HostRequestState, PlatformProvider } from '../../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The developer's dev token reaches the platform, and the stand-in user is signed in. Headers still invoke only warm
|
|
4
|
+
* and describe. Its mode, base and app URL come once the backend has said what the token is for, with `loadLocal`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const hostContextFromLocal: (request: Request, provider: PlatformProvider) => HostRequestState;
|
|
7
|
+
/** What the backend says of the dev token, and its connections. A dev token it won't describe fails the request, saying why. */
|
|
8
|
+
export declare const loadLocal: (host: HostRequestState) => Promise<void>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// A request under `vite dev` with the `local` provider. No host hands `local` what its token is for or its
|
|
2
|
+
// connections' env, so it reads them before app code runs; its pages show the Settings the build baked.
|
|
3
|
+
import { builtSiteHead } from '../../build/placeholders/siteHead.js';
|
|
4
|
+
import { connectionsOnToken } from '../../platform/connections.js';
|
|
5
|
+
import { directAccess } from '../../platform/transport.js';
|
|
6
|
+
import { headerInvoke } from '../invoke.js';
|
|
7
|
+
import { platformHeadOf } from '../pageHead.js';
|
|
8
|
+
/**
|
|
9
|
+
* The developer's dev token reaches the platform, and the stand-in user is signed in. Headers still invoke only warm
|
|
10
|
+
* and describe. Its mode, base and app URL come once the backend has said what the token is for, with `loadLocal`.
|
|
11
|
+
*/
|
|
12
|
+
export const hostContextFromLocal = (request, provider) => ({
|
|
13
|
+
requestId: crypto.randomUUID(),
|
|
14
|
+
url: request.url,
|
|
15
|
+
user: provider.user(),
|
|
16
|
+
mode: 'preview',
|
|
17
|
+
invoke: headerInvoke(request.headers),
|
|
18
|
+
runs: [],
|
|
19
|
+
provider,
|
|
20
|
+
head: platformHeadOf(builtSiteHead ?? {}, {
|
|
21
|
+
url: request.url,
|
|
22
|
+
mode: 'preview',
|
|
23
|
+
}),
|
|
24
|
+
});
|
|
25
|
+
/** What the backend says of the dev token, and its connections. A dev token it won't describe fails the request, saying why. */
|
|
26
|
+
export const loadLocal = async (host) => {
|
|
27
|
+
const access = await directAccess(host);
|
|
28
|
+
if (!access || !host.provider)
|
|
29
|
+
return;
|
|
30
|
+
const context = await host.provider.context();
|
|
31
|
+
host.mode = context.mode;
|
|
32
|
+
host.appUrl = context.appUrl ?? undefined;
|
|
33
|
+
host.baseId = context.baseId ?? undefined;
|
|
34
|
+
const connections = await connectionsOnToken(access, context).catch((error) => {
|
|
35
|
+
console.error("[zite] couldn't load the app's connections", error);
|
|
36
|
+
return undefined;
|
|
37
|
+
});
|
|
38
|
+
if (connections) {
|
|
39
|
+
host.env = connections.env;
|
|
40
|
+
host.envConnections = connections.envConnections;
|
|
41
|
+
}
|
|
42
|
+
// The backend serves the platform's runtime, wherever `local` points it.
|
|
43
|
+
host.head = platformHeadOf(builtSiteHead ?? {}, { url: host.url, mode: host.mode }, { context, runtimeUrl: `${access.urls.backend}/runtime/app-runtime.js` });
|
|
44
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AppContext, ExpiringToken, PlatformProvider, PlatformUrls } from '../../types.js';
|
|
2
|
+
/** What `local` reads, documented in `zitejs`'s help. */
|
|
3
|
+
export declare const LOCAL_ENV: {
|
|
4
|
+
readonly token: "ZITE_DEV_TOKEN";
|
|
5
|
+
readonly apiKey: "ZITE_DEV_API_KEY";
|
|
6
|
+
readonly urls: "ZITE_URLS";
|
|
7
|
+
readonly user: "ZITE_DEV_USER";
|
|
8
|
+
};
|
|
9
|
+
type Env = Record<string, string | undefined>;
|
|
10
|
+
/** `ZITE_URLS`, or a throw saying what it must name. */
|
|
11
|
+
export declare const localUrls: (raw: string | undefined) => PlatformUrls;
|
|
12
|
+
/** For tests: forget the minted dev token and what the backend said of it. */
|
|
13
|
+
export declare const resetDevToken: () => void;
|
|
14
|
+
export declare const mintDevToken: (backend: string, appId: string, apiKey: string) => Promise<ExpiringToken>;
|
|
15
|
+
/**
|
|
16
|
+
* What the backend says of a dev token, from the claims it verified, as OAuth's token introspection answers: asked
|
|
17
|
+
* once per token, whose claims never change. Throws, saying why, when it won't say.
|
|
18
|
+
*/
|
|
19
|
+
export declare const describeDevToken: (backend: string, token: string) => Promise<AppContext>;
|
|
20
|
+
/**
|
|
21
|
+
* `local` when the developer set a dev token, or a key to mint them with, else undefined. Throws on env it can't read,
|
|
22
|
+
* so a typo fails loudly rather than signing nobody in.
|
|
23
|
+
*/
|
|
24
|
+
export declare const localPlatform: (env?: Env, appId?: string | null) => PlatformProvider | undefined;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// `local`: a developer's machine, with a dev token the backend minted, which the backend also describes.
|
|
2
|
+
import { platformFetch } from '../../../internal/platformFetch.js';
|
|
3
|
+
import { devAppId } from '../../build/placeholders/devApp.js';
|
|
4
|
+
import { contextOf, isExpiringToken, renewedToken, trimmed, URL_NAMES, } from '../provider.js';
|
|
5
|
+
/** What `local` reads, documented in `zitejs`'s help. */
|
|
6
|
+
export const LOCAL_ENV = {
|
|
7
|
+
token: 'ZITE_DEV_TOKEN',
|
|
8
|
+
apiKey: 'ZITE_DEV_API_KEY',
|
|
9
|
+
urls: 'ZITE_URLS',
|
|
10
|
+
user: 'ZITE_DEV_USER',
|
|
11
|
+
};
|
|
12
|
+
const processEnv = () => globalThis.process?.env;
|
|
13
|
+
// `local` may leave out the gateway (a call on Zite's AI key is then refused), `runs` (a preview sends no analytics,
|
|
14
|
+
// and `local` keeps no run detail) and each service's own URL.
|
|
15
|
+
const OPTIONAL_URLS = new Set([
|
|
16
|
+
'gateway',
|
|
17
|
+
'runs',
|
|
18
|
+
'email',
|
|
19
|
+
'pdf',
|
|
20
|
+
'uploads',
|
|
21
|
+
'steps',
|
|
22
|
+
'schedules',
|
|
23
|
+
]);
|
|
24
|
+
// Where the backend `ZITE_URLS` names answers a service it doesn't name. A dev token runs no workflow, so no steps.
|
|
25
|
+
const BACKEND_SERVICE_ROUTES = {
|
|
26
|
+
email: '/v1/start/app/email',
|
|
27
|
+
pdf: '/v1/start/app/pdf',
|
|
28
|
+
uploads: '/v1/start/app/uploads/session',
|
|
29
|
+
schedules: '/v1/start/app/schedules',
|
|
30
|
+
};
|
|
31
|
+
/** `ZITE_URLS`, or a throw saying what it must name. */
|
|
32
|
+
export const localUrls = (raw) => {
|
|
33
|
+
let parsed;
|
|
34
|
+
try {
|
|
35
|
+
parsed = JSON.parse(raw ?? '');
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
parsed = undefined;
|
|
39
|
+
}
|
|
40
|
+
const given = (parsed ?? {});
|
|
41
|
+
const isUrl = (value) => typeof value === 'string' && /^https?:\/\//.test(value);
|
|
42
|
+
if (URL_NAMES.some(name => given[name] === undefined
|
|
43
|
+
? !OPTIONAL_URLS.has(name)
|
|
44
|
+
: !isUrl(given[name]))) {
|
|
45
|
+
throw new Error(`${LOCAL_ENV.urls} must be JSON naming the baseRunner and backend URLs, and may name gateway, runs, email, pdf, uploads, steps and schedules`);
|
|
46
|
+
}
|
|
47
|
+
const urls = trimmed(given);
|
|
48
|
+
const defaults = Object.fromEntries(Object.entries(BACKEND_SERVICE_ROUTES).map(([name, route]) => [
|
|
49
|
+
name,
|
|
50
|
+
`${urls.backend}${route}`,
|
|
51
|
+
]));
|
|
52
|
+
return { ...defaults, ...urls };
|
|
53
|
+
};
|
|
54
|
+
const localUser = (raw) => {
|
|
55
|
+
if (!raw)
|
|
56
|
+
return null;
|
|
57
|
+
let given;
|
|
58
|
+
try {
|
|
59
|
+
given = JSON.parse(raw);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
given = undefined;
|
|
63
|
+
}
|
|
64
|
+
if (typeof given?.id !== 'string' || typeof given.email !== 'string') {
|
|
65
|
+
throw new Error(`${LOCAL_ENV.user} must be JSON with the stand-in user's id and email`);
|
|
66
|
+
}
|
|
67
|
+
const roles = Array.isArray(given.roles) ? given.roles : [];
|
|
68
|
+
return {
|
|
69
|
+
id: given.id,
|
|
70
|
+
email: given.email,
|
|
71
|
+
name: typeof given.name === 'string' ? given.name : given.email,
|
|
72
|
+
roles: roles.map((role) => typeof role === 'string' ? { id: role, name: role } : role),
|
|
73
|
+
isInternal: given.isInternal === true,
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
// The backend mints them for 15 minutes.
|
|
77
|
+
const RENEW_DEV_TOKEN_WITHIN_MS = 60_000;
|
|
78
|
+
const BACKEND_TIMEOUT_MS = 10_000;
|
|
79
|
+
// Per isolate, only answers, never a pending call: Workers ties a request's I/O to that request.
|
|
80
|
+
let held;
|
|
81
|
+
let described;
|
|
82
|
+
/** For tests: forget the minted dev token and what the backend said of it. */
|
|
83
|
+
export const resetDevToken = () => {
|
|
84
|
+
held = undefined;
|
|
85
|
+
described = undefined;
|
|
86
|
+
};
|
|
87
|
+
const reasonOf = (response, answer) => {
|
|
88
|
+
const why = [answer?.message, answer?.error].find(text => typeof text === 'string');
|
|
89
|
+
return `${response.status}${why ? ` ${why}` : ''}`;
|
|
90
|
+
};
|
|
91
|
+
export const mintDevToken = async (backend, appId, apiKey) => {
|
|
92
|
+
const response = await platformFetch(new Request(`${backend}/v1/start/apps/${encodeURIComponent(appId)}/dev-token`, {
|
|
93
|
+
method: 'POST',
|
|
94
|
+
headers: { authorization: `Bearer ${apiKey}` },
|
|
95
|
+
signal: AbortSignal.timeout(BACKEND_TIMEOUT_MS),
|
|
96
|
+
}));
|
|
97
|
+
const answer = (await response.json().catch(() => null));
|
|
98
|
+
if (response.ok && isExpiringToken(answer))
|
|
99
|
+
return { token: answer.token, expiresAt: answer.expiresAt };
|
|
100
|
+
throw new Error(`The backend didn't mint a dev token for app ${appId} with ${LOCAL_ENV.apiKey}: ${reasonOf(response, answer)}`);
|
|
101
|
+
};
|
|
102
|
+
const MODES = new Set([
|
|
103
|
+
'live',
|
|
104
|
+
'preview',
|
|
105
|
+
'demo',
|
|
106
|
+
]);
|
|
107
|
+
const isWhole = (value) => Number.isSafeInteger(value) && value >= 0;
|
|
108
|
+
const isText = (value) => typeof value === 'string' && value !== '';
|
|
109
|
+
const isTextOrNull = (value) => value === null || isText(value);
|
|
110
|
+
/** The backend's `/context` answer, or undefined when it isn't one. */
|
|
111
|
+
const appContextOf = (answer) => {
|
|
112
|
+
const given = answer;
|
|
113
|
+
if (!given ||
|
|
114
|
+
!isText(given.appId) ||
|
|
115
|
+
!isWhole(given.buildId) ||
|
|
116
|
+
!isTextOrNull(given.baseId) ||
|
|
117
|
+
!MODES.has(given.mode) ||
|
|
118
|
+
!(given.orgSettingsVersion === null || isWhole(given.orgSettingsVersion)) ||
|
|
119
|
+
typeof given.showZiteBadge !== 'boolean' ||
|
|
120
|
+
!isTextOrNull(given.appUrl)) {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
return contextOf(given);
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* What the backend says of a dev token, from the claims it verified, as OAuth's token introspection answers: asked
|
|
127
|
+
* once per token, whose claims never change. Throws, saying why, when it won't say.
|
|
128
|
+
*/
|
|
129
|
+
export const describeDevToken = async (backend, token) => {
|
|
130
|
+
const key = `${backend} ${token}`;
|
|
131
|
+
if (described?.key === key)
|
|
132
|
+
return described.context;
|
|
133
|
+
const response = await platformFetch(new Request(`${backend}/v1/start/app/context`, {
|
|
134
|
+
headers: { authorization: `Bearer ${token}` },
|
|
135
|
+
signal: AbortSignal.timeout(BACKEND_TIMEOUT_MS),
|
|
136
|
+
}));
|
|
137
|
+
const answer = await response.json().catch(() => null);
|
|
138
|
+
const context = response.ok ? appContextOf(answer) : undefined;
|
|
139
|
+
if (!context)
|
|
140
|
+
throw new Error(`The backend didn't say which app the dev token is for: ${reasonOf(response, answer)}`);
|
|
141
|
+
described = { key, context };
|
|
142
|
+
return context;
|
|
143
|
+
};
|
|
144
|
+
/** The app's dev token, minted with the developer's key, and minted again when the mint's expiry is near. */
|
|
145
|
+
const mintedDevToken = (backend, appId, apiKey) => {
|
|
146
|
+
const key = `${backend} ${appId} ${apiKey}`;
|
|
147
|
+
const token = renewedToken({
|
|
148
|
+
held: () => (held?.key === key ? held.minted : undefined),
|
|
149
|
+
keep: minted => (held = { key, minted }),
|
|
150
|
+
renew: () => mintDevToken(backend, appId, apiKey),
|
|
151
|
+
withinMs: RENEW_DEV_TOKEN_WITHIN_MS,
|
|
152
|
+
});
|
|
153
|
+
return async () => {
|
|
154
|
+
const minted = await token();
|
|
155
|
+
if (!minted)
|
|
156
|
+
throw new Error(`The backend didn't mint a dev token for app ${appId}`);
|
|
157
|
+
return minted;
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
// A given dev token is used as it is. A key mints them only under `vite dev`, which knows the app's id.
|
|
161
|
+
const localToken = (env, appId) => {
|
|
162
|
+
const given = env[LOCAL_ENV.token];
|
|
163
|
+
if (given)
|
|
164
|
+
return () => async () => given;
|
|
165
|
+
const apiKey = env[LOCAL_ENV.apiKey];
|
|
166
|
+
return apiKey && appId
|
|
167
|
+
? backend => mintedDevToken(backend, appId, apiKey)
|
|
168
|
+
: undefined;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* `local` when the developer set a dev token, or a key to mint them with, else undefined. Throws on env it can't read,
|
|
172
|
+
* so a typo fails loudly rather than signing nobody in.
|
|
173
|
+
*/
|
|
174
|
+
export const localPlatform = (env = processEnv() ?? {}, appId = devAppId) => {
|
|
175
|
+
const token = localToken(env, appId);
|
|
176
|
+
if (!token)
|
|
177
|
+
return undefined;
|
|
178
|
+
const urls = localUrls(env[LOCAL_ENV.urls]);
|
|
179
|
+
const user = localUser(env[LOCAL_ENV.user]);
|
|
180
|
+
const tokenOf = token(urls.backend);
|
|
181
|
+
return {
|
|
182
|
+
kind: 'local',
|
|
183
|
+
urls,
|
|
184
|
+
user: () => user,
|
|
185
|
+
token: tokenOf,
|
|
186
|
+
context: async () => describeDevToken(urls.backend, await tokenOf()),
|
|
187
|
+
};
|
|
188
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { IdentityClaims, SignIn } from '../../../signin/index.js';
|
|
2
|
+
import type { Resolution } from '../../../signin/signin.js';
|
|
3
|
+
import type { User } from '../../types.js';
|
|
4
|
+
/** What the module reads, from env or from the `.zite/dev.env` that `zitejs dev` writes. */
|
|
5
|
+
export declare const LOCAL_SIGNIN_ENV: {
|
|
6
|
+
readonly config: "ZITE_SIGNIN";
|
|
7
|
+
readonly secret: "ZITE_AUTH_SECRET";
|
|
8
|
+
};
|
|
9
|
+
type Env = Record<string, string | undefined>;
|
|
10
|
+
/**
|
|
11
|
+
* The module for this request, when the env names an issuer; undefined otherwise, and whenever `ZITE_DEV_USER` is
|
|
12
|
+
* set: the stand-in wins, with no network, as agent sandboxes need.
|
|
13
|
+
*/
|
|
14
|
+
export declare const localSignIn: (env: Env, request: Request) => Promise<SignIn | undefined>;
|
|
15
|
+
/** The identity as app code reads it. Off Zite no role names are known, so each role is named by its id. */
|
|
16
|
+
export declare const userOfIdentity: (claims: IdentityClaims | null) => User | null;
|
|
17
|
+
export declare const withSetCookies: (response: Response, cookies: string[]) => Response;
|
|
18
|
+
/**
|
|
19
|
+
* Off Zite with an issuer configured: the sign-in module answers its own paths and nothing else under them reaches the
|
|
20
|
+
* app, then says who is calling. Undefined when it isn't mounted or has answered.
|
|
21
|
+
*/
|
|
22
|
+
export declare const signInLocally: (request: Request) => Promise<{
|
|
23
|
+
answered: Response;
|
|
24
|
+
} | {
|
|
25
|
+
request: Request;
|
|
26
|
+
signedIn: Resolution;
|
|
27
|
+
} | undefined>;
|
|
28
|
+
export {};
|