@adatechnology/notification-contracts 0.5.0 → 0.7.0
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/index.cjs +99 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +89 -1
- package/dist/index.d.ts +89 -1
- package/dist/index.js +93 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -31,6 +31,7 @@ __export(index_exports, {
|
|
|
31
31
|
EMAIL_ATTACHMENT_MAX_COUNT: () => EMAIL_ATTACHMENT_MAX_COUNT,
|
|
32
32
|
EMAIL_DRIVER: () => EMAIL_DRIVER,
|
|
33
33
|
INTRUSIVE_CHANNELS: () => INTRUSIVE_CHANNELS,
|
|
34
|
+
InvalidTemplateDefinitionError: () => InvalidTemplateDefinitionError,
|
|
34
35
|
InvalidVapidKeysError: () => InvalidVapidKeysError,
|
|
35
36
|
InvalidWebhookSignatureError: () => InvalidWebhookSignatureError,
|
|
36
37
|
NOTIFICATION_CATEGORY_HINT: () => NOTIFICATION_CATEGORY_HINT,
|
|
@@ -63,11 +64,14 @@ __export(index_exports, {
|
|
|
63
64
|
ThrottledError: () => ThrottledError,
|
|
64
65
|
UnknownTemplateVariablesError: () => UnknownTemplateVariablesError,
|
|
65
66
|
WebPushEncryptionError: () => WebPushEncryptionError,
|
|
67
|
+
assertTemplateDefinitions: () => assertTemplateDefinitions,
|
|
66
68
|
assessStandardEmailTemplate: () => assessStandardEmailTemplate,
|
|
67
69
|
broadcastPushFilterSchema: () => broadcastPushFilterSchema,
|
|
68
70
|
broadcastPushSchema: () => broadcastPushSchema,
|
|
71
|
+
buildEnvironmentBannerHtml: () => buildEnvironmentBannerHtml,
|
|
69
72
|
buildInitials: () => buildInitials,
|
|
70
73
|
buildPreviewPayload: () => buildPreviewPayload,
|
|
74
|
+
buildTemplateVariableCatalog: () => buildTemplateVariableCatalog,
|
|
71
75
|
categoryPolicyEntrySchema: () => categoryPolicyEntrySchema,
|
|
72
76
|
checkEmailAttachment: () => checkEmailAttachment,
|
|
73
77
|
createWhatsAppDriverFromChannel: () => createWhatsAppDriverFromChannel,
|
|
@@ -78,6 +82,7 @@ __export(index_exports, {
|
|
|
78
82
|
escapeTemplateHtml: () => escapeTemplateHtml,
|
|
79
83
|
extractCalendarEvent: () => extractCalendarEvent,
|
|
80
84
|
extractTemplatePlaceholders: () => extractTemplatePlaceholders,
|
|
85
|
+
findTemplateDefinition: () => findTemplateDefinition,
|
|
81
86
|
findUnsafeEmailHtml: () => findUnsafeEmailHtml,
|
|
82
87
|
generateCalendarLinks: () => generateCalendarLinks,
|
|
83
88
|
generateGoogleCalendarUrl: () => generateGoogleCalendarUrl,
|
|
@@ -90,6 +95,7 @@ __export(index_exports, {
|
|
|
90
95
|
interpolateEmailHtml: () => interpolateEmailHtml,
|
|
91
96
|
interpolateTemplate: () => interpolateTemplate,
|
|
92
97
|
listNotificationsQuerySchema: () => listNotificationsQuerySchema,
|
|
98
|
+
markEmailForEnvironment: () => markEmailForEnvironment,
|
|
93
99
|
preferenceEntrySchema: () => preferenceEntrySchema,
|
|
94
100
|
pushNotificationPayloadSchema: () => pushNotificationPayloadSchema,
|
|
95
101
|
registerDeviceSchema: () => registerDeviceSchema,
|
|
@@ -816,6 +822,53 @@ function buildPreviewPayload(variables) {
|
|
|
816
822
|
}
|
|
817
823
|
__name(buildPreviewPayload, "buildPreviewPayload");
|
|
818
824
|
|
|
825
|
+
// src/templateDefinition.ts
|
|
826
|
+
var InvalidTemplateDefinitionError = class extends Error {
|
|
827
|
+
static {
|
|
828
|
+
__name(this, "InvalidTemplateDefinitionError");
|
|
829
|
+
}
|
|
830
|
+
definitionKey;
|
|
831
|
+
constructor(definitionKey, reason) {
|
|
832
|
+
super(`Defini\xE7\xE3o de template inv\xE1lida (${definitionKey}): ${reason}`), this.definitionKey = definitionKey;
|
|
833
|
+
this.name = "InvalidTemplateDefinitionError";
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
function buildTemplateVariableCatalog(definitions) {
|
|
837
|
+
const catalog = {};
|
|
838
|
+
for (const definition of definitions) {
|
|
839
|
+
catalog[definition.key] ??= definition.variables;
|
|
840
|
+
}
|
|
841
|
+
return catalog;
|
|
842
|
+
}
|
|
843
|
+
__name(buildTemplateVariableCatalog, "buildTemplateVariableCatalog");
|
|
844
|
+
function findTemplateDefinition(definitions, identity) {
|
|
845
|
+
return definitions.find((definition) => definition.key === identity.key && definition.channel === identity.channel && definition.locale === identity.locale);
|
|
846
|
+
}
|
|
847
|
+
__name(findTemplateDefinition, "findTemplateDefinition");
|
|
848
|
+
function assertTemplateDefinitions(definitions) {
|
|
849
|
+
const seen = /* @__PURE__ */ new Set();
|
|
850
|
+
for (const definition of definitions) {
|
|
851
|
+
const identity = `${definition.key}|${definition.channel}|${definition.locale}`;
|
|
852
|
+
if (seen.has(identity)) throw new InvalidTemplateDefinitionError(definition.key, "identidade duplicada");
|
|
853
|
+
seen.add(identity);
|
|
854
|
+
if (definition.label.trim() === "") throw new InvalidTemplateDefinitionError(definition.key, "label vazio");
|
|
855
|
+
if (definition.body.trim() === "") throw new InvalidTemplateDefinitionError(definition.key, "body vazio");
|
|
856
|
+
const names = definition.variables.map((variable) => variable.name);
|
|
857
|
+
if (new Set(names).size !== names.length) {
|
|
858
|
+
throw new InvalidTemplateDefinitionError(definition.key, "vari\xE1vel declarada duas vezes");
|
|
859
|
+
}
|
|
860
|
+
const { unknown } = diffTemplateVariables({
|
|
861
|
+
body: definition.body,
|
|
862
|
+
subject: definition.subject,
|
|
863
|
+
variables: definition.variables
|
|
864
|
+
});
|
|
865
|
+
if (unknown.length > 0) {
|
|
866
|
+
throw new InvalidTemplateDefinitionError(definition.key, `o texto padr\xE3o usa vari\xE1veis n\xE3o declaradas: ${unknown.join(", ")}`);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
__name(assertTemplateDefinitions, "assertTemplateDefinitions");
|
|
871
|
+
|
|
819
872
|
// src/emailHtml.ts
|
|
820
873
|
var STANDARD_EMAIL_THEME = {
|
|
821
874
|
colors: {
|
|
@@ -965,12 +1018,48 @@ function renderEmailMarksHtml(params) {
|
|
|
965
1018
|
}
|
|
966
1019
|
__name(renderEmailMarksHtml, "renderEmailMarksHtml");
|
|
967
1020
|
|
|
1021
|
+
// src/emailEnvironmentMark.ts
|
|
1022
|
+
var BANNER_ATTRIBUTE = "data-environment-banner";
|
|
1023
|
+
var BODY_OPEN_PATTERN = /<body\b[^>]*>/i;
|
|
1024
|
+
var DEFAULT_BACKGROUND = "#fff1c2";
|
|
1025
|
+
var DEFAULT_COLOR = "#5c3d00";
|
|
1026
|
+
var DEFAULT_BORDER = "#e6c866";
|
|
1027
|
+
var FONT2 = "Arial,Helvetica,sans-serif";
|
|
1028
|
+
function buildEnvironmentBannerHtml(mark) {
|
|
1029
|
+
const background = mark.bannerBackground ?? DEFAULT_BACKGROUND;
|
|
1030
|
+
const color = mark.bannerColor ?? DEFAULT_COLOR;
|
|
1031
|
+
const border = mark.bannerBorder ?? DEFAULT_BORDER;
|
|
1032
|
+
return `<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" ${BANNER_ATTRIBUTE}="true"><tr><td align="center" style="padding:8px 12px;background:${background};color:${color};border-bottom:1px solid ${border};font-family:${FONT2};font-size:13px;line-height:18px;font-weight:bold;text-align:center;">${escapeEmailHtml(mark.bannerText)}</td></tr></table>`;
|
|
1033
|
+
}
|
|
1034
|
+
__name(buildEnvironmentBannerHtml, "buildEnvironmentBannerHtml");
|
|
1035
|
+
function markHtml(html, mark) {
|
|
1036
|
+
if (html.includes(BANNER_ATTRIBUTE)) return html;
|
|
1037
|
+
const banner = buildEnvironmentBannerHtml(mark);
|
|
1038
|
+
const bodyOpen = BODY_OPEN_PATTERN.exec(html);
|
|
1039
|
+
if (!bodyOpen) return banner + html;
|
|
1040
|
+
const insertAt = bodyOpen.index + bodyOpen[0].length;
|
|
1041
|
+
return html.slice(0, insertAt) + banner + html.slice(insertAt);
|
|
1042
|
+
}
|
|
1043
|
+
__name(markHtml, "markHtml");
|
|
1044
|
+
function markEmailForEnvironment(message, mark) {
|
|
1045
|
+
const bannerLine = `[${mark.bannerText}]`;
|
|
1046
|
+
return {
|
|
1047
|
+
...message,
|
|
1048
|
+
subject: message.subject.startsWith(mark.subjectPrefix) ? message.subject : mark.subjectPrefix + message.subject,
|
|
1049
|
+
html: markHtml(message.html, mark),
|
|
1050
|
+
text: message.text.startsWith(bannerLine) ? message.text : `${bannerLine}
|
|
1051
|
+
|
|
1052
|
+
${message.text}`
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
__name(markEmailForEnvironment, "markEmailForEnvironment");
|
|
1056
|
+
|
|
968
1057
|
// src/templates/standardEmailTemplate.generated.ts
|
|
969
1058
|
var STANDARD_EMAIL_PT_BR_HTML = '<table role="presentation" width="620" cellpadding="0" cellspacing="0" border="0" style="width:620px;max-width:620px;margin:0 auto;background:#ffffff;font-family:Arial,Helvetica,sans-serif;color:#1d2b33">\n <tr>\n <td style="background:#10222c;padding:18px 24px">\n <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">\n <tr>\n <td width="56" valign="middle" style="width:56px">{{logoEmpresa}}</td>\n <td valign="middle" style="padding-left:12px;font-size:17px;font-weight:bold;color:#ffffff">{{nomeEmpresa}}</td>\n </tr>\n </table>\n </td>\n </tr>\n <tr>\n <td style="padding:22px 24px 6px;font-size:14px;line-height:1.55;color:#1d2b33">{{corpoMensagem}}</td>\n </tr>\n <tr>\n <td style="padding:0 24px 12px">{{listaAnexos}}</td>\n </tr>\n <tr>\n <td style="padding:0 24px 16px">{{faixaResposta}}</td>\n </tr>\n <tr>\n <td style="padding:16px 24px;border-top:1px solid #d9ded8">\n <table role="presentation" cellpadding="0" cellspacing="0" border="0">\n <tr>\n <td width="40" height="40" align="center" valign="middle" style="width:40px;height:40px;background:#10222c;color:#ffffff;font-size:14px;font-weight:bold">{{iniciaisAssinante}}</td>\n <td valign="middle" style="padding-left:12px;font-size:13px;line-height:1.4">\n <div style="font-weight:bold;color:#10222c">{{nomeAssinante}}</div>\n <div style="color:#5a6b74">{{cargoAssinante}}</div>\n </td>\n </tr>\n </table>\n </td>\n </tr>\n <tr>\n <td align="center" style="background:#f0f2ee;padding:14px 24px;font-size:11px;line-height:1.5;color:#5a6b74">\n <div>{{rodapePlataforma}}</div>\n <div style="padding-top:8px">{{marcasRodape}}</div>\n </td>\n </tr>\n</table>\n';
|
|
970
1059
|
|
|
971
1060
|
// src/standardEmail.ts
|
|
972
1061
|
var { copper: copper2, ink, mist, rule, slate: slate2 } = STANDARD_EMAIL_THEME.colors;
|
|
973
|
-
var
|
|
1062
|
+
var FONT3 = STANDARD_EMAIL_THEME.font;
|
|
974
1063
|
var STANDARD_EMAIL_TEMPLATE_KEY = "notification.standard-email";
|
|
975
1064
|
var STANDARD_EMAIL_CHANNEL = "email";
|
|
976
1065
|
var STANDARD_EMAIL_LOCALE = "pt-BR";
|
|
@@ -1066,13 +1155,13 @@ function buildMessageBody(bodyText) {
|
|
|
1066
1155
|
__name(buildMessageBody, "buildMessageBody");
|
|
1067
1156
|
function buildAttachmentList(attachments) {
|
|
1068
1157
|
if (attachments.length === 0) return "";
|
|
1069
|
-
const rows = attachments.map((attachment) => `<tr><td style="padding:4px 0;border-bottom:1px solid ${rule};font:13px ${
|
|
1070
|
-
return `<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding:0 0 4px;font:700 11px ${
|
|
1158
|
+
const rows = attachments.map((attachment) => `<tr><td style="padding:4px 0;border-bottom:1px solid ${rule};font:13px ${FONT3};color:${ink}">${escapeEmailHtml(attachment.name)}</td></tr>`).join("");
|
|
1159
|
+
return `<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding:0 0 4px;font:700 11px ${FONT3};text-transform:uppercase;color:${slate2}">Anexos</td></tr>${rows}</table>`;
|
|
1071
1160
|
}
|
|
1072
1161
|
__name(buildAttachmentList, "buildAttachmentList");
|
|
1073
1162
|
function buildReplyStrip(replyHint) {
|
|
1074
1163
|
if (replyHint === void 0 || replyHint.trim() === "") return "";
|
|
1075
|
-
return `<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding:10px 14px;background:${mist};border-left:3px solid ${copper2};font-family:${
|
|
1164
|
+
return `<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding:10px 14px;background:${mist};border-left:3px solid ${copper2};font-family:${FONT3};font-size:12px;color:${ink}">${escapeEmailHtml(replyHint)}</td></tr></table>`;
|
|
1076
1165
|
}
|
|
1077
1166
|
__name(buildReplyStrip, "buildReplyStrip");
|
|
1078
1167
|
function renderStandardEmail(params) {
|
|
@@ -1279,6 +1368,7 @@ __name(extractCalendarEvent, "extractCalendarEvent");
|
|
|
1279
1368
|
EMAIL_ATTACHMENT_MAX_COUNT,
|
|
1280
1369
|
EMAIL_DRIVER,
|
|
1281
1370
|
INTRUSIVE_CHANNELS,
|
|
1371
|
+
InvalidTemplateDefinitionError,
|
|
1282
1372
|
InvalidVapidKeysError,
|
|
1283
1373
|
InvalidWebhookSignatureError,
|
|
1284
1374
|
NOTIFICATION_CATEGORY_HINT,
|
|
@@ -1311,11 +1401,14 @@ __name(extractCalendarEvent, "extractCalendarEvent");
|
|
|
1311
1401
|
ThrottledError,
|
|
1312
1402
|
UnknownTemplateVariablesError,
|
|
1313
1403
|
WebPushEncryptionError,
|
|
1404
|
+
assertTemplateDefinitions,
|
|
1314
1405
|
assessStandardEmailTemplate,
|
|
1315
1406
|
broadcastPushFilterSchema,
|
|
1316
1407
|
broadcastPushSchema,
|
|
1408
|
+
buildEnvironmentBannerHtml,
|
|
1317
1409
|
buildInitials,
|
|
1318
1410
|
buildPreviewPayload,
|
|
1411
|
+
buildTemplateVariableCatalog,
|
|
1319
1412
|
categoryPolicyEntrySchema,
|
|
1320
1413
|
checkEmailAttachment,
|
|
1321
1414
|
createWhatsAppDriverFromChannel,
|
|
@@ -1326,6 +1419,7 @@ __name(extractCalendarEvent, "extractCalendarEvent");
|
|
|
1326
1419
|
escapeTemplateHtml,
|
|
1327
1420
|
extractCalendarEvent,
|
|
1328
1421
|
extractTemplatePlaceholders,
|
|
1422
|
+
findTemplateDefinition,
|
|
1329
1423
|
findUnsafeEmailHtml,
|
|
1330
1424
|
generateCalendarLinks,
|
|
1331
1425
|
generateGoogleCalendarUrl,
|
|
@@ -1338,6 +1432,7 @@ __name(extractCalendarEvent, "extractCalendarEvent");
|
|
|
1338
1432
|
interpolateEmailHtml,
|
|
1339
1433
|
interpolateTemplate,
|
|
1340
1434
|
listNotificationsQuerySchema,
|
|
1435
|
+
markEmailForEnvironment,
|
|
1341
1436
|
preferenceEntrySchema,
|
|
1342
1437
|
pushNotificationPayloadSchema,
|
|
1343
1438
|
registerDeviceSchema,
|