@decocms/blocks 8.1.0-next.0 → 8.1.0-next.2
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/bin/deco.js +5 -12
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol/assets.d.ts +46 -0
- package/dist/protocol/assets.d.ts.map +1 -0
- package/dist/protocol/assets.js +105 -0
- package/dist/protocol/assets.js.map +1 -0
- package/dist/protocol/canonical.d.ts +8 -0
- package/dist/protocol/canonical.d.ts.map +1 -0
- package/dist/protocol/canonical.js +8 -0
- package/dist/protocol/canonical.js.map +1 -0
- package/dist/protocol/ciphertext.d.ts +7 -0
- package/dist/protocol/ciphertext.d.ts.map +1 -0
- package/dist/protocol/ciphertext.js +7 -0
- package/dist/protocol/ciphertext.js.map +1 -0
- package/dist/protocol/client.d.ts +54 -0
- package/dist/protocol/client.d.ts.map +1 -0
- package/dist/protocol/client.js +104 -0
- package/dist/protocol/client.js.map +1 -0
- package/dist/protocol/conformance/cases/assets.d.ts +3 -0
- package/dist/protocol/conformance/cases/assets.d.ts.map +1 -0
- package/dist/protocol/conformance/cases/assets.js +71 -0
- package/dist/protocol/conformance/cases/assets.js.map +1 -0
- package/dist/protocol/conformance/cases/guards.d.ts +3 -0
- package/dist/protocol/conformance/cases/guards.d.ts.map +1 -0
- package/dist/protocol/conformance/cases/guards.js +265 -0
- package/dist/protocol/conformance/cases/guards.js.map +1 -0
- package/dist/protocol/conformance/cases/reads.d.ts +3 -0
- package/dist/protocol/conformance/cases/reads.d.ts.map +1 -0
- package/dist/protocol/conformance/cases/reads.js +140 -0
- package/dist/protocol/conformance/cases/reads.js.map +1 -0
- package/dist/protocol/conformance/cases/types.d.ts +9 -0
- package/dist/protocol/conformance/cases/types.d.ts.map +1 -0
- package/dist/protocol/conformance/cases/types.js +2 -0
- package/dist/protocol/conformance/cases/types.js.map +1 -0
- package/dist/protocol/conformance/cases/wire.d.ts +3 -0
- package/dist/protocol/conformance/cases/wire.d.ts.map +1 -0
- package/dist/protocol/conformance/cases/wire.js +130 -0
- package/dist/protocol/conformance/cases/wire.js.map +1 -0
- package/dist/protocol/conformance/cases/writes.d.ts +3 -0
- package/dist/protocol/conformance/cases/writes.d.ts.map +1 -0
- package/dist/protocol/conformance/cases/writes.js +278 -0
- package/dist/protocol/conformance/cases/writes.js.map +1 -0
- package/dist/protocol/conformance/contentHashFixtures.d.ts +22 -0
- package/dist/protocol/conformance/contentHashFixtures.d.ts.map +1 -0
- package/dist/protocol/conformance/contentHashFixtures.js +64 -0
- package/dist/protocol/conformance/contentHashFixtures.js.map +1 -0
- package/dist/protocol/conformance/context.d.ts +100 -0
- package/dist/protocol/conformance/context.d.ts.map +1 -0
- package/dist/protocol/conformance/context.js +155 -0
- package/dist/protocol/conformance/context.js.map +1 -0
- package/dist/protocol/conformance/index.d.ts +32 -0
- package/dist/protocol/conformance/index.d.ts.map +1 -0
- package/dist/protocol/conformance/index.js +90 -0
- package/dist/protocol/conformance/index.js.map +1 -0
- package/dist/protocol/errors.d.ts +85 -0
- package/dist/protocol/errors.d.ts.map +1 -0
- package/dist/protocol/errors.js +62 -0
- package/dist/protocol/errors.js.map +1 -0
- package/dist/protocol/index.d.ts +25 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +25 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/protocol/keys.d.ts +101 -0
- package/dist/protocol/keys.d.ts.map +1 -0
- package/dist/protocol/keys.js +223 -0
- package/dist/protocol/keys.js.map +1 -0
- package/dist/protocol/params.d.ts +10 -0
- package/dist/protocol/params.d.ts.map +1 -0
- package/dist/protocol/params.js +54 -0
- package/dist/protocol/params.js.map +1 -0
- package/dist/protocol/secrets.d.ts +22 -0
- package/dist/protocol/secrets.d.ts.map +1 -0
- package/dist/protocol/secrets.js +200 -0
- package/dist/protocol/secrets.js.map +1 -0
- package/dist/protocol/server/assets.d.ts +20 -0
- package/dist/protocol/server/assets.d.ts.map +1 -0
- package/dist/protocol/server/assets.js +77 -0
- package/dist/protocol/server/assets.js.map +1 -0
- package/dist/protocol/server/auth.d.ts +31 -0
- package/dist/protocol/server/auth.d.ts.map +1 -0
- package/dist/protocol/server/auth.js +32 -0
- package/dist/protocol/server/auth.js.map +1 -0
- package/dist/protocol/server/bodyCache.d.ts +28 -0
- package/dist/protocol/server/bodyCache.d.ts.map +1 -0
- package/dist/protocol/server/bodyCache.js +75 -0
- package/dist/protocol/server/bodyCache.js.map +1 -0
- package/dist/protocol/server/content.d.ts +44 -0
- package/dist/protocol/server/content.d.ts.map +1 -0
- package/dist/protocol/server/content.js +132 -0
- package/dist/protocol/server/content.js.map +1 -0
- package/dist/protocol/server/core.d.ts +63 -0
- package/dist/protocol/server/core.d.ts.map +1 -0
- package/dist/protocol/server/core.js +77 -0
- package/dist/protocol/server/core.js.map +1 -0
- package/dist/protocol/server/handler.d.ts +5 -0
- package/dist/protocol/server/handler.d.ts.map +1 -0
- package/dist/protocol/server/handler.js +70 -0
- package/dist/protocol/server/handler.js.map +1 -0
- package/dist/protocol/server/http.d.ts +24 -0
- package/dist/protocol/server/http.d.ts.map +1 -0
- package/dist/protocol/server/http.js +133 -0
- package/dist/protocol/server/http.js.map +1 -0
- package/dist/protocol/server/index.d.ts +11 -0
- package/dist/protocol/server/index.d.ts.map +1 -0
- package/dist/protocol/server/index.js +9 -0
- package/dist/protocol/server/index.js.map +1 -0
- package/dist/protocol/server/methods/apply.d.ts +4 -0
- package/dist/protocol/server/methods/apply.d.ts.map +1 -0
- package/dist/protocol/server/methods/apply.js +275 -0
- package/dist/protocol/server/methods/apply.js.map +1 -0
- package/dist/protocol/server/methods/read.d.ts +14 -0
- package/dist/protocol/server/methods/read.d.ts.map +1 -0
- package/dist/protocol/server/methods/read.js +132 -0
- package/dist/protocol/server/methods/read.js.map +1 -0
- package/dist/protocol/server/rpc.d.ts +7 -0
- package/dist/protocol/server/rpc.d.ts.map +1 -0
- package/dist/protocol/server/rpc.js +115 -0
- package/dist/protocol/server/rpc.js.map +1 -0
- package/dist/protocol/storage/fs/hash.d.ts +8 -0
- package/dist/protocol/storage/fs/hash.d.ts.map +1 -0
- package/dist/protocol/storage/fs/hash.js +20 -0
- package/dist/protocol/storage/fs/hash.js.map +1 -0
- package/dist/protocol/storage/fs/index.d.ts +30 -0
- package/dist/protocol/storage/fs/index.d.ts.map +1 -0
- package/dist/protocol/storage/fs/index.js +301 -0
- package/dist/protocol/storage/fs/index.js.map +1 -0
- package/dist/protocol/storage/fs/lock.d.ts +8 -0
- package/dist/protocol/storage/fs/lock.d.ts.map +1 -0
- package/dist/protocol/storage/fs/lock.js +61 -0
- package/dist/protocol/storage/fs/lock.js.map +1 -0
- package/dist/protocol/storage/fs/transaction.d.ts +19 -0
- package/dist/protocol/storage/fs/transaction.d.ts.map +1 -0
- package/dist/protocol/storage/fs/transaction.js +174 -0
- package/dist/protocol/storage/fs/transaction.js.map +1 -0
- package/dist/protocol/storage/fs/unsupported.d.ts +10 -0
- package/dist/protocol/storage/fs/unsupported.d.ts.map +1 -0
- package/dist/protocol/storage/fs/unsupported.js +4 -0
- package/dist/protocol/storage/fs/unsupported.js.map +1 -0
- package/dist/protocol/storage/memory.d.ts +40 -0
- package/dist/protocol/storage/memory.d.ts.map +1 -0
- package/dist/protocol/storage/memory.js +179 -0
- package/dist/protocol/storage/memory.js.map +1 -0
- package/dist/protocol/storage.d.ts +178 -0
- package/dist/protocol/storage.d.ts.map +1 -0
- package/dist/protocol/storage.js +29 -0
- package/dist/protocol/storage.js.map +1 -0
- package/dist/protocol/types.d.ts +194 -0
- package/dist/protocol/types.d.ts.map +1 -0
- package/dist/protocol/types.js +31 -0
- package/dist/protocol/types.js.map +1 -0
- package/dist/v8/analytics.d.ts +31 -0
- package/dist/v8/analytics.d.ts.map +1 -0
- package/dist/v8/analytics.js +46 -0
- package/dist/v8/analytics.js.map +1 -0
- package/dist/v8/background.d.ts +26 -0
- package/dist/v8/background.d.ts.map +1 -0
- package/dist/v8/background.js +95 -0
- package/dist/v8/background.js.map +1 -0
- package/dist/v8/builtins/data.d.ts +15 -0
- package/dist/v8/builtins/data.d.ts.map +1 -0
- package/dist/v8/builtins/data.js +18 -0
- package/dist/v8/builtins/data.js.map +1 -0
- package/dist/v8/builtins/index.d.ts +9 -0
- package/dist/v8/builtins/index.d.ts.map +1 -0
- package/dist/v8/builtins/index.js +24 -0
- package/dist/v8/builtins/index.js.map +1 -0
- package/dist/v8/builtins/lazy.d.ts +17 -0
- package/dist/v8/builtins/lazy.d.ts.map +1 -0
- package/dist/v8/builtins/lazy.js +13 -0
- package/dist/v8/builtins/lazy.js.map +1 -0
- package/dist/v8/builtins/legacy.d.ts +41 -0
- package/dist/v8/builtins/legacy.d.ts.map +1 -0
- package/dist/v8/builtins/legacy.js +62 -0
- package/dist/v8/builtins/legacy.js.map +1 -0
- package/dist/v8/builtins/matchers.d.ts +19 -0
- package/dist/v8/builtins/matchers.d.ts.map +1 -0
- package/dist/v8/builtins/matchers.js +24 -0
- package/dist/v8/builtins/matchers.js.map +1 -0
- package/dist/v8/builtins/multivariate.d.ts +15 -0
- package/dist/v8/builtins/multivariate.d.ts.map +1 -0
- package/dist/v8/builtins/multivariate.js +18 -0
- package/dist/v8/builtins/multivariate.js.map +1 -0
- package/dist/v8/builtins/secret.d.ts +7 -0
- package/dist/v8/builtins/secret.d.ts.map +1 -0
- package/dist/v8/builtins/secret.js +68 -0
- package/dist/v8/builtins/secret.js.map +1 -0
- package/dist/v8/canonical.d.ts +42 -0
- package/dist/v8/canonical.d.ts.map +1 -0
- package/dist/v8/canonical.js +111 -0
- package/dist/v8/canonical.js.map +1 -0
- package/dist/v8/ciphertext.d.ts +58 -0
- package/dist/v8/ciphertext.d.ts.map +1 -0
- package/dist/v8/ciphertext.js +134 -0
- package/dist/v8/ciphertext.js.map +1 -0
- package/dist/v8/cli/builtins.d.ts +11 -0
- package/dist/v8/cli/builtins.d.ts.map +1 -0
- package/dist/v8/cli/builtins.js +18 -0
- package/dist/v8/cli/builtins.js.map +1 -0
- package/dist/v8/cli/check/index.d.ts +41 -0
- package/dist/v8/cli/check/index.d.ts.map +1 -0
- package/dist/v8/cli/check/index.js +713 -0
- package/dist/v8/cli/check/index.js.map +1 -0
- package/dist/v8/cli/check/messages.d.ts +24 -0
- package/dist/v8/cli/check/messages.d.ts.map +1 -0
- package/dist/v8/cli/check/messages.js +150 -0
- package/dist/v8/cli/check/messages.js.map +1 -0
- package/dist/v8/cli/content.d.ts +60 -0
- package/dist/v8/cli/content.d.ts.map +1 -0
- package/dist/v8/cli/content.js +231 -0
- package/dist/v8/cli/content.js.map +1 -0
- package/dist/v8/cli/index.d.ts +18 -0
- package/dist/v8/cli/index.d.ts.map +1 -0
- package/dist/v8/cli/index.js +18 -0
- package/dist/v8/cli/index.js.map +1 -0
- package/dist/v8/cli/log.d.ts +9 -0
- package/dist/v8/cli/log.d.ts.map +1 -0
- package/dist/v8/cli/log.js +11 -0
- package/dist/v8/cli/log.js.map +1 -0
- package/dist/v8/cli/main.d.ts +2 -0
- package/dist/v8/cli/main.d.ts.map +1 -0
- package/dist/v8/cli/main.js +9 -0
- package/dist/v8/cli/main.js.map +1 -0
- package/dist/v8/cli/root.d.ts +28 -0
- package/dist/v8/cli/root.d.ts.map +1 -0
- package/dist/v8/cli/root.js +64 -0
- package/dist/v8/cli/root.js.map +1 -0
- package/dist/v8/cli/run.d.ts +13 -0
- package/dist/v8/cli/run.d.ts.map +1 -0
- package/dist/v8/cli/run.js +210 -0
- package/dist/v8/cli/run.js.map +1 -0
- package/dist/v8/cli/schema/builtinSchemas.d.ts +22 -0
- package/dist/v8/cli/schema/builtinSchemas.d.ts.map +1 -0
- package/dist/v8/cli/schema/builtinSchemas.js +213 -0
- package/dist/v8/cli/schema/builtinSchemas.js.map +1 -0
- package/dist/v8/cli/schema/generate.d.ts +50 -0
- package/dist/v8/cli/schema/generate.d.ts.map +1 -0
- package/dist/v8/cli/schema/generate.js +415 -0
- package/dist/v8/cli/schema/generate.js.map +1 -0
- package/dist/v8/cli/schema/index.d.ts +21 -0
- package/dist/v8/cli/schema/index.d.ts.map +1 -0
- package/dist/v8/cli/schema/index.js +51 -0
- package/dist/v8/cli/schema/index.js.map +1 -0
- package/dist/v8/cli/schema/tsProgram.d.ts +120 -0
- package/dist/v8/cli/schema/tsProgram.d.ts.map +1 -0
- package/dist/v8/cli/schema/tsProgram.js +418 -0
- package/dist/v8/cli/schema/tsProgram.js.map +1 -0
- package/dist/v8/cli/schema/typeToSchema.d.ts +81 -0
- package/dist/v8/cli/schema/typeToSchema.d.ts.map +1 -0
- package/dist/v8/cli/schema/typeToSchema.js +683 -0
- package/dist/v8/cli/schema/typeToSchema.js.map +1 -0
- package/dist/v8/cli/serve/server.d.ts +31 -0
- package/dist/v8/cli/serve/server.d.ts.map +1 -0
- package/dist/v8/cli/serve/server.js +247 -0
- package/dist/v8/cli/serve/server.js.map +1 -0
- package/dist/v8/cli/watch.d.ts +20 -0
- package/dist/v8/cli/watch.d.ts.map +1 -0
- package/dist/v8/cli/watch.js +79 -0
- package/dist/v8/cli/watch.js.map +1 -0
- package/dist/v8/client.d.ts +20 -0
- package/dist/v8/client.d.ts.map +1 -0
- package/dist/v8/client.js +115 -0
- package/dist/v8/client.js.map +1 -0
- package/dist/v8/cms.d.ts +9 -0
- package/dist/v8/cms.d.ts.map +1 -0
- package/dist/v8/cms.js +206 -0
- package/dist/v8/cms.js.map +1 -0
- package/dist/v8/content.d.ts +35 -0
- package/dist/v8/content.d.ts.map +1 -0
- package/dist/v8/content.js +183 -0
- package/dist/v8/content.js.map +1 -0
- package/dist/v8/draft.d.ts +44 -0
- package/dist/v8/draft.d.ts.map +1 -0
- package/dist/v8/draft.js +133 -0
- package/dist/v8/draft.js.map +1 -0
- package/dist/v8/errors.d.ts +21 -0
- package/dist/v8/errors.d.ts.map +1 -0
- package/dist/v8/errors.js +39 -0
- package/dist/v8/errors.js.map +1 -0
- package/dist/v8/fetch.d.ts +26 -0
- package/dist/v8/fetch.d.ts.map +1 -0
- package/dist/v8/fetch.js +98 -0
- package/dist/v8/fetch.js.map +1 -0
- package/dist/v8/identity.d.ts +19 -0
- package/dist/v8/identity.d.ts.map +1 -0
- package/dist/v8/identity.js +54 -0
- package/dist/v8/identity.js.map +1 -0
- package/dist/v8/index.d.ts +11 -0
- package/dist/v8/index.d.ts.map +1 -0
- package/dist/v8/index.js +10 -0
- package/dist/v8/index.js.map +1 -0
- package/dist/v8/json.d.ts +19 -0
- package/dist/v8/json.d.ts.map +1 -0
- package/dist/v8/json.js +65 -0
- package/dist/v8/json.js.map +1 -0
- package/dist/v8/matchRoute.d.ts +30 -0
- package/dist/v8/matchRoute.d.ts.map +1 -0
- package/dist/v8/matchRoute.js +175 -0
- package/dist/v8/matchRoute.js.map +1 -0
- package/dist/v8/remoteLoader.d.ts +16 -0
- package/dist/v8/remoteLoader.d.ts.map +1 -0
- package/dist/v8/remoteLoader.js +243 -0
- package/dist/v8/remoteLoader.js.map +1 -0
- package/dist/v8/resolver.d.ts +34 -0
- package/dist/v8/resolver.d.ts.map +1 -0
- package/dist/v8/resolver.js +219 -0
- package/dist/v8/resolver.js.map +1 -0
- package/dist/v8/secrets.d.ts +9 -0
- package/dist/v8/secrets.d.ts.map +1 -0
- package/dist/v8/secrets.js +14 -0
- package/dist/v8/secrets.js.map +1 -0
- package/dist/v8/telemetry.d.ts +61 -0
- package/dist/v8/telemetry.d.ts.map +1 -0
- package/dist/v8/telemetry.js +460 -0
- package/dist/v8/telemetry.js.map +1 -0
- package/dist/v8/types.d.ts +214 -0
- package/dist/v8/types.d.ts.map +1 -0
- package/dist/v8/types.js +2 -0
- package/dist/v8/types.js.map +1 -0
- package/package.json +65 -105
- package/src/index.ts +3 -13
- package/src/protocol/canonical.ts +1 -1
- package/src/protocol/ciphertext.ts +1 -1
- package/src/protocol/client.ts +2 -2
- package/src/protocol/conformance/cases/assets.ts +3 -3
- package/src/protocol/conformance/cases/guards.ts +4 -4
- package/src/protocol/conformance/cases/reads.ts +4 -4
- package/src/protocol/conformance/cases/types.ts +1 -1
- package/src/protocol/conformance/cases/wire.ts +4 -4
- package/src/protocol/conformance/cases/writes.ts +4 -4
- package/src/protocol/conformance/context.ts +4 -4
- package/src/protocol/conformance/index.ts +10 -10
- package/src/protocol/index.ts +6 -6
- package/src/protocol/params.ts +2 -2
- package/src/protocol/secrets.ts +3 -3
- package/src/protocol/server/assets.ts +6 -6
- package/src/protocol/server/auth.ts +1 -1
- package/src/protocol/server/content.ts +5 -5
- package/src/protocol/server/core.ts +12 -6
- package/src/protocol/server/handler.ts +6 -6
- package/src/protocol/server/http.ts +1 -1
- package/src/protocol/server/index.ts +3 -3
- package/src/protocol/server/methods/apply.ts +9 -9
- package/src/protocol/server/methods/read.ts +5 -5
- package/src/protocol/server/rpc.ts +6 -6
- package/src/protocol/storage/fs/index.ts +7 -7
- package/src/protocol/storage/fs/lock.ts +1 -1
- package/src/protocol/storage/fs/unsupported.ts +2 -2
- package/src/protocol/storage/memory.ts +5 -5
- package/src/protocol/storage.ts +1 -1
- package/src/v8/analytics.ts +2 -2
- package/src/v8/background.ts +3 -3
- package/src/v8/builtins/data.ts +1 -1
- package/src/v8/builtins/index.ts +6 -6
- package/src/v8/builtins/lazy.ts +1 -1
- package/src/v8/builtins/legacy.ts +2 -2
- package/src/v8/builtins/multivariate.ts +1 -1
- package/src/v8/builtins/secret.ts +2 -2
- package/src/v8/cli/builtins.ts +2 -2
- package/src/v8/cli/check/index.ts +11 -11
- package/src/v8/cli/content.ts +6 -6
- package/src/v8/cli/index.ts +8 -8
- package/src/v8/cli/main.ts +1 -1
- package/src/v8/cli/run.ts +7 -7
- package/src/v8/cli/schema/builtinSchemas.ts +1 -1
- package/src/v8/cli/schema/generate.ts +6 -6
- package/src/v8/cli/schema/index.ts +4 -4
- package/src/v8/cli/schema/tsProgram.ts +1 -1
- package/src/v8/cli/schema/typeToSchema.ts +24 -2
- package/src/v8/cli/serve/server.ts +9 -9
- package/src/v8/client.ts +5 -5
- package/src/v8/cms.ts +9 -9
- package/src/v8/content.ts +4 -4
- package/src/v8/draft.ts +1 -1
- package/src/v8/errors.ts +1 -1
- package/src/v8/fetch.ts +9 -28
- package/src/v8/identity.ts +1 -1
- package/src/v8/index.ts +5 -5
- package/src/v8/matchRoute.ts +1 -1
- package/src/v8/remoteLoader.ts +7 -7
- package/src/v8/resolver.ts +6 -6
- package/src/v8/secrets.ts +1 -1
- package/src/v8/telemetry.ts +6 -6
- package/src/cms/applySectionConventions.ts +0 -148
- package/src/cms/blockSource.ts +0 -228
- package/src/cms/client.ts +0 -85
- package/src/cms/deferredTrigger.ts +0 -58
- package/src/cms/draftSource.ts +0 -476
- package/src/cms/index.ts +0 -180
- package/src/cms/loadDecofileDirectory.ts +0 -89
- package/src/cms/loader.ts +0 -563
- package/src/cms/registry.ts +0 -264
- package/src/cms/renderJson.ts +0 -179
- package/src/cms/resolve.ts +0 -2583
- package/src/cms/schema.ts +0 -1219
- package/src/cms/sectionLoaderContext.ts +0 -113
- package/src/cms/sectionLoaders.ts +0 -686
- package/src/cms/sectionMixins.ts +0 -153
- package/src/flags/audience.ts +0 -56
- package/src/flags/everyone.ts +0 -29
- package/src/flags/flag.ts +0 -15
- package/src/flags/multivariate/image.ts +0 -11
- package/src/flags/multivariate/message.ts +0 -11
- package/src/flags/multivariate/page.ts +0 -16
- package/src/flags/multivariate/section.ts +0 -16
- package/src/flags/multivariate.ts +0 -1
- package/src/flags/types.ts +0 -59
- package/src/flags/utils/multivariate.ts +0 -20
- package/src/hooks/Image.tsx +0 -314
- package/src/hooks/JsonLd.tsx +0 -353
- package/src/hooks/LazySection.tsx +0 -121
- package/src/hooks/LiveControls.tsx +0 -144
- package/src/hooks/Picture.tsx +0 -127
- package/src/hooks/RenderSection.tsx +0 -91
- package/src/hooks/SectionErrorFallback.tsx +0 -97
- package/src/hooks/Stats.tsx +0 -134
- package/src/hooks/index.ts +0 -35
- package/src/hooks/useLoadMore.ts +0 -100
- package/src/matchers/builtins.ts +0 -459
- package/src/matchers/countryNames.ts +0 -104
- package/src/matchers/override.ts +0 -136
- package/src/matchers/posthog.ts +0 -154
- package/src/middleware/decoState.ts +0 -55
- package/src/middleware/healthMetrics.ts +0 -133
- package/src/middleware/hydrationContext.ts +0 -79
- package/src/middleware/index.ts +0 -88
- package/src/middleware/liveness.ts +0 -21
- package/src/middleware/observability.ts +0 -800
- package/src/middleware/validateSection.ts +0 -100
- package/src/preview/DraftPreviewBadge.tsx +0 -306
- package/src/preview/decoMark.ts +0 -11
- package/src/preview/index.ts +0 -8
- package/src/sdk/abTesting.ts +0 -556
- package/src/sdk/analytics.ts +0 -147
- package/src/sdk/cacheHeaders.ts +0 -633
- package/src/sdk/cacheStorage.ts +0 -287
- package/src/sdk/cachedLoader.ts +0 -556
- package/src/sdk/clx.ts +0 -5
- package/src/sdk/cn.ts +0 -28
- package/src/sdk/composite.ts +0 -114
- package/src/sdk/cookie.ts +0 -129
- package/src/sdk/crypto.ts +0 -199
- package/src/sdk/csp.ts +0 -59
- package/src/sdk/deepOmit.ts +0 -52
- package/src/sdk/detectDevice.ts +0 -45
- package/src/sdk/djb2.ts +0 -20
- package/src/sdk/encoding.ts +0 -44
- package/src/sdk/env.ts +0 -54
- package/src/sdk/experiments.ts +0 -314
- package/src/sdk/fetchCache.ts +0 -269
- package/src/sdk/fetchTimeout.ts +0 -58
- package/src/sdk/flags.ts +0 -138
- package/src/sdk/http.ts +0 -124
- package/src/sdk/index.ts +0 -97
- package/src/sdk/inflightTimeout.ts +0 -53
- package/src/sdk/instrumentedFetch.ts +0 -362
- package/src/sdk/invoke.ts +0 -298
- package/src/sdk/logger.ts +0 -304
- package/src/sdk/mergeCacheControl.ts +0 -150
- package/src/sdk/nonce.ts +0 -46
- package/src/sdk/normalizeUrls.ts +0 -91
- package/src/sdk/observability.ts +0 -116
- package/src/sdk/otel.ts +0 -1118
- package/src/sdk/otelAdapters/clickhouseCollector.ts +0 -65
- package/src/sdk/otelAdapters.ts +0 -144
- package/src/sdk/otelHttpLog.ts +0 -419
- package/src/sdk/otelHttpMeter.ts +0 -532
- package/src/sdk/otelHttpTracer.ts +0 -543
- package/src/sdk/redirects.ts +0 -336
- package/src/sdk/requestContext.ts +0 -281
- package/src/sdk/requestContextStorage.browser.ts +0 -43
- package/src/sdk/requestContextStorage.ts +0 -35
- package/src/sdk/responseCache.ts +0 -82
- package/src/sdk/retry.ts +0 -45
- package/src/sdk/serverTimings.ts +0 -68
- package/src/sdk/signal.ts +0 -42
- package/src/sdk/sitemap.ts +0 -160
- package/src/sdk/urlRedaction.ts +0 -82
- package/src/sdk/urlUtils.ts +0 -183
- package/src/sdk/useDevice.ts +0 -89
- package/src/sdk/useDeviceContext.tsx +0 -108
- package/src/sdk/useId.ts +0 -7
- package/src/sdk/useScript.ts +0 -210
- package/src/sdk/useSuggestions.ts +0 -188
- package/src/sdk/wrapCaughtErrors.ts +0 -107
- package/src/setup.ts +0 -120
- package/src/types/index.ts +0 -53
- package/src/types/widgets.ts +0 -14
package/src/sdk/abTesting.ts
DELETED
|
@@ -1,556 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A/B Testing wrapper for Cloudflare Worker entries.
|
|
3
|
-
*
|
|
4
|
-
* Provides KV-driven traffic splitting between the current TanStack Start
|
|
5
|
-
* worker ("worker" bucket) and a fallback origin ("fallback" bucket, e.g.
|
|
6
|
-
* legacy Deco/Fresh site). Designed for migration-period A/B testing.
|
|
7
|
-
*
|
|
8
|
-
* Features:
|
|
9
|
-
* - FNV-1a IP hashing for stable, deterministic bucket assignment
|
|
10
|
-
* - Sticky bucketing via cookie ("bucket:ratioPct" format) — the cookie carries
|
|
11
|
-
* a fingerprint of the KV ratio at the time of assignment. When the ratio
|
|
12
|
-
* changes in KV, all cookies with the old fingerprint are re-evaluated
|
|
13
|
-
* against the new threshold, so the distribution rebalances in one visit
|
|
14
|
-
* per user; once stable, cookies converge and become sticky again.
|
|
15
|
-
* - Query param override for QA (?_deco_bucket=worker)
|
|
16
|
-
* - Circuit breaker: worker errors auto-fallback to legacy origin
|
|
17
|
-
* - Fallback proxy with hostname rewriting (Set-Cookie, Location, body)
|
|
18
|
-
* - Configurable bypass for paths that must always use the worker
|
|
19
|
-
* (e.g. VTEX checkout proxy paths)
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* import { createDecoWorkerEntry } from "@decocms/start/sdk/workerEntry";
|
|
24
|
-
* import { withABTesting } from "@decocms/start/sdk/abTesting";
|
|
25
|
-
*
|
|
26
|
-
* const decoWorker = createDecoWorkerEntry(serverEntry, { ... });
|
|
27
|
-
*
|
|
28
|
-
* export default withABTesting(decoWorker, {
|
|
29
|
-
* kvBinding: "SITES_KV",
|
|
30
|
-
* shouldBypassAB: (request, url) => isVtexPath(url.pathname),
|
|
31
|
-
* });
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
// Types
|
|
37
|
-
// ---------------------------------------------------------------------------
|
|
38
|
-
|
|
39
|
-
interface WorkerExecutionContext {
|
|
40
|
-
waitUntil(promise: Promise<unknown>): void;
|
|
41
|
-
passThroughOnException(): void;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface WorkerHandler {
|
|
45
|
-
fetch(
|
|
46
|
-
request: Request,
|
|
47
|
-
env: Record<string, unknown>,
|
|
48
|
-
ctx: WorkerExecutionContext,
|
|
49
|
-
): Promise<Response>;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
interface KVNamespace {
|
|
53
|
-
get<T = string>(key: string, type: "json"): Promise<T | null>;
|
|
54
|
-
get(key: string, type?: "text"): Promise<string | null>;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** KV value shape — same as the original cf-gateway config. */
|
|
58
|
-
export interface SiteConfig {
|
|
59
|
-
workerName: string;
|
|
60
|
-
fallbackOrigin: string;
|
|
61
|
-
abTest?: { ratio: number };
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export type Bucket = "worker" | "fallback";
|
|
65
|
-
|
|
66
|
-
export interface ABTestConfig {
|
|
67
|
-
/** KV namespace binding name. @default "SITES_KV" */
|
|
68
|
-
kvBinding?: string;
|
|
69
|
-
|
|
70
|
-
/** Cookie name for bucket persistence. @default "_deco_bucket" */
|
|
71
|
-
cookieName?: string;
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Cookie max-age in seconds. @default 31536000 (1 year)
|
|
75
|
-
*
|
|
76
|
-
* Long by design: the cookie's ratio fingerprint handles invalidation
|
|
77
|
-
* (a change in KV ratio implicitly invalidates all old cookies), so
|
|
78
|
-
* there's no need for the browser to expire the cookie to pick up
|
|
79
|
-
* ratio changes. Shorter values just cause more user-bucket churn
|
|
80
|
-
* across sessions without any rebalancing benefit.
|
|
81
|
-
*/
|
|
82
|
-
cookieMaxAge?: number;
|
|
83
|
-
|
|
84
|
-
/** Auto-fallback to legacy on worker errors. @default true */
|
|
85
|
-
circuitBreaker?: boolean;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Return `true` to bypass A/B for this request — always serve from
|
|
89
|
-
* the worker regardless of bucket assignment.
|
|
90
|
-
*
|
|
91
|
-
* Useful for commerce backend paths (checkout, /api/*) that must
|
|
92
|
-
* not be proxied through the fallback origin.
|
|
93
|
-
*/
|
|
94
|
-
shouldBypassAB?: (request: Request, url: URL) => boolean;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Called before the A/B logic runs. Return a `Response` to short-circuit
|
|
98
|
-
* (e.g. for CMS redirects), or `null` to continue with A/B.
|
|
99
|
-
*/
|
|
100
|
-
preHandler?: (
|
|
101
|
-
request: Request,
|
|
102
|
-
url: URL,
|
|
103
|
-
) => Response | Promise<Response | null> | null;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// ---------------------------------------------------------------------------
|
|
107
|
-
// FNV-1a 32-bit — fast, good distribution for short strings like IPs.
|
|
108
|
-
// Same hash used by the original cf-gateway.
|
|
109
|
-
// ---------------------------------------------------------------------------
|
|
110
|
-
|
|
111
|
-
function fnv1a(str: string): number {
|
|
112
|
-
let hash = 0x811c9dc5;
|
|
113
|
-
for (let i = 0; i < str.length; i++) {
|
|
114
|
-
hash ^= str.charCodeAt(i);
|
|
115
|
-
hash = Math.imul(hash, 0x01000193);
|
|
116
|
-
}
|
|
117
|
-
return Math.abs(hash);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// ---------------------------------------------------------------------------
|
|
121
|
-
// Header constants
|
|
122
|
-
// ---------------------------------------------------------------------------
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Hop-by-hop headers per RFC 7230 §6.1 — must not be forwarded through
|
|
126
|
-
* proxies. Plus `host`, which we always rewrite to the target origin.
|
|
127
|
-
*/
|
|
128
|
-
const HOP_BY_HOP_HEADERS = new Set([
|
|
129
|
-
"connection",
|
|
130
|
-
"keep-alive",
|
|
131
|
-
"transfer-encoding",
|
|
132
|
-
"te",
|
|
133
|
-
"trailer",
|
|
134
|
-
"upgrade",
|
|
135
|
-
"proxy-authorization",
|
|
136
|
-
"proxy-authenticate",
|
|
137
|
-
]);
|
|
138
|
-
|
|
139
|
-
// ---------------------------------------------------------------------------
|
|
140
|
-
// Cookie helpers
|
|
141
|
-
// ---------------------------------------------------------------------------
|
|
142
|
-
|
|
143
|
-
function parseCookies(header: string): Record<string, string> {
|
|
144
|
-
return Object.fromEntries(
|
|
145
|
-
header.split(";").map((c) => {
|
|
146
|
-
const [k, ...v] = c.trim().split("=");
|
|
147
|
-
return [k, v.join("=")];
|
|
148
|
-
}),
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Convert a 0–1 ratio to a 0–100 integer percentage. Anchors the cookie
|
|
154
|
-
* fingerprint to the resolution at which bucketing decisions are actually
|
|
155
|
-
* made (`hash % 100 < ratio * 100`), so two equivalent ratios like 0.5 and
|
|
156
|
-
* 0.500001 produce the same fingerprint and don't invalidate cookies.
|
|
157
|
-
*/
|
|
158
|
-
const RATIO_PCT_MAX = 100;
|
|
159
|
-
|
|
160
|
-
function ratioToPct(ratio: number): number {
|
|
161
|
-
if (!Number.isFinite(ratio) || ratio <= 0) return 0;
|
|
162
|
-
if (ratio >= 1) return RATIO_PCT_MAX;
|
|
163
|
-
return Math.round(ratio * RATIO_PCT_MAX);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Parse the bucket cookie value.
|
|
168
|
-
*
|
|
169
|
-
* Format: "worker:50" (bucket + ratioPct fingerprint, 0–100). The fingerprint
|
|
170
|
-
* is the KV ratio at the time the cookie was set. Callers must compare it
|
|
171
|
-
* against the current KV ratio and only honor the cookie when they match.
|
|
172
|
-
*
|
|
173
|
-
* Legacy formats ("worker:1711540800" with unix timestamp, or bare
|
|
174
|
-
* "worker"/"fallback") parse to `null` so they're treated as missing and
|
|
175
|
-
* re-evaluated against the current ratio. Those cookies vanish naturally
|
|
176
|
-
* because the legacy default Max-Age was 1 day.
|
|
177
|
-
*/
|
|
178
|
-
function parseBucketCookie(
|
|
179
|
-
raw: string | undefined,
|
|
180
|
-
): { bucket: Bucket; ratioPct: number } | null {
|
|
181
|
-
if (!raw) return null;
|
|
182
|
-
|
|
183
|
-
const colonIdx = raw.indexOf(":");
|
|
184
|
-
if (colonIdx <= 0) return null;
|
|
185
|
-
|
|
186
|
-
const bucket = raw.slice(0, colonIdx);
|
|
187
|
-
if (bucket !== "worker" && bucket !== "fallback") return null;
|
|
188
|
-
|
|
189
|
-
const ratioPct = parseInt(raw.slice(colonIdx + 1), 10);
|
|
190
|
-
if (isNaN(ratioPct) || ratioPct < 0 || ratioPct > RATIO_PCT_MAX) return null;
|
|
191
|
-
|
|
192
|
-
return { bucket, ratioPct };
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// ---------------------------------------------------------------------------
|
|
196
|
-
// Public helpers (exported for custom composition)
|
|
197
|
-
// ---------------------------------------------------------------------------
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Deterministically assign a bucket based on:
|
|
201
|
-
* 1. Query param override (?_deco_bucket=worker)
|
|
202
|
-
* 2. Existing cookie whose ratio fingerprint matches the current KV ratio
|
|
203
|
-
* 3. IP hash against ratio threshold
|
|
204
|
-
*
|
|
205
|
-
* Step 2 is the key correctness property: a cookie set when the KV ratio
|
|
206
|
-
* was X is only trusted while the KV ratio is still X. When the operator
|
|
207
|
-
* changes the ratio in KV, all cookies with the old fingerprint fall
|
|
208
|
-
* through to step 3 and are re-evaluated against the new threshold — the
|
|
209
|
-
* fnv1a IP hash being deterministic means each user converges to the new
|
|
210
|
-
* distribution in a single visit, then the cookie is re-issued with the
|
|
211
|
-
* new fingerprint and becomes sticky again.
|
|
212
|
-
*/
|
|
213
|
-
export function getStableBucket(
|
|
214
|
-
request: Request,
|
|
215
|
-
ratio: number,
|
|
216
|
-
url: URL,
|
|
217
|
-
cookieName: string = "_deco_bucket",
|
|
218
|
-
): Bucket {
|
|
219
|
-
const override = url.searchParams.get(cookieName);
|
|
220
|
-
if (override === "worker" || override === "fallback") return override;
|
|
221
|
-
|
|
222
|
-
const currentRatioPct = ratioToPct(ratio);
|
|
223
|
-
const cookies = parseCookies(request.headers.get("cookie") ?? "");
|
|
224
|
-
const parsed = parseBucketCookie(cookies[cookieName]);
|
|
225
|
-
if (parsed && parsed.ratioPct === currentRatioPct) return parsed.bucket;
|
|
226
|
-
|
|
227
|
-
if (currentRatioPct <= 0) return "fallback";
|
|
228
|
-
if (currentRatioPct >= RATIO_PCT_MAX) return "worker";
|
|
229
|
-
|
|
230
|
-
const ip =
|
|
231
|
-
request.headers.get("cf-connecting-ip") ?? Math.random().toString();
|
|
232
|
-
return fnv1a(ip) % RATIO_PCT_MAX < currentRatioPct ? "worker" : "fallback";
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Tag a response with the bucket assignment and refresh the sticky cookie
|
|
237
|
-
* when the current bucket/ratio differs from what the cookie carries.
|
|
238
|
-
*
|
|
239
|
-
* The cookie value is `<bucket>:<ratioPct>` — see `parseBucketCookie`. The
|
|
240
|
-
* fingerprint is what makes ratio changes in KV propagate automatically:
|
|
241
|
-
* when the operator bumps the ratio, this function rewrites the cookie on
|
|
242
|
-
* the next response so the user starts honoring the new threshold.
|
|
243
|
-
*/
|
|
244
|
-
export function tagBucket(
|
|
245
|
-
response: Response,
|
|
246
|
-
bucket: Bucket,
|
|
247
|
-
hostname: string,
|
|
248
|
-
request: Request,
|
|
249
|
-
ratio: number,
|
|
250
|
-
cookieName: string = "_deco_bucket",
|
|
251
|
-
maxAge: number = 60 * 60 * 24 * 365,
|
|
252
|
-
): Response {
|
|
253
|
-
const res = new Response(response.body, response);
|
|
254
|
-
res.headers.set("x-deco-bucket", bucket);
|
|
255
|
-
|
|
256
|
-
const currentRatioPct = ratioToPct(ratio);
|
|
257
|
-
const cookies = parseCookies(request.headers.get("cookie") ?? "");
|
|
258
|
-
const parsed = parseBucketCookie(cookies[cookieName]);
|
|
259
|
-
|
|
260
|
-
const needsSet =
|
|
261
|
-
!parsed ||
|
|
262
|
-
parsed.bucket !== bucket ||
|
|
263
|
-
parsed.ratioPct !== currentRatioPct;
|
|
264
|
-
|
|
265
|
-
if (needsSet) {
|
|
266
|
-
res.headers.append(
|
|
267
|
-
"set-cookie",
|
|
268
|
-
`${cookieName}=${bucket}:${currentRatioPct}; Path=/; Max-Age=${maxAge}; Domain=${hostname}; SameSite=Lax`,
|
|
269
|
-
);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
return res;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* A `TransformStream` that rewrites every occurrence of `search` in a UTF-8 text
|
|
277
|
-
* stream, without ever holding the whole body in memory.
|
|
278
|
-
*
|
|
279
|
-
* Two hazards it exists to handle:
|
|
280
|
-
*
|
|
281
|
-
* - **A match straddling a chunk boundary.** Each pass holds back the last
|
|
282
|
-
* `search.length - 1` characters and prepends them to the next chunk. The
|
|
283
|
-
* held-back slice is taken from the RAW input, never from already-replaced
|
|
284
|
-
* output — otherwise a replacement ending in a prefix of `search` could join
|
|
285
|
-
* the next chunk and be replaced a second time.
|
|
286
|
-
* - **A multi-byte character split across chunks.** `TextDecoder` with
|
|
287
|
-
* `{ stream: true }` carries the partial code point across `decode` calls.
|
|
288
|
-
*
|
|
289
|
-
* Peak memory is one chunk plus `search.length - 1` characters, not the body.
|
|
290
|
-
*/
|
|
291
|
-
export function createReplaceStream(search: string, replace: string): TransformStream<Uint8Array, Uint8Array> {
|
|
292
|
-
const decoder = new TextDecoder("utf-8");
|
|
293
|
-
const encoder = new TextEncoder();
|
|
294
|
-
if (!search) return new TransformStream<Uint8Array, Uint8Array>();
|
|
295
|
-
const keep = search.length - 1;
|
|
296
|
-
let tail = "";
|
|
297
|
-
|
|
298
|
-
return new TransformStream<Uint8Array, Uint8Array>({
|
|
299
|
-
transform(chunk, controller) {
|
|
300
|
-
const buffer = tail + decoder.decode(chunk, { stream: true });
|
|
301
|
-
// Consume complete matches first (left to right, non-overlapping — same
|
|
302
|
-
// as replaceAll), then hold back only the last `search.length - 1` chars
|
|
303
|
-
// of what follows the last match: a not-yet-complete match can only
|
|
304
|
-
// start there. Cutting before consuming matches can slice a complete,
|
|
305
|
-
// self-overlapping match ("aaa" in "xaaaa") in half.
|
|
306
|
-
let end = 0;
|
|
307
|
-
for (let i = buffer.indexOf(search); i !== -1; i = buffer.indexOf(search, end)) {
|
|
308
|
-
end = i + search.length;
|
|
309
|
-
}
|
|
310
|
-
const cut = Math.max(end, buffer.length - keep);
|
|
311
|
-
tail = buffer.slice(cut);
|
|
312
|
-
const head = buffer.slice(0, cut);
|
|
313
|
-
if (head) controller.enqueue(encoder.encode(head.replaceAll(search, replace)));
|
|
314
|
-
},
|
|
315
|
-
flush(controller) {
|
|
316
|
-
const rest = tail + decoder.decode();
|
|
317
|
-
if (rest) controller.enqueue(encoder.encode(rest.replaceAll(search, replace)));
|
|
318
|
-
},
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Proxy a request to the fallback origin with full hostname rewriting.
|
|
324
|
-
*
|
|
325
|
-
* Rewrites:
|
|
326
|
-
* 1. URL hostname → fallback origin
|
|
327
|
-
* 2. Set-Cookie Domain → real hostname
|
|
328
|
-
* 3. Body text: fallback hostname → real hostname (for Fresh partial URLs)
|
|
329
|
-
* 4. Location header → real hostname
|
|
330
|
-
*
|
|
331
|
-
* **`redirect: "manual"` is critical.** The request body is forwarded as a
|
|
332
|
-
* stream (`duplex: "half"`) and is consumed by this first fetch. If the
|
|
333
|
-
* upstream returns a 301/302 and we let CF auto-follow, the runtime would
|
|
334
|
-
* try to replay the request and throw `Cannot reconstruct a Request with
|
|
335
|
-
* a used body.` Instead we forward the 3xx response to the client so the
|
|
336
|
-
* client (browser/curl) follows it on its own. The Location header is
|
|
337
|
-
* rewritten below so the next hop targets the real hostname.
|
|
338
|
-
*/
|
|
339
|
-
export async function proxyToFallback(
|
|
340
|
-
request: Request,
|
|
341
|
-
url: URL,
|
|
342
|
-
fallbackOrigin: string,
|
|
343
|
-
): Promise<Response> {
|
|
344
|
-
const target = new URL(url.toString());
|
|
345
|
-
target.hostname = fallbackOrigin;
|
|
346
|
-
|
|
347
|
-
// Strip hop-by-hop headers + Host before forwarding. Without this the
|
|
348
|
-
// upstream may close the connection (Connection: close) or get confused
|
|
349
|
-
// by Transfer-Encoding/Upgrade meant for the original CF↔client hop.
|
|
350
|
-
const headers = new Headers();
|
|
351
|
-
for (const [key, value] of request.headers.entries()) {
|
|
352
|
-
const lk = key.toLowerCase();
|
|
353
|
-
if (lk === "host") continue;
|
|
354
|
-
if (HOP_BY_HOP_HEADERS.has(lk)) continue;
|
|
355
|
-
headers.set(key, value);
|
|
356
|
-
}
|
|
357
|
-
headers.set("x-forwarded-host", url.hostname);
|
|
358
|
-
|
|
359
|
-
const init: RequestInit = {
|
|
360
|
-
method: request.method,
|
|
361
|
-
headers,
|
|
362
|
-
redirect: "manual",
|
|
363
|
-
};
|
|
364
|
-
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
365
|
-
init.body = request.body;
|
|
366
|
-
// @ts-expect-error -- needed for streaming body in Workers
|
|
367
|
-
init.duplex = "half";
|
|
368
|
-
}
|
|
369
|
-
const response = await fetch(target.toString(), init);
|
|
370
|
-
|
|
371
|
-
const ct = response.headers.get("content-type") ?? "";
|
|
372
|
-
const isText =
|
|
373
|
-
ct.includes("text/") || ct.includes("json") || ct.includes("javascript");
|
|
374
|
-
|
|
375
|
-
// Only rewrite text bodies on 2xx successful responses. Reading
|
|
376
|
-
// `response.text()` on a 3xx (forwarded redirect) or binary response
|
|
377
|
-
// would consume the stream needlessly and could throw on non-text
|
|
378
|
-
// content. The Location header is rewritten separately further down.
|
|
379
|
-
let body: BodyInit | null = response.body;
|
|
380
|
-
let rewrote = false;
|
|
381
|
-
if (
|
|
382
|
-
isText &&
|
|
383
|
-
response.body &&
|
|
384
|
-
response.status >= 200 &&
|
|
385
|
-
response.status < 300 &&
|
|
386
|
-
fallbackOrigin.length > 0
|
|
387
|
-
) {
|
|
388
|
-
// Streamed, not buffered. `response.text()` held the entire body as a
|
|
389
|
-
// JS string (two bytes per character) plus the replaced copy — multiple
|
|
390
|
-
// megabytes of a 128MB isolate budget for a hostname substitution.
|
|
391
|
-
body = response.body.pipeThrough(createReplaceStream(fallbackOrigin, url.hostname));
|
|
392
|
-
rewrote = true;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
const rewritten = new Response(body, response);
|
|
396
|
-
|
|
397
|
-
// The rewrite changes the body length, so the upstream `content-length` is
|
|
398
|
-
// now a lie — and a streamed body has no length to state. (This was already
|
|
399
|
-
// wrong on the buffered path; it just never had to be chunked.)
|
|
400
|
-
if (rewrote) rewritten.headers.delete("content-length");
|
|
401
|
-
|
|
402
|
-
const setCookies = response.headers.getSetCookie?.() ?? [];
|
|
403
|
-
if (setCookies.length > 0) {
|
|
404
|
-
rewritten.headers.delete("set-cookie");
|
|
405
|
-
for (const cookie of setCookies) {
|
|
406
|
-
rewritten.headers.append(
|
|
407
|
-
"set-cookie",
|
|
408
|
-
cookie.replace(
|
|
409
|
-
new RegExp(
|
|
410
|
-
`Domain=\\.?${fallbackOrigin.replace(/\./g, "\\.")}`,
|
|
411
|
-
"gi",
|
|
412
|
-
),
|
|
413
|
-
`Domain=.${url.hostname}`,
|
|
414
|
-
),
|
|
415
|
-
);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
const location = response.headers.get("location");
|
|
420
|
-
if (location?.includes(fallbackOrigin)) {
|
|
421
|
-
rewritten.headers.set(
|
|
422
|
-
"location",
|
|
423
|
-
location.replaceAll(fallbackOrigin, url.hostname),
|
|
424
|
-
);
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
return rewritten;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
// ---------------------------------------------------------------------------
|
|
431
|
-
// Main wrapper
|
|
432
|
-
// ---------------------------------------------------------------------------
|
|
433
|
-
|
|
434
|
-
/**
|
|
435
|
-
* Wrap a Deco worker entry with A/B testing support.
|
|
436
|
-
*
|
|
437
|
-
* Reads config from Cloudflare KV by hostname, assigns buckets,
|
|
438
|
-
* and proxies fallback traffic to the legacy origin.
|
|
439
|
-
*
|
|
440
|
-
* When no KV binding is available or no config exists for the hostname,
|
|
441
|
-
* all traffic goes directly to the inner handler (no A/B).
|
|
442
|
-
*/
|
|
443
|
-
export function withABTesting(
|
|
444
|
-
handler: WorkerHandler,
|
|
445
|
-
config: ABTestConfig = {},
|
|
446
|
-
): WorkerHandler {
|
|
447
|
-
const {
|
|
448
|
-
kvBinding = "SITES_KV",
|
|
449
|
-
cookieName = "_deco_bucket",
|
|
450
|
-
cookieMaxAge = 60 * 60 * 24 * 365,
|
|
451
|
-
circuitBreaker = true,
|
|
452
|
-
shouldBypassAB,
|
|
453
|
-
preHandler,
|
|
454
|
-
} = config;
|
|
455
|
-
|
|
456
|
-
return {
|
|
457
|
-
async fetch(
|
|
458
|
-
request: Request,
|
|
459
|
-
env: Record<string, unknown>,
|
|
460
|
-
ctx: WorkerExecutionContext,
|
|
461
|
-
): Promise<Response> {
|
|
462
|
-
const url = new URL(request.url);
|
|
463
|
-
|
|
464
|
-
// Pre-handler (e.g. CMS redirects) — runs before A/B
|
|
465
|
-
if (preHandler) {
|
|
466
|
-
const pre = await preHandler(request, url);
|
|
467
|
-
if (pre) return pre;
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
const kv = env[kvBinding] as KVNamespace | undefined;
|
|
471
|
-
if (!kv) {
|
|
472
|
-
return handler.fetch(request, env, ctx);
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
const siteConfig = await kv.get<SiteConfig>(url.hostname, "json");
|
|
476
|
-
if (!siteConfig?.fallbackOrigin) {
|
|
477
|
-
return handler.fetch(request, env, ctx);
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
// Bypass A/B for certain paths (e.g. checkout, API)
|
|
481
|
-
if (shouldBypassAB?.(request, url)) {
|
|
482
|
-
return handler.fetch(request, env, ctx);
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
const ratio = siteConfig.abTest?.ratio ?? 0;
|
|
486
|
-
const bucket = getStableBucket(request, ratio, url, cookieName);
|
|
487
|
-
|
|
488
|
-
// Tee the request so the outer `catch` below can still pass the
|
|
489
|
-
// original (with body intact) to `handler.fetch` if proxyToFallback
|
|
490
|
-
// somehow throws after consuming the body. `Request.clone()` is
|
|
491
|
-
// safe in CF Workers — it tees the underlying stream.
|
|
492
|
-
const fallbackRequest = request.clone();
|
|
493
|
-
|
|
494
|
-
try {
|
|
495
|
-
if (bucket === "fallback") {
|
|
496
|
-
const response = await proxyToFallback(
|
|
497
|
-
fallbackRequest,
|
|
498
|
-
url,
|
|
499
|
-
siteConfig.fallbackOrigin,
|
|
500
|
-
);
|
|
501
|
-
return tagBucket(
|
|
502
|
-
response,
|
|
503
|
-
bucket,
|
|
504
|
-
url.hostname,
|
|
505
|
-
request,
|
|
506
|
-
ratio,
|
|
507
|
-
cookieName,
|
|
508
|
-
cookieMaxAge,
|
|
509
|
-
);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
// Worker bucket
|
|
513
|
-
try {
|
|
514
|
-
const response = await handler.fetch(request, env, ctx);
|
|
515
|
-
return tagBucket(
|
|
516
|
-
response,
|
|
517
|
-
bucket,
|
|
518
|
-
url.hostname,
|
|
519
|
-
request,
|
|
520
|
-
ratio,
|
|
521
|
-
cookieName,
|
|
522
|
-
cookieMaxAge,
|
|
523
|
-
);
|
|
524
|
-
} catch (err) {
|
|
525
|
-
if (!circuitBreaker) throw err;
|
|
526
|
-
console.error(
|
|
527
|
-
"[A/B] Worker error, circuit breaker → fallback:",
|
|
528
|
-
err,
|
|
529
|
-
);
|
|
530
|
-
// Use the teed clone — handler.fetch above may have already
|
|
531
|
-
// consumed the original request body before throwing.
|
|
532
|
-
const response = await proxyToFallback(
|
|
533
|
-
fallbackRequest,
|
|
534
|
-
url,
|
|
535
|
-
siteConfig.fallbackOrigin,
|
|
536
|
-
);
|
|
537
|
-
return tagBucket(
|
|
538
|
-
response,
|
|
539
|
-
"fallback",
|
|
540
|
-
url.hostname,
|
|
541
|
-
request,
|
|
542
|
-
ratio,
|
|
543
|
-
cookieName,
|
|
544
|
-
cookieMaxAge,
|
|
545
|
-
);
|
|
546
|
-
}
|
|
547
|
-
} catch (err) {
|
|
548
|
-
console.error(
|
|
549
|
-
"[A/B] Fatal proxy error, passing through to handler:",
|
|
550
|
-
err,
|
|
551
|
-
);
|
|
552
|
-
return handler.fetch(request, env, ctx);
|
|
553
|
-
}
|
|
554
|
-
},
|
|
555
|
-
};
|
|
556
|
-
}
|
package/src/sdk/analytics.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Analytics utilities using the data-event attribute pattern.
|
|
3
|
-
* Compatible with Deco's analytics pipeline and GTM.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export interface DataEventParams {
|
|
7
|
-
on: "view" | "click" | "change";
|
|
8
|
-
event: { name: string; params?: Record<string, unknown> };
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function useSendEvent({ on, event }: DataEventParams) {
|
|
12
|
-
return {
|
|
13
|
-
"data-event": encodeURIComponent(JSON.stringify(event)),
|
|
14
|
-
"data-event-trigger": on,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Inline script that observes data-event attributes and dispatches events.
|
|
20
|
-
* Inject once in the root layout via a <script> tag.
|
|
21
|
-
*
|
|
22
|
-
* Prerender-safe: while a Speculation Rules prerender is running the document
|
|
23
|
-
* is hidden and its IntersectionObserver could fire phantom `view` events, so
|
|
24
|
-
* all init is deferred until the page is actually activated. On a normal load
|
|
25
|
-
* `document.prerendering` is false and it runs immediately (no behavior change).
|
|
26
|
-
*/
|
|
27
|
-
export const ANALYTICS_SCRIPT = `
|
|
28
|
-
(function() {
|
|
29
|
-
function start() {
|
|
30
|
-
function dispatch(event) {
|
|
31
|
-
if (window.dataLayer) {
|
|
32
|
-
window.dataLayer.push({ event: event.name, ...event.params });
|
|
33
|
-
}
|
|
34
|
-
if (window.DECO && window.DECO.events) {
|
|
35
|
-
window.DECO.events.dispatch(event);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function getEvent(el) {
|
|
40
|
-
var raw = el.getAttribute("data-event");
|
|
41
|
-
if (!raw) return null;
|
|
42
|
-
try { return JSON.parse(decodeURIComponent(raw)); } catch(e) { return null; }
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
var viewObserver = new IntersectionObserver(function(entries) {
|
|
46
|
-
entries.forEach(function(entry) {
|
|
47
|
-
if (entry.isIntersecting) {
|
|
48
|
-
var event = getEvent(entry.target);
|
|
49
|
-
if (event) dispatch(event);
|
|
50
|
-
viewObserver.unobserve(entry.target);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}, { threshold: 0.5 });
|
|
54
|
-
|
|
55
|
-
document.addEventListener("click", function(e) {
|
|
56
|
-
var el = e.target.closest("[data-event-trigger='click']");
|
|
57
|
-
if (el) {
|
|
58
|
-
var event = getEvent(el);
|
|
59
|
-
if (event) dispatch(event);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
function observeAll() {
|
|
64
|
-
document.querySelectorAll("[data-event-trigger='view']").forEach(function(el) {
|
|
65
|
-
viewObserver.observe(el);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
observeAll();
|
|
70
|
-
var mo = new MutationObserver(observeAll);
|
|
71
|
-
if (typeof requestIdleCallback !== 'undefined') {
|
|
72
|
-
requestIdleCallback(function() { mo.observe(document.body, { childList: true, subtree: true }); });
|
|
73
|
-
} else {
|
|
74
|
-
setTimeout(function() { mo.observe(document.body, { childList: true, subtree: true }); }, 0);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (document.prerendering) {
|
|
79
|
-
document.addEventListener('prerenderingchange', start, { once: true });
|
|
80
|
-
} else {
|
|
81
|
-
start();
|
|
82
|
-
}
|
|
83
|
-
})();
|
|
84
|
-
`;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Dev-only guardrail for Speculation Rules. While a prerender is running (the
|
|
88
|
-
* hidden pre-navigation document), NOTHING analytics-related should hit the
|
|
89
|
-
* network — otherwise the pageview/event is counted for a navigation that may
|
|
90
|
-
* never happen. This script patches the common egress sinks (sendBeacon, fetch,
|
|
91
|
-
* injected tracker <script>/<img>) and `console.error`s the offending call so
|
|
92
|
-
* the dev knows exactly which loader still needs a `document.prerendering`
|
|
93
|
-
* guard before activating speculation rules on that site.
|
|
94
|
-
*
|
|
95
|
-
* Emit only in dev (see DecoRootLayout) — it self-disables outside prerender,
|
|
96
|
-
* so it is inert on real navigations.
|
|
97
|
-
*/
|
|
98
|
-
export const SPECULATION_DEV_WARN_SCRIPT = `
|
|
99
|
-
(function(){
|
|
100
|
-
if (!document.prerendering) return;
|
|
101
|
-
var TRACKERS = /googletagmanager\\.com|google-analytics\\.com|analytics\\.google|gtag\\/js|gtm\\.js|connect\\.facebook\\.net|analytics\\.tiktok|hotjar|clarity\\.ms|doubleclick|\\/sgtm|sgtm\\.|\\/collect(\\?|$)|\\/j\\.php|vwo|tr\\?id=/i;
|
|
102
|
-
function err(what, detail){
|
|
103
|
-
console.error(
|
|
104
|
-
'[deco][speculation] ' + what + ' ran during prerender and will double-count when the page activates. ' +
|
|
105
|
-
'Guard its loader with: if (document.prerendering) { document.addEventListener("prerenderingchange", init, { once: true }); } else { init(); }',
|
|
106
|
-
detail
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
var sb = navigator.sendBeacon;
|
|
110
|
-
if (sb) navigator.sendBeacon = function(url){ err('navigator.sendBeacon', url); return sb.apply(navigator, arguments); };
|
|
111
|
-
var of = window.fetch;
|
|
112
|
-
if (of) window.fetch = function(input){
|
|
113
|
-
var u = (input && input.url) || input;
|
|
114
|
-
if (TRACKERS.test(String(u))) err('fetch()', u);
|
|
115
|
-
return of.apply(window, arguments);
|
|
116
|
-
};
|
|
117
|
-
var mo = new MutationObserver(function(muts){
|
|
118
|
-
for (var i=0;i<muts.length;i++){
|
|
119
|
-
var nodes = muts[i].addedNodes || [];
|
|
120
|
-
for (var j=0;j<nodes.length;j++){
|
|
121
|
-
var n = nodes[j];
|
|
122
|
-
if (!n || !n.tagName) continue;
|
|
123
|
-
if (n.tagName === 'SCRIPT' && n.src && TRACKERS.test(n.src)) err('tracker <script> load', n.src);
|
|
124
|
-
else if (n.tagName === 'IMG' && n.src && TRACKERS.test(n.src)) err('tracker pixel <img>', n.src);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
mo.observe(document.documentElement, { childList: true, subtree: true });
|
|
129
|
-
document.addEventListener('prerenderingchange', function(){
|
|
130
|
-
mo.disconnect();
|
|
131
|
-
if (sb) navigator.sendBeacon = sb;
|
|
132
|
-
if (of) window.fetch = of;
|
|
133
|
-
}, { once: true });
|
|
134
|
-
})();
|
|
135
|
-
`;
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Returns a GTM container snippet. Returns empty string if no containerId.
|
|
139
|
-
*
|
|
140
|
-
* Prerender-safe: container load is deferred until the page is activated so a
|
|
141
|
-
* Speculation Rules prerender that never activates can't fire GTM (pageview /
|
|
142
|
-
* tags) in the hidden document. No-op guard on normal loads.
|
|
143
|
-
*/
|
|
144
|
-
export function gtmScript(containerId?: string): string {
|
|
145
|
-
if (!containerId) return "";
|
|
146
|
-
return `(function(){function boot(){(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','${containerId}');}if(document.prerendering){document.addEventListener('prerenderingchange',boot,{once:true});}else{boot();}})();`;
|
|
147
|
-
}
|