@bleedingdev/modern-js-create-request 3.2.0-ultramodern.98 → 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
|
@@ -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.
|
|
20
|
+
"version": "3.4.0-ultramodern.0",
|
|
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,17 +62,19 @@
|
|
|
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.
|
|
65
|
-
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.
|
|
65
|
+
"@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.4.0-ultramodern.0",
|
|
66
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.4.0-ultramodern.0"
|
|
66
67
|
},
|
|
67
68
|
"devDependencies": {
|
|
68
|
-
"@rslib/core": "0.
|
|
69
|
-
"@types/node": "^
|
|
69
|
+
"@rslib/core": "0.23.0",
|
|
70
|
+
"@types/node": "^26.0.0",
|
|
70
71
|
"@types/qs": "^6.15.1",
|
|
71
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
72
|
+
"@typescript/native-preview": "7.0.0-dev.20260624.1",
|
|
73
|
+
"happy-dom": "^20.10.6",
|
|
72
74
|
"nock": "^14.0.15",
|
|
73
|
-
"
|
|
74
|
-
"@scripts/rstest-config": "2.66.0"
|
|
75
|
+
"typescript": "^6.0.3",
|
|
76
|
+
"@scripts/rstest-config": "2.66.0",
|
|
77
|
+
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.4.0-ultramodern.0"
|
|
75
78
|
},
|
|
76
79
|
"sideEffects": false,
|
|
77
80
|
"publishConfig": {
|
|
@@ -80,7 +83,7 @@
|
|
|
80
83
|
},
|
|
81
84
|
"scripts": {
|
|
82
85
|
"dev": "rslib build --watch",
|
|
83
|
-
"build": "rslib build",
|
|
86
|
+
"build": "rslib build && pnpm -w tsgo:dts \"$PWD\"",
|
|
84
87
|
"test": "rstest --passWithNoTests"
|
|
85
88
|
}
|
|
86
89
|
}
|