@venizia/ardor-kernel 0.4.8 → 0.5.0-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/README.md CHANGED
@@ -24,7 +24,7 @@ which re-exports this package.
24
24
  | Decorators | `api()` - logs and rethrows a failing API method; the IGNIS stereotypes it re-exports (`component`, `configuration`, `datasource`, `inject`, `injectable`, `model`, `provide`, `repository`, `service`) |
25
25
  | Bindings | `CoreBindings`, `LocalStorageKeys`, `BindingKeys`, `BindingNamespaces` |
26
26
  | Constants | `RequestMethods`, `RequestTypes`, `RequestBodyTypes`, `RequestCountData`, `HeaderConstants`, `Environments`, `App`, `Authentication`, `StorageAreas`, `RequestChannel` |
27
- | Network | `NetworkHeaders`, `RequestBodyEncoder`, `ResponseReader`, `AuthRecovery`, `AuthTokenStore` (the fetch transport is IGNIS's `NodeFetchNetworkRequest`) |
27
+ | Network | `NetworkHeaders`, `RequestBodyEncoder`, `NetworkResponseReader`, `AuthRecovery`, `AuthTokenStore` (the fetch transport is IGNIS's `NativeFetchNetworkRequest`) |
28
28
  | Utilities | `ValueUtility` (`isDefined`, `isString`, `isNumber`, `isObject`, `isValidDate`), `BrowserUtility.isBrowser`, `FileUtility.toDataUrl`, `RuntimeConfig.get` and `RuntimeConfig.getRequired` (with `RUNTIME_CONFIG_GLOBAL`, `RUNTIME_CONFIG_REQUIRED_CODE` and `RUNTIME_CONFIG_INVALID_CODE`), `BrowserStorage`, `BrowserClipboard`, `StorageCodecs`; the earlier bare names are removed (`bun run ardor codemod namespace` moves your code) |
29
29
  | Types | `IdType`, `IAuthUser`, `ValueOrPromise`, `ValueOf`, `TConstValue`, `TPaths`, `TFullPaths`, `ISendParams`, `IRestDataProviderOptions`, `IApplicationInfo`, ... |
30
30
 
@@ -1,5 +1,5 @@
1
1
  import { ArtifactBindingKeys, ArtifactNamespaces, BindingNamespaces, MetadataRegistry, } from '@venizia/ignis-kernel/metadata';
2
- import { BindingScopes, Container, getError, } from '@venizia/ignis-inversion';
2
+ import { BindingKeys, BindingScopes, Container, getError, } from '@venizia/ignis-inversion';
3
3
  import { CoreBindings, } from '../../common/index.js';
4
4
  import { ApplicationInfoGuard } from './app-info.js';
5
5
  /** The six kinds of an artifact index, as `ignis-artifacts generate` emits them. */
@@ -39,7 +39,8 @@ export class AbstractArdorApplication extends Container {
39
39
  this.bindDefaults();
40
40
  this.registerArtifacts();
41
41
  this.registerFeatures({ features: this.features() });
42
- for (const [key, target] of Object.entries(this.bindingList())) {
42
+ for (const [name, target] of Object.entries(this.bindingList())) {
43
+ const key = BindingKeys.build({ key: name });
43
44
  const holder = this.lockedKeys.get(key);
44
45
  if (holder !== undefined) {
45
46
  throw getError({
@@ -1,6 +1,6 @@
1
- import { NodeFetchNetworkRequest } from '@venizia/ignis-helpers/core';
1
+ import { NativeFetchNetworkRequest } from '@venizia/ignis-helpers/core';
2
2
  import { type IApplicationInfo, type IAuthTokenRecord, type IAuthRecoveryOptions, type IDataSourceAuth, type IGetRequestPropsParams, type IGetRequestPropsResult, type INetworkResponse, type INoAuthOptions, RequestCountData, type TConstValue, type TNoAuthPathRegex, type TRequestMethod, type TRequestTimeoutOptions, type TRequestType } from '../../common/index.js';
3
- import { type IEncodedBody, ResponseReader } from '../../helpers/index.js';
3
+ import { type IEncodedBody, NetworkResponseReader } from '../../helpers/index.js';
4
4
  import type { DefaultAuthService } from './auth.js';
5
5
  import { BaseService } from './base.js';
6
6
  /** The `normalized.code` of the 401 that answers a request whose session is gone: the user who sent it signed out or another user signed in while it was in flight. */
@@ -24,7 +24,7 @@ export declare class DefaultNetworkRequestService extends BaseService {
24
24
  protected noAuthPathRegexes: RegExp[];
25
25
  /** Headers added to every request, keyed by lowercase name. */
26
26
  protected headers: Record<string, string>;
27
- protected networkRequest: NodeFetchNetworkRequest;
27
+ protected networkRequest: NativeFetchNetworkRequest;
28
28
  /** The origin and base path requests are sent to; an empty one makes `doRequest` throw. */
29
29
  protected baseUrl: string;
30
30
  protected authRecovery?: IAuthRecoveryOptions;
@@ -57,6 +57,14 @@ export declare class DefaultNetworkRequestService extends BaseService {
57
57
  */
58
58
  timeout?: TRequestTimeoutOptions;
59
59
  });
60
+ /**
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.
64
+ */
65
+ private toSendHeaders;
66
+ /** A body the platform `fetch` gives a content type of its own, or none: it is sent as it is. */
67
+ private static isRawBody;
60
68
  /**
61
69
  * The token under the unscoped session key (`AuthTokenStore.read`), `undefined` outside a browser, for an
62
70
  * application with no `id`. With an application `id` the session is under other keys: use
@@ -181,12 +189,6 @@ export declare class DefaultNetworkRequestService extends BaseService {
181
189
  getRequestHeader(opts: {
182
190
  resource: string;
183
191
  }): Record<string, string>;
184
- /**
185
- * Whether the request stays where `baseUrl` points: no entry of `paths` carries a tab, a line break,
186
- * a backslash or a dot segment (also written `%2E`), and the URL built from
187
- * them, resolved the way a browser does, has the origin of the base and a path under it.
188
- */
189
- private static isUnderBase;
190
192
  /** The body as it is sent and the content type to send it under. Override to encode another way. */
191
193
  protected encodeBody(opts: {
192
194
  bodyType?: string;
@@ -197,8 +199,8 @@ export declare class DefaultNetworkRequestService extends BaseService {
197
199
  * of the encoded body) and the encoded body of a request. Throws as `getRequestHeader` does.
198
200
  */
199
201
  getRequestProps(params: IGetRequestPropsParams): IGetRequestPropsResult;
200
- /** Reads a response by the request type. See `ResponseReader.convert`. */
201
- convertResponse<TData = unknown>(opts: Parameters<typeof ResponseReader.convert<TData>>[0]): {
202
+ /** Reads a response by the request type. See `NetworkResponseReader.convert`. */
203
+ convertResponse<TData = unknown>(opts: Parameters<typeof NetworkResponseReader.convert<TData>>[0]): {
202
204
  data: TData;
203
205
  count?: number;
204
206
  total?: number;
@@ -1,10 +1,10 @@
1
1
  import { getError } from '@venizia/ignis-inversion';
2
2
  import { HTTP } from '@venizia/ignis-helpers/common';
3
- import { NodeFetchNetworkRequest } from '@venizia/ignis-helpers/core';
3
+ import { NativeFetchNetworkRequest } from '@venizia/ignis-helpers/core';
4
4
  import { UuidV4Generator } from '@venizia/ignis-helpers/uuid';
5
5
  import { HttpExtraRequest } from '@venizia/ignis-kernel/repository';
6
6
  import { App, HeaderConstants, LocalStorageKeys, RequestChannel, RequestCountData, RequestMethods, RequestTypes, } from '../../common/index.js';
7
- import { AuthRecovery, AuthTokenStore, NetworkHeaders, RequestBodyEncoder, ResponseReader, } from '../../helpers/index.js';
7
+ import { AuthRecovery, AuthTokenStore, NetworkHeaders, RequestBodyEncoder, NetworkResponseReader, } from '../../helpers/index.js';
8
8
  import { BaseService } from './base.js';
9
9
  /** The `normalized.code` of the 401 that answers a request whose session is gone: the user who sent it signed out or another user signed in while it was in flight. */
10
10
  export const SESSION_CHANGED_CODE = 'ardor.network.session_changed';
@@ -41,12 +41,38 @@ export class DefaultNetworkRequestService extends BaseService {
41
41
  onFailure: () => this.onAuthFailure(),
42
42
  isNoAuthPath: (paths) => this.isNoAuthPath({ resource: paths?.[0], paths }),
43
43
  });
44
- this.networkRequest = new NodeFetchNetworkRequest({
44
+ this.networkRequest = new NativeFetchNetworkRequest({
45
45
  name,
46
46
  // A filter travels as one JSON parameter, and a null is left out: what an IGNIS server reads.
47
- networkOptions: { baseUrl, headers, queryString: { nullish: 'skip', nested: 'json' } },
47
+ networkOptions: { baseUrl, queryString: { nullish: 'skip', nested: 'json' } },
48
48
  });
49
49
  }
50
+ /**
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.
54
+ */
55
+ toSendHeaders(opts) {
56
+ const sent = Object.fromEntries(new Headers(opts.headers ?? this.headers));
57
+ if (opts.headers && !(HeaderConstants.CONTENT_TYPE in sent)) {
58
+ sent[HeaderConstants.CONTENT_TYPE] = null;
59
+ }
60
+ if (DefaultNetworkRequestService.isRawBody({ body: opts.body }) &&
61
+ !sent[HeaderConstants.CONTENT_TYPE]) {
62
+ sent[HeaderConstants.CONTENT_TYPE] = null;
63
+ }
64
+ return sent;
65
+ }
66
+ /** A body the platform `fetch` gives a content type of its own, or none: it is sent as it is. */
67
+ static isRawBody(opts) {
68
+ const { body } = opts;
69
+ return (body instanceof FormData ||
70
+ body instanceof Blob ||
71
+ body instanceof URLSearchParams ||
72
+ body instanceof ArrayBuffer ||
73
+ ArrayBuffer.isView(body) ||
74
+ body instanceof ReadableStream);
75
+ }
50
76
  /**
51
77
  * The token under the unscoped session key (`AuthTokenStore.read`), `undefined` outside a browser, for an
52
78
  * application with no `id`. With an application `id` the session is under other keys: use
@@ -346,7 +372,7 @@ export class DefaultNetworkRequestService extends BaseService {
346
372
  sources: [this.getSessionHeaders(), opts ? this.getTracingHeaders(opts) : {}],
347
373
  });
348
374
  },
349
- onUnauthorized: (context) => {
375
+ onUnauthorized: (context, info) => {
350
376
  if (!this.recovery.canRecover({ paths: context.paths })) {
351
377
  return Promise.resolve(false);
352
378
  }
@@ -355,6 +381,10 @@ export class DefaultNetworkRequestService extends BaseService {
355
381
  if (change === false) {
356
382
  return Promise.reject(this.sessionChangedError());
357
383
  }
384
+ // The retry's own 401 stands, as it does for `doRequest`: one refresh, one retry.
385
+ if (info.attempt >= 2) {
386
+ return Promise.resolve(false);
387
+ }
358
388
  if (change === true) {
359
389
  return Promise.resolve(true);
360
390
  }
@@ -368,7 +398,7 @@ export class DefaultNetworkRequestService extends BaseService {
368
398
  : isRefreshed;
369
399
  });
370
400
  },
371
- errorRootKey: ResponseReader.ERROR_ROOT_KEY,
401
+ errorRootKey: NetworkResponseReader.ERROR_ROOT_KEY,
372
402
  };
373
403
  }
374
404
  /**
@@ -443,30 +473,6 @@ export class DefaultNetworkRequestService extends BaseService {
443
473
  [HeaderConstants.AUTHORIZATION]: authHeader.token,
444
474
  };
445
475
  }
446
- /**
447
- * Whether the request stays where `baseUrl` points: no entry of `paths` carries a tab, a line break,
448
- * a backslash or a dot segment (also written `%2E`), and the URL built from
449
- * them, resolved the way a browser does, has the origin of the base and a path under it.
450
- */
451
- static isUnderBase(opts) {
452
- const { baseUrl, paths, url } = opts;
453
- // The joined path, so a dot segment is found whichever entry holds it.
454
- if (/[\\\t\n\r]|(^|\/)(\.|%2e){1,2}(\/|$)/i.test(paths.join('/'))) {
455
- return false;
456
- }
457
- try {
458
- const origin = 'http://base.invalid';
459
- const base = new URL(baseUrl, origin);
460
- const target = new URL(url, origin);
461
- const prefix = base.pathname.replace(/\/+$/, '');
462
- return (target.origin === base.origin &&
463
- (target.pathname === prefix || target.pathname.startsWith(`${prefix}/`)));
464
- // eslint-disable-next-line venizia/no-silent-catch -- a URL that does not parse is the answer: the request is refused
465
- }
466
- catch {
467
- return false;
468
- }
469
- }
470
476
  /** The body as it is sent and the content type to send it under. Override to encode another way. */
471
477
  encodeBody(opts) {
472
478
  return RequestBodyEncoder.encode(opts);
@@ -496,9 +502,9 @@ export class DefaultNetworkRequestService extends BaseService {
496
502
  };
497
503
  return props;
498
504
  }
499
- /** Reads a response by the request type. See `ResponseReader.convert`. */
505
+ /** Reads a response by the request type. See `NetworkResponseReader.convert`. */
500
506
  convertResponse(opts) {
501
- return ResponseReader.convert(opts);
507
+ return NetworkResponseReader.convert(opts);
502
508
  }
503
509
  /**
504
510
  * Sends the request and reads the response by `type`. Throws when `baseUrl` (the option, else the
@@ -515,9 +521,6 @@ export class DefaultNetworkRequestService extends BaseService {
515
521
  });
516
522
  }
517
523
  const url = this.networkRequest.getRequestUrl({ baseUrl, paths });
518
- if (!DefaultNetworkRequestService.isUnderBase({ baseUrl, paths, url })) {
519
- throw getError({ message: '[doRequest] Invalid path to send request!' });
520
- }
521
524
  const timeoutSignal = this.timeout.use
522
525
  ? AbortSignal.timeout(this.timeout.milliseconds)
523
526
  : undefined;
@@ -551,8 +554,12 @@ export class DefaultNetworkRequestService extends BaseService {
551
554
  method,
552
555
  params: query,
553
556
  body: method === RequestMethods.GET ? undefined : body,
554
- headers: sendHeaders,
557
+ headers: this.toSendHeaders({
558
+ headers: sendHeaders,
559
+ body: method === RequestMethods.GET ? undefined : body,
560
+ }),
555
561
  signal,
562
+ acceptStatus: () => true,
556
563
  }, this.logger);
557
564
  };
558
565
  const sent = this.readSession();
@@ -603,10 +610,10 @@ export class DefaultNetworkRequestService extends BaseService {
603
610
  throw this.sessionChangedError();
604
611
  }
605
612
  if (status < 200 || status >= 300) {
606
- const result2 = await ResponseReader.toError({ response: fetched });
613
+ const result2 = await NetworkResponseReader.toError({ response: fetched });
607
614
  throw result2;
608
615
  }
609
- const response = await ResponseReader.read({
616
+ const response = await NetworkResponseReader.read({
610
617
  response: fetched,
611
618
  type,
612
619
  requestCountData,
@@ -1,29 +1,44 @@
1
- /** The container keys the kernel binds and reads. */
1
+ import { type TBindingKey } from '@venizia/ignis-inversion';
2
+ import type { AbstractArdorApplication } from '../base/applications/abstract.js';
3
+ import type { DefaultAuthService } from '../base/services/auth.js';
4
+ import type { IApplicationInfo, IFeatureBase, IPermissionProvider, IRestDataProviderOptions, IRolePermissionProviderOptions, TAuthProviderOptions } from './types.js';
5
+ /**
6
+ * The types of the `CoreBindings` values that live in `@venizia/ardor-admin`, which merges them in;
7
+ * the kernel alone reads `unknown`.
8
+ */
9
+ export interface ICoreBindingTypes {
10
+ }
11
+ /** The type merged into `ICoreBindingTypes` under `TName`, or `unknown` when nothing merged it. */
12
+ export type TCoreBindingType<TName extends string> = TName extends keyof ICoreBindingTypes ? ICoreBindingTypes[TName] : unknown;
13
+ /**
14
+ * The container keys the kernel binds and reads, each made by `BindingKeys.build<T>` with the type of
15
+ * its value.
16
+ */
2
17
  export declare class CoreBindings {
3
18
  /** The application itself, bound by `preConfigure`. */
4
- static readonly APPLICATION_INSTANCE = "@app/application/instance";
19
+ static readonly APPLICATION_INSTANCE: TBindingKey<AbstractArdorApplication>;
5
20
  /** The `IApplicationInfo`, bound by `preConfigure`. */
6
- static readonly APPLICATION_INFO = "@app/application/info";
21
+ static readonly APPLICATION_INFO: TBindingKey<IApplicationInfo>;
7
22
  /** The auth provider. */
8
- static readonly DEFAULT_AUTH_PROVIDER = "@app/application/auth/default";
23
+ static readonly DEFAULT_AUTH_PROVIDER: TBindingKey<TCoreBindingType<'authProvider'>>;
9
24
  /** The i18n provider. */
10
- static readonly DEFAULT_I18N_PROVIDER = "@app/application/i18n/default";
25
+ static readonly DEFAULT_I18N_PROVIDER: TBindingKey<TCoreBindingType<'i18nProvider'>>;
11
26
  /** The REST data provider. */
12
- static readonly DEFAULT_REST_DATA_PROVIDER = "@app/application/data/rest/default";
27
+ static readonly DEFAULT_REST_DATA_PROVIDER: TBindingKey<TCoreBindingType<'restDataProvider'>>;
13
28
  /** The `TAuthProviderOptions`: `{ use: true }` turns sign-in on; unbound means `{ use: false }`. */
14
- static readonly AUTH_PROVIDER_OPTIONS = "@app/application/options/auth";
29
+ static readonly AUTH_PROVIDER_OPTIONS: TBindingKey<TAuthProviderOptions>;
15
30
  /** The `DefaultAuthService`. */
16
- static readonly DEFAULT_AUTH_SERVICE = "@app/application/service/auth/default";
31
+ static readonly DEFAULT_AUTH_SERVICE: TBindingKey<DefaultAuthService>;
17
32
  /** The `IRestDataProviderOptions`. */
18
- static readonly REST_DATA_PROVIDER_OPTIONS = "@app/application/options/rest/data";
33
+ static readonly REST_DATA_PROVIDER_OPTIONS: TBindingKey<IRestDataProviderOptions>;
19
34
  /** The options of the i18n provider; unbound means English only. */
20
- static readonly I18N_PROVIDER_OPTIONS = "@app/application/options/i18n";
35
+ static readonly I18N_PROVIDER_OPTIONS: TBindingKey<TCoreBindingType<'i18nProviderOptions'>>;
21
36
  /** The `features()` an application mounts, bound by `preConfigure()`. */
22
- static readonly FEATURES = "@app/application/features";
37
+ static readonly FEATURES: TBindingKey<IFeatureBase[]>;
23
38
  /** An `IPermissionProvider`, bound by the application; unbound means every check passes. */
24
- static readonly PERMISSION_PROVIDER = "@app/application/permission/provider";
39
+ static readonly PERMISSION_PROVIDER: TBindingKey<IPermissionProvider>;
25
40
  /** The `IRolePermissionProviderOptions` that `RolePermissionProvider` reads. */
26
- static readonly PERMISSION_PROVIDER_OPTIONS = "@app/application/options/permission";
41
+ static readonly PERMISSION_PROVIDER_OPTIONS: TBindingKey<IRolePermissionProviderOptions>;
27
42
  }
28
43
  /** The session keys and the store prefix of one application, from `LocalStorageKeys.scoped`. */
29
44
  export interface IScopedKeys {
@@ -1,30 +1,57 @@
1
- import { getError } from '@venizia/ignis-inversion';
2
- /** The container keys the kernel binds and reads. */
1
+ import { BindingKeys, getError } from '@venizia/ignis-inversion';
2
+ /**
3
+ * The container keys the kernel binds and reads, each made by `BindingKeys.build<T>` with the type of
4
+ * its value.
5
+ */
3
6
  export class CoreBindings {
4
7
  /** The application itself, bound by `preConfigure`. */
5
- static { this.APPLICATION_INSTANCE = '@app/application/instance'; }
8
+ static { this.APPLICATION_INSTANCE = BindingKeys.build({
9
+ key: '@app/application/instance',
10
+ }); }
6
11
  /** The `IApplicationInfo`, bound by `preConfigure`. */
7
- static { this.APPLICATION_INFO = '@app/application/info'; }
12
+ static { this.APPLICATION_INFO = BindingKeys.build({
13
+ key: '@app/application/info',
14
+ }); }
8
15
  /** The auth provider. */
9
- static { this.DEFAULT_AUTH_PROVIDER = '@app/application/auth/default'; }
16
+ static { this.DEFAULT_AUTH_PROVIDER = BindingKeys.build({
17
+ key: '@app/application/auth/default',
18
+ }); }
10
19
  /** The i18n provider. */
11
- static { this.DEFAULT_I18N_PROVIDER = '@app/application/i18n/default'; }
20
+ static { this.DEFAULT_I18N_PROVIDER = BindingKeys.build({
21
+ key: '@app/application/i18n/default',
22
+ }); }
12
23
  /** The REST data provider. */
13
- static { this.DEFAULT_REST_DATA_PROVIDER = '@app/application/data/rest/default'; }
24
+ static { this.DEFAULT_REST_DATA_PROVIDER = BindingKeys.build({
25
+ key: '@app/application/data/rest/default',
26
+ }); }
14
27
  /** The `TAuthProviderOptions`: `{ use: true }` turns sign-in on; unbound means `{ use: false }`. */
15
- static { this.AUTH_PROVIDER_OPTIONS = '@app/application/options/auth'; }
28
+ static { this.AUTH_PROVIDER_OPTIONS = BindingKeys.build({
29
+ key: '@app/application/options/auth',
30
+ }); }
16
31
  /** The `DefaultAuthService`. */
17
- static { this.DEFAULT_AUTH_SERVICE = '@app/application/service/auth/default'; }
32
+ static { this.DEFAULT_AUTH_SERVICE = BindingKeys.build({
33
+ key: '@app/application/service/auth/default',
34
+ }); }
18
35
  /** The `IRestDataProviderOptions`. */
19
- static { this.REST_DATA_PROVIDER_OPTIONS = '@app/application/options/rest/data'; }
36
+ static { this.REST_DATA_PROVIDER_OPTIONS = BindingKeys.build({
37
+ key: '@app/application/options/rest/data',
38
+ }); }
20
39
  /** The options of the i18n provider; unbound means English only. */
21
- static { this.I18N_PROVIDER_OPTIONS = '@app/application/options/i18n'; }
40
+ static { this.I18N_PROVIDER_OPTIONS = BindingKeys.build({
41
+ key: '@app/application/options/i18n',
42
+ }); }
22
43
  /** The `features()` an application mounts, bound by `preConfigure()`. */
23
- static { this.FEATURES = '@app/application/features'; }
44
+ static { this.FEATURES = BindingKeys.build({
45
+ key: '@app/application/features',
46
+ }); }
24
47
  /** An `IPermissionProvider`, bound by the application; unbound means every check passes. */
25
- static { this.PERMISSION_PROVIDER = '@app/application/permission/provider'; }
48
+ static { this.PERMISSION_PROVIDER = BindingKeys.build({
49
+ key: '@app/application/permission/provider',
50
+ }); }
26
51
  /** The `IRolePermissionProviderOptions` that `RolePermissionProvider` reads. */
27
- static { this.PERMISSION_PROVIDER_OPTIONS = '@app/application/options/permission'; }
52
+ static { this.PERMISSION_PROVIDER_OPTIONS = BindingKeys.build({
53
+ key: '@app/application/options/permission',
54
+ }); }
28
55
  }
29
56
  /** The `localStorage` keys the kernel owns. */
30
57
  export class LocalStorageKeys {
@@ -213,6 +213,10 @@ export interface IAuthTokenRecord {
213
213
  export interface IDataSourceRequestContext {
214
214
  paths: Array<string>;
215
215
  }
216
+ /** What `onUnauthorized` is told besides the request: `attempt` is 1 for the first 401 and 2 for the retry's own. */
217
+ export interface IDataSourceUnauthorizedInfo {
218
+ attempt: number;
219
+ }
216
220
  /**
217
221
  * The settings an `HttpDataSource` takes, bound to one `DefaultNetworkRequestService`, so a
218
222
  * repository sends what the data provider sends: the same headers, the same token on the same
@@ -221,7 +225,7 @@ export interface IDataSourceRequestContext {
221
225
  export interface IDataSourceAuth {
222
226
  authTokenResolver: (context: IDataSourceRequestContext) => IAuthTokenRecord | undefined;
223
227
  headersResolver: (context: IDataSourceRequestContext) => Record<string, string>;
224
- onUnauthorized: (context: IDataSourceRequestContext) => Promise<boolean>;
228
+ onUnauthorized: (context: IDataSourceRequestContext, info: IDataSourceUnauthorizedInfo) => Promise<boolean>;
225
229
  errorRootKey: string;
226
230
  }
227
231
  /** What `DefaultNetworkRequestService.doRequest` answers. */
@@ -1,5 +1,5 @@
1
1
  export * from './headers.js';
2
2
  export * from './request-body-encoder.js';
3
- export * from './response-reader.js';
3
+ export * from './network-response-reader.js';
4
4
  export * from './auth-recovery.js';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
1
  export * from './headers.js';
2
2
  export * from './request-body-encoder.js';
3
- export * from './response-reader.js';
3
+ export * from './network-response-reader.js';
4
4
  export * from './auth-recovery.js';
5
5
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  import { type INetworkResponse, RequestCountData, type TConstValue, type TRequestType } from '../../common/index.js';
2
2
  /** Reads a `Response` into an `INetworkResponse`, and an error response into an error. */
3
- export declare class ResponseReader {
3
+ export declare class NetworkResponseReader {
4
4
  /** The server wraps an error body under this key; both transports unwrap it. */
5
5
  static readonly ERROR_ROOT_KEY = "error";
6
6
  /** A response as `INetworkResponse`: JSON read by the request type, a file as a `Blob`. */
@@ -54,4 +54,4 @@ export declare class ResponseReader {
54
54
  /** The file name a `Content-Disposition` header names, `filename*` before `filename`. */
55
55
  private static parseFilename;
56
56
  }
57
- //# sourceMappingURL=response-reader.d.ts.map
57
+ //# sourceMappingURL=network-response-reader.d.ts.map
@@ -6,7 +6,7 @@ const isCountedBody = (value) => {
6
6
  return typeof value === 'object' && value !== null && 'data' in value && 'count' in value;
7
7
  };
8
8
  /** Reads a `Response` into an `INetworkResponse`, and an error response into an error. */
9
- export class ResponseReader {
9
+ export class NetworkResponseReader {
10
10
  /** The server wraps an error body under this key; both transports unwrap it. */
11
11
  static { this.ERROR_ROOT_KEY = 'error'; }
12
12
  /** A response as `INetworkResponse`: JSON read by the request type, a file as a `Blob`. */
@@ -21,7 +21,7 @@ export class ResponseReader {
21
21
  const isTextual = contentType !== '' && HeaderConstants.TEXTUAL_CONTENT_TYPE_RE.test(contentType);
22
22
  if (isAttachment || !isTextual) {
23
23
  const blob = await response.blob();
24
- const filename = ResponseReader.parseFilename({ header: contentDisposition });
24
+ const filename = NetworkResponseReader.parseFilename({ header: contentDisposition });
25
25
  return {
26
26
  data: blob,
27
27
  ...(filename ? { filename } : {}),
@@ -30,7 +30,7 @@ export class ResponseReader {
30
30
  }
31
31
  const parsedBody = await HttpResponseReader.readBody({
32
32
  response,
33
- context: `[ResponseReader] ${response.status}`,
33
+ context: `[NetworkResponseReader] ${response.status}`,
34
34
  });
35
35
  // A route with extras answers `{ data, extra }`; `readExtra` strips only `extra`, so a
36
36
  // count-in-body request still reads `{ count, data }`.
@@ -38,7 +38,7 @@ export class ResponseReader {
38
38
  body: parsedBody,
39
39
  headers: response.headers,
40
40
  });
41
- const converted = ResponseReader.convert({
41
+ const converted = NetworkResponseReader.convert({
42
42
  type,
43
43
  requestCountData,
44
44
  response: { headers: response.headers, data: body },
@@ -64,16 +64,22 @@ export class ResponseReader {
64
64
  });
65
65
  }
66
66
  const dataFormatted = data;
67
- const normalizedData = ResponseReader.toRows({ data: dataFormatted.data });
68
- const total = ResponseReader.resolveTotal({ headers, rowCount: normalizedData.length });
67
+ const normalizedData = NetworkResponseReader.toRows({ data: dataFormatted.data });
68
+ const total = NetworkResponseReader.resolveTotal({
69
+ headers,
70
+ rowCount: normalizedData.length,
71
+ });
69
72
  return {
70
73
  data: normalizedData,
71
74
  count: dataFormatted?.count ?? normalizedData.length,
72
75
  total,
73
76
  };
74
77
  }
75
- const normalizedData = ResponseReader.toRows({ data });
76
- const total = ResponseReader.resolveTotal({ headers, rowCount: normalizedData.length });
78
+ const normalizedData = NetworkResponseReader.toRows({ data });
79
+ const total = NetworkResponseReader.resolveTotal({
80
+ headers,
81
+ rowCount: normalizedData.length,
82
+ });
77
83
  return {
78
84
  data: normalizedData,
79
85
  total,
@@ -109,7 +115,7 @@ export class ResponseReader {
109
115
  const { response } = opts;
110
116
  const server = await HttpResponseReader.readError({
111
117
  response,
112
- rootKey: ResponseReader.ERROR_ROOT_KEY,
118
+ rootKey: NetworkResponseReader.ERROR_ROOT_KEY,
113
119
  });
114
120
  // A relaying server's `extra.requestId` names the request it made upstream; keep it, nearest first.
115
121
  const extra = { ...server.extra };
@@ -144,7 +150,7 @@ export class ResponseReader {
144
150
  */
145
151
  static readFilename(opts) {
146
152
  const header = opts.headers?.get(HeaderConstants.CONTENT_DISPOSITION) ?? '';
147
- return ResponseReader.parseFilename({ header });
153
+ return NetworkResponseReader.parseFilename({ header });
148
154
  }
149
155
  /** The file name a `Content-Disposition` header names, `filename*` before `filename`. */
150
156
  static parseFilename(opts) {
@@ -172,4 +178,4 @@ export class ResponseReader {
172
178
  return undefined;
173
179
  }
174
180
  }
175
- //# sourceMappingURL=response-reader.js.map
181
+ //# sourceMappingURL=network-response-reader.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@venizia/ardor-kernel",
3
- "version": "0.4.8",
3
+ "version": "0.5.0-0",
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",
@@ -72,12 +72,12 @@
72
72
  "devDependencies": {
73
73
  "@size-limit/preset-small-lib": "^14.2.0",
74
74
  "@types/bun": "^1.4.3",
75
- "@venizia/dev-configs": "^0.4.8",
76
- "@venizia/ignis-connectors": "^0.4.8",
77
- "@venizia/ignis-filter": "^0.4.7",
78
- "@venizia/ignis-helpers": "^0.4.8",
79
- "@venizia/ignis-inversion": "^0.4.7",
80
- "@venizia/ignis-kernel": "^0.4.8",
75
+ "@venizia/dev-configs": "^0.5.0-1",
76
+ "@venizia/ignis-connectors": "^0.5.0-1",
77
+ "@venizia/ignis-filter": "^0.5.0-0",
78
+ "@venizia/ignis-helpers": "^0.5.0-0",
79
+ "@venizia/ignis-inversion": "^0.5.0-0",
80
+ "@venizia/ignis-kernel": "^0.5.0-0",
81
81
  "eslint": "^10.13.0",
82
82
  "oxlint": "1.89.0",
83
83
  "oxlint-tsgolint": "7.0.2004",
@@ -87,11 +87,11 @@
87
87
  "typescript": "^6.0.3"
88
88
  },
89
89
  "peerDependencies": {
90
- "@venizia/ignis-connectors": "^0.4.8",
91
- "@venizia/ignis-filter": "^0.4.7",
92
- "@venizia/ignis-helpers": "^0.4.8",
93
- "@venizia/ignis-inversion": "^0.4.7",
94
- "@venizia/ignis-kernel": "^0.4.8",
90
+ "@venizia/ignis-connectors": "^0.5.0-1",
91
+ "@venizia/ignis-filter": "^0.5.0-0",
92
+ "@venizia/ignis-helpers": "^0.5.0-0",
93
+ "@venizia/ignis-inversion": "^0.5.0-0",
94
+ "@venizia/ignis-kernel": "^0.5.0-0",
95
95
  "reflect-metadata": ">=0.2.2"
96
96
  },
97
97
  "peerDependenciesMeta": {