strapi-plugin-magic-mail 2.3.8 → 2.3.9

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.
@@ -5543,7 +5543,7 @@ function requireOauth() {
5543
5543
  });
5544
5544
  return oauth;
5545
5545
  }
5546
- const version = "2.3.7";
5546
+ const version = "2.3.8";
5547
5547
  const require$$2 = {
5548
5548
  version
5549
5549
  };
@@ -6011,6 +6011,37 @@ function requireEmailDesigner() {
6011
6011
  });
6012
6012
  return results.length > 0 ? results[0] : null;
6013
6013
  },
6014
+ /**
6015
+ * Get version by numeric ID or documentId
6016
+ * First tries documentId, then falls back to internal database id via entityService
6017
+ */
6018
+ async findVersionById(idOrDocumentId) {
6019
+ strapi2.log.info(`[magic-mail] [LOOKUP] Finding version by ID: ${idOrDocumentId}`);
6020
+ const isNumericId = /^\d+$/.test(String(idOrDocumentId));
6021
+ if (!isNumericId) {
6022
+ const version2 = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findOne({
6023
+ documentId: String(idOrDocumentId),
6024
+ populate: { template: true }
6025
+ });
6026
+ if (version2) {
6027
+ strapi2.log.info(`[magic-mail] [SUCCESS] Found version by documentId: ${version2.documentId}`);
6028
+ return version2;
6029
+ }
6030
+ }
6031
+ const numericId = Number(idOrDocumentId);
6032
+ if (!isNaN(numericId)) {
6033
+ strapi2.log.info(`[magic-mail] [FALLBACK] Trying internal db id for version: ${numericId}`);
6034
+ const version2 = await strapi2.entityService.findOne(EMAIL_TEMPLATE_VERSION_UID, numericId, {
6035
+ populate: { template: true }
6036
+ });
6037
+ if (version2) {
6038
+ strapi2.log.info(`[magic-mail] [SUCCESS] Found version by internal id ${numericId}: documentId=${version2.documentId}`);
6039
+ return version2;
6040
+ }
6041
+ }
6042
+ strapi2.log.warn(`[magic-mail] [WARNING] Version with ID ${idOrDocumentId} not found`);
6043
+ return null;
6044
+ },
6014
6045
  /**
6015
6046
  * Create new template with automatic initial version
6016
6047
  */
@@ -6218,27 +6249,24 @@ function requireEmailDesigner() {
6218
6249
  },
6219
6250
  /**
6220
6251
  * Restore template from a specific version
6221
- * @param {string|number} idOrDocumentId - Either numeric id or documentId of template
6222
- * @param {string} versionDocumentId - documentId of version to restore
6252
+ * @param {string|number} templateIdOrDocumentId - Either numeric id or documentId of template
6253
+ * @param {string|number} versionIdOrDocumentId - Either numeric id or documentId of version
6223
6254
  */
