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,510 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every fetch an app makes on the server, wrapped as classic's runtime wraps
|
|
3
|
+
* it: logged, every secret it knows redacted, with the connection whose token
|
|
4
|
+
* it carries and what an org's own AI key used; a 401 on a connection's token
|
|
5
|
+
* refreshed and sent once more; and a call on Zite's own AI key sent to Zite's
|
|
6
|
+
* gateway on the request's app token.
|
|
7
|
+
*/
|
|
8
|
+
import { isPlatformRequest } from '../../internal/platformFetch.js';
|
|
9
|
+
import { AI_USAGE_HOSTS, meterAiResponse, withStreamUsage } from './aiUsage.js';
|
|
10
|
+
import { setCapped } from './caps.js';
|
|
11
|
+
import { DEMO_UNAVAILABLE_MESSAGE } from './data/dispatch.js';
|
|
12
|
+
import { refreshConnection } from './connections.js';
|
|
13
|
+
import { directAccess } from './transport.js';
|
|
14
|
+
import { REDACTED, redactKnown, secretForms } from './redactSecrets.js';
|
|
15
|
+
import { GATEWAY_MARKER, handedSecrets, MIN_TOKEN_LENGTH, } from './requestSecrets.js';
|
|
16
|
+
import { getHost } from '../serve/scope.js';
|
|
17
|
+
import { GATEWAY_CONNECTION_HEADER } from '../protocol.js';
|
|
18
|
+
const MAX_FETCHES = 500;
|
|
19
|
+
// As classic: Workers send no User-Agent, and some APIs (GitHub) refuse a request without one.
|
|
20
|
+
const DEFAULT_USER_AGENT = 'zite';
|
|
21
|
+
// The gateway's name in a connection's `baseUrl`, which zitejs resolves to the provider's `urls.gateway`.
|
|
22
|
+
const GATEWAY_HOST = 'zite-gateway.invalid';
|
|
23
|
+
// A provider's own base URL at the host: `/v1` is OpenAI's, Anthropic's SDK sends it in the path.
|
|
24
|
+
const AI_PROVIDER_HOSTS = {
|
|
25
|
+
'api.openai.com': { provider: 'openai', strip: '/v1' },
|
|
26
|
+
'api.anthropic.com': { provider: 'anthropic', strip: '' },
|
|
27
|
+
};
|
|
28
|
+
// As classic's run log: a body up to 50 KB, a request's fetch bodies up to 200 KB in all.
|
|
29
|
+
const MAX_BODY_CHARS = 50 * 1024;
|
|
30
|
+
const MAX_LOGGED_CHARS = 200 * 1024;
|
|
31
|
+
const MAX_URL_CHARS = 2_000;
|
|
32
|
+
const MAX_ERROR_CHARS = 1_000;
|
|
33
|
+
const SECRET_HEADER = /auth|key|token|secret|signature|password|cookie|session/i;
|
|
34
|
+
// Usage still being read when the request's log is flushed isn't waited on for longer.
|
|
35
|
+
const USAGE_WAIT_MS = 10_000;
|
|
36
|
+
// Tokens refreshed in this isolate, which a later request's props may not name yet.
|
|
37
|
+
const MAX_REFRESHED = 50;
|
|
38
|
+
const refreshedTokens = new Map();
|
|
39
|
+
const replacements = new Map();
|
|
40
|
+
// Moves with each refresh, so a request's list of secrets takes in a token another one refreshed.
|
|
41
|
+
let refreshes = 0;
|
|
42
|
+
const remember = (map, key, value) => setCapped(map, key, value, MAX_REFRESHED);
|
|
43
|
+
const tokensOf = (host) => {
|
|
44
|
+
if (host.connectionTokens)
|
|
45
|
+
return host.connectionTokens;
|
|
46
|
+
const tokens = new Map(refreshedTokens);
|
|
47
|
+
for (const [key, name] of Object.entries(host.envConnections ?? {})) {
|
|
48
|
+
const value = host.env?.[key];
|
|
49
|
+
if (value && value.length >= MIN_TOKEN_LENGTH)
|
|
50
|
+
tokens.set(value, name);
|
|
51
|
+
}
|
|
52
|
+
host.connectionTokens = tokens;
|
|
53
|
+
return tokens;
|
|
54
|
+
};
|
|
55
|
+
/** An `integrations.get` answer, whose values name the calls that carry them. */
|
|
56
|
+
export const rememberConnection = (host, name, connection) => {
|
|
57
|
+
(host.connectionAnswers ??= new Map()).set(name, connection);
|
|
58
|
+
host.secretValues = undefined;
|
|
59
|
+
const tokens = tokensOf(host);
|
|
60
|
+
for (const [field, value] of Object.entries((connection ?? {}))) {
|
|
61
|
+
if (field !== 'status' &&
|
|
62
|
+
field !== 'baseUrl' &&
|
|
63
|
+
typeof value === 'string' &&
|
|
64
|
+
value.length >= MIN_TOKEN_LENGTH) {
|
|
65
|
+
tokens.set(value, name);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
/** An `integrations.get` answer with each token this isolate has since refreshed swapped for its replacement. */
|
|
70
|
+
export const withRefreshedTokens = (answer) => {
|
|
71
|
+
if (replacements.size === 0 || !answer || typeof answer !== 'object')
|
|
72
|
+
return answer;
|
|
73
|
+
let swapped;
|
|
74
|
+
for (const [field, value] of Object.entries(answer)) {
|
|
75
|
+
const fresh = typeof value === 'string' ? replacements.get(value) : undefined;
|
|
76
|
+
if (fresh)
|
|
77
|
+
(swapped ??= { ...answer })[field] = fresh;
|
|
78
|
+
}
|
|
79
|
+
return swapped ?? answer;
|
|
80
|
+
};
|
|
81
|
+
const bare = (value) => value.replace(/^(?:Bearer|Token)\s+/i, '');
|
|
82
|
+
/** Every value this request knows is secret, longest first. */
|
|
83
|
+
const secretsOf = (host) => {
|
|
84
|
+
if (host.secretValues && host.secretsAt === refreshes)
|
|
85
|
+
return host.secretValues;
|
|
86
|
+
const values = new Set([
|
|
87
|
+
...refreshedTokens.keys(),
|
|
88
|
+
...replacements.values(),
|
|
89
|
+
...handedSecrets(host, host.connectionAnswers?.values() ?? []),
|
|
90
|
+
]);
|
|
91
|
+
host.secretValues = [...values].sort((a, b) => b.length - a.length);
|
|
92
|
+
host.secretsAt = refreshes;
|
|
93
|
+
return host.secretValues;
|
|
94
|
+
};
|
|
95
|
+
/** The values a request's own credential headers carry, which the log redacts too. */
|
|
96
|
+
const headerSecrets = (headers) => [...headers].flatMap(([name, value]) => {
|
|
97
|
+
const secret = bare(value);
|
|
98
|
+
return SECRET_HEADER.test(name) &&
|
|
99
|
+
secret.length >= MIN_TOKEN_LENGTH &&
|
|
100
|
+
!GATEWAY_MARKER.test(secret)
|
|
101
|
+
? [secret]
|
|
102
|
+
: [];
|
|
103
|
+
});
|
|
104
|
+
/** `text` cut to `max`, every secret in it redacted, none cut in half first, however it was written. */
|
|
105
|
+
const loggable = (text, secrets, max) => {
|
|
106
|
+
const reach = secrets.reduce((longest, secret) => Math.max(longest, secretForms(secret)[0].length), 0);
|
|
107
|
+
return redactKnown(text.slice(0, max + reach), secrets).slice(0, max);
|
|
108
|
+
};
|
|
109
|
+
const decodings = (raw) => {
|
|
110
|
+
const decoded = [raw];
|
|
111
|
+
for (const text of [raw, raw.replace(/\+/g, ' ')]) {
|
|
112
|
+
try {
|
|
113
|
+
decoded.push(decodeURIComponent(text));
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
// Not encoded as a whole; matched as written.
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return decoded;
|
|
120
|
+
};
|
|
121
|
+
/** A URL with each path segment or query value that holds a secret, however it was encoded, redacted whole. */
|
|
122
|
+
const redactedUrl = (url, secrets) => {
|
|
123
|
+
const holds = (raw) => decodings(raw).some(text => secrets.some(secret => text.includes(secret)));
|
|
124
|
+
const path = url.pathname
|
|
125
|
+
.split('/')
|
|
126
|
+
.map(segment => (holds(segment) ? REDACTED : segment))
|
|
127
|
+
.join('/');
|
|
128
|
+
const query = url.search
|
|
129
|
+
? `?${url.search
|
|
130
|
+
.slice(1)
|
|
131
|
+
.split('&')
|
|
132
|
+
.map(pair => {
|
|
133
|
+
const at = pair.indexOf('=');
|
|
134
|
+
if (at < 0)
|
|
135
|
+
return holds(pair) ? REDACTED : pair;
|
|
136
|
+
return holds(pair.slice(at + 1))
|
|
137
|
+
? `${pair.slice(0, at)}=${REDACTED}`
|
|
138
|
+
: pair;
|
|
139
|
+
})
|
|
140
|
+
.join('&')}`
|
|
141
|
+
: '';
|
|
142
|
+
return `${url.protocol}//${url.host}${path}${query}`;
|
|
143
|
+
};
|
|
144
|
+
/** A request body as classic's run log shows it. */
|
|
145
|
+
const bodyText = (body) => {
|
|
146
|
+
if (body === undefined || body === null)
|
|
147
|
+
return undefined;
|
|
148
|
+
if (typeof body === 'string')
|
|
149
|
+
return body;
|
|
150
|
+
if (body instanceof URLSearchParams)
|
|
151
|
+
return body.toString();
|
|
152
|
+
if (body instanceof ReadableStream)
|
|
153
|
+
return '[stream]';
|
|
154
|
+
if (body instanceof Blob ||
|
|
155
|
+
body instanceof ArrayBuffer ||
|
|
156
|
+
ArrayBuffer.isView(body))
|
|
157
|
+
return '[binary data]';
|
|
158
|
+
if (typeof FormData !== 'undefined' && body instanceof FormData)
|
|
159
|
+
return '[binary data]';
|
|
160
|
+
try {
|
|
161
|
+
return JSON.stringify(body);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return '[non-serializable body]';
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const settledWithin = (promise, ms) => Promise.race([promise, new Promise(resolve => setTimeout(resolve, ms))]).then(() => undefined, () => undefined);
|
|
168
|
+
/** The connection token a request carries, in a header or its query. */
|
|
169
|
+
const carried = (headers, url, tokens) => {
|
|
170
|
+
for (const [, value] of headers) {
|
|
171
|
+
const connection = tokens.get(bare(value));
|
|
172
|
+
if (connection)
|
|
173
|
+
return { token: bare(value), connection };
|
|
174
|
+
}
|
|
175
|
+
for (const [, value] of url.searchParams) {
|
|
176
|
+
const connection = tokens.get(value);
|
|
177
|
+
if (connection)
|
|
178
|
+
return { token: value, connection };
|
|
179
|
+
}
|
|
180
|
+
return undefined;
|
|
181
|
+
};
|
|
182
|
+
/** `url` with each query value equal to `from` set to `to`, every other pair left as it was written. */
|
|
183
|
+
const withQueryValue = (url, from, to) => {
|
|
184
|
+
if (!url.search)
|
|
185
|
+
return url;
|
|
186
|
+
const pairs = url.search
|
|
187
|
+
.slice(1)
|
|
188
|
+
.split('&')
|
|
189
|
+
.map(pair => {
|
|
190
|
+
const at = pair.indexOf('=');
|
|
191
|
+
if (at < 0)
|
|
192
|
+
return pair;
|
|
193
|
+
let value;
|
|
194
|
+
try {
|
|
195
|
+
value = decodeURIComponent(pair.slice(at + 1).replace(/\+/g, ' '));
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
return pair;
|
|
199
|
+
}
|
|
200
|
+
return value === from
|
|
201
|
+
? `${pair.slice(0, at)}=${encodeURIComponent(to)}`
|
|
202
|
+
: pair;
|
|
203
|
+
});
|
|
204
|
+
const swapped = new URL(url);
|
|
205
|
+
swapped.search = `?${pairs.join('&')}`;
|
|
206
|
+
return swapped;
|
|
207
|
+
};
|
|
208
|
+
const swapHeaders = (headers, from, to) => {
|
|
209
|
+
for (const [name, value] of [...headers]) {
|
|
210
|
+
if (value.includes(from))
|
|
211
|
+
headers.set(name, value.split(from).join(to));
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
/** The provider's gateway, from `urls.gateway`. */
|
|
215
|
+
const gatewayOf = (host) => {
|
|
216
|
+
const configured = host.provider?.urls?.gateway;
|
|
217
|
+
if (!configured)
|
|
218
|
+
return undefined;
|
|
219
|
+
try {
|
|
220
|
+
return new URL(configured);
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
/** `url`'s provider and path when it's under `base`'s path, which names the provider next. */
|
|
227
|
+
const underBase = (url, basePath) => {
|
|
228
|
+
const prefix = basePath.replace(/\/+$/, '');
|
|
229
|
+
if (!url.pathname.startsWith(`${prefix}/`))
|
|
230
|
+
return undefined;
|
|
231
|
+
const [provider = '', ...rest] = url.pathname
|
|
232
|
+
.slice(prefix.length + 1)
|
|
233
|
+
.split('/');
|
|
234
|
+
return { provider, path: `/${rest.join('/')}${url.search}` };
|
|
235
|
+
};
|
|
236
|
+
/** A call on Zite's AI key, whether the app named the provider, the `baseUrl` it was given, or the gateway itself. */
|
|
237
|
+
const gatewayCallOf = (url, headers, gateway) => {
|
|
238
|
+
const found = [...headers]
|
|
239
|
+
.map(([, value]) => GATEWAY_MARKER.exec(bare(value)))
|
|
240
|
+
.find(Boolean);
|
|
241
|
+
const marker = found
|
|
242
|
+
? { marker: found[0], connection: found[1] }
|
|
243
|
+
: { marker: undefined, connection: undefined };
|
|
244
|
+
if (url.hostname === GATEWAY_HOST) {
|
|
245
|
+
const route = underBase(url, '');
|
|
246
|
+
return route && { ...route, ...marker };
|
|
247
|
+
}
|
|
248
|
+
if (!found)
|
|
249
|
+
return undefined;
|
|
250
|
+
if (gateway && url.origin === gateway.origin) {
|
|
251
|
+
const route = underBase(url, gateway.pathname);
|
|
252
|
+
return route && { ...route, ...marker };
|
|
253
|
+
}
|
|
254
|
+
const route = AI_PROVIDER_HOSTS[url.hostname];
|
|
255
|
+
if (!route)
|
|
256
|
+
return undefined;
|
|
257
|
+
const path = url.pathname.startsWith(route.strip)
|
|
258
|
+
? url.pathname.slice(route.strip.length)
|
|
259
|
+
: url.pathname;
|
|
260
|
+
return { provider: route.provider, path: `${path}${url.search}`, ...marker };
|
|
261
|
+
};
|
|
262
|
+
/** A connection on Zite's AI key as `integrations.get` answers it, its `baseUrl` at the provider's gateway. */
|
|
263
|
+
export const withGatewayUrl = (host, answer) => {
|
|
264
|
+
const gateway = gatewayOf(host);
|
|
265
|
+
const baseUrl = answer?.baseUrl;
|
|
266
|
+
if (!gateway ||
|
|
267
|
+
typeof baseUrl !== 'string' ||
|
|
268
|
+
!answer ||
|
|
269
|
+
typeof answer !== 'object')
|
|
270
|
+
return answer;
|
|
271
|
+
let url;
|
|
272
|
+
try {
|
|
273
|
+
url = new URL(baseUrl);
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
return answer;
|
|
277
|
+
}
|
|
278
|
+
if (url.hostname !== GATEWAY_HOST)
|
|
279
|
+
return answer;
|
|
280
|
+
return {
|
|
281
|
+
...answer,
|
|
282
|
+
baseUrl: `${gateway.origin}${gateway.pathname.replace(/\/+$/, '')}${url.pathname}`,
|
|
283
|
+
};
|
|
284
|
+
};
|
|
285
|
+
/** The token to send instead of `token`, refreshed once per connection per request. */
|
|
286
|
+
const freshToken = async (host, token, connection) => {
|
|
287
|
+
const known = replacements.get(token);
|
|
288
|
+
if (known)
|
|
289
|
+
return known;
|
|
290
|
+
const refreshing = (host.refreshing ??= new Map());
|
|
291
|
+
let pending = refreshing.get(connection);
|
|
292
|
+
if (!pending) {
|
|
293
|
+
pending = (async () => {
|
|
294
|
+
const result = await refreshConnection(host, connection);
|
|
295
|
+
if (!('value' in result))
|
|
296
|
+
return undefined;
|
|
297
|
+
const fresh = result.value;
|
|
298
|
+
const previous = (host.connectionAnswers?.get(connection) ??
|
|
299
|
+
{});
|
|
300
|
+
const field = Object.keys(previous).find(key => previous[key] === token) ??
|
|
301
|
+
'accessToken';
|
|
302
|
+
const value = fresh[field];
|
|
303
|
+
rememberConnection(host, connection, fresh);
|
|
304
|
+
return typeof value === 'string' ? value : undefined;
|
|
305
|
+
})();
|
|
306
|
+
refreshing.set(connection, pending);
|
|
307
|
+
}
|
|
308
|
+
const value = await pending;
|
|
309
|
+
if (!value || value === token)
|
|
310
|
+
return undefined;
|
|
311
|
+
remember(replacements, token, value);
|
|
312
|
+
remember(refreshedTokens, value, connection);
|
|
313
|
+
refreshes += 1;
|
|
314
|
+
// As classic: the env vars that held the old token hold the new one.
|
|
315
|
+
const env = globalThis.process?.env;
|
|
316
|
+
for (const [key, held] of Object.entries(env ?? {})) {
|
|
317
|
+
if (held === token)
|
|
318
|
+
env[key] = value;
|
|
319
|
+
}
|
|
320
|
+
return value;
|
|
321
|
+
};
|
|
322
|
+
const refusal = (status, type, message) => Response.json({ error: { type, code: type, message } }, { status });
|
|
323
|
+
const gatewayUnavailable = (host) => refusal(503, 'unavailable', host.provider?.kind === 'local'
|
|
324
|
+
? "Zite's AI key needs Zite's gateway: name gateway in ZITE_URLS"
|
|
325
|
+
: "Zite's AI key needs Zite's gateway, which this request wasn't given");
|
|
326
|
+
/**
|
|
327
|
+
* A call on Zite's AI key at the gateway, the marker swapped for the request's app token. The token goes to the
|
|
328
|
+
* gateway's origin alone: the target is built from it, and a redirect is handed back rather than followed.
|
|
329
|
+
*/
|
|
330
|
+
const toGateway = async (nativeFetch, base, headers, call, gateway, token) => {
|
|
331
|
+
const target = new URL(`${gateway.origin}${gateway.pathname.replace(/\/+$/, '')}/${call.provider}${call.path}`);
|
|
332
|
+
const sent = new Headers(headers);
|
|
333
|
+
sent.delete(GATEWAY_CONNECTION_HEADER);
|
|
334
|
+
sent.delete('content-length');
|
|
335
|
+
// As for a connection's call: a Node SDK that asks for gzip inflates a body Workers already inflated.
|
|
336
|
+
sent.delete('accept-encoding');
|
|
337
|
+
if (call.marker && call.connection) {
|
|
338
|
+
swapHeaders(sent, call.marker, token);
|
|
339
|
+
sent.set(GATEWAY_CONNECTION_HEADER, call.connection);
|
|
340
|
+
}
|
|
341
|
+
// Whole, so it goes with its length and the gateway holds only what it is.
|
|
342
|
+
const body = base.body ? await base.arrayBuffer() : undefined;
|
|
343
|
+
return nativeFetch(new Request(target, {
|
|
344
|
+
method: base.method,
|
|
345
|
+
headers: sent,
|
|
346
|
+
body,
|
|
347
|
+
redirect: 'manual',
|
|
348
|
+
signal: base.signal,
|
|
349
|
+
}));
|
|
350
|
+
};
|
|
351
|
+
const cfOf = (request) => request.cf;
|
|
352
|
+
export const createOutboundFetch = (nativeFetch) => async (input, init) => {
|
|
353
|
+
const host = getHost();
|
|
354
|
+
if (!host || isPlatformRequest(input))
|
|
355
|
+
return nativeFetch(input, init);
|
|
356
|
+
let url;
|
|
357
|
+
try {
|
|
358
|
+
url = new URL(input instanceof Request ? input.url : input);
|
|
359
|
+
}
|
|
360
|
+
catch {
|
|
361
|
+
return nativeFetch(input, init);
|
|
362
|
+
}
|
|
363
|
+
const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined));
|
|
364
|
+
if (!headers.has('user-agent'))
|
|
365
|
+
headers.set('user-agent', DEFAULT_USER_AGENT);
|
|
366
|
+
const method = (init?.method ?? (input instanceof Request ? input.method : 'GET')).toUpperCase();
|
|
367
|
+
const gateway = gatewayOf(host);
|
|
368
|
+
const gatewayCall = gatewayCallOf(url, headers, gateway);
|
|
369
|
+
const found = gatewayCall
|
|
370
|
+
? undefined
|
|
371
|
+
: carried(headers, url, tokensOf(host));
|
|
372
|
+
const startedAt = Date.now();
|
|
373
|
+
const sentBody = bodyText(init?.body);
|
|
374
|
+
const sentHeaderSecrets = headerSecrets(headers);
|
|
375
|
+
const record = (outcome) => {
|
|
376
|
+
const fetches = (host.fetches ??= []);
|
|
377
|
+
if (fetches.length >= MAX_FETCHES)
|
|
378
|
+
return undefined;
|
|
379
|
+
const connection = gatewayCall?.connection ?? found?.connection;
|
|
380
|
+
const secrets = [...sentHeaderSecrets, ...secretsOf(host)].sort((a, b) => b.length - a.length);
|
|
381
|
+
const bodyRoom = Math.min(MAX_BODY_CHARS, MAX_LOGGED_CHARS - (host.fetchLogChars ?? 0));
|
|
382
|
+
const requestBody = sentBody !== undefined && bodyRoom > 0
|
|
383
|
+
? loggable(sentBody, secrets, bodyRoom)
|
|
384
|
+
: undefined;
|
|
385
|
+
if (requestBody)
|
|
386
|
+
host.fetchLogChars = (host.fetchLogChars ?? 0) + requestBody.length;
|
|
387
|
+
const entry = {
|
|
388
|
+
at: startedAt,
|
|
389
|
+
method,
|
|
390
|
+
url: loggable(redactedUrl(url, secrets), secrets, MAX_URL_CHARS),
|
|
391
|
+
durationMs: Date.now() - startedAt,
|
|
392
|
+
...(requestBody !== undefined && { requestBody }),
|
|
393
|
+
...(outcome.status !== undefined && { status: outcome.status }),
|
|
394
|
+
...(outcome.error !== undefined && {
|
|
395
|
+
error: loggable(outcome.error instanceof Error
|
|
396
|
+
? outcome.error.message
|
|
397
|
+
: String(outcome.error), secrets, MAX_ERROR_CHARS),
|
|
398
|
+
}),
|
|
399
|
+
...(connection && { connection }),
|
|
400
|
+
...(gatewayCall && { ziteAi: true }),
|
|
401
|
+
...(outcome.retried && { retried: true }),
|
|
402
|
+
};
|
|
403
|
+
fetches.push(entry);
|
|
404
|
+
return entry;
|
|
405
|
+
};
|
|
406
|
+
if (!gatewayCall && !found) {
|
|
407
|
+
try {
|
|
408
|
+
// The app's own call, `cf` and all; only the headers are ours.
|
|
409
|
+
const response = await nativeFetch(input, { ...init, headers });
|
|
410
|
+
record({ status: response.status });
|
|
411
|
+
return response;
|
|
412
|
+
}
|
|
413
|
+
catch (error) {
|
|
414
|
+
record({ error });
|
|
415
|
+
throw error;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
// An org's own AI key, which classic reads usage from for analytics.
|
|
419
|
+
const usageProvider = found ? AI_USAGE_HOSTS[url.hostname] : undefined;
|
|
420
|
+
const usageBody = usageProvider
|
|
421
|
+
? withStreamUsage(url, method, init?.body)
|
|
422
|
+
: undefined;
|
|
423
|
+
if (usageBody !== undefined)
|
|
424
|
+
headers.delete('content-length');
|
|
425
|
+
const base = new Request(input, usageBody === undefined ? init : { ...init, body: usageBody });
|
|
426
|
+
if (gatewayCall) {
|
|
427
|
+
try {
|
|
428
|
+
// As the gateway and the host refuse it: a demo has no AI on Zite's key.
|
|
429
|
+
if (host.mode === 'demo') {
|
|
430
|
+
host.demoRefused = true;
|
|
431
|
+
const refused = refusal(403, 'permission_denied', DEMO_UNAVAILABLE_MESSAGE);
|
|
432
|
+
record({ status: refused.status });
|
|
433
|
+
return refused;
|
|
434
|
+
}
|
|
435
|
+
const access = gateway ? await directAccess(host) : undefined;
|
|
436
|
+
if (gateway && access) {
|
|
437
|
+
const response = await toGateway(nativeFetch, base, headers, gatewayCall, gateway, access.token);
|
|
438
|
+
record({ status: response.status });
|
|
439
|
+
return response;
|
|
440
|
+
}
|
|
441
|
+
const refused = gatewayUnavailable(host);
|
|
442
|
+
record({ status: refused.status });
|
|
443
|
+
return refused;
|
|
444
|
+
}
|
|
445
|
+
catch (error) {
|
|
446
|
+
record({ error });
|
|
447
|
+
throw error;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
// As classic: Node SDKs ask for gzip and inflate it themselves, which fails on the body Workers already inflated.
|
|
451
|
+
if (found)
|
|
452
|
+
headers.delete('accept-encoding');
|
|
453
|
+
const outgoing = new Request(base, { headers });
|
|
454
|
+
const retry = found ? outgoing.clone() : undefined;
|
|
455
|
+
try {
|
|
456
|
+
let response = await nativeFetch(outgoing);
|
|
457
|
+
let retried = false;
|
|
458
|
+
if (response.status === 401 && retry && found) {
|
|
459
|
+
const fresh = await freshToken(host, found.token, found.connection);
|
|
460
|
+
if (fresh) {
|
|
461
|
+
const retryHeaders = new Headers(retry.headers);
|
|
462
|
+
swapHeaders(retryHeaders, found.token, fresh);
|
|
463
|
+
await response.body?.cancel();
|
|
464
|
+
response = await nativeFetch(new Request(withQueryValue(url, found.token, fresh), {
|
|
465
|
+
method: retry.method,
|
|
466
|
+
headers: retryHeaders,
|
|
467
|
+
body: retry.body,
|
|
468
|
+
redirect: retry.redirect,
|
|
469
|
+
signal: retry.signal,
|
|
470
|
+
...(retry.body && { duplex: 'half' }),
|
|
471
|
+
...(cfOf(retry) !== undefined && { cf: cfOf(retry) }),
|
|
472
|
+
}));
|
|
473
|
+
retried = true;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (!retried)
|
|
477
|
+
await retry?.body?.cancel();
|
|
478
|
+
if (usageProvider) {
|
|
479
|
+
const metered = meterAiResponse(usageProvider, response, {
|
|
480
|
+
url,
|
|
481
|
+
body: init?.body,
|
|
482
|
+
});
|
|
483
|
+
response = metered.response;
|
|
484
|
+
const entry = record({ status: response.status, retried });
|
|
485
|
+
const used = metered.usage.then(usage => {
|
|
486
|
+
if (usage && entry)
|
|
487
|
+
entry.ai = usage;
|
|
488
|
+
});
|
|
489
|
+
(host.pending ??= []).push(settledWithin(used, USAGE_WAIT_MS));
|
|
490
|
+
return response;
|
|
491
|
+
}
|
|
492
|
+
record({ status: response.status, retried });
|
|
493
|
+
return response;
|
|
494
|
+
}
|
|
495
|
+
catch (error) {
|
|
496
|
+
await retry?.body?.cancel().catch(() => { });
|
|
497
|
+
record({ error });
|
|
498
|
+
throw error;
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
// Keyed on globalThis so two copies of zitejs in one bundle wrap fetch once.
|
|
502
|
+
const WATCHED_KEY = Symbol.for('zitejs:outbound-fetch');
|
|
503
|
+
/** Wraps the global fetch once. Next patches fetch for the same reason: the run log must hear of each. */
|
|
504
|
+
export const watchOutboundFetches = () => {
|
|
505
|
+
const marks = globalThis;
|
|
506
|
+
if (marks[WATCHED_KEY])
|
|
507
|
+
return;
|
|
508
|
+
marks[WATCHED_KEY] = true;
|
|
509
|
+
globalThis.fetch = createOutboundFetch(globalThis.fetch.bind(globalThis));
|
|
510
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const REDACTED = "REDACTED";
|
|
2
|
+
/**
|
|
3
|
+
* Replace any credentials in `text` with a placeholder, leaving the rest
|
|
4
|
+
* intact. Returns the input unchanged when there is nothing to redact, so
|
|
5
|
+
* callers that pass clean text see byte-identical output.
|
|
6
|
+
*/
|
|
7
|
+
export declare function redactSecrets(text: string): string;
|
|
8
|
+
/** The ways a secret is written into text, longest first: as it is, URL-encoded in either case, form-encoded, JSON-escaped. */
|
|
9
|
+
export declare function secretForms(value: string): string[];
|
|
10
|
+
/** `text` with each of `values`, however it was written, replaced. `values` longest first, so none is left half-done. */
|
|
11
|
+
export declare function replaceKnown(text: string, values: readonly string[]): string;
|
|
12
|
+
/** `text` with each of `values` replaced, as `replaceKnown` does, then anything the patterns above find. */
|
|
13
|
+
export declare function redactKnown(text: string, values: readonly string[]): string;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// Ported from restly's shared/src/redactSecrets.ts, so a live Start app redacts
|
|
2
|
+
// exactly what a classic one does. Keep the two in step.
|
|
3
|
+
export const REDACTED = 'REDACTED';
|
|
4
|
+
/**
|
|
5
|
+
* A run of characters that can plausibly be a secret's value. Stops at
|
|
6
|
+
* whitespace and at the punctuation that normally *ends* a value in a sentence
|
|
7
|
+
* or a serialized payload, so the redaction does not swallow the rest of the
|
|
8
|
+
* text after it.
|
|
9
|
+
*/
|
|
10
|
+
const VALUE_RUN = String.raw `[^\s,;)\]}"'<>]+`;
|
|
11
|
+
const CREDENTIAL_KEY = String.raw `(?:password|passwd|secret|api[_-]?key|apikey|access[_-]?token|refresh[_-]?token|auth[_-]?token|client[_-]?secret|private[_-]?key)`;
|
|
12
|
+
// The scheme is length-capped because, unbounded, every position in a long
|
|
13
|
+
// alphanumeric run (hex, a base64 blob) rescans to the end of the run —
|
|
14
|
+
// quadratic, and minutes of blocked event loop on a megabyte of output.
|
|
15
|
+
const URL_USERINFO = String.raw `([a-z][a-z0-9+.-]{0,31}:\/\/[^\s:/@]+:)`;
|
|
16
|
+
const JSON_MEMBER = String.raw `("${CREDENTIAL_KEY}"\s*:\s*")`;
|
|
17
|
+
const JSON_VALUE = String.raw `(?:[^"\\]|\\.)*`;
|
|
18
|
+
const ESCAPED_JSON_MEMBER = String.raw `(\\"${CREDENTIAL_KEY}\\"\s*:\s*\\")`;
|
|
19
|
+
const ESCAPED_JSON_VALUE = String.raw `(?:[^"\\]|\\\\(?:\\["\\]|[^"\\]))*`;
|
|
20
|
+
const PATTERNS = [
|
|
21
|
+
{
|
|
22
|
+
// URL userinfo: scheme://user:password@host. Keeps the scheme, the user,
|
|
23
|
+
// and the host — the parts that identify *which* connection failed.
|
|
24
|
+
pattern: new RegExp(URL_USERINFO + String.raw `[^\s@/]+(@)`, 'gi'),
|
|
25
|
+
replace: `$1${REDACTED}$2`,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
// Bearer tokens. RFC 6750 `token68` permits a single character, so a length
|
|
29
|
+
// floor lets short opaque tokens through. Same shape guard as Basic below:
|
|
30
|
+
// reject a value that is one alphabetic word, so "Bearer token required"
|
|
31
|
+
// survives while anything mixing case or digits is redacted. Case-sensitive
|
|
32
|
+
// for the same reason as Basic, so the scheme is spelled out.
|
|
33
|
+
//
|
|
34
|
+
// `Token` is deliberately not treated as a scheme: it is a GitHub-ism
|
|
35
|
+
// rather than a registered one, and "Token" is a common enough English word
|
|
36
|
+
// that it matched the next word in prose. The credentials it precedes are
|
|
37
|
+
// already covered by the `gh*_` prefixes below.
|
|
38
|
+
pattern: new RegExp(String.raw `\b([Bb]earer)\s+(?![A-Za-z][a-z]*(?![A-Za-z0-9._~+/=-]))([A-Za-z0-9._~+/=-]+)`, 'g'),
|
|
39
|
+
replace: `$1 ${REDACTED}`,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
// Basic credentials are base64 of "user:pass" and can be legitimately
|
|
43
|
+
// short — base64("u:pw") is four characters — so the 16-char floor used for
|
|
44
|
+
// Bearer would let real credentials through.
|
|
45
|
+
//
|
|
46
|
+
// Length alone therefore cannot separate a credential from prose, and
|
|
47
|
+
// "Basic plan" / "Basic tier" / "Basic Auth" are exactly the kind of copy a
|
|
48
|
+
// subscription app writes. The guard is shape instead: reject the value if
|
|
49
|
+
// it is a single alphabetic word (one letter followed by lowercase to the
|
|
50
|
+
// end of the token). Base64 of any realistic "user:pass" mixes case or
|
|
51
|
+
// digits and so survives the guard, while an English word does not.
|
|
52
|
+
//
|
|
53
|
+
// Case-sensitive by necessity — an `i` flag would make `[a-z]` match
|
|
54
|
+
// uppercase and collapse that distinction — so the scheme is spelled out
|
|
55
|
+
// to still accept the lowercase form.
|
|
56
|
+
pattern: new RegExp(String.raw `\b([Bb]asic)\s+(?![A-Za-z][a-z]*(?![A-Za-z0-9+/=]))([A-Za-z0-9+/=]{4,})`, 'g'),
|
|
57
|
+
replace: `$1 ${REDACTED}`,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
// JWTs, which carry claims and are frequently the credential itself. The
|
|
61
|
+
// header is capped for the same reason as the scheme above (a run of
|
|
62
|
+
// `-eyJ` fragments restarts at each one); a JWT has to fit in an HTTP
|
|
63
|
+
// header, so 8KB loses nothing real.
|
|
64
|
+
pattern: /\beyJ[A-Za-z0-9_-]{8,8192}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]+/g,
|
|
65
|
+
replace: REDACTED,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
// Provider secret keys, matched on each vendor's published prefix.
|
|
69
|
+
// OpenAI/Anthropic `sk-`, Stripe `sk_live_`/`sk_test_`/`rk_live_`.
|
|
70
|
+
// Stripe's publishable `pk_` keys are deliberately absent: they are
|
|
71
|
+
// designed to ship to browsers, so redacting them only loses detail.
|
|
72
|
+
pattern: /\b(?:sk-(?:ant-)?|sk_live_|sk_test_|rk_live_)[A-Za-z0-9_-]{16,}/g,
|
|
73
|
+
replace: REDACTED,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
// AWS access key ids (AKIA long-lived, ASIA temporary) and Google API keys.
|
|
77
|
+
// Google's are documented as AIza + 35 chars; the open-ended quantifier
|
|
78
|
+
// means an unexpectedly long variant is redacted whole rather than having
|
|
79
|
+
// its first 39 characters replaced and the remainder left exposed.
|
|
80
|
+
pattern: /\b(?:A[KS]IA[0-9A-Z]{16}\b|AIza[0-9A-Za-z_-]{35,})/g,
|
|
81
|
+
replace: REDACTED,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
// GitHub (`ghp_`, `gho_`, `ghu_`, `ghs_`, `ghr_`) and Slack (`xoxb-` etc).
|
|
85
|
+
pattern: /\b(?:gh[pousr]_[A-Za-z0-9]{20,}|xox[abprs]-[A-Za-z0-9-]{10,})\b/g,
|
|
86
|
+
replace: REDACTED,
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
// Credential-bearing key/value pairs, in query strings, connection strings
|
|
90
|
+
// and serialized config alike. Anchored on the key name plus its separator,
|
|
91
|
+
// and the key must be a whole token so an app's "reset_password_url=..."
|
|
92
|
+
// style key is not mistaken for the secret itself.
|
|
93
|
+
//
|
|
94
|
+
// The leading boundary is a captured alternation rather than a lookbehind:
|
|
95
|
+
// this module is exported from @fillout/shared and so can be bundled into
|
|
96
|
+
// the frontend, where an unsupported lookbehind would throw while building
|
|
97
|
+
// the RegExp at module load and take the whole bundle down with it.
|
|
98
|
+
pattern: new RegExp(String.raw `(^|[^\w-])(${CREDENTIAL_KEY})(\s*[:=]\s*)` + VALUE_RUN, 'gi'),
|
|
99
|
+
replace: `$1$2$3${REDACTED}`,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
// The same keys as JSON string members. The closing quote after the key
|
|
103
|
+
// sits between it and the colon, so the pattern above never sees them.
|
|
104
|
+
pattern: new RegExp(JSON_MEMBER + JSON_VALUE + '"', 'gi'),
|
|
105
|
+
replace: `$1${REDACTED}"`,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
// ...and as members of JSON serialized into another JSON string, where
|
|
109
|
+
// every quote arrives as \" and the value's own escapes are doubled, so a
|
|
110
|
+
// \\\" inside the value is an escaped quote rather than its end.
|
|
111
|
+
pattern: new RegExp(ESCAPED_JSON_MEMBER + ESCAPED_JSON_VALUE + String.raw `\\"`, 'gi'),
|
|
112
|
+
replace: `$1${REDACTED}\\"`,
|
|
113
|
+
},
|
|
114
|
+
];
|
|
115
|
+
/**
|
|
116
|
+
* Replace any credentials in `text` with a placeholder, leaving the rest
|
|
117
|
+
* intact. Returns the input unchanged when there is nothing to redact, so
|
|
118
|
+
* callers that pass clean text see byte-identical output.
|
|
119
|
+
*/
|
|
120
|
+
export function redactSecrets(text) {
|
|
121
|
+
if (!text)
|
|
122
|
+
return text;
|
|
123
|
+
let result = text;
|
|
124
|
+
for (const { pattern, replace } of PATTERNS) {
|
|
125
|
+
// The patterns are global, so reset lastIndex — these RegExp objects are
|
|
126
|
+
// module-level and reused across calls.
|
|
127
|
+
pattern.lastIndex = 0;
|
|
128
|
+
result = result.replace(pattern, replace);
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
/** The ways a secret is written into text, longest first: as it is, URL-encoded in either case, form-encoded, JSON-escaped. */
|
|
133
|
+
export function secretForms(value) {
|
|
134
|
+
const lower = (text) => text.replace(/%[0-9A-F]{2}/g, hex => hex.toLowerCase());
|
|
135
|
+
const encoded = encodeURIComponent(value);
|
|
136
|
+
const form = new URLSearchParams({ v: value }).toString().slice(2);
|
|
137
|
+
const json = JSON.stringify(value).slice(1, -1);
|
|
138
|
+
return [
|
|
139
|
+
...new Set([value, encoded, lower(encoded), form, lower(form), json]),
|
|
140
|
+
].sort((a, b) => b.length - a.length);
|
|
141
|
+
}
|
|
142
|
+
/** `text` with each of `values`, however it was written, replaced. `values` longest first, so none is left half-done. */
|
|
143
|
+
export function replaceKnown(text, values) {
|
|
144
|
+
let result = text;
|
|
145
|
+
for (const value of values) {
|
|
146
|
+
for (const form of secretForms(value)) {
|
|
147
|
+
if (result.includes(form))
|
|
148
|
+
result = result.split(form).join(REDACTED);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
/** `text` with each of `values` replaced, as `replaceKnown` does, then anything the patterns above find. */
|
|
154
|
+
export function redactKnown(text, values) {
|
|
155
|
+
return redactSecrets(replaceKnown(text, values));
|
|
156
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|