@venizia/ardor-kernel 0.5.0-3 → 0.5.0-5
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 +3 -3
- package/dist/base/services/auth.js +3 -3
- package/dist/base/services/network-request.d.ts +4 -6
- package/dist/base/services/network-request.js +40 -47
- package/dist/common/constants.d.ts +2 -48
- package/dist/common/constants.js +2 -56
- package/dist/helpers/index.d.ts +0 -1
- package/dist/helpers/index.js +0 -1
- package/dist/helpers/networks/auth-recovery.d.ts +2 -3
- package/dist/helpers/networks/auth-recovery.js +6 -4
- package/dist/helpers/networks/index.d.ts +0 -3
- package/dist/helpers/networks/index.js +0 -3
- package/dist/utilities/file.d.ts +16 -0
- package/dist/utilities/file.js +30 -0
- package/dist/utilities/index.d.ts +3 -0
- package/dist/utilities/index.js +3 -0
- package/dist/{helpers/networks → utilities}/network-response-reader.d.ts +3 -11
- package/dist/{helpers/networks → utilities}/network-response-reader.js +17 -47
- package/dist/{helpers/networks → utilities}/request-body-encoder.d.ts +1 -1
- package/dist/{helpers/networks → utilities}/request-body-encoder.js +2 -2
- package/dist/utilities/value.d.ts +0 -8
- package/dist/utilities/value.js +0 -10
- package/package.json +12 -12
- package/dist/helpers/networks/headers.d.ts +0 -16
- package/dist/helpers/networks/headers.js +0 -32
- /package/dist/{helpers → utilities}/auth-token-store.d.ts +0 -0
- /package/dist/{helpers → utilities}/auth-token-store.js +0 -0
package/README.md
CHANGED
|
@@ -23,9 +23,9 @@ which re-exports this package.
|
|
|
23
23
|
| Providers | `BaseProvider` |
|
|
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
|
-
| Constants | `RequestMethods`, `RequestTypes`, `RequestBodyTypes`, `RequestCountData`, `
|
|
27
|
-
| Network | `
|
|
28
|
-
| Utilities | `ValueUtility` (`isDefined`, `isString`, `isNumber
|
|
26
|
+
| Constants | `RequestMethods`, `RequestTypes`, `RequestBodyTypes`, `RequestCountData`, `Environments`, `App`, `StorageAreas`, `RequestChannel` |
|
|
27
|
+
| Network | `RequestBodyEncoder`, `NetworkResponseReader`, `AuthRecoveryHelper`, `AuthTokenStore` (the fetch transport is IGNIS's `NativeFetchNetworkRequest`) |
|
|
28
|
+
| Utilities | `ValueUtility` (`isDefined`, `isString`, `isNumber`), `BrowserUtility.isBrowser`, `FileUtility.toDataUrl` and `FileUtility.save`, `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
|
|
|
31
31
|
## License
|
|
@@ -11,10 +11,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
11
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
12
|
};
|
|
13
13
|
var DefaultAuthService_1;
|
|
14
|
+
import { RecordUtility } from '@venizia/ignis-helpers/core';
|
|
14
15
|
import { getError, inject } from '@venizia/ignis-inversion';
|
|
15
16
|
import { CoreBindings, LocalStorageKeys, StorageAreas, } from '../../common/index.js';
|
|
16
|
-
import { AuthTokenStore } from '../../
|
|
17
|
-
import { BrowserStorage, StorageCodecs } from '../../utilities/index.js';
|
|
17
|
+
import { AuthTokenStore, BrowserStorage, StorageCodecs } from '../../utilities/index.js';
|
|
18
18
|
import { BaseService } from './base.js';
|
|
19
19
|
/**
|
|
20
20
|
* Keeps the signed-in session (token, identity, roles) in `localStorage`, everything under
|
|
@@ -179,7 +179,7 @@ let DefaultAuthService = DefaultAuthService_1 = class DefaultAuthService extends
|
|
|
179
179
|
}
|
|
180
180
|
/** A stored identity is data from the browser: an object whose known fields, when present, have their type. */
|
|
181
181
|
isAuthUser(value) {
|
|
182
|
-
if (
|
|
182
|
+
if (!RecordUtility.isPlainRecord(value)) {
|
|
183
183
|
return false;
|
|
184
184
|
}
|
|
185
185
|
const userId = 'userId' in value ? value.userId : undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
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, NetworkResponseReader } from '../../
|
|
3
|
+
import { type IEncodedBody, NetworkResponseReader } from '../../utilities/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. */
|
|
@@ -22,8 +22,8 @@ export declare class DefaultNetworkRequestService extends BaseService {
|
|
|
22
22
|
protected noAuthPaths?: string[];
|
|
23
23
|
/** `noAuthPathRegex` compiled; a resource matching any is sent without a token. */
|
|
24
24
|
protected noAuthPathRegexes: RegExp[];
|
|
25
|
-
/** Headers added to every request
|
|
26
|
-
protected headers:
|
|
25
|
+
/** Headers added to every request. */
|
|
26
|
+
protected headers: Headers;
|
|
27
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;
|
|
@@ -63,8 +63,6 @@ export declare class DefaultNetworkRequestService extends BaseService {
|
|
|
63
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
|
-
/** A body the platform `fetch` gives a content type of its own, or none: it is sent as it is. */
|
|
67
|
-
private static isRawBody;
|
|
68
66
|
/**
|
|
69
67
|
* The token under the unscoped session key (`AuthTokenStore.read`), `undefined` outside a browser, for an
|
|
70
68
|
* application with no `id`. With an application `id` the session is under other keys: use
|
|
@@ -134,7 +132,7 @@ export declare class DefaultNetworkRequestService extends BaseService {
|
|
|
134
132
|
input?: TNoAuthPathRegex;
|
|
135
133
|
}): RegExp[];
|
|
136
134
|
/**
|
|
137
|
-
* Refreshes the session, once for every 401 in flight on either transport (see `
|
|
135
|
+
* Refreshes the session, once for every 401 in flight on either transport (see `AuthRecoveryHelper`).
|
|
138
136
|
* Also what `DefaultAuthProvider.refreshToken` calls, so a refresh is made in one place.
|
|
139
137
|
*/
|
|
140
138
|
refresh(): Promise<boolean>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { getError } from '@venizia/ignis-inversion';
|
|
2
2
|
import { HTTP } from '@venizia/ignis-helpers/common';
|
|
3
|
-
import { NativeFetchNetworkRequest } from '@venizia/ignis-helpers/core';
|
|
3
|
+
import { HttpHeaders, HttpResponseReader, NativeFetcher, 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
|
-
import { App,
|
|
7
|
-
import {
|
|
6
|
+
import { App, LocalStorageKeys, RequestChannel, RequestCountData, RequestMethods, RequestTypes, } from '../../common/index.js';
|
|
7
|
+
import { AuthRecoveryHelper } from '../../helpers/index.js';
|
|
8
|
+
import { AuthTokenStore, NetworkResponseReader, RequestBodyEncoder, } from '../../utilities/index.js';
|
|
8
9
|
import { BaseService } from './base.js';
|
|
9
10
|
/** 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
11
|
export const SESSION_CHANGED_CODE = 'ardor.network.session_changed';
|
|
@@ -28,14 +29,13 @@ export class DefaultNetworkRequestService extends BaseService {
|
|
|
28
29
|
const { name, baseUrl = '', headers = {}, noAuthPaths, noAuthPathRegex, authRecovery, authService, timeout = { use: false }, } = opts;
|
|
29
30
|
DefaultNetworkRequestService.assertTimeout({ timeout });
|
|
30
31
|
this.timeout = timeout;
|
|
31
|
-
this.headers =
|
|
32
|
+
this.headers = HttpHeaders.merge({ layers: [headers] });
|
|
32
33
|
this.noAuthPaths = noAuthPaths;
|
|
33
34
|
this.noAuthPathRegexes = this.compileNoAuthPathRegex({ input: noAuthPathRegex });
|
|
34
35
|
this.baseUrl = baseUrl;
|
|
35
36
|
this.authRecovery = authRecovery;
|
|
36
37
|
this.authService = authService;
|
|
37
|
-
this.recovery = new
|
|
38
|
-
logger: this.logger,
|
|
38
|
+
this.recovery = new AuthRecoveryHelper({
|
|
39
39
|
getRefreshTokenPath: () => this.authRecovery?.refreshTokenPath,
|
|
40
40
|
refresh: () => this.refreshToken(),
|
|
41
41
|
onFailure: () => this.onAuthFailure(),
|
|
@@ -57,25 +57,16 @@ export class DefaultNetworkRequestService extends BaseService {
|
|
|
57
57
|
...Object.fromEntries(new Headers(opts.headers ?? this.headers)),
|
|
58
58
|
...opts.extra,
|
|
59
59
|
};
|
|
60
|
-
if (opts.headers && !(
|
|
61
|
-
sent[
|
|
60
|
+
if (opts.headers && !(HTTP.Headers.CONTENT_TYPE in sent)) {
|
|
61
|
+
sent[HTTP.Headers.CONTENT_TYPE] = null;
|
|
62
62
|
}
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
sent[
|
|
63
|
+
if (typeof opts.body !== 'string' &&
|
|
64
|
+
NativeFetcher.isRawBody(opts.body) &&
|
|
65
|
+
!sent[HTTP.Headers.CONTENT_TYPE]) {
|
|
66
|
+
sent[HTTP.Headers.CONTENT_TYPE] = null;
|
|
66
67
|
}
|
|
67
68
|
return sent;
|
|
68
69
|
}
|
|
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
|
-
}
|
|
79
70
|
/**
|
|
80
71
|
* The token under the unscoped session key (`AuthTokenStore.read`), `undefined` outside a browser, for an
|
|
81
72
|
* application with no `id`. With an application `id` the session is under other keys: use
|
|
@@ -233,7 +224,7 @@ export class DefaultNetworkRequestService extends BaseService {
|
|
|
233
224
|
if (typeof value !== 'string' || !value) {
|
|
234
225
|
throw getError({ message: '[refreshToken] The refresh response carries no token' });
|
|
235
226
|
}
|
|
236
|
-
return { value, type: typeof type === 'string' ? type :
|
|
227
|
+
return { value, type: typeof type === 'string' ? type : App.TOKEN_TYPE };
|
|
237
228
|
}
|
|
238
229
|
/** Runs once when `refreshToken` threw. The place to send the user back to sign-in. */
|
|
239
230
|
onAuthFailure() {
|
|
@@ -270,7 +261,7 @@ export class DefaultNetworkRequestService extends BaseService {
|
|
|
270
261
|
return compiled;
|
|
271
262
|
}
|
|
272
263
|
/**
|
|
273
|
-
* Refreshes the session, once for every 401 in flight on either transport (see `
|
|
264
|
+
* Refreshes the session, once for every 401 in flight on either transport (see `AuthRecoveryHelper`).
|
|
274
265
|
* Also what `DefaultAuthProvider.refreshToken` calls, so a refresh is made in one place.
|
|
275
266
|
*/
|
|
276
267
|
refresh() {
|
|
@@ -371,9 +362,9 @@ export class DefaultNetworkRequestService extends BaseService {
|
|
|
371
362
|
return token;
|
|
372
363
|
},
|
|
373
364
|
headersResolver: () => {
|
|
374
|
-
return
|
|
375
|
-
|
|
376
|
-
});
|
|
365
|
+
return Object.fromEntries(HttpHeaders.merge({
|
|
366
|
+
layers: [this.getSessionHeaders(), opts ? this.getTracingHeaders(opts) : {}],
|
|
367
|
+
}));
|
|
377
368
|
},
|
|
378
369
|
onUnauthorized: (context, info) => {
|
|
379
370
|
if (!this.recovery.canRecover({ paths: context.paths })) {
|
|
@@ -418,34 +409,33 @@ export class DefaultNetworkRequestService extends BaseService {
|
|
|
418
409
|
}
|
|
419
410
|
return {
|
|
420
411
|
provider: authToken?.provider,
|
|
421
|
-
token: `${authToken?.type?.length ? authToken.type :
|
|
412
|
+
token: `${authToken?.type?.length ? authToken.type : App.TOKEN_TYPE} ${authToken.value}`,
|
|
422
413
|
};
|
|
423
414
|
}
|
|
424
415
|
/** Adds headers to every request this service sends; a name already set is replaced, in any case. */
|
|
425
416
|
setHeaders(opts) {
|
|
426
|
-
this.headers =
|
|
417
|
+
this.headers = HttpHeaders.merge({ layers: [this.headers, opts.headers] });
|
|
427
418
|
}
|
|
428
419
|
/** Removes the headers set by name, in any case. */
|
|
429
420
|
removeHeaders(opts) {
|
|
430
421
|
if (!opts.keys?.length) {
|
|
431
422
|
return;
|
|
432
423
|
}
|
|
433
|
-
// The record is keyed by lowercase name.
|
|
434
424
|
for (const key of opts.keys) {
|
|
435
|
-
|
|
425
|
+
this.headers.delete(key);
|
|
436
426
|
}
|
|
437
427
|
}
|
|
438
428
|
/** The timezone, then whatever `setHeaders` holds now. Both transports send these. */
|
|
439
429
|
getSessionHeaders() {
|
|
440
|
-
return
|
|
441
|
-
|
|
430
|
+
return Object.fromEntries(HttpHeaders.merge({
|
|
431
|
+
layers: [
|
|
442
432
|
{
|
|
443
|
-
[
|
|
444
|
-
[
|
|
433
|
+
[HTTP.Headers.TIMEZONE]: App.TIMEZONE,
|
|
434
|
+
[HTTP.Headers.TIMEZONE_OFFSET]: `${App.TIMEZONE_OFFSET}`,
|
|
445
435
|
},
|
|
446
436
|
this.headers,
|
|
447
437
|
],
|
|
448
|
-
});
|
|
438
|
+
}));
|
|
449
439
|
}
|
|
450
440
|
/** The request channel (`RequestChannel.WEB` unless configured) and a fresh tracing id. */
|
|
451
441
|
getTracingHeaders(opts) {
|
|
@@ -454,8 +444,8 @@ export class DefaultNetworkRequestService extends BaseService {
|
|
|
454
444
|
? restDataProviderOptions.requestTracingChannel
|
|
455
445
|
: RequestChannel.WEB;
|
|
456
446
|
return {
|
|
457
|
-
[
|
|
458
|
-
[
|
|
447
|
+
[HTTP.Headers.REQUEST_CHANNEL]: channel,
|
|
448
|
+
[HTTP.Headers.REQUEST_TRACING_ID]: this.buildRequestTracingId({ applicationInfo }),
|
|
459
449
|
};
|
|
460
450
|
}
|
|
461
451
|
/**
|
|
@@ -472,8 +462,8 @@ export class DefaultNetworkRequestService extends BaseService {
|
|
|
472
462
|
return {
|
|
473
463
|
...defaultHeaders,
|
|
474
464
|
// A token need not name a provider; never send the string `undefined`.
|
|
475
|
-
...(authHeader.provider ? { [
|
|
476
|
-
[
|
|
465
|
+
...(authHeader.provider ? { [HTTP.Headers.AUTH_PROVIDER]: authHeader.provider } : {}),
|
|
466
|
+
[HTTP.Headers.AUTHORIZATION]: authHeader.token,
|
|
477
467
|
};
|
|
478
468
|
}
|
|
479
469
|
/** The body as it is sent and the content type to send it under. Override to encode another way. */
|
|
@@ -488,18 +478,18 @@ export class DefaultNetworkRequestService extends BaseService {
|
|
|
488
478
|
const { bodyType, body, resource, restDataProviderOptions, applicationInfo, requestCountData = RequestCountData.DATA_ONLY, extra, } = params;
|
|
489
479
|
const extraHeader = HttpExtraRequest.toHeader({ extra });
|
|
490
480
|
// Merged, not spread, so a per-request value replaces a static header in any case.
|
|
491
|
-
const headers =
|
|
492
|
-
|
|
481
|
+
const headers = Object.fromEntries(HttpHeaders.merge({
|
|
482
|
+
layers: [
|
|
493
483
|
this.getRequestHeader({ resource }),
|
|
494
484
|
this.getTracingHeaders({ restDataProviderOptions, applicationInfo }),
|
|
495
|
-
{ [
|
|
485
|
+
{ [HTTP.Headers.REQUEST_COUNT_DATA]: requestCountData },
|
|
496
486
|
extraHeader ? { [HttpExtraRequest.HEADER]: extraHeader } : undefined,
|
|
497
487
|
],
|
|
498
|
-
});
|
|
488
|
+
}));
|
|
499
489
|
const encoded = this.encodeBody({ bodyType, body });
|
|
500
490
|
const props = {
|
|
501
491
|
headers: encoded.contentType
|
|
502
|
-
? { ...headers, [
|
|
492
|
+
? { ...headers, [HTTP.Headers.CONTENT_TYPE]: encoded.contentType }
|
|
503
493
|
: headers,
|
|
504
494
|
body: encoded.body,
|
|
505
495
|
};
|
|
@@ -599,8 +589,8 @@ export class DefaultNetworkRequestService extends BaseService {
|
|
|
599
589
|
const authHeader = this.getRequestAuthorizationHeader();
|
|
600
590
|
// The token's provider wins, and a token with none removes the one the call carried.
|
|
601
591
|
const retryHeaders = {
|
|
602
|
-
[
|
|
603
|
-
[
|
|
592
|
+
[HTTP.Headers.AUTHORIZATION]: authHeader.token,
|
|
593
|
+
[HTTP.Headers.AUTH_PROVIDER]: authHeader.provider ?? null,
|
|
604
594
|
};
|
|
605
595
|
const result = await sendOnce(retryHeaders);
|
|
606
596
|
fetched = result;
|
|
@@ -615,7 +605,10 @@ export class DefaultNetworkRequestService extends BaseService {
|
|
|
615
605
|
throw this.sessionChangedError();
|
|
616
606
|
}
|
|
617
607
|
if (status < 200 || status >= 300) {
|
|
618
|
-
const result2 = await
|
|
608
|
+
const result2 = await HttpResponseReader.toApplicationError({
|
|
609
|
+
response: fetched,
|
|
610
|
+
rootKey: NetworkResponseReader.ERROR_ROOT_KEY,
|
|
611
|
+
});
|
|
619
612
|
throw result2;
|
|
620
613
|
}
|
|
621
614
|
const response = await NetworkResponseReader.read({
|
|
@@ -6,19 +6,8 @@ export declare class App {
|
|
|
6
6
|
static readonly TIMEZONE_OFFSET: number;
|
|
7
7
|
/** In milliseconds. */
|
|
8
8
|
static readonly DEFAULT_DEBOUNCE_TIME = 500;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export declare class Authentication {
|
|
12
|
-
/** The scheme in the `authorization` header. */
|
|
13
|
-
static readonly TYPE_BASIC = "Basic";
|
|
14
|
-
static readonly TYPE_BEARER = "Bearer";
|
|
15
|
-
/** The name of the auth strategy. */
|
|
16
|
-
static readonly STRATEGY_BASIC = "basic";
|
|
17
|
-
static readonly STRATEGY_JWT = "jwt";
|
|
18
|
-
/** Every value of this class that `isValid` accepts. */
|
|
19
|
-
static readonly SCHEME_SET: Set<string>;
|
|
20
|
-
/** Whether `value` is in `SCHEME_SET`. */
|
|
21
|
-
static isValid(value: string): boolean;
|
|
9
|
+
/** The authorization scheme of a token that names none. */
|
|
10
|
+
static readonly TOKEN_TYPE = "Bearer";
|
|
22
11
|
}
|
|
23
12
|
/** HTTP methods. */
|
|
24
13
|
export declare class RequestMethods {
|
|
@@ -81,41 +70,6 @@ export declare class Environments {
|
|
|
81
70
|
/** Whether `value` is in `SCHEME_SET`. */
|
|
82
71
|
static isValid(value: string): boolean;
|
|
83
72
|
}
|
|
84
|
-
/** Header names, lowercase, and patterns on header values. */
|
|
85
|
-
export declare class HeaderConstants {
|
|
86
|
-
/** The header on a request body and on a response. */
|
|
87
|
-
static readonly CONTENT_TYPE = "content-type";
|
|
88
|
-
/**
|
|
89
|
-
* content-range: <unit> <range-start>-<range-end>/<size>
|
|
90
|
-
* @format unit start-end/total
|
|
91
|
-
* The positions are zero-indexed, the end inclusive; the total is `*` if unknown.
|
|
92
|
-
*/
|
|
93
|
-
static readonly CONTENT_RANGE = "content-range";
|
|
94
|
-
/** Names the file of a file response. */
|
|
95
|
-
static readonly CONTENT_DISPOSITION = "content-disposition";
|
|
96
|
-
/** Carries `<type> <token>`. */
|
|
97
|
-
static readonly AUTHORIZATION = "authorization";
|
|
98
|
-
/** Names the provider of the token; sent only when the token names one. */
|
|
99
|
-
static readonly X_AUTH_PROVIDER = "x-auth-provider";
|
|
100
|
-
/** The locale of the request, the header `useRequestHeaderLocale` sets by default. */
|
|
101
|
-
static readonly X_LOCALE = "x-locale";
|
|
102
|
-
/** Carries `App.TIMEZONE`. */
|
|
103
|
-
static readonly TIMEZONE = "timezone";
|
|
104
|
-
/** Carries `App.TIMEZONE_OFFSET`, in hours. */
|
|
105
|
-
static readonly TIMEZONE_OFFSET = "timezone-offset";
|
|
106
|
-
/** Carries the tracing id of a request. */
|
|
107
|
-
static readonly REQUEST_TRACING_ID = "x-request-id";
|
|
108
|
-
/** Carries a `RequestChannel` value. */
|
|
109
|
-
static readonly REQUEST_CHANNEL = "x-request-channel";
|
|
110
|
-
/** Carries a `RequestCountData` value: what the request asks the server to return. */
|
|
111
|
-
static readonly REQUEST_COUNT_DATA = "x-request-count";
|
|
112
|
-
/** Carries the count a server sends with a response that is not a list. */
|
|
113
|
-
static readonly RESPONSE_COUNT_DATA = "x-response-count";
|
|
114
|
-
/** Content types read as text. */
|
|
115
|
-
static readonly TEXTUAL_CONTENT_TYPE_RE: RegExp;
|
|
116
|
-
/** A `content-disposition` that marks a file download. */
|
|
117
|
-
static readonly ATTACHMENT_CONTENT_DISPOSITION_RE: RegExp;
|
|
118
|
-
}
|
|
119
73
|
/** The channels a request says it comes from, sent in `x-request-channel`. */
|
|
120
74
|
export declare class RequestChannel {
|
|
121
75
|
/** A browser application; what a request says unless `requestTracingChannel` is set. */
|
package/dist/common/constants.js
CHANGED
|
@@ -6,26 +6,8 @@ export class App {
|
|
|
6
6
|
static { this.TIMEZONE_OFFSET = -(new Date().getTimezoneOffset() / 60); }
|
|
7
7
|
/** In milliseconds. */
|
|
8
8
|
static { this.DEFAULT_DEBOUNCE_TIME = 500; }
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export class Authentication {
|
|
12
|
-
/** The scheme in the `authorization` header. */
|
|
13
|
-
static { this.TYPE_BASIC = 'Basic'; }
|
|
14
|
-
static { this.TYPE_BEARER = 'Bearer'; }
|
|
15
|
-
/** The name of the auth strategy. */
|
|
16
|
-
static { this.STRATEGY_BASIC = 'basic'; }
|
|
17
|
-
static { this.STRATEGY_JWT = 'jwt'; }
|
|
18
|
-
/** Every value of this class that `isValid` accepts. */
|
|
19
|
-
static { this.SCHEME_SET = new Set([
|
|
20
|
-
this.TYPE_BASIC,
|
|
21
|
-
this.TYPE_BEARER,
|
|
22
|
-
this.STRATEGY_BASIC,
|
|
23
|
-
this.STRATEGY_JWT,
|
|
24
|
-
]); }
|
|
25
|
-
/** Whether `value` is in `SCHEME_SET`. */
|
|
26
|
-
static isValid(value) {
|
|
27
|
-
return this.SCHEME_SET.has(value);
|
|
28
|
-
}
|
|
9
|
+
/** The authorization scheme of a token that names none. */
|
|
10
|
+
static { this.TOKEN_TYPE = 'Bearer'; }
|
|
29
11
|
}
|
|
30
12
|
/** HTTP methods. */
|
|
31
13
|
export class RequestMethods {
|
|
@@ -122,42 +104,6 @@ export class Environments {
|
|
|
122
104
|
return this.SCHEME_SET.has(value);
|
|
123
105
|
}
|
|
124
106
|
}
|
|
125
|
-
/** Header names, lowercase, and patterns on header values. */
|
|
126
|
-
export class HeaderConstants {
|
|
127
|
-
/** The header on a request body and on a response. */
|
|
128
|
-
static { this.CONTENT_TYPE = 'content-type'; }
|
|
129
|
-
/**
|
|
130
|
-
* content-range: <unit> <range-start>-<range-end>/<size>
|
|
131
|
-
* @format unit start-end/total
|
|
132
|
-
* The positions are zero-indexed, the end inclusive; the total is `*` if unknown.
|
|
133
|
-
*/
|
|
134
|
-
static { this.CONTENT_RANGE = 'content-range'; }
|
|
135
|
-
/** Names the file of a file response. */
|
|
136
|
-
static { this.CONTENT_DISPOSITION = 'content-disposition'; }
|
|
137
|
-
/** Carries `<type> <token>`. */
|
|
138
|
-
static { this.AUTHORIZATION = 'authorization'; }
|
|
139
|
-
/** Names the provider of the token; sent only when the token names one. */
|
|
140
|
-
static { this.X_AUTH_PROVIDER = 'x-auth-provider'; }
|
|
141
|
-
/** The locale of the request, the header `useRequestHeaderLocale` sets by default. */
|
|
142
|
-
static { this.X_LOCALE = 'x-locale'; }
|
|
143
|
-
// Lowercase: the service keys its header record by lowercased name.
|
|
144
|
-
/** Carries `App.TIMEZONE`. */
|
|
145
|
-
static { this.TIMEZONE = 'timezone'; }
|
|
146
|
-
/** Carries `App.TIMEZONE_OFFSET`, in hours. */
|
|
147
|
-
static { this.TIMEZONE_OFFSET = 'timezone-offset'; }
|
|
148
|
-
/** Carries the tracing id of a request. */
|
|
149
|
-
static { this.REQUEST_TRACING_ID = 'x-request-id'; }
|
|
150
|
-
/** Carries a `RequestChannel` value. */
|
|
151
|
-
static { this.REQUEST_CHANNEL = 'x-request-channel'; }
|
|
152
|
-
/** Carries a `RequestCountData` value: what the request asks the server to return. */
|
|
153
|
-
static { this.REQUEST_COUNT_DATA = 'x-request-count'; }
|
|
154
|
-
/** Carries the count a server sends with a response that is not a list. */
|
|
155
|
-
static { this.RESPONSE_COUNT_DATA = 'x-response-count'; }
|
|
156
|
-
/** Content types read as text. */
|
|
157
|
-
static { this.TEXTUAL_CONTENT_TYPE_RE = /^(application\/(json|.*\+json|xml|.*\+xml|x-www-form-urlencoded|javascript|graphql)|text\/)/i; }
|
|
158
|
-
/** A `content-disposition` that marks a file download. */
|
|
159
|
-
static { this.ATTACHMENT_CONTENT_DISPOSITION_RE = /^attachment/i; }
|
|
160
|
-
}
|
|
161
107
|
/** The channels a request says it comes from, sent in `x-request-channel`. */
|
|
162
108
|
export class RequestChannel {
|
|
163
109
|
/** A browser application; what a request says unless `requestTracingChannel` is set. */
|
package/dist/helpers/index.d.ts
CHANGED
package/dist/helpers/index.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { BaseHelper } from '@venizia/ignis-helpers/core';
|
|
2
2
|
/**
|
|
3
3
|
* What happens after a 401: one refresh shared by every request in flight, and which paths may
|
|
4
4
|
* recover at all. The callbacks are read when called, so a subclass override of the service hooks
|
|
5
5
|
* behind them takes effect.
|
|
6
6
|
*/
|
|
7
|
-
export declare class
|
|
7
|
+
export declare class AuthRecoveryHelper extends BaseHelper {
|
|
8
8
|
private readonly opts;
|
|
9
9
|
/** The refresh in flight for each session (`key`): a request of another session never joins it. */
|
|
10
10
|
private readonly refreshing;
|
|
11
11
|
constructor(opts: {
|
|
12
|
-
logger: ILogger;
|
|
13
12
|
/** Read per request: the service lets its `authRecovery` be set after construction. */
|
|
14
13
|
getRefreshTokenPath: () => string | undefined;
|
|
15
14
|
/** `true`: refreshed, `false`: this service has no refresh, a throw: it failed. */
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { BaseHelper } from '@venizia/ignis-helpers/core';
|
|
1
2
|
/**
|
|
2
3
|
* What happens after a 401: one refresh shared by every request in flight, and which paths may
|
|
3
4
|
* recover at all. The callbacks are read when called, so a subclass override of the service hooks
|
|
4
5
|
* behind them takes effect.
|
|
5
6
|
*/
|
|
6
|
-
export class
|
|
7
|
+
export class AuthRecoveryHelper extends BaseHelper {
|
|
7
8
|
constructor(opts) {
|
|
9
|
+
super({ scope: AuthRecoveryHelper.name });
|
|
8
10
|
this.opts = opts;
|
|
9
11
|
/** The refresh in flight for each session (`key`): a request of another session never joins it. */
|
|
10
12
|
this.refreshing = new Map();
|
|
@@ -15,7 +17,7 @@ export class AuthRecovery {
|
|
|
15
17
|
* `true` when the token was refreshed.
|
|
16
18
|
*/
|
|
17
19
|
refresh(opts = {}) {
|
|
18
|
-
const {
|
|
20
|
+
const { refresh, onFailure } = this.opts;
|
|
19
21
|
const { key = '' } = opts;
|
|
20
22
|
const inFlight = this.refreshing.get(key);
|
|
21
23
|
if (inFlight) {
|
|
@@ -25,12 +27,12 @@ export class AuthRecovery {
|
|
|
25
27
|
const started = Promise.resolve()
|
|
26
28
|
.then(() => refresh())
|
|
27
29
|
.catch(async (error) => {
|
|
28
|
-
logger.error('[refresh] refreshToken failed | error: %o', error);
|
|
30
|
+
this.logger.error('[refresh] refreshToken failed | error: %o', error);
|
|
29
31
|
try {
|
|
30
32
|
await onFailure();
|
|
31
33
|
}
|
|
32
34
|
catch (failure) {
|
|
33
|
-
logger.error('[refresh] onAuthFailure failed | error: %o', failure);
|
|
35
|
+
this.logger.error('[refresh] onAuthFailure failed | error: %o', failure);
|
|
34
36
|
}
|
|
35
37
|
return false;
|
|
36
38
|
})
|
package/dist/utilities/file.d.ts
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
/** Helpers over `Blob` and file data. */
|
|
2
2
|
export declare class FileUtility {
|
|
3
|
+
/** How long a saved file's object URL lives, in milliseconds: a browser that starts the download later (Safari) still finds it. */
|
|
4
|
+
static readonly REVOKE_DELAY_MS = 30000;
|
|
3
5
|
/** The blob as a `data:` URL. */
|
|
4
6
|
static toDataUrl(opts: {
|
|
5
7
|
blob: Blob;
|
|
6
8
|
}): Promise<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Saves `blob` as a file: the browser downloads it under `filename`, or `download` when none is given. Browser
|
|
11
|
+
* only; it throws without a `document`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const { data, filename } = await NetworkResponseReader.read<Blob>({ response, type });
|
|
16
|
+
* FileUtility.save({ blob: data, filename });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
static save(opts: {
|
|
20
|
+
blob: Blob;
|
|
21
|
+
filename?: string;
|
|
22
|
+
}): void;
|
|
7
23
|
}
|
|
8
24
|
//# sourceMappingURL=file.d.ts.map
|
package/dist/utilities/file.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { getError } from '@venizia/ignis-inversion';
|
|
1
2
|
/** Helpers over `Blob` and file data. */
|
|
2
3
|
export class FileUtility {
|
|
4
|
+
/** How long a saved file's object URL lives, in milliseconds: a browser that starts the download later (Safari) still finds it. */
|
|
5
|
+
static { this.REVOKE_DELAY_MS = 30_000; }
|
|
3
6
|
/** The blob as a `data:` URL. */
|
|
4
7
|
static toDataUrl(opts) {
|
|
5
8
|
// `new Promise`, not `Promise.withResolvers` (ES2024, Chrome 119): a WebView on an older Chrome lacks it.
|
|
@@ -10,5 +13,32 @@ export class FileUtility {
|
|
|
10
13
|
reader.readAsDataURL(opts.blob);
|
|
11
14
|
});
|
|
12
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Saves `blob` as a file: the browser downloads it under `filename`, or `download` when none is given. Browser
|
|
18
|
+
* only; it throws without a `document`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const { data, filename } = await NetworkResponseReader.read<Blob>({ response, type });
|
|
23
|
+
* FileUtility.save({ blob: data, filename });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
static save(opts) {
|
|
27
|
+
if (typeof document === 'undefined') {
|
|
28
|
+
throw getError({
|
|
29
|
+
message: '[FileUtility.save] There is no document to save a file from | Call it in a browser',
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const url = URL.createObjectURL(opts.blob);
|
|
33
|
+
const anchor = document.createElement('a');
|
|
34
|
+
anchor.href = url;
|
|
35
|
+
anchor.download = opts.filename || 'download';
|
|
36
|
+
// Attached while it is clicked: Firefox ignores the click of a detached anchor.
|
|
37
|
+
document.body.append(anchor);
|
|
38
|
+
anchor.click();
|
|
39
|
+
anchor.remove();
|
|
40
|
+
// Revoked well after the click: Safari can lose the download when the URL is revoked at once.
|
|
41
|
+
setTimeout(() => URL.revokeObjectURL(url), FileUtility.REVOKE_DELAY_MS);
|
|
42
|
+
}
|
|
13
43
|
}
|
|
14
44
|
//# sourceMappingURL=file.js.map
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export * from './browser.js';
|
|
2
2
|
export * from './browser-clipboard.js';
|
|
3
|
+
export * from './auth-token-store.js';
|
|
3
4
|
export * from './browser-storage.js';
|
|
4
5
|
export * from './file.js';
|
|
6
|
+
export * from './network-response-reader.js';
|
|
7
|
+
export * from './request-body-encoder.js';
|
|
5
8
|
export * from './runtime-config.js';
|
|
6
9
|
export * from './storage-codecs.js';
|
|
7
10
|
export * from './value.js';
|
package/dist/utilities/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export * from './browser.js';
|
|
2
2
|
export * from './browser-clipboard.js';
|
|
3
|
+
export * from './auth-token-store.js';
|
|
3
4
|
export * from './browser-storage.js';
|
|
4
5
|
export * from './file.js';
|
|
6
|
+
export * from './network-response-reader.js';
|
|
7
|
+
export * from './request-body-encoder.js';
|
|
5
8
|
export * from './runtime-config.js';
|
|
6
9
|
export * from './storage-codecs.js';
|
|
7
10
|
export * from './value.js';
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { type INetworkResponse, RequestCountData, type TConstValue, type TRequestType } from '
|
|
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
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
|
+
/** Content types read as text. */
|
|
7
|
+
private static readonly TEXTUAL_RE;
|
|
6
8
|
/** A response as `INetworkResponse`: JSON read by the request type, a file as a `Blob`. */
|
|
7
9
|
static read<TResult = unknown>(opts: {
|
|
8
10
|
response: Response;
|
|
@@ -33,14 +35,6 @@ export declare class NetworkResponseReader {
|
|
|
33
35
|
};
|
|
34
36
|
/** The rows of a list answer: an array as it is, no body at all (an empty answer) as no row, any other value as the one row. */
|
|
35
37
|
private static toRows;
|
|
36
|
-
/**
|
|
37
|
-
* A failed response as an `ApplicationError`, mapped like IGNIS `HttpDataSource`: the HTTP status,
|
|
38
|
-
* the server's code and args, its `extra` with the `requestId` added, and `details.cause`.
|
|
39
|
-
* `message` is the server's text, not a log line, because react-admin shows it to the user.
|
|
40
|
-
*/
|
|
41
|
-
static toError(opts: {
|
|
42
|
-
response: Response;
|
|
43
|
-
}): Promise<import("@venizia/ignis-inversion").ApplicationError>;
|
|
44
38
|
/** The total from `Content-Range`, or the page's own row count when the header is absent or malformed. */
|
|
45
39
|
private static resolveTotal;
|
|
46
40
|
/**
|
|
@@ -51,7 +45,5 @@ export declare class NetworkResponseReader {
|
|
|
51
45
|
static readFilename(opts: {
|
|
52
46
|
headers?: Pick<Headers, 'get'>;
|
|
53
47
|
}): string | undefined;
|
|
54
|
-
/** The file name a `Content-Disposition` header names, `filename*` before `filename`. */
|
|
55
|
-
private static parseFilename;
|
|
56
48
|
}
|
|
57
49
|
//# sourceMappingURL=network-response-reader.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { ContentDispositionTypes, HTTP } from '@venizia/ignis-helpers/common';
|
|
1
2
|
import { getError } from '@venizia/ignis-inversion';
|
|
2
3
|
import { HttpResponseReader } from '@venizia/ignis-helpers/core';
|
|
3
|
-
import {
|
|
4
|
+
import { RequestCountData, RequestTypes, } from '../common/index.js';
|
|
4
5
|
/** A list body that carries its rows and its total: `{ data, count }`. Null and primitives are not one. */
|
|
5
6
|
const isCountedBody = (value) => {
|
|
6
7
|
return typeof value === 'object' && value !== null && 'data' in value && 'count' in value;
|
|
@@ -9,19 +10,23 @@ const isCountedBody = (value) => {
|
|
|
9
10
|
export class NetworkResponseReader {
|
|
10
11
|
/** The server wraps an error body under this key; both transports unwrap it. */
|
|
11
12
|
static { this.ERROR_ROOT_KEY = 'error'; }
|
|
13
|
+
/** Content types read as text. */
|
|
14
|
+
static { this.TEXTUAL_RE = /^(application\/(json|.*\+json|xml|.*\+xml|x-www-form-urlencoded|javascript|graphql)|text\/)/i; }
|
|
12
15
|
/** A response as `INetworkResponse`: JSON read by the request type, a file as a `Blob`. */
|
|
13
16
|
static async read(opts) {
|
|
14
17
|
const { response, type, requestCountData } = opts;
|
|
15
18
|
if (response.status === 204) {
|
|
16
19
|
return { data: {} };
|
|
17
20
|
}
|
|
18
|
-
const contentType = (response.headers?.get(
|
|
19
|
-
const contentDisposition = response.headers?.get(
|
|
20
|
-
const
|
|
21
|
-
|
|
21
|
+
const contentType = (response.headers?.get(HTTP.Headers.CONTENT_TYPE) ?? '').toLowerCase();
|
|
22
|
+
const contentDisposition = response.headers?.get(HTTP.Headers.CONTENT_DISPOSITION) ?? '';
|
|
23
|
+
const { type: dispositionType } = HttpResponseReader.parseContentDisposition({
|
|
24
|
+
header: contentDisposition,
|
|
25
|
+
});
|
|
26
|
+
const isAttachment = dispositionType?.toLowerCase() === ContentDispositionTypes.ATTACHMENT;
|
|
27
|
+
const isTextual = contentType !== '' && NetworkResponseReader.TEXTUAL_RE.test(contentType);
|
|
22
28
|
if (isAttachment || !isTextual) {
|
|
23
|
-
const blob = await
|
|
24
|
-
const filename = NetworkResponseReader.parseFilename({ header: contentDisposition });
|
|
29
|
+
const { blob, filename } = await HttpResponseReader.readFile({ response });
|
|
25
30
|
return {
|
|
26
31
|
data: blob,
|
|
27
32
|
...(filename ? { filename } : {}),
|
|
@@ -90,7 +95,7 @@ export class NetworkResponseReader {
|
|
|
90
95
|
return data;
|
|
91
96
|
}
|
|
92
97
|
// A missing or non-numeric header means the server sent no count - never NaN.
|
|
93
|
-
const count = Number.parseInt(headers?.get(
|
|
98
|
+
const count = Number.parseInt(headers?.get(HTTP.Headers.RESPONSE_COUNT_DATA) ?? '', 10);
|
|
94
99
|
return {
|
|
95
100
|
data: data,
|
|
96
101
|
count: Number.isNaN(count) ? undefined : count,
|
|
@@ -106,21 +111,10 @@ export class NetworkResponseReader {
|
|
|
106
111
|
}
|
|
107
112
|
return data === null || data === undefined ? [] : [data];
|
|
108
113
|
}
|
|
109
|
-
/**
|
|
110
|
-
* A failed response as an `ApplicationError`, mapped like IGNIS `HttpDataSource`: the HTTP status,
|
|
111
|
-
* the server's code and args, its `extra` with the `requestId` added, and `details.cause`.
|
|
112
|
-
* `message` is the server's text, not a log line, because react-admin shows it to the user.
|
|
113
|
-
*/
|
|
114
|
-
static toError(opts) {
|
|
115
|
-
return HttpResponseReader.toApplicationError({
|
|
116
|
-
response: opts.response,
|
|
117
|
-
rootKey: NetworkResponseReader.ERROR_ROOT_KEY,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
114
|
/** The total from `Content-Range`, or the page's own row count when the header is absent or malformed. */
|
|
121
115
|
static resolveTotal(opts) {
|
|
122
116
|
const range = HttpResponseReader.parseContentRange({
|
|
123
|
-
header: opts.headers?.get(
|
|
117
|
+
header: opts.headers?.get(HTTP.Headers.CONTENT_RANGE),
|
|
124
118
|
});
|
|
125
119
|
return range?.total ?? opts.rowCount;
|
|
126
120
|
}
|
|
@@ -130,33 +124,9 @@ export class NetworkResponseReader {
|
|
|
130
124
|
* as `filename`.
|
|
131
125
|
*/
|
|
132
126
|
static readFilename(opts) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
/** The file name a `Content-Disposition` header names, `filename*` before `filename`. */
|
|
137
|
-
static parseFilename(opts) {
|
|
138
|
-
const { header } = opts;
|
|
139
|
-
if (!header) {
|
|
140
|
-
return undefined;
|
|
141
|
-
}
|
|
142
|
-
const encodedMatch = header.match(/filename\*\s*=\s*([^']*)'[^']*'([^;]+)/i);
|
|
143
|
-
if (encodedMatch) {
|
|
144
|
-
try {
|
|
145
|
-
return decodeURIComponent(encodedMatch[2].trim());
|
|
146
|
-
}
|
|
147
|
-
catch {
|
|
148
|
-
return encodedMatch[2].trim();
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
const quotedMatch = header.match(/filename\s*=\s*"([^"]+)"/i);
|
|
152
|
-
if (quotedMatch) {
|
|
153
|
-
return quotedMatch[1];
|
|
154
|
-
}
|
|
155
|
-
const bareMatch = header.match(/filename\s*=\s*([^;]+)/i);
|
|
156
|
-
if (bareMatch) {
|
|
157
|
-
return bareMatch[1].trim();
|
|
158
|
-
}
|
|
159
|
-
return undefined;
|
|
127
|
+
return HttpResponseReader.parseContentDisposition({
|
|
128
|
+
header: opts.headers?.get(HTTP.Headers.CONTENT_DISPOSITION),
|
|
129
|
+
}).filename;
|
|
160
130
|
}
|
|
161
131
|
}
|
|
162
132
|
//# sourceMappingURL=network-response-reader.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getError } from '@venizia/ignis-inversion';
|
|
2
|
-
import { RequestBodyTypes } from '
|
|
3
|
-
import { ValueUtility } from '
|
|
2
|
+
import { RequestBodyTypes } from '../common/index.js';
|
|
3
|
+
import { ValueUtility } from './value.js';
|
|
4
4
|
/** Turns a request body into what `fetch` sends, by `RequestBodyTypes`. */
|
|
5
5
|
export class RequestBodyEncoder {
|
|
6
6
|
static encode(opts) {
|
|
@@ -8,13 +8,5 @@ export declare class ValueUtility {
|
|
|
8
8
|
static isNumber(opts: {
|
|
9
9
|
value: unknown;
|
|
10
10
|
}): boolean;
|
|
11
|
-
/** A non-null object that is not an array. */
|
|
12
|
-
static isObject(opts: {
|
|
13
|
-
value: unknown;
|
|
14
|
-
}): boolean;
|
|
15
|
-
/** Whether `new Date(value)` is a valid date; takes a string, a number or a `Date`. */
|
|
16
|
-
static isValidDate(opts: {
|
|
17
|
-
value: string | number | Date;
|
|
18
|
-
}): boolean;
|
|
19
11
|
}
|
|
20
12
|
//# sourceMappingURL=value.d.ts.map
|
package/dist/utilities/value.js
CHANGED
|
@@ -16,15 +16,5 @@ export class ValueUtility {
|
|
|
16
16
|
}
|
|
17
17
|
return !Number.isNaN(Number.parseFloat(String(value))) && Number.isFinite(Number(value));
|
|
18
18
|
}
|
|
19
|
-
/** A non-null object that is not an array. */
|
|
20
|
-
static isObject(opts) {
|
|
21
|
-
const { value } = opts;
|
|
22
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
23
|
-
}
|
|
24
|
-
/** Whether `new Date(value)` is a valid date; takes a string, a number or a `Date`. */
|
|
25
|
-
static isValidDate(opts) {
|
|
26
|
-
const date = new Date(opts.value);
|
|
27
|
-
return !Number.isNaN(date.valueOf());
|
|
28
|
-
}
|
|
29
19
|
}
|
|
30
20
|
//# sourceMappingURL=value.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venizia/ardor-kernel",
|
|
3
|
-
"version": "0.5.0-
|
|
3
|
+
"version": "0.5.0-5",
|
|
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.5",
|
|
75
|
-
"@venizia/dev-configs": "^0.5.0-
|
|
76
|
-
"@venizia/ignis-connectors": "^0.5.0-
|
|
77
|
-
"@venizia/ignis-filter": "^0.5.0-
|
|
78
|
-
"@venizia/ignis-helpers": "^0.5.0-
|
|
79
|
-
"@venizia/ignis-inversion": "^0.5.0-
|
|
80
|
-
"@venizia/ignis-kernel": "^0.5.0-
|
|
75
|
+
"@venizia/dev-configs": "^0.5.0-5",
|
|
76
|
+
"@venizia/ignis-connectors": "^0.5.0-4",
|
|
77
|
+
"@venizia/ignis-filter": "^0.5.0-1",
|
|
78
|
+
"@venizia/ignis-helpers": "^0.5.0-2",
|
|
79
|
+
"@venizia/ignis-inversion": "^0.5.0-1",
|
|
80
|
+
"@venizia/ignis-kernel": "^0.5.0-3",
|
|
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.5.0-
|
|
91
|
-
"@venizia/ignis-filter": "^0.5.0-
|
|
92
|
-
"@venizia/ignis-helpers": "^0.5.0-
|
|
93
|
-
"@venizia/ignis-inversion": "^0.5.0-
|
|
94
|
-
"@venizia/ignis-kernel": "^0.5.0-
|
|
90
|
+
"@venizia/ignis-connectors": "^0.5.0-4",
|
|
91
|
+
"@venizia/ignis-filter": "^0.5.0-1",
|
|
92
|
+
"@venizia/ignis-helpers": "^0.5.0-2",
|
|
93
|
+
"@venizia/ignis-inversion": "^0.5.0-1",
|
|
94
|
+
"@venizia/ignis-kernel": "^0.5.0-3",
|
|
95
95
|
"reflect-metadata": ">=0.2.2"
|
|
96
96
|
},
|
|
97
97
|
"peerDependenciesMeta": {
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/** The one reading of `HeadersInit` the network layer uses. */
|
|
2
|
-
export declare class NetworkHeaders {
|
|
3
|
-
/**
|
|
4
|
-
* `HeadersInit` (or a record with number values) as a plain record, keys lowercased: header names
|
|
5
|
-
* are case-insensitive but object keys are not, and two spellings of one name would reach the wire
|
|
6
|
-
* joined as `"1, 0"`.
|
|
7
|
-
*/
|
|
8
|
-
static toRecord(opts: {
|
|
9
|
-
headers?: HeadersInit | Record<string, string | number>;
|
|
10
|
-
}): Record<string, string>;
|
|
11
|
-
/** Merge header sources so a later source REPLACES an earlier one, whatever case either used. */
|
|
12
|
-
static merge(opts: {
|
|
13
|
-
sources: Array<HeadersInit | Record<string, string | number> | undefined>;
|
|
14
|
-
}): Record<string, string>;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=headers.d.ts.map
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/** The one reading of `HeadersInit` the network layer uses. */
|
|
2
|
-
export class NetworkHeaders {
|
|
3
|
-
/**
|
|
4
|
-
* `HeadersInit` (or a record with number values) as a plain record, keys lowercased: header names
|
|
5
|
-
* are case-insensitive but object keys are not, and two spellings of one name would reach the wire
|
|
6
|
-
* joined as `"1, 0"`.
|
|
7
|
-
*/
|
|
8
|
-
static toRecord(opts) {
|
|
9
|
-
const { headers } = opts;
|
|
10
|
-
if (!headers) {
|
|
11
|
-
return {};
|
|
12
|
-
}
|
|
13
|
-
const entries = (() => {
|
|
14
|
-
if (headers instanceof Headers) {
|
|
15
|
-
return [...headers.entries()];
|
|
16
|
-
}
|
|
17
|
-
return Array.isArray(headers) ? headers : Object.entries(headers);
|
|
18
|
-
})();
|
|
19
|
-
const rs = {};
|
|
20
|
-
for (const [key, value] of entries) {
|
|
21
|
-
rs[key.toLowerCase()] = String(value);
|
|
22
|
-
}
|
|
23
|
-
return rs;
|
|
24
|
-
}
|
|
25
|
-
/** Merge header sources so a later source REPLACES an earlier one, whatever case either used. */
|
|
26
|
-
static merge(opts) {
|
|
27
|
-
return opts.sources.reduce((acc, headers) => {
|
|
28
|
-
return Object.assign(acc, NetworkHeaders.toRecord({ headers }));
|
|
29
|
-
}, {});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=headers.js.map
|
|
File without changes
|
|
File without changes
|