@timber-js/app 0.2.0-alpha.97 → 0.2.0-alpha.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks/actions-CQ8Z8VGL.js +1061 -0
- package/dist/_chunks/actions-CQ8Z8VGL.js.map +1 -0
- package/dist/_chunks/build-output-helper-DXnW0qjz.js +61 -0
- package/dist/_chunks/build-output-helper-DXnW0qjz.js.map +1 -0
- package/dist/_chunks/{define-Itxvcd7F.js → define-B-Q_UMOD.js} +19 -23
- package/dist/_chunks/define-B-Q_UMOD.js.map +1 -0
- package/dist/_chunks/{define-C77ScO0m.js → define-CfBPoJb0.js} +24 -7
- package/dist/_chunks/define-CfBPoJb0.js.map +1 -0
- package/dist/_chunks/define-cookie-BjpIt4UC.js +194 -0
- package/dist/_chunks/define-cookie-BjpIt4UC.js.map +1 -0
- package/dist/_chunks/{format-CYBGxKtc.js → format-Bcn-Iv1x.js} +1 -1
- package/dist/_chunks/{format-CYBGxKtc.js.map → format-Bcn-Iv1x.js.map} +1 -1
- package/dist/_chunks/handler-store-B-lqaGyh.js +54 -0
- package/dist/_chunks/handler-store-B-lqaGyh.js.map +1 -0
- package/dist/_chunks/logger-0m8MsKdc.js +291 -0
- package/dist/_chunks/logger-0m8MsKdc.js.map +1 -0
- package/dist/_chunks/merge-search-params-BphMdht_.js +122 -0
- package/dist/_chunks/merge-search-params-BphMdht_.js.map +1 -0
- package/dist/_chunks/{metadata-routes-DS3eKNmf.js → metadata-routes-BU684ls2.js} +1 -1
- package/dist/_chunks/{metadata-routes-DS3eKNmf.js.map → metadata-routes-BU684ls2.js.map} +1 -1
- package/dist/_chunks/navigation-root-BCYczjml.js +96 -0
- package/dist/_chunks/navigation-root-BCYczjml.js.map +1 -0
- package/dist/_chunks/registry-I2ss-lvy.js +20 -0
- package/dist/_chunks/registry-I2ss-lvy.js.map +1 -0
- package/dist/_chunks/router-ref-h3-UaCQv.js +28 -0
- package/dist/_chunks/router-ref-h3-UaCQv.js.map +1 -0
- package/dist/_chunks/{schema-bridge-C3xl_vfb.js → schema-bridge-Cxu4l-7p.js} +1 -1
- package/dist/_chunks/{schema-bridge-C3xl_vfb.js.map → schema-bridge-Cxu4l-7p.js.map} +1 -1
- package/dist/_chunks/segment-classify-BjfuctV2.js +137 -0
- package/dist/_chunks/segment-classify-BjfuctV2.js.map +1 -0
- package/dist/_chunks/{segment-context-fHFLF1PE.js → segment-context-Dx_OizxD.js} +1 -1
- package/dist/_chunks/{segment-context-fHFLF1PE.js.map → segment-context-Dx_OizxD.js.map} +1 -1
- package/dist/_chunks/{router-ref-C8OCm7g7.js → ssr-data-B4CdH7rE.js} +2 -26
- package/dist/_chunks/ssr-data-B4CdH7rE.js.map +1 -0
- package/dist/_chunks/{stale-reload-BX5gL1r-.js → stale-reload-Bab885FO.js} +1 -1
- package/dist/_chunks/{stale-reload-BX5gL1r-.js.map → stale-reload-Bab885FO.js.map} +1 -1
- package/dist/_chunks/tracing-C8V-YGsP.js +329 -0
- package/dist/_chunks/tracing-C8V-YGsP.js.map +1 -0
- package/dist/_chunks/{use-query-states-BiV5GJgm.js → use-query-states-B2XTqxDR.js} +3 -19
- package/dist/_chunks/use-query-states-B2XTqxDR.js.map +1 -0
- package/dist/_chunks/{use-params-IOPu7E8t.js → use-segment-params-BkpKAQ7D.js} +9 -95
- package/dist/_chunks/use-segment-params-BkpKAQ7D.js.map +1 -0
- package/dist/_chunks/{interception-BbqMCVXa.js → walkers-Tg0Alwcg.js} +66 -87
- package/dist/_chunks/walkers-Tg0Alwcg.js.map +1 -0
- package/dist/_chunks/{dev-warnings-DpGRGoDi.js → warnings-Cg47l5sk.js} +3 -3
- package/dist/_chunks/warnings-Cg47l5sk.js.map +1 -0
- package/dist/adapters/build-output-helper.d.ts +28 -0
- package/dist/adapters/build-output-helper.d.ts.map +1 -0
- package/dist/adapters/cloudflare.d.ts.map +1 -1
- package/dist/adapters/cloudflare.js +8 -28
- package/dist/adapters/cloudflare.js.map +1 -1
- package/dist/adapters/nitro.d.ts.map +1 -1
- package/dist/adapters/nitro.js +63 -31
- package/dist/adapters/nitro.js.map +1 -1
- package/dist/adapters/shared.d.ts +16 -0
- package/dist/adapters/shared.d.ts.map +1 -0
- package/dist/cache/index.js +9 -2
- package/dist/cache/index.js.map +1 -1
- package/dist/cache/timber-cache.d.ts.map +1 -1
- package/dist/client/error-boundary.js +2 -1
- package/dist/client/error-boundary.js.map +1 -1
- package/dist/client/form.d.ts +10 -24
- package/dist/client/form.d.ts.map +1 -1
- package/dist/client/index.d.ts +1 -5
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +41 -91
- package/dist/client/index.js.map +1 -1
- package/dist/client/internal.d.ts +2 -1
- package/dist/client/internal.d.ts.map +1 -1
- package/dist/client/internal.js +81 -7
- package/dist/client/internal.js.map +1 -1
- package/dist/client/rsc-fetch.d.ts.map +1 -1
- package/dist/client/state.d.ts +1 -1
- package/dist/client/use-cookie.d.ts +8 -0
- package/dist/client/use-cookie.d.ts.map +1 -1
- package/dist/client/{use-params.d.ts → use-segment-params.d.ts} +1 -1
- package/dist/client/use-segment-params.d.ts.map +1 -0
- package/dist/codec.d.ts +1 -1
- package/dist/codec.d.ts.map +1 -1
- package/dist/codec.js +2 -2
- package/dist/config-types.d.ts +28 -0
- package/dist/config-types.d.ts.map +1 -1
- package/dist/cookies/define-cookie.d.ts +87 -35
- package/dist/cookies/define-cookie.d.ts.map +1 -1
- package/dist/cookies/index.d.ts +2 -1
- package/dist/cookies/index.d.ts.map +1 -1
- package/dist/cookies/index.js +48 -2
- package/dist/cookies/index.js.map +1 -0
- package/dist/cookies/json-cookie.d.ts +64 -0
- package/dist/cookies/json-cookie.d.ts.map +1 -0
- package/dist/cookies/validation.d.ts +46 -0
- package/dist/cookies/validation.d.ts.map +1 -0
- package/dist/{plugins/dev-404-page.d.ts → dev-tools/404-page.d.ts} +9 -19
- package/dist/dev-tools/404-page.d.ts.map +1 -0
- package/dist/{plugins/dev-browser-logs.d.ts → dev-tools/browser-logs.d.ts} +1 -1
- package/dist/dev-tools/browser-logs.d.ts.map +1 -0
- package/dist/{plugins/dev-error-page.d.ts → dev-tools/error-page.d.ts} +2 -2
- package/dist/dev-tools/error-page.d.ts.map +1 -0
- package/dist/{server/dev-holding-server.d.ts → dev-tools/holding-server.d.ts} +5 -3
- package/dist/dev-tools/holding-server.d.ts.map +1 -0
- package/dist/dev-tools/index.d.ts +31 -0
- package/dist/dev-tools/index.d.ts.map +1 -0
- package/dist/{server/dev-span-processor.d.ts → dev-tools/instrumentation.d.ts} +26 -6
- package/dist/dev-tools/instrumentation.d.ts.map +1 -0
- package/dist/{server/dev-logger.d.ts → dev-tools/logger.d.ts} +1 -1
- package/dist/dev-tools/logger.d.ts.map +1 -0
- package/dist/{plugins/dev-logs.d.ts → dev-tools/logs.d.ts} +1 -1
- package/dist/dev-tools/logs.d.ts.map +1 -0
- package/dist/{plugins/dev-error-overlay.d.ts → dev-tools/overlay.d.ts} +3 -12
- package/dist/dev-tools/overlay.d.ts.map +1 -0
- package/dist/dev-tools/stack-classifier.d.ts +34 -0
- package/dist/dev-tools/stack-classifier.d.ts.map +1 -0
- package/dist/{plugins/dev-terminal-error.d.ts → dev-tools/terminal.d.ts} +2 -2
- package/dist/dev-tools/terminal.d.ts.map +1 -0
- package/dist/{server/dev-warnings.d.ts → dev-tools/warnings.d.ts} +1 -1
- package/dist/dev-tools/warnings.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +285 -133
- package/dist/index.js.map +1 -1
- package/dist/plugin-context.d.ts +1 -1
- package/dist/plugin-context.d.ts.map +1 -1
- package/dist/plugins/adapter-build.d.ts.map +1 -1
- package/dist/plugins/build-report.d.ts +6 -4
- package/dist/plugins/build-report.d.ts.map +1 -1
- package/dist/routing/convention-lint.d.ts.map +1 -1
- package/dist/routing/index.d.ts +5 -3
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/index.js +3 -3
- package/dist/routing/scanner.d.ts +1 -10
- package/dist/routing/scanner.d.ts.map +1 -1
- package/dist/routing/segment-classify.d.ts +37 -8
- package/dist/routing/segment-classify.d.ts.map +1 -1
- package/dist/routing/status-file-lint.d.ts.map +1 -1
- package/dist/routing/types.d.ts +63 -23
- package/dist/routing/types.d.ts.map +1 -1
- package/dist/routing/walkers.d.ts +51 -0
- package/dist/routing/walkers.d.ts.map +1 -0
- package/dist/search-params/define.d.ts +25 -7
- package/dist/search-params/define.d.ts.map +1 -1
- package/dist/search-params/index.js +5 -3
- package/dist/search-params/index.js.map +1 -1
- package/dist/search-params/wrappers.d.ts +2 -2
- package/dist/search-params/wrappers.d.ts.map +1 -1
- package/dist/segment-params/define.d.ts +23 -6
- package/dist/segment-params/define.d.ts.map +1 -1
- package/dist/segment-params/index.js +1 -1
- package/dist/server/access-gate.d.ts +4 -3
- package/dist/server/access-gate.d.ts.map +1 -1
- package/dist/server/action-handler.d.ts +15 -6
- package/dist/server/action-handler.d.ts.map +1 -1
- package/dist/server/als-registry.d.ts +5 -5
- package/dist/server/als-registry.d.ts.map +1 -1
- package/dist/server/asset-headers.d.ts +1 -15
- package/dist/server/asset-headers.d.ts.map +1 -1
- package/dist/server/cookie-context.d.ts +170 -0
- package/dist/server/cookie-context.d.ts.map +1 -0
- package/dist/server/cookie-parsing.d.ts +51 -0
- package/dist/server/cookie-parsing.d.ts.map +1 -0
- package/dist/server/deny-boundary.d.ts +90 -0
- package/dist/server/deny-boundary.d.ts.map +1 -0
- package/dist/server/deny-renderer.d.ts.map +1 -1
- package/dist/server/early-hints-sender.d.ts.map +1 -1
- package/dist/server/html-injector-core.d.ts +212 -0
- package/dist/server/html-injector-core.d.ts.map +1 -0
- package/dist/server/html-injectors.d.ts +59 -59
- package/dist/server/html-injectors.d.ts.map +1 -1
- package/dist/server/index.d.ts +5 -4
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +4 -149
- package/dist/server/index.js.map +1 -1
- package/dist/server/internal.d.ts +6 -4
- package/dist/server/internal.d.ts.map +1 -1
- package/dist/server/internal.js +852 -852
- package/dist/server/internal.js.map +1 -1
- package/dist/server/logger.d.ts +14 -0
- package/dist/server/logger.d.ts.map +1 -1
- package/dist/server/middleware-runner.d.ts +17 -0
- package/dist/server/middleware-runner.d.ts.map +1 -1
- package/dist/server/node-stream-transforms.d.ts +46 -49
- package/dist/server/node-stream-transforms.d.ts.map +1 -1
- package/dist/server/param-coercion.d.ts +26 -0
- package/dist/server/param-coercion.d.ts.map +1 -0
- package/dist/server/pipeline-helpers.d.ts +95 -0
- package/dist/server/pipeline-helpers.d.ts.map +1 -0
- package/dist/server/pipeline-outcome.d.ts +49 -0
- package/dist/server/pipeline-outcome.d.ts.map +1 -0
- package/dist/server/pipeline-phases.d.ts +52 -0
- package/dist/server/pipeline-phases.d.ts.map +1 -0
- package/dist/server/pipeline.d.ts +51 -32
- package/dist/server/pipeline.d.ts.map +1 -1
- package/dist/server/port-resolution.d.ts +117 -0
- package/dist/server/port-resolution.d.ts.map +1 -0
- package/dist/server/request-context.d.ts +22 -159
- package/dist/server/request-context.d.ts.map +1 -1
- package/dist/server/route-element-builder.d.ts.map +1 -1
- package/dist/server/route-matcher.d.ts +20 -47
- package/dist/server/route-matcher.d.ts.map +1 -1
- package/dist/server/rsc-entry/action-middleware-runner.d.ts +66 -0
- package/dist/server/rsc-entry/action-middleware-runner.d.ts.map +1 -0
- package/dist/server/rsc-entry/helpers.d.ts +1 -1
- package/dist/server/rsc-entry/helpers.d.ts.map +1 -1
- package/dist/server/rsc-entry/index.d.ts.map +1 -1
- package/dist/server/rsc-entry/render-route.d.ts +50 -0
- package/dist/server/rsc-entry/render-route.d.ts.map +1 -0
- package/dist/server/rsc-entry/wrap-action-dispatch.d.ts +119 -0
- package/dist/server/rsc-entry/wrap-action-dispatch.d.ts.map +1 -0
- package/dist/server/state-tree-diff.d.ts.map +1 -1
- package/dist/server/status-code-resolver.d.ts +16 -11
- package/dist/server/status-code-resolver.d.ts.map +1 -1
- package/dist/server/tracing.d.ts +1 -1
- package/dist/server/tracing.d.ts.map +1 -1
- package/dist/server/tree-builder.d.ts +45 -16
- package/dist/server/tree-builder.d.ts.map +1 -1
- package/dist/server/types.d.ts +48 -0
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/utils/escape-html.d.ts +14 -0
- package/dist/server/utils/escape-html.d.ts.map +1 -0
- package/dist/shims/headers.d.ts +2 -2
- package/dist/shims/headers.d.ts.map +1 -1
- package/dist/shims/navigation-client.d.ts +3 -1
- package/dist/shims/navigation-client.d.ts.map +1 -1
- package/dist/shims/navigation.d.ts +9 -4
- package/dist/shims/navigation.d.ts.map +1 -1
- package/dist/utils/directive-parser.d.ts +0 -45
- package/dist/utils/directive-parser.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/adapters/build-output-helper.ts +77 -0
- package/src/adapters/cloudflare.ts +10 -50
- package/src/adapters/nitro.ts +66 -50
- package/src/adapters/shared.ts +40 -0
- package/src/cache/timber-cache.ts +3 -2
- package/src/client/form.tsx +17 -25
- package/src/client/index.ts +16 -9
- package/src/client/internal.ts +3 -2
- package/src/client/router.ts +1 -1
- package/src/client/rsc-fetch.ts +15 -0
- package/src/client/state.ts +2 -2
- package/src/client/use-cookie.ts +29 -0
- package/src/codec.ts +3 -7
- package/src/config-types.ts +28 -0
- package/src/cookies/define-cookie.ts +271 -78
- package/src/cookies/index.ts +11 -8
- package/src/cookies/json-cookie.ts +105 -0
- package/src/cookies/validation.ts +134 -0
- package/src/{plugins/dev-404-page.ts → dev-tools/404-page.ts} +17 -48
- package/src/{plugins/dev-error-page.ts → dev-tools/error-page.ts} +5 -32
- package/src/{server/dev-holding-server.ts → dev-tools/holding-server.ts} +4 -2
- package/src/dev-tools/index.ts +90 -0
- package/src/dev-tools/instrumentation.ts +176 -0
- package/src/{plugins/dev-logs.ts → dev-tools/logs.ts} +2 -2
- package/src/{plugins/dev-error-overlay.ts → dev-tools/overlay.ts} +5 -23
- package/src/dev-tools/stack-classifier.ts +75 -0
- package/src/{plugins/dev-terminal-error.ts → dev-tools/terminal.ts} +4 -38
- package/src/{server/dev-warnings.ts → dev-tools/warnings.ts} +1 -1
- package/src/index.ts +95 -34
- package/src/plugin-context.ts +1 -1
- package/src/plugins/adapter-build.ts +3 -1
- package/src/plugins/build-report.ts +13 -22
- package/src/plugins/dev-server.ts +3 -3
- package/src/plugins/routing.ts +14 -12
- package/src/plugins/shims.ts +1 -1
- package/src/plugins/static-build.ts +1 -1
- package/src/routing/codegen.ts +1 -1
- package/src/routing/convention-lint.ts +9 -8
- package/src/routing/index.ts +5 -3
- package/src/routing/interception.ts +1 -1
- package/src/routing/scanner.ts +22 -95
- package/src/routing/segment-classify.ts +107 -8
- package/src/routing/status-file-lint.ts +7 -5
- package/src/routing/types.ts +63 -23
- package/src/routing/walkers.ts +90 -0
- package/src/search-params/define.ts +71 -15
- package/src/search-params/wrappers.ts +9 -2
- package/src/segment-params/define.ts +66 -13
- package/src/server/access-gate.tsx +9 -8
- package/src/server/action-handler.ts +34 -38
- package/src/server/als-registry.ts +5 -5
- package/src/server/asset-headers.ts +8 -34
- package/src/server/cookie-context.ts +468 -0
- package/src/server/cookie-parsing.ts +135 -0
- package/src/server/{deny-page-resolver.ts → deny-boundary.ts} +78 -14
- package/src/server/deny-renderer.ts +7 -12
- package/src/server/early-hints-sender.ts +3 -2
- package/src/server/fallback-error.ts +2 -2
- package/src/server/html-injector-core.ts +403 -0
- package/src/server/html-injectors.ts +158 -297
- package/src/server/index.ts +13 -14
- package/src/server/internal.ts +10 -3
- package/src/server/logger.ts +23 -0
- package/src/server/middleware-runner.ts +44 -0
- package/src/server/node-stream-transforms.ts +108 -248
- package/src/server/param-coercion.ts +76 -0
- package/src/server/pipeline-helpers.ts +204 -0
- package/src/server/pipeline-outcome.ts +167 -0
- package/src/server/pipeline-phases.ts +409 -0
- package/src/server/pipeline.ts +70 -540
- package/src/server/port-resolution.ts +215 -0
- package/src/server/request-context.ts +46 -451
- package/src/server/route-element-builder.ts +8 -4
- package/src/server/route-matcher.ts +28 -60
- package/src/server/rsc-entry/action-middleware-runner.ts +167 -0
- package/src/server/rsc-entry/api-handler.ts +2 -2
- package/src/server/rsc-entry/error-renderer.ts +2 -2
- package/src/server/rsc-entry/helpers.ts +2 -7
- package/src/server/rsc-entry/index.ts +81 -366
- package/src/server/rsc-entry/render-route.ts +304 -0
- package/src/server/rsc-entry/rsc-payload.ts +1 -1
- package/src/server/rsc-entry/ssr-renderer.ts +2 -2
- package/src/server/rsc-entry/wrap-action-dispatch.ts +449 -0
- package/src/server/sitemap-generator.ts +1 -1
- package/src/server/slot-resolver.ts +1 -1
- package/src/server/ssr-entry.ts +1 -1
- package/src/server/state-tree-diff.ts +4 -1
- package/src/server/status-code-resolver.ts +112 -128
- package/src/server/tracing.ts +3 -3
- package/src/server/tree-builder.ts +134 -56
- package/src/server/types.ts +52 -0
- package/src/server/utils/escape-html.ts +20 -0
- package/src/shims/headers.ts +3 -3
- package/src/shims/navigation-client.ts +4 -3
- package/src/shims/navigation.ts +9 -7
- package/src/utils/directive-parser.ts +0 -392
- package/dist/_chunks/actions-DLnUaR65.js +0 -421
- package/dist/_chunks/actions-DLnUaR65.js.map +0 -1
- package/dist/_chunks/als-registry-HS0LGUl2.js +0 -41
- package/dist/_chunks/als-registry-HS0LGUl2.js.map +0 -1
- package/dist/_chunks/debug-ECi_61pb.js +0 -108
- package/dist/_chunks/debug-ECi_61pb.js.map +0 -1
- package/dist/_chunks/define-C77ScO0m.js.map +0 -1
- package/dist/_chunks/define-Itxvcd7F.js.map +0 -1
- package/dist/_chunks/define-cookie-BowvzoP0.js +0 -94
- package/dist/_chunks/define-cookie-BowvzoP0.js.map +0 -1
- package/dist/_chunks/dev-warnings-DpGRGoDi.js.map +0 -1
- package/dist/_chunks/interception-BbqMCVXa.js.map +0 -1
- package/dist/_chunks/merge-search-params-Cm_KIWDX.js +0 -41
- package/dist/_chunks/merge-search-params-Cm_KIWDX.js.map +0 -1
- package/dist/_chunks/request-context-CK5tZqIP.js +0 -478
- package/dist/_chunks/request-context-CK5tZqIP.js.map +0 -1
- package/dist/_chunks/router-ref-C8OCm7g7.js.map +0 -1
- package/dist/_chunks/segment-classify-BDNn6EzD.js +0 -65
- package/dist/_chunks/segment-classify-BDNn6EzD.js.map +0 -1
- package/dist/_chunks/tracing-CCYbKn5n.js +0 -238
- package/dist/_chunks/tracing-CCYbKn5n.js.map +0 -1
- package/dist/_chunks/use-params-IOPu7E8t.js.map +0 -1
- package/dist/_chunks/use-query-states-BiV5GJgm.js.map +0 -1
- package/dist/client/use-params.d.ts.map +0 -1
- package/dist/plugins/dev-404-page.d.ts.map +0 -1
- package/dist/plugins/dev-browser-logs.d.ts.map +0 -1
- package/dist/plugins/dev-error-overlay.d.ts.map +0 -1
- package/dist/plugins/dev-error-page.d.ts.map +0 -1
- package/dist/plugins/dev-logs.d.ts.map +0 -1
- package/dist/plugins/dev-terminal-error.d.ts.map +0 -1
- package/dist/server/deny-page-resolver.d.ts +0 -52
- package/dist/server/deny-page-resolver.d.ts.map +0 -1
- package/dist/server/dev-fetch-instrumentation.d.ts +0 -22
- package/dist/server/dev-fetch-instrumentation.d.ts.map +0 -1
- package/dist/server/dev-holding-server.d.ts.map +0 -1
- package/dist/server/dev-logger.d.ts.map +0 -1
- package/dist/server/dev-span-processor.d.ts.map +0 -1
- package/dist/server/dev-warnings.d.ts.map +0 -1
- package/dist/server/manifest-status-resolver.d.ts +0 -58
- package/dist/server/manifest-status-resolver.d.ts.map +0 -1
- package/dist/server/page-deny-boundary.d.ts +0 -31
- package/dist/server/page-deny-boundary.d.ts.map +0 -1
- package/src/server/dev-fetch-instrumentation.ts +0 -96
- package/src/server/dev-span-processor.ts +0 -78
- package/src/server/manifest-status-resolver.ts +0 -215
- package/src/server/page-deny-boundary.tsx +0 -56
- /package/src/client/{use-params.ts → use-segment-params.ts} +0 -0
- /package/src/{plugins/dev-browser-logs.ts → dev-tools/browser-logs.ts} +0 -0
- /package/src/{server/dev-logger.ts → dev-tools/logger.ts} +0 -0
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cookie Context — per-request cookie API and on-the-wire helpers.
|
|
3
|
+
*
|
|
4
|
+
* Split out of `request-context.ts` (TIM-853) so the cookie subsystem
|
|
5
|
+
* — encoding contract, options grammar, parser, serializer, RYW map,
|
|
6
|
+
* and rerender seed — lives in one file. The headers/scope/params APIs
|
|
7
|
+
* stay in `request-context.ts` and call into this module via the
|
|
8
|
+
* exported helpers.
|
|
9
|
+
*
|
|
10
|
+
* See design/29-cookies.md for the encoding contract and read-your-own-
|
|
11
|
+
* writes semantics. See ONGOING_SECURITY.md H-3 (TIM-868) for the
|
|
12
|
+
* smuggling primitive that the encoding contract closes.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { requestContextAls, type RequestContextStore } from './als-registry.js';
|
|
16
|
+
import { isDebug } from './debug.js';
|
|
17
|
+
import { assertValidCookieName, assertValidCookieValue } from '../cookies/validation.js';
|
|
18
|
+
import {
|
|
19
|
+
parseCookieHeader,
|
|
20
|
+
parseSetCookie,
|
|
21
|
+
safeDecodeCookieValue,
|
|
22
|
+
serializeCookieEntry,
|
|
23
|
+
} from './cookie-parsing.js';
|
|
24
|
+
|
|
25
|
+
// Re-export the validators so framework-internal consumers and tests can
|
|
26
|
+
// import the canonical implementation from the same module that hosts
|
|
27
|
+
// `getCookies()`. The pure shared module lives in `cookies/validation.ts`
|
|
28
|
+
// so the client `useCookie` hook can use the same checks without pulling
|
|
29
|
+
// in the server ALS code.
|
|
30
|
+
export { assertValidCookieName, assertValidCookieValue };
|
|
31
|
+
|
|
32
|
+
// ─── Public API ───────────────────────────────────────────────────────────
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Returns a cookie accessor for the current request.
|
|
36
|
+
*
|
|
37
|
+
* Available in middleware, access checks, server components, and server actions.
|
|
38
|
+
* Throws if called outside a request context (security principle #2: no global fallback).
|
|
39
|
+
*
|
|
40
|
+
* Read methods (.get, .has, .getAll) are always available and reflect
|
|
41
|
+
* read-your-own-writes from .set() calls in the same request.
|
|
42
|
+
*
|
|
43
|
+
* Mutation methods (.set, .delete, .clear) are only available in mutable
|
|
44
|
+
* contexts (middleware.ts, server actions, route.ts handlers). Calling them
|
|
45
|
+
* in read-only contexts (access.ts, server components) throws.
|
|
46
|
+
*
|
|
47
|
+
* This is the escape hatch for direct cookie jar operations. For typed
|
|
48
|
+
* cookie access, use `defineCookie()` instead.
|
|
49
|
+
*
|
|
50
|
+
* See design/29-cookies.md
|
|
51
|
+
*/
|
|
52
|
+
export function getCookieJar(): RequestCookies {
|
|
53
|
+
const store = requestContextAls.getStore();
|
|
54
|
+
if (!store) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
'[timber] getCookieJar() called outside of a request context. ' +
|
|
57
|
+
'It can only be used in middleware, access checks, server components, and server actions.'
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Parse cookies lazily on first access
|
|
62
|
+
if (!store.parsedCookies) {
|
|
63
|
+
store.parsedCookies = parseCookieHeader(store.cookieHeader);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const map = store.parsedCookies;
|
|
67
|
+
return {
|
|
68
|
+
get(name: string): string | undefined {
|
|
69
|
+
return map.get(name);
|
|
70
|
+
},
|
|
71
|
+
has(name: string): boolean {
|
|
72
|
+
return map.has(name);
|
|
73
|
+
},
|
|
74
|
+
getAll(): Array<{ name: string; value: string }> {
|
|
75
|
+
return Array.from(map.entries()).map(([name, value]) => ({ name, value }));
|
|
76
|
+
},
|
|
77
|
+
get size(): number {
|
|
78
|
+
return map.size;
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
set(name: string, value: string, options?: SetCookieOptions): void {
|
|
82
|
+
assertMutable(store, 'set');
|
|
83
|
+
// Validate the name first — names cannot be URL-encoded (RFC 7230
|
|
84
|
+
// token grammar is strict), so a bad name is always a bug.
|
|
85
|
+
assertValidCookieName(name);
|
|
86
|
+
// Type guard with a guiding error. The single most common mistake
|
|
87
|
+
// is passing a non-string (object, number, Date) and expecting the
|
|
88
|
+
// framework to JSON-encode. Point developers at jsonCookieCodec.
|
|
89
|
+
if (typeof value !== 'string') {
|
|
90
|
+
throw new Error(
|
|
91
|
+
`[timber] getCookieJar().set(${JSON.stringify(name)}, …): value must be a string, got ${typeof value}.\n` +
|
|
92
|
+
` To store a JSON-serializable value, use defineCookie + jsonCookieCodec:\n` +
|
|
93
|
+
`\n` +
|
|
94
|
+
` import { defineCookie, jsonCookieCodec } from '@timber-js/app/cookies';\n` +
|
|
95
|
+
`\n` +
|
|
96
|
+
` export const ${name}Cookie = defineCookie(${JSON.stringify(name)}, {\n` +
|
|
97
|
+
` codec: jsonCookieCodec(),\n` +
|
|
98
|
+
` });\n` +
|
|
99
|
+
`\n` +
|
|
100
|
+
` ${name}Cookie.set(value);\n` +
|
|
101
|
+
`\n` +
|
|
102
|
+
` See design/29-cookies.md §"Typed Cookies with Schema Validation".`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
// Encode the value so the on-the-wire bytes always satisfy
|
|
106
|
+
// RFC 6265 §4.1.1 cookie-octet. encodeURIComponent's output is a
|
|
107
|
+
// strict subset of cookie-octet (only `A-Z a-z 0-9 ! ' ( ) * - . _
|
|
108
|
+
// ~ %`), so the encoded form can never carry the H-3 smuggling
|
|
109
|
+
// primitive — `;` becomes `%3B`, CR/LF become `%0D`/`%0A`, etc.
|
|
110
|
+
// The round-trip is lossless: parseCookieHeader auto-decodes on
|
|
111
|
+
// read, so `cookies().get(name)` returns exactly `value`. See
|
|
112
|
+
// ONGOING_SECURITY.md H-3 (TIM-868) and design/29-cookies.md
|
|
113
|
+
// §"Encoding Contract".
|
|
114
|
+
//
|
|
115
|
+
// The `{ raw: true }` opt-out skips the encoder for callers who
|
|
116
|
+
// need exact byte control (e.g. forwarding pre-encoded cookies
|
|
117
|
+
// from an upstream service). The opt-out goes through the strict
|
|
118
|
+
// cookie-octet validator instead — the smuggling primitive cannot
|
|
119
|
+
// sneak in via the escape hatch.
|
|
120
|
+
const raw = options?.raw === true;
|
|
121
|
+
const wireValue = raw ? value : encodeURIComponent(value);
|
|
122
|
+
if (raw) {
|
|
123
|
+
assertValidCookieValue(name, wireValue);
|
|
124
|
+
}
|
|
125
|
+
if (store.flushed) {
|
|
126
|
+
if (isDebug()) {
|
|
127
|
+
console.warn(
|
|
128
|
+
`[timber] warn: getCookieJar().set('${name}') called after response headers were committed.\n` +
|
|
129
|
+
` The cookie will NOT be sent. Move cookie mutations to middleware.ts, a server action,\n` +
|
|
130
|
+
` or a route.ts handler.`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
// Strip the framework-only `raw` flag before persisting — it is
|
|
136
|
+
// not an HTTP cookie attribute and must not leak into the jar.
|
|
137
|
+
const { raw: _raw, ...attributeOptions } = options ?? {};
|
|
138
|
+
void _raw;
|
|
139
|
+
const opts = { ...DEFAULT_COOKIE_OPTIONS, ...attributeOptions };
|
|
140
|
+
store.cookieJar.set(name, { name, value: wireValue, options: opts });
|
|
141
|
+
// Read-your-own-writes: store the DECODED logical value so that
|
|
142
|
+
// subsequent `cookies().get(name)` in the same request returns
|
|
143
|
+
// exactly what the developer wrote — never the encoded form.
|
|
144
|
+
// For `{ raw: true }`, the wire form IS the logical form.
|
|
145
|
+
map.set(name, raw ? wireValue : value);
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
setFromHeaders(headers: Headers): void {
|
|
149
|
+
assertMutable(store, 'setFromHeaders');
|
|
150
|
+
if (store.flushed) {
|
|
151
|
+
console.warn(
|
|
152
|
+
`[timber] warn: getCookieJar().setFromHeaders() called after response headers were committed.\n` +
|
|
153
|
+
` The cookies will NOT be sent. Move cookie mutations to middleware.ts, a server action,\n` +
|
|
154
|
+
` or a route.ts handler.`
|
|
155
|
+
);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
// Headers.getSetCookie() returns individual Set-Cookie strings,
|
|
159
|
+
// avoiding the fragile comma-splitting that raw .get() requires.
|
|
160
|
+
for (const raw of headers.getSetCookie()) {
|
|
161
|
+
const parsed = parseSetCookie(raw);
|
|
162
|
+
if (parsed) {
|
|
163
|
+
// Use setRaw to preserve the original header's attributes without
|
|
164
|
+
// merging DEFAULT_COOKIE_OPTIONS (parseSetCookie intentionally
|
|
165
|
+
// does not apply defaults — see its doc comment).
|
|
166
|
+
setRaw(store, map, parsed.name, parsed.value, parsed.options);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
delete(name: string, options?: Pick<CookieOptions, 'path' | 'domain'>): void {
|
|
172
|
+
assertMutable(store, 'delete');
|
|
173
|
+
// Validate the name even though delete writes an empty value — a
|
|
174
|
+
// smuggled name (`;` or CR/LF) would corrupt the Set-Cookie header
|
|
175
|
+
// we emit. See ONGOING_SECURITY.md H-3 (TIM-868).
|
|
176
|
+
assertValidCookieName(name);
|
|
177
|
+
if (store.flushed) {
|
|
178
|
+
if (isDebug()) {
|
|
179
|
+
console.warn(
|
|
180
|
+
`[timber] warn: getCookieJar().delete('${name}') called after response headers were committed.\n` +
|
|
181
|
+
` The cookie will NOT be deleted. Move cookie mutations to middleware.ts, a server action,\n` +
|
|
182
|
+
` or a route.ts handler.`
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const opts: CookieOptions = {
|
|
188
|
+
...DEFAULT_COOKIE_OPTIONS,
|
|
189
|
+
...options,
|
|
190
|
+
maxAge: 0,
|
|
191
|
+
expires: new Date(0),
|
|
192
|
+
};
|
|
193
|
+
store.cookieJar.set(name, { name, value: '', options: opts });
|
|
194
|
+
// Remove from read view
|
|
195
|
+
map.delete(name);
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
clear(): void {
|
|
199
|
+
assertMutable(store, 'clear');
|
|
200
|
+
if (store.flushed) return;
|
|
201
|
+
// Delete every incoming cookie
|
|
202
|
+
for (const name of Array.from(map.keys())) {
|
|
203
|
+
store.cookieJar.set(name, {
|
|
204
|
+
name,
|
|
205
|
+
value: '',
|
|
206
|
+
options: { ...DEFAULT_COOKIE_OPTIONS, maxAge: 0, expires: new Date(0) },
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
map.clear();
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
toString(): string {
|
|
213
|
+
// Re-encode values when serializing as a Cookie header — the
|
|
214
|
+
// RYW map holds decoded logical values, but a Cookie header has
|
|
215
|
+
// to satisfy `cookie-octet`. Mirror the auto-encode contract on
|
|
216
|
+
// `set()` so toString() round-trips losslessly with parseCookieHeader.
|
|
217
|
+
return Array.from(map.entries())
|
|
218
|
+
.map(([name, value]) => `${name}=${encodeURIComponent(value)}`)
|
|
219
|
+
.join('; ');
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Returns the value of a single cookie, or undefined if absent.
|
|
226
|
+
*
|
|
227
|
+
* @internal — not part of the public API. Use `defineCookie().get()` or `getCookieJar().get()` instead.
|
|
228
|
+
*/
|
|
229
|
+
export function getCookie(name: string): string | undefined {
|
|
230
|
+
const jar = getCookieJar();
|
|
231
|
+
return jar.get(name);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// ─── Types ────────────────────────────────────────────────────────────────
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Per-call options for `getCookies().set()`. Extends the persistent
|
|
238
|
+
* `CookieOptions` (HTTP cookie attributes) with framework-only flags
|
|
239
|
+
* that are NOT serialized into the Set-Cookie header.
|
|
240
|
+
*
|
|
241
|
+
* The `raw` flag is the escape hatch for the auto-encoding contract.
|
|
242
|
+
* See design/29-cookies.md §"Encoding Contract".
|
|
243
|
+
*/
|
|
244
|
+
export interface SetCookieOptions extends CookieOptions {
|
|
245
|
+
/**
|
|
246
|
+
* Skip the framework's `encodeURIComponent` pass and store the value
|
|
247
|
+
* verbatim. The value is then validated against the strict RFC 6265
|
|
248
|
+
* §4.1.1 `cookie-octet` grammar — the H-3 smuggling primitive cannot
|
|
249
|
+
* sneak in via this opt-out.
|
|
250
|
+
*
|
|
251
|
+
* Use this when forwarding a cookie value that is already in its
|
|
252
|
+
* intended on-the-wire form (e.g. mirroring an upstream service's
|
|
253
|
+
* Set-Cookie). Default: `false` (auto-encode).
|
|
254
|
+
*/
|
|
255
|
+
raw?: boolean;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Options for setting a cookie. See design/29-cookies.md. */
|
|
259
|
+
export interface CookieOptions {
|
|
260
|
+
/** Domain scope. Default: omitted (current domain only). */
|
|
261
|
+
domain?: string;
|
|
262
|
+
/** URL path scope. Default: '/'. */
|
|
263
|
+
path?: string;
|
|
264
|
+
/** Expiration date. Mutually exclusive with maxAge. */
|
|
265
|
+
expires?: Date;
|
|
266
|
+
/** Max age in seconds. Mutually exclusive with expires. */
|
|
267
|
+
maxAge?: number;
|
|
268
|
+
/** Prevent client-side JS access. Default: true. */
|
|
269
|
+
httpOnly?: boolean;
|
|
270
|
+
/** Only send over HTTPS. Default: true. */
|
|
271
|
+
secure?: boolean;
|
|
272
|
+
/** Cross-site request policy. Default: 'lax'. */
|
|
273
|
+
sameSite?: 'strict' | 'lax' | 'none';
|
|
274
|
+
/** Partitioned (CHIPS) — isolate cookie per top-level site. Default: false. */
|
|
275
|
+
partitioned?: boolean;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Cookie accessor returned by `getCookies()`.
|
|
280
|
+
*
|
|
281
|
+
* Read methods are always available. Mutation methods throw in read-only
|
|
282
|
+
* contexts (access.ts, server components).
|
|
283
|
+
*/
|
|
284
|
+
export interface RequestCookies {
|
|
285
|
+
/** Get a cookie value by name. Returns undefined if not present. */
|
|
286
|
+
get(name: string): string | undefined;
|
|
287
|
+
/** Check if a cookie exists. */
|
|
288
|
+
has(name: string): boolean;
|
|
289
|
+
/** Get all cookies as an array of { name, value } pairs. */
|
|
290
|
+
getAll(): Array<{ name: string; value: string }>;
|
|
291
|
+
/** Number of cookies. */
|
|
292
|
+
readonly size: number;
|
|
293
|
+
/**
|
|
294
|
+
* Set a cookie. Only available in mutable contexts (middleware, actions,
|
|
295
|
+
* route handlers).
|
|
296
|
+
*
|
|
297
|
+
* The value is auto-encoded with `encodeURIComponent` so the on-the-wire
|
|
298
|
+
* bytes always satisfy RFC 6265 §4.1.1 cookie-octet — `cookies().get()`
|
|
299
|
+
* returns the same logical value the developer wrote. Pass `{ raw: true }`
|
|
300
|
+
* to skip the encoder; the raw path validates against the strict
|
|
301
|
+
* cookie-octet grammar instead. See design/29-cookies.md §"Encoding
|
|
302
|
+
* Contract" and ONGOING_SECURITY.md H-3 (TIM-868).
|
|
303
|
+
*/
|
|
304
|
+
set(name: string, value: string, options?: SetCookieOptions): void;
|
|
305
|
+
/**
|
|
306
|
+
* Copy all `Set-Cookie` headers from a `Headers` object.
|
|
307
|
+
* Parses each header and forwards name, value, and all attributes
|
|
308
|
+
* (path, domain, max-age, expires, sameSite, secure, httpOnly, partitioned).
|
|
309
|
+
*
|
|
310
|
+
* Useful when forwarding cookies from an internal `fetch()` or auth handler:
|
|
311
|
+
* ```ts
|
|
312
|
+
* const response = await auth.handler(req);
|
|
313
|
+
* getCookies().then(c => c.setFromHeaders(response.headers));
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
setFromHeaders(headers: Headers): void;
|
|
317
|
+
/** Delete a cookie. Only available in mutable contexts. */
|
|
318
|
+
delete(name: string, options?: Pick<CookieOptions, 'path' | 'domain'>): void;
|
|
319
|
+
/** Delete all cookies. Only available in mutable contexts. */
|
|
320
|
+
clear(): void;
|
|
321
|
+
/** Serialize cookies as a Cookie header string. */
|
|
322
|
+
toString(): string;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const DEFAULT_COOKIE_OPTIONS: CookieOptions = {
|
|
326
|
+
path: '/',
|
|
327
|
+
httpOnly: true,
|
|
328
|
+
secure: true,
|
|
329
|
+
sameSite: 'lax',
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// ─── Framework-Internal Helpers ───────────────────────────────────────────
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Per-request seed map of cookie name → value, registered out-of-band so the
|
|
336
|
+
* pipeline's `runWithRequestContext` call can pick it up without changing
|
|
337
|
+
* the function's calling convention. Stored in a WeakMap keyed by the
|
|
338
|
+
* synthetic Request object built for the rerender path, so the seed lives
|
|
339
|
+
* exactly as long as the request and is collected with it.
|
|
340
|
+
*
|
|
341
|
+
* The seed exists to eliminate the parse/serialize round-trip on the no-JS
|
|
342
|
+
* form-rerender path — see ONGOING_SECURITY.md H-3 (TIM-868). The action's
|
|
343
|
+
* post-mutation RYW snapshot is threaded directly into the rerender scope's
|
|
344
|
+
* `parsedCookies` map, bypassing `parseCookieHeader` entirely.
|
|
345
|
+
*/
|
|
346
|
+
const seededRequestCookies = new WeakMap<Request, Map<string, string>>();
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Register a pre-parsed cookie map to use as the request context seed for
|
|
350
|
+
* the next `runWithRequestContext(req, …)` call with this exact `req`.
|
|
351
|
+
*
|
|
352
|
+
* Used by the no-JS form-rerender dispatcher in
|
|
353
|
+
* `rsc-entry/wrap-action-dispatch.ts` to thread the action's post-mutation
|
|
354
|
+
* cookie state into the rerender scope without serializing back through a
|
|
355
|
+
* `Cookie:` header. See TIM-868 / TIM-837.
|
|
356
|
+
*
|
|
357
|
+
* @internal — framework use only.
|
|
358
|
+
*/
|
|
359
|
+
export function seedRequestCookies(req: Request, cookies: Map<string, string>): void {
|
|
360
|
+
// Defensive copy: callers must not be able to mutate the rerender scope's
|
|
361
|
+
// map after seeding, and the rerender scope must not mutate the snapshot
|
|
362
|
+
// we hand back to other observers.
|
|
363
|
+
seededRequestCookies.set(req, new Map(cookies));
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Pop the seed (if any) for `req` and return it. Called from
|
|
368
|
+
* `runWithRequestContext` exactly once per request — the seed is consumed
|
|
369
|
+
* eagerly so it cannot leak into a hypothetical future re-use of the same
|
|
370
|
+
* Request reference.
|
|
371
|
+
*
|
|
372
|
+
* @internal — framework use only.
|
|
373
|
+
*/
|
|
374
|
+
export function consumeSeededCookies(req: Request): Map<string, string> | undefined {
|
|
375
|
+
const seed = seededRequestCookies.get(req);
|
|
376
|
+
if (seed) seededRequestCookies.delete(req);
|
|
377
|
+
return seed;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Build a Map of cookie name → value reflecting the current request's
|
|
382
|
+
* read-your-own-writes state. Includes incoming cookies plus any
|
|
383
|
+
* mutations from getCookies().set() / getCookies().delete() in the same request.
|
|
384
|
+
*
|
|
385
|
+
* Used by SSR renderers to populate NavContext.cookies so that
|
|
386
|
+
* useCookie()'s server snapshot matches the actual response state.
|
|
387
|
+
*
|
|
388
|
+
* See design/29-cookies.md §"Read-Your-Own-Writes"
|
|
389
|
+
* See design/triage/TIM-441-cookie-api-triage.md §4
|
|
390
|
+
*/
|
|
391
|
+
export function getCookiesForSsr(): Map<string, string> {
|
|
392
|
+
const store = requestContextAls.getStore();
|
|
393
|
+
if (!store) {
|
|
394
|
+
throw new Error('[timber] getCookiesForSsr() called outside of a request context.');
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Trigger lazy parsing if not yet done
|
|
398
|
+
if (!store.parsedCookies) {
|
|
399
|
+
store.parsedCookies = parseCookieHeader(store.cookieHeader);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// The parsedCookies map already reflects read-your-own-writes:
|
|
403
|
+
// - getCookies().set() updates the map via map.set(name, value)
|
|
404
|
+
// - getCookies().delete() removes from the map via map.delete(name)
|
|
405
|
+
// Return a copy so callers can't mutate the internal map.
|
|
406
|
+
return new Map(store.parsedCookies);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Collect all Set-Cookie headers from the cookie jar.
|
|
411
|
+
* Called by the framework at flush time to apply cookies to the response.
|
|
412
|
+
*
|
|
413
|
+
* Returns an array of serialized Set-Cookie header values.
|
|
414
|
+
*/
|
|
415
|
+
export function getSetCookieHeaders(): string[] {
|
|
416
|
+
const store = requestContextAls.getStore();
|
|
417
|
+
if (!store) return [];
|
|
418
|
+
return Array.from(store.cookieJar.values()).map(serializeCookieEntry);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// ─── Cookie Helpers ───────────────────────────────────────────────────────
|
|
422
|
+
|
|
423
|
+
/** Throw if cookie mutation is attempted in a read-only context. */
|
|
424
|
+
function assertMutable(store: RequestContextStore, method: string): void {
|
|
425
|
+
if (!store.mutableContext) {
|
|
426
|
+
throw new Error(
|
|
427
|
+
`[timber] getCookieJar().${method}() cannot be called in this context.\n` +
|
|
428
|
+
` Set cookies in middleware.ts, server actions, or route.ts handlers.`
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Write a cookie to the jar WITHOUT merging DEFAULT_COOKIE_OPTIONS.
|
|
435
|
+
* Used by setFromHeaders to preserve the original header's attributes exactly.
|
|
436
|
+
*
|
|
437
|
+
* For deletion cookies (maxAge=0), the jar entry is still created so the
|
|
438
|
+
* Set-Cookie header is emitted, but the cookie is NOT added to the read map
|
|
439
|
+
* (it would be misleading — the cookie is being deleted).
|
|
440
|
+
*/
|
|
441
|
+
function setRaw(
|
|
442
|
+
store: RequestContextStore,
|
|
443
|
+
readMap: Map<string, string>,
|
|
444
|
+
name: string,
|
|
445
|
+
value: string,
|
|
446
|
+
options: CookieOptions
|
|
447
|
+
): void {
|
|
448
|
+
// setRaw is the forwarding path for upstream Set-Cookie headers
|
|
449
|
+
// (`getCookies().setFromHeaders(response.headers)`). The value comes
|
|
450
|
+
// out of `parseSetCookie` in its on-the-wire form — already encoded
|
|
451
|
+
// by whoever produced it — so we re-emit it verbatim into our jar.
|
|
452
|
+
// We DO validate against the strict cookie-octet grammar, both as
|
|
453
|
+
// defense-in-depth against a malicious upstream and to keep the
|
|
454
|
+
// ONGOING_SECURITY.md H-3 invariant intact at every entry point into
|
|
455
|
+
// the cookie jar / RYW map.
|
|
456
|
+
assertValidCookieName(name);
|
|
457
|
+
assertValidCookieValue(name, value);
|
|
458
|
+
store.cookieJar.set(name, { name, value, options });
|
|
459
|
+
// Deletion cookies (Max-Age=0) should not appear in the read map.
|
|
460
|
+
if (options.maxAge === 0) {
|
|
461
|
+
readMap.delete(name);
|
|
462
|
+
} else {
|
|
463
|
+
// Decode for the RYW map so consumers see the same logical bytes
|
|
464
|
+
// they would see if the upstream cookie had arrived on the next
|
|
465
|
+
// request. Mirrors `parseCookieHeader`'s auto-decode.
|
|
466
|
+
readMap.set(name, safeDecodeCookieValue(value));
|
|
467
|
+
}
|
|
468
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cookie parsing and serialization helpers — pure string ↔ structure
|
|
3
|
+
* functions with no ALS dependency. Split out of `cookie-context.ts`
|
|
4
|
+
* (TIM-853) so the API surface and the wire-format codecs can each be
|
|
5
|
+
* read on their own.
|
|
6
|
+
*
|
|
7
|
+
* The functions in this module are total over arbitrary input. They
|
|
8
|
+
* never throw and never call `assertValid*` (the security validators
|
|
9
|
+
* live in the API surface — `cookie-context.ts` invokes them at every
|
|
10
|
+
* jar entry point so the smuggling-primitive invariant from TIM-868
|
|
11
|
+
* is enforced regardless of which path produced the bytes).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { CookieEntry } from './als-registry.js';
|
|
15
|
+
import type { CookieOptions } from './cookie-context.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Parse a Cookie header string into a Map of name → value pairs.
|
|
19
|
+
* Follows RFC 6265 §4.2.1: cookies are semicolon-separated key=value pairs.
|
|
20
|
+
*
|
|
21
|
+
* Values are auto-decoded with `decodeURIComponent` so they round-trip
|
|
22
|
+
* losslessly with `getCookies().set()` (which auto-encodes). Malformed
|
|
23
|
+
* `%`-escapes from third-party cookies fall back to the raw byte sequence
|
|
24
|
+
* — the parser must be total over arbitrary inbound headers, including
|
|
25
|
+
* non-conforming values from other servers, browser extensions, etc.
|
|
26
|
+
*/
|
|
27
|
+
export function parseCookieHeader(header: string): Map<string, string> {
|
|
28
|
+
const map = new Map<string, string>();
|
|
29
|
+
if (!header) return map;
|
|
30
|
+
|
|
31
|
+
for (const pair of header.split(';')) {
|
|
32
|
+
const eqIndex = pair.indexOf('=');
|
|
33
|
+
if (eqIndex === -1) continue;
|
|
34
|
+
const name = pair.slice(0, eqIndex).trim();
|
|
35
|
+
const value = pair.slice(eqIndex + 1).trim();
|
|
36
|
+
if (name) {
|
|
37
|
+
map.set(name, safeDecodeCookieValue(value));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return map;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Decode a single cookie value with `decodeURIComponent`, falling back to
|
|
46
|
+
* the raw byte sequence if the input contains a malformed `%`-escape.
|
|
47
|
+
*
|
|
48
|
+
* Used by both `parseCookieHeader` (incoming Cookie: header) and the
|
|
49
|
+
* `setRaw` forwarding path (outgoing Set-Cookie from upstream services).
|
|
50
|
+
* Total — never throws.
|
|
51
|
+
*/
|
|
52
|
+
export function safeDecodeCookieValue(raw: string): string {
|
|
53
|
+
try {
|
|
54
|
+
return decodeURIComponent(raw);
|
|
55
|
+
} catch {
|
|
56
|
+
return raw;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Serialize a CookieEntry into a Set-Cookie header value. */
|
|
61
|
+
export function serializeCookieEntry(entry: CookieEntry): string {
|
|
62
|
+
const parts = [`${entry.name}=${entry.value}`];
|
|
63
|
+
const opts = entry.options;
|
|
64
|
+
|
|
65
|
+
if (opts.domain) parts.push(`Domain=${opts.domain}`);
|
|
66
|
+
if (opts.path) parts.push(`Path=${opts.path}`);
|
|
67
|
+
if (opts.expires) parts.push(`Expires=${opts.expires.toUTCString()}`);
|
|
68
|
+
if (opts.maxAge !== undefined) parts.push(`Max-Age=${opts.maxAge}`);
|
|
69
|
+
if (opts.httpOnly) parts.push('HttpOnly');
|
|
70
|
+
if (opts.secure) parts.push('Secure');
|
|
71
|
+
if (opts.sameSite) {
|
|
72
|
+
parts.push(`SameSite=${opts.sameSite.charAt(0).toUpperCase()}${opts.sameSite.slice(1)}`);
|
|
73
|
+
}
|
|
74
|
+
if (opts.partitioned) parts.push('Partitioned');
|
|
75
|
+
|
|
76
|
+
return parts.join('; ');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Parse a raw `Set-Cookie` header string into name, value, and options.
|
|
81
|
+
* Handles all standard attributes: Path, Domain, Max-Age, Expires,
|
|
82
|
+
* SameSite, Secure, HttpOnly, Partitioned.
|
|
83
|
+
*
|
|
84
|
+
* Does NOT apply DEFAULT_COOKIE_OPTIONS — the caller decides whether
|
|
85
|
+
* to merge defaults (e.g. `set()` does, but `setRaw()` should preserve
|
|
86
|
+
* the original header's intent).
|
|
87
|
+
*/
|
|
88
|
+
export function parseSetCookie(
|
|
89
|
+
header: string
|
|
90
|
+
): { name: string; value: string; options: CookieOptions } | null {
|
|
91
|
+
const segments = header.split(';');
|
|
92
|
+
const nameValue = segments[0];
|
|
93
|
+
const eqIdx = nameValue.indexOf('=');
|
|
94
|
+
if (eqIdx <= 0) return null;
|
|
95
|
+
|
|
96
|
+
const name = nameValue.slice(0, eqIdx).trim();
|
|
97
|
+
const value = nameValue.slice(eqIdx + 1).trim();
|
|
98
|
+
const options: CookieOptions = {};
|
|
99
|
+
|
|
100
|
+
for (let i = 1; i < segments.length; i++) {
|
|
101
|
+
const seg = segments[i].trim();
|
|
102
|
+
if (!seg) continue;
|
|
103
|
+
const [attrName, ...rest] = seg.split('=');
|
|
104
|
+
const key = attrName.trim().toLowerCase();
|
|
105
|
+
const val = rest.join('=').trim();
|
|
106
|
+
switch (key) {
|
|
107
|
+
case 'path':
|
|
108
|
+
options.path = val || '/';
|
|
109
|
+
break;
|
|
110
|
+
case 'domain':
|
|
111
|
+
options.domain = val;
|
|
112
|
+
break;
|
|
113
|
+
case 'max-age':
|
|
114
|
+
options.maxAge = Number(val);
|
|
115
|
+
break;
|
|
116
|
+
case 'expires':
|
|
117
|
+
options.expires = new Date(val);
|
|
118
|
+
break;
|
|
119
|
+
case 'samesite':
|
|
120
|
+
options.sameSite = val.toLowerCase() as 'strict' | 'lax' | 'none';
|
|
121
|
+
break;
|
|
122
|
+
case 'secure':
|
|
123
|
+
options.secure = true;
|
|
124
|
+
break;
|
|
125
|
+
case 'httponly':
|
|
126
|
+
options.httpOnly = true;
|
|
127
|
+
break;
|
|
128
|
+
case 'partitioned':
|
|
129
|
+
options.partitioned = true;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return { name, value, options };
|
|
135
|
+
}
|