@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.d.cts CHANGED
@@ -1723,6 +1723,8 @@ type TemplateVariableDefinition = {
1723
1723
  readonly required: boolean;
1724
1724
  /** Chave de i18n do rótulo na tela. Ausente, a tela mostra o próprio `name`. */
1725
1725
  readonly labelKey?: string;
1726
+ /** Texto livre para quem edita o modelo ("nome do cliente"). Ausente, a tela mostra só o `name`. */
1727
+ readonly description?: string;
1726
1728
  };
1727
1729
  /** `templateKey` → variáveis que o produto promete enviar no payload daquela notificação. */
1728
1730
  type TemplateVariableCatalog = Readonly<Record<string, readonly TemplateVariableDefinition[]>>;
@@ -1758,6 +1760,58 @@ declare function diffTemplateVariables(params: DiffTemplateVariablesParams): Tem
1758
1760
  */
1759
1761
  declare function buildPreviewPayload(variables: readonly TemplateVariableDefinition[] | undefined): Readonly<Record<string, string>>;
1760
1762
 
1763
+ /**
1764
+ * Copyright (c) 2026 Ada Technology. MIT License.
1765
+ *
1766
+ * A definição de um template: o que o host declara no boot para que o painel saiba rotular,
1767
+ * explicar, validar e restaurar o texto. O conteúdo editável vive no banco (versionado); a definição
1768
+ * é código do host e nunca é gravada — por isso evoluir rótulo, descrição ou variáveis não exige
1769
+ * migration.
1770
+ *
1771
+ * Mora no contracts porque a tela lista as definições e o módulo as valida com a MESMA regra.
1772
+ */
1773
+
1774
+ type TemplateDefinitionIdentity = {
1775
+ readonly key: string;
1776
+ readonly channel: NotificationChannel;
1777
+ readonly locale: string;
1778
+ };
1779
+ type TemplateDefinition = TemplateDefinitionIdentity & {
1780
+ /** Nome legível mostrado na lista do painel. */
1781
+ readonly label: string;
1782
+ readonly description?: string;
1783
+ /** Variáveis que o payload promete, com descrição e exemplo. Alimenta validação e preview. */
1784
+ readonly variables: readonly TemplateVariableDefinition[];
1785
+ /** Texto padrão: gravado como v1 por `ensure` e reaplicado por "restaurar padrão". */
1786
+ readonly body: string;
1787
+ readonly subject?: string;
1788
+ readonly whatsappTemplateName?: string;
1789
+ };
1790
+ /** Uma linha do painel: a definição do host + o estado gravado. Contrato de `GET /notification-template-definitions`. */
1791
+ type TemplateEditorItem = {
1792
+ readonly key: string;
1793
+ readonly channel: NotificationChannel;
1794
+ readonly locale: string;
1795
+ readonly label: string;
1796
+ readonly description?: string;
1797
+ readonly variables: readonly TemplateVariableDefinition[];
1798
+ readonly defaultBody: string;
1799
+ readonly defaultSubject?: string;
1800
+ /** A versão ativa mais alta; ausente se nunca foi gravada ou foi desativada. */
1801
+ readonly current?: NotificationTemplate;
1802
+ /** `true` quando o texto ativo difere do padrão — é o que habilita "restaurar padrão". */
1803
+ readonly isCustomized: boolean;
1804
+ };
1805
+ declare class InvalidTemplateDefinitionError extends Error {
1806
+ readonly definitionKey: string;
1807
+ constructor(definitionKey: string, reason: string);
1808
+ }
1809
+ /** Catálogo por `key`. Locales diferentes da mesma chave compartilham as variáveis da primeira. */
1810
+ declare function buildTemplateVariableCatalog(definitions: readonly TemplateDefinition[]): TemplateVariableCatalog;
1811
+ declare function findTemplateDefinition(definitions: readonly TemplateDefinition[], identity: TemplateDefinitionIdentity): TemplateDefinition | undefined;
1812
+ /** Falha no boot, não no primeiro "restaurar": um padrão que o próprio `upsert` recusaria é bug do host. */
1813
+ declare function assertTemplateDefinitions(definitions: readonly TemplateDefinition[]): void;
1814
+
1761
1815
  /**
1762
1816
  * Copyright (c) 2026 Ada Technology. MIT License.
1763
1817
  *
@@ -1953,4 +2007,4 @@ declare function generateIcsContent(event: NotificationCalendarEvent, now?: Date
1953
2007
  */
