xypriss 9.14.19 → 9.14.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -18272,6 +18272,9 @@ class XyPrisRequestApp {
18272
18272
  if (prop in target || prop === "constructor") {
18273
18273
  return Reflect.get(target, prop, receiver);
18274
18274
  }
18275
+ if (prop === "xems") {
18276
+ return this.appInstance?.xems || this.appInstance?._xems;
18277
+ }
18275
18278
  // Otherwise, proxy to appInstance
18276
18279
  if (this.appInstance && prop in this.appInstance) {
18277
18280
  const value = this.appInstance[prop];
@@ -29685,11 +29688,19 @@ class XyprissApp {
29685
29688
  const self = this;
29686
29689
  return new Proxy(this, {
29687
29690
  set(target, prop, value) {
29691
+ if (prop === "xems" || prop === "_xems") {
29692
+ target[prop] = value;
29693
+ return true;
29694
+ }
29688
29695
  const errorMsg = `[XyPriss Security] Mutation Attempt Detected: Application instance is immutable after creation. Property '${String(prop)}' cannot be changed.`;
29689
29696
  self.logger.error("security", errorMsg);
29690
29697
  throw new Error(errorMsg);
29691
29698
  },
29692
29699
  defineProperty(target, prop, descriptor) {
29700
+ if (prop === "xems" || prop === "_xems") {
29701
+ Object.defineProperty(target, prop, descriptor);
29702
+ return true;
29703
+ }
29693
29704
  const errorMsg = `[XyPriss Security] Mutation Attempt Detected: Cannot define new property '${String(prop)}' on locked app instance.`;
29694
29705
  self.logger.error("security", errorMsg);
29695
29706
  throw new Error(errorMsg);
@@ -34088,6 +34099,7 @@ class PluginSecurity {
34088
34099
  ...allowedMiddlewareMethods,
34089
34100
  "logger",
34090
34101
  "configs",
34102
+ "xems",
34091
34103
  ];
34092
34104
  // Facade for the app instance to avoid Proxy invariants on non-configurable properties
34093
34105
  const appFacade = {};
@@ -34106,6 +34118,9 @@ class PluginSecurity {
34106
34118
  return undefined;
34107
34119
  }
34108
34120
  }
34121
+ if (prop === "xems") {
34122
+ return target.xems || target._xems;
34123
+ }
34109
34124
  const originalMethod = target[prop];
34110
34125
  if (typeof originalMethod === "function") {
34111
34126
  if (allowedRoutingMethods.includes(prop) || allowedMiddlewareMethods.includes(prop)) {
@@ -34173,7 +34188,26 @@ class PluginSecurity {
34173
34188
  return originalMethod.bind(target);
34174
34189
  }
34175
34190
  return originalMethod;
34176
- }
34191
+ },
34192
+ set: (value) => {
34193
+ const target = server.app;
34194
+ if (prop === "xems" && OFFICIAL_PLUGINS.includes(pluginName)) {
34195
+ try {
34196
+ target.xems = value;
34197
+ }
34198
+ catch { }
34199
+ try {
34200
+ target._xems = value;
34201
+ }
34202
+ catch { }
34203
+ }
34204
+ else {
34205
+ try {
34206
+ target[prop] = value;
34207
+ }
34208
+ catch { }
34209
+ }
34210
+ },
34177
34211
  });
34178
34212
  }
34179
34213
  // Facade for the server instance
@@ -35402,7 +35436,13 @@ class XemsRunner {
35402
35436
  * otherwise returns this instance.
35403
35437
  */
35404
35438
  forApp(app) {
35405
- return app?.xems || this;
35439
+ if (!app)
35440
+ return this;
35441
+ const candidate = app.xems ||
35442
+ app._xems ||
35443
+ (app.appInstance && (app.appInstance.xems || app.appInstance._xems)) ||
35444
+ (app.server && (app.server.app?.xems || app.server.xems));
35445
+ return candidate || this;
35406
35446
  }
35407
35447
  /**
35408
35448
  * Forcefully stops the XEMS process and cleans up resources.
@@ -35518,12 +35558,15 @@ class XemsBuiltinPlugin {
35518
35558
  const app = server.app;
35519
35559
  const logger = app.logger;
35520
35560
  // 1. Configuration Extraction
35521
- // Cascade defaults from global configuration if child only specified partial options or none
35561
+ // Child server xems configuration takes absolute precedence over global defaults
35522
35562
  const globalXems = ConfigurationManager.get("server")?.xems;
35523
- const localXems = app.configs?.server?.xems;
35563
+ const localXems = app.configs?.server?.xems ||
35564
+ app.configs?.xems ||
35565
+ server?.app?.configs?.server?.xems ||
35566
+ server?.app?.configs?.xems;
35524
35567
  let xemsOptions;
35525
35568
  if (localXems && globalXems && typeof globalXems === "object") {
35526
- // Intelligent cascade merge: child inherits parent defaults but can override selectively
35569
+ // Intelligent cascade merge: child inherits parent defaults, but child options strictly override
35527
35570
  xemsOptions = mergeWithDefaults(globalXems, localXems);
35528
35571
  }
35529
35572
  else if (localXems) {
@@ -35589,8 +35632,35 @@ class XemsBuiltinPlugin {
35589
35632
  cacheSize: rawResources?.cacheSize,
35590
35633
  });
35591
35634
  this.logger.debug("xems", `XemsRunner instances count: ${XemsRunner.runnersByPath?.size ?? 0} for path: ${pathStr}`);
35592
- // Attach the shared runner to the app
35593
- app.xems = this.runner;
35635
+ // Attach the runner to the app and underlying server instances
35636
+ try {
35637
+ app.xems = this.runner;
35638
+ }
35639
+ catch { }
35640
+ try {
35641
+ app._xems = this.runner;
35642
+ }
35643
+ catch { }
35644
+ if (server && server.app) {
35645
+ try {
35646
+ server.app.xems = this.runner;
35647
+ }
35648
+ catch { }
35649
+ try {
35650
+ server.app._xems = this.runner;
35651
+ }
35652
+ catch { }
35653
+ }
35654
+ if (app.server && app.server.app) {
35655
+ try {
35656
+ app.server.app.xems = this.runner;
35657
+ }
35658
+ catch { }
35659
+ try {
35660
+ app.server.app._xems = this.runner;
35661
+ }
35662
+ catch { }
35663
+ }
35594
35664
  if (rawPath) {
35595
35665
  try {
35596
35666
  this.runner.enablePersistence(rawPath, secret, {
@@ -35604,7 +35674,24 @@ class XemsBuiltinPlugin {
35604
35674
  }
35605
35675
  else {
35606
35676
  // Expose fallback runner on app
35607
- app.xems = this.runner;
35677
+ try {
35678
+ app.xems = this.runner;
35679
+ }
35680
+ catch { }
35681
+ try {
35682
+ app._xems = this.runner;
35683
+ }
35684
+ catch { }
35685
+ if (server && server.app) {
35686
+ try {
35687
+ server.app.xems = this.runner;
35688
+ }
35689
+ catch { }
35690
+ try {
35691
+ server.app._xems = this.runner;
35692
+ }
35693
+ catch { }
35694
+ }
35608
35695
  if (!isAuxiliary && xemsOptions.enable !== false) {
35609
35696
  logger.warn("plugins", "XEMS requested but mandatory 'path' or 32-byte 'secret' is missing. Please provide both.");
35610
35697
  }
@@ -37338,8 +37425,15 @@ class MultiServerManager {
37338
37425
  }
37339
37426
  // Cascade server options (specifically server.xems, cookieOptions, secret, etc.)
37340
37427
  const baseServer = this.baseConfig?.server || {};
37341
- const childServer = config.server || {};
37428
+ const childServer = { ...(config.server || {}) };
37429
+ const childXems = childServer.xems || config.xems;
37430
+ if (childXems) {
37431
+ childServer.xems = childXems;
37432
+ }
37342
37433
  const mergedServer = mergeWithDefaults(baseServer, childServer);
37434
+ if (childXems) {
37435
+ mergedServer.xems = mergeWithDefaults(baseServer.xems || {}, childXems);
37436
+ }
37343
37437
  if (config.port)
37344
37438
  mergedServer.port = config.port;
37345
37439
  if (config.host)
@@ -38589,8 +38683,19 @@ function createServer(options = {}) {
38589
38683
  ConfigurationManager.update("multiServer", options.multiServer);
38590
38684
  }
38591
38685
  const servers = (xms || []).map((server) => {
38686
+ // Hoist top-level xems if child specified it directly on MultiServerConfig
38687
+ if (server.xems && !server.server?.xems) {
38688
+ server.server = server.server || {};
38689
+ server.server.xems = server.xems;
38690
+ }
38592
38691
  // Individual server options take precedence over global ones
38593
38692
  const merged = mergeWithDefaults(globalOptions, server);
38693
+ // Ensure child server xems explicitly overrides global server xems
38694
+ const explicitChildXems = server.server?.xems || server.xems;
38695
+ if (explicitChildXems) {
38696
+ merged.server = merged.server || {};
38697
+ merged.server.xems = mergeWithDefaults(globalOptions.server?.xems || {}, explicitChildXems);
38698
+ }
38594
38699
  // Ensure child server port & host override global server block
38595
38700
  if (server.port) {
38596
38701
  merged.server = merged.server || {};