@wcstack/fetch 4.0.3 → 4.1.0

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/index.d.ts CHANGED
@@ -370,10 +370,26 @@ declare const WCS_FETCH_ERROR_CODE: {
370
370
  readonly Aborted: "aborted";
371
371
  };
372
372
 
373
+ /**
374
+ * `<wcs-fetch-header name value>`: one request header of the `<wcs-fetch>` it sits in, read when a
375
+ * request starts. `name` / `value` are properties too, reflected to the attributes (`null` removes
376
+ * one, `undefined` restores the markup's), so a binding — `data-wcs="value: authHeader"` — sets the
377
+ * header. Without a `value` attribute the header is not sent: a token that is not there yet sends
378
+ * no `Authorization` instead of an empty one. Before this, `value:` wrote an expando the element
379
+ * never read, and the request went out with an empty header (docs/seam-apps.md, router-auth).
380
+ *
381
+ * It declares no `wcBindable`: it is part of `<wcs-fetch>`'s markup, not an I/O node of its own.
382
+ */
373
383
  declare class FetchHeader extends HTMLElement {
374
384
  connectedCallback(): void;
385
+ get name(): string;
386
+ set name(value: unknown);
387
+ get value(): string;
388
+ set value(value: unknown);
375
389
  get headerName(): string;
376
390
  get headerValue(): string;
391
+ /** Whether the header is sent: it has a name and a `value` attribute (an empty one included). */
392
+ get hasHeader(): boolean;
377
393
  }
378
394
 
379
395
  declare class FetchBody extends HTMLElement {
package/dist/index.esm.js CHANGED
@@ -1301,10 +1301,9 @@ class Fetch extends HTMLElement {
1301
1301
  const headers = {};
1302
1302
  const headerElements = this.querySelectorAll(config.tagNames.fetchHeader);
1303
1303
  for (const el of headerElements) {
1304
- const name = el.headerName;
1305
- const value = el.headerValue;
1306
- if (name) {
1307
- headers[name] = value;
1304
+ // a header without a value attribute is not sent (FetchHeader)
1305
+ if (el.hasHeader) {
1306
+ headers[el.headerName] = el.headerValue;
1308
1307
  }
1309
1308
  }
1310
1309
  return headers;
@@ -1490,15 +1489,50 @@ class Fetch extends HTMLElement {
1490
1489
  }
1491
1490
  }
1492
1491
 
1492
+ /**
1493
+ * `<wcs-fetch-header name value>`: one request header of the `<wcs-fetch>` it sits in, read when a
1494
+ * request starts. `name` / `value` are properties too, reflected to the attributes (`null` removes
1495
+ * one, `undefined` restores the markup's), so a binding — `data-wcs="value: authHeader"` — sets the
1496
+ * header. Without a `value` attribute the header is not sent: a token that is not there yet sends
1497
+ * no `Authorization` instead of an empty one. Before this, `value:` wrote an expando the element
1498
+ * never read, and the request went out with an empty header (docs/seam-apps.md, router-auth).
1499
+ *
1500
+ * It declares no `wcBindable`: it is part of `<wcs-fetch>`'s markup, not an I/O node of its own.
1501
+ */
1493
1502
  class FetchHeader extends HTMLElement {
1494
1503
  connectedCallback() {
1504
+ // A value assigned before the element was upgraded sits on the instance and hides the
1505
+ // accessor: pass it through the setter (the upgrade-properties pattern, for two members).
1506
+ for (const key of ["name", "value"]) {
1507
+ if (Object.prototype.hasOwnProperty.call(this, key)) {
1508
+ const value = this[key];
1509
+ delete this[key];
1510
+ this[key] = value;
1511
+ }
1512
+ }
1495
1513
  this.style.display = "none";
1496
1514
  }
1515
+ get name() {
1516
+ return this.getAttribute("name") ?? "";
1517
+ }
1518
+ set name(value) {
1519
+ reflectAttribute(this, "name", value);
1520
+ }
1521
+ get value() {
1522
+ return this.getAttribute("value") ?? "";
1523
+ }
1524
+ set value(value) {
1525
+ reflectAttribute(this, "value", value);
1526
+ }
1497
1527
  get headerName() {
1498
- return this.getAttribute("name") || "";
1528
+ return this.name;
1499
1529
  }
1500
1530
  get headerValue() {
1501
- return this.getAttribute("value") || "";
1531
+ return this.value;
1532
+ }
1533
+ /** Whether the header is sent: it has a name and a `value` attribute (an empty one included). */
1534
+ get hasHeader() {
1535
+ return this.name !== "" && this.hasAttribute("value");
1502
1536
  }
1503
1537
  }
1504
1538