@bleedingdev/modern-js-server-runtime-extensions 3.8.3-ultramodern.6 → 3.9.0-ultramodern.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/cjs/bff-policy/crossProjectPolicy.js +299 -0
- package/dist/cjs/bff-policy/index.js +62 -0
- package/dist/cjs/bff-policy/node.js +69 -0
- package/dist/cjs/bff-policy/operationContracts.js +182 -0
- package/dist/cjs/bff-policy/resolveCrossProjectPolicy.js +65 -0
- package/dist/cjs/contract-gate-snapshot-store/http-store.js +1 -8
- package/dist/cjs/errorResponsePlugin.js +57 -0
- package/dist/cjs/localisedLoaderPlugin.js +62 -0
- package/dist/cjs/mfCache.js +6 -0
- package/dist/cjs/module-federation-css/plugin.js +6 -0
- package/dist/cjs/serverConfig.js +18 -0
- package/dist/cjs/serverPlugin.js +74 -0
- package/dist/cjs/static-serving/plugin.js +57 -0
- package/dist/cjs/static-serving/responders.js +158 -0
- package/dist/cjs/static-serving/staticModuleFederation.js +173 -0
- package/dist/cjs/static-serving/staticPrecompressed.js +152 -0
- package/dist/cjs/telemetry/exporters.js +4 -4
- package/dist/cjs/telemetry/healthSetup.js +14 -14
- package/dist/cjs/telemetry/lifecycle.js +20 -21
- package/dist/cjs/telemetry/plugin.js +10 -4
- package/dist/cjs/telemetry/runtimeEndpoints.js +3 -2
- package/dist/cjs/telemetryCore.js +5 -5
- package/dist/esm/bff-policy/crossProjectPolicy.mjs +249 -0
- package/dist/esm/bff-policy/index.mjs +1 -0
- package/dist/esm/contract-gate-snapshot-store/http-store.mjs +1 -8
- package/dist/esm/errorResponsePlugin.mjs +19 -0
- package/dist/esm/localisedLoaderPlugin.mjs +24 -0
- package/dist/esm/mfCache.mjs +6 -0
- package/dist/esm/module-federation-css/plugin.mjs +6 -0
- package/dist/esm/serverConfig.mjs +0 -0
- package/dist/esm/serverPlugin.mjs +34 -0
- package/dist/esm/telemetry/exporters.mjs +2 -2
- package/dist/esm/telemetry/healthSetup.mjs +14 -14
- package/dist/esm/telemetry/lifecycle.mjs +21 -22
- package/dist/esm/telemetry/plugin.mjs +9 -3
- package/dist/esm/telemetry/runtimeEndpoints.mjs +3 -2
- package/dist/esm/telemetryCore.mjs +1 -1
- package/dist/esm-node/bff-policy/crossProjectPolicy.mjs +250 -0
- package/dist/esm-node/bff-policy/index.mjs +2 -0
- package/dist/esm-node/bff-policy/node.mjs +3 -0
- package/dist/esm-node/bff-policy/operationContracts.mjs +129 -0
- package/dist/esm-node/bff-policy/resolveCrossProjectPolicy.mjs +28 -0
- package/dist/esm-node/contract-gate-snapshot-store/http-store.mjs +1 -8
- package/dist/esm-node/errorResponsePlugin.mjs +20 -0
- package/dist/esm-node/localisedLoaderPlugin.mjs +25 -0
- package/dist/esm-node/mfCache.mjs +6 -0
- package/dist/esm-node/module-federation-css/plugin.mjs +6 -0
- package/dist/esm-node/serverConfig.mjs +1 -0
- package/dist/esm-node/serverPlugin.mjs +35 -0
- package/dist/esm-node/static-serving/plugin.mjs +18 -0
- package/dist/esm-node/static-serving/responders.mjs +111 -0
- package/dist/esm-node/static-serving/staticModuleFederation.mjs +105 -0
- package/dist/esm-node/static-serving/staticPrecompressed.mjs +112 -0
- package/dist/esm-node/telemetry/exporters.mjs +2 -2
- package/dist/esm-node/telemetry/healthSetup.mjs +14 -14
- package/dist/esm-node/telemetry/lifecycle.mjs +21 -22
- package/dist/esm-node/telemetry/plugin.mjs +9 -3
- package/dist/esm-node/telemetry/runtimeEndpoints.mjs +3 -2
- package/dist/esm-node/telemetryCore.mjs +1 -1
- package/dist/types/backend-federation-security/node.d.ts +1 -1
- package/dist/types/bff-policy/crossProjectPolicy.d.ts +101 -0
- package/dist/types/bff-policy/index.d.ts +1 -0
- package/dist/types/bff-policy/node.d.ts +2 -0
- package/dist/types/bff-policy/operationContracts.d.ts +85 -0
- package/dist/types/bff-policy/resolveCrossProjectPolicy.d.ts +39 -0
- package/dist/types/contract-gate-snapshot-normalization.d.ts +1 -1
- package/dist/types/contract-gate-snapshot-store/file-store.d.ts +1 -1
- package/dist/types/contract-gate-snapshot-store/http-store.d.ts +1 -1
- package/dist/types/contract-gate-snapshot-store/index.d.ts +5 -5
- package/dist/types/contract-gate-snapshot-store/resolve.d.ts +1 -1
- package/dist/types/contractGateSnapshotObserver.d.ts +2 -2
- package/dist/types/errorResponsePlugin.d.ts +3 -0
- package/dist/types/index.d.ts +8 -7
- package/dist/types/localisedLoaderPlugin.d.ts +2 -0
- package/dist/types/mfCache.d.ts +2 -3
- package/dist/types/module-federation-css/collector.d.ts +1 -1
- package/dist/types/module-federation-css/index.d.ts +8 -8
- package/dist/types/module-federation-css/plugin.d.ts +2 -3
- package/dist/types/runtime-fallback-signal/index.d.ts +4 -4
- package/dist/types/runtime-fallback-signal/model.d.ts +1 -1
- package/dist/types/runtime-fallback-signal/resolver.d.ts +1 -1
- package/dist/types/runtime-fallback-signal/store.d.ts +1 -1
- package/dist/types/runtimeFallbackSignal.d.ts +1 -1
- package/dist/types/serverConfig.d.ts +17 -0
- package/dist/types/serverPlugin.d.ts +5 -0
- package/dist/types/static-serving/plugin.d.ts +3 -0
- package/dist/types/static-serving/responders.d.ts +2 -0
- package/dist/types/static-serving/staticModuleFederation.d.ts +13 -0
- package/dist/types/static-serving/staticPrecompressed.d.ts +13 -0
- package/dist/types/telemetry/exporters.d.ts +2 -2
- package/dist/types/telemetry/healthEvaluation.d.ts +2 -2
- package/dist/types/telemetry/healthMonitor.d.ts +2 -2
- package/dist/types/telemetry/healthSetup.d.ts +6 -6
- package/dist/types/telemetry/lifecycle.d.ts +6 -6
- package/dist/types/telemetry/metrics.d.ts +1 -1
- package/dist/types/telemetry/plugin.d.ts +5 -4
- package/dist/types/telemetry/registry.d.ts +2 -2
- package/dist/types/telemetry/runtimeEndpoints.d.ts +2 -2
- package/dist/types/telemetry.d.ts +1 -1
- package/dist/types/telemetryCore.d.ts +6 -6
- package/dist/types-esm/backend-federation-security/index.d.mts +68 -0
- package/dist/types-esm/backend-federation-security/node.d.mts +3 -0
- package/dist/types-esm/bff-policy/crossProjectPolicy.d.mts +101 -0
- package/dist/types-esm/bff-policy/index.d.mts +1 -0
- package/dist/types-esm/bff-policy/node.d.mts +2 -0
- package/dist/types-esm/bff-policy/operationContracts.d.mts +85 -0
- package/dist/types-esm/bff-policy/resolveCrossProjectPolicy.d.mts +39 -0
- package/dist/types-esm/contract-gate-snapshot-normalization.d.mts +15 -0
- package/dist/types-esm/contract-gate-snapshot-store/file-store.d.mts +3 -0
- package/dist/types-esm/contract-gate-snapshot-store/http-store.d.mts +5 -0
- package/dist/types-esm/contract-gate-snapshot-store/index.d.mts +5 -0
- package/dist/types-esm/contract-gate-snapshot-store/resolve.d.mts +9 -0
- package/dist/types-esm/contract-gate-snapshot-store/types.d.mts +47 -0
- package/dist/types-esm/contractGateSnapshotObserver.d.mts +33 -0
- package/dist/types-esm/env.d.mts +40 -0
- package/dist/types-esm/errorResponsePlugin.d.mts +3 -0
- package/dist/types-esm/index.d.mts +8 -0
- package/dist/types-esm/localisedLoaderPlugin.d.mts +2 -0
- package/dist/types-esm/mfCache.d.mts +26 -0
- package/dist/types-esm/module-federation-css/collector.d.mts +25 -0
- package/dist/types-esm/module-federation-css/index.d.mts +8 -0
- package/dist/types-esm/module-federation-css/manifest.d.mts +28 -0
- package/dist/types-esm/module-federation-css/plugin.d.mts +22 -0
- package/dist/types-esm/module-federation-css/remote.d.mts +20 -0
- package/dist/types-esm/runtime-fallback-signal/index.d.mts +4 -0
- package/dist/types-esm/runtime-fallback-signal/model.d.mts +70 -0
- package/dist/types-esm/runtime-fallback-signal/resolver.d.mts +29 -0
- package/dist/types-esm/runtime-fallback-signal/store.d.mts +4 -0
- package/dist/types-esm/runtimeFallbackSignal.d.mts +1 -0
- package/dist/types-esm/runtimeLifecycle.d.mts +10 -0
- package/dist/types-esm/serverConfig.d.mts +17 -0
- package/dist/types-esm/serverPlugin.d.mts +5 -0
- package/dist/types-esm/static-serving/plugin.d.mts +3 -0
- package/dist/types-esm/static-serving/responders.d.mts +2 -0
- package/dist/types-esm/static-serving/staticModuleFederation.d.mts +13 -0
- package/dist/types-esm/static-serving/staticPrecompressed.d.mts +13 -0
- package/dist/types-esm/telemetry/envelope.d.mts +55 -0
- package/dist/types-esm/telemetry/exporters.d.mts +12 -0
- package/dist/types-esm/telemetry/healthEvaluation.d.mts +20 -0
- package/dist/types-esm/telemetry/healthMonitor.d.mts +88 -0
- package/dist/types-esm/telemetry/healthSetup.d.mts +17 -0
- package/dist/types-esm/telemetry/lifecycle.d.mts +18 -0
- package/dist/types-esm/telemetry/metrics.d.mts +3 -0
- package/dist/types-esm/telemetry/plugin.d.mts +13 -0
- package/dist/types-esm/telemetry/registry.d.mts +69 -0
- package/dist/types-esm/telemetry/registryTypes.d.mts +50 -0
- package/dist/types-esm/telemetry/runtimeEndpoints.d.mts +35 -0
- package/dist/types-esm/telemetry.d.mts +1 -0
- package/dist/types-esm/telemetryCore.d.mts +6 -0
- package/package.json +160 -28
- package/rslib.config.mts +36 -2
- package/rstest.config.mts +11 -0
- package/src/bff-policy/crossProjectPolicy.ts +754 -0
- package/src/bff-policy/index.ts +1 -0
- package/src/bff-policy/node.ts +2 -0
- package/src/bff-policy/operationContracts.ts +298 -0
- package/src/bff-policy/resolveCrossProjectPolicy.ts +88 -0
- package/src/contract-gate-snapshot-store/http-store.ts +1 -11
- package/src/errorResponsePlugin.ts +21 -0
- package/src/index.ts +4 -0
- package/src/localisedLoaderPlugin.ts +34 -0
- package/src/mfCache.ts +4 -3
- package/src/module-federation-css/plugin.ts +4 -3
- package/src/serverConfig.ts +32 -0
- package/src/serverPlugin.ts +38 -0
- package/src/static-serving/plugin.ts +16 -0
- package/src/static-serving/responders.ts +208 -0
- package/src/static-serving/staticModuleFederation.ts +255 -0
- package/src/static-serving/staticPrecompressed.ts +193 -0
- package/src/telemetry/exporters.ts +1 -1
- package/src/telemetry/healthSetup.ts +17 -20
- package/src/telemetry/lifecycle.ts +27 -39
- package/src/telemetry/plugin.ts +6 -4
- package/src/telemetry/runtimeEndpoints.ts +3 -2
- package/src/telemetryCore.ts +1 -1
- package/tests/bff-policy/crossProjectPolicy.matrix.test.ts +450 -0
- package/tests/bff-policy/crossProjectPolicy.test.ts +197 -0
- package/tests/bff-policy/operationContracts.test.ts +221 -0
- package/tests/bff-policy/optionalZodPeer.test.ts +30 -0
- package/tests/bff-policy/resolveCrossProjectPolicy.test.ts +76 -0
- package/tests/contractGateSnapshotObserver.test.ts +0 -58
- package/tests/contractGateSnapshotStore.test.ts +0 -51
- package/tests/env.test.ts +45 -64
- package/tests/localisedLoader.test.ts +120 -0
- package/tests/mfCache.test.ts +1 -88
- package/tests/moduleFederationCss.test.ts +4 -48
- package/tests/nativeErrorResponse.test.ts +118 -0
- package/tests/nativeServerAssembly.test.ts +385 -0
- package/tests/runtimeLifecycle.test.ts +69 -17
- package/tests/static-serving/ordering.test.ts +214 -0
- package/tests/static-serving/static.test.ts +411 -0
- package/tests/telemetry.test.ts +35 -198
- package/tests/telemetryHealthMonitor.test.ts +0 -4
- package/tests/telemetryHealthObservation.test.ts +302 -0
- package/tests/telemetryLifecycle.test.ts +7 -303
- package/tests/telemetryRegistryQueueMatrix.test.ts +14 -111
- package/tests/registration.test.ts +0 -112
- package/tests/telemetryAutopilot.test.ts +0 -1134
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-project BFF policy evaluator.
|
|
3
|
+
*
|
|
4
|
+
* THREAT MODEL — read before relying on this module:
|
|
5
|
+
*
|
|
6
|
+
* Every header this evaluator inspects (envelope, operation id, operation
|
|
7
|
+
* context details) is constructed by the CLIENT from public, open-source
|
|
8
|
+
* formats. Without an out-of-band identity binding the checks below are a
|
|
9
|
+
* version-skew and misconfiguration gate, not an authentication or
|
|
10
|
+
* authorization boundary: any caller can echo an allowed `requestId` and a
|
|
11
|
+
* matching operation context.
|
|
12
|
+
*
|
|
13
|
+
* To use `allowedNamespaces`, supply
|
|
14
|
+
* {@link CrossProjectPolicyConfig.verifyProducerIdentity}: a server-side
|
|
15
|
+
* hook that derives the producer namespace from a VERIFIED channel (mTLS
|
|
16
|
+
* peer identity, gateway-authenticated JWT claims, service-mesh headers
|
|
17
|
+
* stripped at the edge, ...). Requests fail closed when a namespace allowlist
|
|
18
|
+
* is configured without this hook. When the hook is
|
|
19
|
+
* present, the client-asserted namespace must match the verified namespace
|
|
20
|
+
* and the allowlist is checked against the verified value.
|
|
21
|
+
*
|
|
22
|
+
* Client-side counterparts in `@modern-js/create-request` (identity binding,
|
|
23
|
+
* operation contract validation) are developer-experience aids that fail
|
|
24
|
+
* fast in well-behaved clients; they protect nothing against a malicious
|
|
25
|
+
* caller.
|
|
26
|
+
*/
|
|
27
|
+
export declare const BFF_ENVELOPE_HEADER = "x-modernjs-bff-envelope";
|
|
28
|
+
export declare const BFF_OPERATION_CONTEXT_HEADER = "x-operation-id";
|
|
29
|
+
export declare const BFF_OPERATION_CONTEXT_DETAIL_HEADER = "x-modernjs-bff-operation-context";
|
|
30
|
+
export type CrossProjectOperationContract = {
|
|
31
|
+
schemaHash?: string;
|
|
32
|
+
operationVersion?: number;
|
|
33
|
+
operationId?: string;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Request facts observed by the server adapter rather than asserted by the
|
|
37
|
+
* client. `routePath` is the matched route template when the router exposes
|
|
38
|
+
* one (for example `/api/customers/:id`), not the client-provided detail.
|
|
39
|
+
*/
|
|
40
|
+
export type CrossProjectRequestObservation = {
|
|
41
|
+
method: string;
|
|
42
|
+
routePath: string;
|
|
43
|
+
};
|
|
44
|
+
export type CrossProjectRequestTarget = {
|
|
45
|
+
method: string;
|
|
46
|
+
pathname: string;
|
|
47
|
+
};
|
|
48
|
+
export type CrossProjectPolicyViolationReason = 'missing_envelope' | 'invalid_envelope' | 'missing_request_id' | 'namespace_not_allowed' | 'missing_operation_context' | 'operation_context_mismatch' | 'missing_operation_context_details' | 'invalid_operation_context_details' | 'operation_context_details_request_id_mismatch' | 'missing_operation_schema_hash' | 'missing_operation_version' | 'unknown_operation_contract' | 'operation_schema_hash_mismatch' | 'operation_version_mismatch' | 'producer_identity_mismatch';
|
|
49
|
+
export type CrossProjectPolicyViolation = {
|
|
50
|
+
code: 'BFF_CROSS_PROJECT_POLICY_DENIED';
|
|
51
|
+
reason: CrossProjectPolicyViolationReason;
|
|
52
|
+
message: string;
|
|
53
|
+
status: number;
|
|
54
|
+
};
|
|
55
|
+
export interface CrossProjectPolicyConfig {
|
|
56
|
+
enabled?: boolean;
|
|
57
|
+
requireEnvelope?: boolean;
|
|
58
|
+
requireOperationContext?: boolean;
|
|
59
|
+
requireOperationContextDetails?: boolean;
|
|
60
|
+
requireOperationSchemaHash?: boolean;
|
|
61
|
+
requireOperationVersion?: boolean;
|
|
62
|
+
allowedNamespaces?: string[];
|
|
63
|
+
envelopeHeader?: string;
|
|
64
|
+
operationContextHeader?: string;
|
|
65
|
+
operationContextDetailHeader?: string;
|
|
66
|
+
expectedOperationContracts?: Record<string, CrossProjectOperationContract>;
|
|
67
|
+
allowUnknownOperations?: boolean;
|
|
68
|
+
denyStatus?: number;
|
|
69
|
+
/**
|
|
70
|
+
* Server-side hook binding producer namespace to VERIFIED identity
|
|
71
|
+
* channel (mTLS peer, gateway-authenticated JWT, mesh identity headers).
|
|
72
|
+
*
|
|
73
|
+
* When provided, the namespace asserted by the client envelope must match
|
|
74
|
+
* the namespace returned by this hook, and `allowedNamespaces` is checked
|
|
75
|
+
* against the verified value instead of the client-asserted one. Returning
|
|
76
|
+
* `undefined` (identity could not be verified) denies the request.
|
|
77
|
+
*
|
|
78
|
+
* By default, `allowedNamespaces` requires this hook and fails closed
|
|
79
|
+
* without it.
|
|
80
|
+
*/
|
|
81
|
+
verifyProducerIdentity?: (headers: Record<string, unknown>) => string | undefined;
|
|
82
|
+
}
|
|
83
|
+
/** Serializable, fully-defaulted policy accepted by edge dispatchers. */
|
|
84
|
+
export type NormalizedCrossProjectPolicy = CrossProjectPolicyConfig & {
|
|
85
|
+
enabled: boolean;
|
|
86
|
+
requireEnvelope: boolean;
|
|
87
|
+
requireOperationContext: boolean;
|
|
88
|
+
requireOperationContextDetails: boolean;
|
|
89
|
+
requireOperationSchemaHash: boolean;
|
|
90
|
+
requireOperationVersion: boolean;
|
|
91
|
+
allowUnknownOperations: boolean;
|
|
92
|
+
expectedOperationContracts: Record<string, CrossProjectOperationContract>;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Resolves a concrete adapter request to the server-owned route template in
|
|
96
|
+
* the operation contract map. Effect receives requests after its BFF mount
|
|
97
|
+
* prefix has been stripped, so leading literal route segments may be mount
|
|
98
|
+
* prefixes. Ambiguous matches fail closed by retaining the concrete path.
|
|
99
|
+
*/
|
|
100
|
+
export declare const resolveCrossProjectRequestObservation: (request: CrossProjectRequestTarget, policy: Pick<CrossProjectPolicyConfig, 'expectedOperationContracts'>) => CrossProjectRequestObservation | undefined;
|
|
101
|
+
export declare const evaluateCrossProjectPolicy: (headers: Record<string, unknown>, policy?: CrossProjectPolicyConfig, observedRequest?: CrossProjectRequestObservation) => CrossProjectPolicyViolation | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './crossProjectPolicy.mjs';
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
type ApiHandler = (...args: any) => any | Promise<any>;
|
|
3
|
+
export type OperationContractEntry = {
|
|
4
|
+
name: string;
|
|
5
|
+
httpMethod: string;
|
|
6
|
+
routePath: string;
|
|
7
|
+
};
|
|
8
|
+
export type OperationContractDefinition = {
|
|
9
|
+
requestId: string;
|
|
10
|
+
operationVersion: number;
|
|
11
|
+
schemaHash: string;
|
|
12
|
+
method: string;
|
|
13
|
+
routePath: string;
|
|
14
|
+
operationId: string;
|
|
15
|
+
handlerName: string;
|
|
16
|
+
filename?: string;
|
|
17
|
+
};
|
|
18
|
+
export type OperationContractMap = Record<string, OperationContractDefinition>;
|
|
19
|
+
export declare const DEFAULT_OPERATION_VERSION = 1;
|
|
20
|
+
/**
|
|
21
|
+
* Derives the operation version from a producer package version: the semver
|
|
22
|
+
* major is the contract version, so consumers regenerated against an older
|
|
23
|
+
* producer major fail the `operation_version_mismatch` gate instead of
|
|
24
|
+
* silently calling an incompatible API.
|
|
25
|
+
*
|
|
26
|
+
* Falls back to {@link DEFAULT_OPERATION_VERSION} when no parseable version
|
|
27
|
+
* is available.
|
|
28
|
+
*/
|
|
29
|
+
export declare const deriveOperationVersion: (packageVersion?: unknown) => number;
|
|
30
|
+
/**
|
|
31
|
+
* Serializes the zod input schemas attached to an operator-decorated handler
|
|
32
|
+
* (`Data`/`Query`/`Params`/`Headers`/`Upload` metadata) into JSON-schema
|
|
33
|
+
* documents. Returns `undefined` for handlers without schema metadata
|
|
34
|
+
* (plain handlers, farrow schema-mode handlers).
|
|
35
|
+
*/
|
|
36
|
+
export declare const serializeOperationSchemas: (handler: ApiHandler | undefined) => Record<string, unknown> | undefined;
|
|
37
|
+
export type OperationContractHashInput = OperationContractEntry & {
|
|
38
|
+
/** Serialized schema documents; omit for schema-less operations. */
|
|
39
|
+
schemas?: Record<string, unknown> | undefined;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Per-operation contract hash. The hash covers the operation identity
|
|
43
|
+
* (name, method, route, producer requestId) plus the serialized input
|
|
44
|
+
* schemas, so:
|
|
45
|
+
*
|
|
46
|
+
* - changing an input schema changes the hash of exactly that operation;
|
|
47
|
+
* - reordering routes or adding unrelated operations never rotates the hash
|
|
48
|
+
* of other operations (each operation is hashed independently).
|
|
49
|
+
*/
|
|
50
|
+
export declare const createOperationContractHash: (operation: OperationContractHashInput, requestId: string) => string;
|
|
51
|
+
export declare const createOperationEntries: (handlers: Array<{
|
|
52
|
+
name: string;
|
|
53
|
+
httpMethod: string;
|
|
54
|
+
routePath: string;
|
|
55
|
+
}>) => OperationContractEntry[];
|
|
56
|
+
/**
|
|
57
|
+
* Aggregate hash over a set of per-operation contract hashes. Used for the
|
|
58
|
+
* module-level `operationSchemaHash` manifest export; stable across route
|
|
59
|
+
* reordering because the per-operation hashes are sorted before hashing.
|
|
60
|
+
*/
|
|
61
|
+
export declare const createOperationSchemaHash: (operationEntries: Array<OperationContractEntry & {
|
|
62
|
+
schemaHash?: string;
|
|
63
|
+
}>, requestId: string) => string;
|
|
64
|
+
export type OperationContractSource = {
|
|
65
|
+
name: string;
|
|
66
|
+
httpMethod: string;
|
|
67
|
+
routePath: string;
|
|
68
|
+
filename?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Optional handler function used to serialize schema metadata. Sources
|
|
71
|
+
* without a handler (e.g. reflected Effect HttpApi endpoints) hash the
|
|
72
|
+
* route identity only.
|
|
73
|
+
*/
|
|
74
|
+
handler?: ApiHandler;
|
|
75
|
+
};
|
|
76
|
+
export declare const buildOperationContractMap: ({ handlers, requestId, operationVersion, }: {
|
|
77
|
+
handlers: OperationContractSource[];
|
|
78
|
+
requestId?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Producer contract version, usually `deriveOperationVersion(pkg.version)`.
|
|
81
|
+
* Defaults to {@link DEFAULT_OPERATION_VERSION}.
|
|
82
|
+
*/
|
|
83
|
+
operationVersion?: number;
|
|
84
|
+
}) => OperationContractMap;
|
|
85
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CrossProjectPolicyConfig, NormalizedCrossProjectPolicy } from './crossProjectPolicy.mjs';
|
|
2
|
+
import { type OperationContractSource } from './operationContracts.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Runtime input collected by BFF server adapters (hono/effect/...) before
|
|
5
|
+
* the cross-project policy can be enforced.
|
|
6
|
+
*
|
|
7
|
+
* `crossProjectPolicy` accepts the raw `bff.crossProjectPolicy` user config —
|
|
8
|
+
* `BffCrossProjectPolicyUserConfig` is a structural subset of
|
|
9
|
+
* `CrossProjectPolicyConfig`, so no casts are required at the call site.
|
|
10
|
+
*/
|
|
11
|
+
export interface ResolveCrossProjectPolicyInput {
|
|
12
|
+
crossProjectPolicy?: CrossProjectPolicyConfig;
|
|
13
|
+
/** Registered API handlers used to derive the operation-contract map. */
|
|
14
|
+
handlers: OperationContractSource[];
|
|
15
|
+
/** Logical producer ID (`bff.requestId`). */
|
|
16
|
+
requestId?: string;
|
|
17
|
+
/** Marker injected by generated cross-project SDK plugins. */
|
|
18
|
+
isCrossProjectServer?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Producer contract version (usually derived from the producer
|
|
21
|
+
* package.json major via `deriveOperationVersion`).
|
|
22
|
+
*/
|
|
23
|
+
operationVersion?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Fully-defaulted policy returned by {@link resolveCrossProjectPolicy}.
|
|
27
|
+
*/
|
|
28
|
+
export type ResolvedCrossProjectPolicy = NormalizedCrossProjectPolicy;
|
|
29
|
+
/**
|
|
30
|
+
* Normalizes the user-facing cross-project policy config into the evaluator
|
|
31
|
+
* input shared by every BFF server adapter:
|
|
32
|
+
*
|
|
33
|
+
* - returns `undefined` when neither a policy nor the cross-project server
|
|
34
|
+
* marker is present (policy middleware must not be installed);
|
|
35
|
+
* - applies the documented defaults for all `require*` switches;
|
|
36
|
+
* - merges generated operation contracts (derived from the registered
|
|
37
|
+
* handlers) over any user-provided `expectedOperationContracts`.
|
|
38
|
+
*/
|
|
39
|
+
export declare const resolveCrossProjectPolicy: (input: ResolveCrossProjectPolicyInput) => ResolvedCrossProjectPolicy | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { GateSnapshot } from './contract-gate-snapshot-store/types.mjs';
|
|
2
|
+
type NormalizedGate = {
|
|
3
|
+
name: string;
|
|
4
|
+
passed: boolean;
|
|
5
|
+
reason?: string;
|
|
6
|
+
updatedAt: number;
|
|
7
|
+
expiresAt?: number;
|
|
8
|
+
};
|
|
9
|
+
type NormalizeSnapshotOptions = {
|
|
10
|
+
now: number;
|
|
11
|
+
gateStaleAfterMs: number;
|
|
12
|
+
};
|
|
13
|
+
export declare const getSnapshotGateNames: (snapshot: GateSnapshot) => Set<string> | undefined;
|
|
14
|
+
export declare const normalizeSnapshot: (snapshot: GateSnapshot, { now, gateStaleAfterMs }: NormalizeSnapshotOptions) => NormalizedGate[];
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ContractGateSnapshotStore } from './types.mjs';
|
|
2
|
+
export declare const resolveContractGateSnapshotPath: (appDirectory: string, configuredPath: string | undefined) => string;
|
|
3
|
+
export declare const createFileContractGateSnapshotStore: (gateSnapshotPath: string) => ContractGateSnapshotStore;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ContractGateSnapshotHttpStoreOptions, ContractGateSnapshotStore, ContractGateSnapshotStoreUserConfig } from './types.mjs';
|
|
2
|
+
export declare const createHttpContractGateSnapshotStore: (options: ContractGateSnapshotHttpStoreOptions) => ContractGateSnapshotStore;
|
|
3
|
+
export declare const tryResolveBuiltinSnapshotStore: (input: {
|
|
4
|
+
stateStore: ContractGateSnapshotStoreUserConfig;
|
|
5
|
+
}) => ContractGateSnapshotStore | undefined;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createFileContractGateSnapshotStore, resolveContractGateSnapshotPath, } from './file-store.mjs';
|
|
2
|
+
export { createHttpContractGateSnapshotStore } from './http-store.mjs';
|
|
3
|
+
export { resolveContractGateSnapshotStore } from './resolve.mjs';
|
|
4
|
+
export type { ContractGateSnapshotHttpStoreOptions, ContractGateSnapshotStore, ContractGateSnapshotStoreFactory, ContractGateSnapshotStoreFactoryContext, ContractGateSnapshotStoreModule, ContractGateSnapshotStoreUserConfig, GateSnapshot, GateSnapshotGateValue, } from './types.mjs';
|
|
5
|
+
export { CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION, DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH, } from './types.mjs';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ContractGateSnapshotStore, ContractGateSnapshotStoreUserConfig, GateSnapshot, LoggerLike } from './types.mjs';
|
|
2
|
+
export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
|
|
3
|
+
export declare const normalizeSnapshot: (snapshot: unknown) => GateSnapshot | undefined;
|
|
4
|
+
export declare const resolveContractGateSnapshotStore: (input: {
|
|
5
|
+
appDirectory: string;
|
|
6
|
+
gateSnapshotPath: string;
|
|
7
|
+
stateStore?: ContractGateSnapshotStoreUserConfig;
|
|
8
|
+
logger?: LoggerLike;
|
|
9
|
+
}) => Promise<ContractGateSnapshotStore>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export declare const CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION = 1;
|
|
2
|
+
export declare const DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH = ".modern/contract-gates.json";
|
|
3
|
+
export type GateSnapshotGateValue = boolean | {
|
|
4
|
+
passed?: boolean;
|
|
5
|
+
reason?: string;
|
|
6
|
+
updatedAt?: number;
|
|
7
|
+
expiresAt?: number;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
};
|
|
10
|
+
export type GateSnapshot = {
|
|
11
|
+
schemaVersion?: number;
|
|
12
|
+
updatedAt?: number;
|
|
13
|
+
gates?: Record<string, GateSnapshotGateValue>;
|
|
14
|
+
};
|
|
15
|
+
export type LoggerLike = {
|
|
16
|
+
info?: (message: string) => void;
|
|
17
|
+
warn?: (message: string) => void;
|
|
18
|
+
};
|
|
19
|
+
export type ContractGateSnapshotStore = {
|
|
20
|
+
name: string;
|
|
21
|
+
readSnapshot: () => Promise<GateSnapshot | undefined>;
|
|
22
|
+
writeSnapshot: (snapshot: GateSnapshot) => Promise<void>;
|
|
23
|
+
};
|
|
24
|
+
export type ContractGateSnapshotStoreFactoryContext = {
|
|
25
|
+
appDirectory: string;
|
|
26
|
+
gateSnapshotPath: string;
|
|
27
|
+
options?: Record<string, unknown>;
|
|
28
|
+
logger?: LoggerLike;
|
|
29
|
+
};
|
|
30
|
+
export type ContractGateSnapshotStoreFactory = (context: ContractGateSnapshotStoreFactoryContext) => Promise<ContractGateSnapshotStore> | ContractGateSnapshotStore;
|
|
31
|
+
export type ContractGateSnapshotStoreModule = {
|
|
32
|
+
createContractGateSnapshotStore?: ContractGateSnapshotStoreFactory;
|
|
33
|
+
default?: ContractGateSnapshotStoreFactory | {
|
|
34
|
+
createContractGateSnapshotStore?: ContractGateSnapshotStoreFactory;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export type ContractGateSnapshotStoreUserConfig = {
|
|
38
|
+
module: string;
|
|
39
|
+
options?: Record<string, unknown>;
|
|
40
|
+
};
|
|
41
|
+
export type ContractGateSnapshotHttpStoreOptions = {
|
|
42
|
+
endpoint: string;
|
|
43
|
+
readMethod?: string;
|
|
44
|
+
writeMethod?: string;
|
|
45
|
+
headers?: Record<string, string>;
|
|
46
|
+
timeoutMs?: number;
|
|
47
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ContractGateSnapshotStore } from './contract-gate-snapshot-store/types.mjs';
|
|
2
|
+
import type { TelemetryHealthMonitor } from './telemetry/healthMonitor.mjs';
|
|
3
|
+
type LoggerLike = {
|
|
4
|
+
info?: (message: string) => void;
|
|
5
|
+
warn?: (message: string) => void;
|
|
6
|
+
};
|
|
7
|
+
export type ContractGateSnapshotObserverOptions = {
|
|
8
|
+
monitor: TelemetryHealthMonitor;
|
|
9
|
+
gateSnapshotPath?: string;
|
|
10
|
+
gateSnapshotStore?: ContractGateSnapshotStore;
|
|
11
|
+
pollIntervalMs?: number;
|
|
12
|
+
gateStaleAfterMs?: number;
|
|
13
|
+
logger?: LoggerLike;
|
|
14
|
+
};
|
|
15
|
+
/** Polls contract-gate snapshots and exposes them to telemetry health checks. */
|
|
16
|
+
export declare class ContractGateSnapshotObserver {
|
|
17
|
+
private readonly monitor;
|
|
18
|
+
private readonly gateSnapshotStore;
|
|
19
|
+
private readonly gateSnapshotPath?;
|
|
20
|
+
private readonly pollIntervalMs;
|
|
21
|
+
private readonly gateStaleAfterMs;
|
|
22
|
+
private readonly logger?;
|
|
23
|
+
private poller?;
|
|
24
|
+
private syncGeneration;
|
|
25
|
+
private readonly appliedGateFingerprints;
|
|
26
|
+
constructor(options: ContractGateSnapshotObserverOptions);
|
|
27
|
+
start(): Promise<void>;
|
|
28
|
+
stop(): void;
|
|
29
|
+
syncOnce(): Promise<number>;
|
|
30
|
+
private clearOmittedGates;
|
|
31
|
+
private loadSnapshot;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single typed pass over the statically-known environment variables consumed
|
|
3
|
+
* by the ultramodern.js server runtime extensions (telemetry pipeline and
|
|
4
|
+
* contract-gate canary autopilot).
|
|
5
|
+
*
|
|
6
|
+
* Modules in this package read this environment state through
|
|
7
|
+
* `parseServerRuntimeExtensionsEnv()` so the surface is documented and
|
|
8
|
+
* testable in one place, with one documented exception: the telemetry
|
|
9
|
+
* runtime-fallback-signal auth config can name an arbitrary token variable
|
|
10
|
+
* via `auth.expectedValueEnv`, which is necessarily read dynamically from
|
|
11
|
+
* `process.env` when that config is normalized. See the package README for
|
|
12
|
+
* per-variable docs.
|
|
13
|
+
*/
|
|
14
|
+
export declare const DEFAULT_ENVIRONMENT_NAME = "development";
|
|
15
|
+
export interface ServerRuntimeExtensionsEnv {
|
|
16
|
+
/**
|
|
17
|
+
* `MODERN_ENV` — deployment environment name loaded by the Modern.js env
|
|
18
|
+
* bootstrap (`.env.{MODERN_ENV}`). Undefined when unset or blank.
|
|
19
|
+
*/
|
|
20
|
+
modernEnv?: string;
|
|
21
|
+
/** `NODE_ENV` — standard Node.js environment name. Undefined when unset or blank. */
|
|
22
|
+
nodeEnv?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Effective telemetry environment label:
|
|
25
|
+
* `MODERN_ENV` || `NODE_ENV` || `"development"`.
|
|
26
|
+
*/
|
|
27
|
+
environmentName: string;
|
|
28
|
+
/**
|
|
29
|
+
* `MODERN_CONTRACT_GATES_FILE` — path of the contract-gate snapshot file
|
|
30
|
+
* (absolute, or relative to the app directory). Undefined when unset.
|
|
31
|
+
*/
|
|
32
|
+
contractGatesFile?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Parse the statically-known environment variables consumed by this package
|
|
36
|
+
* in one typed, documented pass. Defaults are applied here so consumers never
|
|
37
|
+
* touch `process.env` directly (except the documented `expectedValueEnv`
|
|
38
|
+
* indirection above).
|
|
39
|
+
*/
|
|
40
|
+
export declare const parseServerRuntimeExtensionsEnv: (env?: Record<string, string | undefined>) => ServerRuntimeExtensionsEnv;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { type BackendFederationCommonJsEvaluator, type BackendFederationEntryExports, type BackendFederationEntryIntegrity, type BackendFederationRemoteEntry, BackendFederationRemoteEntryError, type BackendFederationRemoteEntryErrorCode, type BackendFederationRemoteEntryExpectation, type BackendFederationRemoteEntryFetch, type BackendFederationRemoteEntryPolicy, type BackendFederationRemoteEntryVerification, type BackendFederationResourceFetch, type BackendFederationResourcePolicy, type BackendFederationResourceResponse, evaluateBackendFederationCommonJsEntry, type LoadBoundedBackendFederationResourceOptions, type LoadVerifiedBackendFederationEntryOptions, loadBoundedBackendFederationResource, loadVerifiedBackendFederationEntry, redactBackendFederationUrl, resolveBackendFederationRemoteEntryVerification, } from './backend-federation-security/index.mjs';
|
|
2
|
+
export { ContractGateSnapshotObserver, type ContractGateSnapshotObserverOptions, } from './contractGateSnapshotObserver.mjs';
|
|
3
|
+
export { DEFAULT_ENVIRONMENT_NAME, parseServerRuntimeExtensionsEnv, type ServerRuntimeExtensionsEnv, } from './env.mjs';
|
|
4
|
+
export { getRequestPathname, injectMfAssetCacheHeadersPlugin, isMfManifestAsset, isMfRemoteEntryAsset, resolveMfAssetCacheHeaders, } from './mfCache.mjs';
|
|
5
|
+
export { type CollectDirectRemoteModuleFederationCssOptions, collectDirectRemoteModuleFederationCss, collectDirectRemoteModuleFederationCssWithMeta, collectModuleFederationManifestCss, createModuleFederationCssCollector, injectModuleFederationCssPlugin, type ModuleFederationCssCollectorOptions, type ModuleFederationCssPluginOptions, type ModuleFederationManifest, type RemoteModuleFederationCssCollection, } from './module-federation-css/index.mjs';
|
|
6
|
+
export { createDisposableServerRuntimeHandle, type DisposableServerRuntimeHandle, disposeServerRuntime, initializeDisposableServerRuntime, registerServerRuntimeDisposer, type ServerRuntimeHandle, } from './runtimeLifecycle.mjs';
|
|
7
|
+
export type { UltramodernBffUserConfig, UltramodernServerUserConfig, } from './serverConfig.mjs';
|
|
8
|
+
export { createOtlpTelemetryExporter, createRuntimeFallbackSignalRuntimeState, createRuntimeSignalError, createTelemetryAwareMetrics, createVictoriaMetricsTelemetryExporter, DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT, DEFAULT_RUNTIME_STATUS_ENDPOINT, enforceRuntimeFallbackSignalAuthToken, enforceRuntimeFallbackSignalTrustPolicy, getRuntimeSignalErrorStatusCode, hasEnabledTelemetryExporters, injectTelemetryPlugin, normalizeRequiredRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackTrustPolicy, type OtlpExporterOptions, parseRuntimeFallbackSignalPayloadFromRawBody, type RuntimeFallbackSignalAuthConfig, type RuntimeFallbackSignalRuntimeState, type RuntimeFallbackSignalSource, type RuntimeFallbackSignalTrustContext, type RuntimeFallbackSignalTrustPolicy, type RuntimeSignalError, type RuntimeSignalErrorCode, resolveRuntimeFallbackSignalEndpoint, resolveTelemetrySloOptions, type TelemetryContractGateStatus, type TelemetryEnvelope, type TelemetryExporter, type TelemetryHealthEvaluation, type TelemetryHealthFailure, type TelemetryHealthFailureReason, TelemetryHealthMonitor, type TelemetryHealthMonitorOptions, type TelemetryHealthState, type TelemetryHealthStatusSnapshot, type TelemetryHealthTransition, type TelemetryQueueStats, TelemetryRegistry, type TelemetryRegistryOptions, type TelemetrySignalType, type TelemetrySloAlert, TelemetryStartupHealthError, type VictoriaMetricsExporterOptions, } from './telemetry.mjs';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ServerPlugin } from '@modern-js/server-core';
|
|
2
|
+
export declare function getRequestPathname(url: string): string;
|
|
3
|
+
export declare function isMfManifestAsset(pathname: string): boolean;
|
|
4
|
+
export declare function isMfRemoteEntryAsset(pathname: string): boolean;
|
|
5
|
+
export declare function resolveMfAssetCacheHeaders(url: string, query?: Record<string, unknown>): {
|
|
6
|
+
'cache-control': string;
|
|
7
|
+
pragma: string;
|
|
8
|
+
expires: string;
|
|
9
|
+
} | {
|
|
10
|
+
pragma?: undefined;
|
|
11
|
+
expires?: undefined;
|
|
12
|
+
'cache-control': string;
|
|
13
|
+
} | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Applies the documented MF asset cache-header policy (ADR-0002) to responses
|
|
16
|
+
* for module federation manifest/remoteEntry endpoints:
|
|
17
|
+
*
|
|
18
|
+
* - `mf-manifest.json` / `mf-stats.json` are never cached (`no-store`), so
|
|
19
|
+
* hosts always observe remote redeploys;
|
|
20
|
+
* - `remoteEntry*.js` revalidates unless explicitly version-pinned via a
|
|
21
|
+
* `mfv`/`v`/`version` query parameter, in which case it is immutable.
|
|
22
|
+
*
|
|
23
|
+
* Composed with the other fork server plugins. The middleware runs in the
|
|
24
|
+
* `pre` phase so it wraps the static-file middleware serving these assets.
|
|
25
|
+
*/
|
|
26
|
+
export declare const injectMfAssetCacheHeadersPlugin: () => ServerPlugin;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Monitors } from '@modern-js/types';
|
|
2
|
+
import type { CollectDirectRemoteModuleFederationCssOptions } from './remote.mjs';
|
|
3
|
+
export type ModuleFederationCssCollectorOptions = CollectDirectRemoteModuleFederationCssOptions & {
|
|
4
|
+
/**
|
|
5
|
+
* How long a successful remote CSS collection may be served from cache.
|
|
6
|
+
* `0` disables caching (beyond in-flight request coalescing).
|
|
7
|
+
*/
|
|
8
|
+
ttlMs?: number;
|
|
9
|
+
/** Clock override for tests. */
|
|
10
|
+
now?: () => number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* TTL cache around remote MF CSS collection. Remote manifests mutate
|
|
14
|
+
* independently of the host (that is the point of module federation), so the
|
|
15
|
+
* collection must expire: a boot-time-forever cache serves stale or broken
|
|
16
|
+
* CSS links after any remote redeploy.
|
|
17
|
+
*
|
|
18
|
+
* Error handling: a collection where any remote fetch failed is never cached.
|
|
19
|
+
* The last known-good asset list is served instead (stale-on-error) and the
|
|
20
|
+
* next request retries the collection.
|
|
21
|
+
*/
|
|
22
|
+
export declare const createModuleFederationCssCollector: (pwd: string, options?: ModuleFederationCssCollectorOptions) => {
|
|
23
|
+
collect(monitors?: Monitors): Promise<string[]>;
|
|
24
|
+
};
|
|
25
|
+
export declare const DEFAULT_REMOTE_CSS_CACHE_TTL_MS = 30000;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { ModuleFederationCssCollectorOptions } from './collector.mjs';
|
|
2
|
+
export { createModuleFederationCssCollector } from './collector.mjs';
|
|
3
|
+
export type { ModuleFederationManifest } from './manifest.mjs';
|
|
4
|
+
export { collectModuleFederationManifestCss } from './manifest.mjs';
|
|
5
|
+
export type { ModuleFederationCssPluginOptions } from './plugin.mjs';
|
|
6
|
+
export { injectModuleFederationCssPlugin } from './plugin.mjs';
|
|
7
|
+
export type { CollectDirectRemoteModuleFederationCssOptions, RemoteModuleFederationCssCollection, } from './remote.mjs';
|
|
8
|
+
export { collectDirectRemoteModuleFederationCss, collectDirectRemoteModuleFederationCssWithMeta, } from './remote.mjs';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Monitors } from '@modern-js/types';
|
|
2
|
+
type ModuleFederationAssets = {
|
|
3
|
+
css?: {
|
|
4
|
+
sync?: string[];
|
|
5
|
+
async?: string[];
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export type ModuleFederationManifest = {
|
|
9
|
+
metaData?: {
|
|
10
|
+
publicPath?: string;
|
|
11
|
+
};
|
|
12
|
+
shared?: Array<{
|
|
13
|
+
assets?: ModuleFederationAssets;
|
|
14
|
+
}>;
|
|
15
|
+
remotes?: Array<{
|
|
16
|
+
entry?: string;
|
|
17
|
+
assets?: ModuleFederationAssets;
|
|
18
|
+
}>;
|
|
19
|
+
exposes?: Array<{
|
|
20
|
+
assets?: ModuleFederationAssets;
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
23
|
+
export declare const warn: (monitors: Monitors | undefined, message: string, ...args: unknown[]) => void;
|
|
24
|
+
export declare const ensureTrailingSlash: (value: string) => string;
|
|
25
|
+
export declare const normalizeRemoteEntry: (entry: string) => string | undefined;
|
|
26
|
+
export declare const collectModuleFederationManifestCss: (manifest: ModuleFederationManifest, manifestUrl: string) => string[];
|
|
27
|
+
export declare const getHostManifest: (pwd: string, monitors?: Monitors) => Promise<ModuleFederationManifest | undefined>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ServerPlugin } from '@modern-js/server-core';
|
|
2
|
+
export type ModuleFederationCssPluginOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* TTL for the cached remote CSS collection in production.
|
|
5
|
+
*
|
|
6
|
+
* @default 30000 in production, 0 (no caching) otherwise
|
|
7
|
+
*/
|
|
8
|
+
remoteCssCacheTtlMs?: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Enriches the request-scoped server manifest with CSS assets collected from
|
|
12
|
+
* direct module federation remotes, so SSR/CSR-RSC rendering can inline
|
|
13
|
+
* `<link>` tags for remote CSS.
|
|
14
|
+
*
|
|
15
|
+
* In production the collection is cached with a TTL (default 30s) instead of
|
|
16
|
+
* being pinned at boot: remote manifests change on every remote redeploy, and
|
|
17
|
+
* fetch failures must not pin an empty/partial list for the process lifetime.
|
|
18
|
+
*
|
|
19
|
+
* Existing plugin ordering places this after the native resource plugin
|
|
20
|
+
* (which sets `serverManifest`) and before the native RSC manifest plugin.
|
|
21
|
+
*/
|
|
22
|
+
export declare const injectModuleFederationCssPlugin: (options?: ModuleFederationCssPluginOptions) => ServerPlugin;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Monitors } from '@modern-js/types';
|
|
2
|
+
type FetchLike = (input: string, init?: {
|
|
3
|
+
signal?: AbortSignal;
|
|
4
|
+
}) => Promise<Response>;
|
|
5
|
+
export type CollectDirectRemoteModuleFederationCssOptions = {
|
|
6
|
+
fetcher?: FetchLike;
|
|
7
|
+
monitors?: Monitors;
|
|
8
|
+
timeout?: number;
|
|
9
|
+
};
|
|
10
|
+
export type RemoteModuleFederationCssCollection = {
|
|
11
|
+
assets: string[];
|
|
12
|
+
/**
|
|
13
|
+
* True when at least one remote manifest fetch failed, i.e. `assets` may be
|
|
14
|
+
* incomplete and should not be cached long-term.
|
|
15
|
+
*/
|
|
16
|
+
errored: boolean;
|
|
17
|
+
};
|
|
18
|
+
export declare const collectDirectRemoteModuleFederationCssWithMeta: (pwd: string, options?: CollectDirectRemoteModuleFederationCssOptions) => Promise<RemoteModuleFederationCssCollection>;
|
|
19
|
+
export declare const collectDirectRemoteModuleFederationCss: (pwd: string, options?: CollectDirectRemoteModuleFederationCssOptions) => Promise<string[]>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { RuntimeFallbackSignalAuthConfig, RuntimeFallbackSignalConfig, RuntimeFallbackSignalRuntimeState, RuntimeFallbackSignalSource, RuntimeFallbackSignalTrustContext, RuntimeFallbackSignalTrustPolicy, RuntimeSignalError, RuntimeSignalErrorCode, } from './model.mjs';
|
|
2
|
+
export { createRuntimeSignalError, DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS, DEFAULT_RUNTIME_FALLBACK_GATE_NAME, DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES, DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT, DEFAULT_RUNTIME_STATUS_ENDPOINT, getRuntimeSignalErrorStatusCode, parseRuntimeFallbackSignalPayload, parseRuntimeFallbackSignalPayloadFromRawBody, } from './model.mjs';
|
|
3
|
+
export { enforceRuntimeFallbackSignalAuth, enforceRuntimeFallbackSignalAuthToken, enforceRuntimeFallbackSignalTrustPolicy, normalizeRequiredRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackTrustPolicy, resolveRuntimeFallbackSignalEndpoint, } from './resolver.mjs';
|
|
4
|
+
export { createRuntimeFallbackSignalRuntimeState, persistRuntimeFallbackContractGate, } from './store.mjs';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Context, ServerEnv } from '@modern-js/server-core';
|
|
2
|
+
import type { ContractGateSnapshotStore } from '../contract-gate-snapshot-store/index.mjs';
|
|
3
|
+
export declare const DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT = "/_modern/contract-gates/runtime-fallback";
|
|
4
|
+
export declare const DEFAULT_RUNTIME_STATUS_ENDPOINT = "/_modern/runtime/status";
|
|
5
|
+
export declare const DEFAULT_RUNTIME_FALLBACK_GATE_NAME = "runtime-mf-fallback-health";
|
|
6
|
+
export declare const DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS: number;
|
|
7
|
+
export declare const DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES: number;
|
|
8
|
+
export declare const DEFAULT_RUNTIME_FALLBACK_AUTH_HEADER = "x-modernjs-runtime-signal-token";
|
|
9
|
+
export declare const DEFAULT_RUNTIME_FALLBACK_TRUST_MAX_SIGNALS_PER_WINDOW = 30;
|
|
10
|
+
export declare const DEFAULT_RUNTIME_FALLBACK_TRUST_WINDOW_MS = 60000;
|
|
11
|
+
export declare const DEFAULT_RUNTIME_FALLBACK_TRUST_DEDUPE_WINDOW_MS = 10000;
|
|
12
|
+
export type RuntimeSignalErrorCode = 'PAYLOAD_TOO_LARGE' | 'INVALID_PAYLOAD' | 'RATE_LIMITED' | 'UNAUTHORIZED' | 'UNTRUSTED_SOURCE';
|
|
13
|
+
export type RuntimeSignalError = Error & {
|
|
14
|
+
code?: RuntimeSignalErrorCode;
|
|
15
|
+
};
|
|
16
|
+
export type RuntimeFallbackSignalTrustPolicy = {
|
|
17
|
+
allowedApps: string[];
|
|
18
|
+
allowedEntryOrigins: string[];
|
|
19
|
+
expectedRuntimeDigests: Record<string, string>;
|
|
20
|
+
enforceRuntimeDigest: boolean;
|
|
21
|
+
maxSignalsPerWindow: number;
|
|
22
|
+
windowMs: number;
|
|
23
|
+
dedupeWindowMs: number;
|
|
24
|
+
};
|
|
25
|
+
type RuntimeFallbackSignalRateLimitState = {
|
|
26
|
+
count: number;
|
|
27
|
+
windowStartedAt: number;
|
|
28
|
+
};
|
|
29
|
+
export type RuntimeFallbackSignalAuthConfig = {
|
|
30
|
+
enabled: boolean;
|
|
31
|
+
headerName: string;
|
|
32
|
+
expectedValue?: string;
|
|
33
|
+
};
|
|
34
|
+
export type RuntimeFallbackSignalRuntimeState = {
|
|
35
|
+
rateLimitBySource: Map<string, RuntimeFallbackSignalRateLimitState>;
|
|
36
|
+
dedupeByFingerprint: Map<string, number>;
|
|
37
|
+
};
|
|
38
|
+
export type RuntimeFallbackSignalTrustContext = {
|
|
39
|
+
trustPolicy: RuntimeFallbackSignalTrustPolicy;
|
|
40
|
+
runtimeState: RuntimeFallbackSignalRuntimeState;
|
|
41
|
+
};
|
|
42
|
+
export type RuntimeFallbackSignalConfig = {
|
|
43
|
+
endpoint: string;
|
|
44
|
+
gateName: string;
|
|
45
|
+
gateSnapshotStore: Promise<ContractGateSnapshotStore>;
|
|
46
|
+
failureHoldMs: number;
|
|
47
|
+
maxBodyBytes: number;
|
|
48
|
+
auth: RuntimeFallbackSignalAuthConfig;
|
|
49
|
+
trustPolicy: RuntimeFallbackSignalTrustPolicy;
|
|
50
|
+
runtimeState: RuntimeFallbackSignalRuntimeState;
|
|
51
|
+
};
|
|
52
|
+
export type RuntimeFallbackSignalSource = {
|
|
53
|
+
/**
|
|
54
|
+
* Server-trusted connection identity (socket remote address). Never derive
|
|
55
|
+
* request headers or payload: both are attacker-controlled and would let
|
|
56
|
+
* callers reset their own rate-limit budget.
|
|
57
|
+
*/
|
|
58
|
+
remoteAddress?: string;
|
|
59
|
+
};
|
|
60
|
+
export declare function createRuntimeSignalError(message: string, code: RuntimeSignalError['code']): RuntimeSignalError;
|
|
61
|
+
export declare function getRuntimeSignalErrorStatusCode(signalError: RuntimeSignalError): 400 | 401 | 403 | 413 | 429 | 500;
|
|
62
|
+
export declare function normalizeRuntimeSignalOrigin(value: unknown): string | undefined;
|
|
63
|
+
export declare function normalizeRuntimeSignalAppName(payload: Record<string, unknown>): string;
|
|
64
|
+
export declare function normalizeRuntimeSignalRuntimeDigest(payload: Record<string, unknown>): string | undefined;
|
|
65
|
+
export declare function parseRuntimeFallbackSignalPayload(c: Context<ServerEnv>, maxBodyBytes: number): Promise<{
|
|
66
|
+
rawBody: string;
|
|
67
|
+
payload: Record<string, unknown>;
|
|
68
|
+
}>;
|
|
69
|
+
export declare function parseRuntimeFallbackSignalPayloadFromRawBody(rawBody: string, maxBodyBytes: number): Record<string, unknown>;
|
|
70
|
+
export {};
|