@bleedingdev/modern-js-bff-effect 3.8.3-ultramodern.2
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/LICENSE +21 -0
- package/README.md +25 -0
- package/dist/cjs/data-platform/batch/protocol.js +130 -0
- package/dist/cjs/data-platform/batch/queue.js +623 -0
- package/dist/cjs/data-platform/batch/request.js +121 -0
- package/dist/cjs/data-platform/batch/response.js +65 -0
- package/dist/cjs/data-platform/batch/telemetry.js +71 -0
- package/dist/cjs/data-platform/batch/url.js +69 -0
- package/dist/cjs/data-platform/batch-transport.js +59 -0
- package/dist/cjs/data-platform/codec.js +155 -0
- package/dist/cjs/data-platform/index.js +124 -0
- package/dist/cjs/data-platform/invalidation.js +61 -0
- package/dist/cjs/data-platform/trace.js +73 -0
- package/dist/cjs/data-platform/types.js +48 -0
- package/dist/cjs/data-platform/validation.js +178 -0
- package/dist/cjs/effect/context.js +59 -0
- package/dist/cjs/effect/dispatch.js +101 -0
- package/dist/cjs/effect/edge-context.js +61 -0
- package/dist/cjs/effect/edge-dispatcher.js +354 -0
- package/dist/cjs/effect/edge.js +62 -0
- package/dist/cjs/effect/endpoint-contracts.js +121 -0
- package/dist/cjs/effect/entry-shape-registry.js +31 -0
- package/dist/cjs/effect/entry-shape.js +113 -0
- package/dist/cjs/effect/handler/batch-handler.js +270 -0
- package/dist/cjs/effect/handler/batch.js +170 -0
- package/dist/cjs/effect/handler/definition.js +99 -0
- package/dist/cjs/effect/handler/envelope.js +104 -0
- package/dist/cjs/effect/handler/http.js +107 -0
- package/dist/cjs/effect/handler/openapi.js +58 -0
- package/dist/cjs/effect/handler/routing.js +100 -0
- package/dist/cjs/effect/handler/rpc.js +63 -0
- package/dist/cjs/effect/handler/types.js +43 -0
- package/dist/cjs/effect/handler.js +173 -0
- package/dist/cjs/effect/index.js +137 -0
- package/dist/cjs/effect/module.js +118 -0
- package/dist/cjs/effect/operation-context.js +116 -0
- package/dist/cjs/effect/rpcSerialization.js +54 -0
- package/dist/cjs/effect-client/batch.js +73 -0
- package/dist/cjs/effect-client/envelope.js +145 -0
- package/dist/cjs/effect-client/guards.js +44 -0
- package/dist/cjs/effect-client/index.js +208 -0
- package/dist/cjs/effect-client/request-context.js +64 -0
- package/dist/cjs/effect-client/request.js +66 -0
- package/dist/cjs/effect-client/runtime.js +100 -0
- package/dist/cjs/effect-client/types.js +18 -0
- package/dist/cjs/headers.js +46 -0
- package/dist/cjs/index.js +83 -0
- package/dist/esm/data-platform/batch/protocol.mjs +71 -0
- package/dist/esm/data-platform/batch/queue.mjs +582 -0
- package/dist/esm/data-platform/batch/request.mjs +68 -0
- package/dist/esm/data-platform/batch/response.mjs +24 -0
- package/dist/esm/data-platform/batch/telemetry.mjs +27 -0
- package/dist/esm/data-platform/batch/url.mjs +25 -0
- package/dist/esm/data-platform/batch-transport.mjs +12 -0
- package/dist/esm/data-platform/codec.mjs +90 -0
- package/dist/esm/data-platform/index.mjs +7 -0
- package/dist/esm/data-platform/invalidation.mjs +20 -0
- package/dist/esm/data-platform/trace.mjs +29 -0
- package/dist/esm/data-platform/types.mjs +4 -0
- package/dist/esm/data-platform/validation.mjs +128 -0
- package/dist/esm/effect/context.mjs +12 -0
- package/dist/esm/effect/dispatch.mjs +63 -0
- package/dist/esm/effect/edge-context.mjs +14 -0
- package/dist/esm/effect/edge-dispatcher.mjs +115 -0
- package/dist/esm/effect/edge.mjs +1 -0
- package/dist/esm/effect/endpoint-contracts.mjs +68 -0
- package/dist/esm/effect/entry-shape-registry.mjs +17 -0
- package/dist/esm/effect/entry-shape.mjs +51 -0
- package/dist/esm/effect/handler/batch-handler.mjs +232 -0
- package/dist/esm/effect/handler/batch.mjs +105 -0
- package/dist/esm/effect/handler/definition.mjs +58 -0
- package/dist/esm/effect/handler/envelope.mjs +63 -0
- package/dist/esm/effect/handler/http.mjs +69 -0
- package/dist/esm/effect/handler/openapi.mjs +20 -0
- package/dist/esm/effect/handler/routing.mjs +50 -0
- package/dist/esm/effect/handler/rpc.mjs +22 -0
- package/dist/esm/effect/handler/types.mjs +5 -0
- package/dist/esm/effect/handler.mjs +13 -0
- package/dist/esm/effect/index.mjs +7 -0
- package/dist/esm/effect/module.mjs +80 -0
- package/dist/esm/effect/operation-context.mjs +75 -0
- package/dist/esm/effect/rpcSerialization.mjs +16 -0
- package/dist/esm/effect-client/batch.mjs +35 -0
- package/dist/esm/effect-client/envelope.mjs +104 -0
- package/dist/esm/effect-client/guards.mjs +3 -0
- package/dist/esm/effect-client/index.mjs +110 -0
- package/dist/esm/effect-client/request-context.mjs +23 -0
- package/dist/esm/effect-client/request.mjs +28 -0
- package/dist/esm/effect-client/runtime.mjs +62 -0
- package/dist/esm/effect-client/types.mjs +0 -0
- package/dist/esm/headers.mjs +8 -0
- package/dist/esm/index.mjs +4 -0
- package/dist/esm/rslib-runtime.mjs +18 -0
- package/dist/esm-node/data-platform/batch/protocol.mjs +72 -0
- package/dist/esm-node/data-platform/batch/queue.mjs +583 -0
- package/dist/esm-node/data-platform/batch/request.mjs +69 -0
- package/dist/esm-node/data-platform/batch/response.mjs +25 -0
- package/dist/esm-node/data-platform/batch/telemetry.mjs +28 -0
- package/dist/esm-node/data-platform/batch/url.mjs +26 -0
- package/dist/esm-node/data-platform/batch-transport.mjs +13 -0
- package/dist/esm-node/data-platform/codec.mjs +91 -0
- package/dist/esm-node/data-platform/index.mjs +8 -0
- package/dist/esm-node/data-platform/invalidation.mjs +21 -0
- package/dist/esm-node/data-platform/trace.mjs +30 -0
- package/dist/esm-node/data-platform/types.mjs +5 -0
- package/dist/esm-node/data-platform/validation.mjs +129 -0
- package/dist/esm-node/effect/context.mjs +13 -0
- package/dist/esm-node/effect/dispatch.mjs +64 -0
- package/dist/esm-node/effect/edge-context.mjs +15 -0
- package/dist/esm-node/effect/edge-dispatcher.mjs +116 -0
- package/dist/esm-node/effect/edge.mjs +2 -0
- package/dist/esm-node/effect/endpoint-contracts.mjs +69 -0
- package/dist/esm-node/effect/entry-shape-registry.mjs +18 -0
- package/dist/esm-node/effect/entry-shape.mjs +63 -0
- package/dist/esm-node/effect/handler/batch-handler.mjs +233 -0
- package/dist/esm-node/effect/handler/batch.mjs +106 -0
- package/dist/esm-node/effect/handler/definition.mjs +59 -0
- package/dist/esm-node/effect/handler/envelope.mjs +64 -0
- package/dist/esm-node/effect/handler/http.mjs +70 -0
- package/dist/esm-node/effect/handler/openapi.mjs +21 -0
- package/dist/esm-node/effect/handler/routing.mjs +51 -0
- package/dist/esm-node/effect/handler/rpc.mjs +23 -0
- package/dist/esm-node/effect/handler/types.mjs +6 -0
- package/dist/esm-node/effect/handler.mjs +14 -0
- package/dist/esm-node/effect/index.mjs +8 -0
- package/dist/esm-node/effect/module.mjs +81 -0
- package/dist/esm-node/effect/operation-context.mjs +76 -0
- package/dist/esm-node/effect/rpcSerialization.mjs +17 -0
- package/dist/esm-node/effect-client/batch.mjs +36 -0
- package/dist/esm-node/effect-client/envelope.mjs +105 -0
- package/dist/esm-node/effect-client/guards.mjs +4 -0
- package/dist/esm-node/effect-client/index.mjs +111 -0
- package/dist/esm-node/effect-client/request-context.mjs +24 -0
- package/dist/esm-node/effect-client/request.mjs +29 -0
- package/dist/esm-node/effect-client/runtime.mjs +63 -0
- package/dist/esm-node/effect-client/types.mjs +1 -0
- package/dist/esm-node/headers.mjs +9 -0
- package/dist/esm-node/index.mjs +5 -0
- package/dist/esm-node/rslib-runtime.mjs +19 -0
- package/dist/types/data-platform/batch/protocol.d.ts +9 -0
- package/dist/types/data-platform/batch/queue.d.ts +47 -0
- package/dist/types/data-platform/batch/request.d.ts +19 -0
- package/dist/types/data-platform/batch/response.d.ts +3 -0
- package/dist/types/data-platform/batch/telemetry.d.ts +4 -0
- package/dist/types/data-platform/batch/url.d.ts +4 -0
- package/dist/types/data-platform/batch-transport.d.ts +3 -0
- package/dist/types/data-platform/codec.d.ts +17 -0
- package/dist/types/data-platform/index.d.ts +8 -0
- package/dist/types/data-platform/invalidation.d.ts +8 -0
- package/dist/types/data-platform/trace.d.ts +4 -0
- package/dist/types/data-platform/types.d.ts +151 -0
- package/dist/types/data-platform/validation.d.ts +29 -0
- package/dist/types/effect/context.d.ts +5 -0
- package/dist/types/effect/dispatch.d.ts +13 -0
- package/dist/types/effect/edge-context.d.ts +5 -0
- package/dist/types/effect/edge-dispatcher.d.ts +37 -0
- package/dist/types/effect/edge.d.ts +1 -0
- package/dist/types/effect/endpoint-contracts.d.ts +67 -0
- package/dist/types/effect/entry-shape.d.ts +32 -0
- package/dist/types/effect/handler/batch-handler.d.ts +11 -0
- package/dist/types/effect/handler/batch.d.ts +15 -0
- package/dist/types/effect/handler/definition.d.ts +7 -0
- package/dist/types/effect/handler/envelope.d.ts +13 -0
- package/dist/types/effect/handler/http.d.ts +15 -0
- package/dist/types/effect/handler/openapi.d.ts +4 -0
- package/dist/types/effect/handler/routing.d.ts +5 -0
- package/dist/types/effect/handler/rpc.d.ts +7 -0
- package/dist/types/effect/handler/types.d.ts +153 -0
- package/dist/types/effect/handler.d.ts +13 -0
- package/dist/types/effect/index.d.ts +6 -0
- package/dist/types/effect/module.d.ts +36 -0
- package/dist/types/effect/operation-context.d.ts +15 -0
- package/dist/types/effect/rpcSerialization.d.ts +3 -0
- package/dist/types/effect-client/batch.d.ts +2 -0
- package/dist/types/effect-client/envelope.d.ts +15 -0
- package/dist/types/effect-client/guards.d.ts +2 -0
- package/dist/types/effect-client/index.d.ts +58 -0
- package/dist/types/effect-client/request-context.d.ts +3 -0
- package/dist/types/effect-client/request.d.ts +1 -0
- package/dist/types/effect-client/runtime.d.ts +5 -0
- package/dist/types/effect-client/types.d.ts +68 -0
- package/dist/types/headers.d.ts +1 -0
- package/dist/types/index.d.ts +3 -0
- package/package.json +164 -0
- package/src/data-platform/batch/protocol.ts +112 -0
- package/src/data-platform/batch/queue.ts +876 -0
- package/src/data-platform/batch/request.ts +130 -0
- package/src/data-platform/batch/response.ts +74 -0
- package/src/data-platform/batch/telemetry.ts +47 -0
- package/src/data-platform/batch/url.ts +54 -0
- package/src/data-platform/batch-transport.ts +22 -0
- package/src/data-platform/codec.ts +145 -0
- package/src/data-platform/index.ts +63 -0
- package/src/data-platform/invalidation.ts +57 -0
- package/src/data-platform/trace.ts +49 -0
- package/src/data-platform/types.ts +186 -0
- package/src/data-platform/validation.ts +303 -0
- package/src/effect/context.ts +37 -0
- package/src/effect/dispatch.ts +132 -0
- package/src/effect/edge-context.ts +51 -0
- package/src/effect/edge-dispatcher.ts +310 -0
- package/src/effect/edge.ts +1 -0
- package/src/effect/endpoint-contracts.ts +191 -0
- package/src/effect/entry-shape-registry.cjs +16 -0
- package/src/effect/entry-shape-registry.d.cts +6 -0
- package/src/effect/entry-shape.ts +155 -0
- package/src/effect/handler/batch-handler.ts +475 -0
- package/src/effect/handler/batch.ts +182 -0
- package/src/effect/handler/definition.ts +121 -0
- package/src/effect/handler/envelope.ts +133 -0
- package/src/effect/handler/http.ts +133 -0
- package/src/effect/handler/openapi.ts +45 -0
- package/src/effect/handler/routing.ts +91 -0
- package/src/effect/handler/rpc.ts +45 -0
- package/src/effect/handler/types.ts +255 -0
- package/src/effect/handler.ts +33 -0
- package/src/effect/index.ts +22 -0
- package/src/effect/module.ts +186 -0
- package/src/effect/operation-context.ts +144 -0
- package/src/effect/rpcSerialization.ts +20 -0
- package/src/effect-client/batch.ts +50 -0
- package/src/effect-client/envelope.ts +238 -0
- package/src/effect-client/guards.ts +6 -0
- package/src/effect-client/index.ts +325 -0
- package/src/effect-client/request-context.ts +54 -0
- package/src/effect-client/request.ts +51 -0
- package/src/effect-client/runtime.ts +122 -0
- package/src/effect-client/types.ts +84 -0
- package/src/headers.ts +7 -0
- package/src/index.ts +3 -0
|
@@ -0,0 +1,270 @@
|
|
|
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
|
+
createDataPlatformBatchRequestHandler: ()=>createDataPlatformBatchRequestHandler
|
|
32
|
+
});
|
|
33
|
+
const index_js_namespaceObject = require("../../data-platform/index.js");
|
|
34
|
+
const protocol_js_namespaceObject = require("../../data-platform/batch/protocol.js");
|
|
35
|
+
const external_batch_js_namespaceObject = require("./batch.js");
|
|
36
|
+
const external_routing_js_namespaceObject = require("./routing.js");
|
|
37
|
+
const HOP_BY_HOP_BATCH_ITEM_HEADERS = new Set([
|
|
38
|
+
'connection',
|
|
39
|
+
'keep-alive',
|
|
40
|
+
'proxy-authenticate',
|
|
41
|
+
'proxy-authorization',
|
|
42
|
+
'proxy-connection',
|
|
43
|
+
'te',
|
|
44
|
+
'trailer',
|
|
45
|
+
'transfer-encoding',
|
|
46
|
+
'upgrade'
|
|
47
|
+
]);
|
|
48
|
+
const OUTER_BOUND_BATCH_ITEM_HEADERS = new Set([
|
|
49
|
+
'authorization',
|
|
50
|
+
'cookie',
|
|
51
|
+
'forwarded',
|
|
52
|
+
'origin',
|
|
53
|
+
'referer',
|
|
54
|
+
'sec-fetch-dest',
|
|
55
|
+
'sec-fetch-mode',
|
|
56
|
+
'sec-fetch-site',
|
|
57
|
+
'sec-fetch-user',
|
|
58
|
+
'x-forwarded-client-cert',
|
|
59
|
+
'x-forwarded-for',
|
|
60
|
+
'x-forwarded-host',
|
|
61
|
+
'x-forwarded-port',
|
|
62
|
+
'x-forwarded-proto',
|
|
63
|
+
'x-real-ip',
|
|
64
|
+
'x-subject-id',
|
|
65
|
+
'x-tenant-id',
|
|
66
|
+
'x-user-id',
|
|
67
|
+
'x-verified-producer'
|
|
68
|
+
]);
|
|
69
|
+
const TRANSPORT_CONTROLLED_BATCH_ITEM_HEADERS = new Set([
|
|
70
|
+
'content-length',
|
|
71
|
+
'host',
|
|
72
|
+
...HOP_BY_HOP_BATCH_ITEM_HEADERS
|
|
73
|
+
]);
|
|
74
|
+
async function readRequestTextWithinLimit(request, maxBytes) {
|
|
75
|
+
const contentLength = request.headers.get('content-length');
|
|
76
|
+
if (null !== contentLength) {
|
|
77
|
+
if (!/^\d+$/.test(contentLength)) return {
|
|
78
|
+
status: 'invalid-content-length'
|
|
79
|
+
};
|
|
80
|
+
if (BigInt(contentLength) > BigInt(maxBytes)) return {
|
|
81
|
+
status: 'too-large'
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (null === request.body) return {
|
|
85
|
+
status: 'ok',
|
|
86
|
+
text: ''
|
|
87
|
+
};
|
|
88
|
+
const reader = request.body.getReader();
|
|
89
|
+
const decoder = new TextDecoder();
|
|
90
|
+
const text = [];
|
|
91
|
+
let bytesRead = 0;
|
|
92
|
+
try {
|
|
93
|
+
while(true){
|
|
94
|
+
const chunk = await reader.read();
|
|
95
|
+
if (chunk.done) {
|
|
96
|
+
text.push(decoder.decode());
|
|
97
|
+
return {
|
|
98
|
+
status: 'ok',
|
|
99
|
+
text: text.join('')
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
bytesRead += chunk.value.byteLength;
|
|
103
|
+
if (bytesRead > maxBytes) {
|
|
104
|
+
await reader.cancel('batch-payload-too-large');
|
|
105
|
+
return {
|
|
106
|
+
status: 'too-large'
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
text.push(decoder.decode(chunk.value, {
|
|
110
|
+
stream: true
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
} catch {
|
|
114
|
+
return {
|
|
115
|
+
status: 'read-error'
|
|
116
|
+
};
|
|
117
|
+
} finally{
|
|
118
|
+
reader.releaseLock();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function createDataPlatformBatchRequestHandler(options) {
|
|
122
|
+
const dataPlatformBatchOptions = options.dataPlatform?.batch;
|
|
123
|
+
const batchEnabled = dataPlatformBatchOptions?.enabled !== false;
|
|
124
|
+
const batchPath = (0, external_batch_js_namespaceObject.normalizeBatchPath)(dataPlatformBatchOptions?.endpoint);
|
|
125
|
+
const batchMaxSize = Math.max(1, dataPlatformBatchOptions?.maxBatchSize ?? 16);
|
|
126
|
+
const batchMaxBytes = Math.max(1024, dataPlatformBatchOptions?.maxBatchBytes ?? 65536);
|
|
127
|
+
const batchConcurrency = Math.max(1, dataPlatformBatchOptions?.maxConcurrency ?? 4);
|
|
128
|
+
const batchItemTimeoutMs = Math.max(0, dataPlatformBatchOptions?.requestTimeoutMs ?? 10000);
|
|
129
|
+
const batchAllowedMethods = (0, external_batch_js_namespaceObject.normalizeBatchAllowedMethods)(dataPlatformBatchOptions?.allowedMethods);
|
|
130
|
+
const envelopeHeader = options.dataPlatform?.envelopeHeader || index_js_namespaceObject.DEFAULT_DATA_ENVELOPE_HEADER;
|
|
131
|
+
const normalizedEnvelopeHeader = envelopeHeader.toLowerCase();
|
|
132
|
+
const handle = async (request, context)=>{
|
|
133
|
+
const mountedPrefix = (0, external_routing_js_namespaceObject.getMountedPrefixFromContext)(request, context);
|
|
134
|
+
const method = (0, index_js_namespaceObject.normalizeMethod)(request.method);
|
|
135
|
+
if ('POST' !== method) return (0, external_batch_js_namespaceObject.createBatchValidationResponse)('Batch endpoint only supports POST requests', 405);
|
|
136
|
+
const contentType = request.headers.get('content-type') || '';
|
|
137
|
+
if (!contentType.includes('application/json')) return (0, external_batch_js_namespaceObject.createBatchValidationResponse)('Batch endpoint requires application/json content-type', 415);
|
|
138
|
+
const bodyResult = await readRequestTextWithinLimit(request, batchMaxBytes);
|
|
139
|
+
if ('too-large' === bodyResult.status) return (0, external_batch_js_namespaceObject.createBatchValidationResponse)(`Batch payload exceeds max size (${String(batchMaxBytes)} bytes)`, 413);
|
|
140
|
+
if ('invalid-content-length' === bodyResult.status) return (0, external_batch_js_namespaceObject.createBatchValidationResponse)('Batch payload has invalid content-length');
|
|
141
|
+
if ('read-error' === bodyResult.status) return (0, external_batch_js_namespaceObject.createBatchValidationResponse)('Unable to read batch payload');
|
|
142
|
+
const payloadText = bodyResult.text;
|
|
143
|
+
let payload;
|
|
144
|
+
try {
|
|
145
|
+
payload = JSON.parse(payloadText);
|
|
146
|
+
} catch {
|
|
147
|
+
return (0, external_batch_js_namespaceObject.createBatchValidationResponse)('Invalid batch payload JSON');
|
|
148
|
+
}
|
|
149
|
+
if (!(0, external_batch_js_namespaceObject.isBatchRequestPayload)(payload)) return (0, external_batch_js_namespaceObject.createBatchValidationResponse)('Invalid batch payload shape');
|
|
150
|
+
if (0 === payload.items.length) return (0, external_batch_js_namespaceObject.createBatchValidationResponse)('Batch payload items cannot be empty');
|
|
151
|
+
if (payload.items.length > batchMaxSize) return (0, external_batch_js_namespaceObject.createBatchValidationResponse)(`Batch item count exceeds max size (${String(batchMaxSize)})`, 413);
|
|
152
|
+
const batchRequestOrigin = new URL(request.url).origin;
|
|
153
|
+
const responseItems = await (0, external_batch_js_namespaceObject.mapWithConcurrency)(payload.items, batchConcurrency, async (rawItem, index)=>{
|
|
154
|
+
const fallbackId = `item_${String(index)}`;
|
|
155
|
+
const itemId = (0, index_js_namespaceObject.isPlainObject)(rawItem) && 'string' == typeof rawItem.id ? rawItem.id : fallbackId;
|
|
156
|
+
if (!(0, index_js_namespaceObject.isPlainObject)(rawItem)) return (0, external_batch_js_namespaceObject.toBatchItemError)(itemId, 400, 'Invalid batch item; expected object');
|
|
157
|
+
if ('string' != typeof rawItem.path || 0 === rawItem.path.length) return (0, external_batch_js_namespaceObject.toBatchItemError)(itemId, 400, 'Invalid batch item path');
|
|
158
|
+
if (!rawItem.path.startsWith('/')) return (0, external_batch_js_namespaceObject.toBatchItemError)(itemId, 400, 'Batch item path must start with "/"');
|
|
159
|
+
const normalizedItemPath = (0, external_routing_js_namespaceObject.removeMountedPrefixFromBatchPath)(rawItem.path, mountedPrefix);
|
|
160
|
+
const itemPathname = normalizedItemPath.split('?')[0] || normalizedItemPath;
|
|
161
|
+
if (itemPathname === batchPath || itemPathname.startsWith(`${batchPath}/`)) return (0, external_batch_js_namespaceObject.toBatchItemError)(itemId, 400, 'Batch item path cannot target batch endpoint');
|
|
162
|
+
const itemMethod = (0, index_js_namespaceObject.normalizeMethod)('string' == typeof rawItem.method ? rawItem.method : void 0);
|
|
163
|
+
if (!batchAllowedMethods.has(itemMethod)) return (0, external_batch_js_namespaceObject.toBatchItemError)(itemId, 405, `Batch item method ${itemMethod} is not allowed`);
|
|
164
|
+
if (void 0 !== rawItem.body && !(0, protocol_js_namespaceObject.isBatchBody)(rawItem.body)) return (0, external_batch_js_namespaceObject.toBatchItemError)(itemId, 400, 'Batch item body must use the base64 body protocol');
|
|
165
|
+
if (('GET' === itemMethod || 'HEAD' === itemMethod) && void 0 !== rawItem.body) return (0, external_batch_js_namespaceObject.toBatchItemError)(itemId, 400, `${itemMethod} batch item cannot include body`);
|
|
166
|
+
const normalizedHeaders = {};
|
|
167
|
+
if (void 0 !== rawItem.headers) {
|
|
168
|
+
if (!(0, index_js_namespaceObject.isPlainObject)(rawItem.headers)) return (0, external_batch_js_namespaceObject.toBatchItemError)(itemId, 400, 'Batch item headers must be an object');
|
|
169
|
+
for (const [key, value] of Object.entries(rawItem.headers)){
|
|
170
|
+
if ('string' != typeof value) return (0, external_batch_js_namespaceObject.toBatchItemError)(itemId, 400, `Invalid header "${key}" for batch item`);
|
|
171
|
+
normalizedHeaders[key.toLowerCase()] = value;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const connectionScopedHeaders = new Set((normalizedHeaders.connection || '').split(',').map((header)=>header.trim().toLowerCase()).filter(Boolean));
|
|
175
|
+
for (const header of Object.keys(normalizedHeaders))if (TRANSPORT_CONTROLLED_BATCH_ITEM_HEADERS.has(header) || OUTER_BOUND_BATCH_ITEM_HEADERS.has(header) || connectionScopedHeaders.has(header)) delete normalizedHeaders[header];
|
|
176
|
+
if (!normalizedHeaders.traceparent) {
|
|
177
|
+
const encodedEnvelope = normalizedHeaders[normalizedEnvelopeHeader];
|
|
178
|
+
if ('string' == typeof encodedEnvelope) {
|
|
179
|
+
const envelope = (0, index_js_namespaceObject.decodeRequestEnvelopeHeader)(encodedEnvelope);
|
|
180
|
+
if (envelope?.traceparent) normalizedHeaders.traceparent = envelope.traceparent;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
for (const header of OUTER_BOUND_BATCH_ITEM_HEADERS){
|
|
184
|
+
const value = request.headers.get(header);
|
|
185
|
+
if (null !== value) normalizedHeaders[header] = value;
|
|
186
|
+
}
|
|
187
|
+
if (!normalizedHeaders.traceparent) {
|
|
188
|
+
const requestTraceparent = request.headers.get('traceparent');
|
|
189
|
+
if (requestTraceparent) normalizedHeaders.traceparent = requestTraceparent;
|
|
190
|
+
}
|
|
191
|
+
const targetUrl = new URL(normalizedItemPath, request.url);
|
|
192
|
+
if (targetUrl.origin !== batchRequestOrigin) return (0, external_batch_js_namespaceObject.toBatchItemError)(itemId, 400, 'Batch item path must stay on the same origin');
|
|
193
|
+
let requestHeaders;
|
|
194
|
+
try {
|
|
195
|
+
requestHeaders = new Headers(normalizedHeaders);
|
|
196
|
+
} catch {
|
|
197
|
+
return (0, external_batch_js_namespaceObject.toBatchItemError)(itemId, 400, 'Invalid batch item headers');
|
|
198
|
+
}
|
|
199
|
+
const body = 'GET' === itemMethod || 'HEAD' === itemMethod ? void 0 : void 0 === rawItem.body ? void 0 : (0, protocol_js_namespaceObject.decodeBatchBody)(rawItem.body);
|
|
200
|
+
if (void 0 === body) requestHeaders.delete('content-type');
|
|
201
|
+
const itemAbortController = new AbortController();
|
|
202
|
+
const abortFromBatchRequest = ()=>itemAbortController.abort(request.signal.reason);
|
|
203
|
+
if (request.signal.aborted) abortFromBatchRequest();
|
|
204
|
+
else request.signal.addEventListener('abort', abortFromBatchRequest, {
|
|
205
|
+
once: true
|
|
206
|
+
});
|
|
207
|
+
const itemRequest = new Request(targetUrl.toString(), {
|
|
208
|
+
method: itemMethod,
|
|
209
|
+
headers: requestHeaders,
|
|
210
|
+
body,
|
|
211
|
+
signal: itemAbortController.signal
|
|
212
|
+
});
|
|
213
|
+
try {
|
|
214
|
+
const itemResponse = await (0, external_batch_js_namespaceObject.promiseWithTimeout)(options.handleItem(itemRequest, context), batchItemTimeoutMs, (error)=>itemAbortController.abort(error));
|
|
215
|
+
if (!(itemResponse instanceof Response)) return (0, external_batch_js_namespaceObject.toBatchItemError)(itemId, 500, 'Invalid response returned by batch item handler');
|
|
216
|
+
return (0, protocol_js_namespaceObject.toBatchResponseItem)(itemId, itemResponse, 'HEAD' === itemMethod);
|
|
217
|
+
} catch (error) {
|
|
218
|
+
if (error instanceof external_batch_js_namespaceObject.BatchItemTimeoutError) {
|
|
219
|
+
console.error({
|
|
220
|
+
event: 'bff.batch.item.timeout',
|
|
221
|
+
batchId: payload.batchId,
|
|
222
|
+
itemId,
|
|
223
|
+
method: itemMethod,
|
|
224
|
+
path: itemPathname,
|
|
225
|
+
errorName: error.name
|
|
226
|
+
});
|
|
227
|
+
return (0, external_batch_js_namespaceObject.toBatchItemError)(itemId, 504, 'Batch item request timed out');
|
|
228
|
+
}
|
|
229
|
+
if (error instanceof Response) return (0, protocol_js_namespaceObject.toBatchResponseItem)(itemId, error, 'HEAD' === itemMethod);
|
|
230
|
+
console.error({
|
|
231
|
+
event: 'bff.batch.item.failure',
|
|
232
|
+
batchId: payload.batchId,
|
|
233
|
+
itemId,
|
|
234
|
+
method: itemMethod,
|
|
235
|
+
path: itemPathname,
|
|
236
|
+
errorName: error instanceof Error ? error.name : 'UnknownError'
|
|
237
|
+
});
|
|
238
|
+
return (0, external_batch_js_namespaceObject.toBatchItemError)(itemId, 500, 'Internal Server Error');
|
|
239
|
+
} finally{
|
|
240
|
+
request.signal.removeEventListener('abort', abortFromBatchRequest);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
const responsePayload = {
|
|
244
|
+
protocolVersion: 2,
|
|
245
|
+
batchId: payload.batchId,
|
|
246
|
+
receivedAt: Date.now(),
|
|
247
|
+
items: responseItems
|
|
248
|
+
};
|
|
249
|
+
return new Response(JSON.stringify(responsePayload), {
|
|
250
|
+
status: 200,
|
|
251
|
+
headers: {
|
|
252
|
+
'content-type': 'application/json; charset=utf-8',
|
|
253
|
+
[index_js_namespaceObject.DEFAULT_DATA_BATCH_HEADER]: '2',
|
|
254
|
+
'x-modernjs-data-batch-id': payload.batchId
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
return {
|
|
259
|
+
enabled: batchEnabled,
|
|
260
|
+
path: batchPath,
|
|
261
|
+
handle
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
exports.createDataPlatformBatchRequestHandler = __webpack_exports__.createDataPlatformBatchRequestHandler;
|
|
265
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
266
|
+
"createDataPlatformBatchRequestHandler"
|
|
267
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
268
|
+
Object.defineProperty(exports, '__esModule', {
|
|
269
|
+
value: true
|
|
270
|
+
});
|
|
@@ -0,0 +1,170 @@
|
|
|
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
|
+
BatchItemTimeoutError: ()=>BatchItemTimeoutError,
|
|
32
|
+
createBatchValidationResponse: ()=>createBatchValidationResponse,
|
|
33
|
+
isBatchRequestPayload: ()=>isBatchRequestPayload,
|
|
34
|
+
mapWithConcurrency: ()=>mapWithConcurrency,
|
|
35
|
+
normalizeBatchAllowedMethods: ()=>normalizeBatchAllowedMethods,
|
|
36
|
+
normalizeBatchPath: ()=>normalizeBatchPath,
|
|
37
|
+
prepareJsonRequestBody: ()=>prepareJsonRequestBody,
|
|
38
|
+
promiseWithTimeout: ()=>promiseWithTimeout,
|
|
39
|
+
toBatchItemError: ()=>toBatchItemError,
|
|
40
|
+
toHeaderRecord: ()=>external_headers_js_namespaceObject.toHeaderRecord
|
|
41
|
+
});
|
|
42
|
+
const index_js_namespaceObject = require("../../data-platform/index.js");
|
|
43
|
+
const protocol_js_namespaceObject = require("../../data-platform/batch/protocol.js");
|
|
44
|
+
const external_headers_js_namespaceObject = require("../../headers.js");
|
|
45
|
+
function normalizeBatchPath(pathname) {
|
|
46
|
+
if (!pathname || '/' === pathname) return index_js_namespaceObject.DEFAULT_DATA_BATCH_ENDPOINT;
|
|
47
|
+
if (!pathname.startsWith('/')) return `/${pathname}`;
|
|
48
|
+
return pathname;
|
|
49
|
+
}
|
|
50
|
+
function normalizeBatchAllowedMethods(allowedMethods) {
|
|
51
|
+
const source = Array.isArray(allowedMethods) && allowedMethods.length > 0 ? allowedMethods : [
|
|
52
|
+
'GET'
|
|
53
|
+
];
|
|
54
|
+
return new Set(source.map((method)=>method.toUpperCase()));
|
|
55
|
+
}
|
|
56
|
+
function isBatchRequestPayload(value) {
|
|
57
|
+
return (0, index_js_namespaceObject.isPlainObject)(value) && 2 === value.protocolVersion && 'string' == typeof value.batchId && 'number' == typeof value.sentAt && Array.isArray(value.items);
|
|
58
|
+
}
|
|
59
|
+
function createBatchValidationResponse(message, status = 400) {
|
|
60
|
+
return new Response(JSON.stringify({
|
|
61
|
+
message
|
|
62
|
+
}), {
|
|
63
|
+
status,
|
|
64
|
+
headers: {
|
|
65
|
+
'content-type': 'application/json; charset=utf-8'
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function cloneWithoutJsonBodyHeaders(request) {
|
|
70
|
+
const headers = new Headers(request.headers);
|
|
71
|
+
headers.delete('content-type');
|
|
72
|
+
headers.delete('content-length');
|
|
73
|
+
return new Request(request.url, {
|
|
74
|
+
method: request.method,
|
|
75
|
+
headers,
|
|
76
|
+
signal: request.signal
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async function prepareJsonRequestBody(request) {
|
|
80
|
+
const method = (0, index_js_namespaceObject.normalizeMethod)(request.method);
|
|
81
|
+
if ('GET' === method || 'HEAD' === method) return request;
|
|
82
|
+
const contentType = (request.headers.get('content-type') || '').toLowerCase();
|
|
83
|
+
if (!contentType.includes('application/json')) return request;
|
|
84
|
+
if (null === request.body) return cloneWithoutJsonBodyHeaders(request);
|
|
85
|
+
try {
|
|
86
|
+
const bodyText = await request.clone().text();
|
|
87
|
+
if ('' === bodyText) return cloneWithoutJsonBodyHeaders(request);
|
|
88
|
+
JSON.parse(bodyText);
|
|
89
|
+
} catch {
|
|
90
|
+
return createBatchValidationResponse('Invalid JSON request body');
|
|
91
|
+
}
|
|
92
|
+
return request;
|
|
93
|
+
}
|
|
94
|
+
function toBatchItemError(id, status, message) {
|
|
95
|
+
return {
|
|
96
|
+
id,
|
|
97
|
+
status,
|
|
98
|
+
headers: [
|
|
99
|
+
[
|
|
100
|
+
'content-type',
|
|
101
|
+
'application/json; charset=utf-8'
|
|
102
|
+
]
|
|
103
|
+
],
|
|
104
|
+
body: (0, protocol_js_namespaceObject.encodeBatchText)(JSON.stringify({
|
|
105
|
+
message
|
|
106
|
+
}))
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
class BatchItemTimeoutError extends Error {
|
|
110
|
+
}
|
|
111
|
+
function promiseWithTimeout(effect, timeoutMs, onTimeout) {
|
|
112
|
+
if (timeoutMs <= 0) return effect;
|
|
113
|
+
return new Promise((resolve, reject)=>{
|
|
114
|
+
const timer = setTimeout(()=>{
|
|
115
|
+
const error = new BatchItemTimeoutError(`Batch item timeout after ${String(timeoutMs)}ms`);
|
|
116
|
+
onTimeout?.(error);
|
|
117
|
+
reject(error);
|
|
118
|
+
}, timeoutMs);
|
|
119
|
+
effect.then((value)=>{
|
|
120
|
+
clearTimeout(timer);
|
|
121
|
+
resolve(value);
|
|
122
|
+
}, (error)=>{
|
|
123
|
+
clearTimeout(timer);
|
|
124
|
+
reject(error);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
async function mapWithConcurrency(items, concurrency, mapper) {
|
|
129
|
+
if (0 === items.length) return [];
|
|
130
|
+
const normalizedConcurrency = Math.max(1, concurrency);
|
|
131
|
+
const output = new Array(items.length);
|
|
132
|
+
let index = 0;
|
|
133
|
+
const workers = Array.from({
|
|
134
|
+
length: Math.min(normalizedConcurrency, items.length)
|
|
135
|
+
}, async ()=>{
|
|
136
|
+
while(true){
|
|
137
|
+
const currentIndex = index;
|
|
138
|
+
index += 1;
|
|
139
|
+
if (currentIndex >= items.length) return;
|
|
140
|
+
output[currentIndex] = await mapper(items[currentIndex], currentIndex);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
await Promise.all(workers);
|
|
144
|
+
return output;
|
|
145
|
+
}
|
|
146
|
+
exports.BatchItemTimeoutError = __webpack_exports__.BatchItemTimeoutError;
|
|
147
|
+
exports.createBatchValidationResponse = __webpack_exports__.createBatchValidationResponse;
|
|
148
|
+
exports.isBatchRequestPayload = __webpack_exports__.isBatchRequestPayload;
|
|
149
|
+
exports.mapWithConcurrency = __webpack_exports__.mapWithConcurrency;
|
|
150
|
+
exports.normalizeBatchAllowedMethods = __webpack_exports__.normalizeBatchAllowedMethods;
|
|
151
|
+
exports.normalizeBatchPath = __webpack_exports__.normalizeBatchPath;
|
|
152
|
+
exports.prepareJsonRequestBody = __webpack_exports__.prepareJsonRequestBody;
|
|
153
|
+
exports.promiseWithTimeout = __webpack_exports__.promiseWithTimeout;
|
|
154
|
+
exports.toBatchItemError = __webpack_exports__.toBatchItemError;
|
|
155
|
+
exports.toHeaderRecord = __webpack_exports__.toHeaderRecord;
|
|
156
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
157
|
+
"BatchItemTimeoutError",
|
|
158
|
+
"createBatchValidationResponse",
|
|
159
|
+
"isBatchRequestPayload",
|
|
160
|
+
"mapWithConcurrency",
|
|
161
|
+
"normalizeBatchAllowedMethods",
|
|
162
|
+
"normalizeBatchPath",
|
|
163
|
+
"prepareJsonRequestBody",
|
|
164
|
+
"promiseWithTimeout",
|
|
165
|
+
"toBatchItemError",
|
|
166
|
+
"toHeaderRecord"
|
|
167
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
168
|
+
Object.defineProperty(exports, '__esModule', {
|
|
169
|
+
value: true
|
|
170
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
defineEffectBff: ()=>defineEffectBff,
|
|
32
|
+
defineEffectRpcBff: ()=>defineEffectRpcBff
|
|
33
|
+
});
|
|
34
|
+
const external_entry_shape_js_namespaceObject = require("../entry-shape.js");
|
|
35
|
+
const external_envelope_js_namespaceObject = require("./envelope.js");
|
|
36
|
+
const external_http_js_namespaceObject = require("./http.js");
|
|
37
|
+
const external_rpc_js_namespaceObject = require("./rpc.js");
|
|
38
|
+
function defineEffectBff(definition) {
|
|
39
|
+
const createHandler = (0, external_entry_shape_js_namespaceObject.registerValidatorAwareHandlerFactory)((options)=>{
|
|
40
|
+
const rpcDefinition = definition.rpc;
|
|
41
|
+
let mergedRpcOptions = rpcDefinition;
|
|
42
|
+
if (rpcDefinition && options?.rpc) mergedRpcOptions = {
|
|
43
|
+
...rpcDefinition,
|
|
44
|
+
...options.rpc
|
|
45
|
+
};
|
|
46
|
+
return (0, external_http_js_namespaceObject.createHttpApiHandler)({
|
|
47
|
+
api: definition.api,
|
|
48
|
+
layer: definition.layer,
|
|
49
|
+
openapi: options?.openapi,
|
|
50
|
+
rpc: mergedRpcOptions,
|
|
51
|
+
dataPlatform: (0, external_envelope_js_namespaceObject.mergeDataPlatformOptions)(definition.dataPlatform, options?.dataPlatform),
|
|
52
|
+
interceptRequest: definition.interceptRequest,
|
|
53
|
+
validateRequest: options?.validateRequest
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
const client = createLoaderMaterializedClientPlaceholder();
|
|
57
|
+
return {
|
|
58
|
+
...definition,
|
|
59
|
+
createHandler,
|
|
60
|
+
client
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const LOADER_CLIENT_IGNORED_KEYS = new Set([
|
|
64
|
+
'then',
|
|
65
|
+
'catch',
|
|
66
|
+
'finally',
|
|
67
|
+
'toJSON',
|
|
68
|
+
'$$typeof'
|
|
69
|
+
]);
|
|
70
|
+
function createLoaderMaterializedClientPlaceholder() {
|
|
71
|
+
const explain = (property)=>{
|
|
72
|
+
throw new Error(`[BFF][Effect] client.${String(property)} is not available here: the typed client only exists when the API entry is imported through the "@api/index" transformed path (the BFF loader replaces it with generated client code). On the server, use HttpApiClient or call the Effect layer directly.`);
|
|
73
|
+
};
|
|
74
|
+
return new Proxy(Object.create(null), {
|
|
75
|
+
get (_target, property) {
|
|
76
|
+
if ('symbol' == typeof property || LOADER_CLIENT_IGNORED_KEYS.has(property)) return;
|
|
77
|
+
return explain(property);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function defineEffectRpcBff(definition) {
|
|
82
|
+
const createHandler = (options)=>(0, external_rpc_js_namespaceObject.createRpcApiHandler)({
|
|
83
|
+
...definition,
|
|
84
|
+
...options
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
...definition,
|
|
88
|
+
createHandler
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
exports.defineEffectBff = __webpack_exports__.defineEffectBff;
|
|
92
|
+
exports.defineEffectRpcBff = __webpack_exports__.defineEffectRpcBff;
|
|
93
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
94
|
+
"defineEffectBff",
|
|
95
|
+
"defineEffectRpcBff"
|
|
96
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
97
|
+
Object.defineProperty(exports, '__esModule', {
|
|
98
|
+
value: true
|
|
99
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
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
|
+
mergeDataPlatformOptions: ()=>mergeDataPlatformOptions,
|
|
32
|
+
validateDataPlatformRequestEnvelope: ()=>validateDataPlatformRequestEnvelope
|
|
33
|
+
});
|
|
34
|
+
const index_js_namespaceObject = require("../../data-platform/index.js");
|
|
35
|
+
const external_routing_js_namespaceObject = require("./routing.js");
|
|
36
|
+
function createInvalidEnvelopeResponse(message, errors) {
|
|
37
|
+
return new Response(JSON.stringify({
|
|
38
|
+
message,
|
|
39
|
+
...errors && errors.length > 0 ? {
|
|
40
|
+
errors
|
|
41
|
+
} : {}
|
|
42
|
+
}), {
|
|
43
|
+
status: 400,
|
|
44
|
+
headers: {
|
|
45
|
+
'content-type': 'application/json; charset=utf-8'
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function validateDataPlatformRequestEnvelope(request, options) {
|
|
50
|
+
const isEnabled = options?.enabled ?? true;
|
|
51
|
+
if (!isEnabled) return null;
|
|
52
|
+
const envelopeHeader = options?.envelopeHeader || index_js_namespaceObject.DEFAULT_DATA_ENVELOPE_HEADER;
|
|
53
|
+
const encodedEnvelope = request.headers.get(envelopeHeader);
|
|
54
|
+
if (!encodedEnvelope) {
|
|
55
|
+
if (options?.requireEnvelope) return createInvalidEnvelopeResponse(`Missing required data envelope header: ${envelopeHeader}`);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const envelope = (0, index_js_namespaceObject.decodeRequestEnvelopeHeader)(encodedEnvelope);
|
|
59
|
+
if (!envelope) return createInvalidEnvelopeResponse(`Invalid data envelope header format: ${envelopeHeader}`);
|
|
60
|
+
const validation = (0, index_js_namespaceObject.validateRequestEnvelope)(envelope, {
|
|
61
|
+
expectedProtocolVersion: 1,
|
|
62
|
+
expectedNamespace: options?.expectedNamespace,
|
|
63
|
+
expectedOrigin: options?.validateOrigin === false ? void 0 : (0, external_routing_js_namespaceObject.getExpectedEnvelopeOrigin)(request),
|
|
64
|
+
requireTraceContext: options?.requireTraceContext
|
|
65
|
+
});
|
|
66
|
+
if (!validation.ok) return createInvalidEnvelopeResponse('Invalid data envelope', validation.errors);
|
|
67
|
+
if (envelope.selectionPlan) {
|
|
68
|
+
const selectionValidation = (0, index_js_namespaceObject.validateSelectionPlan)(envelope.selectionPlan, {
|
|
69
|
+
maxDepth: options?.selection?.maxDepth,
|
|
70
|
+
maxFields: options?.selection?.maxFields,
|
|
71
|
+
allowedLeafPaths: options?.selection?.allowedLeafPaths
|
|
72
|
+
});
|
|
73
|
+
if (!selectionValidation.ok) return createInvalidEnvelopeResponse('Invalid data envelope selection plan', selectionValidation.errors);
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
function mergeDataPlatformOptions(base, override) {
|
|
78
|
+
if (!base && !override) return;
|
|
79
|
+
const baseSelection = base?.selection;
|
|
80
|
+
const overrideSelection = override?.selection;
|
|
81
|
+
const baseBatch = base?.batch;
|
|
82
|
+
const overrideBatch = override?.batch;
|
|
83
|
+
return {
|
|
84
|
+
...base,
|
|
85
|
+
...override,
|
|
86
|
+
selection: baseSelection || overrideSelection ? {
|
|
87
|
+
...baseSelection,
|
|
88
|
+
...overrideSelection
|
|
89
|
+
} : void 0,
|
|
90
|
+
batch: baseBatch || overrideBatch ? {
|
|
91
|
+
...baseBatch,
|
|
92
|
+
...overrideBatch
|
|
93
|
+
} : void 0
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
exports.mergeDataPlatformOptions = __webpack_exports__.mergeDataPlatformOptions;
|
|
97
|
+
exports.validateDataPlatformRequestEnvelope = __webpack_exports__.validateDataPlatformRequestEnvelope;
|
|
98
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
99
|
+
"mergeDataPlatformOptions",
|
|
100
|
+
"validateDataPlatformRequestEnvelope"
|
|
101
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
102
|
+
Object.defineProperty(exports, '__esModule', {
|
|
103
|
+
value: true
|
|
104
|
+
});
|