@bleedingdev/modern-js-bff-effect 3.9.0-ultramodern.5 → 3.9.0-ultramodern.7

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.
Files changed (72) hide show
  1. package/README.md +20 -4
  2. package/dist/cjs/effect/endpoint-contracts.js +1 -2
  3. package/dist/cjs/effect/entry-shape.js +2 -2
  4. package/dist/cjs/effect/handler/definition.js +1 -21
  5. package/dist/cjs/effect/module.js +4 -4
  6. package/dist/cjs/effect-client/cross-project.js +92 -0
  7. package/dist/cjs/effect-client/index.js +3 -1
  8. package/dist/esm/effect/endpoint-contracts.mjs +1 -2
  9. package/dist/esm/effect/entry-shape.mjs +2 -2
  10. package/dist/esm/effect/handler/definition.mjs +1 -21
  11. package/dist/esm/effect/module.mjs +4 -4
  12. package/dist/esm/effect-client/cross-project.mjs +54 -0
  13. package/dist/esm/effect-client/index.mjs +3 -1
  14. package/dist/esm-node/effect/endpoint-contracts.mjs +1 -2
  15. package/dist/esm-node/effect/entry-shape.mjs +2 -2
  16. package/dist/esm-node/effect/handler/definition.mjs +1 -21
  17. package/dist/esm-node/effect/module.mjs +4 -4
  18. package/dist/esm-node/effect-client/cross-project.mjs +55 -0
  19. package/dist/esm-node/effect-client/index.mjs +3 -1
  20. package/dist/types/effect/edge-dispatcher.d.ts +1 -1
  21. package/dist/types/effect/endpoint-contracts.d.ts +1 -19
  22. package/dist/types/effect/entry-shape.d.ts +2 -2
  23. package/dist/types/effect/handler/types.d.ts +0 -15
  24. package/dist/types/effect/handler.d.ts +1 -1
  25. package/dist/types/effect-client/cross-project.d.ts +10 -0
  26. package/dist/types/effect-client/index.d.ts +3 -0
  27. package/package.json +5 -18
  28. package/src/effect/edge-dispatcher.ts +0 -1
  29. package/src/effect/endpoint-contracts.ts +2 -23
  30. package/src/effect/entry-shape.ts +6 -4
  31. package/src/effect/handler/definition.ts +0 -44
  32. package/src/effect/handler/http.ts +2 -2
  33. package/src/effect/handler/types.ts +0 -27
  34. package/src/effect/handler.ts +0 -1
  35. package/src/effect/module.ts +4 -4
  36. package/src/effect-client/cross-project.ts +109 -0
  37. package/src/effect-client/index.ts +12 -2
  38. package/dist/cjs/effect-client/batch.js +0 -73
  39. package/dist/cjs/effect-client/envelope.js +0 -145
  40. package/dist/cjs/effect-client/guards.js +0 -44
  41. package/dist/cjs/effect-client/request-context.js +0 -64
  42. package/dist/cjs/effect-client/request.js +0 -66
  43. package/dist/cjs/effect-client/runtime.js +0 -100
  44. package/dist/cjs/effect-client/types.js +0 -18
  45. package/dist/esm/effect-client/batch.mjs +0 -35
  46. package/dist/esm/effect-client/envelope.mjs +0 -104
  47. package/dist/esm/effect-client/guards.mjs +0 -3
  48. package/dist/esm/effect-client/request-context.mjs +0 -23
  49. package/dist/esm/effect-client/request.mjs +0 -28
  50. package/dist/esm/effect-client/runtime.mjs +0 -62
  51. package/dist/esm/effect-client/types.mjs +0 -0
  52. package/dist/esm-node/effect-client/batch.mjs +0 -36
  53. package/dist/esm-node/effect-client/envelope.mjs +0 -105
  54. package/dist/esm-node/effect-client/guards.mjs +0 -4
  55. package/dist/esm-node/effect-client/request-context.mjs +0 -24
  56. package/dist/esm-node/effect-client/request.mjs +0 -29
  57. package/dist/esm-node/effect-client/runtime.mjs +0 -63
  58. package/dist/esm-node/effect-client/types.mjs +0 -1
  59. package/dist/types/effect-client/batch.d.ts +0 -2
  60. package/dist/types/effect-client/envelope.d.ts +0 -15
  61. package/dist/types/effect-client/guards.d.ts +0 -2
  62. package/dist/types/effect-client/request-context.d.ts +0 -3
  63. package/dist/types/effect-client/request.d.ts +0 -1
  64. package/dist/types/effect-client/runtime.d.ts +0 -5
  65. package/dist/types/effect-client/types.d.ts +0 -68
  66. package/src/effect-client/batch.ts +0 -50
  67. package/src/effect-client/envelope.ts +0 -238
  68. package/src/effect-client/guards.ts +0 -6
  69. package/src/effect-client/request-context.ts +0 -54
  70. package/src/effect-client/request.ts +0 -51
  71. package/src/effect-client/runtime.ts +0 -122
  72. package/src/effect-client/types.ts +0 -84
