zitejs 0.9.153 → 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.js +42 -42
- package/dist/cjs/integrations/rules.test.js +60 -55
- 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 +22 -22
- package/dist/cjs/runtime/index.js +28 -28
- package/dist/cjs/runtime/index.test.js +34 -34
- package/dist/cjs/runtime/sendEmailParamsTypes.test-d.js +29 -29
- 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 +651 -665
- 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.js +42 -42
- package/dist/esm/integrations/rules.test.js +62 -57
- 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 +22 -22
- package/dist/esm/runtime/index.js +31 -31
- package/dist/esm/runtime/index.test.js +36 -36
- package/dist/esm/runtime/sendEmailParamsTypes.test-d.js +30 -30
- 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 +655 -669
- 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,83 @@
|
|
|
1
|
+
import * as z from 'zod/mini';
|
|
2
|
+
import { type IdentityKeySource } from './keys.js';
|
|
3
|
+
/** The `typ` every identity token carries in its header, and nothing else does. */
|
|
4
|
+
export declare const IDENTITY_TOKEN_TYPE = "zite-id+jwt";
|
|
5
|
+
export declare const DEFAULT_MAX_LIFETIME_S = 300;
|
|
6
|
+
declare const MODES: readonly ["live", "preview", "demo", "dev"];
|
|
7
|
+
export type IdentityMode = (typeof MODES)[number];
|
|
8
|
+
declare const identityClaims: z.ZodMiniObject<{
|
|
9
|
+
iss: z.ZodMiniString<string>;
|
|
10
|
+
sub: z.ZodMiniString<string>;
|
|
11
|
+
aud: z.ZodMiniString<string>;
|
|
12
|
+
azp: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
13
|
+
iat: z.ZodMiniInt;
|
|
14
|
+
exp: z.ZodMiniInt;
|
|
15
|
+
sid: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
16
|
+
nonce: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
17
|
+
email: z.ZodMiniString<string>;
|
|
18
|
+
name: z.ZodMiniString<string>;
|
|
19
|
+
firstName: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
20
|
+
lastName: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
21
|
+
roles: z.ZodMiniArray<z.ZodMiniString<string>>;
|
|
22
|
+
isInternal: z.ZodMiniBoolean<boolean>;
|
|
23
|
+
mode: z.ZodMiniEnum<{
|
|
24
|
+
live: "live";
|
|
25
|
+
preview: "preview";
|
|
26
|
+
demo: "demo";
|
|
27
|
+
dev: "dev";
|
|
28
|
+
}>;
|
|
29
|
+
ver: z.ZodMiniNullable<z.ZodMiniInt>;
|
|
30
|
+
preview: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
31
|
+
build: z.ZodMiniInt;
|
|
32
|
+
editor: z.ZodMiniString<string>;
|
|
33
|
+
}, z.core.$strip>>;
|
|
34
|
+
}, z.core.$strip>;
|
|
35
|
+
/** An identity token's claims, as the identity server signs them. */
|
|
36
|
+
export type IdentityClaims = z.infer<typeof identityClaims>;
|
|
37
|
+
/** Why a token was refused: jose's error code and the claim it names, or the schema's path for a claim of Zite's. */
|
|
38
|
+
export type Refusal = {
|
|
39
|
+
code: string;
|
|
40
|
+
claim?: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* `expired` and `stale` (issued under another org settings version) are genuine and renewable; `refused` is not and
|
|
44
|
+
* clears the cookie.
|
|
45
|
+
*/
|
|
46
|
+
export type Verdict = {
|
|
47
|
+
status: 'valid' | 'expired' | 'stale';
|
|
48
|
+
claims: IdentityClaims;
|
|
49
|
+
} | {
|
|
50
|
+
status: 'refused';
|
|
51
|
+
reason: Refusal;
|
|
52
|
+
kid?: string;
|
|
53
|
+
};
|
|
54
|
+
export type VerifyExpectations = {
|
|
55
|
+
/** Computed from where the request was served, never read from the token. */
|
|
56
|
+
issuer: string;
|
|
57
|
+
/** `<app>:<mode>`, from routing. */
|
|
58
|
+
clientId: string;
|
|
59
|
+
/** The version the identity must carry, or `any` where it can't be known (off Zite). */
|
|
60
|
+
ver: number | null | 'any';
|
|
61
|
+
/** A snapshot host pinned to one build. */
|
|
62
|
+
previewBuild?: number;
|
|
63
|
+
/** The nonce the sign-in sent, on the callback only. */
|
|
64
|
+
nonce?: string;
|
|
65
|
+
/** The longest `exp - iat` accepted. Identities are issued for 60 s; this keeps a mis-set option from minting days. */
|
|
66
|
+
maxLifetimeS?: number;
|
|
67
|
+
/** Milliseconds since the epoch. */
|
|
68
|
+
now?: number;
|
|
69
|
+
};
|
|
70
|
+
export type RefusalReport = {
|
|
71
|
+
reason: Refusal;
|
|
72
|
+
kid?: string;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Verifies identity tokens against `keys`, the header's `alg` `EdDSA` or RFC 9864's `Ed25519`. A `kid` fetched keys
|
|
76
|
+
* don't know triggers a refetch, at most once a minute. Each refusal is reported to `onRefusal`, by default logged once
|
|
77
|
+
* per reason and key id.
|
|
78
|
+
*/
|
|
79
|
+
export declare const createIdentityVerifier: (keys: IdentityKeySource, options?: {
|
|
80
|
+
onRefusal?: (report: RefusalReport) => void;
|
|
81
|
+
}) => (token: string, expect: VerifyExpectations) => Promise<Verdict>;
|
|
82
|
+
export type IdentityVerifier = ReturnType<typeof createIdentityVerifier>;
|
|
83
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// The identity token's verifier (T5 design §6.1), for the dispatcher, the front and the module off Zite. jose checks the
|
|
2
|
+
// signature, alg, typ, iss, aud and times; the schema and the rules after it are Zite's.
|
|
3
|
+
import { decodeProtectedHeader, errors, jwtVerify } from 'jose';
|
|
4
|
+
import * as z from 'zod/mini';
|
|
5
|
+
import { canonicalBytes } from './encoding.js';
|
|
6
|
+
import { ED25519_ALGS } from './keys.js';
|
|
7
|
+
/** The `typ` every identity token carries in its header, and nothing else does. */
|
|
8
|
+
export const IDENTITY_TOKEN_TYPE = 'zite-id+jwt';
|
|
9
|
+
export const DEFAULT_MAX_LIFETIME_S = 300;
|
|
10
|
+
const CLOCK_SKEW_S = 5;
|
|
11
|
+
const MAX_TOKEN_LENGTH = 8192;
|
|
12
|
+
const MAX_ROLES = 32;
|
|
13
|
+
const MODES = ['live', 'preview', 'demo', 'dev'];
|
|
14
|
+
const text = (max) => z.string().check(z.maxLength(max));
|
|
15
|
+
const id = (max) => z.string().check(z.minLength(1), z.maxLength(max));
|
|
16
|
+
const identityClaims = z.object({
|
|
17
|
+
/** `https://<host>/auth`: the origin the identity was issued on. */
|
|
18
|
+
iss: z.string(),
|
|
19
|
+
/** The `zite_user` id. */
|
|
20
|
+
sub: id(255),
|
|
21
|
+
/** `<app>:<mode>`. jose would take an array. */
|
|
22
|
+
aud: z.string(),
|
|
23
|
+
azp: z.optional(z.string()),
|
|
24
|
+
iat: z.int(),
|
|
25
|
+
exp: z.int(),
|
|
26
|
+
sid: z.optional(text(255)),
|
|
27
|
+
nonce: z.optional(text(255)),
|
|
28
|
+
email: text(320),
|
|
29
|
+
name: text(200),
|
|
30
|
+
firstName: z.optional(text(200)),
|
|
31
|
+
lastName: z.optional(text(200)),
|
|
32
|
+
/** Role ids. */
|
|
33
|
+
roles: z.array(text(128)).check(z.maxLength(MAX_ROLES)),
|
|
34
|
+
isInternal: z.boolean(),
|
|
35
|
+
mode: z.enum(MODES),
|
|
36
|
+
/** The org settings version it was issued under. */
|
|
37
|
+
ver: z.nullable(z.int().check(z.gte(0))),
|
|
38
|
+
/** On previews: the build, and the editor impersonating `sub`. */
|
|
39
|
+
preview: z.optional(z.object({ build: z.int().check(z.gte(0)), editor: id(128) })),
|
|
40
|
+
});
|
|
41
|
+
const claimRefused = (claim) => ({
|
|
42
|
+
code: errors.JWTClaimValidationFailed.code,
|
|
43
|
+
claim,
|
|
44
|
+
});
|
|
45
|
+
const refusalOf = (error) => {
|
|
46
|
+
if (error instanceof errors.JWTClaimValidationFailed)
|
|
47
|
+
return { code: error.code, claim: error.claim };
|
|
48
|
+
if (error instanceof errors.JOSEError)
|
|
49
|
+
return { code: error.code };
|
|
50
|
+
// The key source had no keys to look in: none fetched, or a set its rules refused.
|
|
51
|
+
return { code: errors.JWKSNoMatchingKey.code };
|
|
52
|
+
};
|
|
53
|
+
const rulesRefusal = (claims, expect) => {
|
|
54
|
+
if (claims.azp !== undefined && claims.azp !== claims.aud)
|
|
55
|
+
return claimRefused('azp');
|
|
56
|
+
if (claims.exp <= claims.iat ||
|
|
57
|
+
claims.exp - claims.iat > (expect.maxLifetimeS ?? DEFAULT_MAX_LIFETIME_S))
|
|
58
|
+
return claimRefused('exp');
|
|
59
|
+
if (!expect.clientId.endsWith(`:${claims.mode}`))
|
|
60
|
+
return claimRefused('mode');
|
|
61
|
+
const previewOk = claims.mode === 'preview'
|
|
62
|
+
? claims.preview !== undefined &&
|
|
63
|
+
(expect.previewBuild === undefined ||
|
|
64
|
+
claims.preview.build === expect.previewBuild)
|
|
65
|
+
: claims.preview === undefined;
|
|
66
|
+
if (!previewOk)
|
|
67
|
+
return claimRefused('preview');
|
|
68
|
+
if (expect.nonce !== undefined && claims.nonce !== expect.nonce)
|
|
69
|
+
return claimRefused('nonce');
|
|
70
|
+
return undefined;
|
|
71
|
+
};
|
|
72
|
+
const kidOf = (token) => {
|
|
73
|
+
try {
|
|
74
|
+
const { kid } = decodeProtectedHeader(token);
|
|
75
|
+
return typeof kid === 'string' ? kid.slice(0, 64) : undefined;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
// Reported once per refusal and key id, and only so many: both come from the caller.
|
|
82
|
+
const MAX_REPORTED = 64;
|
|
83
|
+
const reported = new Set();
|
|
84
|
+
const reportOnce = ({ reason, kid }) => {
|
|
85
|
+
const key = `${reason.code} ${reason.claim ?? ''} ${kid ?? ''}`;
|
|
86
|
+
if (reported.has(key) || reported.size >= MAX_REPORTED)
|
|
87
|
+
return;
|
|
88
|
+
reported.add(key);
|
|
89
|
+
console.warn(`[zite] refused an identity token: ${reason.code}${reason.claim ? ` (${reason.claim})` : ''}${kid ? ` (kid ${kid})` : ''}`);
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Verifies identity tokens against `keys`, the header's `alg` `EdDSA` or RFC 9864's `Ed25519`. A `kid` fetched keys
|
|
93
|
+
* don't know triggers a refetch, at most once a minute. Each refusal is reported to `onRefusal`, by default logged once
|
|
94
|
+
* per reason and key id.
|
|
95
|
+
*/
|
|
96
|
+
export const createIdentityVerifier = (keys, options = {}) => async (token, expect) => {
|
|
97
|
+
const refuse = (reason) => {
|
|
98
|
+
const kid = kidOf(token);
|
|
99
|
+
(options.onRefusal ?? reportOnce)({
|
|
100
|
+
reason,
|
|
101
|
+
...(kid !== undefined && { kid }),
|
|
102
|
+
});
|
|
103
|
+
return { status: 'refused', reason, ...(kid !== undefined && { kid }) };
|
|
104
|
+
};
|
|
105
|
+
if (token.length > MAX_TOKEN_LENGTH ||
|
|
106
|
+
!canonicalBytes(token.slice(token.lastIndexOf('.') + 1))) {
|
|
107
|
+
return refuse({ code: errors.JWSInvalid.code });
|
|
108
|
+
}
|
|
109
|
+
let payload;
|
|
110
|
+
let expired = false;
|
|
111
|
+
try {
|
|
112
|
+
({ payload } = await jwtVerify(token, keys, {
|
|
113
|
+
algorithms: [...ED25519_ALGS],
|
|
114
|
+
typ: IDENTITY_TOKEN_TYPE,
|
|
115
|
+
issuer: expect.issuer,
|
|
116
|
+
audience: expect.clientId,
|
|
117
|
+
// For jose's check of an `iat` in the future; the lifetime rule below refuses one too old.
|
|
118
|
+
maxTokenAge: expect.maxLifetimeS ?? DEFAULT_MAX_LIFETIME_S,
|
|
119
|
+
clockTolerance: CLOCK_SKEW_S,
|
|
120
|
+
currentDate: new Date(expect.now ?? Date.now()),
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
if (!(error instanceof errors.JWTExpired))
|
|
125
|
+
return refuse(refusalOf(error));
|
|
126
|
+
// jose checked everything before `exp`; the rules below still hold a lapsed identity to the rest.
|
|
127
|
+
({ payload } = error);
|
|
128
|
+
expired = true;
|
|
129
|
+
}
|
|
130
|
+
const parsed = identityClaims.safeParse(payload);
|
|
131
|
+
if (!parsed.success)
|
|
132
|
+
return refuse(claimRefused(parsed.error.issues[0]?.path.map(String).join('.') ?? ''));
|
|
133
|
+
const claims = parsed.data;
|
|
134
|
+
const broken = rulesRefusal(claims, expect);
|
|
135
|
+
if (broken)
|
|
136
|
+
return refuse(broken);
|
|
137
|
+
if (expired)
|
|
138
|
+
return { status: 'expired', claims };
|
|
139
|
+
if (expect.ver !== 'any' && claims.ver !== expect.ver)
|
|
140
|
+
return { status: 'stale', claims };
|
|
141
|
+
return { status: 'valid', claims };
|
|
142
|
+
};
|
package/dist/esm/sourceRoots.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { existsSync, readdirSync } from
|
|
2
|
-
import { basename, dirname, join, resolve } from
|
|
1
|
+
import { existsSync, readdirSync } from 'fs';
|
|
2
|
+
import { basename, dirname, join, resolve } from 'path';
|
|
3
3
|
/**
|
|
4
4
|
* The repo-root directories a project's own source lives under: `apps/` for
|
|
5
5
|
* apps and `automations/` for automations (endpoints with no frontend). The
|
|
6
6
|
* backend keeps the same list; a dir name is unique across both roots, so a
|
|
7
7
|
* bare name still identifies one dir.
|
|
8
8
|
*/
|
|
9
|
-
export const SOURCE_ROOTS = [
|
|
9
|
+
export const SOURCE_ROOTS = ['apps', 'automations'];
|
|
10
10
|
/** Every source dir under every root, in root order then name order. */
|
|
11
|
-
export function listSourceDirs(cwd =
|
|
11
|
+
export function listSourceDirs(cwd = '.') {
|
|
12
12
|
const dirs = [];
|
|
13
13
|
for (const root of SOURCE_ROOTS) {
|
|
14
14
|
const rootPath = join(cwd, root);
|
|
@@ -28,10 +28,10 @@ export function listSourceDirs(cwd = ".") {
|
|
|
28
28
|
* a config of its own but no source root under it, so it never matches.
|
|
29
29
|
* Undefined outside a monorepo (a single-app project runs where it is).
|
|
30
30
|
*/
|
|
31
|
-
export function findWorkspaceRoot(cwd =
|
|
31
|
+
export function findWorkspaceRoot(cwd = '.') {
|
|
32
32
|
for (let dir = resolve(cwd);; dir = dirname(dir)) {
|
|
33
|
-
if (existsSync(join(dir,
|
|
34
|
-
SOURCE_ROOTS.some(
|
|
33
|
+
if (existsSync(join(dir, 'zite.config.json')) &&
|
|
34
|
+
SOURCE_ROOTS.some(root => existsSync(join(dir, root)))) {
|
|
35
35
|
return dir;
|
|
36
36
|
}
|
|
37
37
|
if (dirname(dir) === dir)
|
|
@@ -39,16 +39,16 @@ export function findWorkspaceRoot(cwd = ".") {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
/** The source dir with this bare name, under whichever root holds it. */
|
|
42
|
-
export function findSourceDir(name, cwd =
|
|
43
|
-
return listSourceDirs(cwd).find(
|
|
42
|
+
export function findSourceDir(name, cwd = '.') {
|
|
43
|
+
return listSourceDirs(cwd).find(d => d.dir === name);
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
46
|
* An automation is one workflow: its single endpoint is `src/index.ts` and
|
|
47
47
|
* its name is fixed, so nothing about an automation is keyed on a file name
|
|
48
48
|
* the way an app's `src/api/<name>.ts` endpoints are.
|
|
49
49
|
*/
|
|
50
|
-
export const AUTOMATION_ENDPOINT_NAME =
|
|
51
|
-
export const AUTOMATION_ENTRY_FILE =
|
|
50
|
+
export const AUTOMATION_ENDPOINT_NAME = 'index';
|
|
51
|
+
export const AUTOMATION_ENTRY_FILE = 'src/index.ts';
|
|
52
52
|
/** The root a source dir sits under, read from its parent directory. */
|
|
53
53
|
export function sourceRootOf(sourceDirPath) {
|
|
54
54
|
const parent = basename(dirname(resolve(sourceDirPath)));
|
|
@@ -58,21 +58,21 @@ export function sourceRootOf(sourceDirPath) {
|
|
|
58
58
|
}
|
|
59
59
|
/** An endpoint's entry file, relative to the source dir. */
|
|
60
60
|
export function endpointEntryFile(root, name) {
|
|
61
|
-
return root ===
|
|
61
|
+
return root === 'automations'
|
|
62
62
|
? AUTOMATION_ENTRY_FILE
|
|
63
|
-
: join(
|
|
63
|
+
: join('src', 'api', `${name}.ts`);
|
|
64
64
|
}
|
|
65
65
|
/** Every endpoint name a source dir has on disk. */
|
|
66
66
|
export function listEndpointNames(root, sourceDirPath) {
|
|
67
|
-
if (root ===
|
|
67
|
+
if (root === 'automations') {
|
|
68
68
|
return existsSync(join(sourceDirPath, AUTOMATION_ENTRY_FILE))
|
|
69
69
|
? [AUTOMATION_ENDPOINT_NAME]
|
|
70
70
|
: [];
|
|
71
71
|
}
|
|
72
|
-
const apiDir = join(sourceDirPath,
|
|
72
|
+
const apiDir = join(sourceDirPath, 'src', 'api');
|
|
73
73
|
return existsSync(apiDir)
|
|
74
74
|
? readdirSync(apiDir)
|
|
75
|
-
.filter(
|
|
76
|
-
.map(
|
|
75
|
+
.filter(f => f.endsWith('.ts') && !f.endsWith('.d.ts'))
|
|
76
|
+
.map(f => f.replace(/\.ts$/, ''))
|
|
77
77
|
: [];
|
|
78
78
|
}
|
|
@@ -1,43 +1,45 @@
|
|
|
1
|
-
import { mkdirSync, mkdtempSync, writeFileSync } from
|
|
2
|
-
import { tmpdir } from
|
|
3
|
-
import { join } from
|
|
4
|
-
import { describe, expect, it } from
|
|
5
|
-
import { endpointEntryFile, findWorkspaceRoot, listEndpointNames, sourceRootOf, } from
|
|
6
|
-
describe(
|
|
1
|
+
import { mkdirSync, mkdtempSync, writeFileSync } from 'fs';
|
|
2
|
+
import { tmpdir } from 'os';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { endpointEntryFile, findWorkspaceRoot, listEndpointNames, sourceRootOf, } from './sourceRoots.js';
|
|
6
|
+
describe('source roots', () => {
|
|
7
7
|
it("reads the root from the source dir's parent", () => {
|
|
8
|
-
expect(sourceRootOf(
|
|
9
|
-
expect(sourceRootOf(
|
|
10
|
-
expect(sourceRootOf(
|
|
8
|
+
expect(sourceRootOf('/repo/apps/crm')).toBe('apps');
|
|
9
|
+
expect(sourceRootOf('/repo/automations/digest')).toBe('automations');
|
|
10
|
+
expect(sourceRootOf('/repo/packages/ui')).toBeUndefined();
|
|
11
11
|
});
|
|
12
12
|
it("an app's endpoints are src/api/<name>.ts; an automation's one endpoint is src/index.ts", () => {
|
|
13
|
-
expect(endpointEntryFile(
|
|
14
|
-
expect(endpointEntryFile(
|
|
13
|
+
expect(endpointEntryFile('apps', 'listItems')).toBe('src/api/listItems.ts');
|
|
14
|
+
expect(endpointEntryFile('automations', 'index')).toBe('src/index.ts');
|
|
15
15
|
});
|
|
16
|
-
it(
|
|
17
|
-
const repo = mkdtempSync(join(tmpdir(),
|
|
18
|
-
mkdirSync(join(repo,
|
|
19
|
-
writeFileSync(join(repo,
|
|
20
|
-
writeFileSync(join(repo,
|
|
21
|
-
mkdirSync(join(repo,
|
|
22
|
-
mkdirSync(join(repo,
|
|
23
|
-
writeFileSync(join(repo,
|
|
24
|
-
expect(listEndpointNames(
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
it('lists what is on disk under each layout', () => {
|
|
17
|
+
const repo = mkdtempSync(join(tmpdir(), 'zitejs-roots-'));
|
|
18
|
+
mkdirSync(join(repo, 'apps/crm/src/api'), { recursive: true });
|
|
19
|
+
writeFileSync(join(repo, 'apps/crm/src/api/listItems.ts'), '');
|
|
20
|
+
writeFileSync(join(repo, 'apps/crm/src/api/apiTypes.d.ts'), '');
|
|
21
|
+
mkdirSync(join(repo, 'automations/digest/src'), { recursive: true });
|
|
22
|
+
mkdirSync(join(repo, 'automations/empty/src'), { recursive: true });
|
|
23
|
+
writeFileSync(join(repo, 'automations/digest/src/index.ts'), '');
|
|
24
|
+
expect(listEndpointNames('apps', join(repo, 'apps/crm'))).toEqual([
|
|
25
|
+
'listItems',
|
|
26
|
+
]);
|
|
27
|
+
expect(listEndpointNames('automations', join(repo, 'automations/digest'))).toEqual(['index']);
|
|
28
|
+
expect(listEndpointNames('automations', join(repo, 'automations/empty'))).toEqual([]);
|
|
27
29
|
});
|
|
28
30
|
it("finds the workspace root from inside an app dir, and not from an app's own config", () => {
|
|
29
|
-
const repo = mkdtempSync(join(tmpdir(),
|
|
30
|
-
writeFileSync(join(repo,
|
|
31
|
-
mkdirSync(join(repo,
|
|
32
|
-
writeFileSync(join(repo,
|
|
31
|
+
const repo = mkdtempSync(join(tmpdir(), 'zitejs-root-'));
|
|
32
|
+
writeFileSync(join(repo, 'zite.config.json'), '{}');
|
|
33
|
+
mkdirSync(join(repo, 'apps/crm/src/api'), { recursive: true });
|
|
34
|
+
writeFileSync(join(repo, 'apps/crm/zite.config.json'), '{}');
|
|
33
35
|
expect(findWorkspaceRoot(repo)).toBe(repo);
|
|
34
|
-
expect(findWorkspaceRoot(join(repo,
|
|
35
|
-
expect(findWorkspaceRoot(join(repo,
|
|
36
|
+
expect(findWorkspaceRoot(join(repo, 'apps/crm'))).toBe(repo);
|
|
37
|
+
expect(findWorkspaceRoot(join(repo, 'apps/crm/src/api'))).toBe(repo);
|
|
36
38
|
});
|
|
37
|
-
it(
|
|
38
|
-
const app = mkdtempSync(join(tmpdir(),
|
|
39
|
-
writeFileSync(join(app,
|
|
40
|
-
mkdirSync(join(app,
|
|
39
|
+
it('has no root for a single-app project', () => {
|
|
40
|
+
const app = mkdtempSync(join(tmpdir(), 'zitejs-single-'));
|
|
41
|
+
writeFileSync(join(app, 'zite.config.json'), '{}');
|
|
42
|
+
mkdirSync(join(app, 'src/api'), { recursive: true });
|
|
41
43
|
expect(findWorkspaceRoot(app)).toBeUndefined();
|
|
42
44
|
});
|
|
43
45
|
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { HostRequestState } from './types.js';
|
|
2
|
+
export declare const host: () => HostRequestState;
|
|
3
|
+
export declare const decide: <T>(serverFnMeta: unknown, request: Request, fn: () => Promise<T>) => Promise<Response | T>;
|
|
4
|
+
/** Only signed-in users. Handlers get `context.user: User`. */
|
|
5
|
+
export declare const signedIn: import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, undefined, {
|
|
6
|
+
user: import("./types.js").User;
|
|
7
|
+
}>;
|
|
8
|
+
/** Anyone, signed in or not. Handlers get `context.user: User | null`. */
|
|
9
|
+
export declare const anyone: import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, undefined, {
|
|
10
|
+
user: import("./types.js").User | null;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Webhooks delivered by the platform, which already checked the URL token.
|
|
14
|
+
* `webhook.paused` keeps the URL but runs nothing: the platform answers the
|
|
15
|
+
* provider 200 and drops the delivery until it's switched back.
|
|
16
|
+
*/
|
|
17
|
+
export declare const webhook: import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, undefined, undefined> & {
|
|
18
|
+
paused: import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, undefined, undefined>;
|
|
19
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createMiddleware } from '@tanstack/react-start';
|
|
2
|
+
import { SIGN_IN_REQUIRED, ZiteError } from './errors.js';
|
|
3
|
+
import { withStatus } from './failures.js';
|
|
4
|
+
import { tag } from './middlewareKind.js';
|
|
5
|
+
import { recordRoute } from './platform/runLog.js';
|
|
6
|
+
import { getHost, runInScope } from './serve/scope.js';
|
|
7
|
+
// Identity comes from server-only storage, never TanStack's context, which
|
|
8
|
+
// merges whatever context the browser sends.
|
|
9
|
+
export const host = () => {
|
|
10
|
+
const current = getHost();
|
|
11
|
+
if (!current)
|
|
12
|
+
throw new ZiteError('UNAUTHORIZED', 'Missing platform context');
|
|
13
|
+
return current;
|
|
14
|
+
};
|
|
15
|
+
// A server route's run is recorded around its access decision, so a refusal shows with its status.
|
|
16
|
+
export const decide = (serverFnMeta, request, fn) => serverFnMeta
|
|
17
|
+
? withStatus(true, fn)
|
|
18
|
+
: recordRoute(getHost(), request, () => withStatus(false, fn));
|
|
19
|
+
/** Only signed-in users. Handlers get `context.user: User`. */
|
|
20
|
+
export const signedIn = tag(createMiddleware().server(({ next, serverFnMeta, request }) => decide(serverFnMeta, request, async () => {
|
|
21
|
+
const { user } = host();
|
|
22
|
+
if (!user)
|
|
23
|
+
throw new ZiteError('UNAUTHORIZED', SIGN_IN_REQUIRED);
|
|
24
|
+
return runInScope({ kind: 'signedIn', user }, () => next({ context: { user } }));
|
|
25
|
+
})), { kind: 'signedIn' });
|
|
26
|
+
/** Anyone, signed in or not. Handlers get `context.user: User | null`. */
|
|
27
|
+
export const anyone = tag(createMiddleware().server(({ next, serverFnMeta, request }) => decide(serverFnMeta, request, async () => {
|
|
28
|
+
const { user } = host();
|
|
29
|
+
return runInScope({ kind: 'anyone', user }, () => next({ context: { user } }));
|
|
30
|
+
})), { kind: 'anyone' });
|
|
31
|
+
const webhookMiddleware = (paused) => tag(createMiddleware().server(({ next, request }) => {
|
|
32
|
+
if (host().invoke?.kind !== 'webhook')
|
|
33
|
+
return new Response('Not found', { status: 404 });
|
|
34
|
+
return recordRoute(getHost(), request, async () => runInScope({ kind: 'webhook', user: null }, () => next()));
|
|
35
|
+
}), paused ? { kind: 'webhook', paused: true } : { kind: 'webhook' });
|
|
36
|
+
/**
|
|
37
|
+
* Webhooks delivered by the platform, which already checked the URL token.
|
|
38
|
+
* `webhook.paused` keeps the URL but runs nothing: the platform answers the
|
|
39
|
+
* provider 200 and drops the delivery until it's switched back.
|
|
40
|
+
*/
|
|
41
|
+
export const webhook = Object.assign(webhookMiddleware(false), {
|
|
42
|
+
paused: webhookMiddleware(true),
|
|
43
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type { User } from './types.js';
|
|
2
|
+
/** Sends the visitor to sign in, then back to `redirectUrl`, else to where they are now. */
|
|
3
|
+
export declare function loginWithRedirect(opts?: {
|
|
4
|
+
redirectUrl?: string;
|
|
5
|
+
}): void;
|
|
6
|
+
export declare function logout(opts?: {
|
|
7
|
+
returnTo?: string;
|
|
8
|
+
}): void;
|
|
9
|
+
export type ProfileChanges = {
|
|
10
|
+
firstName?: string;
|
|
11
|
+
lastName?: string;
|
|
12
|
+
};
|
|
13
|
+
/** Shaped like classic's, so code that reads `error` moves between the runtimes unchanged. */
|
|
14
|
+
export type ProfileUpdateResult = {
|
|
15
|
+
data: {
|
|
16
|
+
status: true;
|
|
17
|
+
};
|
|
18
|
+
error: null;
|
|
19
|
+
} | {
|
|
20
|
+
data: null;
|
|
21
|
+
error: {
|
|
22
|
+
code: string;
|
|
23
|
+
message: string;
|
|
24
|
+
status: number;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
/** Changes the signed-in user's name, and the router's user with it. */
|
|
28
|
+
export declare function updateProfile(changes: ProfileChanges): Promise<ProfileUpdateResult>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// What `zitejs/auth` is in a Start app: zite() aliases it here, and the `zite-start` condition types it. The actions
|
|
2
|
+
// talk to the sign-in module's own routes, so a Start page never ships better-auth's client.
|
|
3
|
+
import { profileUpdated } from '../auth/profileUpdates.js';
|
|
4
|
+
import { loginHref } from './login.js';
|
|
5
|
+
/** Sends the visitor to sign in, then back to `redirectUrl`, else to where they are now. */
|
|
6
|
+
export function loginWithRedirect(opts) {
|
|
7
|
+
if (window.location.pathname.startsWith('/auth/'))
|
|
8
|
+
return;
|
|
9
|
+
window.location.href = loginHref(opts?.redirectUrl);
|
|
10
|
+
}
|
|
11
|
+
export function logout(opts) {
|
|
12
|
+
void fetch('/auth/logout', { method: 'POST' }).then(() => {
|
|
13
|
+
window.location.href = opts?.returnTo || '/';
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/** Changes the signed-in user's name, and the router's user with it. */
|
|
17
|
+
export async function updateProfile(changes) {
|
|
18
|
+
const response = await fetch('/auth/profile', {
|
|
19
|
+
method: 'POST',
|
|
20
|
+
headers: { 'content-type': 'application/json' },
|
|
21
|
+
body: JSON.stringify(changes),
|
|
22
|
+
});
|
|
23
|
+
if (response.ok) {
|
|
24
|
+
profileUpdated(changes);
|
|
25
|
+
return { data: { status: true }, error: null };
|
|
26
|
+
}
|
|
27
|
+
const body = (await response.json().catch(() => ({})));
|
|
28
|
+
const code = body.code ?? 'PROFILE_UPDATE_FAILED';
|
|
29
|
+
return {
|
|
30
|
+
data: null,
|
|
31
|
+
error: { code, message: body.message ?? code, status: response.status },
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Server-only. A trigger registration's console stays out of the platform's
|
|
2
|
+
// logs, as classic's does: the provider can answer it with the signing secret.
|
|
3
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
4
|
+
const LEVELS = [
|
|
5
|
+
'debug',
|
|
6
|
+
'dir',
|
|
7
|
+
'error',
|
|
8
|
+
'info',
|
|
9
|
+
'log',
|
|
10
|
+
'table',
|
|
11
|
+
'trace',
|
|
12
|
+
'warn',
|
|
13
|
+
];
|
|
14
|
+
// Keyed on globalThis so two copies of zitejs in one bundle wrap console once.
|
|
15
|
+
const stores = globalThis;
|
|
16
|
+
const QUIET_KEY = Symbol.for('zitejs:quiet-console');
|
|
17
|
+
const quietStorage = () => {
|
|
18
|
+
const held = stores[QUIET_KEY];
|
|
19
|
+
if (held)
|
|
20
|
+
return held;
|
|
21
|
+
const storage = new AsyncLocalStorage();
|
|
22
|
+
stores[QUIET_KEY] = storage;
|
|
23
|
+
const methods = console;
|
|
24
|
+
for (const level of LEVELS) {
|
|
25
|
+
const original = methods[level];
|
|
26
|
+
if (typeof original !== 'function')
|
|
27
|
+
continue;
|
|
28
|
+
methods[level] = (...args) => {
|
|
29
|
+
if (!storage.getStore())
|
|
30
|
+
original.apply(console, args);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return storage;
|
|
34
|
+
};
|
|
35
|
+
/** Runs `fn` with this request's console dropped; the isolate's other requests log as before. */
|
|
36
|
+
export const withoutConsole = (fn) => quietStorage().run(true, fn);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LoadedWorkflow } from './workflowRun.js';
|
|
2
|
+
export type RegistrationResult = {
|
|
3
|
+
ok: true;
|
|
4
|
+
output: unknown;
|
|
5
|
+
} | {
|
|
6
|
+
ok: false;
|
|
7
|
+
error: {
|
|
8
|
+
code: string;
|
|
9
|
+
message: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
/** Undefined when the workflow has no such function. */
|
|
13
|
+
export declare function runRegistration(workflows: LoadedWorkflow[], name: string, op: unknown, input: unknown): Promise<RegistrationResult | undefined>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Server-only: a provider trigger's `subscribe` or `unsubscribe`, which the host
|
|
2
|
+
// runs at publish. Not a run: nothing is logged, since what `subscribe` returns
|
|
3
|
+
// carries the provider's signing secret.
|
|
4
|
+
import { errorOf } from '../platform/runLog.js';
|
|
5
|
+
import { runInScope } from '../serve/scope.js';
|
|
6
|
+
/** Undefined when the workflow has no such function. */
|
|
7
|
+
export async function runRegistration(workflows, name, op, input) {
|
|
8
|
+
const trigger = workflows.find(w => w.id === name)?.workflow.config.trigger;
|
|
9
|
+
if (!trigger || !('subscribe' in trigger))
|
|
10
|
+
return undefined;
|
|
11
|
+
const fn = op === 'subscribe'
|
|
12
|
+
? trigger.subscribe
|
|
13
|
+
: op === 'unsubscribe'
|
|
14
|
+
? trigger.unsubscribe
|
|
15
|
+
: undefined;
|
|
16
|
+
if (typeof fn !== 'function')
|
|
17
|
+
return undefined;
|
|
18
|
+
try {
|
|
19
|
+
const output = await runInScope({ kind: 'workflow', user: null }, () => fn(input));
|
|
20
|
+
return { ok: true, output: output ?? null };
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
return { ok: false, error: errorOf(error) };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ZiteStep } from '../../backend/index.js';
|
|
2
|
+
import type { StepStore } from '../platform/steps.js';
|
|
3
|
+
import type { DurableCall, StepRecord } from '../types.js';
|
|
4
|
+
/** @internal An automation runs outside any request: TanStack's error for that, as one naming the fix. */
|
|
5
|
+
export declare const asAutomationError: (error: unknown) => unknown;
|
|
6
|
+
/** What a workflow's handler gets as `step`. Waits join it once the host can wait between calls. */
|
|
7
|
+
export type StartStep = Pick<ZiteStep, 'run'>;
|
|
8
|
+
export type StepLog = StepRecord;
|
|
9
|
+
/**
|
|
10
|
+
* Each completed step's result is saved before the code after it runs, so a resumed run gets it back instead of
|
|
11
|
+
* running the step's side effects again. Only a resumed run reads saved results, once, at its first step. Without
|
|
12
|
+
* `durable` a step's error reaches the code at once, as in classic's one-call runs.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createSteps({ store, resuming, durable, now, }: {
|
|
15
|
+
store: StepStore;
|
|
16
|
+
resuming: boolean;
|
|
17
|
+
durable?: DurableCall;
|
|
18
|
+
now?: () => number;
|
|
19
|
+
}): {
|
|
20
|
+
step: StartStep;
|
|
21
|
+
log: StepRecord[];
|
|
22
|
+
failedStep: () => string | undefined;
|
|
23
|
+
stopped: Promise<void>;
|
|
24
|
+
stop: () => import("../../steps/index.js").StepStop | undefined;
|
|
25
|
+
retry: () => import("../../steps/index.js").StepRetry | undefined;
|
|
26
|
+
suspension: () => import("../../steps/index.js").StepSuspension | undefined;
|
|
27
|
+
saved: () => number;
|
|
28
|
+
settle: () => Promise<void>;
|
|
29
|
+
};
|