6224
- async restoreVersion(idOrDocumentId, versionDocumentId) {
6225
- strapi2.log.info(`[magic-mail] [RESTORE] Restoring template ${idOrDocumentId} from version ${versionDocumentId}`);
6226
- const template = await this.findOne(idOrDocumentId);
6255
+ async restoreVersion(templateIdOrDocumentId, versionIdOrDocumentId) {
6256
+ strapi2.log.info(`[magic-mail] [RESTORE] Restoring template ${templateIdOrDocumentId} from version ${versionIdOrDocumentId}`);
6257
+ const template = await this.findOne(templateIdOrDocumentId);
6227
6258
  if (!template) {
6228
6259
  throw new Error("Template not found");
6229
6260
  }
6230
- const actualDocumentId = template.documentId;
6231
- const version2 = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findOne({
6232
- documentId: versionDocumentId,
6233
- populate: { template: true }
6234
- });
6261
+ const actualTemplateDocumentId = template.documentId;
6262
+ const version2 = await this.findVersionById(versionIdOrDocumentId);
6235
6263
  if (!version2) {
6236
6264
  throw new Error("Version not found");
6237
6265
  }
6238
- if (version2.template?.documentId !== actualDocumentId) {
6266
+ if (version2.template?.documentId !== actualTemplateDocumentId) {
6239
6267
  throw new Error("Version does not belong to this template");
6240
6268
  }
6241
- const restored = await this.update(actualDocumentId, {
6269
+ const restored = await this.update(actualTemplateDocumentId, {
6242
6270
  name: version2.name,
6243
6271
  subject: version2.subject,
6244
6272
  design: version2.design,
@@ -6251,28 +6279,25 @@ function requireEmailDesigner() {
6251
6279
  },
6252
6280
  /**
6253
6281
  * Delete a single version
6254
- * @param {string|number} idOrDocumentId - Either numeric id or documentId of template
6255
- * @param {string} versionDocumentId - documentId of version to delete
6282
+ * @param {string|number} templateIdOrDocumentId - Either numeric id or documentId of template
6283
+ * @param {string|number} versionIdOrDocumentId - Either numeric id or documentId of version
6256
6284
  */
6257
- async deleteVersion(idOrDocumentId, versionDocumentId) {
6258
- strapi2.log.info(`[magic-mail] [DELETE] Deleting version ${versionDocumentId}`);
6259
- const template = await this.findOne(idOrDocumentId);
6285
+ async deleteVersion(templateIdOrDocumentId, versionIdOrDocumentId) {
6286
+ strapi2.log.info(`[magic-mail] [DELETE] Deleting version ${versionIdOrDocumentId}`);
6287
+ const template = await this.findOne(templateIdOrDocumentId);
6260
6288
  if (!template) {
6261
6289
  throw new Error("Template not found");
6262
6290
  }
6263
- const actualDocumentId = template.documentId;
6264
- const version2 = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findOne({
6265
- documentId: versionDocumentId,
6266
- populate: { template: true }
6267
- });
6291
+ const actualTemplateDocumentId = template.documentId;
6292
+ const version2 = await this.findVersionById(versionIdOrDocumentId);
6268
6293
  if (!version2) {
6269
6294
  throw new Error("Version not found");
6270
6295
  }
6271
- if (version2.template?.documentId !== actualDocumentId) {
6296
+ if (version2.template?.documentId !== actualTemplateDocumentId) {
6272
6297
  throw new Error("Version does not belong to this template");
6273
6298
  }
6274
6299
  await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).delete({
6275
- documentId: versionDocumentId
6300
+ documentId: version2.documentId
6276
6301
  });
6277
6302
  strapi2.log.info(`[magic-mail] [SUCCESS] Version v${version2.versionNumber} deleted`);
6278
6303
  return { success: true, message: "Version deleted" };
@@ -5533,7 +5533,7 @@ function requireOauth() {
5533
5533
  });
5534
5534
  return oauth;
5535
5535
  }
5536
- const version = "2.3.7";
5536
+ const version = "2.3.8";
5537
5537
  const require$$2 = {
5538
5538
  version
5539
5539
  };
@@ -6001,6 +6001,37 @@ function requireEmailDesigner() {
6001
6001
  });
6002
6002
  return results.length > 0 ? results[0] : null;
6003
6003
  },
6004
+ /**
6005
+ * Get version by numeric ID or documentId
6006
+ * First tries documentId, then falls back to internal database id via entityService
6007
+ */
6008
+ async findVersionById(idOrDocumentId) {
6009
+ strapi2.log.info(`[magic-mail] [LOOKUP] Finding version by ID: ${idOrDocumentId}`);
6010
+ const isNumericId = /^\d+$/.test(String(idOrDocumentId));
6011
+ if (!isNumericId) {
6012
+ const version2 = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findOne({
6013
+ documentId: String(idOrDocumentId),
6014
+ populate: { template: true }
6015
+ });
6016
+ if (version2) {
6017
+ strapi2.log.info(`[magic-mail] [SUCCESS] Found version by documentId: ${version2.documentId}`);
6018
+ return version2;
6019
+ }
6020
+ }
6021
+ const numericId = Number(idOrDocumentId);
6022
+ if (!isNaN(numericId)) {
6023
+ strapi2.log.info(`[magic-mail] [FALLBACK] Trying internal db id for version: ${numericId}`);
6024
+ const version2 = await strapi2.entityService.findOne(EMAIL_TEMPLATE_VERSION_UID, numericId, {
6025
+ populate: { template: true }
6026
+ });
6027
+ if (version2) {
6028
+ strapi2.log.info(`[magic-mail] [SUCCESS] Found version by internal id ${numericId}: documentId=${version2.documentId}`);
6029
+ return version2;
6030
+ }
6031
+ }
6032
+ strapi2.log.warn(`[magic-mail] [WARNING] Version with ID ${idOrDocumentId} not found`);
6033
+ return null;
6034
+ },
6004
6035
  /**
6005
6036
  * Create new template with automatic initial version
6006
6037
  */
@@ -6208,27 +6239,24 @@ function requireEmailDesigner() {
6208
6239
  },
6209
6240
  /**
6210
6241
  * Restore template from a specific version
6211
- * @param {string|number} idOrDocumentId - Either numeric id or documentId of template
6212
- * @param {string} versionDocumentId - documentId of version to restore
6242
+ * @param {string|number} templateIdOrDocumentId - Either numeric id or documentId of template
6243
+ * @param {string|number} versionIdOrDocumentId - Either numeric id or documentId of version
6213
6244
  */
6214
- async restoreVersion(idOrDocumentId, versionDocumentId) {
6215
- strapi2.log.info(`[magic-mail] [RESTORE] Restoring template ${idOrDocumentId} from version ${versionDocumentId}`);
6216
- const template = await this.findOne(idOrDocumentId);
6245
+ async restoreVersion(templateIdOrDocumentId, versionIdOrDocumentId) {
6246
+ strapi2.log.info(`[magic-mail] [RESTORE] Restoring template ${templateIdOrDocumentId} from version ${versionIdOrDocumentId}`);
6247
+ const template = await this.findOne(templateIdOrDocumentId);
6217
6248
  if (!template) {
6218
6249
  throw new Error("Template not found");
6219
6250
  }
6220
- const actualDocumentId = template.documentId;
6221
- const version2 = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findOne({
6222
- documentId: versionDocumentId,
6223
- populate: { template: true }
6224
- });
6251
+ const actualTemplateDocumentId = template.documentId;
6252
+ const version2 = await this.findVersionById(versionIdOrDocumentId);
6225
6253
  if (!version2) {
6226
6254
  throw new Error("Version not found");
6227
6255
  }
6228
- if (version2.template?.documentId !== actualDocumentId) {
6256
+ if (version2.template?.documentId !== actualTemplateDocumentId) {
6229
6257
  throw new Error("Version does not belong to this template");
6230
6258
  }
6231
- const restored = await this.update(actualDocumentId, {
6259
+ const restored = await this.update(actualTemplateDocumentId, {
6232
6260
  name: version2.name,
6233
6261
  subject: version2.subject,
6234
6262
  design: version2.design,
@@ -6241,28 +6269,25 @@ function requireEmailDesigner() {
6241
6269
  },
6242
6270
  /**
6243
6271
  * Delete a single version
6244
- * @param {string|number} idOrDocumentId - Either numeric id or documentId of template
6245
- * @param {string} versionDocumentId - documentId of version to delete
6272
+ * @param {string|number} templateIdOrDocumentId - Either numeric id or documentId of template
6273
+ * @param {string|number} versionIdOrDocumentId - Either numeric id or documentId of version
6246
6274
  */
6247
- async deleteVersion(idOrDocumentId, versionDocumentId) {
6248
- strapi2.log.info(`[magic-mail] [DELETE] Deleting version ${versionDocumentId}`);
6249
- const template = await this.findOne(idOrDocumentId);
6275
+ async deleteVersion(templateIdOrDocumentId, versionIdOrDocumentId) {
6276
+ strapi2.log.info(`[magic-mail] [DELETE] Deleting version ${versionIdOrDocumentId}`);
6277
+ const template = await this.findOne(templateIdOrDocumentId);
6250
6278
  if (!template) {
6251
6279
  throw new Error("Template not found");
6252
6280
  }
6253
- const actualDocumentId = template.documentId;
6254
- const version2 = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findOne({
6255
- documentId: versionDocumentId,
6256
- populate: { template: true }
6257
- });
6281
+ const actualTemplateDocumentId = template.documentId;
6282
+ const version2 = await this.findVersionById(versionIdOrDocumentId);
6258
6283
  if (!version2) {
6259
6284
  throw new Error("Version not found");
6260
6285
  }
6261
- if (version2.template?.documentId !== actualDocumentId) {
6286
+ if (version2.template?.documentId !== actualTemplateDocumentId) {
6262
6287
  throw new Error("Version does not belong to this template");
6263
6288
  }
6264
6289
  await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).delete({
6265
- documentId: versionDocumentId
6290
+ documentId: version2.documentId
6266
6291
  });
6267
6292
  strapi2.log.info(`[magic-mail] [SUCCESS] Version v${version2.versionNumber} deleted`);
6268
6293
  return { success: true, message: "Version deleted" };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.3.8",
2
+ "version": "2.3.9",
3
3
  "keywords": [
4
4
  "strapi",
5
5
  "strapi-plugin",