@bleedingdev/modern-js-plugin-bff-extensions 3.9.0-ultramodern.10 → 3.9.0-ultramodern.12

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 (50) hide show
  1. package/README.md +7 -0
  2. package/dist/cjs/backend-federation/identity.js +23 -22
  3. package/dist/cjs/backend-federation-manifest/load.js +28 -5
  4. package/dist/cjs/backend-federation-manifest/validation.js +11 -7
  5. package/dist/cjs/cross-project-policy/node.js +8 -28
  6. package/dist/cjs/effect-adapter/cross-project-policy.js +2 -2
  7. package/dist/cjs/effect-adapter/entry.js +8 -44
  8. package/dist/cjs/effect-adapter/index.js +10 -2
  9. package/dist/cjs/effect-source-loader/built-entry.js +4 -5
  10. package/dist/cjs/effect-source-loader/loader.js +2 -1
  11. package/dist/cjs/effect-source-loader/operation-contracts.js +8 -31
  12. package/dist/cjs/effect-source-loader/paths.js +38 -10
  13. package/dist/esm/backend-federation/identity.mjs +18 -23
  14. package/dist/esm/backend-federation-manifest/load.mjs +28 -5
  15. package/dist/esm/backend-federation-manifest/validation.mjs +12 -8
  16. package/dist/esm/cross-project-policy/node.mjs +9 -19
  17. package/dist/esm/effect-adapter/cross-project-policy.mjs +2 -2
  18. package/dist/esm/effect-adapter/entry.mjs +9 -45
  19. package/dist/esm/effect-adapter/index.mjs +10 -2
  20. package/dist/esm/effect-source-loader/built-entry.mjs +5 -6
  21. package/dist/esm/effect-source-loader/loader.mjs +2 -1
  22. package/dist/esm/effect-source-loader/operation-contracts.mjs +10 -33
  23. package/dist/esm/effect-source-loader/paths.mjs +30 -11
  24. package/dist/esm-node/backend-federation/identity.mjs +18 -23
  25. package/dist/esm-node/backend-federation-manifest/load.mjs +28 -5
  26. package/dist/esm-node/backend-federation-manifest/validation.mjs +12 -8
  27. package/dist/esm-node/cross-project-policy/node.mjs +9 -19
  28. package/dist/esm-node/effect-adapter/cross-project-policy.mjs +2 -2
  29. package/dist/esm-node/effect-adapter/entry.mjs +9 -45
  30. package/dist/esm-node/effect-adapter/index.mjs +10 -2
  31. package/dist/esm-node/effect-source-loader/built-entry.mjs +5 -6
  32. package/dist/esm-node/effect-source-loader/loader.mjs +2 -1
  33. package/dist/esm-node/effect-source-loader/operation-contracts.mjs +10 -33
  34. package/dist/esm-node/effect-source-loader/paths.mjs +30 -11
  35. package/dist/types/backend-federation/identity.d.ts +3 -6
  36. package/dist/types/cross-project-policy/node.d.ts +2 -2
  37. package/dist/types/effect-adapter/cross-project-policy.d.ts +2 -1
  38. package/dist/types/effect-source-loader/paths.d.ts +20 -2
  39. package/package.json +10 -10
  40. package/src/backend-federation/identity.ts +39 -47
  41. package/src/backend-federation-manifest/load.ts +75 -27
  42. package/src/backend-federation-manifest/validation.ts +22 -29
  43. package/src/cross-project-policy/node.ts +7 -38
  44. package/src/effect-adapter/cross-project-policy.ts +7 -1
  45. package/src/effect-adapter/entry.ts +10 -88
  46. package/src/effect-adapter/index.ts +7 -1
  47. package/src/effect-source-loader/built-entry.ts +11 -9
  48. package/src/effect-source-loader/loader.ts +10 -5
  49. package/src/effect-source-loader/operation-contracts.ts +7 -41
  50. package/src/effect-source-loader/paths.ts +55 -21
package/README.md CHANGED
@@ -21,6 +21,13 @@ upstream Modern.js project.
21
21
  - `/backend-federation-manifest` exposes manifest contracts and resolution,
22
22
  while
23
23
  `/backend-federation-manifest/node` enables its hardened Node evaluator.
24
+ `loadBackendFederatedEffectApiFromManifest` enforces one shared
25
+ manifest-plus-entry load deadline (default 10s, override via `timeoutMs`,
26
+ 0 to opt out) instead of resetting a fresh timeout per network hop. The
27
+ load settles on that shared deadline/abort even when a caller-pinned
28
+ `loadEntry` plugin, its `init`/`get`, or a custom runtime's `loadRemote`
29
+ never settles; it cannot stop that uncooperative work from still running,
30
+ only stop waiting on it.
24
31
 
25
32
  Effect and its OpenTelemetry integration are exact-cohort optional peers. A
26
33
  Hono-only consumer can import `/hono` without installing Effect.
@@ -28,47 +28,48 @@ var __webpack_require__ = {};
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
+ backendFederationCompatibility: ()=>backendFederationCompatibility,
31
32
  formatBackendFederationIdentityIssues: ()=>formatBackendFederationIdentityIssues,
33
+ validateBackendFederationCompatibility: ()=>validateBackendFederationCompatibility,
32
34
  validateExpectedBackendFederationIdentity: ()=>validateExpectedBackendFederationIdentity
33
35
  });
34
36
  const external_utils_js_namespaceObject = require("./utils.js");
