@venizia/ardor-kernel 0.4.8-1 → 0.4.8-2

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.
Files changed (36) hide show
  1. package/README.md +3 -1
  2. package/dist/base/applications/abstract.d.ts +17 -1
  3. package/dist/base/applications/abstract.js +7 -0
  4. package/dist/base/providers/base.d.ts +2 -0
  5. package/dist/base/providers/base.js +1 -0
  6. package/dist/base/services/auth.d.ts +11 -0
  7. package/dist/base/services/auth.js +8 -0
  8. package/dist/base/services/base.d.ts +1 -0
  9. package/dist/base/services/base.js +1 -0
  10. package/dist/base/services/network-request.d.ts +35 -1
  11. package/dist/base/services/network-request.js +20 -1
  12. package/dist/common/constants.d.ts +47 -0
  13. package/dist/common/constants.js +47 -0
  14. package/dist/common/keys.d.ts +16 -0
  15. package/dist/common/keys.js +16 -0
  16. package/dist/common/types.d.ts +86 -4
  17. package/dist/helpers/auth-token-store.d.ts +1 -0
  18. package/dist/helpers/auth-token-store.js +1 -0
  19. package/dist/helpers/networks/auth-recovery.d.ts +1 -0
  20. package/dist/helpers/networks/request-body-encoder.d.ts +1 -0
  21. package/dist/helpers/networks/request-body-encoder.js +1 -0
  22. package/dist/helpers/networks/response-reader.d.ts +8 -0
  23. package/dist/helpers/networks/response-reader.js +8 -0
  24. package/dist/utilities/browser-storage.d.ts +2 -0
  25. package/dist/utilities/browser-storage.js +1 -0
  26. package/dist/utilities/browser.d.ts +2 -0
  27. package/dist/utilities/browser.js +2 -0
  28. package/dist/utilities/file.d.ts +1 -0
  29. package/dist/utilities/file.js +1 -0
  30. package/dist/utilities/runtime-config.d.ts +4 -0
  31. package/dist/utilities/runtime-config.js +1 -0
  32. package/dist/utilities/storage-codecs.d.ts +1 -0
  33. package/dist/utilities/storage-codecs.js +1 -0
  34. package/dist/utilities/value.d.ts +3 -0
  35. package/dist/utilities/value.js +3 -0
  36. package/package.json +12 -12
package/README.md CHANGED
@@ -4,9 +4,11 @@ The isomorphic core of [ARDOR](https://github.com/VENIZIA-AI/ardor). No React, n
4
4
  layer a browser data client and a plain TypeScript consumer can both use.
5
5
 
6
6
  ```bash
7
- bun add @venizia/ardor-kernel @venizia/ignis-inversion @venizia/ignis-filter reflect-metadata
7
+ bun add @venizia/ardor-kernel @venizia/ignis-inversion @venizia/ignis-filter @venizia/ignis-helpers @venizia/ignis-kernel reflect-metadata
8
8
  ```
9
9
 
10
+ `@venizia/ignis-connectors` is an optional peer, needed only for `./repository`.
11
+
10
12
  Most applications install [`@venizia/ardor`](https://www.npmjs.com/package/@venizia/ardor) instead,
11
13
  which re-exports this package.
12
14
 
@@ -7,8 +7,15 @@ export interface IArtifactRegistration {
7
7
  namespace: string;
8
8
  key: string;
9
9
  };
10
+ /**
11
+ * The scope of the binding.
12
+ * @default The scope declared on the class, else `BindingScopes.SINGLETON`
13
+ */
10
14
  scope?: TBindingScope;
11
- /** `false` refuses to replace a binding already under the key. */
15
+ /**
16
+ * `false` refuses to replace a binding already under the key.
17
+ * @default true
18
+ */
12
19
  allowOverride?: boolean;
13
20
  }
14
21
  /**
@@ -17,7 +24,9 @@ export interface IArtifactRegistration {
17
24
  * SINGLETON (IGNIS's server uses transient): a hook resolves on every render.
18
25
  */
19
26
  export declare abstract class AbstractArdorApplication extends Container implements IArdorApplication {
27
+ /** The application's own bindings; `preConfigure` runs it last, so they win over discovered and feature bindings. */
20
28
  abstract bindContext(): ValueOrPromise<void>;
29
+ /** The `IApplicationInfo` that `preConfigure` binds under `CoreBindings.APPLICATION_INFO`. */
21
30
  abstract getAppInfo(): ValueOrPromise<IApplicationInfo>;
22
31
  /** What `start()` resolved from `artifacts()`; unset when `preConfigure()` runs without it. */
23
32
  private resolvedIndexes;
@@ -57,17 +66,24 @@ export declare abstract class AbstractArdorApplication extends Container impleme
57
66
  * been discovered: one that was not means the feature's bindings were silently never made.
58
67
  */
59
68
  private registerFeatures;
69
+ /** Runs after `preConfigure` in `start()`; empty by default, for a subclass to override. */
60
70
  postConfigure(): ValueOrPromise<void>;
71
+ /** Binds `target` in the service namespace; returns the binding. */
61
72
  service<T>(target: TClass<T>, opts?: IArtifactRegistration): Binding<T>;
73
+ /** Binds `target` in the repository namespace; returns the binding. */
62
74
  repository<T>(target: TClass<T>, opts?: IArtifactRegistration): Binding<T>;
75
+ /** Binds `target` in the data source namespace; returns the binding. */
63
76
  dataSource<T>(target: TClass<T>, opts?: IArtifactRegistration): Binding<T>;
77
+ /** Binds `target` in the component namespace; returns the binding. */
64
78
  component<T>(target: TClass<T>, opts?: IArtifactRegistration): Binding<T>;
65
79
  /** `<scope>.<ClassName>`, singleton, with tags. Prefer the per-kind methods above. */
66
80
  injectable<T>(scope: string, value: TClass<T>, tags?: Array<string>): void;
81
+ /** Resolves the artifact indexes, then runs `preConfigure`, then `postConfigure`, in that order. */
67
82
  start(): Promise<void>;
68
83
  /** Key: explicit `binding` > the class's stereotype > `<namespace>.<ClassName>`. Same for scope. */
69
84
  private registerArtifact;
70
85
  }
86
+ /** The base to extend for an application: implement `bindContext` and `getAppInfo`. */
71
87
  export declare abstract class BaseArdorApplication extends AbstractArdorApplication {
72
88
  }
73
89
  //# sourceMappingURL=abstract.d.ts.map
@@ -176,7 +176,9 @@ export class AbstractArdorApplication extends Container {
176
176
  }
177
177
  this.bind({ key: CoreBindings.FEATURES }).toValue(features);
178
178
  }
179
+ /** Runs after `preConfigure` in `start()`; empty by default, for a subclass to override. */
179
180
  postConfigure() { }
