@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,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Placeholder for a future OTel-collector based exporter that ships
|
|
3
|
-
* logs / metrics / traces from this Worker to a co-deployed OTel Collector
|
|
4
|
-
* gateway, which in turn batches into ClickHouse.
|
|
5
|
-
*
|
|
6
|
-
* **NOT IMPLEMENTED in 5.0.0.** The framework today defaults to CF-native
|
|
7
|
-
* observability: logs and traces appear in the Cloudflare dashboard
|
|
8
|
-
* (`observability.{logs,traces}` in `wrangler.jsonc`), and metrics go to
|
|
9
|
-
* Workers Analytics Engine. When the platform-side ClickHouse + collector
|
|
10
|
-
* deployment lands, this file gets the real OTLP/HTTP exporter wiring back
|
|
11
|
-
* — mirror the implementation that lived in `src/sdk/otelAdapters.ts` and
|
|
12
|
-
* `src/sdk/sampler.ts` at the pre-5.0.0 git tag.
|
|
13
|
-
*
|
|
14
|
-
* The expected shape (`endpoint`, optional `headers`, optional `resource`,
|
|
15
|
-
* `exportIntervalMillis`) is recorded here so site-side bootstrapping code
|
|
16
|
-
* can compile against the future surface today and we don't churn the
|
|
17
|
-
* `OtelOptions` type when the implementation lands.
|
|
18
|
-
*
|
|
19
|
-
* Reference: https://clickhouse.com/docs/observability/integrating-opentelemetry
|
|
20
|
-
*
|
|
21
|
-
* Expected wiring once implemented:
|
|
22
|
-
* - Worker → OTLP/HTTP → OTel Collector (gateway, per region)
|
|
23
|
-
* - Collector pipelines:
|
|
24
|
-
* receivers[otlp] → processors[batch, memory_limiter] → exporters[clickhouse]
|
|
25
|
-
* - The Worker uses the collector URL as `endpoint`, NOT a direct
|
|
26
|
-
* ClickHouse URL. The collector owns the credentials, retry policy,
|
|
27
|
-
* and schema mapping.
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
export interface ClickhouseCollectorOptions {
|
|
31
|
-
/**
|
|
32
|
-
* OTel Collector OTLP/HTTP endpoint, e.g. `https://otel-collector.internal`.
|
|
33
|
-
* The Worker never talks to ClickHouse directly — it talks to the collector.
|
|
34
|
-
*/
|
|
35
|
-
endpoint: string;
|
|
36
|
-
/** Optional bearer token / mTLS identity headers — collector-defined. */
|
|
37
|
-
headers?: Record<string, string>;
|
|
38
|
-
/**
|
|
39
|
-
* Resource attributes to stamp on every emitted record. Keep narrow
|
|
40
|
-
* (`service.name`, `deco.runtime.version`, `deployment.environment`) —
|
|
41
|
-
* higher-cardinality attributes belong on individual spans / log records.
|
|
42
|
-
*/
|
|
43
|
-
resource?: Record<string, string>;
|
|
44
|
-
/** Periodic metric reader push interval in ms. Defaults to 60_000 once wired. */
|
|
45
|
-
exportIntervalMillis?: number;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Returns nothing today — throws to make accidental usage loud and obvious.
|
|
50
|
-
*
|
|
51
|
-
* The intended return shape is `{ logger: LoggerAdapter, meter: MeterAdapter,
|
|
52
|
-
* tracer: TracerAdapter, flush: () => Promise<void> }` so the wiring inside
|
|
53
|
-
* `instrumentWorker` can compose this with the AE meter (dual-emit) and the
|
|
54
|
-
* default console logger. None of that ships in 5.0.0.
|
|
55
|
-
*/
|
|
56
|
-
export function createClickhouseCollectorAdapter(_options: ClickhouseCollectorOptions): never {
|
|
57
|
-
throw new Error(
|
|
58
|
-
"createClickhouseCollectorAdapter is not implemented in @decocms/start@5.x. " +
|
|
59
|
-
"ClickHouse + OTel-collector integration is on the roadmap. " +
|
|
60
|
-
"Until then, use Cloudflare-native observability " +
|
|
61
|
-
"(observability.{logs,traces} in wrangler.jsonc) plus the Workers " +
|
|
62
|
-
"Analytics Engine meter wired by instrumentWorker(). Track progress " +
|
|
63
|
-
"at https://github.com/decocms/blocks/issues.",
|
|
64
|
-
);
|
|
65
|
-
}
|
package/src/sdk/otelAdapters.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Metric adapters for `@decocms/start`.
|
|
3
|
-
*
|
|
4
|
-
* The OTLP logger and OTLP meter adapters that lived here through 4.x were
|
|
5
|
-
* removed in 5.0.0. The framework now relies on:
|
|
6
|
-
* - Cloudflare's platform-managed log capture (`console.*` → CF dashboard
|
|
7
|
-
* via `observability.logs`) for log shipping
|
|
8
|
-
* - Cloudflare's auto-instrumented + global-tracer-bridged trace export
|
|
9
|
-
* (`observability.traces`) for trace shipping
|
|
10
|
-
* - Workers Analytics Engine — implemented in this file — for metrics
|
|
11
|
-
*
|
|
12
|
-
* Forwarding to a co-deployed OTel collector (the path to ClickHouse)
|
|
13
|
-
* lives in `./otelAdapters/clickhouseCollector.ts`. That file is a
|
|
14
|
-
* documented stub today; the implementation will reintroduce a thin
|
|
15
|
-
* OTLP/HTTP exporter aimed at the collector — never directly at a
|
|
16
|
-
* destination — when the collector is deployed.
|
|
17
|
-
*
|
|
18
|
-
* The `setRuntimeEnv` / `getRuntimeEnv` helpers stay here because
|
|
19
|
-
* `workerEntry.ts` and the AE adapter both depend on them.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
import type { MeterAdapter } from "../middleware/observability";
|
|
23
|
-
import { MetricNames } from "../middleware/observability";
|
|
24
|
-
import { RequestContext } from "./requestContext";
|
|
25
|
-
|
|
26
|
-
// ---------------------------------------------------------------------------
|
|
27
|
-
// Env / binding access
|
|
28
|
-
// ---------------------------------------------------------------------------
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Per-request access to the Cloudflare Worker `env` bag. Stashed by
|
|
32
|
-
* `workerEntry.ts` at the top of every request via
|
|
33
|
-
* `RequestContext.setBag("__deco_env", env)`.
|
|
34
|
-
*
|
|
35
|
-
* Adapters use this to look up the AE binding (or any future binding-driven
|
|
36
|
-
* destination) without forcing site code to thread `env` through every
|
|
37
|
-
* call site.
|
|
38
|
-
*/
|
|
39
|
-
const ENV_BAG_KEY = "__deco_env";
|
|
40
|
-
|
|
41
|
-
export function setRuntimeEnv(env: Record<string, unknown>): void {
|
|
42
|
-
RequestContext.setBag(ENV_BAG_KEY, env);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function getRuntimeEnv(): Record<string, unknown> | undefined {
|
|
46
|
-
return RequestContext.getBag<Record<string, unknown>>(ENV_BAG_KEY);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// ---------------------------------------------------------------------------
|
|
50
|
-
// AnalyticsEngineMeterAdapter
|
|
51
|
-
// ---------------------------------------------------------------------------
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Workers Analytics Engine binding shape. Defined here so we don't need
|
|
55
|
-
* `@cloudflare/workers-types` as a dep.
|
|
56
|
-
*/
|
|
57
|
-
export interface AnalyticsEngineDataset {
|
|
58
|
-
writeDataPoint(point: { indexes?: string[]; blobs?: string[]; doubles?: number[] }): void;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export interface AnalyticsEngineMeterAdapterOptions {
|
|
62
|
-
/** Env var name holding the AE binding. Defaults to "DECO_METRICS". */
|
|
63
|
-
bindingName?: string;
|
|
64
|
-
/** Pre-resolved binding (mainly for tests). Bypasses RequestContext lookup. */
|
|
65
|
-
binding?: AnalyticsEngineDataset;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Writes one Analytics Engine data point per metric call.
|
|
70
|
-
*
|
|
71
|
-
* Schema (must stay stable — dashboards and SQL queries depend on it):
|
|
72
|
-
* - `indexes[0]`: a low-cardinality dimension. For request metrics that's
|
|
73
|
-
* the normalized URL path; for cache/resolve metrics that's the metric
|
|
74
|
-
* name itself.
|
|
75
|
-
* - `blobs[0]`: metric name (so a single dataset can hold many metrics).
|
|
76
|
-
* - `blobs[1..]`: stringified label values, in stable label-name order.
|
|
77
|
-
* - `doubles[0]`: the metric value (count, ms, gauge value).
|
|
78
|
-
*
|
|
79
|
-
* AE truncates / charges per data point, so this adapter is intentionally
|
|
80
|
-
* coarse: one point per `counterInc` / `histogramRecord` / `gaugeSet`.
|
|
81
|
-
*/
|
|
82
|
-
export function createAnalyticsEngineMeterAdapter(
|
|
83
|
-
options: AnalyticsEngineMeterAdapterOptions = {},
|
|
84
|
-
): MeterAdapter {
|
|
85
|
-
const bindingName = options.bindingName ?? "DECO_METRICS";
|
|
86
|
-
|
|
87
|
-
function resolveBinding(): AnalyticsEngineDataset | null {
|
|
88
|
-
if (options.binding) return options.binding;
|
|
89
|
-
const env = getRuntimeEnv();
|
|
90
|
-
const b = env?.[bindingName] as AnalyticsEngineDataset | undefined;
|
|
91
|
-
return b ?? null;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function write(name: string, value: number, labels?: Record<string, unknown>): void {
|
|
95
|
-
const binding = resolveBinding();
|
|
96
|
-
if (!binding) return; // No-op when binding is missing — never throw.
|
|
97
|
-
|
|
98
|
-
const indexValue = pickIndex(name, labels);
|
|
99
|
-
const blobs: string[] = [name];
|
|
100
|
-
if (labels) {
|
|
101
|
-
// Stable order — sort keys so the same blob index always means the
|
|
102
|
-
// same label across requests. AE has no schema; we enforce one here.
|
|
103
|
-
const keys = Object.keys(labels).sort();
|
|
104
|
-
for (const k of keys) {
|
|
105
|
-
const v = labels[k];
|
|
106
|
-
if (v !== undefined && v !== null) blobs.push(String(v));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
try {
|
|
111
|
-
binding.writeDataPoint({
|
|
112
|
-
indexes: indexValue ? [indexValue] : undefined,
|
|
113
|
-
blobs,
|
|
114
|
-
doubles: [value],
|
|
115
|
-
});
|
|
116
|
-
} catch {
|
|
117
|
-
/* AE write failed — never fail the request */
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return {
|
|
122
|
-
counterInc(name, value, labels) {
|
|
123
|
-
write(name, value ?? 1, labels);
|
|
124
|
-
},
|
|
125
|
-
histogramRecord(name, value, labels) {
|
|
126
|
-
write(name, value, labels);
|
|
127
|
-
},
|
|
128
|
-
gaugeSet(name, value, labels) {
|
|
129
|
-
write(name, value, labels);
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function pickIndex(metricName: string, labels?: Record<string, unknown>): string | undefined {
|
|
135
|
-
if (!labels) return metricName;
|
|
136
|
-
// For HTTP request metrics the natural index is the path (matches the
|
|
137
|
-
// schema: `indexes[0]=path`). For other metrics, fall back to the metric
|
|
138
|
-
// name so the dataset is always queryable by index.
|
|
139
|
-
if (metricName === MetricNames.HTTP_SERVER_REQUEST_DURATION) {
|
|
140
|
-
const p = labels.path;
|
|
141
|
-
if (typeof p === "string" && p.length > 0) return p;
|
|
142
|
-
}
|
|
143
|
-
return metricName;
|
|
144
|
-
}
|
package/src/sdk/otelHttpLog.ts
DELETED
|
@@ -1,419 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Direct OTLP/HTTP JSON error-log exporter.
|
|
3
|
-
*
|
|
4
|
-
* Errors are too important to leave to head sampling. When CF Destinations'
|
|
5
|
-
* `logs.head_sampling_rate` drops below 1.0 (the cost model in
|
|
6
|
-
* `docs/observability.md` lowers it to `0.01` once this channel lands),
|
|
7
|
-
* a 1%-sampled log pipe would lose 99 of every 100 errors emitted by
|
|
8
|
-
* `logger.error(...)`. Sites lose the one signal they care about most.
|
|
9
|
-
*
|
|
10
|
-
* This adapter solves it by carrying `level: "error"` log records over a
|
|
11
|
-
* separate, framework-controlled pipe direct to `deco-otel-ingest`
|
|
12
|
-
* `/v1/logs`, the same endpoint CF Destinations targets. The two pipes
|
|
13
|
-
* write to the same `otel_logs` table — the ingestor doesn't know or
|
|
14
|
-
* care which transport the record arrived on, and dashboards / SQL
|
|
15
|
-
* queries are unchanged.
|
|
16
|
-
*
|
|
17
|
-
* Design:
|
|
18
|
-
*
|
|
19
|
-
* - Filters out `debug`/`info`/`warn` upstream of the buffer — only
|
|
20
|
-
* errors travel through this transport. Calls below "error" are a
|
|
21
|
-
* no-op on this adapter; the composite logger fans them out to the
|
|
22
|
-
* default console-JSON adapter which CF Destinations then samples
|
|
23
|
-
* according to `logs.head_sampling_rate`.
|
|
24
|
-
* - Per-isolate token-bucket rate limiter prevents log storms (a
|
|
25
|
-
* pathological error loop blasting 10K errors/sec into the ingestor
|
|
26
|
-
* would be a self-inflicted denial-of-service against stats-lake).
|
|
27
|
-
* Default: 100 errors per minute, burst capacity of 20.
|
|
28
|
-
* - Buffer + flush + cooldown identical to `otelHttpMeter.ts`. The
|
|
29
|
-
* same `ctx.waitUntil(flush())` in `instrumentWorker` drains both.
|
|
30
|
-
* - Wire format: OTLP/HTTP JSON `ResourceLogs` payload matching the
|
|
31
|
-
* shape CF Destinations produces, so the existing ingestor handler
|
|
32
|
-
* accepts both transports unchanged.
|
|
33
|
-
*
|
|
34
|
-
* Why a separate adapter and not a sampling-bypass flag on
|
|
35
|
-
* `defaultLoggerAdapter`: the default writes via `console.error` which
|
|
36
|
-
* is what CF Destinations samples. Bypassing CF Destinations means
|
|
37
|
-
* NOT writing via `console.*` — a different transport, different
|
|
38
|
-
* code path, different failure modes. Better as a dedicated adapter
|
|
39
|
-
* composed onto the active logger via `createCompositeLogger`.
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
import { getActiveSpan } from "./observability";
|
|
43
|
-
import type { LoggerAdapter, LogLevel } from "./logger";
|
|
44
|
-
|
|
45
|
-
// ---------------------------------------------------------------------------
|
|
46
|
-
// Types
|
|
47
|
-
// ---------------------------------------------------------------------------
|
|
48
|
-
|
|
49
|
-
export interface OtlpHttpLogOptions {
|
|
50
|
-
/** Full OTLP/HTTP JSON logs endpoint, e.g. `https://.../v1/logs`. */
|
|
51
|
-
endpoint: string;
|
|
52
|
-
/** Resource attributes stamped on every payload (service.name etc.). */
|
|
53
|
-
resourceAttributes: Record<string, string>;
|
|
54
|
-
/** Scope name advertised in `scopeLogs[].scope.name`. */
|
|
55
|
-
scopeName?: string;
|
|
56
|
-
/** Scope version. */
|
|
57
|
-
scopeVersion?: string;
|
|
58
|
-
/** Hard cap on pending log records. Default: 500. */
|
|
59
|
-
maxBufferRecords?: number;
|
|
60
|
-
/** Cooldown between successful flushes (ms). Default: 5000. */
|
|
61
|
-
minFlushIntervalMs?: number;
|
|
62
|
-
/** Per-flush HTTP timeout (ms). Default: 5000. */
|
|
63
|
-
flushTimeoutMs?: number;
|
|
64
|
-
/**
|
|
65
|
-
* Token-bucket parameters. The bucket holds up to `burstCapacity`
|
|
66
|
-
* tokens and refills at `refillPerMinute` per minute. Each log record
|
|
67
|
-
* costs one token. When the bucket is empty, records are dropped (with
|
|
68
|
-
* `onError("rate-limit", ...)`) until refill resumes.
|
|
69
|
-
* Defaults: 500 burst, 1000/min — sized for console monkey-patch, which
|
|
70
|
-
* routes ALL console.* (including third-party libs at boot) through this
|
|
71
|
-
* adapter. The old 20/100 defaults were sized for error-only traffic.
|
|
72
|
-
*/
|
|
73
|
-
rateLimitBurstCapacity?: number;
|
|
74
|
-
rateLimitRefillPerMinute?: number;
|
|
75
|
-
/**
|
|
76
|
-
* Minimum log level that this adapter forwards to OTLP. Levels below
|
|
77
|
-
* this threshold are silently dropped at ingress. Defaults to `"error"`
|
|
78
|
-
* — production-safe (only errors travel direct-POST; info/warn flow
|
|
79
|
-
* through CF Destinations sampling). Set to `"info"` or `"debug"` in
|
|
80
|
-
* local dev to capture lower-severity logs in the same channel.
|
|
81
|
-
* Resolved from `DECO_OTEL_LOGS_MIN_LEVEL` in `bootObservability`.
|
|
82
|
-
*/
|
|
83
|
-
minLevel?: LogLevel;
|
|
84
|
-
/**
|
|
85
|
-
* Extra HTTP headers merged into every OTLP POST (e.g. `Authorization: Bearer …`).
|
|
86
|
-
* `Content-Type: application/json` is always set and cannot be overridden here.
|
|
87
|
-
*/
|
|
88
|
-
headers?: Record<string, string>;
|
|
89
|
-
/** Test seam — override fetch. */
|
|
90
|
-
fetchImpl?: typeof fetch;
|
|
91
|
-
/** Test seam — override Date.now(). */
|
|
92
|
-
nowMs?: () => number;
|
|
93
|
-
/**
|
|
94
|
-
* Test seam — override getActiveSpan. Production code uses the
|
|
95
|
-
* framework's AsyncLocalStorage-backed getActiveSpan automatically.
|
|
96
|
-
*/
|
|
97
|
-
getActiveSpanFn?: () => { spanContext?: () => { traceId?: string; spanId?: string; traceFlags?: number } } | undefined | null;
|
|
98
|
-
/** Optional sink for transport / rate-limit / overflow errors. */
|
|
99
|
-
onError?: (kind: "flush" | "overflow" | "rate-limit", err: unknown) => void;
|
|
100
|
-
/**
|
|
101
|
-
* Called when an `error`-level log fires with an active trace context.
|
|
102
|
-
* Used by the caller to promote unsampled traces so their spans are
|
|
103
|
-
* exported regardless of head-sampling decisions.
|
|
104
|
-
*/
|
|
105
|
-
promoteTrace?: (traceId: string) => void;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export interface OtlpHttpLog {
|
|
109
|
-
adapter: LoggerAdapter;
|
|
110
|
-
/** Flush, subject to the per-isolate cooldown unless `force` is true. */
|
|
111
|
-
flush(force?: boolean): Promise<void>;
|
|
112
|
-
/** Pending log record count. For tests + audit. */
|
|
113
|
-
pendingRecordCount(): number;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// ---------------------------------------------------------------------------
|
|
117
|
-
// Internal types
|
|
118
|
-
// ---------------------------------------------------------------------------
|
|
119
|
-
|
|
120
|
-
interface PendingRecord {
|
|
121
|
-
timeUnixNano: string;
|
|
122
|
-
observedTimeUnixNano: string;
|
|
123
|
-
severityNumber: number;
|
|
124
|
-
severityText: string;
|
|
125
|
-
body: string;
|
|
126
|
-
attributes: Record<string, unknown>;
|
|
127
|
-
traceId: string;
|
|
128
|
-
spanId: string;
|
|
129
|
-
traceFlags: number;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// OTel SeverityNumber values, OTel spec. See
|
|
133
|
-
// https://opentelemetry.io/docs/specs/otel/logs/data-model/#field-severitynumber
|
|
134
|
-
const SEVERITY_NUMBER: Record<LogLevel, number> = {
|
|
135
|
-
debug: 5,
|
|
136
|
-
info: 9,
|
|
137
|
-
warn: 13,
|
|
138
|
-
error: 17,
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
// ---------------------------------------------------------------------------
|
|
142
|
-
// Factory
|
|
143
|
-
// ---------------------------------------------------------------------------
|
|
144
|
-
|
|
145
|
-
export function createOtlpHttpLogAdapter(options: OtlpHttpLogOptions): OtlpHttpLog {
|
|
146
|
-
const endpoint = options.endpoint;
|
|
147
|
-
const resourceAttributes = options.resourceAttributes;
|
|
148
|
-
const scopeName = options.scopeName ?? "@decocms/start";
|
|
149
|
-
const scopeVersion = options.scopeVersion ?? "";
|
|
150
|
-
const maxBuffer = options.maxBufferRecords ?? 500;
|
|
151
|
-
const minFlushIntervalMs = options.minFlushIntervalMs ?? 5000;
|
|
152
|
-
const flushTimeoutMs = options.flushTimeoutMs ?? 5000;
|
|
153
|
-
const burstCapacity = options.rateLimitBurstCapacity ?? 500;
|
|
154
|
-
const refillPerMinute = options.rateLimitRefillPerMinute ?? 1000;
|
|
155
|
-
const minSeverity = SEVERITY_NUMBER[options.minLevel ?? "error"];
|
|
156
|
-
const extraHeaders = options.headers ?? {};
|
|
157
|
-
const fetchImpl = options.fetchImpl ?? fetch;
|
|
158
|
-
const now = options.nowMs ?? (() => Date.now());
|
|
159
|
-
const onError = options.onError;
|
|
160
|
-
const promoteTrace = options.promoteTrace;
|
|
161
|
-
const getSpan = options.getActiveSpanFn ?? getActiveSpan;
|
|
162
|
-
|
|
163
|
-
const buffer: PendingRecord[] = [];
|
|
164
|
-
// Token bucket — starts full.
|
|
165
|
-
let tokens = burstCapacity;
|
|
166
|
-
let tokensLastRefilledAt = now();
|
|
167
|
-
|
|
168
|
-
let lastFlushAt = 0;
|
|
169
|
-
let inflight: Promise<void> | null = null;
|
|
170
|
-
|
|
171
|
-
function refillTokens(): void {
|
|
172
|
-
const t = now();
|
|
173
|
-
const elapsedMs = t - tokensLastRefilledAt;
|
|
174
|
-
if (elapsedMs <= 0) return;
|
|
175
|
-
// refillPerMinute tokens per 60_000ms.
|
|
176
|
-
const refill = (elapsedMs / 60_000) * refillPerMinute;
|
|
177
|
-
tokens = Math.min(burstCapacity, tokens + refill);
|
|
178
|
-
tokensLastRefilledAt = t;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function tryConsumeToken(): boolean {
|
|
182
|
-
refillTokens();
|
|
183
|
-
if (tokens < 1) return false;
|
|
184
|
-
tokens -= 1;
|
|
185
|
-
return true;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const adapter: LoggerAdapter = {
|
|
189
|
-
log(level, msg, attrs) {
|
|
190
|
-
// Filter by severity threshold. Levels below minLevel are dropped.
|
|
191
|
-
if (SEVERITY_NUMBER[level] < minSeverity) return;
|
|
192
|
-
|
|
193
|
-
// No SDK-level sampling for info/debug. Volume is controlled by
|
|
194
|
-
// minLevel (severity threshold) here, and by the probabilistic
|
|
195
|
-
// sampler in the otel-ingest collector — keeping log and trace
|
|
196
|
-
// sampling pipelines fully independent per OTel spec.
|
|
197
|
-
|
|
198
|
-
if (!tryConsumeToken()) {
|
|
199
|
-
onError?.(
|
|
200
|
-
"rate-limit",
|
|
201
|
-
new Error(`rate limit exceeded: ${refillPerMinute}/min, burst ${burstCapacity}`),
|
|
202
|
-
);
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (buffer.length >= maxBuffer) {
|
|
207
|
-
onError?.(
|
|
208
|
-
"overflow",
|
|
209
|
-
new Error(`error-log buffer at cap (${maxBuffer}) — dropping record`),
|
|
210
|
-
);
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const spanCtx = getSpan()?.spanContext?.();
|
|
215
|
-
const t = msToNs(now());
|
|
216
|
-
buffer.push({
|
|
217
|
-
timeUnixNano: t,
|
|
218
|
-
observedTimeUnixNano: t,
|
|
219
|
-
severityNumber: SEVERITY_NUMBER[level],
|
|
220
|
-
severityText: level,
|
|
221
|
-
body: msg,
|
|
222
|
-
attributes: attrs ? { ...attrs } : {},
|
|
223
|
-
traceId: spanCtx?.traceId ?? "",
|
|
224
|
-
spanId: spanCtx?.spanId ?? "",
|
|
225
|
-
traceFlags: spanCtx?.traceFlags ?? 0,
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
if (level === "error" && spanCtx?.traceId) {
|
|
229
|
-
promoteTrace?.(spanCtx.traceId);
|
|
230
|
-
}
|
|
231
|
-
},
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
async function doFlush(): Promise<void> {
|
|
235
|
-
if (buffer.length === 0) return;
|
|
236
|
-
// Snapshot + remove BEFORE the network call so concurrent records
|
|
237
|
-
// landing during the POST don't get reset on success. On failure we
|
|
238
|
-
// restore the snapshot to the FRONT of the buffer (preserving order
|
|
239
|
-
// and prioritizing the originating-error context). The `maxBuffer`
|
|
240
|
-
// cap on the `log()` path still bounds total memory if the endpoint
|
|
241
|
-
// stays down — newest records are dropped via `onError("overflow")`.
|
|
242
|
-
const snapshot = buffer.splice(0, buffer.length);
|
|
243
|
-
const payload = serializeOtlp(snapshot, {
|
|
244
|
-
resourceAttributes,
|
|
245
|
-
scopeName,
|
|
246
|
-
scopeVersion,
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
const restoreOnFailure = () => {
|
|
250
|
-
// The snapshot was buffered BEFORE any records that landed during
|
|
251
|
-
// the failed POST — its contents are older and more likely to be
|
|
252
|
-
// the originating-error context operators care about. Restore
|
|
253
|
-
// policy preserves the snapshot first, evicts the NEWEST records
|
|
254
|
-
// when the cap is tight:
|
|
255
|
-
//
|
|
256
|
-
// 1. If snapshot + current buffer fit under the cap → unshift,
|
|
257
|
-
// done.
|
|
258
|
-
// 2. Otherwise, drop newest-tail records from the current buffer
|
|
259
|
-
// (records that arrived during the failed POST). If that
|
|
260
|
-
// suffices, unshift the full snapshot.
|
|
261
|
-
// 3. Only if the snapshot ALONE exceeds the cap do we truncate
|
|
262
|
-
// the snapshot — and even then, we keep its OLDEST end
|
|
263
|
-
// (`snapshot.length = maxBuffer`) and drop the newest tail.
|
|
264
|
-
//
|
|
265
|
-
// This is the inverse of the original (buggy) restore which kept
|
|
266
|
-
// newer records by truncating the older snapshot.
|
|
267
|
-
const total = snapshot.length + buffer.length;
|
|
268
|
-
if (total <= maxBuffer) {
|
|
269
|
-
buffer.unshift(...snapshot);
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
let overflow = total - maxBuffer;
|
|
274
|
-
let droppedFromBuffer = 0;
|
|
275
|
-
if (buffer.length > 0 && overflow > 0) {
|
|
276
|
-
droppedFromBuffer = Math.min(buffer.length, overflow);
|
|
277
|
-
buffer.length -= droppedFromBuffer;
|
|
278
|
-
overflow -= droppedFromBuffer;
|
|
279
|
-
}
|
|
280
|
-
let droppedFromSnapshot = 0;
|
|
281
|
-
if (overflow > 0) {
|
|
282
|
-
// Snapshot alone exceeds the cap. Keep the oldest `maxBuffer`
|
|
283
|
-
// entries and drop the rest from the newest tail.
|
|
284
|
-
droppedFromSnapshot = Math.min(snapshot.length, overflow);
|
|
285
|
-
snapshot.length -= droppedFromSnapshot;
|
|
286
|
-
}
|
|
287
|
-
buffer.unshift(...snapshot);
|
|
288
|
-
|
|
289
|
-
const parts = [`dropped ${droppedFromBuffer} newer records from buffer`];
|
|
290
|
-
if (droppedFromSnapshot > 0) {
|
|
291
|
-
parts.push(`${droppedFromSnapshot} newest-tail records from snapshot`);
|
|
292
|
-
}
|
|
293
|
-
onError?.(
|
|
294
|
-
"overflow",
|
|
295
|
-
new Error(
|
|
296
|
-
`error-log buffer overflow on restore — ${parts.join(" and ")} (preserved ${snapshot.length} originating-error records)`,
|
|
297
|
-
),
|
|
298
|
-
);
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
const controller = new AbortController();
|
|
302
|
-
const timer = setTimeout(() => controller.abort(), flushTimeoutMs);
|
|
303
|
-
try {
|
|
304
|
-
const res = await fetchImpl(endpoint, {
|
|
305
|
-
method: "POST",
|
|
306
|
-
headers: { ...extraHeaders, "Content-Type": "application/json" },
|
|
307
|
-
body: JSON.stringify(payload),
|
|
308
|
-
signal: controller.signal,
|
|
309
|
-
});
|
|
310
|
-
if (!res.ok) {
|
|
311
|
-
try {
|
|
312
|
-
await res.text();
|
|
313
|
-
} catch {
|
|
314
|
-
/* swallow */
|
|
315
|
-
}
|
|
316
|
-
restoreOnFailure();
|
|
317
|
-
onError?.("flush", new Error(`POST ${endpoint} → ${res.status}`));
|
|
318
|
-
}
|
|
319
|
-
} catch (err) {
|
|
320
|
-
restoreOnFailure();
|
|
321
|
-
onError?.("flush", err);
|
|
322
|
-
} finally {
|
|
323
|
-
clearTimeout(timer);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
async function flush(force = false): Promise<void> {
|
|
328
|
-
if (inflight) return inflight;
|
|
329
|
-
|
|
330
|
-
const elapsed = now() - lastFlushAt;
|
|
331
|
-
const overCap = buffer.length >= maxBuffer;
|
|
332
|
-
if (!force && !overCap && elapsed < minFlushIntervalMs) return;
|
|
333
|
-
|
|
334
|
-
inflight = doFlush().finally(() => {
|
|
335
|
-
lastFlushAt = now();
|
|
336
|
-
inflight = null;
|
|
337
|
-
});
|
|
338
|
-
return inflight;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
return {
|
|
342
|
-
adapter,
|
|
343
|
-
flush,
|
|
344
|
-
pendingRecordCount: () => buffer.length,
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// ---------------------------------------------------------------------------
|
|
349
|
-
// OTLP/HTTP JSON serialization
|
|
350
|
-
// ---------------------------------------------------------------------------
|
|
351
|
-
|
|
352
|
-
function msToNs(ms: number): string {
|
|
353
|
-
return `${Math.floor(ms)}000000`;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
function attrToOtlpValue(
|
|
357
|
-
v: unknown,
|
|
358
|
-
):
|
|
359
|
-
| { stringValue: string }
|
|
360
|
-
| { intValue: string }
|
|
361
|
-
| { doubleValue: number }
|
|
362
|
-
| { boolValue: boolean } {
|
|
363
|
-
if (typeof v === "string") return { stringValue: v };
|
|
364
|
-
if (typeof v === "boolean") return { boolValue: v };
|
|
365
|
-
if (typeof v === "number" && Number.isFinite(v)) {
|
|
366
|
-
if (Number.isInteger(v)) return { intValue: String(v) };
|
|
367
|
-
return { doubleValue: v };
|
|
368
|
-
}
|
|
369
|
-
// Fallback — JSON-stringify so structured attrs round-trip as strings.
|
|
370
|
-
// `JSON.stringify` returns `undefined` for `undefined`, functions, and
|
|
371
|
-
// symbols. OTLP requires `stringValue` to be a string, so coerce with
|
|
372
|
-
// `String(v)` whenever serialization yields nothing parseable.
|
|
373
|
-
try {
|
|
374
|
-
const s = JSON.stringify(v);
|
|
375
|
-
return { stringValue: typeof s === "string" ? s : String(v) };
|
|
376
|
-
} catch {
|
|
377
|
-
return { stringValue: String(v) };
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
interface SerializeOpts {
|
|
382
|
-
resourceAttributes: Record<string, string>;
|
|
383
|
-
scopeName: string;
|
|
384
|
-
scopeVersion: string;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
function serializeOtlp(records: PendingRecord[], opts: SerializeOpts): { resourceLogs: unknown[] } {
|
|
388
|
-
const otlpRecords = records.map((r) => ({
|
|
389
|
-
timeUnixNano: r.timeUnixNano,
|
|
390
|
-
observedTimeUnixNano: r.observedTimeUnixNano,
|
|
391
|
-
severityNumber: r.severityNumber,
|
|
392
|
-
severityText: r.severityText,
|
|
393
|
-
body: { stringValue: r.body },
|
|
394
|
-
attributes: Object.entries(r.attributes)
|
|
395
|
-
.filter(([_, v]) => v !== undefined && v !== null)
|
|
396
|
-
.map(([k, v]) => ({ key: k, value: attrToOtlpValue(v) })),
|
|
397
|
-
...(r.traceId ? { traceId: r.traceId } : {}),
|
|
398
|
-
...(r.spanId ? { spanId: r.spanId } : {}),
|
|
399
|
-
...(r.traceFlags ? { flags: r.traceFlags } : {}),
|
|
400
|
-
}));
|
|
401
|
-
|
|
402
|
-
const resourceAttrs = Object.entries(opts.resourceAttributes)
|
|
403
|
-
.sort(([a], [b]) => a.localeCompare(b))
|
|
404
|
-
.map(([k, v]) => ({ key: k, value: { stringValue: v } }));
|
|
405
|
-
|
|
406
|
-
return {
|
|
407
|
-
resourceLogs: [
|
|
408
|
-
{
|
|
409
|
-
resource: { attributes: resourceAttrs },
|
|
410
|
-
scopeLogs: [
|
|
411
|
-
{
|
|
412
|
-
scope: { name: opts.scopeName, version: opts.scopeVersion },
|
|
413
|
-
logRecords: otlpRecords,
|
|
414
|
-
},
|
|
415
|
-
],
|
|
416
|
-
},
|
|
417
|
-
],
|
|
418
|
-
};
|
|
419
|
-
}
|