1954
2008
  declare function extractCalendarEvent(payload?: Readonly<Record<string, unknown>>): NotificationCalendarEvent | undefined;
1955
2009
 
1956
- export { type BroadcastPushBody, type BroadcastPushFilter, type BroadcastPushFilterBody, type BroadcastPushParams, type BroadcastPushResult, type CachePort, type CalendarLinks, 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, InvalidVapidKeysError, 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 NotificationCalendarEvent, 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 PushNotificationPayload, type PushNotificationPayloadBody, type PushServiceContainerConfig, type PushServicePort, type PushSubscriptionRecord, type QueuePort, type RealtimeEvent, type RealtimeNotifierPort, type RealtimeSubscription, type RecipientResolverPort, RecipientUnresolvedError, type RegisterDeviceBody, type RegisterPushSubscriptionBody, type RegisterPushSubscriptionParams, 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 SendPushDirectBody, type SendPushDirectParams, type SendPushDirectResult, type SendPushDirectTarget, type SendPushDirectTargetBody, type SendPushParams, type SendSmsParams, type SendWhatsAppParams, type SendWhatsAppTemplateParams, type SmsDriverPort, type StandardEmailAssessment, type StandardEmailInput, type StandardEmailSystemHtmlVariable, type StandardEmailTemplate, SubscriptionNotFoundError, 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 VapidKeys, WebPushEncryptionError, type WebPushKeys, type WebPushKeysBody, type WebPushSubscription, type WebPushSubscriptionBody, type WhatsAppDriverPort, type WhatsAppSendingChannel, assessStandardEmailTemplate, broadcastPushFilterSchema, broadcastPushSchema, buildInitials, buildPreviewPayload, categoryPolicyEntrySchema, checkEmailAttachment, createWhatsAppDriverFromChannel, deliveryWebhookSchema, deriveTitleFromBody, diffTemplateVariables, escapeEmailHtml, escapeTemplateHtml, extractCalendarEvent, extractTemplatePlaceholders, findUnsafeEmailHtml, generateCalendarLinks, generateGoogleCalendarUrl, generateIcsContent, generateIcsDataUri, generateOffice365CalendarUrl, generateOutlookCalendarUrl, generateYahooCalendarUrl, htmlToPlainText, interpolateEmailHtml, interpolateTemplate, listNotificationsQuerySchema, preferenceEntrySchema, pushNotificationPayloadSchema, registerDeviceSchema, registerPushSubscriptionSchema, renderEmailLogoHtml, renderEmailMarksHtml, renderStandardEmail, renderTemplate, sendNotificationSchema, sendPushDirectSchema, sendPushDirectTargetSchema, updateCategoryPoliciesSchema, updatePreferencesSchema, upsertTemplateSchema, webPushKeysSchema, webPushSubscriptionSchema };
2010
+ export { type BroadcastPushBody, type BroadcastPushFilter, type BroadcastPushFilterBody, type BroadcastPushParams, type BroadcastPushResult, type CachePort, type CalendarLinks, 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, InvalidTemplateDefinitionError, InvalidVapidKeysError, 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 NotificationCalendarEvent, 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 PushNotificationPayload, type PushNotificationPayloadBody, type PushServiceContainerConfig, type PushServicePort, type PushSubscriptionRecord, type QueuePort, type RealtimeEvent, type RealtimeNotifierPort, type RealtimeSubscription, type RecipientResolverPort, RecipientUnresolvedError, type RegisterDeviceBody, type RegisterPushSubscriptionBody, type RegisterPushSubscriptionParams, 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 SendPushDirectBody, type SendPushDirectParams, type SendPushDirectResult, type SendPushDirectTarget, type SendPushDirectTargetBody, type SendPushParams, type SendSmsParams, type SendWhatsAppParams, type SendWhatsAppTemplateParams, type SmsDriverPort, type StandardEmailAssessment, type StandardEmailInput, type StandardEmailSystemHtmlVariable, type StandardEmailTemplate, SubscriptionNotFoundError, SuppressedTargetError, type SuppressionReason, TEMPLATE_CONSTRAINTS_BY_CHANNEL, TEMPLATE_VARIABLE_KIND, type TemplateConstraintCheck, type TemplateConstraintField, type TemplateConstraintLimits, type TemplateDefinition, type TemplateDefinitionIdentity, type TemplateEditorItem, 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 VapidKeys, WebPushEncryptionError, type WebPushKeys, type WebPushKeysBody, type WebPushSubscription, type WebPushSubscriptionBody, type WhatsAppDriverPort, type WhatsAppSendingChannel, assertTemplateDefinitions, assessStandardEmailTemplate, broadcastPushFilterSchema, broadcastPushSchema, buildInitials, buildPreviewPayload, buildTemplateVariableCatalog, categoryPolicyEntrySchema, checkEmailAttachment, createWhatsAppDriverFromChannel, deliveryWebhookSchema, deriveTitleFromBody, diffTemplateVariables, escapeEmailHtml, escapeTemplateHtml, extractCalendarEvent, extractTemplatePlaceholders, findTemplateDefinition, findUnsafeEmailHtml, generateCalendarLinks, generateGoogleCalendarUrl, generateIcsContent, generateIcsDataUri, generateOffice365CalendarUrl, generateOutlookCalendarUrl, generateYahooCalendarUrl, htmlToPlainText, interpolateEmailHtml, interpolateTemplate, listNotificationsQuerySchema, preferenceEntrySchema, pushNotificationPayloadSchema, registerDeviceSchema, registerPushSubscriptionSchema, renderEmailLogoHtml, renderEmailMarksHtml, renderStandardEmail, renderTemplate, sendNotificationSchema, sendPushDirectSchema, sendPushDirectTargetSchema, updateCategoryPoliciesSchema, updatePreferencesSchema, upsertTemplateSchema, webPushKeysSchema, webPushSubscriptionSchema };
package/dist/index.d.ts CHANGED
@@ -1723,6 +1723,8 @@ type TemplateVariableDefinition = {
1723
1723
  readonly required: boolean;
1724
1724
  /** Chave de i18n do rótulo na tela. Ausente, a tela mostra o próprio `name`. */
1725
1725
  readonly labelKey?: string;
1726
+ /** Texto livre para quem edita o modelo ("nome do cliente"). Ausente, a tela mostra só o `name`. */
1727
+ readonly description?: string;
1726
1728
  };
