@bleedingdev/modern-js-create-request 3.2.0-ultramodern.120 → 3.2.0-ultramodern.122
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 +5 -4
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { parseTraceparent } from "./traceparent.mjs";
|
|
3
|
+
const TRACEPARENT_HEADER = 'traceparent';
|
|
4
|
+
const readProcessEnv = (key)=>{
|
|
5
|
+
if ("u" < typeof process || void 0 === process.env || 'string' != typeof process.env[key]) return;
|
|
6
|
+
return process.env[key];
|
|
7
|
+
};
|
|
8
|
+
const isStrictDefaultRequestIdEnabled = ()=>'true' === readProcessEnv('MODERN_BFF_STRICT_DEFAULT_REQUEST_ID');
|
|
9
|
+
const isSecuredRequestId = (requestId)=>'default' !== requestId || isStrictDefaultRequestIdEnabled();
|
|
10
|
+
const isEmptyDomain = (domain)=>'string' != typeof domain || '' === domain.trim();
|
|
11
|
+
const firstHeaderValue = (value)=>Array.isArray(value) ? value[0] : value;
|
|
12
|
+
const findHeaderKey = (headers, header)=>{
|
|
13
|
+
const normalized = header.toLowerCase();
|
|
14
|
+
return Object.keys(headers).find((key)=>key.toLowerCase() === normalized);
|
|
15
|
+
};
|
|
16
|
+
const readHeader = (headers, header)=>{
|
|
17
|
+
const key = findHeaderKey(headers, header);
|
|
18
|
+
return 'string' == typeof key ? headers[key] : void 0;
|
|
19
|
+
};
|
|
20
|
+
const writeHeader = (headers, header, value)=>{
|
|
21
|
+
if (void 0 === value) return;
|
|
22
|
+
const key = findHeaderKey(headers, header);
|
|
23
|
+
if ('string' == typeof key && key !== header) delete headers[key];
|
|
24
|
+
headers[header] = value;
|
|
25
|
+
};
|
|
26
|
+
const deleteHeader = (headers, header)=>{
|
|
27
|
+
const key = findHeaderKey(headers, header);
|
|
28
|
+
if ('string' == typeof key) delete headers[key];
|
|
29
|
+
};
|
|
30
|
+
const toOrigin = (value)=>{
|
|
31
|
+
if (!value) return;
|
|
32
|
+
try {
|
|
33
|
+
return new URL(value).origin;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const parseTraceparentValue = (value)=>parseTraceparent(firstHeaderValue(value));
|
|
39
|
+
const extractPathParamNames = (path)=>Array.from(path.matchAll(/:([A-Za-z0-9_]+)/g)).flatMap(([, key])=>key ? [
|
|
40
|
+
key
|
|
41
|
+
] : []);
|
|
42
|
+
const buildOperationContext = ({ requestId, method, path, operationContext, traceparent })=>{
|
|
43
|
+
const routePath = operationContext?.routePath || path;
|
|
44
|
+
const operationMethod = (operationContext?.method || method || 'GET').toUpperCase();
|
|
45
|
+
const rawOperationId = operationContext?.operationId || `${operationMethod}:${routePath}`;
|
|
46
|
+
const operationId = rawOperationId.startsWith(`${requestId}:`) ? rawOperationId : `${requestId}:${rawOperationId}`;
|
|
47
|
+
const traceparentValue = operationContext?.traceparent || ('string' == typeof firstHeaderValue(traceparent) ? String(firstHeaderValue(traceparent)) : void 0);
|
|
48
|
+
const parsedTraceContext = operationContext?.traceId && operationContext?.spanId ? {
|
|
49
|
+
traceId: operationContext.traceId,
|
|
50
|
+
spanId: operationContext.spanId
|
|
51
|
+
} : parseTraceparentValue(traceparentValue);
|
|
52
|
+
return {
|
|
53
|
+
requestId,
|
|
54
|
+
operationId,
|
|
55
|
+
routePath,
|
|
56
|
+
method: operationMethod,
|
|
57
|
+
...operationContext?.schemaHash ? {
|
|
58
|
+
schemaHash: operationContext.schemaHash
|
|
59
|
+
} : {},
|
|
60
|
+
...'number' == typeof operationContext?.operationVersion ? {
|
|
61
|
+
operationVersion: operationContext.operationVersion
|
|
62
|
+
} : {},
|
|
63
|
+
...traceparentValue ? {
|
|
64
|
+
traceparent: traceparentValue
|
|
65
|
+
} : {},
|
|
66
|
+
...parsedTraceContext ? {
|
|
67
|
+
traceId: parsedTraceContext.traceId,
|
|
68
|
+
spanId: parsedTraceContext.spanId
|
|
69
|
+
} : {}
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
class ProducerClientNotInitializedError extends Error {
|
|
73
|
+
constructor(requestId){
|
|
74
|
+
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';
|
|
75
|
+
this.name = 'ProducerClientNotInitializedError';
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
class ProducerDomainNotConfiguredError extends Error {
|
|
79
|
+
constructor(requestId){
|
|
80
|
+
super(`Producer client "${requestId}" must provide setDomain() during configure().`), this.code = 'BFF_PRODUCER_DOMAIN_NOT_CONFIGURED';
|
|
81
|
+
this.name = 'ProducerDomainNotConfiguredError';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
class CrossOriginEnvelopePolicyError extends Error {
|
|
85
|
+
constructor(requestId, sourceOrigin, targetOrigin){
|
|
86
|
+
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';
|
|
87
|
+
this.name = 'CrossOriginEnvelopePolicyError';
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
class IdentityBindingViolationError extends Error {
|
|
91
|
+
constructor(violation){
|
|
92
|
+
super(`Identity header "${violation.header}" for producer "${violation.requestId}" was rejected by server-derived identity binding.`), this.code = 'BFF_IDENTITY_BINDING_VIOLATION';
|
|
93
|
+
this.name = 'IdentityBindingViolationError';
|
|
94
|
+
this.violation = violation;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
class OperationContractViolationError extends Error {
|
|
98
|
+
constructor(violation){
|
|
99
|
+
super(`Operation contract violation "${violation.reason}" for producer "${violation.requestId}" operation "${violation.operationId}".`), this.code = 'BFF_OPERATION_CONTRACT_VIOLATION';
|
|
100
|
+
this.name = 'OperationContractViolationError';
|
|
101
|
+
this.violation = violation;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const validateOperationContract = ({ requestId, target, contextPayload, operationContract })=>{
|
|
105
|
+
const operationContractEnabled = operationContract?.enabled ?? isSecuredRequestId(requestId);
|
|
106
|
+
if (!operationContractEnabled) return;
|
|
107
|
+
const strict = operationContract?.strict ?? true;
|
|
108
|
+
const requireSchemaHash = operationContract?.requireSchemaHash ?? true;
|
|
109
|
+
const requireOperationVersion = operationContract?.requireOperationVersion ?? true;
|
|
110
|
+
const maybeReportViolation = (reason)=>{
|
|
111
|
+
const violation = {
|
|
112
|
+
requestId,
|
|
113
|
+
target,
|
|
114
|
+
operationId: contextPayload.operationId,
|
|
115
|
+
routePath: contextPayload.routePath,
|
|
116
|
+
method: contextPayload.method,
|
|
117
|
+
schemaHash: 'string' == typeof contextPayload.schemaHash ? contextPayload.schemaHash : void 0,
|
|
118
|
+
operationVersion: 'number' == typeof contextPayload.operationVersion ? contextPayload.operationVersion : void 0,
|
|
119
|
+
reason
|
|
120
|
+
};
|
|
121
|
+
operationContract?.onViolation?.(violation);
|
|
122
|
+
if (strict) throw new OperationContractViolationError(violation);
|
|
123
|
+
};
|
|
124
|
+
if (requireSchemaHash && 'string' != typeof contextPayload.schemaHash) maybeReportViolation('missing_schema_hash');
|
|
125
|
+
if (requireOperationVersion && 'number' != typeof contextPayload.operationVersion) maybeReportViolation('missing_operation_version');
|
|
126
|
+
};
|
|
127
|
+
const resolveConfiguredRequest = (configuredRequests, requestId, fallback)=>{
|
|
128
|
+
const configuredRequest = configuredRequests.get(requestId);
|
|
129
|
+
if (configuredRequest) return configuredRequest;
|
|
130
|
+
if ('default' !== requestId) throw new ProducerClientNotInitializedError(requestId);
|
|
131
|
+
return fallback;
|
|
132
|
+
};
|
|
133
|
+
const buildEnvelopeHeaderValue = ({ requestId, target, sourceOrigin, targetOrigin, traceContext, allowCrossOriginEnvelope })=>{
|
|
134
|
+
const isCrossOrigin = Boolean(sourceOrigin) && Boolean(targetOrigin) && sourceOrigin !== targetOrigin;
|
|
135
|
+
if (isCrossOrigin) {
|
|
136
|
+
const isAllowed = 'function' == typeof allowCrossOriginEnvelope ? allowCrossOriginEnvelope({
|
|
137
|
+
requestId,
|
|
138
|
+
sourceOrigin,
|
|
139
|
+
targetOrigin,
|
|
140
|
+
target
|
|
141
|
+
}) : true === allowCrossOriginEnvelope;
|
|
142
|
+
if (!isAllowed) throw new CrossOriginEnvelopePolicyError(requestId, sourceOrigin, targetOrigin);
|
|
143
|
+
}
|
|
144
|
+
return JSON.stringify({
|
|
145
|
+
requestId,
|
|
146
|
+
target,
|
|
147
|
+
timestamp: Date.now(),
|
|
148
|
+
sourceOrigin,
|
|
149
|
+
targetOrigin,
|
|
150
|
+
...traceContext ? {
|
|
151
|
+
traceId: traceContext.traceId,
|
|
152
|
+
spanId: traceContext.spanId
|
|
153
|
+
} : {}
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
const attachOperationContextHeaders = ({ headers, requestId, target, method, path, operationContext, operationContract, operationContextHeader, operationContextDetailHeader })=>{
|
|
157
|
+
if (void 0 === readHeader(headers, TRACEPARENT_HEADER) && operationContext?.traceparent) writeHeader(headers, TRACEPARENT_HEADER, operationContext.traceparent);
|
|
158
|
+
const contextPayload = buildOperationContext({
|
|
159
|
+
requestId,
|
|
160
|
+
method,
|
|
161
|
+
path,
|
|
162
|
+
operationContext,
|
|
163
|
+
traceparent: readHeader(headers, TRACEPARENT_HEADER)
|
|
164
|
+
});
|
|
165
|
+
validateOperationContract({
|
|
166
|
+
requestId,
|
|
167
|
+
target,
|
|
168
|
+
contextPayload,
|
|
169
|
+
operationContract
|
|
170
|
+
});
|
|
171
|
+
if (void 0 === readHeader(headers, operationContextHeader)) writeHeader(headers, operationContextHeader, contextPayload.operationId);
|
|
172
|
+
writeHeader(headers, operationContextDetailHeader, JSON.stringify(contextPayload));
|
|
173
|
+
return contextPayload;
|
|
174
|
+
};
|
|
175
|
+
export { CrossOriginEnvelopePolicyError, IdentityBindingViolationError, OperationContractViolationError, ProducerClientNotInitializedError, ProducerDomainNotConfiguredError, TRACEPARENT_HEADER, attachOperationContextHeaders, buildEnvelopeHeaderValue, buildOperationContext, deleteHeader, extractPathParamNames, findHeaderKey, firstHeaderValue, isEmptyDomain, isSecuredRequestId, isStrictDefaultRequestIdEnabled, parseTraceparentValue, readHeader, resolveConfiguredRequest, toOrigin, validateOperationContract, writeHeader };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
+
import { parseTraceparent } from "./traceparent.mjs";
|
|
2
3
|
const BFF_LOCALE_HEADER = 'accept-language';
|
|
3
4
|
const BFF_TRACEPARENT_HEADER = 'traceparent';
|
|
4
|
-
const TRACEPARENT_REGEX = /^00-([0-9a-f]{32})-([0-9a-f]{16})-[0-9a-f]{2}$/i;
|
|
5
5
|
const readHeader = (headers, header)=>{
|
|
6
6
|
if (!headers) return;
|
|
7
7
|
const normalized = header.toLowerCase();
|
|
@@ -11,17 +11,6 @@ const readHeader = (headers, header)=>{
|
|
|
11
11
|
return Array.isArray(value) ? value[0] : value;
|
|
12
12
|
};
|
|
13
13
|
const readString = (value)=>'string' == typeof value && value.length > 0 ? value : void 0;
|
|
14
|
-
function parseTraceparent(traceparent) {
|
|
15
|
-
if (!traceparent) return;
|
|
16
|
-
const match = traceparent.trim().match(TRACEPARENT_REGEX);
|
|
17
|
-
if (!match) return;
|
|
18
|
-
const [, traceId, spanId] = match;
|
|
19
|
-
if (!traceId || !spanId) return;
|
|
20
|
-
return {
|
|
21
|
-
traceId: traceId.toLowerCase(),
|
|
22
|
-
spanId: spanId.toLowerCase()
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
14
|
function createOperationContextSnapshot(operationContext, safeContext) {
|
|
26
15
|
if (!operationContext) return;
|
|
27
16
|
const snapshot = {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
const TRACEPARENT_REGEX = /^00-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/i;
|
|
3
|
+
const isAllZeroHex = (value)=>/^0+$/.test(value);
|
|
4
|
+
function parseTraceparent(traceparent) {
|
|
5
|
+
if (!traceparent) return;
|
|
6
|
+
const match = traceparent.trim().match(TRACEPARENT_REGEX);
|
|
7
|
+
if (!match) return;
|
|
8
|
+
const [, rawTraceId, rawSpanId, rawFlags] = match;
|
|
9
|
+
if (!rawTraceId || !rawSpanId || !rawFlags) return;
|
|
10
|
+
const traceId = rawTraceId.toLowerCase();
|
|
11
|
+
const spanId = rawSpanId.toLowerCase();
|
|
12
|
+
if (isAllZeroHex(traceId) || isAllZeroHex(spanId)) return;
|
|
13
|
+
return {
|
|
14
|
+
traceId,
|
|
15
|
+
spanId,
|
|
16
|
+
sampled: (0x1 & Number.parseInt(rawFlags, 16)) === 1
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export { parseTraceparent };
|
package/dist/types/browser.d.ts
CHANGED
|
@@ -1,28 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export
|
|
3
|
-
readonly code = "BFF_PRODUCER_CLIENT_NOT_INITIALIZED";
|
|
4
|
-
constructor(requestId: string);
|
|
5
|
-
}
|
|
6
|
-
export declare class ProducerDomainNotConfiguredError extends Error {
|
|
7
|
-
readonly code = "BFF_PRODUCER_DOMAIN_NOT_CONFIGURED";
|
|
8
|
-
constructor(requestId: string);
|
|
9
|
-
}
|
|
10
|
-
export declare class CrossOriginEnvelopePolicyError extends Error {
|
|
11
|
-
readonly code = "BFF_CROSS_ORIGIN_ENVELOPE_NOT_ALLOWED";
|
|
12
|
-
constructor(requestId: string, sourceOrigin?: string, targetOrigin?: string);
|
|
13
|
-
}
|
|
14
|
-
export declare class IdentityBindingViolationError extends Error {
|
|
15
|
-
readonly code = "BFF_IDENTITY_BINDING_VIOLATION";
|
|
16
|
-
readonly violation: IdentityBindingViolation;
|
|
17
|
-
constructor(violation: IdentityBindingViolation);
|
|
18
|
-
}
|
|
19
|
-
export declare class OperationContractViolationError extends Error {
|
|
20
|
-
readonly code = "BFF_OPERATION_CONTRACT_VIOLATION";
|
|
21
|
-
readonly violation: OperationContractViolation;
|
|
22
|
-
constructor(violation: OperationContractViolation);
|
|
23
|
-
}
|
|
1
|
+
import type { IOptions, RequestCreator, UploadCreator } from './types';
|
|
2
|
+
export { CrossOriginEnvelopePolicyError, IdentityBindingViolationError, OperationContractViolationError, ProducerClientNotInitializedError, ProducerDomainNotConfiguredError, } from './policyCore';
|
|
24
3
|
export declare const configure: (options: IOptions) => void;
|
|
25
4
|
export declare const createRequest: RequestCreator;
|
|
26
5
|
export declare const createUploader: UploadCreator;
|
|
27
6
|
export * from './requestContext';
|
|
7
|
+
export * from './traceparent';
|
|
28
8
|
export * from './types';
|
package/dist/types/node.d.ts
CHANGED
|
@@ -1,29 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IOptions, RequestCreator, UploadCreator } from './types';
|
|
2
|
+
export { CrossOriginEnvelopePolicyError, IdentityBindingViolationError, OperationContractViolationError, ProducerClientNotInitializedError, ProducerDomainNotConfiguredError, } from './policyCore';
|
|
2
3
|
type Fetch = typeof fetch;
|
|
3
|
-
export declare class ProducerClientNotInitializedError extends Error {
|
|
4
|
-
readonly code = "BFF_PRODUCER_CLIENT_NOT_INITIALIZED";
|
|
5
|
-
constructor(requestId: string);
|
|
6
|
-
}
|
|
7
|
-
export declare class ProducerDomainNotConfiguredError extends Error {
|
|
8
|
-
readonly code = "BFF_PRODUCER_DOMAIN_NOT_CONFIGURED";
|
|
9
|
-
constructor(requestId: string);
|
|
10
|
-
}
|
|
11
|
-
export declare class CrossOriginEnvelopePolicyError extends Error {
|
|
12
|
-
readonly code = "BFF_CROSS_ORIGIN_ENVELOPE_NOT_ALLOWED";
|
|
13
|
-
constructor(requestId: string, sourceOrigin?: string, targetOrigin?: string);
|
|
14
|
-
}
|
|
15
|
-
export declare class IdentityBindingViolationError extends Error {
|
|
16
|
-
readonly code = "BFF_IDENTITY_BINDING_VIOLATION";
|
|
17
|
-
readonly violation: IdentityBindingViolation;
|
|
18
|
-
constructor(violation: IdentityBindingViolation);
|
|
19
|
-
}
|
|
20
|
-
export declare class OperationContractViolationError extends Error {
|
|
21
|
-
readonly code = "BFF_OPERATION_CONTRACT_VIOLATION";
|
|
22
|
-
readonly violation: OperationContractViolation;
|
|
23
|
-
constructor(violation: OperationContractViolation);
|
|
24
|
-
}
|
|
25
4
|
export declare const configure: (options: IOptions<Fetch>) => void;
|
|
26
5
|
export declare const createRequest: RequestCreator<Fetch>;
|
|
27
6
|
export declare const createUploader: UploadCreator;
|
|
28
7
|
export * from './requestContext';
|
|
8
|
+
export * from './traceparent';
|
|
29
9
|
export * from './types';
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { IdentityBindingViolation, OperationContext, OperationContractOptions, OperationContractViolation, TransportTarget } from './types';
|
|
2
|
+
export declare const TRACEPARENT_HEADER = "traceparent";
|
|
3
|
+
export declare const isStrictDefaultRequestIdEnabled: () => boolean;
|
|
4
|
+
export declare const isSecuredRequestId: (requestId: string) => boolean;
|
|
5
|
+
export declare const isEmptyDomain: (domain?: string) => boolean;
|
|
6
|
+
export declare const firstHeaderValue: (value: unknown) => any;
|
|
7
|
+
export declare const findHeaderKey: (headers: Record<string, any>, header: string) => string | undefined;
|
|
8
|
+
export declare const readHeader: (headers: Record<string, any>, header: string) => any;
|
|
9
|
+
export declare const writeHeader: (headers: Record<string, any>, header: string, value: unknown) => void;
|
|
10
|
+
export declare const deleteHeader: (headers: Record<string, any>, header: string) => void;
|
|
11
|
+
export declare const toOrigin: (value?: string) => string | undefined;
|
|
12
|
+
export declare const parseTraceparentValue: (value: unknown) => import("./traceparent").TraceparentContext | undefined;
|
|
13
|
+
export declare const extractPathParamNames: (path: string) => string[];
|
|
14
|
+
export declare const buildOperationContext: ({ requestId, method, path, operationContext, traceparent, }: {
|
|
15
|
+
requestId: string;
|
|
16
|
+
method: string;
|
|
17
|
+
path: string;
|
|
18
|
+
operationContext?: OperationContext | undefined;
|
|
19
|
+
traceparent?: unknown;
|
|
20
|
+
}) => {
|
|
21
|
+
requestId: string;
|
|
22
|
+
operationId: string;
|
|
23
|
+
routePath: string;
|
|
24
|
+
method: string;
|
|
25
|
+
schemaHash?: string | undefined;
|
|
26
|
+
operationVersion?: number | undefined;
|
|
27
|
+
traceparent?: string | undefined;
|
|
28
|
+
traceId?: string | undefined;
|
|
29
|
+
spanId?: string | undefined;
|
|
30
|
+
};
|
|
31
|
+
export type OperationContextPayload = ReturnType<typeof buildOperationContext>;
|
|
32
|
+
export declare class ProducerClientNotInitializedError extends Error {
|
|
33
|
+
readonly code = "BFF_PRODUCER_CLIENT_NOT_INITIALIZED";
|
|
34
|
+
constructor(requestId: string);
|
|
35
|
+
}
|
|
36
|
+
export declare class ProducerDomainNotConfiguredError extends Error {
|
|
37
|
+
readonly code = "BFF_PRODUCER_DOMAIN_NOT_CONFIGURED";
|
|
38
|
+
constructor(requestId: string);
|
|
39
|
+
}
|
|
40
|
+
export declare class CrossOriginEnvelopePolicyError extends Error {
|
|
41
|
+
readonly code = "BFF_CROSS_ORIGIN_ENVELOPE_NOT_ALLOWED";
|
|
42
|
+
constructor(requestId: string, sourceOrigin?: string, targetOrigin?: string);
|
|
43
|
+
}
|
|
44
|
+
export declare class IdentityBindingViolationError extends Error {
|
|
45
|
+
readonly code = "BFF_IDENTITY_BINDING_VIOLATION";
|
|
46
|
+
readonly violation: IdentityBindingViolation;
|
|
47
|
+
constructor(violation: IdentityBindingViolation);
|
|
48
|
+
}
|
|
49
|
+
export declare class OperationContractViolationError extends Error {
|
|
50
|
+
readonly code = "BFF_OPERATION_CONTRACT_VIOLATION";
|
|
51
|
+
readonly violation: OperationContractViolation;
|
|
52
|
+
constructor(violation: OperationContractViolation);
|
|
53
|
+
}
|
|
54
|
+
export declare const validateOperationContract: ({ requestId, target, contextPayload, operationContract, }: {
|
|
55
|
+
requestId: string;
|
|
56
|
+
target: TransportTarget;
|
|
57
|
+
contextPayload: OperationContextPayload;
|
|
58
|
+
operationContract: OperationContractOptions | undefined;
|
|
59
|
+
}) => void;
|
|
60
|
+
export declare const resolveConfiguredRequest: <F>(configuredRequests: Map<string, F>, requestId: string, fallback: F) => F;
|
|
61
|
+
/**
|
|
62
|
+
* Builds the JSON value for the `x-modernjs-bff-envelope` header and throws
|
|
63
|
+
* when the cross-origin envelope policy denies the flow. Returns the
|
|
64
|
+
* serialized envelope.
|
|
65
|
+
*/
|
|
66
|
+
export declare const buildEnvelopeHeaderValue: ({ requestId, target, sourceOrigin, targetOrigin, traceContext, allowCrossOriginEnvelope, }: {
|
|
67
|
+
requestId: string;
|
|
68
|
+
target: TransportTarget;
|
|
69
|
+
sourceOrigin: string | undefined;
|
|
70
|
+
targetOrigin: string | undefined;
|
|
71
|
+
traceContext: {
|
|
72
|
+
traceId: string;
|
|
73
|
+
spanId: string;
|
|
74
|
+
} | null | undefined;
|
|
75
|
+
allowCrossOriginEnvelope: boolean | ((options: {
|
|
76
|
+
requestId: string;
|
|
77
|
+
sourceOrigin?: string;
|
|
78
|
+
targetOrigin?: string;
|
|
79
|
+
target: TransportTarget;
|
|
80
|
+
}) => boolean) | undefined;
|
|
81
|
+
}) => string;
|
|
82
|
+
/**
|
|
83
|
+
* Derives the operation context for a secured requestId, validates it against
|
|
84
|
+
* the configured operation contract and writes the `x-operation-id` and
|
|
85
|
+
* `x-modernjs-bff-operation-context` headers (without clobbering caller
|
|
86
|
+
* provided values for the id header).
|
|
87
|
+
*/
|
|
88
|
+
export declare const attachOperationContextHeaders: ({ headers, requestId, target, method, path, operationContext, operationContract, operationContextHeader, operationContextDetailHeader, }: {
|
|
89
|
+
headers: Record<string, any>;
|
|
90
|
+
requestId: string;
|
|
91
|
+
target: TransportTarget;
|
|
92
|
+
method: string;
|
|
93
|
+
path: string;
|
|
94
|
+
operationContext: OperationContext | undefined;
|
|
95
|
+
operationContract: OperationContractOptions | undefined;
|
|
96
|
+
operationContextHeader: string;
|
|
97
|
+
operationContextDetailHeader: string;
|
|
98
|
+
}) => {
|
|
99
|
+
requestId: string;
|
|
100
|
+
operationId: string;
|
|
101
|
+
routePath: string;
|
|
102
|
+
method: string;
|
|
103
|
+
schemaHash?: string | undefined;
|
|
104
|
+
operationVersion?: number | undefined;
|
|
105
|
+
traceparent?: string | undefined;
|
|
106
|
+
traceId?: string | undefined;
|
|
107
|
+
spanId?: string | undefined;
|
|
108
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type TraceparentContext = {
|
|
2
|
+
traceId: string;
|
|
3
|
+
spanId: string;
|
|
4
|
+
sampled: boolean;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Parse a W3C trace context `traceparent` header (version 00).
|
|
8
|
+
* All-zero trace ids and span ids are rejected per the W3C spec.
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseTraceparent(traceparent: string | undefined | null): TraceparentContext | undefined;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -105,7 +105,7 @@ export type CrossProjectOperationContract = {
|
|
|
105
105
|
schemaHash?: string;
|
|
106
106
|
operationVersion?: number;
|
|
107
107
|
};
|
|
108
|
-
export type CrossProjectPolicyViolationReason = 'missing_envelope' | 'invalid_envelope' | 'missing_request_id' | 'namespace_not_allowed' | 'missing_operation_context' | 'operation_context_mismatch' | 'missing_operation_context_details' | 'invalid_operation_context_details' | 'operation_context_details_request_id_mismatch' | 'missing_operation_schema_hash' | 'missing_operation_version' | 'unknown_operation_contract' | 'operation_schema_hash_mismatch' | 'operation_version_mismatch';
|
|
108
|
+
export type CrossProjectPolicyViolationReason = 'missing_envelope' | 'invalid_envelope' | 'missing_request_id' | 'namespace_not_allowed' | 'missing_operation_context' | 'operation_context_mismatch' | 'missing_operation_context_details' | 'invalid_operation_context_details' | 'operation_context_details_request_id_mismatch' | 'missing_operation_schema_hash' | 'missing_operation_version' | 'unknown_operation_contract' | 'operation_schema_hash_mismatch' | 'operation_version_mismatch' | 'producer_identity_mismatch';
|
|
109
109
|
export type CrossProjectPolicyViolation = {
|
|
110
110
|
code: 'BFF_CROSS_PROJECT_POLICY_DENIED';
|
|
111
111
|
reason: CrossProjectPolicyViolationReason;
|
|
@@ -154,6 +154,7 @@ export type UploadCreatorOptions = {
|
|
|
154
154
|
path: string;
|
|
155
155
|
domain?: string;
|
|
156
156
|
requestId?: string;
|
|
157
|
+
operationContext?: OperationContext;
|
|
157
158
|
};
|
|
158
159
|
export type UploadCreator = (options: UploadCreatorOptions) => Sender;
|
|
159
160
|
export type IOptions<F = typeof fetch> = {
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"modern",
|
|
18
18
|
"modern.js"
|
|
19
19
|
],
|
|
20
|
-
"version": "3.2.0-ultramodern.
|
|
20
|
+
"version": "3.2.0-ultramodern.122",
|
|
21
21
|
"modern:source": "./src/node.ts",
|
|
22
22
|
"types": "./dist/types/browser.d.ts",
|
|
23
23
|
"main": "./dist/cjs/node.js",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"./server": {
|
|
41
41
|
"types": "./dist/types/node.d.ts",
|
|
42
42
|
"modern:source": "./src/node.ts",
|
|
43
|
+
"require": "./dist/cjs/node.js",
|
|
43
44
|
"default": "./dist/esm/node.mjs"
|
|
44
45
|
}
|
|
45
46
|
},
|
|
@@ -61,8 +62,8 @@
|
|
|
61
62
|
"encoding": "^0.1.13",
|
|
62
63
|
"path-to-regexp": "^8.4.2",
|
|
63
64
|
"qs": "^6.15.2",
|
|
64
|
-
"@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.2.0-ultramodern.
|
|
65
|
-
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.
|
|
65
|
+
"@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.2.0-ultramodern.122",
|
|
66
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.122"
|
|
66
67
|
},
|
|
67
68
|
"devDependencies": {
|
|
68
69
|
"@rslib/core": "0.22.0",
|
|
@@ -71,7 +72,7 @@
|
|
|
71
72
|
"@typescript/native-preview": "7.0.0-dev.20260610.1",
|
|
72
73
|
"happy-dom": "^20.10.2",
|
|
73
74
|
"nock": "^14.0.15",
|
|
74
|
-
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.
|
|
75
|
+
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.122",
|
|
75
76
|
"@scripts/rstest-config": "2.66.0"
|
|
76
77
|
},
|
|
77
78
|
"sideEffects": false,
|