strapi-plugin-magic-mail 2.10.6 → 2.10.7

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.7](https://github.com/Schero94/Magic-Mail/compare/v2.10.6...v2.10.7) (2026-04-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **email-designer:** prioritize templateReferenceId in findById() to match actual admin UI usage ([bcd7a4b](https://github.com/Schero94/Magic-Mail/commit/bcd7a4bd3b9640f8bc58694ec7a81fddb262245f))
7
+
1
8
  ## [2.10.6](https://github.com/Schero94/Magic-Mail/compare/v2.10.5...v2.10.6) (2026-04-21)
2
9
 
3
10
 
@@ -15851,7 +15851,7 @@ var oauth$1 = ({ strapi: strapi2 }) => ({
15851
15851
  return account;
15852
15852
  }
15853
15853
  });
15854
- const version = "2.10.5";
15854
+ const version = "2.10.6";
15855
15855
  const require$$2 = {
15856
15856
  version
15857
15857
  };
@@ -16277,8 +16277,11 @@ var emailDesigner$1 = ({ strapi: strapi2 }) => ({
16277
16277
  });
16278
16278
  },
16279
16279
  /**
16280
- * Get template by ID (documentId or numeric id) with populated versions
16281
- * Supports both documentId (string) and numeric id for backward compatibility
16280
+ * Get template by ID (numeric id or documentId) with populated versions.
16281
+ *
16282
+ * Numeric IDs are interpreted as `templateReferenceId` first (this is the
16283
+ * app-wide convention — see findById() below), then as legacy DB id.
16284
+ * Non-numeric strings are treated as Strapi v5 `documentId`s.
16282
16285
  */
