@bleedingdev/modern-js-create-request 3.2.0-ultramodern.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021-present Modern.js
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ <p align="center">
2
+ <a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png" width="300" alt="Modern.js Logo" /></a>
3
+ </p>
4
+
5
+ <h1 align="center">Modern.js</h1>
6
+
7
+ <p align="center">
8
+ A Progressive React Framework for modern web development.
9
+ </p>
10
+
11
+ ## Getting Started
12
+
13
+ Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-start) to get started with Modern.js.
14
+
15
+ ## Documentation
16
+
17
+ - [English Documentation](https://modernjs.dev/en/)
18
+ - [中文文档](https://modernjs.dev)
19
+
20
+ ## Contributing
21
+
22
+ Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md).
23
+
24
+ ## License
25
+
26
+ Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE).
@@ -0,0 +1,489 @@
1
+ "use strict";
2
+ var __webpack_modules__ = {
3
+ "./handleRes" (module) {
4
+ module.exports = require("./handleRes.js");
5
+ },
6
+ "./requestContext" (module) {
7
+ module.exports = require("./requestContext.js");
8
+ },
9
+ "./transport" (module) {
10
+ module.exports = require("./transport.js");
11
+ },
12
+ "./types" (module) {
13
+ module.exports = require("./types.js");
14
+ },
15
+ "./utiles" (module) {
16
+ module.exports = require("./utiles.js");
17
+ },
18
+ "path-to-regexp" (module) {
19
+ module.exports = require("path-to-regexp");
20
+ },
21
+ qs (module) {
22
+ module.exports = require("qs");
23
+ }
24
+ };
25
+ var __webpack_module_cache__ = {};
26
+ function __webpack_require__(moduleId) {
27
+ var cachedModule = __webpack_module_cache__[moduleId];
28
+ if (void 0 !== cachedModule) return cachedModule.exports;
29
+ var module = __webpack_module_cache__[moduleId] = {
30
+ exports: {}
31
+ };
32
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
33
+ return module.exports;
34
+ }
35
+ (()=>{
36
+ __webpack_require__.n = (module)=>{
37
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
38
+ __webpack_require__.d(getter, {
39
+ a: getter
40
+ });
41
+ return getter;
42
+ };
43
+ })();
44
+ (()=>{
45
+ __webpack_require__.d = (exports1, definition)=>{
46
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
47
+ enumerable: true,
48
+ get: definition[key]
49
+ });
50
+ };
51
+ })();
52
+ (()=>{
53
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
54
+ })();
55
+ (()=>{
56
+ __webpack_require__.r = (exports1)=>{
57
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
58
+ value: 'Module'
59
+ });
60
+ Object.defineProperty(exports1, '__esModule', {
61
+ value: true
62
+ });
63
+ };
64
+ })();
65
+ var __webpack_exports__ = {};
66
+ (()=>{
67
+ __webpack_require__.r(__webpack_exports__);
68
+ __webpack_require__.d(__webpack_exports__, {
69
+ CrossOriginEnvelopePolicyError: ()=>CrossOriginEnvelopePolicyError,
70
+ IdentityBindingViolationError: ()=>IdentityBindingViolationError,
71
+ OperationContractViolationError: ()=>OperationContractViolationError,
72
+ ProducerClientNotInitializedError: ()=>ProducerClientNotInitializedError,
73
+ ProducerDomainNotConfiguredError: ()=>ProducerDomainNotConfiguredError,
74
+ configure: ()=>configure,
75
+ createRequest: ()=>createRequest,
76
+ createUploader: ()=>createUploader
77
+ });
78
+ var path_to_regexp__rspack_import_0 = __webpack_require__("path-to-regexp");
79
+ var qs__rspack_import_1 = __webpack_require__("qs");
80
+ var _handleRes__rspack_import_2 = __webpack_require__("./handleRes");
81
+ var _transport__rspack_import_3 = __webpack_require__("./transport");
82
+ var _types__rspack_import_4 = __webpack_require__("./types");
83
+ var _utiles__rspack_import_5 = __webpack_require__("./utiles");
84
+ var _requestContext__rspack_import_6 = __webpack_require__("./requestContext");
85
+ var __rspack_reexport = {};
86
+ for(const __rspack_import_key in _requestContext__rspack_import_6)if ([
87
+ "IdentityBindingViolationError",
88
+ "configure",
89
+ "OperationContractViolationError",
90
+ "default",
91
+ "ProducerClientNotInitializedError",
92
+ "ProducerDomainNotConfiguredError",
93
+ "createUploader",
94
+ "CrossOriginEnvelopePolicyError",
95
+ "createRequest"
96
+ ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_requestContext__rspack_import_6[__rspack_import_key];
97
+ __webpack_require__.d(__webpack_exports__, __rspack_reexport);
98
+ var __rspack_reexport = {};
99
+ for(const __rspack_import_key in _types__rspack_import_4)if ([
100
+ "IdentityBindingViolationError",
101
+ "configure",
102
+ "OperationContractViolationError",
103
+ "default",
104
+ "ProducerClientNotInitializedError",
105
+ "ProducerDomainNotConfiguredError",
106
+ "createUploader",
107
+ "CrossOriginEnvelopePolicyError",
108
+ "createRequest"
109
+ ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_types__rspack_import_4[__rspack_import_key];
110
+ __webpack_require__.d(__webpack_exports__, __rspack_reexport);
111
+ const realRequest = new Map();
112
+ const realAllowedHeaders = new Map();
113
+ const realRequireEnvelope = new Map();
114
+ const realAllowCrossOriginEnvelope = new Map();
115
+ const realTransportResilience = new Map();
116
+ const realIdentityBinding = new Map();
117
+ const realOperationContract = new Map();
118
+ const domainMap = new Map();
119
+ const isEmptyDomain = (domain)=>'string' != typeof domain || '' === domain.trim();
120
+ const TRACEPARENT_HEADER = 'traceparent';
121
+ const OPERATION_CONTEXT_DETAIL_HEADER = _types__rspack_import_4.BFF_OPERATION_CONTEXT_DETAIL_HEADER;
122
+ const TRACEPARENT_REGEX = /^00-([0-9a-f]{32})-([0-9a-f]{16})-[0-9a-f]{2}$/i;
123
+ const readProcessEnv = (key)=>{
124
+ if ("u" < typeof process || void 0 === process.env || 'string' != typeof process.env[key]) return;
125
+ return process.env[key];
126
+ };
127
+ const isStrictDefaultRequestIdEnabled = ()=>'true' === readProcessEnv('MODERN_BFF_STRICT_DEFAULT_REQUEST_ID');
128
+ const isSecuredRequestId = (requestId)=>'default' !== requestId || isStrictDefaultRequestIdEnabled();
129
+ const firstHeaderValue = (value)=>Array.isArray(value) ? value[0] : value;
130
+ const findHeaderKey = (headers, header)=>{
131
+ const normalized = header.toLowerCase();
132
+ return Object.keys(headers).find((key)=>key.toLowerCase() === normalized);
133
+ };
134
+ const readHeader = (headers, header)=>{
135
+ const key = findHeaderKey(headers, header);
136
+ return 'string' == typeof key ? headers[key] : void 0;
137
+ };
138
+ const writeHeader = (headers, header, value)=>{
139
+ if (void 0 === value) return;
140
+ const key = findHeaderKey(headers, header);
141
+ if ('string' == typeof key && key !== header) delete headers[key];
142
+ headers[header] = value;
143
+ };
144
+ const deleteHeader = (headers, header)=>{
145
+ const key = findHeaderKey(headers, header);
146
+ if ('string' == typeof key) delete headers[key];
147
+ };
148
+ const toOrigin = (value)=>{
149
+ if (!value) return;
150
+ try {
151
+ return new URL(value).origin;
152
+ } catch (error) {
153
+ return;
154
+ }
155
+ };
156
+ const parseTraceparent = (value)=>{
157
+ const traceparent = firstHeaderValue(value);
158
+ if ('string' != typeof traceparent) return;
159
+ const match = traceparent.trim().match(TRACEPARENT_REGEX);
160
+ if (!match) return;
161
+ const [, traceId, spanId] = match;
162
+ if (!traceId || !spanId) return;
163
+ return {
164
+ traceId: traceId.toLowerCase(),
165
+ spanId: spanId.toLowerCase()
166
+ };
167
+ };
168
+ const extractPathParamNames = (path)=>Array.from(path.matchAll(/:([A-Za-z0-9_]+)/g)).flatMap(([, key])=>key ? [
169
+ key
170
+ ] : []);
171
+ const originFetch = (...params)=>{
172
+ const [url, init] = params;
173
+ if (init?.method?.toLowerCase() === 'get') init.body = void 0;
174
+ return fetch(url, init).then(_handleRes__rspack_import_2.handleRes);
175
+ };
176
+ const buildOperationContext = ({ requestId, method, path, operationContext, traceparent })=>{
177
+ const routePath = operationContext?.routePath || path;
178
+ const operationMethod = (operationContext?.method || method || 'GET').toUpperCase();
179
+ const rawOperationId = operationContext?.operationId || `${operationMethod}:${routePath}`;
180
+ const operationId = rawOperationId.startsWith(`${requestId}:`) ? rawOperationId : `${requestId}:${rawOperationId}`;
181
+ const traceparentValue = operationContext?.traceparent || ('string' == typeof firstHeaderValue(traceparent) ? String(firstHeaderValue(traceparent)) : void 0);
182
+ const parsedTraceContext = operationContext?.traceId && operationContext?.spanId ? {
183
+ traceId: operationContext.traceId,
184
+ spanId: operationContext.spanId
185
+ } : parseTraceparent(traceparentValue);
186
+ return {
187
+ requestId,
188
+ operationId,
189
+ routePath,
190
+ method: operationMethod,
191
+ ...operationContext?.schemaHash ? {
192
+ schemaHash: operationContext.schemaHash
193
+ } : {},
194
+ ...'number' == typeof operationContext?.operationVersion ? {
195
+ operationVersion: operationContext.operationVersion
196
+ } : {},
197
+ ...traceparentValue ? {
198
+ traceparent: traceparentValue
199
+ } : {},
200
+ ...parsedTraceContext ? {
201
+ traceId: parsedTraceContext.traceId,
202
+ spanId: parsedTraceContext.spanId
203
+ } : {}
204
+ };
205
+ };
206
+ class ProducerClientNotInitializedError extends Error {
207
+ constructor(requestId){
208
+ 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';
209
+ this.name = 'ProducerClientNotInitializedError';
210
+ }
211
+ }
212
+ class ProducerDomainNotConfiguredError extends Error {
213
+ constructor(requestId){
214
+ super(`Producer client "${requestId}" must provide setDomain() during configure().`), this.code = 'BFF_PRODUCER_DOMAIN_NOT_CONFIGURED';
215
+ this.name = 'ProducerDomainNotConfiguredError';
216
+ }
217
+ }
218
+ class CrossOriginEnvelopePolicyError extends Error {
219
+ constructor(requestId, sourceOrigin, targetOrigin){
220
+ 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';
221
+ this.name = 'CrossOriginEnvelopePolicyError';
222
+ }
223
+ }
224
+ class IdentityBindingViolationError extends Error {
225
+ constructor(violation){
226
+ super(`Identity header "${violation.header}" for producer "${violation.requestId}" was rejected by server-derived identity binding.`), this.code = 'BFF_IDENTITY_BINDING_VIOLATION';
227
+ this.name = 'IdentityBindingViolationError';
228
+ this.violation = violation;
229
+ }
230
+ }
231
+ class OperationContractViolationError extends Error {
232
+ constructor(violation){
233
+ super(`Operation contract violation "${violation.reason}" for producer "${violation.requestId}" operation "${violation.operationId}".`), this.code = 'BFF_OPERATION_CONTRACT_VIOLATION';
234
+ this.name = 'OperationContractViolationError';
235
+ this.violation = violation;
236
+ }
237
+ }
238
+ const validateOperationContract = (requestId, contextPayload)=>{
239
+ const operationContract = realOperationContract.get(requestId);
240
+ const operationContractEnabled = operationContract?.enabled ?? isSecuredRequestId(requestId);
241
+ if (!operationContractEnabled) return;
242
+ const strict = operationContract?.strict ?? true;
243
+ const requireSchemaHash = operationContract?.requireSchemaHash ?? true;
244
+ const requireOperationVersion = operationContract?.requireOperationVersion ?? true;
245
+ const maybeReportViolation = (reason)=>{
246
+ const violation = {
247
+ requestId,
248
+ target: 'browser',
249
+ operationId: contextPayload.operationId,
250
+ routePath: contextPayload.routePath,
251
+ method: contextPayload.method,
252
+ schemaHash: 'string' == typeof contextPayload.schemaHash ? contextPayload.schemaHash : void 0,
253
+ operationVersion: 'number' == typeof contextPayload.operationVersion ? contextPayload.operationVersion : void 0,
254
+ reason
255
+ };
256
+ operationContract?.onViolation?.(violation);
257
+ if (strict) throw new OperationContractViolationError(violation);
258
+ };
259
+ if (requireSchemaHash && 'string' != typeof contextPayload.schemaHash) maybeReportViolation('missing_schema_hash');
260
+ if (requireOperationVersion && 'number' != typeof contextPayload.operationVersion) maybeReportViolation('missing_operation_version');
261
+ };
262
+ const getConfiguredRequest = (requestId, fallback)=>{
263
+ const configuredRequest = realRequest.get(requestId);
264
+ if (configuredRequest) return configuredRequest;
265
+ if ('default' !== requestId) throw new ProducerClientNotInitializedError(requestId);
266
+ return fallback;
267
+ };
268
+ const configure = (options)=>{
269
+ const { request, interceptor, allowedHeaders, transport, requireEnvelope, allowCrossOriginEnvelope, identityBinding, operationContract, setDomain, requestId = 'default' } = options;
270
+ const hasExistingDomain = domainMap.has(requestId);
271
+ if ('default' !== requestId && !setDomain && !hasExistingDomain) throw new ProducerDomainNotConfiguredError(requestId);
272
+ let configuredRequest = request || originFetch;
273
+ if (interceptor && !request) configuredRequest = interceptor(fetch);
274
+ if (Array.isArray(allowedHeaders)) realAllowedHeaders.set(requestId, allowedHeaders);
275
+ if (transport && 'object' == typeof transport) realTransportResilience.set(requestId, transport);
276
+ if (identityBinding && 'object' == typeof identityBinding) realIdentityBinding.set(requestId, identityBinding);
277
+ if (operationContract && 'object' == typeof operationContract) realOperationContract.set(requestId, operationContract);
278
+ if ('boolean' == typeof requireEnvelope) realRequireEnvelope.set(requestId, requireEnvelope);
279
+ if ('boolean' == typeof allowCrossOriginEnvelope || 'function' == typeof allowCrossOriginEnvelope) realAllowCrossOriginEnvelope.set(requestId, allowCrossOriginEnvelope);
280
+ if (setDomain) {
281
+ const resolvedDomain = setDomain({
282
+ target: 'browser',
283
+ requestId
284
+ });
285
+ if ('default' !== requestId && isEmptyDomain(resolvedDomain)) throw new ProducerDomainNotConfiguredError(requestId);
286
+ if ('string' == typeof resolvedDomain) domainMap.set(requestId, resolvedDomain);
287
+ }
288
+ realRequest.set(requestId, configuredRequest);
289
+ };
290
+ const normalizeRequestOptions = (...args)=>{
291
+ if ('object' == typeof args[0] && null !== args[0]) return args[0];
292
+ const [path, method, port, httpMethodDecider, fetch1, requestId, operationContext] = args;
293
+ return {
294
+ path,
295
+ method,
296
+ port,
297
+ httpMethodDecider,
298
+ fetch: fetch1,
299
+ requestId,
300
+ operationContext
301
+ };
302
+ };
303
+ const createRequest = (...args)=>{
304
+ const { path, method, port, httpMethodDecider = 'functionName', fetch: fetch1 = originFetch, domain, requestId = 'default', operationContext } = normalizeRequestOptions(...args);
305
+ const getFinalPath = (0, path_to_regexp__rspack_import_0.compile)(path, {
306
+ encode: encodeURIComponent
307
+ });
308
+ const keyNames = extractPathParamNames(path);
309
+ const sender = async (...args)=>{
310
+ const fetcher = getConfiguredRequest(requestId, fetch1);
311
+ let body;
312
+ let finalURL;
313
+ let headers;
314
+ if ('inputParams' === httpMethodDecider) {
315
+ finalURL = path;
316
+ body = JSON.stringify({
317
+ args
318
+ });
319
+ headers = {
320
+ 'Content-Type': 'application/json'
321
+ };
322
+ } else {
323
+ const payload = 'object' == typeof args[args.length - 1] ? args[args.length - 1] : {};
324
+ payload.params = payload.params || {};
325
+ const requestParams = args[0];
326
+ if ('object' == typeof requestParams && requestParams.params) {
327
+ const { params } = requestParams;
328
+ keyNames.forEach((keyName)=>{
329
+ payload.params[keyName] = params[keyName];
330
+ });
331
+ } else keyNames.forEach((keyName, index)=>{
332
+ payload.params[keyName] = args[index];
333
+ });
334
+ const finalPath = getFinalPath(payload.params);
335
+ finalURL = payload.query ? `${finalPath}?${(0, qs__rspack_import_1.stringify)(payload.query)}` : finalPath;
336
+ headers = payload.headers ? {
337
+ ...payload.headers
338
+ } : {};
339
+ const identityBinding = realIdentityBinding.get(requestId);
340
+ const identityBindingEnabled = identityBinding?.enabled ?? isSecuredRequestId(requestId);
341
+ const identityBindingStrict = identityBinding?.strict ?? isSecuredRequestId(requestId);
342
+ const protectedIdentityHeaders = (identityBinding?.protectedHeaders || _types__rspack_import_4.BFF_DEFAULT_PROTECTED_IDENTITY_HEADERS).map((header)=>header.toLowerCase());
343
+ if (identityBindingEnabled) {
344
+ const derivedIdentityHeaders = {};
345
+ const customDerivedHeaders = identityBinding?.deriveHeaders?.({
346
+ requestId,
347
+ target: 'browser',
348
+ incomingHeaders: {},
349
+ protectedHeaders: [
350
+ ...protectedIdentityHeaders
351
+ ]
352
+ });
353
+ if (customDerivedHeaders && 'object' == typeof customDerivedHeaders) for (const header of protectedIdentityHeaders){
354
+ const customValue = readHeader(customDerivedHeaders, header);
355
+ if (void 0 !== customValue) writeHeader(derivedIdentityHeaders, header, customValue);
356
+ }
357
+ for (const header of protectedIdentityHeaders){
358
+ const attemptedValue = readHeader(headers, header);
359
+ if (void 0 === attemptedValue) continue;
360
+ const violation = {
361
+ requestId,
362
+ target: 'browser',
363
+ header,
364
+ attemptedValue,
365
+ derivedValue: readHeader(derivedIdentityHeaders, header),
366
+ reason: identityBindingStrict ? 'client_override_rejected' : 'client_override_blocked'
367
+ };
368
+ identityBinding?.onViolation?.(violation);
369
+ if (identityBindingStrict) throw new IdentityBindingViolationError(violation);
370
+ deleteHeader(headers, header);
371
+ }
372
+ Object.keys(derivedIdentityHeaders).forEach((header)=>{
373
+ writeHeader(headers, header, derivedIdentityHeaders[header]);
374
+ });
375
+ }
376
+ body = payload.data && 'object' == typeof payload.data ? JSON.stringify(payload.data) : payload.body;
377
+ if (payload.data) {
378
+ headers['Content-Type'] = 'application/json';
379
+ body = 'object' == typeof payload.data ? JSON.stringify(payload.data) : payload.body;
380
+ } else if (payload.body) {
381
+ headers['Content-Type'] = 'text/plain';
382
+ body = payload.body;
383
+ } else if (payload.formData) body = payload.formData;
384
+ else if (payload.formUrlencoded) {
385
+ headers['Content-Type'] = 'application/x-www-form-urlencoded';
386
+ body = 'object' != typeof payload.formUrlencoded || payload.formUrlencoded instanceof URLSearchParams ? payload.formUrlencoded : (0, qs__rspack_import_1.stringify)(payload.formUrlencoded);
387
+ }
388
+ }
389
+ headers.accept = "application/json,*/*;q=0.8";
390
+ const configDomain = domainMap.get(requestId);
391
+ if ('default' !== requestId && isEmptyDomain(configDomain)) throw new ProducerDomainNotConfiguredError(requestId);
392
+ finalURL = `${configDomain || ''}${finalURL}`;
393
+ const shouldRequireEnvelope = realRequireEnvelope.get(requestId) ?? isSecuredRequestId(requestId);
394
+ if (shouldRequireEnvelope) {
395
+ const sourceOrigin = "u" > typeof window ? window.location.origin : void 0;
396
+ const targetOrigin = toOrigin(finalURL);
397
+ const traceContext = parseTraceparent(readHeader(headers, TRACEPARENT_HEADER));
398
+ const isCrossOrigin = Boolean(sourceOrigin) && Boolean(targetOrigin) && sourceOrigin !== targetOrigin;
399
+ if (isCrossOrigin) {
400
+ const policy = realAllowCrossOriginEnvelope.get(requestId);
401
+ const isAllowed = 'function' == typeof policy ? policy({
402
+ requestId,
403
+ sourceOrigin,
404
+ targetOrigin,
405
+ target: 'browser'
406
+ }) : true === policy;
407
+ if (!isAllowed) throw new CrossOriginEnvelopePolicyError(requestId, sourceOrigin, targetOrigin);
408
+ }
409
+ headers[_types__rspack_import_4.BFF_ENVELOPE_HEADER] = JSON.stringify({
410
+ requestId,
411
+ target: 'browser',
412
+ timestamp: Date.now(),
413
+ sourceOrigin,
414
+ targetOrigin,
415
+ ...traceContext ? {
416
+ traceId: traceContext.traceId,
417
+ spanId: traceContext.spanId
418
+ } : {}
419
+ });
420
+ }
421
+ if (isSecuredRequestId(requestId)) {
422
+ if (void 0 === readHeader(headers, TRACEPARENT_HEADER) && operationContext?.traceparent) writeHeader(headers, TRACEPARENT_HEADER, operationContext.traceparent);
423
+ const contextPayload = buildOperationContext({
424
+ requestId,
425
+ method,
426
+ path,
427
+ operationContext,
428
+ traceparent: readHeader(headers, TRACEPARENT_HEADER)
429
+ });
430
+ validateOperationContract(requestId, contextPayload);
431
+ 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);
432
+ writeHeader(headers, OPERATION_CONTEXT_DETAIL_HEADER, JSON.stringify(contextPayload));
433
+ }
434
+ return (0, _transport__rspack_import_3.executeWithResilience)({
435
+ requestId,
436
+ target: 'browser',
437
+ method,
438
+ url: finalURL,
439
+ init: {
440
+ method,
441
+ body,
442
+ headers
443
+ },
444
+ fetcher,
445
+ transport: realTransportResilience.get(requestId)
446
+ });
447
+ };
448
+ return sender;
449
+ };
450
+ const createUploader = ({ path, domain, requestId = 'default' })=>{
451
+ const getFinalPath = (0, path_to_regexp__rspack_import_0.compile)(path, {
452
+ encode: encodeURIComponent
453
+ });
454
+ const sender = (...args)=>{
455
+ const fetcher = getConfiguredRequest(requestId, originFetch);
456
+ const { body, headers, params } = (0, _utiles__rspack_import_5.getUploadPayload)(args);
457
+ const finalPath = getFinalPath(params);
458
+ const configDomain = domainMap.get(requestId);
459
+ const finalURL = `${configDomain || domain || ''}${finalPath}`;
460
+ return fetcher(finalURL, {
461
+ method: 'POST',
462
+ body,
463
+ headers
464
+ });
465
+ };
466
+ return sender;
467
+ };
468
+ })();
469
+ exports.CrossOriginEnvelopePolicyError = __webpack_exports__.CrossOriginEnvelopePolicyError;
470
+ exports.IdentityBindingViolationError = __webpack_exports__.IdentityBindingViolationError;
471
+ exports.OperationContractViolationError = __webpack_exports__.OperationContractViolationError;
472
+ exports.ProducerClientNotInitializedError = __webpack_exports__.ProducerClientNotInitializedError;
473
+ exports.ProducerDomainNotConfiguredError = __webpack_exports__.ProducerDomainNotConfiguredError;
474
+ exports.configure = __webpack_exports__.configure;
475
+ exports.createRequest = __webpack_exports__.createRequest;
476
+ exports.createUploader = __webpack_exports__.createUploader;
477
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
478
+ "CrossOriginEnvelopePolicyError",
479
+ "IdentityBindingViolationError",
480
+ "OperationContractViolationError",
481
+ "ProducerClientNotInitializedError",
482
+ "ProducerDomainNotConfiguredError",
483
+ "configure",
484
+ "createRequest",
485
+ "createUploader"
486
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
487
+ Object.defineProperty(exports, '__esModule', {
488
+ value: true
489
+ });
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ handleRes: ()=>handleRes
28
+ });
29
+ const handleRes = async (res)=>{
30
+ const contentType = res.headers.get('content-type');
31
+ if (!res.ok) {
32
+ const data = await res.json();
33
+ res.data = data;
34
+ throw res;
35
+ }
36
+ if (contentType?.includes('application/json') || contentType?.includes('text/json')) return res.json();
37
+ if (contentType?.includes('text/html') || contentType?.includes('text/plain')) return res.text();
38
+ if ((contentType?.includes('application/x-www-form-urlencoded') || contentType?.includes('multipart/form-data')) && res instanceof Response) return res.formData();
39
+ if (contentType?.includes('application/octet-stream')) return res.arrayBuffer();
40
+ if (contentType?.includes('image/png')) return res;
41
+ return res.text();
42
+ };
43
+ exports.handleRes = __webpack_exports__.handleRes;
44
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
45
+ "handleRes"
46
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
47
+ Object.defineProperty(exports, '__esModule', {
48
+ value: true
49
+ });