@bleedingdev/modern-js-plugin-bff 3.2.0-ultramodern.98 → 3.4.0-ultramodern.0
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 +40 -27
|
@@ -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
|
(()=>{
|
|
@@ -102,7 +106,7 @@ function makeEffectHttpApiClient(api, options) {
|
|
|
102
106
|
for (const [header, value] of Object.entries(requestContextHeaders))if (void 0 === nextRequest.headers[header.toLowerCase()]) nextRequest = http_namespaceObject.HttpClientRequest.setHeader(nextRequest, header, value);
|
|
103
107
|
return nextRequest;
|
|
104
108
|
}));
|
|
105
|
-
return options?.transformClient ? options.transformClient(contextClient) : contextClient;
|
|
109
|
+
return 'function' == typeof options?.transformClient ? options.transformClient(contextClient) : contextClient;
|
|
106
110
|
};
|
|
107
111
|
return httpapi_namespaceObject.HttpApiClient.make(api, {
|
|
108
112
|
baseUrl: options?.baseUrl,
|
|
@@ -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
|
+
});
|
|
@@ -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
|
(()=>{
|
|
@@ -39,6 +43,8 @@ const server_core_namespaceObject = require("@modern-js/server-core");
|
|
|
39
43
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
40
44
|
const createHonoRoutes_js_namespaceObject = require("../../utils/createHonoRoutes.js");
|
|
41
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");
|
|
42
48
|
const before = [
|
|
43
49
|
'custom-server-hook',
|
|
44
50
|
'custom-server-middleware',
|
|
@@ -56,6 +62,7 @@ class HonoAdapter {
|
|
|
56
62
|
this.apiMiddleware = [];
|
|
57
63
|
this.apiServer = null;
|
|
58
64
|
this.isHono = true;
|
|
65
|
+
this.prefix = '/api';
|
|
59
66
|
this.setHandlers = async ()=>{
|
|
60
67
|
if (!this.isHono) return;
|
|
61
68
|
const { apiHandlerInfos } = this.api.getServerContext();
|
|
@@ -68,6 +75,22 @@ class HonoAdapter {
|
|
|
68
75
|
order: 'post',
|
|
69
76
|
before
|
|
70
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
|
+
}
|
|
71
94
|
};
|
|
72
95
|
this.registerApiRoutes = async ()=>{
|
|
73
96
|
if (!this.isHono) return;
|
|
@@ -104,15 +127,7 @@ class HonoAdapter {
|
|
|
104
127
|
} catch (configError) {
|
|
105
128
|
utils_namespaceObject.logger.error(`Error in serverConfig.onError handler: ${configError}`);
|
|
106
129
|
}
|
|
107
|
-
|
|
108
|
-
return new Response(JSON.stringify({
|
|
109
|
-
message: err instanceof Error ? err.message : '[BFF] Internal Server Error'
|
|
110
|
-
}), {
|
|
111
|
-
status,
|
|
112
|
-
headers: {
|
|
113
|
-
'content-type': 'application/json; charset=utf-8'
|
|
114
|
-
}
|
|
115
|
-
});
|
|
130
|
+
return (0, external_safe_failure_js_namespaceObject.createSafeFailureResponse)(err);
|
|
116
131
|
});
|
|
117
132
|
};
|
|
118
133
|
this.registerMiddleware = async (options)=>{
|
|
@@ -122,6 +137,7 @@ class HonoAdapter {
|
|
|
122
137
|
this.isHono = false;
|
|
123
138
|
return;
|
|
124
139
|
}
|
|
140
|
+
this.prefix = prefix || this.prefix;
|
|
125
141
|
const { middlewares: globalMiddlewares } = this.api.getServerContext();
|
|
126
142
|
await this.setHandlers();
|
|
127
143
|
if ((0, utils_namespaceObject.isProd)()) globalMiddlewares.push(...this.apiMiddleware);
|
|
@@ -27,11 +27,15 @@ function __webpack_require__(moduleId) {
|
|
|
27
27
|
};
|
|
28
28
|
})();
|
|
29
29
|
(()=>{
|
|
30
|
-
__webpack_require__.d = (exports1,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
31
|
+
var define = (defs, kind)=>{
|
|
32
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
[kind]: defs[key]
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
define(getters, "get");
|
|
38
|
+
define(values, "value");
|
|
35
39
|
};
|
|
36
40
|
})();
|
|
37
41
|
(()=>{
|
|
@@ -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
|
(()=>{
|
|
@@ -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
|
+
});
|
package/dist/cjs/server.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
|
(()=>{
|
|
@@ -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
|
(()=>{
|
|
@@ -302,7 +306,7 @@ async function clientGenerator(draftOptions) {
|
|
|
302
306
|
source: effectSource,
|
|
303
307
|
relativeDistPath: draftOptions.relativeDistPath
|
|
304
308
|
});
|
|
305
|
-
const
|
|
309
|
+
const effectClientArtifacts = await (0, external_effectClientGenerator_js_namespaceObject.generateEffectClient)({
|
|
306
310
|
appDir: draftOptions.appDir,
|
|
307
311
|
apiDir: draftOptions.apiDir,
|
|
308
312
|
resourcePath: effectEntryFile,
|
|
@@ -313,10 +317,10 @@ async function clientGenerator(draftOptions) {
|
|
|
313
317
|
httpMethodDecider: draftOptions.httpMethodDecider,
|
|
314
318
|
dataPlatformBatch: draftOptions.effectDataPlatformBatch
|
|
315
319
|
});
|
|
316
|
-
if (
|
|
320
|
+
if (effectClientArtifacts) {
|
|
317
321
|
const targetTypeFile = effectFileDetails.targetDir.replace(/\.js$/, '.d.ts');
|
|
318
|
-
await writeTargetFile(effectFileDetails.absTargetDir,
|
|
319
|
-
await writeTargetFile(external_path_default().resolve(targetTypeFile),
|
|
322
|
+
await writeTargetFile(effectFileDetails.absTargetDir, effectClientArtifacts.code);
|
|
323
|
+
await writeTargetFile(external_path_default().resolve(targetTypeFile), effectClientArtifacts.declaration);
|
|
320
324
|
generatedSourceList.push(effectFileDetails);
|
|
321
325
|
}
|
|
322
326
|
}
|
|
@@ -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
|
(()=>{
|
|
@@ -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
|
(()=>{
|