@bleedingdev/modern-js-bff-effect 3.9.3-ultramodern.2 → 3.9.3-ultramodern.3
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.
|
@@ -91,12 +91,48 @@ function runEffectView(request, selection) {
|
|
|
91
91
|
request.then((value)=>resolve(mask(value, selection)), (reason)=>reject(reason));
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
|
+
const operationContextStringFields = [
|
|
95
|
+
'requestId',
|
|
96
|
+
'operationId',
|
|
97
|
+
'routePath',
|
|
98
|
+
'method',
|
|
99
|
+
'schemaHash',
|
|
100
|
+
'traceparent',
|
|
101
|
+
'traceId',
|
|
102
|
+
'spanId'
|
|
103
|
+
];
|
|
104
|
+
function operationContextHeaders(context) {
|
|
105
|
+
if (void 0 === context) return {};
|
|
106
|
+
const detail = {};
|
|
107
|
+
for (const field of operationContextStringFields){
|
|
108
|
+
const value = context[field];
|
|
109
|
+
if ('string' == typeof value && value.length > 0) detail[field] = value;
|
|
110
|
+
}
|
|
111
|
+
if ('number' == typeof context.operationVersion) detail.operationVersion = context.operationVersion;
|
|
112
|
+
if (0 === Object.keys(detail).length) return {};
|
|
113
|
+
return {
|
|
114
|
+
...'string' == typeof detail.operationId ? {
|
|
115
|
+
[request_context_namespaceObject.BFF_OPERATION_CONTEXT_HEADER]: detail.operationId
|
|
116
|
+
} : {},
|
|
117
|
+
[request_context_namespaceObject.BFF_OPERATION_CONTEXT_DETAIL_HEADER]: JSON.stringify(detail)
|
|
118
|
+
};
|
|
119
|
+
}
|
|
94
120
|
function makeEffectHttpApiClient(api, options) {
|
|
95
|
-
const
|
|
121
|
+
const requestContext = (0, request_context_namespaceObject.createRequestContextSnapshot)(options?.requestContext);
|
|
122
|
+
const defaultHeaders = {
|
|
123
|
+
...Object.fromEntries(Object.entries(options?.headers ?? {}).flatMap(([header, value])=>void 0 === value ? [] : [
|
|
124
|
+
[
|
|
125
|
+
header.toLowerCase(),
|
|
126
|
+
value
|
|
127
|
+
]
|
|
128
|
+
])),
|
|
129
|
+
...requestContext.headers,
|
|
130
|
+
...operationContextHeaders(requestContext.operationContext)
|
|
131
|
+
};
|
|
96
132
|
const transformClient = (client)=>{
|
|
97
|
-
const contextClient = 0 === Object.keys(
|
|
133
|
+
const contextClient = 0 === Object.keys(defaultHeaders).length ? client : client.pipe(http_namespaceObject.HttpClient.mapRequest((request)=>{
|
|
98
134
|
let nextRequest = request;
|
|
99
|
-
for (const [header, value] of Object.entries(
|
|
135
|
+
for (const [header, value] of Object.entries(defaultHeaders))if (void 0 === nextRequest.headers[header.toLowerCase()]) nextRequest = http_namespaceObject.HttpClientRequest.setHeader(nextRequest, header, value);
|
|
100
136
|
return nextRequest;
|
|
101
137
|
}));
|
|
102
138
|
const policyClient = options?.crossProject !== void 0 ? (0, external_cross_project_js_namespaceObject.withCrossProjectPolicy)(api, options.crossProject, contextClient) : contextClient;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BFF_OPERATION_CONTEXT_DETAIL_HEADER, BFF_OPERATION_CONTEXT_HEADER, createRequestContextSnapshot } from "@modern-js/runtime-extensions/request-context";
|
|
2
2
|
import * as __rspack_external_effect_Effect_41060786 from "effect/Effect";
|
|
3
3
|
import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";
|
|
4
4
|
import { HttpApi, HttpApiClient, HttpApiEndpoint, HttpApiGroup, HttpApiSchema } from "effect/http-api";
|
|
@@ -39,12 +39,48 @@ function runEffectView(request, selection) {
|
|
|
39
39
|
request.then((value)=>resolve(mask(value, selection)), (reason)=>reject(reason));
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
+
const operationContextStringFields = [
|
|
43
|
+
'requestId',
|
|
44
|
+
'operationId',
|
|
45
|
+
'routePath',
|
|
46
|
+
'method',
|
|
47
|
+
'schemaHash',
|
|
48
|
+
'traceparent',
|
|
49
|
+
'traceId',
|
|
50
|
+
'spanId'
|
|
51
|
+
];
|
|
52
|
+
function operationContextHeaders(context) {
|
|
53
|
+
if (void 0 === context) return {};
|
|
54
|
+
const detail = {};
|
|
55
|
+
for (const field of operationContextStringFields){
|
|
56
|
+
const value = context[field];
|
|
57
|
+
if ('string' == typeof value && value.length > 0) detail[field] = value;
|
|
58
|
+
}
|
|
59
|
+
if ('number' == typeof context.operationVersion) detail.operationVersion = context.operationVersion;
|
|
60
|
+
if (0 === Object.keys(detail).length) return {};
|
|
61
|
+
return {
|
|
62
|
+
...'string' == typeof detail.operationId ? {
|
|
63
|
+
[BFF_OPERATION_CONTEXT_HEADER]: detail.operationId
|
|
64
|
+
} : {},
|
|
65
|
+
[BFF_OPERATION_CONTEXT_DETAIL_HEADER]: JSON.stringify(detail)
|
|
66
|
+
};
|
|
67
|
+
}
|
|
42
68
|
function makeEffectHttpApiClient(api, options) {
|
|
43
|
-
const
|
|
69
|
+
const requestContext = createRequestContextSnapshot(options?.requestContext);
|
|
70
|
+
const defaultHeaders = {
|
|
71
|
+
...Object.fromEntries(Object.entries(options?.headers ?? {}).flatMap(([header, value])=>void 0 === value ? [] : [
|
|
72
|
+
[
|
|
73
|
+
header.toLowerCase(),
|
|
74
|
+
value
|
|
75
|
+
]
|
|
76
|
+
])),
|
|
77
|
+
...requestContext.headers,
|
|
78
|
+
...operationContextHeaders(requestContext.operationContext)
|
|
79
|
+
};
|
|
44
80
|
const transformClient = (client)=>{
|
|
45
|
-
const contextClient = 0 === Object.keys(
|
|
81
|
+
const contextClient = 0 === Object.keys(defaultHeaders).length ? client : client.pipe(HttpClient.mapRequest((request)=>{
|
|
46
82
|
let nextRequest = request;
|
|
47
|
-
for (const [header, value] of Object.entries(
|
|
83
|
+
for (const [header, value] of Object.entries(defaultHeaders))if (void 0 === nextRequest.headers[header.toLowerCase()]) nextRequest = HttpClientRequest.setHeader(nextRequest, header, value);
|
|
48
84
|
return nextRequest;
|
|
49
85
|
}));
|
|
50
86
|
const policyClient = options?.crossProject !== void 0 ? withCrossProjectPolicy(api, options.crossProject, contextClient) : contextClient;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import {
|
|
2
|
+
import { BFF_OPERATION_CONTEXT_DETAIL_HEADER, BFF_OPERATION_CONTEXT_HEADER, createRequestContextSnapshot } from "@modern-js/runtime-extensions/request-context";
|
|
3
3
|
import * as __rspack_external_effect_Effect_41060786 from "effect/Effect";
|
|
4
4
|
import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";
|
|
5
5
|
import { HttpApi, HttpApiClient, HttpApiEndpoint, HttpApiGroup, HttpApiSchema } from "effect/http-api";
|
|
@@ -40,12 +40,48 @@ function runEffectView(request, selection) {
|
|
|
40
40
|
request.then((value)=>resolve(mask(value, selection)), (reason)=>reject(reason));
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
+
const operationContextStringFields = [
|
|
44
|
+
'requestId',
|
|
45
|
+
'operationId',
|
|
46
|
+
'routePath',
|
|
47
|
+
'method',
|
|
48
|
+
'schemaHash',
|
|
49
|
+
'traceparent',
|
|
50
|
+
'traceId',
|
|
51
|
+
'spanId'
|
|
52
|
+
];
|
|
53
|
+
function operationContextHeaders(context) {
|
|
54
|
+
if (void 0 === context) return {};
|
|
55
|
+
const detail = {};
|
|
56
|
+
for (const field of operationContextStringFields){
|
|
57
|
+
const value = context[field];
|
|
58
|
+
if ('string' == typeof value && value.length > 0) detail[field] = value;
|
|
59
|
+
}
|
|
60
|
+
if ('number' == typeof context.operationVersion) detail.operationVersion = context.operationVersion;
|
|
61
|
+
if (0 === Object.keys(detail).length) return {};
|
|
62
|
+
return {
|
|
63
|
+
...'string' == typeof detail.operationId ? {
|
|
64
|
+
[BFF_OPERATION_CONTEXT_HEADER]: detail.operationId
|
|
65
|
+
} : {},
|
|
66
|
+
[BFF_OPERATION_CONTEXT_DETAIL_HEADER]: JSON.stringify(detail)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
43
69
|
function makeEffectHttpApiClient(api, options) {
|
|
44
|
-
const
|
|
70
|
+
const requestContext = createRequestContextSnapshot(options?.requestContext);
|
|
71
|
+
const defaultHeaders = {
|
|
72
|
+
...Object.fromEntries(Object.entries(options?.headers ?? {}).flatMap(([header, value])=>void 0 === value ? [] : [
|
|
73
|
+
[
|
|
74
|
+
header.toLowerCase(),
|
|
75
|
+
value
|
|
76
|
+
]
|
|
77
|
+
])),
|
|
78
|
+
...requestContext.headers,
|
|
79
|
+
...operationContextHeaders(requestContext.operationContext)
|
|
80
|
+
};
|
|
45
81
|
const transformClient = (client)=>{
|
|
46
|
-
const contextClient = 0 === Object.keys(
|
|
82
|
+
const contextClient = 0 === Object.keys(defaultHeaders).length ? client : client.pipe(HttpClient.mapRequest((request)=>{
|
|
47
83
|
let nextRequest = request;
|
|
48
|
-
for (const [header, value] of Object.entries(
|
|
84
|
+
for (const [header, value] of Object.entries(defaultHeaders))if (void 0 === nextRequest.headers[header.toLowerCase()]) nextRequest = HttpClientRequest.setHeader(nextRequest, header, value);
|
|
49
85
|
return nextRequest;
|
|
50
86
|
}));
|
|
51
87
|
const policyClient = options?.crossProject !== void 0 ? withCrossProjectPolicy(api, options.crossProject, contextClient) : contextClient;
|
|
@@ -14,6 +14,13 @@ export { HttpApi, HttpApiClient, HttpApiEndpoint, HttpApiGroup, HttpApiSchema, R
|
|
|
14
14
|
export type EffectHttpApiClientOptions = {
|
|
15
15
|
crossProject?: EffectCrossProjectClientOptions;
|
|
16
16
|
baseUrl?: URL | string;
|
|
17
|
+
/** Headers for every request. A header the request already sets wins; undefined values are skipped. */
|
|
18
|
+
headers?: Readonly<Record<string, string | undefined>>;
|
|
19
|
+
/**
|
|
20
|
+
* Locale, trace and operation context for every request. An
|
|
21
|
+
* `operationContext` is sent as `x-operation-id` plus the
|
|
22
|
+
* `x-modernjs-bff-operation-context` detail the Effect BFF server reads.
|
|
23
|
+
*/
|
|
17
24
|
requestContext?: RequestContextInput;
|
|
18
25
|
transformClient?: (client: HttpClient.HttpClient) => HttpClient.HttpClient;
|
|
19
26
|
transformResponse?: ((effect: Effect.Effect<unknown, unknown, unknown>) => Effect.Effect<unknown, unknown, unknown>) | undefined;
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"modern.js",
|
|
19
19
|
"ultramodern.js"
|
|
20
20
|
],
|
|
21
|
-
"version": "3.9.3-ultramodern.
|
|
21
|
+
"version": "3.9.3-ultramodern.3",
|
|
22
22
|
"files": [
|
|
23
23
|
"dist",
|
|
24
24
|
"src"
|
|
@@ -121,10 +121,10 @@
|
|
|
121
121
|
"node": ">=26.10.0"
|
|
122
122
|
},
|
|
123
123
|
"dependencies": {
|
|
124
|
-
"@modern-js/bff-core": "npm:@bleedingdev/modern-js-bff-core@3.9.3-ultramodern.
|
|
125
|
-
"@modern-js/create-request": "npm:@bleedingdev/modern-js-create-request@3.9.3-ultramodern.
|
|
126
|
-
"@modern-js/runtime-extensions": "npm:@bleedingdev/modern-js-runtime-extensions@3.9.3-ultramodern.
|
|
127
|
-
"@modern-js/server-runtime-extensions": "npm:@bleedingdev/modern-js-server-runtime-extensions@3.9.3-ultramodern.
|
|
124
|
+
"@modern-js/bff-core": "npm:@bleedingdev/modern-js-bff-core@3.9.3-ultramodern.3",
|
|
125
|
+
"@modern-js/create-request": "npm:@bleedingdev/modern-js-create-request@3.9.3-ultramodern.3",
|
|
126
|
+
"@modern-js/runtime-extensions": "npm:@bleedingdev/modern-js-runtime-extensions@3.9.3-ultramodern.3",
|
|
127
|
+
"@modern-js/server-runtime-extensions": "npm:@bleedingdev/modern-js-server-runtime-extensions@3.9.3-ultramodern.3",
|
|
128
128
|
"@opentelemetry/api": "1.9.1",
|
|
129
129
|
"@opentelemetry/api-logs": "0.222.0",
|
|
130
130
|
"@opentelemetry/resources": "2.11.0",
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// @effect-diagnostics anyUnknownInErrorContext:off asyncFunction:off newPromise:off strictEffectProvide:off
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
BFF_OPERATION_CONTEXT_DETAIL_HEADER,
|
|
4
|
+
BFF_OPERATION_CONTEXT_HEADER,
|
|
5
|
+
createRequestContextSnapshot,
|
|
6
|
+
type OperationContext,
|
|
4
7
|
type RequestContextInput,
|
|
5
8
|
} from '@modern-js/runtime-extensions/request-context';
|
|
6
9
|
import * as Data from 'effect/Data';
|
|
@@ -53,6 +56,13 @@ export {
|
|
|
53
56
|
export type EffectHttpApiClientOptions = {
|
|
54
57
|
crossProject?: EffectCrossProjectClientOptions;
|
|
55
58
|
baseUrl?: URL | string;
|
|
59
|
+
/** Headers for every request. A header the request already sets wins; undefined values are skipped. */
|
|
60
|
+
headers?: Readonly<Record<string, string | undefined>>;
|
|
61
|
+
/**
|
|
62
|
+
* Locale, trace and operation context for every request. An
|
|
63
|
+
* `operationContext` is sent as `x-operation-id` plus the
|
|
64
|
+
* `x-modernjs-bff-operation-context` detail the Effect BFF server reads.
|
|
65
|
+
*/
|
|
56
66
|
requestContext?: RequestContextInput;
|
|
57
67
|
transformClient?: (client: HttpClient.HttpClient) => HttpClient.HttpClient;
|
|
58
68
|
transformResponse?:
|
|
@@ -199,6 +209,45 @@ export function runEffectView<
|
|
|
199
209
|
});
|
|
200
210
|
}
|
|
201
211
|
|
|
212
|
+
const operationContextStringFields = [
|
|
213
|
+
'requestId',
|
|
214
|
+
'operationId',
|
|
215
|
+
'routePath',
|
|
216
|
+
'method',
|
|
217
|
+
'schemaHash',
|
|
218
|
+
'traceparent',
|
|
219
|
+
'traceId',
|
|
220
|
+
'spanId',
|
|
221
|
+
] as const;
|
|
222
|
+
|
|
223
|
+
/** The operation headers the server reads; scope, claims and attributes stay local. */
|
|
224
|
+
function operationContextHeaders(
|
|
225
|
+
context: OperationContext | undefined,
|
|
226
|
+
): Record<string, string> {
|
|
227
|
+
if (context === undefined) {
|
|
228
|
+
return {};
|
|
229
|
+
}
|
|
230
|
+
const detail: Record<string, string | number> = {};
|
|
231
|
+
for (const field of operationContextStringFields) {
|
|
232
|
+
const value = context[field];
|
|
233
|
+
if (typeof value === 'string' && value.length > 0) {
|
|
234
|
+
detail[field] = value;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (typeof context.operationVersion === 'number') {
|
|
238
|
+
detail.operationVersion = context.operationVersion;
|
|
239
|
+
}
|
|
240
|
+
if (Object.keys(detail).length === 0) {
|
|
241
|
+
return {};
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
...(typeof detail.operationId === 'string'
|
|
245
|
+
? { [BFF_OPERATION_CONTEXT_HEADER]: detail.operationId }
|
|
246
|
+
: {}),
|
|
247
|
+
[BFF_OPERATION_CONTEXT_DETAIL_HEADER]: JSON.stringify(detail),
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
202
251
|
export function makeEffectHttpApiClient<
|
|
203
252
|
ApiId extends string,
|
|
204
253
|
Groups extends HttpApiGroup.Constraint,
|
|
@@ -210,19 +259,25 @@ export function makeEffectHttpApiClient<
|
|
|
210
259
|
never,
|
|
211
260
|
HttpApiGroup.MiddlewareClient<Groups>
|
|
212
261
|
> {
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
262
|
+
const requestContext = createRequestContextSnapshot(options?.requestContext);
|
|
263
|
+
// Request-context headers are more specific than the generic headers.
|
|
264
|
+
const defaultHeaders: Record<string, string> = {
|
|
265
|
+
...Object.fromEntries(
|
|
266
|
+
Object.entries(options?.headers ?? {}).flatMap(([header, value]) =>
|
|
267
|
+
value === undefined ? [] : [[header.toLowerCase(), value]],
|
|
268
|
+
),
|
|
269
|
+
),
|
|
270
|
+
...requestContext.headers,
|
|
271
|
+
...operationContextHeaders(requestContext.operationContext),
|
|
272
|
+
};
|
|
216
273
|
const transformClient = (client: HttpClient.HttpClient) => {
|
|
217
274
|
const contextClient =
|
|
218
|
-
Object.keys(
|
|
275
|
+
Object.keys(defaultHeaders).length === 0
|
|
219
276
|
? client
|
|
220
277
|
: client.pipe(
|
|
221
278
|
HttpClient.mapRequest(request => {
|
|
222
279
|
let nextRequest = request;
|
|
223
|
-
for (const [header, value] of Object.entries(
|
|
224
|
-
requestContextHeaders,
|
|
225
|
-
)) {
|
|
280
|
+
for (const [header, value] of Object.entries(defaultHeaders)) {
|
|
226
281
|
if (nextRequest.headers[header.toLowerCase()] === undefined) {
|
|
227
282
|
nextRequest = HttpClientRequest.setHeader(
|
|
228
283
|
nextRequest,
|