From 175d3b40a491c873b244f648848fc05fd959a286 Mon Sep 17 00:00:00 2001 From: Maciej Walusiak Date: Mon, 23 Nov 2026 14:43:40 +0100 Subject: [PATCH 1/6] Add time and cursor options to the suppressions list, and the any stream Decisions: - The API already filters the list by start_time and end_time and pages it with last_id, but ListOptions only took email, so lists over 1000 rows couldn't be read past the first page - The API returns sending_stream "any" for opt-outs stored without a sending stream; create still takes only transactional or bulk, so its type excludes "any" Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- examples/sending/suppressions.ts | 14 ++++++++ .../lib/api/resources/Suppressions.test.ts | 36 +++++++++++++++++++ src/lib/api/resources/Suppressions.ts | 6 +++- src/types/api/suppressions.ts | 20 +++++++++-- 5 files changed, 74 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a7ee2dc..36e787b 100644 --- a/README.md +++ b/README.md @@ -280,7 +280,7 @@ General API: - Templates CRUD, paginated (experimental) – [`templates/everything.ts`](examples/templates/everything.ts) - Email templates CRUD (`/api/email_templates`) – [`templates/email-templates.ts`](examples/templates/email-templates.ts) -- Suppressions (create, find & delete) – [`sending/suppressions.ts`](examples/sending/suppressions.ts) +- Suppressions (create, find by email or date, paginate & delete) – [`sending/suppressions.ts`](examples/sending/suppressions.ts) - Tracking Opt-outs (list, create & delete) – [`sending/tracking-opt-outs.ts`](examples/sending/tracking-opt-outs.ts) - Billing info – [`general/billing.ts`](examples/general/billing.ts) - Accounts info – [`general/accounts.ts`](examples/general/accounts.ts) diff --git a/examples/sending/suppressions.ts b/examples/sending/suppressions.ts index ebae105..ba4eff2 100644 --- a/examples/sending/suppressions.ts +++ b/examples/sending/suppressions.ts @@ -17,6 +17,20 @@ async function suppressionsFlow() { const filteredSuppressions = await client.suppressions.getList({email: "test@example.com"}); console.log("Filtered suppressions:", filteredSuppressions); + // Get every suppression created in the last 30 days. A full page has 1000 + // rows; pass the last row's `id` as `last_id` to get the next one. + const startTime = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString(); + let page = await client.suppressions.getList({start_time: startTime}); + const recentSuppressions = [...page]; + while (page.length === 1000) { + page = await client.suppressions.getList({ + start_time: startTime, + last_id: page[page.length - 1].id + }); + recentSuppressions.push(...page); + } + console.log("Suppressions from the last 30 days:", recentSuppressions.length); + // Include contacts' unsubscriptions from single subscription topics, as // "topic unsubscription" rows with their `subscription_topic_id`. Needs a // token that can read contacts; without subscription topics there are none. diff --git a/src/__tests__/lib/api/resources/Suppressions.test.ts b/src/__tests__/lib/api/resources/Suppressions.test.ts index 2600bf9..2223d81 100644 --- a/src/__tests__/lib/api/resources/Suppressions.test.ts +++ b/src/__tests__/lib/api/resources/Suppressions.test.ts @@ -138,6 +138,42 @@ describe("lib/api/resources/Suppressions: ", () => { expect(result[2].subscription_topic_id).toEqual(12); }); + it("passes start_time, end_time and last_id when set.", async () => { + const endpoint = `${GENERAL_ENDPOINT}/api/accounts/${accountId}/suppressions`; + + expect.assertions(1); + + mock.onGet(endpoint).reply(200, mockSuppressions); + await suppressionsAPI.getList({ + start_time: "2023-01-01T00:00:00Z", + end_time: "2023-01-31T23:59:59Z", + last_id: "2", + }); + + expect(mock.history.get[0].params).toEqual({ + start_time: "2023-01-01T00:00:00Z", + end_time: "2023-01-31T23:59:59Z", + last_id: "2", + }); + }); + + it("returns rows stored without a sending stream as any.", async () => { + const endpoint = `${GENERAL_ENDPOINT}/api/accounts/${accountId}/suppressions`; + const anyStream: Suppression = { + ...mockSuppression, + id: "4", + type: "unsubscription", + sending_stream: "any", + }; + + expect.assertions(1); + + mock.onGet(endpoint).reply(200, [anyStream]); + const result = await suppressionsAPI.getList(); + + expect(result[0].sending_stream).toEqual("any"); + }); + it("sends nothing for include_topic_unsubscriptions: false.", async () => { const endpoint = `${GENERAL_ENDPOINT}/api/accounts/${accountId}/suppressions`; diff --git a/src/lib/api/resources/Suppressions.ts b/src/lib/api/resources/Suppressions.ts index 923d1f4..36bc269 100644 --- a/src/lib/api/resources/Suppressions.ts +++ b/src/lib/api/resources/Suppressions.ts @@ -22,11 +22,15 @@ export default class SuppressionsApi { } /** - * List and search suppressions by email. The endpoint returns up to 1000 suppressions per request. + * List suppressions, optionally filtered by email or creation time. The endpoint returns up to 1000 suppressions + * per request; pass the last one's `id` as `last_id` to get the next page. */ public async getList(options?: ListOptions) { const params = { ...(options?.email && { email: options.email }), + ...(options?.start_time && { start_time: options.start_time }), + ...(options?.end_time && { end_time: options.end_time }), + ...(options?.last_id && { last_id: options.last_id }), ...(options?.include_topic_unsubscriptions && { include_topic_unsubscriptions: true, }), diff --git a/src/types/api/suppressions.ts b/src/types/api/suppressions.ts index 5cd0676..9813d97 100644 --- a/src/types/api/suppressions.ts +++ b/src/types/api/suppressions.ts @@ -9,12 +9,18 @@ export type SuppressionType = | "manual import" | "topic unsubscription"; +/** + * `any` marks an opt-out stored without a sending stream; it can't be passed + * to `create`. + */ +export type SuppressionSendingStream = "transactional" | "bulk" | "any"; + export type Suppression = { id: string; type: SuppressionType; created_at: string; email: string; - sending_stream: "transactional" | "bulk"; + sending_stream: SuppressionSendingStream; domain_name: string | null; message_bounce_category: string | null; message_category: string | null; @@ -30,8 +36,18 @@ export type Suppression = { subscription_topic_id?: number | null; }; +/** + * The endpoint returns up to 1000 suppressions per request; page through + * larger lists by passing the last returned suppression's `id` as `last_id`. + */ export type ListOptions = { + /** Filters by exact address (case-insensitive). */ email?: string; + /** `start_time` and `end_time` bound `created_at` (ISO 8601); either one works alone. */ + start_time?: string; + end_time?: string; + /** Returns the suppressions after the one with this `id`, for cursor-based pagination. */ + last_id?: string; /** * Adds the contacts' unsubscriptions from single subscription topics, as * `topic unsubscription` rows. Needs a token that can read contacts. @@ -42,7 +58,7 @@ export type ListOptions = { export type CreateSuppressionParams = { email: string; domain_id: number; - sending_stream: "transactional" | "bulk"; + sending_stream: Exclude; type?: Exclude; }; From 67cb7085826442a9405ca832bb285e20f800becd Mon Sep 17 00:00:00 2001 From: Maciej Walusiak Date: Mon, 23 Nov 2026 22:08:10 +0100 Subject: [PATCH 2/6] Document start_time and end_time on their own Decisions: - A doc comment attaches only to the member after it, so end_time showed no description on hover; the other paired params in the SDK each get their own Co-Authored-By: Claude Opus 5.5 --- src/types/api/suppressions.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/types/api/suppressions.ts b/src/types/api/suppressions.ts index 9813d97..fb479fb 100644 --- a/src/types/api/suppressions.ts +++ b/src/types/api/suppressions.ts @@ -43,8 +43,9 @@ export type Suppression = { export type ListOptions = { /** Filters by exact address (case-insensitive). */ email?: string; - /** `start_time` and `end_time` bound `created_at` (ISO 8601); either one works alone. */ + /** Start of the `created_at` window (inclusive), ISO 8601, e.g. `2024-01-01T00:00:00Z`. */ start_time?: string; + /** End of the `created_at` window (inclusive), ISO 8601, e.g. `2024-01-31T23:59:59Z`. */ end_time?: string; /** Returns the suppressions after the one with this `id`, for cursor-based pagination. */ last_id?: string; From 4f2de537463b8b99fee5e2658bef9bf5592728df Mon Sep 17 00:00:00 2001 From: Maciej Walusiak Date: Mon, 23 Nov 2026 22:12:20 +0100 Subject: [PATCH 3/6] Build the suppression stream type on SendingStream Decisions: - create takes SendingStream and the read type adds "any" to it, so a value added only to what the API returns can't slip into create - The paging rule is already on getList and last_id, so ListOptions drops its own copy - The example pages with one getList call, so the filter is written once, and keeps a count instead of every row it only counts Co-Authored-By: Claude Opus 5.5 --- examples/sending/suppressions.ts | 21 +++++++++---------- .../lib/api/resources/Suppressions.test.ts | 18 +++++++--------- src/types/api/suppressions.ts | 10 ++++----- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/examples/sending/suppressions.ts b/examples/sending/suppressions.ts index ba4eff2..8a757f5 100644 --- a/examples/sending/suppressions.ts +++ b/examples/sending/suppressions.ts @@ -17,19 +17,18 @@ async function suppressionsFlow() { const filteredSuppressions = await client.suppressions.getList({email: "test@example.com"}); console.log("Filtered suppressions:", filteredSuppressions); - // Get every suppression created in the last 30 days. A full page has 1000 + // Count the suppressions created in the last 30 days. A full page has 1000 // rows; pass the last row's `id` as `last_id` to get the next one. const startTime = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString(); - let page = await client.suppressions.getList({start_time: startTime}); - const recentSuppressions = [...page]; - while (page.length === 1000) { - page = await client.suppressions.getList({ - start_time: startTime, - last_id: page[page.length - 1].id - }); - recentSuppressions.push(...page); - } - console.log("Suppressions from the last 30 days:", recentSuppressions.length); + let recentCount = 0; + let lastId: string | undefined; + let page; + do { + page = await client.suppressions.getList({start_time: startTime, last_id: lastId}); + recentCount += page.length; + lastId = page[page.length - 1]?.id; + } while (page.length === 1000); + console.log("Suppressions from the last 30 days:", recentCount); // Include contacts' unsubscriptions from single subscription topics, as // "topic unsubscription" rows with their `subscription_topic_id`. Needs a diff --git a/src/__tests__/lib/api/resources/Suppressions.test.ts b/src/__tests__/lib/api/resources/Suppressions.test.ts index 2223d81..4cac37b 100644 --- a/src/__tests__/lib/api/resources/Suppressions.test.ts +++ b/src/__tests__/lib/api/resources/Suppressions.test.ts @@ -141,20 +141,18 @@ describe("lib/api/resources/Suppressions: ", () => { it("passes start_time, end_time and last_id when set.", async () => { const endpoint = `${GENERAL_ENDPOINT}/api/accounts/${accountId}/suppressions`; - expect.assertions(1); - - mock.onGet(endpoint).reply(200, mockSuppressions); - await suppressionsAPI.getList({ + const params = { start_time: "2023-01-01T00:00:00Z", end_time: "2023-01-31T23:59:59Z", last_id: "2", - }); + }; - expect(mock.history.get[0].params).toEqual({ - start_time: "2023-01-01T00:00:00Z", - end_time: "2023-01-31T23:59:59Z", - last_id: "2", - }); + expect.assertions(1); + + mock.onGet(endpoint).reply(200, mockSuppressions); + await suppressionsAPI.getList(params); + + expect(mock.history.get[0].params).toEqual(params); }); it("returns rows stored without a sending stream as any.", async () => { diff --git a/src/types/api/suppressions.ts b/src/types/api/suppressions.ts index fb479fb..117370a 100644 --- a/src/types/api/suppressions.ts +++ b/src/types/api/suppressions.ts @@ -1,3 +1,5 @@ +import { SendingStream } from "./webhooks"; + /** * `topic unsubscription` rows are listed only with * `include_topic_unsubscriptions`, and can't be created or deleted. @@ -13,7 +15,7 @@ export type SuppressionType = * `any` marks an opt-out stored without a sending stream; it can't be passed * to `create`. */ -export type SuppressionSendingStream = "transactional" | "bulk" | "any"; +export type SuppressionSendingStream = SendingStream | "any"; export type Suppression = { id: string; @@ -36,10 +38,6 @@ export type Suppression = { subscription_topic_id?: number | null; }; -/** - * The endpoint returns up to 1000 suppressions per request; page through - * larger lists by passing the last returned suppression's `id` as `last_id`. - */ export type ListOptions = { /** Filters by exact address (case-insensitive). */ email?: string; @@ -59,7 +57,7 @@ export type ListOptions = { export type CreateSuppressionParams = { email: string; domain_id: number; - sending_stream: Exclude; + sending_stream: SendingStream; type?: Exclude; }; From 63704047318942d09a280af5bd7e9254b617f16f Mon Sep 17 00:00:00 2001 From: Maciej Walusiak Date: Tue, 24 Nov 2026 00:35:41 +0100 Subject: [PATCH 4/6] Page suppressions until an empty page in the example The API promises up to 1000 rows per request, not that a shorter page is the last one, so stopping on a short page could undercount. Co-Authored-By: Claude Opus 5.5 --- examples/sending/suppressions.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/sending/suppressions.ts b/examples/sending/suppressions.ts index 8a757f5..a42c8e7 100644 --- a/examples/sending/suppressions.ts +++ b/examples/sending/suppressions.ts @@ -17,17 +17,19 @@ async function suppressionsFlow() { const filteredSuppressions = await client.suppressions.getList({email: "test@example.com"}); console.log("Filtered suppressions:", filteredSuppressions); - // Count the suppressions created in the last 30 days. A full page has 1000 - // rows; pass the last row's `id` as `last_id` to get the next one. + // Count the suppressions created in the last 30 days. Each request returns + // up to 1000 rows; pass the last row's `id` as `last_id` to get the next + // ones, until a request returns none. const startTime = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString(); let recentCount = 0; - let lastId: string | undefined; - let page; - do { - page = await client.suppressions.getList({start_time: startTime, last_id: lastId}); + let page = await client.suppressions.getList({start_time: startTime}); + while (page.length > 0) { recentCount += page.length; - lastId = page[page.length - 1]?.id; - } while (page.length === 1000); + page = await client.suppressions.getList({ + start_time: startTime, + last_id: page[page.length - 1].id + }); + } console.log("Suppressions from the last 30 days:", recentCount); // Include contacts' unsubscriptions from single subscription topics, as From 360d94d257d514e48fb8500d5e4ff1cdab22517a Mon Sep 17 00:00:00 2001 From: Maciej Walusiak Date: Wed, 25 Nov 2026 12:44:37 +0100 Subject: [PATCH 5/6] Hold back suppressions paging in the example and README The API sorts each page by created_at after reading it and reorders rows from the same second, so the last row's id doesn't mark where the page ended: paging with last_id can return rows again and stall. Until the API returns a reliable cursor, the example reads one time-windowed page and the README no longer says it paginates. The option docs say what last_id does, and that start_time and end_time are not applied together with email. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- examples/sending/suppressions.ts | 16 +++------------- src/lib/api/resources/Suppressions.ts | 2 +- src/types/api/suppressions.ts | 15 ++++++++++++--- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 36e787b..142727f 100644 --- a/README.md +++ b/README.md @@ -280,7 +280,7 @@ General API: - Templates CRUD, paginated (experimental) – [`templates/everything.ts`](examples/templates/everything.ts) - Email templates CRUD (`/api/email_templates`) – [`templates/email-templates.ts`](examples/templates/email-templates.ts) -- Suppressions (create, find by email or date, paginate & delete) – [`sending/suppressions.ts`](examples/sending/suppressions.ts) +- Suppressions (create, find by email or date & delete) – [`sending/suppressions.ts`](examples/sending/suppressions.ts) - Tracking Opt-outs (list, create & delete) – [`sending/tracking-opt-outs.ts`](examples/sending/tracking-opt-outs.ts) - Billing info – [`general/billing.ts`](examples/general/billing.ts) - Accounts info – [`general/accounts.ts`](examples/general/accounts.ts) diff --git a/examples/sending/suppressions.ts b/examples/sending/suppressions.ts index a42c8e7..1dab094 100644 --- a/examples/sending/suppressions.ts +++ b/examples/sending/suppressions.ts @@ -17,20 +17,10 @@ async function suppressionsFlow() { const filteredSuppressions = await client.suppressions.getList({email: "test@example.com"}); console.log("Filtered suppressions:", filteredSuppressions); - // Count the suppressions created in the last 30 days. Each request returns - // up to 1000 rows; pass the last row's `id` as `last_id` to get the next - // ones, until a request returns none. + // Get suppressions created in the last 30 days (up to 1000 per request) const startTime = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString(); - let recentCount = 0; - let page = await client.suppressions.getList({start_time: startTime}); - while (page.length > 0) { - recentCount += page.length; - page = await client.suppressions.getList({ - start_time: startTime, - last_id: page[page.length - 1].id - }); - } - console.log("Suppressions from the last 30 days:", recentCount); + const recentSuppressions = await client.suppressions.getList({start_time: startTime}); + console.log("Suppressions from the last 30 days (up to 1000):", recentSuppressions); // Include contacts' unsubscriptions from single subscription topics, as // "topic unsubscription" rows with their `subscription_topic_id`. Needs a diff --git a/src/lib/api/resources/Suppressions.ts b/src/lib/api/resources/Suppressions.ts index 36bc269..07b4343 100644 --- a/src/lib/api/resources/Suppressions.ts +++ b/src/lib/api/resources/Suppressions.ts @@ -23,7 +23,7 @@ export default class SuppressionsApi { /** * List suppressions, optionally filtered by email or creation time. The endpoint returns up to 1000 suppressions - * per request; pass the last one's `id` as `last_id` to get the next page. + * per request. */ public async getList(options?: ListOptions) { const params = { diff --git a/src/types/api/suppressions.ts b/src/types/api/suppressions.ts index 117370a..f40d93b 100644 --- a/src/types/api/suppressions.ts +++ b/src/types/api/suppressions.ts @@ -41,11 +41,20 @@ export type Suppression = { export type ListOptions = { /** Filters by exact address (case-insensitive). */ email?: string; - /** Start of the `created_at` window (inclusive), ISO 8601, e.g. `2024-01-01T00:00:00Z`. */ + /** + * Start of the `created_at` window (inclusive), ISO 8601, e.g. + * `2024-01-01T00:00:00Z`. Not applied when `email` is set. + */ start_time?: string; - /** End of the `created_at` window (inclusive), ISO 8601, e.g. `2024-01-31T23:59:59Z`. */ + /** + * End of the `created_at` window (inclusive), ISO 8601, e.g. + * `2024-01-31T23:59:59Z`. Not applied when `email` is set. + */ end_time?: string; - /** Returns the suppressions after the one with this `id`, for cursor-based pagination. */ + /** + * Returns the suppressions after the one with this `id`. Suppressions created + * in the same second as that one can be returned again. + */ last_id?: string; /** * Adds the contacts' unsubscriptions from single subscription topics, as From cec49e7ddf06e0b167485ad793e1db2f0be4bec8 Mon Sep 17 00:00:00 2001 From: Maciej Walusiak Date: Wed, 25 Nov 2026 12:45:57 +0100 Subject: [PATCH 6/6] Keep the getList doc's two sentences on their own lines Co-Authored-By: Claude Opus 5.5 --- src/lib/api/resources/Suppressions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/api/resources/Suppressions.ts b/src/lib/api/resources/Suppressions.ts index 07b4343..d0ec48e 100644 --- a/src/lib/api/resources/Suppressions.ts +++ b/src/lib/api/resources/Suppressions.ts @@ -22,8 +22,8 @@ export default class SuppressionsApi { } /** - * List suppressions, optionally filtered by email or creation time. The endpoint returns up to 1000 suppressions - * per request. + * List suppressions, optionally filtered by email or creation time. + * The endpoint returns up to 1000 suppressions per request. */ public async getList(options?: ListOptions) { const params = {