@adatechnology/notification-contracts 0.5.0 → 0.6.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 +55 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -1
- package/dist/index.d.ts +55 -1
- package/dist/index.js +51 -0
- 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,13 @@ __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,
|
|
69
71
|
buildInitials: () => buildInitials,
|
|
70
72
|
buildPreviewPayload: () => buildPreviewPayload,
|
|
73
|
+
buildTemplateVariableCatalog: () => buildTemplateVariableCatalog,
|
|
71
74
|
categoryPolicyEntrySchema: () => categoryPolicyEntrySchema,
|
|
72
75
|
checkEmailAttachment: () => checkEmailAttachment,
|
|
73
76
|
createWhatsAppDriverFromChannel: () => createWhatsAppDriverFromChannel,
|
|
@@ -78,6 +81,7 @@ __export(index_exports, {
|
|
|
78
81
|
escapeTemplateHtml: () => escapeTemplateHtml,
|
|
79
82
|
extractCalendarEvent: () => extractCalendarEvent,
|
|
80
83
|
extractTemplatePlaceholders: () => extractTemplatePlaceholders,
|
|
84
|
+
findTemplateDefinition: () => findTemplateDefinition,
|
|
81
85
|
findUnsafeEmailHtml: () => findUnsafeEmailHtml,
|
|
82
86
|
generateCalendarLinks: () => generateCalendarLinks,
|
|
83
87
|
generateGoogleCalendarUrl: () => generateGoogleCalendarUrl,
|
|
@@ -816,6 +820,53 @@ function buildPreviewPayload(variables) {
|
|
|
816
820
|
}
|
|
817
821
|
__name(buildPreviewPayload, "buildPreviewPayload");
|
|
818
822
|
|
|
823
|
+
// src/templateDefinition.ts
|
|
824
|
+
var InvalidTemplateDefinitionError = class extends Error {
|
|
825
|
+
static {
|
|
826
|
+
__name(this, "InvalidTemplateDefinitionError");
|
|
827
|
+
}
|
|
828
|
+
definitionKey;
|
|
829
|
+
constructor(definitionKey, reason) {
|
|
830
|
+
super(`Defini\xE7\xE3o de template inv\xE1lida (${definitionKey}): ${reason}`), this.definitionKey = definitionKey;
|
|
831
|
+
this.name = "InvalidTemplateDefinitionError";
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
function buildTemplateVariableCatalog(definitions) {
|
|
835
|
+
const catalog = {};
|
|
836
|
+
for (const definition of definitions) {
|
|
837
|
+
catalog[definition.key] ??= definition.variables;
|
|
838
|
+
}
|
|
839
|
+
return catalog;
|
|
840
|
+
}
|
|
841
|
+
__name(buildTemplateVariableCatalog, "buildTemplateVariableCatalog");
|
|
842
|
+
function findTemplateDefinition(definitions, identity) {
|
|
843
|
+
return definitions.find((definition) => definition.key === identity.key && definition.channel === identity.channel && definition.locale === identity.locale);
|
|
844
|
+
}
|
|
845
|
+
__name(findTemplateDefinition, "findTemplateDefinition");
|
|
846
|
+
function assertTemplateDefinitions(definitions) {
|
|
847
|
+
const seen = /* @__PURE__ */ new Set();
|
|
848
|
+
for (const definition of definitions) {
|
|
849
|
+
const identity = `${definition.key}|${definition.channel}|${definition.locale}`;
|
|
850
|
+
if (seen.has(identity)) throw new InvalidTemplateDefinitionError(definition.key, "identidade duplicada");
|
|
851
|
+
seen.add(identity);
|
|
852
|
+
if (definition.label.trim() === "") throw new InvalidTemplateDefinitionError(definition.key, "label vazio");
|
|
853
|
+
if (definition.body.trim() === "") throw new InvalidTemplateDefinitionError(definition.key, "body vazio");
|
|
854
|
+
const names = definition.variables.map((variable) => variable.name);
|
|
855
|
+
if (new Set(names).size !== names.length) {
|
|
856
|
+
throw new InvalidTemplateDefinitionError(definition.key, "vari\xE1vel declarada duas vezes");
|
|
857
|
+
}
|
|
858
|
+
const { unknown } = diffTemplateVariables({
|
|
859
|
+
body: definition.body,
|
|
860
|
+
subject: definition.subject,
|
|
861
|
+
variables: definition.variables
|
|
862
|
+
});
|
|
863
|
+
if (unknown.length > 0) {
|
|
864
|
+
throw new InvalidTemplateDefinitionError(definition.key, `o texto padr\xE3o usa vari\xE1veis n\xE3o declaradas: ${unknown.join(", ")}`);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
__name(assertTemplateDefinitions, "assertTemplateDefinitions");
|
|
869
|
+
|
|
819
870
|
// src/emailHtml.ts
|
|
820
871
|
var STANDARD_EMAIL_THEME = {
|
|
821
872
|
colors: {
|
|
@@ -1279,6 +1330,7 @@ __name(extractCalendarEvent, "extractCalendarEvent");
|
|
|
1279
1330
|
EMAIL_ATTACHMENT_MAX_COUNT,
|
|
1280
1331
|
EMAIL_DRIVER,
|
|
1281
1332
|
INTRUSIVE_CHANNELS,
|
|
1333
|
+
InvalidTemplateDefinitionError,
|
|
1282
1334
|
InvalidVapidKeysError,
|
|
1283
1335
|
InvalidWebhookSignatureError,
|
|
1284
1336
|
NOTIFICATION_CATEGORY_HINT,
|
|
@@ -1311,11 +1363,13 @@ __name(extractCalendarEvent, "extractCalendarEvent");
|
|
|
1311
1363
|
ThrottledError,
|
|
1312
1364
|
UnknownTemplateVariablesError,
|
|
1313
1365
|
WebPushEncryptionError,
|
|
1366
|
+
assertTemplateDefinitions,
|
|
1314
1367
|
assessStandardEmailTemplate,
|
|
1315
1368
|
broadcastPushFilterSchema,
|
|
1316
1369
|
broadcastPushSchema,
|
|
1317
1370
|
buildInitials,
|
|
1318
1371
|
buildPreviewPayload,
|
|
1372
|
+
buildTemplateVariableCatalog,
|
|
1319
1373
|
categoryPolicyEntrySchema,
|
|
1320
1374
|
checkEmailAttachment,
|
|
1321
1375
|
createWhatsAppDriverFromChannel,
|
|
@@ -1326,6 +1380,7 @@ __name(extractCalendarEvent, "extractCalendarEvent");
|
|
|
1326
1380
|
escapeTemplateHtml,
|
|
1327
1381
|
extractCalendarEvent,
|
|
1328
1382
|
extractTemplatePlaceholders,
|
|
1383
|
+
findTemplateDefinition,
|
|
1329
1384
|
findUnsafeEmailHtml,
|
|
1330
1385
|
generateCalendarLinks,
|
|
1331
1386
|
generateGoogleCalendarUrl,
|