1727
1729
  /** `templateKey` → variáveis que o produto promete enviar no payload daquela notificação. */
1728
1730
  type TemplateVariableCatalog = Readonly<Record<string, readonly TemplateVariableDefinition[]>>;
@@ -1758,6 +1760,58 @@ declare function diffTemplateVariables(params: DiffTemplateVariablesParams): Tem
1758
1760
  */
1759
1761
  declare function buildPreviewPayload(variables: readonly TemplateVariableDefinition[] | undefined): Readonly<Record<string, string>>;
1760
1762
 
1763
+ /**
1764
+ * Copyright (c) 2026 Ada Technology. MIT License.
1765
+ *
1766
+ * A definição de um template: o que o host declara no boot para que o painel saiba rotular,
1767
+ * explicar, validar e restaurar o texto. O conteúdo editável vive no banco (versionado); a definição
1768
+ * é código do host e nunca é gravada — por isso evoluir rótulo, descrição ou variáveis não exige
1769
+ * migration.
1770
+ *
1771
+ * Mora no contracts porque a tela lista as definições e o módulo as valida com a MESMA regra.
1772
+ */
1773
+
1774
+ type TemplateDefinitionIdentity = {
1775
+ readonly key: string;
1776
+ readonly channel: NotificationChannel;
1777
+ readonly locale: string;
1778
+ };
1779
+ type TemplateDefinition = TemplateDefinitionIdentity & {
1780
+ /** Nome legível mostrado na lista do painel. */
1781
+ readonly label: string;
1782
+ readonly description?: string;
1783
+ /** Variáveis que o payload promete, com descrição e exemplo. Alimenta validação e preview. */
1784
+ readonly variables: readonly TemplateVariableDefinition[];
1785
+ /** Texto padrão: gravado como v1 por `ensure` e reaplicado por "restaurar padrão". */
1786
+ readonly body: string;
1787
+ readonly subject?: string;
1788
+ readonly whatsappTemplateName?: string;
1789
+ };
1790
+ /** Uma linha do painel: a definição do host + o estado gravado. Contrato de `GET /notification-template-definitions`. */
1791
+ type TemplateEditorItem = {
1792
+ readonly key: string;
1793
+ readonly channel: NotificationChannel;
1794
+ readonly locale: string;
1795
+ readonly label: string;
1796
+ readonly description?: string;
1797
+ readonly variables: readonly TemplateVariableDefinition[];
1798
+ readonly defaultBody: string;
1799
+ readonly defaultSubject?: string;
1800
+ /** A versão ativa mais alta; ausente se nunca foi gravada ou foi desativada. */
1801
+ readonly current?: NotificationTemplate;
1802
+ /** `true` quando o texto ativo difere do padrão — é o que habilita "restaurar padrão". */
1803
+ readonly isCustomized: boolean;
1804
+ };
1805
+ declare class InvalidTemplateDefinitionError extends Error {
1806
+ readonly definitionKey: string;
1807
+ constructor(definitionKey: string, reason: string);
1808
+ }
1809
+ /** Catálogo por `key`. Locales diferentes da mesma chave compartilham as variáveis da primeira. */
1810
+ declare function buildTemplateVariableCatalog(definitions: readonly TemplateDefinition[]): TemplateVariableCatalog;
1811
+ declare function findTemplateDefinition(definitions: readonly TemplateDefinition[], identity: TemplateDefinitionIdentity): TemplateDefinition | undefined;
1812
+ /** Falha no boot, não no primeiro "restaurar": um padrão que o próprio `upsert` recusaria é bug do host. */
1813
+ declare function assertTemplateDefinitions(definitions: readonly TemplateDefinition[]): void;
1814
+
1761
1815
  /**
1762
1816
  * Copyright (c) 2026 Ada Technology. MIT License.
1763
1817
  *
@@ -1953,4 +2007,4 @@ declare function generateIcsContent(event: NotificationCalendarEvent, now?: Date
1953
2007
  */
