franchising 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +61 -0
- package/README.md +96 -2
- package/dist/accounts-B4bnTXUd.js +242 -0
- package/dist/accounts-B4bnTXUd.js.map +1 -0
- package/dist/accounts-TyMPSHM0.cjs +313 -0
- package/dist/accounts-TyMPSHM0.cjs.map +1 -0
- package/dist/adapters-DM59AJfR.d.cts +216 -0
- package/dist/adapters-DM59AJfR.d.ts +216 -0
- package/dist/cli/template-assets/api/src/errors/codes.ts +17 -0
- package/dist/cli/template-assets/api/src/errors/index.ts +16 -0
- package/dist/cli/template-assets/api/src/filters/exception.ts +53 -0
- package/dist/cli/template-assets/api/src/main.ts +189 -0
- package/dist/cli/template-assets/api/src/modules/health/controller.ts +23 -0
- package/dist/cli/template-assets/api/src/modules/health/dto/response.dto.ts +23 -0
- package/dist/cli/template-assets/api/src/modules/health/module.ts +12 -0
- package/dist/cli/template-assets/api/src/modules/health/service.ts +54 -0
- package/dist/cli/template-assets/api/src/modules/messaging/module.ts +7 -0
- package/dist/cli/template-assets/api/src/modules/messaging/service.ts +74 -0
- package/dist/cli/template-assets/api/src/shared/exceptions.ts +40 -0
- package/dist/cli/template-assets/api/src/shared/response.ts +31 -0
- package/dist/cli/template-assets/api/src/telemetry.ts +59 -0
- package/dist/cli/template-assets/api/src/types.ts +8 -0
- package/dist/cli/template-assets/cloudflare/cache.service.ts +23 -0
- package/dist/cli/template-assets/cloudflare/queue.service.ts +22 -0
- package/dist/cli/template-assets/cloudflare/worker.ts +33 -0
- package/dist/cli/template-assets/packages/jobs/src/index.ts +49 -0
- package/dist/cli/template-assets/packages/queue-runtime/src/index.ts +54 -0
- package/dist/cli/template-assets/root/dot-dockerignore +11 -0
- package/dist/cli/template-assets/root/dot-editorconfig +13 -0
- package/dist/cli/template-assets/root/dot-oxfmtrc.json +9 -0
- package/dist/cli/template-assets/root/dot-oxlintrc.json +47 -0
- package/dist/cli/template-assets/root/lefthook.yml +18 -0
- package/dist/cli/template-assets/web/postcss.config.mjs +9 -0
- package/dist/cli/template-assets/web/src/app/(app)/dashboard/page.tsx +5 -0
- package/dist/cli/template-assets/web/src/app/(app)/layout.tsx +25 -0
- package/dist/cli/template-assets/web/src/app/(auth)/login/page.tsx +75 -0
- package/dist/cli/template-assets/web/src/app/globals.css +48 -0
- package/dist/cli/template-assets/web/src/app/layout.tsx +30 -0
- package/dist/cli/template-assets/web/src/app/page.tsx +20 -0
- package/dist/cli/template-assets/web/src/components/overview/overview-panel.tsx +27 -0
- package/dist/cli/template-assets/web/src/components/shell/app-shell.tsx +37 -0
- package/dist/cli/template-assets/web/src/components/shell/providers.tsx +22 -0
- package/dist/cli/template-assets/web/src/lib/api-client.ts +57 -0
- package/dist/cli/template-assets/web/src/lib/auth-client.ts +15 -0
- package/dist/cli/template-assets/web/src/lib/server-auth.ts +38 -0
- package/dist/cli/template-assets/web/src/types/api.ts +18 -0
- package/dist/cli/template-assets/worker/src/app.module.ts +5 -0
- package/dist/cli/template-assets/worker/src/env.ts +8 -0
- package/dist/cli/template-assets/worker/src/main.ts +25 -0
- package/dist/cli/template-assets/worker/src/modules/queue/config.ts +16 -0
- package/dist/cli/template-assets/worker/src/modules/queue/module.ts +11 -0
- package/dist/cli/template-assets/worker/src/modules/queue/processor.ts +105 -0
- package/dist/cli/template-assets/worker/src/modules/queue/repository.ts +16 -0
- package/dist/cli/template-assets/worker/src/modules/queue/retry.ts +17 -0
- package/dist/cli/template-assets/worker/test/retry.test.ts.tpl +12 -0
- package/dist/cli/template-assets/worker-messaging/jobs-messaging.ts +12 -0
- package/dist/cli/template-assets/worker-messaging/messaging-api-service.ts +39 -0
- package/dist/cli/template-assets/worker-messaging/src/env.ts +14 -0
- package/dist/cli/template-assets/worker-messaging/src/modules/messaging/service.ts +59 -0
- package/dist/cli/template-assets/worker-messaging/src/modules/queue/module.ts +8 -0
- package/dist/cli/template-assets/worker-messaging/src/modules/queue/processor.ts +113 -0
- package/dist/cli.js +1218 -0
- package/dist/cn-BVOnrSza.js +1 -0
- package/dist/constants-C4iP0--i.js +38 -0
- package/dist/constants-C4iP0--i.js.map +1 -0
- package/dist/constants-rCR-LNSN.cjs +91 -0
- package/dist/constants-rCR-LNSN.cjs.map +1 -0
- package/dist/core-BidJDmSN.cjs +759 -0
- package/dist/core-BidJDmSN.cjs.map +1 -0
- package/dist/core-C-EFrEd6.js +710 -0
- package/dist/core-C-EFrEd6.js.map +1 -0
- package/dist/decorate-BR5FVX5x.js +14 -0
- package/dist/decorate-R-oqksAh.cjs +25 -0
- package/dist/decorateParam-BFJPEGKJ.cjs +13 -0
- package/dist/decorateParam-CKE7_J1s.js +8 -0
- package/dist/define-adapter-Cc0QrfKt.cjs +16 -0
- package/dist/define-adapter-Cc0QrfKt.cjs.map +1 -0
- package/dist/define-adapter-DRcXno3j.js +11 -0
- package/dist/define-adapter-DRcXno3j.js.map +1 -0
- package/dist/dispatcher-BsD7cO2w.cjs +84 -0
- package/dist/dispatcher-BsD7cO2w.cjs.map +1 -0
- package/dist/dispatcher-DA_l1Vkv.js +73 -0
- package/dist/dispatcher-DA_l1Vkv.js.map +1 -0
- package/dist/errors-DxHoXrLd.d.cts +46 -0
- package/dist/errors-DxHoXrLd.d.ts +46 -0
- package/dist/http/index.cjs +440 -0
- package/dist/http/index.cjs.map +1 -0
- package/dist/http/index.d.cts +257 -0
- package/dist/http/index.d.ts +257 -0
- package/dist/http/index.js +400 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/swagger.cjs +122 -0
- package/dist/http/swagger.cjs.map +1 -0
- package/dist/http/swagger.d.cts +59 -0
- package/dist/http/swagger.d.ts +59 -0
- package/dist/http/swagger.js +117 -0
- package/dist/http/swagger.js.map +1 -0
- package/dist/index--EJQTnHy.d.cts +174 -0
- package/dist/index-B3aVdDMV.d.cts +51 -0
- package/dist/index-BDYdEWl2.d.cts +833 -0
- package/dist/index-BDYdEWl2.d.ts +833 -0
- package/dist/index-Bdl0AiNM.d.ts +1262 -0
- package/dist/index-By8b4ksT.d.ts +25 -0
- package/dist/index-ByS2IC02.d.ts +51 -0
- package/dist/index-DDSaLjXV.d.cts +25 -0
- package/dist/index-FTrYdHfq.d.cts +1262 -0
- package/dist/index-u3ArUXO0.d.ts +174 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1 -0
- package/dist/label-BqmJoVE-.cjs +1 -0
- package/dist/label-XeChe1Bu.js +1 -0
- package/dist/messaging/index.cjs +1 -0
- package/dist/messaging/index.d.cts +1775 -0
- package/dist/messaging/index.d.ts +1775 -0
- package/dist/messaging/index.js +1 -0
- package/dist/misc-BpM_lMTx.js +1 -0
- package/dist/misc-DkqJOm1V.cjs +1 -0
- package/dist/operational-CnxdBwVG.d.cts +13 -0
- package/dist/operational-CnxdBwVG.d.ts +13 -0
- package/dist/redaction-DhuHTlHA.js +124 -0
- package/dist/redaction-DhuHTlHA.js.map +1 -0
- package/dist/redaction-uRIQbTwZ.cjs +171 -0
- package/dist/redaction-uRIQbTwZ.cjs.map +1 -0
- package/dist/rolldown-runtime-auK_WOaK.cjs +1 -0
- package/dist/rolldown-runtime-xuxB8TGW.cjs +32 -0
- package/dist/sdk-B2Lp3JCz.cjs +45 -0
- package/dist/sdk-B2Lp3JCz.cjs.map +1 -0
- package/dist/sdk-IGOHpAeG.js +22 -0
- package/dist/sdk-IGOHpAeG.js.map +1 -0
- package/dist/skills-C1uwr9Pp.js +4 -0
- package/dist/skills-DuE-XnBp.js +1 -0
- package/dist/sso/client.cjs +37 -0
- package/dist/sso/client.cjs.map +1 -0
- package/dist/sso/client.d.cts +89 -0
- package/dist/sso/client.d.ts +89 -0
- package/dist/sso/client.js +36 -0
- package/dist/sso/client.js.map +1 -0
- package/dist/sso/index.cjs +833 -0
- package/dist/sso/index.cjs.map +1 -0
- package/dist/sso/index.d.cts +2 -0
- package/dist/sso/index.d.ts +2 -0
- package/dist/sso/index.js +821 -0
- package/dist/sso/index.js.map +1 -0
- package/dist/sso/nestjs.cjs +169 -0
- package/dist/sso/nestjs.cjs.map +1 -0
- package/dist/sso/nestjs.d.cts +92 -0
- package/dist/sso/nestjs.d.ts +92 -0
- package/dist/sso/nestjs.js +151 -0
- package/dist/sso/nestjs.js.map +1 -0
- package/dist/sso/resource.cjs +124 -0
- package/dist/sso/resource.cjs.map +1 -0
- package/dist/sso/resource.d.cts +3 -0
- package/dist/sso/resource.d.ts +3 -0
- package/dist/sso/resource.js +114 -0
- package/dist/sso/resource.js.map +1 -0
- package/dist/status-CRvlFPIs.js +13 -0
- package/dist/status-CRvlFPIs.js.map +1 -0
- package/dist/status-DtK6OHtj.cjs +24 -0
- package/dist/status-DtK6OHtj.cjs.map +1 -0
- package/dist/telemetry/adapters.cjs +6 -0
- package/dist/telemetry/adapters.d.cts +3 -0
- package/dist/telemetry/adapters.d.ts +3 -0
- package/dist/telemetry/adapters.js +4 -0
- package/dist/telemetry/betterstack.cjs +74 -0
- package/dist/telemetry/betterstack.cjs.map +1 -0
- package/dist/telemetry/betterstack.d.cts +12 -0
- package/dist/telemetry/betterstack.d.ts +12 -0
- package/dist/telemetry/betterstack.js +71 -0
- package/dist/telemetry/betterstack.js.map +1 -0
- package/dist/telemetry/core.cjs +11 -0
- package/dist/telemetry/core.d.cts +4 -0
- package/dist/telemetry/core.d.ts +4 -0
- package/dist/telemetry/core.js +5 -0
- package/dist/telemetry/index.cjs +524 -0
- package/dist/telemetry/index.cjs.map +1 -0
- package/dist/telemetry/index.d.cts +68 -0
- package/dist/telemetry/index.d.ts +68 -0
- package/dist/telemetry/index.js +499 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/telemetry/posthog.cjs +72 -0
- package/dist/telemetry/posthog.cjs.map +1 -0
- package/dist/telemetry/posthog.d.cts +10 -0
- package/dist/telemetry/posthog.d.ts +10 -0
- package/dist/telemetry/posthog.js +71 -0
- package/dist/telemetry/posthog.js.map +1 -0
- package/dist/telemetry/register.cjs +88 -0
- package/dist/telemetry/register.cjs.map +1 -0
- package/dist/telemetry/register.d.cts +14 -0
- package/dist/telemetry/register.d.ts +14 -0
- package/dist/telemetry/register.js +85 -0
- package/dist/telemetry/register.js.map +1 -0
- package/dist/telemetry/testing.cjs +54 -0
- package/dist/telemetry/testing.cjs.map +1 -0
- package/dist/telemetry/testing.d.cts +15 -0
- package/dist/telemetry/testing.d.ts +15 -0
- package/dist/telemetry/testing.js +52 -0
- package/dist/telemetry/testing.js.map +1 -0
- package/dist/telemetry.mock-BSsx7L6S.cjs +45 -0
- package/dist/telemetry.mock-BSsx7L6S.cjs.map +1 -0
- package/dist/telemetry.mock-BZRpy63c.js +40 -0
- package/dist/telemetry.mock-BZRpy63c.js.map +1 -0
- package/dist/telemetry.mock-C1wXuf-M.d.cts +4 -0
- package/dist/telemetry.mock-CdaxofJ7.d.ts +4 -0
- package/dist/ui/chart.cjs +6 -0
- package/dist/ui/chart.d.cts +34 -0
- package/dist/ui/chart.d.ts +34 -0
- package/dist/ui/chart.js +6 -0
- package/dist/ui/form.cjs +1 -0
- package/dist/ui/form.d.cts +23 -0
- package/dist/ui/form.d.ts +23 -0
- package/dist/ui/form.js +1 -0
- package/dist/ui/hooks.cjs +1 -0
- package/dist/ui/hooks.d.cts +66 -0
- package/dist/ui/hooks.d.ts +66 -0
- package/dist/ui/hooks.js +1 -0
- package/dist/ui/index.cjs +1 -0
- package/dist/ui/index.d.cts +3 -0
- package/dist/ui/index.d.ts +3 -0
- package/dist/ui/index.js +1 -0
- package/dist/ui/styles.css +2 -0
- package/dist/ui/utils.cjs +1 -0
- package/dist/ui/utils.d.cts +199 -0
- package/dist/ui/utils.d.ts +199 -0
- package/dist/ui/utils.js +1 -0
- package/dist/use-mobile-BbeIMRgE.cjs +1 -0
- package/dist/use-mobile-Cdd4Lp7p.js +1 -0
- package/dist/use-mobile-ecpyXWz3.d.cts +10 -0
- package/dist/use-mobile-ecpyXWz3.d.ts +10 -0
- package/dist/verifier-BIBtPCVi.cjs +119 -0
- package/dist/verifier-BIBtPCVi.cjs.map +1 -0
- package/dist/verifier-DNdy5Ynw.js +90 -0
- package/dist/verifier-DNdy5Ynw.js.map +1 -0
- package/dist/version-B0ADow60.js +1 -0
- package/dist/version-CMkha8JJ.cjs +1 -0
- package/package.json +539 -5
|
@@ -0,0 +1,1775 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anexos: limites espelhados de `@messaging/contracts`, codificação para
|
|
3
|
+
* base64 e validação local antes do envio.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Os números e listas daqui são cópia deliberada do contrato da API — este
|
|
7
|
+
* pacote vai para o npm e não pode depender de um workspace privado.
|
|
8
|
+
* `test/contracts.test.ts` compara as duas cópias.
|
|
9
|
+
*
|
|
10
|
+
* Validar no cliente não substitui a API, que revalida tudo. Serve para
|
|
11
|
+
* recusar cedo, sem subir 20 MB de base64 só para ouvir que o arquivo é
|
|
12
|
+
* grande demais. O erro local usa o mesmo `code` e o mesmo status que a API
|
|
13
|
+
* devolveria, para que o tratamento seja um só.
|
|
14
|
+
*/
|
|
15
|
+
/** Quantos anexos um e-mail aceita. */
|
|
16
|
+
export declare const EMAIL_ATTACHMENTS_MAX_COUNT = 10;
|
|
17
|
+
/** Soma dos anexos de um e-mail, em bytes decodificados. */
|
|
18
|
+
export declare const EMAIL_ATTACHMENTS_MAX_TOTAL_BYTES: number;
|
|
19
|
+
/** Quantos anexos uma mensagem de WhatsApp aceita. */
|
|
20
|
+
export declare const WHATSAPP_ATTACHMENTS_MAX_COUNT = 1;
|
|
21
|
+
/** Teto de imagem no WhatsApp, em bytes. */
|
|
22
|
+
export declare const WHATSAPP_IMAGE_MAX_BYTES: number;
|
|
23
|
+
/** Teto de vídeo, áudio e documento no WhatsApp, em bytes. */
|
|
24
|
+
export declare const WHATSAPP_MEDIA_MAX_BYTES: number;
|
|
25
|
+
/** Tamanho máximo do `content` usado como legenda da mídia no WhatsApp. */
|
|
26
|
+
export declare const WHATSAPP_CAPTION_MAX_LENGTH = 1024;
|
|
27
|
+
/** Tamanho máximo de `url` em um anexo. */
|
|
28
|
+
export declare const ATTACHMENT_URL_MAX_LENGTH = 2048;
|
|
29
|
+
/** Tamanho máximo de `filename`. */
|
|
30
|
+
export declare const ATTACHMENT_FILENAME_MAX_LENGTH = 255;
|
|
31
|
+
/** De onde veio o arquivo: enviado em base64 (guardado pela plataforma) ou URL externa. */
|
|
32
|
+
export declare const MESSAGE_ATTACHMENT_SOURCES: readonly ["upload", "url"];
|
|
33
|
+
/** {@link MESSAGE_ATTACHMENT_SOURCES} */
|
|
34
|
+
type MessageAttachmentSource = (typeof MESSAGE_ATTACHMENT_SOURCES)[number];
|
|
35
|
+
/** Como o anexo aparece no e-mail: arquivo anexo ou imagem no corpo (`cid:`). */
|
|
36
|
+
export declare const EMAIL_ATTACHMENT_DISPOSITIONS: readonly ["attachment", "inline"];
|
|
37
|
+
/** {@link EMAIL_ATTACHMENT_DISPOSITIONS} */
|
|
38
|
+
type EmailAttachmentDisposition = (typeof EMAIL_ATTACHMENT_DISPOSITIONS)[number];
|
|
39
|
+
/** Tipos aceitos em anexo de e-mail, comparados sem parâmetros (`; charset`). */
|
|
40
|
+
export declare const EMAIL_ATTACHMENT_CONTENT_TYPES: readonly ["application/pdf", "image/png", "image/jpeg", "image/gif", "image/webp", "text/csv", "text/plain", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.ms-powerpoint", "application/vnd.openxmlformats-officedocument.presentationml.presentation", "application/vnd.oasis.opendocument.text", "application/vnd.oasis.opendocument.spreadsheet", "application/zip", "text/calendar"];
|
|
41
|
+
/**
|
|
42
|
+
* Extensões recusadas no e-mail qualquer que seja o `contentType`.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* O cliente de e-mail do destinatário decide pelo nome do arquivo: um `.exe`
|
|
46
|
+
* rotulado `application/pdf` chegaria executável.
|
|
47
|
+
*/
|
|
48
|
+
export declare const BLOCKED_ATTACHMENT_EXTENSIONS: readonly ["apk", "app", "bat", "cmd", "com", "cpl", "dll", "dmg", "exe", "hta", "jar", "js", "jse", "lnk", "msi", "msp", "pif", "ps1", "reg", "scr", "sh", "vb", "vbe", "vbs", "wsf", "wsh"];
|
|
49
|
+
/** Tipos de mídia do WhatsApp. */
|
|
50
|
+
export declare const WHATSAPP_MEDIA_KINDS: readonly ["image", "video", "audio", "document"];
|
|
51
|
+
/** {@link WHATSAPP_MEDIA_KINDS} */
|
|
52
|
+
type WhatsAppMediaKind = (typeof WHATSAPP_MEDIA_KINDS)[number];
|
|
53
|
+
/** Tipos aceitos por tipo de mídia do WhatsApp. */
|
|
54
|
+
export declare const WHATSAPP_MEDIA_TYPES: {
|
|
55
|
+
readonly image: readonly ["image/jpeg", "image/png"];
|
|
56
|
+
readonly video: readonly ["video/mp4", "video/3gpp"];
|
|
57
|
+
readonly audio: readonly ["audio/aac", "audio/mp4", "audio/mpeg", "audio/amr", "audio/ogg"];
|
|
58
|
+
readonly document: readonly ["application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.ms-powerpoint", "application/vnd.openxmlformats-officedocument.presentationml.presentation", "text/plain", "text/csv", "application/zip"];
|
|
59
|
+
};
|
|
60
|
+
/** Teto de bytes por tipo de mídia do WhatsApp. */
|
|
61
|
+
export declare const WHATSAPP_MEDIA_MAX_BYTES_BY_KIND: {
|
|
62
|
+
readonly image: number;
|
|
63
|
+
readonly video: number;
|
|
64
|
+
readonly audio: number;
|
|
65
|
+
readonly document: number;
|
|
66
|
+
};
|
|
67
|
+
/** Valores que viram query string. */
|
|
68
|
+
type QueryValue = string | number | boolean | Date | ReadonlyArray<string | number | boolean> | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Erros que o SDK devolve em `{ data, error }`.
|
|
71
|
+
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* Nenhuma chamada lança por erro de API: o retorno é sempre
|
|
74
|
+
* `{ data, error }`, e `error` é uma destas instâncias. Elas herdam de `Error`
|
|
75
|
+
* mesmo assim, para que `error.stack` exista e para que quem preferir possa
|
|
76
|
+
* `throw error`.
|
|
77
|
+
*/
|
|
78
|
+
/**
|
|
79
|
+
* Códigos que as rotas de mensagem devolvem.
|
|
80
|
+
*
|
|
81
|
+
* @remarks
|
|
82
|
+
* É o recorte de `ErrorCodes` da API que chega a quem usa API key. Tratar o
|
|
83
|
+
* `code` é mais seguro do que ler a `message`: a frase muda, o código é
|
|
84
|
+
* contrato.
|
|
85
|
+
*/
|
|
86
|
+
export declare const MESSAGING_ERROR_CODES: readonly ["UNAUTHENTICATED", "INVALID_API_KEY", "ACTIVE_PROJECT_REQUIRED", "PROJECT_ROLE_REQUIRED", "VALIDATION_ERROR", "FROM_DOMAIN_NOT_VERIFIED", "SENDER_NOT_FOUND", "WHATSAPP_TEMPLATE_NOT_FOUND", "WHATSAPP_TEMPLATE_CONFLICT", "WHATSAPP_TEMPLATE_PROVIDER_UNSUPPORTED", "WHATSAPP_TEMPLATE_SUBMISSION_FAILED", "WHATSAPP_TEMPLATE_SYNC_FAILED", "WHATSAPP_TEMPLATE_INVALID_STATE", "WHATSAPP_TEMPLATE_BODY_CONFLICT", "ATTACHMENTS_NOT_SUPPORTED_FOR_CHANNEL", "ATTACHMENTS_PROVIDER_TEMPLATE_CONFLICT", "ATTACHMENT_INVALID", "ATTACHMENT_CONTENT_TYPE_NOT_ALLOWED", "ATTACHMENT_TOO_LARGE", "ATTACHMENTS_LIMIT_EXCEEDED", "ATTACHMENT_URL_NOT_ALLOWED", "WHATSAPP_CAPTION_INVALID", "PAYLOAD_TOO_LARGE", "ATTACHMENT_STORAGE_UNAVAILABLE", "ATTACHMENT_STORAGE_NOT_CONFIGURED", "ATTACHMENT_EXPIRED", "MESSAGE_NOT_FOUND", "MESSAGE_NOT_RETRYABLE", "MESSAGE_CONTENT_EXPIRED", "IDEMPOTENCY_KEY_REUSED", "ROUTE_NOT_FOUND", "INTERNAL_SERVER_ERROR", "RATE_LIMIT_EXCEEDED", "CONNECTION_ERROR", "TIMEOUT", "UNEXPECTED_RESPONSE"];
|
|
87
|
+
/** {@link MESSAGING_ERROR_CODES} */
|
|
88
|
+
type MessagingErrorCode = (typeof MESSAGING_ERROR_CODES)[number];
|
|
89
|
+
/** Dados que acompanham toda falha. */
|
|
90
|
+
interface MessagingErrorOptions {
|
|
91
|
+
/** Código estável da falha. */
|
|
92
|
+
code: MessagingErrorCode | (string & Record<never, never>);
|
|
93
|
+
/** Frase da API, em inglês, pensada para log — não para a tela do usuário. */
|
|
94
|
+
message: string;
|
|
95
|
+
/** Status HTTP. Zero quando a requisição nem chegou a ter resposta. */
|
|
96
|
+
status: number;
|
|
97
|
+
/** Detalhes por campo que a API manda em `VALIDATION_ERROR`. */
|
|
98
|
+
errors?: unknown[];
|
|
99
|
+
/** Erro de rede original, quando houve um. */
|
|
100
|
+
cause?: unknown;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Falha em uma chamada ao SDK.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* const { data, error } = await client.messages.send({ ... })
|
|
108
|
+
* if (error) {
|
|
109
|
+
* if (error.code === 'FROM_DOMAIN_NOT_VERIFIED') return verificarDominio()
|
|
110
|
+
* if (error.retryable) return reenfileirar()
|
|
111
|
+
* throw error
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export declare class MessagingError extends Error {
|
|
116
|
+
/**
|
|
117
|
+
* Nome da classe. Fixo em vez de `new.target.name`: o build é minificado e o
|
|
118
|
+
* nome da classe deixaria de ser o que o consumidor lê em `error.name`.
|
|
119
|
+
*/
|
|
120
|
+
readonly name: string;
|
|
121
|
+
/** Código estável da falha. Prefira-o à `message` para ramificar. */
|
|
122
|
+
readonly code: MessagingErrorCode | (string & Record<never, never>);
|
|
123
|
+
/** Status HTTP. Zero em falha de conexão ou timeout. */
|
|
124
|
+
readonly status: number;
|
|
125
|
+
/**
|
|
126
|
+
* Detalhes por campo.
|
|
127
|
+
*
|
|
128
|
+
* @remarks
|
|
129
|
+
* Só vem em `VALIDATION_ERROR`, e cada item é a frase de uma regra que não
|
|
130
|
+
* passou: `['to.email must be an email']`.
|
|
131
|
+
*/
|
|
132
|
+
readonly errors: unknown[] | undefined;
|
|
133
|
+
constructor(options: MessagingErrorOptions);
|
|
134
|
+
/**
|
|
135
|
+
* Vale tentar de novo?
|
|
136
|
+
*
|
|
137
|
+
* @remarks
|
|
138
|
+
* Verdadeiro em timeout, falha de conexão, 429 e 5xx. Falso no resto: um
|
|
139
|
+
* `VALIDATION_ERROR` vai falhar igual na segunda vez.
|
|
140
|
+
*/
|
|
141
|
+
get retryable(): boolean;
|
|
142
|
+
/** Forma serializável, para log estruturado. */
|
|
143
|
+
toJSON(): {
|
|
144
|
+
errors?: unknown[];
|
|
145
|
+
name: string;
|
|
146
|
+
code: "UNAUTHENTICATED" | "INVALID_API_KEY" | "ACTIVE_PROJECT_REQUIRED" | "PROJECT_ROLE_REQUIRED" | "VALIDATION_ERROR" | "FROM_DOMAIN_NOT_VERIFIED" | "SENDER_NOT_FOUND" | "WHATSAPP_TEMPLATE_NOT_FOUND" | "WHATSAPP_TEMPLATE_CONFLICT" | "WHATSAPP_TEMPLATE_PROVIDER_UNSUPPORTED" | "WHATSAPP_TEMPLATE_SUBMISSION_FAILED" | "WHATSAPP_TEMPLATE_SYNC_FAILED" | "WHATSAPP_TEMPLATE_INVALID_STATE" | "WHATSAPP_TEMPLATE_BODY_CONFLICT" | "ATTACHMENTS_NOT_SUPPORTED_FOR_CHANNEL" | "ATTACHMENTS_PROVIDER_TEMPLATE_CONFLICT" | "ATTACHMENT_INVALID" | "ATTACHMENT_CONTENT_TYPE_NOT_ALLOWED" | "ATTACHMENT_TOO_LARGE" | "ATTACHMENTS_LIMIT_EXCEEDED" | "ATTACHMENT_URL_NOT_ALLOWED" | "WHATSAPP_CAPTION_INVALID" | "PAYLOAD_TOO_LARGE" | "ATTACHMENT_STORAGE_UNAVAILABLE" | "ATTACHMENT_STORAGE_NOT_CONFIGURED" | "ATTACHMENT_EXPIRED" | "MESSAGE_NOT_FOUND" | "MESSAGE_NOT_RETRYABLE" | "MESSAGE_CONTENT_EXPIRED" | "IDEMPOTENCY_KEY_REUSED" | "ROUTE_NOT_FOUND" | "INTERNAL_SERVER_ERROR" | "RATE_LIMIT_EXCEEDED" | "CONNECTION_ERROR" | "TIMEOUT" | "UNEXPECTED_RESPONSE" | (string & Record<never, never>);
|
|
147
|
+
message: string;
|
|
148
|
+
status: number;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/** Algum campo foi recusado antes do envio. `errors` diz quais. */
|
|
152
|
+
export declare class ValidationError extends MessagingError {
|
|
153
|
+
readonly name = "ValidationError";
|
|
154
|
+
}
|
|
155
|
+
/** A credencial não foi aceita: chave ausente, inválida ou revogada. */
|
|
156
|
+
export declare class AuthenticationError extends MessagingError {
|
|
157
|
+
readonly name = "AuthenticationError";
|
|
158
|
+
}
|
|
159
|
+
/** A credencial é válida, mas não alcança esta operação ou este projeto. */
|
|
160
|
+
export declare class PermissionError extends MessagingError {
|
|
161
|
+
readonly name = "PermissionError";
|
|
162
|
+
}
|
|
163
|
+
/** A mensagem ou a rota não existe. */
|
|
164
|
+
export declare class NotFoundError extends MessagingError {
|
|
165
|
+
readonly name = "NotFoundError";
|
|
166
|
+
}
|
|
167
|
+
/** Requisições demais em pouco tempo. */
|
|
168
|
+
export declare class RateLimitError extends MessagingError {
|
|
169
|
+
readonly name = "RateLimitError";
|
|
170
|
+
/** Segundos sugeridos pelo cabeçalho `Retry-After`, quando veio um. */
|
|
171
|
+
readonly retryAfter: number | undefined;
|
|
172
|
+
constructor(options: MessagingErrorOptions & {
|
|
173
|
+
retryAfter?: number;
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
/** Erro do lado da plataforma. Em geral vale retentar. */
|
|
177
|
+
export declare class ServerError extends MessagingError {
|
|
178
|
+
readonly name = "ServerError";
|
|
179
|
+
}
|
|
180
|
+
/** Não foi possível falar com a API — DNS, TLS, rede. Nada saiu. */
|
|
181
|
+
export declare class ConnectionError extends MessagingError {
|
|
182
|
+
readonly name = "ConnectionError";
|
|
183
|
+
}
|
|
184
|
+
/** A API não respondeu dentro do tempo configurado. */
|
|
185
|
+
export declare class TimeoutError extends MessagingError {
|
|
186
|
+
readonly name = "TimeoutError";
|
|
187
|
+
}
|
|
188
|
+
/** É um erro deste SDK? */
|
|
189
|
+
export declare function isMessagingError(value: unknown): value is MessagingError;
|
|
190
|
+
/** O que toda chamada do SDK devolve. */
|
|
191
|
+
type Result<Data> = {
|
|
192
|
+
data: Data;
|
|
193
|
+
error: null;
|
|
194
|
+
} | {
|
|
195
|
+
data: null;
|
|
196
|
+
error: MessagingError;
|
|
197
|
+
};
|
|
198
|
+
/** Sucesso. */
|
|
199
|
+
export declare function success<Data>(data: Data): Result<Data>;
|
|
200
|
+
/** Falha. */
|
|
201
|
+
export declare function failure<Data>(error: MessagingError): Result<Data>;
|
|
202
|
+
/** Tempo máximo de uma chamada, quando a configuração não diz outro. */
|
|
203
|
+
export declare const DEFAULT_TIMEOUT_MS = 30000;
|
|
204
|
+
/** Quantas vezes o SDK repete uma chamada retentável. */
|
|
205
|
+
export declare const DEFAULT_MAX_RETRIES = 2;
|
|
206
|
+
/** A mesma assinatura do `fetch` global, para poder injetar o seu. */
|
|
207
|
+
type FetchLike = (input: string, init: RequestInit) => Promise<Response>;
|
|
208
|
+
/** Opções que qualquer método aceita como último argumento. */
|
|
209
|
+
interface RequestOptions {
|
|
210
|
+
/** Cancela a chamada — o seu `AbortController`, o do framework, o que for. */
|
|
211
|
+
signal?: AbortSignal | undefined;
|
|
212
|
+
/** Sobrescreve o tempo máximo desta chamada, em milissegundos. */
|
|
213
|
+
timeout?: number | undefined;
|
|
214
|
+
/** Cabeçalhos extras, somados aos do cliente. */
|
|
215
|
+
headers?: Record<string, string> | undefined;
|
|
216
|
+
}
|
|
217
|
+
/** Configuração do transporte. */
|
|
218
|
+
interface HttpClientConfig {
|
|
219
|
+
secret: string;
|
|
220
|
+
baseUrl: string;
|
|
221
|
+
timeout: number;
|
|
222
|
+
maxRetries: number;
|
|
223
|
+
headers: Record<string, string>;
|
|
224
|
+
fetch: FetchLike;
|
|
225
|
+
}
|
|
226
|
+
interface RequestInput {
|
|
227
|
+
method: 'GET' | 'POST' | 'PATCH';
|
|
228
|
+
path: string;
|
|
229
|
+
query?: Record<string, QueryValue>;
|
|
230
|
+
body?: unknown;
|
|
231
|
+
/**
|
|
232
|
+
* Chave de idempotência da chamada.
|
|
233
|
+
*
|
|
234
|
+
* @remarks
|
|
235
|
+
* Além de virar cabeçalho, é ela que autoriza retentar um `POST`: sem
|
|
236
|
+
* chave, repetir um envio que deu timeout poderia entregar a mensagem duas
|
|
237
|
+
* vezes.
|
|
238
|
+
*/
|
|
239
|
+
idempotencyKey?: string;
|
|
240
|
+
options?: RequestOptions;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* O transporte do SDK.
|
|
244
|
+
*
|
|
245
|
+
* @remarks
|
|
246
|
+
* Faz três coisas que ninguém deveria reescrever por chamada: autentica,
|
|
247
|
+
* desembrulha `{ ok, data }` e decide o que é retentável. Nunca lança por erro
|
|
248
|
+
* de API — devolve `{ data, error }`.
|
|
249
|
+
*/
|
|
250
|
+
declare class HttpClient {
|
|
251
|
+
private readonly config;
|
|
252
|
+
constructor(config: HttpClientConfig);
|
|
253
|
+
request<Data>(input: RequestInput): Promise<Result<Data>>;
|
|
254
|
+
private attempt;
|
|
255
|
+
private headers;
|
|
256
|
+
/**
|
|
257
|
+
* Lê o corpo antes de julgar.
|
|
258
|
+
*
|
|
259
|
+
* @remarks
|
|
260
|
+
* Nem toda resposta é JSON: um proxy no caminho responde HTML, e um 502 vem
|
|
261
|
+
* vazio. Chamar `json()` direto quebraria com um erro de parser que não diz
|
|
262
|
+
* nada sobre o que houve.
|
|
263
|
+
*/
|
|
264
|
+
private parse;
|
|
265
|
+
}
|
|
266
|
+
/** Instante ISO-8601 em UTC, como a API devolve: `2026-09-18T12:00:00.000Z`. */
|
|
267
|
+
type IsoDateTime = string;
|
|
268
|
+
/** JSON livre de quem chama: `data` do template e `metadata` da mensagem. */
|
|
269
|
+
type JsonObject = Record<string, unknown>;
|
|
270
|
+
/**
|
|
271
|
+
* Qualquer string, com os valores conhecidos sugeridos no autocomplete.
|
|
272
|
+
*
|
|
273
|
+
* @remarks
|
|
274
|
+
* Onde aparece, a lista de valores é o que a plataforma sabe hoje, não um
|
|
275
|
+
* fechamento: um provedor pode passar a mandar um tipo de evento novo, e
|
|
276
|
+
* tipá-lo como união fechada faria o SDK recusar o que a API já devolve.
|
|
277
|
+
*/
|
|
278
|
+
type LooseString = string & Record<never, never>;
|
|
279
|
+
type DistributiveOmit<Type, Keys extends PropertyKey> = Type extends unknown ? Omit<Type, Keys> : never;
|
|
280
|
+
/**
|
|
281
|
+
* Estado de uma mensagem como um todo.
|
|
282
|
+
*
|
|
283
|
+
* @remarks
|
|
284
|
+
* A mensagem é o que você pediu; a entrega é o que cada canal fez com o pedido.
|
|
285
|
+
* Os três desfechos negativos do destinatário não se escondem dentro de
|
|
286
|
+
* `failed` porque pedem ações diferentes:
|
|
287
|
+
*
|
|
288
|
+
* - `accepted` — a API validou e enfileirou. Nada saiu ainda.
|
|
289
|
+
* - `canceled` — o agendamento foi cancelado antes de o worker assumir a entrega.
|
|
290
|
+
* - `processing` — algum canal está com a mensagem em mãos.
|
|
291
|
+
* - `sent` — o provedor despachou e ainda não confirmou a chegada.
|
|
292
|
+
* - `delivered` — chegou ao destinatário.
|
|
293
|
+
* - `complained` — chegou e o destinatário marcou como spam. Pare de enviar
|
|
294
|
+
* para ele.
|
|
295
|
+
* - `bounced` — o destino recusou de vez. Reenviar não adianta.
|
|
296
|
+
* - `suppressed` — o provedor nem tentou, por histórico ruim do destinatário.
|
|
297
|
+
* - `failed` — ninguém aceitou a mensagem. É problema nosso ou do provedor, e
|
|
298
|
+
* em geral vale retentar.
|
|
299
|
+
*/
|
|
300
|
+
export declare const MESSAGE_STATUSES: readonly ["accepted", "canceled", "processing", "sent", "delivered", "complained", "bounced", "suppressed", "failed"];
|
|
301
|
+
/** {@link MESSAGE_STATUSES} */
|
|
302
|
+
type MessageStatus = (typeof MESSAGE_STATUSES)[number];
|
|
303
|
+
/**
|
|
304
|
+
* Estado de uma entrega — a mensagem dentro de um canal específico.
|
|
305
|
+
*
|
|
306
|
+
* @remarks
|
|
307
|
+
* Acrescenta dois estados aos da mensagem: `pending`, antes de a fila pegar a
|
|
308
|
+
* entrega, e `sent`, quando o provedor aceitou mas ainda não confirmou que
|
|
309
|
+
* chegou. Confirmar a chegada é `delivered`.
|
|
310
|
+
*/
|
|
311
|
+
export declare const MESSAGE_DELIVERY_STATUSES: readonly ["pending", "canceled", "processing", "sent", "delivered", "complained", "bounced", "suppressed", "failed"];
|
|
312
|
+
/** {@link MESSAGE_DELIVERY_STATUSES} */
|
|
313
|
+
type MessageDeliveryStatus = (typeof MESSAGE_DELIVERY_STATUSES)[number];
|
|
314
|
+
/**
|
|
315
|
+
* Chegou ao destinatário.
|
|
316
|
+
*
|
|
317
|
+
* @remarks
|
|
318
|
+
* `complained` entra aqui: a mensagem foi entregue e só então marcada como
|
|
319
|
+
* spam. Contá-la como falha derrubaria a taxa de entrega por um fato que não é
|
|
320
|
+
* de entrega.
|
|
321
|
+
*/
|
|
322
|
+
export declare const MESSAGE_DELIVERED_STATUSES: readonly ["delivered", "complained"];
|
|
323
|
+
/** Não chegou ao destinatário, seja por nossa causa ou pela dele. */
|
|
324
|
+
export declare const MESSAGE_UNDELIVERED_STATUSES: readonly ["bounced", "suppressed", "failed"];
|
|
325
|
+
/** Estados de entrega dos quais não se sai. */
|
|
326
|
+
export declare const MESSAGE_DELIVERY_TERMINAL_STATUSES: readonly ["canceled", "delivered", "complained", "bounced", "suppressed", "failed"];
|
|
327
|
+
/** A entrega já terminou, seja bem ou mal? */
|
|
328
|
+
export declare function isTerminalDeliveryStatus(value: string): value is (typeof MESSAGE_DELIVERY_TERMINAL_STATUSES)[number];
|
|
329
|
+
/**
|
|
330
|
+
* Desfecho de uma tentativa individual de provedor dentro de uma entrega.
|
|
331
|
+
*
|
|
332
|
+
* @remarks
|
|
333
|
+
* `unknown` não é enfeite: o provedor pode ter aceitado a mensagem e ainda
|
|
334
|
+
* assim devolver erro. Chamar isso de `failed` afirmaria que nada saiu quando
|
|
335
|
+
* talvez tenha saído — por isso a plataforma para em vez de tentar o provedor
|
|
336
|
+
* seguinte, para não entregar duas vezes.
|
|
337
|
+
*/
|
|
338
|
+
export declare const MESSAGE_ATTEMPT_OUTCOMES: readonly ["sent", "failed", "unknown"];
|
|
339
|
+
/** {@link MESSAGE_ATTEMPT_OUTCOMES} */
|
|
340
|
+
type MessageAttemptOutcome = (typeof MESSAGE_ATTEMPT_OUTCOMES)[number];
|
|
341
|
+
/**
|
|
342
|
+
* Eventos de provedor que a plataforma sabe nomear.
|
|
343
|
+
*
|
|
344
|
+
* @remarks
|
|
345
|
+
* A ingestão grava qualquer `type` recebido — esta lista é só o vocabulário
|
|
346
|
+
* conhecido. Um evento novo do provedor aparece pelo nome cru em vez de sumir,
|
|
347
|
+
* e por isso `MessageEvent['type']` aceita qualquer string.
|
|
348
|
+
*/
|
|
349
|
+
export declare const MESSAGE_EVENT_TYPES: readonly ["email.sent", "email.delivered", "email.delivery_delayed", "email.opened", "email.clicked", "email.bounced", "email.complained", "email.failed", "email.suppressed", "whatsapp.sent", "whatsapp.delivered", "whatsapp.read", "whatsapp.failed", "sms.sent", "sms.delivered", "sms.failed", "sms.bounced", "webpush.sent", "webpush.failed", "webpush.expired"];
|
|
350
|
+
/** {@link MESSAGE_EVENT_TYPES} */
|
|
351
|
+
type MessageEventType = (typeof MESSAGE_EVENT_TYPES)[number];
|
|
352
|
+
/** A entrega criada para um canal, na resposta do envio. */
|
|
353
|
+
interface AcceptedDelivery {
|
|
354
|
+
/** Identificador da entrega. Aparece nos webhooks do projeto. */
|
|
355
|
+
id: string;
|
|
356
|
+
/** Sempre `pending` aqui: a resposta é anterior ao envio. */
|
|
357
|
+
status: MessageDeliveryStatus;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* O que `messages.send` devolve.
|
|
361
|
+
*
|
|
362
|
+
* @remarks
|
|
363
|
+
* A API responde **202** sem esperar o provedor: a entrega acontece depois, na
|
|
364
|
+
* fila. O estado final chega pelos webhooks do projeto ou por
|
|
365
|
+
* {@link Messages.get}.
|
|
366
|
+
*/
|
|
367
|
+
interface AcceptedMessage {
|
|
368
|
+
/**
|
|
369
|
+
* Identificador da mensagem.
|
|
370
|
+
*
|
|
371
|
+
* @remarks
|
|
372
|
+
* Guarde-o: é por ele que se consulta a mensagem e é ele que vem nos
|
|
373
|
+
* webhooks.
|
|
374
|
+
*/
|
|
375
|
+
id: string;
|
|
376
|
+
/** Sempre `accepted` aqui. */
|
|
377
|
+
status: MessageStatus;
|
|
378
|
+
/** A entrega criada, pela chave do canal. */
|
|
379
|
+
deliveries: {
|
|
380
|
+
/** Presente quando o destino era um e-mail. */
|
|
381
|
+
email?: AcceptedDelivery;
|
|
382
|
+
/** Presente quando o destino era um WhatsApp. */
|
|
383
|
+
whatsapp?: AcceptedDelivery;
|
|
384
|
+
/** Presente quando o destino era um SMS. */
|
|
385
|
+
sms?: AcceptedDelivery;
|
|
386
|
+
/** Presente quando o destino era web push. */
|
|
387
|
+
webPush?: AcceptedWebPushDelivery;
|
|
388
|
+
};
|
|
389
|
+
/** Quando a mensagem foi aceita. */
|
|
390
|
+
createdAt: IsoDateTime;
|
|
391
|
+
}
|
|
392
|
+
/** Resultado de um item aceito por `messages.batch`. */
|
|
393
|
+
interface AcceptedBatchMessage {
|
|
394
|
+
id: string;
|
|
395
|
+
accepted: true;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* A entrega de push, que alcança vários navegadores de uma vez.
|
|
399
|
+
*
|
|
400
|
+
* @remarks
|
|
401
|
+
* `targets` nunca é zero: um envio sem nenhum navegador inscrito é recusado
|
|
402
|
+
* com `WEBPUSH_NO_ACTIVE_SUBSCRIPTION` em vez de aceito e vazio.
|
|
403
|
+
*/
|
|
404
|
+
interface AcceptedWebPushDelivery extends AcceptedDelivery {
|
|
405
|
+
/** Quantos navegadores esta entrega vai alcançar. */
|
|
406
|
+
targets: number;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Bytes de um anexo.
|
|
410
|
+
*
|
|
411
|
+
* @remarks
|
|
412
|
+
* `Buffer` entra como `Uint8Array`. Uma string é lida como base64 já pronto —
|
|
413
|
+
* o SDK não codifica de novo, só confere o formato.
|
|
414
|
+
*/
|
|
415
|
+
type AttachmentContent = Uint8Array | ArrayBuffer | Blob | string;
|
|
416
|
+
/**
|
|
417
|
+
* Anexo enviado com os bytes.
|
|
418
|
+
*
|
|
419
|
+
* @remarks
|
|
420
|
+
* O SDK converte para base64. Sem `contentType`, usa o `type` do `Blob` ou
|
|
421
|
+
* deduz pela extensão de `filename`; se nada disso disser, o envio é recusado
|
|
422
|
+
* com `ATTACHMENT_INVALID`.
|
|
423
|
+
*/
|
|
424
|
+
interface AttachmentContentInput {
|
|
425
|
+
/** Nome com que o arquivo chega. Até 255 caracteres, sem `/` nem `\`. */
|
|
426
|
+
filename: string;
|
|
427
|
+
/** Tipo MIME. Opcional: deduzido do `Blob` ou da extensão. */
|
|
428
|
+
contentType?: string | undefined;
|
|
429
|
+
/** Os bytes, ou o base64 já pronto. */
|
|
430
|
+
content: AttachmentContent;
|
|
431
|
+
url?: never;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Anexo por URL pública.
|
|
435
|
+
*
|
|
436
|
+
* @remarks
|
|
437
|
+
* Precisa ser `https` na porta padrão, sem usuário na URL e fora de rede
|
|
438
|
+
* privada. A plataforma só baixa o arquivo na entrega: uma URL inacessível
|
|
439
|
+
* aparece como falha da entrega (`ATTACHMENT_FETCH_FAILED`), não do envio.
|
|
440
|
+
*/
|
|
441
|
+
interface AttachmentUrlInput {
|
|
442
|
+
/** Nome com que o arquivo chega. */
|
|
443
|
+
filename: string;
|
|
444
|
+
/** Tipo MIME. Obrigatório: o SDK não baixa a URL para descobrir. */
|
|
445
|
+
contentType: string;
|
|
446
|
+
/** Endereço `https` do arquivo, até 2048 caracteres. */
|
|
447
|
+
url: string;
|
|
448
|
+
content?: never;
|
|
449
|
+
}
|
|
450
|
+
/** Opções que só o e-mail entende. */
|
|
451
|
+
interface EmailAttachmentOptions {
|
|
452
|
+
/**
|
|
453
|
+
* `attachment` (padrão) ou `inline`, para imagem referenciada no HTML
|
|
454
|
+
* por `cid:`.
|
|
455
|
+
*/
|
|
456
|
+
disposition?: EmailAttachmentDisposition | undefined;
|
|
457
|
+
/** O id usado em `<img src="cid:...">` quando `disposition` é `inline`. */
|
|
458
|
+
contentId?: string | undefined;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Anexo de e-mail: até `EMAIL_ATTACHMENTS_MAX_COUNT` por mensagem,
|
|
462
|
+
* somando até `EMAIL_ATTACHMENTS_MAX_TOTAL_BYTES` bytes.
|
|
463
|
+
*/
|
|
464
|
+
type EmailAttachmentInput = (AttachmentContentInput | AttachmentUrlInput) & EmailAttachmentOptions;
|
|
465
|
+
/**
|
|
466
|
+
* Mídia de WhatsApp: imagem, vídeo, áudio ou documento, uma por mensagem.
|
|
467
|
+
*
|
|
468
|
+
* @remarks
|
|
469
|
+
* O tipo de mídia sai do `contentType` (`WHATSAPP_MEDIA_TYPES`). O
|
|
470
|
+
* `content` da mensagem vira a legenda, até
|
|
471
|
+
* `WHATSAPP_CAPTION_MAX_LENGTH` caracteres; áudio não aceita legenda.
|
|
472
|
+
*/
|
|
473
|
+
type WhatsAppAttachmentInput = (AttachmentContentInput | AttachmentUrlInput) & {
|
|
474
|
+
disposition?: never;
|
|
475
|
+
contentId?: never;
|
|
476
|
+
};
|
|
477
|
+
/** Qualquer anexo que o SDK aceita. */
|
|
478
|
+
type AttachmentInput = EmailAttachmentInput | WhatsAppAttachmentInput;
|
|
479
|
+
/**
|
|
480
|
+
* Metadados de um anexo, como `messages.get` devolve.
|
|
481
|
+
*
|
|
482
|
+
* @remarks
|
|
483
|
+
* Nem o conteúdo nem a URL voltam: a plataforma guarda o arquivo só para
|
|
484
|
+
* entregar.
|
|
485
|
+
*/
|
|
486
|
+
interface MessageAttachment {
|
|
487
|
+
id: string;
|
|
488
|
+
filename: string;
|
|
489
|
+
contentType: string;
|
|
490
|
+
/** Bytes decodificados. Nulo em anexo por URL. */
|
|
491
|
+
size: number | null;
|
|
492
|
+
/** SHA-256 em hexadecimal. Nulo em anexo por URL. */
|
|
493
|
+
sha256: string | null;
|
|
494
|
+
/** `MESSAGE_ATTACHMENT_SOURCES` */
|
|
495
|
+
source: MessageAttachmentSource | LooseString;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Destinatário de e-mail.
|
|
499
|
+
*
|
|
500
|
+
* @example
|
|
501
|
+
* ```ts
|
|
502
|
+
* { email: 'hiago@rockfeller.com.br' }
|
|
503
|
+
* ```
|
|
504
|
+
*/
|
|
505
|
+
interface EmailDestination {
|
|
506
|
+
/** Endereço do destinatário. */
|
|
507
|
+
email: string;
|
|
508
|
+
whatsapp?: never;
|
|
509
|
+
sms?: never;
|
|
510
|
+
webpush?: never;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Destinatário de WhatsApp.
|
|
514
|
+
*
|
|
515
|
+
* @remarks
|
|
516
|
+
* Em E.164, com `+` e código do país. A API aceita separadores comuns e os
|
|
517
|
+
* limpa (`+55 (11) 99999-9999`), mas não adivinha país: `11999999999` poderia
|
|
518
|
+
* ser de uns dez lugares, então um número sem `+` é recusado com
|
|
519
|
+
* `VALIDATION_ERROR` em vez de ir para o destino errado calado.
|
|
520
|
+
*
|
|
521
|
+
* @example
|
|
522
|
+
* ```ts
|
|
523
|
+
* { whatsapp: '+5511999999999' }
|
|
524
|
+
* ```
|
|
525
|
+
*/
|
|
526
|
+
interface WhatsAppDestination {
|
|
527
|
+
/** Número do destinatário em E.164. */
|
|
528
|
+
whatsapp: string;
|
|
529
|
+
email?: never;
|
|
530
|
+
sms?: never;
|
|
531
|
+
webpush?: never;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Destinatário de SMS.
|
|
535
|
+
*
|
|
536
|
+
* @remarks
|
|
537
|
+
* Celular em E.164, com `+` e código do país — mesma regra do WhatsApp: a API
|
|
538
|
+
* limpa separadores, mas não adivinha país. Por enquanto só `+55`: outros
|
|
539
|
+
* países são recusados com `VALIDATION_ERROR`.
|
|
540
|
+
*
|
|
541
|
+
* @example
|
|
542
|
+
* ```ts
|
|
543
|
+
* { sms: '+5511999999999' }
|
|
544
|
+
* ```
|
|
545
|
+
*/
|
|
546
|
+
interface SmsDestination {
|
|
547
|
+
/** Celular brasileiro do destinatário em E.164 (`+55…`). */
|
|
548
|
+
sms: string;
|
|
549
|
+
email?: never;
|
|
550
|
+
whatsapp?: never;
|
|
551
|
+
webpush?: never;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Para quem a notificação push vai.
|
|
555
|
+
*
|
|
556
|
+
* @remarks
|
|
557
|
+
* `recipientId` é a pessoa, e alcança todos os navegadores em que ela
|
|
558
|
+
* autorizou — é o caso normal, e o motivo de a entrega de push trazer
|
|
559
|
+
* `targets`. `subscriptionId` é um navegador só, para quando você já sabe
|
|
560
|
+
* qual. Exatamente um dos dois.
|
|
561
|
+
*
|
|
562
|
+
* Qual aplicação envia não entra aqui: isso é o `from`, como em todo canal.
|
|
563
|
+
*
|
|
564
|
+
* @example
|
|
565
|
+
* ```ts
|
|
566
|
+
* { webpush: { recipientId: 'cus_8f3a2c' } }
|
|
567
|
+
* ```
|
|
568
|
+
*/
|
|
569
|
+
type WebPushTarget = {
|
|
570
|
+
recipientId: string;
|
|
571
|
+
subscriptionId?: never;
|
|
572
|
+
} | {
|
|
573
|
+
subscriptionId: string;
|
|
574
|
+
recipientId?: never;
|
|
575
|
+
};
|
|
576
|
+
interface WebPushDestination {
|
|
577
|
+
/** Pessoa ou inscrição que vai receber. */
|
|
578
|
+
webpush: WebPushTarget;
|
|
579
|
+
email?: never;
|
|
580
|
+
whatsapp?: never;
|
|
581
|
+
sms?: never;
|
|
582
|
+
}
|
|
583
|
+
/** Destino de uma mensagem: um canal por envio, nunca dois. */
|
|
584
|
+
type MessageDestination = EmailDestination | WhatsAppDestination | SmsDestination | WebPushDestination;
|
|
585
|
+
/**
|
|
586
|
+
* Envio por SMS.
|
|
587
|
+
*
|
|
588
|
+
* @remarks
|
|
589
|
+
* Só texto: `content` é obrigatório, até {@link SMS_CONTENT_MAX_LENGTH}
|
|
590
|
+
* caracteres; não há assunto, HTML nem anexo. A cobrança da operadora é por
|
|
591
|
+
* segmento — 160 caracteres GSM-7 (70 com acento fora do GSM ou emoji), ou
|
|
592
|
+
* 153/67 por parte quando o texto é dividido.
|
|
593
|
+
*
|
|
594
|
+
* Com `template`, o texto vem do conteúdo genérico do template.
|
|
595
|
+
*/
|
|
596
|
+
interface SendSmsOptions extends SendMessageBase {
|
|
597
|
+
providerTemplate?: never;
|
|
598
|
+
/** Celular do destinatário em E.164. */
|
|
599
|
+
to: SmsDestination;
|
|
600
|
+
/**
|
|
601
|
+
* Remetente: o número Twilio cadastrado no projeto, em E.164, ou o slug
|
|
602
|
+
* dele. Desconhecido ou desligado é `SENDER_NOT_FOUND`.
|
|
603
|
+
*/
|
|
604
|
+
from: string;
|
|
605
|
+
/** Texto do SMS. */
|
|
606
|
+
content: string;
|
|
607
|
+
subject?: never;
|
|
608
|
+
html?: never;
|
|
609
|
+
/** SMS não leva anexo. */
|
|
610
|
+
attachments?: never;
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* O que `sms.send` aceita.
|
|
614
|
+
*
|
|
615
|
+
* @remarks
|
|
616
|
+
* O mesmo de {@link SendSmsOptions}, com o canal já decidido: `to` é o
|
|
617
|
+
* celular em E.164 e o SDK monta o destino.
|
|
618
|
+
*
|
|
619
|
+
* @example
|
|
620
|
+
* ```ts
|
|
621
|
+
* await client.sms.send({
|
|
622
|
+
* to: '+5511999999999',
|
|
623
|
+
* from: '+15550001111',
|
|
624
|
+
* content: 'Seu código de acesso é 482913.',
|
|
625
|
+
* })
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
628
|
+
interface SendSmsInput extends Omit<SendSmsOptions, 'to'> {
|
|
629
|
+
/** Celular do destinatário em E.164. Também aceita `{ sms }`. */
|
|
630
|
+
to: string | SmsDestination;
|
|
631
|
+
}
|
|
632
|
+
/** Opções de um item de `sms.batch`. */
|
|
633
|
+
type BatchSendSmsInput = Omit<SendSmsInput, 'idempotencyKey'>;
|
|
634
|
+
/**
|
|
635
|
+
* Envio de notificação web push.
|
|
636
|
+
*
|
|
637
|
+
* @remarks
|
|
638
|
+
* `subject` é o título e `content` é o corpo, os dois obrigatórios: uma
|
|
639
|
+
* notificação sem um deles aparece truncada na bandeja do sistema, e ali não
|
|
640
|
+
* há "abrir para ler o resto".
|
|
641
|
+
*
|
|
642
|
+
* Único canal em que uma entrega alcança vários destinos: a resposta traz
|
|
643
|
+
* `deliveries.webPush.targets` com quantos navegadores receberam.
|
|
644
|
+
*/
|
|
645
|
+
interface SendWebPushOptions extends SendMessageBase {
|
|
646
|
+
providerTemplate?: never;
|
|
647
|
+
/** Pessoa ou inscrição que vai receber. */
|
|
648
|
+
to: WebPushDestination;
|
|
649
|
+
/**
|
|
650
|
+
* O `appId` da aplicação cadastrada (`checkout-web`).
|
|
651
|
+
*
|
|
652
|
+
* @remarks
|
|
653
|
+
* É ela que assina o envio com o próprio par VAPID. Uma aplicação
|
|
654
|
+
* desconhecida ou desligada é recusada com `WEBPUSH_APP_NOT_FOUND`.
|
|
655
|
+
*/
|
|
656
|
+
from: string;
|
|
657
|
+
/** Título da notificação. */
|
|
658
|
+
subject: string;
|
|
659
|
+
/** Corpo da notificação. */
|
|
660
|
+
content: string;
|
|
661
|
+
html?: never;
|
|
662
|
+
/** Push não leva anexo. */
|
|
663
|
+
attachments?: never;
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* O mesmo de {@link SendWebPushOptions}, com o canal já decidido.
|
|
667
|
+
*
|
|
668
|
+
* @remarks
|
|
669
|
+
* `to` é o alvo direto — `{ recipientId }` ou `{ subscriptionId }` — sem o
|
|
670
|
+
* `{ webpush }` em volta. Uma string é lida como `recipientId`, que é o caso
|
|
671
|
+
* normal.
|
|
672
|
+
*
|
|
673
|
+
* @example
|
|
674
|
+
* ```ts
|
|
675
|
+
* await client.webPush.send({
|
|
676
|
+
* to: 'cus_8f3a2c',
|
|
677
|
+
* from: 'checkout-web',
|
|
678
|
+
* subject: 'Pagamento aprovado',
|
|
679
|
+
* content: 'Recebemos o pagamento da sua mensalidade.',
|
|
680
|
+
* })
|
|
681
|
+
* ```
|
|
682
|
+
*/
|
|
683
|
+
interface SendWebPushInput extends Omit<SendWebPushOptions, 'to'> {
|
|
684
|
+
/** O `recipientId`, ou o alvo completo. */
|
|
685
|
+
to: string | WebPushTarget;
|
|
686
|
+
}
|
|
687
|
+
/** Opções de `webPush.createSubscriptionToken`. */
|
|
688
|
+
interface CreateWebPushSubscriptionTokenInput {
|
|
689
|
+
/** O `appId` da aplicação web push do projeto (`checkout-web`). */
|
|
690
|
+
appId: string;
|
|
691
|
+
/** Quem está logado na página — o mesmo valor do `to` nos envios. */
|
|
692
|
+
recipientId: string;
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* O token que a página manda ao se inscrever.
|
|
696
|
+
*
|
|
697
|
+
* @remarks
|
|
698
|
+
* Vale uma hora, para uma aplicação e um destinatário, e pode ser reutilizado
|
|
699
|
+
* até expirar.
|
|
700
|
+
*/
|
|
701
|
+
interface WebPushSubscriptionToken {
|
|
702
|
+
token: string;
|
|
703
|
+
appId: string;
|
|
704
|
+
recipientId: string;
|
|
705
|
+
/** ISO 8601. */
|
|
706
|
+
expiresAt: string;
|
|
707
|
+
}
|
|
708
|
+
/** Opções de um item de `webPush.batch`. */
|
|
709
|
+
type BatchSendWebPushInput = Omit<SendWebPushInput, 'idempotencyKey'>;
|
|
710
|
+
/**
|
|
711
|
+
* Envio por WhatsApp.
|
|
712
|
+
*
|
|
713
|
+
* @remarks
|
|
714
|
+
* `content` ou `providerTemplate` é obrigatório; não há assunto nem HTML. O `from` é um remetente
|
|
715
|
+
* cadastrado e habilitado no projeto — senão a API responde `SENDER_NOT_FOUND`.
|
|
716
|
+
*/
|
|
717
|
+
interface SendWhatsAppBase extends SendMessageBase {
|
|
718
|
+
/** Destinatário em E.164. */
|
|
719
|
+
to: WhatsAppDestination | LooseString;
|
|
720
|
+
/**
|
|
721
|
+
* Remetente: o slug do número no projeto (`suporte`) ou o próprio número em
|
|
722
|
+
* E.164 (`+5511988887777`).
|
|
723
|
+
*
|
|
724
|
+
* @remarks
|
|
725
|
+
* Prefira o slug: trocar o número por portabilidade ou refazer a instância
|
|
726
|
+
* não obriga a mexer no seu código.
|
|
727
|
+
*/
|
|
728
|
+
from: string;
|
|
729
|
+
/** Corpo da mensagem. Até {@link MESSAGE_BODY_MAX_BYTES} bytes UTF-8. */
|
|
730
|
+
subject?: never;
|
|
731
|
+
html?: never;
|
|
732
|
+
}
|
|
733
|
+
/** Runtime parameters for an approved Meta WhatsApp template (text and buttons only). */
|
|
734
|
+
interface WhatsAppProviderTemplate {
|
|
735
|
+
name: string;
|
|
736
|
+
language: {
|
|
737
|
+
code: string;
|
|
738
|
+
};
|
|
739
|
+
components?: Array<{
|
|
740
|
+
type: 'header' | 'body' | 'button';
|
|
741
|
+
sub_type?: 'quick_reply' | 'url';
|
|
742
|
+
index?: string;
|
|
743
|
+
parameters: Array<{
|
|
744
|
+
type: 'text';
|
|
745
|
+
text: string;
|
|
746
|
+
} | {
|
|
747
|
+
type: 'payload';
|
|
748
|
+
payload: string;
|
|
749
|
+
}>;
|
|
750
|
+
}>;
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Texto, mídia com legenda opcional, ou template do provedor — exclusivos.
|
|
754
|
+
*
|
|
755
|
+
* @remarks
|
|
756
|
+
* Com anexo, `content` deixa de ser obrigatório e vira a legenda. Template do
|
|
757
|
+
* provedor não aceita anexo.
|
|
758
|
+
*/
|
|
759
|
+
type SendWhatsAppOptions = SendWhatsAppBase & ({
|
|
760
|
+
content: string;
|
|
761
|
+
attachments?: [WhatsAppAttachmentInput] | undefined;
|
|
762
|
+
providerTemplate?: never;
|
|
763
|
+
} | {
|
|
764
|
+
attachments: [WhatsAppAttachmentInput];
|
|
765
|
+
content?: string | undefined;
|
|
766
|
+
providerTemplate?: never;
|
|
767
|
+
} | {
|
|
768
|
+
providerTemplate: WhatsAppProviderTemplate;
|
|
769
|
+
content?: never;
|
|
770
|
+
attachments?: never;
|
|
771
|
+
template?: never;
|
|
772
|
+
data?: never;
|
|
773
|
+
locale?: never;
|
|
774
|
+
});
|
|
775
|
+
/**
|
|
776
|
+
* O que `whatsapp.send` aceita.
|
|
777
|
+
*
|
|
778
|
+
* @remarks
|
|
779
|
+
* O mesmo de {@link SendWhatsAppOptions}, com o canal já decidido: `to` é o
|
|
780
|
+
* número em E.164 e o SDK monta o destino.
|
|
781
|
+
*
|
|
782
|
+
* @example
|
|
783
|
+
* ```ts
|
|
784
|
+
* await client.whatsapp.send({
|
|
785
|
+
* to: '+5511999999999',
|
|
786
|
+
* from: 'suporte',
|
|
787
|
+
* content: 'Olá! Como podemos ajudar?',
|
|
788
|
+
* })
|
|
789
|
+
* ```
|
|
790
|
+
*/
|
|
791
|
+
type SendWhatsAppInput = DistributiveOmit<SendWhatsAppOptions, 'to'> & {
|
|
792
|
+
to: string | WhatsAppDestination;
|
|
793
|
+
};
|
|
794
|
+
/** Opções de um item de `whatsapp.batch`. */
|
|
795
|
+
type BatchSendWhatsAppInput = DistributiveOmit<SendWhatsAppInput, 'idempotencyKey'>;
|
|
796
|
+
/**
|
|
797
|
+
* Prioridade de fila de um envio.
|
|
798
|
+
*
|
|
799
|
+
* @remarks
|
|
800
|
+
* `low` cede a vez para as mensagens `normal`. É para disparo em massa que
|
|
801
|
+
* ninguém está esperando na hora, para não atrasar mensagem transacional.
|
|
802
|
+
*/
|
|
803
|
+
export declare const MESSAGE_PRIORITIES: readonly ["normal", "low"];
|
|
804
|
+
/** {@link MESSAGE_PRIORITIES} */
|
|
805
|
+
type MessagePriority = (typeof MESSAGE_PRIORITIES)[number];
|
|
806
|
+
/** O que todo envio aceita, seja qual for o canal. */
|
|
807
|
+
interface SendMessageBase {
|
|
808
|
+
/**
|
|
809
|
+
* Identificador do template que originou a mensagem.
|
|
810
|
+
*
|
|
811
|
+
* @remarks
|
|
812
|
+
* Serve para agrupar e filtrar os envios de um mesmo fluxo em
|
|
813
|
+
* `messages.list`. Não substitui o corpo: a plataforma não renderiza
|
|
814
|
+
* template, você manda o conteúdo pronto.
|
|
815
|
+
*/
|
|
816
|
+
template?: string | undefined;
|
|
817
|
+
/**
|
|
818
|
+
* Variáveis do template, guardadas junto da mensagem.
|
|
819
|
+
*
|
|
820
|
+
* @remarks
|
|
821
|
+
* Até {@link MESSAGE_JSON_MAX_BYTES} bytes serializados.
|
|
822
|
+
*/
|
|
823
|
+
data?: JsonObject | undefined;
|
|
824
|
+
/** Idioma em que a mensagem foi renderizada, por exemplo `pt-BR`. */
|
|
825
|
+
locale?: string | undefined;
|
|
826
|
+
/**
|
|
827
|
+
* Os seus dados, devolvidos em `messages.get` e nos webhooks do projeto.
|
|
828
|
+
*
|
|
829
|
+
* @remarks
|
|
830
|
+
* É por aqui que se amarra a mensagem a um registro seu — a fatura, o
|
|
831
|
+
* atendimento, o aluno. Até {@link MESSAGE_JSON_MAX_BYTES} bytes
|
|
832
|
+
* serializados.
|
|
833
|
+
*/
|
|
834
|
+
metadata?: JsonObject | undefined;
|
|
835
|
+
/** {@link MESSAGE_PRIORITIES}. Padrão `normal`. */
|
|
836
|
+
priority?: MessagePriority | undefined;
|
|
837
|
+
/**
|
|
838
|
+
* Quando a mensagem deve sair. Precisa estar no futuro.
|
|
839
|
+
*
|
|
840
|
+
* @remarks
|
|
841
|
+
* Aceita `Date` ou string ISO-8601. Ausente, a mensagem sai assim que a
|
|
842
|
+
* fila processar.
|
|
843
|
+
*/
|
|
844
|
+
sendAt?: Date | IsoDateTime | undefined;
|
|
845
|
+
/**
|
|
846
|
+
* Torna o reenvio seguro.
|
|
847
|
+
*
|
|
848
|
+
* @remarks
|
|
849
|
+
* Repetir a mesma chave no mesmo projeto com o mesmo pedido devolve a
|
|
850
|
+
* resposta aceita original, mesmo após a entrega mudar de estado. Alterar
|
|
851
|
+
* o pedido ou usar a chave de um lote retorna `IDEMPOTENCY_KEY_REUSED`
|
|
852
|
+
* (409), sem retry automático. Também autoriza o SDK a retentar o `POST`
|
|
853
|
+
* após timeout; sem ela, só `GET` é retentado.
|
|
854
|
+
*/
|
|
855
|
+
idempotencyKey?: string | undefined;
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* Tudo que `messages.send` aceita.
|
|
859
|
+
*
|
|
860
|
+
* @remarks
|
|
861
|
+
* União discriminada pelo destino: o compilador cobra `subject` e `html` no
|
|
862
|
+
* e-mail, `content` no WhatsApp e os dois primeiros no web push — o mesmo que
|
|
863
|
+
* a API cobra em runtime.
|
|
864
|
+
*/
|
|
865
|
+
type SendMessageOptions = SendEmailOptions | SendWhatsAppOptions | SendSmsOptions | SendWebPushOptions;
|
|
866
|
+
/** Opções de cada item de `messages.batch`, sem idempotência por item. */
|
|
867
|
+
type BatchSendMessageOptions = DistributiveOmit<SendMessageOptions, 'idempotencyKey'>;
|
|
868
|
+
/** Configuração da requisição inteira de `messages.batch`. */
|
|
869
|
+
interface BatchRequestOptions {
|
|
870
|
+
/**
|
|
871
|
+
* Recupera a resposta aceita original do mesmo lote no projeto.
|
|
872
|
+
* Alterar campos, tamanho, ordem ou usar a chave de um envio individual
|
|
873
|
+
* retorna `IDEMPOTENCY_KEY_REUSED` (409), sem retry automático.
|
|
874
|
+
*/
|
|
875
|
+
idempotencyKey?: string | undefined;
|
|
876
|
+
signal?: AbortSignal | undefined;
|
|
877
|
+
timeout?: number | undefined;
|
|
878
|
+
headers?: Record<string, string> | undefined;
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Envio por e-mail.
|
|
882
|
+
*
|
|
883
|
+
* @remarks
|
|
884
|
+
* `subject` e `html` são obrigatórios, e o domínio de `from` precisa estar
|
|
885
|
+
* verificado no projeto — senão a API responde `FROM_DOMAIN_NOT_VERIFIED`.
|
|
886
|
+
*/
|
|
887
|
+
interface SendEmailOptions extends SendMessageBase {
|
|
888
|
+
providerTemplate?: never;
|
|
889
|
+
/** Destinatário. */
|
|
890
|
+
to: EmailDestination | LooseString;
|
|
891
|
+
/**
|
|
892
|
+
* Remetente, com domínio verificado no projeto.
|
|
893
|
+
*
|
|
894
|
+
* @remarks
|
|
895
|
+
* Aceita `nome@dominio` ou `Nome <nome@dominio>`.
|
|
896
|
+
*/
|
|
897
|
+
from: string;
|
|
898
|
+
/** Assunto. Até {@link MESSAGE_SUBJECT_MAX_LENGTH} caracteres. */
|
|
899
|
+
subject: string;
|
|
900
|
+
/** Corpo HTML. Até {@link MESSAGE_BODY_MAX_BYTES} bytes UTF-8. */
|
|
901
|
+
html: string;
|
|
902
|
+
/**
|
|
903
|
+
* Corpo em texto simples, como alternativa ao HTML.
|
|
904
|
+
*
|
|
905
|
+
* @remarks
|
|
906
|
+
* É o que aparece em cliente que bloqueia HTML, e ajuda na reputação de
|
|
907
|
+
* entrega. Até {@link MESSAGE_BODY_MAX_BYTES} bytes UTF-8.
|
|
908
|
+
*/
|
|
909
|
+
content?: string | undefined;
|
|
910
|
+
/** Anexos. Veja {@link EmailAttachmentInput}. */
|
|
911
|
+
attachments?: EmailAttachmentInput[] | undefined;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* O que `emails.send` aceita.
|
|
915
|
+
*
|
|
916
|
+
* @remarks
|
|
917
|
+
* O mesmo de {@link SendEmailOptions}, com o canal já decidido: `to` é o
|
|
918
|
+
* endereço em string e o SDK monta o destino.
|
|
919
|
+
*
|
|
920
|
+
* @example
|
|
921
|
+
* ```ts
|
|
922
|
+
* await client.emails.send({
|
|
923
|
+
* to: 'hiago@rockfeller.com.br',
|
|
924
|
+
* from: 'Financeiro <financeiro@rockfeller.com.br>',
|
|
925
|
+
* subject: 'Pagamento aprovado',
|
|
926
|
+
* html: '<p>Recebemos o seu pagamento.</p>',
|
|
927
|
+
* })
|
|
928
|
+
* ```
|
|
929
|
+
*/
|
|
930
|
+
interface SendEmailInput extends Omit<SendEmailOptions, 'to'> {
|
|
931
|
+
/** Endereço do destinatário. Também aceita `{ email }`. */
|
|
932
|
+
to: string | EmailDestination;
|
|
933
|
+
}
|
|
934
|
+
/** Opções de um item de `emails.batch`. */
|
|
935
|
+
type BatchSendEmailInput = Omit<SendEmailInput, 'idempotencyKey'>;
|
|
936
|
+
/** Canais por onde uma mensagem pode sair. */
|
|
937
|
+
export declare const PROVIDER_CHANNELS: readonly ["email", "whatsapp", "sms", "webpush"];
|
|
938
|
+
/** {@link PROVIDER_CHANNELS} */
|
|
939
|
+
type ProviderChannel = (typeof PROVIDER_CHANNELS)[number];
|
|
940
|
+
/** Provedores que a plataforma sabe operar. */
|
|
941
|
+
export declare const PROVIDER_IDS: readonly ["resend", "unosend", "twilio", "meta", "evolution"];
|
|
942
|
+
/** {@link PROVIDER_IDS} */
|
|
943
|
+
type ProviderId = (typeof PROVIDER_IDS)[number];
|
|
944
|
+
/** O estado de um canal, na linha da listagem. */
|
|
945
|
+
interface ListedMessageChannel {
|
|
946
|
+
/** Canal por onde a mensagem saiu. */
|
|
947
|
+
channel: ProviderChannel;
|
|
948
|
+
/** Provedor que ficou com a entrega. */
|
|
949
|
+
provider: ProviderId | LooseString | null;
|
|
950
|
+
/** Destinatário deste canal. */
|
|
951
|
+
destination: string;
|
|
952
|
+
/** {@link MESSAGE_DELIVERY_STATUSES} */
|
|
953
|
+
status: MessageDeliveryStatus;
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Uma mensagem na listagem.
|
|
957
|
+
*
|
|
958
|
+
* @remarks
|
|
959
|
+
* É a forma enxuta: o corpo vem cortado em `preview`, e o conteúdo inteiro só
|
|
960
|
+
* em {@link Messages.get}. A lista existe para reconhecer a mensagem, não para
|
|
961
|
+
* lê-la.
|
|
962
|
+
*/
|
|
963
|
+
interface ListedMessage {
|
|
964
|
+
/** Identificador da mensagem. */
|
|
965
|
+
id: string;
|
|
966
|
+
/** Remetente, como enviado na criação. */
|
|
967
|
+
from: string;
|
|
968
|
+
/** Destinatários, um por entrega. */
|
|
969
|
+
to: string[];
|
|
970
|
+
/** O estado de cada canal. */
|
|
971
|
+
channels: ListedMessageChannel[];
|
|
972
|
+
/** Assunto. Nulo em WhatsApp. */
|
|
973
|
+
subject: string | null;
|
|
974
|
+
/** Template informado na criação. */
|
|
975
|
+
template: string | null;
|
|
976
|
+
/** Trecho do corpo, já sem HTML. */
|
|
977
|
+
preview: string | null;
|
|
978
|
+
/** {@link MESSAGE_STATUSES} */
|
|
979
|
+
status: MessageStatus;
|
|
980
|
+
/** Verdadeiro quando a mensagem foi criada com `sendAt`. */
|
|
981
|
+
scheduled: boolean;
|
|
982
|
+
/** Instante agendado, quando houver. */
|
|
983
|
+
sendAt: IsoDateTime | null;
|
|
984
|
+
/**
|
|
985
|
+
* Quando a política de retenção do projeto anonimizou o conteúdo.
|
|
986
|
+
*
|
|
987
|
+
* @remarks
|
|
988
|
+
* Preenchido, assunto, corpo, `data` e `metadata` vêm vazios e o
|
|
989
|
+
* destinatário, mascarado (`m***@example.com`). Status e horários
|
|
990
|
+
* continuam valendo.
|
|
991
|
+
*/
|
|
992
|
+
redactedAt: IsoDateTime | null;
|
|
993
|
+
/**
|
|
994
|
+
* Instante mais recente em que algum canal entregou ou, na falta disso,
|
|
995
|
+
* enviou. Nulo enquanto nada saiu.
|
|
996
|
+
*/
|
|
997
|
+
sentAt: IsoDateTime | null;
|
|
998
|
+
/** Quando a mensagem foi aceita. */
|
|
999
|
+
createdAt: IsoDateTime;
|
|
1000
|
+
}
|
|
1001
|
+
/** Filtros de `messages.list`. */
|
|
1002
|
+
interface ListMessagesOptions {
|
|
1003
|
+
/**
|
|
1004
|
+
* Filtra pelos estados da mensagem.
|
|
1005
|
+
*
|
|
1006
|
+
* @example
|
|
1007
|
+
* ```ts
|
|
1008
|
+
* { status: ['failed', 'bounced'] }
|
|
1009
|
+
* ```
|
|
1010
|
+
*/
|
|
1011
|
+
status?: MessageStatus | MessageStatus[] | undefined;
|
|
1012
|
+
/** Filtra pelos canais em que a mensagem foi entregue. */
|
|
1013
|
+
channel?: ProviderChannel | ProviderChannel[] | undefined;
|
|
1014
|
+
/**
|
|
1015
|
+
* Filtra pelo destinatário.
|
|
1016
|
+
*
|
|
1017
|
+
* @remarks
|
|
1018
|
+
* Casa com qualquer parte do endereço ou número, então `hiago@` e `+5511`
|
|
1019
|
+
* funcionam.
|
|
1020
|
+
*/
|
|
1021
|
+
to?: string | undefined;
|
|
1022
|
+
/**
|
|
1023
|
+
* Busca no assunto ou no destinatário.
|
|
1024
|
+
*
|
|
1025
|
+
* @remarks
|
|
1026
|
+
* Para filtrar só pelo destinatário, use {@link ListMessagesOptions.to}.
|
|
1027
|
+
*/
|
|
1028
|
+
search?: string | undefined;
|
|
1029
|
+
/** `true` traz só as agendadas; `false`, só as de envio imediato. */
|
|
1030
|
+
scheduled?: boolean | undefined;
|
|
1031
|
+
/** Início da janela de criação, inclusivo. `Date` ou string ISO-8601. */
|
|
1032
|
+
createdAfter?: Date | IsoDateTime | undefined;
|
|
1033
|
+
/** Fim da janela de criação, inclusivo. `Date` ou string ISO-8601. */
|
|
1034
|
+
createdBefore?: Date | IsoDateTime | undefined;
|
|
1035
|
+
/**
|
|
1036
|
+
* Mensagens por página.
|
|
1037
|
+
*
|
|
1038
|
+
* @remarks
|
|
1039
|
+
* Padrão {@link MESSAGE_LIST_DEFAULT_LIMIT}, teto
|
|
1040
|
+
* {@link MESSAGE_LIST_MAX_LIMIT}.
|
|
1041
|
+
*/
|
|
1042
|
+
limit?: number | undefined;
|
|
1043
|
+
/** `nextCursor` da página anterior. */
|
|
1044
|
+
cursor?: string | undefined;
|
|
1045
|
+
}
|
|
1046
|
+
/** O corpo cru de uma página, como a API devolve. */
|
|
1047
|
+
interface MessageListPayload {
|
|
1048
|
+
/** Mensagens da página, da mais recente para a mais antiga. */
|
|
1049
|
+
messages: ListedMessage[];
|
|
1050
|
+
/** Passe em `cursor` para pedir a próxima página. Nulo na última. */
|
|
1051
|
+
nextCursor: string | null;
|
|
1052
|
+
}
|
|
1053
|
+
/** Busca a página seguinte a partir de um cursor. */
|
|
1054
|
+
type FetchPage = (cursor: string) => Promise<Result<MessagesPage>>;
|
|
1055
|
+
/**
|
|
1056
|
+
* Uma página de mensagens que sabe pedir a próxima.
|
|
1057
|
+
*
|
|
1058
|
+
* @remarks
|
|
1059
|
+
* A API pagina por cursor, do mais recente para o mais antigo. Duas formas de
|
|
1060
|
+
* consumir, e as duas continuam devolvendo `{ data, error }` na chamada que
|
|
1061
|
+
* criou a página:
|
|
1062
|
+
*
|
|
1063
|
+
* - página a página, com {@link MessagesPage.next};
|
|
1064
|
+
* - tudo de uma vez, iterando a página com `for await` — ela percorre as
|
|
1065
|
+
* páginas seguintes sozinha.
|
|
1066
|
+
*
|
|
1067
|
+
* @example Página a página
|
|
1068
|
+
* ```ts
|
|
1069
|
+
* let page = (await client.messages.list({ limit: 100 })).data
|
|
1070
|
+
* while (page) {
|
|
1071
|
+
* console.log(page.messages.length)
|
|
1072
|
+
* page = page.hasMore ? (await page.next()).data : null
|
|
1073
|
+
* }
|
|
1074
|
+
* ```
|
|
1075
|
+
*
|
|
1076
|
+
* @example Tudo de uma vez
|
|
1077
|
+
* ```ts
|
|
1078
|
+
* const { data: page, error } = await client.messages.list({ status: 'failed' })
|
|
1079
|
+
* if (error) throw error
|
|
1080
|
+
* for await (const message of page) console.log(message.id, message.status)
|
|
1081
|
+
* ```
|
|
1082
|
+
*/
|
|
1083
|
+
export declare class MessagesPage implements AsyncIterable<ListedMessage> {
|
|
1084
|
+
private readonly fetchPage;
|
|
1085
|
+
/** Mensagens desta página, da mais recente para a mais antiga. */
|
|
1086
|
+
readonly messages: ListedMessage[];
|
|
1087
|
+
/**
|
|
1088
|
+
* Cursor da próxima página.
|
|
1089
|
+
*
|
|
1090
|
+
* @remarks
|
|
1091
|
+
* Nulo na última. Ele também serve para retomar depois: guarde-o e passe em
|
|
1092
|
+
* `messages.list({ cursor })`.
|
|
1093
|
+
*/
|
|
1094
|
+
readonly nextCursor: string | null;
|
|
1095
|
+
constructor(payload: MessageListPayload, fetchPage: FetchPage);
|
|
1096
|
+
/** Existe página seguinte? */
|
|
1097
|
+
get hasMore(): boolean;
|
|
1098
|
+
/**
|
|
1099
|
+
* A próxima página.
|
|
1100
|
+
*
|
|
1101
|
+
* @remarks
|
|
1102
|
+
* Na última página devolve uma página vazia, nunca erro: acabar não é
|
|
1103
|
+
* falha. Confira {@link MessagesPage.hasMore} antes se quiser evitar a
|
|
1104
|
+
* chamada.
|
|
1105
|
+
*/
|
|
1106
|
+
next(): Promise<Result<MessagesPage>>;
|
|
1107
|
+
/**
|
|
1108
|
+
* Percorre todas as mensagens, atravessando as páginas.
|
|
1109
|
+
*
|
|
1110
|
+
* @remarks
|
|
1111
|
+
* Um erro no meio da travessia interrompe a iteração lançando — aqui não há
|
|
1112
|
+
* `{ data, error }` para devolver, porque o `for await` já começou. O erro é
|
|
1113
|
+
* a mesma instância de `MessagingError` que uma chamada normal devolveria.
|
|
1114
|
+
*/
|
|
1115
|
+
[Symbol.asyncIterator](): AsyncIterator<ListedMessage>;
|
|
1116
|
+
}
|
|
1117
|
+
/** Opções de uma retentativa manual da mensagem existente. */
|
|
1118
|
+
interface RetryMessageOptions {
|
|
1119
|
+
/** Chave obrigatória, não vazia, de até 200 caracteres. Reutilize após timeout. */
|
|
1120
|
+
idempotencyKey: string;
|
|
1121
|
+
}
|
|
1122
|
+
/** Uma retentativa aceita pela fila, ainda sem confirmação do provedor. */
|
|
1123
|
+
interface AcceptedMessageRetry {
|
|
1124
|
+
/** Identificador da mensagem original. */
|
|
1125
|
+
id: string;
|
|
1126
|
+
/** Nova entrega criada para a mensagem original. */
|
|
1127
|
+
deliveryId: string;
|
|
1128
|
+
/** Registro de auditoria desta retentativa. */
|
|
1129
|
+
retryId: string;
|
|
1130
|
+
status: 'accepted';
|
|
1131
|
+
}
|
|
1132
|
+
/** Registro de uma retentativa manual aceita, preservado na consulta. */
|
|
1133
|
+
interface MessageRetry {
|
|
1134
|
+
id: string;
|
|
1135
|
+
/** Entrega anterior, preservada com suas tentativas. */
|
|
1136
|
+
previousDeliveryId: string;
|
|
1137
|
+
/** Nova entrega criada para o mesmo conteúdo e destinatário. */
|
|
1138
|
+
deliveryId: string;
|
|
1139
|
+
/** Usuário que solicitou a retentativa; nulo para API key. */
|
|
1140
|
+
actorId: string | null;
|
|
1141
|
+
createdAt: IsoDateTime;
|
|
1142
|
+
}
|
|
1143
|
+
/** Uma tentativa de provedor dentro de uma entrega. */
|
|
1144
|
+
interface MessageAttempt {
|
|
1145
|
+
/** Provedor desta tentativa. */
|
|
1146
|
+
provider: ProviderId | LooseString;
|
|
1147
|
+
/** {@link MESSAGE_ATTEMPT_OUTCOMES} */
|
|
1148
|
+
outcome: MessageAttemptOutcome;
|
|
1149
|
+
/**
|
|
1150
|
+
* Rodada da fila.
|
|
1151
|
+
*
|
|
1152
|
+
* @remarks
|
|
1153
|
+
* Uma rodada nova é o job inteiro sendo tentado de novo, depois de um erro
|
|
1154
|
+
* que permite retentar.
|
|
1155
|
+
*/
|
|
1156
|
+
round: number;
|
|
1157
|
+
/** Ordem da tentativa dentro da rodada. */
|
|
1158
|
+
sequence: number;
|
|
1159
|
+
/** Código devolvido pelo provedor na falha. Nulo quando não houve falha. */
|
|
1160
|
+
failureCode: string | null;
|
|
1161
|
+
/** Texto devolvido pelo provedor na falha. */
|
|
1162
|
+
failureReason: string | null;
|
|
1163
|
+
/** Quando a tentativa começou. */
|
|
1164
|
+
startedAt: IsoDateTime;
|
|
1165
|
+
/** Quando terminou. Nulo enquanto está em curso. */
|
|
1166
|
+
finishedAt: IsoDateTime | null;
|
|
1167
|
+
}
|
|
1168
|
+
/** Uma entrega da mensagem, com o histórico do que cada provedor fez. */
|
|
1169
|
+
interface MessageChannel {
|
|
1170
|
+
/** Identificador da entrega. */
|
|
1171
|
+
id: string;
|
|
1172
|
+
/** Quando uma retentativa substituiu esta entrega. Nulo na entrega atual. */
|
|
1173
|
+
supersededAt: IsoDateTime | null;
|
|
1174
|
+
/** Canal por onde a mensagem saiu. */
|
|
1175
|
+
channel: ProviderChannel;
|
|
1176
|
+
/** Destinatário deste canal: o e-mail ou o número. */
|
|
1177
|
+
destination: string;
|
|
1178
|
+
/** Provedor que ficou com a entrega. Nulo enquanto nenhum foi escolhido. */
|
|
1179
|
+
provider: ProviderId | LooseString | null;
|
|
1180
|
+
/**
|
|
1181
|
+
* Identificador da mensagem no provedor.
|
|
1182
|
+
*
|
|
1183
|
+
* @remarks
|
|
1184
|
+
* Serve para cruzar com o painel dele. Nulo até o provedor aceitar.
|
|
1185
|
+
*/
|
|
1186
|
+
providerMessageId: string | null;
|
|
1187
|
+
/** {@link MESSAGE_DELIVERY_STATUSES} */
|
|
1188
|
+
status: MessageDeliveryStatus;
|
|
1189
|
+
/** Quantas vezes a fila processou esta entrega. */
|
|
1190
|
+
attempts: number;
|
|
1191
|
+
/** Código da última falha. */
|
|
1192
|
+
failureCode: string | null;
|
|
1193
|
+
/**
|
|
1194
|
+
* Texto devolvido pelo provedor na falha.
|
|
1195
|
+
*
|
|
1196
|
+
* @remarks
|
|
1197
|
+
* É o que distingue uma devolução por endereço inexistente de uma por caixa
|
|
1198
|
+
* cheia — o código diz só que a mensagem voltou.
|
|
1199
|
+
*/
|
|
1200
|
+
failureReason: string | null;
|
|
1201
|
+
/** Quando o provedor aceitou a mensagem. */
|
|
1202
|
+
sentAt: IsoDateTime | null;
|
|
1203
|
+
/** Quando o provedor confirmou a entrega ao destinatário. */
|
|
1204
|
+
deliveredAt: IsoDateTime | null;
|
|
1205
|
+
/** Quando a entrega falhou de vez. */
|
|
1206
|
+
failedAt: IsoDateTime | null;
|
|
1207
|
+
/**
|
|
1208
|
+
* Todo provedor tentado, na ordem.
|
|
1209
|
+
*
|
|
1210
|
+
* @remarks
|
|
1211
|
+
* É aqui que se vê um envio que caiu do provedor primário para o
|
|
1212
|
+
* secundário — a entrega mostra só quem ficou com ela.
|
|
1213
|
+
*/
|
|
1214
|
+
attemptLog: MessageAttempt[];
|
|
1215
|
+
}
|
|
1216
|
+
/** O que um webhook de provedor confirmou sobre a mensagem. */
|
|
1217
|
+
interface MessageEvent {
|
|
1218
|
+
/** Identificador do evento. */
|
|
1219
|
+
id: string;
|
|
1220
|
+
/** Entrega a que o evento se refere. */
|
|
1221
|
+
deliveryId: string | null;
|
|
1222
|
+
/** Provedor que mandou o evento. */
|
|
1223
|
+
provider: ProviderId | LooseString;
|
|
1224
|
+
/**
|
|
1225
|
+
* Tipo do evento.
|
|
1226
|
+
*
|
|
1227
|
+
* @remarks
|
|
1228
|
+
* {@link MESSAGE_EVENT_TYPES} lista os conhecidos; um tipo novo do provedor
|
|
1229
|
+
* chega pelo nome cru em vez de sumir, por isso qualquer string é válida.
|
|
1230
|
+
*/
|
|
1231
|
+
type: MessageEventType | LooseString;
|
|
1232
|
+
/** Instante informado pelo provedor ou, na falta dele, o do recebimento. */
|
|
1233
|
+
occurredAt: IsoDateTime;
|
|
1234
|
+
}
|
|
1235
|
+
/**
|
|
1236
|
+
* A mensagem inteira, como `messages.get` devolve.
|
|
1237
|
+
*
|
|
1238
|
+
* @remarks
|
|
1239
|
+
* Traz o corpo completo, o que cada canal fez com ela (`channels`) e o que os
|
|
1240
|
+
* webhooks do provedor confirmaram até agora (`events`).
|
|
1241
|
+
*/
|
|
1242
|
+
interface Message {
|
|
1243
|
+
/** Identificador da mensagem. */
|
|
1244
|
+
id: string;
|
|
1245
|
+
/** Remetente, como enviado na criação. */
|
|
1246
|
+
from: string;
|
|
1247
|
+
/** Assunto. Nulo em WhatsApp. */
|
|
1248
|
+
subject: string | null;
|
|
1249
|
+
/** Corpo em texto, inteiro. */
|
|
1250
|
+
content: string | null;
|
|
1251
|
+
providerTemplate: WhatsAppProviderTemplate | null;
|
|
1252
|
+
/** Metadados dos anexos, na ordem do envio. Vazio quando não houve. */
|
|
1253
|
+
attachments: MessageAttachment[];
|
|
1254
|
+
/** Corpo HTML, inteiro. */
|
|
1255
|
+
html: string | null;
|
|
1256
|
+
/** Template informado na criação. */
|
|
1257
|
+
template: string | null;
|
|
1258
|
+
/** Variáveis do template, como enviadas. */
|
|
1259
|
+
data: JsonObject | null;
|
|
1260
|
+
/** Idioma informado na criação. */
|
|
1261
|
+
locale: string | null;
|
|
1262
|
+
/** Os seus dados, como enviados na criação. */
|
|
1263
|
+
metadata: JsonObject | null;
|
|
1264
|
+
/** {@link MESSAGE_PRIORITIES} */
|
|
1265
|
+
priority: MessagePriority;
|
|
1266
|
+
/** {@link MESSAGE_STATUSES} */
|
|
1267
|
+
status: MessageStatus;
|
|
1268
|
+
/** Verdadeiro quando a mensagem foi criada com `sendAt`. */
|
|
1269
|
+
scheduled: boolean;
|
|
1270
|
+
/** Instante agendado, quando houver. */
|
|
1271
|
+
sendAt: IsoDateTime | null;
|
|
1272
|
+
/**
|
|
1273
|
+
* Quando a política de retenção do projeto anonimizou o conteúdo.
|
|
1274
|
+
*
|
|
1275
|
+
* @remarks
|
|
1276
|
+
* Preenchido, assunto, corpo, `data` e `metadata` vêm vazios e o
|
|
1277
|
+
* destinatário, mascarado (`m***@example.com`). Status e horários
|
|
1278
|
+
* continuam valendo.
|
|
1279
|
+
*/
|
|
1280
|
+
redactedAt: IsoDateTime | null;
|
|
1281
|
+
/** A `idempotencyKey` com que a mensagem foi criada, quando houve uma. */
|
|
1282
|
+
idempotencyKey: string | null;
|
|
1283
|
+
/** Quando a mensagem foi aceita. */
|
|
1284
|
+
createdAt: IsoDateTime;
|
|
1285
|
+
/** Última mudança de estado. */
|
|
1286
|
+
updatedAt: IsoDateTime;
|
|
1287
|
+
/** Entregas atuais e substituídas, cada uma com o histórico de tentativas. */
|
|
1288
|
+
channels: MessageChannel[];
|
|
1289
|
+
/** Retentativas manuais aceitas, da mais antiga para a mais recente. */
|
|
1290
|
+
retryLog: MessageRetry[];
|
|
1291
|
+
/** Do mais antigo para o mais recente. */
|
|
1292
|
+
events: MessageEvent[];
|
|
1293
|
+
}
|
|
1294
|
+
/**
|
|
1295
|
+
* As mensagens do projeto.
|
|
1296
|
+
*
|
|
1297
|
+
* @remarks
|
|
1298
|
+
* Nenhum método lança por erro de API: todos devolvem `{ data, error }`.
|
|
1299
|
+
*/
|
|
1300
|
+
export declare class Messages {
|
|
1301
|
+
private readonly http;
|
|
1302
|
+
constructor(http: HttpClient);
|
|
1303
|
+
/**
|
|
1304
|
+
* Envia uma mensagem por e-mail ou WhatsApp.
|
|
1305
|
+
*
|
|
1306
|
+
* @remarks
|
|
1307
|
+
* A API responde **202** sem esperar o provedor: o retorno confirma que a
|
|
1308
|
+
* mensagem foi aceita e enfileirada, não que chegou. O estado final vem
|
|
1309
|
+
* pelos webhooks do projeto ou por {@link Messages.get}.
|
|
1310
|
+
*
|
|
1311
|
+
* Passe `idempotencyKey` para tornar o reenvio seguro — repetir a mesma
|
|
1312
|
+
* chave com o mesmo pedido devolve a resposta aceita original, mesmo depois
|
|
1313
|
+
* de a entrega mudar de estado. Alterar o pedido ou reutilizar a chave de
|
|
1314
|
+
* um lote retorna `IDEMPOTENCY_KEY_REUSED` (409), sem retry automático.
|
|
1315
|
+
* É também o que autoriza o SDK a retentar um envio que deu timeout.
|
|
1316
|
+
*
|
|
1317
|
+
* @example E-mail
|
|
1318
|
+
* ```ts
|
|
1319
|
+
* const { data, error } = await client.messages.send({
|
|
1320
|
+
* to: { email: 'hiago@rockfeller.com.br' },
|
|
1321
|
+
* from: 'Financeiro <financeiro@rockfeller.com.br>',
|
|
1322
|
+
* subject: 'Pagamento aprovado',
|
|
1323
|
+
* html: '<p>Recebemos o seu pagamento.</p>',
|
|
1324
|
+
* content: 'Recebemos o seu pagamento.',
|
|
1325
|
+
* metadata: { fatura: 'INV-2026-0912' },
|
|
1326
|
+
* idempotencyKey: 'fatura-INV-2026-0912-aprovada',
|
|
1327
|
+
* })
|
|
1328
|
+
* if (error) return console.error(error.code, error.message)
|
|
1329
|
+
* console.log(data.id, data.deliveries.email?.id)
|
|
1330
|
+
* ```
|
|
1331
|
+
*
|
|
1332
|
+
* @example WhatsApp
|
|
1333
|
+
* ```ts
|
|
1334
|
+
* await client.messages.send({
|
|
1335
|
+
* to: { whatsapp: '+5511999999999' },
|
|
1336
|
+
* from: 'suporte',
|
|
1337
|
+
* content: 'Olá! Como podemos ajudar?',
|
|
1338
|
+
* })
|
|
1339
|
+
* ```
|
|
1340
|
+
*/
|
|
1341
|
+
send(options: SendMessageOptions, requestOptions?: RequestOptions): Promise<Result<AcceptedMessage>>;
|
|
1342
|
+
/**
|
|
1343
|
+
* Envia de 1 a 100 mensagens em uma única requisição.
|
|
1344
|
+
*
|
|
1345
|
+
* @remarks
|
|
1346
|
+
* O lote é atômico: a API só aceita a requisição quando todas as mensagens
|
|
1347
|
+
* passam pelo mesmo processamento do envio individual. Use
|
|
1348
|
+
* `idempotencyKey` nas opções da requisição inteira para tornar retries
|
|
1349
|
+
* seguros: o mesmo lote recupera a resposta aceita original. Alterar campos,
|
|
1350
|
+
* tamanho ou ordem dos itens, ou usar a chave de um envio individual,
|
|
1351
|
+
* retorna `IDEMPOTENCY_KEY_REUSED` (409), sem retry automático.
|
|
1352
|
+
*/
|
|
1353
|
+
batch(messages: BatchSendMessageOptions[], requestOptions?: BatchRequestOptions): Promise<Result<AcceptedBatchMessage[]>>;
|
|
1354
|
+
/** Apelido de {@link Messages.send}, para quem prefere o verbo do REST. */
|
|
1355
|
+
create(options: SendMessageOptions, requestOptions?: RequestOptions): Promise<Result<AcceptedMessage>>;
|
|
1356
|
+
/**
|
|
1357
|
+
* Retenta uma mensagem que falhou sem evidência de envio ao provedor.
|
|
1358
|
+
*
|
|
1359
|
+
* @remarks
|
|
1360
|
+
* Exige uma chave de idempotência: repetir a mesma chave devolve a resposta
|
|
1361
|
+
* aceita original. A API recusa entregas em andamento, enviadas ou com
|
|
1362
|
+
* resultado incerto com `MESSAGE_NOT_RETRYABLE`. `failed` sozinho não
|
|
1363
|
+
* garante que a mensagem pode ser retentada.
|
|
1364
|
+
*/
|
|
1365
|
+
retry(id: string, options: RetryMessageOptions, requestOptions?: RequestOptions): Promise<Result<AcceptedMessageRetry>>;
|
|
1366
|
+
/**
|
|
1367
|
+
* A mensagem inteira e o estado de cada entrega.
|
|
1368
|
+
*
|
|
1369
|
+
* @remarks
|
|
1370
|
+
* É por aqui que se acompanha uma mensagem aceita em {@link Messages.send},
|
|
1371
|
+
* já que aquela resposta é anterior ao envio. Traz `channels[].attemptLog`,
|
|
1372
|
+
* onde se vê todo provedor tentado — inclusive um fallback do primário para
|
|
1373
|
+
* o secundário — e `events[]`, com o que os webhooks do provedor
|
|
1374
|
+
* confirmaram.
|
|
1375
|
+
*
|
|
1376
|
+
* @example
|
|
1377
|
+
* ```ts
|
|
1378
|
+
* const { data, error } = await client.messages.get(id)
|
|
1379
|
+
* if (error?.code === 'MESSAGE_NOT_FOUND') return null
|
|
1380
|
+
* console.log(data?.status, data?.channels[0]?.deliveredAt)
|
|
1381
|
+
* ```
|
|
1382
|
+
*/
|
|
1383
|
+
get(id: string, requestOptions?: RequestOptions): Promise<Result<Message>>;
|
|
1384
|
+
/** Apelido de {@link Messages.get}. */
|
|
1385
|
+
retrieve(id: string, requestOptions?: RequestOptions): Promise<Result<Message>>;
|
|
1386
|
+
/**
|
|
1387
|
+
* Lista as mensagens do projeto, da mais recente para a mais antiga.
|
|
1388
|
+
*
|
|
1389
|
+
* @remarks
|
|
1390
|
+
* A página devolvida sabe pedir a próxima (`page.next()`) e também pode ser
|
|
1391
|
+
* iterada com `for await`, atravessando todas as páginas sozinha.
|
|
1392
|
+
*
|
|
1393
|
+
* @example Uma página
|
|
1394
|
+
* ```ts
|
|
1395
|
+
* const { data, error } = await client.messages.list({
|
|
1396
|
+
* status: ['failed', 'bounced'],
|
|
1397
|
+
* createdAfter: new Date(Date.now() - 24 * 60 * 60 * 1000),
|
|
1398
|
+
* limit: 100,
|
|
1399
|
+
* })
|
|
1400
|
+
* if (error) throw error
|
|
1401
|
+
* console.log(data.messages.length, data.nextCursor)
|
|
1402
|
+
* ```
|
|
1403
|
+
*
|
|
1404
|
+
* @example Todas as mensagens
|
|
1405
|
+
* ```ts
|
|
1406
|
+
* const { data: page, error } = await client.messages.list({ channel: 'whatsapp' })
|
|
1407
|
+
* if (error) throw error
|
|
1408
|
+
* for await (const message of page) console.log(message.id)
|
|
1409
|
+
* ```
|
|
1410
|
+
*/
|
|
1411
|
+
list(options?: ListMessagesOptions, requestOptions?: RequestOptions): Promise<Result<MessagesPage>>;
|
|
1412
|
+
}
|
|
1413
|
+
/**
|
|
1414
|
+
* Envio por e-mail, com o canal já decidido.
|
|
1415
|
+
*
|
|
1416
|
+
* @remarks
|
|
1417
|
+
* É {@link Messages.send} com o destino montado por você: `to` é o endereço em
|
|
1418
|
+
* string, sem `{ email }` em volta. Nada mais muda — mesma resposta, mesmos
|
|
1419
|
+
* erros, mesma idempotência.
|
|
1420
|
+
*/
|
|
1421
|
+
export declare class Emails {
|
|
1422
|
+
private readonly messages;
|
|
1423
|
+
constructor(messages: Messages);
|
|
1424
|
+
/**
|
|
1425
|
+
* Envia um e-mail.
|
|
1426
|
+
*
|
|
1427
|
+
* @remarks
|
|
1428
|
+
* `subject` e `html` são obrigatórios, e o domínio de `from` precisa estar
|
|
1429
|
+
* verificado no projeto — senão o erro é `FROM_DOMAIN_NOT_VERIFIED`.
|
|
1430
|
+
* `content` é a alternativa em texto: é o que aparece em cliente que
|
|
1431
|
+
* bloqueia HTML, e ajuda na reputação de entrega.
|
|
1432
|
+
*
|
|
1433
|
+
* @example
|
|
1434
|
+
* ```ts
|
|
1435
|
+
* const { data, error } = await client.emails.send({
|
|
1436
|
+
* to: 'hiago@rockfeller.com.br',
|
|
1437
|
+
* from: 'Financeiro <financeiro@rockfeller.com.br>',
|
|
1438
|
+
* subject: 'Pagamento aprovado',
|
|
1439
|
+
* html: '<p>Recebemos o seu pagamento.</p>',
|
|
1440
|
+
* content: 'Recebemos o seu pagamento.',
|
|
1441
|
+
* })
|
|
1442
|
+
* if (error) return console.error(error.code)
|
|
1443
|
+
* console.log(data.id, data.deliveries.email?.status)
|
|
1444
|
+
* ```
|
|
1445
|
+
*/
|
|
1446
|
+
send(options: SendEmailInput, requestOptions?: RequestOptions): Promise<Result<AcceptedMessage>>;
|
|
1447
|
+
/** Envia de 1 a 100 e-mails em uma única requisição atômica. */
|
|
1448
|
+
batch(options: BatchSendEmailInput[], requestOptions?: BatchRequestOptions): Promise<Result<AcceptedBatchMessage[]>>;
|
|
1449
|
+
}
|
|
1450
|
+
/**
|
|
1451
|
+
* Envio por SMS, com o canal já decidido.
|
|
1452
|
+
*
|
|
1453
|
+
* @remarks
|
|
1454
|
+
* É {@link Messages.send} com o destino montado por você: `to` é o celular em
|
|
1455
|
+
* E.164, sem `{ sms }` em volta. Mesma resposta, mesmos erros, mesma
|
|
1456
|
+
* idempotência.
|
|
1457
|
+
*/
|
|
1458
|
+
export declare class Sms {
|
|
1459
|
+
private readonly messages;
|
|
1460
|
+
constructor(messages: Messages);
|
|
1461
|
+
/**
|
|
1462
|
+
* Envia um SMS.
|
|
1463
|
+
*
|
|
1464
|
+
* @remarks
|
|
1465
|
+
* Só `content`, até 1600 caracteres. O `from` é um número Twilio do
|
|
1466
|
+
* projeto (E.164) ou o slug dele — desconhecido ou desligado é
|
|
1467
|
+
* `SENDER_NOT_FOUND`. A entrega passa a `delivered` quando a operadora
|
|
1468
|
+
* confirma; número inexistente ou fixo vira `bounced`, e destinatário que
|
|
1469
|
+
* respondeu STOP, `suppressed`.
|
|
1470
|
+
*
|
|
1471
|
+
* @example
|
|
1472
|
+
* ```ts
|
|
1473
|
+
* const { data, error } = await client.sms.send({
|
|
1474
|
+
* to: '+5511999999999',
|
|
1475
|
+
* from: '+15550001111',
|
|
1476
|
+
* content: 'Seu código de acesso é 482913.',
|
|
1477
|
+
* })
|
|
1478
|
+
* if (error) return console.error(error.code)
|
|
1479
|
+
* console.log(data.id, data.deliveries.sms?.status)
|
|
1480
|
+
* ```
|
|
1481
|
+
*/
|
|
1482
|
+
send(options: SendSmsInput, requestOptions?: RequestOptions): Promise<Result<AcceptedMessage>>;
|
|
1483
|
+
/** Envia de 1 a 100 SMS em uma única requisição atômica. */
|
|
1484
|
+
batch(options: BatchSendSmsInput[], requestOptions?: BatchRequestOptions): Promise<Result<AcceptedBatchMessage[]>>;
|
|
1485
|
+
}
|
|
1486
|
+
/**
|
|
1487
|
+
* Envio por web push, com o canal já decidido.
|
|
1488
|
+
*
|
|
1489
|
+
* @remarks
|
|
1490
|
+
* É {@link Messages.send} com o destino montado por você: `to` é o
|
|
1491
|
+
* `recipientId`, sem `{ webpush }` em volta. Nada mais muda — mesma resposta,
|
|
1492
|
+
* mesmos erros, mesma idempotência.
|
|
1493
|
+
*/
|
|
1494
|
+
export declare class WebPush {
|
|
1495
|
+
private readonly messages;
|
|
1496
|
+
private readonly http;
|
|
1497
|
+
constructor(messages: Messages, http: HttpClient);
|
|
1498
|
+
/**
|
|
1499
|
+
* Emite o token que autoriza o navegador de alguém a se inscrever.
|
|
1500
|
+
*
|
|
1501
|
+
* @remarks
|
|
1502
|
+
* Chame no **backend**, para a pessoa logada, e entregue `token` à página:
|
|
1503
|
+
* ela o manda no corpo de `POST` e `DELETE /v1/webpush/subscriptions/{appId}`.
|
|
1504
|
+
* É o token que prova à API quem é o destinatário — sem ele a inscrição é
|
|
1505
|
+
* recusada com `WEBPUSH_SUBSCRIPTION_TOKEN_REQUIRED`.
|
|
1506
|
+
*
|
|
1507
|
+
* Vale uma hora e pode ser reutilizado até lá. Exige API key de escopo
|
|
1508
|
+
* `write`; `appId` fora do projeto da chave dá `WEBPUSH_APP_NOT_FOUND`.
|
|
1509
|
+
*
|
|
1510
|
+
* @example
|
|
1511
|
+
* ```ts
|
|
1512
|
+
* const { data, error } = await client.webPush.createSubscriptionToken({
|
|
1513
|
+
* appId: 'checkout-web',
|
|
1514
|
+
* recipientId: customer.id,
|
|
1515
|
+
* })
|
|
1516
|
+
* if (error) return console.error(error.code)
|
|
1517
|
+
* // entregue data.token à página
|
|
1518
|
+
* ```
|
|
1519
|
+
*/
|
|
1520
|
+
createSubscriptionToken(options: CreateWebPushSubscriptionTokenInput, requestOptions?: RequestOptions): Promise<Result<WebPushSubscriptionToken>>;
|
|
1521
|
+
/**
|
|
1522
|
+
* Envia uma notificação web push.
|
|
1523
|
+
*
|
|
1524
|
+
* @remarks
|
|
1525
|
+
* `subject` é o título e `content` é o corpo; os dois são obrigatórios. O
|
|
1526
|
+
* `from` é o `appId` da aplicação cadastrada (`checkout-web`) — precisa
|
|
1527
|
+
* existir e estar habilitada, senão o erro é `WEBPUSH_APP_NOT_FOUND`.
|
|
1528
|
+
*
|
|
1529
|
+
* Um `recipientId` alcança todos os navegadores em que a pessoa autorizou,
|
|
1530
|
+
* e `data.deliveries.webPush.targets` diz quantos foram. Se ela não tiver
|
|
1531
|
+
* nenhum, o erro é `WEBPUSH_NO_ACTIVE_SUBSCRIPTION` — a plataforma não
|
|
1532
|
+
* aceita um envio que ninguém receberia.
|
|
1533
|
+
*
|
|
1534
|
+
* @example
|
|
1535
|
+
* ```ts
|
|
1536
|
+
* const { data, error } = await client.webPush.send({
|
|
1537
|
+
* to: 'cus_8f3a2c',
|
|
1538
|
+
* from: 'checkout-web',
|
|
1539
|
+
* subject: 'Pagamento aprovado',
|
|
1540
|
+
* content: 'Recebemos o pagamento da sua mensalidade.',
|
|
1541
|
+
* metadata: { fatura: 'INV-2026-0912' },
|
|
1542
|
+
* })
|
|
1543
|
+
* if (error) return console.error(error.code)
|
|
1544
|
+
* console.log(data.deliveries.webPush?.targets)
|
|
1545
|
+
* ```
|
|
1546
|
+
*/
|
|
1547
|
+
send(options: SendWebPushInput, requestOptions?: RequestOptions): Promise<Result<AcceptedMessage>>;
|
|
1548
|
+
/** Envia de 1 a 100 notificações web push em uma única requisição atômica. */
|
|
1549
|
+
batch(options: BatchSendWebPushInput[], requestOptions?: BatchRequestOptions): Promise<Result<AcceptedBatchMessage[]>>;
|
|
1550
|
+
}
|
|
1551
|
+
/**
|
|
1552
|
+
* Envio por WhatsApp, com o canal já decidido.
|
|
1553
|
+
*
|
|
1554
|
+
* @remarks
|
|
1555
|
+
* É {@link Messages.send} com o destino montado por você: `to` é o número em
|
|
1556
|
+
* E.164, sem `{ whatsapp }` em volta. Nada mais muda — mesma resposta, mesmos
|
|
1557
|
+
* erros, mesma idempotência.
|
|
1558
|
+
*/
|
|
1559
|
+
export declare class WhatsApp {
|
|
1560
|
+
private readonly messages;
|
|
1561
|
+
constructor(messages: Messages);
|
|
1562
|
+
/**
|
|
1563
|
+
* Envia uma mensagem de WhatsApp.
|
|
1564
|
+
*
|
|
1565
|
+
* @remarks
|
|
1566
|
+
* `content` ou `providerTemplate` é obrigatório; não há assunto nem HTML. O `from` é o slug do
|
|
1567
|
+
* número no projeto (`suporte`) ou o próprio número em E.164 — precisa
|
|
1568
|
+
* existir e estar habilitado, senão o erro é `SENDER_NOT_FOUND`.
|
|
1569
|
+
*
|
|
1570
|
+
* @example
|
|
1571
|
+
* ```ts
|
|
1572
|
+
* const { data, error } = await client.whatsapp.send({
|
|
1573
|
+
* to: '+5511999999999',
|
|
1574
|
+
* from: 'suporte',
|
|
1575
|
+
* content: 'Olá! Sua aula de amanhã é às 19h.',
|
|
1576
|
+
* metadata: { turmaId: '8f3a2c' },
|
|
1577
|
+
* })
|
|
1578
|
+
* if (error) return console.error(error.code)
|
|
1579
|
+
* console.log(data.id, data.deliveries.whatsapp?.status)
|
|
1580
|
+
* ```
|
|
1581
|
+
*/
|
|
1582
|
+
send(options: SendWhatsAppInput, requestOptions?: RequestOptions): Promise<Result<AcceptedMessage>>;
|
|
1583
|
+
/** Envia de 1 a 100 mensagens de WhatsApp em uma única requisição atômica. */
|
|
1584
|
+
batch(options: BatchSendWhatsAppInput[], requestOptions?: BatchRequestOptions): Promise<Result<AcceptedBatchMessage[]>>;
|
|
1585
|
+
}
|
|
1586
|
+
/** Definition submitted to Meta for approval; text headers and supported buttons only. */
|
|
1587
|
+
type WhatsAppTemplateComponent = {
|
|
1588
|
+
type: 'HEADER';
|
|
1589
|
+
format: 'TEXT';
|
|
1590
|
+
text: string;
|
|
1591
|
+
example?: {
|
|
1592
|
+
header_text: string[];
|
|
1593
|
+
};
|
|
1594
|
+
} | {
|
|
1595
|
+
type: 'BODY';
|
|
1596
|
+
text: string;
|
|
1597
|
+
example?: {
|
|
1598
|
+
body_text: string[][];
|
|
1599
|
+
};
|
|
1600
|
+
} | {
|
|
1601
|
+
type: 'FOOTER';
|
|
1602
|
+
text: string;
|
|
1603
|
+
} | {
|
|
1604
|
+
type: 'BUTTONS';
|
|
1605
|
+
buttons: Array<{
|
|
1606
|
+
type: 'QUICK_REPLY';
|
|
1607
|
+
text: string;
|
|
1608
|
+
} | {
|
|
1609
|
+
type: 'URL';
|
|
1610
|
+
text: string;
|
|
1611
|
+
url: string;
|
|
1612
|
+
example?: string[];
|
|
1613
|
+
} | {
|
|
1614
|
+
type: 'PHONE_NUMBER';
|
|
1615
|
+
text: string;
|
|
1616
|
+
phone_number: string;
|
|
1617
|
+
}>;
|
|
1618
|
+
};
|
|
1619
|
+
export declare const WHATSAPP_TEMPLATE_CATEGORIES: readonly ["MARKETING", "UTILITY"];
|
|
1620
|
+
type WhatsAppTemplateCategory = (typeof WHATSAPP_TEMPLATE_CATEGORIES)[number];
|
|
1621
|
+
export declare const WHATSAPP_TEMPLATE_STATUSES: readonly ["DRAFT", "SUBMITTING", "SUBMISSION_UNKNOWN", "PENDING", "APPROVED", "REJECTED", "PAUSED", "DISABLED", "DELETED"];
|
|
1622
|
+
type WhatsAppTemplateStatus = (typeof WHATSAPP_TEMPLATE_STATUSES)[number];
|
|
1623
|
+
interface CreateWhatsAppTemplateOptions {
|
|
1624
|
+
senderId: string;
|
|
1625
|
+
name: string;
|
|
1626
|
+
language: string;
|
|
1627
|
+
category: WhatsAppTemplateCategory;
|
|
1628
|
+
components: WhatsAppTemplateComponent[];
|
|
1629
|
+
}
|
|
1630
|
+
type UpdateWhatsAppTemplateOptions = Omit<CreateWhatsAppTemplateOptions, 'senderId'> & {
|
|
1631
|
+
expectedUpdatedAt: IsoDateTime;
|
|
1632
|
+
};
|
|
1633
|
+
interface SubmitWhatsAppTemplateOptions {
|
|
1634
|
+
/** The updatedAt of the draft reviewed for approval. */
|
|
1635
|
+
expectedUpdatedAt: IsoDateTime;
|
|
1636
|
+
}
|
|
1637
|
+
interface WhatsAppTemplate extends Omit<CreateWhatsAppTemplateOptions, 'category' | 'components'> {
|
|
1638
|
+
category: WhatsAppTemplateCategory | LooseString;
|
|
1639
|
+
/** Meta imports may include media, authentication or other unsupported components. */
|
|
1640
|
+
components: unknown[];
|
|
1641
|
+
id: string;
|
|
1642
|
+
organizationId: string;
|
|
1643
|
+
wabaId: string;
|
|
1644
|
+
status: WhatsAppTemplateStatus | LooseString;
|
|
1645
|
+
providerTemplateId: string | null;
|
|
1646
|
+
rejectionReason: string | null;
|
|
1647
|
+
lastSyncedAt: IsoDateTime | null;
|
|
1648
|
+
submittedAt: IsoDateTime | null;
|
|
1649
|
+
createdBy: string | null;
|
|
1650
|
+
createdAt: IsoDateTime;
|
|
1651
|
+
updatedAt: IsoDateTime;
|
|
1652
|
+
}
|
|
1653
|
+
/** Meta template registry. Mutations require a project API key with admin scope. */
|
|
1654
|
+
export declare class WhatsAppTemplates {
|
|
1655
|
+
private readonly http;
|
|
1656
|
+
constructor(http: HttpClient);
|
|
1657
|
+
list(options?: {
|
|
1658
|
+
senderId?: string;
|
|
1659
|
+
}, requestOptions?: RequestOptions): Promise<Result<WhatsAppTemplate[]>>;
|
|
1660
|
+
get(id: string, requestOptions?: RequestOptions): Promise<Result<WhatsAppTemplate>>;
|
|
1661
|
+
create(options: CreateWhatsAppTemplateOptions, requestOptions?: RequestOptions): Promise<Result<WhatsAppTemplate>>;
|
|
1662
|
+
/** Replace a draft definition using the last observed updatedAt to detect conflicting edits. */
|
|
1663
|
+
update(id: string, options: UpdateWhatsAppTemplateOptions, requestOptions?: RequestOptions): Promise<Result<WhatsAppTemplate>>;
|
|
1664
|
+
submit(id: string, options: SubmitWhatsAppTemplateOptions, requestOptions?: RequestOptions): Promise<Result<WhatsAppTemplate>>;
|
|
1665
|
+
sync(options: {
|
|
1666
|
+
senderId: string;
|
|
1667
|
+
}, requestOptions?: RequestOptions): Promise<Result<{
|
|
1668
|
+
synced: number;
|
|
1669
|
+
conflicts: Array<{
|
|
1670
|
+
name: string;
|
|
1671
|
+
language: string;
|
|
1672
|
+
}>;
|
|
1673
|
+
}>>;
|
|
1674
|
+
}
|
|
1675
|
+
/** Onde a API vive quando a configuração não diz outra coisa. */
|
|
1676
|
+
export declare const DEFAULT_BASE_URL = "https://api.messaging.rockfeller.com.br";
|
|
1677
|
+
/** Configuração do cliente. */
|
|
1678
|
+
interface MessagingConfig {
|
|
1679
|
+
/**
|
|
1680
|
+
* API key do projeto.
|
|
1681
|
+
*
|
|
1682
|
+
* @remarks
|
|
1683
|
+
* É um segredo de servidor: vaza se for parar em bundle de navegador ou em
|
|
1684
|
+
* app móvel, e quem a tiver envia em nome do seu projeto. Guarde em variável
|
|
1685
|
+
* de ambiente.
|
|
1686
|
+
*
|
|
1687
|
+
* O escopo da chave decide o que ela alcança: `write` para enviar, `read`
|
|
1688
|
+
* para consultar e listar.
|
|
1689
|
+
*/
|
|
1690
|
+
secret: string;
|
|
1691
|
+
/**
|
|
1692
|
+
* Base da API, sem a barra final e sem o `/v1` — o SDK acrescenta a versão.
|
|
1693
|
+
*
|
|
1694
|
+
* @remarks
|
|
1695
|
+
* Padrão {@link DEFAULT_BASE_URL}, ou `MESSAGING_BASE_URL` quando definida.
|
|
1696
|
+
* Aponte para `http://localhost:3001` em desenvolvimento.
|
|
1697
|
+
*/
|
|
1698
|
+
baseUrl?: string | undefined;
|
|
1699
|
+
/** Tempo máximo de cada chamada, em milissegundos. Padrão 30 000. */
|
|
1700
|
+
timeout?: number | undefined;
|
|
1701
|
+
/**
|
|
1702
|
+
* Quantas vezes repetir uma chamada que falhou de forma retentável.
|
|
1703
|
+
*
|
|
1704
|
+
* @remarks
|
|
1705
|
+
* Padrão 2, com backoff exponencial, jitter e respeito ao `Retry-After`.
|
|
1706
|
+
* Só valem para `GET` e para envios com `idempotencyKey`: repetir um `POST`
|
|
1707
|
+
* sem chave poderia entregar a mesma mensagem duas vezes. `0` desliga.
|
|
1708
|
+
*/
|
|
1709
|
+
maxRetries?: number | undefined;
|
|
1710
|
+
/** Cabeçalhos somados a toda requisição. */
|
|
1711
|
+
headers?: Record<string, string> | undefined;
|
|
1712
|
+
/**
|
|
1713
|
+
* Implementação de `fetch` a usar.
|
|
1714
|
+
*
|
|
1715
|
+
* @remarks
|
|
1716
|
+
* Padrão é o `fetch` global (Node 18+, Bun, Deno, workers). Injete o seu
|
|
1717
|
+
* para testar sem rede, para instrumentar, ou para passar um agente com
|
|
1718
|
+
* proxy.
|
|
1719
|
+
*/
|
|
1720
|
+
fetch?: FetchLike | undefined;
|
|
1721
|
+
}
|
|
1722
|
+
/**
|
|
1723
|
+
* Cliente da API de mensageria.
|
|
1724
|
+
*
|
|
1725
|
+
* @remarks
|
|
1726
|
+
* Nenhum método lança por erro de API: todos devolvem `{ data, error }`, e
|
|
1727
|
+
* `error` é uma instância de `MessagingError`. Falhas de programação — uma
|
|
1728
|
+
* configuração inválida no construtor — continuam lançando, porque não são
|
|
1729
|
+
* condição de execução.
|
|
1730
|
+
*
|
|
1731
|
+
* @example
|
|
1732
|
+
* ```ts
|
|
1733
|
+
* import { Messaging } from 'franchising/messaging'
|
|
1734
|
+
*
|
|
1735
|
+
* export const client = new Messaging({ secret: process.env.MESSAGING_API_KEY! })
|
|
1736
|
+
*
|
|
1737
|
+
* const { data, error } = await client.emails.send({
|
|
1738
|
+
* to: 'hiago@rockfeller.com.br',
|
|
1739
|
+
* from: 'Financeiro <financeiro@rockfeller.com.br>',
|
|
1740
|
+
* subject: 'Pagamento aprovado',
|
|
1741
|
+
* html: '<p>Recebemos o seu pagamento.</p>',
|
|
1742
|
+
* })
|
|
1743
|
+
* ```
|
|
1744
|
+
*/
|
|
1745
|
+
export declare class Messaging {
|
|
1746
|
+
/** Envio e consulta de mensagens, em qualquer canal. */
|
|
1747
|
+
readonly messages: Messages;
|
|
1748
|
+
/** Atalho de {@link Messaging.messages} para o canal de e-mail. */
|
|
1749
|
+
readonly emails: Emails;
|
|
1750
|
+
/** Atalho de {@link Messaging.messages} para o canal de WhatsApp. */
|
|
1751
|
+
readonly whatsapp: WhatsApp;
|
|
1752
|
+
readonly whatsappTemplates: WhatsAppTemplates;
|
|
1753
|
+
/** Atalho de {@link Messaging.messages} para o canal de SMS. */
|
|
1754
|
+
readonly sms: Sms;
|
|
1755
|
+
/** Envio por web push, com o canal já decidido. */
|
|
1756
|
+
readonly webPush: WebPush;
|
|
1757
|
+
constructor(config: MessagingConfig | string);
|
|
1758
|
+
}
|
|
1759
|
+
/** Quantas mensagens `messages.list` devolve por página quando você não diz. */
|
|
1760
|
+
export declare const MESSAGE_LIST_DEFAULT_LIMIT = 25;
|
|
1761
|
+
/** Teto de `limit` em `messages.list`. Acima disso a API responde `VALIDATION_ERROR`. */
|
|
1762
|
+
export declare const MESSAGE_LIST_MAX_LIMIT = 100;
|
|
1763
|
+
/** Quantas mensagens `messages.batch` aceita em uma única chamada. */
|
|
1764
|
+
export declare const MESSAGE_BATCH_MAX_SIZE = 100;
|
|
1765
|
+
/** Limite do corpo (`content` e `html`), em bytes UTF-8. */
|
|
1766
|
+
export declare const MESSAGE_BODY_MAX_BYTES: number;
|
|
1767
|
+
/** Limite do texto de um SMS, em caracteres (o teto da Twilio). */
|
|
1768
|
+
export declare const SMS_CONTENT_MAX_LENGTH = 1600;
|
|
1769
|
+
/** Limite de `data` e `metadata` já serializados, em bytes. */
|
|
1770
|
+
export declare const MESSAGE_JSON_MAX_BYTES: number;
|
|
1771
|
+
/** Limite do `subject`, em caracteres. */
|
|
1772
|
+
export declare const MESSAGE_SUBJECT_MAX_LENGTH = 998;
|
|
1773
|
+
/** Versão do pacote `franchising`, a mesma do `package.json`. */
|
|
1774
|
+
export declare const VERSION = "0.2.0";
|
|
1775
|
+
export { type AcceptedBatchMessage, type AcceptedDelivery, type AcceptedMessage, type AcceptedMessageRetry, type AcceptedWebPushDelivery, type AttachmentContent, type AttachmentContentInput, type AttachmentInput, type AttachmentUrlInput, type BatchRequestOptions, type BatchSendEmailInput, type BatchSendMessageOptions, type BatchSendSmsInput, type BatchSendWebPushInput, type BatchSendWhatsAppInput, type CreateWebPushSubscriptionTokenInput, type CreateWhatsAppTemplateOptions, type EmailAttachmentDisposition, type EmailAttachmentInput, type EmailAttachmentOptions, type EmailDestination, type FetchLike, type IsoDateTime, type JsonObject, type ListMessagesOptions, type ListedMessage, type ListedMessageChannel, type LooseString, type Message, type MessageAttachment, type MessageAttachmentSource, type MessageAttempt, type MessageAttemptOutcome, type MessageChannel, type MessageDeliveryStatus, type MessageDestination, type MessageEvent, type MessageEventType, type MessageListPayload, type MessagePriority, type MessageRetry, type MessageStatus, Messaging as default, type MessagingConfig, type MessagingErrorCode, type MessagingErrorOptions, type ProviderChannel, type ProviderId, type RequestOptions, type Result, type RetryMessageOptions, type SendEmailInput, type SendEmailOptions, type SendMessageOptions, type SendSmsInput, type SendSmsOptions, type SendWebPushInput, type SendWebPushOptions, type SendWhatsAppInput, type SendWhatsAppOptions, type SmsDestination, type SubmitWhatsAppTemplateOptions, type UpdateWhatsAppTemplateOptions, type WebPushDestination, type WebPushSubscriptionToken, type WebPushTarget, type WhatsAppAttachmentInput, type WhatsAppDestination, type WhatsAppMediaKind, type WhatsAppProviderTemplate, type WhatsAppTemplate, type WhatsAppTemplateCategory, type WhatsAppTemplateComponent, type WhatsAppTemplateStatus };
|