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