@bleedingdev/modern-js-bff-effect 3.9.0-ultramodern.2 → 3.9.0-ultramodern.21

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 (142) hide show
  1. package/README.md +20 -4
  2. package/dist/cjs/assembly.js +50 -0
  3. package/dist/cjs/{effect-client/guards.js → data-platform/batch/options.js} +13 -9
  4. package/dist/cjs/data-platform/batch/queue.js +48 -83
  5. package/dist/cjs/data-platform/trace.js +2 -2
  6. package/dist/cjs/effect/context.js +28 -4
  7. package/dist/cjs/effect/edge-dispatcher.js +12 -12
  8. package/dist/cjs/effect/edge.js +36 -3
  9. package/dist/cjs/effect/endpoint-contracts.js +3 -4
  10. package/dist/cjs/effect/entry-shape.js +40 -12
  11. package/dist/cjs/effect/generated-entry.js +57 -0
  12. package/dist/cjs/effect/handler/batch-handler.js +7 -7
  13. package/dist/cjs/effect/handler/batch.js +8 -10
  14. package/dist/cjs/effect/handler/definition.js +1 -21
  15. package/dist/cjs/effect/index.js +8 -8
  16. package/dist/cjs/effect/module.js +8 -4
  17. package/dist/cjs/effect/operation-context.js +10 -14
  18. package/dist/cjs/effect/rpcSerialization.js +0 -2
  19. package/dist/cjs/effect-client/cross-project.js +89 -0
  20. package/dist/cjs/effect-client/index.js +5 -3
  21. package/dist/cjs/microvertical-api.js +120 -0
  22. package/dist/esm/assembly.mjs +12 -0
  23. package/dist/esm/data-platform/batch/options.mjs +10 -0
  24. package/dist/esm/data-platform/batch/queue.mjs +48 -83
  25. package/dist/esm/data-platform/trace.mjs +1 -1
  26. package/dist/esm/effect/context.mjs +21 -6
  27. package/dist/esm/effect/edge-dispatcher.mjs +6 -6
  28. package/dist/esm/effect/edge.mjs +3 -0
  29. package/dist/esm/effect/endpoint-contracts.mjs +2 -3
  30. package/dist/esm/effect/entry-shape-registry.mjs +2 -2
  31. package/dist/esm/effect/entry-shape.mjs +29 -6
  32. package/dist/esm/effect/generated-entry.mjs +19 -0
  33. package/dist/esm/effect/handler/batch-handler.mjs +8 -8
  34. package/dist/esm/effect/handler/batch.mjs +9 -8
  35. package/dist/esm/effect/handler/definition.mjs +1 -21
  36. package/dist/esm/effect/index.mjs +1 -1
  37. package/dist/esm/effect/module.mjs +8 -4
  38. package/dist/esm/effect/operation-context.mjs +3 -4
  39. package/dist/esm/effect/rpcSerialization.mjs +0 -2
  40. package/dist/esm/effect-client/cross-project.mjs +51 -0
  41. package/dist/esm/effect-client/index.mjs +4 -2
  42. package/dist/esm/microvertical-api.mjs +67 -0
  43. package/dist/esm-node/assembly.mjs +13 -0
  44. package/dist/esm-node/data-platform/batch/options.mjs +11 -0
  45. package/dist/esm-node/data-platform/batch/queue.mjs +48 -83
  46. package/dist/esm-node/data-platform/trace.mjs +1 -1
  47. package/dist/esm-node/effect/context.mjs +21 -6
  48. package/dist/esm-node/effect/edge-dispatcher.mjs +6 -6
  49. package/dist/esm-node/effect/edge.mjs +3 -0
  50. package/dist/esm-node/effect/endpoint-contracts.mjs +2 -3
  51. package/dist/esm-node/effect/entry-shape.mjs +29 -6
  52. package/dist/esm-node/effect/generated-entry.mjs +20 -0
  53. package/dist/esm-node/effect/handler/batch-handler.mjs +8 -8
  54. package/dist/esm-node/effect/handler/batch.mjs +9 -8
  55. package/dist/esm-node/effect/handler/definition.mjs +1 -21
  56. package/dist/esm-node/effect/index.mjs +1 -1
  57. package/dist/esm-node/effect/module.mjs +8 -4
  58. package/dist/esm-node/effect/operation-context.mjs +3 -4
  59. package/dist/esm-node/effect/rpcSerialization.mjs +0 -2
  60. package/dist/esm-node/effect-client/cross-project.mjs +52 -0
  61. package/dist/esm-node/effect-client/index.mjs +4 -2
  62. package/dist/esm-node/microvertical-api.mjs +68 -0
  63. package/dist/types/assembly.d.ts +10 -0
  64. package/dist/types/data-platform/batch/options.d.ts +7 -0
  65. package/dist/types/data-platform/batch/queue.d.ts +0 -1
  66. package/dist/types/effect/context.d.ts +15 -2
  67. package/dist/types/effect/edge-dispatcher.d.ts +3 -3
  68. package/dist/types/effect/edge.d.ts +3 -0
  69. package/dist/types/effect/endpoint-contracts.d.ts +2 -20
  70. package/dist/types/effect/entry-shape.d.ts +16 -2
  71. package/dist/types/effect/generated-entry.d.ts +7 -0
  72. package/dist/types/effect/handler/batch.d.ts +7 -2
  73. package/dist/types/effect/handler/types.d.ts +2 -17
  74. package/dist/types/effect/handler.d.ts +1 -1
  75. package/dist/types/effect/module.d.ts +2 -1
  76. package/dist/types/effect/operation-context.d.ts +1 -2
  77. package/dist/types/effect-client/cross-project.d.ts +10 -0
  78. package/dist/types/effect-client/index.d.ts +7 -4
  79. package/dist/types/microvertical-api.d.ts +65 -0
  80. package/package.json +47 -42
  81. package/src/assembly.ts +43 -0
  82. package/src/data-platform/batch/options.ts +20 -0
  83. package/src/data-platform/batch/queue.ts +63 -92
  84. package/src/data-platform/trace.ts +1 -1
  85. package/src/effect/context.ts +64 -12
  86. package/src/effect/edge-dispatcher.ts +14 -11
  87. package/src/effect/edge.ts +6 -0
  88. package/src/effect/endpoint-contracts.ts +3 -24
  89. package/src/effect/entry-shape.ts +105 -10
  90. package/src/effect/generated-entry.ts +36 -0
  91. package/src/effect/handler/batch-handler.ts +27 -28
  92. package/src/effect/handler/batch.ts +9 -13
  93. package/src/effect/handler/definition.ts +0 -45
  94. package/src/effect/handler/http.ts +2 -2
  95. package/src/effect/handler/types.ts +3 -32
  96. package/src/effect/handler.ts +0 -1
  97. package/src/effect/index.ts +1 -1
  98. package/src/effect/module.ts +11 -4
  99. package/src/effect/operation-context.ts +2 -6
  100. package/src/effect/rpcSerialization.ts +0 -2
  101. package/src/effect-client/cross-project.ts +104 -0
  102. package/src/effect-client/index.ts +17 -7
  103. package/src/microvertical-api.ts +102 -0
  104. package/dist/cjs/effect/edge-context.js +0 -61
  105. package/dist/cjs/effect-client/batch.js +0 -73
  106. package/dist/cjs/effect-client/envelope.js +0 -145
  107. package/dist/cjs/effect-client/request-context.js +0 -64
  108. package/dist/cjs/effect-client/request.js +0 -66
  109. package/dist/cjs/effect-client/runtime.js +0 -100
  110. package/dist/cjs/effect-client/types.js +0 -18
  111. package/dist/esm/effect/edge-context.mjs +0 -14
  112. package/dist/esm/effect-client/batch.mjs +0 -35
  113. package/dist/esm/effect-client/envelope.mjs +0 -104
  114. package/dist/esm/effect-client/guards.mjs +0 -3
  115. package/dist/esm/effect-client/request-context.mjs +0 -23
  116. package/dist/esm/effect-client/request.mjs +0 -28
  117. package/dist/esm/effect-client/runtime.mjs +0 -62
  118. package/dist/esm/effect-client/types.mjs +0 -0
  119. package/dist/esm-node/effect/edge-context.mjs +0 -15
  120. package/dist/esm-node/effect-client/batch.mjs +0 -36
  121. package/dist/esm-node/effect-client/envelope.mjs +0 -105
  122. package/dist/esm-node/effect-client/guards.mjs +0 -4
  123. package/dist/esm-node/effect-client/request-context.mjs +0 -24
  124. package/dist/esm-node/effect-client/request.mjs +0 -29
  125. package/dist/esm-node/effect-client/runtime.mjs +0 -63
  126. package/dist/esm-node/effect-client/types.mjs +0 -1
  127. package/dist/types/effect/edge-context.d.ts +0 -5
  128. package/dist/types/effect-client/batch.d.ts +0 -2
  129. package/dist/types/effect-client/envelope.d.ts +0 -15
  130. package/dist/types/effect-client/guards.d.ts +0 -2
  131. package/dist/types/effect-client/request-context.d.ts +0 -3
  132. package/dist/types/effect-client/request.d.ts +0 -1
  133. package/dist/types/effect-client/runtime.d.ts +0 -5
  134. package/dist/types/effect-client/types.d.ts +0 -68
  135. package/src/effect/edge-context.ts +0 -51
  136. package/src/effect-client/batch.ts +0 -50
  137. package/src/effect-client/envelope.ts +0 -238
  138. package/src/effect-client/guards.ts +0 -6
  139. package/src/effect-client/request-context.ts +0 -54
  140. package/src/effect-client/request.ts +0 -51
  141. package/src/effect-client/runtime.ts +0 -122
  142. package/src/effect-client/types.ts +0 -84
