From 219f3d54270a9ef4bd93f42e7f0cf5262f81d60e Mon Sep 17 00:00:00 2001 From: isra el Date: Sun, 9 Aug 2026 09:37:18 +0300 Subject: [PATCH] fix: correct the Message type union to the casing the API sends The API returns SENT and RECEIVED uppercase, so `type: 'sent' | 'received'` made every comparison a consumer writes against it fail silently while typechecking cleanly. The filter accepted by getMessages stays lowercase, so the README and the test now show both sides of that asymmetry. Also makes status optional, since messages stored before status tracking carry no value, and drops the stale version reference in the readme. Co-Authored-By: Claude Opus 5 (1M context) --- README.md | 7 +++++-- package.json | 2 +- src/types.ts | 9 +++++++-- test/client.test.ts | 4 +++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f4759d0..922727a 100644 --- a/README.md +++ b/README.md @@ -74,12 +74,15 @@ await textbee.setDefaultDevice(deviceId) ```js // Paginated history, filterable and searchable const { data, meta } = await textbee.getMessages(deviceId, { - type: 'received', // 'all' | 'sent' | 'received' + type: 'received', // filter is lowercase: 'all' | 'sent' | 'received' page: 1, limit: 50, search: 'invoice', }) +// Each message reports its direction uppercase, so compare accordingly +data.filter((m) => m.type === 'RECEIVED') + // A single message and its current status const sms = await textbee.getSms(deviceId, smsId) @@ -137,7 +140,7 @@ new Textbee({ ## What is not covered yet -v0.0.1 focuses on sending and reading messages. Bulk send and a few device operations are still REST only, documented at [textbee.dev/docs](https://textbee.dev/docs). +The SDK focuses on sending and reading messages. Bulk send and a few device operations are still REST only, documented at [textbee.dev/docs](https://textbee.dev/docs). ## License diff --git a/package.json b/package.json index 1011440..cfe8fc0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@textbee/sdk", - "version": "0.0.2", + "version": "0.0.3", "description": "Official JavaScript SDK for textbee.dev, the open source SMS gateway", "license": "MIT", "packageManager": "pnpm@9.14.2", diff --git a/src/types.ts b/src/types.ts index ea44690..bd13799 100644 --- a/src/types.ts +++ b/src/types.ts @@ -100,8 +100,13 @@ export interface Device { export interface Message { _id: string message: string - type: 'sent' | 'received' - status: + /** + * Direction, uppercase. Note the asymmetry with the `type` filter accepted by + * getMessages, which is lowercase. + */ + type: 'SENT' | 'RECEIVED' + /** Lowercase, and absent on messages stored before status tracking. */ + status?: | 'pending' | 'dispatched' | 'sent' diff --git a/test/client.test.ts b/test/client.test.ts index b6d6da7..ca68b71 100644 --- a/test/client.test.ts +++ b/test/client.test.ts @@ -187,8 +187,10 @@ describe('telemetry headers', () => { describe('response envelopes', () => { it('returns getMessages as { data, meta } because it has no outer wrapper', async () => { + // The response carries the direction uppercase while the query filter + // below stays lowercase. That asymmetry is the API's, not a typo here. const page = { - data: [{ _id: 'sms-1', message: 'hi', type: 'received', status: 'received' }], + data: [{ _id: 'sms-1', message: 'hi', type: 'RECEIVED', status: 'received' }], meta: { page: 2, limit: 10, total: 11, totalPages: 2 }, } fetchMock.mockImplementation(async () => respond(200, page))