@bleedingdev/modern-js-create-request 3.2.0-ultramodern.99 → 3.4.0-ultramodern.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/browser.js +100 -224
- package/dist/cjs/handleRes.js +12 -8
- package/dist/cjs/node.js +118 -234
- package/dist/cjs/policyCore.js +275 -0
- package/dist/cjs/qs.js +9 -5
- package/dist/cjs/requestContext.js +11 -18
- package/dist/cjs/traceparent.js +56 -0
- package/dist/cjs/transport.js +12 -8
- package/dist/cjs/types.js +15 -11
- package/dist/cjs/utiles.js +12 -8
- 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 +12 -9
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
|
},
|
|
@@ -42,11 +48,15 @@ function __webpack_require__(moduleId) {
|
|
|
42
48
|
};
|
|
43
49
|
})();
|
|
44
50
|
(()=>{
|
|
45
|
-
__webpack_require__.d = (exports1,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
52
|
+
var define = (defs, kind)=>{
|
|
53
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
[kind]: defs[key]
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
define(getters, "get");
|
|
59
|
+
define(values, "value");
|
|
50
60
|
};
|
|
51
61
|
})();
|
|
52
62
|
(()=>{
|
|
@@ -65,25 +75,30 @@ function __webpack_require__(moduleId) {
|
|
|
65
75
|
var __webpack_exports__ = {};
|
|
66
76
|
(()=>{
|
|
67
77
|
__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
78
|
var path_to_regexp__rspack_import_0 = __webpack_require__("path-to-regexp");
|
|
79
79
|
var qs__rspack_import_1 = __webpack_require__("qs");
|
|
80
80
|
var _handleRes__rspack_import_2 = __webpack_require__("./handleRes");
|
|
81
|
-
var
|
|
82
|
-
var
|
|
83
|
-
var
|
|
84
|
-
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");
|
|
85
100
|
var __rspack_reexport = {};
|
|
86
|
-
for(const __rspack_import_key in
|
|
101
|
+
for(const __rspack_import_key in _traceparent__rspack_import_8)if ([
|
|
87
102
|
"IdentityBindingViolationError",
|
|
88
103
|
"configure",
|
|
89
104
|
"OperationContractViolationError",
|
|
@@ -93,10 +108,10 @@ var __webpack_exports__ = {};
|
|
|
93
108
|
"createUploader",
|
|
94
109
|
"CrossOriginEnvelopePolicyError",
|
|
95
110
|
"createRequest"
|
|
96
|
-
].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];
|
|
97
112
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
98
113
|
var __rspack_reexport = {};
|
|
99
|
-
for(const __rspack_import_key in
|
|
114
|
+
for(const __rspack_import_key in _types__rspack_import_5)if ([
|
|
100
115
|
"IdentityBindingViolationError",
|
|
101
116
|
"configure",
|
|
102
117
|
"OperationContractViolationError",
|
|
@@ -106,7 +121,7 @@ var __webpack_exports__ = {};
|
|
|
106
121
|
"createUploader",
|
|
107
122
|
"CrossOriginEnvelopePolicyError",
|
|
108
123
|
"createRequest"
|
|
109
|
-
].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];
|
|
110
125
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
111
126
|
const realRequest = new Map();
|
|
112
127
|
const realAllowedHeaders = new Map();
|
|
@@ -116,159 +131,43 @@ var __webpack_exports__ = {};
|
|
|
116
131
|
const realIdentityBinding = new Map();
|
|
117
132
|
const realOperationContract = new Map();
|
|
118
133
|
const domainMap = new Map();
|
|
119
|
-
const
|
|
120
|
-
const
|
|
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
|
-
] : []);
|
|
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;
|
|
171
136
|
const originFetch = (...params)=>{
|
|
172
137
|
const [url, init] = params;
|
|
173
138
|
if (init?.method?.toLowerCase() === 'get') init.body = void 0;
|
|
174
139
|
return fetch(url, init).then(_handleRes__rspack_import_2.handleRes);
|
|
175
140
|
};
|
|
176
|
-
const
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
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 {
|
|
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)({
|
|
187
145
|
requestId,
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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');
|
|
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
|
+
});
|
|
261
152
|
};
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
+
});
|
|
267
166
|
};
|
|
268
167
|
const configure = (options)=>{
|
|
269
168
|
const { request, interceptor, allowedHeaders, transport, requireEnvelope, allowCrossOriginEnvelope, identityBinding, operationContract, setDomain, requestId = 'default' } = options;
|
|
270
169
|
const hasExistingDomain = domainMap.has(requestId);
|
|
271
|
-
if ('default' !== requestId && !setDomain && !hasExistingDomain) throw new ProducerDomainNotConfiguredError(requestId);
|
|
170
|
+
if ('default' !== requestId && !setDomain && !hasExistingDomain) throw new _policyCore__rspack_import_3.ProducerDomainNotConfiguredError(requestId);
|
|
272
171
|
let configuredRequest = request || originFetch;
|
|
273
172
|
if (interceptor && !request) configuredRequest = interceptor(fetch);
|
|
274
173
|
if (Array.isArray(allowedHeaders)) realAllowedHeaders.set(requestId, allowedHeaders);
|
|
@@ -282,7 +181,7 @@ var __webpack_exports__ = {};
|
|
|
282
181
|
target: 'browser',
|
|
283
182
|
requestId
|
|
284
183
|
});
|
|
285
|
-
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);
|
|
286
185
|
if ('string' == typeof resolvedDomain) domainMap.set(requestId, resolvedDomain);
|
|
287
186
|
}
|
|
288
187
|
realRequest.set(requestId, configuredRequest);
|
|
@@ -305,9 +204,9 @@ var __webpack_exports__ = {};
|
|
|
305
204
|
const getFinalPath = (0, path_to_regexp__rspack_import_0.compile)(path, {
|
|
306
205
|
encode: encodeURIComponent
|
|
307
206
|
});
|
|
308
|
-
const keyNames = extractPathParamNames(path);
|
|
207
|
+
const keyNames = (0, _policyCore__rspack_import_3.extractPathParamNames)(path);
|
|
309
208
|
const sender = async (...args)=>{
|
|
310
|
-
const fetcher =
|
|
209
|
+
const fetcher = (0, _policyCore__rspack_import_3.resolveConfiguredRequest)(realRequest, requestId, fetch1);
|
|
311
210
|
let body;
|
|
312
211
|
let finalURL;
|
|
313
212
|
let headers;
|
|
@@ -337,9 +236,9 @@ var __webpack_exports__ = {};
|
|
|
337
236
|
...payload.headers
|
|
338
237
|
} : {};
|
|
339
238
|
const identityBinding = realIdentityBinding.get(requestId);
|
|
340
|
-
const identityBindingEnabled = identityBinding?.enabled ?? isSecuredRequestId(requestId);
|
|
341
|
-
const identityBindingStrict = identityBinding?.strict ?? isSecuredRequestId(requestId);
|
|
342
|
-
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());
|
|
343
242
|
if (identityBindingEnabled) {
|
|
344
243
|
const derivedIdentityHeaders = {};
|
|
345
244
|
const customDerivedHeaders = identityBinding?.deriveHeaders?.({
|
|
@@ -351,26 +250,26 @@ var __webpack_exports__ = {};
|
|
|
351
250
|
]
|
|
352
251
|
});
|
|
353
252
|
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);
|
|
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);
|
|
356
255
|
}
|
|
357
256
|
for (const header of protectedIdentityHeaders){
|
|
358
|
-
const attemptedValue = readHeader(headers, header);
|
|
257
|
+
const attemptedValue = (0, _policyCore__rspack_import_3.readHeader)(headers, header);
|
|
359
258
|
if (void 0 === attemptedValue) continue;
|
|
360
259
|
const violation = {
|
|
361
260
|
requestId,
|
|
362
261
|
target: 'browser',
|
|
363
262
|
header,
|
|
364
263
|
attemptedValue,
|
|
365
|
-
derivedValue: readHeader(derivedIdentityHeaders, header),
|
|
264
|
+
derivedValue: (0, _policyCore__rspack_import_3.readHeader)(derivedIdentityHeaders, header),
|
|
366
265
|
reason: identityBindingStrict ? 'client_override_rejected' : 'client_override_blocked'
|
|
367
266
|
};
|
|
368
267
|
identityBinding?.onViolation?.(violation);
|
|
369
|
-
if (identityBindingStrict) throw new IdentityBindingViolationError(violation);
|
|
370
|
-
deleteHeader(headers, header);
|
|
268
|
+
if (identityBindingStrict) throw new _policyCore__rspack_import_3.IdentityBindingViolationError(violation);
|
|
269
|
+
(0, _policyCore__rspack_import_3.deleteHeader)(headers, header);
|
|
371
270
|
}
|
|
372
271
|
Object.keys(derivedIdentityHeaders).forEach((header)=>{
|
|
373
|
-
writeHeader(headers, header, derivedIdentityHeaders[header]);
|
|
272
|
+
(0, _policyCore__rspack_import_3.writeHeader)(headers, header, derivedIdentityHeaders[header]);
|
|
374
273
|
});
|
|
375
274
|
}
|
|
376
275
|
body = payload.data && 'object' == typeof payload.data ? JSON.stringify(payload.data) : payload.body;
|
|
@@ -388,50 +287,11 @@ var __webpack_exports__ = {};
|
|
|
388
287
|
}
|
|
389
288
|
headers.accept = "application/json,*/*;q=0.8";
|
|
390
289
|
const configDomain = domainMap.get(requestId);
|
|
391
|
-
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);
|
|
392
291
|
finalURL = `${configDomain || ''}${finalURL}`;
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
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)({
|
|
292
|
+
attachEnvelopeHeaderIfRequired(headers, requestId, finalURL);
|
|
293
|
+
attachSecuredOperationHeaders(headers, requestId, method, path, operationContext);
|
|
294
|
+
return (0, _transport__rspack_import_4.executeWithResilience)({
|
|
435
295
|
requestId,
|
|
436
296
|
target: 'browser',
|
|
437
297
|
method,
|
|
@@ -447,16 +307,21 @@ var __webpack_exports__ = {};
|
|
|
447
307
|
};
|
|
448
308
|
return sender;
|
|
449
309
|
};
|
|
450
|
-
const createUploader = ({ path, domain, requestId = 'default' })=>{
|
|
310
|
+
const createUploader = ({ path, domain, requestId = 'default', operationContext })=>{
|
|
451
311
|
const getFinalPath = (0, path_to_regexp__rspack_import_0.compile)(path, {
|
|
452
312
|
encode: encodeURIComponent
|
|
453
313
|
});
|
|
454
314
|
const sender = (...args)=>{
|
|
455
|
-
const fetcher =
|
|
456
|
-
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
|
+
};
|
|
457
320
|
const finalPath = getFinalPath(params);
|
|
458
321
|
const configDomain = domainMap.get(requestId);
|
|
459
322
|
const finalURL = `${configDomain || domain || ''}${finalPath}`;
|
|
323
|
+
attachEnvelopeHeaderIfRequired(headers, requestId, finalURL);
|
|
324
|
+
attachSecuredOperationHeaders(headers, requestId, 'POST', path, operationContext);
|
|
460
325
|
return fetcher(finalURL, {
|
|
461
326
|
method: 'POST',
|
|
462
327
|
body,
|
|
@@ -465,6 +330,17 @@ var __webpack_exports__ = {};
|
|
|
465
330
|
};
|
|
466
331
|
return sender;
|
|
467
332
|
};
|
|
333
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
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
|
|
339
|
+
}, {
|
|
340
|
+
configure: configure,
|
|
341
|
+
createRequest: createRequest,
|
|
342
|
+
createUploader: createUploader
|
|
343
|
+
});
|
|
468
344
|
})();
|
|
469
345
|
exports.CrossOriginEnvelopePolicyError = __webpack_exports__.CrossOriginEnvelopePolicyError;
|
|
470
346
|
exports.IdentityBindingViolationError = __webpack_exports__.IdentityBindingViolationError;
|
package/dist/cjs/handleRes.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -23,9 +27,6 @@ var __webpack_require__ = {};
|
|
|
23
27
|
})();
|
|
24
28
|
var __webpack_exports__ = {};
|
|
25
29
|
__webpack_require__.r(__webpack_exports__);
|
|
26
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
handleRes: ()=>handleRes
|
|
28
|
-
});
|
|
29
30
|
const handleRes = async (res)=>{
|
|
30
31
|
const contentType = res.headers.get('content-type');
|
|
31
32
|
if (!res.ok) {
|
|
@@ -40,6 +41,9 @@ const handleRes = async (res)=>{
|
|
|
40
41
|
if (contentType?.includes('image/png')) return res;
|
|
41
42
|
return res.text();
|
|
42
43
|
};
|
|
44
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
45
|
+
handleRes: handleRes
|
|
46
|
+
});
|
|
43
47
|
exports.handleRes = __webpack_exports__.handleRes;
|
|
44
48
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
45
49
|
"handleRes"
|