@bleedingdev/modern-js-plugin-bff 3.2.0-ultramodern.99 → 3.4.0-ultramodern.1
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/cli.js +9 -5
- package/dist/cjs/constants.js +13 -9
- package/dist/cjs/index.js +9 -5
- package/dist/cjs/loader.js +9 -5
- package/dist/cjs/runtime/create-request/index.js +9 -5
- package/dist/cjs/runtime/data-platform/index.js +11 -18
- package/dist/cjs/runtime/effect/adapter.js +87 -14
- package/dist/cjs/runtime/effect/context.js +9 -5
- package/dist/cjs/runtime/effect/edge.js +26 -26
- package/dist/cjs/runtime/effect/endpoint-contracts.js +130 -0
- package/dist/cjs/runtime/effect/handler.js +107 -63
- package/dist/cjs/runtime/effect/index.js +28 -16
- package/dist/cjs/runtime/effect/module.js +71 -35
- package/dist/cjs/runtime/effect/operation-context.js +10 -18
- package/dist/cjs/runtime/effect-client/index.js +10 -6
- package/dist/cjs/runtime/effect-client/runtime.js +266 -0
- package/dist/cjs/runtime/hono/adapter.js +30 -14
- package/dist/cjs/runtime/hono/index.js +9 -5
- package/dist/cjs/runtime/hono/operators.js +9 -5
- package/dist/cjs/runtime/safe-failure.js +83 -0
- package/dist/cjs/server.js +9 -5
- package/dist/cjs/utils/clientGenerator.js +13 -9
- package/dist/cjs/utils/createHonoRoutes.js +9 -5
- package/dist/cjs/utils/crossProjectApiPlugin.js +9 -5
- package/dist/cjs/utils/crossProjectServerPolicy.js +104 -0
- package/dist/cjs/utils/effectClientGenerator.js +99 -488
- package/dist/cjs/utils/pluginGenerator.js +9 -5
- package/dist/cjs/utils/runtimeGenerator.js +9 -5
- package/dist/esm/runtime/data-platform/index.mjs +2 -13
- package/dist/esm/runtime/effect/adapter.mjs +78 -9
- package/dist/esm/runtime/effect/edge.mjs +2 -9
- package/dist/esm/runtime/effect/endpoint-contracts.mjs +68 -0
- package/dist/esm/runtime/effect/handler.mjs +41 -8
- package/dist/esm/runtime/effect/index.mjs +2 -0
- package/dist/esm/runtime/effect/module.mjs +63 -31
- package/dist/esm/runtime/effect/operation-context.mjs +1 -13
- package/dist/esm/runtime/effect-client/index.mjs +1 -1
- package/dist/esm/runtime/effect-client/runtime.mjs +228 -0
- package/dist/esm/runtime/hono/adapter.mjs +21 -9
- package/dist/esm/runtime/safe-failure.mjs +45 -0
- package/dist/esm/utils/clientGenerator.mjs +5 -5
- package/dist/esm/utils/crossProjectServerPolicy.mjs +50 -0
- package/dist/esm/utils/effectClientGenerator.mjs +88 -484
- package/dist/esm-node/runtime/data-platform/index.mjs +2 -13
- package/dist/esm-node/runtime/effect/adapter.mjs +78 -9
- package/dist/esm-node/runtime/effect/edge.mjs +2 -9
- package/dist/esm-node/runtime/effect/endpoint-contracts.mjs +69 -0
- package/dist/esm-node/runtime/effect/handler.mjs +41 -8
- package/dist/esm-node/runtime/effect/index.mjs +2 -0
- package/dist/esm-node/runtime/effect/module.mjs +63 -31
- package/dist/esm-node/runtime/effect/operation-context.mjs +1 -13
- package/dist/esm-node/runtime/effect-client/index.mjs +1 -1
- package/dist/esm-node/runtime/effect-client/runtime.mjs +229 -0
- package/dist/esm-node/runtime/hono/adapter.mjs +21 -9
- package/dist/esm-node/runtime/safe-failure.mjs +46 -0
- package/dist/esm-node/utils/clientGenerator.mjs +5 -5
- package/dist/esm-node/utils/crossProjectServerPolicy.mjs +52 -0
- package/dist/esm-node/utils/effectClientGenerator.mjs +88 -484
- package/dist/types/runtime/effect/adapter.d.ts +25 -0
- package/dist/types/runtime/effect/context.d.ts +1 -1
- package/dist/types/runtime/effect/endpoint-contracts.d.ts +62 -0
- package/dist/types/runtime/effect/handler.d.ts +37 -4
- package/dist/types/runtime/effect/index.d.ts +1 -0
- package/dist/types/runtime/effect/module.d.ts +22 -2
- package/dist/types/runtime/effect-client/runtime.d.ts +71 -0
- package/dist/types/runtime/hono/adapter.d.ts +3 -0
- package/dist/types/runtime/safe-failure.d.ts +1 -0
- package/dist/types/server.d.ts +1 -1
- package/dist/types/utils/createHonoRoutes.d.ts +3 -3
- package/dist/types/utils/crossProjectServerPolicy.d.ts +35 -0
- package/dist/types/utils/effectClientGenerator.d.ts +16 -2
- package/package.json +41 -28
package/dist/cjs/cli.js
CHANGED
|
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
|
|
|
10
10
|
};
|
|
11
11
|
})();
|
|
12
12
|
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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");
|
|
18
22
|
};
|
|
19
23
|
})();
|
|
20
24
|
(()=>{
|
package/dist/cjs/constants.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -23,10 +27,6 @@ var __webpack_require__ = {};
|
|
|
23
27
|
})();
|
|
24
28
|
var __webpack_exports__ = {};
|
|
25
29
|
__webpack_require__.r(__webpack_exports__);
|
|
26
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
API_APP_NAME: ()=>API_APP_NAME,
|
|
28
|
-
BUILD_FILES: ()=>BUILD_FILES
|
|
29
|
-
});
|
|
30
30
|
const API_APP_NAME = '_app';
|
|
31
31
|
const BUILD_FILES = [
|
|
32
32
|
'**/*.[tj]sx?',
|
|
@@ -37,6 +37,10 @@ const BUILD_FILES = [
|
|
|
37
37
|
'!__tests__/*.tsx?',
|
|
38
38
|
'!__tests__/*.jsx?'
|
|
39
39
|
];
|
|
40
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
41
|
+
API_APP_NAME: API_APP_NAME,
|
|
42
|
+
BUILD_FILES: BUILD_FILES
|
|
43
|
+
});
|
|
40
44
|
exports.API_APP_NAME = __webpack_exports__.API_APP_NAME;
|
|
41
45
|
exports.BUILD_FILES = __webpack_exports__.BUILD_FILES;
|
|
42
46
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
package/dist/cjs/index.js
CHANGED
|
@@ -24,11 +24,15 @@ function __webpack_require__(moduleId) {
|
|
|
24
24
|
};
|
|
25
25
|
})();
|
|
26
26
|
(()=>{
|
|
27
|
-
__webpack_require__.d = (exports1,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
28
|
+
var define = (defs, kind)=>{
|
|
29
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
[kind]: defs[key]
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
define(getters, "get");
|
|
35
|
+
define(values, "value");
|
|
32
36
|
};
|
|
33
37
|
})();
|
|
34
38
|
(()=>{
|
package/dist/cjs/loader.js
CHANGED
|
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
|
|
|
10
10
|
};
|
|
11
11
|
})();
|
|
12
12
|
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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");
|
|
18
22
|
};
|
|
19
23
|
})();
|
|
20
24
|
(()=>{
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -49,6 +53,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
49
53
|
validateRequestEnvelope: ()=>validateRequestEnvelope,
|
|
50
54
|
validateSelectionPlan: ()=>validateSelectionPlan
|
|
51
55
|
});
|
|
56
|
+
const create_request_namespaceObject = require("@modern-js/create-request");
|
|
52
57
|
const api_namespaceObject = require("@opentelemetry/api");
|
|
53
58
|
const DATA_BATCH_TRANSPORT_OTEL_EVENT = 'modernjs.data.batch';
|
|
54
59
|
function createDataBatchTransportTelemetryAttributes(event) {
|
|
@@ -74,7 +79,6 @@ function emitDataBatchTransportEvent(onEvent, event) {
|
|
|
74
79
|
const DEFAULT_DATA_ENVELOPE_HEADER = 'x-modernjs-data-envelope';
|
|
75
80
|
const DEFAULT_DATA_BATCH_ENDPOINT = '/_data/batch';
|
|
76
81
|
const DEFAULT_DATA_BATCH_HEADER = 'x-modernjs-data-batch';
|
|
77
|
-
const TRACEPARENT_REGEX = /^00-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/i;
|
|
78
82
|
function isPlainObject(value) {
|
|
79
83
|
if ('object' != typeof value || null === value || Array.isArray(value)) return false;
|
|
80
84
|
const proto = Object.getPrototypeOf(value);
|
|
@@ -171,18 +175,7 @@ function isValidHex(value, length) {
|
|
|
171
175
|
return value.length === length && /^[0-9a-f]+$/.test(value);
|
|
172
176
|
}
|
|
173
177
|
function parseTraceparentHeader(header) {
|
|
174
|
-
|
|
175
|
-
if (!match) return null;
|
|
176
|
-
const traceId = match[1].toLowerCase();
|
|
177
|
-
const spanId = match[2].toLowerCase();
|
|
178
|
-
const flags = match[3].toLowerCase();
|
|
179
|
-
if (isAllZeroHex(traceId) || isAllZeroHex(spanId)) return null;
|
|
180
|
-
const sampled = (0x1 & Number.parseInt(flags, 16)) === 1;
|
|
181
|
-
return {
|
|
182
|
-
traceId,
|
|
183
|
-
spanId,
|
|
184
|
-
sampled
|
|
185
|
-
};
|
|
178
|
+
return (0, create_request_namespaceObject.parseTraceparent)(header) ?? null;
|
|
186
179
|
}
|
|
187
180
|
function formatTraceparentHeader(trace) {
|
|
188
181
|
const traceId = trace.traceId.toLowerCase();
|
|
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
|
|
|
10
10
|
};
|
|
11
11
|
})();
|
|
12
12
|
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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");
|
|
18
22
|
};
|
|
19
23
|
})();
|
|
20
24
|
(()=>{
|
|
@@ -35,10 +39,15 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
35
39
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
40
|
EffectAdapter: ()=>EffectAdapter
|
|
37
41
|
});
|
|
42
|
+
const bff_core_namespaceObject = require("@modern-js/bff-core");
|
|
38
43
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
44
|
+
const httpapi_namespaceObject = require("effect/unstable/httpapi");
|
|
39
45
|
const external_path_namespaceObject = require("path");
|
|
40
46
|
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
47
|
+
const crossProjectServerPolicy_js_namespaceObject = require("../../utils/crossProjectServerPolicy.js");
|
|
48
|
+
const external_safe_failure_js_namespaceObject = require("../safe-failure.js");
|
|
41
49
|
const external_context_js_namespaceObject = require("./context.js");
|
|
50
|
+
const external_endpoint_contracts_js_namespaceObject = require("./endpoint-contracts.js");
|
|
42
51
|
const external_module_js_namespaceObject = require("./module.js");
|
|
43
52
|
const before = [
|
|
44
53
|
'custom-server-hook',
|
|
@@ -84,10 +93,73 @@ class EffectAdapter {
|
|
|
84
93
|
const entryWithoutExt = configuredEntry ? external_path_default().isAbsolute(configuredEntry) ? configuredEntry : external_path_default().resolve(appDirectory || process.cwd(), configuredEntry) : defaultEntry;
|
|
85
94
|
return (0, utils_namespaceObject.findExists)(JS_OR_TS_EXTS.map((ext)=>`${entryWithoutExt}${ext}`));
|
|
86
95
|
}
|
|
96
|
+
isApiRequestPath(requestPath, prefix, enableHandleWeb) {
|
|
97
|
+
if (!enableHandleWeb) return true;
|
|
98
|
+
const normalized = normalizePrefix(prefix);
|
|
99
|
+
if (!normalized) return true;
|
|
100
|
+
return requestPath === normalized || requestPath.startsWith(`${normalized}/`);
|
|
101
|
+
}
|
|
102
|
+
async collectLambdaContractSources() {
|
|
103
|
+
try {
|
|
104
|
+
const serverContext = this.api.getServerContext();
|
|
105
|
+
const appDir = serverContext.distDirectory || serverContext.appDirectory;
|
|
106
|
+
if (!appDir) return [];
|
|
107
|
+
const apiDir = 'string' == typeof serverContext.apiDirectory ? serverContext.apiDirectory : external_path_default().resolve(appDir, utils_namespaceObject.API_DIR);
|
|
108
|
+
const lambdaDir = 'string' == typeof serverContext.lambdaDirectory ? serverContext.lambdaDirectory : external_path_default().join(apiDir, 'lambda');
|
|
109
|
+
if (!await utils_namespaceObject.fs.pathExists(lambdaDir)) return [];
|
|
110
|
+
const apiRouter = new bff_core_namespaceObject.ApiRouter({
|
|
111
|
+
appDir,
|
|
112
|
+
apiDir,
|
|
113
|
+
lambdaDir,
|
|
114
|
+
prefix: this.prefix,
|
|
115
|
+
httpMethodDecider: this.api.getServerConfig()?.bff?.httpMethodDecider
|
|
116
|
+
});
|
|
117
|
+
const handlerInfos = await apiRouter.getApiHandlers();
|
|
118
|
+
return handlerInfos.map((info)=>({
|
|
119
|
+
name: info.name,
|
|
120
|
+
httpMethod: info.httpMethod,
|
|
121
|
+
routePath: info.routePath,
|
|
122
|
+
filename: info.filename,
|
|
123
|
+
handler: info.handler
|
|
124
|
+
}));
|
|
125
|
+
} catch (error) {
|
|
126
|
+
utils_namespaceObject.logger.warn(`[BFF][Effect] Failed to derive lambda operation contracts for the cross-project policy: ${String(error)}`);
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async refreshCrossProjectPolicy(mod) {
|
|
131
|
+
let contractSources = [];
|
|
132
|
+
if (mod) try {
|
|
133
|
+
const api = await (0, external_endpoint_contracts_js_namespaceObject.extractHttpApiFromModule)(mod, httpapi_namespaceObject.HttpApi.isHttpApi);
|
|
134
|
+
if (api) {
|
|
135
|
+
const reflect = (apiValue, handlers)=>httpapi_namespaceObject.HttpApi.reflect(apiValue, {
|
|
136
|
+
onGroup: handlers.onGroup ?? (()=>{}),
|
|
137
|
+
onEndpoint: handlers.onEndpoint
|
|
138
|
+
});
|
|
139
|
+
contractSources = (0, external_endpoint_contracts_js_namespaceObject.toOperationContractSources)((0, external_endpoint_contracts_js_namespaceObject.collectEffectEndpoints)(reflect, api, this.prefix));
|
|
140
|
+
}
|
|
141
|
+
} catch (error) {
|
|
142
|
+
utils_namespaceObject.logger.warn(`[BFF][Effect] Failed to reflect HttpApi endpoints for the cross-project policy: ${String(error)}`);
|
|
143
|
+
}
|
|
144
|
+
let policy = (0, crossProjectServerPolicy_js_namespaceObject.resolveAdapterCrossProjectPolicy)(this.api, contractSources);
|
|
145
|
+
if (policy?.enabled) {
|
|
146
|
+
const lambdaSources = await this.collectLambdaContractSources();
|
|
147
|
+
if (lambdaSources.length > 0) {
|
|
148
|
+
contractSources = [
|
|
149
|
+
...contractSources,
|
|
150
|
+
...lambdaSources
|
|
151
|
+
];
|
|
152
|
+
policy = (0, crossProjectServerPolicy_js_namespaceObject.resolveAdapterCrossProjectPolicy)(this.api, contractSources);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
this.crossProjectPolicy = policy;
|
|
156
|
+
if (this.crossProjectPolicy?.enabled && 0 === contractSources.length) utils_namespaceObject.logger.warn('[BFF][Effect] Cross-project policy is enabled but no HttpApi endpoints could be reflected; operation-contract matching is disabled for this server (envelope and operation-context checks still apply).');
|
|
157
|
+
}
|
|
87
158
|
async loadEffectHandlerFromModule(mod) {
|
|
88
159
|
return (0, external_module_js_namespaceObject.resolveEffectBffModuleHandler)(mod, {
|
|
89
160
|
openapi: this.api.getServerConfig()?.bff?.effect?.openapi,
|
|
90
161
|
dataPlatform: this.api.getServerConfig()?.bff?.effect?.dataPlatform,
|
|
162
|
+
validateRequest: (request)=>(0, crossProjectServerPolicy_js_namespaceObject.checkCrossProjectPolicyForRequest)(request, this.crossProjectPolicy),
|
|
91
163
|
onWarning: (message)=>{
|
|
92
164
|
utils_namespaceObject.logger.warn(message);
|
|
93
165
|
}
|
|
@@ -117,6 +189,7 @@ class EffectAdapter {
|
|
|
117
189
|
this.handler = null;
|
|
118
190
|
return;
|
|
119
191
|
}
|
|
192
|
+
await this.refreshCrossProjectPolicy(mod);
|
|
120
193
|
const loaded = await this.loadEffectHandlerFromModule(mod);
|
|
121
194
|
if (!loaded) {
|
|
122
195
|
utils_namespaceObject.logger.warn(`[BFF][Effect] Invalid Effect entry module: ${entryFile}. Export { api, layer } or handler.`);
|
|
@@ -125,6 +198,7 @@ class EffectAdapter {
|
|
|
125
198
|
}
|
|
126
199
|
this.handler = loaded.handler;
|
|
127
200
|
this.dispose = loaded.dispose || null;
|
|
201
|
+
this.policyEnforcedInMiddleware = !loaded.appliesRequestValidator;
|
|
128
202
|
}
|
|
129
203
|
async disposeCurrentHandler() {
|
|
130
204
|
if (!this.dispose) return;
|
|
@@ -148,15 +222,7 @@ class EffectAdapter {
|
|
|
148
222
|
} catch (configError) {
|
|
149
223
|
utils_namespaceObject.logger.error(`Error in serverConfig.onError handler: ${configError}`);
|
|
150
224
|
}
|
|
151
|
-
|
|
152
|
-
return new Response(JSON.stringify({
|
|
153
|
-
message: error instanceof Error ? error.message : '[BFF] Internal Server Error'
|
|
154
|
-
}), {
|
|
155
|
-
status,
|
|
156
|
-
headers: {
|
|
157
|
-
'content-type': 'application/json; charset=utf-8'
|
|
158
|
-
}
|
|
159
|
-
});
|
|
225
|
+
return (0, external_safe_failure_js_namespaceObject.createSafeFailureResponse)(error);
|
|
160
226
|
}
|
|
161
227
|
ensureJsonContext(c) {
|
|
162
228
|
const maybeJsonContext = c;
|
|
@@ -183,6 +249,8 @@ class EffectAdapter {
|
|
|
183
249
|
this.effectMiddleware = null;
|
|
184
250
|
this.handler = null;
|
|
185
251
|
this.dispose = null;
|
|
252
|
+
this.prefix = '/api';
|
|
253
|
+
this.policyEnforcedInMiddleware = false;
|
|
186
254
|
this.registerMiddleware = async (options)=>{
|
|
187
255
|
const { prefix, enableHandleWeb } = options;
|
|
188
256
|
const { bffRuntimeFramework, middlewares: globalMiddlewares } = this.api.getServerContext();
|
|
@@ -190,6 +258,7 @@ class EffectAdapter {
|
|
|
190
258
|
this.isEffect = false;
|
|
191
259
|
return;
|
|
192
260
|
}
|
|
261
|
+
this.prefix = prefix || this.prefix;
|
|
193
262
|
await this.reloadHandler();
|
|
194
263
|
this.effectMiddleware = {
|
|
195
264
|
name: 'effect-bff-handler',
|
|
@@ -202,6 +271,10 @@ class EffectAdapter {
|
|
|
202
271
|
if (enableHandleWeb) return void await next();
|
|
203
272
|
return this.handleRuntimeError(new Error('[BFF][Effect] Missing Effect entry. Define api/effect/index or configure bff.effect.entry.'), c);
|
|
204
273
|
}
|
|
274
|
+
if (this.crossProjectPolicy?.enabled && this.policyEnforcedInMiddleware && this.isApiRequestPath(c.req.path, prefix, enableHandleWeb)) {
|
|
275
|
+
const denial = (0, crossProjectServerPolicy_js_namespaceObject.checkCrossProjectPolicyForRequest)(c.req.raw, this.crossProjectPolicy);
|
|
276
|
+
if (denial) return denial;
|
|
277
|
+
}
|
|
205
278
|
let response;
|
|
206
279
|
try {
|
|
207
280
|
const effectRequest = createRequestForMountedPrefix(c.req.raw, prefix);
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_modules__ = {
|
|
3
|
+
"../safe-failure" (module) {
|
|
4
|
+
module.exports = require("../safe-failure.js");
|
|
5
|
+
},
|
|
3
6
|
"./handler" (module) {
|
|
4
7
|
module.exports = require("./handler.js");
|
|
5
8
|
},
|
|
@@ -30,11 +33,15 @@ function __webpack_require__(moduleId) {
|
|
|
30
33
|
};
|
|
31
34
|
})();
|
|
32
35
|
(()=>{
|
|
33
|
-
__webpack_require__.d = (exports1,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
37
|
+
var define = (defs, kind)=>{
|
|
38
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
[kind]: defs[key]
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
define(getters, "get");
|
|
44
|
+
define(values, "value");
|
|
38
45
|
};
|
|
39
46
|
})();
|
|
40
47
|
(()=>{
|
|
@@ -53,21 +60,17 @@ function __webpack_require__(moduleId) {
|
|
|
53
60
|
var __webpack_exports__ = {};
|
|
54
61
|
(()=>{
|
|
55
62
|
__webpack_require__.r(__webpack_exports__);
|
|
56
|
-
__webpack_require__
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
});
|
|
61
|
-
var _module__rspack_import_0 = __webpack_require__("./module");
|
|
62
|
-
var _operation_context__rspack_import_1 = __webpack_require__("./operation-context");
|
|
63
|
-
var _handler__rspack_import_2 = __webpack_require__("./handler");
|
|
63
|
+
var _safe_failure__rspack_import_0 = __webpack_require__("../safe-failure");
|
|
64
|
+
var _module__rspack_import_1 = __webpack_require__("./module");
|
|
65
|
+
var _operation_context__rspack_import_2 = __webpack_require__("./operation-context");
|
|
66
|
+
var _handler__rspack_import_3 = __webpack_require__("./handler");
|
|
64
67
|
var __rspack_reexport = {};
|
|
65
|
-
for(const __rspack_import_key in
|
|
68
|
+
for(const __rspack_import_key in _handler__rspack_import_3)if ([
|
|
66
69
|
"default",
|
|
67
70
|
"dispatchEffectBffRequest",
|
|
68
71
|
"createEffectOperationContext",
|
|
69
72
|
"createEffectBffEdgeHandler"
|
|
70
|
-
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>
|
|
73
|
+
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_handler__rspack_import_3[__rspack_import_key];
|
|
71
74
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
72
75
|
function normalizePrefix(prefix) {
|
|
73
76
|
if (!prefix || '/' === prefix) return '';
|
|
@@ -98,7 +101,7 @@ var __webpack_exports__ = {};
|
|
|
98
101
|
env: options.env || {},
|
|
99
102
|
path: originalPath,
|
|
100
103
|
method,
|
|
101
|
-
operationContext: (0,
|
|
104
|
+
operationContext: (0, _operation_context__rspack_import_2.createEffectOperationContext)({
|
|
102
105
|
request: effectRequest,
|
|
103
106
|
env: options.env || {},
|
|
104
107
|
path: originalPath,
|
|
@@ -107,15 +110,7 @@ var __webpack_exports__ = {};
|
|
|
107
110
|
};
|
|
108
111
|
}
|
|
109
112
|
function createRuntimeErrorResponse(error) {
|
|
110
|
-
|
|
111
|
-
return new Response(JSON.stringify({
|
|
112
|
-
message: error instanceof Error ? error.message : '[BFF] Internal Server Error'
|
|
113
|
-
}), {
|
|
114
|
-
status,
|
|
115
|
-
headers: {
|
|
116
|
-
'content-type': 'application/json; charset=utf-8'
|
|
117
|
-
}
|
|
118
|
-
});
|
|
113
|
+
return (0, _safe_failure__rspack_import_0.createSafeFailureResponse)(error);
|
|
119
114
|
}
|
|
120
115
|
async function dispatchEffectBffRequest(handler, request, options = {}) {
|
|
121
116
|
const requestPathname = new URL(request.url).pathname;
|
|
@@ -138,7 +133,7 @@ var __webpack_exports__ = {};
|
|
|
138
133
|
}
|
|
139
134
|
}
|
|
140
135
|
async function createEffectBffEdgeHandler(options) {
|
|
141
|
-
const loaded = await (0,
|
|
136
|
+
const loaded = await (0, _module__rspack_import_1.resolveEffectBffModuleHandler)(options.module, {
|
|
142
137
|
openapi: options.openapi,
|
|
143
138
|
dataPlatform: options.dataPlatform,
|
|
144
139
|
onWarning: options.onWarning
|
|
@@ -155,6 +150,11 @@ var __webpack_exports__ = {};
|
|
|
155
150
|
}
|
|
156
151
|
};
|
|
157
152
|
}
|
|
153
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
154
|
+
createEffectBffEdgeHandler: ()=>createEffectBffEdgeHandler,
|
|
155
|
+
createEffectOperationContext: ()=>_operation_context__rspack_import_2.createEffectOperationContext,
|
|
156
|
+
dispatchEffectBffRequest: ()=>dispatchEffectBffRequest
|
|
157
|
+
});
|
|
158
158
|
})();
|
|
159
159
|
exports.createEffectBffEdgeHandler = __webpack_exports__.createEffectBffEdgeHandler;
|
|
160
160
|
exports.createEffectOperationContext = __webpack_exports__.createEffectOperationContext;
|
|
@@ -0,0 +1,130 @@
|
|
|
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
|
+
collectEffectEndpoints: ()=>collectEffectEndpoints,
|
|
32
|
+
createEffectEndpointContractHash: ()=>createEffectEndpointContractHash,
|
|
33
|
+
createEffectOperationContractSource: ()=>createEffectOperationContractSource,
|
|
34
|
+
ensureLeadingSlash: ()=>ensureLeadingSlash,
|
|
35
|
+
extractHttpApiFromModule: ()=>extractHttpApiFromModule,
|
|
36
|
+
getEffectRoutePath: ()=>getEffectRoutePath,
|
|
37
|
+
normalizeEffectPrefix: ()=>normalizeEffectPrefix,
|
|
38
|
+
resolveEffectApiId: ()=>resolveEffectApiId,
|
|
39
|
+
toOperationContractSources: ()=>toOperationContractSources
|
|
40
|
+
});
|
|
41
|
+
const bff_core_namespaceObject = require("@modern-js/bff-core");
|
|
42
|
+
function ensureLeadingSlash(pathname) {
|
|
43
|
+
return pathname.startsWith('/') ? pathname : `/${pathname}`;
|
|
44
|
+
}
|
|
45
|
+
function normalizeEffectPrefix(prefix) {
|
|
46
|
+
if ('/' === prefix) return '';
|
|
47
|
+
return ensureLeadingSlash(prefix || '/api');
|
|
48
|
+
}
|
|
49
|
+
function getEffectRoutePath(prefix, endpointPath) {
|
|
50
|
+
const normalizedPrefix = normalizeEffectPrefix(prefix);
|
|
51
|
+
const normalizedEndpointPath = ensureLeadingSlash(endpointPath);
|
|
52
|
+
const finalEndpointPath = '/' === normalizedEndpointPath ? '' : endpointPath;
|
|
53
|
+
if (!normalizedPrefix && !finalEndpointPath) return '/';
|
|
54
|
+
return `${normalizedPrefix}${finalEndpointPath || ''}`;
|
|
55
|
+
}
|
|
56
|
+
function resolveEffectApiId(api) {
|
|
57
|
+
const fallback = 'EffectHttpApi';
|
|
58
|
+
if ('identifier' in api && 'string' == typeof api.identifier && api.identifier) return api.identifier;
|
|
59
|
+
return fallback;
|
|
60
|
+
}
|
|
61
|
+
function collectEffectEndpoints(reflect, api, prefix) {
|
|
62
|
+
const endpoints = [];
|
|
63
|
+
const apiId = resolveEffectApiId(api);
|
|
64
|
+
reflect(api, {
|
|
65
|
+
onGroup: ()=>{},
|
|
66
|
+
onEndpoint: ({ group, endpoint })=>{
|
|
67
|
+
endpoints.push({
|
|
68
|
+
apiId,
|
|
69
|
+
groupName: String(group.identifier),
|
|
70
|
+
endpointName: String(endpoint.name),
|
|
71
|
+
method: String(endpoint.method).toUpperCase(),
|
|
72
|
+
routePath: getEffectRoutePath(prefix, String(endpoint.path))
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return endpoints.sort((a, b)=>{
|
|
77
|
+
if (a.groupName === b.groupName) return a.endpointName.localeCompare(b.endpointName);
|
|
78
|
+
return a.groupName.localeCompare(b.groupName);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function toOperationContractSources(endpoints) {
|
|
82
|
+
return endpoints.map(createEffectOperationContractSource);
|
|
83
|
+
}
|
|
84
|
+
function createEffectOperationContractSource(endpoint) {
|
|
85
|
+
return {
|
|
86
|
+
name: endpoint.endpointName,
|
|
87
|
+
httpMethod: endpoint.method,
|
|
88
|
+
routePath: endpoint.routePath
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function isRecord(value) {
|
|
92
|
+
return 'object' == typeof value && null !== value;
|
|
93
|
+
}
|
|
94
|
+
async function extractHttpApiFromModule(mod, isHttpApi) {
|
|
95
|
+
if (!isRecord(mod)) return null;
|
|
96
|
+
if (isHttpApi(mod.api)) return mod.api;
|
|
97
|
+
const entry = mod.default;
|
|
98
|
+
if (isRecord(entry) && isHttpApi(entry.api)) return entry.api;
|
|
99
|
+
if ('function' == typeof entry && 0 === entry.length) {
|
|
100
|
+
const output = await entry();
|
|
101
|
+
if (isRecord(output) && isHttpApi(output.api)) return output.api;
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
function createEffectEndpointContractHash(endpoint, requestId) {
|
|
106
|
+
return (0, bff_core_namespaceObject.createOperationContractHash)(createEffectOperationContractSource(endpoint), requestId);
|
|
107
|
+
}
|
|
108
|
+
exports.collectEffectEndpoints = __webpack_exports__.collectEffectEndpoints;
|
|
109
|
+
exports.createEffectEndpointContractHash = __webpack_exports__.createEffectEndpointContractHash;
|
|
110
|
+
exports.createEffectOperationContractSource = __webpack_exports__.createEffectOperationContractSource;
|
|
111
|
+
exports.ensureLeadingSlash = __webpack_exports__.ensureLeadingSlash;
|
|
112
|
+
exports.extractHttpApiFromModule = __webpack_exports__.extractHttpApiFromModule;
|
|
113
|
+
exports.getEffectRoutePath = __webpack_exports__.getEffectRoutePath;
|
|
114
|
+
exports.normalizeEffectPrefix = __webpack_exports__.normalizeEffectPrefix;
|
|
115
|
+
exports.resolveEffectApiId = __webpack_exports__.resolveEffectApiId;
|
|
116
|
+
exports.toOperationContractSources = __webpack_exports__.toOperationContractSources;
|
|
117
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
118
|
+
"collectEffectEndpoints",
|
|
119
|
+
"createEffectEndpointContractHash",
|
|
120
|
+
"createEffectOperationContractSource",
|
|
121
|
+
"ensureLeadingSlash",
|
|
122
|
+
"extractHttpApiFromModule",
|
|
123
|
+
"getEffectRoutePath",
|
|
124
|
+
"normalizeEffectPrefix",
|
|
125
|
+
"resolveEffectApiId",
|
|
126
|
+
"toOperationContractSources"
|
|
127
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
128
|
+
Object.defineProperty(exports, '__esModule', {
|
|
129
|
+
value: true
|
|
130
|
+
});
|