serverless-plugin-module-registry 1.0.20 → 1.0.23

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/index.js CHANGED
@@ -16451,6 +16451,43 @@ var DynamoDBManager = class {
16451
16451
  ...entry
16452
16452
  }));
16453
16453
  }
16454
+ /**
16455
+ * Merge new module items with existing DDB records to preserve fields
16456
+ * not set by the current deploy (e.g., apiGatewayId).
16457
+ *
16458
+ * Uses existing → new merge order so that new values always win,
16459
+ * but fields only present in the existing record are preserved.
16460
+ */
16461
+ async mergeWithExistingModuleItems(newModuleItems, moduleNames) {
16462
+ const existingByModule = /* @__PURE__ */ new Map();
16463
+ for (const moduleName of moduleNames) {
16464
+ try {
16465
+ const existingItems = await this.queryModuleEntries(moduleName);
16466
+ const moduleRecord = existingItems.find((item) => item.sk === "MODULE");
16467
+ if (moduleRecord) {
16468
+ existingByModule.set(moduleName, moduleRecord);
16469
+ }
16470
+ } catch (err) {
16471
+ this.logger.warning(` Could not read existing record for module '${moduleName}': ${err.message}`);
16472
+ }
16473
+ }
16474
+ if (existingByModule.size === 0) {
16475
+ return newModuleItems;
16476
+ }
16477
+ return newModuleItems.map((newItem) => {
16478
+ const moduleName = newItem.moduleName;
16479
+ const existing = existingByModule.get(moduleName);
16480
+ if (!existing) return newItem;
16481
+ const merged = { ...existing, ...newItem };
16482
+ const preservedFields = Object.keys(existing).filter(
16483
+ (k) => !(k in newItem) && existing[k] !== void 0
16484
+ );
16485
+ if (preservedFields.length > 0) {
16486
+ this.logger.info(` \u{1F500} Module '${moduleName}': preserved existing fields: ${preservedFields.join(", ")}`);
16487
+ }
16488
+ return merged;
16489
+ });
16490
+ }
16454
16491
  /**
16455
16492
  * Clean up stale entries for given modules
16456
16493
  * Note: Settings are now stored as attributes on module items, not separate items
@@ -16519,12 +16556,13 @@ var DynamoDBManager = class {
16519
16556
  await this.ensureTable();
16520
16557
  const moduleNames = [...new Set(moduleEntries.map((m) => m.moduleName))];
16521
16558
  await this.cleanupStaleEntries(moduleNames, moduleEntries, featureEntries, settingsEntries);
16522
- const moduleItems = this.moduleEntriesToItems(moduleEntries, settingsEntries);
16559
+ let moduleItems = this.moduleEntriesToItems(moduleEntries, settingsEntries);
16523
16560
  const featureItems = this.featureEntriesToItems(featureEntries);
16524
16561
  this.logger.info(` \u{1F4CA} Preparing items: ${moduleItems.length} modules (${settingsEntries.length} with settings), ${featureItems.length} features`);
16525
16562
  if (settingsEntries.length > 0) {
16526
16563
  this.logger.info(` \u2699\uFE0F Modules with settings: ${settingsEntries.map((s) => s.moduleName).join(", ")}`);
16527
16564
  }
16565
+ moduleItems = await this.mergeWithExistingModuleItems(moduleItems, moduleNames);
16528
16566
  const allItems = [
16529
16567
  ...moduleItems,
16530
16568
  ...featureItems
@@ -16986,22 +17024,26 @@ var PluginOrchestrator = class {
16986
17024
  } catch (cfnError) {
16987
17025
  this.logger.warning(`CloudFormation API Gateway lookup failed: ${cfnError.message}`);
16988
17026
  }
16989
- const apiGatewayClient = new import_client_api_gateway.APIGatewayClient({ region });
16990
- try {
16991
- const apisCommand = new import_client_api_gateway.GetRestApisCommand({});
16992
- const apisResponse = await apiGatewayClient.send(apisCommand);
16993
- const matchingApi = (_b3 = apisResponse.items) == null ? void 0 : _b3.find(
16994
- (api) => {
16995
- var _a5;
16996
- return api.name === serviceName || ((_a5 = api.name) == null ? void 0 : _a5.includes(serviceName));
17027
+ const stage = stackName.startsWith(serviceName + "-") ? stackName.slice(serviceName.length + 1) : void 0;
17028
+ if (!stage) {
17029
+ this.logger.warning(`Could not derive stage from stackName '${stackName}' and serviceName '${serviceName}'. Skipping API Gateway fallback.`);
17030
+ } else {
17031
+ const apiGatewayClient = new import_client_api_gateway.APIGatewayClient({ region });
17032
+ const expectedApiName = `${stage}-${serviceName}`;
17033
+ this.logger.info(`\u{1F50D} Fallback: looking for API Gateway with exact name: ${expectedApiName}`);
17034
+ try {
17035
+ const apisCommand = new import_client_api_gateway.GetRestApisCommand({});
17036
+ const apisResponse = await apiGatewayClient.send(apisCommand);
17037
+ const matchingApi = (_b3 = apisResponse.items) == null ? void 0 : _b3.find(
17038
+ (api) => api.name === expectedApiName
17039
+ );
17040
+ if (matchingApi == null ? void 0 : matchingApi.id) {
17041
+ this.logger.info(`\u2705 Discovered API Gateway ID from API Gateway service: ${matchingApi.id} (name: ${expectedApiName})`);
17042
+ return matchingApi.id;
16997
17043
  }
16998
- );
16999
- if (matchingApi == null ? void 0 : matchingApi.id) {
17000
- this.logger.info(`\u2705 Discovered API Gateway ID from API Gateway service: ${matchingApi.id}`);
17001
- return matchingApi.id;
17044
+ } catch (apiError) {
17045
+ this.logger.warning(`API Gateway service lookup failed: ${apiError.message}`);
17002
17046
  }
17003
- } catch (apiError) {
17004
- this.logger.warning(`API Gateway service lookup failed: ${apiError.message}`);
17005
17047
  }
17006
17048
  this.logger.warning("Could not discover API Gateway ID. Module will be registered without apiGatewayId.");
17007
17049
  return void 0;
@@ -19668,29 +19710,33 @@ var ServerlessModuleRegistryPlugin = class {
19668
19710
  } catch (cfnError) {
19669
19711
  this.logger.warning(`CloudFormation API Gateway lookup failed: ${cfnError.message}`);
19670
19712
  }
19671
- if (!this.apiGatewayClient) {
19672
- this.apiGatewayClient = new import_client_api_gateway2.APIGatewayClient({ region });
19673
- }
19674
- try {
19675
- let position;
19676
- do {
19677
- const apisResponse = await this.apiGatewayClient.send(
19678
- new import_client_api_gateway2.GetRestApisCommand(position ? { position } : {})
19679
- );
19680
- const matchingApi = (_b3 = apisResponse.items) == null ? void 0 : _b3.find(
19681
- (api) => {
19682
- var _a5;
19683
- return api.name === serviceName || ((_a5 = api.name) == null ? void 0 : _a5.includes(serviceName));
19713
+ const stage = stackName.startsWith(serviceName + "-") ? stackName.slice(serviceName.length + 1) : void 0;
19714
+ if (!stage) {
19715
+ this.logger.warning(`Could not derive stage from stackName '${stackName}' and serviceName '${serviceName}'. Skipping API Gateway fallback.`);
19716
+ } else {
19717
+ if (!this.apiGatewayClient) {
19718
+ this.apiGatewayClient = new import_client_api_gateway2.APIGatewayClient({ region });
19719
+ }
19720
+ const expectedApiName = `${stage}-${serviceName}`;
19721
+ this.logger.info(`\u{1F50D} Fallback: looking for API Gateway with exact name: ${expectedApiName}`);
19722
+ try {
19723
+ let position;
19724
+ do {
19725
+ const apisResponse = await this.apiGatewayClient.send(
19726
+ new import_client_api_gateway2.GetRestApisCommand(position ? { position } : {})
19727
+ );
19728
+ const matchingApi = (_b3 = apisResponse.items) == null ? void 0 : _b3.find(
19729
+ (api) => api.name === expectedApiName
19730
+ );
19731
+ if (matchingApi == null ? void 0 : matchingApi.id) {
19732
+ this.logger.info(`\u2705 Discovered API Gateway ID from API Gateway service: ${matchingApi.id} (name: ${expectedApiName})`);
19733
+ return matchingApi.id;
19684
19734
  }
19685
- );
19686
- if (matchingApi == null ? void 0 : matchingApi.id) {
19687
- this.logger.info(`\u2705 Discovered API Gateway ID from API Gateway service: ${matchingApi.id}`);
19688
- return matchingApi.id;
19689
- }
19690
- position = apisResponse.position;
19691
- } while (position);
19692
- } catch (apiError) {
19693
- this.logger.warning(`API Gateway service lookup failed: ${apiError.message}`);
19735
+ position = apisResponse.position;
19736
+ } while (position);
19737
+ } catch (apiError) {
19738
+ this.logger.warning(`API Gateway service lookup failed: ${apiError.message}`);
19739
+ }
19694
19740
  }
19695
19741
  this.logger.warning("Could not discover API Gateway ID. Module will be registered without apiGatewayId.");
19696
19742
  return void 0;