@geekapps/post-nextjs 0.1.14 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +192 -1
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +3 -0
- package/src/index.ts +16 -0
- package/src/resources/whatsapp-messages.ts +83 -0
- package/src/types.ts +122 -0
package/dist/index.d.ts
CHANGED
|
@@ -214,6 +214,15 @@ interface TemplateVariables {
|
|
|
214
214
|
footer?: TemplateVariable[];
|
|
215
215
|
buttons?: TemplateVariable[];
|
|
216
216
|
}
|
|
217
|
+
interface EmailAttachment {
|
|
218
|
+
filename: string;
|
|
219
|
+
/** Conteúdo do arquivo em base64. Informe `content` ou `url`. */
|
|
220
|
+
content?: string;
|
|
221
|
+
/** URL pública (http/https) do arquivo. Informe `content` ou `url`. */
|
|
222
|
+
url?: string;
|
|
223
|
+
/** Ex.: "application/pdf". Se omitido, é inferido pelo nome do arquivo. */
|
|
224
|
+
contentType?: string;
|
|
225
|
+
}
|
|
217
226
|
interface SendMessageInput {
|
|
218
227
|
type: MessageType;
|
|
219
228
|
to: string;
|
|
@@ -224,6 +233,8 @@ interface SendMessageInput {
|
|
|
224
233
|
subject?: string;
|
|
225
234
|
body?: string;
|
|
226
235
|
variables?: TemplateVariable[] | TemplateVariables;
|
|
236
|
+
/** Apenas para `type: "email"`. Máx. 10 arquivos / 25MB no total. */
|
|
237
|
+
attachments?: EmailAttachment[];
|
|
227
238
|
}
|
|
228
239
|
interface CreateTemplateInput {
|
|
229
240
|
name: string;
|
|
@@ -491,6 +502,147 @@ interface MessagePresenceResult {
|
|
|
491
502
|
success: boolean;
|
|
492
503
|
phoneNumberId: string;
|
|
493
504
|
}
|
|
505
|
+
/** Mídia já enviada (`id`) ou URL pública (`link`). */
|
|
506
|
+
interface WhatsappMediaRef {
|
|
507
|
+
id?: string;
|
|
508
|
+
link?: string;
|
|
509
|
+
}
|
|
510
|
+
interface WhatsappContactCard {
|
|
511
|
+
name: {
|
|
512
|
+
formattedName: string;
|
|
513
|
+
firstName?: string;
|
|
514
|
+
lastName?: string;
|
|
515
|
+
};
|
|
516
|
+
phones?: {
|
|
517
|
+
phone: string;
|
|
518
|
+
type?: string;
|
|
519
|
+
waId?: string;
|
|
520
|
+
}[];
|
|
521
|
+
emails?: {
|
|
522
|
+
email: string;
|
|
523
|
+
type?: string;
|
|
524
|
+
}[];
|
|
525
|
+
org?: {
|
|
526
|
+
company?: string;
|
|
527
|
+
title?: string;
|
|
528
|
+
};
|
|
529
|
+
urls?: {
|
|
530
|
+
url: string;
|
|
531
|
+
type?: string;
|
|
532
|
+
}[];
|
|
533
|
+
/** YYYY-MM-DD */
|
|
534
|
+
birthday?: string;
|
|
535
|
+
}
|
|
536
|
+
interface WhatsappInteractiveButtons {
|
|
537
|
+
kind: "buttons";
|
|
538
|
+
body: string;
|
|
539
|
+
header?: string;
|
|
540
|
+
footer?: string;
|
|
541
|
+
/** Até 3 botões. `id` volta em `message_received` quando o usuário clica. */
|
|
542
|
+
buttons: {
|
|
543
|
+
id: string;
|
|
544
|
+
title: string;
|
|
545
|
+
}[];
|
|
546
|
+
}
|
|
547
|
+
interface WhatsappInteractiveList {
|
|
548
|
+
kind: "list";
|
|
549
|
+
body: string;
|
|
550
|
+
header?: string;
|
|
551
|
+
footer?: string;
|
|
552
|
+
buttonText: string;
|
|
553
|
+
sections: {
|
|
554
|
+
title?: string;
|
|
555
|
+
rows: {
|
|
556
|
+
id: string;
|
|
557
|
+
title: string;
|
|
558
|
+
description?: string;
|
|
559
|
+
}[];
|
|
560
|
+
}[];
|
|
561
|
+
}
|
|
562
|
+
interface WhatsappInteractiveCtaUrl {
|
|
563
|
+
kind: "cta_url";
|
|
564
|
+
body: string;
|
|
565
|
+
header?: string;
|
|
566
|
+
footer?: string;
|
|
567
|
+
buttonText: string;
|
|
568
|
+
url: string;
|
|
569
|
+
}
|
|
570
|
+
interface WhatsappInteractiveLocationRequest {
|
|
571
|
+
kind: "location_request";
|
|
572
|
+
body: string;
|
|
573
|
+
}
|
|
574
|
+
type WhatsappInteractive = WhatsappInteractiveButtons | WhatsappInteractiveList | WhatsappInteractiveCtaUrl | WhatsappInteractiveLocationRequest;
|
|
575
|
+
type WhatsappMessage = {
|
|
576
|
+
type: "text";
|
|
577
|
+
body: string;
|
|
578
|
+
previewUrl?: boolean;
|
|
579
|
+
} | ({
|
|
580
|
+
type: "image";
|
|
581
|
+
caption?: string;
|
|
582
|
+
} & WhatsappMediaRef) | ({
|
|
583
|
+
type: "video";
|
|
584
|
+
caption?: string;
|
|
585
|
+
} & WhatsappMediaRef) | ({
|
|
586
|
+
type: "audio";
|
|
587
|
+
} & WhatsappMediaRef) | ({
|
|
588
|
+
type: "document";
|
|
589
|
+
caption?: string;
|
|
590
|
+
filename?: string;
|
|
591
|
+
} & WhatsappMediaRef) | ({
|
|
592
|
+
type: "sticker";
|
|
593
|
+
} & WhatsappMediaRef) | {
|
|
594
|
+
type: "location";
|
|
595
|
+
latitude: number;
|
|
596
|
+
longitude: number;
|
|
597
|
+
name?: string;
|
|
598
|
+
address?: string;
|
|
599
|
+
} | {
|
|
600
|
+
type: "contacts";
|
|
601
|
+
contacts: WhatsappContactCard[];
|
|
602
|
+
} | {
|
|
603
|
+
type: "reaction";
|
|
604
|
+
messageId: string;
|
|
605
|
+
emoji: string;
|
|
606
|
+
} | {
|
|
607
|
+
type: "interactive";
|
|
608
|
+
interactive: WhatsappInteractive;
|
|
609
|
+
};
|
|
610
|
+
interface SendWhatsappMessageInput {
|
|
611
|
+
to: string;
|
|
612
|
+
message: WhatsappMessage;
|
|
613
|
+
/** Meta phone_number_id. Padrão: primeiro número ativo da org. */
|
|
614
|
+
phoneNumberId?: string;
|
|
615
|
+
/** `messageId` de uma mensagem para responder citando. */
|
|
616
|
+
replyTo?: string;
|
|
617
|
+
}
|
|
618
|
+
interface SendWhatsappMessageResult {
|
|
619
|
+
messageId: string;
|
|
620
|
+
phoneNumberId: string;
|
|
621
|
+
}
|
|
622
|
+
interface UploadWhatsappMediaInput {
|
|
623
|
+
/** Conteúdo do arquivo em base64. */
|
|
624
|
+
data: string;
|
|
625
|
+
mimeType: string;
|
|
626
|
+
filename?: string;
|
|
627
|
+
phoneNumberId?: string;
|
|
628
|
+
}
|
|
629
|
+
interface UploadWhatsappMediaResult {
|
|
630
|
+
id: string;
|
|
631
|
+
phoneNumberId: string;
|
|
632
|
+
}
|
|
633
|
+
interface WhatsappMediaInfo {
|
|
634
|
+
id: string;
|
|
635
|
+
mimeType: string;
|
|
636
|
+
fileSize: number | null;
|
|
637
|
+
sha256: string | null;
|
|
638
|
+
}
|
|
639
|
+
interface WhatsappMediaDownload {
|
|
640
|
+
id: string;
|
|
641
|
+
mimeType: string;
|
|
642
|
+
fileSize: number;
|
|
643
|
+
/** Conteúdo em base64. */
|
|
644
|
+
data: string;
|
|
645
|
+
}
|
|
494
646
|
|
|
495
647
|
declare class DomainsResource {
|
|
496
648
|
private readonly http;
|
|
@@ -622,6 +774,44 @@ declare class WhatsappCallsResource {
|
|
|
622
774
|
getPermission(to: string, phoneNumberId?: string, opts?: RequestOptions): Promise<CallPermissionStatus>;
|
|
623
775
|
}
|
|
624
776
|
|
|
777
|
+
type Target = {
|
|
778
|
+
to: string;
|
|
779
|
+
phoneNumberId?: string;
|
|
780
|
+
replyTo?: string;
|
|
781
|
+
};
|
|
782
|
+
declare class WhatsappMessagesResource {
|
|
783
|
+
private readonly http;
|
|
784
|
+
constructor(http: HttpClient);
|
|
785
|
+
/** Envio genérico de qualquer tipo de mensagem. */
|
|
786
|
+
send(input: SendWhatsappMessageInput, opts?: RequestOptions): Promise<SendWhatsappMessageResult>;
|
|
787
|
+
sendText(target: Target, body: string, previewUrl?: boolean, opts?: RequestOptions): Promise<SendWhatsappMessageResult>;
|
|
788
|
+
sendImage(target: Target, media: WhatsappMediaRef, caption?: string, opts?: RequestOptions): Promise<SendWhatsappMessageResult>;
|
|
789
|
+
sendVideo(target: Target, media: WhatsappMediaRef, caption?: string, opts?: RequestOptions): Promise<SendWhatsappMessageResult>;
|
|
790
|
+
sendAudio(target: Target, media: WhatsappMediaRef, opts?: RequestOptions): Promise<SendWhatsappMessageResult>;
|
|
791
|
+
sendDocument(target: Target, media: WhatsappMediaRef, extra?: {
|
|
792
|
+
caption?: string;
|
|
793
|
+
filename?: string;
|
|
794
|
+
}, opts?: RequestOptions): Promise<SendWhatsappMessageResult>;
|
|
795
|
+
sendSticker(target: Target, media: WhatsappMediaRef, opts?: RequestOptions): Promise<SendWhatsappMessageResult>;
|
|
796
|
+
sendLocation(target: Target, location: {
|
|
797
|
+
latitude: number;
|
|
798
|
+
longitude: number;
|
|
799
|
+
name?: string;
|
|
800
|
+
address?: string;
|
|
801
|
+
}, opts?: RequestOptions): Promise<SendWhatsappMessageResult>;
|
|
802
|
+
sendContacts(target: Target, contacts: WhatsappContactCard[], opts?: RequestOptions): Promise<SendWhatsappMessageResult>;
|
|
803
|
+
/** Reage a uma mensagem. Emoji vazio remove a reação. */
|
|
804
|
+
sendReaction(target: Target, messageId: string, emoji: string, opts?: RequestOptions): Promise<SendWhatsappMessageResult>;
|
|
805
|
+
/** Botões de resposta rápida, lista, botão com link ou pedido de localização. */
|
|
806
|
+
sendInteractive(target: Target, interactive: WhatsappInteractive, opts?: RequestOptions): Promise<SendWhatsappMessageResult>;
|
|
807
|
+
/** Sobe um arquivo (base64) e devolve o `id` para usar em `sendImage`, `sendVideo` etc. */
|
|
808
|
+
uploadMedia(input: UploadWhatsappMediaInput, opts?: RequestOptions): Promise<UploadWhatsappMediaResult>;
|
|
809
|
+
/** Metadados de uma mídia (id recebido em `message_received`). */
|
|
810
|
+
getMedia(mediaId: string, phoneNumberId?: string, opts?: RequestOptions): Promise<WhatsappMediaInfo>;
|
|
811
|
+
/** Baixa uma mídia recebida (conteúdo em base64). */
|
|
812
|
+
downloadMedia(mediaId: string, phoneNumberId?: string, opts?: RequestOptions): Promise<WhatsappMediaDownload>;
|
|
813
|
+
}
|
|
814
|
+
|
|
625
815
|
declare class WhatsappNumbersResource {
|
|
626
816
|
private readonly http;
|
|
627
817
|
constructor(http: HttpClient);
|
|
@@ -660,6 +850,7 @@ declare class PostClient {
|
|
|
660
850
|
readonly whatsappTemplates: WhatsappTemplatesResource;
|
|
661
851
|
readonly whatsappNumbers: WhatsappNumbersResource;
|
|
662
852
|
readonly calls: WhatsappCallsResource;
|
|
853
|
+
readonly whatsappMessages: WhatsappMessagesResource;
|
|
663
854
|
readonly domains: DomainsResource;
|
|
664
855
|
readonly webhooks: WebhooksResource;
|
|
665
856
|
readonly smtp: SmtpResource;
|
|
@@ -703,4 +894,4 @@ declare function verifyWebhookSignature(rawBody: string, signatureHeader: string
|
|
|
703
894
|
/** Verifies the signature and parses the payload; throws if invalid. */
|
|
704
895
|
declare function constructWebhookEvent(rawBody: string, signatureHeader: string | null | undefined, secret: string): PostWebhookPayload;
|
|
705
896
|
|
|
706
|
-
export { type AreaCode, type AvailablePlan, type CallActionResult, type CallAnswerInput, type CallConnectWebhookData, type CallPermissionStatus, type CallStatusWebhookData, type CallTargetInput, type CallTerminateWebhookData, type CallingSettings, type CallingStatus, type ConnectCallInput, type ConnectCallResult, type ConnectWabaInput, type ConnectWhatsappNumberInput, type CreateDomainInput, type CreateDomainResult, type CreateTemplateInput, type CreateWebhookInput, type CreateWhatsappTemplateInput, type DnsRecord, type DomainStatus, type DomainType, DomainsResource, GeekappsPost, type GeekappsPostOptions, HistoryResource, type HttpClientOptions, type ListHistoryParams, type ManagedNumber, type ManagedNumberStatus, ManagedNumbersResource, type MessageLog, type MessageLogDetail, type MessagePresenceInput, type MessagePresenceResult, type MessageReceivedWebhookData, type MessageStatus, type MessageTemplate, type MessageType, MessagesResource, type OrgDomain, type OrgPlan, type OrgUsage, type OrgWaba, type OrgWebhook, type OrgWebhookWithSecret, type PaginatedResult, type PhoneNumberStatusResult, type PlanTier, PlansResource, type PlansResult, PostApiError, PostClient, type PostWebhookPayload, type RegisterWhatsappNumberInput, type RequestCallPermissionInput, type RequestCallPermissionResult, type RotateSecretResult, type SaveDraftInput, type SendMessageInput, type SendMessageResult, type SmtpConfig, SmtpResource, type StatisticsParams, StatisticsResource, type StatisticsResult, type SyncWhatsappTemplatesResult, type TemplateVariable, type TemplateVariables, TemplatesResource, type TokenResolver, type UpdateCallingSettingsInput, type UpdatePlanInput, type UpdateTemplateInput, type UpdateWebhookInput, type UpdateWhatsappProfileInput, type UpdateWhatsappTemplateInput, type UpsertSmtpConfigInput, type WabaStatus, type WebhookDelivery, type WebhookEvent, type WebhookSdpSession, WebhooksResource, WhatsappCallsResource, type WhatsappNumber, type WhatsappNumberProfile, type WhatsappNumberStatus, WhatsappNumbersResource, type WhatsappTemplate, type WhatsappTemplateCategory, type WhatsappTemplateStatus, WhatsappTemplatesResource, constructWebhookEvent, verifyWebhookSignature };
|
|
897
|
+
export { type AreaCode, type AvailablePlan, type CallActionResult, type CallAnswerInput, type CallConnectWebhookData, type CallPermissionStatus, type CallStatusWebhookData, type CallTargetInput, type CallTerminateWebhookData, type CallingSettings, type CallingStatus, type ConnectCallInput, type ConnectCallResult, type ConnectWabaInput, type ConnectWhatsappNumberInput, type CreateDomainInput, type CreateDomainResult, type CreateTemplateInput, type CreateWebhookInput, type CreateWhatsappTemplateInput, type DnsRecord, type DomainStatus, type DomainType, DomainsResource, type EmailAttachment, GeekappsPost, type GeekappsPostOptions, HistoryResource, type HttpClientOptions, type ListHistoryParams, type ManagedNumber, type ManagedNumberStatus, ManagedNumbersResource, type MessageLog, type MessageLogDetail, type MessagePresenceInput, type MessagePresenceResult, type MessageReceivedWebhookData, type MessageStatus, type MessageTemplate, type MessageType, MessagesResource, type OrgDomain, type OrgPlan, type OrgUsage, type OrgWaba, type OrgWebhook, type OrgWebhookWithSecret, type PaginatedResult, type PhoneNumberStatusResult, type PlanTier, PlansResource, type PlansResult, PostApiError, PostClient, type PostWebhookPayload, type RegisterWhatsappNumberInput, type RequestCallPermissionInput, type RequestCallPermissionResult, type RotateSecretResult, type SaveDraftInput, type SendMessageInput, type SendMessageResult, type SendWhatsappMessageInput, type SendWhatsappMessageResult, type SmtpConfig, SmtpResource, type StatisticsParams, StatisticsResource, type StatisticsResult, type SyncWhatsappTemplatesResult, type TemplateVariable, type TemplateVariables, TemplatesResource, type TokenResolver, type UpdateCallingSettingsInput, type UpdatePlanInput, type UpdateTemplateInput, type UpdateWebhookInput, type UpdateWhatsappProfileInput, type UpdateWhatsappTemplateInput, type UploadWhatsappMediaInput, type UploadWhatsappMediaResult, type UpsertSmtpConfigInput, type WabaStatus, type WebhookDelivery, type WebhookEvent, type WebhookSdpSession, WebhooksResource, WhatsappCallsResource, type WhatsappContactCard, type WhatsappInteractive, type WhatsappInteractiveButtons, type WhatsappInteractiveCtaUrl, type WhatsappInteractiveList, type WhatsappInteractiveLocationRequest, type WhatsappMediaDownload, type WhatsappMediaInfo, type WhatsappMediaRef, type WhatsappMessage, WhatsappMessagesResource, type WhatsappNumber, type WhatsappNumberProfile, type WhatsappNumberStatus, WhatsappNumbersResource, type WhatsappTemplate, type WhatsappTemplateCategory, type WhatsappTemplateStatus, WhatsappTemplatesResource, constructWebhookEvent, verifyWebhookSignature };
|
package/dist/index.js
CHANGED
|
@@ -313,6 +313,61 @@ var WhatsappCallsResource = class {
|
|
|
313
313
|
}
|
|
314
314
|
};
|
|
315
315
|
|
|
316
|
+
// src/resources/whatsapp-messages.ts
|
|
317
|
+
var WhatsappMessagesResource = class {
|
|
318
|
+
constructor(http) {
|
|
319
|
+
this.http = http;
|
|
320
|
+
}
|
|
321
|
+
/** Envio genérico de qualquer tipo de mensagem. */
|
|
322
|
+
send(input, opts) {
|
|
323
|
+
return this.http.post("/whatsapp/messages/send", input, opts);
|
|
324
|
+
}
|
|
325
|
+
sendText(target, body, previewUrl, opts) {
|
|
326
|
+
return this.send({ ...target, message: { type: "text", body, previewUrl } }, opts);
|
|
327
|
+
}
|
|
328
|
+
sendImage(target, media, caption, opts) {
|
|
329
|
+
return this.send({ ...target, message: { type: "image", ...media, caption } }, opts);
|
|
330
|
+
}
|
|
331
|
+
sendVideo(target, media, caption, opts) {
|
|
332
|
+
return this.send({ ...target, message: { type: "video", ...media, caption } }, opts);
|
|
333
|
+
}
|
|
334
|
+
sendAudio(target, media, opts) {
|
|
335
|
+
return this.send({ ...target, message: { type: "audio", ...media } }, opts);
|
|
336
|
+
}
|
|
337
|
+
sendDocument(target, media, extra, opts) {
|
|
338
|
+
return this.send({ ...target, message: { type: "document", ...media, ...extra } }, opts);
|
|
339
|
+
}
|
|
340
|
+
sendSticker(target, media, opts) {
|
|
341
|
+
return this.send({ ...target, message: { type: "sticker", ...media } }, opts);
|
|
342
|
+
}
|
|
343
|
+
sendLocation(target, location, opts) {
|
|
344
|
+
return this.send({ ...target, message: { type: "location", ...location } }, opts);
|
|
345
|
+
}
|
|
346
|
+
sendContacts(target, contacts, opts) {
|
|
347
|
+
return this.send({ ...target, message: { type: "contacts", contacts } }, opts);
|
|
348
|
+
}
|
|
349
|
+
/** Reage a uma mensagem. Emoji vazio remove a reação. */
|
|
350
|
+
sendReaction(target, messageId, emoji, opts) {
|
|
351
|
+
return this.send({ ...target, message: { type: "reaction", messageId, emoji } }, opts);
|
|
352
|
+
}
|
|
353
|
+
/** Botões de resposta rápida, lista, botão com link ou pedido de localização. */
|
|
354
|
+
sendInteractive(target, interactive, opts) {
|
|
355
|
+
return this.send({ ...target, message: { type: "interactive", interactive } }, opts);
|
|
356
|
+
}
|
|
357
|
+
/** Sobe um arquivo (base64) e devolve o `id` para usar em `sendImage`, `sendVideo` etc. */
|
|
358
|
+
uploadMedia(input, opts) {
|
|
359
|
+
return this.http.post("/whatsapp/media", input, opts);
|
|
360
|
+
}
|
|
361
|
+
/** Metadados de uma mídia (id recebido em `message_received`). */
|
|
362
|
+
getMedia(mediaId, phoneNumberId, opts) {
|
|
363
|
+
return this.http.get(`/whatsapp/media/${mediaId}${phoneNumberId ? `?phoneNumberId=${encodeURIComponent(phoneNumberId)}` : ""}`, opts);
|
|
364
|
+
}
|
|
365
|
+
/** Baixa uma mídia recebida (conteúdo em base64). */
|
|
366
|
+
downloadMedia(mediaId, phoneNumberId, opts) {
|
|
367
|
+
return this.http.get(`/whatsapp/media/${mediaId}/download${phoneNumberId ? `?phoneNumberId=${encodeURIComponent(phoneNumberId)}` : ""}`, opts);
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
|
|
316
371
|
// src/resources/whatsapp-numbers.ts
|
|
317
372
|
var WhatsappNumbersResource = class {
|
|
318
373
|
constructor(http) {
|
|
@@ -399,6 +454,7 @@ var PostClient = class {
|
|
|
399
454
|
this.whatsappTemplates = new WhatsappTemplatesResource(this.http);
|
|
400
455
|
this.whatsappNumbers = new WhatsappNumbersResource(this.http);
|
|
401
456
|
this.calls = new WhatsappCallsResource(this.http);
|
|
457
|
+
this.whatsappMessages = new WhatsappMessagesResource(this.http);
|
|
402
458
|
this.domains = new DomainsResource(this.http);
|
|
403
459
|
this.webhooks = new WebhooksResource(this.http);
|
|
404
460
|
this.smtp = new SmtpResource(this.http);
|
|
@@ -509,6 +565,7 @@ export {
|
|
|
509
565
|
TemplatesResource,
|
|
510
566
|
WebhooksResource,
|
|
511
567
|
WhatsappCallsResource,
|
|
568
|
+
WhatsappMessagesResource,
|
|
512
569
|
WhatsappNumbersResource,
|
|
513
570
|
WhatsappTemplatesResource,
|
|
514
571
|
constructWebhookEvent,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/http.ts","../src/resources/domains.ts","../src/resources/history.ts","../src/resources/managed-numbers.ts","../src/resources/messages.ts","../src/resources/plans.ts","../src/resources/smtp.ts","../src/resources/statistics.ts","../src/resources/templates.ts","../src/resources/webhooks.ts","../src/resources/whatsapp-calls.ts","../src/resources/whatsapp-numbers.ts","../src/resources/whatsapp-templates.ts","../src/client.ts","../src/geekapps-post.ts","../src/webhook.ts"],"sourcesContent":["export class PostApiError extends Error {\n constructor(\n public readonly status: number,\n message: string,\n public readonly detail?: string,\n ) {\n super(detail ? `${message}: ${detail}` : message);\n this.name = \"PostApiError\";\n }\n\n get isNotFound() { return this.status === 404; }\n get isUnauthorized() { return this.status === 401; }\n get isForbidden() { return this.status === 403; }\n get isRateLimited() { return this.status === 429; }\n get isValidationError() { return this.status === 400; }\n}\n","import { PostApiError } from \"./errors.js\";\n\nexport type TokenResolver = string | (() => string | Promise<string>);\n\nexport interface HttpClientOptions {\n baseUrl: string;\n token?: TokenResolver;\n organizationId?: string | (() => string | Promise<string>);\n}\n\nexport interface RequestOptions {\n token?: string;\n organizationId?: string;\n}\n\nexport class HttpClient {\n private readonly baseUrl: string;\n private readonly token?: TokenResolver;\n private readonly organizationId?: string | (() => string | Promise<string>);\n\n constructor(options: HttpClientOptions) {\n this.baseUrl = options.baseUrl.replace(/\\/$/, \"\");\n this.token = options.token;\n this.organizationId = options.organizationId;\n }\n\n private async resolveToken(override?: string): Promise<string> {\n if (override) return override;\n if (!this.token) throw new Error(\"@geekapps/post-nextjs: no token provided\");\n return typeof this.token === \"function\" ? await this.token() : this.token;\n }\n\n private async resolveOrgId(override?: string): Promise<string | undefined> {\n if (override) return override;\n if (!this.organizationId) return undefined;\n return typeof this.organizationId === \"function\"\n ? await this.organizationId()\n : this.organizationId;\n }\n\n async request<T = unknown>(\n method: string,\n path: string,\n body?: unknown,\n opts?: RequestOptions,\n ): Promise<T> {\n const token = await this.resolveToken(opts?.token);\n const orgId = await this.resolveOrgId(opts?.organizationId);\n\n const res = await fetch(`${this.baseUrl}/v1${path}`, {\n method,\n headers: {\n Authorization: `Bearer ${token}`,\n ...(body !== undefined ? { \"Content-Type\": \"application/json\" } : {}),\n ...(orgId ? { \"X-Organization-Id\": orgId } : {}),\n },\n ...(body !== undefined ? { body: JSON.stringify(body) } : {}),\n cache: \"no-store\" as RequestCache,\n });\n\n if (!res.ok) {\n const err = await res.json().catch(() => ({})) as { error?: string; detail?: string };\n throw new PostApiError(res.status, err.error ?? `HTTP ${res.status}`, err.detail);\n }\n\n if (res.status === 204) return undefined as T;\n return res.json() as Promise<T>;\n }\n\n get<T>(path: string, opts?: RequestOptions) { return this.request<T>(\"GET\", path, undefined, opts); }\n post<T>(path: string, body?: unknown, opts?: RequestOptions) { return this.request<T>(\"POST\", path, body, opts); }\n put<T>(path: string, body?: unknown, opts?: RequestOptions) { return this.request<T>(\"PUT\", path, body, opts); }\n patch<T>(path: string, body?: unknown, opts?: RequestOptions) { return this.request<T>(\"PATCH\", path, body, opts); }\n delete<T = void>(path: string, opts?: RequestOptions) { return this.request<T>(\"DELETE\", path, undefined, opts); }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type { CreateDomainInput, CreateDomainResult, OrgDomain } from \"../types.js\";\n\nexport class DomainsResource {\n constructor(private readonly http: HttpClient) {}\n\n list(opts?: RequestOptions): Promise<OrgDomain[]> {\n return this.http.get<OrgDomain[]>(\"/domains\", opts);\n }\n\n get(id: string, opts?: RequestOptions): Promise<OrgDomain> {\n return this.http.get<OrgDomain>(`/domains/${id}`, opts);\n }\n\n create(input: CreateDomainInput, opts?: RequestOptions): Promise<CreateDomainResult> {\n return this.http.post<CreateDomainResult>(\"/domains\", input, opts);\n }\n\n verify(id: string, opts?: RequestOptions): Promise<{ status: \"verified\" | \"failed\" }> {\n return this.http.post<{ status: \"verified\" | \"failed\" }>(`/domains/${id}/verify`, undefined, opts);\n }\n\n delete(id: string, opts?: RequestOptions): Promise<void> {\n return this.http.delete(`/domains/${id}`, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type { ListHistoryParams, MessageLog, MessageLogDetail, PaginatedResult } from \"../types.js\";\n\nexport class HistoryResource {\n constructor(private readonly http: HttpClient) {}\n\n list(params?: ListHistoryParams, opts?: RequestOptions): Promise<PaginatedResult<MessageLog>> {\n const qs = new URLSearchParams();\n if (params?.type) qs.set(\"type\", params.type);\n if (params?.status) qs.set(\"status\", params.status);\n if (params?.from) qs.set(\"from\", params.from);\n if (params?.to) qs.set(\"to\", params.to);\n if (params?.page !== undefined) qs.set(\"page\", String(params.page));\n if (params?.limit !== undefined) qs.set(\"limit\", String(params.limit));\n const query = qs.toString();\n return this.http.get<PaginatedResult<MessageLog>>(`/history${query ? `?${query}` : \"\"}`, opts);\n }\n\n get(id: string, opts?: RequestOptions): Promise<MessageLogDetail> {\n return this.http.get<MessageLogDetail>(`/history/${id}`, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type { AreaCode, ManagedNumber } from \"../types.js\";\n\nexport interface ProvisionManagedNumberInput {\n areaCode: number;\n name?: string;\n displayName: string;\n otpMethod?: \"SMS\" | \"VOICE\";\n otpLanguage?: string;\n pin?: string;\n orgWabaId?: string;\n wabaId?: string;\n accessToken?: string;\n}\n\nexport interface RetryVerificationInput {\n otpMethod?: \"SMS\" | \"VOICE\";\n otpLanguage?: string;\n}\n\nexport class ManagedNumbersResource {\n constructor(private readonly http: HttpClient) {}\n\n listAreaCodes(opts?: RequestOptions): Promise<AreaCode[]> {\n return this.http.get<AreaCode[]>(\"/managed-numbers/area-codes\", opts);\n }\n\n list(opts?: RequestOptions): Promise<ManagedNumber[]> {\n return this.http.get<ManagedNumber[]>(\"/managed-numbers\", opts);\n }\n\n get(id: string, opts?: RequestOptions): Promise<ManagedNumber> {\n return this.http.get<ManagedNumber>(`/managed-numbers/${id}`, opts);\n }\n\n provision(input: ProvisionManagedNumberInput, opts?: RequestOptions): Promise<ManagedNumber> {\n return this.http.post<ManagedNumber>(\"/managed-numbers\", input, opts);\n }\n\n retryVerification(id: string, input?: RetryVerificationInput, opts?: RequestOptions): Promise<ManagedNumber> {\n return this.http.post<ManagedNumber>(`/managed-numbers/${id}/retry-verification`, input, opts);\n }\n\n cancel(id: string, opts?: RequestOptions): Promise<ManagedNumber> {\n return this.http.post<ManagedNumber>(`/managed-numbers/${id}/cancel`, undefined, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type { MessagePresenceInput, MessagePresenceResult, SendMessageInput, SendMessageResult } from \"../types.js\";\n\nexport class MessagesResource {\n constructor(private readonly http: HttpClient) {}\n\n send(input: SendMessageInput, opts?: RequestOptions): Promise<SendMessageResult> {\n return this.http.post<SendMessageResult>(\"/messages\", input, opts);\n }\n\n /** Marca uma mensagem recebida como lida (tique azul). */\n markAsRead(input: MessagePresenceInput, opts?: RequestOptions): Promise<MessagePresenceResult> {\n return this.http.post<MessagePresenceResult>(\"/whatsapp/messages/read\", input, opts);\n }\n\n /** Marca como lida e mostra \"digitando…\" até a resposta ser enviada (máx. ~25s). */\n sendTyping(input: MessagePresenceInput, opts?: RequestOptions): Promise<MessagePresenceResult> {\n return this.http.post<MessagePresenceResult>(\"/whatsapp/messages/typing\", input, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type { AvailablePlan, OrgPlan, PlansResult, UpdatePlanInput } from \"../types.js\";\n\nexport class PlansResource {\n constructor(private readonly http: HttpClient) {}\n\n get(opts?: RequestOptions): Promise<PlansResult> {\n return this.http.get<PlansResult>(\"/plans\", opts);\n }\n\n update(input: UpdatePlanInput, opts?: RequestOptions): Promise<OrgPlan> {\n return this.http.put<OrgPlan>(\"/plans\", input, opts);\n }\n\n listAvailable(opts?: RequestOptions): Promise<AvailablePlan[]> {\n return this.http.get<AvailablePlan[]>(\"/plans/available\", opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type { SmtpConfig, UpsertSmtpConfigInput } from \"../types.js\";\n\nexport class SmtpResource {\n constructor(private readonly http: HttpClient) {}\n\n get(opts?: RequestOptions): Promise<SmtpConfig> {\n return this.http.get<SmtpConfig>(\"/smtp-config\", opts);\n }\n\n upsert(input: UpsertSmtpConfigInput, opts?: RequestOptions): Promise<SmtpConfig> {\n return this.http.put<SmtpConfig>(\"/smtp-config\", input, opts);\n }\n\n delete(opts?: RequestOptions): Promise<void> {\n return this.http.delete(\"/smtp-config\", opts);\n }\n\n test(to: string, opts?: RequestOptions): Promise<{ success: boolean; error?: string }> {\n return this.http.post<{ success: boolean; error?: string }>(\"/smtp-config/test\", { to }, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type { StatisticsParams, StatisticsResult } from \"../types.js\";\n\nexport class StatisticsResource {\n constructor(private readonly http: HttpClient) {}\n\n get(params?: StatisticsParams, opts?: RequestOptions): Promise<StatisticsResult> {\n const qs = new URLSearchParams();\n if (params?.from) qs.set(\"from\", params.from);\n if (params?.to) qs.set(\"to\", params.to);\n if (params?.groupBy) qs.set(\"groupBy\", params.groupBy);\n const query = qs.toString();\n return this.http.get<StatisticsResult>(`/statistics${query ? `?${query}` : \"\"}`, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type {\n CreateTemplateInput,\n MessageTemplate,\n MessageType,\n SaveDraftInput,\n UpdateTemplateInput,\n} from \"../types.js\";\n\nexport class TemplatesResource {\n constructor(private readonly http: HttpClient) {}\n\n list(params?: { type?: MessageType; isActive?: boolean }, opts?: RequestOptions): Promise<MessageTemplate[]> {\n const qs = new URLSearchParams();\n if (params?.type) qs.set(\"type\", params.type);\n if (params?.isActive !== undefined) qs.set(\"isActive\", String(params.isActive));\n const query = qs.toString();\n return this.http.get<MessageTemplate[]>(`/templates${query ? `?${query}` : \"\"}`, opts);\n }\n\n get(id: string, opts?: RequestOptions): Promise<MessageTemplate> {\n return this.http.get<MessageTemplate>(`/templates/${id}`, opts);\n }\n\n create(input: CreateTemplateInput, opts?: RequestOptions): Promise<MessageTemplate> {\n return this.http.post<MessageTemplate>(\"/templates\", input, opts);\n }\n\n update(id: string, input: UpdateTemplateInput, opts?: RequestOptions): Promise<MessageTemplate> {\n return this.http.put<MessageTemplate>(`/templates/${id}`, input, opts);\n }\n\n saveDraft(id: string, input: SaveDraftInput, opts?: RequestOptions): Promise<MessageTemplate> {\n return this.http.patch<MessageTemplate>(`/templates/${id}/draft`, input, opts);\n }\n\n publish(id: string, opts?: RequestOptions): Promise<MessageTemplate> {\n return this.http.post<MessageTemplate>(`/templates/${id}/publish`, undefined, opts);\n }\n\n delete(id: string, opts?: RequestOptions): Promise<void> {\n return this.http.delete(`/templates/${id}`, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type {\n CreateWebhookInput,\n OrgWebhook,\n OrgWebhookWithSecret,\n RotateSecretResult,\n UpdateWebhookInput,\n WebhookDelivery,\n} from \"../types.js\";\n\nexport class WebhooksResource {\n constructor(private readonly http: HttpClient) {}\n\n list(opts?: RequestOptions): Promise<OrgWebhook[]> {\n return this.http.get<OrgWebhook[]>(\"/webhooks\", opts);\n }\n\n create(input: CreateWebhookInput, opts?: RequestOptions): Promise<OrgWebhookWithSecret> {\n return this.http.post<OrgWebhookWithSecret>(\"/webhooks\", input, opts);\n }\n\n update(id: string, input: UpdateWebhookInput, opts?: RequestOptions): Promise<OrgWebhook> {\n return this.http.put<OrgWebhook>(`/webhooks/${id}`, input, opts);\n }\n\n delete(id: string, opts?: RequestOptions): Promise<void> {\n return this.http.delete(`/webhooks/${id}`, opts);\n }\n\n listDeliveries(id: string, opts?: RequestOptions): Promise<WebhookDelivery[]> {\n return this.http.get<WebhookDelivery[]>(`/webhooks/${id}/deliveries`, opts);\n }\n\n rotateSecret(id: string, opts?: RequestOptions): Promise<RotateSecretResult> {\n return this.http.post<RotateSecretResult>(`/webhooks/${id}/rotate-secret`, undefined, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type {\n CallActionResult,\n CallAnswerInput,\n CallPermissionStatus,\n CallTargetInput,\n CallingSettings,\n ConnectCallInput,\n ConnectCallResult,\n RequestCallPermissionInput,\n RequestCallPermissionResult,\n UpdateCallingSettingsInput,\n} from \"../types.js\";\n\n// WhatsApp Cloud API Calling. Signaling only: media flows over WebRTC between\n// Meta and your server. Incoming calls arrive via the `call_connect` webhook.\nexport class WhatsappCallsResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Lê a configuração de chamadas de um número (id do WhatsappNumber no Post). */\n getSettings(numberId: string, opts?: RequestOptions): Promise<CallingSettings> {\n return this.http.get<CallingSettings>(`/whatsapp/numbers/${numberId}/calling`, opts);\n }\n\n /** Ativa/desativa chamadas no número. */\n updateSettings(numberId: string, input: UpdateCallingSettingsInput, opts?: RequestOptions): Promise<CallingSettings> {\n return this.http.put<CallingSettings>(`/whatsapp/numbers/${numberId}/calling`, input, opts);\n }\n\n /** Pré-aceita uma chamada recebida (opcional, acelera a conexão de mídia). */\n preAccept(callId: string, input: CallAnswerInput, opts?: RequestOptions): Promise<CallActionResult> {\n return this.http.post<CallActionResult>(`/whatsapp/calls/${callId}/pre-accept`, input, opts);\n }\n\n /** Aceita uma chamada recebida enviando o SDP de resposta. */\n accept(callId: string, input: CallAnswerInput, opts?: RequestOptions): Promise<CallActionResult> {\n return this.http.post<CallActionResult>(`/whatsapp/calls/${callId}/accept`, input, opts);\n }\n\n /** Rejeita uma chamada recebida. */\n reject(callId: string, input: CallTargetInput = {}, opts?: RequestOptions): Promise<CallActionResult> {\n return this.http.post<CallActionResult>(`/whatsapp/calls/${callId}/reject`, input, opts);\n }\n\n /** Encerra uma chamada em andamento. */\n terminate(callId: string, input: CallTargetInput = {}, opts?: RequestOptions): Promise<CallActionResult> {\n return this.http.post<CallActionResult>(`/whatsapp/calls/${callId}/terminate`, input, opts);\n }\n\n /** Inicia uma chamada (business-initiated). Exige permissão prévia do usuário. */\n connect(input: ConnectCallInput, opts?: RequestOptions): Promise<ConnectCallResult> {\n return this.http.post<ConnectCallResult>(\"/whatsapp/calls\", input, opts);\n }\n\n /** Envia ao usuário o pedido de permissão para receber chamadas. */\n requestPermission(input: RequestCallPermissionInput, opts?: RequestOptions): Promise<RequestCallPermissionResult> {\n return this.http.post<RequestCallPermissionResult>(\"/whatsapp/calls/permissions\", input, opts);\n }\n\n /** Consulta o status de permissão de chamada de um usuário. */\n getPermission(to: string, phoneNumberId?: string, opts?: RequestOptions): Promise<CallPermissionStatus> {\n return this.http.get<CallPermissionStatus>(`/whatsapp/calls/permissions?${new URLSearchParams({ to, ...(phoneNumberId ? { phoneNumberId } : {}) })}`, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type {\n ConnectWabaInput,\n ConnectWhatsappNumberInput,\n OrgWaba,\n PhoneNumberStatusResult,\n RegisterWhatsappNumberInput,\n UpdateWhatsappProfileInput,\n WabaHealthResult,\n WhatsappNumber,\n WhatsappNumberProfile,\n} from \"../types.js\";\n\nexport class WhatsappNumbersResource {\n constructor(private readonly http: HttpClient) {}\n\n listWabas(opts?: RequestOptions): Promise<OrgWaba[]> {\n return this.http.get<OrgWaba[]>(\"/whatsapp/wabas\", opts);\n }\n\n connectWaba(input: ConnectWabaInput, opts?: RequestOptions): Promise<OrgWaba> {\n return this.http.post<OrgWaba>(\"/whatsapp/wabas/connect\", input, opts);\n }\n\n reconnectWaba(id: string, opts?: RequestOptions): Promise<OrgWaba> {\n return this.http.post<OrgWaba>(`/whatsapp/wabas/${id}/reconnect`, undefined, opts);\n }\n\n disconnectWaba(id: string, opts?: RequestOptions): Promise<void> {\n return this.http.delete(`/whatsapp/wabas/${id}`, opts);\n }\n\n getWabaHealth(id: string, opts?: RequestOptions): Promise<WabaHealthResult> {\n return this.http.get<WabaHealthResult>(`/whatsapp/wabas/${id}/health`, opts);\n }\n\n listNumbers(opts?: RequestOptions): Promise<WhatsappNumber[]> {\n return this.http.get<WhatsappNumber[]>(\"/whatsapp/numbers\", opts);\n }\n\n connectNumber(input: ConnectWhatsappNumberInput, opts?: RequestOptions): Promise<WhatsappNumber> {\n return this.http.post<WhatsappNumber>(\"/whatsapp/numbers/connect\", input, opts);\n }\n\n registerNumber(input: RegisterWhatsappNumberInput, opts?: RequestOptions): Promise<WhatsappNumber> {\n return this.http.post<WhatsappNumber>(\"/whatsapp/numbers\", input, opts);\n }\n\n verifyCode(id: string, code: string, opts?: RequestOptions): Promise<WhatsappNumber> {\n return this.http.post<WhatsappNumber>(`/whatsapp/numbers/${id}/verify-code`, { code }, opts);\n }\n\n resendCode(id: string, opts?: RequestOptions): Promise<void> {\n return this.http.post(`/whatsapp/numbers/${id}/resend-code`, undefined, opts);\n }\n\n getProfile(id: string, opts?: RequestOptions): Promise<WhatsappNumberProfile> {\n return this.http.get<WhatsappNumberProfile>(`/whatsapp/numbers/${id}/profile`, opts);\n }\n\n updateProfile(id: string, input: UpdateWhatsappProfileInput, opts?: RequestOptions): Promise<WhatsappNumberProfile> {\n return this.http.patch<WhatsappNumberProfile>(`/whatsapp/numbers/${id}/profile`, input, opts);\n }\n\n updateDisplayName(id: string, displayName: string, opts?: RequestOptions): Promise<WhatsappNumber> {\n return this.http.patch<WhatsappNumber>(`/whatsapp/numbers/${id}`, { displayName }, opts);\n }\n\n getStatus(id: string, opts?: RequestOptions): Promise<PhoneNumberStatusResult> {\n return this.http.get<PhoneNumberStatusResult>(`/whatsapp/numbers/${id}/status`, opts);\n }\n\n refreshNumbers(opts?: RequestOptions): Promise<WhatsappNumber[]> {\n return this.http.post<WhatsappNumber[]>(\"/whatsapp/numbers/refresh\", undefined, opts);\n }\n\n deleteNumber(id: string, opts?: RequestOptions): Promise<void> {\n return this.http.delete(`/whatsapp/numbers/${id}`, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type {\n CreateWhatsappTemplateInput,\n SyncWhatsappTemplatesResult,\n UpdateWhatsappTemplateInput,\n WhatsappTemplate,\n} from \"../types.js\";\n\nexport class WhatsappTemplatesResource {\n constructor(private readonly http: HttpClient) {}\n\n list(opts?: RequestOptions): Promise<WhatsappTemplate[]> {\n return this.http.get<WhatsappTemplate[]>(\"/whatsapp/templates\", opts);\n }\n\n create(input: CreateWhatsappTemplateInput, opts?: RequestOptions): Promise<WhatsappTemplate> {\n return this.http.post<WhatsappTemplate>(\"/whatsapp/templates\", input, opts);\n }\n\n update(id: string, input: UpdateWhatsappTemplateInput, opts?: RequestOptions): Promise<WhatsappTemplate> {\n return this.http.put<WhatsappTemplate>(`/whatsapp/templates/${id}`, input, opts);\n }\n\n sync(opts?: RequestOptions): Promise<SyncWhatsappTemplatesResult> {\n return this.http.post<SyncWhatsappTemplatesResult>(\"/whatsapp/templates/sync\", undefined, opts);\n }\n\n delete(id: string, opts?: RequestOptions): Promise<void> {\n return this.http.delete(`/whatsapp/templates/${id}`, opts);\n }\n}\n","import { HttpClient, type HttpClientOptions } from \"./http.js\";\nimport { DomainsResource } from \"./resources/domains.js\";\nimport { HistoryResource } from \"./resources/history.js\";\nimport { ManagedNumbersResource } from \"./resources/managed-numbers.js\";\nimport { MessagesResource } from \"./resources/messages.js\";\nimport { PlansResource } from \"./resources/plans.js\";\nimport { SmtpResource } from \"./resources/smtp.js\";\nimport { StatisticsResource } from \"./resources/statistics.js\";\nimport { TemplatesResource } from \"./resources/templates.js\";\nimport { WebhooksResource } from \"./resources/webhooks.js\";\nimport { WhatsappCallsResource } from \"./resources/whatsapp-calls.js\";\nimport { WhatsappNumbersResource } from \"./resources/whatsapp-numbers.js\";\nimport { WhatsappTemplatesResource } from \"./resources/whatsapp-templates.js\";\n\nexport interface PostClientOptions extends Omit<HttpClientOptions, \"baseUrl\"> {\n baseUrl?: string;\n}\n\nexport class PostClient {\n private readonly http: HttpClient;\n\n readonly messages: MessagesResource;\n readonly templates: TemplatesResource;\n readonly whatsappTemplates: WhatsappTemplatesResource;\n readonly whatsappNumbers: WhatsappNumbersResource;\n readonly calls: WhatsappCallsResource;\n readonly domains: DomainsResource;\n readonly webhooks: WebhooksResource;\n readonly smtp: SmtpResource;\n readonly plans: PlansResource;\n readonly history: HistoryResource;\n readonly statistics: StatisticsResource;\n readonly managedNumbers: ManagedNumbersResource;\n\n constructor(optionsOrHttp: HttpClientOptions | HttpClient) {\n this.http = optionsOrHttp instanceof HttpClient ? optionsOrHttp : new HttpClient(optionsOrHttp);\n\n this.messages = new MessagesResource(this.http);\n this.templates = new TemplatesResource(this.http);\n this.whatsappTemplates = new WhatsappTemplatesResource(this.http);\n this.whatsappNumbers = new WhatsappNumbersResource(this.http);\n this.calls = new WhatsappCallsResource(this.http);\n this.domains = new DomainsResource(this.http);\n this.webhooks = new WebhooksResource(this.http);\n this.smtp = new SmtpResource(this.http);\n this.plans = new PlansResource(this.http);\n this.history = new HistoryResource(this.http);\n this.statistics = new StatisticsResource(this.http);\n this.managedNumbers = new ManagedNumbersResource(this.http);\n }\n}\n","import { PostClient } from \"./client.js\";\n\nexport interface ServiceAccountOptions {\n issuerUrl: string;\n clientId: string;\n clientSecret: string;\n}\n\nexport interface GeekappsPostOptions {\n serviceAccount: ServiceAccountOptions;\n baseUrl?: string;\n logLevel?: \"trace\" | \"debug\" | \"info\" | \"warn\" | \"error\" | \"silent\";\n}\n\ninterface CachedToken {\n value: string;\n expiresAt: number;\n organizationId: string | undefined;\n}\n\nfunction decodeJwtPayload(token: string): Record<string, unknown> {\n try {\n const [, payload] = token.split(\".\");\n if (!payload) return {};\n const json = atob(payload.replace(/-/g, \"+\").replace(/_/g, \"/\"));\n return JSON.parse(json) as Record<string, unknown>;\n } catch {\n return {};\n }\n}\n\nclass TokenProvider {\n private readonly issuerUrl: string;\n private readonly clientId: string;\n private readonly clientSecret: string;\n private cached: CachedToken | null = null;\n private inflight: Promise<CachedToken> | null = null;\n\n constructor(options: GeekappsPostOptions) {\n this.issuerUrl = options.serviceAccount.issuerUrl.replace(/\\/$/, \"\");\n this.clientId = options.serviceAccount.clientId;\n this.clientSecret = options.serviceAccount.clientSecret;\n }\n\n private async ensureFresh(): Promise<CachedToken> {\n const now = Date.now();\n if (this.cached && this.cached.expiresAt - now > 30_000) return this.cached;\n if (this.inflight) return this.inflight;\n this.inflight = this.fetchToken().finally(() => { this.inflight = null; });\n return this.inflight;\n }\n\n getToken(): Promise<string> {\n return this.ensureFresh().then((c) => c.value);\n }\n\n getOrganizationId(): Promise<string | undefined> {\n return this.ensureFresh().then((c) => c.organizationId);\n }\n\n private async fetchToken(): Promise<CachedToken> {\n const credentials = btoa(`${this.clientId}:${this.clientSecret}`);\n const res = await fetch(`${this.issuerUrl}/auth/token`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Basic ${credentials}`,\n },\n body: JSON.stringify({ grant_type: \"service_account\" }),\n cache: \"no-store\" as RequestCache,\n });\n\n if (!res.ok) {\n const err = await res.json().catch(() => ({})) as { error?: string };\n throw new Error(`GeekappsPost auth failed (${res.status}): ${err.error ?? \"unknown error\"}`);\n }\n\n const data = await res.json() as { access_token: string; expires_in?: number };\n const claims = decodeJwtPayload(data.access_token);\n const organizationId =\n typeof claims.organizationId === \"string\" ? claims.organizationId :\n typeof claims.organization_id === \"string\" ? claims.organization_id :\n undefined;\n\n this.cached = {\n value: data.access_token,\n expiresAt: Date.now() + (data.expires_in ?? 420) * 1000,\n organizationId,\n };\n return this.cached;\n }\n}\n\nexport class GeekappsPost extends PostClient {\n constructor(options: GeekappsPostOptions) {\n const baseUrl = options.baseUrl ?? \"https://post-api.geekapps.com.br\";\n const provider = new TokenProvider(options);\n\n super({\n baseUrl,\n token: () => provider.getToken(),\n organizationId: () => provider.getOrganizationId() as Promise<string>,\n });\n }\n}\n","import { createHmac, timingSafeEqual } from \"node:crypto\";\nimport type { PostWebhookPayload } from \"./types.js\";\n\n/**\n * Verifies the `X-Post-Signature` header (`sha256=<hex>`) of a Post webhook.\n * `rawBody` must be the exact request body string, before JSON parsing.\n */\nexport function verifyWebhookSignature(\n rawBody: string,\n signatureHeader: string | null | undefined,\n secret: string,\n): boolean {\n if (!signatureHeader?.startsWith(\"sha256=\")) return false;\n const expected = Buffer.from(createHmac(\"sha256\", secret).update(rawBody).digest(\"hex\"));\n const received = Buffer.from(signatureHeader.slice(\"sha256=\".length));\n return expected.length === received.length && timingSafeEqual(expected, received);\n}\n\n/** Verifies the signature and parses the payload; throws if invalid. */\nexport function constructWebhookEvent(\n rawBody: string,\n signatureHeader: string | null | undefined,\n secret: string,\n): PostWebhookPayload {\n if (!verifyWebhookSignature(rawBody, signatureHeader, secret)) {\n throw new Error(\"Invalid Post webhook signature\");\n }\n return JSON.parse(rawBody) as PostWebhookPayload;\n}\n"],"mappings":";AAAO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YACkB,QAChB,SACgB,QAChB;AACA,UAAM,SAAS,GAAG,OAAO,KAAK,MAAM,KAAK,OAAO;AAJhC;AAEA;AAGhB,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,IAAI,aAAa;AAAE,WAAO,KAAK,WAAW;AAAA,EAAK;AAAA,EAC/C,IAAI,iBAAiB;AAAE,WAAO,KAAK,WAAW;AAAA,EAAK;AAAA,EACnD,IAAI,cAAc;AAAE,WAAO,KAAK,WAAW;AAAA,EAAK;AAAA,EAChD,IAAI,gBAAgB;AAAE,WAAO,KAAK,WAAW;AAAA,EAAK;AAAA,EAClD,IAAI,oBAAoB;AAAE,WAAO,KAAK,WAAW;AAAA,EAAK;AACxD;;;ACAO,IAAM,aAAN,MAAiB;AAAA,EAKtB,YAAY,SAA4B;AACtC,SAAK,UAAU,QAAQ,QAAQ,QAAQ,OAAO,EAAE;AAChD,SAAK,QAAQ,QAAQ;AACrB,SAAK,iBAAiB,QAAQ;AAAA,EAChC;AAAA,EAEA,MAAc,aAAa,UAAoC;AAC7D,QAAI,SAAU,QAAO;AACrB,QAAI,CAAC,KAAK,MAAO,OAAM,IAAI,MAAM,0CAA0C;AAC3E,WAAO,OAAO,KAAK,UAAU,aAAa,MAAM,KAAK,MAAM,IAAI,KAAK;AAAA,EACtE;AAAA,EAEA,MAAc,aAAa,UAAgD;AACzE,QAAI,SAAU,QAAO;AACrB,QAAI,CAAC,KAAK,eAAgB,QAAO;AACjC,WAAO,OAAO,KAAK,mBAAmB,aAClC,MAAM,KAAK,eAAe,IAC1B,KAAK;AAAA,EACX;AAAA,EAEA,MAAM,QACJ,QACA,MACA,MACA,MACY;AACZ,UAAM,QAAQ,MAAM,KAAK,aAAa,MAAM,KAA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AAO,OAAO,mBAAmB,WAAW,OAAO,iBACnD,OAAO,OAAO,oBAAoB,WAAW,OAAO,kBACpD;AAEF,SAAK,SAAS;AAAA,MACZ,OAAO,KAAK;AAAA,MACZ,WAAW,KAAK,IAAI,KAAK,KAAK,cAAc,OAAO;AAAA,MACnD;AAAA,IACF;AACA,WAAO,KAAK;AAAA,EACd;AACF;AAEO,IAAM,eAAN,cAA2B,WAAW;AAAA,EAC3C,YAAY,SAA8B;AACxC,UAAM,UAAU,QAAQ,WAAW;AACnC,UAAM,WAAW,IAAI,cAAc,OAAO;AAE1C,UAAM;AAAA,MACJ;AAAA,MACA,OAAO,MAAM,SAAS,SAAS;AAAA,MAC/B,gBAAgB,MAAM,SAAS,kBAAkB;AAAA,IACnD,CAAC;AAAA,EACH;AACF;;;ACxGA,SAAS,YAAY,uBAAuB;AAOrC,SAAS,uBACd,SACA,iBACA,QACS;AACT,MAAI,CAAC,iBAAiB,WAAW,SAAS,EAAG,QAAO;AACpD,QAAM,WAAW,OAAO,KAAK,WAAW,UAAU,MAAM,EAAE,OAAO,OAAO,EAAE,OAAO,KAAK,CAAC;AACvF,QAAM,WAAW,OAAO,KAAK,gBAAgB,MAAM,UAAU,MAAM,CAAC;AACpE,SAAO,SAAS,WAAW,SAAS,UAAU,gBAAgB,UAAU,QAAQ;AAClF;AAGO,SAAS,sBACd,SACA,iBACA,QACoB;AACpB,MAAI,CAAC,uBAAuB,SAAS,iBAAiB,MAAM,GAAG;AAC7D,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AACA,SAAO,KAAK,MAAM,OAAO;AAC3B;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/http.ts","../src/resources/domains.ts","../src/resources/history.ts","../src/resources/managed-numbers.ts","../src/resources/messages.ts","../src/resources/plans.ts","../src/resources/smtp.ts","../src/resources/statistics.ts","../src/resources/templates.ts","../src/resources/webhooks.ts","../src/resources/whatsapp-calls.ts","../src/resources/whatsapp-messages.ts","../src/resources/whatsapp-numbers.ts","../src/resources/whatsapp-templates.ts","../src/client.ts","../src/geekapps-post.ts","../src/webhook.ts"],"sourcesContent":["export class PostApiError extends Error {\n constructor(\n public readonly status: number,\n message: string,\n public readonly detail?: string,\n ) {\n super(detail ? `${message}: ${detail}` : message);\n this.name = \"PostApiError\";\n }\n\n get isNotFound() { return this.status === 404; }\n get isUnauthorized() { return this.status === 401; }\n get isForbidden() { return this.status === 403; }\n get isRateLimited() { return this.status === 429; }\n get isValidationError() { return this.status === 400; }\n}\n","import { PostApiError } from \"./errors.js\";\n\nexport type TokenResolver = string | (() => string | Promise<string>);\n\nexport interface HttpClientOptions {\n baseUrl: string;\n token?: TokenResolver;\n organizationId?: string | (() => string | Promise<string>);\n}\n\nexport interface RequestOptions {\n token?: string;\n organizationId?: string;\n}\n\nexport class HttpClient {\n private readonly baseUrl: string;\n private readonly token?: TokenResolver;\n private readonly organizationId?: string | (() => string | Promise<string>);\n\n constructor(options: HttpClientOptions) {\n this.baseUrl = options.baseUrl.replace(/\\/$/, \"\");\n this.token = options.token;\n this.organizationId = options.organizationId;\n }\n\n private async resolveToken(override?: string): Promise<string> {\n if (override) return override;\n if (!this.token) throw new Error(\"@geekapps/post-nextjs: no token provided\");\n return typeof this.token === \"function\" ? await this.token() : this.token;\n }\n\n private async resolveOrgId(override?: string): Promise<string | undefined> {\n if (override) return override;\n if (!this.organizationId) return undefined;\n return typeof this.organizationId === \"function\"\n ? await this.organizationId()\n : this.organizationId;\n }\n\n async request<T = unknown>(\n method: string,\n path: string,\n body?: unknown,\n opts?: RequestOptions,\n ): Promise<T> {\n const token = await this.resolveToken(opts?.token);\n const orgId = await this.resolveOrgId(opts?.organizationId);\n\n const res = await fetch(`${this.baseUrl}/v1${path}`, {\n method,\n headers: {\n Authorization: `Bearer ${token}`,\n ...(body !== undefined ? { \"Content-Type\": \"application/json\" } : {}),\n ...(orgId ? { \"X-Organization-Id\": orgId } : {}),\n },\n ...(body !== undefined ? { body: JSON.stringify(body) } : {}),\n cache: \"no-store\" as RequestCache,\n });\n\n if (!res.ok) {\n const err = await res.json().catch(() => ({})) as { error?: string; detail?: string };\n throw new PostApiError(res.status, err.error ?? `HTTP ${res.status}`, err.detail);\n }\n\n if (res.status === 204) return undefined as T;\n return res.json() as Promise<T>;\n }\n\n get<T>(path: string, opts?: RequestOptions) { return this.request<T>(\"GET\", path, undefined, opts); }\n post<T>(path: string, body?: unknown, opts?: RequestOptions) { return this.request<T>(\"POST\", path, body, opts); }\n put<T>(path: string, body?: unknown, opts?: RequestOptions) { return this.request<T>(\"PUT\", path, body, opts); }\n patch<T>(path: string, body?: unknown, opts?: RequestOptions) { return this.request<T>(\"PATCH\", path, body, opts); }\n delete<T = void>(path: string, opts?: RequestOptions) { return this.request<T>(\"DELETE\", path, undefined, opts); }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type { CreateDomainInput, CreateDomainResult, OrgDomain } from \"../types.js\";\n\nexport class DomainsResource {\n constructor(private readonly http: HttpClient) {}\n\n list(opts?: RequestOptions): Promise<OrgDomain[]> {\n return this.http.get<OrgDomain[]>(\"/domains\", opts);\n }\n\n get(id: string, opts?: RequestOptions): Promise<OrgDomain> {\n return this.http.get<OrgDomain>(`/domains/${id}`, opts);\n }\n\n create(input: CreateDomainInput, opts?: RequestOptions): Promise<CreateDomainResult> {\n return this.http.post<CreateDomainResult>(\"/domains\", input, opts);\n }\n\n verify(id: string, opts?: RequestOptions): Promise<{ status: \"verified\" | \"failed\" }> {\n return this.http.post<{ status: \"verified\" | \"failed\" }>(`/domains/${id}/verify`, undefined, opts);\n }\n\n delete(id: string, opts?: RequestOptions): Promise<void> {\n return this.http.delete(`/domains/${id}`, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type { ListHistoryParams, MessageLog, MessageLogDetail, PaginatedResult } from \"../types.js\";\n\nexport class HistoryResource {\n constructor(private readonly http: HttpClient) {}\n\n list(params?: ListHistoryParams, opts?: RequestOptions): Promise<PaginatedResult<MessageLog>> {\n const qs = new URLSearchParams();\n if (params?.type) qs.set(\"type\", params.type);\n if (params?.status) qs.set(\"status\", params.status);\n if (params?.from) qs.set(\"from\", params.from);\n if (params?.to) qs.set(\"to\", params.to);\n if (params?.page !== undefined) qs.set(\"page\", String(params.page));\n if (params?.limit !== undefined) qs.set(\"limit\", String(params.limit));\n const query = qs.toString();\n return this.http.get<PaginatedResult<MessageLog>>(`/history${query ? `?${query}` : \"\"}`, opts);\n }\n\n get(id: string, opts?: RequestOptions): Promise<MessageLogDetail> {\n return this.http.get<MessageLogDetail>(`/history/${id}`, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type { AreaCode, ManagedNumber } from \"../types.js\";\n\nexport interface ProvisionManagedNumberInput {\n areaCode: number;\n name?: string;\n displayName: string;\n otpMethod?: \"SMS\" | \"VOICE\";\n otpLanguage?: string;\n pin?: string;\n orgWabaId?: string;\n wabaId?: string;\n accessToken?: string;\n}\n\nexport interface RetryVerificationInput {\n otpMethod?: \"SMS\" | \"VOICE\";\n otpLanguage?: string;\n}\n\nexport class ManagedNumbersResource {\n constructor(private readonly http: HttpClient) {}\n\n listAreaCodes(opts?: RequestOptions): Promise<AreaCode[]> {\n return this.http.get<AreaCode[]>(\"/managed-numbers/area-codes\", opts);\n }\n\n list(opts?: RequestOptions): Promise<ManagedNumber[]> {\n return this.http.get<ManagedNumber[]>(\"/managed-numbers\", opts);\n }\n\n get(id: string, opts?: RequestOptions): Promise<ManagedNumber> {\n return this.http.get<ManagedNumber>(`/managed-numbers/${id}`, opts);\n }\n\n provision(input: ProvisionManagedNumberInput, opts?: RequestOptions): Promise<ManagedNumber> {\n return this.http.post<ManagedNumber>(\"/managed-numbers\", input, opts);\n }\n\n retryVerification(id: string, input?: RetryVerificationInput, opts?: RequestOptions): Promise<ManagedNumber> {\n return this.http.post<ManagedNumber>(`/managed-numbers/${id}/retry-verification`, input, opts);\n }\n\n cancel(id: string, opts?: RequestOptions): Promise<ManagedNumber> {\n return this.http.post<ManagedNumber>(`/managed-numbers/${id}/cancel`, undefined, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type { MessagePresenceInput, MessagePresenceResult, SendMessageInput, SendMessageResult } from \"../types.js\";\n\nexport class MessagesResource {\n constructor(private readonly http: HttpClient) {}\n\n send(input: SendMessageInput, opts?: RequestOptions): Promise<SendMessageResult> {\n return this.http.post<SendMessageResult>(\"/messages\", input, opts);\n }\n\n /** Marca uma mensagem recebida como lida (tique azul). */\n markAsRead(input: MessagePresenceInput, opts?: RequestOptions): Promise<MessagePresenceResult> {\n return this.http.post<MessagePresenceResult>(\"/whatsapp/messages/read\", input, opts);\n }\n\n /** Marca como lida e mostra \"digitando…\" até a resposta ser enviada (máx. ~25s). */\n sendTyping(input: MessagePresenceInput, opts?: RequestOptions): Promise<MessagePresenceResult> {\n return this.http.post<MessagePresenceResult>(\"/whatsapp/messages/typing\", input, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type { AvailablePlan, OrgPlan, PlansResult, UpdatePlanInput } from \"../types.js\";\n\nexport class PlansResource {\n constructor(private readonly http: HttpClient) {}\n\n get(opts?: RequestOptions): Promise<PlansResult> {\n return this.http.get<PlansResult>(\"/plans\", opts);\n }\n\n update(input: UpdatePlanInput, opts?: RequestOptions): Promise<OrgPlan> {\n return this.http.put<OrgPlan>(\"/plans\", input, opts);\n }\n\n listAvailable(opts?: RequestOptions): Promise<AvailablePlan[]> {\n return this.http.get<AvailablePlan[]>(\"/plans/available\", opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type { SmtpConfig, UpsertSmtpConfigInput } from \"../types.js\";\n\nexport class SmtpResource {\n constructor(private readonly http: HttpClient) {}\n\n get(opts?: RequestOptions): Promise<SmtpConfig> {\n return this.http.get<SmtpConfig>(\"/smtp-config\", opts);\n }\n\n upsert(input: UpsertSmtpConfigInput, opts?: RequestOptions): Promise<SmtpConfig> {\n return this.http.put<SmtpConfig>(\"/smtp-config\", input, opts);\n }\n\n delete(opts?: RequestOptions): Promise<void> {\n return this.http.delete(\"/smtp-config\", opts);\n }\n\n test(to: string, opts?: RequestOptions): Promise<{ success: boolean; error?: string }> {\n return this.http.post<{ success: boolean; error?: string }>(\"/smtp-config/test\", { to }, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type { StatisticsParams, StatisticsResult } from \"../types.js\";\n\nexport class StatisticsResource {\n constructor(private readonly http: HttpClient) {}\n\n get(params?: StatisticsParams, opts?: RequestOptions): Promise<StatisticsResult> {\n const qs = new URLSearchParams();\n if (params?.from) qs.set(\"from\", params.from);\n if (params?.to) qs.set(\"to\", params.to);\n if (params?.groupBy) qs.set(\"groupBy\", params.groupBy);\n const query = qs.toString();\n return this.http.get<StatisticsResult>(`/statistics${query ? `?${query}` : \"\"}`, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type {\n CreateTemplateInput,\n MessageTemplate,\n MessageType,\n SaveDraftInput,\n UpdateTemplateInput,\n} from \"../types.js\";\n\nexport class TemplatesResource {\n constructor(private readonly http: HttpClient) {}\n\n list(params?: { type?: MessageType; isActive?: boolean }, opts?: RequestOptions): Promise<MessageTemplate[]> {\n const qs = new URLSearchParams();\n if (params?.type) qs.set(\"type\", params.type);\n if (params?.isActive !== undefined) qs.set(\"isActive\", String(params.isActive));\n const query = qs.toString();\n return this.http.get<MessageTemplate[]>(`/templates${query ? `?${query}` : \"\"}`, opts);\n }\n\n get(id: string, opts?: RequestOptions): Promise<MessageTemplate> {\n return this.http.get<MessageTemplate>(`/templates/${id}`, opts);\n }\n\n create(input: CreateTemplateInput, opts?: RequestOptions): Promise<MessageTemplate> {\n return this.http.post<MessageTemplate>(\"/templates\", input, opts);\n }\n\n update(id: string, input: UpdateTemplateInput, opts?: RequestOptions): Promise<MessageTemplate> {\n return this.http.put<MessageTemplate>(`/templates/${id}`, input, opts);\n }\n\n saveDraft(id: string, input: SaveDraftInput, opts?: RequestOptions): Promise<MessageTemplate> {\n return this.http.patch<MessageTemplate>(`/templates/${id}/draft`, input, opts);\n }\n\n publish(id: string, opts?: RequestOptions): Promise<MessageTemplate> {\n return this.http.post<MessageTemplate>(`/templates/${id}/publish`, undefined, opts);\n }\n\n delete(id: string, opts?: RequestOptions): Promise<void> {\n return this.http.delete(`/templates/${id}`, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type {\n CreateWebhookInput,\n OrgWebhook,\n OrgWebhookWithSecret,\n RotateSecretResult,\n UpdateWebhookInput,\n WebhookDelivery,\n} from \"../types.js\";\n\nexport class WebhooksResource {\n constructor(private readonly http: HttpClient) {}\n\n list(opts?: RequestOptions): Promise<OrgWebhook[]> {\n return this.http.get<OrgWebhook[]>(\"/webhooks\", opts);\n }\n\n create(input: CreateWebhookInput, opts?: RequestOptions): Promise<OrgWebhookWithSecret> {\n return this.http.post<OrgWebhookWithSecret>(\"/webhooks\", input, opts);\n }\n\n update(id: string, input: UpdateWebhookInput, opts?: RequestOptions): Promise<OrgWebhook> {\n return this.http.put<OrgWebhook>(`/webhooks/${id}`, input, opts);\n }\n\n delete(id: string, opts?: RequestOptions): Promise<void> {\n return this.http.delete(`/webhooks/${id}`, opts);\n }\n\n listDeliveries(id: string, opts?: RequestOptions): Promise<WebhookDelivery[]> {\n return this.http.get<WebhookDelivery[]>(`/webhooks/${id}/deliveries`, opts);\n }\n\n rotateSecret(id: string, opts?: RequestOptions): Promise<RotateSecretResult> {\n return this.http.post<RotateSecretResult>(`/webhooks/${id}/rotate-secret`, undefined, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type {\n CallActionResult,\n CallAnswerInput,\n CallPermissionStatus,\n CallTargetInput,\n CallingSettings,\n ConnectCallInput,\n ConnectCallResult,\n RequestCallPermissionInput,\n RequestCallPermissionResult,\n UpdateCallingSettingsInput,\n} from \"../types.js\";\n\n// WhatsApp Cloud API Calling. Signaling only: media flows over WebRTC between\n// Meta and your server. Incoming calls arrive via the `call_connect` webhook.\nexport class WhatsappCallsResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Lê a configuração de chamadas de um número (id do WhatsappNumber no Post). */\n getSettings(numberId: string, opts?: RequestOptions): Promise<CallingSettings> {\n return this.http.get<CallingSettings>(`/whatsapp/numbers/${numberId}/calling`, opts);\n }\n\n /** Ativa/desativa chamadas no número. */\n updateSettings(numberId: string, input: UpdateCallingSettingsInput, opts?: RequestOptions): Promise<CallingSettings> {\n return this.http.put<CallingSettings>(`/whatsapp/numbers/${numberId}/calling`, input, opts);\n }\n\n /** Pré-aceita uma chamada recebida (opcional, acelera a conexão de mídia). */\n preAccept(callId: string, input: CallAnswerInput, opts?: RequestOptions): Promise<CallActionResult> {\n return this.http.post<CallActionResult>(`/whatsapp/calls/${callId}/pre-accept`, input, opts);\n }\n\n /** Aceita uma chamada recebida enviando o SDP de resposta. */\n accept(callId: string, input: CallAnswerInput, opts?: RequestOptions): Promise<CallActionResult> {\n return this.http.post<CallActionResult>(`/whatsapp/calls/${callId}/accept`, input, opts);\n }\n\n /** Rejeita uma chamada recebida. */\n reject(callId: string, input: CallTargetInput = {}, opts?: RequestOptions): Promise<CallActionResult> {\n return this.http.post<CallActionResult>(`/whatsapp/calls/${callId}/reject`, input, opts);\n }\n\n /** Encerra uma chamada em andamento. */\n terminate(callId: string, input: CallTargetInput = {}, opts?: RequestOptions): Promise<CallActionResult> {\n return this.http.post<CallActionResult>(`/whatsapp/calls/${callId}/terminate`, input, opts);\n }\n\n /** Inicia uma chamada (business-initiated). Exige permissão prévia do usuário. */\n connect(input: ConnectCallInput, opts?: RequestOptions): Promise<ConnectCallResult> {\n return this.http.post<ConnectCallResult>(\"/whatsapp/calls\", input, opts);\n }\n\n /** Envia ao usuário o pedido de permissão para receber chamadas. */\n requestPermission(input: RequestCallPermissionInput, opts?: RequestOptions): Promise<RequestCallPermissionResult> {\n return this.http.post<RequestCallPermissionResult>(\"/whatsapp/calls/permissions\", input, opts);\n }\n\n /** Consulta o status de permissão de chamada de um usuário. */\n getPermission(to: string, phoneNumberId?: string, opts?: RequestOptions): Promise<CallPermissionStatus> {\n return this.http.get<CallPermissionStatus>(`/whatsapp/calls/permissions?${new URLSearchParams({ to, ...(phoneNumberId ? { phoneNumberId } : {}) })}`, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type {\n SendWhatsappMessageInput,\n SendWhatsappMessageResult,\n UploadWhatsappMediaInput,\n UploadWhatsappMediaResult,\n WhatsappContactCard,\n WhatsappInteractive,\n WhatsappMediaDownload,\n WhatsappMediaInfo,\n WhatsappMediaRef,\n WhatsappMessage,\n} from \"../types.js\";\n\ntype Target = { to: string; phoneNumberId?: string; replyTo?: string };\n\n// Mensagens livres: só dentro da janela de 24h aberta por uma mensagem recebida.\n// Fora dela, envie um template por `messages.send`.\nexport class WhatsappMessagesResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Envio genérico de qualquer tipo de mensagem. */\n send(input: SendWhatsappMessageInput, opts?: RequestOptions): Promise<SendWhatsappMessageResult> {\n return this.http.post<SendWhatsappMessageResult>(\"/whatsapp/messages/send\", input, opts);\n }\n\n sendText(target: Target, body: string, previewUrl?: boolean, opts?: RequestOptions) {\n return this.send({ ...target, message: { type: \"text\", body, previewUrl } }, opts);\n }\n\n sendImage(target: Target, media: WhatsappMediaRef, caption?: string, opts?: RequestOptions) {\n return this.send({ ...target, message: { type: \"image\", ...media, caption } }, opts);\n }\n\n sendVideo(target: Target, media: WhatsappMediaRef, caption?: string, opts?: RequestOptions) {\n return this.send({ ...target, message: { type: \"video\", ...media, caption } }, opts);\n }\n\n sendAudio(target: Target, media: WhatsappMediaRef, opts?: RequestOptions) {\n return this.send({ ...target, message: { type: \"audio\", ...media } }, opts);\n }\n\n sendDocument(target: Target, media: WhatsappMediaRef, extra?: { caption?: string; filename?: string }, opts?: RequestOptions) {\n return this.send({ ...target, message: { type: \"document\", ...media, ...extra } }, opts);\n }\n\n sendSticker(target: Target, media: WhatsappMediaRef, opts?: RequestOptions) {\n return this.send({ ...target, message: { type: \"sticker\", ...media } }, opts);\n }\n\n sendLocation(target: Target, location: { latitude: number; longitude: number; name?: string; address?: string }, opts?: RequestOptions) {\n return this.send({ ...target, message: { type: \"location\", ...location } }, opts);\n }\n\n sendContacts(target: Target, contacts: WhatsappContactCard[], opts?: RequestOptions) {\n return this.send({ ...target, message: { type: \"contacts\", contacts } }, opts);\n }\n\n /** Reage a uma mensagem. Emoji vazio remove a reação. */\n sendReaction(target: Target, messageId: string, emoji: string, opts?: RequestOptions) {\n return this.send({ ...target, message: { type: \"reaction\", messageId, emoji } }, opts);\n }\n\n /** Botões de resposta rápida, lista, botão com link ou pedido de localização. */\n sendInteractive(target: Target, interactive: WhatsappInteractive, opts?: RequestOptions) {\n return this.send({ ...target, message: { type: \"interactive\", interactive } }, opts);\n }\n\n /** Sobe um arquivo (base64) e devolve o `id` para usar em `sendImage`, `sendVideo` etc. */\n uploadMedia(input: UploadWhatsappMediaInput, opts?: RequestOptions): Promise<UploadWhatsappMediaResult> {\n return this.http.post<UploadWhatsappMediaResult>(\"/whatsapp/media\", input, opts);\n }\n\n /** Metadados de uma mídia (id recebido em `message_received`). */\n getMedia(mediaId: string, phoneNumberId?: string, opts?: RequestOptions): Promise<WhatsappMediaInfo> {\n return this.http.get<WhatsappMediaInfo>(`/whatsapp/media/${mediaId}${phoneNumberId ? `?phoneNumberId=${encodeURIComponent(phoneNumberId)}` : \"\"}`, opts);\n }\n\n /** Baixa uma mídia recebida (conteúdo em base64). */\n downloadMedia(mediaId: string, phoneNumberId?: string, opts?: RequestOptions): Promise<WhatsappMediaDownload> {\n return this.http.get<WhatsappMediaDownload>(`/whatsapp/media/${mediaId}/download${phoneNumberId ? `?phoneNumberId=${encodeURIComponent(phoneNumberId)}` : \"\"}`, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type {\n ConnectWabaInput,\n ConnectWhatsappNumberInput,\n OrgWaba,\n PhoneNumberStatusResult,\n RegisterWhatsappNumberInput,\n UpdateWhatsappProfileInput,\n WabaHealthResult,\n WhatsappNumber,\n WhatsappNumberProfile,\n} from \"../types.js\";\n\nexport class WhatsappNumbersResource {\n constructor(private readonly http: HttpClient) {}\n\n listWabas(opts?: RequestOptions): Promise<OrgWaba[]> {\n return this.http.get<OrgWaba[]>(\"/whatsapp/wabas\", opts);\n }\n\n connectWaba(input: ConnectWabaInput, opts?: RequestOptions): Promise<OrgWaba> {\n return this.http.post<OrgWaba>(\"/whatsapp/wabas/connect\", input, opts);\n }\n\n reconnectWaba(id: string, opts?: RequestOptions): Promise<OrgWaba> {\n return this.http.post<OrgWaba>(`/whatsapp/wabas/${id}/reconnect`, undefined, opts);\n }\n\n disconnectWaba(id: string, opts?: RequestOptions): Promise<void> {\n return this.http.delete(`/whatsapp/wabas/${id}`, opts);\n }\n\n getWabaHealth(id: string, opts?: RequestOptions): Promise<WabaHealthResult> {\n return this.http.get<WabaHealthResult>(`/whatsapp/wabas/${id}/health`, opts);\n }\n\n listNumbers(opts?: RequestOptions): Promise<WhatsappNumber[]> {\n return this.http.get<WhatsappNumber[]>(\"/whatsapp/numbers\", opts);\n }\n\n connectNumber(input: ConnectWhatsappNumberInput, opts?: RequestOptions): Promise<WhatsappNumber> {\n return this.http.post<WhatsappNumber>(\"/whatsapp/numbers/connect\", input, opts);\n }\n\n registerNumber(input: RegisterWhatsappNumberInput, opts?: RequestOptions): Promise<WhatsappNumber> {\n return this.http.post<WhatsappNumber>(\"/whatsapp/numbers\", input, opts);\n }\n\n verifyCode(id: string, code: string, opts?: RequestOptions): Promise<WhatsappNumber> {\n return this.http.post<WhatsappNumber>(`/whatsapp/numbers/${id}/verify-code`, { code }, opts);\n }\n\n resendCode(id: string, opts?: RequestOptions): Promise<void> {\n return this.http.post(`/whatsapp/numbers/${id}/resend-code`, undefined, opts);\n }\n\n getProfile(id: string, opts?: RequestOptions): Promise<WhatsappNumberProfile> {\n return this.http.get<WhatsappNumberProfile>(`/whatsapp/numbers/${id}/profile`, opts);\n }\n\n updateProfile(id: string, input: UpdateWhatsappProfileInput, opts?: RequestOptions): Promise<WhatsappNumberProfile> {\n return this.http.patch<WhatsappNumberProfile>(`/whatsapp/numbers/${id}/profile`, input, opts);\n }\n\n updateDisplayName(id: string, displayName: string, opts?: RequestOptions): Promise<WhatsappNumber> {\n return this.http.patch<WhatsappNumber>(`/whatsapp/numbers/${id}`, { displayName }, opts);\n }\n\n getStatus(id: string, opts?: RequestOptions): Promise<PhoneNumberStatusResult> {\n return this.http.get<PhoneNumberStatusResult>(`/whatsapp/numbers/${id}/status`, opts);\n }\n\n refreshNumbers(opts?: RequestOptions): Promise<WhatsappNumber[]> {\n return this.http.post<WhatsappNumber[]>(\"/whatsapp/numbers/refresh\", undefined, opts);\n }\n\n deleteNumber(id: string, opts?: RequestOptions): Promise<void> {\n return this.http.delete(`/whatsapp/numbers/${id}`, opts);\n }\n}\n","import type { HttpClient, RequestOptions } from \"../http.js\";\nimport type {\n CreateWhatsappTemplateInput,\n SyncWhatsappTemplatesResult,\n UpdateWhatsappTemplateInput,\n WhatsappTemplate,\n} from \"../types.js\";\n\nexport class WhatsappTemplatesResource {\n constructor(private readonly http: HttpClient) {}\n\n list(opts?: RequestOptions): Promise<WhatsappTemplate[]> {\n return this.http.get<WhatsappTemplate[]>(\"/whatsapp/templates\", opts);\n }\n\n create(input: CreateWhatsappTemplateInput, opts?: RequestOptions): Promise<WhatsappTemplate> {\n return this.http.post<WhatsappTemplate>(\"/whatsapp/templates\", input, opts);\n }\n\n update(id: string, input: UpdateWhatsappTemplateInput, opts?: RequestOptions): Promise<WhatsappTemplate> {\n return this.http.put<WhatsappTemplate>(`/whatsapp/templates/${id}`, input, opts);\n }\n\n sync(opts?: RequestOptions): Promise<SyncWhatsappTemplatesResult> {\n return this.http.post<SyncWhatsappTemplatesResult>(\"/whatsapp/templates/sync\", undefined, opts);\n }\n\n delete(id: string, opts?: RequestOptions): Promise<void> {\n return this.http.delete(`/whatsapp/templates/${id}`, opts);\n }\n}\n","import { HttpClient, type HttpClientOptions } from \"./http.js\";\nimport { DomainsResource } from \"./resources/domains.js\";\nimport { HistoryResource } from \"./resources/history.js\";\nimport { ManagedNumbersResource } from \"./resources/managed-numbers.js\";\nimport { MessagesResource } from \"./resources/messages.js\";\nimport { PlansResource } from \"./resources/plans.js\";\nimport { SmtpResource } from \"./resources/smtp.js\";\nimport { StatisticsResource } from \"./resources/statistics.js\";\nimport { TemplatesResource } from \"./resources/templates.js\";\nimport { WebhooksResource } from \"./resources/webhooks.js\";\nimport { WhatsappCallsResource } from \"./resources/whatsapp-calls.js\";\nimport { WhatsappMessagesResource } from \"./resources/whatsapp-messages.js\";\nimport { WhatsappNumbersResource } from \"./resources/whatsapp-numbers.js\";\nimport { WhatsappTemplatesResource } from \"./resources/whatsapp-templates.js\";\n\nexport interface PostClientOptions extends Omit<HttpClientOptions, \"baseUrl\"> {\n baseUrl?: string;\n}\n\nexport class PostClient {\n private readonly http: HttpClient;\n\n readonly messages: MessagesResource;\n readonly templates: TemplatesResource;\n readonly whatsappTemplates: WhatsappTemplatesResource;\n readonly whatsappNumbers: WhatsappNumbersResource;\n readonly calls: WhatsappCallsResource;\n readonly whatsappMessages: WhatsappMessagesResource;\n readonly domains: DomainsResource;\n readonly webhooks: WebhooksResource;\n readonly smtp: SmtpResource;\n readonly plans: PlansResource;\n readonly history: HistoryResource;\n readonly statistics: StatisticsResource;\n readonly managedNumbers: ManagedNumbersResource;\n\n constructor(optionsOrHttp: HttpClientOptions | HttpClient) {\n this.http = optionsOrHttp instanceof HttpClient ? optionsOrHttp : new HttpClient(optionsOrHttp);\n\n this.messages = new MessagesResource(this.http);\n this.templates = new TemplatesResource(this.http);\n this.whatsappTemplates = new WhatsappTemplatesResource(this.http);\n this.whatsappNumbers = new WhatsappNumbersResource(this.http);\n this.calls = new WhatsappCallsResource(this.http);\n this.whatsappMessages = new WhatsappMessagesResource(this.http);\n this.domains = new DomainsResource(this.http);\n this.webhooks = new WebhooksResource(this.http);\n this.smtp = new SmtpResource(this.http);\n this.plans = new PlansResource(this.http);\n this.history = new HistoryResource(this.http);\n this.statistics = new StatisticsResource(this.http);\n this.managedNumbers = new ManagedNumbersResource(this.http);\n }\n}\n","import { PostClient } from \"./client.js\";\n\nexport interface ServiceAccountOptions {\n issuerUrl: string;\n clientId: string;\n clientSecret: string;\n}\n\nexport interface GeekappsPostOptions {\n serviceAccount: ServiceAccountOptions;\n baseUrl?: string;\n logLevel?: \"trace\" | \"debug\" | \"info\" | \"warn\" | \"error\" | \"silent\";\n}\n\ninterface CachedToken {\n value: string;\n expiresAt: number;\n organizationId: string | undefined;\n}\n\nfunction decodeJwtPayload(token: string): Record<string, unknown> {\n try {\n const [, payload] = token.split(\".\");\n if (!payload) return {};\n const json = atob(payload.replace(/-/g, \"+\").replace(/_/g, \"/\"));\n return JSON.parse(json) as Record<string, unknown>;\n } catch {\n return {};\n }\n}\n\nclass TokenProvider {\n private readonly issuerUrl: string;\n private readonly clientId: string;\n private readonly clientSecret: string;\n private cached: CachedToken | null = null;\n private inflight: Promise<CachedToken> | null = null;\n\n constructor(options: GeekappsPostOptions) {\n this.issuerUrl = options.serviceAccount.issuerUrl.replace(/\\/$/, \"\");\n this.clientId = options.serviceAccount.clientId;\n this.clientSecret = options.serviceAccount.clientSecret;\n }\n\n private async ensureFresh(): Promise<CachedToken> {\n const now = Date.now();\n if (this.cached && this.cached.expiresAt - now > 30_000) return this.cached;\n if (this.inflight) return this.inflight;\n this.inflight = this.fetchToken().finally(() => { this.inflight = null; });\n return this.inflight;\n }\n\n getToken(): Promise<string> {\n return this.ensureFresh().then((c) => c.value);\n }\n\n getOrganizationId(): Promise<string | undefined> {\n return this.ensureFresh().then((c) => c.organizationId);\n }\n\n private async fetchToken(): Promise<CachedToken> {\n const credentials = btoa(`${this.clientId}:${this.clientSecret}`);\n const res = await fetch(`${this.issuerUrl}/auth/token`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Basic ${credentials}`,\n },\n body: JSON.stringify({ grant_type: \"service_account\" }),\n cache: \"no-store\" as RequestCache,\n });\n\n if (!res.ok) {\n const err = await res.json().catch(() => ({})) as { error?: string };\n throw new Error(`GeekappsPost auth failed (${res.status}): ${err.error ?? \"unknown error\"}`);\n }\n\n const data = await res.json() as { access_token: string; expires_in?: number };\n const claims = decodeJwtPayload(data.access_token);\n const organizationId =\n typeof claims.organizationId === \"string\" ? claims.organizationId :\n typeof claims.organization_id === \"string\" ? claims.organization_id :\n undefined;\n\n this.cached = {\n value: data.access_token,\n expiresAt: Date.now() + (data.expires_in ?? 420) * 1000,\n organizationId,\n };\n return this.cached;\n }\n}\n\nexport class GeekappsPost extends PostClient {\n constructor(options: GeekappsPostOptions) {\n const baseUrl = options.baseUrl ?? \"https://post-api.geekapps.com.br\";\n const provider = new TokenProvider(options);\n\n super({\n baseUrl,\n token: () => provider.getToken(),\n organizationId: () => provider.getOrganizationId() as Promise<string>,\n });\n }\n}\n","import { createHmac, timingSafeEqual } from \"node:crypto\";\nimport type { PostWebhookPayload } from \"./types.js\";\n\n/**\n * Verifies the `X-Post-Signature` header (`sha256=<hex>`) of a Post webhook.\n * `rawBody` must be the exact request body string, before JSON parsing.\n */\nexport function verifyWebhookSignature(\n rawBody: string,\n signatureHeader: string | null | undefined,\n secret: string,\n): boolean {\n if (!signatureHeader?.startsWith(\"sha256=\")) return false;\n const expected = Buffer.from(createHmac(\"sha256\", secret).update(rawBody).digest(\"hex\"));\n const received = Buffer.from(signatureHeader.slice(\"sha256=\".length));\n return expected.length === received.length && timingSafeEqual(expected, received);\n}\n\n/** Verifies the signature and parses the payload; throws if invalid. */\nexport function constructWebhookEvent(\n rawBody: string,\n signatureHeader: string | null | undefined,\n secret: string,\n): PostWebhookPayload {\n if (!verifyWebhookSignature(rawBody, signatureHeader, secret)) {\n throw new Error(\"Invalid Post webhook signature\");\n }\n return JSON.parse(rawBody) as PostWebhook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C,UAAM,WAAW,IAAI,cAAc,OAAO;AAE1C,UAAM;AAAA,MACJ;AAAA,MACA,OAAO,MAAM,SAAS,SAAS;AAAA,MAC/B,gBAAgB,MAAM,SAAS,kBAAkB;AAAA,IACnD,CAAC;AAAA,EACH;AACF;;;ACxGA,SAAS,YAAY,uBAAuB;AAOrC,SAAS,uBACd,SACA,iBACA,QACS;AACT,MAAI,CAAC,iBAAiB,WAAW,SAAS,EAAG,QAAO;AACpD,QAAM,WAAW,OAAO,KAAK,WAAW,UAAU,MAAM,EAAE,OAAO,OAAO,EAAE,OAAO,KAAK,CAAC;AACvF,QAAM,WAAW,OAAO,KAAK,gBAAgB,MAAM,UAAU,MAAM,CAAC;AACpE,SAAO,SAAS,WAAW,SAAS,UAAU,gBAAgB,UAAU,QAAQ;AAClF;AAGO,SAAS,sBACd,SACA,iBACA,QACoB;AACpB,MAAI,CAAC,uBAAuB,SAAS,iBAAiB,MAAM,GAAG;AAC7D,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AACA,SAAO,KAAK,MAAM,OAAO;AAC3B;","names":[]}
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { StatisticsResource } from "./resources/statistics.js";
|
|
|
9
9
|
import { TemplatesResource } from "./resources/templates.js";
|
|
10
10
|
import { WebhooksResource } from "./resources/webhooks.js";
|
|
11
11
|
import { WhatsappCallsResource } from "./resources/whatsapp-calls.js";
|
|
12
|
+
import { WhatsappMessagesResource } from "./resources/whatsapp-messages.js";
|
|
12
13
|
import { WhatsappNumbersResource } from "./resources/whatsapp-numbers.js";
|
|
13
14
|
import { WhatsappTemplatesResource } from "./resources/whatsapp-templates.js";
|
|
14
15
|
|
|
@@ -24,6 +25,7 @@ export class PostClient {
|
|
|
24
25
|
readonly whatsappTemplates: WhatsappTemplatesResource;
|
|
25
26
|
readonly whatsappNumbers: WhatsappNumbersResource;
|
|
26
27
|
readonly calls: WhatsappCallsResource;
|
|
28
|
+
readonly whatsappMessages: WhatsappMessagesResource;
|
|
27
29
|
readonly domains: DomainsResource;
|
|
28
30
|
readonly webhooks: WebhooksResource;
|
|
29
31
|
readonly smtp: SmtpResource;
|
|
@@ -40,6 +42,7 @@ export class PostClient {
|
|
|
40
42
|
this.whatsappTemplates = new WhatsappTemplatesResource(this.http);
|
|
41
43
|
this.whatsappNumbers = new WhatsappNumbersResource(this.http);
|
|
42
44
|
this.calls = new WhatsappCallsResource(this.http);
|
|
45
|
+
this.whatsappMessages = new WhatsappMessagesResource(this.http);
|
|
43
46
|
this.domains = new DomainsResource(this.http);
|
|
44
47
|
this.webhooks = new WebhooksResource(this.http);
|
|
45
48
|
this.smtp = new SmtpResource(this.http);
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ export { StatisticsResource } from "./resources/statistics.js";
|
|
|
14
14
|
export { TemplatesResource } from "./resources/templates.js";
|
|
15
15
|
export { WebhooksResource } from "./resources/webhooks.js";
|
|
16
16
|
export { WhatsappCallsResource } from "./resources/whatsapp-calls.js";
|
|
17
|
+
export { WhatsappMessagesResource } from "./resources/whatsapp-messages.js";
|
|
17
18
|
export { WhatsappNumbersResource } from "./resources/whatsapp-numbers.js";
|
|
18
19
|
export { constructWebhookEvent, verifyWebhookSignature } from "./webhook.js";
|
|
19
20
|
export { WhatsappTemplatesResource } from "./resources/whatsapp-templates.js";
|
|
@@ -70,7 +71,22 @@ export type {
|
|
|
70
71
|
RotateSecretResult,
|
|
71
72
|
SaveDraftInput,
|
|
72
73
|
SendMessageInput,
|
|
74
|
+
EmailAttachment,
|
|
73
75
|
MessagePresenceInput,
|
|
76
|
+
WhatsappMediaRef,
|
|
77
|
+
WhatsappContactCard,
|
|
78
|
+
WhatsappInteractive,
|
|
79
|
+
WhatsappInteractiveButtons,
|
|
80
|
+
WhatsappInteractiveList,
|
|
81
|
+
WhatsappInteractiveCtaUrl,
|
|
82
|
+
WhatsappInteractiveLocationRequest,
|
|
83
|
+
WhatsappMessage,
|
|
84
|
+
SendWhatsappMessageInput,
|
|
85
|
+
SendWhatsappMessageResult,
|
|
86
|
+
UploadWhatsappMediaInput,
|
|
87
|
+
UploadWhatsappMediaResult,
|
|
88
|
+
WhatsappMediaInfo,
|
|
89
|
+
WhatsappMediaDownload,
|
|
74
90
|
MessagePresenceResult,
|
|
75
91
|
SendMessageResult,
|
|
76
92
|
TemplateVariable,
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { HttpClient, RequestOptions } from "../http.js";
|
|
2
|
+
import type {
|
|
3
|
+
SendWhatsappMessageInput,
|
|
4
|
+
SendWhatsappMessageResult,
|
|
5
|
+
UploadWhatsappMediaInput,
|
|
6
|
+
UploadWhatsappMediaResult,
|
|
7
|
+
WhatsappContactCard,
|
|
8
|
+
WhatsappInteractive,
|
|
9
|
+
WhatsappMediaDownload,
|
|
10
|
+
WhatsappMediaInfo,
|
|
11
|
+
WhatsappMediaRef,
|
|
12
|
+
WhatsappMessage,
|
|
13
|
+
} from "../types.js";
|
|
14
|
+
|
|
15
|
+
type Target = { to: string; phoneNumberId?: string; replyTo?: string };
|
|
16
|
+
|
|
17
|
+
// Mensagens livres: só dentro da janela de 24h aberta por uma mensagem recebida.
|
|
18
|
+
// Fora dela, envie um template por `messages.send`.
|
|
19
|
+
export class WhatsappMessagesResource {
|
|
20
|
+
constructor(private readonly http: HttpClient) {}
|
|
21
|
+
|
|
22
|
+
/** Envio genérico de qualquer tipo de mensagem. */
|
|
23
|
+
send(input: SendWhatsappMessageInput, opts?: RequestOptions): Promise<SendWhatsappMessageResult> {
|
|
24
|
+
return this.http.post<SendWhatsappMessageResult>("/whatsapp/messages/send", input, opts);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
sendText(target: Target, body: string, previewUrl?: boolean, opts?: RequestOptions) {
|
|
28
|
+
return this.send({ ...target, message: { type: "text", body, previewUrl } }, opts);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
sendImage(target: Target, media: WhatsappMediaRef, caption?: string, opts?: RequestOptions) {
|
|
32
|
+
return this.send({ ...target, message: { type: "image", ...media, caption } }, opts);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
sendVideo(target: Target, media: WhatsappMediaRef, caption?: string, opts?: RequestOptions) {
|
|
36
|
+
return this.send({ ...target, message: { type: "video", ...media, caption } }, opts);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
sendAudio(target: Target, media: WhatsappMediaRef, opts?: RequestOptions) {
|
|
40
|
+
return this.send({ ...target, message: { type: "audio", ...media } }, opts);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
sendDocument(target: Target, media: WhatsappMediaRef, extra?: { caption?: string; filename?: string }, opts?: RequestOptions) {
|
|
44
|
+
return this.send({ ...target, message: { type: "document", ...media, ...extra } }, opts);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
sendSticker(target: Target, media: WhatsappMediaRef, opts?: RequestOptions) {
|
|
48
|
+
return this.send({ ...target, message: { type: "sticker", ...media } }, opts);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
sendLocation(target: Target, location: { latitude: number; longitude: number; name?: string; address?: string }, opts?: RequestOptions) {
|
|
52
|
+
return this.send({ ...target, message: { type: "location", ...location } }, opts);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
sendContacts(target: Target, contacts: WhatsappContactCard[], opts?: RequestOptions) {
|
|
56
|
+
return this.send({ ...target, message: { type: "contacts", contacts } }, opts);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Reage a uma mensagem. Emoji vazio remove a reação. */
|
|
60
|
+
sendReaction(target: Target, messageId: string, emoji: string, opts?: RequestOptions) {
|
|
61
|
+
return this.send({ ...target, message: { type: "reaction", messageId, emoji } }, opts);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Botões de resposta rápida, lista, botão com link ou pedido de localização. */
|
|
65
|
+
sendInteractive(target: Target, interactive: WhatsappInteractive, opts?: RequestOptions) {
|
|
66
|
+
return this.send({ ...target, message: { type: "interactive", interactive } }, opts);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Sobe um arquivo (base64) e devolve o `id` para usar em `sendImage`, `sendVideo` etc. */
|
|
70
|
+
uploadMedia(input: UploadWhatsappMediaInput, opts?: RequestOptions): Promise<UploadWhatsappMediaResult> {
|
|
71
|
+
return this.http.post<UploadWhatsappMediaResult>("/whatsapp/media", input, opts);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Metadados de uma mídia (id recebido em `message_received`). */
|
|
75
|
+
getMedia(mediaId: string, phoneNumberId?: string, opts?: RequestOptions): Promise<WhatsappMediaInfo> {
|
|
76
|
+
return this.http.get<WhatsappMediaInfo>(`/whatsapp/media/${mediaId}${phoneNumberId ? `?phoneNumberId=${encodeURIComponent(phoneNumberId)}` : ""}`, opts);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Baixa uma mídia recebida (conteúdo em base64). */
|
|
80
|
+
downloadMedia(mediaId: string, phoneNumberId?: string, opts?: RequestOptions): Promise<WhatsappMediaDownload> {
|
|
81
|
+
return this.http.get<WhatsappMediaDownload>(`/whatsapp/media/${mediaId}/download${phoneNumberId ? `?phoneNumberId=${encodeURIComponent(phoneNumberId)}` : ""}`, opts);
|
|
82
|
+
}
|
|
83
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -256,6 +256,16 @@ export interface TemplateVariables {
|
|
|
256
256
|
buttons?: TemplateVariable[];
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
+
export interface EmailAttachment {
|
|
260
|
+
filename: string;
|
|
261
|
+
/** Conteúdo do arquivo em base64. Informe `content` ou `url`. */
|
|
262
|
+
content?: string;
|
|
263
|
+
/** URL pública (http/https) do arquivo. Informe `content` ou `url`. */
|
|
264
|
+
url?: string;
|
|
265
|
+
/** Ex.: "application/pdf". Se omitido, é inferido pelo nome do arquivo. */
|
|
266
|
+
contentType?: string;
|
|
267
|
+
}
|
|
268
|
+
|
|
259
269
|
export interface SendMessageInput {
|
|
260
270
|
type: MessageType;
|
|
261
271
|
to: string;
|
|
@@ -266,6 +276,8 @@ export interface SendMessageInput {
|
|
|
266
276
|
subject?: string;
|
|
267
277
|
body?: string;
|
|
268
278
|
variables?: TemplateVariable[] | TemplateVariables;
|
|
279
|
+
/** Apenas para `type: "email"`. Máx. 10 arquivos / 25MB no total. */
|
|
280
|
+
attachments?: EmailAttachment[];
|
|
269
281
|
}
|
|
270
282
|
|
|
271
283
|
export interface CreateTemplateInput {
|
|
@@ -559,3 +571,113 @@ export interface MessagePresenceResult {
|
|
|
559
571
|
success: boolean;
|
|
560
572
|
phoneNumberId: string;
|
|
561
573
|
}
|
|
574
|
+
|
|
575
|
+
// ─── WhatsApp: mensagens livres (janela de 24h) ──────────────────────────────
|
|
576
|
+
|
|
577
|
+
/** Mídia já enviada (`id`) ou URL pública (`link`). */
|
|
578
|
+
export interface WhatsappMediaRef {
|
|
579
|
+
id?: string;
|
|
580
|
+
link?: string;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
export interface WhatsappContactCard {
|
|
584
|
+
name: { formattedName: string; firstName?: string; lastName?: string };
|
|
585
|
+
phones?: { phone: string; type?: string; waId?: string }[];
|
|
586
|
+
emails?: { email: string; type?: string }[];
|
|
587
|
+
org?: { company?: string; title?: string };
|
|
588
|
+
urls?: { url: string; type?: string }[];
|
|
589
|
+
/** YYYY-MM-DD */
|
|
590
|
+
birthday?: string;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
export interface WhatsappInteractiveButtons {
|
|
594
|
+
kind: "buttons";
|
|
595
|
+
body: string;
|
|
596
|
+
header?: string;
|
|
597
|
+
footer?: string;
|
|
598
|
+
/** Até 3 botões. `id` volta em `message_received` quando o usuário clica. */
|
|
599
|
+
buttons: { id: string; title: string }[];
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
export interface WhatsappInteractiveList {
|
|
603
|
+
kind: "list";
|
|
604
|
+
body: string;
|
|
605
|
+
header?: string;
|
|
606
|
+
footer?: string;
|
|
607
|
+
buttonText: string;
|
|
608
|
+
sections: { title?: string; rows: { id: string; title: string; description?: string }[] }[];
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
export interface WhatsappInteractiveCtaUrl {
|
|
612
|
+
kind: "cta_url";
|
|
613
|
+
body: string;
|
|
614
|
+
header?: string;
|
|
615
|
+
footer?: string;
|
|
616
|
+
buttonText: string;
|
|
617
|
+
url: string;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
export interface WhatsappInteractiveLocationRequest {
|
|
621
|
+
kind: "location_request";
|
|
622
|
+
body: string;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
export type WhatsappInteractive =
|
|
626
|
+
| WhatsappInteractiveButtons
|
|
627
|
+
| WhatsappInteractiveList
|
|
628
|
+
| WhatsappInteractiveCtaUrl
|
|
629
|
+
| WhatsappInteractiveLocationRequest;
|
|
630
|
+
|
|
631
|
+
export type WhatsappMessage =
|
|
632
|
+
| { type: "text"; body: string; previewUrl?: boolean }
|
|
633
|
+
| ({ type: "image"; caption?: string } & WhatsappMediaRef)
|
|
634
|
+
| ({ type: "video"; caption?: string } & WhatsappMediaRef)
|
|
635
|
+
| ({ type: "audio" } & WhatsappMediaRef)
|
|
636
|
+
| ({ type: "document"; caption?: string; filename?: string } & WhatsappMediaRef)
|
|
637
|
+
| ({ type: "sticker" } & WhatsappMediaRef)
|
|
638
|
+
| { type: "location"; latitude: number; longitude: number; name?: string; address?: string }
|
|
639
|
+
| { type: "contacts"; contacts: WhatsappContactCard[] }
|
|
640
|
+
| { type: "reaction"; messageId: string; emoji: string }
|
|
641
|
+
| { type: "interactive"; interactive: WhatsappInteractive };
|
|
642
|
+
|
|
643
|
+
export interface SendWhatsappMessageInput {
|
|
644
|
+
to: string;
|
|
645
|
+
message: WhatsappMessage;
|
|
646
|
+
/** Meta phone_number_id. Padrão: primeiro número ativo da org. */
|
|
647
|
+
phoneNumberId?: string;
|
|
648
|
+
/** `messageId` de uma mensagem para responder citando. */
|
|
649
|
+
replyTo?: string;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
export interface SendWhatsappMessageResult {
|
|
653
|
+
messageId: string;
|
|
654
|
+
phoneNumberId: string;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
export interface UploadWhatsappMediaInput {
|
|
658
|
+
/** Conteúdo do arquivo em base64. */
|
|
659
|
+
data: string;
|
|
660
|
+
mimeType: string;
|
|
661
|
+
filename?: string;
|
|
662
|
+
phoneNumberId?: string;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
export interface UploadWhatsappMediaResult {
|
|
666
|
+
id: string;
|
|
667
|
+
phoneNumberId: string;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
export interface WhatsappMediaInfo {
|
|
671
|
+
id: string;
|
|
672
|
+
mimeType: string;
|
|
673
|
+
fileSize: number | null;
|
|
674
|
+
sha256: string | null;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
export interface WhatsappMediaDownload {
|
|
678
|
+
id: string;
|
|
679
|
+
mimeType: string;
|
|
680
|
+
fileSize: number;
|
|
681
|
+
/** Conteúdo em base64. */
|
|
682
|
+
data: string;
|
|
683
|
+
}
|