@@ -1,62 +0,0 @@
1
- import { configureGeneratedEffectClientRuntime } from "./batch.mjs";
2
- import { prepareEffectRequest } from "./envelope.mjs";
3
- import { createEffectRequestContext as external_request_context_mjs_createEffectRequestContext } from "./request-context.mjs";
4
- const createGeneratedEffectClient = (manifest, config, requestRuntime)=>{
5
- const createRequest = requestRuntime.createRequest;
6
- const configureRequest = 'function' == typeof requestRuntime.configure ? requestRuntime.configure : void 0;
7
- const createRequestContextHeaders = 'function' == typeof requestRuntime.createRequestContextHeaders ? requestRuntime.createRequestContextHeaders : void 0;
8
- const httpMethodDecider = config.httpMethodDecider || 'functionName';
9
- const port = config.useEnvPort && "u" > typeof process && process.env && process.env.PORT ? process.env.PORT : config.port;
10
- configureGeneratedEffectClientRuntime(config, configureRequest);
11
- const createEffectRequestContext = (requestContext)=>external_request_context_mjs_createEffectRequestContext(createRequestContextHeaders, requestContext);
12
- const client = {};
13
- const operationManifest = {};
14
- for (const endpoint of manifest.endpoints){
15
- const operationId = `${endpoint.method}:${endpoint.routePath}`;
16
- const operation = {
17
- appNamespace: config.appNamespace,
18
- apiId: endpoint.apiId,
19
- group: endpoint.group,
20
- endpoint: endpoint.endpoint,
21
- operationId,
22
- routePath: endpoint.routePath,
23
- method: endpoint.method,
24
- operationVersion: endpoint.operationVersion,
25
- schemaHash: endpoint.schemaHash,
26
- version: endpoint.operationVersion
27
- };
28
- const sender = createRequest({
29
- path: endpoint.routePath,
30
- method: endpoint.method,
31
- port,
32
- operationContext: {
33
- operationId,
34
- routePath: endpoint.routePath,
35
- method: endpoint.method,
36
- schemaHash: endpoint.schemaHash,
37
- operationVersion: endpoint.operationVersion
38
- },
39
- httpMethodDecider,
40
- ...config.requestId ? {
41
- requestId: config.requestId
42
- } : {}
43
- });
44
- const call = (request = {})=>sender(prepareEffectRequest({
45
- endpoint,
46
- operation,
47
- request,
48
- config,
49
- createEffectRequestContext
50
- }));
51
- client[endpoint.group] ??= {};
52
- client[endpoint.group][endpoint.endpoint] = call;
53
- operationManifest[endpoint.group] ??= {};
54
- operationManifest[endpoint.group][endpoint.endpoint] = operation;
55
- }
56
- return {
57
- client,
58
- operationManifest,
59
- createEffectRequestContext
60
- };
61
- };
62
- export { createGeneratedEffectClient };
File without changes
@@ -1,36 +0,0 @@
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 };
@@ -1,105 +0,0 @@
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 };
@@ -1,4 +0,0 @@
1
- import "node:module";
2
- const isRecord = (value)=>'object' == typeof value && null !== value;
3
- const stringOrUndefined = (value)=>'string' == typeof value && value.length > 0 ? value : void 0;
4
- export { isRecord, stringOrUndefined };
@@ -1,24 +0,0 @@
1
- import "node:module";
2
- import { isRecord } from "./guards.mjs";
3
- const createEffectRequestContext = (createRequestContextHeaders, requestContext)=>{
4
- if (!isRecord(requestContext)) return {};
5
- const headers = createRequestContextHeaders ? createRequestContextHeaders(requestContext) : {};
6
- return {
7
- ...requestContext,
8
- headers
9
- };
10
- };
11
- const applyRequestContext = (normalizedRequest, request, createRequestContext)=>{
12
- if (!isRecord(request) || !isRecord(request.requestContext)) return normalizedRequest;
13
- const requestContext = createRequestContext(request.requestContext);
14
- const requestHeaders = isRecord(requestContext.headers) ? requestContext.headers : {};
15
- if (0 === Object.keys(requestHeaders).length) return normalizedRequest;
16
- return {
17
- ...normalizedRequest,
18
- headers: {
19
- ...isRecord(normalizedRequest.headers) ? normalizedRequest.headers : {},
20
- ...requestHeaders
21
- }
22
- };
23
- };
24
- export { applyRequestContext, createEffectRequestContext };
@@ -1,29 +0,0 @@
1
- import "node:module";
2
- import { isRecord } from "./guards.mjs";
3
- const METHODS_WITHOUT_BODY = new Set([
4
- 'GET',
5
- 'DELETE',
6
- 'HEAD',
7
- 'OPTIONS'
8
- ]);
9
- const normalizeRequest = (method, request)=>{
10
- if (!isRecord(request)) return {};
11
- const payload = {
12
- ...request
13
- };
14
- if (isRecord(request.path) && !isRecord(payload.params)) payload.params = request.path;
15
- if (isRecord(request.urlParams) && !isRecord(payload.query)) payload.query = request.urlParams;
16
- if (isRecord(request.headers) && !isRecord(payload.headers)) payload.headers = request.headers;
17
- if ('payload' in request && void 0 !== request.payload) if ("u" > typeof FormData && request.payload instanceof FormData && !('formData' in payload)) payload.formData = request.payload;
18
- else if (METHODS_WITHOUT_BODY.has(method)) {
19
- if (isRecord(request.payload)) payload.query = isRecord(payload.query) ? {
20
- ...payload.query,
21
- ...request.payload
22
- } : request.payload;
23
- else if (!('body' in payload)) payload.body = request.payload;
24
- } else if (!isRecord(request.payload) || 'data' in payload) {
25
- if (!('body' in payload)) payload.body = request.payload;
26
- } else payload.data = request.payload;
27
- return payload;
28
- };
29
- export { normalizeRequest };
@@ -1,63 +0,0 @@
1
- import "node:module";
2
- import { configureGeneratedEffectClientRuntime } from "./batch.mjs";
3
- import { prepareEffectRequest } from "./envelope.mjs";
4
- import { createEffectRequestContext as external_request_context_mjs_createEffectRequestContext } from "./request-context.mjs";
5
- const createGeneratedEffectClient = (manifest, config, requestRuntime)=>{
6
- const createRequest = requestRuntime.createRequest;
7
- const configureRequest = 'function' == typeof requestRuntime.configure ? requestRuntime.configure : void 0;
8
- const createRequestContextHeaders = 'function' == typeof requestRuntime.createRequestContextHeaders ? requestRuntime.createRequestContextHeaders : void 0;
9
- const httpMethodDecider = config.httpMethodDecider || 'functionName';
10
- const port = config.useEnvPort && "u" > typeof process && process.env && process.env.PORT ? process.env.PORT : config.port;
11
- configureGeneratedEffectClientRuntime(config, configureRequest);
12
- const createEffectRequestContext = (requestContext)=>external_request_context_mjs_createEffectRequestContext(createRequestContextHeaders, requestContext);
13
- const client = {};
14
- const operationManifest = {};
15
- for (const endpoint of manifest.endpoints){
16
- const operationId = `${endpoint.method}:${endpoint.routePath}`;
17
- const operation = {
18
- appNamespace: config.appNamespace,
19
- apiId: endpoint.apiId,
20
- group: endpoint.group,
21
- endpoint: endpoint.endpoint,
22
- operationId,
23
- routePath: endpoint.routePath,
24
- method: endpoint.method,
25
- operationVersion: endpoint.operationVersion,
26
- schemaHash: endpoint.schemaHash,
27
- version: endpoint.operationVersion
28
- };
29
- const sender = createRequest({
30
- path: endpoint.routePath,
31
- method: endpoint.method,
32
- port,
33
- operationContext: {
34
- operationId,
35
- routePath: endpoint.routePath,
36
- method: endpoint.method,
37
- schemaHash: endpoint.schemaHash,
38
- operationVersion: endpoint.operationVersion
39
- },
40
- httpMethodDecider,
41
- ...config.requestId ? {
42
- requestId: config.requestId
43
- } : {}
44
- });
45
- const call = (request = {})=>sender(prepareEffectRequest({
46
- endpoint,
47
- operation,
48
- request,
49
- config,
50
- createEffectRequestContext
51
- }));
52
- client[endpoint.group] ??= {};
53
- client[endpoint.group][endpoint.endpoint] = call;
54
- operationManifest[endpoint.group] ??= {};
55
- operationManifest[endpoint.group][endpoint.endpoint] = operation;
56
- }
57
- return {
58
- client,
59
- operationManifest,
60
- createEffectRequestContext
61
- };
62
- };
63
- export { createGeneratedEffectClient };
@@ -1 +0,0 @@
1
- import "node:module";
@@ -1,2 +0,0 @@
1
- import type { EffectRequestRuntime, GeneratedEffectClientConfig } from './types.js';
2
- export declare const configureGeneratedEffectClientRuntime: (config: GeneratedEffectClientConfig, configureRequest: EffectRequestRuntime['configure'] | undefined) => void;
@@ -1,15 +0,0 @@
1
- import type { EffectOperationDescriptor, EffectRequestContext, EffectRequestContextInput, GeneratedEffectClientConfig, GeneratedEffectEndpoint } from './types.js';
2
- /**
3
- * Resolves the current page origin with a configurable fallback. Single
4
- * implementation shared by the configure() bootstrap and the data envelope
5
- * (the generated template previously duplicated data-platform's
6
- * `resolveRuntimeOrigin` with a different fallback).
7
- */
8
- export declare const resolveOrigin: (defaultOrigin: string) => string;
9
- export declare const prepareEffectRequest: (options: {
10
- endpoint: GeneratedEffectEndpoint;
11
- operation: EffectOperationDescriptor;
12
- request: unknown;
13
- config: GeneratedEffectClientConfig;
14
- createEffectRequestContext: (requestContext: EffectRequestContextInput) => EffectRequestContext;
15
- }) => Record<string, unknown>;
@@ -1,2 +0,0 @@
1
- export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
2
- export declare const stringOrUndefined: (value: unknown) => string | undefined;
@@ -1,3 +0,0 @@
1
- import type { EffectRequestContext, EffectRequestContextInput, EffectRequestRuntime } from './types.js';
2
- export declare const createEffectRequestContext: (createRequestContextHeaders: EffectRequestRuntime['createRequestContextHeaders'], requestContext: EffectRequestContextInput) => EffectRequestContext;
3
- export declare const applyRequestContext: (normalizedRequest: Record<string, unknown>, request: unknown, createRequestContext: (requestContext: EffectRequestContextInput) => EffectRequestContext) => Record<string, unknown>;
@@ -1 +0,0 @@
1
- export declare const normalizeRequest: (method: string, request: unknown) => Record<string, unknown>;
@@ -1,5 +0,0 @@
1
- import type { EffectRequestRuntime, GeneratedEffectClientConfig, GeneratedEffectClientModule, GeneratedEffectEndpoint } from './types.js';
2
- export type { EffectClient, EffectClientGroup, EffectClientOperation, EffectOperationDescriptor, EffectOperationManifest, EffectRequestContext, EffectRequestContextInput, EffectRequestRuntime, GeneratedEffectBatchConfig, GeneratedEffectClientConfig, GeneratedEffectClientModule, GeneratedEffectEndpoint, } from './types.js';
3
- export declare const createGeneratedEffectClient: (manifest: {
4
- endpoints: GeneratedEffectEndpoint[];
5
- }, config: GeneratedEffectClientConfig, requestRuntime: EffectRequestRuntime) => GeneratedEffectClientModule;
@@ -1,68 +0,0 @@
1
- export type GeneratedEffectEndpoint = {
2
- apiId: string;
3
- group: string;
4
- endpoint: string;
5
- method: string;
6
- routePath: string;
7
- /** Per-endpoint operation contract hash (bff-core hash). */
8
- schemaHash: string;
9
- operationVersion: number;
10
- };
11
- export type GeneratedEffectBatchConfig = {
12
- enabled: boolean;
13
- endpoint: string;
14
- flushIntervalMs: number;
15
- maxBatchSize: number;
16
- maxBatchBytes: number;
17
- requestTimeoutMs: number;
18
- allowedMethods: string[];
19
- };
20
- export type GeneratedEffectClientConfig = {
21
- appNamespace: string;
22
- /** Cross-project producer id; absent for same-project clients. */
23
- requestId?: string;
24
- port: number;
25
- /** Resolve the port from process.env.PORT first (server bundles). */
26
- useEnvPort?: boolean;
27
- defaultOrigin: string;
28
- httpMethodDecider?: string;
29
- batch: GeneratedEffectBatchConfig;
30
- };
31
- export type EffectOperationDescriptor = {
32
- appNamespace: string;
33
- apiId: string;
34
- group: string;
35
- endpoint: string;
36
- operationId: string;
37
- routePath: string;
38
- method: string;
39
- operationVersion: number;
40
- schemaHash: string;
41
- version: number;
42
- };
43
- export type EffectClientOperation = (request?: unknown) => Promise<unknown>;
44
- export type EffectClientGroup = Record<string, EffectClientOperation>;
45
- export type EffectClient = Record<string, EffectClientGroup>;
46
- export type EffectOperationManifest = Record<string, Record<string, EffectOperationDescriptor>>;
47
- export type EffectRequestContextInput = Record<string, unknown>;
48
- export type EffectRequestContext = {
49
- headers: Record<string, string>;
50
- } & Record<string, unknown>;
51
- /** Structural slice of `@modern-js/runtime-extensions/request-policy` the runtime relies on. */
52
- export type EffectRequestRuntime = {
53
- createRequest: (options: {
54
- path: string;
55
- method: string;
56
- port: number | string;
57
- operationContext: Record<string, unknown>;
58
- httpMethodDecider: string;
59
- requestId?: string;
60
- }) => (...args: unknown[]) => Promise<unknown>;
61
- configure?: (options: Record<string, unknown>) => void;
62
- createRequestContextHeaders?: (input: EffectRequestContextInput) => Record<string, string>;
63
- };
64
- export type GeneratedEffectClientModule = {
65
- client: EffectClient;
66
- operationManifest: EffectOperationManifest;
67
- createEffectRequestContext: (requestContext: EffectRequestContextInput) => EffectRequestContext;
68
- };
@@ -1,50 +0,0 @@
1
- // @effect-diagnostics processEnv:off strictBooleanExpressions:off
2
- import { createDataBatchTransport } from '../data-platform';
3
- import { resolveOrigin } from './envelope';
4
- import type {
5
- EffectRequestRuntime,
6
- GeneratedEffectClientConfig,
7
- } from './types';
8
-
9
- const resolveRuntimeFetch = (): typeof fetch | undefined =>
10
- typeof fetch === 'function' ? fetch.bind(globalThis) : undefined;
11
-
12
- export const configureGeneratedEffectClientRuntime = (
13
- config: GeneratedEffectClientConfig,
14
- configureRequest: EffectRequestRuntime['configure'] | undefined,
15
- ): void => {
16
- const defaultOrigin = config.defaultOrigin;
17
-
18
- if (config.requestId && configureRequest) {
19
- const configurePayload: Record<string, unknown> = {
20
- requestId: config.requestId,
21
- requireEnvelope: true,
22
- identityBinding: {
23
- enabled: true,
24
- strict: true,
25
- },
26
- operationContract: {
27
- enabled: true,
28
- strict: true,
29
- requireSchemaHash: true,
30
- requireOperationVersion: true,
31
- },
32
- setDomain: () => resolveOrigin(defaultOrigin),
33
- };
34
-
35
- const runtimeFetch = resolveRuntimeFetch();
36
- if (config.batch.enabled !== false && runtimeFetch) {
37
- configurePayload.request = createDataBatchTransport({
38
- fetch: runtimeFetch,
39
- endpoint: config.batch.endpoint,
40
- flushIntervalMs: config.batch.flushIntervalMs,
41
- maxBatchSize: config.batch.maxBatchSize,
42
- maxBatchBytes: config.batch.maxBatchBytes,
43
- requestTimeoutMs: config.batch.requestTimeoutMs,
44
- allowedMethods: config.batch.allowedMethods,
45
- });
46
- }
47
-
48
- configureRequest(configurePayload);
49
- }
50
- };