@adatechnology/notification-contracts 0.4.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 +221 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +107 -1
- package/dist/index.d.ts +107 -1
- package/dist/index.js +209 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
*
|
|
@@ -1901,4 +1955,56 @@ declare function renderStandardEmail(params: {
|
|
|
1901
1955
|
readonly template: StandardEmailTemplate;
|
|
1902
1956
|
}): RenderedStandardEmail;
|
|
1903
1957
|
|
|
1904
|
-
|
|
1958
|
+
/**
|
|
1959
|
+
* Copyright (c) 2026 Ada Technology. MIT License.
|
|
1960
|
+
*/
|
|
1961
|
+
type NotificationCalendarEvent = {
|
|
1962
|
+
readonly title: string;
|
|
1963
|
+
readonly description?: string;
|
|
1964
|
+
readonly startsAt: string | Date;
|
|
1965
|
+
readonly endsAt?: string | Date;
|
|
1966
|
+
readonly location?: string;
|
|
1967
|
+
readonly url?: string;
|
|
1968
|
+
};
|
|
1969
|
+
/**
|
|
1970
|
+
* Gera URL para adicionar evento no Google Calendar via web.
|
|
1971
|
+
*/
|
|
1972
|
+
declare function generateGoogleCalendarUrl(event: NotificationCalendarEvent): string;
|
|
1973
|
+
/**
|
|
1974
|
+
* Gera URL para adicionar evento no Outlook Web / Live.
|
|
1975
|
+
*/
|
|
1976
|
+
declare function generateOutlookCalendarUrl(event: NotificationCalendarEvent): string;
|
|
1977
|
+
/**
|
|
1978
|
+
* Gera URL para adicionar evento no Microsoft 365 / Office 365 corporativo.
|
|
1979
|
+
*/
|
|
1980
|
+
declare function generateOffice365CalendarUrl(event: NotificationCalendarEvent): string;
|
|
1981
|
+
/**
|
|
1982
|
+
* Gera URL para adicionar evento no Yahoo Calendar.
|
|
1983
|
+
*/
|
|
1984
|
+
declare function generateYahooCalendarUrl(event: NotificationCalendarEvent): string;
|
|
1985
|
+
/**
|
|
1986
|
+
* Gera Data URI com o conteúdo iCalendar (.ics).
|
|
1987
|
+
* Permite abrir diretamente no Apple Calendar (iOS / macOS) ou disparar download no navegador.
|
|
1988
|
+
*/
|
|
1989
|
+
declare function generateIcsDataUri(event: NotificationCalendarEvent, now?: Date): string;
|
|
1990
|
+
type CalendarLinks = {
|
|
1991
|
+
readonly google: string;
|
|
1992
|
+
readonly outlook: string;
|
|
1993
|
+
readonly office365: string;
|
|
1994
|
+
readonly yahoo: string;
|
|
1995
|
+
readonly icsDataUri: string;
|
|
1996
|
+
};
|
|
1997
|
+
/**
|
|
1998
|
+
* Retorna todos os links de calendário disponíveis para uma notificação/evento.
|
|
1999
|
+
*/
|
|
2000
|
+
declare function generateCalendarLinks(event: NotificationCalendarEvent): CalendarLinks;
|
|
2001
|
+
/**
|
|
2002
|
+
* Gera conteúdo RFC 5545 iCalendar (.ics).
|
|
2003
|
+
*/
|
|
2004
|
+
declare function generateIcsContent(event: NotificationCalendarEvent, now?: Date): string;
|
|
2005
|
+
/**
|
|
2006
|
+
* Extrai metadados de evento de calendário do payload de notificação, se presente.
|
|
2007
|
+
*/
|
|
2008
|
+
declare function extractCalendarEvent(payload?: Readonly<Record<string, unknown>>): NotificationCalendarEvent | undefined;
|
|
2009
|
+
|
|
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
|
*
|
|
@@ -1901,4 +1955,56 @@ declare function renderStandardEmail(params: {
|
|
|
1901
1955
|
readonly template: StandardEmailTemplate;
|
|
1902
1956
|
}): RenderedStandardEmail;
|
|
1903
1957
|
|
|
1904
|
-
|
|
1958
|
+
/**
|
|
1959
|
+
* Copyright (c) 2026 Ada Technology. MIT License.
|
|
1960
|
+
*/
|
|
1961
|
+
type NotificationCalendarEvent = {
|
|
1962
|
+
readonly title: string;
|
|
1963
|
+
readonly description?: string;
|
|
1964
|
+
readonly startsAt: string | Date;
|
|
1965
|
+
readonly endsAt?: string | Date;
|
|
1966
|
+
readonly location?: string;
|
|
1967
|
+
readonly url?: string;
|
|
1968
|
+
};
|
|
1969
|
+
/**
|
|
1970
|
+
* Gera URL para adicionar evento no Google Calendar via web.
|
|
1971
|
+
*/
|
|
1972
|
+
declare function generateGoogleCalendarUrl(event: NotificationCalendarEvent): string;
|
|
1973
|
+
/**
|
|
1974
|
+
* Gera URL para adicionar evento no Outlook Web / Live.
|
|
1975
|
+
*/
|
|
1976
|
+
declare function generateOutlookCalendarUrl(event: NotificationCalendarEvent): string;
|
|
1977
|
+
/**
|
|
1978
|
+
* Gera URL para adicionar evento no Microsoft 365 / Office 365 corporativo.
|
|
1979
|
+
*/
|
|
1980
|
+
declare function generateOffice365CalendarUrl(event: NotificationCalendarEvent): string;
|
|
1981
|
+
/**
|
|
1982
|
+
* Gera URL para adicionar evento no Yahoo Calendar.
|
|
1983
|
+
*/
|
|
1984
|
+
declare function generateYahooCalendarUrl(event: NotificationCalendarEvent): string;
|
|
1985
|
+
/**
|
|
1986
|
+
* Gera Data URI com o conteúdo iCalendar (.ics).
|
|
1987
|
+
* Permite abrir diretamente no Apple Calendar (iOS / macOS) ou disparar download no navegador.
|
|
1988
|
+
*/
|
|
1989
|
+
declare function generateIcsDataUri(event: NotificationCalendarEvent, now?: Date): string;
|
|
1990
|
+
type CalendarLinks = {
|
|
1991
|
+
readonly google: string;
|
|
1992
|
+
readonly outlook: string;
|
|
1993
|
+
readonly office365: string;
|
|
1994
|
+
readonly yahoo: string;
|
|
1995
|
+
readonly icsDataUri: string;
|
|
1996
|
+
};
|
|
1997
|
+
/**
|
|
1998
|
+
* Retorna todos os links de calendário disponíveis para uma notificação/evento.
|
|
1999
|
+
*/
|
|
2000
|
+
declare function generateCalendarLinks(event: NotificationCalendarEvent): CalendarLinks;
|
|
2001
|
+
/**
|
|
2002
|
+
* Gera conteúdo RFC 5545 iCalendar (.ics).
|
|
2003
|
+
*/
|
|
2004
|
+
declare function generateIcsContent(event: NotificationCalendarEvent, now?: Date): string;
|
|
2005
|
+
/**
|
|
2006
|
+
* Extrai metadados de evento de calendário do payload de notificação, se presente.
|
|
2007
|
+
*/
|
|
2008
|
+
declare function extractCalendarEvent(payload?: Readonly<Record<string, unknown>>): NotificationCalendarEvent | undefined;
|
|
2009
|
+
|
|
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: {
|
|
@@ -1009,6 +1056,156 @@ function renderStandardEmail(params) {
|
|
|
1009
1056
|
};
|
|
1010
1057
|
}
|
|
1011
1058
|
__name(renderStandardEmail, "renderStandardEmail");
|
|
1059
|
+
|
|
1060
|
+
// src/calendarEvent.ts
|
|
1061
|
+
function toIsoDate(value) {
|
|
1062
|
+
return value instanceof Date ? value : new Date(value);
|
|
1063
|
+
}
|
|
1064
|
+
__name(toIsoDate, "toIsoDate");
|
|
1065
|
+
function formatUtcCompact(date) {
|
|
1066
|
+
return date.toISOString().replace(/[-:]/g, "").replace(/\.\d{3}/, "");
|
|
1067
|
+
}
|
|
1068
|
+
__name(formatUtcCompact, "formatUtcCompact");
|
|
1069
|
+
function escapeIcsText(text) {
|
|
1070
|
+
return text.replace(/\\/g, "\\\\").replace(/;/g, "\\;").replace(/,/g, "\\,").replace(/\r\n/g, "\\n").replace(/\n/g, "\\n");
|
|
1071
|
+
}
|
|
1072
|
+
__name(escapeIcsText, "escapeIcsText");
|
|
1073
|
+
function generateGoogleCalendarUrl(event) {
|
|
1074
|
+
const start = toIsoDate(event.startsAt);
|
|
1075
|
+
const end = event.endsAt ? toIsoDate(event.endsAt) : new Date(start.getTime() + 60 * 60 * 1e3);
|
|
1076
|
+
const params = new URLSearchParams({
|
|
1077
|
+
action: "TEMPLATE",
|
|
1078
|
+
text: event.title,
|
|
1079
|
+
dates: `${formatUtcCompact(start)}/${formatUtcCompact(end)}`
|
|
1080
|
+
});
|
|
1081
|
+
if (event.description) params.set("details", event.description);
|
|
1082
|
+
if (event.location) params.set("location", event.location);
|
|
1083
|
+
return `https://calendar.google.com/calendar/render?${params.toString()}`;
|
|
1084
|
+
}
|
|
1085
|
+
__name(generateGoogleCalendarUrl, "generateGoogleCalendarUrl");
|
|
1086
|
+
function generateOutlookCalendarUrl(event) {
|
|
1087
|
+
const start = toIsoDate(event.startsAt);
|
|
1088
|
+
const end = event.endsAt ? toIsoDate(event.endsAt) : new Date(start.getTime() + 60 * 60 * 1e3);
|
|
1089
|
+
const params = new URLSearchParams({
|
|
1090
|
+
path: "/calendar/action/compose",
|
|
1091
|
+
rru: "addevent",
|
|
1092
|
+
subject: event.title,
|
|
1093
|
+
startdt: start.toISOString(),
|
|
1094
|
+
enddt: end.toISOString()
|
|
1095
|
+
});
|
|
1096
|
+
if (event.description) params.set("body", event.description);
|
|
1097
|
+
if (event.location) params.set("location", event.location);
|
|
1098
|
+
return `https://outlook.live.com/calendar/0/deeplink/compose?${params.toString()}`;
|
|
1099
|
+
}
|
|
1100
|
+
__name(generateOutlookCalendarUrl, "generateOutlookCalendarUrl");
|
|
1101
|
+
function generateOffice365CalendarUrl(event) {
|
|
1102
|
+
const start = toIsoDate(event.startsAt);
|
|
1103
|
+
const end = event.endsAt ? toIsoDate(event.endsAt) : new Date(start.getTime() + 60 * 60 * 1e3);
|
|
1104
|
+
const params = new URLSearchParams({
|
|
1105
|
+
path: "/calendar/action/compose",
|
|
1106
|
+
rru: "addevent",
|
|
1107
|
+
subject: event.title,
|
|
1108
|
+
startdt: start.toISOString(),
|
|
1109
|
+
enddt: end.toISOString()
|
|
1110
|
+
});
|
|
1111
|
+
if (event.description) params.set("body", event.description);
|
|
1112
|
+
if (event.location) params.set("location", event.location);
|
|
1113
|
+
return `https://outlook.office.com/calendar/0/deeplink/compose?${params.toString()}`;
|
|
1114
|
+
}
|
|
1115
|
+
__name(generateOffice365CalendarUrl, "generateOffice365CalendarUrl");
|
|
1116
|
+
function generateYahooCalendarUrl(event) {
|
|
1117
|
+
const start = toIsoDate(event.startsAt);
|
|
1118
|
+
const end = event.endsAt ? toIsoDate(event.endsAt) : new Date(start.getTime() + 60 * 60 * 1e3);
|
|
1119
|
+
const durationMs = Math.max(0, end.getTime() - start.getTime());
|
|
1120
|
+
const durationHours = Math.floor(durationMs / (60 * 60 * 1e3));
|
|
1121
|
+
const durationMinutes = Math.floor(durationMs % (60 * 60 * 1e3) / (60 * 1e3));
|
|
1122
|
+
const durStr = `${String(durationHours).padStart(2, "0")}${String(durationMinutes).padStart(2, "0")}`;
|
|
1123
|
+
const params = new URLSearchParams({
|
|
1124
|
+
v: "60",
|
|
1125
|
+
view: "d",
|
|
1126
|
+
type: "20",
|
|
1127
|
+
title: event.title,
|
|
1128
|
+
st: formatUtcCompact(start),
|
|
1129
|
+
dur: durStr
|
|
1130
|
+
});
|
|
1131
|
+
if (event.description) params.set("desc", event.description);
|
|
1132
|
+
if (event.location) params.set("in_loc", event.location);
|
|
1133
|
+
return `https://calendar.yahoo.com/?${params.toString()}`;
|
|
1134
|
+
}
|
|
1135
|
+
__name(generateYahooCalendarUrl, "generateYahooCalendarUrl");
|
|
1136
|
+
function generateIcsDataUri(event, now = /* @__PURE__ */ new Date()) {
|
|
1137
|
+
const ics = generateIcsContent(event, now);
|
|
1138
|
+
return `data:text/calendar;charset=utf-8,${encodeURIComponent(ics)}`;
|
|
1139
|
+
}
|
|
1140
|
+
__name(generateIcsDataUri, "generateIcsDataUri");
|
|
1141
|
+
function generateCalendarLinks(event) {
|
|
1142
|
+
return {
|
|
1143
|
+
google: generateGoogleCalendarUrl(event),
|
|
1144
|
+
outlook: generateOutlookCalendarUrl(event),
|
|
1145
|
+
office365: generateOffice365CalendarUrl(event),
|
|
1146
|
+
yahoo: generateYahooCalendarUrl(event),
|
|
1147
|
+
icsDataUri: generateIcsDataUri(event)
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1150
|
+
__name(generateCalendarLinks, "generateCalendarLinks");
|
|
1151
|
+
function generateIcsContent(event, now = /* @__PURE__ */ new Date()) {
|
|
1152
|
+
const start = toIsoDate(event.startsAt);
|
|
1153
|
+
const end = event.endsAt ? toIsoDate(event.endsAt) : new Date(start.getTime() + 60 * 60 * 1e3);
|
|
1154
|
+
const uid = `${now.getTime()}-${Math.random().toString(36).substring(2, 9)}@adatechnology.com.br`;
|
|
1155
|
+
const lines = [
|
|
1156
|
+
"BEGIN:VCALENDAR",
|
|
1157
|
+
"VERSION:2.0",
|
|
1158
|
+
"PRODID:-//Ada Technology//Notification Calendar//PT",
|
|
1159
|
+
"CALSCALE:GREGORIAN",
|
|
1160
|
+
"METHOD:PUBLISH",
|
|
1161
|
+
"BEGIN:VEVENT",
|
|
1162
|
+
`UID:${uid}`,
|
|
1163
|
+
`DTSTAMP:${formatUtcCompact(now)}`,
|
|
1164
|
+
`DTSTART:${formatUtcCompact(start)}`,
|
|
1165
|
+
`DTEND:${formatUtcCompact(end)}`,
|
|
1166
|
+
`SUMMARY:${escapeIcsText(event.title)}`
|
|
1167
|
+
];
|
|
1168
|
+
if (event.description) {
|
|
1169
|
+
lines.push(`DESCRIPTION:${escapeIcsText(event.description)}`);
|
|
1170
|
+
}
|
|
1171
|
+
if (event.location) {
|
|
1172
|
+
lines.push(`LOCATION:${escapeIcsText(event.location)}`);
|
|
1173
|
+
}
|
|
1174
|
+
if (event.url) {
|
|
1175
|
+
lines.push(`URL:${event.url}`);
|
|
1176
|
+
}
|
|
1177
|
+
lines.push("END:VEVENT", "END:VCALENDAR");
|
|
1178
|
+
return lines.join("\r\n");
|
|
1179
|
+
}
|
|
1180
|
+
__name(generateIcsContent, "generateIcsContent");
|
|
1181
|
+
function extractCalendarEvent(payload) {
|
|
1182
|
+
if (!payload || typeof payload !== "object") return void 0;
|
|
1183
|
+
const raw = payload.calendarEvent && typeof payload.calendarEvent === "object" ? payload.calendarEvent : payload;
|
|
1184
|
+
const title = typeof raw.calendarTitle === "string" ? raw.calendarTitle : typeof raw.title === "string" ? raw.title : void 0;
|
|
1185
|
+
const startsAt = typeof raw.calendarStartsAt === "string" ? raw.calendarStartsAt : raw.startsAt instanceof Date || typeof raw.startsAt === "string" ? raw.startsAt : typeof raw.activityDate === "string" ? typeof raw.activityTime === "string" ? `${raw.activityDate}T${raw.activityTime}:00` : `${raw.activityDate}T09:00:00` : void 0;
|
|
1186
|
+
if (!title || !startsAt) return void 0;
|
|
1187
|
+
const description = typeof raw.calendarDescription === "string" ? raw.calendarDescription : typeof raw.description === "string" ? raw.description : void 0;
|
|
1188
|
+
const endsAt = typeof raw.calendarEndsAt === "string" ? raw.calendarEndsAt : raw.endsAt instanceof Date || typeof raw.endsAt === "string" ? raw.endsAt : void 0;
|
|
1189
|
+
const location = typeof raw.location === "string" ? raw.location : void 0;
|
|
1190
|
+
const url = typeof raw.url === "string" ? raw.url : void 0;
|
|
1191
|
+
return {
|
|
1192
|
+
title,
|
|
1193
|
+
startsAt,
|
|
1194
|
+
...description ? {
|
|
1195
|
+
description
|
|
1196
|
+
} : {},
|
|
1197
|
+
...endsAt ? {
|
|
1198
|
+
endsAt
|
|
1199
|
+
} : {},
|
|
1200
|
+
...location ? {
|
|
1201
|
+
location
|
|
1202
|
+
} : {},
|
|
1203
|
+
...url ? {
|
|
1204
|
+
url
|
|
1205
|
+
} : {}
|
|
1206
|
+
};
|
|
1207
|
+
}
|
|
1208
|
+
__name(extractCalendarEvent, "extractCalendarEvent");
|
|
1012
1209
|
export {
|
|
1013
1210
|
ChannelNotConfiguredError,
|
|
1014
1211
|
ConfigMissingError,
|
|
@@ -1020,6 +1217,7 @@ export {
|
|
|
1020
1217
|
EMAIL_ATTACHMENT_MAX_COUNT,
|
|
1021
1218
|
EMAIL_DRIVER,
|
|
1022
1219
|
INTRUSIVE_CHANNELS,
|
|
1220
|
+
InvalidTemplateDefinitionError,
|
|
1023
1221
|
InvalidVapidKeysError,
|
|
1024
1222
|
InvalidWebhookSignatureError,
|
|
1025
1223
|
NOTIFICATION_CATEGORY_HINT,
|
|
@@ -1052,11 +1250,13 @@ export {
|
|
|
1052
1250
|
ThrottledError,
|
|
1053
1251
|
UnknownTemplateVariablesError,
|
|
1054
1252
|
WebPushEncryptionError,
|
|
1253
|
+
assertTemplateDefinitions,
|
|
1055
1254
|
assessStandardEmailTemplate,
|
|
1056
1255
|
broadcastPushFilterSchema,
|
|
1057
1256
|
broadcastPushSchema,
|
|
1058
1257
|
buildInitials,
|
|
1059
1258
|
buildPreviewPayload,
|
|
1259
|
+
buildTemplateVariableCatalog,
|
|
1060
1260
|
categoryPolicyEntrySchema,
|
|
1061
1261
|
checkEmailAttachment,
|
|
1062
1262
|
createWhatsAppDriverFromChannel,
|
|
@@ -1065,8 +1265,17 @@ export {
|
|
|
1065
1265
|
diffTemplateVariables,
|
|
1066
1266
|
escapeEmailHtml,
|
|
1067
1267
|
escapeTemplateHtml,
|
|
1268
|
+
extractCalendarEvent,
|
|
1068
1269
|
extractTemplatePlaceholders,
|
|
1270
|
+
findTemplateDefinition,
|
|
1069
1271
|
findUnsafeEmailHtml,
|
|
1272
|
+
generateCalendarLinks,
|
|
1273
|
+
generateGoogleCalendarUrl,
|
|
1274
|
+
generateIcsContent,
|
|
1275
|
+
generateIcsDataUri,
|
|
1276
|
+
generateOffice365CalendarUrl,
|
|
1277
|
+
generateOutlookCalendarUrl,
|
|
1278
|
+
generateYahooCalendarUrl,
|
|
1070
1279
|
htmlToPlainText,
|
|
1071
1280
|
interpolateEmailHtml,
|
|
1072
1281
|
interpolateTemplate,
|