@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
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Instrumented fetch wrapper that adds logging and tracing to outbound HTTP calls.
|
|
3
|
-
*
|
|
4
|
-
* Designed to be wired into commerce clients (VTEX, Shopify) so all
|
|
5
|
-
* API calls become visible in dev logs and production traces.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* import { createInstrumentedFetch } from "@decocms/start/sdk/instrumentedFetch";
|
|
10
|
-
*
|
|
11
|
-
* const vtexFetch = createInstrumentedFetch("vtex");
|
|
12
|
-
*
|
|
13
|
-
* // Use it instead of global fetch:
|
|
14
|
-
* const response = await vtexFetch("https://account.vtexcommercestable.com.br/api/...");
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { DEFAULT_FETCH_TIMEOUT_MS, withTimeoutSignal } from "./fetchTimeout";
|
|
19
|
-
import { logger } from "./logger";
|
|
20
|
-
import { getTracer, injectTraceContext } from "./observability";
|
|
21
|
-
import { redactUrl } from "./urlRedaction";
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Cloudflare / VTEX response headers that operators want to see as span
|
|
25
|
-
* attributes when debugging cache behavior. Mirrors `applyCustomAttributesOnSpan`
|
|
26
|
-
* in `deco-cx/deco/observability/otel/`.
|
|
27
|
-
*/
|
|
28
|
-
const CACHE_HEADERS_TO_SPAN: Array<{ header: string; attr: string }> = [
|
|
29
|
-
{ header: "cf-cache-status", attr: "cf.cache.status" },
|
|
30
|
-
{ header: "cf-ray", attr: "cf.ray" },
|
|
31
|
-
{ header: "x-vtex-io-cluster-id", attr: "vtex.io.cluster.id" },
|
|
32
|
-
{ header: "x-edge-cache-status", attr: "edge.cache.status" },
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
const TRUE_LITERAL = "true";
|
|
36
|
-
|
|
37
|
-
function envFlag(name: string): boolean {
|
|
38
|
-
const env = typeof globalThis.process !== "undefined" ? globalThis.process.env : undefined;
|
|
39
|
-
return env?.[name] === TRUE_LITERAL;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface FetchInstrumentationOptions {
|
|
43
|
-
/** Tag for log/trace grouping (e.g., "vtex", "shopify"). */
|
|
44
|
-
name: string;
|
|
45
|
-
/** Enable request/response logging. Default: true in development. */
|
|
46
|
-
logging?: boolean;
|
|
47
|
-
/** Enable tracing via the configured TracerAdapter. Default: true. */
|
|
48
|
-
tracing?: boolean;
|
|
49
|
-
/** Callback when a request completes (for custom metrics). */
|
|
50
|
-
onComplete?: (info: FetchMetrics) => void;
|
|
51
|
-
/**
|
|
52
|
-
* Underlying fetch implementation to wrap. Defaults to `globalThis.fetch`.
|
|
53
|
-
* Use this when the client already has a custom fetch (e.g. with cookies,
|
|
54
|
-
* custom headers, or a proxy) that must be preserved.
|
|
55
|
-
*/
|
|
56
|
-
baseFetch?: typeof fetch;
|
|
57
|
-
/**
|
|
58
|
-
* Query parameter names whose value should NOT be redacted in logs +
|
|
59
|
-
* span attributes. Default: empty — every value is redacted. Use for
|
|
60
|
-
* structural params that don't carry secrets, e.g. `["page", "sort"]`.
|
|
61
|
-
* See `redactUrl` in `./urlRedaction.ts`.
|
|
62
|
-
*/
|
|
63
|
-
keepQueryKeys?: ReadonlyArray<string>;
|
|
64
|
-
/**
|
|
65
|
-
* Inject the active span's W3C `traceparent` header onto outbound
|
|
66
|
-
* requests so downstream services that participate in OTel can join
|
|
67
|
-
* our trace. Default: true. Set to false for calls to endpoints that
|
|
68
|
-
* reject unknown headers (rare).
|
|
69
|
-
*/
|
|
70
|
-
injectTraceparent?: boolean;
|
|
71
|
-
/**
|
|
72
|
-
* Fallback operation name used when a call doesn't supply one via
|
|
73
|
-
* `init.operation`. Span name becomes `${name}.${defaultOperation}`.
|
|
74
|
-
* Useful when a client is single-purpose, e.g. a Resend client where
|
|
75
|
-
* every call is the literal `"emails.send"`. Default: not set (the
|
|
76
|
-
* resolver below runs next, then the literal `"fetch"`).
|
|
77
|
-
*/
|
|
78
|
-
defaultOperation?: string;
|
|
79
|
-
/**
|
|
80
|
-
* URL-derived operation router. Called when neither `init.operation`
|
|
81
|
-
* nor `defaultOperation` is set. Receives the rawUrl + method, returns
|
|
82
|
-
* an operation string or `undefined` to opt out (in which case the
|
|
83
|
-
* span falls back to `${name}.fetch`). Centralizes the long-tail of
|
|
84
|
-
* commerce endpoints that don't merit a hand-authored operation name
|
|
85
|
-
* at the call site while staying visibly debuggable in spans.
|
|
86
|
-
*
|
|
87
|
-
* Resolution precedence:
|
|
88
|
-
* `init.operation` ?? `defaultOperation` ?? `resolveOperation(url, method)` ?? `"fetch"`
|
|
89
|
-
*/
|
|
90
|
-
resolveOperation?: (url: string, method: string) => string | undefined;
|
|
91
|
-
/**
|
|
92
|
-
* Abort a request after this many ms unless it settles first, via
|
|
93
|
-
* `AbortSignal.timeout` composed with any signal the caller already
|
|
94
|
-
* passed in `init.signal`. Default: {@link DEFAULT_FETCH_TIMEOUT_MS}
|
|
95
|
-
* (10s). Pass `0` or `Infinity` to disable for this integration (e.g. a
|
|
96
|
-
* client that intentionally makes long-lived/streaming requests).
|
|
97
|
-
* Override per-call via `init.timeoutMs`.
|
|
98
|
-
*/
|
|
99
|
-
timeoutMs?: number;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export interface FetchMetrics {
|
|
103
|
-
name: string;
|
|
104
|
-
url: string;
|
|
105
|
-
method: string;
|
|
106
|
-
status: number;
|
|
107
|
-
durationMs: number;
|
|
108
|
-
cached: boolean;
|
|
109
|
-
/** Resolved operation name (post-precedence-resolution). */
|
|
110
|
-
operation: string;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Init shape accepted by an instrumented fetch. Strictly a superset of
|
|
115
|
-
* `RequestInit` (the only extra property is optional), so an
|
|
116
|
-
* `InstrumentedFetch` is assignable wherever a `typeof fetch` is
|
|
117
|
-
* expected — existing callers that don't author an operation string
|
|
118
|
-
* keep compiling unchanged.
|
|
119
|
-
*/
|
|
120
|
-
export type InstrumentedFetchInit = RequestInit & {
|
|
121
|
-
/**
|
|
122
|
-
* Per-call operation override. Produces a span named
|
|
123
|
-
* `${name}.${operation}` instead of the default `${name}.fetch`.
|
|
124
|
-
* Stripped from the init before reaching `baseFetch` so it never
|
|
125
|
-
* surfaces to the network as a request property.
|
|
126
|
-
*/
|
|
127
|
-
operation?: string;
|
|
128
|
-
/**
|
|
129
|
-
* Per-call timeout override (ms). See
|
|
130
|
-
* {@link FetchInstrumentationOptions.timeoutMs}. Stripped from the init
|
|
131
|
-
* before reaching `baseFetch`.
|
|
132
|
-
*/
|
|
133
|
-
timeoutMs?: number;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Fetch with an optional per-call `operation` extension on init. Returned
|
|
138
|
-
* by `createInstrumentedFetch`. Assignable to `typeof fetch` because the
|
|
139
|
-
* extra property is optional.
|
|
140
|
-
*/
|
|
141
|
-
export type InstrumentedFetch = (
|
|
142
|
-
input: RequestInfo | URL,
|
|
143
|
-
init?: InstrumentedFetchInit,
|
|
144
|
-
) => Promise<Response>;
|
|
145
|
-
|
|
146
|
-
const isDev =
|
|
147
|
-
typeof globalThis.process !== "undefined" && globalThis.process.env?.NODE_ENV === "development";
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Creates a fetch wrapper that instruments all requests for a given integration.
|
|
151
|
-
*/
|
|
152
|
-
export function createInstrumentedFetch(
|
|
153
|
-
nameOrOptions: string | FetchInstrumentationOptions,
|
|
154
|
-
): InstrumentedFetch {
|
|
155
|
-
const options: FetchInstrumentationOptions =
|
|
156
|
-
typeof nameOrOptions === "string" ? { name: nameOrOptions } : nameOrOptions;
|
|
157
|
-
|
|
158
|
-
const {
|
|
159
|
-
name,
|
|
160
|
-
logging = isDev,
|
|
161
|
-
tracing = true,
|
|
162
|
-
onComplete,
|
|
163
|
-
baseFetch = globalThis.fetch,
|
|
164
|
-
keepQueryKeys,
|
|
165
|
-
injectTraceparent = true,
|
|
166
|
-
defaultOperation,
|
|
167
|
-
resolveOperation,
|
|
168
|
-
timeoutMs = DEFAULT_FETCH_TIMEOUT_MS,
|
|
169
|
-
} = options;
|
|
170
|
-
|
|
171
|
-
return async (input: RequestInfo | URL, init?: InstrumentedFetchInit): Promise<Response> => {
|
|
172
|
-
const rawUrl =
|
|
173
|
-
typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
|
174
|
-
const safeUrl = redactUrl(rawUrl, { keepQueryKeys });
|
|
175
|
-
// Per the Fetch spec, when both a Request and an `init.method` are
|
|
176
|
-
// passed to `fetch()`, init.method replaces the Request's method.
|
|
177
|
-
// When init.method is omitted, the Request's method survives. So:
|
|
178
|
-
//
|
|
179
|
-
// - explicit `init.method` wins
|
|
180
|
-
// - else, if `input` is a Request, fall back to `input.method`
|
|
181
|
-
// - else, "GET" (matches `new Request(url).method` default)
|
|
182
|
-
//
|
|
183
|
-
// Without this, a caller like `fetch(new Request(url, { method: "POST" }))`
|
|
184
|
-
// would surface as a GET in `http.method` on the span AND in the URL
|
|
185
|
-
// router's `resolveOperation(url, method)` callback — mislabeling
|
|
186
|
-
// POST traffic as GET in dashboards and routing decisions.
|
|
187
|
-
const method =
|
|
188
|
-
init?.method ??
|
|
189
|
-
(typeof input !== "string" && !(input instanceof URL) ? input.method : undefined) ??
|
|
190
|
-
"GET";
|
|
191
|
-
const startTime = performance.now();
|
|
192
|
-
|
|
193
|
-
// Resolve the operation BEFORE we touch init, then strip `operation`
|
|
194
|
-
// off init so it never reaches `baseFetch` as an unknown RequestInit
|
|
195
|
-
// property (some runtimes warn / future runtimes might reject).
|
|
196
|
-
const explicitOp = init?.operation;
|
|
197
|
-
const effectiveTimeoutMs = init?.timeoutMs ?? timeoutMs;
|
|
198
|
-
let initForFetch: RequestInit | undefined = init;
|
|
199
|
-
if (init && ("operation" in init || "timeoutMs" in init)) {
|
|
200
|
-
const { operation: _drop, timeoutMs: _drop2, ...rest } = init;
|
|
201
|
-
initForFetch = rest;
|
|
202
|
-
}
|
|
203
|
-
const operation =
|
|
204
|
-
explicitOp ?? defaultOperation ?? resolveOperation?.(rawUrl, method) ?? "fetch";
|
|
205
|
-
const spanName = `${name}.${operation}`;
|
|
206
|
-
|
|
207
|
-
// Inject W3C traceparent onto outbound requests so upstream services
|
|
208
|
-
// that participate in OTel join our trace. No-op when no span is
|
|
209
|
-
// active; never throws (see `injectTraceContext`).
|
|
210
|
-
//
|
|
211
|
-
// Header semantics follow the Fetch spec: when both a Request and an
|
|
212
|
-
// `init` are passed to `fetch()`, `init.headers` REPLACES the
|
|
213
|
-
// Request's headers — they do NOT union. So:
|
|
214
|
-
//
|
|
215
|
-
// - If the caller supplied `init.headers`, start from those (the
|
|
216
|
-
// caller's explicit choice wins; we don't smuggle in Request
|
|
217
|
-
// headers behind their back).
|
|
218
|
-
// - Otherwise, if `input` is a Request, start from its headers (so
|
|
219
|
-
// its existing headers reach the wire alongside the injected
|
|
220
|
-
// traceparent).
|
|
221
|
-
// - Otherwise, start empty.
|
|
222
|
-
//
|
|
223
|
-
// In all cases, we mutate a fresh Headers object and pass it via the
|
|
224
|
-
// returned `init` — Request objects are immutable in modern runtimes
|
|
225
|
-
// and accepting `RequestInfo` means we may not own them.
|
|
226
|
-
let finalInit: RequestInit | undefined = initForFetch;
|
|
227
|
-
if (injectTraceparent) {
|
|
228
|
-
const base =
|
|
229
|
-
initForFetch?.headers !== undefined
|
|
230
|
-
? initForFetch.headers
|
|
231
|
-
: typeof input !== "string" && !(input instanceof URL)
|
|
232
|
-
? input.headers
|
|
233
|
-
: undefined;
|
|
234
|
-
const headers = new Headers(base ?? undefined);
|
|
235
|
-
injectTraceContext(headers);
|
|
236
|
-
finalInit = { ...(initForFetch ?? {}), headers };
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
finalInit = {
|
|
240
|
-
...(finalInit ?? {}),
|
|
241
|
-
signal: withTimeoutSignal(finalInit?.signal, effectiveTimeoutMs),
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
const doFetch = async (): Promise<Response> => {
|
|
245
|
-
if (logging) {
|
|
246
|
-
console.log(`[${name}] ${method} ${truncateUrl(safeUrl)}`);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
const response = await baseFetch(input, finalInit);
|
|
250
|
-
const durationMs = performance.now() - startTime;
|
|
251
|
-
const cached = response.headers.get("x-cache") === "HIT";
|
|
252
|
-
|
|
253
|
-
if (logging) {
|
|
254
|
-
const color = response.ok ? "\x1b[32m" : "\x1b[31m";
|
|
255
|
-
console.log(
|
|
256
|
-
`[${name}] ${color}${response.status}\x1b[0m ${method} ${truncateUrl(safeUrl)} ${durationMs.toFixed(0)}ms${cached ? " (cached)" : ""}`,
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
// Structured outgoing-fetch breadcrumb. Same field shape as the Fresh
|
|
261
|
-
// `@deco/deco/o11y` impl so log pipelines built off the old stack
|
|
262
|
-
// keep working unchanged. Off by default to avoid log explosion;
|
|
263
|
-
// enable with `OTEL_LOG_OUTGOING_FETCH=true`.
|
|
264
|
-
if (envFlag("OTEL_LOG_OUTGOING_FETCH")) {
|
|
265
|
-
let host = "";
|
|
266
|
-
let path = "";
|
|
267
|
-
try {
|
|
268
|
-
const u = new URL(rawUrl);
|
|
269
|
-
host = u.host;
|
|
270
|
-
path = u.pathname;
|
|
271
|
-
} catch {
|
|
272
|
-
/* unparseable URL — leave host/path blank */
|
|
273
|
-
}
|
|
274
|
-
logger.info("outgoing fetch", {
|
|
275
|
-
app: name,
|
|
276
|
-
host,
|
|
277
|
-
path,
|
|
278
|
-
method,
|
|
279
|
-
status: response.status,
|
|
280
|
-
ok: response.ok,
|
|
281
|
-
durationMs: Math.round(durationMs),
|
|
282
|
-
cached,
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
onComplete?.({
|
|
287
|
-
name,
|
|
288
|
-
url: safeUrl,
|
|
289
|
-
method,
|
|
290
|
-
status: response.status,
|
|
291
|
-
durationMs,
|
|
292
|
-
cached,
|
|
293
|
-
operation,
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
return response;
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
if (tracing) {
|
|
300
|
-
const tracer = getTracer();
|
|
301
|
-
if (tracer) {
|
|
302
|
-
const span = tracer.startSpan(spanName, {
|
|
303
|
-
"http.method": method,
|
|
304
|
-
// Redacted URL on the span attribute — once a CF Trace lands in
|
|
305
|
-
// the dashboard, we can't redact retroactively.
|
|
306
|
-
"http.url": safeUrl,
|
|
307
|
-
"fetch.integration": name,
|
|
308
|
-
// Stamp the resolved operation so it's queryable independent of
|
|
309
|
-
// span name (e.g. "GROUP BY SpanAttributes['fetch.operation']").
|
|
310
|
-
"fetch.operation": operation,
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
try {
|
|
314
|
-
const response = await doFetch();
|
|
315
|
-
// Promote CF / VTEX cache headers as span attributes — the plan
|
|
316
|
-
// calls out these four. `@microlabs/otel-cf-workers` does not
|
|
317
|
-
// expose the response inside its own fetch span lifecycle, so
|
|
318
|
-
// capturing them here on our wrapper span is the practical
|
|
319
|
-
// place to do it.
|
|
320
|
-
for (const { header, attr } of CACHE_HEADERS_TO_SPAN) {
|
|
321
|
-
const value = response.headers.get(header);
|
|
322
|
-
if (value) span.setAttribute?.(attr, value);
|
|
323
|
-
}
|
|
324
|
-
span.setAttribute?.("http.status_code", response.status);
|
|
325
|
-
if (response.status >= 400) {
|
|
326
|
-
span.setError?.(new Error(`HTTP ${response.status} ${response.statusText}`));
|
|
327
|
-
}
|
|
328
|
-
span.end();
|
|
329
|
-
return response;
|
|
330
|
-
} catch (error) {
|
|
331
|
-
span.setError?.(error);
|
|
332
|
-
span.end();
|
|
333
|
-
throw error;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
return doFetch();
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
function truncateUrl(url: string, maxLen = 120): string {
|
|
343
|
-
if (url.length <= maxLen) return url;
|
|
344
|
-
return url.slice(0, maxLen - 3) + "...";
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Wraps an existing fetch function with logging and tracing instrumentation.
|
|
349
|
-
* Unlike `createInstrumentedFetch`, this preserves the original fetch's
|
|
350
|
-
* behavior (custom headers, cookies, proxy logic) and adds observability on top.
|
|
351
|
-
*
|
|
352
|
-
* Accepts the same options as `createInstrumentedFetch` (sans `name` and
|
|
353
|
-
* `baseFetch`, which are positional), so callers can supply
|
|
354
|
-
* `defaultOperation` / `resolveOperation` here as well.
|
|
355
|
-
*/
|
|
356
|
-
export function instrumentFetch(
|
|
357
|
-
originalFetch: typeof fetch,
|
|
358
|
-
name: string,
|
|
359
|
-
options?: Omit<FetchInstrumentationOptions, "name" | "baseFetch">,
|
|
360
|
-
): InstrumentedFetch {
|
|
361
|
-
return createInstrumentedFetch({ ...(options ?? {}), name, baseFetch: originalFetch });
|
|
362
|
-
}
|
package/src/sdk/invoke.ts
DELETED
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Typed invoke proxies for client-side RPC to deco loaders/actions.
|
|
3
|
-
*
|
|
4
|
-
* Two flavors:
|
|
5
|
-
*
|
|
6
|
-
* 1. `createInvokeProxy<T>()` — flat keys (e.g. `invoke["vtex/loaders/productList.ts"](props)`)
|
|
7
|
-
* 2. `createAppInvoke<T>()` — nested keys (e.g. `invoke.vtex.actions.checkout.addItemsToCart(props)`)
|
|
8
|
-
*
|
|
9
|
-
* Both POST to `/deco/invoke/{key}` under the hood.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* // Flat proxy (legacy):
|
|
14
|
-
* const invoke = createInvokeProxy<Loaders>();
|
|
15
|
-
* await invoke["vtex/loaders/productList.ts"]({ query: "shoes" });
|
|
16
|
-
*
|
|
17
|
-
* // Nested proxy (recommended):
|
|
18
|
-
* const invoke = createAppInvoke();
|
|
19
|
-
* await invoke.vtex.actions.checkout.addItemsToCart({ orderFormId, orderItems });
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
export type InvokeProxy<TLoaders extends Record<string, (props: any) => Promise<any>>> = {
|
|
24
|
-
[K in keyof TLoaders]: TLoaders[K] extends (props: infer P) => Promise<infer R>
|
|
25
|
-
? (props: P) => Promise<R>
|
|
26
|
-
: never;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Creates a proxy that turns loader key access into fetch calls to `/deco/invoke/:key`.
|
|
31
|
-
*/
|
|
32
|
-
export function createInvokeProxy<TLoaders extends Record<string, (props: any) => Promise<any>>>(
|
|
33
|
-
basePath = "/deco/invoke",
|
|
34
|
-
): InvokeProxy<TLoaders> {
|
|
35
|
-
return new Proxy({} as InvokeProxy<TLoaders>, {
|
|
36
|
-
get(_target, prop: string) {
|
|
37
|
-
return async (props: unknown) => {
|
|
38
|
-
const url = `${basePath}/${encodeURIComponent(prop)}`;
|
|
39
|
-
const response = await fetch(url, {
|
|
40
|
-
method: "POST",
|
|
41
|
-
headers: { "Content-Type": "application/json" },
|
|
42
|
-
body: JSON.stringify(props ?? {}),
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
if (!response.ok) {
|
|
46
|
-
const error = await response.json().catch(() => ({ error: response.statusText }));
|
|
47
|
-
throw new Error(
|
|
48
|
-
`Invoke ${prop} failed (${response.status}): ${(error as any).error || response.statusText}`,
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return response.json();
|
|
53
|
-
};
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Batch invoke multiple loaders in a single request.
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```ts
|
|
63
|
-
* const results = await batchInvoke("/deco/invoke", {
|
|
64
|
-
* products: { __resolveType: "vtex/loaders/productList.ts", query: "shoes" },
|
|
65
|
-
* details: { __resolveType: "vtex/loaders/productDetailsPage.ts", slug: "shoe-1" },
|
|
66
|
-
* });
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
export async function batchInvoke<T extends Record<string, unknown>>(
|
|
70
|
-
basePath: string,
|
|
71
|
-
payloads: T,
|
|
72
|
-
): Promise<{ [K in keyof T]: unknown }> {
|
|
73
|
-
const response = await fetch(basePath, {
|
|
74
|
-
method: "POST",
|
|
75
|
-
headers: { "Content-Type": "application/json" },
|
|
76
|
-
body: JSON.stringify(payloads),
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
if (!response.ok) {
|
|
80
|
-
throw new Error(`Batch invoke failed (${response.status})`);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return response.json();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Helper to create TanStack Query `queryOptions` for an invoke call.
|
|
88
|
-
* The storefront must have `@tanstack/react-query` installed.
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```ts
|
|
92
|
-
* import { useQuery } from "@tanstack/react-query";
|
|
93
|
-
* import { invokeQueryOptions } from "@decocms/start/sdk/invoke";
|
|
94
|
-
*
|
|
95
|
-
* const options = invokeQueryOptions(
|
|
96
|
-
* "vtex/loaders/productList.ts",
|
|
97
|
-
* { query: "shoes" },
|
|
98
|
-
* { staleTime: 60_000 }
|
|
99
|
-
* );
|
|
100
|
-
*
|
|
101
|
-
* // In a component:
|
|
102
|
-
* const { data } = useQuery(options);
|
|
103
|
-
*
|
|
104
|
-
* // In a route loader:
|
|
105
|
-
* queryClient.ensureQueryData(options);
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
export function invokeQueryOptions<TResult = unknown>(
|
|
109
|
-
key: string,
|
|
110
|
-
props: unknown,
|
|
111
|
-
options?: { staleTime?: number; gcTime?: number; basePath?: string },
|
|
112
|
-
) {
|
|
113
|
-
const basePath = options?.basePath ?? "/deco/invoke";
|
|
114
|
-
|
|
115
|
-
return {
|
|
116
|
-
queryKey: ["deco-invoke", key, props] as const,
|
|
117
|
-
queryFn: async (): Promise<TResult> => {
|
|
118
|
-
const url = `${basePath}/${encodeURIComponent(key)}`;
|
|
119
|
-
const response = await fetch(url, {
|
|
120
|
-
method: "POST",
|
|
121
|
-
headers: { "Content-Type": "application/json" },
|
|
122
|
-
body: JSON.stringify(props ?? {}),
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
if (!response.ok) {
|
|
126
|
-
throw new Error(`Invoke ${key} failed (${response.status})`);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return response.json();
|
|
130
|
-
},
|
|
131
|
-
staleTime: options?.staleTime,
|
|
132
|
-
gcTime: options?.gcTime,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// ---------------------------------------------------------------------------
|
|
137
|
-
// Nested invoke proxy — createAppInvoke
|
|
138
|
-
// ---------------------------------------------------------------------------
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Converts flat slash-separated keys into a nested object type.
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* ```ts
|
|
145
|
-
* type Map = {
|
|
146
|
-
* "vtex/actions/checkout/addItemsToCart": (props: CartInput) => Promise<OrderForm>;
|
|
147
|
-
* "vtex/loaders/catalog/getProduct": (props: { slug: string }) => Promise<Product>;
|
|
148
|
-
* };
|
|
149
|
-
* type Nested = NestedFromFlat<Map>;
|
|
150
|
-
* // { vtex: { actions: { checkout: { addItemsToCart: (props: CartInput) => Promise<OrderForm> } } } }
|
|
151
|
-
* ```
|
|
152
|
-
*/
|
|
153
|
-
type SplitFirst<S extends string> = S extends `${infer Head}/${infer Tail}`
|
|
154
|
-
? [Head, Tail]
|
|
155
|
-
: [S, never];
|
|
156
|
-
|
|
157
|
-
type BuildNested<Key extends string, Value> =
|
|
158
|
-
SplitFirst<Key> extends [infer H extends string, infer T]
|
|
159
|
-
? T extends string
|
|
160
|
-
? { [K in H]: BuildNested<T, Value> }
|
|
161
|
-
: { [K in H]: Value }
|
|
162
|
-
: never;
|
|
163
|
-
|
|
164
|
-
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void
|
|
165
|
-
? I
|
|
166
|
-
: never;
|
|
167
|
-
|
|
168
|
-
type DeepMerge<T> = T extends object ? { [K in keyof T]: DeepMerge<T[K]> } : T;
|
|
169
|
-
|
|
170
|
-
export type NestedFromFlat<T extends Record<string, any>> = DeepMerge<
|
|
171
|
-
UnionToIntersection<{ [K in keyof T & string]: BuildNested<K, T[K]> }[keyof T & string]>
|
|
172
|
-
>;
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Creates a typed nested invoke proxy.
|
|
176
|
-
*
|
|
177
|
-
* Each property access accumulates path segments. When called as a function,
|
|
178
|
-
* the segments are joined with "/" and POSTed to `/deco/invoke/{key}`.
|
|
179
|
-
* If the primary key returns 404, a `.ts` suffix variant is tried.
|
|
180
|
-
*
|
|
181
|
-
* @example
|
|
182
|
-
* ```ts
|
|
183
|
-
* import { createAppInvoke } from "@decocms/start/sdk/invoke";
|
|
184
|
-
*
|
|
185
|
-
* // Untyped (any):
|
|
186
|
-
* const invoke = createAppInvoke();
|
|
187
|
-
* await invoke.vtex.actions.checkout.addItemsToCart({ orderFormId, orderItems });
|
|
188
|
-
*
|
|
189
|
-
* // Typed (with handler map):
|
|
190
|
-
* type Handlers = {
|
|
191
|
-
* "vtex/actions/checkout/addItemsToCart": (props: CartInput) => Promise<OrderForm>;
|
|
192
|
-
* };
|
|
193
|
-
* const invoke = createAppInvoke<Handlers>();
|
|
194
|
-
* await invoke.vtex.actions.checkout.addItemsToCart({ orderFormId, orderItems });
|
|
195
|
-
* ```
|
|
196
|
-
*/
|
|
197
|
-
export function createAppInvoke(basePath?: string): any;
|
|
198
|
-
export function createAppInvoke<T extends Record<string, any>>(
|
|
199
|
-
basePath?: string,
|
|
200
|
-
): NestedFromFlat<T>;
|
|
201
|
-
export function createAppInvoke(basePath = "/deco/invoke"): any {
|
|
202
|
-
return createAppInvokeWith({ basePath });
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Default nested invoke proxy bound to `/deco/invoke`.
|
|
207
|
-
*
|
|
208
|
-
* Replaces site-level `~/runtime.ts` shims that wrap the same `createAppInvoke`
|
|
209
|
-
* call. Importing this singleton means no per-site boilerplate.
|
|
210
|
-
*
|
|
211
|
-
* @example
|
|
212
|
-
* ```ts
|
|
213
|
-
* import { invoke } from "@decocms/start/sdk/invoke";
|
|
214
|
-
*
|
|
215
|
-
* await invoke.vtex.actions.checkout.addItemsToCart({ orderFormId, orderItems });
|
|
216
|
-
* await invoke.site.loaders.Wishlist.getWishlist({});
|
|
217
|
-
* ```
|
|
218
|
-
*
|
|
219
|
-
* For a custom `basePath` or typed handlers, call `createAppInvoke()` directly:
|
|
220
|
-
* ```ts
|
|
221
|
-
* const invoke = createAppInvoke<Handlers>("/my/invoke");
|
|
222
|
-
* ```
|
|
223
|
-
*/
|
|
224
|
-
export const invoke = createAppInvoke();
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* A `fetch`-compatible function. Lets callers route the invoke proxy's HTTP
|
|
228
|
-
* calls through a custom transport — e.g. server-side, an absolute-origin
|
|
229
|
-
* self-fetch that injects the request's AbortSignal (`RequestContext.fetch`).
|
|
230
|
-
*/
|
|
231
|
-
export type InvokeFetcher = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Like {@link createAppInvoke}, but with an injectable `fetcher`.
|
|
235
|
-
*
|
|
236
|
-
* The default `createAppInvoke` targets a relative path (`/deco/invoke`) via
|
|
237
|
-
* the global `fetch`, which only works in the browser. Server-side callers
|
|
238
|
-
* (e.g. a section loader's `ctx.invoke`) need an **absolute** base URL plus a
|
|
239
|
-
* fetcher that forwards the request's AbortSignal. This factory keeps the exact
|
|
240
|
-
* same nested-proxy semantics and 404→`.ts` retry, only swapping the transport.
|
|
241
|
-
*
|
|
242
|
-
* @example
|
|
243
|
-
* ```ts
|
|
244
|
-
* const origin = new URL(req.url).origin;
|
|
245
|
-
* const invoke = createAppInvokeWith({
|
|
246
|
-
* basePath: `${origin}/deco/invoke`,
|
|
247
|
-
* fetcher: (input, init) => RequestContext.fetch(input, init),
|
|
248
|
-
* });
|
|
249
|
-
* await invoke.vtex.loaders.product.detailsPageGQL({ slug });
|
|
250
|
-
* ```
|
|
251
|
-
*/
|
|
252
|
-
export function createAppInvokeWith(options?: { basePath?: string; fetcher?: InvokeFetcher }): any;
|
|
253
|
-
export function createAppInvokeWith<T extends Record<string, any>>(options?: {
|
|
254
|
-
basePath?: string;
|
|
255
|
-
fetcher?: InvokeFetcher;
|
|
256
|
-
}): NestedFromFlat<T>;
|
|
257
|
-
export function createAppInvokeWith(options?: { basePath?: string; fetcher?: InvokeFetcher }): any {
|
|
258
|
-
const basePath = options?.basePath ?? "/deco/invoke";
|
|
259
|
-
const fetcher: InvokeFetcher = options?.fetcher ?? ((input, init) => fetch(input, init));
|
|
260
|
-
|
|
261
|
-
function buildProxy(path: string[]): any {
|
|
262
|
-
return new Proxy(
|
|
263
|
-
Object.assign(async (props: any) => {
|
|
264
|
-
const key = path.join("/");
|
|
265
|
-
for (const k of [key, `${key}.ts`]) {
|
|
266
|
-
const response = await fetcher(`${basePath}/${k}`, {
|
|
267
|
-
method: "POST",
|
|
268
|
-
headers: { "Content-Type": "application/json" },
|
|
269
|
-
body: JSON.stringify(props ?? {}),
|
|
270
|
-
});
|
|
271
|
-
if (response.status === 404) {
|
|
272
|
-
await response.body?.cancel();
|
|
273
|
-
continue;
|
|
274
|
-
}
|
|
275
|
-
if (!response.ok) {
|
|
276
|
-
const error = await response.json().catch(() => ({ error: response.statusText }));
|
|
277
|
-
throw new Error(
|
|
278
|
-
`invoke(${k}) failed (${response.status}): ${(error as any).error || response.statusText}`,
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
return response.json();
|
|
282
|
-
}
|
|
283
|
-
throw new Error(`invoke(${key}) failed: handler not found`);
|
|
284
|
-
}, {}),
|
|
285
|
-
{
|
|
286
|
-
get(_target: any, prop: string | symbol) {
|
|
287
|
-
if (typeof prop === "symbol") return undefined;
|
|
288
|
-
if (prop === "then" || prop === "catch" || prop === "finally") {
|
|
289
|
-
return undefined;
|
|
290
|
-
}
|
|
291
|
-
return buildProxy([...path, prop]);
|
|
292
|
-
},
|
|
293
|
-
},
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
return buildProxy([]);
|
|
298
|
-
}
|