strapi-plugin-magic-mail 2.3.7 → 2.3.9
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 +53 -28
- package/dist/server/index.mjs +53 -28
- 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.8";
|
|
5547
5547
|
const require$$2 = {
|
|
5548
5548
|
version
|
|
5549
5549
|
};
|
|
@@ -5971,7 +5971,7 @@ function requireEmailDesigner() {
|
|
|
5971
5971
|
}
|
|
5972
5972
|
return strapi2.documents(EMAIL_TEMPLATE_UID).findOne({
|
|
5973
5973
|
documentId: String(idOrDocumentId),
|
|
5974
|
-
populate:
|
|
5974
|
+
populate: { versions: true }
|
|
5975
5975
|
});
|
|
5976
5976
|
},
|
|
5977
5977
|
/**
|
|
@@ -5984,7 +5984,7 @@ function requireEmailDesigner() {
|
|
|
5984
5984
|
const byRefId = await strapi2.documents(EMAIL_TEMPLATE_UID).findMany({
|
|
5985
5985
|
filters: { templateReferenceId: numericId },
|
|
5986
5986
|
limit: 1,
|
|
5987
|
-
populate:
|
|
5987
|
+
populate: { versions: true }
|
|
5988
5988
|
});
|
|
5989
5989
|
if (byRefId.length > 0) {
|
|
5990
5990
|
strapi2.log.info(`[magic-mail] [SUCCESS] Found template by templateReferenceId ${numericId}: documentId=${byRefId[0].documentId}, name="${byRefId[0].name}"`);
|
|
@@ -5992,7 +5992,7 @@ function requireEmailDesigner() {
|
|
|
5992
5992
|
}
|
|
5993
5993
|
strapi2.log.info(`[magic-mail] [FALLBACK] templateReferenceId not found, trying internal db id: ${numericId}`);
|
|
5994
5994
|
const byInternalId = await strapi2.entityService.findOne(EMAIL_TEMPLATE_UID, numericId, {
|
|
5995
|
-
populate:
|
|
5995
|
+
populate: { versions: true }
|
|
5996
5996
|
});
|
|
5997
5997
|
if (byInternalId) {
|
|
5998
5998
|
strapi2.log.info(`[magic-mail] [SUCCESS] Found template by internal id ${numericId}: documentId=${byInternalId.documentId}, name="${byInternalId.name}"`);
|
|
@@ -6011,6 +6011,37 @@ function requireEmailDesigner() {
|
|
|
6011
6011
|
});
|
|
6012
6012
|
return results.length > 0 ? results[0] : null;
|
|
6013
6013
|
},
|
|
6014
|
+
/**
|
|
6015
|
+
* Get version by numeric ID or documentId
|
|
6016
|
+
* First tries documentId, then falls back to internal database id via entityService
|
|
6017
|
+
*/
|
|
6018
|
+
async findVersionById(idOrDocumentId) {
|
|
6019
|
+
strapi2.log.info(`[magic-mail] [LOOKUP] Finding version by ID: ${idOrDocumentId}`);
|
|
6020
|
+
const isNumericId = /^\d+$/.test(String(idOrDocumentId));
|
|
6021
|
+
if (!isNumericId) {
|
|
6022
|
+
const version2 = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findOne({
|
|
6023
|
+
documentId: String(idOrDocumentId),
|
|
6024
|
+
populate: { template: true }
|
|
6025
|
+
});
|
|
6026
|
+
if (version2) {
|
|
6027
|
+
strapi2.log.info(`[magic-mail] [SUCCESS] Found version by documentId: ${version2.documentId}`);
|
|
6028
|
+
return version2;
|
|
6029
|
+
}
|
|
6030
|
+
}
|
|
6031
|
+
const numericId = Number(idOrDocumentId);
|
|
6032
|
+
if (!isNaN(numericId)) {
|
|
6033
|
+
strapi2.log.info(`[magic-mail] [FALLBACK] Trying internal db id for version: ${numericId}`);
|
|
6034
|
+
const version2 = await strapi2.entityService.findOne(EMAIL_TEMPLATE_VERSION_UID, numericId, {
|
|
6035
|
+
populate: { template: true }
|
|
6036
|
+
});
|
|
6037
|
+
if (version2) {
|
|
6038
|
+
strapi2.log.info(`[magic-mail] [SUCCESS] Found version by internal id ${numericId}: documentId=${version2.documentId}`);
|
|
6039
|
+
return version2;
|
|
6040
|
+
}
|
|
6041
|
+
}
|
|
6042
|
+
strapi2.log.warn(`[magic-mail] [WARNING] Version with ID ${idOrDocumentId} not found`);
|
|
6043
|
+
return null;
|
|
6044
|
+
},
|
|
6014
6045
|
/**
|
|
6015
6046
|
* Create new template with automatic initial version
|
|
6016
6047
|
*/
|
|
@@ -6218,27 +6249,24 @@ function requireEmailDesigner() {
|
|
|
6218
6249
|
},
|
|
6219
6250
|
/**
|
|
6220
6251
|
* Restore template from a specific version
|
|
6221
|
-
* @param {string|number}
|
|
6222
|
-
* @param {string}
|
|
6252
|
+
* @param {string|number} templateIdOrDocumentId - Either numeric id or documentId of template
|
|
6253
|
+
* @param {string|number} versionIdOrDocumentId - Either numeric id or documentId of version
|
|
6223
6254
|
*/
|
|
6224
|
-
async restoreVersion(
|
|
6225
|
-
strapi2.log.info(`[magic-mail] [RESTORE] Restoring template ${
|
|
6226
|
-
const template = await this.findOne(
|
|
6255
|
+
async restoreVersion(templateIdOrDocumentId, versionIdOrDocumentId) {
|
|
6256
|
+
strapi2.log.info(`[magic-mail] [RESTORE] Restoring template ${templateIdOrDocumentId} from version ${versionIdOrDocumentId}`);
|
|
6257
|
+
const template = await this.findOne(templateIdOrDocumentId);
|
|
6227
6258
|
if (!template) {
|
|
6228
6259
|
throw new Error("Template not found");
|
|
6229
6260
|
}
|
|
6230
|
-
const
|
|
6231
|
-
const version2 = await
|
|
6232
|
-
documentId: versionDocumentId,
|
|
6233
|
-
populate: ["template"]
|
|
6234
|
-
});
|
|
6261
|
+
const actualTemplateDocumentId = template.documentId;
|
|
6262
|
+
const version2 = await this.findVersionById(versionIdOrDocumentId);
|
|
6235
6263
|
if (!version2) {
|
|
6236
6264
|
throw new Error("Version not found");
|
|
6237
6265
|
}
|
|
6238
|
-
if (version2.template?.documentId !==
|
|
6266
|
+
if (version2.template?.documentId !== actualTemplateDocumentId) {
|
|
6239
6267
|
throw new Error("Version does not belong to this template");
|
|
6240
6268
|
}
|
|
6241
|
-
const restored = await this.update(
|
|
6269
|
+
const restored = await this.update(actualTemplateDocumentId, {
|
|
6242
6270
|
name: version2.name,
|
|
6243
6271
|
subject: version2.subject,
|
|
6244
6272
|
design: version2.design,
|
|
@@ -6251,28 +6279,25 @@ function requireEmailDesigner() {
|
|
|
6251
6279
|
},
|
|
6252
6280
|
/**
|
|
6253
6281
|
* Delete a single version
|
|
6254
|
-
* @param {string|number}
|
|
6255
|
-
* @param {string}
|
|
6282
|
+
* @param {string|number} templateIdOrDocumentId - Either numeric id or documentId of template
|
|
6283
|
+
* @param {string|number} versionIdOrDocumentId - Either numeric id or documentId of version
|
|
6256
6284
|
*/
|
|
6257
|
-
async deleteVersion(
|
|
6258
|
-
strapi2.log.info(`[magic-mail] [DELETE] Deleting version ${
|
|
6259
|
-
const template = await this.findOne(
|
|
6285
|
+
async deleteVersion(templateIdOrDocumentId, versionIdOrDocumentId) {
|
|
6286
|
+
strapi2.log.info(`[magic-mail] [DELETE] Deleting version ${versionIdOrDocumentId}`);
|
|
6287
|
+
const template = await this.findOne(templateIdOrDocumentId);
|
|
6260
6288
|
if (!template) {
|
|
6261
6289
|
throw new Error("Template not found");
|
|
6262
6290
|
}
|
|
6263
|
-
const
|
|
6264
|
-
const version2 = await
|
|
6265
|
-
documentId: versionDocumentId,
|
|
6266
|
-
populate: ["template"]
|
|
6267
|
-
});
|
|
6291
|
+
const actualTemplateDocumentId = template.documentId;
|
|
6292
|
+
const version2 = await this.findVersionById(versionIdOrDocumentId);
|
|
6268
6293
|
if (!version2) {
|
|
6269
6294
|
throw new Error("Version not found");
|
|
6270
6295
|
}
|
|
6271
|
-
if (version2.template?.documentId !==
|
|
6296
|
+
if (version2.template?.documentId !== actualTemplateDocumentId) {
|
|
6272
6297
|
throw new Error("Version does not belong to this template");
|
|
6273
6298
|
}
|
|
6274
6299
|
await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).delete({
|
|
6275
|
-
documentId:
|
|
6300
|
+
documentId: version2.documentId
|
|
6276
6301
|
});
|
|
6277
6302
|
strapi2.log.info(`[magic-mail] [SUCCESS] Version v${version2.versionNumber} deleted`);
|
|
6278
6303
|
return { success: true, message: "Version deleted" };
|
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.8";
|
|
5537
5537
|
const require$$2 = {
|
|
5538
5538
|
version
|
|
5539
5539
|
};
|
|
@@ -5961,7 +5961,7 @@ function requireEmailDesigner() {
|
|
|
5961
5961
|
}
|
|
5962
5962
|
return strapi2.documents(EMAIL_TEMPLATE_UID).findOne({
|
|
5963
5963
|
documentId: String(idOrDocumentId),
|
|
5964
|
-
populate:
|
|
5964
|
+
populate: { versions: true }
|
|
5965
5965
|
});
|
|
5966
5966
|
},
|
|
5967
5967
|
/**
|
|
@@ -5974,7 +5974,7 @@ function requireEmailDesigner() {
|
|
|
5974
5974
|
const byRefId = await strapi2.documents(EMAIL_TEMPLATE_UID).findMany({
|
|
5975
5975
|
filters: { templateReferenceId: numericId },
|
|
5976
5976
|
limit: 1,
|
|
5977
|
-
populate:
|
|
5977
|
+
populate: { versions: true }
|
|
5978
5978
|
});
|
|
5979
5979
|
if (byRefId.length > 0) {
|
|
5980
5980
|
strapi2.log.info(`[magic-mail] [SUCCESS] Found template by templateReferenceId ${numericId}: documentId=${byRefId[0].documentId}, name="${byRefId[0].name}"`);
|
|
@@ -5982,7 +5982,7 @@ function requireEmailDesigner() {
|
|
|
5982
5982
|
}
|
|
5983
5983
|
strapi2.log.info(`[magic-mail] [FALLBACK] templateReferenceId not found, trying internal db id: ${numericId}`);
|
|
5984
5984
|
const byInternalId = await strapi2.entityService.findOne(EMAIL_TEMPLATE_UID, numericId, {
|
|
5985
|
-
populate:
|
|
5985
|
+
populate: { versions: true }
|
|
5986
5986
|
});
|
|
5987
5987
|
if (byInternalId) {
|
|
5988
5988
|
strapi2.log.info(`[magic-mail] [SUCCESS] Found template by internal id ${numericId}: documentId=${byInternalId.documentId}, name="${byInternalId.name}"`);
|
|
@@ -6001,6 +6001,37 @@ function requireEmailDesigner() {
|
|
|
6001
6001
|
});
|
|
6002
6002
|
return results.length > 0 ? results[0] : null;
|
|
6003
6003
|
},
|
|
6004
|
+
/**
|
|
6005
|
+
* Get version by numeric ID or documentId
|
|
6006
|
+
* First tries documentId, then falls back to internal database id via entityService
|
|
6007
|
+
*/
|
|
6008
|
+
async findVersionById(idOrDocumentId) {
|
|
6009
|
+
strapi2.log.info(`[magic-mail] [LOOKUP] Finding version by ID: ${idOrDocumentId}`);
|
|
6010
|
+
const isNumericId = /^\d+$/.test(String(idOrDocumentId));
|
|
6011
|
+
if (!isNumericId) {
|
|
6012
|
+
const version2 = await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).findOne({
|
|
6013
|
+
documentId: String(idOrDocumentId),
|
|
6014
|
+
populate: { template: true }
|
|
6015
|
+
});
|
|
6016
|
+
if (version2) {
|
|
6017
|
+
strapi2.log.info(`[magic-mail] [SUCCESS] Found version by documentId: ${version2.documentId}`);
|
|
6018
|
+
return version2;
|
|
6019
|
+
}
|
|
6020
|
+
}
|
|
6021
|
+
const numericId = Number(idOrDocumentId);
|
|
6022
|
+
if (!isNaN(numericId)) {
|
|
6023
|
+
strapi2.log.info(`[magic-mail] [FALLBACK] Trying internal db id for version: ${numericId}`);
|
|
6024
|
+
const version2 = await strapi2.entityService.findOne(EMAIL_TEMPLATE_VERSION_UID, numericId, {
|
|
6025
|
+
populate: { template: true }
|
|
6026
|
+
});
|
|
6027
|
+
if (version2) {
|
|
6028
|
+
strapi2.log.info(`[magic-mail] [SUCCESS] Found version by internal id ${numericId}: documentId=${version2.documentId}`);
|
|
6029
|
+
return version2;
|
|
6030
|
+
}
|
|
6031
|
+
}
|
|
6032
|
+
strapi2.log.warn(`[magic-mail] [WARNING] Version with ID ${idOrDocumentId} not found`);
|
|
6033
|
+
return null;
|
|
6034
|
+
},
|
|
6004
6035
|
/**
|
|
6005
6036
|
* Create new template with automatic initial version
|
|
6006
6037
|
*/
|
|
@@ -6208,27 +6239,24 @@ function requireEmailDesigner() {
|
|
|
6208
6239
|
},
|
|
6209
6240
|
/**
|
|
6210
6241
|
* Restore template from a specific version
|
|
6211
|
-
* @param {string|number}
|
|
6212
|
-
* @param {string}
|
|
6242
|
+
* @param {string|number} templateIdOrDocumentId - Either numeric id or documentId of template
|
|
6243
|
+
* @param {string|number} versionIdOrDocumentId - Either numeric id or documentId of version
|
|
6213
6244
|
*/
|
|
6214
|
-
async restoreVersion(
|
|
6215
|
-
strapi2.log.info(`[magic-mail] [RESTORE] Restoring template ${
|
|
6216
|
-
const template = await this.findOne(
|
|
6245
|
+
async restoreVersion(templateIdOrDocumentId, versionIdOrDocumentId) {
|
|
6246
|
+
strapi2.log.info(`[magic-mail] [RESTORE] Restoring template ${templateIdOrDocumentId} from version ${versionIdOrDocumentId}`);
|
|
6247
|
+
const template = await this.findOne(templateIdOrDocumentId);
|
|
6217
6248
|
if (!template) {
|
|
6218
6249
|
throw new Error("Template not found");
|
|
6219
6250
|
}
|
|
6220
|
-
const
|
|
6221
|
-
const version2 = await
|
|
6222
|
-
documentId: versionDocumentId,
|
|
6223
|
-
populate: ["template"]
|
|
6224
|
-
});
|
|
6251
|
+
const actualTemplateDocumentId = template.documentId;
|
|
6252
|
+
const version2 = await this.findVersionById(versionIdOrDocumentId);
|
|
6225
6253
|
if (!version2) {
|
|
6226
6254
|
throw new Error("Version not found");
|
|
6227
6255
|
}
|
|
6228
|
-
if (version2.template?.documentId !==
|
|
6256
|
+
if (version2.template?.documentId !== actualTemplateDocumentId) {
|
|
6229
6257
|
throw new Error("Version does not belong to this template");
|
|
6230
6258
|
}
|
|
6231
|
-
const restored = await this.update(
|
|
6259
|
+
const restored = await this.update(actualTemplateDocumentId, {
|
|
6232
6260
|
name: version2.name,
|
|
6233
6261
|
subject: version2.subject,
|
|
6234
6262
|
design: version2.design,
|
|
@@ -6241,28 +6269,25 @@ function requireEmailDesigner() {
|
|
|
6241
6269
|
},
|
|
6242
6270
|
/**
|
|
6243
6271
|
* Delete a single version
|
|
6244
|
-
* @param {string|number}
|
|
6245
|
-
* @param {string}
|
|
6272
|
+
* @param {string|number} templateIdOrDocumentId - Either numeric id or documentId of template
|
|
6273
|
+
* @param {string|number} versionIdOrDocumentId - Either numeric id or documentId of version
|
|
6246
6274
|
*/
|
|
6247
|
-
async deleteVersion(
|
|
6248
|
-
strapi2.log.info(`[magic-mail] [DELETE] Deleting version ${
|
|
6249
|
-
const template = await this.findOne(
|
|
6275
|
+
async deleteVersion(templateIdOrDocumentId, versionIdOrDocumentId) {
|
|
6276
|
+
strapi2.log.info(`[magic-mail] [DELETE] Deleting version ${versionIdOrDocumentId}`);
|
|
6277
|
+
const template = await this.findOne(templateIdOrDocumentId);
|
|
6250
6278
|
if (!template) {
|
|
6251
6279
|
throw new Error("Template not found");
|
|
6252
6280
|
}
|
|
6253
|
-
const
|
|
6254
|
-
const version2 = await
|
|
6255
|
-
documentId: versionDocumentId,
|
|
6256
|
-
populate: ["template"]
|
|
6257
|
-
});
|
|
6281
|
+
const actualTemplateDocumentId = template.documentId;
|
|
6282
|
+
const version2 = await this.findVersionById(versionIdOrDocumentId);
|
|
6258
6283
|
if (!version2) {
|
|
6259
6284
|
throw new Error("Version not found");
|
|
6260
6285
|
}
|
|
6261
|
-
if (version2.template?.documentId !==
|
|
6286
|
+
if (version2.template?.documentId !== actualTemplateDocumentId) {
|
|
6262
6287
|
throw new Error("Version does not belong to this template");
|
|
6263
6288
|
}
|
|
6264
6289
|
await strapi2.documents(EMAIL_TEMPLATE_VERSION_UID).delete({
|
|
6265
|
-
documentId:
|
|
6290
|
+
documentId: version2.documentId
|
|
6266
6291
|
});
|
|
6267
6292
|
strapi2.log.info(`[magic-mail] [SUCCESS] Version v${version2.versionNumber} deleted`);
|
|
6268
6293
|
return { success: true, message: "Version deleted" };
|
package/package.json
CHANGED