Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(sdk-js): type catalog info and product as nullable
Yudhi Armyndharis173c2c54b44a
diff --git a/sdk/javascript/src/resources/catalog.ts b/sdk/javascript/src/resources/catalog.tsindex 032717701..b056653c1 100644--- a/sdk/javascript/src/resources/catalog.ts+++ b/sdk/javascript/src/resources/catalog.ts@@ -23,9 +23,9 @@ import type {export class CatalogResource {constructor(private readonly client: OpenWAClient) {}- /** Get the business catalog info. */- info(sessionId: string): Promise<CatalogInfo> {- return this.client.request<CatalogInfo>({+ /** Get the business catalog info, or `null` when the account has no catalog. */+ info(sessionId: string): Promise<CatalogInfo | null> {+ return this.client.request<CatalogInfo | null>({method: 'GET',path: `/api/sessions/${encodeSegment(sessionId)}/catalog`,});@@ -40,9 +40,9 @@ export class CatalogResource {});}- /** Get a single product by id. */- product(sessionId: string, productId: string): Promise<CatalogProduct> {- return this.client.request<CatalogProduct>({+ /** Get a single product by id, or `null` when no product in the catalog carries that id. */+ product(sessionId: string, productId: string): Promise<CatalogProduct | null> {+ return this.client.request<CatalogProduct | null>({method: 'GET',path: `/api/sessions/${encodeSegment(sessionId)}/catalog/products/${encodeSegment(productId)}`,});diff --git a/sdk/javascript/test/labels-channels-catalog.test.ts b/sdk/javascript/test/labels-channels-catalog.test.tsindex 85d619d24..97245a740 100644--- a/sdk/javascript/test/labels-channels-catalog.test.ts+++ b/sdk/javascript/test/labels-channels-catalog.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 CatalogInfo, type CatalogProduct } from '../src';import { MockTransport } from './helpers';function client(t: MockTransport): OpenWAClient {@@ -76,6 +76,18 @@ describe('CatalogResource — exact paths (note: catalog controller is session-rexpect(t.lastCall!.url).toBe('http://localhost:2785/api/sessions/s/catalog/products/p1');});+ it('types and resolves an empty catalog or product body as null', async () => {+ // The gateway answers 200 with an empty body when the account has no catalog or no product has the id.+ const t = new MockTransport().on('GET', /\/catalog(\/products\/p9)?$/, { status: 200 });+ const c = client(t);+ const info = await c.catalog.info('s');+ expectTypeOf(info).toEqualTypeOf<CatalogInfo | null>();+ expect(info).toBeNull();+ const product = await c.catalog.product('s', 'p9');+ expectTypeOf(product).toEqualTypeOf<CatalogProduct | null>();+ expect(product).toBeNull();+ });+it('sendProduct shares the messages path', async () => {const t = new MockTransport().on('POST', /\/messages\/send-product$/, { body: { messageId: 'm', timestamp: 1 } });