@venizia/ardor-kernel 0.5.0-0 → 0.5.0-1

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.
@@ -59,8 +59,8 @@ export declare class DefaultNetworkRequestService extends BaseService {
59
59
  });
60
60
  /**
61
61
  * The headers of one call: its own alone, or the ones `setHeaders` holds now. The transport keeps no
62
- * default of ours, so a removed header is gone; a call that names no `content-type` sends none (`null`)
63
- * when its body is one `fetch` types itself (`FormData`, `Blob`, bytes, a stream), so a multipart boundary is written.
62
+ * default of ours, so a removed header is gone. A call with headers but no `content-type` sends none (`null`),
63
+ * and so does a raw body (`FormData`, `Blob`, `URLSearchParams`, bytes, a stream) with none, so `fetch` writes it.
64
64
  */
65
65
  private toSendHeaders;
66
66
  /** A body the platform `fetch` gives a content type of its own, or none: it is sent as it is. */
@@ -49,11 +49,14 @@ export class DefaultNetworkRequestService extends BaseService {
49
49
  }
50
50
  /**
51
51
  * The headers of one call: its own alone, or the ones `setHeaders` holds now. The transport keeps no
52
- * default of ours, so a removed header is gone; a call that names no `content-type` sends none (`null`)
53
- * when its body is one `fetch` types itself (`FormData`, `Blob`, bytes, a stream), so a multipart boundary is written.
52
+ * default of ours, so a removed header is gone. A call with headers but no `content-type` sends none (`null`),
53
+ * and so does a raw body (`FormData`, `Blob`, `URLSearchParams`, bytes, a stream) with none, so `fetch` writes it.
54
54
  */
55
55
  toSendHeaders(opts) {
56
- const sent = Object.fromEntries(new Headers(opts.headers ?? this.headers));
56
+ const sent = {
57
+ ...Object.fromEntries(new Headers(opts.headers ?? this.headers)),
58
+ ...opts.extra,
59
+ };
57
60
  if (opts.headers && !(HeaderConstants.CONTENT_TYPE in sent)) {
58
61
  sent[HeaderConstants.CONTENT_TYPE] = null;
59
62
  }
@@ -548,14 +551,15 @@ export class DefaultNetworkRequestService extends BaseService {
548
551
  /** `doRequest` once the URL is checked: the send, the refresh and retry after a 401, then the read. */
549
552
  async sendAndRead(opts) {
550
553
  const { url, type, method, paths, body, headers, query, requestCountData, signal } = opts;
551
- const sendOnce = (sendHeaders) => {
554
+ const sendOnce = (retryHeaders) => {
552
555
  return this.networkRequest.getNetworkService().send({
553
556
  url,
554
557
  method,
555
558
  params: query,
556
559
  body: method === RequestMethods.GET ? undefined : body,
557
560
  headers: this.toSendHeaders({
558
- headers: sendHeaders,
561
+ headers,
562
+ extra: retryHeaders,
559
563
  body: method === RequestMethods.GET ? undefined : body,
560
564
  }),
561
565
  signal,
@@ -564,7 +568,7 @@ export class DefaultNetworkRequestService extends BaseService {
564
568
  };
565
569
  const sent = this.readSession();
566
570
  let isRetried = false;
567
- let fetched = await sendOnce(headers);
571
+ let fetched = await sendOnce();
568
572
  if (fetched.status === 401 && this.recovery.canRecover({ paths })) {
569
573
  // A 401 that arrives after the session changed is not the new session's to refresh or to end.
570
574
  const change = this.readSessionChange({ sent });
@@ -587,16 +591,17 @@ export class DefaultNetworkRequestService extends BaseService {
587
591
  // The shared refresh is never aborted for one request: this request stops when it returns.
588
592
  signal?.throwIfAborted();
589
593
  if (isRefreshed) {
594
+ if (method !== RequestMethods.GET && body instanceof ReadableStream) {
595
+ throw getError({
596
+ message: '[doRequest] The session was refreshed, but a ReadableStream body cannot be sent a second time | Send the request again from your code, or send a body that can be read again (FormData, Blob, a string)',
597
+ });
598
+ }
590
599
  const authHeader = this.getRequestAuthorizationHeader();
591
- const retryHeaders = NetworkHeaders.merge({
592
- sources: [
593
- headers,
594
- { [HeaderConstants.AUTHORIZATION]: authHeader.token },
595
- authHeader.provider
596
- ? { [HeaderConstants.X_AUTH_PROVIDER]: authHeader.provider }
597
- : undefined,
598
- ],
599
- });
600
+ // The token's provider wins, and a token with none removes the one the call carried.
601
+ const retryHeaders = {
602
+ [HeaderConstants.AUTHORIZATION]: authHeader.token,
603
+ [HeaderConstants.X_AUTH_PROVIDER]: authHeader.provider ?? null,
604
+ };
600
605
  const result = await sendOnce(retryHeaders);
601
606
  fetched = result;
602
607
  isRetried = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@venizia/ardor-kernel",
3
- "version": "0.5.0-0",
3
+ "version": "0.5.0-1",
4
4
  "description": "ARDOR kernel - the isomorphic core of the ARDOR frontend framework: application base on IGNIS inversion, service and provider bases, request/auth constants, binding keys, the network request service, runtime config and the HTTP repository (from IGNIS). No React and no react-admin.",
5
5
  "keywords": [
6
6
  "ardor",
@@ -108,7 +108,7 @@
108
108
  "@venizia/ignis-inversion",
109
109
  "reflect-metadata"
110
110
  ],
111
- "limit": "11070 B"
111
+ "limit": "11300 B"
112
112
  },
113
113
  {
114
114
  "path": "dist/testing.js",