@adatechnology/notification-contracts 0.1.0-rc.6 → 0.2.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/README.md +18 -0
- package/dist/index.cjs +338 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +144 -1
- package/dist/index.d.ts +144 -1
- package/dist/index.js +320 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -47,6 +47,24 @@ ou o e-mail entra na lista de supressão, em vez de a fila insistir para sempre
|
|
|
47
47
|
- Alvo de entrega (telefone, e-mail) nunca aparece cru em log — ver `maskTarget`/`hashTarget` no
|
|
48
48
|
módulo.
|
|
49
49
|
|
|
50
|
+
## Modelo padrão de e-mail (`notification.standard-email`)
|
|
51
|
+
|
|
52
|
+
Moldura única de todo e-mail do sistema (canal `email`, locale `pt-BR`). Identidade (logo e nome),
|
|
53
|
+
assinante e rodapé são marcação **do modelo**, com variáveis — a empresa edita o HTML, não o código.
|
|
54
|
+
|
|
55
|
+
- Variáveis do sistema (HTML montado e escapado pelo sistema, usadas só pelo nome):
|
|
56
|
+
`STANDARD_EMAIL_SYSTEM_HTML_VARIABLES` (`logoEmpresa`, `corpoMensagem`, `listaAnexos`,
|
|
57
|
+
`faixaResposta`, `marcasRodape`). O resto é texto, escapado por valor.
|
|
58
|
+
- Obrigatórias: `STANDARD_EMAIL_REQUIRED_VARIABLES` (corpo, logo, nome da empresa, assinante,
|
|
59
|
+
rodapé da plataforma, marcas). Modelo sem uma delas é inutilizável.
|
|
60
|
+
- **Nenhuma variável em atributo ou `style`** — `findUnsafeEmailHtml` recusa.
|
|
61
|
+
- `assessStandardEmailTemplate(html)` → `{ usable, missing, unsafe }`; `renderStandardEmail` renderiza
|
|
62
|
+
com texto puro (`htmlToPlainText`) e `tooLarge` acima de `STANDARD_EMAIL_HTML_MAX_BYTES`.
|
|
63
|
+
`STANDARD_EMAIL_BUILTIN_TEMPLATE` é o embutido (`source: 'builtin'`, `version: 0`).
|
|
64
|
+
- Regras genéricas de e-mail HTML (reusáveis fora do padrão): `findUnsafeEmailHtml` (regras `event`,
|
|
65
|
+
`placeholder_in_tag`, `scheme`, `tag`), `htmlToPlainText`, `escapeEmailHtml`, `interpolateEmailHtml`,
|
|
66
|
+
`buildInitials`, `renderEmailLogoHtml`, `renderEmailMarksHtml`, `STANDARD_EMAIL_THEME`.
|
|
67
|
+
|
|
50
68
|
## Licença
|
|
51
69
|
|
|
52
70
|
MIT © Ada Technology
|
package/dist/index.cjs
CHANGED
|
@@ -43,6 +43,15 @@ __export(index_exports, {
|
|
|
43
43
|
PREVIEW_VIEWPORT_BY_CHANNEL: () => PREVIEW_VIEWPORT_BY_CHANNEL,
|
|
44
44
|
PUSH_DRIVER: () => PUSH_DRIVER,
|
|
45
45
|
RecipientUnresolvedError: () => RecipientUnresolvedError,
|
|
46
|
+
STANDARD_EMAIL_BUILTIN_TEMPLATE: () => STANDARD_EMAIL_BUILTIN_TEMPLATE,
|
|
47
|
+
STANDARD_EMAIL_CHANNEL: () => STANDARD_EMAIL_CHANNEL,
|
|
48
|
+
STANDARD_EMAIL_HTML_MAX_BYTES: () => STANDARD_EMAIL_HTML_MAX_BYTES,
|
|
49
|
+
STANDARD_EMAIL_LOCALE: () => STANDARD_EMAIL_LOCALE,
|
|
50
|
+
STANDARD_EMAIL_REQUIRED_VARIABLES: () => STANDARD_EMAIL_REQUIRED_VARIABLES,
|
|
51
|
+
STANDARD_EMAIL_SYSTEM_HTML_VARIABLES: () => STANDARD_EMAIL_SYSTEM_HTML_VARIABLES,
|
|
52
|
+
STANDARD_EMAIL_TEMPLATE_KEY: () => STANDARD_EMAIL_TEMPLATE_KEY,
|
|
53
|
+
STANDARD_EMAIL_THEME: () => STANDARD_EMAIL_THEME,
|
|
54
|
+
STANDARD_EMAIL_VARIABLES: () => STANDARD_EMAIL_VARIABLES,
|
|
46
55
|
SUPPRESSION_REASON: () => SUPPRESSION_REASON,
|
|
47
56
|
SuppressedTargetError: () => SuppressedTargetError,
|
|
48
57
|
TEMPLATE_CONSTRAINTS_BY_CHANNEL: () => TEMPLATE_CONSTRAINTS_BY_CHANNEL,
|
|
@@ -51,6 +60,8 @@ __export(index_exports, {
|
|
|
51
60
|
TemplateNotFoundError: () => TemplateNotFoundError,
|
|
52
61
|
ThrottledError: () => ThrottledError,
|
|
53
62
|
UnknownTemplateVariablesError: () => UnknownTemplateVariablesError,
|
|
63
|
+
assessStandardEmailTemplate: () => assessStandardEmailTemplate,
|
|
64
|
+
buildInitials: () => buildInitials,
|
|
54
65
|
buildPreviewPayload: () => buildPreviewPayload,
|
|
55
66
|
categoryPolicyEntrySchema: () => categoryPolicyEntrySchema,
|
|
56
67
|
checkEmailAttachment: () => checkEmailAttachment,
|
|
@@ -58,12 +69,19 @@ __export(index_exports, {
|
|
|
58
69
|
deliveryWebhookSchema: () => deliveryWebhookSchema,
|
|
59
70
|
deriveTitleFromBody: () => deriveTitleFromBody,
|
|
60
71
|
diffTemplateVariables: () => diffTemplateVariables,
|
|
72
|
+
escapeEmailHtml: () => escapeEmailHtml,
|
|
61
73
|
escapeTemplateHtml: () => escapeTemplateHtml,
|
|
62
74
|
extractTemplatePlaceholders: () => extractTemplatePlaceholders,
|
|
75
|
+
findUnsafeEmailHtml: () => findUnsafeEmailHtml,
|
|
76
|
+
htmlToPlainText: () => htmlToPlainText,
|
|
77
|
+
interpolateEmailHtml: () => interpolateEmailHtml,
|
|
63
78
|
interpolateTemplate: () => interpolateTemplate,
|
|
64
79
|
listNotificationsQuerySchema: () => listNotificationsQuerySchema,
|
|
65
80
|
preferenceEntrySchema: () => preferenceEntrySchema,
|
|
66
81
|
registerDeviceSchema: () => registerDeviceSchema,
|
|
82
|
+
renderEmailLogoHtml: () => renderEmailLogoHtml,
|
|
83
|
+
renderEmailMarksHtml: () => renderEmailMarksHtml,
|
|
84
|
+
renderStandardEmail: () => renderStandardEmail,
|
|
67
85
|
renderTemplate: () => renderTemplate,
|
|
68
86
|
sendNotificationSchema: () => sendNotificationSchema,
|
|
69
87
|
updateCategoryPoliciesSchema: () => updateCategoryPoliciesSchema,
|
|
@@ -689,6 +707,308 @@ function buildPreviewPayload(variables) {
|
|
|
689
707
|
]));
|
|
690
708
|
}
|
|
691
709
|
__name(buildPreviewPayload, "buildPreviewPayload");
|
|
710
|
+
|
|
711
|
+
// src/emailHtml.ts
|
|
712
|
+
var STANDARD_EMAIL_THEME = {
|
|
713
|
+
colors: {
|
|
714
|
+
asphalt: "#10222c",
|
|
715
|
+
copper: "#d58a47",
|
|
716
|
+
ink: "#1d2b33",
|
|
717
|
+
mist: "#f0f2ee",
|
|
718
|
+
rule: "#d9ded8",
|
|
719
|
+
slate: "#5a6b74"
|
|
720
|
+
},
|
|
721
|
+
font: "Arial,Helvetica,sans-serif",
|
|
722
|
+
/** O quadrado do logo (e das iniciais), em pixels. */
|
|
723
|
+
logoSize: 48
|
|
724
|
+
};
|
|
725
|
+
var { asphalt, copper, slate } = STANDARD_EMAIL_THEME.colors;
|
|
726
|
+
var { font: FONT, logoSize: LOGO_SIZE } = STANDARD_EMAIL_THEME;
|
|
727
|
+
var HTML_ESCAPE_MAP2 = {
|
|
728
|
+
"&": "&",
|
|
729
|
+
"<": "<",
|
|
730
|
+
">": ">",
|
|
731
|
+
'"': """,
|
|
732
|
+
"'": "'"
|
|
733
|
+
};
|
|
734
|
+
function escapeEmailHtml(value) {
|
|
735
|
+
return value.replace(/[&<>"']/gu, (character) => HTML_ESCAPE_MAP2[character] ?? character);
|
|
736
|
+
}
|
|
737
|
+
__name(escapeEmailHtml, "escapeEmailHtml");
|
|
738
|
+
var UNSAFE_TAG_REGEX = /<(?:script|iframe|form|object|embed)\b/iu;
|
|
739
|
+
var EVENT_REGEX = /[\s/"']on[a-z]+\s*=/iu;
|
|
740
|
+
var SCHEME_REGEX = /(?:javascript|vbscript):/iu;
|
|
741
|
+
var PLACEHOLDER_IN_TAG_REGEX = /<[a-zA-Z/!](?:[^>"']|"[^"]*"|'[^']*')*(?:\{\{|"[^"]*\{\{|'[^']*\{\{)/u;
|
|
742
|
+
var PLACEHOLDER_IN_STYLE_REGEX = /<style\b(?:(?!<\/style\b)[\s\S])*?\{\{/iu;
|
|
743
|
+
var CONTROL_AND_SPACE_REGEX = /[\u0000- ]/gu;
|
|
744
|
+
var NUMERIC_ENTITY_REGEX = /&#(?:x([0-9a-f]+)|([0-9]+));?/giu;
|
|
745
|
+
var NAMED_ENTITY_REGEX = /&(colon|tab|newline);/giu;
|
|
746
|
+
var NAMED_ENTITY_VALUE = {
|
|
747
|
+
colon: ":",
|
|
748
|
+
newline: "\n",
|
|
749
|
+
tab: " "
|
|
750
|
+
};
|
|
751
|
+
var MAX_CODE_POINT = 1114111;
|
|
752
|
+
function decodeCodePoint(code) {
|
|
753
|
+
return Number.isFinite(code) && code <= MAX_CODE_POINT ? String.fromCodePoint(code) : "";
|
|
754
|
+
}
|
|
755
|
+
__name(decodeCodePoint, "decodeCodePoint");
|
|
756
|
+
function normalizeForScheme(html) {
|
|
757
|
+
return html.replace(NUMERIC_ENTITY_REGEX, (_entity, hex, decimal) => decodeCodePoint(hex === void 0 ? Number.parseInt(decimal ?? "", 10) : Number.parseInt(hex, 16))).replace(NAMED_ENTITY_REGEX, (_entity, name) => NAMED_ENTITY_VALUE[name.toLowerCase()] ?? "").replace(CONTROL_AND_SPACE_REGEX, "");
|
|
758
|
+
}
|
|
759
|
+
__name(normalizeForScheme, "normalizeForScheme");
|
|
760
|
+
function findUnsafeEmailHtml(html) {
|
|
761
|
+
return [
|
|
762
|
+
...UNSAFE_TAG_REGEX.test(html) ? [
|
|
763
|
+
"tag"
|
|
764
|
+
] : [],
|
|
765
|
+
...EVENT_REGEX.test(html) ? [
|
|
766
|
+
"event"
|
|
767
|
+
] : [],
|
|
768
|
+
...SCHEME_REGEX.test(normalizeForScheme(html)) ? [
|
|
769
|
+
"scheme"
|
|
770
|
+
] : [],
|
|
771
|
+
...PLACEHOLDER_IN_TAG_REGEX.test(html) || PLACEHOLDER_IN_STYLE_REGEX.test(html) ? [
|
|
772
|
+
"placeholder_in_tag"
|
|
773
|
+
] : []
|
|
774
|
+
];
|
|
775
|
+
}
|
|
776
|
+
__name(findUnsafeEmailHtml, "findUnsafeEmailHtml");
|
|
777
|
+
var COMMENT_REGEX = /<!--[\s\S]*?-->/gu;
|
|
778
|
+
var DROPPED_ELEMENT_REGEX = /<(head|style|title)\b[^>]*>[\s\S]*?<\/\1\s*>/giu;
|
|
779
|
+
var LINE_BREAK_REGEX = /<br\b[^>]*>|<\/(?:p|div|tr|li|h[1-6]|table)\s*>/giu;
|
|
780
|
+
var CELL_END_REGEX = /<\/(?:td|th)\s*>/giu;
|
|
781
|
+
var TAG_REGEX = /<\/?[a-zA-Z][^>]*>/gu;
|
|
782
|
+
var TEXT_ENTITY_REGEX = /&(?:#x([0-9a-f]+)|#([0-9]+)|(amp|lt|gt|quot|apos|nbsp));/giu;
|
|
783
|
+
var TEXT_NAMED_ENTITY = {
|
|
784
|
+
amp: "&",
|
|
785
|
+
apos: "'",
|
|
786
|
+
gt: ">",
|
|
787
|
+
lt: "<",
|
|
788
|
+
nbsp: " ",
|
|
789
|
+
quot: '"'
|
|
790
|
+
};
|
|
791
|
+
var SURROGATE_MIN = 55296;
|
|
792
|
+
var SURROGATE_MAX = 57343;
|
|
793
|
+
var HORIZONTAL_SPACE_RUN = /[^\S\n]+/gu;
|
|
794
|
+
var BLANK_LINE_RUN = /\n{3,}/gu;
|
|
795
|
+
function isValidScalar(code) {
|
|
796
|
+
const isSurrogate = code >= SURROGATE_MIN && code <= SURROGATE_MAX;
|
|
797
|
+
return Number.isFinite(code) && code > 0 && code <= MAX_CODE_POINT && !isSurrogate;
|
|
798
|
+
}
|
|
799
|
+
__name(isValidScalar, "isValidScalar");
|
|
800
|
+
function decodeEntities(text) {
|
|
801
|
+
return text.replace(TEXT_ENTITY_REGEX, (_entity, hex, decimal, named) => {
|
|
802
|
+
if (named !== void 0) return TEXT_NAMED_ENTITY[named.toLowerCase()] ?? "";
|
|
803
|
+
const code = hex === void 0 ? Number.parseInt(decimal ?? "", 10) : Number.parseInt(hex, 16);
|
|
804
|
+
return isValidScalar(code) ? String.fromCodePoint(code) : "";
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
__name(decodeEntities, "decodeEntities");
|
|
808
|
+
function htmlToPlainText(html) {
|
|
809
|
+
const withoutNoise = html.replace(COMMENT_REGEX, "").replace(DROPPED_ELEMENT_REGEX, "");
|
|
810
|
+
const withBreaks = withoutNoise.replace(LINE_BREAK_REGEX, "\n").replace(CELL_END_REGEX, " ").replace(TAG_REGEX, "");
|
|
811
|
+
return decodeEntities(withBreaks).replaceAll("\r\n", "\n").split("\n").map((line) => line.replace(HORIZONTAL_SPACE_RUN, " ").trim()).join("\n").replace(BLANK_LINE_RUN, "\n\n").trim();
|
|
812
|
+
}
|
|
813
|
+
__name(htmlToPlainText, "htmlToPlainText");
|
|
814
|
+
var PLACEHOLDER_REGEX = /\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/gu;
|
|
815
|
+
var NEWLINE_REGEX = /\r\n|\r|\n/gu;
|
|
816
|
+
function lookup(source, name) {
|
|
817
|
+
return Object.hasOwn(source, name) ? source[name] ?? "" : "";
|
|
818
|
+
}
|
|
819
|
+
__name(lookup, "lookup");
|
|
820
|
+
function escapeValue(value) {
|
|
821
|
+
return escapeEmailHtml(value).replace(NEWLINE_REGEX, "<br>");
|
|
822
|
+
}
|
|
823
|
+
__name(escapeValue, "escapeValue");
|
|
824
|
+
function interpolateEmailHtml(params) {
|
|
825
|
+
const { systemHtml, systemHtmlNames, template, values } = params;
|
|
826
|
+
const names = new Set(systemHtmlNames);
|
|
827
|
+
return template.replace(PLACEHOLDER_REGEX, (_match, name) => names.has(name) ? lookup(systemHtml, name) : escapeValue(lookup(values, name)));
|
|
828
|
+
}
|
|
829
|
+
__name(interpolateEmailHtml, "interpolateEmailHtml");
|
|
830
|
+
var INITIALS_LENGTH = 2;
|
|
831
|
+
var INITIAL_PATTERN = /^[\p{L}\p{N}]/u;
|
|
832
|
+
var WHITESPACE = /\s+/u;
|
|
833
|
+
function buildInitials(name) {
|
|
834
|
+
return name.split(WHITESPACE).filter((word) => INITIAL_PATTERN.test(word)).slice(0, INITIALS_LENGTH).map((word) => (Array.from(word)[0] ?? "").toLocaleUpperCase("pt-BR")).join("");
|
|
835
|
+
}
|
|
836
|
+
__name(buildInitials, "buildInitials");
|
|
837
|
+
function renderEmailLogoHtml(params) {
|
|
838
|
+
const { displayName, logo } = params;
|
|
839
|
+
if (logo.kind === "cid") {
|
|
840
|
+
return `<img src="cid:${escapeEmailHtml(logo.contentId)}" alt="${escapeEmailHtml(displayName)}" width="${LOGO_SIZE}" height="${LOGO_SIZE}" style="display:block;border:0;width:${LOGO_SIZE}px;height:${LOGO_SIZE}px">`;
|
|
841
|
+
}
|
|
842
|
+
const size = `${LOGO_SIZE}px`;
|
|
843
|
+
return `<table role="presentation" cellpadding="0" cellspacing="0" border="0" width="${LOGO_SIZE}" height="${LOGO_SIZE}"><tr><td align="center" valign="middle" width="${LOGO_SIZE}" height="${LOGO_SIZE}" style="width:${size};height:${size};background:${asphalt};color:${copper};font-family:${FONT};font-size:18px;font-weight:700">${escapeEmailHtml(buildInitials(displayName))}</td></tr></table>`;
|
|
844
|
+
}
|
|
845
|
+
__name(renderEmailLogoHtml, "renderEmailLogoHtml");
|
|
846
|
+
var HTTP_URL = /^https?:\/\//iu;
|
|
847
|
+
function isHttpUrl(url) {
|
|
848
|
+
return url !== void 0 && HTTP_URL.test(url);
|
|
849
|
+
}
|
|
850
|
+
__name(isHttpUrl, "isHttpUrl");
|
|
851
|
+
function renderEmailMarksHtml(params) {
|
|
852
|
+
const { platformMarkUrl, productMarkUrl, text } = params;
|
|
853
|
+
const productMark = isHttpUrl(productMarkUrl) ? `<img src="${escapeEmailHtml(productMarkUrl)}" alt="" height="28" style="display:block;margin:0 auto 8px;border:0;height:28px">` : "";
|
|
854
|
+
const platformMark = isHttpUrl(platformMarkUrl) ? `<img src="${escapeEmailHtml(platformMarkUrl)}" alt="" height="12" style="vertical-align:middle;margin-right:6px;border:0;height:12px">` : "";
|
|
855
|
+
const label = text === void 0 || text === "" ? "" : `<span style="font-family:${FONT};font-size:11px;color:${slate}">${escapeEmailHtml(text)}</span>`;
|
|
856
|
+
return `${productMark}${platformMark}${label}`;
|
|
857
|
+
}
|
|
858
|
+
__name(renderEmailMarksHtml, "renderEmailMarksHtml");
|
|
859
|
+
|
|
860
|
+
// src/templates/standardEmailTemplate.generated.ts
|
|
861
|
+
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';
|
|
862
|
+
|
|
863
|
+
// src/standardEmail.ts
|
|
864
|
+
var { copper: copper2, ink, mist, rule, slate: slate2 } = STANDARD_EMAIL_THEME.colors;
|
|
865
|
+
var FONT2 = STANDARD_EMAIL_THEME.font;
|
|
866
|
+
var STANDARD_EMAIL_TEMPLATE_KEY = "notification.standard-email";
|
|
867
|
+
var STANDARD_EMAIL_CHANNEL = "email";
|
|
868
|
+
var STANDARD_EMAIL_LOCALE = "pt-BR";
|
|
869
|
+
var STANDARD_EMAIL_HTML_MAX_BYTES = 524288;
|
|
870
|
+
var STANDARD_EMAIL_SYSTEM_HTML_VARIABLES = [
|
|
871
|
+
"logoEmpresa",
|
|
872
|
+
"corpoMensagem",
|
|
873
|
+
"listaAnexos",
|
|
874
|
+
"faixaResposta",
|
|
875
|
+
"marcasRodape"
|
|
876
|
+
];
|
|
877
|
+
var STANDARD_EMAIL_REQUIRED_VARIABLES = [
|
|
878
|
+
"corpoMensagem",
|
|
879
|
+
"logoEmpresa",
|
|
880
|
+
"nomeEmpresa",
|
|
881
|
+
"nomeAssinante",
|
|
882
|
+
"rodapePlataforma",
|
|
883
|
+
"marcasRodape"
|
|
884
|
+
];
|
|
885
|
+
var STANDARD_EMAIL_VARIABLES = [
|
|
886
|
+
{
|
|
887
|
+
name: "nomeEmpresa",
|
|
888
|
+
example: "Alfa Transportes",
|
|
889
|
+
required: true
|
|
890
|
+
},
|
|
891
|
+
{
|
|
892
|
+
name: "logoEmpresa",
|
|
893
|
+
example: "(logo ou iniciais da empresa)",
|
|
894
|
+
required: true
|
|
895
|
+
},
|
|
896
|
+
{
|
|
897
|
+
name: "corpoMensagem",
|
|
898
|
+
example: "Ol\xE1, segue a nota fiscal.",
|
|
899
|
+
required: true
|
|
900
|
+
},
|
|
901
|
+
{
|
|
902
|
+
name: "listaAnexos",
|
|
903
|
+
example: "nota-1234.pdf",
|
|
904
|
+
required: false
|
|
905
|
+
},
|
|
906
|
+
{
|
|
907
|
+
name: "faixaResposta",
|
|
908
|
+
example: "Responda este e-mail.",
|
|
909
|
+
required: false
|
|
910
|
+
},
|
|
911
|
+
{
|
|
912
|
+
name: "iniciaisAssinante",
|
|
913
|
+
example: "MS",
|
|
914
|
+
required: false
|
|
915
|
+
},
|
|
916
|
+
{
|
|
917
|
+
name: "nomeAssinante",
|
|
918
|
+
example: "Maria da Silva",
|
|
919
|
+
required: true
|
|
920
|
+
},
|
|
921
|
+
{
|
|
922
|
+
name: "cargoAssinante",
|
|
923
|
+
example: "Analista de log\xEDstica",
|
|
924
|
+
required: false
|
|
925
|
+
},
|
|
926
|
+
{
|
|
927
|
+
name: "rodapePlataforma",
|
|
928
|
+
example: "Enviado pelo TransportAdA \u2014 uma solu\xE7\xE3o Ada Technology",
|
|
929
|
+
required: true
|
|
930
|
+
},
|
|
931
|
+
{
|
|
932
|
+
name: "marcasRodape",
|
|
933
|
+
example: "(marcas do produto e da plataforma)",
|
|
934
|
+
required: true
|
|
935
|
+
}
|
|
936
|
+
];
|
|
937
|
+
var STANDARD_EMAIL_BUILTIN_TEMPLATE = {
|
|
938
|
+
html: STANDARD_EMAIL_PT_BR_HTML,
|
|
939
|
+
source: "builtin",
|
|
940
|
+
version: 0
|
|
941
|
+
};
|
|
942
|
+
function assessStandardEmailTemplate(html) {
|
|
943
|
+
const used = new Set(extractTemplatePlaceholders(html));
|
|
944
|
+
const missing = STANDARD_EMAIL_REQUIRED_VARIABLES.filter((name) => !used.has(name));
|
|
945
|
+
const unsafe = findUnsafeEmailHtml(html);
|
|
946
|
+
return {
|
|
947
|
+
missing,
|
|
948
|
+
unsafe,
|
|
949
|
+
usable: missing.length === 0 && unsafe.length === 0
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
__name(assessStandardEmailTemplate, "assessStandardEmailTemplate");
|
|
953
|
+
var PARAGRAPH_BREAK = /(?:\r\n|\r|\n)[^\S\r\n]*(?:(?:\r\n|\r|\n)[^\S\r\n]*)+/u;
|
|
954
|
+
var NEWLINE = /\r\n|\r|\n/gu;
|
|
955
|
+
function buildMessageBody(bodyText) {
|
|
956
|
+
return bodyText.split(PARAGRAPH_BREAK).map((paragraph) => paragraph.trim()).filter((paragraph) => paragraph !== "").map((paragraph) => `<p style="margin:0 0 14px">${escapeEmailHtml(paragraph).replace(NEWLINE, "<br>")}</p>`).join("");
|
|
957
|
+
}
|
|
958
|
+
__name(buildMessageBody, "buildMessageBody");
|
|
959
|
+
function buildAttachmentList(attachments) {
|
|
960
|
+
if (attachments.length === 0) return "";
|
|
961
|
+
const rows = attachments.map((attachment) => `<tr><td style="padding:4px 0;border-bottom:1px solid ${rule};font:13px ${FONT2};color:${ink}">${escapeEmailHtml(attachment.name)}</td></tr>`).join("");
|
|
962
|
+
return `<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding:0 0 4px;font:700 11px ${FONT2};text-transform:uppercase;color:${slate2}">Anexos</td></tr>${rows}</table>`;
|
|
963
|
+
}
|
|
964
|
+
__name(buildAttachmentList, "buildAttachmentList");
|
|
965
|
+
function buildReplyStrip(replyHint) {
|
|
966
|
+
if (replyHint === void 0 || replyHint.trim() === "") return "";
|
|
967
|
+
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:${FONT2};font-size:12px;color:${ink}">${escapeEmailHtml(replyHint)}</td></tr></table>`;
|
|
968
|
+
}
|
|
969
|
+
__name(buildReplyStrip, "buildReplyStrip");
|
|
970
|
+
function renderStandardEmail(params) {
|
|
971
|
+
const { input, template } = params;
|
|
972
|
+
const { attachments, bodyText, footer, identity, replyHint, signer, values } = input;
|
|
973
|
+
const html = interpolateEmailHtml({
|
|
974
|
+
systemHtml: {
|
|
975
|
+
corpoMensagem: buildMessageBody(bodyText),
|
|
976
|
+
faixaResposta: buildReplyStrip(replyHint),
|
|
977
|
+
listaAnexos: buildAttachmentList(attachments),
|
|
978
|
+
logoEmpresa: renderEmailLogoHtml({
|
|
979
|
+
displayName: identity.displayName,
|
|
980
|
+
logo: identity.logo
|
|
981
|
+
}),
|
|
982
|
+
marcasRodape: renderEmailMarksHtml({
|
|
983
|
+
platformMarkUrl: footer.platformMarkUrl,
|
|
984
|
+
productMarkUrl: footer.productMarkUrl
|
|
985
|
+
})
|
|
986
|
+
},
|
|
987
|
+
systemHtmlNames: STANDARD_EMAIL_SYSTEM_HTML_VARIABLES,
|
|
988
|
+
template: template.html,
|
|
989
|
+
values: {
|
|
990
|
+
...values,
|
|
991
|
+
cargoAssinante: signer.role ?? "",
|
|
992
|
+
iniciaisAssinante: buildInitials(signer.name),
|
|
993
|
+
nomeAssinante: signer.name,
|
|
994
|
+
nomeEmpresa: identity.displayName,
|
|
995
|
+
rodapePlataforma: footer.platformNote
|
|
996
|
+
}
|
|
997
|
+
});
|
|
998
|
+
const bytes = new TextEncoder().encode(html).length;
|
|
999
|
+
return {
|
|
1000
|
+
bytes,
|
|
1001
|
+
html,
|
|
1002
|
+
template: {
|
|
1003
|
+
key: STANDARD_EMAIL_TEMPLATE_KEY,
|
|
1004
|
+
source: template.source,
|
|
1005
|
+
version: template.version
|
|
1006
|
+
},
|
|
1007
|
+
text: htmlToPlainText(html),
|
|
1008
|
+
tooLarge: bytes > STANDARD_EMAIL_HTML_MAX_BYTES
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
__name(renderStandardEmail, "renderStandardEmail");
|
|
692
1012
|
// Annotate the CommonJS export names for ESM import in node:
|
|
693
1013
|
0 && (module.exports = {
|
|
694
1014
|
ChannelNotConfiguredError,
|
|
@@ -713,6 +1033,15 @@ __name(buildPreviewPayload, "buildPreviewPayload");
|
|
|
713
1033
|
PREVIEW_VIEWPORT_BY_CHANNEL,
|
|
714
1034
|
PUSH_DRIVER,
|
|
715
1035
|
RecipientUnresolvedError,
|
|
1036
|
+
STANDARD_EMAIL_BUILTIN_TEMPLATE,
|
|
1037
|
+
STANDARD_EMAIL_CHANNEL,
|
|
1038
|
+
STANDARD_EMAIL_HTML_MAX_BYTES,
|
|
1039
|
+
STANDARD_EMAIL_LOCALE,
|
|
1040
|
+
STANDARD_EMAIL_REQUIRED_VARIABLES,
|
|
1041
|
+
STANDARD_EMAIL_SYSTEM_HTML_VARIABLES,
|
|
1042
|
+
STANDARD_EMAIL_TEMPLATE_KEY,
|
|
1043
|
+
STANDARD_EMAIL_THEME,
|
|
1044
|
+
STANDARD_EMAIL_VARIABLES,
|
|
716
1045
|
SUPPRESSION_REASON,
|
|
717
1046
|
SuppressedTargetError,
|
|
718
1047
|
TEMPLATE_CONSTRAINTS_BY_CHANNEL,
|
|
@@ -721,6 +1050,8 @@ __name(buildPreviewPayload, "buildPreviewPayload");
|
|
|
721
1050
|
TemplateNotFoundError,
|
|
722
1051
|
ThrottledError,
|
|
723
1052
|
UnknownTemplateVariablesError,
|
|
1053
|
+
assessStandardEmailTemplate,
|
|
1054
|
+
buildInitials,
|
|
724
1055
|
buildPreviewPayload,
|
|
725
1056
|
categoryPolicyEntrySchema,
|
|
726
1057
|
checkEmailAttachment,
|
|
@@ -728,12 +1059,19 @@ __name(buildPreviewPayload, "buildPreviewPayload");
|
|
|
728
1059
|
deliveryWebhookSchema,
|
|
729
1060
|
deriveTitleFromBody,
|
|
730
1061
|
diffTemplateVariables,
|
|
1062
|
+
escapeEmailHtml,
|
|
731
1063
|
escapeTemplateHtml,
|
|
732
1064
|
extractTemplatePlaceholders,
|
|
1065
|
+
findUnsafeEmailHtml,
|
|
1066
|
+
htmlToPlainText,
|
|
1067
|
+
interpolateEmailHtml,
|
|
733
1068
|
interpolateTemplate,
|
|
734
1069
|
listNotificationsQuerySchema,
|
|
735
1070
|
preferenceEntrySchema,
|
|
736
1071
|
registerDeviceSchema,
|
|
1072
|
+
renderEmailLogoHtml,
|
|
1073
|
+
renderEmailMarksHtml,
|
|
1074
|
+
renderStandardEmail,
|
|
737
1075
|
renderTemplate,
|
|
738
1076
|
sendNotificationSchema,
|
|
739
1077
|
updateCategoryPoliciesSchema,
|