1954
2008
  declare function extractCalendarEvent(payload?: Readonly<Record<string, unknown>>): NotificationCalendarEvent | undefined;
1955
2009
 
1956
- export { type BroadcastPushBody, type BroadcastPushFilter, type BroadcastPushFilterBody, type BroadcastPushParams, type BroadcastPushResult, type CachePort, type CalendarLinks, 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, InvalidVapidKeysError, 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 NotificationCalendarEvent, 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 PushNotificationPayload, type PushNotificationPayloadBody, type PushServiceContainerConfig, type PushServicePort, type PushSubscriptionRecord, type QueuePort, type RealtimeEvent, type RealtimeNotifierPort, type RealtimeSubscription, type RecipientResolverPort, RecipientUnresolvedError, type RegisterDeviceBody, type RegisterPushSubscriptionBody, type RegisterPushSubscriptionParams, 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 SendPushDirectBody, type SendPushDirectParams, type SendPushDirectResult, type SendPushDirectTarget, type SendPushDirectTargetBody, type SendPushParams, type SendSmsParams, type SendWhatsAppParams, type SendWhatsAppTemplateParams, type SmsDriverPort, type StandardEmailAssessment, type StandardEmailInput, type StandardEmailSystemHtmlVariable, type StandardEmailTemplate, SubscriptionNotFoundError, 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 VapidKeys, WebPushEncryptionError, type WebPushKeys, type WebPushKeysBody, type WebPushSubscription, type WebPushSubscriptionBody, type WhatsAppDriverPort, type WhatsAppSendingChannel, assessStandardEmailTemplate, broadcastPushFilterSchema, broadcastPushSchema, buildInitials, buildPreviewPayload, categoryPolicyEntrySchema, checkEmailAttachment, createWhatsAppDriverFromChannel, deliveryWebhookSchema, deriveTitleFromBody, diffTemplateVariables, escapeEmailHtml, escapeTemplateHtml, extractCalendarEvent, extractTemplatePlaceholders, findUnsafeEmailHtml, generateCalendarLinks, generateGoogleCalendarUrl, generateIcsContent, generateIcsDataUri, generateOffice365CalendarUrl, generateOutlookCalendarUrl, generateYahooCalendarUrl, htmlToPlainText, interpolateEmailHtml, interpolateTemplate, listNotificationsQuerySchema, preferenceEntrySchema, pushNotificationPayloadSchema, registerDeviceSchema, registerPushSubscriptionSchema, renderEmailLogoHtml, renderEmailMarksHtml, renderStandardEmail, renderTemplate, sendNotificationSchema, sendPushDirectSchema, sendPushDirectTargetSchema, updateCategoryPoliciesSchema, updatePreferencesSchema, upsertTemplateSchema, webPushKeysSchema, webPushSubscriptionSchema };
2010
+ export { type BroadcastPushBody, type BroadcastPushFilter, type BroadcastPushFilterBody, type BroadcastPushParams, type BroadcastPushResult, type CachePort, type CalendarLinks, 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, InvalidTemplateDefinitionError, InvalidVapidKeysError, 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 NotificationCalendarEvent, 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 PushNotificationPayload, type PushNotificationPayloadBody, type PushServiceContainerConfig, type PushServicePort, type PushSubscriptionRecord, type QueuePort, type RealtimeEvent, type RealtimeNotifierPort, type RealtimeSubscription, type RecipientResolverPort, RecipientUnresolvedError, type RegisterDeviceBody, type RegisterPushSubscriptionBody, type RegisterPushSubscriptionParams, 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 SendPushDirectBody, type SendPushDirectParams, type SendPushDirectResult, type SendPushDirectTarget, type SendPushDirectTargetBody, type SendPushParams, type SendSmsParams, type SendWhatsAppParams, type SendWhatsAppTemplateParams, type SmsDriverPort, type StandardEmailAssessment, type StandardEmailInput, type StandardEmailSystemHtmlVariable, type StandardEmailTemplate, SubscriptionNotFoundError, SuppressedTargetError, type SuppressionReason, TEMPLATE_CONSTRAINTS_BY_CHANNEL, TEMPLATE_VARIABLE_KIND, type TemplateConstraintCheck, type TemplateConstraintField, type TemplateConstraintLimits, type TemplateDefinition, type TemplateDefinitionIdentity, type TemplateEditorItem, 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 VapidKeys, WebPushEncryptionError, type WebPushKeys, type WebPushKeysBody, type WebPushSubscription, type WebPushSubscriptionBody, type WhatsAppDriverPort, type WhatsAppSendingChannel, assertTemplateDefinitions, assessStandardEmailTemplate, broadcastPushFilterSchema, broadcastPushSchema, buildInitials, buildPreviewPayload, buildTemplateVariableCatalog, categoryPolicyEntrySchema, checkEmailAttachment, createWhatsAppDriverFromChannel, deliveryWebhookSchema, deriveTitleFromBody, diffTemplateVariables, escapeEmailHtml, escapeTemplateHtml, extractCalendarEvent, extractTemplatePlaceholders, findTemplateDefinition, findUnsafeEmailHtml, generateCalendarLinks, generateGoogleCalendarUrl, generateIcsContent, generateIcsDataUri, generateOffice365CalendarUrl, generateOutlookCalendarUrl, generateYahooCalendarUrl, htmlToPlainText, interpolateEmailHtml, interpolateTemplate, listNotificationsQuerySchema, preferenceEntrySchema, pushNotificationPayloadSchema, registerDeviceSchema, registerPushSubscriptionSchema, renderEmailLogoHtml, renderEmailMarksHtml, renderStandardEmail, renderTemplate, sendNotificationSchema, sendPushDirectSchema, sendPushDirectTargetSchema, updateCategoryPoliciesSchema, updatePreferencesSchema, upsertTemplateSchema, webPushKeysSchema, webPushSubscriptionSchema };
package/dist/index.js CHANGED
@@ -708,6 +708,53 @@ function buildPreviewPayload(variables) {
708
708
  }
