@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/browser.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
|
},
|
|
@@ -72,12 +78,27 @@ var __webpack_exports__ = {};
|
|
|
72
78
|
var path_to_regexp__rspack_import_0 = __webpack_require__("path-to-regexp");
|
|
73
79
|
var qs__rspack_import_1 = __webpack_require__("qs");
|
|
74
80
|
var _handleRes__rspack_import_2 = __webpack_require__("./handleRes");
|
|
75
|
-
var
|
|
76
|
-
var
|
|
77
|
-
var
|
|
78
|
-
var
|
|
81
|
+
var _policyCore__rspack_import_3 = __webpack_require__("./policyCore");
|
|
82
|
+
var _transport__rspack_import_4 = __webpack_require__("./transport");
|
|
83
|
+
var _types__rspack_import_5 = __webpack_require__("./types");
|
|
84
|
+
var _utiles__rspack_import_6 = __webpack_require__("./utiles");
|
|
85
|
+
var _requestContext__rspack_import_7 = __webpack_require__("./requestContext");
|
|
86
|
+
var __rspack_reexport = {};
|
|
87
|
+
for(const __rspack_import_key in _requestContext__rspack_import_7)if ([
|
|
88
|
+
"IdentityBindingViolationError",
|
|
89
|
+
"configure",
|
|
90
|
+
"OperationContractViolationError",
|
|
91
|
+
"default",
|
|
92
|
+
"ProducerClientNotInitializedError",
|
|
93
|
+
"ProducerDomainNotConfiguredError",
|
|
94
|
+
"createUploader",
|
|
95
|
+
"CrossOriginEnvelopePolicyError",
|
|
96
|
+
"createRequest"
|
|
97
|
+
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_requestContext__rspack_import_7[__rspack_import_key];
|
|
98
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
99
|
+
var _traceparent__rspack_import_8 = __webpack_require__("./traceparent");
|
|
79
100
|
var __rspack_reexport = {};
|
|
80
|
-
for(const __rspack_import_key in
|
|
101
|
+
for(const __rspack_import_key in _traceparent__rspack_import_8)if ([
|
|
81
102
|
"IdentityBindingViolationError",
|
|
82
103
|
"configure",
|
|
83
104
|
"OperationContractViolationError",
|
|
@@ -87,10 +108,10 @@ var __webpack_exports__ = {};
|
|
|
87
108
|
"createUploader",
|
|
88
109
|
"CrossOriginEnvelopePolicyError",
|
|
89
110
|
"createRequest"
|
|
90
|
-
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>
|
|
111
|
+
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_traceparent__rspack_import_8[__rspack_import_key];
|
|
91
112
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
92
113
|
var __rspack_reexport = {};
|
|
93
|
-
for(const __rspack_import_key in
|
|
114
|
+
for(const __rspack_import_key in _types__rspack_import_5)if ([
|
|
94
115
|
"IdentityBindingViolationError",
|
|
95
116
|
"configure",
|
|
96
117
|
"OperationContractViolationError",
|
|
@@ -100,7 +121,7 @@ var __webpack_exports__ = {};
|
|
|
100
121
|
"createUploader",
|
|
101
122
|
"CrossOriginEnvelopePolicyError",
|
|
102
123
|
"createRequest"
|
|
103
|
-
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>
|
|
124
|
+
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_types__rspack_import_5[__rspack_import_key];
|
|
104
125
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
105
126
|
const realRequest = new Map();
|
|
106
127
|
const realAllowedHeaders = new Map();
|
|
@@ -110,159 +131,43 @@ var __webpack_exports__ = {};
|
|
|
110
131
|
const realIdentityBinding = new Map();
|
|
111
132
|
const realOperationContract = new Map();
|
|
112
133
|
const domainMap = new Map();
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
const OPERATION_CONTEXT_DETAIL_HEADER = _types__rspack_import_4.BFF_OPERATION_CONTEXT_DETAIL_HEADER;
|
|
116
|
-
const TRACEPARENT_REGEX = /^00-([0-9a-f]{32})-([0-9a-f]{16})-[0-9a-f]{2}$/i;
|
|
117
|
-
const readProcessEnv = (key)=>{
|
|
118
|
-
if ("u" < typeof process || void 0 === process.env || 'string' != typeof process.env[key]) return;
|
|
119
|
-
return process.env[key];
|
|
120
|
-
};
|
|
121
|
-
const isStrictDefaultRequestIdEnabled = ()=>'true' === readProcessEnv('MODERN_BFF_STRICT_DEFAULT_REQUEST_ID');
|
|
122
|
-
const isSecuredRequestId = (requestId)=>'default' !== requestId || isStrictDefaultRequestIdEnabled();
|
|
123
|
-
const firstHeaderValue = (value)=>Array.isArray(value) ? value[0] : value;
|
|
124
|
-
const findHeaderKey = (headers, header)=>{
|
|
125
|
-
const normalized = header.toLowerCase();
|
|
126
|
-
return Object.keys(headers).find((key)=>key.toLowerCase() === normalized);
|
|
127
|
-
};
|
|
128
|
-
const readHeader = (headers, header)=>{
|
|
129
|
-
const key = findHeaderKey(headers, header);
|
|
130
|
-
return 'string' == typeof key ? headers[key] : void 0;
|
|
131
|
-
};
|
|
132
|
-
const writeHeader = (headers, header, value)=>{
|
|
133
|
-
if (void 0 === value) return;
|
|
134
|
-
const key = findHeaderKey(headers, header);
|
|
135
|
-
if ('string' == typeof key && key !== header) delete headers[key];
|
|
136
|
-
headers[header] = value;
|
|
137
|
-
};
|
|
138
|
-
const deleteHeader = (headers, header)=>{
|
|
139
|
-
const key = findHeaderKey(headers, header);
|
|
140
|
-
if ('string' == typeof key) delete headers[key];
|
|
141
|
-
};
|
|
142
|
-
const toOrigin = (value)=>{
|
|
143
|
-
if (!value) return;
|
|
144
|
-
try {
|
|
145
|
-
return new URL(value).origin;
|
|
146
|
-
} catch (error) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
const parseTraceparent = (value)=>{
|
|
151
|
-
const traceparent = firstHeaderValue(value);
|
|
152
|
-
if ('string' != typeof traceparent) return;
|
|
153
|
-
const match = traceparent.trim().match(TRACEPARENT_REGEX);
|
|
154
|
-
if (!match) return;
|
|
155
|
-
const [, traceId, spanId] = match;
|
|
156
|
-
if (!traceId || !spanId) return;
|
|
157
|
-
return {
|
|
158
|
-
traceId: traceId.toLowerCase(),
|
|
159
|
-
spanId: spanId.toLowerCase()
|
|
160
|
-
};
|
|
161
|
-
};
|
|
162
|
-
const extractPathParamNames = (path)=>Array.from(path.matchAll(/:([A-Za-z0-9_]+)/g)).flatMap(([, key])=>key ? [
|
|
163
|
-
key
|
|
164
|
-
] : []);
|
|
134
|
+
const OPERATION_CONTEXT_DETAIL_HEADER = _types__rspack_import_5.BFF_OPERATION_CONTEXT_DETAIL_HEADER;
|
|
135
|
+
const resolveBrowserOrigin = ()=>"u" > typeof window ? window.location.origin : void 0;
|
|
165
136
|
const originFetch = (...params)=>{
|
|
166
137
|
const [url, init] = params;
|
|
167
138
|
if (init?.method?.toLowerCase() === 'get') init.body = void 0;
|
|
168
139
|
return fetch(url, init).then(_handleRes__rspack_import_2.handleRes);
|
|
169
140
|
};
|
|
170
|
-
const
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const operationId = rawOperationId.startsWith(`${requestId}:`) ? rawOperationId : `${requestId}:${rawOperationId}`;
|
|
175
|
-
const traceparentValue = operationContext?.traceparent || ('string' == typeof firstHeaderValue(traceparent) ? String(firstHeaderValue(traceparent)) : void 0);
|
|
176
|
-
const parsedTraceContext = operationContext?.traceId && operationContext?.spanId ? {
|
|
177
|
-
traceId: operationContext.traceId,
|
|
178
|
-
spanId: operationContext.spanId
|
|
179
|
-
} : parseTraceparent(traceparentValue);
|
|
180
|
-
return {
|
|
141
|
+
const attachEnvelopeHeaderIfRequired = (headers, requestId, finalURL)=>{
|
|
142
|
+
const shouldRequireEnvelope = realRequireEnvelope.get(requestId) ?? (0, _policyCore__rspack_import_3.isSecuredRequestId)(requestId);
|
|
143
|
+
if (!shouldRequireEnvelope) return;
|
|
144
|
+
headers[_types__rspack_import_5.BFF_ENVELOPE_HEADER] = (0, _policyCore__rspack_import_3.buildEnvelopeHeaderValue)({
|
|
181
145
|
requestId,
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
...'number' == typeof operationContext?.operationVersion ? {
|
|
189
|
-
operationVersion: operationContext.operationVersion
|
|
190
|
-
} : {},
|
|
191
|
-
...traceparentValue ? {
|
|
192
|
-
traceparent: traceparentValue
|
|
193
|
-
} : {},
|
|
194
|
-
...parsedTraceContext ? {
|
|
195
|
-
traceId: parsedTraceContext.traceId,
|
|
196
|
-
spanId: parsedTraceContext.spanId
|
|
197
|
-
} : {}
|
|
198
|
-
};
|
|
199
|
-
};
|
|
200
|
-
class ProducerClientNotInitializedError extends Error {
|
|
201
|
-
constructor(requestId){
|
|
202
|
-
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';
|
|
203
|
-
this.name = 'ProducerClientNotInitializedError';
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
class ProducerDomainNotConfiguredError extends Error {
|
|
207
|
-
constructor(requestId){
|
|
208
|
-
super(`Producer client "${requestId}" must provide setDomain() during configure().`), this.code = 'BFF_PRODUCER_DOMAIN_NOT_CONFIGURED';
|
|
209
|
-
this.name = 'ProducerDomainNotConfiguredError';
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
class CrossOriginEnvelopePolicyError extends Error {
|
|
213
|
-
constructor(requestId, sourceOrigin, targetOrigin){
|
|
214
|
-
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';
|
|
215
|
-
this.name = 'CrossOriginEnvelopePolicyError';
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
class IdentityBindingViolationError extends Error {
|
|
219
|
-
constructor(violation){
|
|
220
|
-
super(`Identity header "${violation.header}" for producer "${violation.requestId}" was rejected by server-derived identity binding.`), this.code = 'BFF_IDENTITY_BINDING_VIOLATION';
|
|
221
|
-
this.name = 'IdentityBindingViolationError';
|
|
222
|
-
this.violation = violation;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
class OperationContractViolationError extends Error {
|
|
226
|
-
constructor(violation){
|
|
227
|
-
super(`Operation contract violation "${violation.reason}" for producer "${violation.requestId}" operation "${violation.operationId}".`), this.code = 'BFF_OPERATION_CONTRACT_VIOLATION';
|
|
228
|
-
this.name = 'OperationContractViolationError';
|
|
229
|
-
this.violation = violation;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
const validateOperationContract = (requestId, contextPayload)=>{
|
|
233
|
-
const operationContract = realOperationContract.get(requestId);
|
|
234
|
-
const operationContractEnabled = operationContract?.enabled ?? isSecuredRequestId(requestId);
|
|
235
|
-
if (!operationContractEnabled) return;
|
|
236
|
-
const strict = operationContract?.strict ?? true;
|
|
237
|
-
const requireSchemaHash = operationContract?.requireSchemaHash ?? true;
|
|
238
|
-
const requireOperationVersion = operationContract?.requireOperationVersion ?? true;
|
|
239
|
-
const maybeReportViolation = (reason)=>{
|
|
240
|
-
const violation = {
|
|
241
|
-
requestId,
|
|
242
|
-
target: 'browser',
|
|
243
|
-
operationId: contextPayload.operationId,
|
|
244
|
-
routePath: contextPayload.routePath,
|
|
245
|
-
method: contextPayload.method,
|
|
246
|
-
schemaHash: 'string' == typeof contextPayload.schemaHash ? contextPayload.schemaHash : void 0,
|
|
247
|
-
operationVersion: 'number' == typeof contextPayload.operationVersion ? contextPayload.operationVersion : void 0,
|
|
248
|
-
reason
|
|
249
|
-
};
|
|
250
|
-
operationContract?.onViolation?.(violation);
|
|
251
|
-
if (strict) throw new OperationContractViolationError(violation);
|
|
252
|
-
};
|
|
253
|
-
if (requireSchemaHash && 'string' != typeof contextPayload.schemaHash) maybeReportViolation('missing_schema_hash');
|
|
254
|
-
if (requireOperationVersion && 'number' != typeof contextPayload.operationVersion) maybeReportViolation('missing_operation_version');
|
|
146
|
+
target: 'browser',
|
|
147
|
+
sourceOrigin: resolveBrowserOrigin(),
|
|
148
|
+
targetOrigin: (0, _policyCore__rspack_import_3.toOrigin)(finalURL),
|
|
149
|
+
traceContext: (0, _policyCore__rspack_import_3.parseTraceparentValue)((0, _policyCore__rspack_import_3.readHeader)(headers, _policyCore__rspack_import_3.TRACEPARENT_HEADER)),
|
|
150
|
+
allowCrossOriginEnvelope: realAllowCrossOriginEnvelope.get(requestId)
|
|
151
|
+
});
|
|
255
152
|
};
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
153
|
+
const attachSecuredOperationHeaders = (headers, requestId, method, path, operationContext)=>{
|
|
154
|
+
if (!(0, _policyCore__rspack_import_3.isSecuredRequestId)(requestId)) return;
|
|
155
|
+
(0, _policyCore__rspack_import_3.attachOperationContextHeaders)({
|
|
156
|
+
headers,
|
|
157
|
+
requestId,
|
|
158
|
+
target: 'browser',
|
|
159
|
+
method,
|
|
160
|
+
path,
|
|
161
|
+
operationContext,
|
|
162
|
+
operationContract: realOperationContract.get(requestId),
|
|
163
|
+
operationContextHeader: _types__rspack_import_5.BFF_OPERATION_CONTEXT_HEADER,
|
|
164
|
+
operationContextDetailHeader: OPERATION_CONTEXT_DETAIL_HEADER
|
|
165
|
+
});
|
|
261
166
|
};
|
|
262
167
|
const configure = (options)=>{
|
|
263
168
|
const { request, interceptor, allowedHeaders, transport, requireEnvelope, allowCrossOriginEnvelope, identityBinding, operationContract, setDomain, requestId = 'default' } = options;
|
|
264
169
|
const hasExistingDomain = domainMap.has(requestId);
|
|
265
|
-
if ('default' !== requestId && !setDomain && !hasExistingDomain) throw new ProducerDomainNotConfiguredError(requestId);
|
|
170
|
+
if ('default' !== requestId && !setDomain && !hasExistingDomain) throw new _policyCore__rspack_import_3.ProducerDomainNotConfiguredError(requestId);
|
|
266
171
|
let configuredRequest = request || originFetch;
|
|
267
172
|
if (interceptor && !request) configuredRequest = interceptor(fetch);
|
|
268
173
|
if (Array.isArray(allowedHeaders)) realAllowedHeaders.set(requestId, allowedHeaders);
|
|
@@ -276,7 +181,7 @@ var __webpack_exports__ = {};
|
|
|
276
181
|
target: 'browser',
|
|
277
182
|
requestId
|
|
278
183
|
});
|
|
279
|
-
if ('default' !== requestId && isEmptyDomain(resolvedDomain)) throw new ProducerDomainNotConfiguredError(requestId);
|
|
184
|
+
if ('default' !== requestId && (0, _policyCore__rspack_import_3.isEmptyDomain)(resolvedDomain)) throw new _policyCore__rspack_import_3.ProducerDomainNotConfiguredError(requestId);
|
|
280
185
|
if ('string' == typeof resolvedDomain) domainMap.set(requestId, resolvedDomain);
|
|
281
186
|
}
|
|
282
187
|
realRequest.set(requestId, configuredRequest);
|
|
@@ -299,9 +204,9 @@ var __webpack_exports__ = {};
|
|
|
299
204
|
const getFinalPath = (0, path_to_regexp__rspack_import_0.compile)(path, {
|
|
300
205
|
encode: encodeURIComponent
|
|
301
206
|
});
|
|
302
|
-
const keyNames = extractPathParamNames(path);
|
|
207
|
+
const keyNames = (0, _policyCore__rspack_import_3.extractPathParamNames)(path);
|
|
303
208
|
const sender = async (...args)=>{
|
|
304
|
-
const fetcher =
|
|
209
|
+
const fetcher = (0, _policyCore__rspack_import_3.resolveConfiguredRequest)(realRequest, requestId, fetch1);
|
|
305
210
|
let body;
|
|
306
211
|
let finalURL;
|
|
307
212
|
let headers;
|
|
@@ -331,9 +236,9 @@ var __webpack_exports__ = {};
|
|
|
331
236
|
...payload.headers
|
|
332
237
|
} : {};
|
|
333
238
|
const identityBinding = realIdentityBinding.get(requestId);
|
|
334
|
-
const identityBindingEnabled = identityBinding?.enabled ?? isSecuredRequestId(requestId);
|
|
335
|
-
const identityBindingStrict = identityBinding?.strict ?? isSecuredRequestId(requestId);
|
|
336
|
-
const protectedIdentityHeaders = (identityBinding?.protectedHeaders ||
|
|
239
|
+
const identityBindingEnabled = identityBinding?.enabled ?? (0, _policyCore__rspack_import_3.isSecuredRequestId)(requestId);
|
|
240
|
+
const identityBindingStrict = identityBinding?.strict ?? (0, _policyCore__rspack_import_3.isSecuredRequestId)(requestId);
|
|
241
|
+
const protectedIdentityHeaders = (identityBinding?.protectedHeaders || _types__rspack_import_5.BFF_DEFAULT_PROTECTED_IDENTITY_HEADERS).map((header)=>header.toLowerCase());
|
|
337
242
|
if (identityBindingEnabled) {
|
|
338
243
|
const derivedIdentityHeaders = {};
|
|
339
244
|
const customDerivedHeaders = identityBinding?.deriveHeaders?.({
|
|
@@ -345,26 +250,26 @@ var __webpack_exports__ = {};
|
|
|
345
250
|
]
|
|
346
251
|
});
|
|
347
252
|
if (customDerivedHeaders && 'object' == typeof customDerivedHeaders) for (const header of protectedIdentityHeaders){
|
|
348
|
-
const customValue = readHeader(customDerivedHeaders, header);
|
|
349
|
-
if (void 0 !== customValue) writeHeader(derivedIdentityHeaders, header, customValue);
|
|
253
|
+
const customValue = (0, _policyCore__rspack_import_3.readHeader)(customDerivedHeaders, header);
|
|
254
|
+
if (void 0 !== customValue) (0, _policyCore__rspack_import_3.writeHeader)(derivedIdentityHeaders, header, customValue);
|
|
350
255
|
}
|
|
351
256
|
for (const header of protectedIdentityHeaders){
|
|
352
|
-
const attemptedValue = readHeader(headers, header);
|
|
257
|
+
const attemptedValue = (0, _policyCore__rspack_import_3.readHeader)(headers, header);
|
|
353
258
|
if (void 0 === attemptedValue) continue;
|
|
354
259
|
const violation = {
|
|
355
260
|
requestId,
|
|
356
261
|
target: 'browser',
|
|
357
262
|
header,
|
|
358
263
|
attemptedValue,
|
|
359
|
-
derivedValue: readHeader(derivedIdentityHeaders, header),
|
|
264
|
+
derivedValue: (0, _policyCore__rspack_import_3.readHeader)(derivedIdentityHeaders, header),
|
|
360
265
|
reason: identityBindingStrict ? 'client_override_rejected' : 'client_override_blocked'
|
|
361
266
|
};
|
|
362
267
|
identityBinding?.onViolation?.(violation);
|
|
363
|
-
if (identityBindingStrict) throw new IdentityBindingViolationError(violation);
|
|
364
|
-
deleteHeader(headers, header);
|
|
268
|
+
if (identityBindingStrict) throw new _policyCore__rspack_import_3.IdentityBindingViolationError(violation);
|
|
269
|
+
(0, _policyCore__rspack_import_3.deleteHeader)(headers, header);
|
|
365
270
|
}
|
|
366
271
|
Object.keys(derivedIdentityHeaders).forEach((header)=>{
|
|
367
|
-
writeHeader(headers, header, derivedIdentityHeaders[header]);
|
|
272
|
+
(0, _policyCore__rspack_import_3.writeHeader)(headers, header, derivedIdentityHeaders[header]);
|
|
368
273
|
});
|
|
369
274
|
}
|
|
370
275
|
body = payload.data && 'object' == typeof payload.data ? JSON.stringify(payload.data) : payload.body;
|
|
@@ -382,50 +287,11 @@ var __webpack_exports__ = {};
|
|
|
382
287
|
}
|
|
383
288
|
headers.accept = "application/json,*/*;q=0.8";
|
|
384
289
|
const configDomain = domainMap.get(requestId);
|
|
385
|
-
if ('default' !== requestId && isEmptyDomain(configDomain)) throw new ProducerDomainNotConfiguredError(requestId);
|
|
290
|
+
if ('default' !== requestId && (0, _policyCore__rspack_import_3.isEmptyDomain)(configDomain)) throw new _policyCore__rspack_import_3.ProducerDomainNotConfiguredError(requestId);
|
|
386
291
|
finalURL = `${configDomain || ''}${finalURL}`;
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
const targetOrigin = toOrigin(finalURL);
|
|
391
|
-
const traceContext = parseTraceparent(readHeader(headers, TRACEPARENT_HEADER));
|
|
392
|
-
const isCrossOrigin = Boolean(sourceOrigin) && Boolean(targetOrigin) && sourceOrigin !== targetOrigin;
|
|
393
|
-
if (isCrossOrigin) {
|
|
394
|
-
const policy = realAllowCrossOriginEnvelope.get(requestId);
|
|
395
|
-
const isAllowed = 'function' == typeof policy ? policy({
|
|
396
|
-
requestId,
|
|
397
|
-
sourceOrigin,
|
|
398
|
-
targetOrigin,
|
|
399
|
-
target: 'browser'
|
|
400
|
-
}) : true === policy;
|
|
401
|
-
if (!isAllowed) throw new CrossOriginEnvelopePolicyError(requestId, sourceOrigin, targetOrigin);
|
|
402
|
-
}
|
|
403
|
-
headers[_types__rspack_import_4.BFF_ENVELOPE_HEADER] = JSON.stringify({
|
|
404
|
-
requestId,
|
|
405
|
-
target: 'browser',
|
|
406
|
-
timestamp: Date.now(),
|
|
407
|
-
sourceOrigin,
|
|
408
|
-
targetOrigin,
|
|
409
|
-
...traceContext ? {
|
|
410
|
-
traceId: traceContext.traceId,
|
|
411
|
-
spanId: traceContext.spanId
|
|
412
|
-
} : {}
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
|
-
if (isSecuredRequestId(requestId)) {
|
|
416
|
-
if (void 0 === readHeader(headers, TRACEPARENT_HEADER) && operationContext?.traceparent) writeHeader(headers, TRACEPARENT_HEADER, operationContext.traceparent);
|
|
417
|
-
const contextPayload = buildOperationContext({
|
|
418
|
-
requestId,
|
|
419
|
-
method,
|
|
420
|
-
path,
|
|
421
|
-
operationContext,
|
|
422
|
-
traceparent: readHeader(headers, TRACEPARENT_HEADER)
|
|
423
|
-
});
|
|
424
|
-
validateOperationContract(requestId, contextPayload);
|
|
425
|
-
if (void 0 === readHeader(headers, _types__rspack_import_4.BFF_OPERATION_CONTEXT_HEADER)) writeHeader(headers, _types__rspack_import_4.BFF_OPERATION_CONTEXT_HEADER, contextPayload.operationId);
|
|
426
|
-
writeHeader(headers, OPERATION_CONTEXT_DETAIL_HEADER, JSON.stringify(contextPayload));
|
|
427
|
-
}
|
|
428
|
-
return (0, _transport__rspack_import_3.executeWithResilience)({
|
|
292
|
+
attachEnvelopeHeaderIfRequired(headers, requestId, finalURL);
|
|
293
|
+
attachSecuredOperationHeaders(headers, requestId, method, path, operationContext);
|
|
294
|
+
return (0, _transport__rspack_import_4.executeWithResilience)({
|
|
429
295
|
requestId,
|
|
430
296
|
target: 'browser',
|
|
431
297
|
method,
|
|
@@ -441,16 +307,21 @@ var __webpack_exports__ = {};
|
|
|
441
307
|
};
|
|
442
308
|
return sender;
|
|
443
309
|
};
|
|
444
|
-
const createUploader = ({ path, domain, requestId = 'default' })=>{
|
|
310
|
+
const createUploader = ({ path, domain, requestId = 'default', operationContext })=>{
|
|
445
311
|
const getFinalPath = (0, path_to_regexp__rspack_import_0.compile)(path, {
|
|
446
312
|
encode: encodeURIComponent
|
|
447
313
|
});
|
|
448
314
|
const sender = (...args)=>{
|
|
449
|
-
const fetcher =
|
|
450
|
-
const { body, headers, params } = (0,
|
|
315
|
+
const fetcher = (0, _policyCore__rspack_import_3.resolveConfiguredRequest)(realRequest, requestId, originFetch);
|
|
316
|
+
const { body, headers: uploadHeaders, params } = (0, _utiles__rspack_import_6.getUploadPayload)(args);
|
|
317
|
+
const headers = {
|
|
318
|
+
...uploadHeaders
|
|
319
|
+
};
|
|
451
320
|
const finalPath = getFinalPath(params);
|
|
452
321
|
const configDomain = domainMap.get(requestId);
|
|
453
322
|
const finalURL = `${configDomain || domain || ''}${finalPath}`;
|
|
323
|
+
attachEnvelopeHeaderIfRequired(headers, requestId, finalURL);
|
|
324
|
+
attachSecuredOperationHeaders(headers, requestId, 'POST', path, operationContext);
|
|
454
325
|
return fetcher(finalURL, {
|
|
455
326
|
method: 'POST',
|
|
456
327
|
body,
|
|
@@ -460,11 +331,11 @@ var __webpack_exports__ = {};
|
|
|
460
331
|
return sender;
|
|
461
332
|
};
|
|
462
333
|
__webpack_require__.d(__webpack_exports__, {
|
|
463
|
-
CrossOriginEnvelopePolicyError: ()=>CrossOriginEnvelopePolicyError,
|
|
464
|
-
IdentityBindingViolationError: ()=>IdentityBindingViolationError,
|
|
465
|
-
OperationContractViolationError: ()=>OperationContractViolationError,
|
|
466
|
-
ProducerClientNotInitializedError: ()=>ProducerClientNotInitializedError,
|
|
467
|
-
ProducerDomainNotConfiguredError: ()=>ProducerDomainNotConfiguredError
|
|
334
|
+
CrossOriginEnvelopePolicyError: ()=>_policyCore__rspack_import_3.CrossOriginEnvelopePolicyError,
|
|
335
|
+
IdentityBindingViolationError: ()=>_policyCore__rspack_import_3.IdentityBindingViolationError,
|
|
336
|
+
OperationContractViolationError: ()=>_policyCore__rspack_import_3.OperationContractViolationError,
|
|
337
|
+
ProducerClientNotInitializedError: ()=>_policyCore__rspack_import_3.ProducerClientNotInitializedError,
|
|
338
|
+
ProducerDomainNotConfiguredError: ()=>_policyCore__rspack_import_3.ProducerDomainNotConfiguredError
|
|
468
339
|
}, {
|
|
469
340
|
configure: configure,
|
|
470
341
|
createRequest: createRequest,
|