strapi-plugin-magic-mail 2.3.1 → 2.3.2

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.
@@ -5544,7 +5544,7 @@ function requireOauth() {
5544
5544
  });
5545
5545
  return oauth;
5546
5546
  }
5547
- const version = "2.3.0";
5547
+ const version = "2.3.1";
5548
5548
  const require$$2 = {
5549
5549
  version
5550
5550
  };
@@ -6331,31 +6331,71 @@ function requireEmailDesigner() {
6331
6331
  },
6332
6332
  /**
6333
6333
  * Import templates from JSON
6334
+ * Supports both magic-mail export format and strapi-plugin-email-designer-5 format
6334
6335
  */
6335
6336
  async importTemplates(templates) {
6336
6337
  strapi2.log.info(`[magic-mail] [IMPORT] Importing ${templates.length} templates...`);
6337
6338
  const results = [];
6338
- for (const templateData of templates) {
6339
+ for (const rawData of templates) {
6339
6340
  try {
6341
+ const templateData = this.normalizeImportData(rawData);
6342
+ strapi2.log.info(`[magic-mail] [IMPORT] Processing: "${templateData.name}" (ref: ${templateData.templateReferenceId})`);
6340
6343
  const existing = await this.findByReferenceId(templateData.templateReferenceId);
6341
6344
  if (existing) {
6342
6345
  const updated = await this.update(existing.documentId, templateData);
6343
6346
  results.push({ success: true, action: "updated", template: updated });
6347
+ strapi2.log.info(`[magic-mail] [SUCCESS] Updated: "${templateData.name}"`);
6344
6348
  } else {
6345
6349
  const created = await this.create(templateData);
6346
6350
  results.push({ success: true, action: "created", template: created });
6351
+ strapi2.log.info(`[magic-mail] [SUCCESS] Created: "${templateData.name}"`);
6347
6352
  }
6348
6353
  } catch (error) {
6354
+ strapi2.log.error(`[magic-mail] [ERROR] Import failed for "${rawData.name}": ${error.message}`);
6349
6355
  results.push({
6350
6356
  success: false,
6351
6357
  action: "failed",
6352
6358
  error: error.message,
6353
- templateName: templateData.name
6359
+ templateName: rawData.name
6354
6360
  });
6355
6361
  }
6356
6362
  }
6363
+ const successful = results.filter((r) => r.success).length;
6364
+ const failed = results.filter((r) => !r.success).length;
6365
+ strapi2.log.info(`[magic-mail] [IMPORT] Complete: ${successful} successful, ${failed} failed`);
6357
6366
  return results;
6358
6367
  },
6368
+ /**
6369
+ * Normalize import data from different export formats
6370
+ * Supports: magic-mail, strapi-plugin-email-designer-5, and generic formats
6371
+ */
6372
+ normalizeImportData(rawData) {
6373
+ const isActive = rawData.isActive !== void 0 ? rawData.isActive : rawData.enabled !== void 0 ? rawData.enabled : true;
6374
+ const templateReferenceId = rawData.templateReferenceId || rawData.referenceId || Date.now() + Math.floor(Math.random() * 1e3);
6375
+ const category = rawData.category || "custom";
6376
+ let tags = rawData.tags;
6377
+ if (typeof tags === "string") {
6378
+ try {
6379
+ tags = JSON.parse(tags);
6380
+ } catch (e) {
6381
+ tags = tags.split(",").map((t) => t.trim()).filter(Boolean);
6382
+ }
6383
+ }
6384
+ if (!Array.isArray(tags)) {
6385
+ tags = [];
6386
+ }
6387
+ return {
6388
+ templateReferenceId,
6389
+ name: rawData.name || "Imported Template",
6390
+ subject: rawData.subject || "",
6391
+ design: rawData.design || null,
6392
+ bodyHtml: rawData.bodyHtml || rawData.message || "",
6393
+ bodyText: rawData.bodyText || "",
6394
+ category,
6395
+ tags,
6396
+ isActive
6397
+ };
6398
+ },
6359
6399
  // ============================================================
6360
6400
  // STATISTICS
6361
6401
  // ============================================================
@@ -5534,7 +5534,7 @@ function requireOauth() {
5534
5534
  });
