@bleedingdev/modern-js-plugin-bff-extensions 3.9.0-ultramodern.2 → 3.9.0-ultramodern.20
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 +25 -5
- package/dist/cjs/backend-federation/edge-runtime.js +3 -15
- package/dist/cjs/backend-federation/edge.js +9 -10
- package/dist/cjs/backend-federation/identity.js +26 -31
- package/dist/cjs/backend-federation/index.js +5 -5
- package/dist/cjs/backend-federation/integrity-plugin.js +112 -0
- package/dist/cjs/backend-federation/load.js +3 -13
- package/dist/cjs/backend-federation/node-shared.js +85 -0
- package/dist/cjs/backend-federation/node.js +6 -1
- package/dist/cjs/backend-federation/plugin.js +40 -21
- package/dist/cjs/backend-federation/runtime.js +16 -84
- package/dist/cjs/backend-federation/validate-loaded.js +2 -4
- package/dist/cjs/backend-federation-manifest/load.js +40 -12
- package/dist/cjs/backend-federation-manifest/metadata.js +3 -3
- package/dist/cjs/backend-federation-manifest/node.js +3 -1
- package/dist/cjs/backend-federation-manifest/remote.js +3 -9
- package/dist/cjs/backend-federation-manifest/validation.js +16 -12
- package/dist/cjs/cross-project-policy/evaluation.js +3 -3
- package/dist/cjs/cross-project-policy/node.js +11 -30
- package/dist/cjs/{backend-federation/legacy-warning.js → cross-project-policy/producer-runtime.js} +23 -5
- package/dist/cjs/{effect-adapter → effect-server}/cross-project-policy.js +5 -5
- package/dist/cjs/effect-server/entry.js +63 -0
- package/dist/cjs/{effect-adapter → effect-server}/error-response.js +4 -4
- package/dist/cjs/effect-server/index.js +199 -0
- package/dist/cjs/{client-generator → effect-source-loader}/built-entry.js +5 -6
- package/dist/cjs/{client-generator/runtime.js → effect-source-loader/http-api-runtime.js} +12 -20
- package/dist/cjs/effect-source-loader/index.js +18 -6
- package/dist/cjs/effect-source-loader/loader.js +17 -30
- package/dist/cjs/effect-source-loader/operation-contracts.js +60 -0
- package/dist/cjs/effect-source-loader/paths.js +90 -0
- package/dist/cjs/effect-source-loader/rspack-loader.js +73 -0
- package/dist/cjs/effect-source-loader/worker-runtime-source.js +71 -0
- package/dist/cjs/effect-source-loader/worker-runtime-wrapper.js +7 -50
- package/dist/cjs/hono/cross-project-policy.js +2 -1
- package/dist/cjs/{client-generator/paths.js → hono/node.js} +14 -25
- package/dist/esm/backend-federation/edge-runtime.mjs +2 -11
- package/dist/esm/backend-federation/edge.mjs +5 -6
- package/dist/esm/backend-federation/identity.mjs +21 -32
- package/dist/esm/backend-federation/index.mjs +1 -1
- package/dist/esm/backend-federation/integrity-plugin.mjs +68 -0
- package/dist/esm/backend-federation/load.mjs +2 -12
- package/dist/esm/backend-federation/node-shared.mjs +41 -0
- package/dist/esm/backend-federation/node.mjs +4 -2
- package/dist/esm/backend-federation/plugin.mjs +37 -18
- package/dist/esm/backend-federation/runtime.mjs +16 -84
- package/dist/esm/backend-federation/validate-loaded.mjs +2 -4
- package/dist/esm/backend-federation-manifest/load.mjs +40 -12
- package/dist/esm/backend-federation-manifest/metadata.mjs +1 -1
- package/dist/esm/backend-federation-manifest/node.mjs +3 -1
- package/dist/esm/backend-federation-manifest/remote.mjs +2 -8
- package/dist/esm/backend-federation-manifest/validation.mjs +15 -11
- package/dist/esm/cross-project-policy/evaluation.mjs +1 -1
- package/dist/esm/cross-project-policy/node.mjs +10 -19
- package/dist/esm/cross-project-policy/producer-runtime.mjs +20 -0
- package/dist/esm/{effect-adapter → effect-server}/cross-project-policy.mjs +3 -3
- package/dist/esm/effect-server/entry.mjs +15 -0
- package/dist/esm/{effect-adapter → effect-server}/error-response.mjs +2 -2
- package/dist/esm/effect-server/index.mjs +151 -0
- package/dist/esm/{client-generator → effect-source-loader}/built-entry.mjs +6 -7
- package/dist/esm/effect-source-loader/http-api-runtime.mjs +19 -0
- package/dist/esm/effect-source-loader/index.mjs +5 -2
- package/dist/esm/effect-source-loader/loader.mjs +17 -30
- package/dist/esm/effect-source-loader/operation-contracts.mjs +22 -0
- package/dist/esm/effect-source-loader/paths.mjs +43 -0
- package/dist/esm/effect-source-loader/rspack-loader.mjs +35 -0
- package/dist/esm/effect-source-loader/worker-runtime-source.mjs +23 -0
- package/dist/esm/effect-source-loader/worker-runtime-wrapper.mjs +5 -45
- package/dist/esm/hono/cross-project-policy.mjs +2 -1
- package/dist/esm-node/backend-federation/edge-runtime.mjs +2 -11
- package/dist/esm-node/backend-federation/edge.mjs +5 -6
- package/dist/esm-node/backend-federation/identity.mjs +21 -32
- package/dist/esm-node/backend-federation/index.mjs +1 -1
- package/dist/esm-node/backend-federation/integrity-plugin.mjs +69 -0
- package/dist/esm-node/backend-federation/load.mjs +2 -12
- package/dist/esm-node/backend-federation/node-shared.mjs +42 -0
- package/dist/esm-node/backend-federation/node.mjs +4 -2
- package/dist/esm-node/backend-federation/plugin.mjs +37 -18
- package/dist/esm-node/backend-federation/runtime.mjs +16 -84
- package/dist/esm-node/backend-federation/validate-loaded.mjs +2 -4
- package/dist/esm-node/backend-federation-manifest/load.mjs +40 -12
- package/dist/esm-node/backend-federation-manifest/metadata.mjs +1 -1
- package/dist/esm-node/backend-federation-manifest/node.mjs +3 -1
- package/dist/esm-node/backend-federation-manifest/remote.mjs +2 -8
- package/dist/esm-node/backend-federation-manifest/validation.mjs +15 -11
- package/dist/esm-node/cross-project-policy/evaluation.mjs +1 -1
- package/dist/esm-node/cross-project-policy/node.mjs +10 -19
- package/dist/esm-node/cross-project-policy/producer-runtime.mjs +21 -0
- package/dist/esm-node/{effect-adapter → effect-server}/cross-project-policy.mjs +3 -3
- package/dist/esm-node/effect-server/entry.mjs +16 -0
- package/dist/esm-node/{effect-adapter → effect-server}/error-response.mjs +2 -2
- package/dist/esm-node/effect-server/index.mjs +152 -0
- package/dist/esm-node/{client-generator → effect-source-loader}/built-entry.mjs +6 -7
- package/dist/esm-node/effect-source-loader/http-api-runtime.mjs +20 -0
- package/dist/esm-node/effect-source-loader/index.mjs +5 -2
- package/dist/esm-node/effect-source-loader/loader.mjs +17 -30
- package/dist/esm-node/effect-source-loader/operation-contracts.mjs +23 -0
- package/dist/esm-node/effect-source-loader/paths.mjs +44 -0
- package/dist/esm-node/effect-source-loader/rspack-loader.mjs +37 -0
- package/dist/esm-node/effect-source-loader/worker-runtime-source.mjs +24 -0
- package/dist/esm-node/effect-source-loader/worker-runtime-wrapper.mjs +5 -45
- package/dist/esm-node/hono/cross-project-policy.mjs +2 -1
- package/dist/esm-node/hono/node.mjs +14 -0
- package/dist/types/backend-federation/edge-runtime.d.ts +0 -5
- package/dist/types/backend-federation/edge.d.ts +5 -5
- package/dist/types/backend-federation/identity.d.ts +4 -16
- package/dist/types/backend-federation/index.d.ts +1 -1
- package/dist/types/backend-federation/integrity-plugin.d.ts +13 -0
- package/dist/types/backend-federation/load.d.ts +1 -7
- package/dist/types/backend-federation/node-shared.d.ts +20 -0
- package/dist/types/backend-federation/node.d.ts +4 -3
- package/dist/types/backend-federation/plugin.d.ts +4 -0
- package/dist/types/backend-federation/types.d.ts +3 -14
- package/dist/types/backend-federation/validate-loaded.d.ts +1 -2
- package/dist/types/backend-federation-manifest/metadata.d.ts +0 -6
- package/dist/types/backend-federation-manifest/types.d.ts +2 -1
- package/dist/types/cross-project-policy/evaluation.d.ts +1 -1
- package/dist/types/cross-project-policy/node.d.ts +3 -2
- package/dist/types/cross-project-policy/producer-runtime.d.ts +20 -0
- package/dist/types/effect-server/cross-project-policy.d.ts +5 -0
- package/dist/types/effect-server/entry.d.ts +3 -0
- package/dist/types/effect-server/error-response.d.ts +2 -0
- package/dist/types/effect-server/index.d.ts +4 -0
- package/dist/types/effect-source-loader/index.d.ts +5 -2
- package/dist/types/effect-source-loader/operation-contracts.d.ts +8 -0
- package/dist/types/effect-source-loader/paths.d.ts +23 -0
- package/dist/types/effect-source-loader/rspack-loader.d.ts +9 -0
- package/dist/types/effect-source-loader/worker-runtime-source.d.ts +4 -0
- package/dist/types/effect-source-loader/worker-runtime-wrapper.d.ts +4 -22
- package/dist/types/hono/node.d.ts +4 -0
- package/package.json +64 -36
- package/src/backend-federation/edge-runtime.ts +2 -13
- package/src/backend-federation/edge.ts +16 -21
- package/src/backend-federation/identity.ts +39 -65
- package/src/backend-federation/index.ts +1 -1
- package/src/backend-federation/integrity-plugin.ts +157 -0
- package/src/backend-federation/load.ts +7 -35
- package/src/backend-federation/node-shared.ts +76 -0
- package/src/backend-federation/node.ts +7 -14
- package/src/backend-federation/plugin.ts +73 -25
- package/src/backend-federation/runtime.ts +16 -90
- package/src/backend-federation/types.ts +3 -18
- package/src/backend-federation/validate-loaded.ts +2 -7
- package/src/backend-federation-manifest/load.ts +93 -38
- package/src/backend-federation-manifest/metadata.ts +1 -7
- package/src/backend-federation-manifest/node.ts +3 -2
- package/src/backend-federation-manifest/remote.ts +1 -7
- package/src/backend-federation-manifest/types.ts +2 -0
- package/src/backend-federation-manifest/validation.ts +29 -39
- package/src/cross-project-policy/evaluation.ts +1 -1
- package/src/cross-project-policy/node.ts +10 -41
- package/src/cross-project-policy/producer-runtime.ts +43 -0
- package/src/{effect-adapter → effect-server}/cross-project-policy.ts +8 -2
- package/src/effect-server/entry.ts +18 -0
- package/src/{effect-adapter → effect-server}/error-response.ts +1 -1
- package/src/effect-server/index.ts +242 -0
- package/src/{client-generator → effect-source-loader}/built-entry.ts +12 -12
- package/src/effect-source-loader/http-api-runtime.ts +39 -0
- package/src/effect-source-loader/index.ts +8 -5
- package/src/effect-source-loader/loader.ts +47 -52
- package/src/effect-source-loader/operation-contracts.ts +38 -0
- package/src/effect-source-loader/paths.ts +74 -0
- package/src/effect-source-loader/rspack-loader.ts +71 -0
- package/src/effect-source-loader/worker-runtime-source.ts +34 -0
- package/src/effect-source-loader/worker-runtime-wrapper.ts +5 -75
- package/src/hono/cross-project-policy.ts +2 -1
- package/src/hono/node.ts +24 -0
- package/dist/cjs/backend-federation/entry.js +0 -94
- package/dist/cjs/client-generator/generator.js +0 -73
- package/dist/cjs/client-generator/index.js +0 -54
- package/dist/cjs/client-generator/rendering.js +0 -253
- package/dist/cjs/client-generator/types.js +0 -18
- package/dist/cjs/effect-adapter/entry.js +0 -98
- package/dist/cjs/effect-adapter/index.js +0 -187
- package/dist/esm/backend-federation/entry.mjs +0 -56
- package/dist/esm/backend-federation/legacy-warning.mjs +0 -2
- package/dist/esm/client-generator/generator.mjs +0 -32
- package/dist/esm/client-generator/index.mjs +0 -3
- package/dist/esm/client-generator/paths.mjs +0 -24
- package/dist/esm/client-generator/rendering.mjs +0 -209
- package/dist/esm/client-generator/runtime.mjs +0 -27
- package/dist/esm/client-generator/types.mjs +0 -0
- package/dist/esm/effect-adapter/entry.mjs +0 -50
- package/dist/esm/effect-adapter/index.mjs +0 -139
- package/dist/esm-node/backend-federation/entry.mjs +0 -57
- package/dist/esm-node/backend-federation/legacy-warning.mjs +0 -3
- package/dist/esm-node/client-generator/generator.mjs +0 -33
- package/dist/esm-node/client-generator/index.mjs +0 -4
- package/dist/esm-node/client-generator/paths.mjs +0 -25
- package/dist/esm-node/client-generator/rendering.mjs +0 -210
- package/dist/esm-node/client-generator/runtime.mjs +0 -29
- package/dist/esm-node/client-generator/types.mjs +0 -1
- package/dist/esm-node/effect-adapter/entry.mjs +0 -51
- package/dist/esm-node/effect-adapter/index.mjs +0 -140
- package/dist/types/backend-federation/entry.d.ts +0 -2
- package/dist/types/backend-federation/legacy-warning.d.ts +0 -1
- package/dist/types/client-generator/generator.d.ts +0 -3
- package/dist/types/client-generator/index.d.ts +0 -4
- package/dist/types/client-generator/paths.d.ts +0 -5
- package/dist/types/client-generator/rendering.d.ts +0 -24
- package/dist/types/client-generator/types.d.ts +0 -33
- package/dist/types/effect-adapter/cross-project-policy.d.ts +0 -4
- package/dist/types/effect-adapter/entry.d.ts +0 -2
- package/dist/types/effect-adapter/error-response.d.ts +0 -2
- package/dist/types/effect-adapter/index.d.ts +0 -19
- package/src/backend-federation/entry.ts +0 -125
- package/src/backend-federation/legacy-warning.ts +0 -2
- package/src/client-generator/generator.ts +0 -52
- package/src/client-generator/index.ts +0 -10
- package/src/client-generator/paths.ts +0 -40
- package/src/client-generator/rendering.ts +0 -307
- package/src/client-generator/runtime.ts +0 -69
- package/src/client-generator/types.ts +0 -35
- package/src/effect-adapter/entry.ts +0 -95
- package/src/effect-adapter/index.ts +0 -246
- /package/dist/types/{client-generator → effect-source-loader}/built-entry.d.ts +0 -0
- /package/dist/types/{client-generator/runtime.d.ts → effect-source-loader/http-api-runtime.d.ts} +0 -0
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
-
var define = (defs, kind)=>{
|
|
6
|
-
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
[kind]: defs[key]
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
define(getters, "get");
|
|
12
|
-
define(values, "value");
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
(()=>{
|
|
16
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
-
})();
|
|
18
|
-
(()=>{
|
|
19
|
-
__webpack_require__.r = (exports1)=>{
|
|
20
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
-
value: 'Module'
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
-
value: true
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
})();
|
|
28
|
-
var __webpack_exports__ = {};
|
|
29
|
-
__webpack_require__.r(__webpack_exports__);
|
|
30
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
-
createEffectClientGeneration: ()=>createEffectClientGeneration,
|
|
32
|
-
renderEffectClientCode: ()=>renderEffectClientCode,
|
|
33
|
-
renderEffectClientDeclaration: ()=>renderEffectClientDeclaration
|
|
34
|
-
});
|
|
35
|
-
const bff_core_namespaceObject = require("@modern-js/bff-core");
|
|
36
|
-
const effect_namespaceObject = require("@modern-js/bff-effect/effect");
|
|
37
|
-
const utils_namespaceObject = require("@modern-js/utils");
|
|
38
|
-
const DEFAULT_REQUEST_CREATOR = '@modern-js/plugin-bff/client';
|
|
39
|
-
const EFFECT_CLIENT_RUNTIME_IMPORT = '@modern-js/plugin-bff/effect-client-runtime';
|
|
40
|
-
function isAbsoluteUrl(value) {
|
|
41
|
-
try {
|
|
42
|
-
new URL(value);
|
|
43
|
-
return true;
|
|
44
|
-
} catch {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function resolveBatchEndpoint(prefix, endpoint) {
|
|
49
|
-
const value = void 0 === endpoint || '' === endpoint ? '/_data/batch' : endpoint;
|
|
50
|
-
if (isAbsoluteUrl(value)) return value;
|
|
51
|
-
const normalizedPrefix = (0, effect_namespaceObject.normalizeEffectPrefix)(prefix);
|
|
52
|
-
const normalizedEndpoint = (0, effect_namespaceObject.ensureLeadingSlash)(value);
|
|
53
|
-
if ('' === normalizedPrefix) return normalizedEndpoint;
|
|
54
|
-
if (normalizedEndpoint === normalizedPrefix || normalizedEndpoint.startsWith(`${normalizedPrefix}/`)) return normalizedEndpoint;
|
|
55
|
-
return `${normalizedPrefix}${'/' === normalizedEndpoint ? '' : normalizedEndpoint}`;
|
|
56
|
-
}
|
|
57
|
-
function getPackageInfo(resourcePath, appDir, onDependency) {
|
|
58
|
-
for (const startDir of [
|
|
59
|
-
utils_namespaceObject.upath.dirname(resourcePath),
|
|
60
|
-
appDir
|
|
61
|
-
]){
|
|
62
|
-
let current = utils_namespaceObject.upath.resolve(startDir);
|
|
63
|
-
for(let depth = 0; depth < 32; depth += 1){
|
|
64
|
-
const packageJsonPath = utils_namespaceObject.upath.join(current, 'package.json');
|
|
65
|
-
if (utils_namespaceObject.fs.existsSync(packageJsonPath)) {
|
|
66
|
-
onDependency?.(packageJsonPath);
|
|
67
|
-
try {
|
|
68
|
-
const packageJson = utils_namespaceObject.fs.readJSONSync(packageJsonPath);
|
|
69
|
-
return {
|
|
70
|
-
name: packageJson.name,
|
|
71
|
-
version: packageJson.version
|
|
72
|
-
};
|
|
73
|
-
} catch {
|
|
74
|
-
return {};
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
const parent = utils_namespaceObject.upath.dirname(current);
|
|
78
|
-
if (parent === current) break;
|
|
79
|
-
current = parent;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return {};
|
|
83
|
-
}
|
|
84
|
-
function renderEffectClientCode(generation) {
|
|
85
|
-
const { config, manifest } = generation;
|
|
86
|
-
return `import * as __requestRuntime from ${JSON.stringify(generation.requestCreator)};
|
|
87
|
-
import { createGeneratedEffectClient } from ${JSON.stringify(EFFECT_CLIENT_RUNTIME_IMPORT)};
|
|
88
|
-
|
|
89
|
-
const __manifest = ${JSON.stringify(manifest, null, 2)};
|
|
90
|
-
|
|
91
|
-
const __config = ${JSON.stringify(config, null, 2)};
|
|
92
|
-
|
|
93
|
-
const __generated = createGeneratedEffectClient(__manifest, __config, __requestRuntime);
|
|
94
|
-
|
|
95
|
-
const client = __generated.client;
|
|
96
|
-
const operationManifest = __generated.operationManifest;
|
|
97
|
-
const createEffectRequestContext = __generated.createEffectRequestContext;
|
|
98
|
-
const apiModule = {
|
|
99
|
-
client,
|
|
100
|
-
operationManifest,
|
|
101
|
-
createEffectRequestContext,
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
export { client, createEffectRequestContext, operationManifest };
|
|
105
|
-
export default apiModule;
|
|
106
|
-
`;
|
|
107
|
-
}
|
|
108
|
-
function createEffectClientGeneration(endpoints, options) {
|
|
109
|
-
const requestCreator = options.requestCreator || DEFAULT_REQUEST_CREATOR;
|
|
110
|
-
const httpMethodDecider = options.httpMethodDecider || 'functionName';
|
|
111
|
-
const packageInfo = getPackageInfo(options.resourcePath, options.appDir, options.onDependency);
|
|
112
|
-
const packageName = packageInfo.name;
|
|
113
|
-
const dataPlatformAppNamespace = void 0 === packageName || '' === packageName ? 'unknown-app' : packageName;
|
|
114
|
-
const requestId = 'bundle' === options.target ? void 0 !== options.requestId && '' !== options.requestId.trim() ? options.requestId.trim() : void 0 !== packageName && '' !== packageName ? packageName : void 0 : void 0;
|
|
115
|
-
const normalizedRequestId = void 0 === requestId || '' === requestId ? 'default' : requestId;
|
|
116
|
-
const operationVersion = (0, bff_core_namespaceObject.deriveOperationVersion)(packageInfo.version);
|
|
117
|
-
const batchConfig = options.dataPlatformBatch;
|
|
118
|
-
const batchEndpoint = resolveBatchEndpoint(options.prefix, batchConfig?.endpoint);
|
|
119
|
-
const manifest = {
|
|
120
|
-
endpoints: endpoints.map((endpoint)=>({
|
|
121
|
-
apiId: endpoint.apiId,
|
|
122
|
-
group: endpoint.groupName,
|
|
123
|
-
endpoint: endpoint.endpointName,
|
|
124
|
-
method: endpoint.method,
|
|
125
|
-
routePath: endpoint.routePath,
|
|
126
|
-
schemaHash: (0, effect_namespaceObject.createEffectEndpointContractHash)(endpoint, normalizedRequestId),
|
|
127
|
-
operationVersion
|
|
128
|
-
}))
|
|
129
|
-
};
|
|
130
|
-
const config = {
|
|
131
|
-
appNamespace: dataPlatformAppNamespace,
|
|
132
|
-
...void 0 !== requestId && '' !== requestId ? {
|
|
133
|
-
requestId
|
|
134
|
-
} : {},
|
|
135
|
-
port: options.port,
|
|
136
|
-
useEnvPort: 'server' === options.target,
|
|
137
|
-
defaultOrigin: `http://localhost:${String(options.port)}`,
|
|
138
|
-
httpMethodDecider,
|
|
139
|
-
batch: {
|
|
140
|
-
enabled: batchConfig?.enabled ?? true,
|
|
141
|
-
endpoint: batchEndpoint,
|
|
142
|
-
flushIntervalMs: batchConfig?.flushIntervalMs ?? 8,
|
|
143
|
-
maxBatchSize: batchConfig?.maxBatchSize ?? 16,
|
|
144
|
-
maxBatchBytes: batchConfig?.maxBatchBytes ?? 65536,
|
|
145
|
-
requestTimeoutMs: batchConfig?.requestTimeoutMs ?? 10000,
|
|
146
|
-
allowedMethods: batchConfig?.allowedMethods !== void 0 && batchConfig.allowedMethods.length > 0 ? batchConfig.allowedMethods : [
|
|
147
|
-
'GET'
|
|
148
|
-
]
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
return {
|
|
152
|
-
config,
|
|
153
|
-
manifest,
|
|
154
|
-
operationContracts: (0, bff_core_namespaceObject.buildOperationContractMap)({
|
|
155
|
-
handlers: (0, effect_namespaceObject.toOperationContractSources)(endpoints),
|
|
156
|
-
requestId: normalizedRequestId,
|
|
157
|
-
operationVersion
|
|
158
|
-
}),
|
|
159
|
-
operationVersion,
|
|
160
|
-
requestCreator,
|
|
161
|
-
requestId: normalizedRequestId
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
function renderClientShape(endpoints, valueType) {
|
|
165
|
-
if (0 === endpoints.length) return `Record<string, Record<string, ${valueType}>>`;
|
|
166
|
-
const groups = new Map();
|
|
167
|
-
for (const endpoint of endpoints){
|
|
168
|
-
const group = groups.get(endpoint.groupName) || [];
|
|
169
|
-
group.push(endpoint.endpointName);
|
|
170
|
-
groups.set(endpoint.groupName, group);
|
|
171
|
-
}
|
|
172
|
-
const groupEntries = [
|
|
173
|
-
...groups.entries()
|
|
174
|
-
].map(([groupName, names])=>{
|
|
175
|
-
const endpointEntries = names.map((name)=>` ${JSON.stringify(name)}: ${valueType};`).join('\n');
|
|
176
|
-
return ` ${JSON.stringify(groupName)}: {\n${endpointEntries}\n };`;
|
|
177
|
-
});
|
|
178
|
-
return `{\n${groupEntries.join('\n')}\n}`;
|
|
179
|
-
}
|
|
180
|
-
function renderEffectClientDeclaration(endpoints = []) {
|
|
181
|
-
return `export type EffectClientOperation = (
|
|
182
|
-
request?: unknown,
|
|
183
|
-
) => Promise<unknown>;
|
|
184
|
-
export type EffectClientGroup = Record<string, EffectClientOperation>;
|
|
185
|
-
export type EffectClient = Record<string, EffectClientGroup>;
|
|
186
|
-
export type EffectOperationDescriptor = {
|
|
187
|
-
appNamespace: string;
|
|
188
|
-
apiId: string;
|
|
189
|
-
group: string;
|
|
190
|
-
endpoint: string;
|
|
191
|
-
operationId: string;
|
|
192
|
-
routePath: string;
|
|
193
|
-
method: string;
|
|
194
|
-
operationVersion: number;
|
|
195
|
-
schemaHash: string;
|
|
196
|
-
version: number;
|
|
197
|
-
};
|
|
198
|
-
export type EffectOperationManifest = Record<
|
|
199
|
-
string,
|
|
200
|
-
Record<string, EffectOperationDescriptor>
|
|
201
|
-
>;
|
|
202
|
-
export type EffectOperationContext = {
|
|
203
|
-
requestId?: string;
|
|
204
|
-
operationId?: string;
|
|
205
|
-
routePath?: string;
|
|
206
|
-
method?: string;
|
|
207
|
-
schemaHash?: string;
|
|
208
|
-
operationVersion?: number;
|
|
209
|
-
locale?: string;
|
|
210
|
-
traceparent?: string;
|
|
211
|
-
traceId?: string;
|
|
212
|
-
spanId?: string;
|
|
213
|
-
source?: string;
|
|
214
|
-
scope?: Record<string, unknown>;
|
|
215
|
-
sessionClaims?: Record<string, unknown>;
|
|
216
|
-
attributes?: Record<string, unknown>;
|
|
217
|
-
};
|
|
218
|
-
export type EffectRequestContext = {
|
|
219
|
-
headers?: Record<string, string>;
|
|
220
|
-
locale?: string;
|
|
221
|
-
operationContext?: EffectOperationContext;
|
|
222
|
-
traceparent?: string;
|
|
223
|
-
traceId?: string;
|
|
224
|
-
spanId?: string;
|
|
225
|
-
};
|
|
226
|
-
export type GeneratedEffectClient = ${renderClientShape(endpoints, 'EffectClientOperation')};
|
|
227
|
-
export type GeneratedEffectOperationManifest = ${renderClientShape(endpoints, "EffectOperationDescriptor")};
|
|
228
|
-
|
|
229
|
-
export declare const client: GeneratedEffectClient;
|
|
230
|
-
export declare const createEffectRequestContext: (
|
|
231
|
-
requestContext: Record<string, unknown>,
|
|
232
|
-
) => EffectRequestContext;
|
|
233
|
-
export declare const operationManifest: GeneratedEffectOperationManifest;
|
|
234
|
-
declare const apiModule: {
|
|
235
|
-
client: GeneratedEffectClient;
|
|
236
|
-
createEffectRequestContext: typeof createEffectRequestContext;
|
|
237
|
-
operationManifest: GeneratedEffectOperationManifest;
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
export default apiModule;
|
|
241
|
-
`;
|
|
242
|
-
}
|
|
243
|
-
exports.createEffectClientGeneration = __webpack_exports__.createEffectClientGeneration;
|
|
244
|
-
exports.renderEffectClientCode = __webpack_exports__.renderEffectClientCode;
|
|
245
|
-
exports.renderEffectClientDeclaration = __webpack_exports__.renderEffectClientDeclaration;
|
|
246
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
247
|
-
"createEffectClientGeneration",
|
|
248
|
-
"renderEffectClientCode",
|
|
249
|
-
"renderEffectClientDeclaration"
|
|
250
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
251
|
-
Object.defineProperty(exports, '__esModule', {
|
|
252
|
-
value: true
|
|
253
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.r = (exports1)=>{
|
|
5
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
6
|
-
value: 'Module'
|
|
7
|
-
});
|
|
8
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
9
|
-
value: true
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
})();
|
|
13
|
-
var __webpack_exports__ = {};
|
|
14
|
-
__webpack_require__.r(__webpack_exports__);
|
|
15
|
-
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
16
|
-
Object.defineProperty(exports, '__esModule', {
|
|
17
|
-
value: true
|
|
18
|
-
});
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
-
__webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
});
|
|
9
|
-
return getter;
|
|
10
|
-
};
|
|
11
|
-
})();
|
|
12
|
-
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
|
-
var define = (defs, kind)=>{
|
|
15
|
-
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
[kind]: defs[key]
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
define(getters, "get");
|
|
21
|
-
define(values, "value");
|
|
22
|
-
};
|
|
23
|
-
})();
|
|
24
|
-
(()=>{
|
|
25
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
26
|
-
})();
|
|
27
|
-
(()=>{
|
|
28
|
-
__webpack_require__.r = (exports1)=>{
|
|
29
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
30
|
-
value: 'Module'
|
|
31
|
-
});
|
|
32
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
33
|
-
value: true
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
})();
|
|
37
|
-
var __webpack_exports__ = {};
|
|
38
|
-
__webpack_require__.r(__webpack_exports__);
|
|
39
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
40
|
-
resolveEffectAdapterEntryFile: ()=>resolveEffectAdapterEntryFile
|
|
41
|
-
});
|
|
42
|
-
const external_node_path_namespaceObject = require("node:path");
|
|
43
|
-
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
44
|
-
const utils_namespaceObject = require("@modern-js/utils");
|
|
45
|
-
const JS_OR_TS_EXTS = [
|
|
46
|
-
'.js',
|
|
47
|
-
'.jsx',
|
|
48
|
-
'.ts',
|
|
49
|
-
'.tsx',
|
|
50
|
-
'.mjs',
|
|
51
|
-
'.mts',
|
|
52
|
-
'.cjs',
|
|
53
|
-
'.cts'
|
|
54
|
-
];
|
|
55
|
-
function resolveJsOrTsEntry(entryWithoutOrWithExt) {
|
|
56
|
-
const extension = external_node_path_default().extname(entryWithoutOrWithExt);
|
|
57
|
-
if (JS_OR_TS_EXTS.includes(extension)) return utils_namespaceObject.fs.existsSync(entryWithoutOrWithExt) ? entryWithoutOrWithExt : void 0;
|
|
58
|
-
return (0, utils_namespaceObject.findExists)(JS_OR_TS_EXTS.map((ext)=>`${entryWithoutOrWithExt}${ext}`)) || void 0;
|
|
59
|
-
}
|
|
60
|
-
function builtEntryPath(entryPath) {
|
|
61
|
-
return entryPath.replace(/\.(?:[cm]?ts|tsx|jsx)$/u, '.js');
|
|
62
|
-
}
|
|
63
|
-
function relativeAppPath(appDirectory, entryPath) {
|
|
64
|
-
const relativePath = external_node_path_default().relative(appDirectory, entryPath);
|
|
65
|
-
return '..' === relativePath || relativePath.startsWith(`..${external_node_path_default().sep}`) ? void 0 : relativePath;
|
|
66
|
-
}
|
|
67
|
-
function isDependencyPath(relativePath) {
|
|
68
|
-
return relativePath?.split(/[\\/]/u).includes('node_modules') ?? false;
|
|
69
|
-
}
|
|
70
|
-
function resolveEffectAdapterEntryFile(api) {
|
|
71
|
-
const { appDirectory, apiDirectory, distDirectory } = api.getServerContext();
|
|
72
|
-
const appRoot = external_node_path_default().resolve(appDirectory || process.cwd());
|
|
73
|
-
const productionRoot = (0, utils_namespaceObject.isProd)() && distDirectory ? external_node_path_default().resolve(distDirectory) : void 0;
|
|
74
|
-
const configuredEntry = api.getServerConfig()?.bff?.effect?.entry;
|
|
75
|
-
if (configuredEntry) {
|
|
76
|
-
const sourceEntry = external_node_path_default().isAbsolute(configuredEntry) ? configuredEntry : external_node_path_default().resolve(appRoot, configuredEntry);
|
|
77
|
-
if (productionRoot) {
|
|
78
|
-
const relativeEntry = relativeAppPath(appRoot, sourceEntry);
|
|
79
|
-
if (void 0 === relativeEntry || isDependencyPath(relativeEntry)) return resolveJsOrTsEntry(sourceEntry);
|
|
80
|
-
return relativeEntry ? resolveJsOrTsEntry(builtEntryPath(external_node_path_default().resolve(productionRoot, relativeEntry))) : void 0;
|
|
81
|
-
}
|
|
82
|
-
return resolveJsOrTsEntry(sourceEntry);
|
|
83
|
-
}
|
|
84
|
-
const resolvedApiDirectory = external_node_path_default().resolve(appRoot, apiDirectory || utils_namespaceObject.API_DIR);
|
|
85
|
-
const productionApiDirectory = productionRoot ? void 0 !== relativeAppPath(productionRoot, resolvedApiDirectory) ? resolvedApiDirectory : (()=>{
|
|
86
|
-
const relativeApiDirectory = relativeAppPath(appRoot, resolvedApiDirectory);
|
|
87
|
-
if (isDependencyPath(relativeApiDirectory)) return resolvedApiDirectory;
|
|
88
|
-
return relativeApiDirectory ? external_node_path_default().resolve(productionRoot, relativeApiDirectory) : void 0;
|
|
89
|
-
})() : resolvedApiDirectory;
|
|
90
|
-
return productionApiDirectory ? resolveJsOrTsEntry(external_node_path_default().resolve(productionApiDirectory, 'index')) : void 0;
|
|
91
|
-
}
|
|
92
|
-
exports.resolveEffectAdapterEntryFile = __webpack_exports__.resolveEffectAdapterEntryFile;
|
|
93
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
94
|
-
"resolveEffectAdapterEntryFile"
|
|
95
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
96
|
-
Object.defineProperty(exports, '__esModule', {
|
|
97
|
-
value: true
|
|
98
|
-
});
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
-
__webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
});
|
|
9
|
-
return getter;
|
|
10
|
-
};
|
|
11
|
-
})();
|
|
12
|
-
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
|
-
var define = (defs, kind)=>{
|
|
15
|
-
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
[kind]: defs[key]
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
define(getters, "get");
|
|
21
|
-
define(values, "value");
|
|
22
|
-
};
|
|
23
|
-
})();
|
|
24
|
-
(()=>{
|
|
25
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
26
|
-
})();
|
|
27
|
-
(()=>{
|
|
28
|
-
__webpack_require__.r = (exports1)=>{
|
|
29
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
30
|
-
value: 'Module'
|
|
31
|
-
});
|
|
32
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
33
|
-
value: true
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
})();
|
|
37
|
-
var __webpack_exports__ = {};
|
|
38
|
-
__webpack_require__.r(__webpack_exports__);
|
|
39
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
40
|
-
EffectAdapter: ()=>EffectAdapter
|
|
41
|
-
});
|
|
42
|
-
const external_node_path_namespaceObject = require("node:path");
|
|
43
|
-
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
44
|
-
const effect_namespaceObject = require("@modern-js/bff-effect/effect");
|
|
45
|
-
const runtime_lifecycle_namespaceObject = require("@modern-js/server-runtime-extensions/runtime-lifecycle");
|
|
46
|
-
const utils_namespaceObject = require("@modern-js/utils");
|
|
47
|
-
const evaluation_js_namespaceObject = require("../cross-project-policy/evaluation.js");
|
|
48
|
-
const loader_js_namespaceObject = require("../effect-source-loader/loader.js");
|
|
49
|
-
const external_cross_project_policy_js_namespaceObject = require("./cross-project-policy.js");
|
|
50
|
-
const external_entry_js_namespaceObject = require("./entry.js");
|
|
51
|
-
const external_error_response_js_namespaceObject = require("./error-response.js");
|
|
52
|
-
const EFFECT_MIDDLEWARE_BEFORE = [
|
|
53
|
-
'custom-server-hook',
|
|
54
|
-
'custom-server-middleware',
|
|
55
|
-
'render'
|
|
56
|
-
];
|
|
57
|
-
class EffectAdapter {
|
|
58
|
-
async loadHandler() {
|
|
59
|
-
const entryFile = (0, external_entry_js_namespaceObject.resolveEffectAdapterEntryFile)(this.api);
|
|
60
|
-
if (!entryFile || !await utils_namespaceObject.fs.pathExists(entryFile)) {
|
|
61
|
-
this.handler = null;
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
let mod;
|
|
65
|
-
try {
|
|
66
|
-
const { appDirectory } = this.api.getServerContext();
|
|
67
|
-
mod = await ((0, utils_namespaceObject.isProd)() ? (0, loader_js_namespaceObject.loadEffectBuiltModule)(entryFile) : (0, loader_js_namespaceObject.loadEffectSourceModule)({
|
|
68
|
-
resourcePath: entryFile,
|
|
69
|
-
appDir: appDirectory || external_node_path_default().dirname(entryFile)
|
|
70
|
-
}));
|
|
71
|
-
} catch (error) {
|
|
72
|
-
utils_namespaceObject.logger.error(`[BFF][Effect] Failed to load Effect entry: ${entryFile}\n${String(error)}`);
|
|
73
|
-
throw error;
|
|
74
|
-
}
|
|
75
|
-
const crossProjectPolicies = new Map(await Promise.all(this.prefixes.map(async (prefix)=>[
|
|
76
|
-
prefix,
|
|
77
|
-
await (0, external_cross_project_policy_js_namespaceObject.resolveEffectAdapterCrossProjectPolicy)(this.api, prefix, mod)
|
|
78
|
-
])));
|
|
79
|
-
const effectConfig = this.api.getServerConfig()?.bff?.effect;
|
|
80
|
-
const loaded = await (0, effect_namespaceObject.resolveEffectBffModuleHandler)(mod, {
|
|
81
|
-
openapi: effectConfig?.openapi,
|
|
82
|
-
dataPlatform: effectConfig?.dataPlatform,
|
|
83
|
-
validateRequest: (request)=>{
|
|
84
|
-
const { path: mountedPathname } = (0, effect_namespaceObject.useEffectContext)();
|
|
85
|
-
const prefix = this.matchingPrefixes.find((item)=>'/' === item || mountedPathname === item || mountedPathname.startsWith(`${item}/`));
|
|
86
|
-
if (!prefix) return null;
|
|
87
|
-
const requestUrl = new URL(request.url);
|
|
88
|
-
if ('/' !== prefix) requestUrl.pathname = '/' === requestUrl.pathname ? prefix : `${prefix}${requestUrl.pathname}`;
|
|
89
|
-
return (0, evaluation_js_namespaceObject.checkCrossProjectPolicyForRequest)(new Request(requestUrl, request), crossProjectPolicies.get(prefix));
|
|
90
|
-
},
|
|
91
|
-
onWarning: (message)=>utils_namespaceObject.logger.warn(message)
|
|
92
|
-
});
|
|
93
|
-
if (!loaded) {
|
|
94
|
-
const error = new Error(`[BFF][Effect] Invalid Effect entry module: ${entryFile}. Export defineEffectBff(...) or a { api, layer } HttpApi module.`);
|
|
95
|
-
utils_namespaceObject.logger.warn(error.message);
|
|
96
|
-
throw error;
|
|
97
|
-
}
|
|
98
|
-
const candidateOwner = {};
|
|
99
|
-
if (loaded.dispose) (0, runtime_lifecycle_namespaceObject.registerServerRuntimeDisposer)(candidateOwner, loaded.dispose);
|
|
100
|
-
const candidate = (0, runtime_lifecycle_namespaceObject.createDisposableServerRuntimeHandle)(candidateOwner, loaded.handler);
|
|
101
|
-
if (this.retired) {
|
|
102
|
-
await candidate.dispose();
|
|
103
|
-
throw new Error('Cannot initialize a retired Effect adapter.');
|
|
104
|
-
}
|
|
105
|
-
this.handler = candidate;
|
|
106
|
-
}
|
|
107
|
-
constructor(api){
|
|
108
|
-
this.handler = null;
|
|
109
|
-
this.prefix = '/api';
|
|
110
|
-
this.prefixes = [
|
|
111
|
-
'/api'
|
|
112
|
-
];
|
|
113
|
-
this.matchingPrefixes = [
|
|
114
|
-
'/api'
|
|
115
|
-
];
|
|
116
|
-
this.retired = false;
|
|
117
|
-
this.registerMiddleware = async (options)=>{
|
|
118
|
-
const { enableHandleWeb } = options;
|
|
119
|
-
const { bffRuntimeFramework, middlewares: globalMiddlewares } = this.api.getServerContext();
|
|
120
|
-
if ('hono' === bffRuntimeFramework) return;
|
|
121
|
-
const configuredPrefixes = Array.isArray(options.prefix) ? options.prefix.filter(Boolean) : [
|
|
122
|
-
options.prefix || '/api'
|
|
123
|
-
];
|
|
124
|
-
this.prefixes = [
|
|
125
|
-
...new Set(configuredPrefixes.length > 0 ? configuredPrefixes : [
|
|
126
|
-
'/api'
|
|
127
|
-
])
|
|
128
|
-
];
|
|
129
|
-
this.matchingPrefixes = [
|
|
130
|
-
...this.prefixes
|
|
131
|
-
].sort((left, right)=>right.length - left.length);
|
|
132
|
-
this.prefix = this.prefixes[0] || '/api';
|
|
133
|
-
const { serverBase } = this.api.getServerContext();
|
|
134
|
-
if (serverBase) this.unregisterRuntimeDisposer = (0, runtime_lifecycle_namespaceObject.registerServerRuntimeDisposer)(serverBase, this.dispose);
|
|
135
|
-
try {
|
|
136
|
-
await this.loadHandler();
|
|
137
|
-
} catch (error) {
|
|
138
|
-
await this.dispose();
|
|
139
|
-
throw error;
|
|
140
|
-
}
|
|
141
|
-
const middlewarePrefixes = enableHandleWeb ? [
|
|
142
|
-
this.prefix
|
|
143
|
-
] : this.matchingPrefixes;
|
|
144
|
-
const middlewares = middlewarePrefixes.map((middlewarePrefix)=>({
|
|
145
|
-
name: 'effect-api-handler',
|
|
146
|
-
path: enableHandleWeb ? '*' : `${middlewarePrefix}/*`,
|
|
147
|
-
method: 'all',
|
|
148
|
-
order: 'post',
|
|
149
|
-
before: EFFECT_MIDDLEWARE_BEFORE,
|
|
150
|
-
handler: async (context, next)=>{
|
|
151
|
-
const handler = this.handler;
|
|
152
|
-
if (!handler) {
|
|
153
|
-
if (enableHandleWeb) return void await next();
|
|
154
|
-
return (0, external_error_response_js_namespaceObject.createEffectAdapterRuntimeErrorResponse)(this.api, new Error('[BFF][Effect] Missing Effect entry. Define api/index or configure bff.effect.entry.'), context);
|
|
155
|
-
}
|
|
156
|
-
const prefix = enableHandleWeb ? this.matchingPrefixes.find((item)=>'/' === item || context.req.path === item || context.req.path.startsWith(`${item}/`)) || this.prefix : middlewarePrefix;
|
|
157
|
-
const response = await (0, effect_namespaceObject.dispatchEffectBffRequest)(handler, context.req.raw, {
|
|
158
|
-
prefix,
|
|
159
|
-
env: context.env,
|
|
160
|
-
path: context.req.path,
|
|
161
|
-
method: context.req.method,
|
|
162
|
-
onError: (error)=>(0, external_error_response_js_namespaceObject.createEffectAdapterRuntimeErrorResponse)(this.api, error, context)
|
|
163
|
-
});
|
|
164
|
-
if (404 === response.status && enableHandleWeb) return void await next();
|
|
165
|
-
return new Response(response.body, response);
|
|
166
|
-
}
|
|
167
|
-
}));
|
|
168
|
-
globalMiddlewares.push(...middlewares);
|
|
169
|
-
};
|
|
170
|
-
this.dispose = async ()=>{
|
|
171
|
-
this.retired = true;
|
|
172
|
-
this.unregisterRuntimeDisposer?.();
|
|
173
|
-
this.unregisterRuntimeDisposer = void 0;
|
|
174
|
-
const previous = this.handler;
|
|
175
|
-
this.handler = null;
|
|
176
|
-
await previous?.dispose();
|
|
177
|
-
};
|
|
178
|
-
this.api = api;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
exports.EffectAdapter = __webpack_exports__.EffectAdapter;
|
|
182
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
183
|
-
"EffectAdapter"
|
|
184
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
185
|
-
Object.defineProperty(exports, '__esModule', {
|
|
186
|
-
value: true
|
|
187
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { evaluateBackendFederationCommonJsEntry, loadVerifiedBackendFederationEntry } from "@modern-js/server-runtime-extensions/backend-federation-security";
|
|
2
|
-
import { isRecord, normalizeExpose } from "./utils.mjs";
|
|
3
|
-
function decodeDataUrl(url) {
|
|
4
|
-
const commaIndex = url.indexOf(',');
|
|
5
|
-
if (commaIndex < 0) throw new Error('[BFF][Effect] Invalid backend federation data URL entry.');
|
|
6
|
-
return decodeURIComponent(url.slice(commaIndex + 1));
|
|
7
|
-
}
|
|
8
|
-
async function readCommonJsEntrySource(remote) {
|
|
9
|
-
if (remote.entry.startsWith('data:')) return decodeDataUrl(remote.entry);
|
|
10
|
-
throw new Error(`[BFF][Effect] Backend federation remote ${remote.name} cannot load CommonJS entry ${remote.entry}.`);
|
|
11
|
-
}
|
|
12
|
-
async function importModuleEntry(remote) {
|
|
13
|
-
const entry = await import(remote.entry);
|
|
14
|
-
return entry.default ?? entry;
|
|
15
|
-
}
|
|
16
|
-
async function resolvePluginEntry(remote, plugins) {
|
|
17
|
-
for (const plugin of plugins ?? []){
|
|
18
|
-
const loadEntry = plugin.loadEntry;
|
|
19
|
-
if ('function' != typeof loadEntry) continue;
|
|
20
|
-
const entry = await loadEntry({
|
|
21
|
-
remoteInfo: remote
|
|
22
|
-
});
|
|
23
|
-
if (entry) return entry;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
async function loadBackendFederationEntry(remote, options) {
|
|
27
|
-
const requiresVerification = Boolean(remote.verification || options.entryPolicy?.expected);
|
|
28
|
-
const isNetworkEntry = /^https?:\/\//iu.test(remote.entry);
|
|
29
|
-
if (isNetworkEntry && !requiresVerification) throw new Error(`[BFF][Effect] Backend federation remote ${remote.name} requires verified entry bytes before network execution.`);
|
|
30
|
-
if (requiresVerification) return loadVerifiedBackendFederationEntry({
|
|
31
|
-
...options.entryPolicy,
|
|
32
|
-
remote,
|
|
33
|
-
...remote.verification ? {
|
|
34
|
-
verification: remote.verification
|
|
35
|
-
} : {}
|
|
36
|
-
});
|
|
37
|
-
const pluginEntry = await resolvePluginEntry(remote, options.plugins);
|
|
38
|
-
if (pluginEntry) return pluginEntry;
|
|
39
|
-
if (remote.entryGlobalName) {
|
|
40
|
-
const globalEntry = globalThis[remote.entryGlobalName];
|
|
41
|
-
if (isRecord(globalEntry)) return globalEntry;
|
|
42
|
-
}
|
|
43
|
-
if ('module' === remote.type || remote.entry.startsWith('file:')) return importModuleEntry(remote);
|
|
44
|
-
return evaluateBackendFederationCommonJsEntry(remote, new TextEncoder().encode(await readCommonJsEntrySource(remote)), options.entryPolicy?.evaluateCommonJs);
|
|
45
|
-
}
|
|
46
|
-
async function loadBackendFederationExpose(remote, expose, options) {
|
|
47
|
-
const entry = await loadBackendFederationEntry(remote, options);
|
|
48
|
-
if ('function' == typeof entry.init) await entry.init({
|
|
49
|
-
hostName: options.hostName
|
|
50
|
-
});
|
|
51
|
-
if ('function' != typeof entry.get) throw new Error(`[BFF][Effect] Backend federation remote ${remote.name} entry must expose get().`);
|
|
52
|
-
const factory = await entry.get(expose);
|
|
53
|
-
if ('function' != typeof factory) throw new Error(`[BFF][Effect] Backend federation expose ${remote.name}/${normalizeExpose(expose)} must load factory function.`);
|
|
54
|
-
return factory();
|
|
55
|
-
}
|
|
56
|
-
export { loadBackendFederationExpose };
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const LEGACY_LOAD_WARNING = '[BFF][Effect] loadBackendFederatedEffectApi was called without an expected delivery-unit identity (expected.unitId + expected.buildMarker). Identity-less public backend loads are deprecated (ADR-0019/MV-G23) and will be rejected in a future major.';
|
|
2
|
-
export { LEGACY_LOAD_WARNING };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { collectEffectEndpoints } from "@modern-js/bff-effect/effect";
|
|
2
|
-
import { logger } from "@modern-js/utils";
|
|
3
|
-
import { createEffectClientGeneration, renderEffectClientCode, renderEffectClientDeclaration } from "./rendering.mjs";
|
|
4
|
-
import { getHttpApiRuntime, loadEffectApi } from "./runtime.mjs";
|
|
5
|
-
function generateEffectClient(options) {
|
|
6
|
-
return loadEffectApi({
|
|
7
|
-
appDir: options.appDir,
|
|
8
|
-
resourcePath: options.resourcePath,
|
|
9
|
-
onDependency: options.onDependency
|
|
10
|
-
}).then((api)=>{
|
|
11
|
-
if (null === api) {
|
|
12
|
-
logger.warn(`[BFF][Effect] Failed to generate client for ${options.resourcePath}: unable to resolve exported HttpApi.`);
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
return getHttpApiRuntime().then((httpApiRuntime)=>{
|
|
16
|
-
const endpoints = collectEffectEndpoints(httpApiRuntime.reflect, api, options.prefix);
|
|
17
|
-
const generation = createEffectClientGeneration(endpoints, options);
|
|
18
|
-
return {
|
|
19
|
-
code: renderEffectClientCode(generation),
|
|
20
|
-
declaration: renderEffectClientDeclaration(endpoints),
|
|
21
|
-
endpoints,
|
|
22
|
-
operationContracts: generation.operationContracts,
|
|
23
|
-
operationVersion: generation.operationVersion,
|
|
24
|
-
requestId: generation.requestId
|
|
25
|
-
};
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
function generateEffectClientCode(options) {
|
|
30
|
-
return generateEffectClient(options).then((artifacts)=>null === artifacts ? null : artifacts.code);
|
|
31
|
-
}
|
|
32
|
-
export { generateEffectClient, generateEffectClientCode };
|