35
- function validateExpectedBackendFederationIdentity(loaded, expected) {
36
- const issues = [];
37
+ function backendFederationCompatibility(loaded) {
37
38
  const contract = (0, external_utils_js_namespaceObject.isRecord)(loaded) ? loaded.backendFederationContract : void 0;
38
39
  const compatibility = (0, external_utils_js_namespaceObject.isRecord)(contract) ? contract.compatibility : void 0;
39
- if (!(0, external_utils_js_namespaceObject.isRecord)(compatibility)) return [
40
+ return (0, external_utils_js_namespaceObject.isRecord)(compatibility) ? compatibility : void 0;
41
+ }
42
+ function validateBackendFederationCompatibility(compatibility, expected) {
43
+ return Object.entries(expected).flatMap(([field, value])=>void 0 === value || 'string' == typeof compatibility[field] && compatibility[field].length > 0 && compatibility[field] === value ? [] : [
44
+ {
45
+ path: `backendFederationContract.compatibility.${field}`,
46
+ message: `expected ${value}, received ${'string' == typeof compatibility[field] ? compatibility[field] : typeof compatibility[field]}`
47
+ }
48
+ ]);
49
+ }
50
+ function validateExpectedBackendFederationIdentity(loaded, expected) {
51
+ const compatibility = backendFederationCompatibility(loaded);
52
+ return compatibility ? validateBackendFederationCompatibility(compatibility, {
53
+ unitId: expected.unitId,
54
+ build: expected.buildMarker
55
+ }) : [
40
56
  {
41
57
  path: 'backendFederationContract.compatibility',
42
58
  message: 'loaded module declares no compatibility metadata; delivery-unit identity cannot be validated'
43
59
  }
44
60
  ];
45
- const unitId = compatibility.unitId;
46
- if ('string' != typeof unitId || 0 === unitId.length) issues.push({
47
- path: 'backendFederationContract.compatibility.unitId',
48
- message: `missing delivery-unit id; expected ${expected.unitId}`
49
- });
50
- else if (unitId !== expected.unitId) issues.push({
51
- path: 'backendFederationContract.compatibility.unitId',
52
- message: `expected ${expected.unitId}, received ${unitId}`
53
- });
54
- const build = compatibility.build;
55
- if ('string' != typeof build || 0 === build.length) issues.push({
56
- path: 'backendFederationContract.compatibility.build',
57
- message: `missing build marker; expected ${expected.buildMarker}`
58
- });
59
- else if (build !== expected.buildMarker) issues.push({
60
- path: 'backendFederationContract.compatibility.build',
61
- message: `expected ${expected.buildMarker}, received ${build}`
62
- });
63
- return issues;
64
61
  }
65
62
  function formatBackendFederationIdentityIssues(issues) {
66
63
  return issues.map((issue)=>`${issue.path}: ${issue.message}`).join('; ');
67
64
  }
65
+ exports.backendFederationCompatibility = __webpack_exports__.backendFederationCompatibility;
68
66
  exports.formatBackendFederationIdentityIssues = __webpack_exports__.formatBackendFederationIdentityIssues;
67
+ exports.validateBackendFederationCompatibility = __webpack_exports__.validateBackendFederationCompatibility;
69
68
  exports.validateExpectedBackendFederationIdentity = __webpack_exports__.validateExpectedBackendFederationIdentity;
70
69
  for(var __rspack_i in __webpack_exports__)if (-1 === [
70
+ "backendFederationCompatibility",
71
71
  "formatBackendFederationIdentityIssues",
72
+ "validateBackendFederationCompatibility",
72
73
  "validateExpectedBackendFederationIdentity"
73
74
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
74
75
  Object.defineProperty(exports, '__esModule', {
@@ -37,6 +37,7 @@ const external_metadata_js_namespaceObject = require("./metadata.js");
37
37
  const external_reference_js_namespaceObject = require("./reference.js");
38
38
  const external_remote_js_namespaceObject = require("./remote.js");
39
39
  const external_validation_js_namespaceObject = require("./validation.js");
40
+ const DEFAULT_SHARED_MANIFEST_LOAD_TIMEOUT_MS = 10000;
40
41
  function createManifestLoadScope(options) {
41
42
  const controller = new AbortController();
42
43
  const policyTimeouts = [
@@ -48,7 +49,8 @@ function createManifestLoadScope(options) {
48
49
  ...policyTimeouts
49
50
  ].filter((timeout)=>void 0 !== timeout);
50
51
  for (const timeout of configuredTimeouts)if (!Number.isSafeInteger(timeout) || timeout < 0) throw new external_errors_js_namespaceObject.BackendFederationManifestAdapterError('manifest_invalid', '[BFF][Effect] Backend federation timeoutMs must be a non-negative safe integer.');
51
- const timeoutMs = options.timeoutMs ?? (policyTimeouts.length > 0 ? Math.min(...policyTimeouts) : 0);
52
+ const positivePolicyTimeouts = policyTimeouts.filter((timeout)=>timeout > 0);
53
+ const timeoutMs = options.timeoutMs ?? (0 === policyTimeouts.length ? DEFAULT_SHARED_MANIFEST_LOAD_TIMEOUT_MS : positivePolicyTimeouts.length > 0 ? Math.min(...positivePolicyTimeouts) : 0);
52
54
  const inputSignals = [
53
55
  options.signal,
54
56
  options.manifestPolicy?.signal,
@@ -102,6 +104,27 @@ function isCallerPinnedStaticRemote(options, remote) {
102
104
  function throwIfManifestLoadAborted(signal) {
103
105
  if (signal.aborted) throw new external_errors_js_namespaceObject.BackendFederationManifestAdapterError('remote_unavailable', '[BFF][Effect] Backend federation load was aborted before remote execution.', signal.reason);
104
106
  }
107
+ function settleOnSharedAbort(promise, signal) {
108
+ if (signal.aborted) {
109
+ promise.catch(()=>{});
110
+ throwIfManifestLoadAborted(signal);
111
+ }
112
+ let onAbort;
113
+ const aborted = new Promise((_resolve, reject)=>{
114
+ onAbort = ()=>{
115
+ reject(new external_errors_js_namespaceObject.BackendFederationManifestAdapterError('remote_unavailable', '[BFF][Effect] Backend federation load was aborted before remote execution.', signal.reason));
116
+ };
117
+ signal.addEventListener('abort', onAbort, {
118
+ once: true
119
+ });
120
+ });
121
+ return Promise.race([
122
+ promise,
123
+ aborted
124
+ ]).finally(()=>{
125
+ if (onAbort) signal.removeEventListener('abort', onAbort);
126
+ });
127
+ }
105
128
  async function loadBackendFederatedEffectApiFromManifest(options) {
106
129
  let manifest;
107
130
  let remote;
@@ -109,7 +132,7 @@ async function loadBackendFederatedEffectApiFromManifest(options) {
109
132
  try {
110
133
  scope = createManifestLoadScope(options);
111
134
  throwIfManifestLoadAborted(scope.signal);
112
- manifest = await (0, external_reference_js_namespaceObject.loadBackendFederationManifest)({
135
+ manifest = await settleOnSharedAbort((0, external_reference_js_namespaceObject.loadBackendFederationManifest)({
113
136
  ...options,
114
137
  manifestPolicy: {
115
138
  ...options.manifestPolicy,
@@ -118,7 +141,7 @@ async function loadBackendFederatedEffectApiFromManifest(options) {
118
141
  },
119
142
  signal: scope.signal,
120
143
  timeoutMs: 0
121
- });
144
+ }), scope.signal);
122
145
  (0, external_validation_js_namespaceObject.validateBackendFederationManifest)(manifest, options.expected);
123
146
  remote = (0, external_remote_js_namespaceObject.resolveBackendFederationRemoteFromManifest)(manifest, options.remote);
124
147
  throwIfManifestLoadAborted(scope.signal);
@@ -132,7 +155,7 @@ async function loadBackendFederatedEffectApiFromManifest(options) {
132
155
  const unitId = (0, external_metadata_js_namespaceObject.stringValue)(deliveryUnit.boundary?.unitId) ?? (0, external_metadata_js_namespaceObject.stringValue)(deliveryUnit.top?.unitId);
133
156
  const buildMarker = (0, external_metadata_js_namespaceObject.stringValue)(deliveryUnit.boundary?.buildMarker);
134
157
  if (!unitId || !buildMarker) throw new external_errors_js_namespaceObject.BackendFederationManifestAdapterError('manifest_invalid', 'Backend federation manifest requires delivery-unit identity.');
135
- const loaded = await (0, load_js_namespaceObject.loadBackendFederatedEffectApi)({
158
+ const loaded = await settleOnSharedAbort((0, load_js_namespaceObject.loadBackendFederatedEffectApi)({
136
159
  hostName: options.hostName,
137
160
  remote,
138
161
  ...options.plugins ? {
@@ -152,7 +175,7 @@ async function loadBackendFederatedEffectApiFromManifest(options) {
152
175
  }
153
176
  }).catch((error)=>{
154
177
  throw new external_errors_js_namespaceObject.BackendFederationManifestAdapterError(scope?.timedOut() === true ? 'timeout' : (0, external_validation_js_namespaceObject.classifyLoadError)(error), `[BFF][Effect] Backend federation remote ${remote?.name ?? 'unknown'} could not load ${remote?.expose ?? index_js_namespaceObject.BACKEND_FEDERATION_EFFECT_EXPOSE}.`, error);
155
- });
178
+ }), scope.signal);
156
179
  (0, external_validation_js_namespaceObject.validateLoadedBackendFederationContract)(loaded, manifest, remote);
157
180
  return loaded;
158
181
  } catch (error) {
@@ -34,6 +34,7 @@ __webpack_require__.d(__webpack_exports__, {
34
34
  });
35
35
  const backend_federation_contracts_namespaceObject = require("@modern-js/backend-federation-contracts");
36
36
  const index_js_namespaceObject = require("../backend-federation/index.js");
37
+ const identity_js_namespaceObject = require("../backend-federation/identity.js");
37
38
  const external_errors_js_namespaceObject = require("./errors.js");
38
39
  const external_metadata_js_namespaceObject = require("./metadata.js");
39
40
  function resolveExpectedBuildMarker(expected) {
@@ -76,19 +77,22 @@ function validateLoadedBackendFederationContract(loaded, manifest, remote) {
76
77
  const loadedContract = loaded.backendFederationContract;
77
78
  const backendFederation = (0, external_metadata_js_namespaceObject.backendFederationMetadata)(manifest);
78
79
  const boundary = (0, external_metadata_js_namespaceObject.versionBoundaryMetadata)(manifest);
79
- const compatibility = (0, external_metadata_js_namespaceObject.recordField)(loadedContract, 'compatibility');
80
+ const compatibility = (0, identity_js_namespaceObject.backendFederationCompatibility)(loaded);
80
81
  (0, external_errors_js_namespaceObject.assertManifestAdapter)(compatibility, 'version_mismatch', `[BFF][Effect] Backend federation expose ${remote.name}/${remote.expose?.replace(/^\.\//u, '')} must declare compatibility metadata.`);
81
82
  (0, external_errors_js_namespaceObject.assertVersionValue)((0, external_metadata_js_namespaceObject.stringValue)(loadedContract?.role), 'microvertical-server', 'expose role');
82
83
  (0, external_errors_js_namespaceObject.assertVersionValue)((0, external_metadata_js_namespaceObject.stringValue)(loadedContract?.name), remote.name, 'expose name');
83
- (0, external_errors_js_namespaceObject.assertVersionValue)((0, external_metadata_js_namespaceObject.stringValue)(compatibility.contractVersion), (0, external_metadata_js_namespaceObject.stringValue)(backendFederation?.contractVersion), 'expose contractVersion');
84
- (0, external_errors_js_namespaceObject.assertVersionValue)((0, external_metadata_js_namespaceObject.stringValue)(compatibility.nodeAdapterVersion), (0, external_metadata_js_namespaceObject.stringValue)(backendFederation?.nodeAdapterVersion), 'expose nodeAdapterVersion');
85
- (0, external_errors_js_namespaceObject.assertVersionValue)((0, external_metadata_js_namespaceObject.stringValue)(compatibility.packageName), (0, external_metadata_js_namespaceObject.stringValue)(boundary?.packageName), 'expose packageName');
86
- (0, external_errors_js_namespaceObject.assertVersionValue)((0, external_metadata_js_namespaceObject.stringValue)(compatibility.build), (0, external_metadata_js_namespaceObject.stringValue)(boundary?.buildVersion), 'expose buildVersion');
87
84
  const deliveryUnit = (0, external_metadata_js_namespaceObject.manifestDeliveryUnit)(backendFederation, boundary);
88
85
  const manifestUnitId = (0, external_metadata_js_namespaceObject.stringValue)(deliveryUnit.boundary?.unitId) ?? (0, external_metadata_js_namespaceObject.stringValue)(deliveryUnit.top?.unitId);
89
86
  const manifestBuildMarker = (0, external_metadata_js_namespaceObject.stringValue)(deliveryUnit.boundary?.buildMarker);
90
- (0, external_errors_js_namespaceObject.assertVersionValue)((0, external_metadata_js_namespaceObject.stringValue)(compatibility.unitId), manifestUnitId, 'deliveryUnit.unitId vs expose compatibility.unitId');
91
- (0, external_errors_js_namespaceObject.assertVersionValue)((0, external_metadata_js_namespaceObject.stringValue)(compatibility.build), manifestBuildMarker, 'deliveryUnit.buildMarker vs expose compatibility.build');
87
+ const issues = (0, identity_js_namespaceObject.validateBackendFederationCompatibility)(compatibility, {
88
+ contractVersion: (0, external_metadata_js_namespaceObject.stringValue)(backendFederation?.contractVersion),
89
+ nodeAdapterVersion: (0, external_metadata_js_namespaceObject.stringValue)(backendFederation?.nodeAdapterVersion),
90
+ packageName: (0, external_metadata_js_namespaceObject.stringValue)(boundary?.packageName),
91
+ unitId: manifestUnitId,
92
+ build: manifestBuildMarker ?? (0, external_metadata_js_namespaceObject.stringValue)(boundary?.buildVersion)
93
+ });
94
+ (0, external_errors_js_namespaceObject.assertVersionValue)((0, external_metadata_js_namespaceObject.stringValue)(compatibility.build), (0, external_metadata_js_namespaceObject.stringValue)(boundary?.buildVersion), 'expose buildVersion');
95
+ (0, external_errors_js_namespaceObject.assertManifestAdapter)(0 === issues.length, 'version_mismatch', `[BFF][Effect] ${(0, identity_js_namespaceObject.formatBackendFederationIdentityIssues)(issues)}.`);
92
96
  }
93
97
  function classifyLoadError(error) {
94
98
  const message = error instanceof Error ? error.message : String(error);
@@ -1,14 +1,5 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.n = (module)=>{
5
- var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
- __webpack_require__.d(getter, {
7
- a: getter
8
- });
9
- return getter;
10
- };
11
- })();
12
3
  (()=>{
13
4
  __webpack_require__.d = (exports1, getters, values)=>{
14
5
  var define = (defs, kind)=>{
@@ -39,33 +30,22 @@ __webpack_require__.r(__webpack_exports__);
39
30
  __webpack_require__.d(__webpack_exports__, {
40
31
  resolveAdapterCrossProjectPolicy: ()=>resolveAdapterCrossProjectPolicy
41
32
  });
42
- const external_node_fs_namespaceObject = require("node:fs");
43
- const external_node_path_namespaceObject = require("node:path");
44
- var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
45
33
  require("@modern-js/server-runtime-extensions/server-config");
46
34
  const node_namespaceObject = require("@modern-js/server-runtime-extensions/bff-policy/node");
47
- const readNearestPackageVersion = (startDir)=>{
48
- if (!startDir) return;
49
- let current = external_node_path_default().resolve(startDir);
50
- for(let depth = 0; depth < 10; depth += 1){
51
- try {
52
- const packageJson = JSON.parse((0, external_node_fs_namespaceObject.readFileSync)(external_node_path_default().join(current, 'package.json'), 'utf8'));
53
- if ('string' == typeof packageJson.version) return packageJson.version;
54
- } catch {}
55
- const parent = external_node_path_default().dirname(current);
56
- if (parent === current) break;
57
- current = parent;
58
- }
59
- };
60
- const resolveAdapterCrossProjectPolicy = (api, handlers)=>{
35
+ const resolveAdapterCrossProjectPolicy = (api, handlers, producer)=>{
61
36
  const bff = api.getServerConfig()?.bff;
62
37
  const { apiDirectory, appDirectory } = api.getServerContext();
63
38
  return (0, node_namespaceObject.resolveCrossProjectPolicy)({
64
39
  crossProjectPolicy: bff?.crossProjectPolicy,
65
40
  handlers,
66
- requestId: bff?.requestId,
67
41
  isCrossProjectServer: bff?.isCrossProjectServer,
68
- operationVersion: (0, node_namespaceObject.deriveOperationVersion)(readNearestPackageVersion(apiDirectory) ?? readNearestPackageVersion(appDirectory))
42
+ ...producer ?? (0, node_namespaceObject.resolveOperationProducer)({
43
+ directories: [
44
+ apiDirectory,
45
+ appDirectory
46
+ ],
47
+ requestId: bff?.requestId || 'default'
48
+ })
69
49
  });
70
50
  };
71
51
  exports.resolveAdapterCrossProjectPolicy = __webpack_exports__.resolveAdapterCrossProjectPolicy;
@@ -34,7 +34,7 @@ const effect_namespaceObject = require("@modern-js/bff-effect/effect");
34
34
  const utils_namespaceObject = require("@modern-js/utils");
35
35
  const httpapi_namespaceObject = require("effect/unstable/httpapi");
36
36
  const index_js_namespaceObject = require("../cross-project-policy/index.js");
37
- function resolveEffectAdapterCrossProjectPolicy(api, prefix, mod) {
37
+ function resolveEffectAdapterCrossProjectPolicy(api, prefix, mod, producer) {
38
38
  const contractSourcesPromise = null === mod ? Promise.resolve([]) : Promise.resolve().then(()=>(0, effect_namespaceObject.extractHttpApiFromModule)(mod, httpapi_namespaceObject.HttpApi.isHttpApi)).then((effectApi)=>{
39
39
  if (null === effectApi) return [];
40
40
  const reflect = (apiValue, handlers)=>{
@@ -50,7 +50,7 @@ function resolveEffectAdapterCrossProjectPolicy(api, prefix, mod) {
50
50
  return [];
51
51
  });
52
52
  return contractSourcesPromise.then((contractSources)=>{
53
- const policy = (0, index_js_namespaceObject.resolveAdapterCrossProjectPolicy)(api, contractSources);
53
+ const policy = (0, index_js_namespaceObject.resolveAdapterCrossProjectPolicy)(api, contractSources, producer);
54
54
  if (policy?.enabled === true && 0 === contractSources.length) utils_namespaceObject.logger.warn('[BFF][Effect] Cross-project policy enabled but no HttpApi endpoints could be reflected; requests fail operation-contract matching unless allowUnknownOperations is enabled.');
55
55
  return policy;
56
56
  });
@@ -43,52 +43,16 @@ const external_node_path_namespaceObject = require("node:path");
43
43
  var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
44
44
  require("@modern-js/server-runtime-extensions/server-config");
45
45
  const utils_namespaceObject = require("@modern-js/utils");
46
- const JS_OR_TS_EXTS = [
47
- '.js',
48
- '.jsx',
49
- '.ts',
50
- '.tsx',
51
- '.mjs',
52
- '.mts',
53
- '.cjs',
54
- '.cts'
55
- ];
56
- function resolveJsOrTsEntry(entryWithoutOrWithExt) {
57
- const extension = external_node_path_default().extname(entryWithoutOrWithExt);
58
- if (JS_OR_TS_EXTS.includes(extension)) return utils_namespaceObject.fs.existsSync(entryWithoutOrWithExt) ? entryWithoutOrWithExt : void 0;
59
- return (0, utils_namespaceObject.findExists)(JS_OR_TS_EXTS.map((ext)=>`${entryWithoutOrWithExt}${ext}`)) || void 0;
60
- }
61
- function builtEntryPath(entryPath) {
62
- return entryPath.replace(/\.(?:[cm]?ts|tsx|jsx)$/u, '.js');
63
- }
64
- function relativeAppPath(appDirectory, entryPath) {
65
- const relativePath = external_node_path_default().relative(appDirectory, entryPath);
66
- return '..' === relativePath || relativePath.startsWith(`..${external_node_path_default().sep}`) ? void 0 : relativePath;
67
- }
68
- function isDependencyPath(relativePath) {
69
- return relativePath?.split(/[\\/]/u).includes('node_modules') ?? false;
70
- }
46
+ const paths_js_namespaceObject = require("../effect-source-loader/paths.js");
71
47
  function resolveEffectAdapterEntryFile(api) {
72
48
  const { appDirectory, apiDirectory, distDirectory } = api.getServerContext();
73
- const appRoot = external_node_path_default().resolve(appDirectory || process.cwd());
74
- const productionRoot = (0, utils_namespaceObject.isProd)() && distDirectory ? external_node_path_default().resolve(distDirectory) : void 0;
75
- const configuredEntry = api.getServerConfig()?.bff?.effect?.entry;
76
- if (configuredEntry) {
77
- const sourceEntry = external_node_path_default().isAbsolute(configuredEntry) ? configuredEntry : external_node_path_default().resolve(appRoot, configuredEntry);
78
- if (productionRoot) {
79
- const relativeEntry = relativeAppPath(appRoot, sourceEntry);
80
- if (void 0 === relativeEntry || isDependencyPath(relativeEntry)) return resolveJsOrTsEntry(sourceEntry);
81
- return relativeEntry ? resolveJsOrTsEntry(builtEntryPath(external_node_path_default().resolve(productionRoot, relativeEntry))) : void 0;
82
- }
83
- return resolveJsOrTsEntry(sourceEntry);
84
- }
85
- const resolvedApiDirectory = external_node_path_default().resolve(appRoot, apiDirectory || utils_namespaceObject.API_DIR);
86
- const productionApiDirectory = productionRoot ? void 0 !== relativeAppPath(productionRoot, resolvedApiDirectory) ? resolvedApiDirectory : (()=>{
87
- const relativeApiDirectory = relativeAppPath(appRoot, resolvedApiDirectory);
88
- if (isDependencyPath(relativeApiDirectory)) return resolvedApiDirectory;
89
- return relativeApiDirectory ? external_node_path_default().resolve(productionRoot, relativeApiDirectory) : void 0;
90
- })() : resolvedApiDirectory;
91
- return productionApiDirectory ? resolveJsOrTsEntry(external_node_path_default().resolve(productionApiDirectory, 'index')) : void 0;
49
+ const appDir = external_node_path_default().resolve(appDirectory || process.cwd());
50
+ return (0, paths_js_namespaceObject.resolveEffectEntry)({
51
+ appDir,
52
+ apiDir: external_node_path_default().resolve(appDir, apiDirectory || utils_namespaceObject.API_DIR),
53
+ effectEntry: api.getServerConfig()?.bff?.effect?.entry,
54
+ distDir: (0, utils_namespaceObject.isProd)() && distDirectory ? external_node_path_default().resolve(distDirectory) : void 0
55
+ }).path;
92
56
  }
93
57
  exports.resolveEffectAdapterEntryFile = __webpack_exports__.resolveEffectAdapterEntryFile;
94
58
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -44,6 +44,7 @@ const external_node_path_namespaceObject = require("node:path");
44
44
  var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
45
45
  require("@modern-js/server-runtime-extensions/server-config");
46
46
  const effect_namespaceObject = require("@modern-js/bff-effect/effect");
47
+ const node_namespaceObject = require("@modern-js/server-runtime-extensions/bff-policy/node");
47
48
  const runtime_lifecycle_namespaceObject = require("@modern-js/server-runtime-extensions/runtime-lifecycle");
48
49
  const utils_namespaceObject = require("@modern-js/utils");
49
50
  const evaluation_js_namespaceObject = require("../cross-project-policy/evaluation.js");
@@ -63,9 +64,9 @@ class EffectAdapter {
63
64
  this.handler = null;
64
65
  return;
65
66
  }
67
+ const { appDirectory } = this.api.getServerContext();
66
68
  let mod;
67
69
  try {
68
- const { appDirectory } = this.api.getServerContext();
69
70
  mod = await ((0, utils_namespaceObject.isProd)() ? (0, loader_js_namespaceObject.loadEffectBuiltModule)(entryFile) : (0, loader_js_namespaceObject.loadEffectSourceModule)({
70
71
  resourcePath: entryFile,
71
72
  appDir: appDirectory || external_node_path_default().dirname(entryFile)
@@ -74,9 +75,16 @@ class EffectAdapter {
74
75
  utils_namespaceObject.logger.error(`[BFF][Effect] Failed to load Effect entry: ${entryFile}\n${String(error)}`);
75
76
  throw error;
76
77
  }
78
+ const producer = (0, node_namespaceObject.resolveOperationProducer)({
79
+ directories: [
80
+ external_node_path_default().dirname(entryFile),
81
+ appDirectory
82
+ ],
83
+ requestId: this.api.getServerConfig()?.bff?.requestId
84
+ });
77
85
  const crossProjectPolicies = new Map(await Promise.all(this.prefixes.map(async (prefix)=>[
78
86
  prefix,
79
- await (0, external_cross_project_policy_js_namespaceObject.resolveEffectAdapterCrossProjectPolicy)(this.api, prefix, mod)
87
+ await (0, external_cross_project_policy_js_namespaceObject.resolveEffectAdapterCrossProjectPolicy)(this.api, prefix, mod, producer)
80
88
  ])));
81
89
  const effectConfig = this.api.getServerConfig()?.bff?.effect;
82
90
  const loaded = await (0, effect_namespaceObject.resolveEffectBffModuleHandler)(mod, {
@@ -34,12 +34,11 @@ __webpack_require__.d(__webpack_exports__, {
34
34
  });
35
35
  const utils_namespaceObject = require("@modern-js/utils");
36
36
  const external_paths_js_namespaceObject = require("./paths.js");
37
- const BUILT_ENTRY_EXT = /\.(?:[cm]?ts|tsx|jsx)$/u;
38
37
  function resolveBuiltEffectEntry(appDirectory, distDirectory, sourceEntry) {
39
38
  if (void 0 === sourceEntry || 0 === sourceEntry.length) return;
40
- const relativeEntry = utils_namespaceObject.upath.relative(appDirectory, sourceEntry);
41
- if ('..' === relativeEntry || relativeEntry.startsWith(`..${utils_namespaceObject.upath.sep}`)) throw new Error(`Effect BFF entry must be inside the application directory: ${sourceEntry}`);
42
- const builtEntry = utils_namespaceObject.upath.resolve(distDirectory, relativeEntry).replace(BUILT_ENTRY_EXT, '.js');
39
+ const relativeEntry = (0, external_paths_js_namespaceObject.relativeEffectAppPath)(appDirectory, sourceEntry);
40
+ if (void 0 === relativeEntry) throw new Error(`Effect BFF entry must be inside the application directory: ${sourceEntry}`);
41
+ const builtEntry = (0, external_paths_js_namespaceObject.emittedEffectEntry)(utils_namespaceObject.upath.resolve(distDirectory, relativeEntry));
43
42
  return utils_namespaceObject.fs.existsSync(builtEntry) ? builtEntry : void 0;
44
43
  }
45
44
  async function bundleBuiltEffectEntryForNode(options) {
@@ -65,7 +64,7 @@ function resolveEffectEntryPaths(options) {
65
64
  apiDir,
66
65
  effectEntry
67
66
  });
68
- const relativeEffectEntry = void 0 !== sourceEffectEntry && sourceEffectEntry.length > 0 ? utils_namespaceObject.upath.relative(appDir, sourceEffectEntry).replace(BUILT_ENTRY_EXT, '.js') : '';
67
+ const relativeEffectEntry = void 0 !== sourceEffectEntry && sourceEffectEntry.length > 0 ? (0, external_paths_js_namespaceObject.emittedEffectEntry)(utils_namespaceObject.upath.relative(appDir, sourceEffectEntry)) : '';
69
68
  return {
70
69
  sourceEffectEntry,
71
70
  relativeEffectEntry
@@ -176,7 +176,8 @@ function externalizeInstalledDependencies(options) {
176
176
  path: args.path
177
177
  };
178
178
  const realPath = await external_node_fs_default().promises.realpath(resolution.path).catch(()=>resolution.path);
179
- if (realPath.includes(`${external_node_path_default().sep}node_modules${external_node_path_default().sep}`)) {
179
+ const loader = SOURCE_LOADERS.get(external_node_path_default().extname(realPath).toLowerCase());
180
+ if (realPath.includes(`${external_node_path_default().sep}node_modules${external_node_path_default().sep}`) && 'ts' !== loader && 'tsx' !== loader && 'jsx' !== loader) {
180
181
  const runtimeResolution = await buildApi.resolve(args.path, {
181
182
  importer: '',
182
183
  kind: args.kind,
@@ -34,44 +34,21 @@ const effect_namespaceObject = require("@modern-js/bff-effect/effect");
34
34
  const node_namespaceObject = require("@modern-js/server-runtime-extensions/bff-policy/node");
35
35
  const utils_namespaceObject = require("@modern-js/utils");
36
36
  const external_http_api_runtime_js_namespaceObject = require("./http-api-runtime.js");
37
- function getPackageInfo(resourcePath, appDir, onDependency) {
38
- for (const startDir of [
39
- utils_namespaceObject.upath.dirname(resourcePath),
40
- appDir
41
- ]){
42
- let current = utils_namespaceObject.upath.resolve(startDir);
43
- for(let depth = 0; depth < 32; depth += 1){
44
- const packageJsonPath = utils_namespaceObject.upath.join(current, 'package.json');
45
- if (utils_namespaceObject.fs.existsSync(packageJsonPath)) {
46
- onDependency?.(packageJsonPath);
47
- try {
48
- const packageJson = utils_namespaceObject.fs.readJSONSync(packageJsonPath);
49
- return {
50
- name: packageJson.name,
51
- version: packageJson.version
52
- };
53
- } catch {
54
- return {};
55
- }
56
- }
57
- const parent = utils_namespaceObject.upath.dirname(current);
58
- if (parent === current) break;
59
- current = parent;
60
- }
61
- }
62
- return {};
63
- }
64
37
  async function resolveEffectOperationContracts(options) {
65
38
  const api = await (0, external_http_api_runtime_js_namespaceObject.loadEffectApi)(options);
66
39
  if (null === api) return null;
67
40
  const runtime = await (0, external_http_api_runtime_js_namespaceObject.getHttpApiRuntime)();
68
41
  const endpoints = (0, effect_namespaceObject.collectEffectEndpoints)(runtime.reflect, api, options.prefix);
69
- const packageInfo = getPackageInfo(options.resourcePath, options.appDir, options.onDependency);
70
- const requestId = options.requestId?.trim() || packageInfo.name || 'default';
71
42
  return (0, node_namespaceObject.buildOperationContractMap)({
72
43
  handlers: (0, effect_namespaceObject.toOperationContractSources)(endpoints),
73
- requestId,
74
- operationVersion: (0, node_namespaceObject.deriveOperationVersion)(packageInfo.version)
44
+ ...(0, node_namespaceObject.resolveOperationProducer)({
45
+ directories: [
46
+ utils_namespaceObject.upath.dirname(options.resourcePath),
47
+ options.appDir
48
+ ],
49
+ requestId: options.requestId,
50
+ onDependency: options.onDependency
51
+ })
75
52
  });
76
53
  }
77
54
  exports.resolveEffectOperationContracts = __webpack_exports__.resolveEffectOperationContracts;
@@ -28,6 +28,9 @@ var __webpack_require__ = {};
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
+ emittedEffectEntry: ()=>emittedEffectEntry,
32
+ relativeEffectAppPath: ()=>relativeEffectAppPath,
33
+ resolveEffectEntry: ()=>resolveEffectEntry,
31
34
  resolveEffectEntryFile: ()=>resolveEffectEntryFile
32
35
  });
33
36
  const utils_namespaceObject = require("@modern-js/utils");
@@ -41,20 +44,45 @@ const JS_OR_TS_EXTS = [
41
44
  '.cjs',
42
45
  '.cts'
43
46
  ];
44
- function resolveEffectEntryFile(options) {
45
- const { appDir, apiDir, effectEntry } = options;
46
- const resolveEntry = (entryWithoutExt)=>{
47
- if ('' !== utils_namespaceObject.upath.extname(entryWithoutExt)) return utils_namespaceObject.fs.existsSync(entryWithoutExt) ? entryWithoutExt : void 0;
48
- return (0, utils_namespaceObject.findExists)(JS_OR_TS_EXTS.map((ext)=>`${entryWithoutExt}${ext}`)) || void 0;
47
+ const emittedEffectEntry = (entry)=>entry.replace(/\.(?:[cm]?ts|tsx|jsx)$/u, '.js');
48
+ function relativeEffectAppPath(appDir, entry) {
49
+ const relative = utils_namespaceObject.upath.relative(appDir, entry);
50
+ return '..' === relative || relative.startsWith('../') || relative.split('/').includes('node_modules') ? void 0 : relative;
51
+ }
52
+ function existingEntry(entry) {
53
+ return utils_namespaceObject.upath.extname(entry) ? utils_namespaceObject.fs.existsSync(entry) ? entry : void 0 : (0, utils_namespaceObject.findExists)(JS_OR_TS_EXTS.map((ext)=>`${entry}${ext}`)) || void 0;
54
+ }
55
+ function resolveEffectEntry(options) {
56
+ const { appDir, apiDir, effectEntry, distDir } = options;
57
+ const entry = utils_namespaceObject.upath.resolve(appDir, effectEntry || utils_namespaceObject.upath.join(apiDir, 'index'));
58
+ if (distDir && void 0 !== relativeEffectAppPath(distDir, entry)) return {
59
+ kind: 'built-output',
60
+ path: existingEntry(emittedEffectEntry(entry))
61
+ };
62
+ const relative = relativeEffectAppPath(appDir, entry);
63
+ if (void 0 === relative) return {
64
+ kind: 'external-sdk',
65
+ path: existingEntry(entry)
49
66
  };
50
- if (void 0 !== effectEntry && '' !== effectEntry) {
51
- const entryWithoutExt = utils_namespaceObject.upath.isAbsolute(effectEntry) ? effectEntry : utils_namespaceObject.upath.resolve(appDir, effectEntry);
52
- return resolveEntry(entryWithoutExt);
53
- }
54
- return resolveEntry(utils_namespaceObject.upath.resolve(apiDir, 'index'));
67
+ return distDir ? {
68
+ kind: 'built-output',
69
+ path: existingEntry(emittedEffectEntry(utils_namespaceObject.upath.resolve(distDir, relative)))
70
+ } : {
71
+ kind: 'app-source',
72
+ path: existingEntry(entry)
73
+ };
74
+ }
75
+ function resolveEffectEntryFile(options) {
76
+ return resolveEffectEntry(options).path;
55
77
  }
78
+ exports.emittedEffectEntry = __webpack_exports__.emittedEffectEntry;
79
+ exports.relativeEffectAppPath = __webpack_exports__.relativeEffectAppPath;
80
+ exports.resolveEffectEntry = __webpack_exports__.resolveEffectEntry;
56
81
  exports.resolveEffectEntryFile = __webpack_exports__.resolveEffectEntryFile;
57
82
  for(var __rspack_i in __webpack_exports__)if (-1 === [
83
+ "emittedEffectEntry",
84
+ "relativeEffectAppPath",
85
+ "resolveEffectEntry",
58
86
  "resolveEffectEntryFile"
59
87
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
60
88
  Object.defineProperty(exports, '__esModule', {
@@ -1,35 +1,30 @@
1
1
  import { isRecord } from "./utils.mjs";
2
- function validateExpectedBackendFederationIdentity(loaded, expected) {
3
- const issues = [];
2
+ function backendFederationCompatibility(loaded) {
4
3
  const contract = isRecord(loaded) ? loaded.backendFederationContract : void 0;
5
4
  const compatibility = isRecord(contract) ? contract.compatibility : void 0;
6
- if (!isRecord(compatibility)) return [
5
+ return isRecord(compatibility) ? compatibility : void 0;
6
+ }
7
+ function validateBackendFederationCompatibility(compatibility, expected) {
8
+ return Object.entries(expected).flatMap(([field, value])=>void 0 === value || 'string' == typeof compatibility[field] && compatibility[field].length > 0 && compatibility[field] === value ? [] : [
9
+ {
10
+ path: `backendFederationContract.compatibility.${field}`,
11
+ message: `expected ${value}, received ${'string' == typeof compatibility[field] ? compatibility[field] : typeof compatibility[field]}`
12
+ }
13
+ ]);
14
+ }
15
+ function validateExpectedBackendFederationIdentity(loaded, expected) {
16
+ const compatibility = backendFederationCompatibility(loaded);
17
+ return compatibility ? validateBackendFederationCompatibility(compatibility, {
18
+ unitId: expected.unitId,
19
+ build: expected.buildMarker
20
+ }) : [
7
21
  {
8
22
  path: 'backendFederationContract.compatibility',
9
23
  message: 'loaded module declares no compatibility metadata; delivery-unit identity cannot be validated'
10
24
  }
11
25
  ];
12
- const unitId = compatibility.unitId;
13
- if ('string' != typeof unitId || 0 === unitId.length) issues.push({
14
- path: 'backendFederationContract.compatibility.unitId',
15
- message: `missing delivery-unit id; expected ${expected.unitId}`
16
- });
17
- else if (unitId !== expected.unitId) issues.push({
18
- path: 'backendFederationContract.compatibility.unitId',
19
- message: `expected ${expected.unitId}, received ${unitId}`
20
- });
21
- const build = compatibility.build;
22
- if ('string' != typeof build || 0 === build.length) issues.push({
23
- path: 'backendFederationContract.compatibility.build',
24
- message: `missing build marker; expected ${expected.buildMarker}`
25
- });
26
- else if (build !== expected.buildMarker) issues.push({
27
- path: 'backendFederationContract.compatibility.build',
28
- message: `expected ${expected.buildMarker}, received ${build}`
29
- });
30
- return issues;
31
26
  }
32
27
  function formatBackendFederationIdentityIssues(issues) {
33
28
  return issues.map((issue)=>`${issue.path}: ${issue.message}`).join('; ');
34
29
  }
35
- export { formatBackendFederationIdentityIssues, validateExpectedBackendFederationIdentity };
30
+ export { backendFederationCompatibility, formatBackendFederationIdentityIssues, validateBackendFederationCompatibility, validateExpectedBackendFederationIdentity };