16283
16286
  async findOne(idOrDocumentId) {
16284
16287
  const isNumericId = /^\d+$/.test(String(idOrDocumentId));
@@ -16294,28 +16297,35 @@ var emailDesigner$1 = ({ strapi: strapi2 }) => ({
16294
16297
  /**
16295
16298
  * Get template by numeric ID.
16296
16299
  *
16297
- * HISTORICAL NOTE this method supports two semantics for historical
16298
- * compatibility: the internal Strapi DB id AND the user-settable
16299
- * `templateReferenceId`. They are both `integer`, both `unique`, and
16300
- * they CAN collide (e.g. Template A has db.id=5 and Template B has
16301
- * templateReferenceId=5). Up until now the lookup tried
16302
- * templateReferenceId *first* and fell back to the DB id — which
16303
- * meant "Send Test" on the admin UI (which passes the DB id) would
16304
- * silently send the WRONG template if another template happened to
16305
- * have a templateReferenceId matching that number.
16300
+ * CONTRACTevery HTTP route that carries `:id` (admin UI, REST callers,
16301
+ * magic-link's `magic_mail_template_id`, Strapi's own test-send) refers to
16302
+ * the user-visible `templateReferenceId`. That is what `TemplateList`
16303
+ * navigates with, what `EditorPage` reads from `useParams()`, and what the
16304
+ * `findAll()` response surfaces as `templateReferenceId` (alongside `.id`).
16306
16305
  *
16307
- * Correct ordering: ask the DB id first (that is the value every
16308
- * `findAll()` response carries as `.id`, and that is what the admin
16309
- * UI and Strapi's own routing use). Only if that truly misses, try
16310
- * the reference id as a best-effort fallback for legacy callers that
16311
- * already persisted a reference id as their template key.
16306
+ * So: we resolve the reference id FIRST. The DB id is only kept as a
16307
+ * best-effort fallback for very old installs that might have persisted
16308
+ * the Strapi primary key as their template key before the reference id
16309
+ * was introduced. Collisions between the two ID spaces are prevented on
16310
+ * create() (refId uniqueness is enforced there).
16312
16311
  *
16313
- * When the fallback actually fires we log WARN + print both IDs so
16314
- * the operator can spot and fix a collision in their data.
16312
+ * We intentionally do NOT spam warn-logs in the success path: the
16313
+ * reference-id lookup IS the primary path.
16315
16314
  */
16316
16315
  async findById(id) {
16317
16316
  const numericId = Number(id);
16318
- strapi2.log.info(`[magic-mail] [LOOKUP] Finding template by numeric ID: ${numericId}`);
16317
+ strapi2.log.info(`[magic-mail] [LOOKUP] Finding template by ID: ${numericId}`);
16318
+ const byRefId = await strapi2.documents(EMAIL_TEMPLATE_UID).findMany({
16319
+ filters: { templateReferenceId: numericId },
16320
+ limit: 1,
16321
+ populate: { versions: true }
16322
+ });
16323
+ if (byRefId.length > 0) {
16324
+ strapi2.log.info(
16325
+ `[magic-mail] [SUCCESS] Found template by templateReferenceId ${numericId}: documentId=${byRefId[0].documentId}, name="${byRefId[0].name}"`
16326
+ );
16327
+ return byRefId[0];
16328
+ }
16319
16329
  let byInternalId = null;
16320
16330
  try {
16321
16331
  byInternalId = await strapi2.entityService.findOne(EMAIL_TEMPLATE_UID, numericId, {
@@ -16325,21 +16335,12 @@ var emailDesigner$1 = ({ strapi: strapi2 }) => ({
16325
16335
  strapi2.log.debug(`[magic-mail] [LOOKUP] entityService.findOne(${numericId}) threw: ${err.message}`);
16326
16336
  }
16327
16337
  if (byInternalId) {
16328
- strapi2.log.info(`[magic-mail] [SUCCESS] Found template by internal id ${numericId}: documentId=${byInternalId.documentId}, name="${byInternalId.name}"`);
16329
- return byInternalId;
16330
- }
16331
- const byRefId = await strapi2.documents(EMAIL_TEMPLATE_UID).findMany({
16332
- filters: { templateReferenceId: numericId },
16333
- limit: 1,
16334
- populate: { versions: true }
16335
- });
16336
- if (byRefId.length > 0) {
16337
- strapi2.log.warn(
16338
- `[magic-mail] [FALLBACK] No template with internal id=${numericId}; resolved via templateReferenceId=${numericId} → "${byRefId[0].name}" (documentId=${byRefId[0].documentId}). If the caller meant the DB id, this is the wrong record — update the caller to pass templateReferenceId explicitly or use findByReferenceId().`
16338
+ strapi2.log.info(
16339
+ `[magic-mail] [LEGACY-LOOKUP] No templateReferenceId=${numericId}; resolved via internal DB id=${numericId} → "${byInternalId.name}" (documentId=${byInternalId.documentId}). Consider storing the template's templateReferenceId (${byInternalId.templateReferenceId ?? "none set"}) instead of its DB id to keep callers stable across migrations.`
16339
16340
  );
16340
- return byRefId[0];
16341
+ return byInternalId;
16341
16342
  }
16342
- strapi2.log.warn(`[magic-mail] [WARNING] Template with ID ${numericId} not found (tried internal id and templateReferenceId)`);
16343
+ strapi2.log.warn(`[magic-mail] [WARNING] Template with ID ${numericId} not found (tried templateReferenceId and internal DB id)`);
16343
16344
  return null;
16344
16345
  },
16345
16346
  /**
@@ -15838,7 +15838,7 @@ var oauth$1 = ({ strapi: strapi2 }) => ({
15838
15838
  return account;
15839
15839
  }
15840
15840
  });
15841
- const version = "2.10.5";
15841
+ const version = "2.10.6";
15842
15842
  const require$$2 = {
15843
15843
  version
15844
15844
  };
@@ -16264,8 +16264,11 @@ var emailDesigner$1 = ({ strapi: strapi2 }) => ({
16264
16264
  });
16265
16265
  },
16266
16266
  /**
16267
- * Get template by ID (documentId or numeric id) with populated versions
16268
- * Supports both documentId (string) and numeric id for backward compatibility
16267
+ * Get template by ID (numeric id or documentId) with populated versions.
16268
+ *
16269
+ * Numeric IDs are interpreted as `templateReferenceId` first (this is the
16270
+ * app-wide convention — see findById() below), then as legacy DB id.
16271
+ * Non-numeric strings are treated as Strapi v5 `documentId`s.
16269
16272
  */
16270
16273
  async findOne(idOrDocumentId) {
16271
16274
  const isNumericId = /^\d+$/.test(String(idOrDocumentId));
@@ -16281,28 +16284,35 @@ var emailDesigner$1 = ({ strapi: strapi2 }) => ({
16281
16284
  /**
16282
16285
  * Get template by numeric ID.
16283
16286
  *
16284
- * HISTORICAL NOTE this method supports two semantics for historical
16285
- * compatibility: the internal Strapi DB id AND the user-settable
16286
- * `templateReferenceId`. They are both `integer`, both `unique`, and
16287
- * they CAN collide (e.g. Template A has db.id=5 and Template B has
16288
- * templateReferenceId=5). Up until now the lookup tried
16289
- * templateReferenceId *first* and fell back to the DB id — which
16290
- * meant "Send Test" on the admin UI (which passes the DB id) would
16291
- * silently send the WRONG template if another template happened to
16292
- * have a templateReferenceId matching that number.
16287
+ * CONTRACTevery HTTP route that carries `:id` (admin UI, REST callers,
16288
+ * magic-link's `magic_mail_template_id`, Strapi's own test-send) refers to
16289
+ * the user-visible `templateReferenceId`. That is what `TemplateList`
16290
+ * navigates with, what `EditorPage` reads from `useParams()`, and what the
16291
+ * `findAll()` response surfaces as `templateReferenceId` (alongside `.id`).
16293
16292
  *
16294
- * Correct ordering: ask the DB id first (that is the value every
16295
- * `findAll()` response carries as `.id`, and that is what the admin
16296
- * UI and Strapi's own routing use). Only if that truly misses, try
16297
- * the reference id as a best-effort fallback for legacy callers that
16298
- * already persisted a reference id as their template key.
16293
+ * So: we resolve the reference id FIRST. The DB id is only kept as a
16294
+ * best-effort fallback for very old installs that might have persisted
16295
+ * the Strapi primary key as their template key before the reference id
16296
+ * was introduced. Collisions between the two ID spaces are prevented on
16297
+ * create() (refId uniqueness is enforced there).
16299
16298
  *
16300
- * When the fallback actually fires we log WARN + print both IDs so
16301
- * the operator can spot and fix a collision in their data.
16299
+ * We intentionally do NOT spam warn-logs in the success path: the
16300
+ * reference-id lookup IS the primary path.
16302
16301
  */
16303
16302
  async findById(id) {
16304
16303
  const numericId = Number(id);
16305
- strapi2.log.info(`[magic-mail] [LOOKUP] Finding template by numeric ID: ${numericId}`);
16304
+ strapi2.log.info(`[magic-mail] [LOOKUP] Finding template by ID: ${numericId}`);
16305
+ const byRefId = await strapi2.documents(EMAIL_TEMPLATE_UID).findMany({
16306
+ filters: { templateReferenceId: numericId },
16307
+ limit: 1,
16308
+ populate: { versions: true }
16309
+ });
16310
+ if (byRefId.length > 0) {
16311
+ strapi2.log.info(
16312
+ `[magic-mail] [SUCCESS] Found template by templateReferenceId ${numericId}: documentId=${byRefId[0].documentId}, name="${byRefId[0].name}"`
16313
+ );
16314
+ return byRefId[0];
16315
+ }
16306
16316
  let byInternalId = null;
16307
16317
  try {
16308
16318
  byInternalId = await strapi2.entityService.findOne(EMAIL_TEMPLATE_UID, numericId, {
@@ -16312,21 +16322,12 @@ var emailDesigner$1 = ({ strapi: strapi2 }) => ({
16312
16322
  strapi2.log.debug(`[magic-mail] [LOOKUP] entityService.findOne(${numericId}) threw: ${err.message}`);
16313
16323
  }
16314
16324
  if (byInternalId) {
16315
- strapi2.log.info(`[magic-mail] [SUCCESS] Found template by internal id ${numericId}: documentId=${byInternalId.documentId}, name="${byInternalId.name}"`);
16316
- return byInternalId;
16317
- }
16318
- const byRefId = await strapi2.documents(EMAIL_TEMPLATE_UID).findMany({
16319
- filters: { templateReferenceId: numericId },
16320
- limit: 1,
16321
- populate: { versions: true }
16322
- });
16323
- if (byRefId.length > 0) {
16324
- strapi2.log.warn(
16325
- `[magic-mail] [FALLBACK] No template with internal id=${numericId}; resolved via templateReferenceId=${numericId} → "${byRefId[0].name}" (documentId=${byRefId[0].documentId}). If the caller meant the DB id, this is the wrong record — update the caller to pass templateReferenceId explicitly or use findByReferenceId().`
16325
+ strapi2.log.info(
16326
+ `[magic-mail] [LEGACY-LOOKUP] No templateReferenceId=${numericId}; resolved via internal DB id=${numericId} → "${byInternalId.name}" (documentId=${byInternalId.documentId}). Consider storing the template's templateReferenceId (${byInternalId.templateReferenceId ?? "none set"}) instead of its DB id to keep callers stable across migrations.`
16326
16327
  );
16327
- return byRefId[0];
16328
+ return byInternalId;
16328
16329
  }
16329
- strapi2.log.warn(`[magic-mail] [WARNING] Template with ID ${numericId} not found (tried internal id and templateReferenceId)`);
16330
+ strapi2.log.warn(`[magic-mail] [WARNING] Template with ID ${numericId} not found (tried templateReferenceId and internal DB id)`);
16330
16331
  return null;
16331
16332
  },
16332
16333
  /**
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.10.6",
2
+ "version": "2.10.7",
3
3
  "keywords": [
4
4
  "strapi",
5
5
  "plugin",