@podium/client 5.0.21 → 5.0.22
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/types/client.d.ts +110 -0
- package/types/http-outgoing.d.ts +177 -0
- package/types/http.d.ts +29 -0
- package/types/resolver.cache.d.ts +31 -0
- package/types/resolver.content.d.ts +29 -0
- package/types/resolver.d.ts +35 -0
- package/types/resolver.fallback.d.ts +29 -0
- package/types/resolver.manifest.d.ts +27 -0
- package/types/resource.d.ts +89 -0
- package/types/response.d.ts +47 -0
- package/types/state.d.ts +33 -0
- package/types/utils.d.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [5.0.22](https://github.com/podium-lib/client/compare/v5.0.21...v5.0.22) (2024-05-15)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* generate type definitions before publish ([8189b01](https://github.com/podium-lib/client/commit/8189b01c54c733c760b02f2138803f9b64a6fee5))
|
|
7
|
+
|
|
1
8
|
## [5.0.21](https://github.com/podium-lib/client/compare/v5.0.20...v5.0.21) (2024-05-14)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {import('./resource.js').default} PodiumClientResource
|
|
4
|
+
* @typedef {import('./resource.js').PodiumClientResourceOptions} PodiumClientResourceOptions
|
|
5
|
+
* @typedef {import('./response.js').default} PodiumClientResponse
|
|
6
|
+
* @typedef {import('./http-outgoing.js').PodiumRedirect} PodiumRedirect
|
|
7
|
+
* @typedef {import('@podium/schemas').PodletManifestSchema} PodletManifest
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {object} PodiumClientOptions
|
|
11
|
+
* @property {string} name
|
|
12
|
+
* @property {import('abslog').AbstractLoggerOptions} [logger]
|
|
13
|
+
* @property {number} [retries=4]
|
|
14
|
+
* @property {number} [timeout=1000] In milliseconds
|
|
15
|
+
* @property {number} [maxAge=Infinity]
|
|
16
|
+
* @property {boolean} [rejectUnauthorized=true]
|
|
17
|
+
* @property {number} [resolveThreshold]
|
|
18
|
+
* @property {number} [resolveMax]
|
|
19
|
+
* @property {import('http').Agent} [httpAgent]
|
|
20
|
+
* @property {import('https').Agent} [httpsAgent]
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {object} RegisterOptions
|
|
24
|
+
* @property {string} name A unique name for the podlet
|
|
25
|
+
* @property {string} uri URL to the podlet's `manifest.json`
|
|
26
|
+
* @property {number} [retries=4] Number of retries before serving fallback
|
|
27
|
+
* @property {number} [timeout=1000] In milliseconds, the amount of time to wait before serving fallback.
|
|
28
|
+
* @property {boolean} [throwable=false] Set to `true` and surround `fetch` in `try/catch` to serve different content in case podlet is unavailable. Will not server fallback content.
|
|
29
|
+
* @property {boolean} [redirectable=false] Set to `true` to allow podlet to respond with a redirect. You need to look for the redirect response from the podlet and return a redirect response to the browser yourself.
|
|
30
|
+
*/
|
|
31
|
+
export default class PodiumClient extends EventEmitter<[never]> {
|
|
32
|
+
/**
|
|
33
|
+
* @constructor
|
|
34
|
+
* @param {PodiumClientOptions} options
|
|
35
|
+
*/
|
|
36
|
+
constructor(options?: PodiumClientOptions);
|
|
37
|
+
get registry(): any;
|
|
38
|
+
get metrics(): Metrics;
|
|
39
|
+
get state(): "instantiated" | "stable" | "initializing" | "unhealthy" | "unstable";
|
|
40
|
+
/**
|
|
41
|
+
* Register a podlet so you can fetch its contents later with {@link PodiumClientResource.fetch}.
|
|
42
|
+
*
|
|
43
|
+
* @param {RegisterOptions} options
|
|
44
|
+
* @returns {PodiumClientResource}
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```js
|
|
48
|
+
* const headerPodlet = layout.client.register({
|
|
49
|
+
* name: 'header',
|
|
50
|
+
* uri: 'http://header/manifest.json',
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
register(options: RegisterOptions): PodiumClientResource;
|
|
55
|
+
dump(): any;
|
|
56
|
+
load(dump: any): any;
|
|
57
|
+
/**
|
|
58
|
+
* Refreshes the cached podlet manifest for all {@link register}ed podlets.
|
|
59
|
+
*/
|
|
60
|
+
refreshManifests(): Promise<void>;
|
|
61
|
+
#private;
|
|
62
|
+
}
|
|
63
|
+
export type PodiumClientResource = import('./resource.js').default;
|
|
64
|
+
export type PodiumClientResourceOptions = import('./resource.js').PodiumClientResourceOptions;
|
|
65
|
+
export type PodiumClientResponse = import('./response.js').default;
|
|
66
|
+
export type PodiumRedirect = import('./http-outgoing.js').PodiumRedirect;
|
|
67
|
+
export type PodletManifest = import('@podium/schemas').PodletManifestSchema;
|
|
68
|
+
export type PodiumClientOptions = {
|
|
69
|
+
name: string;
|
|
70
|
+
logger?: import('abslog').AbstractLoggerOptions;
|
|
71
|
+
retries?: number;
|
|
72
|
+
/**
|
|
73
|
+
* In milliseconds
|
|
74
|
+
*/
|
|
75
|
+
timeout?: number;
|
|
76
|
+
maxAge?: number;
|
|
77
|
+
rejectUnauthorized?: boolean;
|
|
78
|
+
resolveThreshold?: number;
|
|
79
|
+
resolveMax?: number;
|
|
80
|
+
httpAgent?: import('http').Agent;
|
|
81
|
+
httpsAgent?: import('https').Agent;
|
|
82
|
+
};
|
|
83
|
+
export type RegisterOptions = {
|
|
84
|
+
/**
|
|
85
|
+
* A unique name for the podlet
|
|
86
|
+
*/
|
|
87
|
+
name: string;
|
|
88
|
+
/**
|
|
89
|
+
* URL to the podlet's `manifest.json`
|
|
90
|
+
*/
|
|
91
|
+
uri: string;
|
|
92
|
+
/**
|
|
93
|
+
* Number of retries before serving fallback
|
|
94
|
+
*/
|
|
95
|
+
retries?: number;
|
|
96
|
+
/**
|
|
97
|
+
* In milliseconds, the amount of time to wait before serving fallback.
|
|
98
|
+
*/
|
|
99
|
+
timeout?: number;
|
|
100
|
+
/**
|
|
101
|
+
* Set to `true` and surround `fetch` in `try/catch` to serve different content in case podlet is unavailable. Will not server fallback content.
|
|
102
|
+
*/
|
|
103
|
+
throwable?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Set to `true` to allow podlet to respond with a redirect. You need to look for the redirect response from the podlet and return a redirect response to the browser yourself.
|
|
106
|
+
*/
|
|
107
|
+
redirectable?: boolean;
|
|
108
|
+
};
|
|
109
|
+
import EventEmitter from 'events';
|
|
110
|
+
import Metrics from '@metrics/client';
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} PodiumClientHttpOutgoingOptions
|
|
3
|
+
* @property {string} name
|
|
4
|
+
* @property {string} uri To the podlet's `manifest.json`
|
|
5
|
+
* @property {number} timeout In milliseconds
|
|
6
|
+
* @property {number} maxAge
|
|
7
|
+
* @property {number} [retries=4]
|
|
8
|
+
* @property {boolean} [throwable=false]
|
|
9
|
+
* @property {boolean} [redirectable=false]
|
|
10
|
+
* @property {boolean} [rejectUnauthorized=true]
|
|
11
|
+
* @property {import('http').Agent} [httpAgent]
|
|
12
|
+
* @property {import('https').Agent} [httpsAgent]
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {object} PodiumClientResourceOptions
|
|
16
|
+
* @property {string} [pathname]
|
|
17
|
+
* @property {import('http').IncomingHttpHeaders} [headers]
|
|
18
|
+
* @property {object} [query]
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {object} PodiumRedirect
|
|
22
|
+
* @property {number} statusCode;
|
|
23
|
+
* @property {string} location;
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {object} PodletProxySchema
|
|
27
|
+
* @property {string} target
|
|
28
|
+
* @property {string} name
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {object} PodletManifest Similar to the schema's manifest, but with instances of AssetCss and AssetJs from `@podium/utils` and default values.
|
|
32
|
+
* @property {string} name
|
|
33
|
+
* @property {string} version
|
|
34
|
+
* @property {string} content
|
|
35
|
+
* @property {string} fallback
|
|
36
|
+
* @property {Array<import('@podium/utils').AssetJs>} js
|
|
37
|
+
* @property {Array<import('@podium/utils').AssetCss>} css
|
|
38
|
+
* @property {Record<string, string> | Array<PodletProxySchema>} proxy
|
|
39
|
+
* @property {string} team
|
|
40
|
+
*/
|
|
41
|
+
export default class PodletClientHttpOutgoing extends PassThrough {
|
|
42
|
+
/**
|
|
43
|
+
* @constructor
|
|
44
|
+
* @param {PodiumClientHttpOutgoingOptions} options
|
|
45
|
+
* @param {PodiumClientResourceOptions} [reqOptions]
|
|
46
|
+
* @param {import('@podium/utils').HttpIncoming} [incoming]
|
|
47
|
+
*/
|
|
48
|
+
constructor(options?: PodiumClientHttpOutgoingOptions, reqOptions?: PodiumClientResourceOptions, incoming?: import('@podium/utils').HttpIncoming);
|
|
49
|
+
get rejectUnauthorized(): boolean;
|
|
50
|
+
get reqOptions(): {
|
|
51
|
+
pathname: string;
|
|
52
|
+
headers: import('http').IncomingHttpHeaders;
|
|
53
|
+
query: object;
|
|
54
|
+
};
|
|
55
|
+
get throwable(): boolean;
|
|
56
|
+
set manifest(obj: PodletManifest);
|
|
57
|
+
get manifest(): PodletManifest;
|
|
58
|
+
set fallback(value: any);
|
|
59
|
+
get fallback(): any;
|
|
60
|
+
get timeout(): number;
|
|
61
|
+
set success(value: boolean);
|
|
62
|
+
get success(): boolean;
|
|
63
|
+
get context(): {};
|
|
64
|
+
set headers(value: {});
|
|
65
|
+
get headers(): {};
|
|
66
|
+
set maxAge(value: number);
|
|
67
|
+
get maxAge(): number;
|
|
68
|
+
set status(value: "empty" | "fresh" | "cached" | "stale");
|
|
69
|
+
/**
|
|
70
|
+
* What status the manifest is in. This is used to tell what actions need to
|
|
71
|
+
* be performed throughout the resolving process to complete a request.
|
|
72
|
+
*
|
|
73
|
+
* The different statuses can be:
|
|
74
|
+
* - `"empty"` - there is no manifest available - we are in process of fetching it
|
|
75
|
+
* - `"fresh"` - the manifest has been fetched but is not stored in cache yet
|
|
76
|
+
* - `"cached"` - the manifest was retrieved from cache
|
|
77
|
+
* - `"stale"` - the manifest is outdated, a new manifest needs to be fetched
|
|
78
|
+
*/
|
|
79
|
+
get status(): "empty" | "fresh" | "cached" | "stale";
|
|
80
|
+
get name(): string;
|
|
81
|
+
get manifestUri(): string;
|
|
82
|
+
get fallbackUri(): string;
|
|
83
|
+
get contentUri(): string;
|
|
84
|
+
/**
|
|
85
|
+
* Kill switch for breaking the recursive promise chain in case it is never able to completely resolve.
|
|
86
|
+
* This is true if the number of recursions matches the threshold.
|
|
87
|
+
*/
|
|
88
|
+
get kill(): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Set the number of recursions before the request should be {@link kill}ed
|
|
91
|
+
*/
|
|
92
|
+
set recursions(value: number);
|
|
93
|
+
/**
|
|
94
|
+
* The number of recursions before the request should be {@link kill}ed
|
|
95
|
+
*/
|
|
96
|
+
get recursions(): number;
|
|
97
|
+
set redirect(value: PodiumRedirect);
|
|
98
|
+
/**
|
|
99
|
+
* When {@link redirectable} is `true` this is populated with redirect information so you can send a redirect response to the browser from your layout.
|
|
100
|
+
*
|
|
101
|
+
* @see https://podium-lib.io/docs/layout/handling_redirects
|
|
102
|
+
*/
|
|
103
|
+
get redirect(): PodiumRedirect;
|
|
104
|
+
set redirectable(value: boolean);
|
|
105
|
+
/**
|
|
106
|
+
* Whether the podlet can signal redirects to the layout.
|
|
107
|
+
*
|
|
108
|
+
* @see https://podium-lib.io/docs/layout/handling_redirects
|
|
109
|
+
*/
|
|
110
|
+
get redirectable(): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* True if the client has returned the podlet's fallback.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
*
|
|
116
|
+
* ```js
|
|
117
|
+
* if (outgoing.isFallback) console.log("Fallback!");
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @see https://podium-lib.io/docs/podlet/fallbacks
|
|
121
|
+
*/
|
|
122
|
+
get isFallback(): boolean;
|
|
123
|
+
pushFallback(): void;
|
|
124
|
+
get [Symbol.toStringTag](): string;
|
|
125
|
+
#private;
|
|
126
|
+
}
|
|
127
|
+
export type PodiumClientHttpOutgoingOptions = {
|
|
128
|
+
name: string;
|
|
129
|
+
/**
|
|
130
|
+
* To the podlet's `manifest.json`
|
|
131
|
+
*/
|
|
132
|
+
uri: string;
|
|
133
|
+
/**
|
|
134
|
+
* In milliseconds
|
|
135
|
+
*/
|
|
136
|
+
timeout: number;
|
|
137
|
+
maxAge: number;
|
|
138
|
+
retries?: number;
|
|
139
|
+
throwable?: boolean;
|
|
140
|
+
redirectable?: boolean;
|
|
141
|
+
rejectUnauthorized?: boolean;
|
|
142
|
+
httpAgent?: import('http').Agent;
|
|
143
|
+
httpsAgent?: import('https').Agent;
|
|
144
|
+
};
|
|
145
|
+
export type PodiumClientResourceOptions = {
|
|
146
|
+
pathname?: string;
|
|
147
|
+
headers?: import('http').IncomingHttpHeaders;
|
|
148
|
+
query?: object;
|
|
149
|
+
};
|
|
150
|
+
export type PodiumRedirect = {
|
|
151
|
+
/**
|
|
152
|
+
* ;
|
|
153
|
+
*/
|
|
154
|
+
statusCode: number;
|
|
155
|
+
/**
|
|
156
|
+
* ;
|
|
157
|
+
*/
|
|
158
|
+
location: string;
|
|
159
|
+
};
|
|
160
|
+
export type PodletProxySchema = {
|
|
161
|
+
target: string;
|
|
162
|
+
name: string;
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Similar to the schema's manifest, but with instances of AssetCss and AssetJs from `@podium/utils` and default values.
|
|
166
|
+
*/
|
|
167
|
+
export type PodletManifest = {
|
|
168
|
+
name: string;
|
|
169
|
+
version: string;
|
|
170
|
+
content: string;
|
|
171
|
+
fallback: string;
|
|
172
|
+
js: Array<import('@podium/utils').AssetJs>;
|
|
173
|
+
css: Array<import('@podium/utils').AssetCss>;
|
|
174
|
+
proxy: Record<string, string> | Array<PodletProxySchema>;
|
|
175
|
+
team: string;
|
|
176
|
+
};
|
|
177
|
+
import { PassThrough } from 'stream';
|
package/types/http.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} PodiumHttpClientRequestOptions
|
|
3
|
+
* @property {'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH'} method
|
|
4
|
+
* @property {boolean} [json]
|
|
5
|
+
* @property {boolean} [rejectUnauthorized]
|
|
6
|
+
* @property {boolean} [follow]
|
|
7
|
+
* @property {number} [timeout]
|
|
8
|
+
* @property {number} [bodyTimeout]
|
|
9
|
+
* @property {object} [query]
|
|
10
|
+
* @property {import('http').IncomingHttpHeaders} [headers]
|
|
11
|
+
*/
|
|
12
|
+
export default class HTTP {
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} url
|
|
15
|
+
* @param {PodiumHttpClientRequestOptions} options
|
|
16
|
+
* @returns {Promise<Pick<import('undici').Dispatcher.ResponseData, 'statusCode' | 'headers' | 'body'>>}
|
|
17
|
+
*/
|
|
18
|
+
request(url: string, options: PodiumHttpClientRequestOptions): Promise<Pick<import('undici').Dispatcher.ResponseData, 'statusCode' | 'headers' | 'body'>>;
|
|
19
|
+
}
|
|
20
|
+
export type PodiumHttpClientRequestOptions = {
|
|
21
|
+
method: 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';
|
|
22
|
+
json?: boolean;
|
|
23
|
+
rejectUnauthorized?: boolean;
|
|
24
|
+
follow?: boolean;
|
|
25
|
+
timeout?: number;
|
|
26
|
+
bodyTimeout?: number;
|
|
27
|
+
query?: object;
|
|
28
|
+
headers?: import('http').IncomingHttpHeaders;
|
|
29
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} PodletClientCacheResolverOptions
|
|
3
|
+
* @property {import('abslog').AbstractLoggerOptions} [logger]
|
|
4
|
+
*/
|
|
5
|
+
export default class PodletClientCacheResolver {
|
|
6
|
+
/**
|
|
7
|
+
* @constructor
|
|
8
|
+
* @param {import('ttl-mem-cache').default} registry
|
|
9
|
+
* @param {PodletClientCacheResolverOptions} options
|
|
10
|
+
*/
|
|
11
|
+
constructor(registry: any, options?: PodletClientCacheResolverOptions);
|
|
12
|
+
/**
|
|
13
|
+
* Loads the podlet's manifest from cache if not stale
|
|
14
|
+
*
|
|
15
|
+
* @param {import('./http-outgoing.js').default} outgoing
|
|
16
|
+
* @returns {Promise<import('./http-outgoing.js').default>}
|
|
17
|
+
*/
|
|
18
|
+
load(outgoing: import('./http-outgoing.js').default): Promise<import('./http-outgoing.js').default>;
|
|
19
|
+
/**
|
|
20
|
+
* Saves the podlet's manifest to the cache
|
|
21
|
+
*
|
|
22
|
+
* @param {import('./http-outgoing.js').default} outgoing
|
|
23
|
+
* @returns {Promise<import('./http-outgoing.js').default>}
|
|
24
|
+
*/
|
|
25
|
+
save(outgoing: import('./http-outgoing.js').default): Promise<import('./http-outgoing.js').default>;
|
|
26
|
+
get [Symbol.toStringTag](): string;
|
|
27
|
+
#private;
|
|
28
|
+
}
|
|
29
|
+
export type PodletClientCacheResolverOptions = {
|
|
30
|
+
logger?: import('abslog').AbstractLoggerOptions;
|
|
31
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} PodletClientContentResolverOptions
|
|
3
|
+
* @property {string} clientName
|
|
4
|
+
* @property {import('./http.js').default} [http]
|
|
5
|
+
* @property {import('abslog').AbstractLoggerOptions} [logger]
|
|
6
|
+
*/
|
|
7
|
+
export default class PodletClientContentResolver {
|
|
8
|
+
/**
|
|
9
|
+
* @constructor
|
|
10
|
+
* @param {PodletClientContentResolverOptions} options
|
|
11
|
+
*/
|
|
12
|
+
constructor(options?: PodletClientContentResolverOptions);
|
|
13
|
+
get metrics(): Metrics;
|
|
14
|
+
/**
|
|
15
|
+
* Resolves/fetches the podlet's content.
|
|
16
|
+
*
|
|
17
|
+
* @param {import('./http-outgoing.js').default} outgoing
|
|
18
|
+
* @returns {Promise<import('./http-outgoing.js').default>}
|
|
19
|
+
*/
|
|
20
|
+
resolve(outgoing: import('./http-outgoing.js').default): Promise<import('./http-outgoing.js').default>;
|
|
21
|
+
get [Symbol.toStringTag](): string;
|
|
22
|
+
#private;
|
|
23
|
+
}
|
|
24
|
+
export type PodletClientContentResolverOptions = {
|
|
25
|
+
clientName: string;
|
|
26
|
+
http?: import('./http.js').default;
|
|
27
|
+
logger?: import('abslog').AbstractLoggerOptions;
|
|
28
|
+
};
|
|
29
|
+
import Metrics from '@metrics/client';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} PodletClientResolverOptions
|
|
3
|
+
* @property {string} clientName
|
|
4
|
+
* @property {import('abslog').AbstractLoggerOptions} [logger]
|
|
5
|
+
*/
|
|
6
|
+
export default class PodletClientResolver {
|
|
7
|
+
/**
|
|
8
|
+
* @constructor
|
|
9
|
+
* @param {import('ttl-mem-cache').default} registry
|
|
10
|
+
* @param {PodletClientResolverOptions} options
|
|
11
|
+
*/
|
|
12
|
+
constructor(registry: any, options?: PodletClientResolverOptions);
|
|
13
|
+
get metrics(): Metrics;
|
|
14
|
+
/**
|
|
15
|
+
* Resolve the podlet's manifest, fallback and content
|
|
16
|
+
*
|
|
17
|
+
* @param {import('./http-outgoing.js').default} outgoing
|
|
18
|
+
* @returns {Promise<import('./http-outgoing.js').default>}
|
|
19
|
+
*/
|
|
20
|
+
resolve(outgoing: import('./http-outgoing.js').default): Promise<import('./http-outgoing.js').default>;
|
|
21
|
+
/**
|
|
22
|
+
* Refresh the podlet's cached manifest and fallback
|
|
23
|
+
*
|
|
24
|
+
* @param {import('./http-outgoing.js').default} outgoing
|
|
25
|
+
* @returns {Promise<boolean>} `true` if successful
|
|
26
|
+
*/
|
|
27
|
+
refresh(outgoing: import('./http-outgoing.js').default): Promise<boolean>;
|
|
28
|
+
get [Symbol.toStringTag](): string;
|
|
29
|
+
#private;
|
|
30
|
+
}
|
|
31
|
+
export type PodletClientResolverOptions = {
|
|
32
|
+
clientName: string;
|
|
33
|
+
logger?: import('abslog').AbstractLoggerOptions;
|
|
34
|
+
};
|
|
35
|
+
import Metrics from '@metrics/client';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} PodletClientFallbackResolverOptions
|
|
3
|
+
* @property {string} clientName
|
|
4
|
+
* @property {import('./http.js').default} [http]
|
|
5
|
+
* @property {import('abslog').AbstractLoggerOptions} [logger]
|
|
6
|
+
*/
|
|
7
|
+
export default class PodletClientFallbackResolver {
|
|
8
|
+
/**
|
|
9
|
+
* @constructor
|
|
10
|
+
* @param {PodletClientFallbackResolverOptions} options
|
|
11
|
+
*/
|
|
12
|
+
constructor(options?: PodletClientFallbackResolverOptions);
|
|
13
|
+
get metrics(): Metrics;
|
|
14
|
+
/**
|
|
15
|
+
* Resolves/fetches the podlet's fallback.
|
|
16
|
+
*
|
|
17
|
+
* @param {import('./http-outgoing.js').default} outgoing
|
|
18
|
+
* @returns {Promise<import('./http-outgoing.js').default>}
|
|
19
|
+
*/
|
|
20
|
+
resolve(outgoing: import('./http-outgoing.js').default): Promise<import('./http-outgoing.js').default>;
|
|
21
|
+
get [Symbol.toStringTag](): string;
|
|
22
|
+
#private;
|
|
23
|
+
}
|
|
24
|
+
export type PodletClientFallbackResolverOptions = {
|
|
25
|
+
clientName: string;
|
|
26
|
+
http?: import('./http.js').default;
|
|
27
|
+
logger?: import('abslog').AbstractLoggerOptions;
|
|
28
|
+
};
|
|
29
|
+
import Metrics from '@metrics/client';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} PodletClientManifestResolverOptions
|
|
3
|
+
* @property {string} clientName
|
|
4
|
+
* @property {import('abslog').AbstractLoggerOptions} [logger]
|
|
5
|
+
* @property {import('./http.js').default} [http]
|
|
6
|
+
*/
|
|
7
|
+
export default class PodletClientManifestResolver {
|
|
8
|
+
/**
|
|
9
|
+
* @constructor
|
|
10
|
+
* @param {PodletClientManifestResolverOptions} options
|
|
11
|
+
*/
|
|
12
|
+
constructor(options?: PodletClientManifestResolverOptions);
|
|
13
|
+
get metrics(): Metrics;
|
|
14
|
+
/**
|
|
15
|
+
* @param {import('./http-outgoing.js').default} outgoing
|
|
16
|
+
* @returns {Promise<import('./http-outgoing.js').default>}
|
|
17
|
+
*/
|
|
18
|
+
resolve(outgoing: import('./http-outgoing.js').default): Promise<import('./http-outgoing.js').default>;
|
|
19
|
+
get [Symbol.toStringTag](): string;
|
|
20
|
+
#private;
|
|
21
|
+
}
|
|
22
|
+
export type PodletClientManifestResolverOptions = {
|
|
23
|
+
clientName: string;
|
|
24
|
+
logger?: import('abslog').AbstractLoggerOptions;
|
|
25
|
+
http?: import('./http.js').default;
|
|
26
|
+
};
|
|
27
|
+
import Metrics from '@metrics/client';
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} PodiumClientResourceOptions
|
|
3
|
+
* @property {import('abslog').AbstractLoggerOptions} [logger]
|
|
4
|
+
* @property {string} clientName
|
|
5
|
+
* @property {string} name
|
|
6
|
+
* @property {string} uri To the podlet's `manifest.json`
|
|
7
|
+
* @property {number} timeout In milliseconds
|
|
8
|
+
* @property {number} maxAge
|
|
9
|
+
* @property {number} [retries]
|
|
10
|
+
* @property {boolean} [throwable]
|
|
11
|
+
* @property {boolean} [redirectable]
|
|
12
|
+
* @property {boolean} [rejectUnauthorized]
|
|
13
|
+
* @property {import('http').Agent} [httpAgent]
|
|
14
|
+
* @property {import('https').Agent} [httpsAgent]
|
|
15
|
+
*/
|
|
16
|
+
export default class PodiumClientResource {
|
|
17
|
+
/**
|
|
18
|
+
* @constructor
|
|
19
|
+
* @param {import('ttl-mem-cache').default} registry
|
|
20
|
+
* @param {import('./state.js').default} state
|
|
21
|
+
* @param {PodiumClientResourceOptions} options
|
|
22
|
+
*/
|
|
23
|
+
constructor(registry: any, state: import('./state.js').default, options?: PodiumClientResourceOptions);
|
|
24
|
+
get metrics(): Metrics;
|
|
25
|
+
get name(): string;
|
|
26
|
+
get uri(): string;
|
|
27
|
+
/**
|
|
28
|
+
* Fetch the podlet's content, or fallback if the podlet is unavailable.
|
|
29
|
+
* The podlet response includes references to its CSS and JS assets which should be included in the final HTML document.
|
|
30
|
+
*
|
|
31
|
+
* @param {import('@podium/utils').HttpIncoming} incoming Instance of HttpIncoming
|
|
32
|
+
* @param {import('./http-outgoing.js').PodiumClientResourceOptions} [reqOptions={}] Optional parameters to the HTTP request, such as query parameters or HTTP request headers.
|
|
33
|
+
* @returns {Promise<import('./response.js').default>}
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```js
|
|
37
|
+
* const incoming = res.locals.podium; // Express server example
|
|
38
|
+
* const header = await headerPodlet.fetch(incoming);
|
|
39
|
+
* incoming.podlets = [header]; // Register the podlet's JS and CSS assets with the layout's HTML template
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
fetch(incoming: import('@podium/utils').HttpIncoming, reqOptions?: import('./http-outgoing.js').PodiumClientResourceOptions): Promise<import('./response.js').default>;
|
|
43
|
+
/**
|
|
44
|
+
* Stream the podlet's content, or fallback if the podlet is unavailable.
|
|
45
|
+
*
|
|
46
|
+
* @param {import('@podium/utils').HttpIncoming} incoming
|
|
47
|
+
* @param {import('./http-outgoing.js').PodiumClientResourceOptions} [reqOptions={}]
|
|
48
|
+
* @returns {import('./http-outgoing.js').default}
|
|
49
|
+
*/
|
|
50
|
+
stream(incoming: import('@podium/utils').HttpIncoming, reqOptions?: import('./http-outgoing.js').PodiumClientResourceOptions): import('./http-outgoing.js').default;
|
|
51
|
+
/**
|
|
52
|
+
* Refresh the podlet's manifest and fallback in the cache.
|
|
53
|
+
*
|
|
54
|
+
* @param {import('@podium/utils').HttpIncoming} [incoming]
|
|
55
|
+
* @param {import('./http-outgoing.js').PodiumClientResourceOptions} [reqOptions={}]
|
|
56
|
+
* @returns {Promise<boolean>} `true` if succesful
|
|
57
|
+
*/
|
|
58
|
+
refresh(incoming?: import('@podium/utils').HttpIncoming, reqOptions?: import('./http-outgoing.js').PodiumClientResourceOptions): Promise<boolean>;
|
|
59
|
+
[inspect](): {
|
|
60
|
+
metrics: Metrics;
|
|
61
|
+
name: string;
|
|
62
|
+
uri: string;
|
|
63
|
+
};
|
|
64
|
+
get [Symbol.toStringTag](): string;
|
|
65
|
+
#private;
|
|
66
|
+
}
|
|
67
|
+
export type PodiumClientResourceOptions = {
|
|
68
|
+
logger?: import('abslog').AbstractLoggerOptions;
|
|
69
|
+
clientName: string;
|
|
70
|
+
name: string;
|
|
71
|
+
/**
|
|
72
|
+
* To the podlet's `manifest.json`
|
|
73
|
+
*/
|
|
74
|
+
uri: string;
|
|
75
|
+
/**
|
|
76
|
+
* In milliseconds
|
|
77
|
+
*/
|
|
78
|
+
timeout: number;
|
|
79
|
+
maxAge: number;
|
|
80
|
+
retries?: number;
|
|
81
|
+
throwable?: boolean;
|
|
82
|
+
redirectable?: boolean;
|
|
83
|
+
rejectUnauthorized?: boolean;
|
|
84
|
+
httpAgent?: import('http').Agent;
|
|
85
|
+
httpsAgent?: import('https').Agent;
|
|
86
|
+
};
|
|
87
|
+
import Metrics from '@metrics/client';
|
|
88
|
+
declare const inspect: unique symbol;
|
|
89
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} PodiumClientResponseOptions
|
|
3
|
+
* @property {string} [content]
|
|
4
|
+
* @property {object} [headers]
|
|
5
|
+
* @property {Array<import('@podium/utils').AssetJs>} [js]
|
|
6
|
+
* @property {Array<import('@podium/utils').AssetCss>} [css]
|
|
7
|
+
* @property {import('./http-outgoing.js').PodiumRedirect | null} [redirect]
|
|
8
|
+
*/
|
|
9
|
+
export default class PodiumClientResponse {
|
|
10
|
+
/**
|
|
11
|
+
* @constructor
|
|
12
|
+
* @param {PodiumClientResponseOptions} options
|
|
13
|
+
*/
|
|
14
|
+
constructor({ content, headers, css, js, redirect, }?: PodiumClientResponseOptions);
|
|
15
|
+
get content(): string;
|
|
16
|
+
get headers(): any;
|
|
17
|
+
get css(): import("@podium/utils").AssetCss[];
|
|
18
|
+
get js(): import("@podium/utils").AssetJs[];
|
|
19
|
+
get redirect(): import("./http-outgoing.js").PodiumRedirect;
|
|
20
|
+
toJSON(): {
|
|
21
|
+
redirect: import("./http-outgoing.js").PodiumRedirect;
|
|
22
|
+
content: string;
|
|
23
|
+
headers: any;
|
|
24
|
+
css: import("@podium/utils").AssetCss[];
|
|
25
|
+
js: import("@podium/utils").AssetJs[];
|
|
26
|
+
};
|
|
27
|
+
toString(): string;
|
|
28
|
+
[Symbol.toPrimitive](): string;
|
|
29
|
+
[inspect](): {
|
|
30
|
+
redirect: import("./http-outgoing.js").PodiumRedirect;
|
|
31
|
+
content: string;
|
|
32
|
+
headers: any;
|
|
33
|
+
css: import("@podium/utils").AssetCss[];
|
|
34
|
+
js: import("@podium/utils").AssetJs[];
|
|
35
|
+
};
|
|
36
|
+
get [Symbol.toStringTag](): string;
|
|
37
|
+
#private;
|
|
38
|
+
}
|
|
39
|
+
export type PodiumClientResponseOptions = {
|
|
40
|
+
content?: string;
|
|
41
|
+
headers?: object;
|
|
42
|
+
js?: Array<import('@podium/utils').AssetJs>;
|
|
43
|
+
css?: Array<import('@podium/utils').AssetCss>;
|
|
44
|
+
redirect?: import('./http-outgoing.js').PodiumRedirect | null;
|
|
45
|
+
};
|
|
46
|
+
declare const inspect: unique symbol;
|
|
47
|
+
export {};
|
package/types/state.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {object} PodiumClientStateOptions
|
|
4
|
+
* @property {number} [resolveThreshold=10000]
|
|
5
|
+
* @property {number} [resolveMax=240000]
|
|
6
|
+
*/
|
|
7
|
+
export default class PodiumClientState extends EventEmitter<[never]> {
|
|
8
|
+
/**
|
|
9
|
+
* @param {PodiumClientStateOptions} [options]
|
|
10
|
+
*/
|
|
11
|
+
constructor({ resolveThreshold, resolveMax, }?: PodiumClientStateOptions);
|
|
12
|
+
get status(): "instantiated" | "stable" | "initializing" | "unhealthy" | "unstable";
|
|
13
|
+
setInitializingState(): void;
|
|
14
|
+
setStableState(): void;
|
|
15
|
+
setUnhealthyState(): void;
|
|
16
|
+
setUnstableState(): void;
|
|
17
|
+
reset(): void;
|
|
18
|
+
toJSON(): {
|
|
19
|
+
status: "instantiated" | "stable" | "initializing" | "unhealthy" | "unstable";
|
|
20
|
+
};
|
|
21
|
+
[inspect](): {
|
|
22
|
+
status: "instantiated" | "stable" | "initializing" | "unhealthy" | "unstable";
|
|
23
|
+
};
|
|
24
|
+
get [Symbol.toStringTag](): string;
|
|
25
|
+
#private;
|
|
26
|
+
}
|
|
27
|
+
export type PodiumClientStateOptions = {
|
|
28
|
+
resolveThreshold?: number;
|
|
29
|
+
resolveMax?: number;
|
|
30
|
+
};
|
|
31
|
+
import EventEmitter from 'events';
|
|
32
|
+
declare const inspect: unique symbol;
|
|
33
|
+
export {};
|
package/types/utils.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export function isHeaderDefined(headers: object, header: string): boolean;
|
|
2
|
+
export function hasManifestChange(item: object): boolean;
|
|
3
|
+
export function validateIncoming(incoming?: object): boolean;
|
|
4
|
+
export function filterAssets<T extends import("@podium/utils").AssetJs | import("@podium/utils").AssetCss>(scope: "content" | "fallback" | "all", assets: T[]): T[];
|