strapi-plugin-magic-mail 2.3.2 → 2.3.4
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/dist/server/index.js +70 -46
- package/dist/server/index.mjs +70 -46
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -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(
|
|
21
|
-
return
|
|
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 } =
|
|
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.
|
|
5546
|
+
const version = "2.3.3";
|
|
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(
|
|
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
|
},
|
|
@@ -6034,18 +6039,21 @@ function requireEmailDesigner() {
|
|
|
6034
6039
|
},
|
|
6035
6040
|
/**
|
|
6036
6041
|
* Update template with automatic version snapshot
|
|
6042
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId
|
|
6043
|
+
* @param {Object} data - Update data
|
|
6037
6044
|
*/
|
|
6038
|
-
async update(
|
|
6039
|
-
strapi2.log.info(`[magic-mail] [UPDATE] Updating template
|
|
6040
|
-
const template = await this.findOne(
|
|
6045
|
+
async update(idOrDocumentId, data) {
|
|
6046
|
+
strapi2.log.info(`[magic-mail] [UPDATE] Updating template: ${idOrDocumentId}`);
|
|
6047
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6041
6048
|
if (!template) {
|
|
6042
6049
|
throw new Error("Template not found");
|
|
6043
6050
|
}
|
|
6044
|
-
|
|
6051
|
+
const actualDocumentId = template.documentId;
|
|
6052
|
+
strapi2.log.info(`[magic-mail] [INFO] Found template: documentId=${actualDocumentId}, name="${template.name}"`);
|
|
6045
6053
|
const hasVersioning = await strapi2.plugin("magic-mail").service("license-guard").hasFeature("email-designer-versioning");
|
|
6046
6054
|
if (hasVersioning) {
|
|
6047
6055
|
strapi2.log.info("[magic-mail] [SAVE] Creating version snapshot before update...");
|
|
6048
|
-
await this.createVersion(
|
|
6056
|
+
await this.createVersion(actualDocumentId, {
|
|
6049
6057
|
name: template.name,
|
|
6050
6058
|
subject: template.subject,
|
|
6051
6059
|
design: template.design,
|
|
@@ -6061,7 +6069,7 @@ function requireEmailDesigner() {
|
|
|
6061
6069
|
strapi2.log.warn("[magic-mail] [WARNING] Removed versions field from update data");
|
|
6062
6070
|
}
|
|
6063
6071
|
const updated = await strapi2.documents(EMAIL_TEMPLATE_UID).update({
|
|
6064
|
-
documentId,
|
|
6072
|
+
documentId: actualDocumentId,
|
|
6065
6073
|
data: updateData
|
|
6066
6074
|
});
|
|
6067
6075
|
strapi2.log.info(`[magic-mail] [SUCCESS] Template updated: documentId=${updated.documentId}`);
|
|
@@ -6069,42 +6077,47 @@ function requireEmailDesigner() {
|
|
|
6069
6077
|
},
|
|
6070
6078
|
/**
|
|
6071
6079
|
* Delete template and all its versions
|
|
6080
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId
|
|
6072
6081
|
*/
|
|
6073
|
-
async delete(
|
|
6074
|
-
strapi2.log.info(`[magic-mail] [DELETE]
|
|
6075
|
-
const template = await this.findOne(
|
|
6082
|
+
async delete(idOrDocumentId) {
|
|
6083
|
+
strapi2.log.info(`[magic-mail] [DELETE] Deleting template: ${idOrDocumentId}`);
|
|
6084
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6076
6085
|
if (!template) {
|
|
6077
6086
|
throw new Error("Template not found");
|
|
6078
6087
|
}
|
|
6079
|
-
|
|
6088
|
+
const actualDocumentId = template.documentId;
|
|
6089
|
+
strapi2.log.info(`[magic-mail] [DELETE] Template: documentId=${actualDocumentId}, name="${template.name}"`);
|
|
6080
6090
|
const allVersions = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findMany({
|
|
6081
6091
|
filters: {
|
|
6082
6092
|
template: {
|
|
6083
|
-
documentId:
|
|
6093
|
+
documentId: actualDocumentId
|
|
6084
6094
|
}
|
|
6085
6095
|
}
|
|
6086
6096
|
});
|
|
6087
|
-
strapi2.log.info(`[magic-mail] [DELETE]
|
|
6097
|
+
strapi2.log.info(`[magic-mail] [DELETE] Found ${allVersions.length} versions to delete`);
|
|
6088
6098
|
for (const version2 of allVersions) {
|
|
6089
6099
|
try {
|
|
6090
6100
|
await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).delete({
|
|
6091
6101
|
documentId: version2.documentId
|
|
6092
6102
|
});
|
|
6093
|
-
strapi2.log.info(`[magic-mail] [DELETE]
|
|
6103
|
+
strapi2.log.info(`[magic-mail] [DELETE] Deleted version #${version2.versionNumber}`);
|
|
6094
6104
|
} catch (versionError) {
|
|
6095
|
-
strapi2.log.warn(`[magic-mail] [WARNING]
|
|
6105
|
+
strapi2.log.warn(`[magic-mail] [WARNING] Failed to delete version: ${versionError.message}`);
|
|
6096
6106
|
}
|
|
6097
6107
|
}
|
|
6098
|
-
const result = await strapi2.documents(EMAIL_TEMPLATE_UID).delete({
|
|
6108
|
+
const result = await strapi2.documents(EMAIL_TEMPLATE_UID).delete({
|
|
6109
|
+
documentId: actualDocumentId
|
|
6110
|
+
});
|
|
6099
6111
|
strapi2.log.info(`[magic-mail] [SUCCESS] Template "${template.name}" and ${allVersions.length} versions deleted`);
|
|
6100
6112
|
return result;
|
|
6101
6113
|
},
|
|
6102
6114
|
/**
|
|
6103
6115
|
* Duplicate template
|
|
6116
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId
|
|
6104
6117
|
*/
|
|
6105
|
-
async duplicate(
|
|
6106
|
-
strapi2.log.info(`[magic-mail] [INFO] Duplicating template
|
|
6107
|
-
const original = await this.findOne(
|
|
6118
|
+
async duplicate(idOrDocumentId) {
|
|
6119
|
+
strapi2.log.info(`[magic-mail] [INFO] Duplicating template: ${idOrDocumentId}`);
|
|
6120
|
+
const original = await this.findOne(idOrDocumentId);
|
|
6108
6121
|
if (!original) {
|
|
6109
6122
|
throw new Error("Template not found");
|
|
6110
6123
|
}
|
|
@@ -6162,16 +6175,15 @@ function requireEmailDesigner() {
|
|
|
6162
6175
|
},
|
|
6163
6176
|
/**
|
|
6164
6177
|
* Get all versions for a template
|
|
6178
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId
|
|
6165
6179
|
*/
|
|
6166
|
-
async getVersions(
|
|
6167
|
-
strapi2.log.info(`[magic-mail]
|
|
6168
|
-
const template = await
|
|
6169
|
-
documentId: templateDocumentId,
|
|
6170
|
-
populate: ["versions"]
|
|
6171
|
-
});
|
|
6180
|
+
async getVersions(idOrDocumentId) {
|
|
6181
|
+
strapi2.log.info(`[magic-mail] [VERSION] Fetching versions for template: ${idOrDocumentId}`);
|
|
6182
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6172
6183
|
if (!template) {
|
|
6173
6184
|
throw new Error("Template not found");
|
|
6174
6185
|
}
|
|
6186
|
+
const actualDocumentId = template.documentId;
|
|
6175
6187
|
strapi2.log.info(`[magic-mail] [PACKAGE] Template has ${template.versions?.length || 0} versions`);
|
|
6176
6188
|
if (template.versions && template.versions.length > 0) {
|
|
6177
6189
|
const sortedVersions = [...template.versions].sort((a, b) => b.versionNumber - a.versionNumber);
|
|
@@ -6180,7 +6192,7 @@ function requireEmailDesigner() {
|
|
|
6180
6192
|
const versions = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findMany({
|
|
6181
6193
|
filters: {
|
|
6182
6194
|
template: {
|
|
6183
|
-
documentId:
|
|
6195
|
+
documentId: actualDocumentId
|
|
6184
6196
|
}
|
|
6185
6197
|
},
|
|
6186
6198
|
sort: [{ versionNumber: "desc" }]
|
|
@@ -6190,9 +6202,16 @@ function requireEmailDesigner() {
|
|
|
6190
6202
|
},
|
|
6191
6203
|
/**
|
|
6192
6204
|
* Restore template from a specific version
|
|
6205
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId of template
|
|
6206
|
+
* @param {string} versionDocumentId - documentId of version to restore
|
|
6193
6207
|
*/
|
|
6194
|
-
async restoreVersion(
|
|
6195
|
-
strapi2.log.info(`[magic-mail] [RESTORE] Restoring template ${
|
|
6208
|
+
async restoreVersion(idOrDocumentId, versionDocumentId) {
|
|
6209
|
+
strapi2.log.info(`[magic-mail] [RESTORE] Restoring template ${idOrDocumentId} from version ${versionDocumentId}`);
|
|
6210
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6211
|
+
if (!template) {
|
|
6212
|
+
throw new Error("Template not found");
|
|
6213
|
+
}
|
|
6214
|
+
const actualDocumentId = template.documentId;
|
|
6196
6215
|
const version2 = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findOne({
|
|
6197
6216
|
documentId: versionDocumentId,
|
|
6198
6217
|
populate: ["template"]
|
|
@@ -6200,10 +6219,10 @@ function requireEmailDesigner() {
|
|
|
6200
6219
|
if (!version2) {
|
|
6201
6220
|
throw new Error("Version not found");
|
|
6202
6221
|
}
|
|
6203
|
-
if (version2.template?.documentId !==
|
|
6222
|
+
if (version2.template?.documentId !== actualDocumentId) {
|
|
6204
6223
|
throw new Error("Version does not belong to this template");
|
|
6205
6224
|
}
|
|
6206
|
-
const restored = await this.update(
|
|
6225
|
+
const restored = await this.update(actualDocumentId, {
|
|
6207
6226
|
name: version2.name,
|
|
6208
6227
|
subject: version2.subject,
|
|
6209
6228
|
design: version2.design,
|
|
@@ -6216,9 +6235,16 @@ function requireEmailDesigner() {
|
|
|
6216
6235
|
},
|
|
6217
6236
|
/**
|
|
6218
6237
|
* Delete a single version
|
|
6238
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId of template
|
|
6239
|
+
* @param {string} versionDocumentId - documentId of version to delete
|
|
6219
6240
|
*/
|
|
6220
|
-
async deleteVersion(
|
|
6221
|
-
strapi2.log.info(`[magic-mail] [DELETE]
|
|
6241
|
+
async deleteVersion(idOrDocumentId, versionDocumentId) {
|
|
6242
|
+
strapi2.log.info(`[magic-mail] [DELETE] Deleting version ${versionDocumentId}`);
|
|
6243
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6244
|
+
if (!template) {
|
|
6245
|
+
throw new Error("Template not found");
|
|
6246
|
+
}
|
|
6247
|
+
const actualDocumentId = template.documentId;
|
|
6222
6248
|
const version2 = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findOne({
|
|
6223
6249
|
documentId: versionDocumentId,
|
|
6224
6250
|
populate: ["template"]
|
|
@@ -6226,7 +6252,7 @@ function requireEmailDesigner() {
|
|
|
6226
6252
|
if (!version2) {
|
|
6227
6253
|
throw new Error("Version not found");
|
|
6228
6254
|
}
|
|
6229
|
-
if (version2.template?.documentId !==
|
|
6255
|
+
if (version2.template?.documentId !== actualDocumentId) {
|
|
6230
6256
|
throw new Error("Version does not belong to this template");
|
|
6231
6257
|
}
|
|
6232
6258
|
await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).delete({
|
|
@@ -6237,13 +6263,11 @@ function requireEmailDesigner() {
|
|
|
6237
6263
|
},
|
|
6238
6264
|
/**
|
|
6239
6265
|
* Delete all versions for a template
|
|
6266
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId
|
|
6240
6267
|
*/
|
|
6241
|
-
async deleteAllVersions(
|
|
6242
|
-
strapi2.log.info(`[magic-mail] [DELETE]
|
|
6243
|
-
const template = await
|
|
6244
|
-
documentId: templateDocumentId,
|
|
6245
|
-
populate: ["versions"]
|
|
6246
|
-
});
|
|
6268
|
+
async deleteAllVersions(idOrDocumentId) {
|
|
6269
|
+
strapi2.log.info(`[magic-mail] [DELETE] Deleting all versions for template ${idOrDocumentId}`);
|
|
6270
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6247
6271
|
if (!template) {
|
|
6248
6272
|
throw new Error("Template not found");
|
|
6249
6273
|
}
|
package/dist/server/index.mjs
CHANGED
|
@@ -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(
|
|
11
|
-
return
|
|
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 } =
|
|
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.
|
|
5536
|
+
const version = "2.3.3";
|
|
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(
|
|
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
|
},
|
|
@@ -6024,18 +6029,21 @@ function requireEmailDesigner() {
|
|
|
6024
6029
|
},
|
|
6025
6030
|
/**
|
|
6026
6031
|
* Update template with automatic version snapshot
|
|
6032
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId
|
|
6033
|
+
* @param {Object} data - Update data
|
|
6027
6034
|
*/
|
|
6028
|
-
async update(
|
|
6029
|
-
strapi2.log.info(`[magic-mail] [UPDATE] Updating template
|
|
6030
|
-
const template = await this.findOne(
|
|
6035
|
+
async update(idOrDocumentId, data) {
|
|
6036
|
+
strapi2.log.info(`[magic-mail] [UPDATE] Updating template: ${idOrDocumentId}`);
|
|
6037
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6031
6038
|
if (!template) {
|
|
6032
6039
|
throw new Error("Template not found");
|
|
6033
6040
|
}
|
|
6034
|
-
|
|
6041
|
+
const actualDocumentId = template.documentId;
|
|
6042
|
+
strapi2.log.info(`[magic-mail] [INFO] Found template: documentId=${actualDocumentId}, name="${template.name}"`);
|
|
6035
6043
|
const hasVersioning = await strapi2.plugin("magic-mail").service("license-guard").hasFeature("email-designer-versioning");
|
|
6036
6044
|
if (hasVersioning) {
|
|
6037
6045
|
strapi2.log.info("[magic-mail] [SAVE] Creating version snapshot before update...");
|
|
6038
|
-
await this.createVersion(
|
|
6046
|
+
await this.createVersion(actualDocumentId, {
|
|
6039
6047
|
name: template.name,
|
|
6040
6048
|
subject: template.subject,
|
|
6041
6049
|
design: template.design,
|
|
@@ -6051,7 +6059,7 @@ function requireEmailDesigner() {
|
|
|
6051
6059
|
strapi2.log.warn("[magic-mail] [WARNING] Removed versions field from update data");
|
|
6052
6060
|
}
|
|
6053
6061
|
const updated = await strapi2.documents(EMAIL_TEMPLATE_UID).update({
|
|
6054
|
-
documentId,
|
|
6062
|
+
documentId: actualDocumentId,
|
|
6055
6063
|
data: updateData
|
|
6056
6064
|
});
|
|
6057
6065
|
strapi2.log.info(`[magic-mail] [SUCCESS] Template updated: documentId=${updated.documentId}`);
|
|
@@ -6059,42 +6067,47 @@ function requireEmailDesigner() {
|
|
|
6059
6067
|
},
|
|
6060
6068
|
/**
|
|
6061
6069
|
* Delete template and all its versions
|
|
6070
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId
|
|
6062
6071
|
*/
|
|
6063
|
-
async delete(
|
|
6064
|
-
strapi2.log.info(`[magic-mail] [DELETE]
|
|
6065
|
-
const template = await this.findOne(
|
|
6072
|
+
async delete(idOrDocumentId) {
|
|
6073
|
+
strapi2.log.info(`[magic-mail] [DELETE] Deleting template: ${idOrDocumentId}`);
|
|
6074
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6066
6075
|
if (!template) {
|
|
6067
6076
|
throw new Error("Template not found");
|
|
6068
6077
|
}
|
|
6069
|
-
|
|
6078
|
+
const actualDocumentId = template.documentId;
|
|
6079
|
+
strapi2.log.info(`[magic-mail] [DELETE] Template: documentId=${actualDocumentId}, name="${template.name}"`);
|
|
6070
6080
|
const allVersions = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findMany({
|
|
6071
6081
|
filters: {
|
|
6072
6082
|
template: {
|
|
6073
|
-
documentId:
|
|
6083
|
+
documentId: actualDocumentId
|
|
6074
6084
|
}
|
|
6075
6085
|
}
|
|
6076
6086
|
});
|
|
6077
|
-
strapi2.log.info(`[magic-mail] [DELETE]
|
|
6087
|
+
strapi2.log.info(`[magic-mail] [DELETE] Found ${allVersions.length} versions to delete`);
|
|
6078
6088
|
for (const version2 of allVersions) {
|
|
6079
6089
|
try {
|
|
6080
6090
|
await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).delete({
|
|
6081
6091
|
documentId: version2.documentId
|
|
6082
6092
|
});
|
|
6083
|
-
strapi2.log.info(`[magic-mail] [DELETE]
|
|
6093
|
+
strapi2.log.info(`[magic-mail] [DELETE] Deleted version #${version2.versionNumber}`);
|
|
6084
6094
|
} catch (versionError) {
|
|
6085
|
-
strapi2.log.warn(`[magic-mail] [WARNING]
|
|
6095
|
+
strapi2.log.warn(`[magic-mail] [WARNING] Failed to delete version: ${versionError.message}`);
|
|
6086
6096
|
}
|
|
6087
6097
|
}
|
|
6088
|
-
const result = await strapi2.documents(EMAIL_TEMPLATE_UID).delete({
|
|
6098
|
+
const result = await strapi2.documents(EMAIL_TEMPLATE_UID).delete({
|
|
6099
|
+
documentId: actualDocumentId
|
|
6100
|
+
});
|
|
6089
6101
|
strapi2.log.info(`[magic-mail] [SUCCESS] Template "${template.name}" and ${allVersions.length} versions deleted`);
|
|
6090
6102
|
return result;
|
|
6091
6103
|
},
|
|
6092
6104
|
/**
|
|
6093
6105
|
* Duplicate template
|
|
6106
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId
|
|
6094
6107
|
*/
|
|
6095
|
-
async duplicate(
|
|
6096
|
-
strapi2.log.info(`[magic-mail] [INFO] Duplicating template
|
|
6097
|
-
const original = await this.findOne(
|
|
6108
|
+
async duplicate(idOrDocumentId) {
|
|
6109
|
+
strapi2.log.info(`[magic-mail] [INFO] Duplicating template: ${idOrDocumentId}`);
|
|
6110
|
+
const original = await this.findOne(idOrDocumentId);
|
|
6098
6111
|
if (!original) {
|
|
6099
6112
|
throw new Error("Template not found");
|
|
6100
6113
|
}
|
|
@@ -6152,16 +6165,15 @@ function requireEmailDesigner() {
|
|
|
6152
6165
|
},
|
|
6153
6166
|
/**
|
|
6154
6167
|
* Get all versions for a template
|
|
6168
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId
|
|
6155
6169
|
*/
|
|
6156
|
-
async getVersions(
|
|
6157
|
-
strapi2.log.info(`[magic-mail]
|
|
6158
|
-
const template = await
|
|
6159
|
-
documentId: templateDocumentId,
|
|
6160
|
-
populate: ["versions"]
|
|
6161
|
-
});
|
|
6170
|
+
async getVersions(idOrDocumentId) {
|
|
6171
|
+
strapi2.log.info(`[magic-mail] [VERSION] Fetching versions for template: ${idOrDocumentId}`);
|
|
6172
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6162
6173
|
if (!template) {
|
|
6163
6174
|
throw new Error("Template not found");
|
|
6164
6175
|
}
|
|
6176
|
+
const actualDocumentId = template.documentId;
|
|
6165
6177
|
strapi2.log.info(`[magic-mail] [PACKAGE] Template has ${template.versions?.length || 0} versions`);
|
|
6166
6178
|
if (template.versions && template.versions.length > 0) {
|
|
6167
6179
|
const sortedVersions = [...template.versions].sort((a, b) => b.versionNumber - a.versionNumber);
|
|
@@ -6170,7 +6182,7 @@ function requireEmailDesigner() {
|
|
|
6170
6182
|
const versions = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findMany({
|
|
6171
6183
|
filters: {
|
|
6172
6184
|
template: {
|
|
6173
|
-
documentId:
|
|
6185
|
+
documentId: actualDocumentId
|
|
6174
6186
|
}
|
|
6175
6187
|
},
|
|
6176
6188
|
sort: [{ versionNumber: "desc" }]
|
|
@@ -6180,9 +6192,16 @@ function requireEmailDesigner() {
|
|
|
6180
6192
|
},
|
|
6181
6193
|
/**
|
|
6182
6194
|
* Restore template from a specific version
|
|
6195
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId of template
|
|
6196
|
+
* @param {string} versionDocumentId - documentId of version to restore
|
|
6183
6197
|
*/
|
|
6184
|
-
async restoreVersion(
|
|
6185
|
-
strapi2.log.info(`[magic-mail] [RESTORE] Restoring template ${
|
|
6198
|
+
async restoreVersion(idOrDocumentId, versionDocumentId) {
|
|
6199
|
+
strapi2.log.info(`[magic-mail] [RESTORE] Restoring template ${idOrDocumentId} from version ${versionDocumentId}`);
|
|
6200
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6201
|
+
if (!template) {
|
|
6202
|
+
throw new Error("Template not found");
|
|
6203
|
+
}
|
|
6204
|
+
const actualDocumentId = template.documentId;
|
|
6186
6205
|
const version2 = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findOne({
|
|
6187
6206
|
documentId: versionDocumentId,
|
|
6188
6207
|
populate: ["template"]
|
|
@@ -6190,10 +6209,10 @@ function requireEmailDesigner() {
|
|
|
6190
6209
|
if (!version2) {
|
|
6191
6210
|
throw new Error("Version not found");
|
|
6192
6211
|
}
|
|
6193
|
-
if (version2.template?.documentId !==
|
|
6212
|
+
if (version2.template?.documentId !== actualDocumentId) {
|
|
6194
6213
|
throw new Error("Version does not belong to this template");
|
|
6195
6214
|
}
|
|
6196
|
-
const restored = await this.update(
|
|
6215
|
+
const restored = await this.update(actualDocumentId, {
|
|
6197
6216
|
name: version2.name,
|
|
6198
6217
|
subject: version2.subject,
|
|
6199
6218
|
design: version2.design,
|
|
@@ -6206,9 +6225,16 @@ function requireEmailDesigner() {
|
|
|
6206
6225
|
},
|
|
6207
6226
|
/**
|
|
6208
6227
|
* Delete a single version
|
|
6228
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId of template
|
|
6229
|
+
* @param {string} versionDocumentId - documentId of version to delete
|
|
6209
6230
|
*/
|
|
6210
|
-
async deleteVersion(
|
|
6211
|
-
strapi2.log.info(`[magic-mail] [DELETE]
|
|
6231
|
+
async deleteVersion(idOrDocumentId, versionDocumentId) {
|
|
6232
|
+
strapi2.log.info(`[magic-mail] [DELETE] Deleting version ${versionDocumentId}`);
|
|
6233
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6234
|
+
if (!template) {
|
|
6235
|
+
throw new Error("Template not found");
|
|
6236
|
+
}
|
|
6237
|
+
const actualDocumentId = template.documentId;
|
|
6212
6238
|
const version2 = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findOne({
|
|
6213
6239
|
documentId: versionDocumentId,
|
|
6214
6240
|
populate: ["template"]
|
|
@@ -6216,7 +6242,7 @@ function requireEmailDesigner() {
|
|
|
6216
6242
|
if (!version2) {
|
|
6217
6243
|
throw new Error("Version not found");
|
|
6218
6244
|
}
|
|
6219
|
-
if (version2.template?.documentId !==
|
|
6245
|
+
if (version2.template?.documentId !== actualDocumentId) {
|
|
6220
6246
|
throw new Error("Version does not belong to this template");
|
|
6221
6247
|
}
|
|
6222
6248
|
await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).delete({
|
|
@@ -6227,13 +6253,11 @@ function requireEmailDesigner() {
|
|
|
6227
6253
|
},
|
|
6228
6254
|
/**
|
|
6229
6255
|
* Delete all versions for a template
|
|
6256
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId
|
|
6230
6257
|
*/
|
|
6231
|
-
async deleteAllVersions(
|
|
6232
|
-
strapi2.log.info(`[magic-mail] [DELETE]
|
|
6233
|
-
const template = await
|
|
6234
|
-
documentId: templateDocumentId,
|
|
6235
|
-
populate: ["versions"]
|
|
6236
|
-
});
|
|
6258
|
+
async deleteAllVersions(idOrDocumentId) {
|
|
6259
|
+
strapi2.log.info(`[magic-mail] [DELETE] Deleting all versions for template ${idOrDocumentId}`);
|
|
6260
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6237
6261
|
if (!template) {
|
|
6238
6262
|
throw new Error("Template not found");
|
|
6239
6263
|
}
|
package/package.json
CHANGED