Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(sdk): gate the JS request bodies against the contract and fix three drifts
Yudhi Armyndharis299dd7b3f682
diff --cc scripts/check-contract-shapes.mjsindex 438652349,19ab8b2fe..3f9a85c75--- a/scripts/check-contract-shapes.mjs+++ b/scripts/check-contract-shapes.mjs@@@ -60,7 -60,8 +60,64 @@@ const MAPPINGS =GroupParticipant: 'GroupParticipantDto',GroupSummary: 'GroupSummaryDto',MessageListResponse: 'MessageListResponseDto',+ MessageRecord: 'MessageListItemDto',MessageResponse: 'MessageResponseDto',++ // Request-side pairs: every *Request interface with a matching DTO, plus the filter-condition++ // shape. Two requests have NO named schema (inline objects on their routes) and stay unmapped:++ // AddLabelRequest (POST /labels/chat/:chatId) and SubscribeChannelRequest (POST /channels/subscribe).++ ArchiveChatRequest: 'ArchiveChatDto',++ BulkMediaRequest: 'BulkMediaDto',++ CreateCallLinkRequest: 'CreateCallLinkDto',++ CreateChannelRequest: 'CreateChannelDto',++ CreateGroupRequest: 'CreateGroupDto',++ CreateSessionRequest: 'CreateSessionDto',++ CreateTemplateRequest: 'CreateTemplateDto',++ CreateWebhookRequest: 'CreateWebhookDto',++ DeleteChatRequest: 'DeleteChatDto',++ DeleteMessageRequest: 'DeleteMessageDto',++ DemoteChannelAdminRequest: 'DemoteChannelAdminDto',++ EditMessageRequest: 'EditMessageDto',++ ForwardMessageRequest: 'ForwardMessageDto',++ GroupDescriptionRequest: 'GroupDescriptionDto',++ GroupMembershipRequest: 'GroupMembershipRequestDto',++ GroupSubjectRequest: 'GroupSubjectDto',++ JoinGroupRequest: 'JoinGroupDto',++ MarkChatRequest: 'MarkChatReadDto',++ MuteChannelRequest: 'MuteChannelDto',++ MuteChatRequest: 'MuteChatDto',++ ParticipantsRequest: 'ParticipantsDto',++ PinChatRequest: 'PinChatDto',++ PinMessageRequest: 'PinMessageDto',++ ReactMessageRequest: 'ReactMessageDto',++ ReplyMessageRequest: 'ReplyMessageDto',++ RequestPairingCodeRequest: 'RequestPairingCodeDto',++ SendAudioRequest: 'SendAudioMessageDto',++ SendBulkRequest: 'SendBulkMessageDto',++ SendChatStateRequest: 'SendChatStateDto',++ SendContactRequest: 'SendContactDto',++ SendImageStatusRequest: 'SendImageStatusDto',++ SendLocationRequest: 'SendLocationDto',++ SendMediaRequest: 'SendMediaMessageDto',++ SendPollRequest: 'SendPollDto',++ SendProductRequest: 'SendProductDto',++ SendTemplateRequest: 'SendTemplateMessageDto',++ SendTextRequest: 'SendTextMessageDto',++ SendTextStatusRequest: 'SendTextStatusDto',++ SendVideoStatusRequest: 'SendVideoStatusDto',++ SendVoiceStatusRequest: 'SendVoiceStatusDto',++ SetGroupPictureRequest: 'SetGroupPictureDto',++ SetOwnPresenceRequest: 'SetOwnPresenceDto',++ SetProfileNameRequest: 'SetProfileNameDto',++ SetProfilePictureRequest: 'SetProfilePictureDto',++ SetProfileStatusRequest: 'SetProfileStatusDto',++ StarMessageRequest: 'StarMessageDto',++ TransferChannelOwnershipRequest: 'TransferChannelOwnershipDto',++ UnpinMessageRequest: 'UnpinMessageDto',++ UpdateSessionConfigRequest: 'UpdateSessionConfigDto',++ UpsertContactRequest: 'UpsertContactDto',++ UpsertLabelRequest: 'UpsertLabelDto',++ VotePollRequest: 'VotePollDto',++ WebhookFilterCondition: 'WebhookFilterConditionDto',PairingCodeResponse: 'PairingCodeResponseDto',ParticipantPresence: 'ParticipantPresenceDto',ProfilePictureResponse: 'ProfilePictureResponseDto',@@@ -101,11 -102,11 +158,11 @@@* these floors as pairs are added makes the shrink loud.*/const MINIMUM_MAPPED = {- 'sdk/javascript/src/types.ts': 24,- 'sdk/javascript/src/types.ts': 25,++ 'sdk/javascript/src/types.ts': 78,'dashboard/src/services/api.ts': 20,- 'sdk/python/openwa/types.py': 22,- 'sdk/go': 24,- 'sdk/java': 24,+ 'sdk/python/openwa/types.py': 23,+ 'sdk/go': 25,+ 'sdk/java': 25,};/** Known drift, deliberately not gated yet — each line is a to-adjudicate follow-up. */diff --cc sdk/javascript/src/types.tsindex 4e96d5f2b,7590e0471..f940b305c--- a/sdk/javascript/src/types.ts+++ b/sdk/javascript/src/types.ts@@@ -265,6 -265,6 +265,8 @@@ export interface SendMediaRequest* stored. An id the engine cannot resolve fails the send rather than delivering it unquoted.*/quotedMessageId?: string;++ /** WIDs to @mention; the caption must also contain the @<number> token. */++ mentions?: string[];}export interface SendAudioRequest extends SendMediaRequest {@@@ -862,7 -870,7 +872,7 @@@ export type WebhookEventexport interface WebhookFilterCondition {field: string;-- operator: string;++ operator: 'contains' | 'equals' | 'is' | 'isNot';/*** Polymorphic per field kind: a single string (text fields), a string array* (id/idArray/enum fields), or a boolean (boolean fields).@@@ -1018,8 -1026,8 +1028,8 @@@ export interface SendTextStatusRequestrecipients?: string[];/** Hex background color, e.g. `#25D366`. */backgroundColor?: string;-- /** Font index supported by WhatsApp status. */-- font?: number;++ /** WhatsApp status font family: 0 (default), 1, 2, 6 (bold), 7, 8, 9, 10. */++ font?: 0 | 1 | 2 | 6 | 7 | 8 | 9 | 10;}/** Media payload for a status post: provide `url` OR `base64`. */diff --cc sdk/javascript/test/resources.test.tsindex d2ca89058,d2ca89058..1bc080bd4--- a/sdk/javascript/test/resources.test.ts+++ b/sdk/javascript/test/resources.test.ts@@@ -1,5 -1,5 +1,6 @@@import { describe, expect, it } from 'vitest';import { OpenWAClient } from '../src';++import type { WebhookFilters } from '../src/types';import { MockTransport } from './helpers';function client(t: MockTransport): OpenWAClient {@@@ -226,7 -226,7 +227,17 @@@ describe('WebhooksResource — exact pabody: { id: 'w1', sessionId: 's', url: 'u', events: ['*'], active: true, createdAt: '', updatedAt: '' },}).on('POST', /\/webhooks$/, {-- body: { id: 'w1', sessionId: 's', url: 'u', events: ['*'], active: true, retryCount: 5, lastTriggeredAt: null, createdAt: '', updatedAt: '' },++ body: {++ id: 'w1',++ sessionId: 's',++ url: 'u',++ events: ['*'],++ active: true,++ retryCount: 5,++ lastTriggeredAt: null,++ createdAt: '',++ updatedAt: '',++ },}).on('PUT', /\/webhooks\/w1$/, {body: { id: 'w1', sessionId: 's', url: 'u', events: ['*'], active: false, createdAt: '', updatedAt: '' },@@@ -253,7 -253,7 +264,7 @@@const t = new MockTransport().on('POST', /\/webhooks$/, {body: { id: 'w1', sessionId: 's', url: 'u', events: ['*'], active: true, createdAt: '', updatedAt: '' },});-- const filters = {++ const filters: WebhookFilters = {conditions: [{ field: 'sender', operator: 'is', value: ['[email protected]'] },{ field: 'body', operator: 'contains', value: 'invoice', caseSensitive: true },@@@ -268,8 -268,8 +279,12 @@@describe('StatusResource — nested media bodies', () => {it('sendImage/sendVideo forward the server-required nested {image|video:{...}} shape', async () => {const t = new MockTransport()-- .on('POST', /\/status\/send-image$/, { body: { statusId: 's1', timestamp: '2025-01-01T00:00:00.000Z', expiresAt: '2025-01-02T00:00:00.000Z' } })-- .on('POST', /\/status\/send-video$/, { body: { statusId: 's2', timestamp: '2025-01-01T00:00:00.000Z', expiresAt: '2025-01-02T00:00:00.000Z' } });++ .on('POST', /\/status\/send-image$/, {++ body: { statusId: 's1', timestamp: '2025-01-01T00:00:00.000Z', expiresAt: '2025-01-02T00:00:00.000Z' },++ })++ .on('POST', /\/status\/send-video$/, {++ body: { statusId: 's2', timestamp: '2025-01-01T00:00:00.000Z', expiresAt: '2025-01-02T00:00:00.000Z' },++ });const c = client(t);await c.status.sendImage('s', { image: { url: 'http://img' }, recipients: ['[email protected]'], caption: 'hi' });expect(t.lastCall!.body).toEqual({ image: { url: 'http://img' }, recipients: ['[email protected]'], caption: 'hi' });@@@ -453,7 -453,7 +468,9 @@@ describe('HealthResource + auth — exadescribe('CallsResource — call link', () => {it('createLink posts to /calls/link with the type and start time', async () => {-- const t = new MockTransport().on('POST', /\/calls\/link$/, { body: { link: 'https://call.whatsapp.com/video/AbC' } });++ const t = new MockTransport().on('POST', /\/calls\/link$/, {++ body: { link: 'https://call.whatsapp.com/video/AbC' },++ });const res = await client(t).calls.createLink('s', { type: 'video', startTime: 1800000000000 });expect(t.lastCall!.method).toBe('POST');