@bleedingdev/modern-js-bff-effect 3.8.3-ultramodern.2
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/LICENSE +21 -0
- package/README.md +25 -0
- package/dist/cjs/data-platform/batch/protocol.js +130 -0
- package/dist/cjs/data-platform/batch/queue.js +623 -0
- package/dist/cjs/data-platform/batch/request.js +121 -0
- package/dist/cjs/data-platform/batch/response.js +65 -0
- package/dist/cjs/data-platform/batch/telemetry.js +71 -0
- package/dist/cjs/data-platform/batch/url.js +69 -0
- package/dist/cjs/data-platform/batch-transport.js +59 -0
- package/dist/cjs/data-platform/codec.js +155 -0
- package/dist/cjs/data-platform/index.js +124 -0
- package/dist/cjs/data-platform/invalidation.js +61 -0
- package/dist/cjs/data-platform/trace.js +73 -0
- package/dist/cjs/data-platform/types.js +48 -0
- package/dist/cjs/data-platform/validation.js +178 -0
- package/dist/cjs/effect/context.js +59 -0
- package/dist/cjs/effect/dispatch.js +101 -0
- package/dist/cjs/effect/edge-context.js +61 -0
- package/dist/cjs/effect/edge-dispatcher.js +354 -0
- package/dist/cjs/effect/edge.js +62 -0
- package/dist/cjs/effect/endpoint-contracts.js +121 -0
- package/dist/cjs/effect/entry-shape-registry.js +31 -0
- package/dist/cjs/effect/entry-shape.js +113 -0
- package/dist/cjs/effect/handler/batch-handler.js +270 -0
- package/dist/cjs/effect/handler/batch.js +170 -0
- package/dist/cjs/effect/handler/definition.js +99 -0
- package/dist/cjs/effect/handler/envelope.js +104 -0
- package/dist/cjs/effect/handler/http.js +107 -0
- package/dist/cjs/effect/handler/openapi.js +58 -0
- package/dist/cjs/effect/handler/routing.js +100 -0
- package/dist/cjs/effect/handler/rpc.js +63 -0
- package/dist/cjs/effect/handler/types.js +43 -0
- package/dist/cjs/effect/handler.js +173 -0
- package/dist/cjs/effect/index.js +137 -0
- package/dist/cjs/effect/module.js +118 -0
- package/dist/cjs/effect/operation-context.js +116 -0
- package/dist/cjs/effect/rpcSerialization.js +54 -0
- package/dist/cjs/effect-client/batch.js +73 -0
- package/dist/cjs/effect-client/envelope.js +145 -0
- package/dist/cjs/effect-client/guards.js +44 -0
- package/dist/cjs/effect-client/index.js +208 -0
- package/dist/cjs/effect-client/request-context.js +64 -0
- package/dist/cjs/effect-client/request.js +66 -0
- package/dist/cjs/effect-client/runtime.js +100 -0
- package/dist/cjs/effect-client/types.js +18 -0
- package/dist/cjs/headers.js +46 -0
- package/dist/cjs/index.js +83 -0
- package/dist/esm/data-platform/batch/protocol.mjs +71 -0
- package/dist/esm/data-platform/batch/queue.mjs +582 -0
- package/dist/esm/data-platform/batch/request.mjs +68 -0
- package/dist/esm/data-platform/batch/response.mjs +24 -0
- package/dist/esm/data-platform/batch/telemetry.mjs +27 -0
- package/dist/esm/data-platform/batch/url.mjs +25 -0
- package/dist/esm/data-platform/batch-transport.mjs +12 -0
- package/dist/esm/data-platform/codec.mjs +90 -0
- package/dist/esm/data-platform/index.mjs +7 -0
- package/dist/esm/data-platform/invalidation.mjs +20 -0
- package/dist/esm/data-platform/trace.mjs +29 -0
- package/dist/esm/data-platform/types.mjs +4 -0
- package/dist/esm/data-platform/validation.mjs +128 -0
- package/dist/esm/effect/context.mjs +12 -0
- package/dist/esm/effect/dispatch.mjs +63 -0
- package/dist/esm/effect/edge-context.mjs +14 -0
- package/dist/esm/effect/edge-dispatcher.mjs +115 -0
- package/dist/esm/effect/edge.mjs +1 -0
- package/dist/esm/effect/endpoint-contracts.mjs +68 -0
- package/dist/esm/effect/entry-shape-registry.mjs +17 -0
- package/dist/esm/effect/entry-shape.mjs +51 -0
- package/dist/esm/effect/handler/batch-handler.mjs +232 -0
- package/dist/esm/effect/handler/batch.mjs +105 -0
- package/dist/esm/effect/handler/definition.mjs +58 -0
- package/dist/esm/effect/handler/envelope.mjs +63 -0
- package/dist/esm/effect/handler/http.mjs +69 -0
- package/dist/esm/effect/handler/openapi.mjs +20 -0
- package/dist/esm/effect/handler/routing.mjs +50 -0
- package/dist/esm/effect/handler/rpc.mjs +22 -0
- package/dist/esm/effect/handler/types.mjs +5 -0
- package/dist/esm/effect/handler.mjs +13 -0
- package/dist/esm/effect/index.mjs +7 -0
- package/dist/esm/effect/module.mjs +80 -0
- package/dist/esm/effect/operation-context.mjs +75 -0
- package/dist/esm/effect/rpcSerialization.mjs +16 -0
- package/dist/esm/effect-client/batch.mjs +35 -0
- package/dist/esm/effect-client/envelope.mjs +104 -0
- package/dist/esm/effect-client/guards.mjs +3 -0
- package/dist/esm/effect-client/index.mjs +110 -0
- package/dist/esm/effect-client/request-context.mjs +23 -0
- package/dist/esm/effect-client/request.mjs +28 -0
- package/dist/esm/effect-client/runtime.mjs +62 -0
- package/dist/esm/effect-client/types.mjs +0 -0
- package/dist/esm/headers.mjs +8 -0
- package/dist/esm/index.mjs +4 -0
- package/dist/esm/rslib-runtime.mjs +18 -0
- package/dist/esm-node/data-platform/batch/protocol.mjs +72 -0
- package/dist/esm-node/data-platform/batch/queue.mjs +583 -0
- package/dist/esm-node/data-platform/batch/request.mjs +69 -0
- package/dist/esm-node/data-platform/batch/response.mjs +25 -0
- package/dist/esm-node/data-platform/batch/telemetry.mjs +28 -0
- package/dist/esm-node/data-platform/batch/url.mjs +26 -0
- package/dist/esm-node/data-platform/batch-transport.mjs +13 -0
- package/dist/esm-node/data-platform/codec.mjs +91 -0
- package/dist/esm-node/data-platform/index.mjs +8 -0
- package/dist/esm-node/data-platform/invalidation.mjs +21 -0
- package/dist/esm-node/data-platform/trace.mjs +30 -0
- package/dist/esm-node/data-platform/types.mjs +5 -0
- package/dist/esm-node/data-platform/validation.mjs +129 -0
- package/dist/esm-node/effect/context.mjs +13 -0
- package/dist/esm-node/effect/dispatch.mjs +64 -0
- package/dist/esm-node/effect/edge-context.mjs +15 -0
- package/dist/esm-node/effect/edge-dispatcher.mjs +116 -0
- package/dist/esm-node/effect/edge.mjs +2 -0
- package/dist/esm-node/effect/endpoint-contracts.mjs +69 -0
- package/dist/esm-node/effect/entry-shape-registry.mjs +18 -0
- package/dist/esm-node/effect/entry-shape.mjs +63 -0
- package/dist/esm-node/effect/handler/batch-handler.mjs +233 -0
- package/dist/esm-node/effect/handler/batch.mjs +106 -0
- package/dist/esm-node/effect/handler/definition.mjs +59 -0
- package/dist/esm-node/effect/handler/envelope.mjs +64 -0
- package/dist/esm-node/effect/handler/http.mjs +70 -0
- package/dist/esm-node/effect/handler/openapi.mjs +21 -0
- package/dist/esm-node/effect/handler/routing.mjs +51 -0
- package/dist/esm-node/effect/handler/rpc.mjs +23 -0
- package/dist/esm-node/effect/handler/types.mjs +6 -0
- package/dist/esm-node/effect/handler.mjs +14 -0
- package/dist/esm-node/effect/index.mjs +8 -0
- package/dist/esm-node/effect/module.mjs +81 -0
- package/dist/esm-node/effect/operation-context.mjs +76 -0
- package/dist/esm-node/effect/rpcSerialization.mjs +17 -0
- package/dist/esm-node/effect-client/batch.mjs +36 -0
- package/dist/esm-node/effect-client/envelope.mjs +105 -0
- package/dist/esm-node/effect-client/guards.mjs +4 -0
- package/dist/esm-node/effect-client/index.mjs +111 -0
- package/dist/esm-node/effect-client/request-context.mjs +24 -0
- package/dist/esm-node/effect-client/request.mjs +29 -0
- package/dist/esm-node/effect-client/runtime.mjs +63 -0
- package/dist/esm-node/effect-client/types.mjs +1 -0
- package/dist/esm-node/headers.mjs +9 -0
- package/dist/esm-node/index.mjs +5 -0
- package/dist/esm-node/rslib-runtime.mjs +19 -0
- package/dist/types/data-platform/batch/protocol.d.ts +9 -0
- package/dist/types/data-platform/batch/queue.d.ts +47 -0
- package/dist/types/data-platform/batch/request.d.ts +19 -0
- package/dist/types/data-platform/batch/response.d.ts +3 -0
- package/dist/types/data-platform/batch/telemetry.d.ts +4 -0
- package/dist/types/data-platform/batch/url.d.ts +4 -0
- package/dist/types/data-platform/batch-transport.d.ts +3 -0
- package/dist/types/data-platform/codec.d.ts +17 -0
- package/dist/types/data-platform/index.d.ts +8 -0
- package/dist/types/data-platform/invalidation.d.ts +8 -0
- package/dist/types/data-platform/trace.d.ts +4 -0
- package/dist/types/data-platform/types.d.ts +151 -0
- package/dist/types/data-platform/validation.d.ts +29 -0
- package/dist/types/effect/context.d.ts +5 -0
- package/dist/types/effect/dispatch.d.ts +13 -0
- package/dist/types/effect/edge-context.d.ts +5 -0
- package/dist/types/effect/edge-dispatcher.d.ts +37 -0
- package/dist/types/effect/edge.d.ts +1 -0
- package/dist/types/effect/endpoint-contracts.d.ts +67 -0
- package/dist/types/effect/entry-shape.d.ts +32 -0
- package/dist/types/effect/handler/batch-handler.d.ts +11 -0
- package/dist/types/effect/handler/batch.d.ts +15 -0
- package/dist/types/effect/handler/definition.d.ts +7 -0
- package/dist/types/effect/handler/envelope.d.ts +13 -0
- package/dist/types/effect/handler/http.d.ts +15 -0
- package/dist/types/effect/handler/openapi.d.ts +4 -0
- package/dist/types/effect/handler/routing.d.ts +5 -0
- package/dist/types/effect/handler/rpc.d.ts +7 -0
- package/dist/types/effect/handler/types.d.ts +153 -0
- package/dist/types/effect/handler.d.ts +13 -0
- package/dist/types/effect/index.d.ts +6 -0
- package/dist/types/effect/module.d.ts +36 -0
- package/dist/types/effect/operation-context.d.ts +15 -0
- package/dist/types/effect/rpcSerialization.d.ts +3 -0
- package/dist/types/effect-client/batch.d.ts +2 -0
- package/dist/types/effect-client/envelope.d.ts +15 -0
- package/dist/types/effect-client/guards.d.ts +2 -0
- package/dist/types/effect-client/index.d.ts +58 -0
- package/dist/types/effect-client/request-context.d.ts +3 -0
- package/dist/types/effect-client/request.d.ts +1 -0
- package/dist/types/effect-client/runtime.d.ts +5 -0
- package/dist/types/effect-client/types.d.ts +68 -0
- package/dist/types/headers.d.ts +1 -0
- package/dist/types/index.d.ts +3 -0
- package/package.json +164 -0
- package/src/data-platform/batch/protocol.ts +112 -0
- package/src/data-platform/batch/queue.ts +876 -0
- package/src/data-platform/batch/request.ts +130 -0
- package/src/data-platform/batch/response.ts +74 -0
- package/src/data-platform/batch/telemetry.ts +47 -0
- package/src/data-platform/batch/url.ts +54 -0
- package/src/data-platform/batch-transport.ts +22 -0
- package/src/data-platform/codec.ts +145 -0
- package/src/data-platform/index.ts +63 -0
- package/src/data-platform/invalidation.ts +57 -0
- package/src/data-platform/trace.ts +49 -0
- package/src/data-platform/types.ts +186 -0
- package/src/data-platform/validation.ts +303 -0
- package/src/effect/context.ts +37 -0
- package/src/effect/dispatch.ts +132 -0
- package/src/effect/edge-context.ts +51 -0
- package/src/effect/edge-dispatcher.ts +310 -0
- package/src/effect/edge.ts +1 -0
- package/src/effect/endpoint-contracts.ts +191 -0
- package/src/effect/entry-shape-registry.cjs +16 -0
- package/src/effect/entry-shape-registry.d.cts +6 -0
- package/src/effect/entry-shape.ts +155 -0
- package/src/effect/handler/batch-handler.ts +475 -0
- package/src/effect/handler/batch.ts +182 -0
- package/src/effect/handler/definition.ts +121 -0
- package/src/effect/handler/envelope.ts +133 -0
- package/src/effect/handler/http.ts +133 -0
- package/src/effect/handler/openapi.ts +45 -0
- package/src/effect/handler/routing.ts +91 -0
- package/src/effect/handler/rpc.ts +45 -0
- package/src/effect/handler/types.ts +255 -0
- package/src/effect/handler.ts +33 -0
- package/src/effect/index.ts +22 -0
- package/src/effect/module.ts +186 -0
- package/src/effect/operation-context.ts +144 -0
- package/src/effect/rpcSerialization.ts +20 -0
- package/src/effect-client/batch.ts +50 -0
- package/src/effect-client/envelope.ts +238 -0
- package/src/effect-client/guards.ts +6 -0
- package/src/effect-client/index.ts +325 -0
- package/src/effect-client/request-context.ts +54 -0
- package/src/effect-client/request.ts +51 -0
- package/src/effect-client/runtime.ts +122 -0
- package/src/effect-client/types.ts +84 -0
- package/src/headers.ts +7 -0
- package/src/index.ts +3 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { DEFAULT_DATA_ENVELOPE_HEADER, decodeRequestEnvelopeHeader, validateRequestEnvelope, validateSelectionPlan } from "../../data-platform/index.mjs";
|
|
3
|
+
import { getExpectedEnvelopeOrigin } from "./routing.mjs";
|
|
4
|
+
function createInvalidEnvelopeResponse(message, errors) {
|
|
5
|
+
return new Response(JSON.stringify({
|
|
6
|
+
message,
|
|
7
|
+
...errors && errors.length > 0 ? {
|
|
8
|
+
errors
|
|
9
|
+
} : {}
|
|
10
|
+
}), {
|
|
11
|
+
status: 400,
|
|
12
|
+
headers: {
|
|
13
|
+
'content-type': 'application/json; charset=utf-8'
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function validateDataPlatformRequestEnvelope(request, options) {
|
|
18
|
+
const isEnabled = options?.enabled ?? true;
|
|
19
|
+
if (!isEnabled) return null;
|
|
20
|
+
const envelopeHeader = options?.envelopeHeader || DEFAULT_DATA_ENVELOPE_HEADER;
|
|
21
|
+
const encodedEnvelope = request.headers.get(envelopeHeader);
|
|
22
|
+
if (!encodedEnvelope) {
|
|
23
|
+
if (options?.requireEnvelope) return createInvalidEnvelopeResponse(`Missing required data envelope header: ${envelopeHeader}`);
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const envelope = decodeRequestEnvelopeHeader(encodedEnvelope);
|
|
27
|
+
if (!envelope) return createInvalidEnvelopeResponse(`Invalid data envelope header format: ${envelopeHeader}`);
|
|
28
|
+
const validation = validateRequestEnvelope(envelope, {
|
|
29
|
+
expectedProtocolVersion: 1,
|
|
30
|
+
expectedNamespace: options?.expectedNamespace,
|
|
31
|
+
expectedOrigin: options?.validateOrigin === false ? void 0 : getExpectedEnvelopeOrigin(request),
|
|
32
|
+
requireTraceContext: options?.requireTraceContext
|
|
33
|
+
});
|
|
34
|
+
if (!validation.ok) return createInvalidEnvelopeResponse('Invalid data envelope', validation.errors);
|
|
35
|
+
if (envelope.selectionPlan) {
|
|
36
|
+
const selectionValidation = validateSelectionPlan(envelope.selectionPlan, {
|
|
37
|
+
maxDepth: options?.selection?.maxDepth,
|
|
38
|
+
maxFields: options?.selection?.maxFields,
|
|
39
|
+
allowedLeafPaths: options?.selection?.allowedLeafPaths
|
|
40
|
+
});
|
|
41
|
+
if (!selectionValidation.ok) return createInvalidEnvelopeResponse('Invalid data envelope selection plan', selectionValidation.errors);
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
function mergeDataPlatformOptions(base, override) {
|
|
46
|
+
if (!base && !override) return;
|
|
47
|
+
const baseSelection = base?.selection;
|
|
48
|
+
const overrideSelection = override?.selection;
|
|
49
|
+
const baseBatch = base?.batch;
|
|
50
|
+
const overrideBatch = override?.batch;
|
|
51
|
+
return {
|
|
52
|
+
...base,
|
|
53
|
+
...override,
|
|
54
|
+
selection: baseSelection || overrideSelection ? {
|
|
55
|
+
...baseSelection,
|
|
56
|
+
...overrideSelection
|
|
57
|
+
} : void 0,
|
|
58
|
+
batch: baseBatch || overrideBatch ? {
|
|
59
|
+
...baseBatch,
|
|
60
|
+
...overrideBatch
|
|
61
|
+
} : void 0
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export { mergeDataPlatformOptions, validateDataPlatformRequestEnvelope };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { HttpRouter, HttpServer } from "effect/unstable/http";
|
|
3
|
+
import { prepareJsonRequestBody } from "./batch.mjs";
|
|
4
|
+
import { createDataPlatformBatchRequestHandler } from "./batch-handler.mjs";
|
|
5
|
+
import { validateDataPlatformRequestEnvelope } from "./envelope.mjs";
|
|
6
|
+
import { createOpenApiLayer } from "./openapi.mjs";
|
|
7
|
+
import { getRequestPathname, isRpcRequest } from "./routing.mjs";
|
|
8
|
+
import { createRpcApiHandler, normalizeRpcPath } from "./rpc.mjs";
|
|
9
|
+
import { toEffectServiceContext } from "./types.mjs";
|
|
10
|
+
import * as __rspack_external_effect_Layer_69c46453 from "effect/Layer";
|
|
11
|
+
function createHttpApiHandler(options) {
|
|
12
|
+
const apiLayer = options.layer.pipe(__rspack_external_effect_Layer_69c46453.provide(HttpServer.layerServices));
|
|
13
|
+
const openApiLayer = createOpenApiLayer(options.api, options.openapi);
|
|
14
|
+
const mergedLayer = openApiLayer ? __rspack_external_effect_Layer_69c46453.mergeAll(apiLayer, openApiLayer) : apiLayer;
|
|
15
|
+
const httpApiHandler = HttpRouter.toWebHandler(mergedLayer);
|
|
16
|
+
const dispatchHttpApiRequest = async (request, context)=>{
|
|
17
|
+
const preparedRequest = await prepareJsonRequestBody(request);
|
|
18
|
+
if (preparedRequest instanceof Response) return preparedRequest;
|
|
19
|
+
const validationError = validateDataPlatformRequestEnvelope(preparedRequest, options.dataPlatform);
|
|
20
|
+
if (validationError) return validationError;
|
|
21
|
+
return httpApiHandler.handler(preparedRequest, toEffectServiceContext(context));
|
|
22
|
+
};
|
|
23
|
+
const withRequestPolicy = async (request, context)=>{
|
|
24
|
+
const policyDenial = options.validateRequest?.(request);
|
|
25
|
+
if (policyDenial) return policyDenial;
|
|
26
|
+
const next = ()=>dispatchHttpApiRequest(request, context);
|
|
27
|
+
return options.interceptRequest ? options.interceptRequest({
|
|
28
|
+
request,
|
|
29
|
+
next
|
|
30
|
+
}) : next();
|
|
31
|
+
};
|
|
32
|
+
const batchHandler = createDataPlatformBatchRequestHandler({
|
|
33
|
+
dataPlatform: options.dataPlatform,
|
|
34
|
+
handleItem: withRequestPolicy
|
|
35
|
+
});
|
|
36
|
+
const handleHttpApiRequest = async (request, context)=>{
|
|
37
|
+
const pathname = getRequestPathname(request);
|
|
38
|
+
if (batchHandler.enabled && pathname === batchHandler.path) return batchHandler.handle(request, context);
|
|
39
|
+
return withRequestPolicy(request, context);
|
|
40
|
+
};
|
|
41
|
+
if (!options.rpc) return {
|
|
42
|
+
handler: handleHttpApiRequest,
|
|
43
|
+
dispose: async ()=>{
|
|
44
|
+
await httpApiHandler.dispose();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const rpcPath = normalizeRpcPath(options.rpc.path);
|
|
48
|
+
const rpcHandler = createRpcApiHandler(options.rpc);
|
|
49
|
+
return {
|
|
50
|
+
handler: async (request, context)=>{
|
|
51
|
+
if (isRpcRequest(request, rpcPath)) {
|
|
52
|
+
const policyDenial = options.validateRequest?.(request);
|
|
53
|
+
if (policyDenial) return policyDenial;
|
|
54
|
+
const next = ()=>rpcHandler.handler(request, toEffectServiceContext(context));
|
|
55
|
+
return options.interceptRequest ? options.interceptRequest({
|
|
56
|
+
request,
|
|
57
|
+
next
|
|
58
|
+
}) : next();
|
|
59
|
+
}
|
|
60
|
+
return handleHttpApiRequest(request, context);
|
|
61
|
+
},
|
|
62
|
+
dispose: async ()=>{
|
|
63
|
+
await Promise.all([
|
|
64
|
+
httpApiHandler.dispose(),
|
|
65
|
+
rpcHandler.dispose()
|
|
66
|
+
]);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export { createHttpApiHandler };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { HttpRouter, HttpServerResponse } from "effect/unstable/http";
|
|
3
|
+
import { OpenApi } from "effect/unstable/httpapi";
|
|
4
|
+
const DEFAULT_OPENAPI_PATH = '/openapi.json';
|
|
5
|
+
function normalizeOpenApiPath(pathname) {
|
|
6
|
+
if (!pathname.startsWith('/')) return `/${pathname}`;
|
|
7
|
+
return pathname;
|
|
8
|
+
}
|
|
9
|
+
function getOpenApiOptions(openapi) {
|
|
10
|
+
if (false === openapi || void 0 === openapi) return;
|
|
11
|
+
const path = true === openapi ? DEFAULT_OPENAPI_PATH : openapi.path;
|
|
12
|
+
return {
|
|
13
|
+
path: normalizeOpenApiPath(path ?? DEFAULT_OPENAPI_PATH)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function createOpenApiLayer(api, openapi) {
|
|
17
|
+
const openApiOptions = getOpenApiOptions(openapi);
|
|
18
|
+
if (!openApiOptions) return null;
|
|
19
|
+
return HttpRouter.add('GET', openApiOptions.path, HttpServerResponse.jsonUnsafe(OpenApi.fromApi(api)));
|
|
20
|
+
}
|
|
21
|
+
export { createOpenApiLayer };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { isPlainObject } from "../../data-platform/index.mjs";
|
|
3
|
+
function getRequestPathname(request) {
|
|
4
|
+
try {
|
|
5
|
+
return new URL(request.url).pathname;
|
|
6
|
+
} catch {
|
|
7
|
+
return new URL(request.url, 'http://localhost').pathname;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function normalizeMountPrefix(prefix) {
|
|
11
|
+
if (!prefix || '/' === prefix) return '';
|
|
12
|
+
return prefix.endsWith('/') ? prefix.slice(0, -1) : prefix;
|
|
13
|
+
}
|
|
14
|
+
function getMountedPrefixFromContext(request, context) {
|
|
15
|
+
if (!isPlainObject(context) || 'string' != typeof context.path) return '';
|
|
16
|
+
const contextPath = normalizeMountPrefix(context.path);
|
|
17
|
+
const requestPath = normalizeMountPrefix(getRequestPathname(request));
|
|
18
|
+
if (!contextPath || !requestPath || contextPath === requestPath || !contextPath.endsWith(requestPath)) return '';
|
|
19
|
+
return normalizeMountPrefix(contextPath.slice(0, contextPath.length - requestPath.length));
|
|
20
|
+
}
|
|
21
|
+
function removeMountedPrefixFromBatchPath(pathWithQuery, prefix) {
|
|
22
|
+
const normalizedPrefix = normalizeMountPrefix(prefix);
|
|
23
|
+
if (!normalizedPrefix) return pathWithQuery;
|
|
24
|
+
const [pathname, ...queryParts] = pathWithQuery.split('?');
|
|
25
|
+
if (!pathname) return pathWithQuery;
|
|
26
|
+
let nextPathname = pathname;
|
|
27
|
+
if (pathname === normalizedPrefix) nextPathname = '/';
|
|
28
|
+
else if (pathname.startsWith(`${normalizedPrefix}/`)) {
|
|
29
|
+
const sliced = pathname.slice(normalizedPrefix.length);
|
|
30
|
+
nextPathname = sliced.startsWith('/') ? sliced : `/${sliced}`;
|
|
31
|
+
}
|
|
32
|
+
if (0 === queryParts.length) return nextPathname;
|
|
33
|
+
return `${nextPathname}?${queryParts.join('?')}`;
|
|
34
|
+
}
|
|
35
|
+
function getRequestOrigin(request) {
|
|
36
|
+
try {
|
|
37
|
+
return new URL(request.url).origin;
|
|
38
|
+
} catch {
|
|
39
|
+
return new URL(request.url, 'http://localhost').origin;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function getExpectedEnvelopeOrigin(request) {
|
|
43
|
+
const origin = request.headers.get('origin');
|
|
44
|
+
if (origin && 'null' !== origin) return origin;
|
|
45
|
+
return getRequestOrigin(request);
|
|
46
|
+
}
|
|
47
|
+
function isRpcRequest(request, rpcPath) {
|
|
48
|
+
const pathname = getRequestPathname(request);
|
|
49
|
+
return pathname === rpcPath || pathname.startsWith(`${rpcPath}/`);
|
|
50
|
+
}
|
|
51
|
+
export { getExpectedEnvelopeOrigin, getMountedPrefixFromContext, getRequestPathname, isRpcRequest, removeMountedPrefixFromBatchPath };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { HttpRouter } from "effect/unstable/http";
|
|
3
|
+
import { RpcServer } from "effect/unstable/rpc";
|
|
4
|
+
import { getRpcSerializationLayer } from "../rpcSerialization.mjs";
|
|
5
|
+
import * as __rspack_external_effect_Layer_69c46453 from "effect/Layer";
|
|
6
|
+
function normalizeRpcPath(pathname) {
|
|
7
|
+
if (!pathname || '/' === pathname) return '/rpc';
|
|
8
|
+
if (!pathname.startsWith('/')) return `/${pathname}`;
|
|
9
|
+
return pathname;
|
|
10
|
+
}
|
|
11
|
+
function createRpcApiHandler(options) {
|
|
12
|
+
const rpcPath = normalizeRpcPath(options.path);
|
|
13
|
+
const rpcLayer = __rspack_external_effect_Layer_69c46453.provide(RpcServer.layerHttp({
|
|
14
|
+
group: options.group,
|
|
15
|
+
path: rpcPath,
|
|
16
|
+
protocol: 'http',
|
|
17
|
+
disableTracing: options.disableTracing,
|
|
18
|
+
spanPrefix: options.spanPrefix,
|
|
19
|
+
spanAttributes: options.spanAttributes
|
|
20
|
+
}), __rspack_external_effect_Layer_69c46453.mergeAll(options.layer, getRpcSerializationLayer(options.serialization)));
|
|
21
|
+
return HttpRouter.toWebHandler(rpcLayer);
|
|
22
|
+
}
|
|
23
|
+
export { createRpcApiHandler, normalizeRpcPath };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import * as __rspack_external_effect_Context_b3520bd3 from "effect/Context";
|
|
3
|
+
const emptyEffectServiceContext = __rspack_external_effect_Context_b3520bd3.empty();
|
|
4
|
+
const isEffectServiceContext = (context)=>'object' == typeof context && null !== context && 'mapUnsafe' in context;
|
|
5
|
+
const toEffectServiceContext = (context)=>isEffectServiceContext(context) ? context : emptyEffectServiceContext;
|
|
6
|
+
export { toEffectServiceContext };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import * as __rspack_external_effect_Config_76cfa59d from "effect/Config";
|
|
3
|
+
import * as __rspack_external_effect_Effect_41060786 from "effect/Effect";
|
|
4
|
+
import * as __rspack_external_effect_Layer_69c46453 from "effect/Layer";
|
|
5
|
+
import * as __rspack_external_effect_Option_0498e63a from "effect/Option";
|
|
6
|
+
import * as __rspack_external_effect_Schema_6065f72d from "effect/Schema";
|
|
7
|
+
export * from "effect/unstable/http";
|
|
8
|
+
export * from "effect/unstable/httpapi";
|
|
9
|
+
export * from "effect/unstable/rpc";
|
|
10
|
+
export { HttpTraceContext } from "effect/unstable/http";
|
|
11
|
+
export { HttpApiBuilder } from "effect/unstable/httpapi";
|
|
12
|
+
export { defineEffectBff, defineEffectRpcBff } from "./handler/definition.mjs";
|
|
13
|
+
export { createHttpApiHandler } from "./handler/http.mjs";
|
|
14
|
+
export { __rspack_external_effect_Config_76cfa59d as Config, __rspack_external_effect_Effect_41060786 as Effect, __rspack_external_effect_Layer_69c46453 as Layer, __rspack_external_effect_Option_0498e63a as Option, __rspack_external_effect_Schema_6065f72d as Schema };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import * as __rspack_external__effect_opentelemetry_66324c75 from "@effect/opentelemetry";
|
|
3
|
+
export * from "./endpoint-contracts.mjs";
|
|
4
|
+
export * from "./handler.mjs";
|
|
5
|
+
export { createEffectOperationContext, runWithEffectContext, useEffectContext, useOperationContext } from "./context.mjs";
|
|
6
|
+
export { createEffectBffEdgeHandler, createEffectBffTestHandler, dispatchEffectBffRequest } from "./edge.mjs";
|
|
7
|
+
export { resolveEffectBffModuleHandler } from "./module.mjs";
|
|
8
|
+
export { __rspack_external__effect_opentelemetry_66324c75 as OpenTelemetry };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { HttpApi } from "effect/unstable/httpapi";
|
|
3
|
+
import { classifyEffectBffEntryModule, isValidatorAwareHandlerFactory, strictEffectApproachMessage } from "./entry-shape.mjs";
|
|
4
|
+
import { createHttpApiHandler } from "./handler.mjs";
|
|
5
|
+
function isRequestHandler(value) {
|
|
6
|
+
return 'function' == typeof value;
|
|
7
|
+
}
|
|
8
|
+
function shareDispose(dispose) {
|
|
9
|
+
let disposePromise;
|
|
10
|
+
return ()=>{
|
|
11
|
+
disposePromise ??= Promise.resolve().then(dispose);
|
|
12
|
+
return disposePromise;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function rejectLegacyEffectModuleShape(options, shape) {
|
|
16
|
+
options.onWarning?.(`${strictEffectApproachMessage} Rejected ${shape}.`);
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
function callEffectBffRequestHandler(handler, request, context) {
|
|
20
|
+
return void 0 === context ? handler(request) : handler(request, context);
|
|
21
|
+
}
|
|
22
|
+
function createLoadedHandler(webHandler) {
|
|
23
|
+
return {
|
|
24
|
+
handler: (request, context)=>callEffectBffRequestHandler(webHandler.handler, request, context),
|
|
25
|
+
dispose: shareDispose(webHandler.dispose)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function createLoadedHttpApiHandler(webHandler) {
|
|
29
|
+
return createLoadedHandler({
|
|
30
|
+
handler: webHandler.handler,
|
|
31
|
+
dispose: webHandler.dispose
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function classifyEffectBffRuntimeEntryShape(module) {
|
|
35
|
+
return classifyEffectBffEntryModule(module, {
|
|
36
|
+
isRequestHandler: isRequestHandler,
|
|
37
|
+
isValidatorAwareHandlerFactory: isValidatorAwareHandlerFactory,
|
|
38
|
+
isHttpApi: HttpApi.isHttpApi
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function resolveClassifiedEffectBffModuleHandler(facts, options = {}) {
|
|
42
|
+
if (!facts) return null;
|
|
43
|
+
if (facts.legacyShape) {
|
|
44
|
+
if (rejectLegacyEffectModuleShape(options, facts.legacyShape)) return null;
|
|
45
|
+
}
|
|
46
|
+
if ('function' == typeof facts.createHandler) {
|
|
47
|
+
if (facts.createHandlerValidatorAware) {
|
|
48
|
+
const factory = facts.createHandler;
|
|
49
|
+
const webHandler = factory({
|
|
50
|
+
openapi: options.openapi,
|
|
51
|
+
dataPlatform: options.dataPlatform,
|
|
52
|
+
validateRequest: options.validateRequest
|
|
53
|
+
});
|
|
54
|
+
return createLoadedHandler(webHandler);
|
|
55
|
+
}
|
|
56
|
+
if (void 0 === facts.api || !facts.hasRuntimeLayer) {
|
|
57
|
+
rejectLegacyEffectModuleShape(options, 'unbranded `createHandler` export');
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
options.onWarning?.(`${strictEffectApproachMessage} Ignored unbranded \`createHandler\` export and rebuilt the handler from its { api, layer } exports.`);
|
|
61
|
+
}
|
|
62
|
+
if (void 0 !== facts.api && facts.hasRuntimeLayer) {
|
|
63
|
+
if (void 0 === facts.createHandler) options.onWarning?.('[BFF][Effect] Detected { api, layer } export without createHandler. Prefer `defineEffectBff(...)` from @modern-js/bff-effect/effect to avoid module instance mismatch.');
|
|
64
|
+
const webHandler = createHttpApiHandler({
|
|
65
|
+
api: facts.api,
|
|
66
|
+
layer: facts.layer,
|
|
67
|
+
openapi: options.openapi,
|
|
68
|
+
dataPlatform: options.dataPlatform,
|
|
69
|
+
validateRequest: options.validateRequest
|
|
70
|
+
});
|
|
71
|
+
return createLoadedHttpApiHandler(webHandler);
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
function resolveNormalizedEffectBffModuleHandler(normalizedModule, options = {}) {
|
|
76
|
+
return resolveClassifiedEffectBffModuleHandler(classifyEffectBffRuntimeEntryShape(normalizedModule), options);
|
|
77
|
+
}
|
|
78
|
+
function resolveEffectBffModuleHandler(mod, options = {}) {
|
|
79
|
+
return Promise.resolve(resolveNormalizedEffectBffModuleHandler(mod, options));
|
|
80
|
+
}
|
|
81
|
+
export { resolveEffectBffModuleHandler };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { BFF_LOCALE_HEADER, BFF_OPERATION_CONTEXT_DETAIL_HEADER, BFF_OPERATION_CONTEXT_HEADER, BFF_TRACEPARENT_HEADER, parseTraceparent } from "@modern-js/create-request";
|
|
3
|
+
const kEffectContextStorage = Symbol.for('modernjs.plugin-bff.effectContextStorage');
|
|
4
|
+
const readHeader = (headers, header)=>{
|
|
5
|
+
const value = headers.get(header);
|
|
6
|
+
return value && value.length > 0 ? value : void 0;
|
|
7
|
+
};
|
|
8
|
+
const copyStringField = (target, details, key)=>{
|
|
9
|
+
const value = details[key];
|
|
10
|
+
if ('string' == typeof value && value.length > 0) target[key] = value;
|
|
11
|
+
};
|
|
12
|
+
const readOperationContextDetails = (request)=>{
|
|
13
|
+
const rawDetails = readHeader(request.headers, BFF_OPERATION_CONTEXT_DETAIL_HEADER);
|
|
14
|
+
if (!rawDetails) return {};
|
|
15
|
+
try {
|
|
16
|
+
const parsed = JSON.parse(rawDetails);
|
|
17
|
+
if (!parsed || 'object' != typeof parsed || Array.isArray(parsed)) return {};
|
|
18
|
+
const details = parsed;
|
|
19
|
+
const safeDetails = {};
|
|
20
|
+
copyStringField(safeDetails, details, 'requestId');
|
|
21
|
+
copyStringField(safeDetails, details, 'operationId');
|
|
22
|
+
copyStringField(safeDetails, details, 'schemaHash');
|
|
23
|
+
copyStringField(safeDetails, details, 'traceparent');
|
|
24
|
+
copyStringField(safeDetails, details, 'traceId');
|
|
25
|
+
copyStringField(safeDetails, details, 'spanId');
|
|
26
|
+
if ('number' == typeof details.operationVersion) safeDetails.operationVersion = details.operationVersion;
|
|
27
|
+
return safeDetails;
|
|
28
|
+
} catch {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const createEffectOperationContext = ({ request, path, method })=>{
|
|
33
|
+
const details = readOperationContextDetails(request);
|
|
34
|
+
const operationDetails = {
|
|
35
|
+
...details
|
|
36
|
+
};
|
|
37
|
+
delete operationDetails.traceparent;
|
|
38
|
+
delete operationDetails.traceId;
|
|
39
|
+
delete operationDetails.spanId;
|
|
40
|
+
const servicePath = new URL(request.url).pathname;
|
|
41
|
+
const headerTraceparent = readHeader(request.headers, BFF_TRACEPARENT_HEADER);
|
|
42
|
+
const headerTraceContext = parseTraceparent(headerTraceparent);
|
|
43
|
+
const detailTraceContext = parseTraceparent(details.traceparent);
|
|
44
|
+
const traceparent = headerTraceContext ? headerTraceparent : detailTraceContext ? details.traceparent : void 0;
|
|
45
|
+
const parsedTraceparent = headerTraceContext || detailTraceContext || (details.traceId && details.spanId ? {
|
|
46
|
+
traceId: details.traceId,
|
|
47
|
+
spanId: details.spanId
|
|
48
|
+
} : void 0);
|
|
49
|
+
const locale = readHeader(request.headers, BFF_LOCALE_HEADER);
|
|
50
|
+
const headerOperationId = readHeader(request.headers, BFF_OPERATION_CONTEXT_HEADER);
|
|
51
|
+
return {
|
|
52
|
+
...operationDetails,
|
|
53
|
+
...headerOperationId || details.operationId ? {
|
|
54
|
+
operationId: headerOperationId || details.operationId
|
|
55
|
+
} : {},
|
|
56
|
+
routePath: servicePath,
|
|
57
|
+
method: (method || request.method || 'GET').toUpperCase(),
|
|
58
|
+
source: 'effect-adapter',
|
|
59
|
+
...path && path !== servicePath ? {
|
|
60
|
+
attributes: {
|
|
61
|
+
mountedPath: path
|
|
62
|
+
}
|
|
63
|
+
} : {},
|
|
64
|
+
...locale ? {
|
|
65
|
+
locale
|
|
66
|
+
} : {},
|
|
67
|
+
...traceparent ? {
|
|
68
|
+
traceparent
|
|
69
|
+
} : {},
|
|
70
|
+
...parsedTraceparent ? {
|
|
71
|
+
traceId: parsedTraceparent.traceId,
|
|
72
|
+
spanId: parsedTraceparent.spanId
|
|
73
|
+
} : {}
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
export { createEffectOperationContext, kEffectContextStorage };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { RpcSerialization } from "effect/unstable/rpc";
|
|
3
|
+
function getRpcSerializationLayer(serialization) {
|
|
4
|
+
switch(serialization){
|
|
5
|
+
case 'ndjson':
|
|
6
|
+
return RpcSerialization.layerNdjson;
|
|
7
|
+
case 'jsonRpc':
|
|
8
|
+
return RpcSerialization.layerJsonRpc();
|
|
9
|
+
case 'ndJsonRpc':
|
|
10
|
+
return RpcSerialization.layerNdJsonRpc();
|
|
11
|
+
case 'msgPack':
|
|
12
|
+
return RpcSerialization.layerMsgPack;
|
|
13
|
+
default:
|
|
14
|
+
return RpcSerialization.layerJsonRpc();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export { getRpcSerializationLayer };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { createDataBatchTransport } from "../data-platform/index.mjs";
|
|
3
|
+
import { resolveOrigin } from "./envelope.mjs";
|
|
4
|
+
const resolveRuntimeFetch = ()=>'function' == typeof fetch ? fetch.bind(globalThis) : void 0;
|
|
5
|
+
const configureGeneratedEffectClientRuntime = (config, configureRequest)=>{
|
|
6
|
+
const defaultOrigin = config.defaultOrigin;
|
|
7
|
+
if (config.requestId && configureRequest) {
|
|
8
|
+
const configurePayload = {
|
|
9
|
+
requestId: config.requestId,
|
|
10
|
+
requireEnvelope: true,
|
|
11
|
+
identityBinding: {
|
|
12
|
+
enabled: true,
|
|
13
|
+
strict: true
|
|
14
|
+
},
|
|
15
|
+
operationContract: {
|
|
16
|
+
enabled: true,
|
|
17
|
+
strict: true,
|
|
18
|
+
requireSchemaHash: true,
|
|
19
|
+
requireOperationVersion: true
|
|
20
|
+
},
|
|
21
|
+
setDomain: ()=>resolveOrigin(defaultOrigin)
|
|
22
|
+
};
|
|
23
|
+
const runtimeFetch = resolveRuntimeFetch();
|
|
24
|
+
if (false !== config.batch.enabled && runtimeFetch) configurePayload.request = createDataBatchTransport({
|
|
25
|
+
fetch: runtimeFetch,
|
|
26
|
+
endpoint: config.batch.endpoint,
|
|
27
|
+
flushIntervalMs: config.batch.flushIntervalMs,
|
|
28
|
+
maxBatchSize: config.batch.maxBatchSize,
|
|
29
|
+
maxBatchBytes: config.batch.maxBatchBytes,
|
|
30
|
+
requestTimeoutMs: config.batch.requestTimeoutMs,
|
|
31
|
+
allowedMethods: config.batch.allowedMethods
|
|
32
|
+
});
|
|
33
|
+
configureRequest(configurePayload);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
export { configureGeneratedEffectClientRuntime };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { DEFAULT_DATA_BATCH_HEADER, DEFAULT_DATA_ENVELOPE_HEADER, createRequestEnvelope, encodeRequestEnvelopeHeader } from "../data-platform/index.mjs";
|
|
3
|
+
import { isRecord, stringOrUndefined } from "./guards.mjs";
|
|
4
|
+
import { normalizeRequest } from "./request.mjs";
|
|
5
|
+
import { applyRequestContext } from "./request-context.mjs";
|
|
6
|
+
const DATA_REQUEST_MODES = new Set([
|
|
7
|
+
'cache-first',
|
|
8
|
+
'stale-while-revalidate',
|
|
9
|
+
'network-only'
|
|
10
|
+
]);
|
|
11
|
+
const DATA_MUTATION_MODES = new Set([
|
|
12
|
+
'optimistic',
|
|
13
|
+
'pessimistic',
|
|
14
|
+
'fire-and-forget'
|
|
15
|
+
]);
|
|
16
|
+
const isDataRequestMode = (value)=>'string' == typeof value && DATA_REQUEST_MODES.has(value);
|
|
17
|
+
const isDataMutationMode = (value)=>'string' == typeof value && DATA_MUTATION_MODES.has(value);
|
|
18
|
+
const normalizeOrigin = (value)=>{
|
|
19
|
+
if ('string' != typeof value || 0 === value.length) return;
|
|
20
|
+
try {
|
|
21
|
+
return new URL(value).origin;
|
|
22
|
+
} catch {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const resolveOrigin = (defaultOrigin)=>{
|
|
27
|
+
if ("u" > typeof window && window.location && 'string' == typeof window.location.origin && window.location.origin) return window.location.origin;
|
|
28
|
+
const globalLocation = globalThis?.location;
|
|
29
|
+
if (globalLocation && 'string' == typeof globalLocation.origin && globalLocation.origin) return globalLocation.origin;
|
|
30
|
+
return defaultOrigin;
|
|
31
|
+
};
|
|
32
|
+
const resolveTargetOrigin = (dataPlatform, defaultOrigin)=>{
|
|
33
|
+
const explicitTargetOrigin = stringOrUndefined(dataPlatform.targetOrigin) || stringOrUndefined(dataPlatform.endpointOrigin);
|
|
34
|
+
if (explicitTargetOrigin) return explicitTargetOrigin;
|
|
35
|
+
return defaultOrigin;
|
|
36
|
+
};
|
|
37
|
+
const shouldAttachEnvelopeHeader = (dataPlatform, defaultOrigin)=>{
|
|
38
|
+
if (true === dataPlatform.allowCrossOriginEnvelope) return true;
|
|
39
|
+
const currentOrigin = normalizeOrigin(resolveOrigin(defaultOrigin));
|
|
40
|
+
const targetOrigin = normalizeOrigin(resolveTargetOrigin(dataPlatform, defaultOrigin));
|
|
41
|
+
if (!currentOrigin || !targetOrigin) return true;
|
|
42
|
+
return currentOrigin === targetOrigin;
|
|
43
|
+
};
|
|
44
|
+
const toEnvelopeInput = (normalizedRequest)=>{
|
|
45
|
+
const payload = {};
|
|
46
|
+
if (isRecord(normalizedRequest.params)) payload.path = normalizedRequest.params;
|
|
47
|
+
if (isRecord(normalizedRequest.query)) payload.query = normalizedRequest.query;
|
|
48
|
+
if ('data' in normalizedRequest && void 0 !== normalizedRequest.data) payload.data = normalizedRequest.data;
|
|
49
|
+
if ('body' in normalizedRequest && void 0 !== normalizedRequest.body) payload.body = normalizedRequest.body;
|
|
50
|
+
if ("u" > typeof FormData && normalizedRequest.formData instanceof FormData) payload.formData = Array.from(normalizedRequest.formData.entries()).map(([key, value])=>[
|
|
51
|
+
key,
|
|
52
|
+
String(value)
|
|
53
|
+
]);
|
|
54
|
+
if ("u" > typeof URLSearchParams && normalizedRequest.formUrlencoded instanceof URLSearchParams) payload.formUrlencoded = normalizedRequest.formUrlencoded.toString();
|
|
55
|
+
return payload;
|
|
56
|
+
};
|
|
57
|
+
const prepareEffectRequest = (options)=>{
|
|
58
|
+
const { endpoint, operation, request, config, createEffectRequestContext } = options;
|
|
59
|
+
const defaultOrigin = config.defaultOrigin;
|
|
60
|
+
const normalizedRequest = applyRequestContext(normalizeRequest(endpoint.method, request), request, createEffectRequestContext);
|
|
61
|
+
const dataPlatform = isRecord(request) && isRecord(request.dataPlatform) ? request.dataPlatform : {};
|
|
62
|
+
const strictEnvelope = true === dataPlatform.requireEnvelope || true === dataPlatform.strict;
|
|
63
|
+
if (!strictEnvelope && !shouldAttachEnvelopeHeader(dataPlatform, defaultOrigin)) return normalizedRequest;
|
|
64
|
+
try {
|
|
65
|
+
const namespace = stringOrUndefined(dataPlatform.appNamespace) || config.appNamespace;
|
|
66
|
+
const origin = stringOrUndefined(dataPlatform.origin) || resolveOrigin(defaultOrigin);
|
|
67
|
+
const envelope = createRequestEnvelope({
|
|
68
|
+
operation: {
|
|
69
|
+
...operation,
|
|
70
|
+
appNamespace: namespace
|
|
71
|
+
},
|
|
72
|
+
scope: {
|
|
73
|
+
appNamespace: namespace,
|
|
74
|
+
origin,
|
|
75
|
+
tenantId: stringOrUndefined(dataPlatform.tenantId),
|
|
76
|
+
userId: stringOrUndefined(dataPlatform.userId),
|
|
77
|
+
sessionId: stringOrUndefined(dataPlatform.sessionId)
|
|
78
|
+
},
|
|
79
|
+
requestInput: {
|
|
80
|
+
method: endpoint.method,
|
|
81
|
+
routePath: endpoint.routePath,
|
|
82
|
+
payload: toEnvelopeInput(normalizedRequest)
|
|
83
|
+
},
|
|
84
|
+
requestMode: isDataRequestMode(dataPlatform.requestMode) ? dataPlatform.requestMode : void 0,
|
|
85
|
+
mutationMode: isDataMutationMode(dataPlatform.mutationMode) ? dataPlatform.mutationMode : void 0,
|
|
86
|
+
selectionPlan: isRecord(dataPlatform.selectionPlan) ? dataPlatform.selectionPlan : void 0,
|
|
87
|
+
traceContext: isRecord(dataPlatform.traceContext) ? dataPlatform.traceContext : void 0,
|
|
88
|
+
requireTraceContext: true === dataPlatform.requireTraceContext
|
|
89
|
+
});
|
|
90
|
+
const headerName = stringOrUndefined(dataPlatform.envelopeHeader) || DEFAULT_DATA_ENVELOPE_HEADER;
|
|
91
|
+
const headers = isRecord(normalizedRequest.headers) ? {
|
|
92
|
+
...normalizedRequest.headers
|
|
93
|
+
} : {};
|
|
94
|
+
if (false === dataPlatform.batch) headers[DEFAULT_DATA_BATCH_HEADER] = 'off';
|
|
95
|
+
headers[headerName] = encodeRequestEnvelopeHeader(envelope);
|
|
96
|
+
return {
|
|
97
|
+
...normalizedRequest,
|
|
98
|
+
headers
|
|
99
|
+
};
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (strictEnvelope) throw error;
|
|
102
|
+
return normalizedRequest;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
export { prepareEffectRequest, resolveOrigin };
|