@venizia/ardor-kernel 0.4.8 → 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.
- package/README.md +1 -1
- package/dist/base/applications/abstract.js +3 -2
- package/dist/base/services/network-request.d.ts +13 -11
- package/dist/base/services/network-request.js +61 -49
- package/dist/common/keys.d.ts +28 -13
- package/dist/common/keys.js +41 -14
- package/dist/common/types.d.ts +5 -1
- package/dist/helpers/networks/index.d.ts +1 -1
- package/dist/helpers/networks/index.js +1 -1
- package/dist/helpers/networks/{response-reader.d.ts → network-response-reader.d.ts} +2 -2
- package/dist/helpers/networks/{response-reader.js → network-response-reader.js} +17 -11
- package/package.json +13 -13
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`, `
|
|
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 [
|
|
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 {
|
|
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,
|
|
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:
|
|
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 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
|
+
*/
|
|
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 `
|
|
201
|
-
convertResponse<TData = unknown>(opts: Parameters<typeof
|
|
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 {
|
|
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,
|
|
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,41 @@ 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
|
|
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,
|
|
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 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
|
+
*/
|
|
55
|
+
toSendHeaders(opts) {
|
|
56
|
+
const sent = {
|
|
57
|
+
...Object.fromEntries(new Headers(opts.headers ?? this.headers)),
|
|
58
|
+
...opts.extra,
|
|
59
|
+
};
|
|
60
|
+
if (opts.headers && !(HeaderConstants.CONTENT_TYPE in sent)) {
|
|
61
|
+
sent[HeaderConstants.CONTENT_TYPE] = null;
|
|
62
|
+
}
|
|
63
|
+
if (DefaultNetworkRequestService.isRawBody({ body: opts.body }) &&
|
|
64
|
+
!sent[HeaderConstants.CONTENT_TYPE]) {
|
|
65
|
+
sent[HeaderConstants.CONTENT_TYPE] = null;
|
|
66
|
+
}
|
|
67
|
+
return sent;
|
|
68
|
+
}
|
|
69
|
+
/** A body the platform `fetch` gives a content type of its own, or none: it is sent as it is. */
|
|
70
|
+
static isRawBody(opts) {
|
|
71
|
+
const { body } = opts;
|
|
72
|
+
return (body instanceof FormData ||
|
|
73
|
+
body instanceof Blob ||
|
|
74
|
+
body instanceof URLSearchParams ||
|
|
75
|
+
body instanceof ArrayBuffer ||
|
|
76
|
+
ArrayBuffer.isView(body) ||
|
|
77
|
+
body instanceof ReadableStream);
|
|
78
|
+
}
|
|
50
79
|
/**
|
|
51
80
|
* The token under the unscoped session key (`AuthTokenStore.read`), `undefined` outside a browser, for an
|
|
52
81
|
* application with no `id`. With an application `id` the session is under other keys: use
|
|
@@ -346,7 +375,7 @@ export class DefaultNetworkRequestService extends BaseService {
|
|
|
346
375
|
sources: [this.getSessionHeaders(), opts ? this.getTracingHeaders(opts) : {}],
|
|
347
376
|
});
|
|
348
377
|
},
|
|
349
|
-
onUnauthorized: (context) => {
|
|
378
|
+
onUnauthorized: (context, info) => {
|
|
350
379
|
if (!this.recovery.canRecover({ paths: context.paths })) {
|
|
351
380
|
return Promise.resolve(false);
|
|
352
381
|
}
|
|
@@ -355,6 +384,10 @@ export class DefaultNetworkRequestService extends BaseService {
|
|
|
355
384
|
if (change === false) {
|
|
356
385
|
return Promise.reject(this.sessionChangedError());
|
|
357
386
|
}
|
|
387
|
+
// The retry's own 401 stands, as it does for `doRequest`: one refresh, one retry.
|
|
388
|
+
if (info.attempt >= 2) {
|
|
389
|
+
return Promise.resolve(false);
|
|
390
|
+
}
|
|
358
391
|
if (change === true) {
|
|
359
392
|
return Promise.resolve(true);
|
|
360
393
|
}
|
|
@@ -368,7 +401,7 @@ export class DefaultNetworkRequestService extends BaseService {
|
|
|
368
401
|
: isRefreshed;
|
|
369
402
|
});
|
|
370
403
|
},
|
|
371
|
-
errorRootKey:
|
|
404
|
+
errorRootKey: NetworkResponseReader.ERROR_ROOT_KEY,
|
|
372
405
|
};
|
|
373
406
|
}
|
|
374
407
|
/**
|
|
@@ -443,30 +476,6 @@ export class DefaultNetworkRequestService extends BaseService {
|
|
|
443
476
|
[HeaderConstants.AUTHORIZATION]: authHeader.token,
|
|
444
477
|
};
|
|
445
478
|
}
|
|
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
479
|
/** The body as it is sent and the content type to send it under. Override to encode another way. */
|
|
471
480
|
encodeBody(opts) {
|
|
472
481
|
return RequestBodyEncoder.encode(opts);
|
|
@@ -496,9 +505,9 @@ export class DefaultNetworkRequestService extends BaseService {
|
|
|
496
505
|
};
|
|
497
506
|
return props;
|
|
498
507
|
}
|
|
499
|
-
/** Reads a response by the request type. See `
|
|
508
|
+
/** Reads a response by the request type. See `NetworkResponseReader.convert`. */
|
|
500
509
|
convertResponse(opts) {
|
|
501
|
-
return
|
|
510
|
+
return NetworkResponseReader.convert(opts);
|
|
502
511
|
}
|
|
503
512
|
/**
|
|
504
513
|
* Sends the request and reads the response by `type`. Throws when `baseUrl` (the option, else the
|
|
@@ -515,9 +524,6 @@ export class DefaultNetworkRequestService extends BaseService {
|
|
|
515
524
|
});
|
|
516
525
|
}
|
|
517
526
|
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
527
|
const timeoutSignal = this.timeout.use
|
|
522
528
|
? AbortSignal.timeout(this.timeout.milliseconds)
|
|
523
529
|
: undefined;
|
|
@@ -545,19 +551,24 @@ export class DefaultNetworkRequestService extends BaseService {
|
|
|
545
551
|
/** `doRequest` once the URL is checked: the send, the refresh and retry after a 401, then the read. */
|
|
546
552
|
async sendAndRead(opts) {
|
|
547
553
|
const { url, type, method, paths, body, headers, query, requestCountData, signal } = opts;
|
|
548
|
-
const sendOnce = (
|
|
554
|
+
const sendOnce = (retryHeaders) => {
|
|
549
555
|
return this.networkRequest.getNetworkService().send({
|
|
550
556
|
url,
|
|
551
557
|
method,
|
|
552
558
|
params: query,
|
|
553
559
|
body: method === RequestMethods.GET ? undefined : body,
|
|
554
|
-
headers:
|
|
560
|
+
headers: this.toSendHeaders({
|
|
561
|
+
headers,
|
|
562
|
+
extra: retryHeaders,
|
|
563
|
+
body: method === RequestMethods.GET ? undefined : body,
|
|
564
|
+
}),
|
|
555
565
|
signal,
|
|
566
|
+
acceptStatus: () => true,
|
|
556
567
|
}, this.logger);
|
|
557
568
|
};
|
|
558
569
|
const sent = this.readSession();
|
|
559
570
|
let isRetried = false;
|
|
560
|
-
let fetched = await sendOnce(
|
|
571
|
+
let fetched = await sendOnce();
|
|
561
572
|
if (fetched.status === 401 && this.recovery.canRecover({ paths })) {
|
|
562
573
|
// A 401 that arrives after the session changed is not the new session's to refresh or to end.
|
|
563
574
|
const change = this.readSessionChange({ sent });
|
|
@@ -580,16 +591,17 @@ export class DefaultNetworkRequestService extends BaseService {
|
|
|
580
591
|
// The shared refresh is never aborted for one request: this request stops when it returns.
|
|
581
592
|
signal?.throwIfAborted();
|
|
582
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
|
+
}
|
|
583
599
|
const authHeader = this.getRequestAuthorizationHeader();
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
? { [HeaderConstants.X_AUTH_PROVIDER]: authHeader.provider }
|
|
590
|
-
: undefined,
|
|
591
|
-
],
|
|
592
|
-
});
|
|
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
|
+
};
|
|
593
605
|
const result = await sendOnce(retryHeaders);
|
|
594
606
|
fetched = result;
|
|
595
607
|
isRetried = true;
|
|
@@ -603,10 +615,10 @@ export class DefaultNetworkRequestService extends BaseService {
|
|
|
603
615
|
throw this.sessionChangedError();
|
|
604
616
|
}
|
|
605
617
|
if (status < 200 || status >= 300) {
|
|
606
|
-
const result2 = await
|
|
618
|
+
const result2 = await NetworkResponseReader.toError({ response: fetched });
|
|
607
619
|
throw result2;
|
|
608
620
|
}
|
|
609
|
-
const response = await
|
|
621
|
+
const response = await NetworkResponseReader.read({
|
|
610
622
|
response: fetched,
|
|
611
623
|
type,
|
|
612
624
|
requestCountData,
|
package/dist/common/keys.d.ts
CHANGED
|
@@ -1,29 +1,44 @@
|
|
|
1
|
-
|
|
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
|
|
19
|
+
static readonly APPLICATION_INSTANCE: TBindingKey<AbstractArdorApplication>;
|
|
5
20
|
/** The `IApplicationInfo`, bound by `preConfigure`. */
|
|
6
|
-
static readonly APPLICATION_INFO
|
|
21
|
+
static readonly APPLICATION_INFO: TBindingKey<IApplicationInfo>;
|
|
7
22
|
/** The auth provider. */
|
|
8
|
-
static readonly DEFAULT_AUTH_PROVIDER
|
|
23
|
+
static readonly DEFAULT_AUTH_PROVIDER: TBindingKey<TCoreBindingType<'authProvider'>>;
|
|
9
24
|
/** The i18n provider. */
|
|
10
|
-
static readonly DEFAULT_I18N_PROVIDER
|
|
25
|
+
static readonly DEFAULT_I18N_PROVIDER: TBindingKey<TCoreBindingType<'i18nProvider'>>;
|
|
11
26
|
/** The REST data provider. */
|
|
12
|
-
static readonly DEFAULT_REST_DATA_PROVIDER
|
|
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
|
|
29
|
+
static readonly AUTH_PROVIDER_OPTIONS: TBindingKey<TAuthProviderOptions>;
|
|
15
30
|
/** The `DefaultAuthService`. */
|
|
16
|
-
static readonly DEFAULT_AUTH_SERVICE
|
|
31
|
+
static readonly DEFAULT_AUTH_SERVICE: TBindingKey<DefaultAuthService>;
|
|
17
32
|
/** The `IRestDataProviderOptions`. */
|
|
18
|
-
static readonly REST_DATA_PROVIDER_OPTIONS
|
|
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
|
|
35
|
+
static readonly I18N_PROVIDER_OPTIONS: TBindingKey<TCoreBindingType<'i18nProviderOptions'>>;
|
|
21
36
|
/** The `features()` an application mounts, bound by `preConfigure()`. */
|
|
22
|
-
static readonly 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
|
|
39
|
+
static readonly PERMISSION_PROVIDER: TBindingKey<IPermissionProvider>;
|
|
25
40
|
/** The `IRolePermissionProviderOptions` that `RolePermissionProvider` reads. */
|
|
26
|
-
static readonly PERMISSION_PROVIDER_OPTIONS
|
|
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 {
|
package/dist/common/keys.js
CHANGED
|
@@ -1,30 +1,57 @@
|
|
|
1
|
-
import { getError } from '@venizia/ignis-inversion';
|
|
2
|
-
/**
|
|
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 =
|
|
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 =
|
|
12
|
+
static { this.APPLICATION_INFO = BindingKeys.build({
|
|
13
|
+
key: '@app/application/info',
|
|
14
|
+
}); }
|
|
8
15
|
/** The auth provider. */
|
|
9
|
-
static { this.DEFAULT_AUTH_PROVIDER =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 {
|
package/dist/common/types.d.ts
CHANGED
|
@@ -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,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
|
|
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
|
|
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 =
|
|
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: `[
|
|
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 =
|
|
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 =
|
|
68
|
-
const total =
|
|
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 =
|
|
76
|
-
const total =
|
|
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:
|
|
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
|
|
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.
|
|
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",
|
|
@@ -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.
|
|
76
|
-
"@venizia/ignis-connectors": "^0.
|
|
77
|
-
"@venizia/ignis-filter": "^0.
|
|
78
|
-
"@venizia/ignis-helpers": "^0.
|
|
79
|
-
"@venizia/ignis-inversion": "^0.
|
|
80
|
-
"@venizia/ignis-kernel": "^0.
|
|
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.
|
|
91
|
-
"@venizia/ignis-filter": "^0.
|
|
92
|
-
"@venizia/ignis-helpers": "^0.
|
|
93
|
-
"@venizia/ignis-inversion": "^0.
|
|
94
|
-
"@venizia/ignis-kernel": "^0.
|
|
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": {
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
"@venizia/ignis-inversion",
|
|
109
109
|
"reflect-metadata"
|
|
110
110
|
],
|
|
111
|
-
"limit": "
|
|
111
|
+
"limit": "11300 B"
|
|
112
112
|
},
|
|
113
113
|
{
|
|
114
114
|
"path": "dist/testing.js",
|