@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/dist/index.d.ts
CHANGED
|
@@ -1127,4 +1127,147 @@ declare function diffTemplateVariables(params: DiffTemplateVariablesParams): Tem
|
|
|
1127
1127
|
*/
|
|
1128
1128
|
declare function buildPreviewPayload(variables: readonly TemplateVariableDefinition[] | undefined): Readonly<Record<string, string>>;
|
|
1129
1129
|
|
|
1130
|
-
|
|
1130
|
+
/**
|
|
1131
|
+
* Copyright (c) 2026 Ada Technology. MIT License.
|
|
1132
|
+
*
|
|
1133
|
+
* Regras genéricas de e-mail HTML (spec 274 T1.1), sem vocabulário de produto: escape, interpolação "valor
|
|
1134
|
+
* escapado, HTML do sistema pelo nome", bloqueio de conteúdo ativo, texto simples a partir do HTML, o desenho do
|
|
1135
|
+
* logo/iniciais e das marcas do rodapé. Puras e sem dependência.
|
|
1136
|
+
*
|
|
1137
|
+
* Mora aqui, e não no host, pelo mesmo motivo do `renderTemplate`: a API, o painel e a prévia precisam da MESMA
|
|
1138
|
+
* regra, e duas cópias divergiriam. As tabelas de caso são as da spec 272 do TransportAdA.
|
|
1139
|
+
*/
|
|
1140
|
+
/** Cores fixas (`color-scheme: light`): e-mail não herda tema. */
|
|
1141
|
+
declare const STANDARD_EMAIL_THEME: {
|
|
1142
|
+
readonly colors: {
|
|
1143
|
+
readonly asphalt: "#10222c";
|
|
1144
|
+
readonly copper: "#d58a47";
|
|
1145
|
+
readonly ink: "#1d2b33";
|
|
1146
|
+
readonly mist: "#f0f2ee";
|
|
1147
|
+
readonly rule: "#d9ded8";
|
|
1148
|
+
readonly slate: "#5a6b74";
|
|
1149
|
+
};
|
|
1150
|
+
readonly font: "Arial,Helvetica,sans-serif";
|
|
1151
|
+
/** O quadrado do logo (e das iniciais), em pixels. */
|
|
1152
|
+
readonly logoSize: 48;
|
|
1153
|
+
};
|
|
1154
|
+
/** `&` sempre primeiro: escapar os outros antes duplicaria o `&` que eles introduzem. */
|
|
1155
|
+
declare function escapeEmailHtml(value: string): string;
|
|
1156
|
+
type UnsafeEmailHtmlRule = 'event' | 'placeholder_in_tag' | 'scheme' | 'tag';
|
|
1157
|
+
/**
|
|
1158
|
+
* Bloqueio de conteúdo ativo, não um sanitizador: o autor do modelo é usuário interno. Vazio é HTML seguro.
|
|
1159
|
+
*/
|
|
1160
|
+
declare function findUnsafeEmailHtml(html: string): readonly UnsafeEmailHtmlRule[];
|
|
1161
|
+
/** A parte `text/plain` gerada do HTML renderizado. Sem biblioteca. */
|
|
1162
|
+
declare function htmlToPlainText(html: string): string;
|
|
1163
|
+
type InterpolateEmailHtmlParams = {
|
|
1164
|
+
/** HTML pronto, montado só pelo sistema (já escapa o que carrega); só os nomes de `systemHtmlNames` valem. */
|
|
1165
|
+
readonly systemHtml: Readonly<Record<string, string>>;
|
|
1166
|
+
/** O conjunto fechado de chaves de HTML do sistema, decidido pelo nome. */
|
|
1167
|
+
readonly systemHtmlNames: readonly string[];
|
|
1168
|
+
readonly template: string;
|
|
1169
|
+
/** Texto cru: é escapado na saída. */
|
|
1170
|
+
readonly values: Readonly<Record<string, string>>;
|
|
1171
|
+
};
|
|
1172
|
+
/**
|
|
1173
|
+
* Uma varredura só sobre o texto do **modelo**: o valor é escapado, exceto as chaves do conjunto fechado, decididas
|
|
1174
|
+
* pelo nome. O valor nunca é reinterpretado.
|
|
1175
|
+
*/
|
|
1176
|
+
declare function interpolateEmailHtml(params: InterpolateEmailHtmlParams): string;
|
|
1177
|
+
/** As primeiras letras das duas primeiras palavras, em maiúscula; pontuação solta não conta. */
|
|
1178
|
+
declare function buildInitials(name: string): string;
|
|
1179
|
+
type EmailLogo = {
|
|
1180
|
+
readonly contentId: string;
|
|
1181
|
+
readonly kind: 'cid';
|
|
1182
|
+
} | {
|
|
1183
|
+
readonly kind: 'initials';
|
|
1184
|
+
};
|
|
1185
|
+
/** `<img src="cid:…">` (a parte inline vai no envio) ou o quadrado de iniciais. Tudo o que carrega é escapado. */
|
|
1186
|
+
declare function renderEmailLogoHtml(params: {
|
|
1187
|
+
readonly displayName: string;
|
|
1188
|
+
readonly logo: EmailLogo;
|
|
1189
|
+
}): string;
|
|
1190
|
+
/**
|
|
1191
|
+
* As marcas do rodapé: as imagens por URL absoluta (só `http(s)`; outra não vira `src`) e o texto, se houver.
|
|
1192
|
+
* Sem imagem e sem texto, vazio.
|
|
1193
|
+
*/
|
|
1194
|
+
declare function renderEmailMarksHtml(params: {
|
|
1195
|
+
readonly platformMarkUrl?: string | undefined;
|
|
1196
|
+
readonly productMarkUrl?: string | undefined;
|
|
1197
|
+
readonly text?: string | undefined;
|
|
1198
|
+
}): string;
|
|
1199
|
+
|
|
1200
|
+
/**
|
|
1201
|
+
* Copyright (c) 2026 Ada Technology. MIT License.
|
|
1202
|
+
*
|
|
1203
|
+
* O modelo padrão de e-mail (spec 274 T1.2, plan D3). Identidade (logo e nome), assinante e rodapé são marcação do
|
|
1204
|
+
* modelo, com variáveis; o texto vem escapado por valor e o HTML do sistema só por nome (conjunto fechado). Nenhuma
|
|
1205
|
+
* variável entra em atributo ou `style`. Puro: não envia — o transporte é do host.
|
|
1206
|
+
*/
|
|
1207
|
+
|
|
1208
|
+
declare const STANDARD_EMAIL_TEMPLATE_KEY = "notification.standard-email";
|
|
1209
|
+
declare const STANDARD_EMAIL_CHANNEL = "email";
|
|
1210
|
+
declare const STANDARD_EMAIL_LOCALE = "pt-BR";
|
|
1211
|
+
/** O HTML passa de tantos bytes UTF-8: problema do modelo, não erro 500. */
|
|
1212
|
+
declare const STANDARD_EMAIL_HTML_MAX_BYTES = 524288;
|
|
1213
|
+
/** HTML do sistema, decidido pelo nome: o sistema o monta e escapa o que ele carrega. */
|
|
1214
|
+
declare const STANDARD_EMAIL_SYSTEM_HTML_VARIABLES: readonly ["logoEmpresa", "corpoMensagem", "listaAnexos", "faixaResposta", "marcasRodape"];
|
|
1215
|
+
type StandardEmailSystemHtmlVariable = (typeof STANDARD_EMAIL_SYSTEM_HTML_VARIABLES)[number];
|
|
1216
|
+
/** Identidade, assinante, rodapé e corpo: um modelo sem uma delas não é utilizável. */
|
|
1217
|
+
declare const STANDARD_EMAIL_REQUIRED_VARIABLES: readonly ["corpoMensagem", "logoEmpresa", "nomeEmpresa", "nomeAssinante", "rodapePlataforma", "marcasRodape"];
|
|
1218
|
+
declare const STANDARD_EMAIL_VARIABLES: readonly TemplateVariableDefinition[];
|
|
1219
|
+
/** O modelo, com a procedência que a resposta devolve: `builtin` é a rede de segurança (versão `0`). */
|
|
1220
|
+
type StandardEmailTemplate = {
|
|
1221
|
+
readonly html: string;
|
|
1222
|
+
readonly source: 'builtin' | 'company';
|
|
1223
|
+
readonly version: number;
|
|
1224
|
+
};
|
|
1225
|
+
declare const STANDARD_EMAIL_BUILTIN_TEMPLATE: StandardEmailTemplate;
|
|
1226
|
+
/** Só texto: nenhum HTML entra aqui. */
|
|
1227
|
+
type StandardEmailInput = {
|
|
1228
|
+
readonly attachments: readonly {
|
|
1229
|
+
readonly name: string;
|
|
1230
|
+
}[];
|
|
1231
|
+
readonly bodyText: string;
|
|
1232
|
+
readonly footer: {
|
|
1233
|
+
readonly platformMarkUrl?: string | undefined;
|
|
1234
|
+
readonly platformNote: string;
|
|
1235
|
+
readonly productMarkUrl?: string | undefined;
|
|
1236
|
+
};
|
|
1237
|
+
readonly identity: {
|
|
1238
|
+
readonly displayName: string;
|
|
1239
|
+
readonly logo: EmailLogo;
|
|
1240
|
+
};
|
|
1241
|
+
readonly replyHint?: string | undefined;
|
|
1242
|
+
readonly signer: {
|
|
1243
|
+
readonly name: string;
|
|
1244
|
+
readonly role?: string | undefined;
|
|
1245
|
+
};
|
|
1246
|
+
/** Valores extras para modelos da empresa que os usem; nunca sobrescrevem as variáveis do sistema. */
|
|
1247
|
+
readonly values?: Readonly<Record<string, string>> | undefined;
|
|
1248
|
+
};
|
|
1249
|
+
type RenderedStandardEmail = {
|
|
1250
|
+
readonly bytes: number;
|
|
1251
|
+
readonly html: string;
|
|
1252
|
+
readonly template: {
|
|
1253
|
+
readonly key: typeof STANDARD_EMAIL_TEMPLATE_KEY;
|
|
1254
|
+
readonly source: StandardEmailTemplate['source'];
|
|
1255
|
+
readonly version: number;
|
|
1256
|
+
};
|
|
1257
|
+
readonly text: string;
|
|
1258
|
+
readonly tooLarge: boolean;
|
|
1259
|
+
};
|
|
1260
|
+
type StandardEmailAssessment = {
|
|
1261
|
+
/** Obrigatórias que o modelo não usa. */
|
|
1262
|
+
readonly missing: readonly (typeof STANDARD_EMAIL_REQUIRED_VARIABLES)[number][];
|
|
1263
|
+
readonly unsafe: readonly UnsafeEmailHtmlRule[];
|
|
1264
|
+
readonly usable: boolean;
|
|
1265
|
+
};
|
|
1266
|
+
/** Utilizável = HTML seguro e todas as obrigatórias presentes. Inutilizável nunca é enviado. */
|
|
1267
|
+
declare function assessStandardEmailTemplate(html: string): StandardEmailAssessment;
|
|
1268
|
+
declare function renderStandardEmail(params: {
|
|
1269
|
+
readonly input: StandardEmailInput;
|
|
1270
|
+
readonly template: StandardEmailTemplate;
|
|
1271
|
+
}): RenderedStandardEmail;
|
|
1272
|
+
|
|
1273
|
+
export { type CachePort, type ChannelDrivers, ChannelNotConfiguredError, type ClockPort, type CompanyId, ConfigMissingError, DELIVERY_STATUS, DEVICE_PLATFORM, type DeliveryAttemptResult, type DeliveryBouncedEvent, type DeliveryFailedEvent, type DeliveryReceipt, type DeliverySentEvent, type DeliveryStatus, type DeliverySummary, type DeliveryWebhookBody, type DeviceInvalidatedEvent, DeviceNotFoundError, type DevicePlatform, type DeviceRegisteredEvent, type DeviceRegistration, type DiffTemplateVariablesParams, DuplicateWebhookDeliveryError, EMAIL_ATTACHMENT_MAX_BYTES, EMAIL_ATTACHMENT_MAX_COUNT, EMAIL_DRIVER, type EmailAttachment, type EmailDriver, type EmailDriverPort, type EmailLogo, INTRUSIVE_CHANNELS, type InterpolateEmailHtmlParams, InvalidWebhookSignatureError, type ListNotificationsParams, type ListNotificationsQuery, type ListNotificationsResult, type LogMeta, type LoggerPort, type MetricsPort, NOTIFICATION_CATEGORY_HINT, NOTIFICATION_CHANNEL, NOTIFICATION_ERROR_CODES, NOTIFICATION_EVENT, NOTIFICATION_STATUS, type NotificationCategoryPolicy, type NotificationChannel, type NotificationCreatedEvent, type NotificationDispatchedEvent, NotificationError, type NotificationEvent, type NotificationHooks, type NotificationId, type NotificationJob, NotificationNotFoundError, type NotificationPreference, type NotificationReadEvent, type NotificationStatus, type NotificationSummary, type NotificationTemplate, PREVIEW_VIEWPORT, PREVIEW_VIEWPORT_BY_CHANNEL, PUSH_DRIVER, type PreferencesUpdatedEvent, type PreviewViewport, type PreviewViewportSpec, type PushDriver, type PushDriverPort, type QueuePort, type RealtimeEvent, type RealtimeNotifierPort, type RealtimeSubscription, type RecipientResolverPort, RecipientUnresolvedError, type RegisterDeviceBody, type RenderTemplateParams, type RenderedStandardEmail, type RenderedTemplate, type RenderedTemplatePreview, type ResolvedRecipient, STANDARD_EMAIL_BUILTIN_TEMPLATE, STANDARD_EMAIL_CHANNEL, STANDARD_EMAIL_HTML_MAX_BYTES, STANDARD_EMAIL_LOCALE, STANDARD_EMAIL_REQUIRED_VARIABLES, STANDARD_EMAIL_SYSTEM_HTML_VARIABLES, STANDARD_EMAIL_TEMPLATE_KEY, STANDARD_EMAIL_THEME, STANDARD_EMAIL_VARIABLES, SUPPRESSION_REASON, type SendEmailParams, type SendNotificationBody, type SendNotificationParams, type SendNotificationResult, type SendPushParams, type SendSmsParams, type SendWhatsAppParams, type SendWhatsAppTemplateParams, type SmsDriverPort, type StandardEmailAssessment, type StandardEmailInput, type StandardEmailSystemHtmlVariable, type StandardEmailTemplate, SuppressedTargetError, type SuppressionReason, TEMPLATE_CONSTRAINTS_BY_CHANNEL, TEMPLATE_VARIABLE_KIND, type TemplateConstraintCheck, type TemplateConstraintField, type TemplateConstraintLimits, TemplateIdNotFoundError, TemplateNotFoundError, type TemplateRendererPort, type TemplateVariableCatalog, type TemplateVariableDefinition, type TemplateVariableDiff, type TemplateVariableKind, ThrottledError, UnknownTemplateVariablesError, type UnsafeEmailHtmlRule, type UpdateCategoryPoliciesBody, type UpdatePreferencesBody, type UpsertTemplateBody, type UserId, type WhatsAppDriverPort, type WhatsAppSendingChannel, assessStandardEmailTemplate, buildInitials, buildPreviewPayload, categoryPolicyEntrySchema, checkEmailAttachment, createWhatsAppDriverFromChannel, deliveryWebhookSchema, deriveTitleFromBody, diffTemplateVariables, escapeEmailHtml, escapeTemplateHtml, extractTemplatePlaceholders, findUnsafeEmailHtml, htmlToPlainText, interpolateEmailHtml, interpolateTemplate, listNotificationsQuerySchema, preferenceEntrySchema, registerDeviceSchema, renderEmailLogoHtml, renderEmailMarksHtml, renderStandardEmail, renderTemplate, sendNotificationSchema, updateCategoryPoliciesSchema, updatePreferencesSchema, upsertTemplateSchema };
|
package/dist/index.js
CHANGED
|
@@ -618,6 +618,308 @@ function buildPreviewPayload(variables) {
|
|
|
618
618
|
]));
|
|
619
619
|
}
|
|
620
620
|
__name(buildPreviewPayload, "buildPreviewPayload");
|
|
621
|
+
|
|
622
|
+
// src/emailHtml.ts
|
|
623
|
+
var STANDARD_EMAIL_THEME = {
|
|
624
|
+
colors: {
|
|
625
|
+
asphalt: "#10222c",
|
|
626
|
+
copper: "#d58a47",
|
|
627
|
+
ink: "#1d2b33",
|
|
628
|
+
mist: "#f0f2ee",
|
|
629
|
+
rule: "#d9ded8",
|
|
630
|
+
slate: "#5a6b74"
|
|
631
|
+
},
|
|
632
|
+
font: "Arial,Helvetica,sans-serif",
|
|
633
|
+
/** O quadrado do logo (e das iniciais), em pixels. */
|
|
634
|
+
logoSize: 48
|
|
635
|
+
};
|
|
636
|
+
var { asphalt, copper, slate } = STANDARD_EMAIL_THEME.colors;
|
|
637
|
+
var { font: FONT, logoSize: LOGO_SIZE } = STANDARD_EMAIL_THEME;
|
|
638
|
+
var HTML_ESCAPE_MAP2 = {
|
|
639
|
+
"&": "&",
|
|
640
|
+
"<": "<",
|
|
641
|
+
">": ">",
|
|
642
|
+
'"': """,
|
|
643
|
+
"'": "'"
|
|
644
|
+
};
|
|
645
|
+
function escapeEmailHtml(value) {
|
|
646
|
+
return value.replace(/[&<>"']/gu, (character) => HTML_ESCAPE_MAP2[character] ?? character);
|
|
647
|
+
}
|
|
648
|
+
__name(escapeEmailHtml, "escapeEmailHtml");
|
|
649
|
+
var UNSAFE_TAG_REGEX = /<(?:script|iframe|form|object|embed)\b/iu;
|
|
650
|
+
var EVENT_REGEX = /[\s/"']on[a-z]+\s*=/iu;
|
|
651
|
+
var SCHEME_REGEX = /(?:javascript|vbscript):/iu;
|
|
652
|
+
var PLACEHOLDER_IN_TAG_REGEX = /<[a-zA-Z/!](?:[^>"']|"[^"]*"|'[^']*')*(?:\{\{|"[^"]*\{\{|'[^']*\{\{)/u;
|
|
653
|
+
var PLACEHOLDER_IN_STYLE_REGEX = /<style\b(?:(?!<\/style\b)[\s\S])*?\{\{/iu;
|
|
654
|
+
var CONTROL_AND_SPACE_REGEX = /[\u0000- ]/gu;
|
|
655
|
+
var NUMERIC_ENTITY_REGEX = /&#(?:x([0-9a-f]+)|([0-9]+));?/giu;
|
|
656
|
+
var NAMED_ENTITY_REGEX = /&(colon|tab|newline);/giu;
|
|
657
|
+
var NAMED_ENTITY_VALUE = {
|
|
658
|
+
colon: ":",
|
|
659
|
+
newline: "\n",
|
|
660
|
+
tab: " "
|
|
661
|
+
};
|
|
662
|
+
var MAX_CODE_POINT = 1114111;
|
|
663
|
+
function decodeCodePoint(code) {
|
|
664
|
+
return Number.isFinite(code) && code <= MAX_CODE_POINT ? String.fromCodePoint(code) : "";
|
|
665
|
+
}
|
|
666
|
+
__name(decodeCodePoint, "decodeCodePoint");
|
|
667
|
+
function normalizeForScheme(html) {
|
|
668
|
+
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, "");
|
|
669
|
+
}
|
|
670
|
+
__name(normalizeForScheme, "normalizeForScheme");
|
|
671
|
+
function findUnsafeEmailHtml(html) {
|
|
672
|
+
return [
|
|
673
|
+
...UNSAFE_TAG_REGEX.test(html) ? [
|
|
674
|
+
"tag"
|
|
675
|
+
] : [],
|
|
676
|
+
...EVENT_REGEX.test(html) ? [
|
|
677
|
+
"event"
|
|
678
|
+
] : [],
|
|
679
|
+
...SCHEME_REGEX.test(normalizeForScheme(html)) ? [
|
|
680
|
+
"scheme"
|
|
681
|
+
] : [],
|
|
682
|
+
...PLACEHOLDER_IN_TAG_REGEX.test(html) || PLACEHOLDER_IN_STYLE_REGEX.test(html) ? [
|
|
683
|
+
"placeholder_in_tag"
|
|
684
|
+
] : []
|
|
685
|
+
];
|
|
686
|
+
}
|
|
687
|
+
__name(findUnsafeEmailHtml, "findUnsafeEmailHtml");
|
|
688
|
+
var COMMENT_REGEX = /<!--[\s\S]*?-->/gu;
|
|
689
|
+
var DROPPED_ELEMENT_REGEX = /<(head|style|title)\b[^>]*>[\s\S]*?<\/\1\s*>/giu;
|
|
690
|
+
var LINE_BREAK_REGEX = /<br\b[^>]*>|<\/(?:p|div|tr|li|h[1-6]|table)\s*>/giu;
|
|
691
|
+
var CELL_END_REGEX = /<\/(?:td|th)\s*>/giu;
|
|
692
|
+
var TAG_REGEX = /<\/?[a-zA-Z][^>]*>/gu;
|
|
693
|
+
var TEXT_ENTITY_REGEX = /&(?:#x([0-9a-f]+)|#([0-9]+)|(amp|lt|gt|quot|apos|nbsp));/giu;
|
|
694
|
+
var TEXT_NAMED_ENTITY = {
|
|
695
|
+
amp: "&",
|
|
696
|
+
apos: "'",
|
|
697
|
+
gt: ">",
|
|
698
|
+
lt: "<",
|
|
699
|
+
nbsp: " ",
|
|
700
|
+
quot: '"'
|
|
701
|
+
};
|
|
702
|
+
var SURROGATE_MIN = 55296;
|
|
703
|
+
var SURROGATE_MAX = 57343;
|
|
704
|
+
var HORIZONTAL_SPACE_RUN = /[^\S\n]+/gu;
|
|
705
|
+
var BLANK_LINE_RUN = /\n{3,}/gu;
|
|
706
|
+
function isValidScalar(code) {
|
|
707
|
+
const isSurrogate = code >= SURROGATE_MIN && code <= SURROGATE_MAX;
|
|
708
|
+
return Number.isFinite(code) && code > 0 && code <= MAX_CODE_POINT && !isSurrogate;
|
|
709
|
+
}
|
|
710
|
+
__name(isValidScalar, "isValidScalar");
|
|
711
|
+
function decodeEntities(text) {
|
|
712
|
+
return text.replace(TEXT_ENTITY_REGEX, (_entity, hex, decimal, named) => {
|
|
713
|
+
if (named !== void 0) return TEXT_NAMED_ENTITY[named.toLowerCase()] ?? "";
|
|
714
|
+
const code = hex === void 0 ? Number.parseInt(decimal ?? "", 10) : Number.parseInt(hex, 16);
|
|
715
|
+
return isValidScalar(code) ? String.fromCodePoint(code) : "";
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
__name(decodeEntities, "decodeEntities");
|
|
719
|
+
function htmlToPlainText(html) {
|
|
720
|
+
const withoutNoise = html.replace(COMMENT_REGEX, "").replace(DROPPED_ELEMENT_REGEX, "");
|
|
721
|
+
const withBreaks = withoutNoise.replace(LINE_BREAK_REGEX, "\n").replace(CELL_END_REGEX, " ").replace(TAG_REGEX, "");
|
|
722
|
+
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();
|
|
723
|
+
}
|
|
724
|
+
__name(htmlToPlainText, "htmlToPlainText");
|
|
725
|
+
var PLACEHOLDER_REGEX = /\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/gu;
|
|
726
|
+
var NEWLINE_REGEX = /\r\n|\r|\n/gu;
|
|
727
|
+
function lookup(source, name) {
|
|
728
|
+
return Object.hasOwn(source, name) ? source[name] ?? "" : "";
|
|
729
|
+
}
|
|
730
|
+
__name(lookup, "lookup");
|
|
731
|
+
function escapeValue(value) {
|
|
732
|
+
return escapeEmailHtml(value).replace(NEWLINE_REGEX, "<br>");
|
|
733
|
+
}
|
|
734
|
+
__name(escapeValue, "escapeValue");
|
|
735
|
+
function interpolateEmailHtml(params) {
|
|
736
|
+
const { systemHtml, systemHtmlNames, template, values } = params;
|
|
737
|
+
const names = new Set(systemHtmlNames);
|
|
738
|
+
return template.replace(PLACEHOLDER_REGEX, (_match, name) => names.has(name) ? lookup(systemHtml, name) : escapeValue(lookup(values, name)));
|
|
739
|
+
}
|
|
740
|
+
__name(interpolateEmailHtml, "interpolateEmailHtml");
|
|
741
|
+
var INITIALS_LENGTH = 2;
|
|
742
|
+
var INITIAL_PATTERN = /^[\p{L}\p{N}]/u;
|
|
743
|
+
var WHITESPACE = /\s+/u;
|
|
744
|
+
function buildInitials(name) {
|
|
745
|
+
return name.split(WHITESPACE).filter((word) => INITIAL_PATTERN.test(word)).slice(0, INITIALS_LENGTH).map((word) => (Array.from(word)[0] ?? "").toLocaleUpperCase("pt-BR")).join("");
|
|
746
|
+
}
|
|
747
|
+
__name(buildInitials, "buildInitials");
|
|
748
|
+
function renderEmailLogoHtml(params) {
|
|
749
|
+
const { displayName, logo } = params;
|
|
750
|
+
if (logo.kind === "cid") {
|
|
751
|
+
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">`;
|
|
752
|
+
}
|
|
753
|
+
const size = `${LOGO_SIZE}px`;
|
|
754
|
+
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>`;
|
|
755
|
+
}
|
|
756
|
+
__name(renderEmailLogoHtml, "renderEmailLogoHtml");
|
|
757
|
+
var HTTP_URL = /^https?:\/\//iu;
|
|
758
|
+
function isHttpUrl(url) {
|
|
759
|
+
return url !== void 0 && HTTP_URL.test(url);
|
|
760
|
+
}
|
|
761
|
+
__name(isHttpUrl, "isHttpUrl");
|
|
762
|
+
function renderEmailMarksHtml(params) {
|
|
763
|
+
const { platformMarkUrl, productMarkUrl, text } = params;
|
|
764
|
+
const productMark = isHttpUrl(productMarkUrl) ? `<img src="${escapeEmailHtml(productMarkUrl)}" alt="" height="28" style="display:block;margin:0 auto 8px;border:0;height:28px">` : "";
|
|
765
|
+
const platformMark = isHttpUrl(platformMarkUrl) ? `<img src="${escapeEmailHtml(platformMarkUrl)}" alt="" height="12" style="vertical-align:middle;margin-right:6px;border:0;height:12px">` : "";
|
|
766
|
+
const label = text === void 0 || text === "" ? "" : `<span style="font-family:${FONT};font-size:11px;color:${slate}">${escapeEmailHtml(text)}</span>`;
|
|
767
|
+
return `${productMark}${platformMark}${label}`;
|
|
768
|
+
}
|
|
769
|
+
__name(renderEmailMarksHtml, "renderEmailMarksHtml");
|
|
770
|
+
|
|
771
|
+
// src/templates/standardEmailTemplate.generated.ts
|
|
772
|
+
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';
|
|
773
|
+
|
|
774
|
+
// src/standardEmail.ts
|
|
775
|
+
var { copper: copper2, ink, mist, rule, slate: slate2 } = STANDARD_EMAIL_THEME.colors;
|
|
776
|
+
var FONT2 = STANDARD_EMAIL_THEME.font;
|
|
777
|
+
var STANDARD_EMAIL_TEMPLATE_KEY = "notification.standard-email";
|
|
778
|
+
var STANDARD_EMAIL_CHANNEL = "email";
|
|
779
|
+
var STANDARD_EMAIL_LOCALE = "pt-BR";
|
|
780
|
+
var STANDARD_EMAIL_HTML_MAX_BYTES = 524288;
|
|
781
|
+
var STANDARD_EMAIL_SYSTEM_HTML_VARIABLES = [
|
|
782
|
+
"logoEmpresa",
|
|
783
|
+
"corpoMensagem",
|
|
784
|
+
"listaAnexos",
|
|
785
|
+
"faixaResposta",
|
|
786
|
+
"marcasRodape"
|
|
787
|
+
];
|
|
788
|
+
var STANDARD_EMAIL_REQUIRED_VARIABLES = [
|
|
789
|
+
"corpoMensagem",
|
|
790
|
+
"logoEmpresa",
|
|
791
|
+
"nomeEmpresa",
|
|
792
|
+
"nomeAssinante",
|
|
793
|
+
"rodapePlataforma",
|
|
794
|
+
"marcasRodape"
|
|
795
|
+
];
|
|
796
|
+
var STANDARD_EMAIL_VARIABLES = [
|
|
797
|
+
{
|
|
798
|
+
name: "nomeEmpresa",
|
|
799
|
+
example: "Alfa Transportes",
|
|
800
|
+
required: true
|
|
801
|
+
},
|
|
802
|
+
{
|
|
803
|
+
name: "logoEmpresa",
|
|
804
|
+
example: "(logo ou iniciais da empresa)",
|
|
805
|
+
required: true
|
|
806
|
+
},
|
|
807
|
+
{
|
|
808
|
+
name: "corpoMensagem",
|
|
809
|
+
example: "Ol\xE1, segue a nota fiscal.",
|
|
810
|
+
required: true
|
|
811
|
+
},
|
|
812
|
+
{
|
|
813
|
+
name: "listaAnexos",
|
|
814
|
+
example: "nota-1234.pdf",
|
|
815
|
+
required: false
|
|
816
|
+
},
|
|
817
|
+
{
|
|
818
|
+
name: "faixaResposta",
|
|
819
|
+
example: "Responda este e-mail.",
|
|
820
|
+
required: false
|
|
821
|
+
},
|
|
822
|
+
{
|
|
823
|
+
name: "iniciaisAssinante",
|
|
824
|
+
example: "MS",
|
|
825
|
+
required: false
|
|
826
|
+
},
|
|
827
|
+
{
|
|
828
|
+
name: "nomeAssinante",
|
|
829
|
+
example: "Maria da Silva",
|
|
830
|
+
required: true
|
|
831
|
+
},
|
|
832
|
+
{
|
|
833
|
+
name: "cargoAssinante",
|
|
834
|
+
example: "Analista de log\xEDstica",
|
|
835
|
+
required: false
|
|
836
|
+
},
|
|
837
|
+
{
|
|
838
|
+
name: "rodapePlataforma",
|
|
839
|
+
example: "Enviado pelo TransportAdA \u2014 uma solu\xE7\xE3o Ada Technology",
|
|
840
|
+
required: true
|
|
841
|
+
},
|
|
842
|
+
{
|
|
843
|
+
name: "marcasRodape",
|
|
844
|
+
example: "(marcas do produto e da plataforma)",
|
|
845
|
+
required: true
|
|
846
|
+
}
|
|
847
|
+
];
|
|
848
|
+
var STANDARD_EMAIL_BUILTIN_TEMPLATE = {
|
|
849
|
+
html: STANDARD_EMAIL_PT_BR_HTML,
|
|
850
|
+
source: "builtin",
|
|
851
|
+
version: 0
|
|
852
|
+
};
|
|
853
|
+
function assessStandardEmailTemplate(html) {
|
|
854
|
+
const used = new Set(extractTemplatePlaceholders(html));
|
|
855
|
+
const missing = STANDARD_EMAIL_REQUIRED_VARIABLES.filter((name) => !used.has(name));
|
|
856
|
+
const unsafe = findUnsafeEmailHtml(html);
|
|
857
|
+
return {
|
|
858
|
+
missing,
|
|
859
|
+
unsafe,
|
|
860
|
+
usable: missing.length === 0 && unsafe.length === 0
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
__name(assessStandardEmailTemplate, "assessStandardEmailTemplate");
|
|
864
|
+
var PARAGRAPH_BREAK = /(?:\r\n|\r|\n)[^\S\r\n]*(?:(?:\r\n|\r|\n)[^\S\r\n]*)+/u;
|
|
865
|
+
var NEWLINE = /\r\n|\r|\n/gu;
|
|
866
|
+
function buildMessageBody(bodyText) {
|
|
867
|
+
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("");
|
|
868
|
+
}
|
|
869
|
+
__name(buildMessageBody, "buildMessageBody");
|
|
870
|
+
function buildAttachmentList(attachments) {
|
|
871
|
+
if (attachments.length === 0) return "";
|
|
872
|
+
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("");
|
|
873
|
+
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>`;
|
|
874
|
+
}
|
|
875
|
+
__name(buildAttachmentList, "buildAttachmentList");
|
|
876
|
+
function buildReplyStrip(replyHint) {
|
|
877
|
+
if (replyHint === void 0 || replyHint.trim() === "") return "";
|
|
878
|
+
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>`;
|
|
879
|
+
}
|
|
880
|
+
__name(buildReplyStrip, "buildReplyStrip");
|
|
881
|
+
function renderStandardEmail(params) {
|
|
882
|
+
const { input, template } = params;
|
|
883
|
+
const { attachments, bodyText, footer, identity, replyHint, signer, values } = input;
|
|
884
|
+
const html = interpolateEmailHtml({
|
|
885
|
+
systemHtml: {
|
|
886
|
+
corpoMensagem: buildMessageBody(bodyText),
|
|
887
|
+
faixaResposta: buildReplyStrip(replyHint),
|
|
888
|
+
listaAnexos: buildAttachmentList(attachments),
|
|
889
|
+
logoEmpresa: renderEmailLogoHtml({
|
|
890
|
+
displayName: identity.displayName,
|
|
891
|
+
logo: identity.logo
|
|
892
|
+
}),
|
|
893
|
+
marcasRodape: renderEmailMarksHtml({
|
|
894
|
+
platformMarkUrl: footer.platformMarkUrl,
|
|
895
|
+
productMarkUrl: footer.productMarkUrl
|
|
896
|
+
})
|
|
897
|
+
},
|
|
898
|
+
systemHtmlNames: STANDARD_EMAIL_SYSTEM_HTML_VARIABLES,
|
|
899
|
+
template: template.html,
|
|
900
|
+
values: {
|
|
901
|
+
...values,
|
|
902
|
+
cargoAssinante: signer.role ?? "",
|
|
903
|
+
iniciaisAssinante: buildInitials(signer.name),
|
|
904
|
+
nomeAssinante: signer.name,
|
|
905
|
+
nomeEmpresa: identity.displayName,
|
|
906
|
+
rodapePlataforma: footer.platformNote
|
|
907
|
+
}
|
|
908
|
+
});
|
|
909
|
+
const bytes = new TextEncoder().encode(html).length;
|
|
910
|
+
return {
|
|
911
|
+
bytes,
|
|
912
|
+
html,
|
|
913
|
+
template: {
|
|
914
|
+
key: STANDARD_EMAIL_TEMPLATE_KEY,
|
|
915
|
+
source: template.source,
|
|
916
|
+
version: template.version
|
|
917
|
+
},
|
|
918
|
+
text: htmlToPlainText(html),
|
|
919
|
+
tooLarge: bytes > STANDARD_EMAIL_HTML_MAX_BYTES
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
__name(renderStandardEmail, "renderStandardEmail");
|
|
621
923
|
export {
|
|
622
924
|
ChannelNotConfiguredError,
|
|
623
925
|
ConfigMissingError,
|
|
@@ -641,6 +943,15 @@ export {
|
|
|
641
943
|
PREVIEW_VIEWPORT_BY_CHANNEL,
|
|
642
944
|
PUSH_DRIVER,
|
|
643
945
|
RecipientUnresolvedError,
|
|
946
|
+
STANDARD_EMAIL_BUILTIN_TEMPLATE,
|
|
947
|
+
STANDARD_EMAIL_CHANNEL,
|
|
948
|
+
STANDARD_EMAIL_HTML_MAX_BYTES,
|
|
949
|
+
STANDARD_EMAIL_LOCALE,
|
|
950
|
+
STANDARD_EMAIL_REQUIRED_VARIABLES,
|
|
951
|
+
STANDARD_EMAIL_SYSTEM_HTML_VARIABLES,
|
|
952
|
+
STANDARD_EMAIL_TEMPLATE_KEY,
|
|
953
|
+
STANDARD_EMAIL_THEME,
|
|
954
|
+
STANDARD_EMAIL_VARIABLES,
|
|
644
955
|
SUPPRESSION_REASON,
|
|
645
956
|
SuppressedTargetError,
|
|
646
957
|
TEMPLATE_CONSTRAINTS_BY_CHANNEL,
|
|
@@ -649,6 +960,8 @@ export {
|
|
|
649
960
|
TemplateNotFoundError,
|
|
650
961
|
ThrottledError,
|
|
651
962
|
UnknownTemplateVariablesError,
|
|
963
|
+
assessStandardEmailTemplate,
|
|
964
|
+
buildInitials,
|
|
652
965
|
buildPreviewPayload,
|
|
653
966
|
categoryPolicyEntrySchema,
|
|
654
967
|
checkEmailAttachment,
|
|
@@ -656,12 +969,19 @@ export {
|
|
|
656
969
|
deliveryWebhookSchema,
|
|
657
970
|
deriveTitleFromBody,
|
|
658
971
|
diffTemplateVariables,
|
|
972
|
+
escapeEmailHtml,
|
|
659
973
|
escapeTemplateHtml,
|
|
660
974
|
extractTemplatePlaceholders,
|
|
975
|
+
findUnsafeEmailHtml,
|
|
976
|
+
htmlToPlainText,
|
|
977
|
+
interpolateEmailHtml,
|
|
661
978
|
interpolateTemplate,
|
|
662
979
|
listNotificationsQuerySchema,
|
|
663
980
|
preferenceEntrySchema,
|
|
664
981
|
registerDeviceSchema,
|
|
982
|
+
renderEmailLogoHtml,
|
|
983
|
+
renderEmailMarksHtml,
|
|
984
|
+
renderStandardEmail,
|
|
665
985
|
renderTemplate,
|
|
666
986
|
sendNotificationSchema,
|
|
667
987
|
updateCategoryPoliciesSchema,
|