Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(sdk-js): treat a null idempotency key as no key
Yudhi Armyndharis7f52120a5c00
diff --git a/sdk/javascript/src/client.ts b/sdk/javascript/src/client.tsindex 08986aad9..ef76a634a 100644--- a/sdk/javascript/src/client.ts+++ b/sdk/javascript/src/client.ts@@ -114,7 +114,7 @@ export class OpenWAClient {/** Issue a raw request against the API. (Public for advanced use.) */request<T>(options: RequestOptions, idempotencyKey?: string): Promise<T> {- if (idempotencyKey !== undefined) {+ if (idempotencyKey !== undefined && idempotencyKey !== null) {if (typeof idempotencyKey !== 'string' ||idempotencyKey.length < 1 ||diff --git a/sdk/javascript/test/messages.test.ts b/sdk/javascript/test/messages.test.tsindex c34921055..96020ae55 100644--- a/sdk/javascript/test/messages.test.ts+++ b/sdk/javascript/test/messages.test.ts@@ -58,6 +58,13 @@ describe('MessagesResource idempotency keys', () => {expect(t.lastCall!.body).toEqual(originalBody);});+ it('treats a null key from an untyped caller as no key, as the Python and PHP SDKs do', async () => {+ const t = new MockTransport().on('POST', /\/messages\/send-text$/, { body: { messageId: 'm', timestamp: 1 } });+ const c = new OpenWAClient({ baseUrl: 'http://localhost', apiKey: 'k', fetch: t.asFetch() });+ await c.messages.sendText('s', { chatId: '[email protected]', text: 'hi' }, null as unknown as string);+ expect(t.lastCall!.headers['idempotency-key']).toBeUndefined();+ });+it('overrides a mixed-case default without changing later calls', async () => {const t = new MockTransport().on('POST', /send-text$/, { body: { messageId: 'm', timestamp: 1 } });const headers = { 'iDeMpOtEnCy-KeY': 'default-key', 'X-Trace': 'trace' };