strapi-plugin-magic-mail 2.10.10 → 2.10.11

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [2.10.11](https://github.com/Schero94/Magic-Mail/compare/v2.10.10...v2.10.11) (2026-04-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **email-designer:** generate duplicate-template refId within int4 range ([d1ecae8](https://github.com/Schero94/Magic-Mail/commit/d1ecae8d657ead41521b08fcad35d9c483f779d9))
7
+
1
8
  ## [2.10.10](https://github.com/Schero94/Magic-Mail/compare/v2.10.9...v2.10.10) (2026-04-21)
2
9
 
3
10
 
@@ -15909,7 +15909,7 @@ var oauth$1 = ({ strapi: strapi2 }) => ({
15909
15909
  return account;
15910
15910
  }
15911
15911
  });
15912
- const version = "2.10.9";
15912
+ const version = "2.10.10";
15913
15913
  const require$$2 = {
15914
15914
  version
15915
15915
  };
@@ -16558,6 +16558,35 @@ var emailDesigner$1 = ({ strapi: strapi2 }) => ({
16558
16558
  strapi2.log.info(`[magic-mail] [SUCCESS] Template "${template.name}" and ${allVersions.length} versions deleted`);
16559
16559
  return result2;
16560
16560
  },
16561
+ /**
16562
+ * Generate a new `templateReferenceId` guaranteed to fit in PostgreSQL's
16563
+ * `integer` column (max 2_147_483_647). We retry a few times to dodge
16564
+ * the astronomically unlikely collision with an already-used reference
16565
+ * id — the schema declares `unique: true`, so picking a duplicate here
16566
+ * would otherwise fail at insert time.
16567
+ *
16568
+ * Previous implementation used `Date.now()` which overflows the int4
16569
+ * range (13 digits vs. 10-digit max), producing a "value is out of range
16570
+ * for type integer" error on every duplicate call.
16571
+ *
16572
+ * @returns {Promise<number>}
16573
+ * @throws {Error} if no unique id can be found after MAX_ATTEMPTS tries
16574
+ */
16575
+ async _generateUniqueTemplateReferenceId() {
16576
+ const MAX_ATTEMPTS = 5;
16577
+ const UPPER_BOUND = 2e9;
16578
+ for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt += 1) {
16579
+ const candidate = Math.floor(Math.random() * UPPER_BOUND) + 1;
16580
+ const existing = await this.findByReferenceId(candidate);
16581
+ if (!existing) return candidate;
16582
+ strapi2.log.warn(
16583
+ `[magic-mail] [DUPLICATE] templateReferenceId collision on ${candidate} (attempt ${attempt + 1}/${MAX_ATTEMPTS}); retrying`
16584
+ );
16585
+ }
16586
+ throw new Error(
16587
+ `Could not generate a unique templateReferenceId after ${MAX_ATTEMPTS} attempts`
16588
+ );
16589
+ },
16561
16590
  /**
16562
16591
  * Duplicate template
16563
16592
  * @param {string|number} idOrDocumentId - Either numeric id or documentId
@@ -16569,6 +16598,7 @@ var emailDesigner$1 = ({ strapi: strapi2 }) => ({
16569
16598
  throw new Error("Template not found");
16570
16599
  }
16571
16600
  strapi2.log.info(`[magic-mail] [PACKAGE] Original template: documentId=${original.documentId}, name="${original.name}"`);
16601
+ const newRefId = await this._generateUniqueTemplateReferenceId();
16572
16602
  const duplicateData = {
16573
16603
  name: `${original.name} copy`,
16574
16604
  subject: original.subject,
@@ -16578,10 +16608,10 @@ var emailDesigner$1 = ({ strapi: strapi2 }) => ({
16578
16608
  category: original.category,
16579
16609
  tags: original.tags,
16580
16610
  isActive: original.isActive,
16581
- templateReferenceId: Date.now() + Math.floor(Math.random() * 1e3)
16611
+ templateReferenceId: newRefId
16582
16612
  };
16583
16613
  const duplicated = await this.create(duplicateData);
16584
- strapi2.log.info(`[magic-mail] [SUCCESS] Template duplicated: documentId=${duplicated.documentId}`);
16614
+ strapi2.log.info(`[magic-mail] [SUCCESS] Template duplicated: documentId=${duplicated.documentId}, newRefId=${newRefId}`);
16585
16615
  return duplicated;
16586
16616
  },
16587
16617
  // ============================================================
@@ -15896,7 +15896,7 @@ var oauth$1 = ({ strapi: strapi2 }) => ({
15896
15896
  return account;
15897
15897
  }
15898
15898
  });
15899
- const version = "2.10.9";
15899
+ const version = "2.10.10";
15900
15900
  const require$$2 = {
15901
15901
  version
15902
15902
  };
@@ -16545,6 +16545,35 @@ var emailDesigner$1 = ({ strapi: strapi2 }) => ({
16545
16545
  strapi2.log.info(`[magic-mail] [SUCCESS] Template "${template.name}" and ${allVersions.length} versions deleted`);
16546
16546
  return result2;
16547
16547
  },
16548
+ /**
16549
+ * Generate a new `templateReferenceId` guaranteed to fit in PostgreSQL's
16550
+ * `integer` column (max 2_147_483_647). We retry a few times to dodge
16551
+ * the astronomically unlikely collision with an already-used reference
16552
+ * id — the schema declares `unique: true`, so picking a duplicate here
16553
+ * would otherwise fail at insert time.
16554
+ *
16555
+ * Previous implementation used `Date.now()` which overflows the int4
16556
+ * range (13 digits vs. 10-digit max), producing a "value is out of range
16557
+ * for type integer" error on every duplicate call.
16558
+ *
16559
+ * @returns {Promise<number>}
16560
+ * @throws {Error} if no unique id can be found after MAX_ATTEMPTS tries
16561
+ */
16562
+ async _generateUniqueTemplateReferenceId() {
16563
+ const MAX_ATTEMPTS = 5;
16564
+ const UPPER_BOUND = 2e9;
16565
+ for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt += 1) {
16566
+ const candidate = Math.floor(Math.random() * UPPER_BOUND) + 1;
16567
+ const existing = await this.findByReferenceId(candidate);
16568
+ if (!existing) return candidate;
16569
+ strapi2.log.warn(
16570
+ `[magic-mail] [DUPLICATE] templateReferenceId collision on ${candidate} (attempt ${attempt + 1}/${MAX_ATTEMPTS}); retrying`
16571
+ );
16572
+ }
16573
+ throw new Error(
16574
+ `Could not generate a unique templateReferenceId after ${MAX_ATTEMPTS} attempts`
16575
+ );
16576
+ },
16548
16577
  /**
16549
16578
  * Duplicate template
16550
16579
  * @param {string|number} idOrDocumentId - Either numeric id or documentId
@@ -16556,6 +16585,7 @@ var emailDesigner$1 = ({ strapi: strapi2 }) => ({
16556
16585
  throw new Error("Template not found");
16557
16586
  }
16558
16587
  strapi2.log.info(`[magic-mail] [PACKAGE] Original template: documentId=${original.documentId}, name="${original.name}"`);
16588
+ const newRefId = await this._generateUniqueTemplateReferenceId();
16559
16589
  const duplicateData = {
16560
16590
  name: `${original.name} copy`,
16561
16591
  subject: original.subject,
@@ -16565,10 +16595,10 @@ var emailDesigner$1 = ({ strapi: strapi2 }) => ({
16565
16595
  category: original.category,
16566
16596
  tags: original.tags,
16567
16597
  isActive: original.isActive,
16568
- templateReferenceId: Date.now() + Math.floor(Math.random() * 1e3)
16598
+ templateReferenceId: newRefId
16569
16599
  };
16570
16600
  const duplicated = await this.create(duplicateData);
16571
- strapi2.log.info(`[magic-mail] [SUCCESS] Template duplicated: documentId=${duplicated.documentId}`);
16601
+ strapi2.log.info(`[magic-mail] [SUCCESS] Template duplicated: documentId=${duplicated.documentId}, newRefId=${newRefId}`);
16572
16602
  return duplicated;
16573
16603
  },
16574
16604
  // ============================================================
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.10.10",
2
+ "version": "2.10.11",
3
3
  "keywords": [
4
4
  "strapi",
5
5
  "plugin",