strapi-plugin-magic-mail 2.3.3 → 2.3.5
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 +68 -43
- package/dist/server/index.mjs +68 -43
- 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.4";
|
|
5547
5547
|
const require$$2 = {
|
|
5548
5548
|
version
|
|
5549
5549
|
};
|
|
@@ -5976,14 +5976,20 @@ function requireEmailDesigner() {
|
|
|
5976
5976
|
},
|
|
5977
5977
|
/**
|
|
5978
5978
|
* Get template by numeric ID (for backward compatibility)
|
|
5979
|
+
* Note: Document Service cannot filter by internal 'id' field,
|
|
5980
|
+
* so we use entityService as fallback for numeric IDs
|
|
5979
5981
|
*/
|
|
5980
5982
|
async findById(id) {
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
limit: 1,
|
|
5983
|
+
strapi2.log.info(`[magic-mail] [LOOKUP] Finding template by numeric ID: ${id}`);
|
|
5984
|
+
const result = await strapi2.entityService.findOne(EMAIL_TEMPLATE_UID, id, {
|
|
5984
5985
|
populate: ["versions"]
|
|
5985
5986
|
});
|
|
5986
|
-
|
|
5987
|
+
if (result) {
|
|
5988
|
+
strapi2.log.info(`[magic-mail] [SUCCESS] Found template by ID ${id}: documentId=${result.documentId}, name="${result.name}"`);
|
|
5989
|
+
} else {
|
|
5990
|
+
strapi2.log.warn(`[magic-mail] [WARNING] Template with ID ${id} not found`);
|
|
5991
|
+
}
|
|
5992
|
+
return result;
|
|
5987
5993
|
},
|
|
5988
5994
|
/**
|
|
5989
5995
|
* Get template by reference ID
|
|
@@ -6039,18 +6045,21 @@ function requireEmailDesigner() {
|
|
|
6039
6045
|
},
|
|
6040
6046
|
/**
|
|
6041
6047
|
* Update template with automatic version snapshot
|
|
6048
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId
|
|
6049
|
+
* @param {Object} data - Update data
|
|
6042
6050
|
*/
|
|
6043
|
-
async update(
|
|
6044
|
-
strapi2.log.info(`[magic-mail] [UPDATE] Updating template
|
|
6045
|
-
const template = await this.findOne(
|
|
6051
|
+
async update(idOrDocumentId, data) {
|
|
6052
|
+
strapi2.log.info(`[magic-mail] [UPDATE] Updating template: ${idOrDocumentId}`);
|
|
6053
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6046
6054
|
if (!template) {
|
|
6047
6055
|
throw new Error("Template not found");
|
|
6048
6056
|
}
|
|
6049
|
-
|
|
6057
|
+
const actualDocumentId = template.documentId;
|
|
6058
|
+
strapi2.log.info(`[magic-mail] [INFO] Found template: documentId=${actualDocumentId}, name="${template.name}"`);
|
|
6050
6059
|
const hasVersioning = await strapi2.plugin("magic-mail").service("license-guard").hasFeature("email-designer-versioning");
|
|
6051
6060
|
if (hasVersioning) {
|
|
6052
6061
|
strapi2.log.info("[magic-mail] [SAVE] Creating version snapshot before update...");
|
|
6053
|
-
await this.createVersion(
|
|
6062
|
+
await this.createVersion(actualDocumentId, {
|
|
6054
6063
|
name: template.name,
|
|
6055
6064
|
subject: template.subject,
|
|
6056
6065
|
design: template.design,
|
|
@@ -6066,7 +6075,7 @@ function requireEmailDesigner() {
|
|
|
6066
6075
|
strapi2.log.warn("[magic-mail] [WARNING] Removed versions field from update data");
|
|
6067
6076
|
}
|
|
6068
6077
|
const updated = await strapi2.documents(EMAIL_TEMPLATE_UID).update({
|
|
6069
|
-
documentId,
|
|
6078
|
+
documentId: actualDocumentId,
|
|
6070
6079
|
data: updateData
|
|
6071
6080
|
});
|
|
6072
6081
|
strapi2.log.info(`[magic-mail] [SUCCESS] Template updated: documentId=${updated.documentId}`);
|
|
@@ -6074,42 +6083,47 @@ function requireEmailDesigner() {
|
|
|
6074
6083
|
},
|
|
6075
6084
|
/**
|
|
6076
6085
|
* Delete template and all its versions
|
|
6086
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId
|
|
6077
6087
|
*/
|
|
6078
|
-
async delete(
|
|
6079
|
-
strapi2.log.info(`[magic-mail] [DELETE]
|
|
6080
|
-
const template = await this.findOne(
|
|
6088
|
+
async delete(idOrDocumentId) {
|
|
6089
|
+
strapi2.log.info(`[magic-mail] [DELETE] Deleting template: ${idOrDocumentId}`);
|
|
6090
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6081
6091
|
if (!template) {
|
|
6082
6092
|
throw new Error("Template not found");
|
|
6083
6093
|
}
|
|
6084
|
-
|
|
6094
|
+
const actualDocumentId = template.documentId;
|
|
6095
|
+
strapi2.log.info(`[magic-mail] [DELETE] Template: documentId=${actualDocumentId}, name="${template.name}"`);
|
|
6085
6096
|
const allVersions = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findMany({
|
|
6086
6097
|
filters: {
|
|
6087
6098
|
template: {
|
|
6088
|
-
documentId:
|
|
6099
|
+
documentId: actualDocumentId
|
|
6089
6100
|
}
|
|
6090
6101
|
}
|
|
6091
6102
|
});
|
|
6092
|
-
strapi2.log.info(`[magic-mail] [DELETE]
|
|
6103
|
+
strapi2.log.info(`[magic-mail] [DELETE] Found ${allVersions.length} versions to delete`);
|
|
6093
6104
|
for (const version2 of allVersions) {
|
|
6094
6105
|
try {
|
|
6095
6106
|
await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).delete({
|
|
6096
6107
|
documentId: version2.documentId
|
|
6097
6108
|
});
|
|
6098
|
-
strapi2.log.info(`[magic-mail] [DELETE]
|
|
6109
|
+
strapi2.log.info(`[magic-mail] [DELETE] Deleted version #${version2.versionNumber}`);
|
|
6099
6110
|
} catch (versionError) {
|
|
6100
|
-
strapi2.log.warn(`[magic-mail] [WARNING]
|
|
6111
|
+
strapi2.log.warn(`[magic-mail] [WARNING] Failed to delete version: ${versionError.message}`);
|
|
6101
6112
|
}
|
|
6102
6113
|
}
|
|
6103
|
-
const result = await strapi2.documents(EMAIL_TEMPLATE_UID).delete({
|
|
6114
|
+
const result = await strapi2.documents(EMAIL_TEMPLATE_UID).delete({
|
|
6115
|
+
documentId: actualDocumentId
|
|
6116
|
+
});
|
|
6104
6117
|
strapi2.log.info(`[magic-mail] [SUCCESS] Template "${template.name}" and ${allVersions.length} versions deleted`);
|
|
6105
6118
|
return result;
|
|
6106
6119
|
},
|
|
6107
6120
|
/**
|
|
6108
6121
|
* Duplicate template
|
|
6122
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId
|
|
6109
6123
|
*/
|
|
6110
|
-
async duplicate(
|
|
6111
|
-
strapi2.log.info(`[magic-mail] [INFO] Duplicating template
|
|
6112
|
-
const original = await this.findOne(
|
|
6124
|
+
async duplicate(idOrDocumentId) {
|
|
6125
|
+
strapi2.log.info(`[magic-mail] [INFO] Duplicating template: ${idOrDocumentId}`);
|
|
6126
|
+
const original = await this.findOne(idOrDocumentId);
|
|
6113
6127
|
if (!original) {
|
|
6114
6128
|
throw new Error("Template not found");
|
|
6115
6129
|
}
|
|
@@ -6167,16 +6181,15 @@ function requireEmailDesigner() {
|
|
|
6167
6181
|
},
|
|
6168
6182
|
/**
|
|
6169
6183
|
* Get all versions for a template
|
|
6184
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId
|
|
6170
6185
|
*/
|
|
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
|
-
});
|
|
6186
|
+
async getVersions(idOrDocumentId) {
|
|
6187
|
+
strapi2.log.info(`[magic-mail] [VERSION] Fetching versions for template: ${idOrDocumentId}`);
|
|
6188
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6177
6189
|
if (!template) {
|
|
6178
6190
|
throw new Error("Template not found");
|
|
6179
6191
|
}
|
|
6192
|
+
const actualDocumentId = template.documentId;
|
|
6180
6193
|
strapi2.log.info(`[magic-mail] [PACKAGE] Template has ${template.versions?.length || 0} versions`);
|
|
6181
6194
|
if (template.versions && template.versions.length > 0) {
|
|
6182
6195
|
const sortedVersions = [...template.versions].sort((a, b) => b.versionNumber - a.versionNumber);
|
|
@@ -6185,7 +6198,7 @@ function requireEmailDesigner() {
|
|
|
6185
6198
|
const versions = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findMany({
|
|
6186
6199
|
filters: {
|
|
6187
6200
|
template: {
|
|
6188
|
-
documentId:
|
|
6201
|
+
documentId: actualDocumentId
|
|
6189
6202
|
}
|
|
6190
6203
|
},
|
|
6191
6204
|
sort: [{ versionNumber: "desc" }]
|
|
@@ -6195,9 +6208,16 @@ function requireEmailDesigner() {
|
|
|
6195
6208
|
},
|
|
6196
6209
|
/**
|
|
6197
6210
|
* 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
|
|
6198
6213
|
*/
|
|
6199
|
-
async restoreVersion(
|
|
6200
|
-
strapi2.log.info(`[magic-mail] [RESTORE] Restoring template ${
|
|
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);
|
|
6217
|
+
if (!template) {
|
|
6218
|
+
throw new Error("Template not found");
|
|
6219
|
+
}
|
|
6220
|
+
const actualDocumentId = template.documentId;
|
|
6201
6221
|
const version2 = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findOne({
|
|
6202
6222
|
documentId: versionDocumentId,
|
|
6203
6223
|
populate: ["template"]
|
|
@@ -6205,10 +6225,10 @@ function requireEmailDesigner() {
|
|
|
6205
6225
|
if (!version2) {
|
|
6206
6226
|
throw new Error("Version not found");
|
|
6207
6227
|
}
|
|
6208
|
-
if (version2.template?.documentId !==
|
|
6228
|
+
if (version2.template?.documentId !== actualDocumentId) {
|
|
6209
6229
|
throw new Error("Version does not belong to this template");
|
|
6210
6230
|
}
|
|
6211
|
-
const restored = await this.update(
|
|
6231
|
+
const restored = await this.update(actualDocumentId, {
|
|
6212
6232
|
name: version2.name,
|
|
6213
6233
|
subject: version2.subject,
|
|
6214
6234
|
design: version2.design,
|
|
@@ -6221,9 +6241,16 @@ function requireEmailDesigner() {
|
|
|
6221
6241
|
},
|
|
6222
6242
|
/**
|
|
6223
6243
|
* 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
|
|
6224
6246
|
*/
|
|
6225
|
-
async deleteVersion(
|
|
6226
|
-
strapi2.log.info(`[magic-mail] [DELETE]
|
|
6247
|
+
async deleteVersion(idOrDocumentId, versionDocumentId) {
|
|
6248
|
+
strapi2.log.info(`[magic-mail] [DELETE] Deleting version ${versionDocumentId}`);
|
|
6249
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6250
|
+
if (!template) {
|
|
6251
|
+
throw new Error("Template not found");
|
|
6252
|
+
}
|
|
6253
|
+
const actualDocumentId = template.documentId;
|
|
6227
6254
|
const version2 = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findOne({
|
|
6228
6255
|
documentId: versionDocumentId,
|
|
6229
6256
|
populate: ["template"]
|
|
@@ -6231,7 +6258,7 @@ function requireEmailDesigner() {
|
|
|
6231
6258
|
if (!version2) {
|
|
6232
6259
|
throw new Error("Version not found");
|
|
6233
6260
|
}
|
|
6234
|
-
if (version2.template?.documentId !==
|
|
6261
|
+
if (version2.template?.documentId !== actualDocumentId) {
|
|
6235
6262
|
throw new Error("Version does not belong to this template");
|
|
6236
6263
|
}
|
|
6237
6264
|
await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).delete({
|
|
@@ -6242,13 +6269,11 @@ function requireEmailDesigner() {
|
|
|
6242
6269
|
},
|
|
6243
6270
|
/**
|
|
6244
6271
|
* Delete all versions for a template
|
|
6272
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId
|
|
6245
6273
|
*/
|
|
6246
|
-
async deleteAllVersions(
|
|
6247
|
-
strapi2.log.info(`[magic-mail] [DELETE]
|
|
6248
|
-
const template = await
|
|
6249
|
-
documentId: templateDocumentId,
|
|
6250
|
-
populate: ["versions"]
|
|
6251
|
-
});
|
|
6274
|
+
async deleteAllVersions(idOrDocumentId) {
|
|
6275
|
+
strapi2.log.info(`[magic-mail] [DELETE] Deleting all versions for template ${idOrDocumentId}`);
|
|
6276
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6252
6277
|
if (!template) {
|
|
6253
6278
|
throw new Error("Template not found");
|
|
6254
6279
|
}
|
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.4";
|
|
5537
5537
|
const require$$2 = {
|
|
5538
5538
|
version
|
|
5539
5539
|
};
|
|
@@ -5966,14 +5966,20 @@ function requireEmailDesigner() {
|
|
|
5966
5966
|
},
|
|
5967
5967
|
/**
|
|
5968
5968
|
* Get template by numeric ID (for backward compatibility)
|
|
5969
|
+
* Note: Document Service cannot filter by internal 'id' field,
|
|
5970
|
+
* so we use entityService as fallback for numeric IDs
|
|
5969
5971
|
*/
|
|
5970
5972
|
async findById(id) {
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
limit: 1,
|
|
5973
|
+
strapi2.log.info(`[magic-mail] [LOOKUP] Finding template by numeric ID: ${id}`);
|
|
5974
|
+
const result = await strapi2.entityService.findOne(EMAIL_TEMPLATE_UID, id, {
|
|
5974
5975
|
populate: ["versions"]
|
|
5975
5976
|
});
|
|
5976
|
-
|
|
5977
|
+
if (result) {
|
|
5978
|
+
strapi2.log.info(`[magic-mail] [SUCCESS] Found template by ID ${id}: documentId=${result.documentId}, name="${result.name}"`);
|
|
5979
|
+
} else {
|
|
5980
|
+
strapi2.log.warn(`[magic-mail] [WARNING] Template with ID ${id} not found`);
|
|
5981
|
+
}
|
|
5982
|
+
return result;
|
|
5977
5983
|
},
|
|
5978
5984
|
/**
|
|
5979
5985
|
* Get template by reference ID
|
|
@@ -6029,18 +6035,21 @@ function requireEmailDesigner() {
|
|
|
6029
6035
|
},
|
|
6030
6036
|
/**
|
|
6031
6037
|
* Update template with automatic version snapshot
|
|
6038
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId
|
|
6039
|
+
* @param {Object} data - Update data
|
|
6032
6040
|
*/
|
|
6033
|
-
async update(
|
|
6034
|
-
strapi2.log.info(`[magic-mail] [UPDATE] Updating template
|
|
6035
|
-
const template = await this.findOne(
|
|
6041
|
+
async update(idOrDocumentId, data) {
|
|
6042
|
+
strapi2.log.info(`[magic-mail] [UPDATE] Updating template: ${idOrDocumentId}`);
|
|
6043
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6036
6044
|
if (!template) {
|
|
6037
6045
|
throw new Error("Template not found");
|
|
6038
6046
|
}
|
|
6039
|
-
|
|
6047
|
+
const actualDocumentId = template.documentId;
|
|
6048
|
+
strapi2.log.info(`[magic-mail] [INFO] Found template: documentId=${actualDocumentId}, name="${template.name}"`);
|
|
6040
6049
|
const hasVersioning = await strapi2.plugin("magic-mail").service("license-guard").hasFeature("email-designer-versioning");
|
|
6041
6050
|
if (hasVersioning) {
|
|
6042
6051
|
strapi2.log.info("[magic-mail] [SAVE] Creating version snapshot before update...");
|
|
6043
|
-
await this.createVersion(
|
|
6052
|
+
await this.createVersion(actualDocumentId, {
|
|
6044
6053
|
name: template.name,
|
|
6045
6054
|
subject: template.subject,
|
|
6046
6055
|
design: template.design,
|
|
@@ -6056,7 +6065,7 @@ function requireEmailDesigner() {
|
|
|
6056
6065
|
strapi2.log.warn("[magic-mail] [WARNING] Removed versions field from update data");
|
|
6057
6066
|
}
|
|
6058
6067
|
const updated = await strapi2.documents(EMAIL_TEMPLATE_UID).update({
|
|
6059
|
-
documentId,
|
|
6068
|
+
documentId: actualDocumentId,
|
|
6060
6069
|
data: updateData
|
|
6061
6070
|
});
|
|
6062
6071
|
strapi2.log.info(`[magic-mail] [SUCCESS] Template updated: documentId=${updated.documentId}`);
|
|
@@ -6064,42 +6073,47 @@ function requireEmailDesigner() {
|
|
|
6064
6073
|
},
|
|
6065
6074
|
/**
|
|
6066
6075
|
* Delete template and all its versions
|
|
6076
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId
|
|
6067
6077
|
*/
|
|
6068
|
-
async delete(
|
|
6069
|
-
strapi2.log.info(`[magic-mail] [DELETE]
|
|
6070
|
-
const template = await this.findOne(
|
|
6078
|
+
async delete(idOrDocumentId) {
|
|
6079
|
+
strapi2.log.info(`[magic-mail] [DELETE] Deleting template: ${idOrDocumentId}`);
|
|
6080
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6071
6081
|
if (!template) {
|
|
6072
6082
|
throw new Error("Template not found");
|
|
6073
6083
|
}
|
|
6074
|
-
|
|
6084
|
+
const actualDocumentId = template.documentId;
|
|
6085
|
+
strapi2.log.info(`[magic-mail] [DELETE] Template: documentId=${actualDocumentId}, name="${template.name}"`);
|
|
6075
6086
|
const allVersions = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findMany({
|
|
6076
6087
|
filters: {
|
|
6077
6088
|
template: {
|
|
6078
|
-
documentId:
|
|
6089
|
+
documentId: actualDocumentId
|
|
6079
6090
|
}
|
|
6080
6091
|
}
|
|
6081
6092
|
});
|
|
6082
|
-
strapi2.log.info(`[magic-mail] [DELETE]
|
|
6093
|
+
strapi2.log.info(`[magic-mail] [DELETE] Found ${allVersions.length} versions to delete`);
|
|
6083
6094
|
for (const version2 of allVersions) {
|
|
6084
6095
|
try {
|
|
6085
6096
|
await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).delete({
|
|
6086
6097
|
documentId: version2.documentId
|
|
6087
6098
|
});
|
|
6088
|
-
strapi2.log.info(`[magic-mail] [DELETE]
|
|
6099
|
+
strapi2.log.info(`[magic-mail] [DELETE] Deleted version #${version2.versionNumber}`);
|
|
6089
6100
|
} catch (versionError) {
|
|
6090
|
-
strapi2.log.warn(`[magic-mail] [WARNING]
|
|
6101
|
+
strapi2.log.warn(`[magic-mail] [WARNING] Failed to delete version: ${versionError.message}`);
|
|
6091
6102
|
}
|
|
6092
6103
|
}
|
|
6093
|
-
const result = await strapi2.documents(EMAIL_TEMPLATE_UID).delete({
|
|
6104
|
+
const result = await strapi2.documents(EMAIL_TEMPLATE_UID).delete({
|
|
6105
|
+
documentId: actualDocumentId
|
|
6106
|
+
});
|
|
6094
6107
|
strapi2.log.info(`[magic-mail] [SUCCESS] Template "${template.name}" and ${allVersions.length} versions deleted`);
|
|
6095
6108
|
return result;
|
|
6096
6109
|
},
|
|
6097
6110
|
/**
|
|
6098
6111
|
* Duplicate template
|
|
6112
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId
|
|
6099
6113
|
*/
|
|
6100
|
-
async duplicate(
|
|
6101
|
-
strapi2.log.info(`[magic-mail] [INFO] Duplicating template
|
|
6102
|
-
const original = await this.findOne(
|
|
6114
|
+
async duplicate(idOrDocumentId) {
|
|
6115
|
+
strapi2.log.info(`[magic-mail] [INFO] Duplicating template: ${idOrDocumentId}`);
|
|
6116
|
+
const original = await this.findOne(idOrDocumentId);
|
|
6103
6117
|
if (!original) {
|
|
6104
6118
|
throw new Error("Template not found");
|
|
6105
6119
|
}
|
|
@@ -6157,16 +6171,15 @@ function requireEmailDesigner() {
|
|
|
6157
6171
|
},
|
|
6158
6172
|
/**
|
|
6159
6173
|
* Get all versions for a template
|
|
6174
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId
|
|
6160
6175
|
*/
|
|
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
|
-
});
|
|
6176
|
+
async getVersions(idOrDocumentId) {
|
|
6177
|
+
strapi2.log.info(`[magic-mail] [VERSION] Fetching versions for template: ${idOrDocumentId}`);
|
|
6178
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6167
6179
|
if (!template) {
|
|
6168
6180
|
throw new Error("Template not found");
|
|
6169
6181
|
}
|
|
6182
|
+
const actualDocumentId = template.documentId;
|
|
6170
6183
|
strapi2.log.info(`[magic-mail] [PACKAGE] Template has ${template.versions?.length || 0} versions`);
|
|
6171
6184
|
if (template.versions && template.versions.length > 0) {
|
|
6172
6185
|
const sortedVersions = [...template.versions].sort((a, b) => b.versionNumber - a.versionNumber);
|
|
@@ -6175,7 +6188,7 @@ function requireEmailDesigner() {
|
|
|
6175
6188
|
const versions = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findMany({
|
|
6176
6189
|
filters: {
|
|
6177
6190
|
template: {
|
|
6178
|
-
documentId:
|
|
6191
|
+
documentId: actualDocumentId
|
|
6179
6192
|
}
|
|
6180
6193
|
},
|
|
6181
6194
|
sort: [{ versionNumber: "desc" }]
|
|
@@ -6185,9 +6198,16 @@ function requireEmailDesigner() {
|
|
|
6185
6198
|
},
|
|
6186
6199
|
/**
|
|
6187
6200
|
* Restore template from a specific version
|
|
6201
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId of template
|
|
6202
|
+
* @param {string} versionDocumentId - documentId of version to restore
|
|
6188
6203
|
*/
|
|
6189
|
-
async restoreVersion(
|
|
6190
|
-
strapi2.log.info(`[magic-mail] [RESTORE] Restoring template ${
|
|
6204
|
+
async restoreVersion(idOrDocumentId, versionDocumentId) {
|
|
6205
|
+
strapi2.log.info(`[magic-mail] [RESTORE] Restoring template ${idOrDocumentId} from version ${versionDocumentId}`);
|
|
6206
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6207
|
+
if (!template) {
|
|
6208
|
+
throw new Error("Template not found");
|
|
6209
|
+
}
|
|
6210
|
+
const actualDocumentId = template.documentId;
|
|
6191
6211
|
const version2 = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findOne({
|
|
6192
6212
|
documentId: versionDocumentId,
|
|
6193
6213
|
populate: ["template"]
|
|
@@ -6195,10 +6215,10 @@ function requireEmailDesigner() {
|
|
|
6195
6215
|
if (!version2) {
|
|
6196
6216
|
throw new Error("Version not found");
|
|
6197
6217
|
}
|
|
6198
|
-
if (version2.template?.documentId !==
|
|
6218
|
+
if (version2.template?.documentId !== actualDocumentId) {
|
|
6199
6219
|
throw new Error("Version does not belong to this template");
|
|
6200
6220
|
}
|
|
6201
|
-
const restored = await this.update(
|
|
6221
|
+
const restored = await this.update(actualDocumentId, {
|
|
6202
6222
|
name: version2.name,
|
|
6203
6223
|
subject: version2.subject,
|
|
6204
6224
|
design: version2.design,
|
|
@@ -6211,9 +6231,16 @@ function requireEmailDesigner() {
|
|
|
6211
6231
|
},
|
|
6212
6232
|
/**
|
|
6213
6233
|
* Delete a single version
|
|
6234
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId of template
|
|
6235
|
+
* @param {string} versionDocumentId - documentId of version to delete
|
|
6214
6236
|
*/
|
|
6215
|
-
async deleteVersion(
|
|
6216
|
-
strapi2.log.info(`[magic-mail] [DELETE]
|
|
6237
|
+
async deleteVersion(idOrDocumentId, versionDocumentId) {
|
|
6238
|
+
strapi2.log.info(`[magic-mail] [DELETE] Deleting version ${versionDocumentId}`);
|
|
6239
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6240
|
+
if (!template) {
|
|
6241
|
+
throw new Error("Template not found");
|
|
6242
|
+
}
|
|
6243
|
+
const actualDocumentId = template.documentId;
|
|
6217
6244
|
const version2 = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findOne({
|
|
6218
6245
|
documentId: versionDocumentId,
|
|
6219
6246
|
populate: ["template"]
|
|
@@ -6221,7 +6248,7 @@ function requireEmailDesigner() {
|
|
|
6221
6248
|
if (!version2) {
|
|
6222
6249
|
throw new Error("Version not found");
|
|
6223
6250
|
}
|
|
6224
|
-
if (version2.template?.documentId !==
|
|
6251
|
+
if (version2.template?.documentId !== actualDocumentId) {
|
|
6225
6252
|
throw new Error("Version does not belong to this template");
|
|
6226
6253
|
}
|
|
6227
6254
|
await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).delete({
|
|
@@ -6232,13 +6259,11 @@ function requireEmailDesigner() {
|
|
|
6232
6259
|
},
|
|
6233
6260
|
/**
|
|
6234
6261
|
* Delete all versions for a template
|
|
6262
|
+
* @param {string|number} idOrDocumentId - Either numeric id or documentId
|
|
6235
6263
|
*/
|
|
6236
|
-
async deleteAllVersions(
|
|
6237
|
-
strapi2.log.info(`[magic-mail] [DELETE]
|
|
6238
|
-
const template = await
|
|
6239
|
-
documentId: templateDocumentId,
|
|
6240
|
-
populate: ["versions"]
|
|
6241
|
-
});
|
|
6264
|
+
async deleteAllVersions(idOrDocumentId) {
|
|
6265
|
+
strapi2.log.info(`[magic-mail] [DELETE] Deleting all versions for template ${idOrDocumentId}`);
|
|
6266
|
+
const template = await this.findOne(idOrDocumentId);
|
|
6242
6267
|
if (!template) {
|
|
6243
6268
|
throw new Error("Template not found");
|
|
6244
6269
|
}
|
package/package.json
CHANGED