Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api-keys/api-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class ApiKeys {

async remove(id: string): Promise<RemoveApiKeyResponse> {
const data = await this.resend.delete<RemoveApiKeyResponseSuccess>(
`/api-keys/${id}`,
`/api-keys/${encodeURIComponent(id)}`,
);
return data;
}
Expand Down
7 changes: 4 additions & 3 deletions src/automation-runs/automation-runs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class AutomationRuns {
options: GetAutomationRunOptions,
): Promise<GetAutomationRunResponse> {
const data = await this.resend.get<GetAutomationRunResponseSuccess>(
`/automations/${options.automationId}/runs/${options.runId}`,
`/automations/${encodeURIComponent(options.automationId)}/runs/${encodeURIComponent(options.runId)}`,
);
return data;
}
Expand All @@ -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<ListAutomationRunsResponseSuccess>(url);
return data;
Expand Down
8 changes: 4 additions & 4 deletions src/automations/automations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ export class Automations {

async get(id: string): Promise<GetAutomationResponse> {
const data = await this.resend.get<GetAutomationResponseSuccess>(
`/automations/${id}`,
`/automations/${encodeURIComponent(id)}`,
);
return data;
}

async remove(id: string): Promise<RemoveAutomationResponse> {
const data = await this.resend.delete<RemoveAutomationResponseSuccess>(
`/automations/${id}`,
`/automations/${encodeURIComponent(id)}`,
);
return data;
}
Expand All @@ -103,15 +103,15 @@ export class Automations {
}

const data = await this.resend.patch<UpdateAutomationResponseSuccess>(
`/automations/${id}`,
`/automations/${encodeURIComponent(id)}`,
apiPayload,
);
return data;
}

async stop(id: string): Promise<StopAutomationResponse> {
const data = await this.resend.post<StopAutomationResponseSuccess>(
`/automations/${id}/stop`,
`/automations/${encodeURIComponent(id)}/stop`,
);
return data;
}
Expand Down
8 changes: 4 additions & 4 deletions src/broadcasts/broadcasts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class Broadcasts {
payload?: SendBroadcastOptions,
): Promise<SendBroadcastResponse> {
const data = await this.resend.post<SendBroadcastResponseSuccess>(
`/broadcasts/${id}/send`,
`/broadcasts/${encodeURIComponent(id)}/send`,
{ scheduled_at: payload?.scheduledAt },
);

Expand All @@ -86,14 +86,14 @@ export class Broadcasts {

async get(id: string): Promise<GetBroadcastResponse> {
const data = await this.resend.get<GetBroadcastResponseSuccess>(
`/broadcasts/${id}`,
`/broadcasts/${encodeURIComponent(id)}`,
);
return data;
}

async remove(id: string): Promise<RemoveBroadcastResponse> {
const data = await this.resend.delete<RemoveBroadcastResponseSuccess>(
`/broadcasts/${id}`,
`/broadcasts/${encodeURIComponent(id)}`,
);
return data;
}
Expand All @@ -107,7 +107,7 @@ export class Broadcasts {
}

const data = await this.resend.patch<UpdateBroadcastResponseSuccess>(
`/broadcasts/${id}`,
`/broadcasts/${encodeURIComponent(id)}`,
{
name: payload.name,
segment_id: payload.segmentId,
Expand Down
6 changes: 3 additions & 3 deletions src/contact-properties/contact-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class ContactProperties {
};
}
const response = await this.resend.get<GetContactPropertyResponseSuccess>(
`/contact-properties/${id}`,
`/contact-properties/${encodeURIComponent(id)}`,
);

if (response.data) {
Expand Down Expand Up @@ -116,7 +116,7 @@ export class ContactProperties {

const apiOptions = parseContactPropertyToApiOptions(payload);
const data = await this.resend.patch<UpdateContactPropertyResponseSuccess>(
`/contact-properties/${payload.id}`,
`/contact-properties/${encodeURIComponent(payload.id)}`,
apiOptions,
);
return data;
Expand All @@ -135,7 +135,7 @@ export class ContactProperties {
};
}
const data = await this.resend.delete<RemoveContactPropertyResponseSuccess>(
`/contact-properties/${id}`,
`/contact-properties/${encodeURIComponent(id)}`,
);
return data;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
}
},
{
"_id": "70c5e9377d072322ddac67f0c0bd118a",
"_id": "1a48bb48c19f8d09cd04bf4a03f1cfce",
"_order": 0,
"cache": {},
"request": {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
}
},
{
"_id": "8bd97c70e6262ff3457e940564a57c1d",
"_id": "2f94ae5b19cd9c94f1c06496b359fdfe",
"_order": 0,
"cache": {},
"request": {
Expand All @@ -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,
Expand Down Expand Up @@ -331,7 +331,7 @@
}
},
{
"_id": "2a82fb0d94b4d030d83a97cac5ebec39",
"_id": "c823249fe704ca057c26c0468aab6858",
"_order": 0,
"cache": {},
"request": {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
}
},
{
"_id": "70c5e9377d072322ddac67f0c0bd118a",
"_id": "1a48bb48c19f8d09cd04bf4a03f1cfce",
"_order": 0,
"cache": {},
"request": {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
}
},
{
"_id": "1fad80e2a22ff503e5f44f022f93de00",
"_id": "20dd181c0b8984945c9354cd579a2155",
"_order": 0,
"cache": {},
"request": {
Expand All @@ -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,
Expand Down Expand Up @@ -331,7 +331,7 @@
}
},
{
"_id": "bfb41970ab8f65d8dc3d5fe083c888f3",
"_id": "e334867c6fa64600a91ee7311b6037a0",
"_order": 0,
"cache": {},
"request": {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/contacts/contacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
26 changes: 13 additions & 13 deletions src/contacts/contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class Contacts {
}

const data = await this.resend.post<CreateContactResponseSuccess>(
`/audiences/${payload.audienceId}/contacts`,
`/audiences/${encodeURIComponent(payload.audienceId)}/contacts`,
{
unsubscribed: payload.unsubscribed,
email: payload.email,
Expand Down Expand Up @@ -109,15 +109,17 @@ 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<ListContactsResponseSuccess>(url);
return data;
}

async get(options: GetContactOptions): Promise<GetContactResponse> {
if (typeof options === 'string') {
return this.resend.get<GetContactResponseSuccess>(`/contacts/${options}`);
return this.resend.get<GetContactResponseSuccess>(
`/contacts/${encodeURIComponent(options)}`,
);
}

if (!options.id && !options.email) {
Expand All @@ -134,12 +136,12 @@ export class Contacts {

if (!options.audienceId) {
return this.resend.get<GetContactResponseSuccess>(
`/contacts/${options?.email ? options?.email : options?.id}`,
`/contacts/${encodeURIComponent(options.email ?? options.id ?? '')}`,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Using email ?? id changes fallback behavior and can route to an empty contact path when email is ""; fallback should prefer id in that case.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/contacts/contacts.ts, line 139:

<comment>Using `email ?? id` changes fallback behavior and can route to an empty contact path when `email` is `""`; fallback should prefer `id` in that case.</comment>

<file context>
@@ -134,12 +136,12 @@ export class Contacts {
     if (!options.audienceId) {
       return this.resend.get<GetContactResponseSuccess>(
-        `/contacts/${encodeURIComponent(options?.email ? options?.email : options?.id!)}`,
+        `/contacts/${encodeURIComponent(options.email ?? options.id ?? '')}`,
       );
     }
</file context>

);
}

return this.resend.get<GetContactResponseSuccess>(
`/audiences/${options.audienceId}/contacts/${options?.email ? options?.email : options?.id}`,
`/audiences/${encodeURIComponent(options.audienceId)}/contacts/${encodeURIComponent(options.email ?? options.id ?? '')}`,
);
}

Expand All @@ -158,7 +160,7 @@ export class Contacts {

if (!options.audienceId) {
const data = await this.resend.patch<UpdateContactResponseSuccess>(
`/contacts/${options?.email ? options?.email : options?.id}`,
`/contacts/${encodeURIComponent(options.email ?? options.id ?? '')}`,
{
unsubscribed: options.unsubscribed,
first_name: options.firstName,
Expand All @@ -170,7 +172,7 @@ export class Contacts {
}

const data = await this.resend.patch<UpdateContactResponseSuccess>(
`/audiences/${options.audienceId}/contacts/${options?.email ? options?.email : options?.id}`,
`/audiences/${encodeURIComponent(options.audienceId)}/contacts/${encodeURIComponent(options.email ?? options.id ?? '')}`,
{
unsubscribed: options.unsubscribed,
first_name: options.firstName,
Expand All @@ -184,7 +186,7 @@ export class Contacts {
async remove(payload: RemoveContactOptions): Promise<RemoveContactsResponse> {
if (typeof payload === 'string') {
return this.resend.delete<RemoveContactsResponseSuccess>(
`/contacts/${payload}`,
`/contacts/${encodeURIComponent(payload)}`,
);
}

Expand All @@ -202,14 +204,12 @@ export class Contacts {

if (!payload.audienceId) {
return this.resend.delete<RemoveContactsResponseSuccess>(
`/contacts/${payload?.email ? payload?.email : payload?.id}`,
`/contacts/${encodeURIComponent(payload.email ?? payload.id ?? '')}`,
);
}

return this.resend.delete<RemoveContactsResponseSuccess>(
`/audiences/${payload.audienceId}/contacts/${
payload?.email ? payload?.email : payload?.id
}`,
`/audiences/${encodeURIComponent(payload.audienceId)}/contacts/${encodeURIComponent(payload.email ?? payload.id ?? '')}`,
);
}
}
14 changes: 7 additions & 7 deletions src/contacts/segments/contact-segments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export class ContactSegments {
};
}

const identifier = options.email ? options.email : options.contactId;
const identifier = options.email ?? options.contactId ?? '';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Using nullish coalescing here can select an empty-string email over a valid contactId, producing an invalid /contacts//... path.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/contacts/segments/contact-segments.ts, line 37:

<comment>Using nullish coalescing here can select an empty-string email over a valid contactId, producing an invalid `/contacts//...` path.</comment>

<file context>
@@ -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
</file context>
Suggested change
const identifier = options.email ?? options.contactId ?? '';
const identifier = 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<ListContactSegmentsResponseSuccess>(url);
return data;
Expand All @@ -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<AddContactSegmentResponseSuccess>(
`/contacts/${identifier}/segments/${options.segmentId}`,
`/contacts/${encodeURIComponent(identifier)}/segments/${encodeURIComponent(options.segmentId)}`,
);
}

Expand All @@ -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<RemoveContactSegmentResponseSuccess>(
`/contacts/${identifier}/segments/${options.segmentId}`,
`/contacts/${encodeURIComponent(identifier)}/segments/${encodeURIComponent(options.segmentId)}`,
);
}
}
Loading
Loading