@bleedingdev/modern-js-plugin-bff 3.2.0-ultramodern.120 → 3.2.0-ultramodern.121
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/runtime/data-platform/index.js +2 -13
- package/dist/cjs/runtime/effect/adapter.js +78 -9
- package/dist/cjs/runtime/effect/edge.js +13 -17
- package/dist/cjs/runtime/effect/endpoint-contracts.js +130 -0
- package/dist/cjs/runtime/effect/handler.js +50 -5
- package/dist/cjs/runtime/effect/module.js +16 -7
- package/dist/cjs/runtime/effect/operation-context.js +1 -13
- package/dist/cjs/runtime/effect-client/runtime.js +266 -0
- package/dist/cjs/runtime/hono/adapter.js +21 -9
- package/dist/cjs/runtime/safe-failure.js +83 -0
- package/dist/cjs/utils/clientGenerator.js +4 -4
- package/dist/cjs/utils/crossProjectServerPolicy.js +104 -0
- package/dist/cjs/utils/effectClientGenerator.js +90 -483
- 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 +36 -4
- package/dist/esm/runtime/effect/module.mjs +17 -8
- package/dist/esm/runtime/effect/operation-context.mjs +1 -13
- 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 +36 -4
- package/dist/esm-node/runtime/effect/module.mjs +17 -8
- package/dist/esm-node/runtime/effect/operation-context.mjs +1 -13
- 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/endpoint-contracts.d.ts +62 -0
- package/dist/types/runtime/effect/handler.d.ts +30 -0
- package/dist/types/runtime/effect/module.d.ts +21 -1
- 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/utils/crossProjectServerPolicy.d.ts +35 -0
- package/dist/types/utils/effectClientGenerator.d.ts +15 -1
- package/package.json +24 -12
|
@@ -0,0 +1,266 @@
|
|
|
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
|
+
createGeneratedEffectClient: ()=>createGeneratedEffectClient
|
|
32
|
+
});
|
|
33
|
+
const index_js_namespaceObject = require("../data-platform/index.js");
|
|
34
|
+
const METHODS_WITHOUT_BODY = new Set([
|
|
35
|
+
'GET',
|
|
36
|
+
'DELETE',
|
|
37
|
+
'HEAD',
|
|
38
|
+
'OPTIONS'
|
|
39
|
+
]);
|
|
40
|
+
const DATA_REQUEST_MODES = new Set([
|
|
41
|
+
'cache-first',
|
|
42
|
+
'stale-while-revalidate',
|
|
43
|
+
'network-only'
|
|
44
|
+
]);
|
|
45
|
+
const DATA_MUTATION_MODES = new Set([
|
|
46
|
+
'optimistic',
|
|
47
|
+
'pessimistic',
|
|
48
|
+
'fire-and-forget'
|
|
49
|
+
]);
|
|
50
|
+
const isRecord = (value)=>'object' == typeof value && null !== value;
|
|
51
|
+
const stringOrUndefined = (value)=>'string' == typeof value && value.length > 0 ? value : void 0;
|
|
52
|
+
const isDataRequestMode = (value)=>'string' == typeof value && DATA_REQUEST_MODES.has(value);
|
|
53
|
+
const isDataMutationMode = (value)=>'string' == typeof value && DATA_MUTATION_MODES.has(value);
|
|
54
|
+
const normalizeOrigin = (value)=>{
|
|
55
|
+
if ('string' != typeof value || 0 === value.length) return;
|
|
56
|
+
try {
|
|
57
|
+
return new URL(value).origin;
|
|
58
|
+
} catch {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const resolveRuntimeFetch = ()=>'function' == typeof fetch ? fetch.bind(globalThis) : void 0;
|
|
63
|
+
const resolveOrigin = (defaultOrigin)=>{
|
|
64
|
+
if ("u" > typeof window && window.location && 'string' == typeof window.location.origin && window.location.origin) return window.location.origin;
|
|
65
|
+
const globalLocation = globalThis?.location;
|
|
66
|
+
if (globalLocation && 'string' == typeof globalLocation.origin && globalLocation.origin) return globalLocation.origin;
|
|
67
|
+
return defaultOrigin;
|
|
68
|
+
};
|
|
69
|
+
const normalizeRequest = (method, request)=>{
|
|
70
|
+
if (!isRecord(request)) return {};
|
|
71
|
+
const payload = {
|
|
72
|
+
...request
|
|
73
|
+
};
|
|
74
|
+
if (isRecord(request.path) && !isRecord(payload.params)) payload.params = request.path;
|
|
75
|
+
if (isRecord(request.urlParams) && !isRecord(payload.query)) payload.query = request.urlParams;
|
|
76
|
+
if (isRecord(request.headers) && !isRecord(payload.headers)) payload.headers = request.headers;
|
|
77
|
+
if ('payload' in request && void 0 !== request.payload) if ("u" > typeof FormData && request.payload instanceof FormData && !('formData' in payload)) payload.formData = request.payload;
|
|
78
|
+
else if (METHODS_WITHOUT_BODY.has(method)) {
|
|
79
|
+
if (isRecord(request.payload)) payload.query = isRecord(payload.query) ? {
|
|
80
|
+
...payload.query,
|
|
81
|
+
...request.payload
|
|
82
|
+
} : request.payload;
|
|
83
|
+
else if (!('body' in payload)) payload.body = request.payload;
|
|
84
|
+
} else if (!isRecord(request.payload) || 'data' in payload) {
|
|
85
|
+
if (!('body' in payload)) payload.body = request.payload;
|
|
86
|
+
} else payload.data = request.payload;
|
|
87
|
+
return payload;
|
|
88
|
+
};
|
|
89
|
+
const resolveTargetOrigin = (dataPlatform, defaultOrigin)=>{
|
|
90
|
+
const explicitTargetOrigin = stringOrUndefined(dataPlatform.targetOrigin) || stringOrUndefined(dataPlatform.endpointOrigin);
|
|
91
|
+
if (explicitTargetOrigin) return explicitTargetOrigin;
|
|
92
|
+
return defaultOrigin;
|
|
93
|
+
};
|
|
94
|
+
const shouldAttachEnvelopeHeader = (dataPlatform, defaultOrigin)=>{
|
|
95
|
+
if (true === dataPlatform.allowCrossOriginEnvelope) return true;
|
|
96
|
+
const currentOrigin = normalizeOrigin(resolveOrigin(defaultOrigin));
|
|
97
|
+
const targetOrigin = normalizeOrigin(resolveTargetOrigin(dataPlatform, defaultOrigin));
|
|
98
|
+
if (!currentOrigin || !targetOrigin) return true;
|
|
99
|
+
return currentOrigin === targetOrigin;
|
|
100
|
+
};
|
|
101
|
+
const toEnvelopeInput = (normalizedRequest)=>{
|
|
102
|
+
const payload = {};
|
|
103
|
+
if (isRecord(normalizedRequest.params)) payload.path = normalizedRequest.params;
|
|
104
|
+
if (isRecord(normalizedRequest.query)) payload.query = normalizedRequest.query;
|
|
105
|
+
if ('data' in normalizedRequest && void 0 !== normalizedRequest.data) payload.data = normalizedRequest.data;
|
|
106
|
+
if ('body' in normalizedRequest && void 0 !== normalizedRequest.body) payload.body = normalizedRequest.body;
|
|
107
|
+
if ("u" > typeof FormData && normalizedRequest.formData instanceof FormData) payload.formData = Array.from(normalizedRequest.formData.entries()).map(([key, value])=>[
|
|
108
|
+
key,
|
|
109
|
+
String(value)
|
|
110
|
+
]);
|
|
111
|
+
if ("u" > typeof URLSearchParams && normalizedRequest.formUrlencoded instanceof URLSearchParams) payload.formUrlencoded = normalizedRequest.formUrlencoded.toString();
|
|
112
|
+
return payload;
|
|
113
|
+
};
|
|
114
|
+
const createGeneratedEffectClient = (manifest, config, requestRuntime)=>{
|
|
115
|
+
const createRequest = requestRuntime.createRequest;
|
|
116
|
+
const configureRequest = 'function' == typeof requestRuntime.configure ? requestRuntime.configure : void 0;
|
|
117
|
+
const createRequestContextHeaders = 'function' == typeof requestRuntime.createRequestContextHeaders ? requestRuntime.createRequestContextHeaders : void 0;
|
|
118
|
+
const defaultOrigin = config.defaultOrigin;
|
|
119
|
+
const httpMethodDecider = config.httpMethodDecider || 'functionName';
|
|
120
|
+
const port = config.useEnvPort && "u" > typeof process && process.env && process.env.PORT ? process.env.PORT : config.port;
|
|
121
|
+
if (config.requestId && configureRequest) {
|
|
122
|
+
const configurePayload = {
|
|
123
|
+
requestId: config.requestId,
|
|
124
|
+
requireEnvelope: true,
|
|
125
|
+
identityBinding: {
|
|
126
|
+
enabled: true,
|
|
127
|
+
strict: true
|
|
128
|
+
},
|
|
129
|
+
operationContract: {
|
|
130
|
+
enabled: true,
|
|
131
|
+
strict: true,
|
|
132
|
+
requireSchemaHash: true,
|
|
133
|
+
requireOperationVersion: true
|
|
134
|
+
},
|
|
135
|
+
setDomain: ()=>resolveOrigin(defaultOrigin)
|
|
136
|
+
};
|
|
137
|
+
const runtimeFetch = resolveRuntimeFetch();
|
|
138
|
+
if (false !== config.batch.enabled && runtimeFetch) configurePayload.request = (0, index_js_namespaceObject.createDataBatchTransport)({
|
|
139
|
+
fetch: runtimeFetch,
|
|
140
|
+
endpoint: config.batch.endpoint,
|
|
141
|
+
flushIntervalMs: config.batch.flushIntervalMs,
|
|
142
|
+
maxBatchSize: config.batch.maxBatchSize,
|
|
143
|
+
maxBatchBytes: config.batch.maxBatchBytes,
|
|
144
|
+
requestTimeoutMs: config.batch.requestTimeoutMs,
|
|
145
|
+
allowedMethods: config.batch.allowedMethods
|
|
146
|
+
});
|
|
147
|
+
configureRequest(configurePayload);
|
|
148
|
+
}
|
|
149
|
+
const createEffectRequestContext = (requestContext)=>{
|
|
150
|
+
if (!isRecord(requestContext)) return {};
|
|
151
|
+
const headers = createRequestContextHeaders ? createRequestContextHeaders(requestContext) : {};
|
|
152
|
+
return {
|
|
153
|
+
...requestContext,
|
|
154
|
+
headers
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
const applyRequestContext = (normalizedRequest, request)=>{
|
|
158
|
+
if (!isRecord(request) || !isRecord(request.requestContext)) return normalizedRequest;
|
|
159
|
+
const requestContext = createEffectRequestContext(request.requestContext);
|
|
160
|
+
const requestHeaders = isRecord(requestContext.headers) ? requestContext.headers : {};
|
|
161
|
+
if (0 === Object.keys(requestHeaders).length) return normalizedRequest;
|
|
162
|
+
return {
|
|
163
|
+
...normalizedRequest,
|
|
164
|
+
headers: {
|
|
165
|
+
...requestHeaders,
|
|
166
|
+
...isRecord(normalizedRequest.headers) ? normalizedRequest.headers : {}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
const prepareEffectRequest = (endpoint, operation, request)=>{
|
|
171
|
+
const normalizedRequest = applyRequestContext(normalizeRequest(endpoint.method, request), request);
|
|
172
|
+
const dataPlatform = isRecord(request) && isRecord(request.dataPlatform) ? request.dataPlatform : {};
|
|
173
|
+
const strictEnvelope = true === dataPlatform.requireEnvelope || true === dataPlatform.strict;
|
|
174
|
+
if (!strictEnvelope && !shouldAttachEnvelopeHeader(dataPlatform, defaultOrigin)) return normalizedRequest;
|
|
175
|
+
try {
|
|
176
|
+
const namespace = stringOrUndefined(dataPlatform.appNamespace) || config.appNamespace;
|
|
177
|
+
const origin = stringOrUndefined(dataPlatform.origin) || resolveOrigin(defaultOrigin);
|
|
178
|
+
const envelope = (0, index_js_namespaceObject.createRequestEnvelope)({
|
|
179
|
+
operation: {
|
|
180
|
+
...operation,
|
|
181
|
+
appNamespace: namespace
|
|
182
|
+
},
|
|
183
|
+
scope: {
|
|
184
|
+
appNamespace: namespace,
|
|
185
|
+
origin,
|
|
186
|
+
tenantId: stringOrUndefined(dataPlatform.tenantId),
|
|
187
|
+
userId: stringOrUndefined(dataPlatform.userId),
|
|
188
|
+
sessionId: stringOrUndefined(dataPlatform.sessionId)
|
|
189
|
+
},
|
|
190
|
+
requestInput: {
|
|
191
|
+
method: endpoint.method,
|
|
192
|
+
routePath: endpoint.routePath,
|
|
193
|
+
payload: toEnvelopeInput(normalizedRequest)
|
|
194
|
+
},
|
|
195
|
+
requestMode: isDataRequestMode(dataPlatform.requestMode) ? dataPlatform.requestMode : void 0,
|
|
196
|
+
mutationMode: isDataMutationMode(dataPlatform.mutationMode) ? dataPlatform.mutationMode : void 0,
|
|
197
|
+
selectionPlan: isRecord(dataPlatform.selectionPlan) ? dataPlatform.selectionPlan : void 0,
|
|
198
|
+
traceContext: isRecord(dataPlatform.traceContext) ? dataPlatform.traceContext : void 0,
|
|
199
|
+
requireTraceContext: true === dataPlatform.requireTraceContext
|
|
200
|
+
});
|
|
201
|
+
const headerName = stringOrUndefined(dataPlatform.envelopeHeader) || index_js_namespaceObject.DEFAULT_DATA_ENVELOPE_HEADER;
|
|
202
|
+
const headers = isRecord(normalizedRequest.headers) ? {
|
|
203
|
+
...normalizedRequest.headers
|
|
204
|
+
} : {};
|
|
205
|
+
if (false === dataPlatform.batch) headers[index_js_namespaceObject.DEFAULT_DATA_BATCH_HEADER] = 'off';
|
|
206
|
+
headers[headerName] = (0, index_js_namespaceObject.encodeRequestEnvelopeHeader)(envelope);
|
|
207
|
+
return {
|
|
208
|
+
...normalizedRequest,
|
|
209
|
+
headers
|
|
210
|
+
};
|
|
211
|
+
} catch (error) {
|
|
212
|
+
if (strictEnvelope) throw error;
|
|
213
|
+
return normalizedRequest;
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
const client = {};
|
|
217
|
+
const operationManifest = {};
|
|
218
|
+
for (const endpoint of manifest.endpoints){
|
|
219
|
+
const operationId = `${endpoint.method}:${endpoint.routePath}`;
|
|
220
|
+
const operation = {
|
|
221
|
+
appNamespace: config.appNamespace,
|
|
222
|
+
apiId: endpoint.apiId,
|
|
223
|
+
group: endpoint.group,
|
|
224
|
+
endpoint: endpoint.endpoint,
|
|
225
|
+
operationId,
|
|
226
|
+
routePath: endpoint.routePath,
|
|
227
|
+
method: endpoint.method,
|
|
228
|
+
operationVersion: endpoint.operationVersion,
|
|
229
|
+
schemaHash: endpoint.schemaHash,
|
|
230
|
+
version: endpoint.operationVersion
|
|
231
|
+
};
|
|
232
|
+
const sender = createRequest({
|
|
233
|
+
path: endpoint.routePath,
|
|
234
|
+
method: endpoint.method,
|
|
235
|
+
port,
|
|
236
|
+
operationContext: {
|
|
237
|
+
operationId,
|
|
238
|
+
routePath: endpoint.routePath,
|
|
239
|
+
method: endpoint.method,
|
|
240
|
+
schemaHash: endpoint.schemaHash,
|
|
241
|
+
operationVersion: endpoint.operationVersion
|
|
242
|
+
},
|
|
243
|
+
httpMethodDecider,
|
|
244
|
+
...config.requestId ? {
|
|
245
|
+
requestId: config.requestId
|
|
246
|
+
} : {}
|
|
247
|
+
});
|
|
248
|
+
const call = (request = {})=>sender(prepareEffectRequest(endpoint, operation, request));
|
|
249
|
+
client[endpoint.group] ??= {};
|
|
250
|
+
client[endpoint.group][endpoint.endpoint] = call;
|
|
251
|
+
operationManifest[endpoint.group] ??= {};
|
|
252
|
+
operationManifest[endpoint.group][endpoint.endpoint] = operation;
|
|
253
|
+
}
|
|
254
|
+
return {
|
|
255
|
+
client,
|
|
256
|
+
operationManifest,
|
|
257
|
+
createEffectRequestContext
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
exports.createGeneratedEffectClient = __webpack_exports__.createGeneratedEffectClient;
|
|
261
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
262
|
+
"createGeneratedEffectClient"
|
|
263
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
264
|
+
Object.defineProperty(exports, '__esModule', {
|
|
265
|
+
value: true
|
|
266
|
+
});
|
|
@@ -43,6 +43,8 @@ const server_core_namespaceObject = require("@modern-js/server-core");
|
|
|
43
43
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
44
44
|
const createHonoRoutes_js_namespaceObject = require("../../utils/createHonoRoutes.js");
|
|
45
45
|
var createHonoRoutes_js_default = /*#__PURE__*/ __webpack_require__.n(createHonoRoutes_js_namespaceObject);
|
|
46
|
+
const crossProjectServerPolicy_js_namespaceObject = require("../../utils/crossProjectServerPolicy.js");
|
|
47
|
+
const external_safe_failure_js_namespaceObject = require("../safe-failure.js");
|
|
46
48
|
const before = [
|
|
47
49
|
'custom-server-hook',
|
|
48
50
|
'custom-server-middleware',
|
|
@@ -60,6 +62,7 @@ class HonoAdapter {
|
|
|
60
62
|
this.apiMiddleware = [];
|
|
61
63
|
this.apiServer = null;
|
|
62
64
|
this.isHono = true;
|
|
65
|
+
this.prefix = '/api';
|
|
63
66
|
this.setHandlers = async ()=>{
|
|
64
67
|
if (!this.isHono) return;
|
|
65
68
|
const { apiHandlerInfos } = this.api.getServerContext();
|
|
@@ -72,6 +75,22 @@ class HonoAdapter {
|
|
|
72
75
|
order: 'post',
|
|
73
76
|
before
|
|
74
77
|
}));
|
|
78
|
+
this.crossProjectPolicy = (0, crossProjectServerPolicy_js_namespaceObject.resolveAdapterCrossProjectPolicy)(this.api, apiHandlerInfos || []);
|
|
79
|
+
if (this.crossProjectPolicy) {
|
|
80
|
+
const policyMiddleware = async (c, next)=>{
|
|
81
|
+
const denial = (0, crossProjectServerPolicy_js_namespaceObject.checkCrossProjectPolicyResponse)(c.req.header(), this.crossProjectPolicy);
|
|
82
|
+
if (denial) return denial;
|
|
83
|
+
await next();
|
|
84
|
+
};
|
|
85
|
+
this.apiMiddleware.unshift({
|
|
86
|
+
name: 'bff-cross-project-policy',
|
|
87
|
+
path: `${this.prefix}/*`,
|
|
88
|
+
method: 'all',
|
|
89
|
+
handler: policyMiddleware,
|
|
90
|
+
order: 'post',
|
|
91
|
+
before
|
|
92
|
+
});
|
|
93
|
+
}
|
|
75
94
|
};
|
|
76
95
|
this.registerApiRoutes = async ()=>{
|
|
77
96
|
if (!this.isHono) return;
|
|
@@ -108,15 +127,7 @@ class HonoAdapter {
|
|
|
108
127
|
} catch (configError) {
|
|
109
128
|
utils_namespaceObject.logger.error(`Error in serverConfig.onError handler: ${configError}`);
|
|
110
129
|
}
|
|
111
|
-
|
|
112
|
-
return new Response(JSON.stringify({
|
|
113
|
-
message: err instanceof Error ? err.message : '[BFF] Internal Server Error'
|
|
114
|
-
}), {
|
|
115
|
-
status,
|
|
116
|
-
headers: {
|
|
117
|
-
'content-type': 'application/json; charset=utf-8'
|
|
118
|
-
}
|
|
119
|
-
});
|
|
130
|
+
return (0, external_safe_failure_js_namespaceObject.createSafeFailureResponse)(err);
|
|
120
131
|
});
|
|
121
132
|
};
|
|
122
133
|
this.registerMiddleware = async (options)=>{
|
|
@@ -126,6 +137,7 @@ class HonoAdapter {
|
|
|
126
137
|
this.isHono = false;
|
|
127
138
|
return;
|
|
128
139
|
}
|
|
140
|
+
this.prefix = prefix || this.prefix;
|
|
129
141
|
const { middlewares: globalMiddlewares } = this.api.getServerContext();
|
|
130
142
|
await this.setHandlers();
|
|
131
143
|
if ((0, utils_namespaceObject.isProd)()) globalMiddlewares.push(...this.apiMiddleware);
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
const SAFE_FAILURE_MESSAGES = {
|
|
31
|
+
500: 'Internal Server Error',
|
|
32
|
+
503: 'Service Unavailable'
|
|
33
|
+
};
|
|
34
|
+
const SAFE_FAILURE_CODES = {
|
|
35
|
+
500: 'INTERNAL_SERVER_ERROR',
|
|
36
|
+
503: 'SERVICE_UNAVAILABLE'
|
|
37
|
+
};
|
|
38
|
+
const readErrorProperty = (error, key)=>{
|
|
39
|
+
if ('object' != typeof error || null === error || !(key in error)) return;
|
|
40
|
+
return error[key];
|
|
41
|
+
};
|
|
42
|
+
const normalizeFailureStatus = (value)=>{
|
|
43
|
+
if ('number' != typeof value || !Number.isInteger(value)) return;
|
|
44
|
+
return value >= 400 && value <= 599 ? value : void 0;
|
|
45
|
+
};
|
|
46
|
+
const normalizeRetryAfter = (value)=>{
|
|
47
|
+
if ('number' == typeof value && Number.isFinite(value) && value >= 0) return String(Math.ceil(value));
|
|
48
|
+
if ('string' == typeof value) {
|
|
49
|
+
const trimmed = value.trim();
|
|
50
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
51
|
+
}
|
|
52
|
+
if (value instanceof Date) return value.toUTCString();
|
|
53
|
+
};
|
|
54
|
+
const createSafeFailureResponse = (error)=>{
|
|
55
|
+
const status = normalizeFailureStatus(readErrorProperty(error, 'status')) ?? normalizeFailureStatus(readErrorProperty(error, 'statusCode')) ?? 500;
|
|
56
|
+
const retryAfter = 503 === status ? normalizeRetryAfter(readErrorProperty(error, 'retryAfter')) ?? normalizeRetryAfter(readErrorProperty(error, 'retryAfterSeconds')) ?? normalizeRetryAfter('number' == typeof readErrorProperty(error, 'retryAfterMs') ? readErrorProperty(error, 'retryAfterMs') / 1000 : void 0) : void 0;
|
|
57
|
+
const body = {
|
|
58
|
+
success: false,
|
|
59
|
+
error: {
|
|
60
|
+
code: SAFE_FAILURE_CODES[status] ?? 'REQUEST_FAILED',
|
|
61
|
+
message: SAFE_FAILURE_MESSAGES[status] ?? 'Request failed',
|
|
62
|
+
status
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const headers = {
|
|
66
|
+
'content-type': 'application/json; charset=utf-8'
|
|
67
|
+
};
|
|
68
|
+
if (void 0 !== retryAfter) headers['Retry-After'] = retryAfter;
|
|
69
|
+
return new Response(JSON.stringify(body), {
|
|
70
|
+
status,
|
|
71
|
+
headers
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
75
|
+
createSafeFailureResponse: createSafeFailureResponse
|
|
76
|
+
});
|
|
77
|
+
exports.createSafeFailureResponse = __webpack_exports__.createSafeFailureResponse;
|
|
78
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
79
|
+
"createSafeFailureResponse"
|
|
80
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
81
|
+
Object.defineProperty(exports, '__esModule', {
|
|
82
|
+
value: true
|
|
83
|
+
});
|
|
@@ -306,7 +306,7 @@ async function clientGenerator(draftOptions) {
|
|
|
306
306
|
source: effectSource,
|
|
307
307
|
relativeDistPath: draftOptions.relativeDistPath
|
|
308
308
|
});
|
|
309
|
-
const
|
|
309
|
+
const effectClientArtifacts = await (0, external_effectClientGenerator_js_namespaceObject.generateEffectClient)({
|
|
310
310
|
appDir: draftOptions.appDir,
|
|
311
311
|
apiDir: draftOptions.apiDir,
|
|
312
312
|
resourcePath: effectEntryFile,
|
|
@@ -317,10 +317,10 @@ async function clientGenerator(draftOptions) {
|
|
|
317
317
|
httpMethodDecider: draftOptions.httpMethodDecider,
|
|
318
318
|
dataPlatformBatch: draftOptions.effectDataPlatformBatch
|
|
319
319
|
});
|
|
320
|
-
if (
|
|
320
|
+
if (effectClientArtifacts) {
|
|
321
321
|
const targetTypeFile = effectFileDetails.targetDir.replace(/\.js$/, '.d.ts');
|
|
322
|
-
await writeTargetFile(effectFileDetails.absTargetDir,
|
|
323
|
-
await writeTargetFile(external_path_default().resolve(targetTypeFile),
|
|
322
|
+
await writeTargetFile(effectFileDetails.absTargetDir, effectClientArtifacts.code);
|
|
323
|
+
await writeTargetFile(external_path_default().resolve(targetTypeFile), effectClientArtifacts.declaration);
|
|
324
324
|
generatedSourceList.push(effectFileDetails);
|
|
325
325
|
}
|
|
326
326
|
}
|
|
@@ -0,0 +1,104 @@
|
|
|
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
|
+
checkCrossProjectPolicyForRequest: ()=>checkCrossProjectPolicyForRequest,
|
|
41
|
+
checkCrossProjectPolicyResponse: ()=>checkCrossProjectPolicyResponse,
|
|
42
|
+
resolveAdapterCrossProjectPolicy: ()=>resolveAdapterCrossProjectPolicy
|
|
43
|
+
});
|
|
44
|
+
const bff_core_namespaceObject = require("@modern-js/bff-core");
|
|
45
|
+
const external_path_namespaceObject = require("path");
|
|
46
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
47
|
+
const readNearestPackageVersion = (startDir)=>{
|
|
48
|
+
if (!startDir) return;
|
|
49
|
+
let current = external_path_default().resolve(startDir);
|
|
50
|
+
for(let depth = 0; depth < 10; depth += 1){
|
|
51
|
+
try {
|
|
52
|
+
const packageJson = require(external_path_default().join(current, 'package.json'));
|
|
53
|
+
if ('string' == typeof packageJson.version) return packageJson.version;
|
|
54
|
+
} catch {}
|
|
55
|
+
const parent = external_path_default().dirname(current);
|
|
56
|
+
if (parent === current) break;
|
|
57
|
+
current = parent;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const resolveAdapterCrossProjectPolicy = (api, handlers)=>{
|
|
61
|
+
const bff = api.getServerConfig()?.bff;
|
|
62
|
+
const { apiDirectory, appDirectory } = api.getServerContext();
|
|
63
|
+
return (0, bff_core_namespaceObject.resolveCrossProjectPolicy)({
|
|
64
|
+
crossProjectPolicy: bff?.crossProjectPolicy,
|
|
65
|
+
handlers,
|
|
66
|
+
requestId: bff?.requestId,
|
|
67
|
+
isCrossProjectServer: bff?.isCrossProjectServer,
|
|
68
|
+
operationVersion: (0, bff_core_namespaceObject.deriveOperationVersion)(readNearestPackageVersion(apiDirectory) ?? readNearestPackageVersion(appDirectory))
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const DENIAL_HEADERS = {
|
|
72
|
+
'content-type': 'application/json; charset=utf-8'
|
|
73
|
+
};
|
|
74
|
+
const checkCrossProjectPolicyResponse = (headers, policy)=>{
|
|
75
|
+
if (!policy?.enabled) return null;
|
|
76
|
+
const denial = (0, bff_core_namespaceObject.checkCrossProjectPolicy)(headers, policy);
|
|
77
|
+
if (!denial) return null;
|
|
78
|
+
return new Response(JSON.stringify(denial.body), {
|
|
79
|
+
status: denial.status,
|
|
80
|
+
headers: DENIAL_HEADERS
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
const toHeaderRecord = (headers)=>{
|
|
84
|
+
const record = {};
|
|
85
|
+
headers.forEach((value, key)=>{
|
|
86
|
+
record[key] = value;
|
|
87
|
+
});
|
|
88
|
+
return record;
|
|
89
|
+
};
|
|
90
|
+
const checkCrossProjectPolicyForRequest = (request, policy)=>{
|
|
91
|
+
if (!policy?.enabled) return null;
|
|
92
|
+
return checkCrossProjectPolicyResponse(toHeaderRecord(request.headers), policy);
|
|
93
|
+
};
|
|
94
|
+
exports.checkCrossProjectPolicyForRequest = __webpack_exports__.checkCrossProjectPolicyForRequest;
|
|
95
|
+
exports.checkCrossProjectPolicyResponse = __webpack_exports__.checkCrossProjectPolicyResponse;
|
|
96
|
+
exports.resolveAdapterCrossProjectPolicy = __webpack_exports__.resolveAdapterCrossProjectPolicy;
|
|
97
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
98
|
+
"checkCrossProjectPolicyForRequest",
|
|
99
|
+
"checkCrossProjectPolicyResponse",
|
|
100
|
+
"resolveAdapterCrossProjectPolicy"
|
|
101
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
102
|
+
Object.defineProperty(exports, '__esModule', {
|
|
103
|
+
value: true
|
|
104
|
+
});
|