@bleedingdev/modern-js-server-runtime-extensions 3.5.0-ultramodern.35 → 3.5.0-ultramodern.37
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/dist/cjs/contract-gate-snapshot-normalization.js +122 -0
- package/dist/cjs/contract-gate-snapshot-store/file-store.js +13 -13
- package/dist/cjs/contract-gate-snapshot-store/http-store.js +2 -11
- package/dist/cjs/contract-gate-snapshot-store/resolve.js +8 -6
- package/dist/cjs/contractGateAutopilot.js +8 -77
- package/dist/cjs/index.js +6 -25
- package/dist/cjs/module-federation-css/manifest.js +3 -18
- package/dist/cjs/runtime-fallback-signal/index.js +21 -27
- package/dist/cjs/runtime-fallback-signal/model.js +157 -0
- package/dist/cjs/runtime-fallback-signal/resolver.js +163 -0
- package/dist/cjs/runtime-fallback-signal/{contract-gate.js → store.js} +19 -0
- package/dist/cjs/telemetry/envelope.js +74 -0
- package/dist/cjs/telemetry/registry.js +20 -72
- package/dist/esm/contract-gate-snapshot-normalization.mjs +81 -0
- package/dist/esm/contract-gate-snapshot-store/file-store.mjs +7 -7
- package/dist/esm/contract-gate-snapshot-store/http-store.mjs +1 -1
- package/dist/esm/contract-gate-snapshot-store/resolve.mjs +7 -5
- package/dist/esm/contractGateAutopilot.mjs +7 -76
- package/dist/esm/index.mjs +0 -1
- package/dist/esm/module-federation-css/manifest.mjs +3 -3
- package/dist/esm/runtime-fallback-signal/index.mjs +3 -9
- package/dist/esm/runtime-fallback-signal/model.mjs +73 -0
- package/dist/esm/runtime-fallback-signal/resolver.mjs +107 -0
- package/dist/esm/runtime-fallback-signal/{contract-gate.mjs → store.mjs} +14 -1
- package/dist/esm/telemetry/envelope.mjs +63 -1
- package/dist/esm/telemetry/registry.mjs +21 -73
- package/dist/esm-node/contract-gate-snapshot-normalization.mjs +82 -0
- package/dist/esm-node/contract-gate-snapshot-store/file-store.mjs +7 -7
- package/dist/esm-node/contract-gate-snapshot-store/http-store.mjs +1 -1
- package/dist/esm-node/contract-gate-snapshot-store/resolve.mjs +8 -7
- package/dist/esm-node/contractGateAutopilot.mjs +7 -76
- package/dist/esm-node/index.mjs +0 -1
- package/dist/esm-node/module-federation-css/manifest.mjs +3 -3
- package/dist/esm-node/runtime-fallback-signal/index.mjs +3 -9
- package/dist/esm-node/runtime-fallback-signal/model.mjs +74 -0
- package/dist/esm-node/runtime-fallback-signal/resolver.mjs +108 -0
- package/dist/esm-node/runtime-fallback-signal/{contract-gate.mjs → store.mjs} +14 -1
- package/dist/esm-node/telemetry/envelope.mjs +63 -1
- package/dist/esm-node/telemetry/registry.mjs +21 -73
- package/dist/types/contract-gate-snapshot-normalization.d.ts +15 -0
- package/dist/types/contract-gate-snapshot-store/http-store.d.ts +0 -6
- package/dist/types/contractGateAutopilot.d.ts +1 -6
- package/dist/types/index.d.ts +0 -1
- package/dist/types/module-federation-css/manifest.d.ts +0 -5
- package/dist/types/runtime-fallback-signal/index.d.ts +4 -10
- package/dist/types/runtime-fallback-signal/model.d.ts +70 -0
- package/dist/types/runtime-fallback-signal/resolver.d.ts +29 -0
- package/dist/types/runtime-fallback-signal/store.d.ts +4 -0
- package/dist/types/telemetry/canaryEvaluation.d.ts +3 -2
- package/dist/types/telemetry/envelope.d.ts +10 -0
- package/dist/types/telemetry/registry.d.ts +1 -4
- package/package.json +9 -9
- package/src/contract-gate-snapshot-normalization.ts +155 -0
- package/src/contract-gate-snapshot-store/file-store.ts +2 -4
- package/src/contract-gate-snapshot-store/http-store.ts +3 -3
- package/src/contract-gate-snapshot-store/resolve.ts +8 -4
- package/src/contractGateAutopilot.ts +13 -141
- package/src/index.ts +0 -16
- package/src/module-federation-css/manifest.ts +6 -9
- package/src/runtime-fallback-signal/index.ts +23 -25
- package/src/runtime-fallback-signal/model.ts +230 -0
- package/src/runtime-fallback-signal/resolver.ts +304 -0
- package/src/runtime-fallback-signal/{contract-gate.ts → store.ts} +38 -3
- package/src/telemetry/canaryEvaluation.ts +2 -2
- package/src/telemetry/envelope.ts +84 -0
- package/src/telemetry/registry.ts +31 -74
- package/tests/telemetryAutopilot.test.ts +141 -0
- package/tests/telemetryRegistryQueueMatrix.test.ts +227 -0
- package/dist/cjs/runtime-fallback-signal/auth.js +0 -87
- package/dist/cjs/runtime-fallback-signal/constants.js +0 -72
- package/dist/cjs/runtime-fallback-signal/endpoint.js +0 -50
- package/dist/cjs/runtime-fallback-signal/errors.js +0 -44
- package/dist/cjs/runtime-fallback-signal/payload.js +0 -72
- package/dist/cjs/runtime-fallback-signal/source.js +0 -66
- package/dist/cjs/runtime-fallback-signal/state.js +0 -57
- package/dist/cjs/runtime-fallback-signal/status.js +0 -47
- package/dist/cjs/runtime-fallback-signal/trust-policy.js +0 -108
- package/dist/cjs/runtime-fallback-signal/types.js +0 -18
- package/dist/esm/runtime-fallback-signal/auth.mjs +0 -40
- package/dist/esm/runtime-fallback-signal/constants.mjs +0 -10
- package/dist/esm/runtime-fallback-signal/endpoint.mjs +0 -12
- package/dist/esm/runtime-fallback-signal/errors.mjs +0 -6
- package/dist/esm/runtime-fallback-signal/payload.mjs +0 -31
- package/dist/esm/runtime-fallback-signal/source.mjs +0 -22
- package/dist/esm/runtime-fallback-signal/state.mjs +0 -16
- package/dist/esm/runtime-fallback-signal/status.mjs +0 -9
- package/dist/esm/runtime-fallback-signal/trust-policy.mjs +0 -67
- package/dist/esm/runtime-fallback-signal/types.mjs +0 -0
- package/dist/esm-node/runtime-fallback-signal/auth.mjs +0 -41
- package/dist/esm-node/runtime-fallback-signal/constants.mjs +0 -11
- package/dist/esm-node/runtime-fallback-signal/endpoint.mjs +0 -13
- package/dist/esm-node/runtime-fallback-signal/errors.mjs +0 -7
- package/dist/esm-node/runtime-fallback-signal/payload.mjs +0 -32
- package/dist/esm-node/runtime-fallback-signal/source.mjs +0 -23
- package/dist/esm-node/runtime-fallback-signal/state.mjs +0 -17
- package/dist/esm-node/runtime-fallback-signal/status.mjs +0 -10
- package/dist/esm-node/runtime-fallback-signal/trust-policy.mjs +0 -68
- package/dist/esm-node/runtime-fallback-signal/types.mjs +0 -1
- package/dist/types/runtime-fallback-signal/auth.d.ts +0 -18
- package/dist/types/runtime-fallback-signal/constants.d.ts +0 -9
- package/dist/types/runtime-fallback-signal/contract-gate.d.ts +0 -2
- package/dist/types/runtime-fallback-signal/endpoint.d.ts +0 -1
- package/dist/types/runtime-fallback-signal/errors.d.ts +0 -2
- package/dist/types/runtime-fallback-signal/payload.d.ts +0 -6
- package/dist/types/runtime-fallback-signal/source.d.ts +0 -3
- package/dist/types/runtime-fallback-signal/state.d.ts +0 -3
- package/dist/types/runtime-fallback-signal/status.d.ts +0 -2
- package/dist/types/runtime-fallback-signal/trust-policy.d.ts +0 -13
- package/dist/types/runtime-fallback-signal/types.d.ts +0 -50
- package/src/runtime-fallback-signal/auth.ts +0 -117
- package/src/runtime-fallback-signal/constants.ts +0 -19
- package/src/runtime-fallback-signal/endpoint.ts +0 -22
- package/src/runtime-fallback-signal/errors.ts +0 -10
- package/src/runtime-fallback-signal/payload.ts +0 -79
- package/src/runtime-fallback-signal/source.ts +0 -49
- package/src/runtime-fallback-signal/state.ts +0 -34
- package/src/runtime-fallback-signal/status.ts +0 -22
- package/src/runtime-fallback-signal/trust-policy.ts +0 -179
- package/src/runtime-fallback-signal/types.ts +0 -66
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
GateSnapshot,
|
|
3
|
+
GateSnapshotGateValue,
|
|
4
|
+
} from './contract-gate-snapshot-store/types';
|
|
5
|
+
|
|
6
|
+
type NormalizedGate = {
|
|
7
|
+
name: string;
|
|
8
|
+
passed: boolean;
|
|
9
|
+
reason?: string;
|
|
10
|
+
updatedAt: number;
|
|
11
|
+
expiresAt?: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type NormalizeSnapshotOptions = {
|
|
15
|
+
now: number;
|
|
16
|
+
gateStaleAfterMs: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type SnapshotGateEntry = [string, GateSnapshotGateValue];
|
|
20
|
+
|
|
21
|
+
const getSnapshotGateEntries = (
|
|
22
|
+
snapshot: GateSnapshot,
|
|
23
|
+
): SnapshotGateEntry[] | undefined => {
|
|
24
|
+
const gates = snapshot.gates;
|
|
25
|
+
if (!gates || typeof gates !== 'object') {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const entries: SnapshotGateEntry[] = [];
|
|
30
|
+
for (const [name, value] of Object.entries(gates)) {
|
|
31
|
+
const normalizedName = name.trim();
|
|
32
|
+
if (!normalizedName) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
entries.push([normalizedName, value]);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return entries;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const getSnapshotGateNames = (snapshot: GateSnapshot) => {
|
|
42
|
+
const entries = getSnapshotGateEntries(snapshot);
|
|
43
|
+
if (!entries) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const names = new Set<string>();
|
|
48
|
+
for (const [name] of entries) {
|
|
49
|
+
names.add(name);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return names;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const normalizeSnapshot = (
|
|
56
|
+
snapshot: GateSnapshot,
|
|
57
|
+
{ now, gateStaleAfterMs }: NormalizeSnapshotOptions,
|
|
58
|
+
) => {
|
|
59
|
+
const output: NormalizedGate[] = [];
|
|
60
|
+
const entries = getSnapshotGateEntries(snapshot);
|
|
61
|
+
if (!entries) {
|
|
62
|
+
return output;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
for (const [normalizedName, value] of entries) {
|
|
66
|
+
const gate = normalizeGateValue(value, snapshot.updatedAt, now);
|
|
67
|
+
if (!gate) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (
|
|
72
|
+
typeof gate.expiresAt === 'number' &&
|
|
73
|
+
Number.isFinite(gate.expiresAt) &&
|
|
74
|
+
gate.expiresAt > 0 &&
|
|
75
|
+
now >= gate.expiresAt
|
|
76
|
+
) {
|
|
77
|
+
output.push({
|
|
78
|
+
name: normalizedName,
|
|
79
|
+
passed: true,
|
|
80
|
+
reason: undefined,
|
|
81
|
+
updatedAt: gate.updatedAt,
|
|
82
|
+
expiresAt: gate.expiresAt,
|
|
83
|
+
});
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const isStale =
|
|
88
|
+
gateStaleAfterMs > 0 && now - gate.updatedAt > gateStaleAfterMs;
|
|
89
|
+
if (isStale) {
|
|
90
|
+
output.push({
|
|
91
|
+
name: normalizedName,
|
|
92
|
+
passed: false,
|
|
93
|
+
reason: gate.reason || 'Gate snapshot is stale',
|
|
94
|
+
updatedAt: gate.updatedAt,
|
|
95
|
+
});
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
output.push({
|
|
100
|
+
name: normalizedName,
|
|
101
|
+
passed: gate.passed,
|
|
102
|
+
reason: gate.reason,
|
|
103
|
+
updatedAt: gate.updatedAt,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return output;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const normalizeGateValue = (
|
|
111
|
+
value: GateSnapshotGateValue,
|
|
112
|
+
snapshotUpdatedAt: number | undefined,
|
|
113
|
+
now: number,
|
|
114
|
+
) => {
|
|
115
|
+
if (typeof value === 'boolean') {
|
|
116
|
+
return {
|
|
117
|
+
passed: value,
|
|
118
|
+
updatedAt: normalizeUpdatedAt(snapshotUpdatedAt, now),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (!value || typeof value !== 'object') {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const hasPassed = typeof value.passed === 'boolean';
|
|
127
|
+
const passed = value.passed === true;
|
|
128
|
+
let reason =
|
|
129
|
+
typeof value.reason === 'string' && value.reason.trim().length > 0
|
|
130
|
+
? value.reason
|
|
131
|
+
: undefined;
|
|
132
|
+
if (!hasPassed) {
|
|
133
|
+
reason = reason || 'Gate snapshot record missing "passed" boolean';
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
passed,
|
|
137
|
+
reason,
|
|
138
|
+
updatedAt: normalizeUpdatedAt(value.updatedAt ?? snapshotUpdatedAt, now),
|
|
139
|
+
expiresAt: normalizeExpiresAt(value.expiresAt),
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const normalizeUpdatedAt = (value: number | undefined, fallback: number) => {
|
|
144
|
+
if (typeof value === 'number' && Number.isFinite(value) && value > 0) {
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
return fallback;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const normalizeExpiresAt = (value: number | undefined) => {
|
|
151
|
+
if (typeof value === 'number' && Number.isFinite(value) && value > 0) {
|
|
152
|
+
return value;
|
|
153
|
+
}
|
|
154
|
+
return undefined;
|
|
155
|
+
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
import { promises as nodeFs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
1
3
|
import { fs } from '@modern-js/utils';
|
|
2
4
|
|
|
3
|
-
import { promises as nodeFs } from 'fs';
|
|
4
|
-
|
|
5
|
-
import path from 'path';
|
|
6
|
-
|
|
7
5
|
import { parseServerRuntimeExtensionsEnv } from '../env';
|
|
8
6
|
|
|
9
7
|
import { normalizeSnapshot } from './resolve';
|
|
@@ -8,7 +8,7 @@ import { CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION } from './types';
|
|
|
8
8
|
|
|
9
9
|
const DEFAULT_HTTP_STORE_TIMEOUT_MS = 5_000;
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
const BUILTIN_HTTP_STATE_STORE_MODULES = new Set([
|
|
12
12
|
'http',
|
|
13
13
|
// historical aliases kept for config compatibility with the era when these
|
|
14
14
|
// modules lived inside @modern-js/server-core.
|
|
@@ -18,7 +18,7 @@ export const BUILTIN_HTTP_STATE_STORE_MODULES = new Set([
|
|
|
18
18
|
'@modern-js/server-runtime-extensions/contract-gate-http-store',
|
|
19
19
|
]);
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
const normalizeHttpStoreOptions = (
|
|
22
22
|
options: Record<string, unknown> | undefined,
|
|
23
23
|
): ContractGateSnapshotHttpStoreOptions => {
|
|
24
24
|
const endpoint =
|
|
@@ -67,7 +67,7 @@ export const normalizeHttpStoreOptions = (
|
|
|
67
67
|
};
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
const withTimeoutAbort = (timeoutMs: number) => {
|
|
71
71
|
const controller = new AbortController();
|
|
72
72
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
73
73
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
-
|
|
3
|
-
import
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
4
|
|
|
5
5
|
import { createFileContractGateSnapshotStore } from './file-store';
|
|
6
6
|
|
|
@@ -123,6 +123,9 @@ const resolveStoreModulePath = (appDirectory: string, modulePath: string) => {
|
|
|
123
123
|
}
|
|
124
124
|
};
|
|
125
125
|
|
|
126
|
+
const toStoreModuleImportSpecifier = (modulePath: string) =>
|
|
127
|
+
path.isAbsolute(modulePath) ? pathToFileURL(modulePath).href : modulePath;
|
|
128
|
+
|
|
126
129
|
export const resolveContractGateSnapshotStore = async (input: {
|
|
127
130
|
appDirectory: string;
|
|
128
131
|
gateSnapshotPath: string;
|
|
@@ -146,8 +149,9 @@ export const resolveContractGateSnapshotStore = async (input: {
|
|
|
146
149
|
const modulePath = resolveStoreModulePath(appDirectory, stateStore.module);
|
|
147
150
|
let mod: ContractGateSnapshotStoreModule;
|
|
148
151
|
try {
|
|
149
|
-
|
|
150
|
-
|
|
152
|
+
mod = (await import(
|
|
153
|
+
toStoreModuleImportSpecifier(modulePath)
|
|
154
|
+
)) as ContractGateSnapshotStoreModule;
|
|
151
155
|
} catch (error) {
|
|
152
156
|
throw new Error(
|
|
153
157
|
`[telemetry.canary.autopilot] Failed to load stateStore.module "${stateStore.module}" (${modulePath}): ${error instanceof Error ? error.message : String(error)}`,
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
getSnapshotGateNames,
|
|
3
|
+
normalizeSnapshot,
|
|
4
|
+
} from './contract-gate-snapshot-normalization';
|
|
5
|
+
import { createFileContractGateSnapshotStore } from './contract-gate-snapshot-store/file-store';
|
|
6
|
+
import type {
|
|
7
|
+
ContractGateSnapshotStore,
|
|
8
|
+
GateSnapshot,
|
|
9
|
+
} from './contract-gate-snapshot-store/types';
|
|
7
10
|
import type { TelemetryCanaryOrchestrator } from './telemetryCore';
|
|
8
11
|
|
|
9
12
|
const DEFAULT_POLL_INTERVAL_MS = 15_000;
|
|
@@ -23,14 +26,6 @@ export type ContractGateAutopilotOptions = {
|
|
|
23
26
|
logger?: LoggerLike;
|
|
24
27
|
};
|
|
25
28
|
|
|
26
|
-
type NormalizedGate = {
|
|
27
|
-
name: string;
|
|
28
|
-
passed: boolean;
|
|
29
|
-
reason?: string;
|
|
30
|
-
updatedAt: number;
|
|
31
|
-
expiresAt?: number;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
29
|
export class ContractGateAutopilot {
|
|
35
30
|
private readonly orchestrator: TelemetryCanaryOrchestrator;
|
|
36
31
|
private readonly gateSnapshotStore: ContractGateSnapshotStore;
|
|
@@ -96,8 +91,11 @@ export class ContractGateAutopilot {
|
|
|
96
91
|
return 0;
|
|
97
92
|
}
|
|
98
93
|
|
|
99
|
-
const snapshotGateNames =
|
|
100
|
-
const gates =
|
|
94
|
+
const snapshotGateNames = getSnapshotGateNames(snapshot);
|
|
95
|
+
const gates = normalizeSnapshot(snapshot, {
|
|
96
|
+
now: Date.now(),
|
|
97
|
+
gateStaleAfterMs: this.gateStaleAfterMs,
|
|
98
|
+
});
|
|
101
99
|
let updatedCount = snapshotGateNames
|
|
102
100
|
? this.clearOmittedGates(snapshotGateNames)
|
|
103
101
|
: 0;
|
|
@@ -119,23 +117,6 @@ export class ContractGateAutopilot {
|
|
|
119
117
|
return updatedCount;
|
|
120
118
|
}
|
|
121
119
|
|
|
122
|
-
private getSnapshotGateNames(snapshot: GateSnapshot) {
|
|
123
|
-
const gates = snapshot.gates;
|
|
124
|
-
if (!gates || typeof gates !== 'object') {
|
|
125
|
-
return undefined;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const names = new Set<string>();
|
|
129
|
-
for (const name of Object.keys(gates)) {
|
|
130
|
-
const normalizedName = name.trim();
|
|
131
|
-
if (normalizedName) {
|
|
132
|
-
names.add(normalizedName);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return names;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
120
|
private clearOmittedGates(snapshotGateNames: ReadonlySet<string>) {
|
|
140
121
|
let updatedCount = 0;
|
|
141
122
|
for (const gateName of Array.from(this.appliedGateFingerprints.keys())) {
|
|
@@ -171,113 +152,4 @@ export class ContractGateAutopilot {
|
|
|
171
152
|
return undefined;
|
|
172
153
|
}
|
|
173
154
|
}
|
|
174
|
-
|
|
175
|
-
private normalizeSnapshot(snapshot: GateSnapshot) {
|
|
176
|
-
const now = Date.now();
|
|
177
|
-
const output: NormalizedGate[] = [];
|
|
178
|
-
const gates = snapshot.gates;
|
|
179
|
-
if (!gates || typeof gates !== 'object') {
|
|
180
|
-
return output;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
for (const [name, value] of Object.entries(gates)) {
|
|
184
|
-
const normalizedName = name.trim();
|
|
185
|
-
if (!normalizedName) {
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const gate = this.normalizeGateValue(value, snapshot.updatedAt, now);
|
|
190
|
-
if (!gate) {
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (
|
|
195
|
-
typeof gate.expiresAt === 'number' &&
|
|
196
|
-
Number.isFinite(gate.expiresAt) &&
|
|
197
|
-
gate.expiresAt > 0 &&
|
|
198
|
-
now >= gate.expiresAt
|
|
199
|
-
) {
|
|
200
|
-
output.push({
|
|
201
|
-
name: normalizedName,
|
|
202
|
-
passed: true,
|
|
203
|
-
reason: undefined,
|
|
204
|
-
updatedAt: gate.updatedAt,
|
|
205
|
-
expiresAt: gate.expiresAt,
|
|
206
|
-
});
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const isStale =
|
|
211
|
-
this.gateStaleAfterMs > 0 &&
|
|
212
|
-
now - gate.updatedAt > this.gateStaleAfterMs;
|
|
213
|
-
if (isStale) {
|
|
214
|
-
output.push({
|
|
215
|
-
name: normalizedName,
|
|
216
|
-
passed: false,
|
|
217
|
-
reason: gate.reason || 'Gate snapshot is stale',
|
|
218
|
-
updatedAt: gate.updatedAt,
|
|
219
|
-
});
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
output.push({
|
|
224
|
-
name: normalizedName,
|
|
225
|
-
passed: gate.passed,
|
|
226
|
-
reason: gate.reason,
|
|
227
|
-
updatedAt: gate.updatedAt,
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return output;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
private normalizeGateValue(
|
|
235
|
-
value: GateSnapshotGateValue,
|
|
236
|
-
snapshotUpdatedAt: number | undefined,
|
|
237
|
-
now: number,
|
|
238
|
-
) {
|
|
239
|
-
if (typeof value === 'boolean') {
|
|
240
|
-
return {
|
|
241
|
-
passed: value,
|
|
242
|
-
updatedAt: this.normalizeUpdatedAt(snapshotUpdatedAt, now),
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if (!value || typeof value !== 'object') {
|
|
247
|
-
return undefined;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const hasPassed = typeof value.passed === 'boolean';
|
|
251
|
-
const passed = value.passed === true;
|
|
252
|
-
let reason =
|
|
253
|
-
typeof value.reason === 'string' && value.reason.trim().length > 0
|
|
254
|
-
? value.reason
|
|
255
|
-
: undefined;
|
|
256
|
-
if (!hasPassed) {
|
|
257
|
-
reason = reason || 'Gate snapshot record is missing "passed" boolean';
|
|
258
|
-
}
|
|
259
|
-
return {
|
|
260
|
-
passed,
|
|
261
|
-
reason,
|
|
262
|
-
updatedAt: this.normalizeUpdatedAt(
|
|
263
|
-
value.updatedAt ?? snapshotUpdatedAt,
|
|
264
|
-
now,
|
|
265
|
-
),
|
|
266
|
-
expiresAt: this.normalizeExpiresAt(value.expiresAt),
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
private normalizeUpdatedAt(value: number | undefined, fallback: number) {
|
|
271
|
-
if (typeof value === 'number' && Number.isFinite(value) && value > 0) {
|
|
272
|
-
return value;
|
|
273
|
-
}
|
|
274
|
-
return fallback;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
private normalizeExpiresAt(value: number | undefined) {
|
|
278
|
-
if (typeof value === 'number' && Number.isFinite(value) && value > 0) {
|
|
279
|
-
return value;
|
|
280
|
-
}
|
|
281
|
-
return undefined;
|
|
282
|
-
}
|
|
283
155
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION,
|
|
3
|
-
type ContractGateSnapshotHttpStoreOptions,
|
|
4
|
-
type ContractGateSnapshotStore,
|
|
5
|
-
type ContractGateSnapshotStoreFactory,
|
|
6
|
-
type ContractGateSnapshotStoreFactoryContext,
|
|
7
|
-
type ContractGateSnapshotStoreModule,
|
|
8
|
-
type ContractGateSnapshotStoreUserConfig,
|
|
9
|
-
createFileContractGateSnapshotStore,
|
|
10
|
-
createHttpContractGateSnapshotStore,
|
|
11
|
-
DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH,
|
|
12
|
-
type GateSnapshot,
|
|
13
|
-
type GateSnapshotGateValue,
|
|
14
|
-
resolveContractGateSnapshotPath,
|
|
15
|
-
resolveContractGateSnapshotStore,
|
|
16
|
-
} from './contract-gate-snapshot-store';
|
|
17
1
|
export {
|
|
18
2
|
ContractGateAutopilot,
|
|
19
3
|
type ContractGateAutopilotOptions,
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
1
2
|
import { fileReader } from '@modern-js/runtime-utils/fileReader';
|
|
2
|
-
|
|
3
3
|
import type { Monitors } from '@modern-js/types';
|
|
4
|
-
|
|
5
4
|
import { fs } from '@modern-js/utils';
|
|
6
5
|
|
|
7
|
-
import path from 'path';
|
|
8
|
-
|
|
9
6
|
const MODULE_FEDERATION_MANIFEST_FILE = 'mf-manifest.json';
|
|
10
7
|
|
|
11
8
|
type ModuleFederationAssets = {
|
|
@@ -47,7 +44,7 @@ export const warn = (
|
|
|
47
44
|
export const ensureTrailingSlash = (value: string) =>
|
|
48
45
|
value.endsWith('/') ? value : `${value}/`;
|
|
49
46
|
|
|
50
|
-
|
|
47
|
+
const tryResolveUrl = (value: string, base: string) => {
|
|
51
48
|
try {
|
|
52
49
|
return new URL(value, base).toString();
|
|
53
50
|
} catch {
|
|
@@ -65,12 +62,12 @@ export const normalizeRemoteEntry = (entry: string) => {
|
|
|
65
62
|
return atIndex >= 0 ? value.slice(atIndex + 1) : value;
|
|
66
63
|
};
|
|
67
64
|
|
|
68
|
-
|
|
65
|
+
const getCssAssets = (assets?: ModuleFederationAssets) => [
|
|
69
66
|
...(assets?.css?.sync || []),
|
|
70
67
|
...(assets?.css?.async || []),
|
|
71
68
|
];
|
|
72
69
|
|
|
73
|
-
|
|
70
|
+
const getManifestFallbackBase = (manifestUrl: string) => {
|
|
74
71
|
try {
|
|
75
72
|
return new URL('.', manifestUrl).toString();
|
|
76
73
|
} catch {
|
|
@@ -78,7 +75,7 @@ export const getManifestFallbackBase = (manifestUrl: string) => {
|
|
|
78
75
|
}
|
|
79
76
|
};
|
|
80
77
|
|
|
81
|
-
|
|
78
|
+
const getManifestPublicPathBase = (
|
|
82
79
|
publicPath: string | undefined,
|
|
83
80
|
manifestUrl: string,
|
|
84
81
|
) => {
|
|
@@ -90,7 +87,7 @@ export const getManifestPublicPathBase = (
|
|
|
90
87
|
return base || getManifestFallbackBase(manifestUrl);
|
|
91
88
|
};
|
|
92
89
|
|
|
93
|
-
|
|
90
|
+
const appendResolvedCssAssets = (
|
|
94
91
|
result: string[],
|
|
95
92
|
seen: Set<string>,
|
|
96
93
|
assets: string[],
|
|
@@ -1,36 +1,34 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
RuntimeFallbackSignalAuthConfig,
|
|
3
|
+
RuntimeFallbackSignalConfig,
|
|
4
|
+
RuntimeFallbackSignalRuntimeState,
|
|
5
|
+
RuntimeFallbackSignalSource,
|
|
6
|
+
RuntimeFallbackSignalTrustContext,
|
|
7
|
+
RuntimeFallbackSignalTrustPolicy,
|
|
8
|
+
RuntimeSignalError,
|
|
9
|
+
RuntimeSignalErrorCode,
|
|
10
|
+
} from './model';
|
|
1
11
|
export {
|
|
2
|
-
|
|
3
|
-
enforceRuntimeFallbackSignalAuthToken,
|
|
4
|
-
normalizeRequiredRuntimeFallbackSignalAuthConfig,
|
|
5
|
-
normalizeRuntimeFallbackSignalAuthConfig,
|
|
6
|
-
} from './auth';
|
|
7
|
-
export {
|
|
12
|
+
createRuntimeSignalError,
|
|
8
13
|
DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS,
|
|
9
14
|
DEFAULT_RUNTIME_FALLBACK_GATE_NAME,
|
|
10
15
|
DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES,
|
|
11
16
|
DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT,
|
|
12
17
|
DEFAULT_RUNTIME_STATUS_ENDPOINT,
|
|
13
|
-
|
|
14
|
-
export { persistRuntimeFallbackContractGate } from './contract-gate';
|
|
15
|
-
export { resolveRuntimeFallbackSignalEndpoint } from './endpoint';
|
|
16
|
-
export { createRuntimeSignalError } from './errors';
|
|
17
|
-
export {
|
|
18
|
+
getRuntimeSignalErrorStatusCode,
|
|
18
19
|
parseRuntimeFallbackSignalPayload,
|
|
19
20
|
parseRuntimeFallbackSignalPayloadFromRawBody,
|
|
20
|
-
} from './
|
|
21
|
-
export { createRuntimeFallbackSignalRuntimeState } from './state';
|
|
22
|
-
export { getRuntimeSignalErrorStatusCode } from './status';
|
|
21
|
+
} from './model';
|
|
23
22
|
export {
|
|
23
|
+
enforceRuntimeFallbackSignalAuth,
|
|
24
|
+
enforceRuntimeFallbackSignalAuthToken,
|
|
24
25
|
enforceRuntimeFallbackSignalTrustPolicy,
|
|
26
|
+
normalizeRequiredRuntimeFallbackSignalAuthConfig,
|
|
27
|
+
normalizeRuntimeFallbackSignalAuthConfig,
|
|
25
28
|
normalizeRuntimeFallbackTrustPolicy,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
RuntimeFallbackSignalTrustContext,
|
|
33
|
-
RuntimeFallbackSignalTrustPolicy,
|
|
34
|
-
RuntimeSignalError,
|
|
35
|
-
RuntimeSignalErrorCode,
|
|
36
|
-
} from './types';
|
|
29
|
+
resolveRuntimeFallbackSignalEndpoint,
|
|
30
|
+
} from './resolver';
|
|
31
|
+
export {
|
|
32
|
+
createRuntimeFallbackSignalRuntimeState,
|
|
33
|
+
persistRuntimeFallbackContractGate,
|
|
34
|
+
} from './store';
|