@bleedingdev/modern-js-plugin-bff-extensions 3.9.0-ultramodern.10 → 3.9.0-ultramodern.12
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 +7 -0
- package/dist/cjs/backend-federation/identity.js +23 -22
- package/dist/cjs/backend-federation-manifest/load.js +28 -5
- package/dist/cjs/backend-federation-manifest/validation.js +11 -7
- package/dist/cjs/cross-project-policy/node.js +8 -28
- package/dist/cjs/effect-adapter/cross-project-policy.js +2 -2
- package/dist/cjs/effect-adapter/entry.js +8 -44
- package/dist/cjs/effect-adapter/index.js +10 -2
- package/dist/cjs/effect-source-loader/built-entry.js +4 -5
- package/dist/cjs/effect-source-loader/loader.js +2 -1
- package/dist/cjs/effect-source-loader/operation-contracts.js +8 -31
- package/dist/cjs/effect-source-loader/paths.js +38 -10
- package/dist/esm/backend-federation/identity.mjs +18 -23
- package/dist/esm/backend-federation-manifest/load.mjs +28 -5
- package/dist/esm/backend-federation-manifest/validation.mjs +12 -8
- package/dist/esm/cross-project-policy/node.mjs +9 -19
- package/dist/esm/effect-adapter/cross-project-policy.mjs +2 -2
- package/dist/esm/effect-adapter/entry.mjs +9 -45
- package/dist/esm/effect-adapter/index.mjs +10 -2
- package/dist/esm/effect-source-loader/built-entry.mjs +5 -6
- package/dist/esm/effect-source-loader/loader.mjs +2 -1
- package/dist/esm/effect-source-loader/operation-contracts.mjs +10 -33
- package/dist/esm/effect-source-loader/paths.mjs +30 -11
- package/dist/esm-node/backend-federation/identity.mjs +18 -23
- package/dist/esm-node/backend-federation-manifest/load.mjs +28 -5
- package/dist/esm-node/backend-federation-manifest/validation.mjs +12 -8
- package/dist/esm-node/cross-project-policy/node.mjs +9 -19
- package/dist/esm-node/effect-adapter/cross-project-policy.mjs +2 -2
- package/dist/esm-node/effect-adapter/entry.mjs +9 -45
- package/dist/esm-node/effect-adapter/index.mjs +10 -2
- package/dist/esm-node/effect-source-loader/built-entry.mjs +5 -6
- package/dist/esm-node/effect-source-loader/loader.mjs +2 -1
- package/dist/esm-node/effect-source-loader/operation-contracts.mjs +10 -33
- package/dist/esm-node/effect-source-loader/paths.mjs +30 -11
- package/dist/types/backend-federation/identity.d.ts +3 -6
- package/dist/types/cross-project-policy/node.d.ts +2 -2
- package/dist/types/effect-adapter/cross-project-policy.d.ts +2 -1
- package/dist/types/effect-source-loader/paths.d.ts +20 -2
- package/package.json +10 -10
- package/src/backend-federation/identity.ts +39 -47
- package/src/backend-federation-manifest/load.ts +75 -27
- package/src/backend-federation-manifest/validation.ts +22 -29
- package/src/cross-project-policy/node.ts +7 -38
- package/src/effect-adapter/cross-project-policy.ts +7 -1
- package/src/effect-adapter/entry.ts +10 -88
- package/src/effect-adapter/index.ts +7 -1
- package/src/effect-source-loader/built-entry.ts +11 -9
- package/src/effect-source-loader/loader.ts +10 -5
- package/src/effect-source-loader/operation-contracts.ts +7 -41
- package/src/effect-source-loader/paths.ts +55 -21
|
@@ -5,6 +5,7 @@ import { backendFederationMetadata, manifestDeliveryUnit, stringValue, versionBo
|
|
|
5
5
|
import { loadBackendFederationManifest } from "./reference.mjs";
|
|
6
6
|
import { resolveBackendFederationRemoteFromManifest } from "./remote.mjs";
|
|
7
7
|
import { classifyLoadError, validateBackendFederationManifest, validateLoadedBackendFederationContract } from "./validation.mjs";
|
|
8
|
+
const DEFAULT_SHARED_MANIFEST_LOAD_TIMEOUT_MS = 10000;
|
|
8
9
|
function createManifestLoadScope(options) {
|
|
9
10
|
const controller = new AbortController();
|
|
10
11
|
const policyTimeouts = [
|
|
@@ -16,7 +17,8 @@ function createManifestLoadScope(options) {
|
|
|
16
17
|
...policyTimeouts
|
|
17
18
|
].filter((timeout)=>void 0 !== timeout);
|
|
18
19
|
for (const timeout of configuredTimeouts)if (!Number.isSafeInteger(timeout) || timeout < 0) throw new BackendFederationManifestAdapterError('manifest_invalid', '[BFF][Effect] Backend federation timeoutMs must be a non-negative safe integer.');
|
|
19
|
-
const
|
|
20
|
+
const positivePolicyTimeouts = policyTimeouts.filter((timeout)=>timeout > 0);
|
|
21
|
+
const timeoutMs = options.timeoutMs ?? (0 === policyTimeouts.length ? DEFAULT_SHARED_MANIFEST_LOAD_TIMEOUT_MS : positivePolicyTimeouts.length > 0 ? Math.min(...positivePolicyTimeouts) : 0);
|
|
20
22
|
const inputSignals = [
|
|
21
23
|
options.signal,
|
|
22
24
|
options.manifestPolicy?.signal,
|
|
@@ -70,6 +72,27 @@ function isCallerPinnedStaticRemote(options, remote) {
|
|
|
70
72
|
function throwIfManifestLoadAborted(signal) {
|
|
71
73
|
if (signal.aborted) throw new BackendFederationManifestAdapterError('remote_unavailable', '[BFF][Effect] Backend federation load was aborted before remote execution.', signal.reason);
|
|
72
74
|
}
|
|
75
|
+
function settleOnSharedAbort(promise, signal) {
|
|
76
|
+
if (signal.aborted) {
|
|
77
|
+
promise.catch(()=>{});
|
|
78
|
+
throwIfManifestLoadAborted(signal);
|
|
79
|
+
}
|
|
80
|
+
let onAbort;
|
|
81
|
+
const aborted = new Promise((_resolve, reject)=>{
|
|
82
|
+
onAbort = ()=>{
|
|
83
|
+
reject(new BackendFederationManifestAdapterError('remote_unavailable', '[BFF][Effect] Backend federation load was aborted before remote execution.', signal.reason));
|
|
84
|
+
};
|
|
85
|
+
signal.addEventListener('abort', onAbort, {
|
|
86
|
+
once: true
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
return Promise.race([
|
|
90
|
+
promise,
|
|
91
|
+
aborted
|
|
92
|
+
]).finally(()=>{
|
|
93
|
+
if (onAbort) signal.removeEventListener('abort', onAbort);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
73
96
|
async function loadBackendFederatedEffectApiFromManifest(options) {
|
|
74
97
|
let manifest;
|
|
75
98
|
let remote;
|
|
@@ -77,7 +100,7 @@ async function loadBackendFederatedEffectApiFromManifest(options) {
|
|
|
77
100
|
try {
|
|
78
101
|
scope = createManifestLoadScope(options);
|
|
79
102
|
throwIfManifestLoadAborted(scope.signal);
|
|
80
|
-
manifest = await loadBackendFederationManifest({
|
|
103
|
+
manifest = await settleOnSharedAbort(loadBackendFederationManifest({
|
|
81
104
|
...options,
|
|
82
105
|
manifestPolicy: {
|
|
83
106
|
...options.manifestPolicy,
|
|
@@ -86,7 +109,7 @@ async function loadBackendFederatedEffectApiFromManifest(options) {
|
|
|
86
109
|
},
|
|
87
110
|
signal: scope.signal,
|
|
88
111
|
timeoutMs: 0
|
|
89
|
-
});
|
|
112
|
+
}), scope.signal);
|
|
90
113
|
validateBackendFederationManifest(manifest, options.expected);
|
|
91
114
|
remote = resolveBackendFederationRemoteFromManifest(manifest, options.remote);
|
|
92
115
|
throwIfManifestLoadAborted(scope.signal);
|
|
@@ -100,7 +123,7 @@ async function loadBackendFederatedEffectApiFromManifest(options) {
|
|
|
100
123
|
const unitId = stringValue(deliveryUnit.boundary?.unitId) ?? stringValue(deliveryUnit.top?.unitId);
|
|
101
124
|
const buildMarker = stringValue(deliveryUnit.boundary?.buildMarker);
|
|
102
125
|
if (!unitId || !buildMarker) throw new BackendFederationManifestAdapterError('manifest_invalid', 'Backend federation manifest requires delivery-unit identity.');
|
|
103
|
-
const loaded = await loadBackendFederatedEffectApi({
|
|
126
|
+
const loaded = await settleOnSharedAbort(loadBackendFederatedEffectApi({
|
|
104
127
|
hostName: options.hostName,
|
|
105
128
|
remote,
|
|
106
129
|
...options.plugins ? {
|
|
@@ -120,7 +143,7 @@ async function loadBackendFederatedEffectApiFromManifest(options) {
|
|
|
120
143
|
}
|
|
121
144
|
}).catch((error)=>{
|
|
122
145
|
throw new BackendFederationManifestAdapterError(scope?.timedOut() === true ? 'timeout' : classifyLoadError(error), `[BFF][Effect] Backend federation remote ${remote?.name ?? 'unknown'} could not load ${remote?.expose ?? BACKEND_FEDERATION_EFFECT_EXPOSE}.`, error);
|
|
123
|
-
});
|
|
146
|
+
}), scope.signal);
|
|
124
147
|
validateLoadedBackendFederationContract(loaded, manifest, remote);
|
|
125
148
|
return loaded;
|
|
126
149
|
} catch (error) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { formatBackendFederationValidationErrors, validateBackendFederationManifest } from "@modern-js/backend-federation-contracts";
|
|
2
2
|
import { BACKEND_FEDERATION_CONTRACT_VERSION, BACKEND_FEDERATION_NODE_ADAPTER_VERSION } from "../backend-federation/index.mjs";
|
|
3
|
+
import { backendFederationCompatibility, formatBackendFederationIdentityIssues, validateBackendFederationCompatibility } from "../backend-federation/identity.mjs";
|
|
3
4
|
import { BackendFederationManifestAdapterError, assertConsistentValue, assertManifestAdapter, assertVersionValue } from "./errors.mjs";
|
|
4
|
-
import { backendFederationMetadata, manifestDeliveryUnit,
|
|
5
|
+
import { backendFederationMetadata, manifestDeliveryUnit, stringValue, versionBoundaryMetadata } from "./metadata.mjs";
|
|
5
6
|
function resolveExpectedBuildMarker(expected) {
|
|
6
7
|
if (void 0 !== expected.buildVersion && void 0 !== expected.buildMarker && expected.buildVersion !== expected.buildMarker) throw new BackendFederationManifestAdapterError('version_mismatch', `[BFF][Effect] Backend federation expected buildVersion/buildMarker mismatch: buildVersion ${expected.buildVersion}, buildMarker ${expected.buildMarker}.`, void 0, {
|
|
7
8
|
label: 'expected.buildVersion/buildMarker',
|
|
@@ -42,19 +43,22 @@ function validateLoadedBackendFederationContract(loaded, manifest, remote) {
|
|
|
42
43
|
const loadedContract = loaded.backendFederationContract;
|
|
43
44
|
const backendFederation = backendFederationMetadata(manifest);
|
|
44
45
|
const boundary = versionBoundaryMetadata(manifest);
|
|
45
|
-
const compatibility =
|
|
46
|
+
const compatibility = backendFederationCompatibility(loaded);
|
|
46
47
|
assertManifestAdapter(compatibility, 'version_mismatch', `[BFF][Effect] Backend federation expose ${remote.name}/${remote.expose?.replace(/^\.\//u, '')} must declare compatibility metadata.`);
|
|
47
48
|
assertVersionValue(stringValue(loadedContract?.role), 'microvertical-server', 'expose role');
|
|
48
49
|
assertVersionValue(stringValue(loadedContract?.name), remote.name, 'expose name');
|
|
49
|
-
assertVersionValue(stringValue(compatibility.contractVersion), stringValue(backendFederation?.contractVersion), 'expose contractVersion');
|
|
50
|
-
assertVersionValue(stringValue(compatibility.nodeAdapterVersion), stringValue(backendFederation?.nodeAdapterVersion), 'expose nodeAdapterVersion');
|
|
51
|
-
assertVersionValue(stringValue(compatibility.packageName), stringValue(boundary?.packageName), 'expose packageName');
|
|
52
|
-
assertVersionValue(stringValue(compatibility.build), stringValue(boundary?.buildVersion), 'expose buildVersion');
|
|
53
50
|
const deliveryUnit = manifestDeliveryUnit(backendFederation, boundary);
|
|
54
51
|
const manifestUnitId = stringValue(deliveryUnit.boundary?.unitId) ?? stringValue(deliveryUnit.top?.unitId);
|
|
55
52
|
const manifestBuildMarker = stringValue(deliveryUnit.boundary?.buildMarker);
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
const issues = validateBackendFederationCompatibility(compatibility, {
|
|
54
|
+
contractVersion: stringValue(backendFederation?.contractVersion),
|
|
55
|
+
nodeAdapterVersion: stringValue(backendFederation?.nodeAdapterVersion),
|
|
56
|
+
packageName: stringValue(boundary?.packageName),
|
|
57
|
+
unitId: manifestUnitId,
|
|
58
|
+
build: manifestBuildMarker ?? stringValue(boundary?.buildVersion)
|
|
59
|
+
});
|
|
60
|
+
assertVersionValue(stringValue(compatibility.build), stringValue(boundary?.buildVersion), 'expose buildVersion');
|
|
61
|
+
assertManifestAdapter(0 === issues.length, 'version_mismatch', `[BFF][Effect] ${formatBackendFederationIdentityIssues(issues)}.`);
|
|
58
62
|
}
|
|
59
63
|
function classifyLoadError(error) {
|
|
60
64
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -1,29 +1,19 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import node_path from "node:path";
|
|
3
1
|
import "@modern-js/server-runtime-extensions/server-config";
|
|
4
|
-
import {
|
|
5
|
-
const
|
|
6
|
-
if (!startDir) return;
|
|
7
|
-
let current = node_path.resolve(startDir);
|
|
8
|
-
for(let depth = 0; depth < 10; depth += 1){
|
|
9
|
-
try {
|
|
10
|
-
const packageJson = JSON.parse(readFileSync(node_path.join(current, 'package.json'), 'utf8'));
|
|
11
|
-
if ('string' == typeof packageJson.version) return packageJson.version;
|
|
12
|
-
} catch {}
|
|
13
|
-
const parent = node_path.dirname(current);
|
|
14
|
-
if (parent === current) break;
|
|
15
|
-
current = parent;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
const resolveAdapterCrossProjectPolicy = (api, handlers)=>{
|
|
2
|
+
import { resolveCrossProjectPolicy, resolveOperationProducer } from "@modern-js/server-runtime-extensions/bff-policy/node";
|
|
3
|
+
const resolveAdapterCrossProjectPolicy = (api, handlers, producer)=>{
|
|
19
4
|
const bff = api.getServerConfig()?.bff;
|
|
20
5
|
const { apiDirectory, appDirectory } = api.getServerContext();
|
|
21
6
|
return resolveCrossProjectPolicy({
|
|
22
7
|
crossProjectPolicy: bff?.crossProjectPolicy,
|
|
23
8
|
handlers,
|
|
24
|
-
requestId: bff?.requestId,
|
|
25
9
|
isCrossProjectServer: bff?.isCrossProjectServer,
|
|
26
|
-
|
|
10
|
+
...producer ?? resolveOperationProducer({
|
|
11
|
+
directories: [
|
|
12
|
+
apiDirectory,
|
|
13
|
+
appDirectory
|
|
14
|
+
],
|
|
15
|
+
requestId: bff?.requestId || 'default'
|
|
16
|
+
})
|
|
27
17
|
});
|
|
28
18
|
};
|
|
29
19
|
export { resolveAdapterCrossProjectPolicy };
|
|
@@ -2,7 +2,7 @@ import { collectEffectEndpoints, extractHttpApiFromModule, toOperationContractSo
|
|
|
2
2
|
import { logger } from "@modern-js/utils";
|
|
3
3
|
import { HttpApi } from "effect/unstable/httpapi";
|
|
4
4
|
import { resolveAdapterCrossProjectPolicy } from "../cross-project-policy/index.mjs";
|
|
5
|
-
function resolveEffectAdapterCrossProjectPolicy(api, prefix, mod) {
|
|
5
|
+
function resolveEffectAdapterCrossProjectPolicy(api, prefix, mod, producer) {
|
|
6
6
|
const contractSourcesPromise = null === mod ? Promise.resolve([]) : Promise.resolve().then(()=>extractHttpApiFromModule(mod, HttpApi.isHttpApi)).then((effectApi)=>{
|
|
7
7
|
if (null === effectApi) return [];
|
|
8
8
|
const reflect = (apiValue, handlers)=>{
|
|
@@ -18,7 +18,7 @@ function resolveEffectAdapterCrossProjectPolicy(api, prefix, mod) {
|
|
|
18
18
|
return [];
|
|
19
19
|
});
|
|
20
20
|
return contractSourcesPromise.then((contractSources)=>{
|
|
21
|
-
const policy = resolveAdapterCrossProjectPolicy(api, contractSources);
|
|
21
|
+
const policy = resolveAdapterCrossProjectPolicy(api, contractSources, producer);
|
|
22
22
|
if (policy?.enabled === true && 0 === contractSources.length) logger.warn('[BFF][Effect] Cross-project policy enabled but no HttpApi endpoints could be reflected; requests fail operation-contract matching unless allowUnknownOperations is enabled.');
|
|
23
23
|
return policy;
|
|
24
24
|
});
|
|
@@ -1,51 +1,15 @@
|
|
|
1
1
|
import node_path from "node:path";
|
|
2
2
|
import "@modern-js/server-runtime-extensions/server-config";
|
|
3
|
-
import { API_DIR,
|
|
4
|
-
|
|
5
|
-
'.js',
|
|
6
|
-
'.jsx',
|
|
7
|
-
'.ts',
|
|
8
|
-
'.tsx',
|
|
9
|
-
'.mjs',
|
|
10
|
-
'.mts',
|
|
11
|
-
'.cjs',
|
|
12
|
-
'.cts'
|
|
13
|
-
];
|
|
14
|
-
function resolveJsOrTsEntry(entryWithoutOrWithExt) {
|
|
15
|
-
const extension = node_path.extname(entryWithoutOrWithExt);
|
|
16
|
-
if (JS_OR_TS_EXTS.includes(extension)) return fs.existsSync(entryWithoutOrWithExt) ? entryWithoutOrWithExt : void 0;
|
|
17
|
-
return findExists(JS_OR_TS_EXTS.map((ext)=>`${entryWithoutOrWithExt}${ext}`)) || void 0;
|
|
18
|
-
}
|
|
19
|
-
function builtEntryPath(entryPath) {
|
|
20
|
-
return entryPath.replace(/\.(?:[cm]?ts|tsx|jsx)$/u, '.js');
|
|
21
|
-
}
|
|
22
|
-
function relativeAppPath(appDirectory, entryPath) {
|
|
23
|
-
const relativePath = node_path.relative(appDirectory, entryPath);
|
|
24
|
-
return '..' === relativePath || relativePath.startsWith(`..${node_path.sep}`) ? void 0 : relativePath;
|
|
25
|
-
}
|
|
26
|
-
function isDependencyPath(relativePath) {
|
|
27
|
-
return relativePath?.split(/[\\/]/u).includes('node_modules') ?? false;
|
|
28
|
-
}
|
|
3
|
+
import { API_DIR, isProd } from "@modern-js/utils";
|
|
4
|
+
import { resolveEffectEntry } from "../effect-source-loader/paths.mjs";
|
|
29
5
|
function resolveEffectAdapterEntryFile(api) {
|
|
30
6
|
const { appDirectory, apiDirectory, distDirectory } = api.getServerContext();
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (void 0 === relativeEntry || isDependencyPath(relativeEntry)) return resolveJsOrTsEntry(sourceEntry);
|
|
39
|
-
return relativeEntry ? resolveJsOrTsEntry(builtEntryPath(node_path.resolve(productionRoot, relativeEntry))) : void 0;
|
|
40
|
-
}
|
|
41
|
-
return resolveJsOrTsEntry(sourceEntry);
|
|
42
|
-
}
|
|
43
|
-
const resolvedApiDirectory = node_path.resolve(appRoot, apiDirectory || API_DIR);
|
|
44
|
-
const productionApiDirectory = productionRoot ? void 0 !== relativeAppPath(productionRoot, resolvedApiDirectory) ? resolvedApiDirectory : (()=>{
|
|
45
|
-
const relativeApiDirectory = relativeAppPath(appRoot, resolvedApiDirectory);
|
|
46
|
-
if (isDependencyPath(relativeApiDirectory)) return resolvedApiDirectory;
|
|
47
|
-
return relativeApiDirectory ? node_path.resolve(productionRoot, relativeApiDirectory) : void 0;
|
|
48
|
-
})() : resolvedApiDirectory;
|
|
49
|
-
return productionApiDirectory ? resolveJsOrTsEntry(node_path.resolve(productionApiDirectory, 'index')) : void 0;
|
|
7
|
+
const appDir = node_path.resolve(appDirectory || process.cwd());
|
|
8
|
+
return resolveEffectEntry({
|
|
9
|
+
appDir,
|
|
10
|
+
apiDir: node_path.resolve(appDir, apiDirectory || API_DIR),
|
|
11
|
+
effectEntry: api.getServerConfig()?.bff?.effect?.entry,
|
|
12
|
+
distDir: isProd() && distDirectory ? node_path.resolve(distDirectory) : void 0
|
|
13
|
+
}).path;
|
|
50
14
|
}
|
|
51
15
|
export { resolveEffectAdapterEntryFile };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import node_path from "node:path";
|
|
2
2
|
import "@modern-js/server-runtime-extensions/server-config";
|
|
3
3
|
import { dispatchEffectBffRequest, resolveEffectBffModuleHandler, useEffectContext } from "@modern-js/bff-effect/effect";
|
|
4
|
+
import { resolveOperationProducer } from "@modern-js/server-runtime-extensions/bff-policy/node";
|
|
4
5
|
import { createDisposableServerRuntimeHandle, registerServerRuntimeDisposer } from "@modern-js/server-runtime-extensions/runtime-lifecycle";
|
|
5
6
|
import { fs, isProd, logger } from "@modern-js/utils";
|
|
6
7
|
import { checkCrossProjectPolicyForRequest } from "../cross-project-policy/evaluation.mjs";
|
|
@@ -20,9 +21,9 @@ class EffectAdapter {
|
|
|
20
21
|
this.handler = null;
|
|
21
22
|
return;
|
|
22
23
|
}
|
|
24
|
+
const { appDirectory } = this.api.getServerContext();
|
|
23
25
|
let mod;
|
|
24
26
|
try {
|
|
25
|
-
const { appDirectory } = this.api.getServerContext();
|
|
26
27
|
mod = await (isProd() ? loadEffectBuiltModule(entryFile) : loadEffectSourceModule({
|
|
27
28
|
resourcePath: entryFile,
|
|
28
29
|
appDir: appDirectory || node_path.dirname(entryFile)
|
|
@@ -31,9 +32,16 @@ class EffectAdapter {
|
|
|
31
32
|
logger.error(`[BFF][Effect] Failed to load Effect entry: ${entryFile}\n${String(error)}`);
|
|
32
33
|
throw error;
|
|
33
34
|
}
|
|
35
|
+
const producer = resolveOperationProducer({
|
|
36
|
+
directories: [
|
|
37
|
+
node_path.dirname(entryFile),
|
|
38
|
+
appDirectory
|
|
39
|
+
],
|
|
40
|
+
requestId: this.api.getServerConfig()?.bff?.requestId
|
|
41
|
+
});
|
|
34
42
|
const crossProjectPolicies = new Map(await Promise.all(this.prefixes.map(async (prefix)=>[
|
|
35
43
|
prefix,
|
|
36
|
-
await resolveEffectAdapterCrossProjectPolicy(this.api, prefix, mod)
|
|
44
|
+
await resolveEffectAdapterCrossProjectPolicy(this.api, prefix, mod, producer)
|
|
37
45
|
])));
|
|
38
46
|
const effectConfig = this.api.getServerConfig()?.bff?.effect;
|
|
39
47
|
const loaded = await resolveEffectBffModuleHandler(mod, {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { fs, upath } from "@modern-js/utils";
|
|
2
|
-
import { resolveEffectEntryFile } from "./paths.mjs";
|
|
3
|
-
const BUILT_ENTRY_EXT = /\.(?:[cm]?ts|tsx|jsx)$/u;
|
|
2
|
+
import { emittedEffectEntry, relativeEffectAppPath, resolveEffectEntryFile } from "./paths.mjs";
|
|
4
3
|
function resolveBuiltEffectEntry(appDirectory, distDirectory, sourceEntry) {
|
|
5
4
|
if (void 0 === sourceEntry || 0 === sourceEntry.length) return;
|
|
6
|
-
const relativeEntry =
|
|
7
|
-
if (
|
|
8
|
-
const builtEntry = upath.resolve(distDirectory, relativeEntry)
|
|
5
|
+
const relativeEntry = relativeEffectAppPath(appDirectory, sourceEntry);
|
|
6
|
+
if (void 0 === relativeEntry) throw new Error(`Effect BFF entry must be inside the application directory: ${sourceEntry}`);
|
|
7
|
+
const builtEntry = emittedEffectEntry(upath.resolve(distDirectory, relativeEntry));
|
|
9
8
|
return fs.existsSync(builtEntry) ? builtEntry : void 0;
|
|
10
9
|
}
|
|
11
10
|
async function bundleBuiltEffectEntryForNode(options) {
|
|
@@ -31,7 +30,7 @@ function resolveEffectEntryPaths(options) {
|
|
|
31
30
|
apiDir,
|
|
32
31
|
effectEntry
|
|
33
32
|
});
|
|
34
|
-
const relativeEffectEntry = void 0 !== sourceEffectEntry && sourceEffectEntry.length > 0 ? upath.relative(appDir, sourceEffectEntry)
|
|
33
|
+
const relativeEffectEntry = void 0 !== sourceEffectEntry && sourceEffectEntry.length > 0 ? emittedEffectEntry(upath.relative(appDir, sourceEffectEntry)) : '';
|
|
35
34
|
return {
|
|
36
35
|
sourceEffectEntry,
|
|
37
36
|
relativeEffectEntry
|
|
@@ -130,7 +130,8 @@ function externalizeInstalledDependencies(options) {
|
|
|
130
130
|
path: args.path
|
|
131
131
|
};
|
|
132
132
|
const realPath = await node_fs.promises.realpath(resolution.path).catch(()=>resolution.path);
|
|
133
|
-
|
|
133
|
+
const loader = SOURCE_LOADERS.get(node_path.extname(realPath).toLowerCase());
|
|
134
|
+
if (realPath.includes(`${node_path.sep}node_modules${node_path.sep}`) && 'ts' !== loader && 'tsx' !== loader && 'jsx' !== loader) {
|
|
134
135
|
const runtimeResolution = await buildApi.resolve(args.path, {
|
|
135
136
|
importer: '',
|
|
136
137
|
kind: args.kind,
|
|
@@ -1,45 +1,22 @@
|
|
|
1
1
|
import { collectEffectEndpoints, toOperationContractSources } from "@modern-js/bff-effect/effect";
|
|
2
|
-
import { buildOperationContractMap,
|
|
3
|
-
import {
|
|
2
|
+
import { buildOperationContractMap, resolveOperationProducer } from "@modern-js/server-runtime-extensions/bff-policy/node";
|
|
3
|
+
import { upath } from "@modern-js/utils";
|
|
4
4
|
import { getHttpApiRuntime, loadEffectApi } from "./http-api-runtime.mjs";
|
|
5
|
-
function getPackageInfo(resourcePath, appDir, onDependency) {
|
|
6
|
-
for (const startDir of [
|
|
7
|
-
upath.dirname(resourcePath),
|
|
8
|
-
appDir
|
|
9
|
-
]){
|
|
10
|
-
let current = upath.resolve(startDir);
|
|
11
|
-
for(let depth = 0; depth < 32; depth += 1){
|
|
12
|
-
const packageJsonPath = upath.join(current, 'package.json');
|
|
13
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
14
|
-
onDependency?.(packageJsonPath);
|
|
15
|
-
try {
|
|
16
|
-
const packageJson = fs.readJSONSync(packageJsonPath);
|
|
17
|
-
return {
|
|
18
|
-
name: packageJson.name,
|
|
19
|
-
version: packageJson.version
|
|
20
|
-
};
|
|
21
|
-
} catch {
|
|
22
|
-
return {};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
const parent = upath.dirname(current);
|
|
26
|
-
if (parent === current) break;
|
|
27
|
-
current = parent;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return {};
|
|
31
|
-
}
|
|
32
5
|
async function resolveEffectOperationContracts(options) {
|
|
33
6
|
const api = await loadEffectApi(options);
|
|
34
7
|
if (null === api) return null;
|
|
35
8
|
const runtime = await getHttpApiRuntime();
|
|
36
9
|
const endpoints = collectEffectEndpoints(runtime.reflect, api, options.prefix);
|
|
37
|
-
const packageInfo = getPackageInfo(options.resourcePath, options.appDir, options.onDependency);
|
|
38
|
-
const requestId = options.requestId?.trim() || packageInfo.name || 'default';
|
|
39
10
|
return buildOperationContractMap({
|
|
40
11
|
handlers: toOperationContractSources(endpoints),
|
|
41
|
-
|
|
42
|
-
|
|
12
|
+
...resolveOperationProducer({
|
|
13
|
+
directories: [
|
|
14
|
+
upath.dirname(options.resourcePath),
|
|
15
|
+
options.appDir
|
|
16
|
+
],
|
|
17
|
+
requestId: options.requestId,
|
|
18
|
+
onDependency: options.onDependency
|
|
19
|
+
})
|
|
43
20
|
});
|
|
44
21
|
}
|
|
45
22
|
export { resolveEffectOperationContracts };
|
|
@@ -9,16 +9,35 @@ const JS_OR_TS_EXTS = [
|
|
|
9
9
|
'.cjs',
|
|
10
10
|
'.cts'
|
|
11
11
|
];
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
const emittedEffectEntry = (entry)=>entry.replace(/\.(?:[cm]?ts|tsx|jsx)$/u, '.js');
|
|
13
|
+
function relativeEffectAppPath(appDir, entry) {
|
|
14
|
+
const relative = upath.relative(appDir, entry);
|
|
15
|
+
return '..' === relative || relative.startsWith('../') || relative.split('/').includes('node_modules') ? void 0 : relative;
|
|
16
|
+
}
|
|
17
|
+
function existingEntry(entry) {
|
|
18
|
+
return upath.extname(entry) ? fs.existsSync(entry) ? entry : void 0 : findExists(JS_OR_TS_EXTS.map((ext)=>`${entry}${ext}`)) || void 0;
|
|
19
|
+
}
|
|
20
|
+
function resolveEffectEntry(options) {
|
|
21
|
+
const { appDir, apiDir, effectEntry, distDir } = options;
|
|
22
|
+
const entry = upath.resolve(appDir, effectEntry || upath.join(apiDir, 'index'));
|
|
23
|
+
if (distDir && void 0 !== relativeEffectAppPath(distDir, entry)) return {
|
|
24
|
+
kind: 'built-output',
|
|
25
|
+
path: existingEntry(emittedEffectEntry(entry))
|
|
26
|
+
};
|
|
27
|
+
const relative = relativeEffectAppPath(appDir, entry);
|
|
28
|
+
if (void 0 === relative) return {
|
|
29
|
+
kind: 'external-sdk',
|
|
30
|
+
path: existingEntry(entry)
|
|
17
31
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
32
|
+
return distDir ? {
|
|
33
|
+
kind: 'built-output',
|
|
34
|
+
path: existingEntry(emittedEffectEntry(upath.resolve(distDir, relative)))
|
|
35
|
+
} : {
|
|
36
|
+
kind: 'app-source',
|
|
37
|
+
path: existingEntry(entry)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function resolveEffectEntryFile(options) {
|
|
41
|
+
return resolveEffectEntry(options).path;
|
|
23
42
|
}
|
|
24
|
-
export { resolveEffectEntryFile };
|
|
43
|
+
export { emittedEffectEntry, relativeEffectAppPath, resolveEffectEntry, resolveEffectEntryFile };
|
|
@@ -1,36 +1,31 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { isRecord } from "./utils.mjs";
|
|
3
|
-
function
|
|
4
|
-
const issues = [];
|
|
3
|
+
function backendFederationCompatibility(loaded) {
|
|
5
4
|
const contract = isRecord(loaded) ? loaded.backendFederationContract : void 0;
|
|
6
5
|
const compatibility = isRecord(contract) ? contract.compatibility : void 0;
|
|
7
|
-
|
|
6
|
+
return isRecord(compatibility) ? compatibility : void 0;
|
|
7
|
+
}
|
|
8
|
+
function validateBackendFederationCompatibility(compatibility, expected) {
|
|
9
|
+
return Object.entries(expected).flatMap(([field, value])=>void 0 === value || 'string' == typeof compatibility[field] && compatibility[field].length > 0 && compatibility[field] === value ? [] : [
|
|
10
|
+
{
|
|
11
|
+
path: `backendFederationContract.compatibility.${field}`,
|
|
12
|
+
message: `expected ${value}, received ${'string' == typeof compatibility[field] ? compatibility[field] : typeof compatibility[field]}`
|
|
13
|
+
}
|
|
14
|
+
]);
|
|
15
|
+
}
|
|
16
|
+
function validateExpectedBackendFederationIdentity(loaded, expected) {
|
|
17
|
+
const compatibility = backendFederationCompatibility(loaded);
|
|
18
|
+
return compatibility ? validateBackendFederationCompatibility(compatibility, {
|
|
19
|
+
unitId: expected.unitId,
|
|
20
|
+
build: expected.buildMarker
|
|
21
|
+
}) : [
|
|
8
22
|
{
|
|
9
23
|
path: 'backendFederationContract.compatibility',
|
|
10
24
|
message: 'loaded module declares no compatibility metadata; delivery-unit identity cannot be validated'
|
|
11
25
|
}
|
|
12
26
|
];
|
|
13
|
-
const unitId = compatibility.unitId;
|
|
14
|
-
if ('string' != typeof unitId || 0 === unitId.length) issues.push({
|
|
15
|
-
path: 'backendFederationContract.compatibility.unitId',
|
|
16
|
-
message: `missing delivery-unit id; expected ${expected.unitId}`
|
|
17
|
-
});
|
|
18
|
-
else if (unitId !== expected.unitId) issues.push({
|
|
19
|
-
path: 'backendFederationContract.compatibility.unitId',
|
|
20
|
-
message: `expected ${expected.unitId}, received ${unitId}`
|
|
21
|
-
});
|
|
22
|
-
const build = compatibility.build;
|
|
23
|
-
if ('string' != typeof build || 0 === build.length) issues.push({
|
|
24
|
-
path: 'backendFederationContract.compatibility.build',
|
|
25
|
-
message: `missing build marker; expected ${expected.buildMarker}`
|
|
26
|
-
});
|
|
27
|
-
else if (build !== expected.buildMarker) issues.push({
|
|
28
|
-
path: 'backendFederationContract.compatibility.build',
|
|
29
|
-
message: `expected ${expected.buildMarker}, received ${build}`
|
|
30
|
-
});
|
|
31
|
-
return issues;
|
|
32
27
|
}
|
|
33
28
|
function formatBackendFederationIdentityIssues(issues) {
|
|
34
29
|
return issues.map((issue)=>`${issue.path}: ${issue.message}`).join('; ');
|
|
35
30
|
}
|
|
36
|
-
export { formatBackendFederationIdentityIssues, validateExpectedBackendFederationIdentity };
|
|
31
|
+
export { backendFederationCompatibility, formatBackendFederationIdentityIssues, validateBackendFederationCompatibility, validateExpectedBackendFederationIdentity };
|
|
@@ -6,6 +6,7 @@ import { backendFederationMetadata, manifestDeliveryUnit, stringValue, versionBo
|
|
|
6
6
|
import { loadBackendFederationManifest } from "./reference.mjs";
|
|
7
7
|
import { resolveBackendFederationRemoteFromManifest } from "./remote.mjs";
|
|
8
8
|
import { classifyLoadError, validateBackendFederationManifest, validateLoadedBackendFederationContract } from "./validation.mjs";
|
|
9
|
+
const DEFAULT_SHARED_MANIFEST_LOAD_TIMEOUT_MS = 10000;
|
|
9
10
|
function createManifestLoadScope(options) {
|
|
10
11
|
const controller = new AbortController();
|
|
11
12
|
const policyTimeouts = [
|
|
@@ -17,7 +18,8 @@ function createManifestLoadScope(options) {
|
|
|
17
18
|
...policyTimeouts
|
|
18
19
|
].filter((timeout)=>void 0 !== timeout);
|
|
19
20
|
for (const timeout of configuredTimeouts)if (!Number.isSafeInteger(timeout) || timeout < 0) throw new BackendFederationManifestAdapterError('manifest_invalid', '[BFF][Effect] Backend federation timeoutMs must be a non-negative safe integer.');
|
|
20
|
-
const
|
|
21
|
+
const positivePolicyTimeouts = policyTimeouts.filter((timeout)=>timeout > 0);
|
|
22
|
+
const timeoutMs = options.timeoutMs ?? (0 === policyTimeouts.length ? DEFAULT_SHARED_MANIFEST_LOAD_TIMEOUT_MS : positivePolicyTimeouts.length > 0 ? Math.min(...positivePolicyTimeouts) : 0);
|
|
21
23
|
const inputSignals = [
|
|
22
24
|
options.signal,
|
|
23
25
|
options.manifestPolicy?.signal,
|
|
@@ -71,6 +73,27 @@ function isCallerPinnedStaticRemote(options, remote) {
|
|
|
71
73
|
function throwIfManifestLoadAborted(signal) {
|
|
72
74
|
if (signal.aborted) throw new BackendFederationManifestAdapterError('remote_unavailable', '[BFF][Effect] Backend federation load was aborted before remote execution.', signal.reason);
|
|
73
75
|
}
|
|
76
|
+
function settleOnSharedAbort(promise, signal) {
|
|
77
|
+
if (signal.aborted) {
|
|
78
|
+
promise.catch(()=>{});
|
|
79
|
+
throwIfManifestLoadAborted(signal);
|
|
80
|
+
}
|
|
81
|
+
let onAbort;
|
|
82
|
+
const aborted = new Promise((_resolve, reject)=>{
|
|
83
|
+
onAbort = ()=>{
|
|
84
|
+
reject(new BackendFederationManifestAdapterError('remote_unavailable', '[BFF][Effect] Backend federation load was aborted before remote execution.', signal.reason));
|
|
85
|
+
};
|
|
86
|
+
signal.addEventListener('abort', onAbort, {
|
|
87
|
+
once: true
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
return Promise.race([
|
|
91
|
+
promise,
|
|
92
|
+
aborted
|
|
93
|
+
]).finally(()=>{
|
|
94
|
+
if (onAbort) signal.removeEventListener('abort', onAbort);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
74
97
|
async function loadBackendFederatedEffectApiFromManifest(options) {
|
|
75
98
|
let manifest;
|
|
76
99
|
let remote;
|
|
@@ -78,7 +101,7 @@ async function loadBackendFederatedEffectApiFromManifest(options) {
|
|
|
78
101
|
try {
|
|
79
102
|
scope = createManifestLoadScope(options);
|
|
80
103
|
throwIfManifestLoadAborted(scope.signal);
|
|
81
|
-
manifest = await loadBackendFederationManifest({
|
|
104
|
+
manifest = await settleOnSharedAbort(loadBackendFederationManifest({
|
|
82
105
|
...options,
|
|
83
106
|
manifestPolicy: {
|
|
84
107
|
...options.manifestPolicy,
|
|
@@ -87,7 +110,7 @@ async function loadBackendFederatedEffectApiFromManifest(options) {
|
|
|
87
110
|
},
|
|
88
111
|
signal: scope.signal,
|
|
89
112
|
timeoutMs: 0
|
|
90
|
-
});
|
|
113
|
+
}), scope.signal);
|
|
91
114
|
validateBackendFederationManifest(manifest, options.expected);
|
|
92
115
|
remote = resolveBackendFederationRemoteFromManifest(manifest, options.remote);
|
|
93
116
|
throwIfManifestLoadAborted(scope.signal);
|
|
@@ -101,7 +124,7 @@ async function loadBackendFederatedEffectApiFromManifest(options) {
|
|
|
101
124
|
const unitId = stringValue(deliveryUnit.boundary?.unitId) ?? stringValue(deliveryUnit.top?.unitId);
|
|
102
125
|
const buildMarker = stringValue(deliveryUnit.boundary?.buildMarker);
|
|
103
126
|
if (!unitId || !buildMarker) throw new BackendFederationManifestAdapterError('manifest_invalid', 'Backend federation manifest requires delivery-unit identity.');
|
|
104
|
-
const loaded = await loadBackendFederatedEffectApi({
|
|
127
|
+
const loaded = await settleOnSharedAbort(loadBackendFederatedEffectApi({
|
|
105
128
|
hostName: options.hostName,
|
|
106
129
|
remote,
|
|
107
130
|
...options.plugins ? {
|
|
@@ -121,7 +144,7 @@ async function loadBackendFederatedEffectApiFromManifest(options) {
|
|
|
121
144
|
}
|
|
122
145
|
}).catch((error)=>{
|
|
123
146
|
throw new BackendFederationManifestAdapterError(scope?.timedOut() === true ? 'timeout' : classifyLoadError(error), `[BFF][Effect] Backend federation remote ${remote?.name ?? 'unknown'} could not load ${remote?.expose ?? BACKEND_FEDERATION_EFFECT_EXPOSE}.`, error);
|
|
124
|
-
});
|
|
147
|
+
}), scope.signal);
|
|
125
148
|
validateLoadedBackendFederationContract(loaded, manifest, remote);
|
|
126
149
|
return loaded;
|
|
127
150
|
} catch (error) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { formatBackendFederationValidationErrors, validateBackendFederationManifest } from "@modern-js/backend-federation-contracts";
|
|
3
3
|
import { BACKEND_FEDERATION_CONTRACT_VERSION, BACKEND_FEDERATION_NODE_ADAPTER_VERSION } from "../backend-federation/index.mjs";
|
|
4
|
+
import { backendFederationCompatibility, formatBackendFederationIdentityIssues, validateBackendFederationCompatibility } from "../backend-federation/identity.mjs";
|
|
4
5
|
import { BackendFederationManifestAdapterError, assertConsistentValue, assertManifestAdapter, assertVersionValue } from "./errors.mjs";
|
|
5
|
-
import { backendFederationMetadata, manifestDeliveryUnit,
|
|
6
|
+
import { backendFederationMetadata, manifestDeliveryUnit, stringValue, versionBoundaryMetadata } from "./metadata.mjs";
|
|
6
7
|
function resolveExpectedBuildMarker(expected) {
|
|
7
8
|
if (void 0 !== expected.buildVersion && void 0 !== expected.buildMarker && expected.buildVersion !== expected.buildMarker) throw new BackendFederationManifestAdapterError('version_mismatch', `[BFF][Effect] Backend federation expected buildVersion/buildMarker mismatch: buildVersion ${expected.buildVersion}, buildMarker ${expected.buildMarker}.`, void 0, {
|
|
8
9
|
label: 'expected.buildVersion/buildMarker',
|
|
@@ -43,19 +44,22 @@ function validateLoadedBackendFederationContract(loaded, manifest, remote) {
|
|
|
43
44
|
const loadedContract = loaded.backendFederationContract;
|
|
44
45
|
const backendFederation = backendFederationMetadata(manifest);
|
|
45
46
|
const boundary = versionBoundaryMetadata(manifest);
|
|
46
|
-
const compatibility =
|
|
47
|
+
const compatibility = backendFederationCompatibility(loaded);
|
|
47
48
|
assertManifestAdapter(compatibility, 'version_mismatch', `[BFF][Effect] Backend federation expose ${remote.name}/${remote.expose?.replace(/^\.\//u, '')} must declare compatibility metadata.`);
|
|
48
49
|
assertVersionValue(stringValue(loadedContract?.role), 'microvertical-server', 'expose role');
|
|
49
50
|
assertVersionValue(stringValue(loadedContract?.name), remote.name, 'expose name');
|
|
50
|
-
assertVersionValue(stringValue(compatibility.contractVersion), stringValue(backendFederation?.contractVersion), 'expose contractVersion');
|
|
51
|
-
assertVersionValue(stringValue(compatibility.nodeAdapterVersion), stringValue(backendFederation?.nodeAdapterVersion), 'expose nodeAdapterVersion');
|
|
52
|
-
assertVersionValue(stringValue(compatibility.packageName), stringValue(boundary?.packageName), 'expose packageName');
|
|
53
|
-
assertVersionValue(stringValue(compatibility.build), stringValue(boundary?.buildVersion), 'expose buildVersion');
|
|
54
51
|
const deliveryUnit = manifestDeliveryUnit(backendFederation, boundary);
|
|
55
52
|
const manifestUnitId = stringValue(deliveryUnit.boundary?.unitId) ?? stringValue(deliveryUnit.top?.unitId);
|
|
56
53
|
const manifestBuildMarker = stringValue(deliveryUnit.boundary?.buildMarker);
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
const issues = validateBackendFederationCompatibility(compatibility, {
|
|
55
|
+
contractVersion: stringValue(backendFederation?.contractVersion),
|
|
56
|
+
nodeAdapterVersion: stringValue(backendFederation?.nodeAdapterVersion),
|
|
57
|
+
packageName: stringValue(boundary?.packageName),
|
|
58
|
+
unitId: manifestUnitId,
|
|
59
|
+
build: manifestBuildMarker ?? stringValue(boundary?.buildVersion)
|
|
60
|
+
});
|
|
61
|
+
assertVersionValue(stringValue(compatibility.build), stringValue(boundary?.buildVersion), 'expose buildVersion');
|
|
62
|
+
assertManifestAdapter(0 === issues.length, 'version_mismatch', `[BFF][Effect] ${formatBackendFederationIdentityIssues(issues)}.`);
|
|
59
63
|
}
|
|
60
64
|
function classifyLoadError(error) {
|
|
61
65
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -1,30 +1,20 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import { readFileSync } from "node:fs";
|
|
3
|
-
import node_path from "node:path";
|
|
4
2
|
import "@modern-js/server-runtime-extensions/server-config";
|
|
5
|
-
import {
|
|
6
|
-
const
|
|
7
|
-
if (!startDir) return;
|
|
8
|
-
let current = node_path.resolve(startDir);
|
|
9
|
-
for(let depth = 0; depth < 10; depth += 1){
|
|
10
|
-
try {
|
|
11
|
-
const packageJson = JSON.parse(readFileSync(node_path.join(current, 'package.json'), 'utf8'));
|
|
12
|
-
if ('string' == typeof packageJson.version) return packageJson.version;
|
|
13
|
-
} catch {}
|
|
14
|
-
const parent = node_path.dirname(current);
|
|
15
|
-
if (parent === current) break;
|
|
16
|
-
current = parent;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
const resolveAdapterCrossProjectPolicy = (api, handlers)=>{
|
|
3
|
+
import { resolveCrossProjectPolicy, resolveOperationProducer } from "@modern-js/server-runtime-extensions/bff-policy/node";
|
|
4
|
+
const resolveAdapterCrossProjectPolicy = (api, handlers, producer)=>{
|
|
20
5
|
const bff = api.getServerConfig()?.bff;
|
|
21
6
|
const { apiDirectory, appDirectory } = api.getServerContext();
|
|
22
7
|
return resolveCrossProjectPolicy({
|
|
23
8
|
crossProjectPolicy: bff?.crossProjectPolicy,
|
|
24
9
|
handlers,
|
|
25
|
-
requestId: bff?.requestId,
|
|
26
10
|
isCrossProjectServer: bff?.isCrossProjectServer,
|
|
27
|
-
|
|
11
|
+
...producer ?? resolveOperationProducer({
|
|
12
|
+
directories: [
|
|
13
|
+
apiDirectory,
|
|
14
|
+
appDirectory
|
|
15
|
+
],
|
|
16
|
+
requestId: bff?.requestId || 'default'
|
|
17
|
+
})
|
|
28
18
|
});
|
|
29
19
|
};
|
|
30
20
|
export { resolveAdapterCrossProjectPolicy };
|