From c050b0ab342fcfb215346046fc4d48f86c9a0fe8 Mon Sep 17 00:00:00 2001 From: Bu Kinoshita Date: Wed, 15 Apr 2026 18:52:59 +0000 Subject: [PATCH 1/2] fix: encode endpoint --- src/api-keys/api-keys.ts | 2 +- src/automation-runs/automation-runs.ts | 7 +++--- src/automations/automations.ts | 8 +++---- src/broadcasts/broadcasts.ts | 8 +++---- src/contact-properties/contact-properties.ts | 6 ++--- .../recording.har | 4 ++-- .../recording.har | 8 +++---- .../recording.har | 2 +- .../recording.har | 4 ++-- .../recording.har | 8 +++---- .../recording.har | 4 ++-- src/contacts/contacts.spec.ts | 2 +- src/contacts/contacts.ts | 24 +++++++++---------- src/contacts/segments/contact-segments.ts | 8 +++---- src/contacts/topics/contact-topics.ts | 6 ++--- src/domains/domains.ts | 8 +++---- src/emails/attachments/attachments.ts | 6 ++--- src/emails/emails.ts | 6 ++--- .../receiving/attachments/attachments.ts | 6 ++--- src/emails/receiving/receiving.ts | 2 +- src/logs/logs.ts | 2 +- src/segments/segments.ts | 4 ++-- src/templates/templates.ts | 10 ++++---- src/topics/topics.ts | 6 ++--- src/webhooks/webhooks.ts | 6 ++--- 25 files changed, 78 insertions(+), 79 deletions(-) diff --git a/src/api-keys/api-keys.ts b/src/api-keys/api-keys.ts index 1d332a7d..c0621d03 100644 --- a/src/api-keys/api-keys.ts +++ b/src/api-keys/api-keys.ts @@ -42,7 +42,7 @@ export class ApiKeys { async remove(id: string): Promise { const data = await this.resend.delete( - `/api-keys/${id}`, + `/api-keys/${encodeURIComponent(id)}`, ); return data; } diff --git a/src/automation-runs/automation-runs.ts b/src/automation-runs/automation-runs.ts index 9a50413d..cf8b611d 100644 --- a/src/automation-runs/automation-runs.ts +++ b/src/automation-runs/automation-runs.ts @@ -18,7 +18,7 @@ export class AutomationRuns { options: GetAutomationRunOptions, ): Promise { const data = await this.resend.get( - `/automations/${options.automationId}/runs/${options.runId}`, + `/automations/${encodeURIComponent(options.automationId)}/runs/${encodeURIComponent(options.runId)}`, ); return data; } @@ -37,9 +37,10 @@ export class AutomationRuns { } const qs = searchParams.toString(); + const safeAutomationId = encodeURIComponent(options.automationId); const url = qs - ? `/automations/${options.automationId}/runs?${qs}` - : `/automations/${options.automationId}/runs`; + ? `/automations/${safeAutomationId}/runs?${qs}` + : `/automations/${safeAutomationId}/runs`; const data = await this.resend.get(url); return data; diff --git a/src/automations/automations.ts b/src/automations/automations.ts index 159a9d65..b1db55dd 100644 --- a/src/automations/automations.ts +++ b/src/automations/automations.ts @@ -71,14 +71,14 @@ export class Automations { async get(id: string): Promise { const data = await this.resend.get( - `/automations/${id}`, + `/automations/${encodeURIComponent(id)}`, ); return data; } async remove(id: string): Promise { const data = await this.resend.delete( - `/automations/${id}`, + `/automations/${encodeURIComponent(id)}`, ); return data; } @@ -103,7 +103,7 @@ export class Automations { } const data = await this.resend.patch( - `/automations/${id}`, + `/automations/${encodeURIComponent(id)}`, apiPayload, ); return data; @@ -111,7 +111,7 @@ export class Automations { async stop(id: string): Promise { const data = await this.resend.post( - `/automations/${id}/stop`, + `/automations/${encodeURIComponent(id)}/stop`, ); return data; } diff --git a/src/broadcasts/broadcasts.ts b/src/broadcasts/broadcasts.ts index 018aa2a4..64d21ccc 100644 --- a/src/broadcasts/broadcasts.ts +++ b/src/broadcasts/broadcasts.ts @@ -67,7 +67,7 @@ export class Broadcasts { payload?: SendBroadcastOptions, ): Promise { const data = await this.resend.post( - `/broadcasts/${id}/send`, + `/broadcasts/${encodeURIComponent(id)}/send`, { scheduled_at: payload?.scheduledAt }, ); @@ -86,14 +86,14 @@ export class Broadcasts { async get(id: string): Promise { const data = await this.resend.get( - `/broadcasts/${id}`, + `/broadcasts/${encodeURIComponent(id)}`, ); return data; } async remove(id: string): Promise { const data = await this.resend.delete( - `/broadcasts/${id}`, + `/broadcasts/${encodeURIComponent(id)}`, ); return data; } @@ -107,7 +107,7 @@ export class Broadcasts { } const data = await this.resend.patch( - `/broadcasts/${id}`, + `/broadcasts/${encodeURIComponent(id)}`, { name: payload.name, segment_id: payload.segmentId, diff --git a/src/contact-properties/contact-properties.ts b/src/contact-properties/contact-properties.ts index 30d12ba3..e7b317ae 100644 --- a/src/contact-properties/contact-properties.ts +++ b/src/contact-properties/contact-properties.ts @@ -82,7 +82,7 @@ export class ContactProperties { }; } const response = await this.resend.get( - `/contact-properties/${id}`, + `/contact-properties/${encodeURIComponent(id)}`, ); if (response.data) { @@ -116,7 +116,7 @@ export class ContactProperties { const apiOptions = parseContactPropertyToApiOptions(payload); const data = await this.resend.patch( - `/contact-properties/${payload.id}`, + `/contact-properties/${encodeURIComponent(payload.id)}`, apiOptions, ); return data; @@ -135,7 +135,7 @@ export class ContactProperties { }; } const data = await this.resend.delete( - `/contact-properties/${id}`, + `/contact-properties/${encodeURIComponent(id)}`, ); return data; } diff --git a/src/contacts/__recordings__/Contacts-Integration-Tests-contacts-API-endpoint-get-retrieves-a-contact-by-email_2206692250/recording.har b/src/contacts/__recordings__/Contacts-Integration-Tests-contacts-API-endpoint-get-retrieves-a-contact-by-email_2206692250/recording.har index 7c92bfe4..2ee1305f 100644 --- a/src/contacts/__recordings__/Contacts-Integration-Tests-contacts-API-endpoint-get-retrieves-a-contact-by-email_2206692250/recording.har +++ b/src/contacts/__recordings__/Contacts-Integration-Tests-contacts-API-endpoint-get-retrieves-a-contact-by-email_2206692250/recording.har @@ -116,7 +116,7 @@ } }, { - "_id": "70c5e9377d072322ddac67f0c0bd118a", + "_id": "1a48bb48c19f8d09cd04bf4a03f1cfce", "_order": 0, "cache": {}, "request": { @@ -140,7 +140,7 @@ "httpVersion": "HTTP/1.1", "method": "GET", "queryString": [], - "url": "https://api.resend.com/contacts/test-get-by-email@example.com" + "url": "https://api.resend.com/contacts/test-get-by-email%40example.com" }, "response": { "bodySize": 221, diff --git a/src/contacts/__recordings__/Contacts-Integration-Tests-contacts-API-endpoint-remove-removes-a-contact-by-email_421891524/recording.har b/src/contacts/__recordings__/Contacts-Integration-Tests-contacts-API-endpoint-remove-removes-a-contact-by-email_421891524/recording.har index bb19f7d6..e7d047bb 100644 --- a/src/contacts/__recordings__/Contacts-Integration-Tests-contacts-API-endpoint-remove-removes-a-contact-by-email_421891524/recording.har +++ b/src/contacts/__recordings__/Contacts-Integration-Tests-contacts-API-endpoint-remove-removes-a-contact-by-email_421891524/recording.har @@ -224,7 +224,7 @@ } }, { - "_id": "8bd97c70e6262ff3457e940564a57c1d", + "_id": "2f94ae5b19cd9c94f1c06496b359fdfe", "_order": 0, "cache": {}, "request": { @@ -248,7 +248,7 @@ "httpVersion": "HTTP/1.1", "method": "DELETE", "queryString": [], - "url": "https://api.resend.com/audiences/d6a1792a-0a97-41aa-a3dd-7ebec2becceb/contacts/test-remove-by-email@example.com" + "url": "https://api.resend.com/audiences/d6a1792a-0a97-41aa-a3dd-7ebec2becceb/contacts/test-remove-by-email%40example.com" }, "response": { "bodySize": 80, @@ -331,7 +331,7 @@ } }, { - "_id": "2a82fb0d94b4d030d83a97cac5ebec39", + "_id": "c823249fe704ca057c26c0468aab6858", "_order": 0, "cache": {}, "request": { @@ -355,7 +355,7 @@ "httpVersion": "HTTP/1.1", "method": "GET", "queryString": [], - "url": "https://api.resend.com/audiences/d6a1792a-0a97-41aa-a3dd-7ebec2becceb/contacts/test-remove-by-email@example.com" + "url": "https://api.resend.com/audiences/d6a1792a-0a97-41aa-a3dd-7ebec2becceb/contacts/test-remove-by-email%40example.com" }, "response": { "bodySize": 67, diff --git a/src/contacts/__recordings__/Contacts-Integration-Tests-get-retrieves-a-contact-by-email_2183683318/recording.har b/src/contacts/__recordings__/Contacts-Integration-Tests-get-retrieves-a-contact-by-email_2183683318/recording.har index 26102539..d78ffa42 100644 --- a/src/contacts/__recordings__/Contacts-Integration-Tests-get-retrieves-a-contact-by-email_2183683318/recording.har +++ b/src/contacts/__recordings__/Contacts-Integration-Tests-get-retrieves-a-contact-by-email_2183683318/recording.har @@ -248,7 +248,7 @@ "httpVersion": "HTTP/1.1", "method": "GET", "queryString": [], - "url": "https://api.resend.com/audiences/b12a7fd8-7514-4893-8361-9ef21678dc4c/contacts/test-get-by-email@example.com" + "url": "https://api.resend.com/audiences/b12a7fd8-7514-4893-8361-9ef21678dc4c/contacts/test-get-by-email%40example.com" }, "response": { "bodySize": 205, diff --git a/src/contacts/__recordings__/Contacts-Integration-Tests-legacy-contacts-API-endpoint-get-retrieves-a-contact-by-email_321416205/recording.har b/src/contacts/__recordings__/Contacts-Integration-Tests-legacy-contacts-API-endpoint-get-retrieves-a-contact-by-email_321416205/recording.har index c04de58a..53cd90e9 100644 --- a/src/contacts/__recordings__/Contacts-Integration-Tests-legacy-contacts-API-endpoint-get-retrieves-a-contact-by-email_321416205/recording.har +++ b/src/contacts/__recordings__/Contacts-Integration-Tests-legacy-contacts-API-endpoint-get-retrieves-a-contact-by-email_321416205/recording.har @@ -224,7 +224,7 @@ } }, { - "_id": "70c5e9377d072322ddac67f0c0bd118a", + "_id": "1a48bb48c19f8d09cd04bf4a03f1cfce", "_order": 0, "cache": {}, "request": { @@ -248,7 +248,7 @@ "httpVersion": "HTTP/1.1", "method": "GET", "queryString": [], - "url": "https://api.resend.com/contacts/test-get-by-email@example.com" + "url": "https://api.resend.com/contacts/test-get-by-email%40example.com" }, "response": { "bodySize": 221, diff --git a/src/contacts/__recordings__/Contacts-Integration-Tests-legacy-contacts-API-endpoint-remove-removes-a-contact-by-email_1387333173/recording.har b/src/contacts/__recordings__/Contacts-Integration-Tests-legacy-contacts-API-endpoint-remove-removes-a-contact-by-email_1387333173/recording.har index fae6a7cc..d81c51db 100644 --- a/src/contacts/__recordings__/Contacts-Integration-Tests-legacy-contacts-API-endpoint-remove-removes-a-contact-by-email_1387333173/recording.har +++ b/src/contacts/__recordings__/Contacts-Integration-Tests-legacy-contacts-API-endpoint-remove-removes-a-contact-by-email_1387333173/recording.har @@ -224,7 +224,7 @@ } }, { - "_id": "1fad80e2a22ff503e5f44f022f93de00", + "_id": "20dd181c0b8984945c9354cd579a2155", "_order": 0, "cache": {}, "request": { @@ -248,7 +248,7 @@ "httpVersion": "HTTP/1.1", "method": "DELETE", "queryString": [], - "url": "https://api.resend.com/audiences/583da88a-79b0-407c-bb33-fe6b79487754/contacts/test-remove-by-email@example.com" + "url": "https://api.resend.com/audiences/583da88a-79b0-407c-bb33-fe6b79487754/contacts/test-remove-by-email%40example.com" }, "response": { "bodySize": 80, @@ -331,7 +331,7 @@ } }, { - "_id": "bfb41970ab8f65d8dc3d5fe083c888f3", + "_id": "e334867c6fa64600a91ee7311b6037a0", "_order": 0, "cache": {}, "request": { @@ -355,7 +355,7 @@ "httpVersion": "HTTP/1.1", "method": "GET", "queryString": [], - "url": "https://api.resend.com/audiences/583da88a-79b0-407c-bb33-fe6b79487754/contacts/test-remove-by-email@example.com" + "url": "https://api.resend.com/audiences/583da88a-79b0-407c-bb33-fe6b79487754/contacts/test-remove-by-email%40example.com" }, "response": { "bodySize": 67, diff --git a/src/contacts/__recordings__/Contacts-Integration-Tests-remove-removes-a-contact-by-email_1973365032/recording.har b/src/contacts/__recordings__/Contacts-Integration-Tests-remove-removes-a-contact-by-email_1973365032/recording.har index fd02682b..746d47fd 100644 --- a/src/contacts/__recordings__/Contacts-Integration-Tests-remove-removes-a-contact-by-email_1973365032/recording.har +++ b/src/contacts/__recordings__/Contacts-Integration-Tests-remove-removes-a-contact-by-email_1973365032/recording.har @@ -248,7 +248,7 @@ "httpVersion": "HTTP/1.1", "method": "DELETE", "queryString": [], - "url": "https://api.resend.com/audiences/3810aa6d-856d-42e7-b1cb-05a3b21b8db6/contacts/test-remove-by-email@example.com" + "url": "https://api.resend.com/audiences/3810aa6d-856d-42e7-b1cb-05a3b21b8db6/contacts/test-remove-by-email%40example.com" }, "response": { "bodySize": 80, @@ -355,7 +355,7 @@ "httpVersion": "HTTP/1.1", "method": "GET", "queryString": [], - "url": "https://api.resend.com/audiences/3810aa6d-856d-42e7-b1cb-05a3b21b8db6/contacts/test-remove-by-email@example.com" + "url": "https://api.resend.com/audiences/3810aa6d-856d-42e7-b1cb-05a3b21b8db6/contacts/test-remove-by-email%40example.com" }, "response": { "bodySize": 67, diff --git a/src/contacts/contacts.spec.ts b/src/contacts/contacts.spec.ts index 9a6201cb..61431d59 100644 --- a/src/contacts/contacts.spec.ts +++ b/src/contacts/contacts.spec.ts @@ -823,7 +823,7 @@ describe('Contacts', () => { `); expect(fetchMock).toHaveBeenCalledWith( - 'https://api.resend.com/contacts/team@resend.com', + 'https://api.resend.com/contacts/team%40resend.com', expect.objectContaining({ method: 'GET', headers: expect.any(Headers), diff --git a/src/contacts/contacts.ts b/src/contacts/contacts.ts index 7b0478bb..315386ba 100644 --- a/src/contacts/contacts.ts +++ b/src/contacts/contacts.ts @@ -68,7 +68,7 @@ export class Contacts { } const data = await this.resend.post( - `/audiences/${payload.audienceId}/contacts`, + `/audiences/${encodeURIComponent(payload.audienceId)}/contacts`, { unsubscribed: payload.unsubscribed, email: payload.email, @@ -109,15 +109,15 @@ export class Contacts { const queryString = buildPaginationQuery(options); const url = queryString - ? `/segments/${segmentId}/contacts?${queryString}` - : `/segments/${segmentId}/contacts`; + ? `/segments/${encodeURIComponent(segmentId)}/contacts?${queryString}` + : `/segments/${encodeURIComponent(segmentId)}/contacts`; const data = await this.resend.get(url); return data; } async get(options: GetContactOptions): Promise { if (typeof options === 'string') { - return this.resend.get(`/contacts/${options}`); + return this.resend.get(`/contacts/${encodeURIComponent(options)}`); } if (!options.id && !options.email) { @@ -134,12 +134,12 @@ export class Contacts { if (!options.audienceId) { return this.resend.get( - `/contacts/${options?.email ? options?.email : options?.id}`, + `/contacts/${encodeURIComponent(options?.email ? options?.email : options?.id!)}`, ); } return this.resend.get( - `/audiences/${options.audienceId}/contacts/${options?.email ? options?.email : options?.id}`, + `/audiences/${encodeURIComponent(options.audienceId)}/contacts/${encodeURIComponent((options?.email ? options?.email : options?.id)!)}`, ); } @@ -158,7 +158,7 @@ export class Contacts { if (!options.audienceId) { const data = await this.resend.patch( - `/contacts/${options?.email ? options?.email : options?.id}`, + `/contacts/${encodeURIComponent((options?.email ? options?.email : options?.id)!)}`, { unsubscribed: options.unsubscribed, first_name: options.firstName, @@ -170,7 +170,7 @@ export class Contacts { } const data = await this.resend.patch( - `/audiences/${options.audienceId}/contacts/${options?.email ? options?.email : options?.id}`, + `/audiences/${encodeURIComponent(options.audienceId)}/contacts/${encodeURIComponent((options?.email ? options?.email : options?.id)!)}`, { unsubscribed: options.unsubscribed, first_name: options.firstName, @@ -184,7 +184,7 @@ export class Contacts { async remove(payload: RemoveContactOptions): Promise { if (typeof payload === 'string') { return this.resend.delete( - `/contacts/${payload}`, + `/contacts/${encodeURIComponent(payload)}`, ); } @@ -202,14 +202,12 @@ export class Contacts { if (!payload.audienceId) { return this.resend.delete( - `/contacts/${payload?.email ? payload?.email : payload?.id}`, + `/contacts/${encodeURIComponent((payload?.email ? payload?.email : payload?.id)!)}`, ); } return this.resend.delete( - `/audiences/${payload.audienceId}/contacts/${ - payload?.email ? payload?.email : payload?.id - }`, + `/audiences/${encodeURIComponent(payload.audienceId)}/contacts/${encodeURIComponent((payload?.email ? payload?.email : payload?.id)!)}`, ); } } diff --git a/src/contacts/segments/contact-segments.ts b/src/contacts/segments/contact-segments.ts index bb04802f..f7e6f2ae 100644 --- a/src/contacts/segments/contact-segments.ts +++ b/src/contacts/segments/contact-segments.ts @@ -37,8 +37,8 @@ export class ContactSegments { const identifier = options.email ? options.email : options.contactId; const queryString = buildPaginationQuery(options); const url = queryString - ? `/contacts/${identifier}/segments?${queryString}` - : `/contacts/${identifier}/segments`; + ? `/contacts/${encodeURIComponent(identifier!)}/segments?${queryString}` + : `/contacts/${encodeURIComponent(identifier!)}/segments`; const data = await this.resend.get(url); return data; @@ -61,7 +61,7 @@ export class ContactSegments { const identifier = options.email ? options.email : options.contactId; return this.resend.post( - `/contacts/${identifier}/segments/${options.segmentId}`, + `/contacts/${encodeURIComponent(identifier!)}/segments/${encodeURIComponent(options.segmentId)}`, ); } @@ -82,7 +82,7 @@ export class ContactSegments { const identifier = options.email ? options.email : options.contactId; return this.resend.delete( - `/contacts/${identifier}/segments/${options.segmentId}`, + `/contacts/${encodeURIComponent(identifier!)}/segments/${encodeURIComponent(options.segmentId)}`, ); } } diff --git a/src/contacts/topics/contact-topics.ts b/src/contacts/topics/contact-topics.ts index 48bc551f..8c86e8b3 100644 --- a/src/contacts/topics/contact-topics.ts +++ b/src/contacts/topics/contact-topics.ts @@ -31,7 +31,7 @@ export class ContactTopics { const identifier = payload.email ? payload.email : payload.id; return this.resend.patch( - `/contacts/${identifier}/topics`, + `/contacts/${encodeURIComponent(identifier!)}/topics`, payload.topics, ); } @@ -54,8 +54,8 @@ export class ContactTopics { const identifier = options.email ? options.email : options.id; const queryString = buildPaginationQuery(options); const url = queryString - ? `/contacts/${identifier}/topics?${queryString}` - : `/contacts/${identifier}/topics`; + ? `/contacts/${encodeURIComponent(identifier!)}/topics?${queryString}` + : `/contacts/${encodeURIComponent(identifier!)}/topics`; return this.resend.get(url); } diff --git a/src/domains/domains.ts b/src/domains/domains.ts index e871d32e..aaf8f15e 100644 --- a/src/domains/domains.ts +++ b/src/domains/domains.ts @@ -55,7 +55,7 @@ export class Domains { async get(id: string): Promise { const data = await this.resend.get( - `/domains/${id}`, + `/domains/${encodeURIComponent(id)}`, ); return data; @@ -63,7 +63,7 @@ export class Domains { async update(payload: UpdateDomainsOptions): Promise { const data = await this.resend.patch( - `/domains/${payload.id}`, + `/domains/${encodeURIComponent(payload.id)}`, { click_tracking: payload.clickTracking, open_tracking: payload.openTracking, @@ -76,14 +76,14 @@ export class Domains { async remove(id: string): Promise { const data = await this.resend.delete( - `/domains/${id}`, + `/domains/${encodeURIComponent(id)}`, ); return data; } async verify(id: string): Promise { const data = await this.resend.post( - `/domains/${id}/verify`, + `/domains/${encodeURIComponent(id)}/verify`, ); return data; } diff --git a/src/emails/attachments/attachments.ts b/src/emails/attachments/attachments.ts index 960b9002..b2a8189c 100644 --- a/src/emails/attachments/attachments.ts +++ b/src/emails/attachments/attachments.ts @@ -16,7 +16,7 @@ export class Attachments { const { emailId, id } = options; const data = await this.resend.get( - `/emails/${emailId}/attachments/${id}`, + `/emails/${encodeURIComponent(emailId)}/attachments/${encodeURIComponent(id)}`, ); return data; @@ -29,8 +29,8 @@ export class Attachments { const queryString = buildPaginationQuery(options); const url = queryString - ? `/emails/${emailId}/attachments?${queryString}` - : `/emails/${emailId}/attachments`; + ? `/emails/${encodeURIComponent(emailId)}/attachments?${queryString}` + : `/emails/${encodeURIComponent(emailId)}/attachments`; const data = await this.resend.get(url); diff --git a/src/emails/emails.ts b/src/emails/emails.ts index 61a9dda7..bdbcca74 100644 --- a/src/emails/emails.ts +++ b/src/emails/emails.ts @@ -65,7 +65,7 @@ export class Emails { async get(id: string): Promise { const data = await this.resend.get( - `/emails/${id}`, + `/emails/${encodeURIComponent(id)}`, ); return data; @@ -82,7 +82,7 @@ export class Emails { async update(payload: UpdateEmailOptions): Promise { const data = await this.resend.patch( - `/emails/${payload.id}`, + `/emails/${encodeURIComponent(payload.id)}`, { scheduled_at: payload.scheduledAt, }, @@ -92,7 +92,7 @@ export class Emails { async cancel(id: string): Promise { const data = await this.resend.post( - `/emails/${id}/cancel`, + `/emails/${encodeURIComponent(id)}/cancel`, ); return data; } diff --git a/src/emails/receiving/attachments/attachments.ts b/src/emails/receiving/attachments/attachments.ts index 9bd1420b..90bdcf52 100644 --- a/src/emails/receiving/attachments/attachments.ts +++ b/src/emails/receiving/attachments/attachments.ts @@ -16,7 +16,7 @@ export class Attachments { const { emailId, id } = options; const data = await this.resend.get( - `/emails/receiving/${emailId}/attachments/${id}`, + `/emails/receiving/${encodeURIComponent(emailId)}/attachments/${encodeURIComponent(id)}`, ); return data; @@ -29,8 +29,8 @@ export class Attachments { const queryString = buildPaginationQuery(options); const url = queryString - ? `/emails/receiving/${emailId}/attachments?${queryString}` - : `/emails/receiving/${emailId}/attachments`; + ? `/emails/receiving/${encodeURIComponent(emailId)}/attachments?${queryString}` + : `/emails/receiving/${encodeURIComponent(emailId)}/attachments`; const data = await this.resend.get(url); diff --git a/src/emails/receiving/receiving.ts b/src/emails/receiving/receiving.ts index 22b76e4d..4b12e4b9 100644 --- a/src/emails/receiving/receiving.ts +++ b/src/emails/receiving/receiving.ts @@ -26,7 +26,7 @@ export class Receiving { async get(id: string): Promise { const data = await this.resend.get( - `/emails/receiving/${id}`, + `/emails/receiving/${encodeURIComponent(id)}`, ); return data; diff --git a/src/logs/logs.ts b/src/logs/logs.ts index 6767984d..0a5e7087 100644 --- a/src/logs/logs.ts +++ b/src/logs/logs.ts @@ -21,7 +21,7 @@ export class Logs { } async get(id: string): Promise { - const data = await this.resend.get(`/logs/${id}`); + const data = await this.resend.get(`/logs/${encodeURIComponent(id)}`); return data; } } diff --git a/src/segments/segments.ts b/src/segments/segments.ts index 5db4fce6..10e57aae 100644 --- a/src/segments/segments.ts +++ b/src/segments/segments.ts @@ -45,14 +45,14 @@ export class Segments { async get(id: string): Promise { const data = await this.resend.get( - `/segments/${id}`, + `/segments/${encodeURIComponent(id)}`, ); return data; } async remove(id: string): Promise { const data = await this.resend.delete( - `/segments/${id}`, + `/segments/${encodeURIComponent(id)}`, ); return data; } diff --git a/src/templates/templates.ts b/src/templates/templates.ts index 85551e66..f3e692dc 100644 --- a/src/templates/templates.ts +++ b/src/templates/templates.ts @@ -76,14 +76,14 @@ export class Templates { async remove(identifier: string): Promise { const data = await this.resend.delete( - `/templates/${identifier}`, + `/templates/${encodeURIComponent(identifier)}`, ); return data; } async get(identifier: string): Promise { const data = await this.resend.get( - `/templates/${identifier}`, + `/templates/${encodeURIComponent(identifier)}`, ); return data; } @@ -98,7 +98,7 @@ export class Templates { identifier: string, ): ChainableTemplateResult { const promiseDuplicate = this.resend.post( - `/templates/${identifier}/duplicate`, + `/templates/${encodeURIComponent(identifier)}/duplicate`, ); return new ChainableTemplateResult( promiseDuplicate, @@ -108,7 +108,7 @@ export class Templates { async publish(identifier: string): Promise { const data = await this.resend.post( - `/templates/${identifier}/publish`, + `/templates/${encodeURIComponent(identifier)}/publish`, ); return data; } @@ -118,7 +118,7 @@ export class Templates { payload: UpdateTemplateOptions, ): Promise { const data = await this.resend.patch( - `/templates/${identifier}`, + `/templates/${encodeURIComponent(identifier)}`, parseTemplateToApiOptions(payload), ); return data; diff --git a/src/topics/topics.ts b/src/topics/topics.ts index 528bd047..0787afff 100644 --- a/src/topics/topics.ts +++ b/src/topics/topics.ts @@ -55,7 +55,7 @@ export class Topics { }; } const data = await this.resend.get( - `/topics/${id}`, + `/topics/${encodeURIComponent(id)}`, ); return data; @@ -75,7 +75,7 @@ export class Topics { } const data = await this.resend.patch( - `/topics/${payload.id}`, + `/topics/${encodeURIComponent(payload.id)}`, payload, ); @@ -96,7 +96,7 @@ export class Topics { } const data = await this.resend.delete( - `/topics/${id}`, + `/topics/${encodeURIComponent(id)}`, ); return data; diff --git a/src/webhooks/webhooks.ts b/src/webhooks/webhooks.ts index c86acf4e..0b6c4ca6 100644 --- a/src/webhooks/webhooks.ts +++ b/src/webhooks/webhooks.ts @@ -56,7 +56,7 @@ export class Webhooks { async get(id: string): Promise { const data = await this.resend.get( - `/webhooks/${id}`, + `/webhooks/${encodeURIComponent(id)}`, ); return data; @@ -75,7 +75,7 @@ export class Webhooks { payload: UpdateWebhookOptions, ): Promise { const data = await this.resend.patch( - `/webhooks/${id}`, + `/webhooks/${encodeURIComponent(id)}`, payload, ); return data; @@ -83,7 +83,7 @@ export class Webhooks { async remove(id: string): Promise { const data = await this.resend.delete( - `/webhooks/${id}`, + `/webhooks/${encodeURIComponent(id)}`, ); return data; } From 951d8c66dbc4df176672e5847c162f1a3fe1875c Mon Sep 17 00:00:00 2001 From: Bu Kinoshita Date: Wed, 15 Apr 2026 19:19:28 +0000 Subject: [PATCH 2/2] fix: int --- src/contacts/contacts.ts | 16 +++++++++------- src/contacts/segments/contact-segments.ts | 14 +++++++------- src/contacts/topics/contact-topics.ts | 10 +++++----- src/logs/logs.ts | 4 +++- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/contacts/contacts.ts b/src/contacts/contacts.ts index 315386ba..787d1387 100644 --- a/src/contacts/contacts.ts +++ b/src/contacts/contacts.ts @@ -117,7 +117,9 @@ export class Contacts { async get(options: GetContactOptions): Promise { if (typeof options === 'string') { - return this.resend.get(`/contacts/${encodeURIComponent(options)}`); + return this.resend.get( + `/contacts/${encodeURIComponent(options)}`, + ); } if (!options.id && !options.email) { @@ -134,12 +136,12 @@ export class Contacts { if (!options.audienceId) { return this.resend.get( - `/contacts/${encodeURIComponent(options?.email ? options?.email : options?.id!)}`, + `/contacts/${encodeURIComponent(options.email ?? options.id ?? '')}`, ); } return this.resend.get( - `/audiences/${encodeURIComponent(options.audienceId)}/contacts/${encodeURIComponent((options?.email ? options?.email : options?.id)!)}`, + `/audiences/${encodeURIComponent(options.audienceId)}/contacts/${encodeURIComponent(options.email ?? options.id ?? '')}`, ); } @@ -158,7 +160,7 @@ export class Contacts { if (!options.audienceId) { const data = await this.resend.patch( - `/contacts/${encodeURIComponent((options?.email ? options?.email : options?.id)!)}`, + `/contacts/${encodeURIComponent(options.email ?? options.id ?? '')}`, { unsubscribed: options.unsubscribed, first_name: options.firstName, @@ -170,7 +172,7 @@ export class Contacts { } const data = await this.resend.patch( - `/audiences/${encodeURIComponent(options.audienceId)}/contacts/${encodeURIComponent((options?.email ? options?.email : options?.id)!)}`, + `/audiences/${encodeURIComponent(options.audienceId)}/contacts/${encodeURIComponent(options.email ?? options.id ?? '')}`, { unsubscribed: options.unsubscribed, first_name: options.firstName, @@ -202,12 +204,12 @@ export class Contacts { if (!payload.audienceId) { return this.resend.delete( - `/contacts/${encodeURIComponent((payload?.email ? payload?.email : payload?.id)!)}`, + `/contacts/${encodeURIComponent(payload.email ?? payload.id ?? '')}`, ); } return this.resend.delete( - `/audiences/${encodeURIComponent(payload.audienceId)}/contacts/${encodeURIComponent((payload?.email ? payload?.email : payload?.id)!)}`, + `/audiences/${encodeURIComponent(payload.audienceId)}/contacts/${encodeURIComponent(payload.email ?? payload.id ?? '')}`, ); } } diff --git a/src/contacts/segments/contact-segments.ts b/src/contacts/segments/contact-segments.ts index f7e6f2ae..84a0953d 100644 --- a/src/contacts/segments/contact-segments.ts +++ b/src/contacts/segments/contact-segments.ts @@ -34,11 +34,11 @@ export class ContactSegments { }; } - const identifier = options.email ? options.email : options.contactId; + const identifier = options.email ?? options.contactId ?? ''; const queryString = buildPaginationQuery(options); const url = queryString - ? `/contacts/${encodeURIComponent(identifier!)}/segments?${queryString}` - : `/contacts/${encodeURIComponent(identifier!)}/segments`; + ? `/contacts/${encodeURIComponent(identifier)}/segments?${queryString}` + : `/contacts/${encodeURIComponent(identifier)}/segments`; const data = await this.resend.get(url); return data; @@ -59,9 +59,9 @@ export class ContactSegments { }; } - const identifier = options.email ? options.email : options.contactId; + const identifier = options.email ?? options.contactId ?? ''; return this.resend.post( - `/contacts/${encodeURIComponent(identifier!)}/segments/${encodeURIComponent(options.segmentId)}`, + `/contacts/${encodeURIComponent(identifier)}/segments/${encodeURIComponent(options.segmentId)}`, ); } @@ -80,9 +80,9 @@ export class ContactSegments { }; } - const identifier = options.email ? options.email : options.contactId; + const identifier = options.email ?? options.contactId ?? ''; return this.resend.delete( - `/contacts/${encodeURIComponent(identifier!)}/segments/${encodeURIComponent(options.segmentId)}`, + `/contacts/${encodeURIComponent(identifier)}/segments/${encodeURIComponent(options.segmentId)}`, ); } } diff --git a/src/contacts/topics/contact-topics.ts b/src/contacts/topics/contact-topics.ts index 8c86e8b3..fd37210b 100644 --- a/src/contacts/topics/contact-topics.ts +++ b/src/contacts/topics/contact-topics.ts @@ -29,9 +29,9 @@ export class ContactTopics { }; } - const identifier = payload.email ? payload.email : payload.id; + const identifier = payload.email ?? payload.id ?? ''; return this.resend.patch( - `/contacts/${encodeURIComponent(identifier!)}/topics`, + `/contacts/${encodeURIComponent(identifier)}/topics`, payload.topics, ); } @@ -51,11 +51,11 @@ export class ContactTopics { }; } - const identifier = options.email ? options.email : options.id; + const identifier = options.email ?? options.id ?? ''; const queryString = buildPaginationQuery(options); const url = queryString - ? `/contacts/${encodeURIComponent(identifier!)}/topics?${queryString}` - : `/contacts/${encodeURIComponent(identifier!)}/topics`; + ? `/contacts/${encodeURIComponent(identifier)}/topics?${queryString}` + : `/contacts/${encodeURIComponent(identifier)}/topics`; return this.resend.get(url); } diff --git a/src/logs/logs.ts b/src/logs/logs.ts index 0a5e7087..e540d978 100644 --- a/src/logs/logs.ts +++ b/src/logs/logs.ts @@ -21,7 +21,9 @@ export class Logs { } async get(id: string): Promise { - const data = await this.resend.get(`/logs/${encodeURIComponent(id)}`); + const data = await this.resend.get( + `/logs/${encodeURIComponent(id)}`, + ); return data; } }