5535
5535
  return oauth;
5536
5536
  }
5537
- const version = "2.3.0";
5537
+ const version = "2.3.1";
5538
5538
  const require$$2 = {
5539
5539
  version
5540
5540
  };
@@ -6321,31 +6321,71 @@ function requireEmailDesigner() {
6321
6321
  },
6322
6322
  /**
6323
6323
  * Import templates from JSON
6324
+ * Supports both magic-mail export format and strapi-plugin-email-designer-5 format
6324
6325
  */
6325
6326
  async importTemplates(templates) {
6326
6327
  strapi2.log.info(`[magic-mail] [IMPORT] Importing ${templates.length} templates...`);
6327
6328
  const results = [];
6328
- for (const templateData of templates) {
6329
+ for (const rawData of templates) {
6329
6330
  try {
6331
+ const templateData = this.normalizeImportData(rawData);
6332
+ strapi2.log.info(`[magic-mail] [IMPORT] Processing: "${templateData.name}" (ref: ${templateData.templateReferenceId})`);
6330
6333
  const existing = await this.findByReferenceId(templateData.templateReferenceId);
6331
6334
  if (existing) {
6332
6335
  const updated = await this.update(existing.documentId, templateData);
6333
6336
  results.push({ success: true, action: "updated", template: updated });
6337
+ strapi2.log.info(`[magic-mail] [SUCCESS] Updated: "${templateData.name}"`);
6334
6338
  } else {
6335
6339
  const created = await this.create(templateData);
6336
6340
  results.push({ success: true, action: "created", template: created });
6341
+ strapi2.log.info(`[magic-mail] [SUCCESS] Created: "${templateData.name}"`);
6337
6342
  }
6338
6343
  } catch (error) {
6344
+ strapi2.log.error(`[magic-mail] [ERROR] Import failed for "${rawData.name}": ${error.message}`);
6339
6345
  results.push({
6340
6346
  success: false,
6341
6347
  action: "failed",
6342
6348
  error: error.message,
6343
- templateName: templateData.name
6349
+ templateName: rawData.name
6344
6350
  });
6345
6351
  }
6346
6352
  }
6353
+ const successful = results.filter((r) => r.success).length;
6354
+ const failed = results.filter((r) => !r.success).length;
6355
+ strapi2.log.info(`[magic-mail] [IMPORT] Complete: ${successful} successful, ${failed} failed`);
6347
6356
  return results;
6348
6357
  },
6358
+ /**
6359
+ * Normalize import data from different export formats
6360
+ * Supports: magic-mail, strapi-plugin-email-designer-5, and generic formats
6361
+ */
6362
+ normalizeImportData(rawData) {
6363
+ const isActive = rawData.isActive !== void 0 ? rawData.isActive : rawData.enabled !== void 0 ? rawData.enabled : true;
6364
+ const templateReferenceId = rawData.templateReferenceId || rawData.referenceId || Date.now() + Math.floor(Math.random() * 1e3);
6365
+ const category = rawData.category || "custom";
6366
+ let tags = rawData.tags;
6367
+ if (typeof tags === "string") {
6368
+ try {
6369
+ tags = JSON.parse(tags);
6370
+ } catch (e) {
6371
+ tags = tags.split(",").map((t) => t.trim()).filter(Boolean);
6372
+ }
6373
+ }
6374
+ if (!Array.isArray(tags)) {
6375
+ tags = [];
6376
+ }
6377
+ return {
6378
+ templateReferenceId,
6379
+ name: rawData.name || "Imported Template",
6380
+ subject: rawData.subject || "",
6381
+ design: rawData.design || null,
6382
+ bodyHtml: rawData.bodyHtml || rawData.message || "",
6383
+ bodyText: rawData.bodyText || "",
6384
+ category,
6385
+ tags,
6386
+ isActive
6387
+ };
6388
+ },
6349
6389
  // ============================================================
6350
6390
  // STATISTICS
6351
6391
  // ============================================================
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.3.1",
2
+ "version": "2.3.2",
3
3
  "keywords": [
4
4
  "strapi",
5
5
  "strapi-plugin",