@venizia/ardor-kernel 0.5.0-12 → 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 +13 -13
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ which re-exports this package.
|
|
|
26
26
|
| Constants | `RequestMethods`, `RequestTypes`, `RequestBodyTypes`, `RequestCountData`, `Environments`, `App`, `StorageAreas`, `RequestChannel` |
|
|
27
27
|
| Network | `RequestBodyEncoder`, `NetworkResponseReader`, `AuthRecoveryHelper`, `AuthTokenStore` (the fetch transport is IGNIS's `NativeFetchNetworkRequest`) |
|
|
28
28
|
| Utilities | `ValueUtility` (`isDefined`, `isString`, `isNumber`), `BrowserUtility.isBrowser`, `FileUtility.toDataUrl` and `FileUtility.save`, `RuntimeConfig.get` and `RuntimeConfig.getRequired` (with `RUNTIME_CONFIG_GLOBAL`, `RUNTIME_CONFIG_REQUIRED_CODE` and `RUNTIME_CONFIG_INVALID_CODE`), `BrowserStorage`, `BrowserClipboard`, `StorageCodecs`; the earlier bare names are removed (`bun run ardor codemod namespace` moves your code) |
|
|
29
|
-
| Types | `IdType`, `
|
|
29
|
+
| Types | `IdType`, `IStoredAuthUser`, `ValueOrPromise`, `ValueOf`, `TConstValue`, `TPaths`, `TFullPaths`, `ISendParams`, `IRequestPayload`, `IRestDataProviderOptions`, `IApplicationInfo`, ... |
|
|
30
30
|
|
|
31
31
|
## License
|
|
32
32
|
|
|
@@ -1,31 +1,19 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* @default The scope declared on the class, else `BindingScopes.SINGLETON`
|
|
13
|
-
*/
|
|
14
|
-
scope?: TBindingScope;
|
|
15
|
-
/**
|
|
16
|
-
* `false` refuses to replace a binding already under the key, and keeps `bindingList()` from
|
|
17
|
-
* replacing this one; only `bindContext()` does.
|
|
18
|
-
* @default true
|
|
19
|
-
*/
|
|
20
|
-
allowOverride?: boolean;
|
|
1
|
+
import { type IArtifactRegistrationOptions } from '@venizia/ignis-kernel/metadata';
|
|
2
|
+
import { type Binding, Container, type TClass } from '@venizia/ignis-inversion';
|
|
3
|
+
import { type IApplicationInfo, type IArdorArtifactIndex, type IFeatureBase, type ValueOrPromise } from '../../common/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Per-registration choices for `service()`, `repository()`, `dataSource()` and `component()`.
|
|
6
|
+
* `binding` binds under that key instead of `<namespace>.<ClassName>`. `scope` defaults to the scope
|
|
7
|
+
* declared on the class, else `BindingScopes.SINGLETON`. `allowOverride` defaults to `true`; `false`
|
|
8
|
+
* refuses to replace a binding already under the key, and keeps `bindingList()` from replacing this one
|
|
9
|
+
* (only `bindContext()` does).
|
|
10
|
+
*/
|
|
11
|
+
export interface IArtifactRegistration extends Pick<IArtifactRegistrationOptions, 'binding' | 'scope' | 'allowOverride'> {
|
|
21
12
|
}
|
|
22
13
|
/**
|
|
23
14
|
* Two ways to register, as in IGNIS: stereotype discovery, or `service()`/`repository()`/
|
|
24
15
|
* `dataSource()`/`component()` by hand. Both record the key on the class. Every kind defaults to
|
|
25
16
|
* SINGLETON (IGNIS's server uses transient): a hook resolves on every render.
|
|
26
|
-
*
|
|
27
|
-
* @useWhen you write the application class of an ARDOR app and register its services, repositories, data sources and components
|
|
28
|
-
* @insteadOf wiring the container by hand
|
|
29
17
|
*/
|
|
30
18
|
export declare abstract class AbstractArdorApplication extends Container {
|
|
31
19
|
/** The application's own bindings; `preConfigure` runs it last, so they win over discovered and feature bindings. */
|
|
@@ -73,7 +61,7 @@ export declare abstract class AbstractArdorApplication extends Container {
|
|
|
73
61
|
* The generated artifact indexes (`ignis-artifacts generate`). Discovery still binds every
|
|
74
62
|
* stereotyped class; an index only holds each class by value and has `start()` check it.
|
|
75
63
|
*/
|
|
76
|
-
artifacts(): Array<
|
|
64
|
+
artifacts(): Array<IArdorArtifactIndex>;
|
|
77
65
|
/** The feature packages this application mounts, bound under `CoreBindings.FEATURES`. */
|
|
78
66
|
features(): Array<IFeatureBase>;
|
|
79
67
|
/**
|
|
@@ -15,9 +15,6 @@ const ArtifactIndexKinds = [
|
|
|
15
15
|
* Two ways to register, as in IGNIS: stereotype discovery, or `service()`/`repository()`/
|
|
16
16
|
* `dataSource()`/`component()` by hand. Both record the key on the class. Every kind defaults to
|
|
17
17
|
* SINGLETON (IGNIS's server uses transient): a hook resolves on every render.
|
|
18
|
-
*
|
|
19
|
-
* @useWhen you write the application class of an ARDOR app and register its services, repositories, data sources and components
|
|
20
|
-
* @insteadOf wiring the container by hand
|
|
21
18
|
*/
|
|
22
19
|
export class AbstractArdorApplication extends Container {
|
|
23
20
|
constructor() {
|
|
@@ -69,7 +66,7 @@ export class AbstractArdorApplication extends Container {
|
|
|
69
66
|
discovered: new Set(discovered),
|
|
70
67
|
});
|
|
71
68
|
const targets = discovered
|
|
72
|
-
.filter((target) => typeof target === 'function')
|
|
69
|
+
.filter((target) => typeof target === 'function' && typeof target.prototype === 'object')
|
|
73
70
|
.filter((target) => this.isSelected({ target }));
|
|
74
71
|
// Two classes a minifier named alike derive one key, and the second would silently replace the
|
|
75
72
|
// first. Checked here, never at decoration, so a hot reload that re-decorates a class is no error.
|
|
@@ -218,8 +215,9 @@ export class AbstractArdorApplication extends Container {
|
|
|
218
215
|
assertIndexed(opts) {
|
|
219
216
|
const { indexes, discovered } = opts;
|
|
220
217
|
for (const entry of indexes) {
|
|
221
|
-
const
|
|
222
|
-
|
|
218
|
+
const index = ArtifactGroup.isGroup(entry)
|
|
219
|
+
? entry.content
|
|
220
|
+
: entry;
|
|
223
221
|
if (!index) {
|
|
224
222
|
continue;
|
|
225
223
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import type { BaseService } from '../services/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Logs a failing method with its name, and its `resource` when the class has one, then rethrows.
|
|
4
|
-
*
|
|
5
|
-
* @useWhen a method of a repository or service should log its failure with its name and rethrow
|
|
6
|
-
* @insteadOf a try and catch that only logs
|
|
7
4
|
*/
|
|
8
5
|
export declare const api: () => (_target: BaseService, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
9
6
|
//# sourceMappingURL=api.d.ts.map
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Logs a failing method with its name, and its `resource` when the class has one, then rethrows.
|
|
3
|
-
*
|
|
4
|
-
* @useWhen a method of a repository or service should log its failure with its name and rethrow
|
|
5
|
-
* @insteadOf a try and catch that only logs
|
|
6
3
|
*/
|
|
7
4
|
export const api = () => {
|
|
8
5
|
return (_target, propertyKey, descriptor) => {
|
|
@@ -2,9 +2,6 @@ import { BaseHelper } from '@venizia/ignis-helpers/core';
|
|
|
2
2
|
import type { Container, IProvider } from '@venizia/ignis-inversion';
|
|
3
3
|
/**
|
|
4
4
|
* Base of a provider: `value` yields what the provider supplies, resolved through the container.
|
|
5
|
-
*
|
|
6
|
-
* @useWhen you write a provider that yields a value resolved through the container
|
|
7
|
-
* @insteadOf a hand-built singleton that reads the container
|
|
8
5
|
*/
|
|
9
6
|
export declare abstract class BaseProvider<T> extends BaseHelper implements IProvider<T> {
|
|
10
7
|
/** Produces the provided value. */
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { BaseHelper } from '@venizia/ignis-helpers/core';
|
|
2
2
|
/**
|
|
3
3
|
* Base of a provider: `value` yields what the provider supplies, resolved through the container.
|
|
4
|
-
*
|
|
5
|
-
* @useWhen you write a provider that yields a value resolved through the container
|
|
6
|
-
* @insteadOf a hand-built singleton that reads the container
|
|
7
4
|
*/
|
|
8
5
|
export class BaseProvider extends BaseHelper {
|
|
9
6
|
}
|
|
@@ -45,18 +45,11 @@ import type { DefaultAuthService } from '../services/auth.js';
|
|
|
45
45
|
* }
|
|
46
46
|
* }
|
|
47
47
|
* ```
|
|
48
|
-
*
|
|
49
|
-
* @useWhen access is decided by roles whose grant patterns sit in a table the application writes
|
|
50
|
-
* @insteadOf a hand-written permission check in each screen
|
|
51
48
|
*/
|
|
52
49
|
export declare class RolePermissionProvider extends BaseHelper implements IPermissionProvider {
|
|
53
50
|
private readonly authService;
|
|
54
51
|
private readonly grants;
|
|
55
52
|
constructor(authService: DefaultAuthService, options: IRolePermissionProviderOptions);
|
|
56
|
-
canAccess(opts:
|
|
57
|
-
resource: string;
|
|
58
|
-
action: string;
|
|
59
|
-
record?: unknown;
|
|
60
|
-
}): Promise<boolean>;
|
|
53
|
+
canAccess(opts: Parameters<IPermissionProvider['canAccess']>[0]): Promise<boolean>;
|
|
61
54
|
}
|
|
62
55
|
//# sourceMappingURL=role-permission.d.ts.map
|
|
@@ -84,9 +84,6 @@ class GrantPattern {
|
|
|
84
84
|
* }
|
|
85
85
|
* }
|
|
86
86
|
* ```
|
|
87
|
-
*
|
|
88
|
-
* @useWhen access is decided by roles whose grant patterns sit in a table the application writes
|
|
89
|
-
* @insteadOf a hand-written permission check in each screen
|
|
90
87
|
*/
|
|
91
88
|
let RolePermissionProvider = RolePermissionProvider_1 = class RolePermissionProvider extends BaseHelper {
|
|
92
89
|
constructor(authService, options) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type IApplicationInfo, type IAuthTokenRecord, type
|
|
1
|
+
import { type IApplicationInfo, type IAuthTokenRecord, type IStoredAuthUser, type IdType, type ISignInSession, type IScopedKeys } from '../../common/index.js';
|
|
2
2
|
import { BaseService } from './base.js';
|
|
3
3
|
/** What a subscriber of `DefaultAuthService` is told: `isExternal` is a change another tab of the application made. */
|
|
4
4
|
export interface IAuthChange {
|
|
@@ -6,10 +6,7 @@ export interface IAuthChange {
|
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* Keeps the signed-in session (token, identity, roles) in `localStorage`, everything under
|
|
9
|
-
* `keys.
|
|
10
|
-
*
|
|
11
|
-
* @useWhen you need the signed-in session (token, identity, roles) kept in `localStorage`
|
|
12
|
-
* @insteadOf reading and writing the token and roles in storage by hand
|
|
9
|
+
* `keys.prefixes.auth`: `LocalStorageKeys.PREFIX_AUTH`, or `@app/auth/<id>/` when the application has an `id`.
|
|
13
10
|
*/
|
|
14
11
|
export declare class DefaultAuthService extends BaseService {
|
|
15
12
|
private readonly listeners;
|
|
@@ -54,7 +51,7 @@ export declare class DefaultAuthService extends BaseService {
|
|
|
54
51
|
*/
|
|
55
52
|
private parseStored;
|
|
56
53
|
/** The stored identity; `{}` when nothing usable is stored, also outside a browser. */
|
|
57
|
-
getUser():
|
|
54
|
+
getUser(): IStoredAuthUser;
|
|
58
55
|
/** A stored identity is data from the browser: an object whose known fields, when present, have their type. */
|
|
59
56
|
private isAuthUser;
|
|
60
57
|
/**
|
|
@@ -78,17 +75,14 @@ export declare class DefaultAuthService extends BaseService {
|
|
|
78
75
|
* not available. Roles are stored only when `roles` is given.
|
|
79
76
|
*/
|
|
80
77
|
saveAuth(opts: {
|
|
81
|
-
userId:
|
|
78
|
+
userId: IdType;
|
|
82
79
|
/** @default '' */
|
|
83
80
|
username?: string;
|
|
84
81
|
/** @default '' */
|
|
85
82
|
provider?: string;
|
|
86
83
|
/** @default '' */
|
|
87
84
|
referenceId?: IdType;
|
|
88
|
-
token:
|
|
89
|
-
value: string;
|
|
90
|
-
type: string;
|
|
91
|
-
};
|
|
85
|
+
token: ISignInSession['token'];
|
|
92
86
|
/**
|
|
93
87
|
* The user's roles, where `getRoles` reads them. Left alone when absent, so a token refresh
|
|
94
88
|
* that saves only the new token keeps the roles; `[]` says the user has none.
|
|
@@ -102,7 +96,7 @@ export declare class DefaultAuthService extends BaseService {
|
|
|
102
96
|
*/
|
|
103
97
|
private isSessionKey;
|
|
104
98
|
/**
|
|
105
|
-
* Removes the session keys under `keys.
|
|
99
|
+
* Removes the session keys under `keys.prefixes.auth`, then notifies the subscribers; does nothing
|
|
106
100
|
* outside a browser. A service without an application `id` leaves the sessions of applications with
|
|
107
101
|
* an `id` alone.
|
|
108
102
|
*/
|
|
@@ -18,10 +18,7 @@ import { AuthTokenStore, BrowserStorage, StorageCodecs } from '../../utilities/i
|
|
|
18
18
|
import { BaseService } from './base.js';
|
|
19
19
|
/**
|
|
20
20
|
* Keeps the signed-in session (token, identity, roles) in `localStorage`, everything under
|
|
21
|
-
* `keys.
|
|
22
|
-
*
|
|
23
|
-
* @useWhen you need the signed-in session (token, identity, roles) kept in `localStorage`
|
|
24
|
-
* @insteadOf reading and writing the token and roles in storage by hand
|
|
21
|
+
* `keys.prefixes.auth`: `LocalStorageKeys.PREFIX_AUTH`, or `@app/auth/<id>/` when the application has an `id`.
|
|
25
22
|
*/
|
|
26
23
|
let DefaultAuthService = DefaultAuthService_1 = class DefaultAuthService extends BaseService {
|
|
27
24
|
/** A subclass with its own constructor passes `info` on to `super(info)`; otherwise its keys are the unscoped ones. */
|
|
@@ -249,14 +246,14 @@ let DefaultAuthService = DefaultAuthService_1 = class DefaultAuthService extends
|
|
|
249
246
|
*/
|
|
250
247
|
isSessionKey(opts) {
|
|
251
248
|
const { key } = opts;
|
|
252
|
-
if (!key.startsWith(this.keys.
|
|
249
|
+
if (!key.startsWith(this.keys.prefixes.auth)) {
|
|
253
250
|
return false;
|
|
254
251
|
}
|
|
255
|
-
return (this.keys.
|
|
256
|
-
!key.slice(this.keys.
|
|
252
|
+
return (this.keys.prefixes.auth !== LocalStorageKeys.PREFIX_AUTH ||
|
|
253
|
+
!key.slice(this.keys.prefixes.auth.length).includes('/'));
|
|
257
254
|
}
|
|
258
255
|
/**
|
|
259
|
-
* Removes the session keys under `keys.
|
|
256
|
+
* Removes the session keys under `keys.prefixes.auth`, then notifies the subscribers; does nothing
|
|
260
257
|
* outside a browser. A service without an application `id` leaves the sessions of applications with
|
|
261
258
|
* an `id` alone.
|
|
262
259
|
*/
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { BaseHelper } from '@venizia/ignis-helpers/core';
|
|
2
2
|
/**
|
|
3
3
|
* Base of the services of an application; a `BaseHelper` with a scoped logger.
|
|
4
|
-
*
|
|
5
|
-
* @useWhen you write a service of the application and want a scoped logger
|
|
6
|
-
* @insteadOf a service class that creates its own logger
|
|
7
4
|
*/
|
|
8
5
|
export declare class BaseService extends BaseHelper {
|
|
9
6
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { BaseHelper } from '@venizia/ignis-helpers/core';
|
|
2
2
|
/**
|
|
3
3
|
* Base of the services of an application; a `BaseHelper` with a scoped logger.
|
|
4
|
-
*
|
|
5
|
-
* @useWhen you write a service of the application and want a scoped logger
|
|
6
|
-
* @insteadOf a service class that creates its own logger
|
|
7
4
|
*/
|
|
8
5
|
export class BaseService extends BaseHelper {
|
|
9
6
|
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { type IApplicationInfo, type IAuthTokenRecord, type IGetRequestPropsParams, type IGetRequestPropsResult, type ISignInSession, type TNoAuthPathRegex, type TRequestTimeoutOptions } from '../../common/index.js';
|
|
2
|
+
import { type IEncodedBody, NetworkResponseReader } from '../../utilities/index.js';
|
|
3
|
+
import type { DefaultAuthService } from './auth.js';
|
|
4
|
+
import { BaseService } from './base.js';
|
|
5
|
+
/**
|
|
6
|
+
* What `DefaultNetworkRequestService` is built on: which requests go without a token, the token, the
|
|
7
|
+
* headers and body of a request, and the hooks that read data. It holds nothing about a request in
|
|
8
|
+
* flight.
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class AbstractNetworkRequestService extends BaseService {
|
|
11
|
+
/** Resources sent without a token, matched exactly: `noAuth.paths`. */
|
|
12
|
+
protected noAuthPaths?: string[];
|
|
13
|
+
/** `noAuth.regex` compiled; a resource matching any is sent without a token. */
|
|
14
|
+
protected noAuthPathRegexes: RegExp[];
|
|
15
|
+
/** Headers added to every request. */
|
|
16
|
+
protected headers: Headers;
|
|
17
|
+
protected authService?: DefaultAuthService;
|
|
18
|
+
/**
|
|
19
|
+
* The token under the unscoped session key (`AuthTokenStore.read`), `undefined` outside a browser, for an
|
|
20
|
+
* application with no `id`. With an application `id` the session is under other keys: use
|
|
21
|
+
* `createAuthTokenReader({ id })`, the `HttpDataSource` `getDataSourceAuth()` of the data provider, or `authService.getAuth`.
|
|
22
|
+
*/
|
|
23
|
+
static readAuthTokenFromStorage(): IAuthTokenRecord | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* A reader of the stored token of the application with this `id` (`IApplicationInfo.id`): the same
|
|
26
|
+
* key `DefaultAuthService.getAuth` reads (`LocalStorageKeys.scoped({ id }).token`). Without an `id` it
|
|
27
|
+
* is `readAuthTokenFromStorage`. Throws for an invalid `id`, when it is created.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* super({ baseUrl: '/api', authTokenResolver: DefaultNetworkRequestService.createAuthTokenReader({ id: 'shop' }) });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
static createAuthTokenReader(opts?: {
|
|
35
|
+
id?: string;
|
|
36
|
+
}): () => IAuthTokenRecord | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Throws for options that carry `noAuthPaths` or `noAuthPathRegex`, which `noAuth` replaced, and for
|
|
39
|
+
* a `noAuth` that is not `{ paths, regex }`: an ignored one would send the token to a path that is
|
|
40
|
+
* meant to go without it.
|
|
41
|
+
*/
|
|
42
|
+
static assertNoAuthOptions(opts: {
|
|
43
|
+
options: object;
|
|
44
|
+
/** The class that was given the options, named in the message. */
|
|
45
|
+
owner: string;
|
|
46
|
+
}): void;
|
|
47
|
+
/** What is wrong with a `noAuth` value: its shape, `paths` or `regex`; `undefined` when nothing is. */
|
|
48
|
+
private static findInvalidNoAuth;
|
|
49
|
+
/** Throws unless a timeout that is on has a positive integer `milliseconds`. */
|
|
50
|
+
static assertTimeout(opts: {
|
|
51
|
+
timeout?: TRequestTimeoutOptions;
|
|
52
|
+
}): void;
|
|
53
|
+
/**
|
|
54
|
+
* The token this service sends. The one way to supply a token: override it to read another
|
|
55
|
+
* store, or to hold the token in memory.
|
|
56
|
+
*/
|
|
57
|
+
protected resolveAuthToken(): IAuthTokenRecord | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Whether a request goes without a token: its `resource` is in `noAuth.paths`, or the resource, or
|
|
60
|
+
* the joined `paths`, matches `noAuth.regex`. To send no token at all (an API with no sign-in),
|
|
61
|
+
* set `noAuth: { regex: /./ }`.
|
|
62
|
+
*/
|
|
63
|
+
protected isNoAuthPath(opts: {
|
|
64
|
+
resource?: string;
|
|
65
|
+
paths?: string[];
|
|
66
|
+
}): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* The new token of a refresh response: `{ token: { value, type } }` or `{ token: '<jwt>' }`. A
|
|
69
|
+
* refresh keeps the same user, so nothing else is read. Override it for another shape. No token is
|
|
70
|
+
* a throw.
|
|
71
|
+
*/
|
|
72
|
+
protected readRefreshedToken(opts: {
|
|
73
|
+
data: unknown;
|
|
74
|
+
}): ISignInSession['token'];
|
|
75
|
+
/** Runs once when `refreshToken` threw. The place to send the user back to sign-in. */
|
|
76
|
+
protected onAuthFailure(): Promise<void>;
|
|
77
|
+
/** The tracing id of a request, sent in `x-request-id`. Default `<application name>_<uuid>`. */
|
|
78
|
+
protected buildRequestTracingId(opts: {
|
|
79
|
+
applicationInfo: IApplicationInfo;
|
|
80
|
+
}): string;
|
|
81
|
+
/** `noAuth.regex` as `RegExp`s; a string is compiled, and an invalid one is logged and dropped. */
|
|
82
|
+
protected compileNoAuthPathRegex(opts: {
|
|
83
|
+
input?: TNoAuthPathRegex;
|
|
84
|
+
}): RegExp[];
|
|
85
|
+
/**
|
|
86
|
+
* The `token` (`<type> <value>`, `Bearer` when the type is empty) and `provider` of the stored
|
|
87
|
+
* token. Throws an error with status 401 when there is no token.
|
|
88
|
+
*/
|
|
89
|
+
getRequestAuthorizationHeader(): {
|
|
90
|
+
provider: string | undefined;
|
|
91
|
+
token: string;
|
|
92
|
+
};
|
|
93
|
+
/** Adds headers to every request this service sends; a name already set is replaced, in any case. */
|
|
94
|
+
setHeaders(opts: {
|
|
95
|
+
headers: HeadersInit;
|
|
96
|
+
}): void;
|
|
97
|
+
/** Removes the headers set by name, in any case. */
|
|
98
|
+
removeHeaders(opts: {
|
|
99
|
+
keys: string[];
|
|
100
|
+
}): void;
|
|
101
|
+
/** The timezone, then whatever `setHeaders` holds now. Both transports send these. */
|
|
102
|
+
protected getSessionHeaders(): Record<string, string>;
|
|
103
|
+
/** The request channel (`RequestChannel.WEB` unless configured) and a fresh tracing id. */
|
|
104
|
+
protected getTracingHeaders(opts: Pick<IGetRequestPropsParams, 'restDataProviderOptions' | 'applicationInfo'>): Record<string, string>;
|
|
105
|
+
/**
|
|
106
|
+
* The session headers, plus `authorization` and `x-auth-provider` unless `resource` is a no-auth
|
|
107
|
+
* path. Throws a 401 error for any other resource when there is no token.
|
|
108
|
+
*/
|
|
109
|
+
getRequestHeader(opts: {
|
|
110
|
+
resource: string;
|
|
111
|
+
}): Record<string, string>;
|
|
112
|
+
/**
|
|
113
|
+
* The body as it is sent and the content type to send it under. Override to encode another way. It
|
|
114
|
+
* takes `body` and `bodyType`, not a `payload`: an override written for these names would otherwise
|
|
115
|
+
* receive the wrapper and send it.
|
|
116
|
+
*/
|
|
117
|
+
protected encodeBody(opts: {
|
|
118
|
+
bodyType?: string;
|
|
119
|
+
body: unknown;
|
|
120
|
+
}): IEncodedBody;
|
|
121
|
+
/**
|
|
122
|
+
* The headers (session, auth, tracing, `x-request-count`, the `extra` header, and the content type
|
|
123
|
+
* of the encoded body) and the encoded body of a request. Throws as `getRequestHeader` does.
|
|
124
|
+
*/
|
|
125
|
+
getRequestProps(params: IGetRequestPropsParams): IGetRequestPropsResult;
|
|
126
|
+
/** Reads a response by the request type. See `NetworkResponseReader.convert`. */
|
|
127
|
+
convertResponse(opts: Parameters<typeof NetworkResponseReader.convert>[0]): {
|
|
128
|
+
data: unknown;
|
|
129
|
+
count?: number;
|
|
130
|
+
total?: number;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=network-request-base.d.ts.map
|