709
709
  __name(buildPreviewPayload, "buildPreviewPayload");
710
710
 
711
+ // src/templateDefinition.ts
712
+ var InvalidTemplateDefinitionError = class extends Error {
713
+ static {
714
+ __name(this, "InvalidTemplateDefinitionError");
715
+ }
716
+ definitionKey;
717
+ constructor(definitionKey, reason) {
718
+ super(`Defini\xE7\xE3o de template inv\xE1lida (${definitionKey}): ${reason}`), this.definitionKey = definitionKey;
719
+ this.name = "InvalidTemplateDefinitionError";
720
+ }
721
+ };
722
+ function buildTemplateVariableCatalog(definitions) {
723
+ const catalog = {};
724
+ for (const definition of definitions) {
725
+ catalog[definition.key] ??= definition.variables;
726
+ }
727
+ return catalog;
728
+ }
729
+ __name(buildTemplateVariableCatalog, "buildTemplateVariableCatalog");
730
+ function findTemplateDefinition(definitions, identity) {
731
+ return definitions.find((definition) => definition.key === identity.key && definition.channel === identity.channel && definition.locale === identity.locale);
732
+ }
733
+ __name(findTemplateDefinition, "findTemplateDefinition");
734
+ function assertTemplateDefinitions(definitions) {
735
+ const seen = /* @__PURE__ */ new Set();
736
+ for (const definition of definitions) {
737
+ const identity = `${definition.key}|${definition.channel}|${definition.locale}`;
738
+ if (seen.has(identity)) throw new InvalidTemplateDefinitionError(definition.key, "identidade duplicada");
739
+ seen.add(identity);
740
+ if (definition.label.trim() === "") throw new InvalidTemplateDefinitionError(definition.key, "label vazio");
741
+ if (definition.body.trim() === "") throw new InvalidTemplateDefinitionError(definition.key, "body vazio");
742
+ const names = definition.variables.map((variable) => variable.name);
743
+ if (new Set(names).size !== names.length) {
744
+ throw new InvalidTemplateDefinitionError(definition.key, "vari\xE1vel declarada duas vezes");
745
+ }
746
+ const { unknown } = diffTemplateVariables({
747
+ body: definition.body,
748
+ subject: definition.subject,
749
+ variables: definition.variables
750
+ });
751
+ if (unknown.length > 0) {
752
+ throw new InvalidTemplateDefinitionError(definition.key, `o texto padr\xE3o usa vari\xE1veis n\xE3o declaradas: ${unknown.join(", ")}`);
753
+ }
754
+ }
755
+ }
756
+ __name(assertTemplateDefinitions, "assertTemplateDefinitions");
757
+
711
758
  // src/emailHtml.ts
