@venizia/ardor-kernel 0.5.0-1 → 0.5.0-10
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/applications/abstract.d.ts +5 -3
- package/dist/base/applications/abstract.js +44 -35
- 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 +9 -78
- package/dist/common/constants.js +9 -123
- package/dist/common/types.d.ts +2 -0
- 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 +18 -67
- 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 +13 -13
- 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/dist/common/constants.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ConstClass } from '@venizia/ignis-helpers/common';
|
|
1
2
|
/** Values of the running environment, read once when the module loads. */
|
|
2
3
|
export class App {
|
|
3
4
|
/** The IANA name of the timezone of the runtime. */
|
|
@@ -6,29 +7,11 @@ export class App {
|
|
|
6
7
|
static { this.TIMEZONE_OFFSET = -(new Date().getTimezoneOffset() / 60); }
|
|
7
8
|
/** In milliseconds. */
|
|
8
9
|
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
|
-
}
|
|
10
|
+
/** The authorization scheme of a token that names none. */
|
|
11
|
+
static { this.TOKEN_TYPE = 'Bearer'; }
|
|
29
12
|
}
|
|
30
13
|
/** HTTP methods. */
|
|
31
|
-
export class RequestMethods {
|
|
14
|
+
export class RequestMethods extends ConstClass {
|
|
32
15
|
static { this.HEAD = 'HEAD'; }
|
|
33
16
|
static { this.OPTIONS = 'OPTIONS'; }
|
|
34
17
|
static { this.GET = 'GET'; }
|
|
@@ -36,23 +19,9 @@ export class RequestMethods {
|
|
|
36
19
|
static { this.PUT = 'PUT'; }
|
|
37
20
|
static { this.PATCH = 'PATCH'; }
|
|
38
21
|
static { this.DELETE = 'DELETE'; }
|
|
39
|
-
/** Every value of this class that `isValid` accepts. */
|
|
40
|
-
static { this.SCHEME_SET = new Set([
|
|
41
|
-
this.HEAD,
|
|
42
|
-
this.OPTIONS,
|
|
43
|
-
this.GET,
|
|
44
|
-
this.POST,
|
|
45
|
-
this.PUT,
|
|
46
|
-
this.PATCH,
|
|
47
|
-
this.DELETE,
|
|
48
|
-
]); }
|
|
49
|
-
/** Whether `value` is in `SCHEME_SET`. */
|
|
50
|
-
static isValid(value) {
|
|
51
|
-
return this.SCHEME_SET.has(value);
|
|
52
|
-
}
|
|
53
22
|
}
|
|
54
23
|
/** What a request is for, which decides how its response is read: `SEND`, and react-admin's data provider calls. */
|
|
55
|
-
export class RequestTypes {
|
|
24
|
+
export class RequestTypes extends ConstClass {
|
|
56
25
|
/** A request that is not a react-admin call. */
|
|
57
26
|
static { this.SEND = 'SEND'; }
|
|
58
27
|
// react-admin
|
|
@@ -65,23 +34,6 @@ export class RequestTypes {
|
|
|
65
34
|
static { this.UPDATE_MANY = 'UPDATE_MANY'; }
|
|
66
35
|
static { this.DELETE = 'DELETE'; }
|
|
67
36
|
static { this.DELETE_MANY = 'DELETE_MANY'; }
|
|
68
|
-
/** Every value of this class that `isValid` accepts. */
|
|
69
|
-
static { this.SCHEME_SET = new Set([
|
|
70
|
-
this.SEND,
|
|
71
|
-
this.GET_ONE,
|
|
72
|
-
this.GET_LIST,
|
|
73
|
-
this.GET_MANY,
|
|
74
|
-
this.GET_MANY_REFERENCE,
|
|
75
|
-
this.CREATE,
|
|
76
|
-
this.UPDATE,
|
|
77
|
-
this.UPDATE_MANY,
|
|
78
|
-
this.DELETE,
|
|
79
|
-
this.DELETE_MANY,
|
|
80
|
-
]); }
|
|
81
|
-
/** Whether `value` is in `SCHEME_SET`. */
|
|
82
|
-
static isValid(value) {
|
|
83
|
-
return this.SCHEME_SET.has(value);
|
|
84
|
-
}
|
|
85
37
|
}
|
|
86
38
|
/** The Web Storage areas `BrowserStorage` reads and writes. */
|
|
87
39
|
export class StorageAreas {
|
|
@@ -91,86 +43,26 @@ export class StorageAreas {
|
|
|
91
43
|
static { this.SESSION = 'session'; }
|
|
92
44
|
}
|
|
93
45
|
/** How a request body is encoded; see `RequestBodyEncoder`. */
|
|
94
|
-
export class RequestBodyTypes {
|
|
46
|
+
export class RequestBodyTypes extends ConstClass {
|
|
95
47
|
/** The body goes through as it is. */
|
|
96
48
|
static { this.NONE = 'none'; }
|
|
97
49
|
static { this.FORM_DATA = 'form-data'; }
|
|
98
50
|
static { this.FORM_URL_ENCODED = 'x-www-form-urlencoded'; }
|
|
99
51
|
static { this.JSON = 'json'; }
|
|
100
52
|
static { this.BINARY = 'binary'; }
|
|
101
|
-
/** Every value of this class that `isValid` accepts. */
|
|
102
|
-
static { this.SCHEME_SET = new Set([
|
|
103
|
-
this.NONE,
|
|
104
|
-
this.FORM_DATA,
|
|
105
|
-
this.FORM_URL_ENCODED,
|
|
106
|
-
this.JSON,
|
|
107
|
-
this.BINARY,
|
|
108
|
-
]); }
|
|
109
|
-
/** Whether `value` is in `SCHEME_SET`. */
|
|
110
|
-
static isValid(value) {
|
|
111
|
-
return this.SCHEME_SET.has(value);
|
|
112
|
-
}
|
|
113
53
|
}
|
|
114
54
|
/** Names of the build environments. */
|
|
115
|
-
export class Environments {
|
|
55
|
+
export class Environments extends ConstClass {
|
|
116
56
|
static { this.DEVELOPMENT = 'development'; }
|
|
117
57
|
static { this.PRODUCTION = 'production'; }
|
|
118
|
-
/** Every value of this class that `isValid` accepts. */
|
|
119
|
-
static { this.SCHEME_SET = new Set([this.DEVELOPMENT, this.PRODUCTION]); }
|
|
120
|
-
/** Whether `value` is in `SCHEME_SET`. */
|
|
121
|
-
static isValid(value) {
|
|
122
|
-
return this.SCHEME_SET.has(value);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
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
58
|
}
|
|
161
59
|
/** The channels a request says it comes from, sent in `x-request-channel`. */
|
|
162
|
-
export class RequestChannel {
|
|
60
|
+
export class RequestChannel extends ConstClass {
|
|
163
61
|
/** A browser application; what a request says unless `requestTracingChannel` is set. */
|
|
164
62
|
static { this.WEB = '100_WEB'; }
|
|
165
|
-
/** Every value of this class that `isValid` accepts. */
|
|
166
|
-
static { this.SCHEME_SET = new Set([this.WEB]); }
|
|
167
|
-
/** Whether `value` is in `SCHEME_SET`. */
|
|
168
|
-
static isValid(value) {
|
|
169
|
-
return this.SCHEME_SET.has(value);
|
|
170
|
-
}
|
|
171
63
|
}
|
|
172
64
|
/** Whether a response carries a count, sent in `x-request-count`. */
|
|
173
|
-
export class RequestCountData {
|
|
65
|
+
export class RequestCountData extends ConstClass {
|
|
174
66
|
/**
|
|
175
67
|
* @description Only the data is returned in the response body
|
|
176
68
|
*/
|
|
@@ -179,11 +71,5 @@ export class RequestCountData {
|
|
|
179
71
|
* @description Both data and count are returned in the response body
|
|
180
72
|
*/
|
|
181
73
|
static { this.DATA_WITH_COUNT = '1'; }
|
|
182
|
-
/** Every value of this class that `isValid` accepts. */
|
|
183
|
-
static { this.SCHEME_SET = new Set([this.DATA_ONLY, this.DATA_WITH_COUNT]); }
|
|
184
|
-
/** Whether `value` is in `SCHEME_SET`. */
|
|
185
|
-
static isValid(value) {
|
|
186
|
-
return this.SCHEME_SET.has(value);
|
|
187
|
-
}
|
|
188
74
|
}
|
|
189
75
|
//# sourceMappingURL=constants.js.map
|
package/dist/common/types.d.ts
CHANGED
|
@@ -281,6 +281,8 @@ export interface IArtifactIndex {
|
|
|
281
281
|
repositories?: ReadonlyArray<TClass<unknown>>;
|
|
282
282
|
services?: ReadonlyArray<TClass<unknown>>;
|
|
283
283
|
controllers?: ReadonlyArray<TClass<unknown>>;
|
|
284
|
+
/** The classes of the types the application declared with `ArtifactTypes.define`, by type name. */
|
|
285
|
+
custom?: Readonly<Record<string, ReadonlyArray<TClass<unknown>>>>;
|
|
284
286
|
}
|
|
285
287
|
/**
|
|
286
288
|
* Answers whether the current actor may act on a resource. Bound by the application under
|
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
|
-
import { HttpResponseReader } from '@venizia/ignis-
|
|
3
|
-
import {
|
|
3
|
+
import { HttpResponseReader } from '@venizia/ignis-helpers/core';
|
|
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,40 +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 async toError(opts) {
|
|
115
|
-
const { response } = opts;
|
|
116
|
-
const server = await HttpResponseReader.readError({
|
|
117
|
-
response,
|
|
118
|
-
rootKey: NetworkResponseReader.ERROR_ROOT_KEY,
|
|
119
|
-
});
|
|
120
|
-
// A relaying server's `extra.requestId` names the request it made upstream; keep it, nearest first.
|
|
121
|
-
const extra = { ...server.extra };
|
|
122
|
-
if (server.requestId) {
|
|
123
|
-
const upstreamRequestId = extra.requestId;
|
|
124
|
-
extra.requestId = server.requestId;
|
|
125
|
-
if (upstreamRequestId !== undefined && upstreamRequestId !== server.requestId) {
|
|
126
|
-
const known = Array.isArray(extra.upstreamRequestIds) ? extra.upstreamRequestIds : [];
|
|
127
|
-
extra.upstreamRequestIds = [upstreamRequestId, ...known];
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return getError({
|
|
131
|
-
statusCode: response.status,
|
|
132
|
-
message: server.normalized?.text ?? server.message ?? `HTTP ${response.status}`,
|
|
133
|
-
messageCode: server.normalized?.code,
|
|
134
|
-
messageArgs: server.normalized?.args,
|
|
135
|
-
extra: Object.keys(extra).length > 0 ? extra : undefined,
|
|
136
|
-
cause: server.details?.cause,
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
114
|
/** The total from `Content-Range`, or the page's own row count when the header is absent or malformed. */
|
|
140
115
|
static resolveTotal(opts) {
|
|
141
116
|
const range = HttpResponseReader.parseContentRange({
|
|
142
|
-
header: opts.headers?.get(
|
|
117
|
+
header: opts.headers?.get(HTTP.Headers.CONTENT_RANGE),
|
|
143
118
|
});
|
|
144
119
|
return range?.total ?? opts.rowCount;
|
|
145
120
|
}
|
|
@@ -149,33 +124,9 @@ export class NetworkResponseReader {
|
|
|
149
124
|
* as `filename`.
|
|
150
125
|
*/
|
|
151
126
|
static readFilename(opts) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
/** The file name a `Content-Disposition` header names, `filename*` before `filename`. */
|
|
156
|
-
static parseFilename(opts) {
|
|
157
|
-
const { header } = opts;
|
|
158
|
-
if (!header) {
|
|
159
|
-
return undefined;
|
|
160
|
-
}
|
|
161
|
-
const encodedMatch = header.match(/filename\*\s*=\s*([^']*)'[^']*'([^;]+)/i);
|
|
162
|
-
if (encodedMatch) {
|
|
163
|
-
try {
|
|
164
|
-
return decodeURIComponent(encodedMatch[2].trim());
|
|
165
|
-
}
|
|
166
|
-
catch {
|
|
167
|
-
return encodedMatch[2].trim();
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
const quotedMatch = header.match(/filename\s*=\s*"([^"]+)"/i);
|
|
171
|
-
if (quotedMatch) {
|
|
172
|
-
return quotedMatch[1];
|
|
173
|
-
}
|
|
174
|
-
const bareMatch = header.match(/filename\s*=\s*([^;]+)/i);
|
|
175
|
-
if (bareMatch) {
|
|
176
|
-
return bareMatch[1].trim();
|
|
177
|
-
}
|
|
178
|
-
return undefined;
|
|
127
|
+
return HttpResponseReader.parseContentDisposition({
|
|
128
|
+
header: opts.headers?.get(HTTP.Headers.CONTENT_DISPOSITION),
|
|
129
|
+
}).filename;
|
|
179
130
|
}
|
|
180
131
|
}
|
|
181
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-10",
|
|
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",
|
|
@@ -71,13 +71,13 @@
|
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@size-limit/preset-small-lib": "^14.2.0",
|
|
74
|
-
"@types/bun": "^1.4.
|
|
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-
|
|
74
|
+
"@types/bun": "^1.4.5",
|
|
75
|
+
"@venizia/dev-configs": "^0.5.0-6",
|
|
76
|
+
"@venizia/ignis-connectors": "^0.5.0-10",
|
|
77
|
+
"@venizia/ignis-filter": "^0.5.0-3",
|
|
78
|
+
"@venizia/ignis-helpers": "^0.5.0-8",
|
|
79
|
+
"@venizia/ignis-inversion": "^0.5.0-3",
|
|
80
|
+
"@venizia/ignis-kernel": "^0.5.0-9",
|
|
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-10",
|
|
91
|
+
"@venizia/ignis-filter": "^0.5.0-3",
|
|
92
|
+
"@venizia/ignis-helpers": "^0.5.0-8",
|
|
93
|
+
"@venizia/ignis-inversion": "^0.5.0-3",
|
|
94
|
+
"@venizia/ignis-kernel": "^0.5.0-9",
|
|
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
|