Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(sdk-js): type cancelBatch as the cancel response it returns
Yudhi Armyndharise77218d45e74
diff --git a/sdk/javascript/src/resources/messages.ts b/sdk/javascript/src/resources/messages.tsindex b5f76508e..faefb0b6c 100644--- a/sdk/javascript/src/resources/messages.ts+++ b/sdk/javascript/src/resources/messages.ts@@ -10,6 +10,7 @@ import { encodeSegment } from '../http.js';import type { BinaryResponse } from '../http.js';import type { OpenWAClient } from '../client.js';import type {+ BatchCancelResponse,BatchStatusResponse,BulkMessageResponse,ChatHistoryMessage,@@ -275,8 +276,8 @@ export class MessagesResource {}/** Cancel a running batch. Requires an OPERATOR-level key. */- cancelBatch(sessionId: string, batchId: string): Promise<BatchStatusResponse> {- return this.client.request<BatchStatusResponse>({+ cancelBatch(sessionId: string, batchId: string): Promise<BatchCancelResponse> {+ return this.client.request<BatchCancelResponse>({method: 'POST',path: `/api/sessions/${encodeSegment(sessionId)}/messages/batch/${encodeSegment(batchId)}/cancel`,});diff --git a/sdk/javascript/src/types.ts b/sdk/javascript/src/types.tsindex 585c3f6b8..c7c6e54c8 100644--- a/sdk/javascript/src/types.ts+++ b/sdk/javascript/src/types.ts@@ -703,9 +703,8 @@ export interface BatchMessageResult {export type BatchMessageStatus = 'pending' | 'sent' | 'failed' | 'cancelled';/**- * Response from `GET /messages/batch/:batchId` (batch status polling) and- * `POST /messages/batch/:batchId/cancel`. Distinct from- * {@link BulkMessageResponse} (the send-bulk acknowledgement).+ * Response from `GET /messages/batch/:batchId` (batch status polling). Distinct from+ * {@link BulkMessageResponse} (the send-bulk acknowledgement) and {@link BatchCancelResponse}.*/export interface BatchStatusResponse {batchId: string;@@ -716,6 +715,13 @@ export interface BatchStatusResponse {completedAt?: string | null;}+/** Response from `POST /messages/batch/:batchId/cancel`: the batch state without per-recipient `results`. */+export interface BatchCancelResponse {+ batchId: string;+ status: BatchLifecycleStatus;+ progress: BatchProgress;+}+/** Lifecycle of a whole batch — the `status` of {@link BatchStatusResponse}. */export type BatchLifecycleStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled';diff --git a/sdk/javascript/test/messages.test.ts b/sdk/javascript/test/messages.test.tsindex 1b224e7d8..3679fe629 100644--- a/sdk/javascript/test/messages.test.ts+++ b/sdk/javascript/test/messages.test.ts@@ -1,5 +1,5 @@-import { describe, expect, it } from 'vitest';-import { OpenWAClient } from '../src';+import { describe, expect, expectTypeOf, it } from 'vitest';+import { OpenWAClient, type BatchCancelResponse } from '../src';import { MockTransport } from './helpers';function client(t: MockTransport): OpenWAClient {@@ -238,6 +238,8 @@ describe('MessagesResource — exact paths', () => {expect(status.progress?.sent).toBe(1);expect(t.lastCall!.url).toContain('/messages/batch/b');const cancelled = await c.messages.cancelBatch('s', 'b');+ // The cancel route answers without the per-recipient `results` the status route carries.+ expectTypeOf(cancelled).toEqualTypeOf<BatchCancelResponse>();expect(cancelled.status).toBe('cancelled');expect(t.lastCall!.url).toContain('/messages/batch/b/cancel');expect(t.lastCall!.method).toBe('POST');