712
759
  var STANDARD_EMAIL_THEME = {
713
760
  colors: {
@@ -1170,6 +1217,7 @@ export {
1170
1217
  EMAIL_ATTACHMENT_MAX_COUNT,
1171
1218
  EMAIL_DRIVER,
1172
1219
  INTRUSIVE_CHANNELS,
1220
+ InvalidTemplateDefinitionError,
1173
1221
  InvalidVapidKeysError,
1174
1222
  InvalidWebhookSignatureError,
1175
1223
  NOTIFICATION_CATEGORY_HINT,
@@ -1202,11 +1250,13 @@ export {
1202
1250
  ThrottledError,
1203
1251
  UnknownTemplateVariablesError,
1204
1252
  WebPushEncryptionError,
1253
+ assertTemplateDefinitions,
1205
1254
  assessStandardEmailTemplate,
1206
1255
  broadcastPushFilterSchema,
1207
1256
  broadcastPushSchema,
1208
1257
  buildInitials,
1209
1258
  buildPreviewPayload,
1259
+ buildTemplateVariableCatalog,
1210
1260
  categoryPolicyEntrySchema,
1211
1261
  checkEmailAttachment,
1212
1262
  createWhatsAppDriverFromChannel,
@@ -1217,6 +1267,7 @@ export {
1217
1267
  escapeTemplateHtml,
1218
1268
  extractCalendarEvent,
1219
1269
  extractTemplatePlaceholders,
1270
+ findTemplateDefinition,
1220
1271
  findUnsafeEmailHtml,
1221
1272
  generateCalendarLinks,
1222
1273
  generateGoogleCalendarUrl,