strapi-plugin-magic-mail 2.3.1 → 2.3.3

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.
@@ -17,8 +17,8 @@ const require$$2__default = /* @__PURE__ */ _interopDefault(require$$2$2);
17
17
  const require$$0__default$3 = /* @__PURE__ */ _interopDefault(require$$0$4);
18
18
  const require$$1__default$2 = /* @__PURE__ */ _interopDefault(require$$1$3);
19
19
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
20
- function getDefaultExportFromCjs(x2) {
21
- return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
20
+ function getDefaultExportFromCjs(x) {
21
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
22
22
  }
23
23
  var register;
24
24
  var hasRequiredRegister;
@@ -1835,8 +1835,7 @@ function requireEmailDesigner$1() {
1835
1835
  */
1836
1836
  async renderTemplate(ctx) {
1837
1837
  try {
1838
- const { templateReferenceId } = ct;
1839
- x.params;
1838
+ const { templateReferenceId } = ctx.params;
1840
1839
  const { data } = ctx.request.body;
1841
1840
  const rendered = await strapi2.plugin("magic-mail").service("email-designer").renderTemplate(parseInt(templateReferenceId), data);
1842
1841
  return ctx.send({
@@ -5544,7 +5543,7 @@ function requireOauth() {
5544
5543
  });
5545
5544
  return oauth;
5546
5545
  }
5547
- const version = "2.3.0";
5546
+ const version = "2.3.2";
5548
5547
  const require$$2 = {
5549
5548
  version
5550
5549
  };
@@ -5961,11 +5960,17 @@ function requireEmailDesigner() {
5961
5960
  });
5962
5961
  },
5963
5962
  /**
5964
- * Get template by ID (documentId) with populated versions
5963
+ * Get template by ID (documentId or numeric id) with populated versions
5964
+ * Supports both documentId (string) and numeric id for backward compatibility
5965
5965
  */
5966
- async findOne(documentId) {
5966
+ async findOne(idOrDocumentId) {
5967
+ const isNumericId = /^\d+$/.test(String(idOrDocumentId));
5968
+ if (isNumericId) {
5969
+ const result = await this.findById(Number(idOrDocumentId));
5970
+ if (result) return result;
5971
+ }
5967
5972
  return strapi2.documents(EMAIL_TEMPLATE_UID).findOne({
5968
- documentId,
5973
+ documentId: String(idOrDocumentId),
5969
5974
  populate: ["versions"]
5970
5975
  });
5971
5976
  },
@@ -6164,7 +6169,7 @@ function requireEmailDesigner() {
6164
6169
  * Get all versions for a template
6165
6170
  */
6166
6171
  async getVersions(templateDocumentId) {
6167
- strapi2.log.info(`[magic-mail] 📜 Fetching versions for template documentId: ${templateDocumentId}`);
6172
+ strapi2.log.info(`[magic-mail] [VERSION] Fetching versions for template documentId: ${templateDocumentId}`);
6168
6173
  const template = await strapi2.documents(EMAIL_TEMPLATE_UID).findOne({
6169
6174
  documentId: templateDocumentId,
6170
6175
  populate: ["versions"]
@@ -6331,31 +6336,71 @@ function requireEmailDesigner() {
6331
6336
  },
6332
6337
  /**
6333
6338
  * Import templates from JSON
6339
+ * Supports both magic-mail export format and strapi-plugin-email-designer-5 format
6334
6340
  */
6335
6341
  async importTemplates(templates) {
6336
6342
  strapi2.log.info(`[magic-mail] [IMPORT] Importing ${templates.length} templates...`);
6337
6343
  const results = [];
6338
- for (const templateData of templates) {
6344
+ for (const rawData of templates) {
6339
6345
  try {
6346
+ const templateData = this.normalizeImportData(rawData);
6347
+ strapi2.log.info(`[magic-mail] [IMPORT] Processing: "${templateData.name}" (ref: ${templateData.templateReferenceId})`);
6340
6348
  const existing = await this.findByReferenceId(templateData.templateReferenceId);
6341
6349
  if (existing) {
6342
6350
  const updated = await this.update(existing.documentId, templateData);
6343
6351
  results.push({ success: true, action: "updated", template: updated });
6352
+ strapi2.log.info(`[magic-mail] [SUCCESS] Updated: "${templateData.name}"`);
6344
6353
  } else {
6345
6354
  const created = await this.create(templateData);
6346
6355
  results.push({ success: true, action: "created", template: created });
6356
+ strapi2.log.info(`[magic-mail] [SUCCESS] Created: "${templateData.name}"`);
6347
6357
  }
6348
6358
  } catch (error) {
6359
+ strapi2.log.error(`[magic-mail] [ERROR] Import failed for "${rawData.name}": ${error.message}`);
6349
6360
  results.push({
6350
6361
  success: false,
6351
6362
  action: "failed",
6352
6363
  error: error.message,
6353
- templateName: templateData.name
6364
+ templateName: rawData.name
6354
6365
  });
6355
6366
  }
6356
6367
  }
6368
+ const successful = results.filter((r) => r.success).length;
6369
+ const failed = results.filter((r) => !r.success).length;
6370
+ strapi2.log.info(`[magic-mail] [IMPORT] Complete: ${successful} successful, ${failed} failed`);
6357
6371
  return results;
6358
6372
  },
6373
+ /**
6374
+ * Normalize import data from different export formats
6375
+ * Supports: magic-mail, strapi-plugin-email-designer-5, and generic formats
6376
+ */
6377
+ normalizeImportData(rawData) {
6378
+ const isActive = rawData.isActive !== void 0 ? rawData.isActive : rawData.enabled !== void 0 ? rawData.enabled : true;
6379
+ const templateReferenceId = rawData.templateReferenceId || rawData.referenceId || Date.now() + Math.floor(Math.random() * 1e3);
6380
+ const category = rawData.category || "custom";
6381
+ let tags = rawData.tags;
6382
+ if (typeof tags === "string") {
6383
+ try {
6384
+ tags = JSON.parse(tags);
6385
+ } catch (e) {
6386
+ tags = tags.split(",").map((t) => t.trim()).filter(Boolean);
6387
+ }
6388
+ }
6389
+ if (!Array.isArray(tags)) {
6390
+ tags = [];
6391
+ }
6392
+ return {
6393
+ templateReferenceId,
6394
+ name: rawData.name || "Imported Template",
6395
+ subject: rawData.subject || "",
6396
+ design: rawData.design || null,
6397
+ bodyHtml: rawData.bodyHtml || rawData.message || "",
6398
+ bodyText: rawData.bodyText || "",
6399
+ category,
6400
+ tags,
6401
+ isActive
6402
+ };
6403
+ },
6359
6404
  // ============================================================
6360
6405
  // STATISTICS
6361
6406
  // ============================================================
@@ -7,8 +7,8 @@ import require$$2$2 from "decode-html";
7
7
  import require$$0$4 from "path";
8
8
  import require$$1$3 from "fs";
9
9
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
10
- function getDefaultExportFromCjs(x2) {
11
- return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
10
+ function getDefaultExportFromCjs(x) {
11
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
12
12
  }
13
13
  var register;
14
14
  var hasRequiredRegister;
@@ -1825,8 +1825,7 @@ function requireEmailDesigner$1() {
1825
1825
  */
1826
1826
  async renderTemplate(ctx) {
1827
1827
  try {
1828
- const { templateReferenceId } = ct;
1829
- x.params;
1828
+ const { templateReferenceId } = ctx.params;
1830
1829
  const { data } = ctx.request.body;
1831
1830
  const rendered = await strapi2.plugin("magic-mail").service("email-designer").renderTemplate(parseInt(templateReferenceId), data);
1832
1831
  return ctx.send({
@@ -5534,7 +5533,7 @@ function requireOauth() {
5534
5533
  });
5535
5534
  return oauth;
5536
5535
  }
5537
- const version = "2.3.0";
5536
+ const version = "2.3.2";
5538
5537
  const require$$2 = {
5539
5538
  version
5540
5539
  };
@@ -5951,11 +5950,17 @@ function requireEmailDesigner() {
5951
5950
  });
5952
5951
  },
5953
5952
  /**
5954
- * Get template by ID (documentId) with populated versions
5953
+ * Get template by ID (documentId or numeric id) with populated versions
5954
+ * Supports both documentId (string) and numeric id for backward compatibility
5955
5955
  */
5956
- async findOne(documentId) {
5956
+ async findOne(idOrDocumentId) {
5957
+ const isNumericId = /^\d+$/.test(String(idOrDocumentId));
5958
+ if (isNumericId) {
5959
+ const result = await this.findById(Number(idOrDocumentId));
5960
+ if (result) return result;
5961
+ }
5957
5962
  return strapi2.documents(EMAIL_TEMPLATE_UID).findOne({
5958
- documentId,
5963
+ documentId: String(idOrDocumentId),
5959
5964
  populate: ["versions"]
5960
5965
  });
5961
5966
  },
@@ -6154,7 +6159,7 @@ function requireEmailDesigner() {
6154
6159
  * Get all versions for a template
6155
6160
  */
6156
6161
  async getVersions(templateDocumentId) {
6157
- strapi2.log.info(`[magic-mail] 📜 Fetching versions for template documentId: ${templateDocumentId}`);
6162
+ strapi2.log.info(`[magic-mail] [VERSION] Fetching versions for template documentId: ${templateDocumentId}`);
6158
6163
  const template = await strapi2.documents(EMAIL_TEMPLATE_UID).findOne({
6159
6164
  documentId: templateDocumentId,
6160
6165
  populate: ["versions"]
@@ -6321,31 +6326,71 @@ function requireEmailDesigner() {
6321
6326
  },
6322
6327
  /**
6323
6328
  * Import templates from JSON
6329
+ * Supports both magic-mail export format and strapi-plugin-email-designer-5 format
6324
6330
  */
6325
6331
  async importTemplates(templates) {
6326
6332
  strapi2.log.info(`[magic-mail] [IMPORT] Importing ${templates.length} templates...`);
6327
6333
  const results = [];
6328
- for (const templateData of templates) {
6334
+ for (const rawData of templates) {
6329
6335
  try {
6336
+ const templateData = this.normalizeImportData(rawData);
6337
+ strapi2.log.info(`[magic-mail] [IMPORT] Processing: "${templateData.name}" (ref: ${templateData.templateReferenceId})`);
6330
6338
  const existing = await this.findByReferenceId(templateData.templateReferenceId);
6331
6339
  if (existing) {
6332
6340
  const updated = await this.update(existing.documentId, templateData);
6333
6341
  results.push({ success: true, action: "updated", template: updated });
6342
+ strapi2.log.info(`[magic-mail] [SUCCESS] Updated: "${templateData.name}"`);
6334
6343
  } else {
6335
6344
  const created = await this.create(templateData);
6336
6345
  results.push({ success: true, action: "created", template: created });
6346
+ strapi2.log.info(`[magic-mail] [SUCCESS] Created: "${templateData.name}"`);
6337
6347
  }
6338
6348
  } catch (error) {
6349
+ strapi2.log.error(`[magic-mail] [ERROR] Import failed for "${rawData.name}": ${error.message}`);
6339
6350
  results.push({
6340
6351
  success: false,
6341
6352
  action: "failed",
6342
6353
  error: error.message,
6343
- templateName: templateData.name
6354
+ templateName: rawData.name
6344
6355
  });
6345
6356
  }
6346
6357
  }
6358
+ const successful = results.filter((r) => r.success).length;
6359
+ const failed = results.filter((r) => !r.success).length;
6360
+ strapi2.log.info(`[magic-mail] [IMPORT] Complete: ${successful} successful, ${failed} failed`);
6347
6361
  return results;
6348
6362
  },
6363
+ /**
6364
+ * Normalize import data from different export formats
6365
+ * Supports: magic-mail, strapi-plugin-email-designer-5, and generic formats
6366
+ */
6367
+ normalizeImportData(rawData) {
6368
+ const isActive = rawData.isActive !== void 0 ? rawData.isActive : rawData.enabled !== void 0 ? rawData.enabled : true;
6369
+ const templateReferenceId = rawData.templateReferenceId || rawData.referenceId || Date.now() + Math.floor(Math.random() * 1e3);
6370
+ const category = rawData.category || "custom";
6371
+ let tags = rawData.tags;
6372
+ if (typeof tags === "string") {
6373
+ try {
6374
+ tags = JSON.parse(tags);
6375
+ } catch (e) {
6376
+ tags = tags.split(",").map((t) => t.trim()).filter(Boolean);
6377
+ }
6378
+ }
6379
+ if (!Array.isArray(tags)) {
6380
+ tags = [];
6381
+ }
6382
+ return {
6383
+ templateReferenceId,
6384
+ name: rawData.name || "Imported Template",
6385
+ subject: rawData.subject || "",
6386
+ design: rawData.design || null,
6387
+ bodyHtml: rawData.bodyHtml || rawData.message || "",
6388
+ bodyText: rawData.bodyText || "",
6389
+ category,
6390
+ tags,
6391
+ isActive
6392
+ };
6393
+ },
6349
6394
  // ============================================================
6350
6395
  // STATISTICS
6351
6396
  // ============================================================
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.3.1",
2
+ "version": "2.3.3",
3
3
  "keywords": [
4
4
  "strapi",
5
5
  "strapi-plugin",