Skip to content

feat: custom request headers and fetch (0.3.0) - #7

Merged
mrgoonie merged 1 commit into
mainfrom
feat/request-headers
Oct 20, 2026
Merged

mrgoonie merged 1 commit into
mainfrom
feat/request-headers

Conversation

@mrgoonie

Copy link
Copy Markdown
Contributor

Summary

For backends behind a same-origin BFF that needs a CSRF header on POSTs.

  • New option headers?: RequestHeadersOption (Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>)), evaluated before every request (config, session, history, chat), so a rotating CSRF token works. content-type, authorization, x-dewee-gateway-url and x-dewee-gateway-token cannot be overridden (case-insensitive; dropped).
  • New option fetch?: typeof fetch used for every widget request (default globalThis.fetch).
  • Both work through configure(), el.headers / el.fetch properties (no attributes), React props and Vue props, and changes apply on the next request without remounting. RequestHeadersOption and RESERVED_HEADERS are exported.
  • Session reuse: refresh once less than 10% of the observed token lifetime remains (capped at 24 h, floored at 30 s). Sessions stored by older versions keep the 24 h margin.
  • Docs: README "Custom headers and fetch", docs/http-contract.md "Extra request headers". Cross-origin backends must allow extra headers in CORS preflight (built-in handlers allow only their own).
  • Version 0.3.0.

Tests

test/request-headers.test.ts: merge order and per-request evaluation, reserved-header protection, default/global and custom fetch, short and long session TTL reuse, element configure() and property updates.

- headers option (object or per-request function) merged into every widget request; content-type,
  authorization and the gateway credential headers cannot be overridden
- fetch option replaces globalThis.fetch for all widget requests
- both available via configure(), element properties, and React/Vue props
- reuse visitor sessions until 10% of the token lifetime remains (capped at 24 h) instead of a fixed 24 h
- bump to 0.3.0
@mrgoonie
mrgoonie merged commit 4cc9a05 into main Oct 20, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant