@bleedingdev/modern-js-server-runtime-extensions 3.9.0-ultramodern.11 → 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 (40) hide show
  1. package/dist/cjs/backend-federation-security/index.js +73 -152
  2. package/dist/cjs/bff-policy/index.js +7 -0
  3. package/dist/cjs/bff-policy/node.js +20 -4
  4. package/dist/cjs/bff-policy/operationContracts.js +150 -135
  5. package/dist/cjs/bff-policy/operationIdentity.js +81 -0
  6. package/dist/cjs/bff-policy/producer.js +79 -0
  7. package/dist/cjs/localisedLoaderPlugin.js +22 -1
  8. package/dist/esm/backend-federation-security/index.mjs +73 -152
  9. package/dist/esm/bff-policy/index.mjs +1 -0
  10. package/dist/esm/bff-policy/operationIdentity.mjs +30 -0
  11. package/dist/esm/bff-policy/producer.mjs +31 -0
  12. package/dist/esm/localisedLoaderPlugin.mjs +22 -1
  13. package/dist/esm-node/backend-federation-security/index.mjs +73 -152
  14. package/dist/esm-node/bff-policy/index.mjs +1 -0
  15. package/dist/esm-node/bff-policy/node.mjs +1 -0
  16. package/dist/esm-node/bff-policy/operationContracts.mjs +5 -27
  17. package/dist/esm-node/bff-policy/operationIdentity.mjs +31 -0
  18. package/dist/esm-node/bff-policy/producer.mjs +32 -0
  19. package/dist/esm-node/localisedLoaderPlugin.mjs +22 -1
  20. package/dist/types/bff-policy/index.d.ts +1 -0
  21. package/dist/types/bff-policy/node.d.ts +1 -0
  22. package/dist/types/bff-policy/operationContracts.d.ts +2 -41
  23. package/dist/types/bff-policy/operationIdentity.d.ts +34 -0
  24. package/dist/types/bff-policy/producer.d.ts +10 -0
  25. package/dist/types-esm/bff-policy/index.d.mts +1 -0
  26. package/dist/types-esm/bff-policy/node.d.mts +1 -0
  27. package/dist/types-esm/bff-policy/operationContracts.d.mts +2 -41
  28. package/dist/types-esm/bff-policy/operationIdentity.d.mts +34 -0
  29. package/dist/types-esm/bff-policy/producer.d.mts +10 -0
  30. package/package.json +10 -10
  31. package/src/backend-federation-security/index.ts +151 -318
  32. package/src/bff-policy/index.ts +1 -0
  33. package/src/bff-policy/node.ts +1 -0
  34. package/src/bff-policy/operationContracts.ts +13 -86
  35. package/src/bff-policy/operationIdentity.ts +90 -0
  36. package/src/bff-policy/producer.ts +40 -0
  37. package/src/localisedLoaderPlugin.ts +31 -0
  38. package/tests/backendFederationSecurity.test.ts +63 -0
  39. package/tests/bff-policy/operationContracts.test.ts +57 -0
  40. package/tests/localisedLoader.test.ts +36 -1
@@ -1,5 +1,37 @@
1
1
  "use strict";
2
- var __webpack_require__ = {};
2
+ var __webpack_modules__ = {
3
+ "./operationIdentity" (module) {
4
+ module.exports = require("./operationIdentity.js");
5
+ },
6
+ crypto (module) {
7
+ module.exports = require("crypto");
8
+ },
9
+ "node:module" (module) {
10
+ module.exports = require("node:module");
11
+ },
12
+ "reflect-metadata" (module) {
13
+ module.exports = require("reflect-metadata");
14
+ }
15
+ };
16
+ var __webpack_module_cache__ = {};
17
+ function __webpack_require__(moduleId) {
18
+ var cachedModule = __webpack_module_cache__[moduleId];
19
+ if (void 0 !== cachedModule) return cachedModule.exports;
20
+ var module = __webpack_module_cache__[moduleId] = {
21
+ exports: {}
22
+ };
23
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
24
+ return module.exports;
25
+ }
26
+ (()=>{
27
+ __webpack_require__.n = (module)=>{
28
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
29
+ __webpack_require__.d(getter, {
30
+ a: getter
31
+ });
32
+ return getter;
33
+ };
34
+ })();
3
35
  (()=>{
4
36
  __webpack_require__.d = (exports1, getters, values)=>{
5
37
  var define = (defs, kind)=>{
@@ -26,155 +58,138 @@ var __webpack_require__ = {};
26
58
  };
27
59
  })();
28
60
  var __webpack_exports__ = {};
29
- __webpack_require__.r(__webpack_exports__);
30
- __webpack_require__.d(__webpack_exports__, {
31
- DEFAULT_OPERATION_VERSION: ()=>DEFAULT_OPERATION_VERSION,
32
- buildOperationContractMap: ()=>buildOperationContractMap,
33
- createOperationContractHash: ()=>createOperationContractHash,
34
- createOperationEntries: ()=>createOperationEntries,
35
- createOperationSchemaHash: ()=>createOperationSchemaHash,
36
- deriveOperationVersion: ()=>deriveOperationVersion,
37
- serializeOperationSchemas: ()=>serializeOperationSchemas
38
- });
39
- const external_node_module_namespaceObject = require("node:module");
40
- const external_crypto_namespaceObject = require("crypto");
41
- require("reflect-metadata");
42
- const DEFAULT_OPERATION_VERSION = 1;
43
- const deriveOperationVersion = (packageVersion)=>{
44
- if ('string' != typeof packageVersion) return DEFAULT_OPERATION_VERSION;
45
- const match = packageVersion.trim().match(/^v?(\d+)\./);
46
- if (!match) return DEFAULT_OPERATION_VERSION;
47
- const major = Number.parseInt(match[1], 10);
48
- return Number.isInteger(major) && major >= 0 ? major : DEFAULT_OPERATION_VERSION;
49
- };
50
- const stableStringify = (value)=>{
51
- if (Array.isArray(value)) return `[${value.map((item)=>stableStringify(item)).join(',')}]`;
52
- if (value && 'object' == typeof value) {
53
- const entries = Object.entries(value).filter(([, entryValue])=>void 0 !== entryValue).sort(([a], [b])=>a.localeCompare(b)).map(([key, entryValue])=>`${JSON.stringify(key)}:${stableStringify(entryValue)}`);
54
- return `{${entries.join(',')}}`;
55
- }
56
- return JSON.stringify(value) ?? 'null';
57
- };
58
- const sha256 = (text)=>(0, external_crypto_namespaceObject.createHash)('sha256').update(text).digest('hex');
59
- let cachedZodToJSONSchema;
60
- const ZOD_SPECIFIER = "zod";
61
- const resolveZodToJSONSchema = ()=>{
62
- if (void 0 !== cachedZodToJSONSchema) return cachedZodToJSONSchema;
63
- try {
64
- const load = (0, external_node_module_namespaceObject.createRequire)(__filename);
65
- const zod = load(ZOD_SPECIFIER);
66
- const candidate = zod?.toJSONSchema ?? zod?.z?.toJSONSchema;
67
- cachedZodToJSONSchema = 'function' == typeof candidate ? candidate : null;
68
- } catch {
69
- cachedZodToJSONSchema = null;
70
- }
71
- return cachedZodToJSONSchema;
72
- };
73
- const INPUT_SCHEMA_METADATA_KEYS = [
74
- 'DATA',
75
- 'QUERY',
76
- 'PARAMS',
77
- 'HEADERS',
78
- 'Files'
79
- ];
80
- const serializeSchema = (schema)=>{
81
- const toJSONSchema = resolveZodToJSONSchema();
82
- if (toJSONSchema) try {
83
- return toJSONSchema(schema, {
84
- io: 'input',
85
- unrepresentable: 'any'
86
- });
87
- } catch {}
88
- return {
89
- __unserializableSchema: true
90
- };
91
- };
92
- const serializeOperationSchemas = (handler)=>{
93
- if ('function' != typeof handler) return;
94
- const serialized = {};
95
- for (const metadataKey of INPUT_SCHEMA_METADATA_KEYS){
96
- let schema;
61
+ (()=>{
62
+ __webpack_require__.r(__webpack_exports__);
63
+ var node_module__rspack_import_0 = __webpack_require__("node:module");
64
+ var crypto__rspack_import_1 = __webpack_require__("crypto");
65
+ __webpack_require__("reflect-metadata");
66
+ var _operationIdentity__rspack_import_3 = __webpack_require__("./operationIdentity");
67
+ var __rspack_reexport = {};
68
+ for(const __rspack_import_key in _operationIdentity__rspack_import_3)if ([
69
+ "createOperationEntries",
70
+ "buildOperationContractMap",
71
+ "createOperationSchemaHash",
72
+ "default",
73
+ "serializeOperationSchemas",
74
+ "createOperationContractHash"
75
+ ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_operationIdentity__rspack_import_3[__rspack_import_key];
76
+ __webpack_require__.d(__webpack_exports__, __rspack_reexport);
77
+ const sha256 = (text)=>(0, crypto__rspack_import_1.createHash)('sha256').update(text).digest('hex');
78
+ let cachedZodToJSONSchema;
79
+ const ZOD_SPECIFIER = "zod";
80
+ const resolveZodToJSONSchema = ()=>{
81
+ if (void 0 !== cachedZodToJSONSchema) return cachedZodToJSONSchema;
97
82
  try {
98
- schema = Reflect.getMetadata(metadataKey, handler);
83
+ const load = (0, node_module__rspack_import_0.createRequire)(__filename);
84
+ const zod = load(ZOD_SPECIFIER);
85
+ const candidate = zod?.toJSONSchema ?? zod?.z?.toJSONSchema;
86
+ cachedZodToJSONSchema = 'function' == typeof candidate ? candidate : null;
99
87
  } catch {
100
- schema = void 0;
88
+ cachedZodToJSONSchema = null;
101
89
  }
102
- if (null != schema) serialized[metadataKey] = serializeSchema(schema);
103
- }
104
- return Object.keys(serialized).length > 0 ? serialized : void 0;
105
- };
106
- const createOperationContractHash = (operation, requestId)=>sha256(stableStringify({
107
- httpMethod: String(operation.httpMethod || '').toUpperCase(),
108
- name: operation.name,
109
- requestId,
110
- routePath: operation.routePath,
111
- ...operation.schemas ? {
112
- schemas: operation.schemas
113
- } : {}
114
- }));
115
- const createOperationEntries = (handlers)=>handlers.map((item)=>({
116
- name: item.name,
117
- httpMethod: String(item.httpMethod || '').toUpperCase(),
118
- routePath: item.routePath
119
- })).sort((a, b)=>{
120
- const keyA = `${a.routePath}:${a.httpMethod}:${a.name}`;
121
- const keyB = `${b.routePath}:${b.httpMethod}:${b.name}`;
122
- return keyA.localeCompare(keyB);
123
- });
124
- const createOperationSchemaHash = (operationEntries, requestId)=>sha256(stableStringify({
125
- operations: [
126
- ...operationEntries
127
- ].map((item)=>({
128
- hash: item.schemaHash ?? createOperationContractHash({
129
- name: item.name,
130
- httpMethod: item.httpMethod,
131
- routePath: item.routePath
132
- }, requestId)
133
- })).sort((a, b)=>a.hash.localeCompare(b.hash)),
134
- requestId
135
- }));
136
- const buildOperationContractMap = ({ handlers, requestId, operationVersion })=>{
137
- const normalizedRequestId = 'string' == typeof requestId && requestId.trim().length > 0 ? requestId.trim() : 'default';
138
- const normalizedOperationVersion = 'number' == typeof operationVersion && Number.isInteger(operationVersion) ? operationVersion : DEFAULT_OPERATION_VERSION;
139
- const contracts = {};
140
- handlers.forEach((item)=>{
141
- const httpMethod = String(item.httpMethod || '').toUpperCase();
142
- const schemaHash = createOperationContractHash({
143
- name: item.name,
144
- httpMethod,
145
- routePath: item.routePath,
146
- schemas: serializeOperationSchemas(item.handler)
147
- }, normalizedRequestId);
148
- const operationId = `${normalizedRequestId}:${item.name}`;
149
- const contract = {
150
- requestId: normalizedRequestId,
151
- operationVersion: normalizedOperationVersion,
152
- schemaHash,
153
- method: httpMethod,
154
- routePath: item.routePath,
155
- operationId,
156
- handlerName: item.name,
157
- filename: item.filename
90
+ return cachedZodToJSONSchema;
91
+ };
92
+ const INPUT_SCHEMA_METADATA_KEYS = [
93
+ 'DATA',
94
+ 'QUERY',
95
+ 'PARAMS',
96
+ 'HEADERS',
97
+ 'Files'
98
+ ];
99
+ const serializeSchema = (schema)=>{
100
+ const toJSONSchema = resolveZodToJSONSchema();
101
+ if (toJSONSchema) try {
102
+ return toJSONSchema(schema, {
103
+ io: 'input',
104
+ unrepresentable: 'any'
105
+ });
106
+ } catch {}
107
+ return {
108
+ __unserializableSchema: true
158
109
  };
159
- contracts[`${httpMethod}:${item.routePath}`] = contract;
160
- contracts[`operation:${operationId}`] = contract;
110
+ };
111
+ const serializeOperationSchemas = (handler)=>{
112
+ if ('function' != typeof handler) return;
113
+ const serialized = {};
114
+ for (const metadataKey of INPUT_SCHEMA_METADATA_KEYS){
115
+ let schema;
116
+ try {
117
+ schema = Reflect.getMetadata(metadataKey, handler);
118
+ } catch {
119
+ schema = void 0;
120
+ }
121
+ if (null != schema) serialized[metadataKey] = serializeSchema(schema);
122
+ }
123
+ return Object.keys(serialized).length > 0 ? serialized : void 0;
124
+ };
125
+ const createOperationContractHash = (operation, requestId)=>sha256((0, _operationIdentity__rspack_import_3.serializeOperationContract)(operation, requestId));
126
+ const createOperationEntries = (handlers)=>handlers.map((item)=>({
127
+ name: item.name,
128
+ httpMethod: String(item.httpMethod || '').toUpperCase(),
129
+ routePath: item.routePath
130
+ })).sort((a, b)=>{
131
+ const keyA = `${a.routePath}:${a.httpMethod}:${a.name}`;
132
+ const keyB = `${b.routePath}:${b.httpMethod}:${b.name}`;
133
+ return keyA.localeCompare(keyB);
134
+ });
135
+ const createOperationSchemaHash = (operationEntries, requestId)=>sha256((0, _operationIdentity__rspack_import_3.stableOperationStringify)({
136
+ operations: [
137
+ ...operationEntries
138
+ ].map((item)=>({
139
+ hash: item.schemaHash ?? createOperationContractHash({
140
+ name: item.name,
141
+ httpMethod: item.httpMethod,
142
+ routePath: item.routePath
143
+ }, requestId)
144
+ })).sort((a, b)=>a.hash.localeCompare(b.hash)),
145
+ requestId
146
+ }));
147
+ const buildOperationContractMap = ({ handlers, requestId, operationVersion })=>{
148
+ const normalizedRequestId = 'string' == typeof requestId && requestId.trim().length > 0 ? requestId.trim() : 'default';
149
+ const normalizedOperationVersion = 'number' == typeof operationVersion && Number.isInteger(operationVersion) ? operationVersion : _operationIdentity__rspack_import_3.DEFAULT_OPERATION_VERSION;
150
+ const contracts = {};
151
+ handlers.forEach((item)=>{
152
+ const httpMethod = String(item.httpMethod || '').toUpperCase();
153
+ const schemaHash = createOperationContractHash({
154
+ name: item.name,
155
+ httpMethod,
156
+ routePath: item.routePath,
157
+ schemas: serializeOperationSchemas(item.handler)
158
+ }, normalizedRequestId);
159
+ const operationId = `${normalizedRequestId}:${item.name}`;
160
+ const contract = {
161
+ requestId: normalizedRequestId,
162
+ operationVersion: normalizedOperationVersion,
163
+ schemaHash,
164
+ method: httpMethod,
165
+ routePath: item.routePath,
166
+ operationId,
167
+ handlerName: item.name,
168
+ filename: item.filename
169
+ };
170
+ contracts[`${httpMethod}:${item.routePath}`] = contract;
171
+ contracts[`operation:${operationId}`] = contract;
172
+ });
173
+ return contracts;
174
+ };
175
+ __webpack_require__.d(__webpack_exports__, {}, {
176
+ buildOperationContractMap: buildOperationContractMap,
177
+ createOperationContractHash: createOperationContractHash,
178
+ createOperationEntries: createOperationEntries,
179
+ createOperationSchemaHash: createOperationSchemaHash,
180
+ serializeOperationSchemas: serializeOperationSchemas
161
181
  });
162
- return contracts;
163
- };
164
- exports.DEFAULT_OPERATION_VERSION = __webpack_exports__.DEFAULT_OPERATION_VERSION;
182
+ })();
165
183
  exports.buildOperationContractMap = __webpack_exports__.buildOperationContractMap;
166
184
  exports.createOperationContractHash = __webpack_exports__.createOperationContractHash;
167
185
  exports.createOperationEntries = __webpack_exports__.createOperationEntries;
168
186
  exports.createOperationSchemaHash = __webpack_exports__.createOperationSchemaHash;
169
- exports.deriveOperationVersion = __webpack_exports__.deriveOperationVersion;
170
187
  exports.serializeOperationSchemas = __webpack_exports__.serializeOperationSchemas;
171
188
  for(var __rspack_i in __webpack_exports__)if (-1 === [
172
- "DEFAULT_OPERATION_VERSION",
173
189
  "buildOperationContractMap",
174
190
  "createOperationContractHash",
175
191
  "createOperationEntries",
176
192
  "createOperationSchemaHash",
177
- "deriveOperationVersion",
178
193
  "serializeOperationSchemas"
179
194
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
180
195
  Object.defineProperty(exports, '__esModule', {
@@ -0,0 +1,81 @@
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
+ const DEFAULT_OPERATION_VERSION = 1;
31
+ const deriveOperationVersion = (packageVersion)=>{
32
+ if ('string' != typeof packageVersion) return DEFAULT_OPERATION_VERSION;
33
+ const match = packageVersion.trim().match(/^v?(\d+)\./);
34
+ if (!match) return DEFAULT_OPERATION_VERSION;
35
+ const major = Number.parseInt(match[1], 10);
36
+ return Number.isInteger(major) && major >= 0 ? major : DEFAULT_OPERATION_VERSION;
37
+ };
38
+ const stableOperationStringify = (value)=>{
39
+ if (Array.isArray(value)) return `[${value.map((item)=>stableOperationStringify(item)).join(',')}]`;
40
+ if (value && 'object' == typeof value) {
41
+ const entries = Object.entries(value).filter(([, entryValue])=>void 0 !== entryValue).sort(([a], [b])=>a.localeCompare(b)).map(([key, entryValue])=>`${JSON.stringify(key)}:${stableOperationStringify(entryValue)}`);
42
+ return `{${entries.join(',')}}`;
43
+ }
44
+ return JSON.stringify(value) ?? 'null';
45
+ };
46
+ const serializeOperationContract = (operation, requestId)=>stableOperationStringify({
47
+ httpMethod: String(operation.httpMethod || '').toUpperCase(),
48
+ name: operation.name,
49
+ requestId,
50
+ routePath: operation.routePath,
51
+ ...operation.schemas ? {
52
+ schemas: operation.schemas
53
+ } : {}
54
+ });
55
+ async function digestOperationContract(operation, requestId) {
56
+ const digest = await globalThis.crypto.subtle.digest('SHA-256', new TextEncoder().encode(serializeOperationContract(operation, requestId)));
57
+ return Array.from(new Uint8Array(digest), (value)=>value.toString(16).padStart(2, '0')).join('');
58
+ }
59
+ __webpack_require__.d(__webpack_exports__, {
60
+ digestOperationContract: ()=>digestOperationContract
61
+ }, {
62
+ DEFAULT_OPERATION_VERSION: DEFAULT_OPERATION_VERSION,
63
+ deriveOperationVersion: deriveOperationVersion,
64
+ serializeOperationContract: serializeOperationContract,
65
+ stableOperationStringify: stableOperationStringify
66
+ });
67
+ exports.DEFAULT_OPERATION_VERSION = __webpack_exports__.DEFAULT_OPERATION_VERSION;
68
+ exports.deriveOperationVersion = __webpack_exports__.deriveOperationVersion;
69
+ exports.digestOperationContract = __webpack_exports__.digestOperationContract;
70
+ exports.serializeOperationContract = __webpack_exports__.serializeOperationContract;
71
+ exports.stableOperationStringify = __webpack_exports__.stableOperationStringify;
72
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
73
+ "DEFAULT_OPERATION_VERSION",
74
+ "deriveOperationVersion",
75
+ "digestOperationContract",
76
+ "serializeOperationContract",
77
+ "stableOperationStringify"
78
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
79
+ Object.defineProperty(exports, '__esModule', {
80
+ value: true
81
+ });
@@ -0,0 +1,79 @@
1
+ "use strict";
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
+ (()=>{
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.r = (exports1)=>{
29
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
+ value: 'Module'
31
+ });
32
+ Object.defineProperty(exports1, '__esModule', {
33
+ value: true
34
+ });
35
+ };
36
+ })();
37
+ var __webpack_exports__ = {};
38
+ __webpack_require__.r(__webpack_exports__);
39
+ __webpack_require__.d(__webpack_exports__, {
40
+ resolveOperationProducer: ()=>resolveOperationProducer
41
+ });
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
+ const external_operationIdentity_js_namespaceObject = require("./operationIdentity.js");
46
+ function resolveOperationProducer(options) {
47
+ for (const directory of options.directories){
48
+ if (!directory) continue;
49
+ let current = external_node_path_default().resolve(directory);
50
+ while(true){
51
+ const filename = external_node_path_default().join(current, 'package.json');
52
+ if ((0, external_node_fs_namespaceObject.existsSync)(filename)) {
53
+ options.onDependency?.(filename);
54
+ let metadata = {};
55
+ try {
56
+ metadata = JSON.parse((0, external_node_fs_namespaceObject.readFileSync)(filename, 'utf8')) ?? {};
57
+ } catch {}
58
+ return {
59
+ requestId: options.requestId?.trim() || 'string' == typeof metadata.name && metadata.name.trim() || 'default',
60
+ operationVersion: (0, external_operationIdentity_js_namespaceObject.deriveOperationVersion)(metadata.version)
61
+ };
62
+ }
63
+ const parent = external_node_path_default().dirname(current);
64
+ if (parent === current) break;
65
+ current = parent;
66
+ }
67
+ }
68
+ return {
69
+ requestId: options.requestId?.trim() || 'default',
70
+ operationVersion: (0, external_operationIdentity_js_namespaceObject.deriveOperationVersion)()
71
+ };
72
+ }
73
+ exports.resolveOperationProducer = __webpack_exports__.resolveOperationProducer;
74
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
75
+ "resolveOperationProducer"
76
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
77
+ Object.defineProperty(exports, '__esModule', {
78
+ value: true
79
+ });
@@ -32,13 +32,34 @@ __webpack_require__.d(__webpack_exports__, {
32
32
  });
33
33
  const runtime_namespaceObject = require("@modern-js/plugin-data-loader/runtime");
34
34
  const localised_loader_identity_namespaceObject = require("@modern-js/runtime-extensions/localised-loader-identity");
35
+ const localised_urls_namespaceObject = require("@modern-js/runtime-extensions/localised-urls");
35
36
  const server_core_namespaceObject = require("@modern-js/server-core");
37
+ function expandCanonicalRoutes(routes) {
38
+ const languages = new Set();
39
+ const localisedUrls = {};
40
+ let physical = false;
41
+ const visit = (nodes)=>{
42
+ for (const route of nodes){
43
+ physical ||= 'modernCanonicalPath' in route;
44
+ const identity = Reflect.get(route, 'modernLocalisedRoute');
45
+ if (identity?.paths) {
46
+ localisedUrls[identity.canonicalPath] = identity.paths;
47
+ for (const language of Object.keys(identity.paths))languages.add(language);
48
+ }
49
+ if ('children' in route && route.children) visit(route.children);
50
+ }
51
+ };
52
+ visit(routes);
53
+ return physical || 0 === languages.size ? routes : (0, localised_urls_namespaceObject.applyLocalisedUrlsToRoutes)(routes, [
54
+ ...languages
55
+ ], localisedUrls);
56
+ }
36
57
  function injectLocalisedLoaderPlugin() {
37
58
  return {
38
59
  name: '@modern-js/localised-loader',
39
60
  setup (api) {
40
61
  const handler = async (context, next)=>{
41
- (0, runtime_namespaceObject.setLoaderRouteIdResolver)((0, server_core_namespaceObject.getLoaderCtx)(context), (requestedRouteId, { routes, matchedRouteIds })=>(0, localised_loader_identity_namespaceObject.resolveLocalisedLoaderRouteId)(routes, requestedRouteId, matchedRouteIds));
62
+ (0, runtime_namespaceObject.setLoaderRouteIdResolver)((0, server_core_namespaceObject.getLoaderCtx)(context), (requestedRouteId, { routes, matchedRouteIds })=>(0, localised_loader_identity_namespaceObject.resolveLocalisedLoaderRouteId)(routes, requestedRouteId, matchedRouteIds), expandCanonicalRoutes);
42
63
  await next();
43
64
  };
44
65
  api.onPrepare(()=>{