@venizia/ardor-kernel 0.5.0-11 → 0.5.0-13
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.d.ts +12 -24
- package/dist/base/applications/abstract.js +4 -6
- package/dist/base/decorators/api.d.ts +0 -3
- package/dist/base/decorators/api.js +0 -3
- package/dist/base/providers/base.d.ts +0 -3
- package/dist/base/providers/base.js +0 -3
- package/dist/base/providers/role-permission.d.ts +1 -8
- package/dist/base/providers/role-permission.js +0 -3
- package/dist/base/services/auth.d.ts +6 -12
- package/dist/base/services/auth.js +5 -8
- package/dist/base/services/base.d.ts +0 -3
- package/dist/base/services/base.js +0 -3
- package/dist/base/services/network-request-base.d.ts +133 -0
- package/dist/base/services/network-request-base.js +302 -0
- package/dist/base/services/network-request.d.ts +28 -131
- package/dist/base/services/network-request.js +13 -252
- package/dist/common/constants.d.ts +0 -23
- package/dist/common/constants.js +0 -23
- package/dist/common/keys.d.ts +17 -20
- package/dist/common/keys.js +5 -9
- package/dist/common/types.d.ts +45 -45
- package/dist/helpers/networks/auth-recovery.d.ts +0 -3
- package/dist/helpers/networks/auth-recovery.js +0 -3
- package/dist/{testing.d.ts → testing/index.d.ts} +2 -17
- package/dist/{testing.js → testing/index.js} +1 -16
- package/dist/utilities/auth-token-store.d.ts +2 -8
- package/dist/utilities/auth-token-store.js +1 -4
- package/dist/utilities/browser-clipboard.d.ts +1 -3
- package/dist/utilities/browser-clipboard.js +5 -5
- package/dist/utilities/browser-storage.d.ts +16 -10
- package/dist/utilities/browser-storage.js +36 -20
- package/dist/utilities/browser.d.ts +0 -3
- package/dist/utilities/browser.js +0 -3
- package/dist/utilities/file.d.ts +5 -5
- package/dist/utilities/file.js +5 -5
- package/dist/utilities/network-response-reader.d.ts +61 -17
- package/dist/utilities/network-response-reader.js +157 -22
- package/dist/utilities/request-body-encoder.d.ts +35 -15
- package/dist/utilities/request-body-encoder.js +67 -10
- package/dist/utilities/runtime-config.d.ts +8 -9
- package/dist/utilities/runtime-config.js +0 -9
- package/dist/utilities/storage-codecs.d.ts +0 -3
- package/dist/utilities/storage-codecs.js +0 -3
- package/dist/utilities/value.d.ts +0 -3
- package/dist/utilities/value.js +0 -3
- package/package.json +24 -24
package/dist/common/types.d.ts
CHANGED
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
import type { TConstValue, TNumberConstValue, TPrettify, TStringConstValue, ValueOf, ValueOptional, ValueOptionalExcept, ValueOrPromise } from '@venizia/ignis-helpers/common';
|
|
2
2
|
import type { TBuildInfoRecord } from '@venizia/ignis-helpers/core';
|
|
3
3
|
import type { TClass } from '@venizia/ignis-inversion';
|
|
4
|
+
import type * as Ignis from '@venizia/ignis-kernel';
|
|
4
5
|
import type { TExtraRequest } from '@venizia/ignis-kernel/repository';
|
|
5
6
|
import type { AbstractArdorApplication } from '../base/applications/abstract.js';
|
|
6
7
|
import type { Environments, RequestBodyTypes, RequestCountData, RequestMethods, RequestTypes, StorageAreas } from './constants.js';
|
|
7
|
-
/** A record id: a string or a number. */
|
|
8
|
-
export type IdType =
|
|
8
|
+
/** A record id: a string or a number. IGNIS's `IdType` without `bigint`, which `JSON.stringify` and react-admin refuse. */
|
|
9
|
+
export type IdType = Ignis.NumberIdType | Ignis.StringIdType;
|
|
9
10
|
export type { TConstValue, TNumberConstValue, TPrettify, TStringConstValue, ValueOf, ValueOptional, ValueOptionalExcept, ValueOrPromise, };
|
|
10
11
|
/** One of the `RequestMethods` values. */
|
|
11
12
|
export type TRequestMethod = TStringConstValue<typeof RequestMethods>;
|
|
12
13
|
/** One of the `Environments` values. */
|
|
13
14
|
export type TEnvironment = TStringConstValue<typeof Environments>;
|
|
15
|
+
/** A request body before it is encoded: what to send, and how. */
|
|
16
|
+
export interface IRequestPayload {
|
|
17
|
+
data: unknown;
|
|
18
|
+
/** How `data` is encoded; it goes through as JSON when absent. */
|
|
19
|
+
type?: TRequestBodyType;
|
|
20
|
+
}
|
|
14
21
|
/** What `IDataProvider.send` takes. */
|
|
15
22
|
export interface ISendParams {
|
|
16
23
|
/** Required: `send` throws without it. */
|
|
17
24
|
method?: TRequestMethod;
|
|
18
25
|
/** How the response is read. `RequestTypes.SEND` when absent. */
|
|
19
26
|
requestType?: TRequestType;
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
body?: unknown;
|
|
27
|
+
/** The body of the request. */
|
|
28
|
+
payload?: IRequestPayload;
|
|
23
29
|
/** Sent as the query string of the request. */
|
|
24
30
|
query?: Record<string, unknown>;
|
|
25
31
|
/** Added to the headers of this request. */
|
|
@@ -57,16 +63,15 @@ export interface IStorageCodec<TValue> {
|
|
|
57
63
|
export type TRequestType = TStringConstValue<typeof RequestTypes>;
|
|
58
64
|
/** What `DefaultNetworkRequestService.getRequestProps` takes. */
|
|
59
65
|
export interface IGetRequestPropsParams {
|
|
60
|
-
/** Decides whether the request goes without a token (`
|
|
66
|
+
/** Decides whether the request goes without a token (`noAuth`). */
|
|
61
67
|
resource: string;
|
|
62
68
|
/**
|
|
63
69
|
* Whether the response carries a count.
|
|
64
70
|
* @default RequestCountData.DATA_ONLY
|
|
65
71
|
*/
|
|
66
72
|
requestCountData?: TConstValue<typeof RequestCountData>;
|
|
67
|
-
body
|
|
68
|
-
|
|
69
|
-
bodyType?: TRequestBodyType;
|
|
73
|
+
/** The body of the request, encoded by `getRequestProps`. */
|
|
74
|
+
payload?: IRequestPayload;
|
|
70
75
|
/** Gives the request channel. */
|
|
71
76
|
restDataProviderOptions: IRestDataProviderOptions;
|
|
72
77
|
/** Gives the name the tracing id starts with. */
|
|
@@ -91,7 +96,7 @@ export interface ICustomParams {
|
|
|
91
96
|
* The identity `saveAuth` stores and `getUser` reads back: every field is absent when nothing is
|
|
92
97
|
* stored. It has no index signature, so an interface of your own that has these fields fits it.
|
|
93
98
|
*/
|
|
94
|
-
export interface
|
|
99
|
+
export interface IStoredAuthUser {
|
|
95
100
|
userId?: IdType;
|
|
96
101
|
username?: string;
|
|
97
102
|
referenceId?: IdType;
|
|
@@ -99,11 +104,8 @@ export interface IAuthUser {
|
|
|
99
104
|
}
|
|
100
105
|
/** What `login` read from the sign-in response. `roles` are names. */
|
|
101
106
|
export interface ISignInSession {
|
|
102
|
-
userId:
|
|
103
|
-
token:
|
|
104
|
-
value: string;
|
|
105
|
-
type: string;
|
|
106
|
-
};
|
|
107
|
+
userId: IdType;
|
|
108
|
+
token: Required<Pick<IAuthTokenRecord, 'value' | 'type'>>;
|
|
107
109
|
roles: Array<string>;
|
|
108
110
|
}
|
|
109
111
|
/**
|
|
@@ -140,7 +142,7 @@ export type TAuthProviderOptions = {
|
|
|
140
142
|
/** How a request recovers from a 401. */
|
|
141
143
|
export interface IAuthRecoveryOptions {
|
|
142
144
|
/**
|
|
143
|
-
* A request to this path never starts a refresh: it is the refresh. Listing it in `
|
|
145
|
+
* A request to this path never starts a refresh: it is the refresh. Listing it in `noAuth.paths`
|
|
144
146
|
* as well keeps the expired token off that request.
|
|
145
147
|
* @example
|
|
146
148
|
* ```ts
|
|
@@ -154,7 +156,7 @@ export interface IAuthRecoveryOptions {
|
|
|
154
156
|
* url: 'https://api.example.com',
|
|
155
157
|
* // The refresh path is also a no-auth path: the expired token stays off that request, so the
|
|
156
158
|
* // server identifies the session another way, such as a cookie.
|
|
157
|
-
*
|
|
159
|
+
* noAuth: { paths: ['/auth/sign-in', '/auth/refresh'] },
|
|
158
160
|
* authRecovery: { refreshTokenPath: '/auth/refresh' },
|
|
159
161
|
* };
|
|
160
162
|
* }
|
|
@@ -166,24 +168,26 @@ export interface IAuthRecoveryOptions {
|
|
|
166
168
|
/** One pattern or a list; a string is compiled with `new RegExp(...)`. */
|
|
167
169
|
export type TNoAuthPathRegex = string | RegExp | Array<string | RegExp>;
|
|
168
170
|
/**
|
|
169
|
-
* Data only. A request that matches goes without an `Authorization` header; to
|
|
170
|
-
* API with no sign-in) set `
|
|
171
|
+
* Data only: the `noAuth` options. A request that matches goes without an `Authorization` header; to
|
|
172
|
+
* send none at all (an API with no sign-in) set `noAuth: { regex: /./ }`.
|
|
171
173
|
*/
|
|
172
174
|
export interface INoAuthOptions {
|
|
173
175
|
/**
|
|
174
176
|
* Exact resource paths which will be requested without authorization header.
|
|
175
177
|
*/
|
|
176
|
-
|
|
178
|
+
paths?: Array<string>;
|
|
177
179
|
/**
|
|
178
180
|
* Pattern(s) of resource paths which will be requested without authorization header.
|
|
179
181
|
* Accept `RegExp` or `string` (which will be compiled with `new RegExp(...)`).
|
|
180
182
|
*/
|
|
181
|
-
|
|
183
|
+
regex?: TNoAuthPathRegex;
|
|
182
184
|
}
|
|
183
185
|
/** Data only: where and how the REST data provider sends. */
|
|
184
|
-
export interface IRestDataProviderOptions
|
|
186
|
+
export interface IRestDataProviderOptions {
|
|
185
187
|
/** The base URL requests are sent to. */
|
|
186
188
|
url: string;
|
|
189
|
+
/** Which requests go without a token. Absent: every request carries the stored one. */
|
|
190
|
+
noAuth?: INoAuthOptions;
|
|
187
191
|
/**
|
|
188
192
|
* Sent in `x-request-channel`.
|
|
189
193
|
* @default RequestChannel.WEB
|
|
@@ -228,6 +232,14 @@ export interface IDataSourceAuth {
|
|
|
228
232
|
onUnauthorized: (context: IDataSourceRequestContext, info: IDataSourceUnauthorizedInfo) => Promise<boolean>;
|
|
229
233
|
errorRootKey: string;
|
|
230
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* A schema that checks the data of a response: `parse` answers the checked value and throws what it
|
|
237
|
+
* refuses. A zod schema is one. Whatever `parse` throws is read as a refusal, a bug inside it
|
|
238
|
+
* included.
|
|
239
|
+
*/
|
|
240
|
+
export interface IResponseSchema<TResult = unknown> {
|
|
241
|
+
parse(data: unknown): TResult;
|
|
242
|
+
}
|
|
231
243
|
/** What `DefaultNetworkRequestService.doRequest` answers. */
|
|
232
244
|
export interface INetworkResponse<TResult = unknown> {
|
|
233
245
|
/** The response body, or its rows for a list. */
|
|
@@ -261,7 +273,7 @@ export interface IFeatureBase {
|
|
|
261
273
|
* `start()` checks each was discovered.
|
|
262
274
|
* @default {}
|
|
263
275
|
*/
|
|
264
|
-
artifacts?:
|
|
276
|
+
artifacts?: IArdorArtifactIndex;
|
|
265
277
|
/**
|
|
266
278
|
* The permission names the feature's pages use, in the application's vocabulary: metadata for a
|
|
267
279
|
* role editor to list. Descriptive only, it enforces nothing; `access` on a route or a menu entry
|
|
@@ -273,16 +285,11 @@ export interface IFeatureBase {
|
|
|
273
285
|
* The index `ignis-artifacts generate` (from `@venizia/ignis-boot`) emits: every stereotyped class,
|
|
274
286
|
* by value, per kind. Referencing them keeps a bundler from dropping a module nothing else imports,
|
|
275
287
|
* and `start()` checks each was discovered. `controllers` stays empty in a browser application.
|
|
288
|
+
*
|
|
289
|
+
* The field names come from the installed IGNIS. A group a newer IGNIS adds passes this type, but
|
|
290
|
+
* `start()` does not check it.
|
|
276
291
|
*/
|
|
277
|
-
export interface IArtifactIndex {
|
|
278
|
-
configurations?: ReadonlyArray<TClass<unknown>>;
|
|
279
|
-
dataSources?: ReadonlyArray<TClass<unknown>>;
|
|
280
|
-
components?: ReadonlyArray<TClass<unknown>>;
|
|
281
|
-
repositories?: ReadonlyArray<TClass<unknown>>;
|
|
282
|
-
services?: ReadonlyArray<TClass<unknown>>;
|
|
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>>>>;
|
|
292
|
+
export interface IArdorArtifactIndex extends Partial<Record<Exclude<keyof Ignis.IArtifactIndex, 'custom'>, ReadonlyArray<TClass<unknown>>>>, Pick<Ignis.IArtifactIndex, 'custom'> {
|
|
286
293
|
}
|
|
287
294
|
/**
|
|
288
295
|
* Answers whether the current actor may act on a resource. Bound by the application under
|
|
@@ -290,9 +297,7 @@ export interface IArtifactIndex {
|
|
|
290
297
|
* to do: the backend must check every permission on every request.
|
|
291
298
|
*/
|
|
292
299
|
export interface IPermissionProvider {
|
|
293
|
-
canAccess(opts: {
|
|
294
|
-
resource: string;
|
|
295
|
-
action: string;
|
|
300
|
+
canAccess(opts: Pick<Ignis.IAuthorizationRequest, 'resource' | 'action'> & {
|
|
296
301
|
record?: unknown;
|
|
297
302
|
}): Promise<boolean>;
|
|
298
303
|
}
|
|
@@ -326,22 +331,17 @@ export type TPaths<T, DeepLevel extends number = 10> = DeepLevel extends 0 ? nev
|
|
|
326
331
|
export type TFullPaths<T, DeepLevel extends number = 10> = DeepLevel extends never ? never : T extends Array<infer U> ? TFullPaths<U> : T extends object ? {
|
|
327
332
|
[K in keyof T]-?: K extends string | number ? T[K] extends object ? `${K}.${TFullPaths<T[K], TDeepPath[DeepLevel]>}` : `${K}` : never;
|
|
328
333
|
}[keyof T] : never;
|
|
329
|
-
/**
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
+
/**
|
|
335
|
+
* What an application is: bound under `CoreBindings.APPLICATION_INFO`, and the name a tracing id starts
|
|
336
|
+
* with. IGNIS's `IApplicationInfo`, so it takes keys of your own, plus ARDOR's `id`.
|
|
337
|
+
*/
|
|
338
|
+
export interface IApplicationInfo extends Ignis.IApplicationInfo {
|
|
334
339
|
/**
|
|
335
340
|
* Scopes the session and store keys in browser storage to this application (`LocalStorageKeys.scoped`),
|
|
336
341
|
* so two applications on one origin do not share a session. Give every application of an origin an id.
|
|
337
342
|
* Without one the keys are the unscoped ones.
|
|
338
343
|
*/
|
|
339
344
|
id?: string;
|
|
340
|
-
author?: {
|
|
341
|
-
name: string;
|
|
342
|
-
email: string;
|
|
343
|
-
url?: string;
|
|
344
|
-
};
|
|
345
345
|
}
|
|
346
346
|
/** The `build-info.json` that the `buildInfoFile` Vite plugin of `@venizia/ardor/vite` writes: IGNIS's build stamp and the installed versions of the framework packages. */
|
|
347
347
|
export interface IBuildInfoFile extends TBuildInfoRecord {
|
|
@@ -3,9 +3,6 @@ import { BaseHelper } from '@venizia/ignis-helpers/core';
|
|
|
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
|
-
*
|
|
7
|
-
* @useWhen a 401 must trigger one shared refresh for every request in flight
|
|
8
|
-
* @insteadOf a refresh and retry written by hand in each request
|
|
9
6
|
*/
|
|
10
7
|
export declare class AuthRecoveryHelper extends BaseHelper {
|
|
11
8
|
private readonly opts;
|
|
@@ -3,9 +3,6 @@ import { BaseHelper } from '@venizia/ignis-helpers/core';
|
|
|
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
|
-
*
|
|
7
|
-
* @useWhen a 401 must trigger one shared refresh for every request in flight
|
|
8
|
-
* @insteadOf a refresh and retry written by hand in each request
|
|
9
6
|
*/
|
|
10
7
|
export class AuthRecoveryHelper extends BaseHelper {
|
|
11
8
|
constructor(opts) {
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import type { TStorageArea } from '
|
|
1
|
+
import type { TStorageArea } from '../common/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* A `ResizeObserver` whose `observe()` records the element. `flush` delivers a size to the observers
|
|
4
4
|
* of an element; a callback runs at once, so code that waits for an animation frame still needs the
|
|
5
5
|
* test's own frame control.
|
|
6
|
-
*
|
|
7
|
-
* @useWhen a test needs a `ResizeObserver` it can drive
|
|
8
|
-
* @insteadOf a hand-written `ResizeObserver` stub in the test
|
|
9
6
|
*/
|
|
10
7
|
export declare class FakeResizeObserver implements ResizeObserver {
|
|
11
8
|
readonly callback: ResizeObserverCallback;
|
|
@@ -34,9 +31,6 @@ export declare class FakeResizeObserver implements ResizeObserver {
|
|
|
34
31
|
/**
|
|
35
32
|
* An `IntersectionObserver` whose `observe()` records the element and reports nothing by itself: `settle`
|
|
36
33
|
* delivers the first report of a browser, `flush` delivers an entry to the observers of an element.
|
|
37
|
-
*
|
|
38
|
-
* @useWhen a test needs an `IntersectionObserver` it can drive
|
|
39
|
-
* @insteadOf a hand-written `IntersectionObserver` stub in the test
|
|
40
34
|
*/
|
|
41
35
|
export declare class FakeIntersectionObserver implements IntersectionObserver {
|
|
42
36
|
#private;
|
|
@@ -80,9 +74,6 @@ export declare class FakeIntersectionObserver implements IntersectionObserver {
|
|
|
80
74
|
}
|
|
81
75
|
/**
|
|
82
76
|
* The `MediaQueryList` that `matchMedia` answers under `FakeMatchMedia.install`: one per query, `false` until `set`.
|
|
83
|
-
*
|
|
84
|
-
* @useWhen a test needs `matchMedia` answers it can set per query
|
|
85
|
-
* @insteadOf a hand-written `window.matchMedia` stub in the test
|
|
86
77
|
*/
|
|
87
78
|
export declare class FakeMatchMedia extends EventTarget {
|
|
88
79
|
#private;
|
|
@@ -112,9 +103,6 @@ export declare class FakeMatchMedia extends EventTarget {
|
|
|
112
103
|
* `setItem` and `clear` throw `QuotaExceededError` and `removeItem` throw `SecurityError`. A key named like a member of the fake (`getItem`,
|
|
113
104
|
* `length`, `writes`, `failWrites` and the rest) would shadow it, so `setItem` throws a `TypeError`
|
|
114
105
|
* for it, where the real `Storage` accepts it.
|
|
115
|
-
*
|
|
116
|
-
* @useWhen a test needs a `Storage` that can fail on demand
|
|
117
|
-
* @insteadOf a hand-written `localStorage` stub in the test
|
|
118
106
|
*/
|
|
119
107
|
export declare class FakeStorage implements Storage {
|
|
120
108
|
#private;
|
|
@@ -138,9 +126,6 @@ export declare class FakeStorage implements Storage {
|
|
|
138
126
|
}
|
|
139
127
|
/**
|
|
140
128
|
* A `navigator.clipboard` that keeps the text in memory; `isDenied` makes both methods reject as a refused permission does.
|
|
141
|
-
*
|
|
142
|
-
* @useWhen a test needs a `navigator.clipboard` that can be refused
|
|
143
|
-
* @insteadOf a hand-written `navigator.clipboard` stub in the test
|
|
144
129
|
*/
|
|
145
130
|
export declare class FakeClipboard {
|
|
146
131
|
/** The text of every `writeText`, in order. */
|
|
@@ -153,4 +138,4 @@ export declare class FakeClipboard {
|
|
|
153
138
|
writeText(text: string): Promise<void>;
|
|
154
139
|
readText(): Promise<string>;
|
|
155
140
|
}
|
|
156
|
-
//# sourceMappingURL=
|
|
141
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -47,9 +47,6 @@ const drop = (opts) => {
|
|
|
47
47
|
* A `ResizeObserver` whose `observe()` records the element. `flush` delivers a size to the observers
|
|
48
48
|
* of an element; a callback runs at once, so code that waits for an animation frame still needs the
|
|
49
49
|
* test's own frame control.
|
|
50
|
-
*
|
|
51
|
-
* @useWhen a test needs a `ResizeObserver` it can drive
|
|
52
|
-
* @insteadOf a hand-written `ResizeObserver` stub in the test
|
|
53
50
|
*/
|
|
54
51
|
export class FakeResizeObserver {
|
|
55
52
|
/** The observers created since the last `install`, in creation order. */
|
|
@@ -119,9 +116,6 @@ const intersectionEntryOf = (opts) => {
|
|
|
119
116
|
/**
|
|
120
117
|
* An `IntersectionObserver` whose `observe()` records the element and reports nothing by itself: `settle`
|
|
121
118
|
* delivers the first report of a browser, `flush` delivers an entry to the observers of an element.
|
|
122
|
-
*
|
|
123
|
-
* @useWhen a test needs an `IntersectionObserver` it can drive
|
|
124
|
-
* @insteadOf a hand-written `IntersectionObserver` stub in the test
|
|
125
119
|
*/
|
|
126
120
|
export class FakeIntersectionObserver {
|
|
127
121
|
/** The observers created since the last `install`, in creation order. */
|
|
@@ -204,9 +198,6 @@ export class FakeIntersectionObserver {
|
|
|
204
198
|
}
|
|
205
199
|
/**
|
|
206
200
|
* The `MediaQueryList` that `matchMedia` answers under `FakeMatchMedia.install`: one per query, `false` until `set`.
|
|
207
|
-
*
|
|
208
|
-
* @useWhen a test needs `matchMedia` answers it can set per query
|
|
209
|
-
* @insteadOf a hand-written `window.matchMedia` stub in the test
|
|
210
201
|
*/
|
|
211
202
|
export class FakeMatchMedia extends EventTarget {
|
|
212
203
|
/** The queries asked since the last `install`, with the list each one got. */
|
|
@@ -261,9 +252,6 @@ export class FakeMatchMedia extends EventTarget {
|
|
|
261
252
|
* `setItem` and `clear` throw `QuotaExceededError` and `removeItem` throw `SecurityError`. A key named like a member of the fake (`getItem`,
|
|
262
253
|
* `length`, `writes`, `failWrites` and the rest) would shadow it, so `setItem` throws a `TypeError`
|
|
263
254
|
* for it, where the real `Storage` accepts it.
|
|
264
|
-
*
|
|
265
|
-
* @useWhen a test needs a `Storage` that can fail on demand
|
|
266
|
-
* @insteadOf a hand-written `localStorage` stub in the test
|
|
267
255
|
*/
|
|
268
256
|
export class FakeStorage {
|
|
269
257
|
#failReads = false;
|
|
@@ -352,9 +340,6 @@ export class FakeStorage {
|
|
|
352
340
|
}
|
|
353
341
|
/**
|
|
354
342
|
* A `navigator.clipboard` that keeps the text in memory; `isDenied` makes both methods reject as a refused permission does.
|
|
355
|
-
*
|
|
356
|
-
* @useWhen a test needs a `navigator.clipboard` that can be refused
|
|
357
|
-
* @insteadOf a hand-written `navigator.clipboard` stub in the test
|
|
358
343
|
*/
|
|
359
344
|
export class FakeClipboard {
|
|
360
345
|
constructor() {
|
|
@@ -383,4 +368,4 @@ export class FakeClipboard {
|
|
|
383
368
|
return Promise.resolve(this.text);
|
|
384
369
|
}
|
|
385
370
|
}
|
|
386
|
-
//# sourceMappingURL=
|
|
371
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { type IAuthTokenRecord, type IdType } from '../common/index.js';
|
|
1
|
+
import { type IAuthTokenRecord, type IdType, type ISignInSession } from '../common/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* The one place that reads and writes the stored auth token, with the browser guard.
|
|
4
|
-
*
|
|
5
|
-
* @useWhen you read or write the stored auth token
|
|
6
|
-
* @insteadOf reading `localStorage` for the token by hand
|
|
7
4
|
*/
|
|
8
5
|
export declare class AuthTokenStore {
|
|
9
6
|
private static readonly logger;
|
|
@@ -16,10 +13,7 @@ export declare class AuthTokenStore {
|
|
|
16
13
|
* (`LocalStorageKeys.KEY_AUTH_TOKEN` by default). Throws when `localStorage` is not available.
|
|
17
14
|
*/
|
|
18
15
|
static write(opts: {
|
|
19
|
-
token:
|
|
20
|
-
value: string;
|
|
21
|
-
type: string;
|
|
22
|
-
};
|
|
16
|
+
token: ISignInSession['token'];
|
|
23
17
|
provider: string;
|
|
24
18
|
userId?: IdType;
|
|
25
19
|
key?: string;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { LoggerFactory } from '@venizia/ignis-helpers/core';
|
|
2
2
|
import { getError } from '@venizia/ignis-inversion';
|
|
3
|
-
import { LocalStorageKeys } from '../common/index.js';
|
|
3
|
+
import { LocalStorageKeys, } from '../common/index.js';
|
|
4
4
|
/**
|
|
5
5
|
* The one place that reads and writes the stored auth token, with the browser guard.
|
|
6
|
-
*
|
|
7
|
-
* @useWhen you read or write the stored auth token
|
|
8
|
-
* @insteadOf reading `localStorage` for the token by hand
|
|
9
6
|
*/
|
|
10
7
|
export class AuthTokenStore {
|
|
11
8
|
static { this.logger = LoggerFactory.getLogger(['AuthTokenStore']); }
|
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
* (a server), no `navigator.clipboard` (an insecure context, an old WebView), a denied permission,
|
|
4
4
|
* a missing user gesture and an unfocused document all answer `false` or `undefined`. Nothing
|
|
5
5
|
* touches `navigator` at import.
|
|
6
|
-
*
|
|
7
|
-
* @useWhen code outside React copies text and must never throw
|
|
8
|
-
* @insteadOf `navigator.clipboard.writeText`
|
|
9
6
|
*/
|
|
10
7
|
export declare class BrowserClipboard {
|
|
8
|
+
private static readonly logger;
|
|
11
9
|
/** The one catch: every refusal the browser can make is the case this class absorbs. */
|
|
12
10
|
private static safe;
|
|
13
11
|
/** `true` when the text is on the clipboard. */
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
+
import { LoggerFactory } from '@venizia/ignis-helpers/core';
|
|
1
2
|
/**
|
|
2
3
|
* The clipboard of the browser, for code outside React. Nothing throws or rejects: no `navigator`
|
|
3
4
|
* (a server), no `navigator.clipboard` (an insecure context, an old WebView), a denied permission,
|
|
4
5
|
* a missing user gesture and an unfocused document all answer `false` or `undefined`. Nothing
|
|
5
6
|
* touches `navigator` at import.
|
|
6
|
-
*
|
|
7
|
-
* @useWhen code outside React copies text and must never throw
|
|
8
|
-
* @insteadOf `navigator.clipboard.writeText`
|
|
9
7
|
*/
|
|
10
8
|
export class BrowserClipboard {
|
|
9
|
+
static { this.logger = LoggerFactory.getLogger(['BrowserClipboard']); }
|
|
11
10
|
/** The one catch: every refusal the browser can make is the case this class absorbs. */
|
|
12
11
|
static async safe(opts) {
|
|
13
12
|
try {
|
|
14
13
|
const result = await opts.run();
|
|
15
14
|
return result;
|
|
16
|
-
// eslint-disable-next-line venizia/no-silent-catch -- absorbing a refusing clipboard is the contract of BrowserClipboard
|
|
17
15
|
}
|
|
18
|
-
catch {
|
|
16
|
+
catch (error) {
|
|
17
|
+
// The name only: a message may quote what was being copied.
|
|
18
|
+
BrowserClipboard.logger.debug('[safe] The clipboard refused | error: %s', error instanceof Error ? error.name : typeof error);
|
|
19
19
|
return opts.fallback;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -5,15 +5,14 @@ export interface IStorageChange {
|
|
|
5
5
|
isExternal: boolean;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
-
* `localStorage` and `sessionStorage` that never throw: a missing area, a
|
|
9
|
-
* error or text the codec cannot read gives the fallback or `false`.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @useWhen code outside React reads or writes `localStorage` or `sessionStorage` and must never throw
|
|
13
|
-
* @insteadOf `localStorage.getItem` and `setItem` with try and catch
|
|
8
|
+
* `localStorage` and `sessionStorage` that never throw for what the storage does: a missing area, a
|
|
9
|
+
* blocked accessor, a quota error or text the codec cannot read gives the fallback or `false`. A
|
|
10
|
+
* prefix that is not a non-empty string throws, in `removeWhere` and in `keys`. Nothing touches
|
|
11
|
+
* `window` at import. A key under `LocalStorageKeys.PREFIX_AUTH` is the session and is never written here.
|
|
14
12
|
*/
|
|
15
13
|
export declare class BrowserStorage {
|
|
16
14
|
private static readonly subs;
|
|
15
|
+
private static readonly logger;
|
|
17
16
|
/** The one catch: a storage that throws is the case this class absorbs, so every access runs here. */
|
|
18
17
|
private static safe;
|
|
19
18
|
private static area;
|
|
@@ -37,6 +36,7 @@ export declare class BrowserStorage {
|
|
|
37
36
|
storage?: TStorageArea;
|
|
38
37
|
codec: IStorageCodec<TValue>;
|
|
39
38
|
}): boolean;
|
|
39
|
+
/** Without a codec, or with one that may be absent, the value's own type is the stored type. */
|
|
40
40
|
static set<TValue>(opts: {
|
|
41
41
|
key: string;
|
|
42
42
|
value: TValue;
|
|
@@ -48,15 +48,21 @@ export declare class BrowserStorage {
|
|
|
48
48
|
key: string;
|
|
49
49
|
storage?: TStorageArea;
|
|
50
50
|
}): boolean;
|
|
51
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* The keys of the area, only those that start with `prefix` when it is given. Lists the session keys
|
|
53
|
+
* too. A `prefix` that is given and is not a non-empty string throws.
|
|
54
|
+
*/
|
|
52
55
|
static keys(opts?: {
|
|
53
56
|
storage?: TStorageArea;
|
|
54
|
-
/**
|
|
57
|
+
/** Absent: every key. */
|
|
55
58
|
prefix?: string;
|
|
56
59
|
}): Array<string>;
|
|
60
|
+
/** Throws unless `prefix` is a non-empty string: `undefined` would match nothing, `''` everything. */
|
|
61
|
+
private static assertPrefix;
|
|
57
62
|
/**
|
|
58
|
-
* Removes every key that starts with `prefix` and answers how many it removed.
|
|
59
|
-
*
|
|
63
|
+
* Removes every key that starts with `prefix` and answers how many it removed. A `prefix` that is
|
|
64
|
+
* not a non-empty string throws, so a name read wrongly cannot pass for a sweep, and a session key
|
|
65
|
+
* is never removed, as in `remove`. Every subscriber of a key under the
|
|
60
66
|
* prefix is told, whether or not the key was stored. A key another tab removed
|
|
61
67
|
* after the listing still counts: `removeItem` of a missing key does not throw.
|
|
62
68
|
*/
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
+
import { getError } from '@venizia/ignis-inversion';
|
|
2
|
+
import { LoggerFactory } from '@venizia/ignis-helpers/core';
|
|
1
3
|
import { LocalStorageKeys, StorageAreas } from '../common/index.js';
|
|
2
4
|
/**
|
|
3
|
-
* `localStorage` and `sessionStorage` that never throw: a missing area, a
|
|
4
|
-
* error or text the codec cannot read gives the fallback or `false`.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* @useWhen code outside React reads or writes `localStorage` or `sessionStorage` and must never throw
|
|
8
|
-
* @insteadOf `localStorage.getItem` and `setItem` with try and catch
|
|
5
|
+
* `localStorage` and `sessionStorage` that never throw for what the storage does: a missing area, a
|
|
6
|
+
* blocked accessor, a quota error or text the codec cannot read gives the fallback or `false`. A
|
|
7
|
+
* prefix that is not a non-empty string throws, in `removeWhere` and in `keys`. Nothing touches
|
|
8
|
+
* `window` at import. A key under `LocalStorageKeys.PREFIX_AUTH` is the session and is never written here.
|
|
9
9
|
*/
|
|
10
10
|
export class BrowserStorage {
|
|
11
11
|
static { this.subs = new Set(); }
|
|
12
|
+
static { this.logger = LoggerFactory.getLogger(['BrowserStorage']); }
|
|
12
13
|
/** The one catch: a storage that throws is the case this class absorbs, so every access runs here. */
|
|
13
14
|
static safe(opts) {
|
|
14
15
|
try {
|
|
15
16
|
return opts.run();
|
|
16
|
-
// eslint-disable-next-line venizia/no-silent-catch -- absorbing a throwing storage is the contract of BrowserStorage
|
|
17
17
|
}
|
|
18
|
-
catch {
|
|
18
|
+
catch (error) {
|
|
19
|
+
// The name only: a message may quote the stored text.
|
|
20
|
+
BrowserStorage.logger.debug('[safe] The storage refused | error: %s', error instanceof Error ? error.name : typeof error);
|
|
19
21
|
return opts.fallback;
|
|
20
22
|
}
|
|
21
23
|
}
|
|
@@ -60,8 +62,14 @@ export class BrowserStorage {
|
|
|
60
62
|
static remove(opts) {
|
|
61
63
|
return BrowserStorage.write({ ...opts, run: (area) => area.removeItem(opts.key) });
|
|
62
64
|
}
|
|
63
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* The keys of the area, only those that start with `prefix` when it is given. Lists the session keys
|
|
67
|
+
* too. A `prefix` that is given and is not a non-empty string throws.
|
|
68
|
+
*/
|
|
64
69
|
static keys(opts = {}) {
|
|
70
|
+
if ('prefix' in opts) {
|
|
71
|
+
BrowserStorage.assertPrefix({ prefix: opts.prefix, method: 'keys' });
|
|
72
|
+
}
|
|
65
73
|
const { prefix = '' } = opts;
|
|
66
74
|
return BrowserStorage.safe({
|
|
67
75
|
run: () => {
|
|
@@ -75,25 +83,33 @@ export class BrowserStorage {
|
|
|
75
83
|
fallback: [],
|
|
76
84
|
});
|
|
77
85
|
}
|
|
86
|
+
/** Throws unless `prefix` is a non-empty string: `undefined` would match nothing, `''` everything. */
|
|
87
|
+
static assertPrefix(opts) {
|
|
88
|
+
if (typeof opts.prefix !== 'string' || !opts.prefix) {
|
|
89
|
+
throw getError({
|
|
90
|
+
message: `[BrowserStorage.${opts.method}] prefix must be a non-empty string`,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
78
94
|
/**
|
|
79
|
-
* Removes every key that starts with `prefix` and answers how many it removed.
|
|
80
|
-
*
|
|
95
|
+
* Removes every key that starts with `prefix` and answers how many it removed. A `prefix` that is
|
|
96
|
+
* not a non-empty string throws, so a name read wrongly cannot pass for a sweep, and a session key
|
|
97
|
+
* is never removed, as in `remove`. Every subscriber of a key under the
|
|
81
98
|
* prefix is told, whether or not the key was stored. A key another tab removed
|
|
82
99
|
* after the listing still counts: `removeItem` of a missing key does not throw.
|
|
83
100
|
*/
|
|
84
101
|
static removeWhere(opts) {
|
|
85
102
|
const { storage, prefix } = opts;
|
|
86
|
-
|
|
103
|
+
BrowserStorage.assertPrefix({ prefix, method: 'removeWhere' });
|
|
104
|
+
const keys = BrowserStorage.keys({ storage, prefix });
|
|
87
105
|
const removed = keys.filter((key) => BrowserStorage.remove({ key, storage })).length;
|
|
88
106
|
// A key not stored yet, with a write waiting for it, is under the prefix too: tell its subscribers.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
});
|
|
96
|
-
}
|
|
107
|
+
BrowserStorage.notify({
|
|
108
|
+
key: undefined,
|
|
109
|
+
area: BrowserStorage.area({ storage }),
|
|
110
|
+
prefix,
|
|
111
|
+
isExternal: false,
|
|
112
|
+
});
|
|
97
113
|
return removed;
|
|
98
114
|
}
|
|
99
115
|
/**
|
package/dist/utilities/file.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Helpers over `Blob` and file data.
|
|
3
|
-
*
|
|
4
|
-
* @useWhen you work with `Blob` and file data, such as a download or a size
|
|
5
|
-
* @insteadOf hand-written `Blob` and object URL code
|
|
6
3
|
*/
|
|
7
4
|
export declare class FileUtility {
|
|
8
5
|
/** How long a saved file's object URL lives, in milliseconds: a browser that starts the download later (Safari) still finds it. */
|
|
@@ -17,8 +14,11 @@ export declare class FileUtility {
|
|
|
17
14
|
*
|
|
18
15
|
* @example
|
|
19
16
|
* ```ts
|
|
20
|
-
* const { data, filename } = await NetworkResponseReader.read
|
|
21
|
-
*
|
|
17
|
+
* const { data, filename } = await NetworkResponseReader.read({ response, type });
|
|
18
|
+
*
|
|
19
|
+
* if (data instanceof Blob) {
|
|
20
|
+
* FileUtility.save({ blob: data, filename });
|
|
21
|
+
* }
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
static save(opts: {
|
package/dist/utilities/file.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { getError } from '@venizia/ignis-inversion';
|
|
2
2
|
/**
|
|
3
3
|
* Helpers over `Blob` and file data.
|
|
4
|
-
*
|
|
5
|
-
* @useWhen you work with `Blob` and file data, such as a download or a size
|
|
6
|
-
* @insteadOf hand-written `Blob` and object URL code
|
|
7
4
|
*/
|
|
8
5
|
export class FileUtility {
|
|
9
6
|
/** How long a saved file's object URL lives, in milliseconds: a browser that starts the download later (Safari) still finds it. */
|
|
@@ -24,8 +21,11 @@ export class FileUtility {
|
|
|
24
21
|
*
|
|
25
22
|
* @example
|
|
26
23
|
* ```ts
|
|
27
|
-
* const { data, filename } = await NetworkResponseReader.read
|
|
28
|
-
*
|
|
24
|
+
* const { data, filename } = await NetworkResponseReader.read({ response, type });
|
|
25
|
+
*
|
|
26
|
+
* if (data instanceof Blob) {
|
|
27
|
+
* FileUtility.save({ blob: data, filename });
|
|
28
|
+
* }
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
static save(opts) {
|