@bleedingdev/modern-js-create-request 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/browser.js +85 -214
- package/dist/cjs/node.js +103 -224
- package/dist/cjs/policyCore.js +275 -0
- package/dist/cjs/requestContext.js +8 -20
- package/dist/cjs/traceparent.js +56 -0
- package/dist/esm/browser.mjs +37 -185
- package/dist/esm/node.mjs +44 -184
- package/dist/esm/policyCore.mjs +174 -0
- package/dist/esm/requestContext.mjs +1 -12
- package/dist/esm/traceparent.mjs +18 -0
- package/dist/esm-node/browser.mjs +37 -185
- package/dist/esm-node/node.mjs +44 -184
- package/dist/esm-node/policyCore.mjs +175 -0
- package/dist/esm-node/requestContext.mjs +1 -12
- package/dist/esm-node/traceparent.mjs +19 -0
- package/dist/types/browser.d.ts +3 -23
- package/dist/types/node.d.ts +3 -23
- package/dist/types/policyCore.d.ts +108 -0
- package/dist/types/traceparent.d.ts +10 -0
- package/dist/types/types.d.ts +2 -1
- package/package.json +6 -5
package/dist/cjs/node.js
CHANGED
|
@@ -3,9 +3,15 @@ var __webpack_modules__ = {
|
|
|
3
3
|
"./handleRes" (module) {
|
|
4
4
|
module.exports = require("./handleRes.js");
|
|
5
5
|
},
|
|
6
|
+
"./policyCore" (module) {
|
|
7
|
+
module.exports = require("./policyCore.js");
|
|
8
|
+
},
|
|
6
9
|
"./requestContext" (module) {
|
|
7
10
|
module.exports = require("./requestContext.js");
|
|
8
11
|
},
|
|
12
|
+
"./traceparent" (module) {
|
|
13
|
+
module.exports = require("./traceparent.js");
|
|
14
|
+
},
|
|
9
15
|
"./transport" (module) {
|
|
10
16
|
module.exports = require("./transport.js");
|
|
11
17
|
},
|
|
@@ -76,12 +82,13 @@ var __webpack_exports__ = {};
|
|
|
76
82
|
var path_to_regexp__rspack_import_1 = __webpack_require__("path-to-regexp");
|
|
77
83
|
var qs__rspack_import_2 = __webpack_require__("qs");
|
|
78
84
|
var _handleRes__rspack_import_3 = __webpack_require__("./handleRes");
|
|
79
|
-
var
|
|
80
|
-
var
|
|
81
|
-
var
|
|
82
|
-
var
|
|
85
|
+
var _policyCore__rspack_import_4 = __webpack_require__("./policyCore");
|
|
86
|
+
var _transport__rspack_import_5 = __webpack_require__("./transport");
|
|
87
|
+
var _types__rspack_import_6 = __webpack_require__("./types");
|
|
88
|
+
var _utiles__rspack_import_7 = __webpack_require__("./utiles");
|
|
89
|
+
var _requestContext__rspack_import_8 = __webpack_require__("./requestContext");
|
|
83
90
|
var __rspack_reexport = {};
|
|
84
|
-
for(const __rspack_import_key in
|
|
91
|
+
for(const __rspack_import_key in _requestContext__rspack_import_8)if ([
|
|
85
92
|
"IdentityBindingViolationError",
|
|
86
93
|
"configure",
|
|
87
94
|
"OperationContractViolationError",
|
|
@@ -91,10 +98,11 @@ var __webpack_exports__ = {};
|
|
|
91
98
|
"createUploader",
|
|
92
99
|
"CrossOriginEnvelopePolicyError",
|
|
93
100
|
"createRequest"
|
|
94
|
-
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>
|
|
101
|
+
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_requestContext__rspack_import_8[__rspack_import_key];
|
|
95
102
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
103
|
+
var _traceparent__rspack_import_9 = __webpack_require__("./traceparent");
|
|
96
104
|
var __rspack_reexport = {};
|
|
97
|
-
for(const __rspack_import_key in
|
|
105
|
+
for(const __rspack_import_key in _traceparent__rspack_import_9)if ([
|
|
98
106
|
"IdentityBindingViolationError",
|
|
99
107
|
"configure",
|
|
100
108
|
"OperationContractViolationError",
|
|
@@ -104,7 +112,20 @@ var __webpack_exports__ = {};
|
|
|
104
112
|
"createUploader",
|
|
105
113
|
"CrossOriginEnvelopePolicyError",
|
|
106
114
|
"createRequest"
|
|
107
|
-
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>
|
|
115
|
+
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_traceparent__rspack_import_9[__rspack_import_key];
|
|
116
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
117
|
+
var __rspack_reexport = {};
|
|
118
|
+
for(const __rspack_import_key in _types__rspack_import_6)if ([
|
|
119
|
+
"IdentityBindingViolationError",
|
|
120
|
+
"configure",
|
|
121
|
+
"OperationContractViolationError",
|
|
122
|
+
"default",
|
|
123
|
+
"ProducerClientNotInitializedError",
|
|
124
|
+
"ProducerDomainNotConfiguredError",
|
|
125
|
+
"createUploader",
|
|
126
|
+
"CrossOriginEnvelopePolicyError",
|
|
127
|
+
"createRequest"
|
|
128
|
+
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_types__rspack_import_6[__rspack_import_key];
|
|
108
129
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
109
130
|
const realRequest = new Map();
|
|
110
131
|
const realAllowedHeaders = new Map();
|
|
@@ -115,163 +136,59 @@ var __webpack_exports__ = {};
|
|
|
115
136
|
const realIdentityBinding = new Map();
|
|
116
137
|
const realOperationContract = new Map();
|
|
117
138
|
const domainMap = new Map();
|
|
118
|
-
const
|
|
119
|
-
const TRACEPARENT_HEADER = 'traceparent';
|
|
120
|
-
const OPERATION_CONTEXT_DETAIL_HEADER = _types__rspack_import_5.BFF_OPERATION_CONTEXT_DETAIL_HEADER;
|
|
121
|
-
const TRACEPARENT_REGEX = /^00-([0-9a-f]{32})-([0-9a-f]{16})-[0-9a-f]{2}$/i;
|
|
122
|
-
const isStrictDefaultRequestIdEnabled = ()=>'true' === process.env.MODERN_BFF_STRICT_DEFAULT_REQUEST_ID;
|
|
123
|
-
const isSecuredRequestId = (requestId)=>'default' !== requestId || isStrictDefaultRequestIdEnabled();
|
|
124
|
-
const firstHeaderValue = (value)=>Array.isArray(value) ? value[0] : value;
|
|
125
|
-
const findHeaderKey = (headers, header)=>{
|
|
126
|
-
const normalized = header.toLowerCase();
|
|
127
|
-
return Object.keys(headers).find((key)=>key.toLowerCase() === normalized);
|
|
128
|
-
};
|
|
129
|
-
const readHeader = (headers, header)=>{
|
|
130
|
-
const key = findHeaderKey(headers, header);
|
|
131
|
-
return 'string' == typeof key ? headers[key] : void 0;
|
|
132
|
-
};
|
|
133
|
-
const writeHeader = (headers, header, value)=>{
|
|
134
|
-
if (void 0 === value) return;
|
|
135
|
-
const key = findHeaderKey(headers, header);
|
|
136
|
-
if ('string' == typeof key && key !== header) delete headers[key];
|
|
137
|
-
headers[header] = value;
|
|
138
|
-
};
|
|
139
|
-
const deleteHeader = (headers, header)=>{
|
|
140
|
-
const key = findHeaderKey(headers, header);
|
|
141
|
-
if ('string' == typeof key) delete headers[key];
|
|
142
|
-
};
|
|
143
|
-
const toOrigin = (value)=>{
|
|
144
|
-
if (!value) return;
|
|
145
|
-
try {
|
|
146
|
-
return new URL(value).origin;
|
|
147
|
-
} catch (error) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
const parseTraceparent = (value)=>{
|
|
152
|
-
const traceparent = firstHeaderValue(value);
|
|
153
|
-
if ('string' != typeof traceparent) return;
|
|
154
|
-
const match = traceparent.trim().match(TRACEPARENT_REGEX);
|
|
155
|
-
if (!match) return;
|
|
156
|
-
const [, traceId, spanId] = match;
|
|
157
|
-
if (!traceId || !spanId) return;
|
|
158
|
-
return {
|
|
159
|
-
traceId: traceId.toLowerCase(),
|
|
160
|
-
spanId: spanId.toLowerCase()
|
|
161
|
-
};
|
|
162
|
-
};
|
|
139
|
+
const OPERATION_CONTEXT_DETAIL_HEADER = _types__rspack_import_6.BFF_OPERATION_CONTEXT_DETAIL_HEADER;
|
|
163
140
|
const resolveSourceOrigin = (headers)=>{
|
|
164
|
-
const origin = toOrigin(firstHeaderValue(headers.origin));
|
|
141
|
+
const origin = (0, _policyCore__rspack_import_4.toOrigin)((0, _policyCore__rspack_import_4.firstHeaderValue)(headers.origin));
|
|
165
142
|
if (origin) return origin;
|
|
166
|
-
const referer = toOrigin(firstHeaderValue(headers.referer));
|
|
143
|
+
const referer = (0, _policyCore__rspack_import_4.toOrigin)((0, _policyCore__rspack_import_4.firstHeaderValue)(headers.referer));
|
|
167
144
|
if (referer) return referer;
|
|
168
|
-
const host = firstHeaderValue(headers.host);
|
|
145
|
+
const host = (0, _policyCore__rspack_import_4.firstHeaderValue)(headers.host);
|
|
169
146
|
if (!host) return;
|
|
170
|
-
const proto = firstHeaderValue(headers['x-forwarded-proto']) || 'http';
|
|
147
|
+
const proto = (0, _policyCore__rspack_import_4.firstHeaderValue)(headers['x-forwarded-proto']) || 'http';
|
|
171
148
|
return `${proto}://${host}`;
|
|
172
149
|
};
|
|
173
|
-
const
|
|
150
|
+
const readIncomingWebHeaders = ()=>{
|
|
151
|
+
try {
|
|
152
|
+
return _modern_js_runtime_utils_node__rspack_import_0.storage.useContext().headers || {};
|
|
153
|
+
} catch (error) {
|
|
154
|
+
return {};
|
|
155
|
+
}
|
|
156
|
+
};
|
|
174
157
|
const originFetch = (...params)=>{
|
|
175
158
|
const [, init] = params;
|
|
176
159
|
if (init?.method?.toLowerCase() === 'get') init.body = void 0;
|
|
177
160
|
return fetch(...params).then(_handleRes__rspack_import_3.handleRes);
|
|
178
161
|
};
|
|
179
|
-
const
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const operationId = rawOperationId.startsWith(`${requestId}:`) ? rawOperationId : `${requestId}:${rawOperationId}`;
|
|
184
|
-
const traceparentValue = operationContext?.traceparent || ('string' == typeof firstHeaderValue(traceparent) ? String(firstHeaderValue(traceparent)) : void 0);
|
|
185
|
-
const parsedTraceContext = operationContext?.traceId && operationContext?.spanId ? {
|
|
186
|
-
traceId: operationContext.traceId,
|
|
187
|
-
spanId: operationContext.spanId
|
|
188
|
-
} : parseTraceparent(traceparentValue);
|
|
189
|
-
return {
|
|
162
|
+
const attachEnvelopeHeaderIfRequired = (headers, requestId, url, webRequestHeaders)=>{
|
|
163
|
+
const shouldRequireEnvelope = realRequireEnvelope.get(requestId) ?? (0, _policyCore__rspack_import_4.isSecuredRequestId)(requestId);
|
|
164
|
+
if (!shouldRequireEnvelope) return;
|
|
165
|
+
headers[_types__rspack_import_6.BFF_ENVELOPE_HEADER] = (0, _policyCore__rspack_import_4.buildEnvelopeHeaderValue)({
|
|
190
166
|
requestId,
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
...'number' == typeof operationContext?.operationVersion ? {
|
|
198
|
-
operationVersion: operationContext.operationVersion
|
|
199
|
-
} : {},
|
|
200
|
-
...traceparentValue ? {
|
|
201
|
-
traceparent: traceparentValue
|
|
202
|
-
} : {},
|
|
203
|
-
...parsedTraceContext ? {
|
|
204
|
-
traceId: parsedTraceContext.traceId,
|
|
205
|
-
spanId: parsedTraceContext.spanId
|
|
206
|
-
} : {}
|
|
207
|
-
};
|
|
208
|
-
};
|
|
209
|
-
class ProducerClientNotInitializedError extends Error {
|
|
210
|
-
constructor(requestId){
|
|
211
|
-
super(`Producer client "${requestId}" is not initialized. Call initProducerClient() (or configure()) before using generated APIs for this requestId.`), this.code = 'BFF_PRODUCER_CLIENT_NOT_INITIALIZED';
|
|
212
|
-
this.name = 'ProducerClientNotInitializedError';
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
class ProducerDomainNotConfiguredError extends Error {
|
|
216
|
-
constructor(requestId){
|
|
217
|
-
super(`Producer client "${requestId}" must provide setDomain() during configure().`), this.code = 'BFF_PRODUCER_DOMAIN_NOT_CONFIGURED';
|
|
218
|
-
this.name = 'ProducerDomainNotConfiguredError';
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
class CrossOriginEnvelopePolicyError extends Error {
|
|
222
|
-
constructor(requestId, sourceOrigin, targetOrigin){
|
|
223
|
-
super(`Cross-origin envelope is not allowed for producer "${requestId}" (${sourceOrigin || 'unknown-origin'} -> ${targetOrigin || 'unknown-origin'}). Configure allowCrossOriginEnvelope to explicitly allow this flow.`), this.code = 'BFF_CROSS_ORIGIN_ENVELOPE_NOT_ALLOWED';
|
|
224
|
-
this.name = 'CrossOriginEnvelopePolicyError';
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
class IdentityBindingViolationError extends Error {
|
|
228
|
-
constructor(violation){
|
|
229
|
-
super(`Identity header "${violation.header}" for producer "${violation.requestId}" was rejected by server-derived identity binding.`), this.code = 'BFF_IDENTITY_BINDING_VIOLATION';
|
|
230
|
-
this.name = 'IdentityBindingViolationError';
|
|
231
|
-
this.violation = violation;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
class OperationContractViolationError extends Error {
|
|
235
|
-
constructor(violation){
|
|
236
|
-
super(`Operation contract violation "${violation.reason}" for producer "${violation.requestId}" operation "${violation.operationId}".`), this.code = 'BFF_OPERATION_CONTRACT_VIOLATION';
|
|
237
|
-
this.name = 'OperationContractViolationError';
|
|
238
|
-
this.violation = violation;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
const validateOperationContract = (requestId, contextPayload)=>{
|
|
242
|
-
const operationContract = realOperationContract.get(requestId);
|
|
243
|
-
const operationContractEnabled = operationContract?.enabled ?? isSecuredRequestId(requestId);
|
|
244
|
-
if (!operationContractEnabled) return;
|
|
245
|
-
const strict = operationContract?.strict ?? true;
|
|
246
|
-
const requireSchemaHash = operationContract?.requireSchemaHash ?? true;
|
|
247
|
-
const requireOperationVersion = operationContract?.requireOperationVersion ?? true;
|
|
248
|
-
const maybeReportViolation = (reason)=>{
|
|
249
|
-
const violation = {
|
|
250
|
-
requestId,
|
|
251
|
-
target: 'server',
|
|
252
|
-
operationId: contextPayload.operationId,
|
|
253
|
-
routePath: contextPayload.routePath,
|
|
254
|
-
method: contextPayload.method,
|
|
255
|
-
schemaHash: 'string' == typeof contextPayload.schemaHash ? contextPayload.schemaHash : void 0,
|
|
256
|
-
operationVersion: 'number' == typeof contextPayload.operationVersion ? contextPayload.operationVersion : void 0,
|
|
257
|
-
reason
|
|
258
|
-
};
|
|
259
|
-
operationContract?.onViolation?.(violation);
|
|
260
|
-
if (strict) throw new OperationContractViolationError(violation);
|
|
261
|
-
};
|
|
262
|
-
if (requireSchemaHash && 'string' != typeof contextPayload.schemaHash) maybeReportViolation('missing_schema_hash');
|
|
263
|
-
if (requireOperationVersion && 'number' != typeof contextPayload.operationVersion) maybeReportViolation('missing_operation_version');
|
|
167
|
+
target: 'server',
|
|
168
|
+
sourceOrigin: resolveSourceOrigin(webRequestHeaders),
|
|
169
|
+
targetOrigin: (0, _policyCore__rspack_import_4.toOrigin)(url),
|
|
170
|
+
traceContext: (0, _policyCore__rspack_import_4.parseTraceparentValue)((0, _policyCore__rspack_import_4.readHeader)(headers, _policyCore__rspack_import_4.TRACEPARENT_HEADER)),
|
|
171
|
+
allowCrossOriginEnvelope: realAllowCrossOriginEnvelope.get(requestId)
|
|
172
|
+
});
|
|
264
173
|
};
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
174
|
+
const attachSecuredOperationHeaders = (headers, requestId, method, path, operationContext)=>{
|
|
175
|
+
if (!(0, _policyCore__rspack_import_4.isSecuredRequestId)(requestId)) return;
|
|
176
|
+
(0, _policyCore__rspack_import_4.attachOperationContextHeaders)({
|
|
177
|
+
headers,
|
|
178
|
+
requestId,
|
|
179
|
+
target: 'server',
|
|
180
|
+
method,
|
|
181
|
+
path,
|
|
182
|
+
operationContext,
|
|
183
|
+
operationContract: realOperationContract.get(requestId),
|
|
184
|
+
operationContextHeader: _types__rspack_import_6.BFF_OPERATION_CONTEXT_HEADER,
|
|
185
|
+
operationContextDetailHeader: OPERATION_CONTEXT_DETAIL_HEADER
|
|
186
|
+
});
|
|
270
187
|
};
|
|
271
188
|
const configure = (options)=>{
|
|
272
189
|
const { request, interceptor, allowedHeaders, resolveHeaders, transport, requireEnvelope, allowCrossOriginEnvelope, identityBinding, operationContract, setDomain, requestId = 'default' } = options;
|
|
273
190
|
const hasExistingDomain = domainMap.has(requestId);
|
|
274
|
-
if ('default' !== requestId && !setDomain && !hasExistingDomain) throw new ProducerDomainNotConfiguredError(requestId);
|
|
191
|
+
if ('default' !== requestId && !setDomain && !hasExistingDomain) throw new _policyCore__rspack_import_4.ProducerDomainNotConfiguredError(requestId);
|
|
275
192
|
let configuredRequest = request || originFetch;
|
|
276
193
|
if (interceptor && !request) configuredRequest = interceptor(fetch);
|
|
277
194
|
if (Array.isArray(allowedHeaders)) realAllowedHeaders.set(requestId, allowedHeaders);
|
|
@@ -286,7 +203,7 @@ var __webpack_exports__ = {};
|
|
|
286
203
|
target: 'server',
|
|
287
204
|
requestId
|
|
288
205
|
});
|
|
289
|
-
if ('default' !== requestId && isEmptyDomain(resolvedDomain)) throw new ProducerDomainNotConfiguredError(requestId);
|
|
206
|
+
if ('default' !== requestId && (0, _policyCore__rspack_import_4.isEmptyDomain)(resolvedDomain)) throw new _policyCore__rspack_import_4.ProducerDomainNotConfiguredError(requestId);
|
|
290
207
|
if ('string' == typeof resolvedDomain) domainMap.set(requestId, resolvedDomain);
|
|
291
208
|
}
|
|
292
209
|
realRequest.set(requestId, configuredRequest);
|
|
@@ -309,21 +226,16 @@ var __webpack_exports__ = {};
|
|
|
309
226
|
const getFinalPath = (0, path_to_regexp__rspack_import_1.compile)(path, {
|
|
310
227
|
encode: encodeURIComponent
|
|
311
228
|
});
|
|
312
|
-
const keyNames = extractPathParamNames(path);
|
|
229
|
+
const keyNames = (0, _policyCore__rspack_import_4.extractPathParamNames)(path);
|
|
313
230
|
const sender = (...args)=>{
|
|
314
|
-
const fetcher =
|
|
315
|
-
|
|
316
|
-
try {
|
|
317
|
-
webRequestHeaders = _modern_js_runtime_utils_node__rspack_import_0.storage.useContext().headers || {};
|
|
318
|
-
} catch (error) {
|
|
319
|
-
webRequestHeaders = {};
|
|
320
|
-
}
|
|
231
|
+
const fetcher = (0, _policyCore__rspack_import_4.resolveConfiguredRequest)(realRequest, requestId, fetch1);
|
|
232
|
+
const webRequestHeaders = readIncomingWebHeaders();
|
|
321
233
|
let body;
|
|
322
234
|
let headers;
|
|
323
235
|
let url;
|
|
324
236
|
if ('inputParams' === httpMethodDecider) {
|
|
325
237
|
const configDomain = domainMap.get(requestId);
|
|
326
|
-
if ('default' !== requestId && isEmptyDomain(configDomain)) throw new ProducerDomainNotConfiguredError(requestId);
|
|
238
|
+
if ('default' !== requestId && (0, _policyCore__rspack_import_4.isEmptyDomain)(configDomain)) throw new _policyCore__rspack_import_4.ProducerDomainNotConfiguredError(requestId);
|
|
327
239
|
url = `${configDomain || `http://127.0.0.1:${port}`}${path}`;
|
|
328
240
|
body = args;
|
|
329
241
|
headers = {
|
|
@@ -347,17 +259,17 @@ var __webpack_exports__ = {};
|
|
|
347
259
|
...payload.headers
|
|
348
260
|
} : {};
|
|
349
261
|
const identityBinding = realIdentityBinding.get(requestId);
|
|
350
|
-
const identityBindingEnabled = identityBinding?.enabled ?? isSecuredRequestId(requestId);
|
|
351
|
-
const identityBindingStrict = identityBinding?.strict ?? isSecuredRequestId(requestId);
|
|
352
|
-
const protectedIdentityHeaders = (identityBinding?.protectedHeaders ||
|
|
262
|
+
const identityBindingEnabled = identityBinding?.enabled ?? (0, _policyCore__rspack_import_4.isSecuredRequestId)(requestId);
|
|
263
|
+
const identityBindingStrict = identityBinding?.strict ?? (0, _policyCore__rspack_import_4.isSecuredRequestId)(requestId);
|
|
264
|
+
const protectedIdentityHeaders = (identityBinding?.protectedHeaders || _types__rspack_import_6.BFF_DEFAULT_PROTECTED_IDENTITY_HEADERS).map((header)=>header.toLowerCase());
|
|
353
265
|
const targetAllowedHeaders = realAllowedHeaders.get(requestId) || [];
|
|
354
266
|
const forwardedHeaders = {};
|
|
355
267
|
for (const key of targetAllowedHeaders)if (void 0 !== webRequestHeaders[key]) forwardedHeaders[key] = webRequestHeaders[key];
|
|
356
268
|
if (identityBindingEnabled) {
|
|
357
269
|
const derivedIdentityHeaders = {};
|
|
358
270
|
for (const header of protectedIdentityHeaders){
|
|
359
|
-
const incomingHeaderValue = readHeader(webRequestHeaders, header);
|
|
360
|
-
if (void 0 !== incomingHeaderValue) writeHeader(derivedIdentityHeaders, header, incomingHeaderValue);
|
|
271
|
+
const incomingHeaderValue = (0, _policyCore__rspack_import_4.readHeader)(webRequestHeaders, header);
|
|
272
|
+
if (void 0 !== incomingHeaderValue) (0, _policyCore__rspack_import_4.writeHeader)(derivedIdentityHeaders, header, incomingHeaderValue);
|
|
361
273
|
}
|
|
362
274
|
const customDerivedHeaders = identityBinding?.deriveHeaders?.({
|
|
363
275
|
requestId,
|
|
@@ -370,26 +282,26 @@ var __webpack_exports__ = {};
|
|
|
370
282
|
]
|
|
371
283
|
});
|
|
372
284
|
if (customDerivedHeaders && 'object' == typeof customDerivedHeaders) for (const header of protectedIdentityHeaders){
|
|
373
|
-
const customValue = readHeader(customDerivedHeaders, header);
|
|
374
|
-
if (void 0 !== customValue) writeHeader(derivedIdentityHeaders, header, customValue);
|
|
285
|
+
const customValue = (0, _policyCore__rspack_import_4.readHeader)(customDerivedHeaders, header);
|
|
286
|
+
if (void 0 !== customValue) (0, _policyCore__rspack_import_4.writeHeader)(derivedIdentityHeaders, header, customValue);
|
|
375
287
|
}
|
|
376
288
|
for (const header of protectedIdentityHeaders){
|
|
377
|
-
const attemptedValue = readHeader(headers, header);
|
|
289
|
+
const attemptedValue = (0, _policyCore__rspack_import_4.readHeader)(headers, header);
|
|
378
290
|
if (void 0 === attemptedValue) continue;
|
|
379
291
|
const violation = {
|
|
380
292
|
requestId,
|
|
381
293
|
target: 'server',
|
|
382
294
|
header,
|
|
383
295
|
attemptedValue,
|
|
384
|
-
derivedValue: readHeader(derivedIdentityHeaders, header),
|
|
296
|
+
derivedValue: (0, _policyCore__rspack_import_4.readHeader)(derivedIdentityHeaders, header),
|
|
385
297
|
reason: identityBindingStrict ? 'client_override_rejected' : 'client_override_blocked'
|
|
386
298
|
};
|
|
387
299
|
identityBinding?.onViolation?.(violation);
|
|
388
|
-
if (identityBindingStrict) throw new IdentityBindingViolationError(violation);
|
|
389
|
-
deleteHeader(headers, header);
|
|
300
|
+
if (identityBindingStrict) throw new _policyCore__rspack_import_4.IdentityBindingViolationError(violation);
|
|
301
|
+
(0, _policyCore__rspack_import_4.deleteHeader)(headers, header);
|
|
390
302
|
}
|
|
391
303
|
Object.keys(derivedIdentityHeaders).forEach((header)=>{
|
|
392
|
-
writeHeader(forwardedHeaders, header, derivedIdentityHeaders[header]);
|
|
304
|
+
(0, _policyCore__rspack_import_4.writeHeader)(forwardedHeaders, header, derivedIdentityHeaders[header]);
|
|
393
305
|
});
|
|
394
306
|
}
|
|
395
307
|
const resolveHeaders = realResolveHeaders.get(requestId);
|
|
@@ -421,57 +333,19 @@ var __webpack_exports__ = {};
|
|
|
421
333
|
body = 'object' == typeof payload.formUrlencoded ? (0, qs__rspack_import_2.stringify)(payload.formUrlencoded) : payload.formUrlencoded;
|
|
422
334
|
}
|
|
423
335
|
const configDomain = domainMap.get(requestId);
|
|
424
|
-
if ('default' !== requestId && isEmptyDomain(configDomain)) throw new ProducerDomainNotConfiguredError(requestId);
|
|
336
|
+
if ('default' !== requestId && (0, _policyCore__rspack_import_4.isEmptyDomain)(configDomain)) throw new _policyCore__rspack_import_4.ProducerDomainNotConfiguredError(requestId);
|
|
425
337
|
url = `${configDomain || `http://127.0.0.1:${port}`}${finalPath}`;
|
|
426
338
|
}
|
|
427
|
-
if (void 0 === readHeader(headers, TRACEPARENT_HEADER)) {
|
|
428
|
-
const incomingTraceparent = firstHeaderValue(readHeader(webRequestHeaders, TRACEPARENT_HEADER));
|
|
429
|
-
if ('string' == typeof incomingTraceparent) writeHeader(headers, TRACEPARENT_HEADER, incomingTraceparent);
|
|
430
|
-
}
|
|
431
|
-
if (void 0 === readHeader(headers, TRACEPARENT_HEADER) && operationContext?.traceparent) writeHeader(headers, TRACEPARENT_HEADER, operationContext.traceparent);
|
|
432
|
-
const shouldRequireEnvelope = realRequireEnvelope.get(requestId) ?? isSecuredRequestId(requestId);
|
|
433
|
-
if (shouldRequireEnvelope) {
|
|
434
|
-
const sourceOrigin = resolveSourceOrigin(webRequestHeaders);
|
|
435
|
-
const targetOrigin = toOrigin(url);
|
|
436
|
-
const traceContext = parseTraceparent(readHeader(headers, TRACEPARENT_HEADER));
|
|
437
|
-
const isCrossOrigin = Boolean(sourceOrigin) && Boolean(targetOrigin) && sourceOrigin !== targetOrigin;
|
|
438
|
-
if (isCrossOrigin) {
|
|
439
|
-
const policy = realAllowCrossOriginEnvelope.get(requestId);
|
|
440
|
-
const isAllowed = 'function' == typeof policy ? policy({
|
|
441
|
-
requestId,
|
|
442
|
-
sourceOrigin,
|
|
443
|
-
targetOrigin,
|
|
444
|
-
target: 'server'
|
|
445
|
-
}) : true === policy;
|
|
446
|
-
if (!isAllowed) throw new CrossOriginEnvelopePolicyError(requestId, sourceOrigin, targetOrigin);
|
|
447
|
-
}
|
|
448
|
-
headers[_types__rspack_import_5.BFF_ENVELOPE_HEADER] = JSON.stringify({
|
|
449
|
-
requestId,
|
|
450
|
-
target: 'server',
|
|
451
|
-
timestamp: Date.now(),
|
|
452
|
-
sourceOrigin,
|
|
453
|
-
targetOrigin,
|
|
454
|
-
...traceContext ? {
|
|
455
|
-
traceId: traceContext.traceId,
|
|
456
|
-
spanId: traceContext.spanId
|
|
457
|
-
} : {}
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
if (isSecuredRequestId(requestId)) {
|
|
461
|
-
const contextPayload = buildOperationContext({
|
|
462
|
-
requestId,
|
|
463
|
-
method,
|
|
464
|
-
path,
|
|
465
|
-
operationContext,
|
|
466
|
-
traceparent: readHeader(headers, TRACEPARENT_HEADER)
|
|
467
|
-
});
|
|
468
|
-
validateOperationContract(requestId, contextPayload);
|
|
469
|
-
if (void 0 === readHeader(headers, _types__rspack_import_5.BFF_OPERATION_CONTEXT_HEADER)) writeHeader(headers, _types__rspack_import_5.BFF_OPERATION_CONTEXT_HEADER, contextPayload.operationId);
|
|
470
|
-
writeHeader(headers, OPERATION_CONTEXT_DETAIL_HEADER, JSON.stringify(contextPayload));
|
|
339
|
+
if (void 0 === (0, _policyCore__rspack_import_4.readHeader)(headers, _policyCore__rspack_import_4.TRACEPARENT_HEADER)) {
|
|
340
|
+
const incomingTraceparent = (0, _policyCore__rspack_import_4.firstHeaderValue)((0, _policyCore__rspack_import_4.readHeader)(webRequestHeaders, _policyCore__rspack_import_4.TRACEPARENT_HEADER));
|
|
341
|
+
if ('string' == typeof incomingTraceparent) (0, _policyCore__rspack_import_4.writeHeader)(headers, _policyCore__rspack_import_4.TRACEPARENT_HEADER, incomingTraceparent);
|
|
471
342
|
}
|
|
343
|
+
if (void 0 === (0, _policyCore__rspack_import_4.readHeader)(headers, _policyCore__rspack_import_4.TRACEPARENT_HEADER) && operationContext?.traceparent) (0, _policyCore__rspack_import_4.writeHeader)(headers, _policyCore__rspack_import_4.TRACEPARENT_HEADER, operationContext.traceparent);
|
|
344
|
+
attachEnvelopeHeaderIfRequired(headers, requestId, url, webRequestHeaders);
|
|
345
|
+
attachSecuredOperationHeaders(headers, requestId, method, path, operationContext);
|
|
472
346
|
if ('get' === method.toLowerCase()) body = void 0;
|
|
473
347
|
headers.accept = "application/json,*/*;q=0.8";
|
|
474
|
-
return (0,
|
|
348
|
+
return (0, _transport__rspack_import_5.executeWithResilience)({
|
|
475
349
|
requestId,
|
|
476
350
|
target: 'server',
|
|
477
351
|
method,
|
|
@@ -487,12 +361,17 @@ var __webpack_exports__ = {};
|
|
|
487
361
|
};
|
|
488
362
|
return sender;
|
|
489
363
|
};
|
|
490
|
-
const createUploader = ({ path, requestId = 'default' })=>{
|
|
364
|
+
const createUploader = ({ path, requestId = 'default', operationContext })=>{
|
|
491
365
|
const sender = (...args)=>{
|
|
492
|
-
const fetcher =
|
|
493
|
-
const { body, headers } = (0,
|
|
366
|
+
const fetcher = (0, _policyCore__rspack_import_4.resolveConfiguredRequest)(realRequest, requestId, originFetch);
|
|
367
|
+
const { body, headers: uploadHeaders } = (0, _utiles__rspack_import_7.getUploadPayload)(args);
|
|
368
|
+
const headers = {
|
|
369
|
+
...uploadHeaders
|
|
370
|
+
};
|
|
494
371
|
const configDomain = domainMap.get(requestId);
|
|
495
372
|
const finalURL = `${configDomain || ''}${path}`;
|
|
373
|
+
attachEnvelopeHeaderIfRequired(headers, requestId, finalURL, readIncomingWebHeaders());
|
|
374
|
+
attachSecuredOperationHeaders(headers, requestId, 'POST', path, operationContext);
|
|
496
375
|
return fetcher(finalURL, {
|
|
497
376
|
method: 'POST',
|
|
498
377
|
body,
|
|
@@ -502,11 +381,11 @@ var __webpack_exports__ = {};
|
|
|
502
381
|
return sender;
|
|
503
382
|
};
|
|
504
383
|
__webpack_require__.d(__webpack_exports__, {
|
|
505
|
-
CrossOriginEnvelopePolicyError: ()=>CrossOriginEnvelopePolicyError,
|
|
506
|
-
IdentityBindingViolationError: ()=>IdentityBindingViolationError,
|
|
507
|
-
OperationContractViolationError: ()=>OperationContractViolationError,
|
|
508
|
-
ProducerClientNotInitializedError: ()=>ProducerClientNotInitializedError,
|
|
509
|
-
ProducerDomainNotConfiguredError: ()=>ProducerDomainNotConfiguredError
|
|
384
|
+
CrossOriginEnvelopePolicyError: ()=>_policyCore__rspack_import_4.CrossOriginEnvelopePolicyError,
|
|
385
|
+
IdentityBindingViolationError: ()=>_policyCore__rspack_import_4.IdentityBindingViolationError,
|
|
386
|
+
OperationContractViolationError: ()=>_policyCore__rspack_import_4.OperationContractViolationError,
|
|
387
|
+
ProducerClientNotInitializedError: ()=>_policyCore__rspack_import_4.ProducerClientNotInitializedError,
|
|
388
|
+
ProducerDomainNotConfiguredError: ()=>_policyCore__rspack_import_4.ProducerDomainNotConfiguredError
|
|
510
389
|
}, {
|
|
511
390
|
configure: configure,
|
|
512
391
|
createRequest: createRequest,
|