@bleedingdev/modern-js-create-request 3.2.0-ultramodern.12 → 3.2.0-ultramodern.121

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
+ };
@@ -5,7 +5,7 @@ export type RequestContextInput = {
5
5
  headers?: Record<string, unknown>;
6
6
  locale?: string;
7
7
  traceparent?: string;
8
- operationContext?: Pick<OperationContext, 'traceparent' | 'traceId' | 'spanId'>;
8
+ operationContext?: OperationContext;
9
9
  };
10
10
  export type RequestContextSnapshot = {
11
11
  headers: Record<string, string>;
@@ -13,6 +13,7 @@ export type RequestContextSnapshot = {
13
13
  traceparent?: string;
14
14
  traceId?: string;
15
15
  spanId?: string;
16
+ operationContext?: OperationContext;
16
17
  };
17
18
  export declare function createRequestContextSnapshot(input?: RequestContextInput): RequestContextSnapshot;
18
19
  export declare function createRequestContextHeaders(input?: RequestContextInput): Record<string, string>;
@@ -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;
@@ -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;
@@ -119,15 +119,22 @@ export type OperationContractOptions = {
119
119
  requireOperationVersion?: boolean;
120
120
  onViolation?: (violation: OperationContractViolation) => void;
121
121
  };
122
+ export type OperationContextSource = 'client' | 'server' | 'generated-client' | 'effect-adapter' | 'data-platform' | 'unknown';
122
123
  export type OperationContext = {
124
+ requestId?: string;
123
125
  operationId?: string;
124
126
  routePath?: string;
125
127
  method?: string;
126
128
  schemaHash?: string;
127
129
  operationVersion?: number;
130
+ locale?: string;
128
131
  traceparent?: string;
129
132
  traceId?: string;
130
133
  spanId?: string;
134
+ source?: OperationContextSource;
135
+ scope?: Record<string, unknown>;
136
+ sessionClaims?: Record<string, unknown>;
137
+ attributes?: Record<string, unknown>;
131
138
  };
132
139
  export type RequestCreatorOptions<F = typeof fetch> = {
133
140
  path: string;
@@ -147,6 +154,7 @@ export type UploadCreatorOptions = {
147
154
  path: string;
148
155
  domain?: string;
149
156
  requestId?: string;
157
+ operationContext?: OperationContext;
150
158
  };
151
159
  export type UploadCreator = (options: UploadCreatorOptions) => Sender;
152
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.12",
20
+ "version": "3.2.0-ultramodern.121",
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
  },
@@ -57,21 +58,22 @@
57
58
  }
58
59
  },
59
60
  "dependencies": {
60
- "@swc/helpers": "^0.5.21",
61
+ "@swc/helpers": "^0.5.23",
61
62
  "encoding": "^0.1.13",
62
63
  "path-to-regexp": "^8.4.2",
63
- "qs": "^6.15.1",
64
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.12",
65
- "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.2.0-ultramodern.12"
64
+ "qs": "^6.15.2",
65
+ "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.2.0-ultramodern.121",
66
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.121"
66
67
  },
67
68
  "devDependencies": {
68
- "@rslib/core": "0.21.5",
69
- "@types/node": "^25.8.0",
69
+ "@rslib/core": "0.22.0",
70
+ "@types/node": "^25.9.3",
70
71
  "@types/qs": "^6.15.1",
71
- "@typescript/native-preview": "7.0.0-dev.20260516.1",
72
+ "@typescript/native-preview": "7.0.0-dev.20260610.1",
73
+ "happy-dom": "^20.10.2",
72
74
  "nock": "^14.0.15",
73
- "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.12",
74
- "@scripts/rstest-config": "2.66.0"
75
+ "@scripts/rstest-config": "2.66.0",
76
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.121"
75
77
  },
76
78
  "sideEffects": false,
77
79
  "publishConfig": {
@@ -80,7 +82,7 @@
80
82
  },
81
83
  "scripts": {
82
84
  "dev": "rslib build --watch",
83
- "build": "rslib build",
85
+ "build": "rslib build && pnpm -w tsgo:dts \"$PWD\"",
84
86
  "test": "rstest --passWithNoTests"
85
87
  }
86
88
  }