181
+ /** Binds `target` in the service namespace; returns the binding. */
180
182
  service(target, opts) {
181
183
  return this.registerArtifact({
182
184
  target,
@@ -185,6 +187,7 @@ export class AbstractArdorApplication extends Container {
185
187
  opts,
186
188
  });
187
189
  }
190
+ /** Binds `target` in the repository namespace; returns the binding. */
188
191
  repository(target, opts) {
189
192
  return this.registerArtifact({
190
193
  target,
@@ -193,6 +196,7 @@ export class AbstractArdorApplication extends Container {
193
196
  opts,
194
197
  });
195
198
  }
199
+ /** Binds `target` in the data source namespace; returns the binding. */
196
200
  dataSource(target, opts) {
197
201
  return this.registerArtifact({
198
202
  target,
@@ -201,6 +205,7 @@ export class AbstractArdorApplication extends Container {
201
205
  opts,
202
206
  });
203
207
  }
208
+ /** Binds `target` in the component namespace; returns the binding. */
204
209
  component(target, opts) {
205
210
  return this.registerArtifact({
206
211
  target,
@@ -218,6 +223,7 @@ export class AbstractArdorApplication extends Container {
218
223
  .setScope(BindingScopes.SINGLETON)
219
224
  .setTags(...(tags ?? []));
220
225
  }
226
+ /** Resolves the artifact indexes, then runs `preConfigure`, then `postConfigure`, in that order. */
221
227
  async start() {
222
228
  const result = await this.resolveArtifactIndexes();
223
229
  this.resolvedIndexes = result;
@@ -245,6 +251,7 @@ export class AbstractArdorApplication extends Container {
245
251
  .setScope(opts.opts?.scope ?? declared?.scope ?? BindingScopes.SINGLETON);
246
252
  }
247
253
  }
254
+ /** The base to extend for an application: implement `bindContext` and `getAppInfo`. */
248
255
  export class BaseArdorApplication extends AbstractArdorApplication {
249
256
  }
250
257
  //# sourceMappingURL=abstract.js.map
@@ -1,6 +1,8 @@
1
1
  import { BaseHelper } from '@venizia/ignis-helpers/core';
2
2
  import type { Container, IProvider } from '@venizia/ignis-inversion';
3
+ /** Base of a provider: `value` yields what the provider supplies, resolved through the container. */
3
4
  export declare abstract class BaseProvider<T> extends BaseHelper implements IProvider<T> {
5
+ /** Produces the provided value. */
4
6
  abstract value(container: Container): T;
5
7
  }
6
8
  //# sourceMappingURL=base.d.ts.map
@@ -1,4 +1,5 @@
1
1
  import { BaseHelper } from '@venizia/ignis-helpers/core';
2
+ /** Base of a provider: `value` yields what the provider supplies, resolved through the container. */
2
3
  export class BaseProvider extends BaseHelper {
3
4
  }
4
5
  //# sourceMappingURL=base.js.map
@@ -1,5 +1,6 @@
1
1
  import { type AnyType, type IAuthTokenRecord, type IdType } from '../../common/index.js';
2
2
  import { BaseService } from './base.js';
3
+ /** Keeps the signed-in session (token, identity, roles) in `localStorage`; everything under `LocalStorageKeys.PREFIX_AUTH`. */
3
4
  export declare class DefaultAuthService extends BaseService {
4
5
  private readonly listeners;
5
6
  constructor();
@@ -15,14 +16,23 @@ export declare class DefaultAuthService extends BaseService {
15
16
  * logged: the message of a JSON parse error quotes the text it could not parse, which can be a token.
16
17
  */
17
18
  private parseStored;
19
+ /** The stored identity; `{}` when nothing usable is stored, also outside a browser. */
18
20
  getUser(): AnyType;
21
+ /** The stored roles; empty when nothing usable is stored, also outside a browser. */
19
22
  getRoles(): Set<string>;
20
23
  /** The stored token, `null` for every visitor who has not signed in. */
21
24
  getAuth(): IAuthTokenRecord | null;
25
+ /**
26
+ * Stores the token and identity, then notifies the subscribers. Throws when `localStorage` is
27
+ * not available. Roles are stored only when `roles` is given.
28
+ */
22
29
  saveAuth(opts: {
23
30
  userId: number | string;
31
+ /** @default '' */
24
32
  username?: string;
33
+ /** @default '' */
25
34
  provider?: string;
35
+ /** @default '' */
26
36
  referenceId?: IdType;
27
37
  token: {
28
38
  value: string;
@@ -34,6 +44,7 @@ export declare class DefaultAuthService extends BaseService {
34
44
  */
35
45
  roles?: ReadonlyArray<string>;
36
46
  }): void;
47
+ /** Removes every key under `LocalStorageKeys.PREFIX_AUTH`, then notifies the subscribers; does nothing outside a browser. */
37
48
  cleanUp(): void;
38
49
  }
39
50
  //# sourceMappingURL=auth.d.ts.map
@@ -2,6 +2,7 @@ import { getError } from '@venizia/ignis-inversion';
2
2
  import { LocalStorageKeys } from '../../common/index.js';
3
3
  import { AuthTokenStore } from '../../helpers/index.js';
4
4
  import { BaseService } from './base.js';
5
+ /** Keeps the signed-in session (token, identity, roles) in `localStorage`; everything under `LocalStorageKeys.PREFIX_AUTH`. */
5
6
  export class DefaultAuthService extends BaseService {
6
7
  constructor() {
7
8
  super({ scope: DefaultAuthService.name });
@@ -45,6 +46,7 @@ export class DefaultAuthService extends BaseService {
45
46
  return undefined;
46
47
  }
47
48
  }
49
+ /** The stored identity; `{}` when nothing usable is stored, also outside a browser. */
48
50
  getUser() {
49
51
  const identity = this.parseStored({
50
52
  key: LocalStorageKeys.KEY_AUTH_IDENTITY,
@@ -53,6 +55,7 @@ export class DefaultAuthService extends BaseService {
53
55
  const isRecord = typeof identity === 'object' && identity !== null && !Array.isArray(identity);
54
56
  return isRecord ? identity : {};
55
57
  }
58
+ /** The stored roles; empty when nothing usable is stored, also outside a browser. */
56
59
  getRoles() {
57
60
  const stored = this.parseStored({
58
61
  key: LocalStorageKeys.KEY_AUTH_PERMISSION,
@@ -65,6 +68,10 @@ export class DefaultAuthService extends BaseService {
65
68
  getAuth() {
66
69
  return AuthTokenStore.read() ?? null;
67
70
  }
71
+ /**
72
+ * Stores the token and identity, then notifies the subscribers. Throws when `localStorage` is
73
+ * not available. Roles are stored only when `roles` is given.
74
+ */
68
75
  saveAuth(opts) {
69
76
  // Not a silent skip: a sign-in that is not kept would look like it worked.
70
77
  if (typeof localStorage === 'undefined') {
@@ -80,6 +87,7 @@ export class DefaultAuthService extends BaseService {
80
87
  }
81
88
  this.notify();
82
89
  }
90
+ /** Removes every key under `LocalStorageKeys.PREFIX_AUTH`, then notifies the subscribers; does nothing outside a browser. */
83
91
  cleanUp() {
84
92
  if (typeof localStorage === 'undefined') {
85
93
  return;
@@ -1,4 +1,5 @@
1
1
  import { BaseHelper } from '@venizia/ignis-helpers/core';
2
+ /** Base of the services of an application; a `BaseHelper` with a scoped logger. */
2
3
  export declare class BaseService extends BaseHelper {
3
4
  }
4
5
  //# sourceMappingURL=base.d.ts.map
@@ -1,4 +1,5 @@
1
1
  import { BaseHelper } from '@venizia/ignis-helpers/core';
2
+ /** Base of the services of an application; a `BaseHelper` with a scoped logger. */
2
3
  export class BaseService extends BaseHelper {
3
4
  }
4
5
  //# sourceMappingURL=base.js.map
@@ -8,18 +8,32 @@ import { BaseService } from './base.js';
8
8
  * in the protected hooks, each taking one `opts` object, which a subclass overrides.
9
9
  */
10
10
  export declare class DefaultNetworkRequestService extends BaseService {
11
+ /** Resources sent without a token, matched exactly. */
11
12
  protected noAuthPaths?: string[];
13
+ /** `noAuthPathRegex` compiled; a resource matching any is sent without a token. */
12
14
  protected noAuthPathRegexes: RegExp[];
15
+ /** Headers added to every request, keyed by lowercase name. */
13
16
  protected headers: Record<string, string>;
14
17
  protected networkRequest: NodeFetchNetworkRequest;
18
+ /** The origin and base path requests are sent to; an empty one makes `doRequest` throw. */
15
19
  protected baseUrl: string;
16
20
  protected authRecovery?: IAuthRecoveryOptions;
17
21
  protected authService?: DefaultAuthService;
18
22
  private readonly recovery;
19
23
  constructor(opts: INoAuthOptions & {
24
+ /** The name of the underlying network request helper. */
20
25
  name: string;
26
+ /**
27
+ * An empty one makes `doRequest` refuse, unless it is given its own `baseUrl`.
28
+ * @default ''
29
+ */
21
30
  baseUrl?: string;
31
+ /**
32
+ * Sent with every request; a name set later with `setHeaders` replaces it.
33
+ * @default {}
34
+ */
22
35
  headers?: HeadersInit;
36
+ /** Enables the refresh-and-retry after a 401. */
23
37
  authRecovery?: IAuthRecoveryOptions;
24
38
  /** What the default `refreshToken` saves the new token through. */
25
39
  authService?: DefaultAuthService;
@@ -63,7 +77,7 @@ export declare class DefaultNetworkRequestService extends BaseService {
63
77
  };
64
78
  /** Runs once when `refreshToken` threw. The place to send the user back to sign-in. */
65
79
  protected onAuthFailure(): Promise<void>;
66
- /** The tracing id of a request, sent in `x-request-tracing-id`. Default `<application name>_<uuid>`. */
80
+ /** The tracing id of a request, sent in `x-request-id`. Default `<application name>_<uuid>`. */
67
81
  protected buildRequestTracingId(opts: {
68
82
  applicationInfo: IApplicationInfo;
69
83
  }): string;
@@ -82,6 +96,10 @@ export declare class DefaultNetworkRequestService extends BaseService {
82
96
  * options), and a 401 joins this service's shared `refresh`. A no-auth path gets no token.
83
97
  */
84
98
  getDataSourceAuth(opts?: Pick<IGetRequestPropsParams, 'restDataProviderOptions' | 'applicationInfo'>): IDataSourceAuth;
99
+ /**
100
+ * The `token` (`<type> <value>`, `Bearer` when the type is empty) and `provider` of the stored
101
+ * token. Throws an error with status 401 when there is no token.
102
+ */
85
103
  getRequestAuthorizationHeader(): {
86
104
  provider: string | undefined;
87
105
  token: string;
@@ -90,6 +108,7 @@ export declare class DefaultNetworkRequestService extends BaseService {
90
108
  setHeaders(opts: {
91
109
  headers: HeadersInit;
92
110
  }): void;
111
+ /** Removes the headers set by name, in any case. */
93
112
  removeHeaders(opts: {
94
113
  keys: string[];
95
114
  }): void;
@@ -97,6 +116,10 @@ export declare class DefaultNetworkRequestService extends BaseService {
97
116
  protected getSessionHeaders(): Record<string, string>;
98
117
  /** The request channel (`RequestChannel.WEB` unless configured) and a fresh tracing id. */
99
118
  protected getTracingHeaders(opts: Pick<IGetRequestPropsParams, 'restDataProviderOptions' | 'applicationInfo'>): Record<string, string>;
119
+ /**
120
+ * The session headers, plus `authorization` and `x-auth-provider` unless `resource` is a no-auth
121
+ * path. Throws a 401 error for any other resource when there is no token.
122
+ */
100
123
  getRequestHeader(opts: {
101
124
  resource: string;
102
125
  }): Record<string, string>;
@@ -105,6 +128,10 @@ export declare class DefaultNetworkRequestService extends BaseService {
105
128
  bodyType?: string;
106
129
  body: unknown;
107
130
  }): IEncodedBody;
131
+ /**
132
+ * The headers (session, auth, tracing, `x-request-count`, the `extra` header, and the content type
133
+ * of the encoded body) and the encoded body of a request. Throws as `getRequestHeader` does.
134
+ */
108
135
  getRequestProps(params: IGetRequestPropsParams): IGetRequestPropsResult;
109
136
  /** Reads a response by the request type. See `ResponseReader.convert`. */
110
137
  convertResponse<TData = unknown>(opts: Parameters<typeof ResponseReader.convert<TData>>[0]): {
@@ -112,7 +139,14 @@ export declare class DefaultNetworkRequestService extends BaseService {
112
139
  count?: number;
113
140
  total?: number;
114
141
  };
142
+ /**
143
+ * Sends the request and reads the response by `type`. Throws when `baseUrl` (the option, else the
144
+ * service's) is empty. A 401 on a path that can recover triggers `refresh` and, if it refreshed,
145
+ * one retry with the new token. Any other non-2xx response, or a retry that still fails, throws
146
+ * the error read from the response.
147
+ */
115
148
  doRequest<TResult = unknown>(opts: IGetRequestPropsResult & {
149
+ /** @default this.baseUrl */
116
150
  baseUrl?: string;
117
151
  query?: any;
118
152
  type: TRequestType;
@@ -128,7 +128,7 @@ export class DefaultNetworkRequestService extends BaseService {
128
128
  onAuthFailure() {
129
129
  return Promise.resolve();
130
130
  }
131
- /** The tracing id of a request, sent in `x-request-tracing-id`. Default `<application name>_<uuid>`. */
131
+ /** The tracing id of a request, sent in `x-request-id`. Default `<application name>_<uuid>`. */
132
132
  buildRequestTracingId(opts) {
133
133
  return `${opts.applicationInfo.name}_${UuidV4Generator.generate()}`;
134
134
  }
@@ -189,6 +189,10 @@ export class DefaultNetworkRequestService extends BaseService {
189
189
  errorRootKey: ResponseReader.ERROR_ROOT_KEY,
190
190
  };
191
191
  }
192
+ /**
193
+ * The `token` (`<type> <value>`, `Bearer` when the type is empty) and `provider` of the stored
194
+ * token. Throws an error with status 401 when there is no token.
195
+ */
192
196
  getRequestAuthorizationHeader() {
193
197
  const authToken = this.resolveAuthToken();
194
198
  if (!authToken?.value) {
@@ -206,6 +210,7 @@ export class DefaultNetworkRequestService extends BaseService {
206
210
  setHeaders(opts) {
207
211
  this.headers = NetworkHeaders.merge({ sources: [this.headers, opts.headers] });
208
212
  }
213
+ /** Removes the headers set by name, in any case. */
209
214
  removeHeaders(opts) {
210
215
  if (!opts.keys?.length) {
211
216
  return;
@@ -238,6 +243,10 @@ export class DefaultNetworkRequestService extends BaseService {
238
243
  [HeaderConstants.REQUEST_TRACING_ID]: this.buildRequestTracingId({ applicationInfo }),
239
244
  };
240
245
  }
246
+ /**
247
+ * The session headers, plus `authorization` and `x-auth-provider` unless `resource` is a no-auth
248
+ * path. Throws a 401 error for any other resource when there is no token.
249
+ */
241
250
  getRequestHeader(opts) {
242
251
  const { resource } = opts;
243
252
  const defaultHeaders = this.getSessionHeaders();
@@ -256,6 +265,10 @@ export class DefaultNetworkRequestService extends BaseService {
256
265
  encodeBody(opts) {
257
266
  return RequestBodyEncoder.encode(opts);
258
267
  }
268
+ /**
269
+ * The headers (session, auth, tracing, `x-request-count`, the `extra` header, and the content type
270
+ * of the encoded body) and the encoded body of a request. Throws as `getRequestHeader` does.
271
+ */
259
272
  getRequestProps(params) {
260
273
  const { bodyType, body, resource, restDataProviderOptions, applicationInfo, requestCountData = RequestCountData.DATA_ONLY, extra, } = params;
261
274
  const extraHeader = HttpExtraRequest.toHeader({ extra });
@@ -281,6 +294,12 @@ export class DefaultNetworkRequestService extends BaseService {
281
294
  convertResponse(opts) {
282
295
  return ResponseReader.convert(opts);
283
296
  }
297
+ /**
298
+ * Sends the request and reads the response by `type`. Throws when `baseUrl` (the option, else the
299
+ * service's) is empty. A 401 on a path that can recover triggers `refresh` and, if it refreshed,
300
+ * one retry with the new token. Any other non-2xx response, or a retry that still fails, throws
301
+ * the error read from the response.
302
+ */
284
303
  async doRequest(opts) {
285
304
  const { baseUrl = this.baseUrl, type, method, paths, body, headers, query, requestCountData, } = opts;
286
305
  if (!baseUrl) {
@@ -1,16 +1,26 @@
1
+ /** Values of the running environment, read once when the module loads. */
1
2
  export declare class App {
3
+ /** The IANA name of the timezone of the runtime. */
2
4
  static readonly TIMEZONE: string;
5
+ /** The offset from UTC in hours, positive east of UTC (the opposite sign of `getTimezoneOffset()`). */
3
6
  static readonly TIMEZONE_OFFSET: number;
7
+ /** In milliseconds. */
4
8
  static readonly DEFAULT_DEBOUNCE_TIME = 500;
5
9
  }
10
+ /** Authorization schemes (`Basic`, `Bearer`) and strategies (`basic`, `jwt`). */
6
11
  export declare class Authentication {
12
+ /** The scheme in the `authorization` header. */
7
13
  static readonly TYPE_BASIC = "Basic";
8
14
  static readonly TYPE_BEARER = "Bearer";
15
+ /** The name of the auth strategy. */
9
16
  static readonly STRATEGY_BASIC = "basic";
10
17
  static readonly STRATEGY_JWT = "jwt";
18
+ /** Every value of this class that `isValid` accepts. */
11
19
  static readonly SCHEME_SET: Set<string>;
20
+ /** Whether `value` is in `SCHEME_SET`. */
12
21
  static isValid(value: string): boolean;
13
22
  }
23
+ /** HTTP methods. */
14
24
  export declare class RequestMethods {
15
25
  static readonly HEAD = "HEAD";
16
26
  static readonly OPTIONS = "OPTIONS";
@@ -19,10 +29,14 @@ export declare class RequestMethods {
19
29
  static readonly PUT = "PUT";
20
30
  static readonly PATCH = "PATCH";
21
31
  static readonly DELETE = "DELETE";
32
+ /** Every value of this class that `isValid` accepts. */
22
33
  static readonly SCHEME_SET: Set<string>;
34
+ /** Whether `value` is in `SCHEME_SET`. */
23
35
  static isValid(value: string): boolean;
24
36
  }
37
+ /** What a request is for, which decides how its response is read: `SEND`, and react-admin's data provider calls. */
25
38
  export declare class RequestTypes {
39
+ /** A request that is not a react-admin call. */
26
40
  static readonly SEND = "SEND";
27
41
  static readonly GET_LIST = "GET_LIST";
28
42
  static readonly GET_ONE = "GET_ONE";
@@ -33,29 +47,43 @@ export declare class RequestTypes {
33
47
  static readonly UPDATE_MANY = "UPDATE_MANY";
34
48
  static readonly DELETE = "DELETE";
35
49
  static readonly DELETE_MANY = "DELETE_MANY";
50
+ /** Every value of this class that `isValid` accepts. */
36
51
  static readonly SCHEME_SET: Set<string>;
52
+ /** Whether `value` is in `SCHEME_SET`. */
37
53
  static isValid(value: string): boolean;
38
54
  }
55
+ /** The Web Storage areas `BrowserStorage` reads and writes. */
39
56
  export declare class StorageAreas {
57
+ /** `localStorage`. */
40
58
  static readonly LOCAL = "local";
59
+ /** `sessionStorage`. */
41
60
  static readonly SESSION = "session";
42
61
  }
62
+ /** How a request body is encoded; see `RequestBodyEncoder`. */
43
63
  export declare class RequestBodyTypes {
64
+ /** The body goes through as it is. */
44
65
  static readonly NONE = "none";
45
66
  static readonly FORM_DATA = "form-data";
46
67
  static readonly FORM_URL_ENCODED = "x-www-form-urlencoded";
47
68
  static readonly JSON = "json";
48
69
  static readonly BINARY = "binary";
70
+ /** Every value of this class that `isValid` accepts. */
49
71
  static readonly SCHEME_SET: Set<string>;
72
+ /** Whether `value` is in `SCHEME_SET`. */
50
73
  static isValid(value: string): boolean;
51
74
  }
75
+ /** Names of the build environments. */
52
76
  export declare class Environments {
53
77
  static readonly DEVELOPMENT = "development";
54
78
  static readonly PRODUCTION = "production";
79
+ /** Every value of this class that `isValid` accepts. */
55
80
  static readonly SCHEME_SET: Set<string>;
81
+ /** Whether `value` is in `SCHEME_SET`. */
56
82
  static isValid(value: string): boolean;
57
83
  }
84
+ /** Header names, lowercase, and patterns on header values. */
58
85
  export declare class HeaderConstants {
86
+ /** The header on a request body and on a response. */
59
87
  static readonly CONTENT_TYPE = "content-type";
60
88
  /**
61
89
  * content-range: <unit> <range-start>-<range-end>/<size>
@@ -63,24 +91,41 @@ export declare class HeaderConstants {
63
91
  * The positions are zero-indexed, the end inclusive; the total is `*` if unknown.
64
92
  */
65
93
  static readonly CONTENT_RANGE = "content-range";
94
+ /** Names the file of a file response. */
66
95
  static readonly CONTENT_DISPOSITION = "content-disposition";
96
+ /** Carries `<type> <token>`. */
67
97
  static readonly AUTHORIZATION = "authorization";
98
+ /** Names the provider of the token; sent only when the token names one. */
68
99
  static readonly X_AUTH_PROVIDER = "x-auth-provider";
100
+ /** The locale of the request, the header `useRequestHeaderLocale` sets by default. */
69
101
  static readonly X_LOCALE = "x-locale";
102
+ /** Carries `App.TIMEZONE`. */
70
103
  static readonly TIMEZONE = "timezone";
104
+ /** Carries `App.TIMEZONE_OFFSET`, in hours. */
71
105
  static readonly TIMEZONE_OFFSET = "timezone-offset";
106
+ /** Carries the tracing id of a request. */
72
107
  static readonly REQUEST_TRACING_ID = "x-request-id";
108
+ /** Carries a `RequestChannel` value. */
73
109
  static readonly REQUEST_CHANNEL = "x-request-channel";
110
+ /** Carries a `RequestCountData` value: what the request asks the server to return. */
74
111
  static readonly REQUEST_COUNT_DATA = "x-request-count";
112
+ /** Carries the count a server sends with a response that is not a list. */
75
113
  static readonly RESPONSE_COUNT_DATA = "x-response-count";
114
+ /** Content types read as text. */
76
115
  static readonly TEXTUAL_CONTENT_TYPE_RE: RegExp;
116
+ /** A `content-disposition` that marks a file download. */
77
117
  static readonly ATTACHMENT_CONTENT_DISPOSITION_RE: RegExp;
78
118
  }
119
+ /** The channels a request says it comes from, sent in `x-request-channel`. */
79
120
  export declare class RequestChannel {
121
+ /** A browser application; what a request says unless `requestTracingChannel` is set. */
80
122
  static readonly WEB = "100_WEB";
123
+ /** Every value of this class that `isValid` accepts. */
81
124
  static readonly SCHEME_SET: Set<string>;
125
+ /** Whether `value` is in `SCHEME_SET`. */
82
126
  static isValid(value: string): boolean;
83
127
  }
128
+ /** Whether a response carries a count, sent in `x-request-count`. */
84
129
  export declare class RequestCountData {
85
130
  /**
86
131
  * @description Only the data is returned in the response body
@@ -90,7 +135,9 @@ export declare class RequestCountData {
90
135
  * @description Both data and count are returned in the response body
91
136
  */
92
137
  static readonly DATA_WITH_COUNT = "1";
138
+ /** Every value of this class that `isValid` accepts. */
93
139
  static readonly SCHEME_SET: Set<string>;
140
+ /** Whether `value` is in `SCHEME_SET`. */
94
141
  static isValid(value: string): boolean;
95
142
  }
96
143
  //# sourceMappingURL=constants.d.ts.map
@@ -1,23 +1,33 @@
1
+ /** Values of the running environment, read once when the module loads. */
1
2
  export class App {
3
+ /** The IANA name of the timezone of the runtime. */
2
4
  static { this.TIMEZONE = Intl.DateTimeFormat().resolvedOptions().timeZone; }
5
+ /** The offset from UTC in hours, positive east of UTC (the opposite sign of `getTimezoneOffset()`). */
3
6
  static { this.TIMEZONE_OFFSET = -(new Date().getTimezoneOffset() / 60); }
7
+ /** In milliseconds. */
4
8
  static { this.DEFAULT_DEBOUNCE_TIME = 500; }
5
9
  }
10
+ /** Authorization schemes (`Basic`, `Bearer`) and strategies (`basic`, `jwt`). */
6
11
  export class Authentication {
12
+ /** The scheme in the `authorization` header. */
7
13
  static { this.TYPE_BASIC = 'Basic'; }
8
14
  static { this.TYPE_BEARER = 'Bearer'; }
15
+ /** The name of the auth strategy. */
9
16
  static { this.STRATEGY_BASIC = 'basic'; }
10
17
  static { this.STRATEGY_JWT = 'jwt'; }
18
+ /** Every value of this class that `isValid` accepts. */
11
19
  static { this.SCHEME_SET = new Set([
12
20
  this.TYPE_BASIC,
13
21
  this.TYPE_BEARER,
14
22
  this.STRATEGY_BASIC,
15
23
  this.STRATEGY_JWT,
16
24
  ]); }
25
+ /** Whether `value` is in `SCHEME_SET`. */
17
26
  static isValid(value) {
18
27
  return this.SCHEME_SET.has(value);
19
28
  }
20
29
  }
30
+ /** HTTP methods. */
21
31
  export class RequestMethods {
22
32
  static { this.HEAD = 'HEAD'; }
23
33
  static { this.OPTIONS = 'OPTIONS'; }
@@ -26,6 +36,7 @@ export class RequestMethods {
26
36
  static { this.PUT = 'PUT'; }
27
37
  static { this.PATCH = 'PATCH'; }
28
38
  static { this.DELETE = 'DELETE'; }
39
+ /** Every value of this class that `isValid` accepts. */
29
40
  static { this.SCHEME_SET = new Set([
30
41
  this.HEAD,
31
42
  this.OPTIONS,
@@ -35,11 +46,14 @@ export class RequestMethods {
35
46
  this.PATCH,
36
47
  this.DELETE,
37
48
  ]); }
49
+ /** Whether `value` is in `SCHEME_SET`. */
38
50
  static isValid(value) {
39
51
  return this.SCHEME_SET.has(value);
40
52
  }
41
53
  }
54
+ /** What a request is for, which decides how its response is read: `SEND`, and react-admin's data provider calls. */
42
55
  export class RequestTypes {
56
+ /** A request that is not a react-admin call. */
43
57
  static { this.SEND = 'SEND'; }
44
58
  // react-admin
45
59
  static { this.GET_LIST = 'GET_LIST'; }
@@ -51,6 +65,7 @@ export class RequestTypes {
51
65
  static { this.UPDATE_MANY = 'UPDATE_MANY'; }
52
66
  static { this.DELETE = 'DELETE'; }
53
67
  static { this.DELETE_MANY = 'DELETE_MANY'; }
68
+ /** Every value of this class that `isValid` accepts. */
54
69
  static { this.SCHEME_SET = new Set([
55
70
  this.SEND,
56
71
  this.GET_ONE,
@@ -63,20 +78,27 @@ export class RequestTypes {
63
78
  this.DELETE,
64
79
  this.DELETE_MANY,
65
80
  ]); }
81
+ /** Whether `value` is in `SCHEME_SET`. */
66
82
  static isValid(value) {
67
83
  return this.SCHEME_SET.has(value);
68
84
  }
69
85
  }
86
+ /** The Web Storage areas `BrowserStorage` reads and writes. */
70
87
  export class StorageAreas {
88
+ /** `localStorage`. */
71
89
  static { this.LOCAL = 'local'; }
90
+ /** `sessionStorage`. */
72
91
  static { this.SESSION = 'session'; }
73
92
  }
93
+ /** How a request body is encoded; see `RequestBodyEncoder`. */
74
94
  export class RequestBodyTypes {
95
+ /** The body goes through as it is. */
75
96
  static { this.NONE = 'none'; }
76
97
  static { this.FORM_DATA = 'form-data'; }
77
98
  static { this.FORM_URL_ENCODED = 'x-www-form-urlencoded'; }
78
99
  static { this.JSON = 'json'; }
79
100
  static { this.BINARY = 'binary'; }
101
+ /** Every value of this class that `isValid` accepts. */
80
102
  static { this.SCHEME_SET = new Set([
81
103
  this.NONE,
82
104
  this.FORM_DATA,
@@ -84,19 +106,25 @@ export class RequestBodyTypes {
84
106
  this.JSON,
85
107
  this.BINARY,
86
108
  ]); }
109
+ /** Whether `value` is in `SCHEME_SET`. */
87
110
  static isValid(value) {
88
111
  return this.SCHEME_SET.has(value);
89
112
  }
90
113
  }
114
+ /** Names of the build environments. */
91
115
  export class Environments {
92
116
  static { this.DEVELOPMENT = 'development'; }
93
117
  static { this.PRODUCTION = 'production'; }
118
+ /** Every value of this class that `isValid` accepts. */
94
119
  static { this.SCHEME_SET = new Set([this.DEVELOPMENT, this.PRODUCTION]); }
120
+ /** Whether `value` is in `SCHEME_SET`. */
95
121
  static isValid(value) {
96
122
  return this.SCHEME_SET.has(value);
97
123
  }
98
124
  }
125
+ /** Header names, lowercase, and patterns on header values. */
99
126
  export class HeaderConstants {
127
+ /** The header on a request body and on a response. */
100
128
  static { this.CONTENT_TYPE = 'content-type'; }
101
129
  /**
102
130
  * content-range: <unit> <range-start>-<range-end>/<size>
@@ -104,27 +132,44 @@ export class HeaderConstants {
104
132
  * The positions are zero-indexed, the end inclusive; the total is `*` if unknown.
105
133
  */
106
134
  static { this.CONTENT_RANGE = 'content-range'; }
135
+ /** Names the file of a file response. */
107
136
  static { this.CONTENT_DISPOSITION = 'content-disposition'; }
137
+ /** Carries `<type> <token>`. */
108
138
  static { this.AUTHORIZATION = 'authorization'; }
139
+ /** Names the provider of the token; sent only when the token names one. */
109
140
  static { this.X_AUTH_PROVIDER = 'x-auth-provider'; }
141
+ /** The locale of the request, the header `useRequestHeaderLocale` sets by default. */
110
142
  static { this.X_LOCALE = 'x-locale'; }
111
143
  // Lowercase: the service keys its header record by lowercased name.
144
+ /** Carries `App.TIMEZONE`. */
112
145
  static { this.TIMEZONE = 'timezone'; }
146
+ /** Carries `App.TIMEZONE_OFFSET`, in hours. */
113
147
  static { this.TIMEZONE_OFFSET = 'timezone-offset'; }
148
+ /** Carries the tracing id of a request. */
114
149
  static { this.REQUEST_TRACING_ID = 'x-request-id'; }
150
+ /** Carries a `RequestChannel` value. */
115
151
  static { this.REQUEST_CHANNEL = 'x-request-channel'; }
152
+ /** Carries a `RequestCountData` value: what the request asks the server to return. */
116
153
  static { this.REQUEST_COUNT_DATA = 'x-request-count'; }
154
+ /** Carries the count a server sends with a response that is not a list. */
117
155
  static { this.RESPONSE_COUNT_DATA = 'x-response-count'; }
156
+ /** Content types read as text. */
118
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. */
119
159
  static { this.ATTACHMENT_CONTENT_DISPOSITION_RE = /^attachment/i; }
120
160
  }
161
+ /** The channels a request says it comes from, sent in `x-request-channel`. */
121
162
  export class RequestChannel {
163
+ /** A browser application; what a request says unless `requestTracingChannel` is set. */
122
164
  static { this.WEB = '100_WEB'; }
165
+ /** Every value of this class that `isValid` accepts. */
123
166
  static { this.SCHEME_SET = new Set([this.WEB]); }
167
+ /** Whether `value` is in `SCHEME_SET`. */
124
168
  static isValid(value) {
125
169
  return this.SCHEME_SET.has(value);
126
170
  }
127
171
  }
172
+ /** Whether a response carries a count, sent in `x-request-count`. */
128
173
  export class RequestCountData {
129
174
  /**
130
175
  * @description Only the data is returned in the response body
@@ -134,7 +179,9 @@ export class RequestCountData {
134
179
  * @description Both data and count are returned in the response body
135
180
  */
136
181
  static { this.DATA_WITH_COUNT = '1'; }
182
+ /** Every value of this class that `isValid` accepts. */
137
183
  static { this.SCHEME_SET = new Set([this.DATA_ONLY, this.DATA_WITH_COUNT]); }
184
+ /** Whether `value` is in `SCHEME_SET`. */
138
185
  static isValid(value) {
139
186
  return this.SCHEME_SET.has(value);
140
187
  }
@@ -1,27 +1,43 @@
1
+ /** The container keys the kernel binds and reads. */
1
2
  export declare class CoreBindings {
3
+ /** The application itself, bound by `preConfigure`. */
2
4
  static readonly APPLICATION_INSTANCE = "@app/application/instance";
5
+ /** The `IApplicationInfo`, bound by `preConfigure`. */
3
6
  static readonly APPLICATION_INFO = "@app/application/info";
7
+ /** The auth provider. */
4
8
  static readonly DEFAULT_AUTH_PROVIDER = "@app/application/auth/default";
9
+ /** The i18n provider. */
5
10
  static readonly DEFAULT_I18N_PROVIDER = "@app/application/i18n/default";
11
+ /** The REST data provider. */
6
12
  static readonly DEFAULT_REST_DATA_PROVIDER = "@app/application/data/rest/default";
13
+ /** The `IAuthProviderOptions`. */
7
14
  static readonly AUTH_PROVIDER_OPTIONS = "@app/application/options/auth";
15
+ /** The `DefaultAuthService`. */
8
16
  static readonly DEFAULT_AUTH_SERVICE = "@app/application/service/auth/default";
17
+ /** The `IRestDataProviderOptions`. */
9
18
  static readonly REST_DATA_PROVIDER_OPTIONS = "@app/application/options/rest/data";
19
+ /** The options of the i18n provider. */
10
20
  static readonly I18N_PROVIDER_OPTIONS = "@app/application/options/i18n";
11
21
  /** The `features()` an application mounts, bound by `preConfigure()`. */
12
22
  static readonly FEATURES = "@app/application/features";
13
23
  /** An `IPermissionProvider`, bound by the application; unbound means every check passes. */
14
24
  static readonly PERMISSION_PROVIDER = "@app/application/permission/provider";
15
25
  }
26
+ /** The `localStorage` keys the kernel owns. */
16
27
  export declare class LocalStorageKeys {
17
28
  /** Everything under this prefix is the session: `DefaultAuthService.cleanUp` removes it all. */
18
29
  static readonly PREFIX_AUTH = "@app/auth/";
19
30
  /** The namespace `BrowserStorage` recommends for the keys of an application. */
20
31
  static readonly PREFIX_STORE = "@app/store/";
32
+ /** The stored `IAuthTokenRecord`, as JSON. */
21
33
  static readonly KEY_AUTH_TOKEN = "@app/auth/token";
34
+ /** The stored identity (`userId`, `username`, `referenceId`, `provider`), as JSON. */
22
35
  static readonly KEY_AUTH_IDENTITY = "@app/auth/identity";
36
+ /** The stored roles, as a JSON array of names. */
23
37
  static readonly KEY_AUTH_PERMISSION = "@app/auth/permission";
38
+ /** The three session keys. */
24
39
  static readonly SCHEME_SET: Set<string>;
40
+ /** Whether `value` is a session key in `SCHEME_SET`. */
25
41
  static isValid(value: string): boolean;
26
42
  }
27
43
  //# sourceMappingURL=keys.d.ts.map
@@ -1,31 +1,47 @@
1
+ /** The container keys the kernel binds and reads. */
1
2
  export class CoreBindings {
3
+ /** The application itself, bound by `preConfigure`. */
2
4
  static { this.APPLICATION_INSTANCE = '@app/application/instance'; }
5
+ /** The `IApplicationInfo`, bound by `preConfigure`. */
3
6
  static { this.APPLICATION_INFO = '@app/application/info'; }
7
+ /** The auth provider. */
4
8
  static { this.DEFAULT_AUTH_PROVIDER = '@app/application/auth/default'; }
9
+ /** The i18n provider. */
5
10
  static { this.DEFAULT_I18N_PROVIDER = '@app/application/i18n/default'; }
11
+ /** The REST data provider. */
6
12
  static { this.DEFAULT_REST_DATA_PROVIDER = '@app/application/data/rest/default'; }
13
+ /** The `IAuthProviderOptions`. */
7
14
  static { this.AUTH_PROVIDER_OPTIONS = '@app/application/options/auth'; }
15
+ /** The `DefaultAuthService`. */
8
16
  static { this.DEFAULT_AUTH_SERVICE = '@app/application/service/auth/default'; }
17
+ /** The `IRestDataProviderOptions`. */
9
18
  static { this.REST_DATA_PROVIDER_OPTIONS = '@app/application/options/rest/data'; }
19
+ /** The options of the i18n provider. */
10
20
  static { this.I18N_PROVIDER_OPTIONS = '@app/application/options/i18n'; }
11
21
  /** The `features()` an application mounts, bound by `preConfigure()`. */
12
22
  static { this.FEATURES = '@app/application/features'; }
13
23
  /** An `IPermissionProvider`, bound by the application; unbound means every check passes. */
14
24
  static { this.PERMISSION_PROVIDER = '@app/application/permission/provider'; }
15
25
  }
26
+ /** The `localStorage` keys the kernel owns. */
16
27
  export class LocalStorageKeys {
17
28
  /** Everything under this prefix is the session: `DefaultAuthService.cleanUp` removes it all. */
18
29
  static { this.PREFIX_AUTH = '@app/auth/'; }
19
30
  /** The namespace `BrowserStorage` recommends for the keys of an application. */
20
31
  static { this.PREFIX_STORE = '@app/store/'; }
32
+ /** The stored `IAuthTokenRecord`, as JSON. */
21
33
  static { this.KEY_AUTH_TOKEN = '@app/auth/token'; }
34
+ /** The stored identity (`userId`, `username`, `referenceId`, `provider`), as JSON. */
22
35
  static { this.KEY_AUTH_IDENTITY = '@app/auth/identity'; }
36
+ /** The stored roles, as a JSON array of names. */
23
37
  static { this.KEY_AUTH_PERMISSION = '@app/auth/permission'; }
38
+ /** The three session keys. */
24
39
  static { this.SCHEME_SET = new Set([
25
40
  this.KEY_AUTH_TOKEN,
26
41
  this.KEY_AUTH_IDENTITY,
27
42
  this.KEY_AUTH_PERMISSION,
28
43
  ]); }
44
+ /** Whether `value` is a session key in `SCHEME_SET`. */
29
45
  static isValid(value) {
30
46
  return this.SCHEME_SET.has(value);
31
47
  }
@@ -3,41 +3,67 @@ import type { TBuildInfoRecord } from '@venizia/ignis-helpers/core';
3
3
  import type { TClass } from '@venizia/ignis-inversion';
4
4
  import type { TExtraRequest } from '@venizia/ignis-kernel/repository';
5
5
  import type { Environments, RequestBodyTypes, RequestCountData, RequestMethods, RequestTypes, StorageAreas } from './constants.js';
6
+ /** A record id: a string or a number. */
6
7
  export type IdType = string | number;
7
8
  export type { AnyObject, AnyType, TConstValue, TNumberConstValue, TPrettify, TStringConstValue, ValueOf, ValueOptional, ValueOptionalExcept, ValueOrPromise, };
9
+ /** One of the `RequestMethods` values. */
8
10
  export type TRequestMethod = TStringConstValue<typeof RequestMethods>;
11
+ /** One of the `Environments` values. */
9
12
  export type TEnvironment = TStringConstValue<typeof Environments>;
13
+ /** What `IDataProvider.send` takes. */
10
14
  export interface ISendParams {
15
+ /** Required: `send` throws without it. */
11
16
  method?: TRequestMethod;
17
+ /** How the response is read. `RequestTypes.SEND` when absent. */
12
18
  requestType?: TRequestType;
19
+ /** How `body` is encoded; it goes through as JSON when absent. */
13
20
  bodyType?: TRequestBodyType;
14
21
  body?: unknown;
22
+ /** Sent as the query string of the request. */
15
23
  query?: Record<string, unknown>;
24
+ /** Added to the headers of this request. */
16
25
  headers?: Record<string, string | number>;
26
+ /**
27
+ * Whether the response carries a count; sent in `x-request-count`.
28
+ * @default RequestCountData.DATA_ONLY
29
+ */
17
30
  requestCountData?: TConstValue<typeof RequestCountData>;
18
31
  /** The list extras to ask the route for, sent in `x-request-extra`. */
19
32
  extra?: TExtraRequest;
20
33
  }
21
34
  /** What `IDataProvider.send` answers: the network service's response. */
22
35
  export type ISendResponse<T = unknown> = INetworkResponse<T>;
36
+ /** One of the `RequestBodyTypes` values. */
23
37
  export type TRequestBodyType = TStringConstValue<typeof RequestBodyTypes>;
38
+ /** One of the `StorageAreas` values. */
24
39
  export type TStorageArea = TStringConstValue<typeof StorageAreas>;
25
40
  /** How `BrowserStorage` turns a value into text and back. `decode` may throw: `get` then gives the fallback. */
26
41
  export interface IStorageCodec<TValue> {
27
42
  encode: (value: TValue) => string;
28
43
  decode: (text: string) => TValue;
29
44
  }
45
+ /** One of the `RequestTypes` values. */
30
46
  export type TRequestType = TStringConstValue<typeof RequestTypes>;
47
+ /** What `DefaultNetworkRequestService.getRequestProps` takes. */
31
48
  export interface IGetRequestPropsParams {
49
+ /** Decides whether the request goes without a token (`noAuthPaths`, `noAuthPathRegex`). */
32
50
  resource: string;
51
+ /**
52
+ * Whether the response carries a count.
53
+ * @default RequestCountData.DATA_ONLY
54
+ */
33
55
  requestCountData?: TConstValue<typeof RequestCountData>;
34
56
  body?: unknown;
57
+ /** How `body` is encoded. */
35
58
  bodyType?: TRequestBodyType;
59
+ /** Gives the request channel. */
36
60
  restDataProviderOptions: IRestDataProviderOptions;
61
+ /** Gives the name the tracing id starts with. */
37
62
  applicationInfo: IApplicationInfo;
38
63
  /** The list extras to ask the route for, sent in `x-request-extra`. */
39
64
  extra?: TExtraRequest;
40
65
  }
66
+ /** The headers and the encoded body of a request. */
41
67
  export interface IGetRequestPropsResult {
42
68
  headers?: HeadersInit;
43
69
  body?: unknown;
@@ -59,18 +85,47 @@ export interface ISignInSession {
59
85
  /** Data only: where the auth provider talks to. Behaviour is in `DefaultAuthProvider`'s protected hooks. */
60
86
  export interface IAuthProviderOptions {
61
87
  paths?: {
62
- /** Where `login` posts. Default `/auth/sign-in`, the IGNIS auth controller's route. */
88
+ /**
89
+ * Where `login` posts: the IGNIS auth controller's route.
90
+ * @default '/auth/sign-in'
91
+ */
63
92
  signIn?: string;
64
93
  /** Where `checkAuth` validates the stored token. Default: not called; the stored token is enough. */
65
94
  checkAuth?: string;
66
- /** Where the admin goes once `login` resolves. Default `/`. */
95
+ /**
96
+ * Where the admin goes once `login` resolves.
97
+ * @default '/'
98
+ */
67
99
  afterLogin?: string;
68
100
  };
69
101
  }
102
+ /** How a request recovers from a 401. */
70
103
  export interface IAuthRecoveryOptions {
71
- /** A request to this path never starts a refresh: it is the refresh. */
104
+ /**
105
+ * A request to this path never starts a refresh: it is the refresh. Listing it in `noAuthPaths`
106
+ * as well keeps the expired token off that request.
107
+ * @example
108
+ * ```ts
109
+ * import { configuration, CoreBindings, provide } from '@venizia/ardor';
110
+ *
111
+ * @configuration()
112
+ * export class ApiConfiguration {
113
+ * @provide({ key: CoreBindings.REST_DATA_PROVIDER_OPTIONS })
114
+ * restDataProviderOptions() {
115
+ * return {
116
+ * url: 'https://api.example.com',
117
+ * // The refresh path is also a no-auth path: the expired token stays off that request, so the
118
+ * // server identifies the session another way, such as a cookie.
119
+ * noAuthPaths: ['/auth/sign-in', '/auth/refresh'],
120
+ * authRecovery: { refreshTokenPath: '/auth/refresh' },
121
+ * };
122
+ * }
123
+ * }
124
+ * ```
125
+ */
72
126
  refreshTokenPath?: string;
73
127
  }
128
+ /** One pattern or a list; a string is compiled with `new RegExp(...)`. */
74
129
  export type TNoAuthPathRegex = string | RegExp | Array<string | RegExp>;
75
130
  /**
76
131
  * Data only. A request that matches goes without an `Authorization` header; to send none at all (an
@@ -87,14 +142,23 @@ export interface INoAuthOptions {
87
142
  */
88
143
  noAuthPathRegex?: TNoAuthPathRegex;
89
144
  }
145
+ /** Data only: where and how the REST data provider sends. */
90
146
  export interface IRestDataProviderOptions extends INoAuthOptions {
147
+ /** The base URL requests are sent to. */
91
148
  url: string;
92
- /** Sent in `x-request-channel`. Default `RequestChannel.WEB`. */
149
+ /**
150
+ * Sent in `x-request-channel`.
151
+ * @default RequestChannel.WEB
152
+ */
93
153
  requestTracingChannel?: string;
154
+ /** Sent with every request. */
94
155
  headers?: HeadersInit;
156
+ /** Enables the refresh-and-retry after a 401. */
95
157
  authRecovery?: IAuthRecoveryOptions;
96
158
  }
159
+ /** The token an application is signed in with. */
97
160
  export interface IAuthTokenRecord {
161
+ /** The authorization scheme; the service sends `Bearer` when it is empty or absent. */
98
162
  type?: string;
99
163
  value: string;
100
164
  provider?: string;
@@ -116,7 +180,9 @@ export interface IDataSourceAuth {
116
180
  }
117
181
  /** What `DefaultNetworkRequestService.doRequest` answers. */
118
182
  export interface INetworkResponse<TResult = unknown> {
183
+ /** The response body, or its rows for a list. */
119
184
  data: TResult;
185
+ /** The count the server sent, in the body or in `x-response-count`; absent when it sent none. */
120
186
  count?: number;
121
187
  /** GET_LIST and GET_MANY_REFERENCE: the total of `Content-Range`, else the page's own row count. */
122
188
  total?: number;
@@ -136,6 +202,7 @@ export interface IFeatureBase {
136
202
  /**
137
203
  * The feature's `@configuration()` classes, by value. Referencing them keeps a bundler from
138
204
  * dropping a module nothing else imports, and `start()` checks each was discovered.
205
+ * @default []
139
206
  */
140
207
  configurations?: Array<TClass<unknown>>;
141
208
  /** What the feature checks, in the application's vocabulary. Declared for a role editor; ARDOR enforces nothing. */
@@ -162,18 +229,31 @@ export interface IPermissionProvider {
162
229
  record?: unknown;
163
230
  }): Promise<boolean>;
164
231
  }
232
+ /** The contract of an application: lifecycle hooks, registration of artifacts, and `start`. */
165
233
  export interface IArdorApplication {
234
+ /** Binds the application instance and info, then the discovered, feature and listed classes. */
166
235
  preConfigure(): ValueOrPromise<void>;
236
+ /** Runs after `preConfigure` in `start`. */
167
237
  postConfigure(): ValueOrPromise<void>;
238
+ /** The application's own bindings, bound last in `preConfigure`. */
168
239
  bindContext(): ValueOrPromise<void>;
240
+ /** Classes bound by key as singletons. */
169
241
  bindingList(): Record<string, TClass<unknown>>;
242
+ /** The features this application mounts. */
170
243
  features(): Array<IFeatureBase>;
244
+ /** The artifact indexes `start` checks every stereotyped class against. */
171
245
  artifacts(): Array<IArtifactIndex>;
246
+ /** Binds `value` under `<scope>.<ClassName>` as a singleton. */
172
247
  injectable<T>(scope: string, value: TClass<T>, tags?: Array<string>): void;
248
+ /** Binds `value` in the service namespace. */
173
249
  service<T>(value: TClass<T>): unknown;
250
+ /** Binds `value` in the repository namespace. */
174
251
  repository<T>(value: TClass<T>): unknown;
252
+ /** Binds `value` in the data source namespace. */
175
253
  dataSource<T>(value: TClass<T>): unknown;
254
+ /** Binds `value` in the component namespace. */
176
255
  component<T>(value: TClass<T>): unknown;
256
+ /** Runs the whole startup: resolves the indexes, then `preConfigure`, then `postConfigure`. */
177
257
  start(): ValueOrPromise<void>;
178
258
  }
179
259
  type TDeepPath = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
@@ -187,9 +267,11 @@ type TIsAny<TValue> = 0 extends 1 & TValue ? true : false;
187
267
  export type TPaths<T, DeepLevel extends number = 10> = DeepLevel extends 0 ? never : T extends Array<AnyType> | TPathLeaf ? never : T extends object ? {
188
268
  [K in keyof T]-?: K extends string | number ? TIsAny<T[K]> extends true ? `${K}` : NonNullable<T[K]> extends Array<AnyType> | TPathLeaf ? `${K}` : NonNullable<T[K]> extends object ? `${K}` | `${K}.${TPaths<NonNullable<T[K]>, TDeepPath[DeepLevel]>}` : `${K}` : never;
189
269
  }[keyof T] : never;
270
+ /** The dotted paths of an object type, to `DeepLevel` levels (10 by default); unlike `TPaths`, only the paths down to a leaf value. */
190
271
  export type TFullPaths<T, DeepLevel extends number = 10> = DeepLevel extends never ? never : T extends Array<infer U> ? TFullPaths<U> : T extends object ? {
191
272
  [K in keyof T]-?: K extends string | number ? T[K] extends Array<any> | object ? `${K}.${TFullPaths<T[K], TDeepPath[DeepLevel]>}` : `${K}` : never;
192
273
  }[keyof T] : never;
274
+ /** What an application is: bound under `CoreBindings.APPLICATION_INFO`, and the name a tracing id starts with. */
193
275
  export interface IApplicationInfo {
194
276
  name: string;
195
277
  version: string;
@@ -4,6 +4,7 @@ export declare class AuthTokenStore {
4
4
  private static readonly logger;
5
5
  /** The stored token, or `undefined` when none is stored, it is unusable, or there is no `localStorage`. */
6
6
  static read(): IAuthTokenRecord | undefined;
7
+ /** Stores the token with its `provider` under `LocalStorageKeys.KEY_AUTH_TOKEN`. Throws when `localStorage` is not available. */
7
8
  static write(opts: {
8
9
  token: {
9
10
  value: string;
@@ -23,6 +23,7 @@ export class AuthTokenStore {
23
23
  return undefined;
24
24
  }
25
25
  }
26
+ /** Stores the token with its `provider` under `LocalStorageKeys.KEY_AUTH_TOKEN`. Throws when `localStorage` is not available. */
26
27
  static write(opts) {
27
28
  // Not a silent skip: a sign-in that is not kept would look like it worked.
28
29
  if (typeof localStorage === 'undefined') {
@@ -15,6 +15,7 @@ export declare class AuthRecovery {
15
15
  refresh: () => Promise<boolean>;
16
16
  /** Runs once when the refresh threw. */
17
17
  onFailure: () => Promise<void>;
18
+ /** Whether the request, given by its paths, goes without a token; such a request never recovers. */
18
19
  isNoAuthPath: (paths: string[]) => boolean;
19
20
  });
20
21
  /** Once for every 401 in flight: the callers share one `refresh`. `true` when the token was refreshed. */
@@ -6,6 +6,7 @@ export interface IEncodedBody {
6
6
  }
7
7
  /** The body types that go through as they are, under the JSON content type. */
8
8
  type TPassThroughBodyType = typeof RequestBodyTypes.JSON | typeof RequestBodyTypes.NONE | typeof RequestBodyTypes.BINARY;
9
+ /** Turns a request body into what `fetch` sends, by `RequestBodyTypes`. */
9
10
  export declare class RequestBodyEncoder {
10
11
  /**
11
12
  * The body as it is sent and the content type to send it under. The overloads give the type of what
@@ -1,6 +1,7 @@
1
1
  import { getError } from '@venizia/ignis-inversion';
2
2
  import { RequestBodyTypes } from '../../common/index.js';
3
3
  import { ValueUtility } from '../../utilities/index.js';
4
+ /** Turns a request body into what `fetch` sends, by `RequestBodyTypes`. */
4
5
  export class RequestBodyEncoder {
5
6
  static encode(opts) {
6
7
  const { bodyType, body } = opts;
@@ -1,4 +1,5 @@
1
1
  import { type INetworkResponse, RequestCountData, type TConstValue, type TRequestType } from '../../common/index.js';
2
+ /** Reads a `Response` into an `INetworkResponse`, and an error response into an error. */
2
3
  export declare class ResponseReader {
3
4
  /** The server wraps an error body under this key; both transports unwrap it. */
4
5
  static readonly ERROR_ROOT_KEY = "error";
@@ -8,6 +9,13 @@ export declare class ResponseReader {
8
9
  type: TRequestType;
9
10
  requestCountData?: TConstValue<typeof RequestCountData>;
10
11
  }): Promise<INetworkResponse<TResult>>;
12
+ /**
13
+ * Shapes a parsed body by request type. `GET_LIST` and `GET_MANY_REFERENCE` give `data` as an
14
+ * array and `total` from `Content-Range`, else the row count; with `RequestCountData.DATA_WITH_COUNT`
15
+ * the body must be `{ data, count }`, or it throws. Any other type gives `data` as is, and `count`
16
+ * from `x-response-count` when that is a number; with `DATA_WITH_COUNT` it returns the
17
+ * `{ data, count }` body unchanged.
18
+ */
11
19
  static convert<TData = unknown>(opts: {
12
20
  response: {
13
21
  data: TData | {
@@ -5,6 +5,7 @@ import { HeaderConstants, RequestCountData, RequestTypes, } from '../../common/i
5
5
  const isCountedBody = (value) => {
6
6
  return typeof value === 'object' && value !== null && 'data' in value && 'count' in value;
7
7
  };
8
+ /** Reads a `Response` into an `INetworkResponse`, and an error response into an error. */
8
9
  export class ResponseReader {
9
10
  /** The server wraps an error body under this key; both transports unwrap it. */
10
11
  static { this.ERROR_ROOT_KEY = 'error'; }
@@ -41,6 +42,13 @@ export class ResponseReader {
41
42
  });
42
43
  return extra ? { ...converted, extra } : converted;
43
44
  }
45
+ /**
46
+ * Shapes a parsed body by request type. `GET_LIST` and `GET_MANY_REFERENCE` give `data` as an
47
+ * array and `total` from `Content-Range`, else the row count; with `RequestCountData.DATA_WITH_COUNT`
48
+ * the body must be `{ data, count }`, or it throws. Any other type gives `data` as is, and `count`
49
+ * from `x-response-count` when that is a number; with `DATA_WITH_COUNT` it returns the
50
+ * `{ data, count }` body unchanged.
51
+ */
44
52
  static convert(opts) {
45
53
  const { response: { data, headers }, type, requestCountData, } = opts;
46
54
  switch (type) {
@@ -35,6 +35,7 @@ export declare class BrowserStorage {
35
35
  storage?: TStorageArea;
36
36
  codec?: IStorageCodec<TValue>;
37
37
  }): boolean;
38
+ /** Removes the key; `false` when it is under `LocalStorageKeys.PREFIX_AUTH`, when there is no such area, or when storage throws. */
38
39
  static remove(opts: {
39
40
  key: string;
40
41
  storage?: TStorageArea;
@@ -42,6 +43,7 @@ export declare class BrowserStorage {
42
43
  /** The keys of the area, only those that start with `prefix` when it is given. Lists the session keys too. */
43
44
  static keys(opts?: {
44
45
  storage?: TStorageArea;
46
+ /** @default '' */
45
47
  prefix?: string;
46
48
  }): Array<string>;
47
49
  /**
@@ -53,6 +53,7 @@ export class BrowserStorage {
53
53
  },
54
54
  });
55
55
  }
56
+ /** Removes the key; `false` when it is under `LocalStorageKeys.PREFIX_AUTH`, when there is no such area, or when storage throws. */
56
57
  static remove(opts) {
57
58
  return BrowserStorage.write({ ...opts, run: (area) => area.removeItem(opts.key) });
58
59
  }
@@ -1,4 +1,6 @@
1
+ /** Checks of the runtime. */
1
2
  export declare class BrowserUtility {
3
+ /** Whether a global `window` exists. */
2
4
  static isBrowser(): boolean;
3
5
  }
4
6
  //# sourceMappingURL=browser.d.ts.map
@@ -1,4 +1,6 @@
1
+ /** Checks of the runtime. */
1
2
  export class BrowserUtility {
3
+ /** Whether a global `window` exists. */
2
4
  static isBrowser() {
3
5
  return typeof window !== 'undefined';
4
6
  }
@@ -1,3 +1,4 @@
1
+ /** Helpers over `Blob` and file data. */
1
2
  export declare class FileUtility {
2
3
  /** The blob as a `data:` URL. */
3
4
  static toDataUrl(opts: {
@@ -1,3 +1,4 @@
1
+ /** Helpers over `Blob` and file data. */
1
2
  export class FileUtility {
2
3
  /** The blob as a `data:` URL. */
3
4
  static toDataUrl(opts) {
@@ -6,10 +6,14 @@ export declare const RUNTIME_CONFIG_GLOBAL = "__APP_CONFIG__";
6
6
  /** The `normalized.code` of the error `RuntimeConfig.get` throws for a required value that is not set; the key is in its `extra.key`. */
7
7
  export declare const RUNTIME_CONFIG_REQUIRED_CODE = "ardor.runtime_config.required";
8
8
  interface IRuntimeConfigOptions {
9
+ /** The name looked up in `window.__APP_CONFIG__` and in `buildTimeEnv`. */
9
10
  key: string;
11
+ /** The build-time source, normally `import.meta.env`. */
10
12
  buildTimeEnv?: Record<string, unknown>;
13
+ /** Used when neither source has a non-empty string for `key`. */
11
14
  defaultValue?: string;
12
15
  }
16
+ /** Reads configuration a deployment can change without a rebuild. */
13
17
  export declare class RuntimeConfig {
14
18
  /**
15
19
  * One config value: the runtime one (`window.__APP_CONFIG__`), else the build-time one
@@ -18,6 +18,7 @@ const readString = (opts) => {
18
18
  const value = Reflect.get(source, key);
19
19
  return typeof value === 'string' && value !== '' ? value : undefined;
20
20
  };
21
+ /** Reads configuration a deployment can change without a rebuild. */
21
22
  export class RuntimeConfig {
22
23
  static get(opts) {
23
24
  const { key, buildTimeEnv, defaultValue, required } = opts;
@@ -1,4 +1,5 @@
1
1
  import type { IStorageCodec } from '../common/index.js';
2
+ /** The codecs `BrowserStorage` takes, in place of its JSON default. */
2
3
  export declare class StorageCodecs {
3
4
  /** A bare string, not JSON. Create once; outside `allowed`, decode and encode throw. */
4
5
  static text<TText extends string = string>(opts?: {
@@ -1,4 +1,5 @@
1
1
  import { getError } from '@venizia/ignis-inversion';
2
+ /** The codecs `BrowserStorage` takes, in place of its JSON default. */
2
3
  export class StorageCodecs {
3
4
  /** A bare string, not JSON. Create once; outside `allowed`, decode and encode throw. */
4
5
  static text(opts = {}) {
@@ -1,3 +1,4 @@
1
+ /** Checks of a value's kind. */
1
2
  export declare class ValueUtility {
2
3
  /** Positional on purpose: a type predicate narrows its own parameter. */
3
4
  static isDefined<TValue>(value: TValue | null | undefined): value is TValue;
@@ -7,9 +8,11 @@ export declare class ValueUtility {
7
8
  static isNumber(opts: {
8
9
  value: unknown;
9
10
  }): boolean;
11
+ /** A non-null object that is not an array. */
10
12
  static isObject(opts: {
11
13
  value: unknown;
12
14
  }): boolean;
15
+ /** Whether `new Date(value)` is a valid date; takes a string, a number or a `Date`. */
13
16
  static isValidDate(opts: {
14
17
  value: string | number | Date;
15
18
  }): boolean;
@@ -1,3 +1,4 @@
1
+ /** Checks of a value's kind. */
1
2
  export class ValueUtility {
2
3
  /** Positional on purpose: a type predicate narrows its own parameter. */
3
4
  static isDefined(value) {
@@ -15,10 +16,12 @@ export class ValueUtility {
15
16
  }
16
17
  return !Number.isNaN(Number.parseFloat(String(value))) && Number.isFinite(Number(value));
17
18
  }
19
+ /** A non-null object that is not an array. */
18
20
  static isObject(opts) {
19
21
  const { value } = opts;
20
22
  return typeof value === 'object' && value !== null && !Array.isArray(value);
21
23
  }
24
+ /** Whether `new Date(value)` is a valid date; takes a string, a number or a `Date`. */
22
25
  static isValidDate(opts) {
23
26
  const date = new Date(opts.value);
24
27
  return !Number.isNaN(date.valueOf());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@venizia/ardor-kernel",
3
- "version": "0.4.8-1",
3
+ "version": "0.4.8-2",
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",
@@ -68,12 +68,12 @@
68
68
  "devDependencies": {
69
69
  "@size-limit/preset-small-lib": "^14.2.0",
70
70
  "@types/bun": "^1.4.3",
71
- "@venizia/dev-configs": "^0.4.8-0",
72
- "@venizia/ignis-connectors": "^0.4.8-0",
73
- "@venizia/ignis-filter": "^0.4.7-0",
74
- "@venizia/ignis-helpers": "^0.4.8-0",
75
- "@venizia/ignis-inversion": "^0.4.7-0",
76
- "@venizia/ignis-kernel": "^0.4.8-0",
71
+ "@venizia/dev-configs": "^0.4.8-1",
72
+ "@venizia/ignis-connectors": "^0.4.8-1",
73
+ "@venizia/ignis-filter": "^0.4.7-1",
74
+ "@venizia/ignis-helpers": "^0.4.8-1",
75
+ "@venizia/ignis-inversion": "^0.4.7-1",
76
+ "@venizia/ignis-kernel": "^0.4.8-1",
77
77
  "eslint": "^10.13.0",
78
78
  "oxlint": "1.89.0",
79
79
  "oxlint-tsgolint": "7.0.2004",
@@ -83,11 +83,11 @@
83
83
  "typescript": "^6.0.3"
84
84
  },
85
85
  "peerDependencies": {
86
- "@venizia/ignis-connectors": "^0.4.8-0",
87
- "@venizia/ignis-filter": "^0.4.7-0",
88
- "@venizia/ignis-helpers": "^0.4.8-0",
89
- "@venizia/ignis-inversion": "^0.4.7-0",
90
- "@venizia/ignis-kernel": "^0.4.8-0",
86
+ "@venizia/ignis-connectors": "^0.4.8-1",
87
+ "@venizia/ignis-filter": "^0.4.7-1",
88
+ "@venizia/ignis-helpers": "^0.4.8-1",
89
+ "@venizia/ignis-inversion": "^0.4.7-1",
90
+ "@venizia/ignis-kernel": "^0.4.8-1",
91
91
  "reflect-metadata": ">=0.2.2"
92
92
  },
93
93
  "peerDependenciesMeta": {