@adatechnology/notification-contracts 0.1.0-rc.1 → 0.1.0-rc.3

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
@@ -13,6 +13,15 @@ declare const NOTIFICATION_CHANNEL: {
13
13
  type NotificationChannel = (typeof NOTIFICATION_CHANNEL)[keyof typeof NOTIFICATION_CHANNEL];
14
14
  /** Canais que interrompem o destinatário e por isso respeitam quiet hours (ver spec §10.4). */
15
15
  declare const INTRUSIVE_CHANNELS: readonly NotificationChannel[];
16
+ /**
17
+ * O teto de canais da empresa por categoria, acima da preferência do usuário. Linha ausente
18
+ * significa permitido — fechar por omissão calaria toda categoria existente.
19
+ */
20
+ type NotificationCategoryPolicy = {
21
+ readonly category: string;
22
+ readonly channel: NotificationChannel;
23
+ readonly enabled: boolean;
24
+ };
16
25
  declare const NOTIFICATION_STATUS: {
17
26
  readonly PENDING: "pending";
18
27
  readonly SCHEDULED: "scheduled";
@@ -558,6 +567,59 @@ declare const updatePreferencesSchema: z.ZodObject<{
558
567
  }[];
559
568
  }>;
560
569
  type UpdatePreferencesBody = z.infer<typeof updatePreferencesSchema>;
570
+ declare const categoryPolicyEntrySchema: z.ZodObject<{
571
+ category: z.ZodString;
572
+ channel: z.ZodNativeEnum<{
573
+ readonly INBOX: "inbox";
574
+ readonly PUSH: "push";
575
+ readonly EMAIL: "email";
576
+ readonly WHATSAPP: "whatsapp";
577
+ readonly SMS: "sms";
578
+ }>;
579
+ enabled: z.ZodBoolean;
580
+ }, "strip", z.ZodTypeAny, {
581
+ category: string;
582
+ channel: "inbox" | "push" | "email" | "whatsapp" | "sms";
583
+ enabled: boolean;
584
+ }, {
585
+ category: string;
586
+ channel: "inbox" | "push" | "email" | "whatsapp" | "sms";
587
+ enabled: boolean;
588
+ }>;
589
+ declare const updateCategoryPoliciesSchema: z.ZodObject<{
590
+ policies: z.ZodArray<z.ZodObject<{
591
+ category: z.ZodString;
592
+ channel: z.ZodNativeEnum<{
593
+ readonly INBOX: "inbox";
594
+ readonly PUSH: "push";
595
+ readonly EMAIL: "email";
596
+ readonly WHATSAPP: "whatsapp";
597
+ readonly SMS: "sms";
598
+ }>;
599
+ enabled: z.ZodBoolean;
600
+ }, "strip", z.ZodTypeAny, {
601
+ category: string;
602
+ channel: "inbox" | "push" | "email" | "whatsapp" | "sms";
603
+ enabled: boolean;
604
+ }, {
605
+ category: string;
606
+ channel: "inbox" | "push" | "email" | "whatsapp" | "sms";
607
+ enabled: boolean;
608
+ }>, "many">;
609
+ }, "strip", z.ZodTypeAny, {
610
+ policies: {
611
+ category: string;
612
+ channel: "inbox" | "push" | "email" | "whatsapp" | "sms";
613
+ enabled: boolean;
614
+ }[];
615
+ }, {
616
+ policies: {
617
+ category: string;
618
+ channel: "inbox" | "push" | "email" | "whatsapp" | "sms";
619
+ enabled: boolean;
620
+ }[];
621
+ }>;
622
+ type UpdateCategoryPoliciesBody = z.infer<typeof updateCategoryPoliciesSchema>;
561
623
  declare const upsertTemplateSchema: z.ZodObject<{
562
624
  key: z.ZodString;
563
625
  channel: z.ZodNativeEnum<{
@@ -762,7 +824,25 @@ declare const NOTIFICATION_ERROR_CODES: {
762
824
  readonly DEVICE_NOT_FOUND: "NOTIFICATION_DEVICE_NOT_FOUND";
763
825
  readonly THROTTLED: "NOTIFICATION_THROTTLED";
764
826
  readonly CONFIG_MISSING: "NOTIFICATION_CONFIG_MISSING";
827
+ readonly TEMPLATE_UNKNOWN_VARIABLE: "NOTIFICATION_TEMPLATE_UNKNOWN_VARIABLE";
765
828
  };
829
+ /** Busca por id, e não por identidade — o painel remove pela linha que listou. */
830
+ declare class TemplateIdNotFoundError extends NotificationError {
831
+ readonly templateId: string;
832
+ constructor(templateId: string);
833
+ }
834
+ /**
835
+ * O template referencia `{{campo}}` que o produto não promete enviar. Renderizaria vazio para
836
+ * sempre, sem log e sem erro — daí ser recusa na gravação, e não aviso.
837
+ *
838
+ * `details.fields` traz TODAS as desconhecidas, não a primeira: corrigir uma por vez transforma o
839
+ * salvamento em tentativa e erro (`apis.md`, Validação).
840
+ */
841
+ declare class UnknownTemplateVariablesError extends NotificationError {
842
+ readonly templateKey: string;
843
+ readonly fields: readonly string[];
844
+ constructor(templateKey: string, fields: readonly string[]);
845
+ }
766
846
  declare class TemplateNotFoundError extends NotificationError {
767
847
  readonly templateKey: string;
768
848
  readonly channel: NotificationChannel;
@@ -850,4 +930,140 @@ type WhatsAppSendingChannel = {
850
930
  };
851
931
  declare function createWhatsAppDriverFromChannel(channel: WhatsAppSendingChannel): WhatsAppDriverPort;
852
932
 
853
- 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, DuplicateWebhookDeliveryError, EMAIL_DRIVER, type EmailDriver, type EmailDriverPort, INTRUSIVE_CHANNELS, 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 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, PUSH_DRIVER, type PreferencesUpdatedEvent, type PushDriver, type PushDriverPort, type QueuePort, type RealtimeEvent, type RealtimeNotifierPort, type RealtimeSubscription, type RecipientResolverPort, RecipientUnresolvedError, type RegisterDeviceBody, type RenderTemplateParams, type RenderedTemplate, type ResolvedRecipient, SUPPRESSION_REASON, type SendEmailParams, type SendNotificationBody, type SendNotificationParams, type SendNotificationResult, type SendPushParams, type SendSmsParams, type SendWhatsAppParams, type SendWhatsAppTemplateParams, type SmsDriverPort, SuppressedTargetError, type SuppressionReason, TemplateNotFoundError, type TemplateRendererPort, ThrottledError, type UpdatePreferencesBody, type UpsertTemplateBody, type UserId, type WhatsAppDriverPort, type WhatsAppSendingChannel, createWhatsAppDriverFromChannel, deliveryWebhookSchema, listNotificationsQuerySchema, preferenceEntrySchema, registerDeviceSchema, sendNotificationSchema, updatePreferencesSchema, upsertTemplateSchema };
933
+ /**
934
+ * Copyright (c) 2026 Ada Technology. MIT License.
935
+ *
936
+ * Larguras e limites do preview, por canal.
937
+ *
938
+ * Moram aqui, e não no CSS da UI, porque o host que consome a camada headless precisa deles para
939
+ * desenhar o próprio preview — e porque o limite de caracteres não é decoração de tela: ele é a
940
+ * regra do canal, e o editor avisa com ela antes de salvar.
941
+ */
942
+
943
+ declare const PREVIEW_VIEWPORT: {
944
+ readonly DESKTOP: "desktop";
945
+ readonly MOBILE: "mobile";
946
+ };
947
+ type PreviewViewport = (typeof PREVIEW_VIEWPORT)[keyof typeof PREVIEW_VIEWPORT];
948
+ type PreviewViewportSpec = {
949
+ readonly viewport: PreviewViewport;
950
+ readonly width: number;
951
+ };
952
+ /**
953
+ * `email` em 600px é a largura clássica de corpo de e-mail; os demais aproximam o container em que
954
+ * a mensagem aparece no desktop. `sms` não tem desktop — a mensagem é a mesma no aparelho e ponto.
955
+ */
956
+ declare const PREVIEW_VIEWPORT_BY_CHANNEL: Readonly<Record<NotificationChannel, readonly PreviewViewportSpec[]>>;
957
+ type TemplateConstraintField = 'title' | 'body';
958
+ type TemplateConstraintLimits = {
959
+ readonly title?: number;
960
+ readonly body?: number;
961
+ };
962
+ /**
963
+ * Onde o canal corta de verdade. `email.title` são os ~78 caracteres que a lista da caixa de
964
+ * entrada mostra no celular; `push` segue o teto prático do Android; `sms` é o segmento de 160,
965
+ * depois do qual a operadora cobra outra mensagem; `whatsapp.body` é o teto de corpo de template
966
+ * da Meta. `inbox` acompanha o `deriveTitleFromBody`.
967
+ */
968
+ declare const TEMPLATE_CONSTRAINTS_BY_CHANNEL: Readonly<Record<NotificationChannel, TemplateConstraintLimits>>;
969
+
970
+ /**
971
+ * Copyright (c) 2026 Ada Technology. MIT License.
972
+ *
973
+ * A renderização default de template, pura e sem dependência.
974
+ *
975
+ * Mora no contracts, e não no módulo, por um motivo específico: a tela de configuração precisa
976
+ * mostrar um PREVIEW do que o cliente vai receber, e o módulo carrega Drizzle — o frontend não pode
977
+ * importá-lo. Reimplementar a interpolação no host resolveria hoje e divergiria amanhã, e **preview
978
+ * que mente é pior que preview nenhum**: alguém salva o template confiando no que viu.
979
+ *
980
+ * Com a função aqui, o `notification-module` renderiza para enviar e a UI renderiza para mostrar,
981
+ * lendo o MESMO código. Divergência deixa de ser possível em vez de ser improvável.
982
+ */
983
+
984
+ declare function escapeTemplateHtml(text: string): string;
985
+ /** `{{campo}}` → valor do payload. Campo ausente vira string vazia, nunca o literal `{{campo}}`. */
986
+ declare function interpolateTemplate(template: string, payload: Readonly<Record<string, unknown>>): string;
987
+ declare function deriveTitleFromBody(body: string): string;
988
+ /** Os nomes de campo que um template referencia — o que a tela de configuração precisa pedir. */
989
+ declare function extractTemplatePlaceholders(template: string): readonly string[];
990
+ type TemplateConstraintCheck = {
991
+ readonly field: TemplateConstraintField;
992
+ readonly limit: number;
993
+ readonly actual: number;
994
+ readonly exceeded: boolean;
995
+ };
996
+ type RenderedTemplatePreview = {
997
+ readonly title: string;
998
+ readonly body: string;
999
+ readonly html?: string;
1000
+ /**
1001
+ * O que o canal corta. Vazio quando o canal não declara limite. O editor usa isto para avisar
1002
+ * antes de salvar, e o preview para marcar onde o texto some — sem isso, dois quadros de
1003
+ * larguras diferentes só provariam que CSS quebra linha.
1004
+ */
1005
+ readonly constraints: readonly TemplateConstraintCheck[];
1006
+ };
1007
+ /**
1008
+ * Mesma saída que o envio produz. `channel` importa porque só e-mail ganha a versão HTML — mostrar
1009
+ * HTML no preview de WhatsApp faria a tela prometer formatação que o canal não tem.
1010
+ */
1011
+ declare function renderTemplate(params: {
1012
+ readonly channel: string;
1013
+ readonly subject?: string | undefined;
1014
+ readonly body: string;
1015
+ readonly payload: Readonly<Record<string, unknown>>;
1016
+ }): RenderedTemplatePreview;
1017
+
1018
+ /**
1019
+ * Copyright (c) 2026 Ada Technology. MIT License.
1020
+ *
1021
+ * O catálogo de variáveis de um template, e a diferença entre o que ele declara e o que o texto
1022
+ * usa.
1023
+ *
1024
+ * Existe porque `{{campo}}` desconhecido não falha: `interpolateTemplate` devolve string vazia, que
1025
+ * é o comportamento correto no envio — mensagem com buraco é melhor que mensagem com `{{campo}}`
1026
+ * cru. O preço é que um erro de digitação no painel some sem log e sem erro, e só aparece quando o
1027
+ * cliente recebe "Olá , seu pedido". Com um painel, isso deixa de ser raro.
1028
+ *
1029
+ * A função é pura e mora aqui, e não no módulo, pelo mesmo motivo do `renderTemplate`: a validação
1030
+ * do servidor e o aviso da tela precisam da MESMA regra, e o frontend não pode importar o módulo
1031
+ * (carrega Drizzle). Duas implementações divergiriam, e a tela passaria a aprovar o que a rota
1032
+ * recusa.
1033
+ */
1034
+ type TemplateVariableDefinition = {
1035
+ readonly name: string;
1036
+ /** Valor de exemplo — alimenta o preview. Só o produto sabe que `orderNumber` é "QC-1042". */
1037
+ readonly example: string;
1038
+ /** `true` avisa quando o texto não usa a variável; nunca bloqueia (ver `diffTemplateVariables`). */
1039
+ readonly required: boolean;
1040
+ /** Chave de i18n do rótulo na tela. Ausente, a tela mostra o próprio `name`. */
1041
+ readonly labelKey?: string;
1042
+ };
1043
+ /** `templateKey` → variáveis que o produto promete enviar no payload daquela notificação. */
1044
+ type TemplateVariableCatalog = Readonly<Record<string, readonly TemplateVariableDefinition[]>>;
1045
+ type TemplateVariableDiff = {
1046
+ /** Placeholders que o texto referencia, na ordem em que aparecem. */
1047
+ readonly used: readonly string[];
1048
+ /** Referenciados e não declarados — renderizariam vazio para sempre. */
1049
+ readonly unknown: readonly string[];
1050
+ /** Declarados como `required` e ausentes do texto. */
1051
+ readonly missingRequired: readonly string[];
1052
+ };
1053
+ type DiffTemplateVariablesParams = {
1054
+ readonly body: string;
1055
+ readonly subject?: string | undefined;
1056
+ /**
1057
+ * Ausente significa catálogo não declarado para esta `key`, e não catálogo vazio: nesse caso
1058
+ * nada é desconhecido. Fechar por omissão quebraria todo host que já usa o módulo sem catálogo.
1059
+ */
1060
+ readonly variables?: readonly TemplateVariableDefinition[] | undefined;
1061
+ };
1062
+ declare function diffTemplateVariables(params: DiffTemplateVariablesParams): TemplateVariableDiff;
1063
+ /**
1064
+ * O payload de preview sai do próprio catálogo. Um mapa `key → exemplo` mantido em paralelo
1065
+ * divergiria do catálogo na primeira variável nova, e o preview voltaria a mentir.
1066
+ */
1067
+ declare function buildPreviewPayload(variables: readonly TemplateVariableDefinition[] | undefined): Readonly<Record<string, string>>;
1068
+
1069
+ 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_DRIVER, type EmailDriver, type EmailDriverPort, INTRUSIVE_CHANNELS, 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 RenderedTemplate, type RenderedTemplatePreview, type ResolvedRecipient, SUPPRESSION_REASON, type SendEmailParams, type SendNotificationBody, type SendNotificationParams, type SendNotificationResult, type SendPushParams, type SendSmsParams, type SendWhatsAppParams, type SendWhatsAppTemplateParams, type SmsDriverPort, SuppressedTargetError, type SuppressionReason, TEMPLATE_CONSTRAINTS_BY_CHANNEL, type TemplateConstraintCheck, type TemplateConstraintField, type TemplateConstraintLimits, TemplateIdNotFoundError, TemplateNotFoundError, type TemplateRendererPort, type TemplateVariableCatalog, type TemplateVariableDefinition, type TemplateVariableDiff, ThrottledError, UnknownTemplateVariablesError, type UpdateCategoryPoliciesBody, type UpdatePreferencesBody, type UpsertTemplateBody, type UserId, type WhatsAppDriverPort, type WhatsAppSendingChannel, buildPreviewPayload, categoryPolicyEntrySchema, createWhatsAppDriverFromChannel, deliveryWebhookSchema, deriveTitleFromBody, diffTemplateVariables, escapeTemplateHtml, extractTemplatePlaceholders, interpolateTemplate, listNotificationsQuerySchema, preferenceEntrySchema, registerDeviceSchema, renderTemplate, sendNotificationSchema, updateCategoryPoliciesSchema, updatePreferencesSchema, upsertTemplateSchema };
package/dist/index.d.ts CHANGED
@@ -13,6 +13,15 @@ declare const NOTIFICATION_CHANNEL: {
13
13
  type NotificationChannel = (typeof NOTIFICATION_CHANNEL)[keyof typeof NOTIFICATION_CHANNEL];
14
14
  /** Canais que interrompem o destinatário e por isso respeitam quiet hours (ver spec §10.4). */
15
15
  declare const INTRUSIVE_CHANNELS: readonly NotificationChannel[];
16
+ /**
17
+ * O teto de canais da empresa por categoria, acima da preferência do usuário. Linha ausente
18
+ * significa permitido — fechar por omissão calaria toda categoria existente.
19
+ */
20
+ type NotificationCategoryPolicy = {
21
+ readonly category: string;
22
+ readonly channel: NotificationChannel;
23
+ readonly enabled: boolean;
24
+ };
16
25
  declare const NOTIFICATION_STATUS: {
17
26
  readonly PENDING: "pending";
18
27
  readonly SCHEDULED: "scheduled";
@@ -558,6 +567,59 @@ declare const updatePreferencesSchema: z.ZodObject<{
558
567
  }[];
559
568
  }>;
560
569
  type UpdatePreferencesBody = z.infer<typeof updatePreferencesSchema>;
570
+ declare const categoryPolicyEntrySchema: z.ZodObject<{
571
+ category: z.ZodString;
572
+ channel: z.ZodNativeEnum<{
573
+ readonly INBOX: "inbox";
574
+ readonly PUSH: "push";
575
+ readonly EMAIL: "email";
576
+ readonly WHATSAPP: "whatsapp";
577
+ readonly SMS: "sms";
578
+ }>;
579
+ enabled: z.ZodBoolean;
580
+ }, "strip", z.ZodTypeAny, {
581
+ category: string;
582
+ channel: "inbox" | "push" | "email" | "whatsapp" | "sms";
583
+ enabled: boolean;
584
+ }, {
585
+ category: string;
586
+ channel: "inbox" | "push" | "email" | "whatsapp" | "sms";
587
+ enabled: boolean;
588
+ }>;
589
+ declare const updateCategoryPoliciesSchema: z.ZodObject<{
590
+ policies: z.ZodArray<z.ZodObject<{
591
+ category: z.ZodString;
592
+ channel: z.ZodNativeEnum<{
593
+ readonly INBOX: "inbox";
594
+ readonly PUSH: "push";
595
+ readonly EMAIL: "email";
596
+ readonly WHATSAPP: "whatsapp";
597
+ readonly SMS: "sms";
598
+ }>;
599
+ enabled: z.ZodBoolean;
600
+ }, "strip", z.ZodTypeAny, {
601
+ category: string;
602
+ channel: "inbox" | "push" | "email" | "whatsapp" | "sms";
603
+ enabled: boolean;
604
+ }, {
605
+ category: string;
606
+ channel: "inbox" | "push" | "email" | "whatsapp" | "sms";
607
+ enabled: boolean;
608
+ }>, "many">;
609
+ }, "strip", z.ZodTypeAny, {
610
+ policies: {
611
+ category: string;
612
+ channel: "inbox" | "push" | "email" | "whatsapp" | "sms";
613
+ enabled: boolean;
614
+ }[];
615
+ }, {
616
+ policies: {
617
+ category: string;
618
+ channel: "inbox" | "push" | "email" | "whatsapp" | "sms";
619
+ enabled: boolean;
620
+ }[];
621
+ }>;
622
+ type UpdateCategoryPoliciesBody = z.infer<typeof updateCategoryPoliciesSchema>;
561
623
  declare const upsertTemplateSchema: z.ZodObject<{
562
624
  key: z.ZodString;
563
625
  channel: z.ZodNativeEnum<{
@@ -762,7 +824,25 @@ declare const NOTIFICATION_ERROR_CODES: {
762
824
  readonly DEVICE_NOT_FOUND: "NOTIFICATION_DEVICE_NOT_FOUND";
763
825
  readonly THROTTLED: "NOTIFICATION_THROTTLED";
764
826
  readonly CONFIG_MISSING: "NOTIFICATION_CONFIG_MISSING";
827
+ readonly TEMPLATE_UNKNOWN_VARIABLE: "NOTIFICATION_TEMPLATE_UNKNOWN_VARIABLE";
765
828
  };
829
+ /** Busca por id, e não por identidade — o painel remove pela linha que listou. */
830
+ declare class TemplateIdNotFoundError extends NotificationError {
831
+ readonly templateId: string;
832
+ constructor(templateId: string);
833
+ }
834
+ /**
835
+ * O template referencia `{{campo}}` que o produto não promete enviar. Renderizaria vazio para
836
+ * sempre, sem log e sem erro — daí ser recusa na gravação, e não aviso.
837
+ *
838
+ * `details.fields` traz TODAS as desconhecidas, não a primeira: corrigir uma por vez transforma o
839
+ * salvamento em tentativa e erro (`apis.md`, Validação).
840
+ */
841
+ declare class UnknownTemplateVariablesError extends NotificationError {
842
+ readonly templateKey: string;
843
+ readonly fields: readonly string[];
844
+ constructor(templateKey: string, fields: readonly string[]);
845
+ }
766
846
  declare class TemplateNotFoundError extends NotificationError {
767
847
  readonly templateKey: string;
768
848
  readonly channel: NotificationChannel;
@@ -850,4 +930,140 @@ type WhatsAppSendingChannel = {
850
930
  };
851
931
  declare function createWhatsAppDriverFromChannel(channel: WhatsAppSendingChannel): WhatsAppDriverPort;
852
932
 
853
- 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, DuplicateWebhookDeliveryError, EMAIL_DRIVER, type EmailDriver, type EmailDriverPort, INTRUSIVE_CHANNELS, 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 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, PUSH_DRIVER, type PreferencesUpdatedEvent, type PushDriver, type PushDriverPort, type QueuePort, type RealtimeEvent, type RealtimeNotifierPort, type RealtimeSubscription, type RecipientResolverPort, RecipientUnresolvedError, type RegisterDeviceBody, type RenderTemplateParams, type RenderedTemplate, type ResolvedRecipient, SUPPRESSION_REASON, type SendEmailParams, type SendNotificationBody, type SendNotificationParams, type SendNotificationResult, type SendPushParams, type SendSmsParams, type SendWhatsAppParams, type SendWhatsAppTemplateParams, type SmsDriverPort, SuppressedTargetError, type SuppressionReason, TemplateNotFoundError, type TemplateRendererPort, ThrottledError, type UpdatePreferencesBody, type UpsertTemplateBody, type UserId, type WhatsAppDriverPort, type WhatsAppSendingChannel, createWhatsAppDriverFromChannel, deliveryWebhookSchema, listNotificationsQuerySchema, preferenceEntrySchema, registerDeviceSchema, sendNotificationSchema, updatePreferencesSchema, upsertTemplateSchema };
933
+ /**
934
+ * Copyright (c) 2026 Ada Technology. MIT License.
935
+ *
936
+ * Larguras e limites do preview, por canal.
937
+ *
938
+ * Moram aqui, e não no CSS da UI, porque o host que consome a camada headless precisa deles para
939
+ * desenhar o próprio preview — e porque o limite de caracteres não é decoração de tela: ele é a
940
+ * regra do canal, e o editor avisa com ela antes de salvar.
941
+ */
942
+
943
+ declare const PREVIEW_VIEWPORT: {
944
+ readonly DESKTOP: "desktop";
945
+ readonly MOBILE: "mobile";
946
+ };
947
+ type PreviewViewport = (typeof PREVIEW_VIEWPORT)[keyof typeof PREVIEW_VIEWPORT];
948
+ type PreviewViewportSpec = {
949
+ readonly viewport: PreviewViewport;
950
+ readonly width: number;
951
+ };
952
+ /**
953
+ * `email` em 600px é a largura clássica de corpo de e-mail; os demais aproximam o container em que
954
+ * a mensagem aparece no desktop. `sms` não tem desktop — a mensagem é a mesma no aparelho e ponto.
955
+ */
956
+ declare const PREVIEW_VIEWPORT_BY_CHANNEL: Readonly<Record<NotificationChannel, readonly PreviewViewportSpec[]>>;
957
+ type TemplateConstraintField = 'title' | 'body';
958
+ type TemplateConstraintLimits = {
959
+ readonly title?: number;
960
+ readonly body?: number;
961
+ };
962
+ /**
963
+ * Onde o canal corta de verdade. `email.title` são os ~78 caracteres que a lista da caixa de
964
+ * entrada mostra no celular; `push` segue o teto prático do Android; `sms` é o segmento de 160,
965
+ * depois do qual a operadora cobra outra mensagem; `whatsapp.body` é o teto de corpo de template
966
+ * da Meta. `inbox` acompanha o `deriveTitleFromBody`.
967
+ */
968
+ declare const TEMPLATE_CONSTRAINTS_BY_CHANNEL: Readonly<Record<NotificationChannel, TemplateConstraintLimits>>;
969
+
970
+ /**
971
+ * Copyright (c) 2026 Ada Technology. MIT License.
972
+ *
973
+ * A renderização default de template, pura e sem dependência.
974
+ *
975
+ * Mora no contracts, e não no módulo, por um motivo específico: a tela de configuração precisa
976
+ * mostrar um PREVIEW do que o cliente vai receber, e o módulo carrega Drizzle — o frontend não pode
977
+ * importá-lo. Reimplementar a interpolação no host resolveria hoje e divergiria amanhã, e **preview
978
+ * que mente é pior que preview nenhum**: alguém salva o template confiando no que viu.
979
+ *
980
+ * Com a função aqui, o `notification-module` renderiza para enviar e a UI renderiza para mostrar,
981
+ * lendo o MESMO código. Divergência deixa de ser possível em vez de ser improvável.
982
+ */
983
+
984
+ declare function escapeTemplateHtml(text: string): string;
985
+ /** `{{campo}}` → valor do payload. Campo ausente vira string vazia, nunca o literal `{{campo}}`. */
986
+ declare function interpolateTemplate(template: string, payload: Readonly<Record<string, unknown>>): string;
987
+ declare function deriveTitleFromBody(body: string): string;
988
+ /** Os nomes de campo que um template referencia — o que a tela de configuração precisa pedir. */
989
+ declare function extractTemplatePlaceholders(template: string): readonly string[];
990
+ type TemplateConstraintCheck = {
991
+ readonly field: TemplateConstraintField;
992
+ readonly limit: number;
993
+ readonly actual: number;
994
+ readonly exceeded: boolean;
995
+ };
996
+ type RenderedTemplatePreview = {
997
+ readonly title: string;
998
+ readonly body: string;
999
+ readonly html?: string;
1000
+ /**
1001
+ * O que o canal corta. Vazio quando o canal não declara limite. O editor usa isto para avisar
1002
+ * antes de salvar, e o preview para marcar onde o texto some — sem isso, dois quadros de
1003
+ * larguras diferentes só provariam que CSS quebra linha.
1004
+ */
1005
+ readonly constraints: readonly TemplateConstraintCheck[];
1006
+ };
1007
+ /**
1008
+ * Mesma saída que o envio produz. `channel` importa porque só e-mail ganha a versão HTML — mostrar
1009
+ * HTML no preview de WhatsApp faria a tela prometer formatação que o canal não tem.
1010
+ */
1011
+ declare function renderTemplate(params: {
1012
+ readonly channel: string;
1013
+ readonly subject?: string | undefined;
1014
+ readonly body: string;
1015
+ readonly payload: Readonly<Record<string, unknown>>;
1016
+ }): RenderedTemplatePreview;
1017
+
1018
+ /**
1019
+ * Copyright (c) 2026 Ada Technology. MIT License.
1020
+ *
1021
+ * O catálogo de variáveis de um template, e a diferença entre o que ele declara e o que o texto
1022
+ * usa.
1023
+ *
1024
+ * Existe porque `{{campo}}` desconhecido não falha: `interpolateTemplate` devolve string vazia, que
1025
+ * é o comportamento correto no envio — mensagem com buraco é melhor que mensagem com `{{campo}}`
1026
+ * cru. O preço é que um erro de digitação no painel some sem log e sem erro, e só aparece quando o
1027
+ * cliente recebe "Olá , seu pedido". Com um painel, isso deixa de ser raro.
1028
+ *
1029
+ * A função é pura e mora aqui, e não no módulo, pelo mesmo motivo do `renderTemplate`: a validação
1030
+ * do servidor e o aviso da tela precisam da MESMA regra, e o frontend não pode importar o módulo
1031
+ * (carrega Drizzle). Duas implementações divergiriam, e a tela passaria a aprovar o que a rota
1032
+ * recusa.
1033
+ */
1034
+ type TemplateVariableDefinition = {
1035
+ readonly name: string;
1036
+ /** Valor de exemplo — alimenta o preview. Só o produto sabe que `orderNumber` é "QC-1042". */
1037
+ readonly example: string;
1038
+ /** `true` avisa quando o texto não usa a variável; nunca bloqueia (ver `diffTemplateVariables`). */
1039
+ readonly required: boolean;
1040
+ /** Chave de i18n do rótulo na tela. Ausente, a tela mostra o próprio `name`. */
1041
+ readonly labelKey?: string;
1042
+ };
1043
+ /** `templateKey` → variáveis que o produto promete enviar no payload daquela notificação. */
1044
+ type TemplateVariableCatalog = Readonly<Record<string, readonly TemplateVariableDefinition[]>>;
1045
+ type TemplateVariableDiff = {
1046
+ /** Placeholders que o texto referencia, na ordem em que aparecem. */
1047
+ readonly used: readonly string[];
1048
+ /** Referenciados e não declarados — renderizariam vazio para sempre. */
1049
+ readonly unknown: readonly string[];
1050
+ /** Declarados como `required` e ausentes do texto. */
1051
+ readonly missingRequired: readonly string[];
1052
+ };
1053
+ type DiffTemplateVariablesParams = {
1054
+ readonly body: string;
1055
+ readonly subject?: string | undefined;
1056
+ /**
1057
+ * Ausente significa catálogo não declarado para esta `key`, e não catálogo vazio: nesse caso
1058
+ * nada é desconhecido. Fechar por omissão quebraria todo host que já usa o módulo sem catálogo.
1059
+ */
1060
+ readonly variables?: readonly TemplateVariableDefinition[] | undefined;
1061
+ };
1062
+ declare function diffTemplateVariables(params: DiffTemplateVariablesParams): TemplateVariableDiff;
1063
+ /**
1064
+ * O payload de preview sai do próprio catálogo. Um mapa `key → exemplo` mantido em paralelo
1065
+ * divergiria do catálogo na primeira variável nova, e o preview voltaria a mentir.
1066
+ */
1067
+ declare function buildPreviewPayload(variables: readonly TemplateVariableDefinition[] | undefined): Readonly<Record<string, string>>;
1068
+
1069
+ 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_DRIVER, type EmailDriver, type EmailDriverPort, INTRUSIVE_CHANNELS, 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 RenderedTemplate, type RenderedTemplatePreview, type ResolvedRecipient, SUPPRESSION_REASON, type SendEmailParams, type SendNotificationBody, type SendNotificationParams, type SendNotificationResult, type SendPushParams, type SendSmsParams, type SendWhatsAppParams, type SendWhatsAppTemplateParams, type SmsDriverPort, SuppressedTargetError, type SuppressionReason, TEMPLATE_CONSTRAINTS_BY_CHANNEL, type TemplateConstraintCheck, type TemplateConstraintField, type TemplateConstraintLimits, TemplateIdNotFoundError, TemplateNotFoundError, type TemplateRendererPort, type TemplateVariableCatalog, type TemplateVariableDefinition, type TemplateVariableDiff, ThrottledError, UnknownTemplateVariablesError, type UpdateCategoryPoliciesBody, type UpdatePreferencesBody, type UpsertTemplateBody, type UserId, type WhatsAppDriverPort, type WhatsAppSendingChannel, buildPreviewPayload, categoryPolicyEntrySchema, createWhatsAppDriverFromChannel, deliveryWebhookSchema, deriveTitleFromBody, diffTemplateVariables, escapeTemplateHtml, extractTemplatePlaceholders, interpolateTemplate, listNotificationsQuerySchema, preferenceEntrySchema, registerDeviceSchema, renderTemplate, sendNotificationSchema, updateCategoryPoliciesSchema, updatePreferencesSchema, upsertTemplateSchema };