@@ -1,66 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (exports1, getters, values)=>{
5
- var define = (defs, kind)=>{
6
- for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
- enumerable: true,
8
- [kind]: defs[key]
9
- });
10
- };
11
- define(getters, "get");
12
- define(values, "value");
13
- };
14
- })();
15
- (()=>{
16
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
- })();
18
- (()=>{
19
- __webpack_require__.r = (exports1)=>{
20
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
- value: 'Module'
22
- });
23
- Object.defineProperty(exports1, '__esModule', {
24
- value: true
25
- });
26
- };
27
- })();
28
- var __webpack_exports__ = {};
29
- __webpack_require__.r(__webpack_exports__);
30
- __webpack_require__.d(__webpack_exports__, {
31
- normalizeRequest: ()=>normalizeRequest
32
- });
33
- const external_guards_js_namespaceObject = require("./guards.js");
34
- const METHODS_WITHOUT_BODY = new Set([
35
- 'GET',
36
- 'DELETE',
37
- 'HEAD',
38
- 'OPTIONS'
39
- ]);
40
- const normalizeRequest = (method, request)=>{
41
- if (!(0, external_guards_js_namespaceObject.isRecord)(request)) return {};
42
- const payload = {
43
- ...request
44
- };
45
- if ((0, external_guards_js_namespaceObject.isRecord)(request.path) && !(0, external_guards_js_namespaceObject.isRecord)(payload.params)) payload.params = request.path;
46
- if ((0, external_guards_js_namespaceObject.isRecord)(request.urlParams) && !(0, external_guards_js_namespaceObject.isRecord)(payload.query)) payload.query = request.urlParams;
47
- if ((0, external_guards_js_namespaceObject.isRecord)(request.headers) && !(0, external_guards_js_namespaceObject.isRecord)(payload.headers)) payload.headers = request.headers;
48
- if ('payload' in request && void 0 !== request.payload) if ("u" > typeof FormData && request.payload instanceof FormData && !('formData' in payload)) payload.formData = request.payload;
49
- else if (METHODS_WITHOUT_BODY.has(method)) {
50
- if ((0, external_guards_js_namespaceObject.isRecord)(request.payload)) payload.query = (0, external_guards_js_namespaceObject.isRecord)(payload.query) ? {
51
- ...payload.query,
52
- ...request.payload
53
- } : request.payload;
54
- else if (!('body' in payload)) payload.body = request.payload;
55
- } else if (!(0, external_guards_js_namespaceObject.isRecord)(request.payload) || 'data' in payload) {
56
- if (!('body' in payload)) payload.body = request.payload;
57
- } else payload.data = request.payload;
58
- return payload;
59
- };
60
- exports.normalizeRequest = __webpack_exports__.normalizeRequest;
61
- for(var __rspack_i in __webpack_exports__)if (-1 === [
62
- "normalizeRequest"
63
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
64
- Object.defineProperty(exports, '__esModule', {
65
- value: true
66
- });
@@ -1,100 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (exports1, getters, values)=>{
5
- var define = (defs, kind)=>{
6
- for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
- enumerable: true,
8
- [kind]: defs[key]
9
- });
10
- };
11
- define(getters, "get");
12
- define(values, "value");
13
- };
14
- })();
15
- (()=>{
16
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
- })();
18
- (()=>{
19
- __webpack_require__.r = (exports1)=>{
20
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
- value: 'Module'
22
- });
23
- Object.defineProperty(exports1, '__esModule', {
24
- value: true
25
- });
26
- };
27
- })();
28
- var __webpack_exports__ = {};
29
- __webpack_require__.r(__webpack_exports__);
30
- __webpack_require__.d(__webpack_exports__, {
31
- createGeneratedEffectClient: ()=>createGeneratedEffectClient
32
- });
33
- const external_batch_js_namespaceObject = require("./batch.js");
34
- const external_envelope_js_namespaceObject = require("./envelope.js");
35
- const external_request_context_js_namespaceObject = require("./request-context.js");
36
- const createGeneratedEffectClient = (manifest, config, requestRuntime)=>{
37
- const createRequest = requestRuntime.createRequest;
38
- const configureRequest = 'function' == typeof requestRuntime.configure ? requestRuntime.configure : void 0;
39
- const createRequestContextHeaders = 'function' == typeof requestRuntime.createRequestContextHeaders ? requestRuntime.createRequestContextHeaders : void 0;
40
- const httpMethodDecider = config.httpMethodDecider || 'functionName';
41
- const port = config.useEnvPort && "u" > typeof process && process.env && process.env.PORT ? process.env.PORT : config.port;
42
- (0, external_batch_js_namespaceObject.configureGeneratedEffectClientRuntime)(config, configureRequest);
43
- const createEffectRequestContext = (requestContext)=>(0, external_request_context_js_namespaceObject.createEffectRequestContext)(createRequestContextHeaders, requestContext);
44
- const client = {};
45
- const operationManifest = {};
46
- for (const endpoint of manifest.endpoints){
47
- const operationId = `${endpoint.method}:${endpoint.routePath}`;
48
- const operation = {
49
- appNamespace: config.appNamespace,
50
- apiId: endpoint.apiId,
51
- group: endpoint.group,
52
- endpoint: endpoint.endpoint,
53
- operationId,
54
- routePath: endpoint.routePath,
55
- method: endpoint.method,
56
- operationVersion: endpoint.operationVersion,
57
- schemaHash: endpoint.schemaHash,
58
- version: endpoint.operationVersion
59
- };
60
- const sender = createRequest({
61
- path: endpoint.routePath,
62
- method: endpoint.method,
63
- port,
64
- operationContext: {
65
- operationId,
66
- routePath: endpoint.routePath,
67
- method: endpoint.method,
68
- schemaHash: endpoint.schemaHash,
69
- operationVersion: endpoint.operationVersion
70
- },
71
- httpMethodDecider,
72
- ...config.requestId ? {
73
- requestId: config.requestId
74
- } : {}
75
- });
76
- const call = (request = {})=>sender((0, external_envelope_js_namespaceObject.prepareEffectRequest)({
77
- endpoint,
78
- operation,
79
- request,
80
- config,
81
- createEffectRequestContext
82
- }));
83
- client[endpoint.group] ??= {};
84
- client[endpoint.group][endpoint.endpoint] = call;
85
- operationManifest[endpoint.group] ??= {};
86
- operationManifest[endpoint.group][endpoint.endpoint] = operation;
87
- }
88
- return {
89
- client,
90
- operationManifest,
91
- createEffectRequestContext
92
- };
93
- };
94
- exports.createGeneratedEffectClient = __webpack_exports__.createGeneratedEffectClient;
95
- for(var __rspack_i in __webpack_exports__)if (-1 === [
96
- "createGeneratedEffectClient"
97
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
98
- Object.defineProperty(exports, '__esModule', {
99
- value: true
100
- });
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.r = (exports1)=>{
5
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
6
- value: 'Module'
7
- });
8
- Object.defineProperty(exports1, '__esModule', {
9
- value: true
10
- });
11
- };
12
- })();
13
- var __webpack_exports__ = {};
14
- __webpack_require__.r(__webpack_exports__);
15
- for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
16
- Object.defineProperty(exports, '__esModule', {
17
- value: true
18
- });
@@ -1,14 +0,0 @@
1
- import { createEffectOperationContext, kEffectContextStorage } from "./operation-context.mjs";
2
- const globalStore = globalThis;
3
- const asyncHooks = globalStore.process?.getBuiltinModule?.('node:async_hooks');
4
- const AsyncLocalStorage = asyncHooks?.AsyncLocalStorage;
5
- if ('function' != typeof AsyncLocalStorage) throw new Error('[BFF][Effect] The edge runtime must provide AsyncLocalStorage. Enable Node.js compatibility or the nodejs_als compatibility flag.');
6
- const effectContextStorage = globalStore[kEffectContextStorage] ?? (globalStore[kEffectContextStorage] = new AsyncLocalStorage());
7
- const runWithEffectContext = (context, cb)=>effectContextStorage.run(context, cb);
8
- const useEffectContext = ()=>{
9
- const context = effectContextStorage.getStore();
10
- if (!context) throw new Error("Can't call useEffectContext out of Effect runtime scope");
11
- return context;
12
- };
13
- const useOperationContext = ()=>useEffectContext().operationContext;
14
- export { createEffectOperationContext, runWithEffectContext, useEffectContext, useOperationContext };
@@ -1,35 +0,0 @@
1
- import { createDataBatchTransport } from "../data-platform/index.mjs";
2
- import { resolveOrigin } from "./envelope.mjs";
3
- const resolveRuntimeFetch = ()=>'function' == typeof fetch ? fetch.bind(globalThis) : void 0;
4
- const configureGeneratedEffectClientRuntime = (config, configureRequest)=>{
5
- const defaultOrigin = config.defaultOrigin;
6
- if (config.requestId && configureRequest) {
7
- const configurePayload = {
8
- requestId: config.requestId,
9
- requireEnvelope: true,
10
- identityBinding: {
11
- enabled: true,
12
- strict: true
13
- },
14
- operationContract: {
15
- enabled: true,
16
- strict: true,
17
- requireSchemaHash: true,
18
- requireOperationVersion: true
19
- },
20
- setDomain: ()=>resolveOrigin(defaultOrigin)
21
- };
22
- const runtimeFetch = resolveRuntimeFetch();
23
- if (false !== config.batch.enabled && runtimeFetch) configurePayload.request = createDataBatchTransport({
24
- fetch: runtimeFetch,
25
- endpoint: config.batch.endpoint,
26
- flushIntervalMs: config.batch.flushIntervalMs,
27
- maxBatchSize: config.batch.maxBatchSize,
28
- maxBatchBytes: config.batch.maxBatchBytes,
29
- requestTimeoutMs: config.batch.requestTimeoutMs,
30
- allowedMethods: config.batch.allowedMethods
31
- });
32
- configureRequest(configurePayload);
33
- }
34
- };
35
- export { configureGeneratedEffectClientRuntime };
@@ -1,104 +0,0 @@
1
- import { DEFAULT_DATA_BATCH_HEADER, DEFAULT_DATA_ENVELOPE_HEADER, createRequestEnvelope, encodeRequestEnvelopeHeader } from "../data-platform/index.mjs";
2
- import { isRecord, stringOrUndefined } from "./guards.mjs";
3
- import { normalizeRequest } from "./request.mjs";
4
- import { applyRequestContext } from "./request-context.mjs";
5
- const DATA_REQUEST_MODES = new Set([
6
- 'cache-first',
7
- 'stale-while-revalidate',
8
- 'network-only'
9
- ]);
10
- const DATA_MUTATION_MODES = new Set([
11
- 'optimistic',
12
- 'pessimistic',
13
- 'fire-and-forget'
14
- ]);
15
- const isDataRequestMode = (value)=>'string' == typeof value && DATA_REQUEST_MODES.has(value);
16
- const isDataMutationMode = (value)=>'string' == typeof value && DATA_MUTATION_MODES.has(value);
17
- const normalizeOrigin = (value)=>{
18
- if ('string' != typeof value || 0 === value.length) return;
19
- try {
20
- return new URL(value).origin;
21
- } catch {
22
- return;
23
- }
24
- };
25
- const resolveOrigin = (defaultOrigin)=>{
26
- if ("u" > typeof window && window.location && 'string' == typeof window.location.origin && window.location.origin) return window.location.origin;
27
- const globalLocation = globalThis?.location;
28
- if (globalLocation && 'string' == typeof globalLocation.origin && globalLocation.origin) return globalLocation.origin;
29
- return defaultOrigin;
30
- };
31
- const resolveTargetOrigin = (dataPlatform, defaultOrigin)=>{
32
- const explicitTargetOrigin = stringOrUndefined(dataPlatform.targetOrigin) || stringOrUndefined(dataPlatform.endpointOrigin);
33
- if (explicitTargetOrigin) return explicitTargetOrigin;
34
- return defaultOrigin;
35
- };
36
- const shouldAttachEnvelopeHeader = (dataPlatform, defaultOrigin)=>{
37
- if (true === dataPlatform.allowCrossOriginEnvelope) return true;
38
- const currentOrigin = normalizeOrigin(resolveOrigin(defaultOrigin));
39
- const targetOrigin = normalizeOrigin(resolveTargetOrigin(dataPlatform, defaultOrigin));
40
- if (!currentOrigin || !targetOrigin) return true;
41
- return currentOrigin === targetOrigin;
42
- };
43
- const toEnvelopeInput = (normalizedRequest)=>{
44
- const payload = {};
45
- if (isRecord(normalizedRequest.params)) payload.path = normalizedRequest.params;
46
- if (isRecord(normalizedRequest.query)) payload.query = normalizedRequest.query;
47
- if ('data' in normalizedRequest && void 0 !== normalizedRequest.data) payload.data = normalizedRequest.data;
48
- if ('body' in normalizedRequest && void 0 !== normalizedRequest.body) payload.body = normalizedRequest.body;
49
- if ("u" > typeof FormData && normalizedRequest.formData instanceof FormData) payload.formData = Array.from(normalizedRequest.formData.entries()).map(([key, value])=>[
50
- key,
51
- String(value)
52
- ]);
53
- if ("u" > typeof URLSearchParams && normalizedRequest.formUrlencoded instanceof URLSearchParams) payload.formUrlencoded = normalizedRequest.formUrlencoded.toString();
54
- return payload;
55
- };
56
- const prepareEffectRequest = (options)=>{
57
- const { endpoint, operation, request, config, createEffectRequestContext } = options;
58
- const defaultOrigin = config.defaultOrigin;
59
- const normalizedRequest = applyRequestContext(normalizeRequest(endpoint.method, request), request, createEffectRequestContext);
60
- const dataPlatform = isRecord(request) && isRecord(request.dataPlatform) ? request.dataPlatform : {};
61
- const strictEnvelope = true === dataPlatform.requireEnvelope || true === dataPlatform.strict;
62
- if (!strictEnvelope && !shouldAttachEnvelopeHeader(dataPlatform, defaultOrigin)) return normalizedRequest;
63
- try {
64
- const namespace = stringOrUndefined(dataPlatform.appNamespace) || config.appNamespace;
65
- const origin = stringOrUndefined(dataPlatform.origin) || resolveOrigin(defaultOrigin);
66
- const envelope = createRequestEnvelope({
67
- operation: {
68
- ...operation,
69
- appNamespace: namespace
70
- },
71
- scope: {
72
- appNamespace: namespace,
73
- origin,
74
- tenantId: stringOrUndefined(dataPlatform.tenantId),
75
- userId: stringOrUndefined(dataPlatform.userId),
76
- sessionId: stringOrUndefined(dataPlatform.sessionId)
77
- },
78
- requestInput: {
79
- method: endpoint.method,
80
- routePath: endpoint.routePath,
81
- payload: toEnvelopeInput(normalizedRequest)
82
- },
83
- requestMode: isDataRequestMode(dataPlatform.requestMode) ? dataPlatform.requestMode : void 0,
84
- mutationMode: isDataMutationMode(dataPlatform.mutationMode) ? dataPlatform.mutationMode : void 0,
85
- selectionPlan: isRecord(dataPlatform.selectionPlan) ? dataPlatform.selectionPlan : void 0,
86
- traceContext: isRecord(dataPlatform.traceContext) ? dataPlatform.traceContext : void 0,
87
- requireTraceContext: true === dataPlatform.requireTraceContext
88
- });
89
- const headerName = stringOrUndefined(dataPlatform.envelopeHeader) || DEFAULT_DATA_ENVELOPE_HEADER;
90
- const headers = isRecord(normalizedRequest.headers) ? {
91
- ...normalizedRequest.headers
92
- } : {};
93
- if (false === dataPlatform.batch) headers[DEFAULT_DATA_BATCH_HEADER] = 'off';
94
- headers[headerName] = encodeRequestEnvelopeHeader(envelope);
95
- return {
96
- ...normalizedRequest,
97
- headers
98
- };
99
- } catch (error) {
100
- if (strictEnvelope) throw error;
101
- return normalizedRequest;
102
- }
103
- };
104
- export { prepareEffectRequest, resolveOrigin };
@@ -1,3 +0,0 @@
1
- const isRecord = (value)=>'object' == typeof value && null !== value;
2
- const stringOrUndefined = (value)=>'string' == typeof value && value.length > 0 ? value : void 0;
3
- export { isRecord, stringOrUndefined };
@@ -1,23 +0,0 @@
1
- import { isRecord } from "./guards.mjs";
2
- const createEffectRequestContext = (createRequestContextHeaders, requestContext)=>{
3
- if (!isRecord(requestContext)) return {};
4
- const headers = createRequestContextHeaders ? createRequestContextHeaders(requestContext) : {};
5
- return {
6
- ...requestContext,
7
- headers
8
- };
9
- };
10
- const applyRequestContext = (normalizedRequest, request, createRequestContext)=>{
11
- if (!isRecord(request) || !isRecord(request.requestContext)) return normalizedRequest;
12
- const requestContext = createRequestContext(request.requestContext);
13
- const requestHeaders = isRecord(requestContext.headers) ? requestContext.headers : {};
14
- if (0 === Object.keys(requestHeaders).length) return normalizedRequest;
15
- return {
16
- ...normalizedRequest,
17
- headers: {
18
- ...isRecord(normalizedRequest.headers) ? normalizedRequest.headers : {},
19
- ...requestHeaders
20
- }
21
- };
22
- };
23
- export { applyRequestContext, createEffectRequestContext };
@@ -1,28 +0,0 @@
1
- import { isRecord } from "./guards.mjs";
2
- const METHODS_WITHOUT_BODY = new Set([
3
- 'GET',
4
- 'DELETE',
5
- 'HEAD',
6
- 'OPTIONS'
7
- ]);
8
- const normalizeRequest = (method, request)=>{
9
- if (!isRecord(request)) return {};
10
- const payload = {
11
- ...request
12
- };
13
- if (isRecord(request.path) && !isRecord(payload.params)) payload.params = request.path;
14
- if (isRecord(request.urlParams) && !isRecord(payload.query)) payload.query = request.urlParams;
15
- if (isRecord(request.headers) && !isRecord(payload.headers)) payload.headers = request.headers;
16
- if ('payload' in request && void 0 !== request.payload) if ("u" > typeof FormData && request.payload instanceof FormData && !('formData' in payload)) payload.formData = request.payload;
17
- else if (METHODS_WITHOUT_BODY.has(method)) {
18
- if (isRecord(request.payload)) payload.query = isRecord(payload.query) ? {
19
- ...payload.query,
20
- ...request.payload
21
- } : request.payload;
22
- else if (!('body' in payload)) payload.body = request.payload;
23
- } else if (!isRecord(request.payload) || 'data' in payload) {
24
- if (!('body' in payload)) payload.body = request.payload;
25
- } else payload.data = request.payload;
26
- return payload;
27
- };
28
- export { normalizeRequest };
@@ -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,15 +0,0 @@
1
- import "node:module";
2
- import { createEffectOperationContext, kEffectContextStorage } from "./operation-context.mjs";
3
- const globalStore = globalThis;
4
- const asyncHooks = globalStore.process?.getBuiltinModule?.('node:async_hooks');
5
- const AsyncLocalStorage = asyncHooks?.AsyncLocalStorage;
6
- if ('function' != typeof AsyncLocalStorage) throw new Error('[BFF][Effect] The edge runtime must provide AsyncLocalStorage. Enable Node.js compatibility or the nodejs_als compatibility flag.');
7
- const effectContextStorage = globalStore[kEffectContextStorage] ?? (globalStore[kEffectContextStorage] = new AsyncLocalStorage());
8
- const runWithEffectContext = (context, cb)=>effectContextStorage.run(context, cb);
9
- const useEffectContext = ()=>{
10
- const context = effectContextStorage.getStore();
11
- if (!context) throw new Error("Can't call useEffectContext out of Effect runtime scope");
12
- return context;
13
- };
14
- const useOperationContext = ()=>useEffectContext().operationContext;
15
- export { createEffectOperationContext, runWithEffectContext, useEffectContext, useOperationContext };
@@ -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 };