Skip to content

Commit 6c06191

Browse files
committed
chore: revert rateLimiting API to avoid blocking release channel (#618)
1 parent 05303fb commit 6c06191

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+685
-724
lines changed

src/api-keys/api-keys.spec.ts

Lines changed: 49 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import type { ErrorResponse } from '../interfaces';
22
import { Resend } from '../resend';
3-
import {
4-
mockErrorResponse,
5-
mockSuccessResponse,
6-
} from '../test-utils/mock-fetch';
3+
import { mockSuccessResponse } from '../test-utils/mock-fetch';
74
import type {
85
CreateApiKeyOptions,
96
CreateApiKeyResponseSuccess,
@@ -22,8 +19,12 @@ describe('API Keys', () => {
2219
id: '430eed87-632a-4ea6-90db-0aace67ec228',
2320
};
2421

25-
mockSuccessResponse(response, {
26-
headers: { Authorization: 'Bearer re_924b3rjh2387fbewf823' },
22+
fetchMock.mockOnce(JSON.stringify(response), {
23+
status: 201,
24+
headers: {
25+
'content-type': 'application/json',
26+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
27+
},
2728
});
2829

2930
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
@@ -37,11 +38,6 @@ describe('API Keys', () => {
3738
"token": "re_PKr4RCko_Lhm9ost2YjNCctnPjbLw8Nqk",
3839
},
3940
"error": null,
40-
"rateLimiting": {
41-
"limit": 2,
42-
"remainingRequests": 2,
43-
"shouldResetAfter": 1,
44-
},
4541
}
4642
`);
4743
});
@@ -55,8 +51,12 @@ describe('API Keys', () => {
5551
name: 'validation_error',
5652
};
5753

58-
mockErrorResponse(response, {
59-
headers: { Authorization: 'Bearer re_924b3rjh2387fbewf823' },
54+
fetchMock.mockOnce(JSON.stringify(response), {
55+
status: 422,
56+
headers: {
57+
'content-type': 'application/json',
58+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
59+
},
6060
});
6161

6262
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
@@ -70,11 +70,6 @@ describe('API Keys', () => {
7070
"message": "String must contain at least 1 character(s)",
7171
"name": "validation_error",
7272
},
73-
"rateLimiting": {
74-
"limit": 2,
75-
"remainingRequests": 2,
76-
"shouldResetAfter": 1,
77-
},
7873
}
7974
`);
8075
});
@@ -91,8 +86,12 @@ describe('API Keys', () => {
9186
id: '430eed87-632a-4ea6-90db-0aace67ec228',
9287
};
9388

94-
mockSuccessResponse(response, {
95-
headers: { Authorization: 'Bearer re_924b3rjh2387fbewf823' },
89+
fetchMock.mockOnce(JSON.stringify(response), {
90+
status: 201,
91+
headers: {
92+
'content-type': 'application/json',
93+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
94+
},
9695
});
9796

9897
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
@@ -106,11 +105,6 @@ describe('API Keys', () => {
106105
"token": "re_PKr4RCko_Lhm9ost2YjNCctnPjbLw8Nqk",
107106
},
108107
"error": null,
109-
"rateLimiting": {
110-
"limit": 2,
111-
"remainingRequests": 2,
112-
"shouldResetAfter": 1,
113-
},
114108
}
115109
`);
116110
});
@@ -125,8 +119,12 @@ describe('API Keys', () => {
125119
id: '430eed87-632a-4ea6-90db-0aace67ec228',
126120
};
127121

128-
mockSuccessResponse(response, {
129-
headers: { Authorization: 'Bearer re_924b3rjh2387fbewf823' },
122+
fetchMock.mockOnce(JSON.stringify(response), {
123+
status: 201,
124+
headers: {
125+
'content-type': 'application/json',
126+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
127+
},
130128
});
131129

132130
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
@@ -140,11 +138,6 @@ describe('API Keys', () => {
140138
"token": "re_PKr4RCko_Lhm9ost2YjNCctnPjbLw8Nqk",
141139
},
142140
"error": null,
143-
"rateLimiting": {
144-
"limit": 2,
145-
"remainingRequests": 2,
146-
"shouldResetAfter": 1,
147-
},
148141
}
149142
`);
150143
});
@@ -155,8 +148,12 @@ describe('API Keys', () => {
155148
message: 'Access must be "full_access" | "sending_access"',
156149
};
157150

158-
mockErrorResponse(response, {
159-
headers: { Authorization: 'Bearer re_924b3rjh2387fbewf823' },
151+
fetchMock.mockOnce(JSON.stringify(response), {
152+
status: 422,
153+
headers: {
154+
'content-type': 'application/json',
155+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
156+
},
160157
});
161158

162159
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
@@ -175,11 +172,6 @@ describe('API Keys', () => {
175172
"message": "Access must be "full_access" | "sending_access"",
176173
"name": "invalid_access",
177174
},
178-
"rateLimiting": {
179-
"limit": 2,
180-
"remainingRequests": 2,
181-
"shouldResetAfter": 1,
182-
},
183175
}
184176
`);
185177
});
@@ -291,11 +283,6 @@ describe('API Keys', () => {
291283
expect(result).toEqual({
292284
data: response,
293285
error: null,
294-
rateLimiting: {
295-
limit: 2,
296-
remainingRequests: 2,
297-
shouldResetAfter: 1,
298-
},
299286
});
300287

301288
expect(fetchMock).toHaveBeenCalledWith(
@@ -319,11 +306,6 @@ describe('API Keys', () => {
319306
expect(result).toEqual({
320307
data: response,
321308
error: null,
322-
rateLimiting: {
323-
limit: 2,
324-
remainingRequests: 2,
325-
shouldResetAfter: 1,
326-
},
327309
});
328310

329311
expect(fetchMock).toHaveBeenCalledWith(
@@ -348,11 +330,6 @@ describe('API Keys', () => {
348330
expect(result).toEqual({
349331
data: response,
350332
error: null,
351-
rateLimiting: {
352-
limit: 2,
353-
remainingRequests: 2,
354-
shouldResetAfter: 1,
355-
},
356333
});
357334

358335
expect(fetchMock).toHaveBeenCalledWith(
@@ -377,11 +354,6 @@ describe('API Keys', () => {
377354
expect(result).toEqual({
378355
data: response,
379356
error: null,
380-
rateLimiting: {
381-
limit: 2,
382-
remainingRequests: 2,
383-
shouldResetAfter: 1,
384-
},
385357
});
386358

387359
expect(fetchMock).toHaveBeenCalledWith(
@@ -400,8 +372,12 @@ describe('API Keys', () => {
400372
const response: RemoveApiKeyResponseSuccess = {};
401373

402374
it('removes an api key', async () => {
403-
mockSuccessResponse(response, {
404-
headers: { Authorization: 'Bearer re_924b3rjh2387fbewf823' },
375+
fetchMock.mockOnce(JSON.stringify(response), {
376+
status: 200,
377+
headers: {
378+
'content-type': 'application/json',
379+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
380+
},
405381
});
406382

407383
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
@@ -410,11 +386,6 @@ describe('API Keys', () => {
410386
{
411387
"data": {},
412388
"error": null,
413-
"rateLimiting": {
414-
"limit": 2,
415-
"remainingRequests": 2,
416-
"shouldResetAfter": 1,
417-
},
418389
}
419390
`);
420391
});
@@ -425,8 +396,12 @@ describe('API Keys', () => {
425396
message: 'Something went wrong',
426397
};
427398

428-
mockErrorResponse(response, {
429-
headers: { Authorization: 'Bearer re_924b3rjh2387fbewf823' },
399+
fetchMock.mockOnce(JSON.stringify(response), {
400+
status: 500,
401+
headers: {
402+
'content-type': 'application/json',
403+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
404+
},
430405
});
431406

432407
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
@@ -440,11 +415,6 @@ describe('API Keys', () => {
440415
"message": "Something went wrong",
441416
"name": "application_error",
442417
},
443-
"rateLimiting": {
444-
"limit": 2,
445-
"remainingRequests": 2,
446-
"shouldResetAfter": 1,
447-
},
448418
}
449419
`);
450420
});
@@ -455,8 +425,12 @@ describe('API Keys', () => {
455425
message: 'API key not found',
456426
};
457427

458-
mockErrorResponse(response, {
459-
headers: { Authorization: 'Bearer re_924b3rjh2387fbewf823' },
428+
fetchMock.mockOnce(JSON.stringify(response), {
429+
status: 404,
430+
headers: {
431+
'content-type': 'application/json',
432+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
433+
},
460434
});
461435

462436
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
@@ -472,11 +446,6 @@ describe('API Keys', () => {
472446
"message": "API key not found",
473447
"name": "not_found",
474448
},
475-
"rateLimiting": {
476-
"limit": 2,
477-
"remainingRequests": 2,
478-
"shouldResetAfter": 1,
479-
},
480449
}
481450
`);
482451
});

src/api-keys/interfaces/create-api-key-options.interface.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { PostOptions } from '../../common/interfaces';
2-
import type { Response } from '../../interfaces';
2+
import type { ErrorResponse } from '../../interfaces';
33

44
export interface CreateApiKeyOptions {
55
name: string;
@@ -14,4 +14,12 @@ export interface CreateApiKeyResponseSuccess {
1414
id: string;
1515
}
1616

17-
export type CreateApiKeyResponse = Response<CreateApiKeyResponseSuccess>;
17+
export type CreateApiKeyResponse =
18+
| {
19+
data: CreateApiKeyResponseSuccess;
20+
error: null;
21+
}
22+
| {
23+
data: null;
24+
error: ErrorResponse;
25+
};

src/api-keys/interfaces/list-api-keys.interface.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { PaginationOptions } from '../../common/interfaces';
2-
import type { Response } from '../../interfaces';
2+
import type { ErrorResponse } from '../../interfaces';
33
import type { ApiKey } from './api-key';
44

55
export type ListApiKeysOptions = PaginationOptions;
@@ -10,4 +10,12 @@ export type ListApiKeysResponseSuccess = {
1010
data: Pick<ApiKey, 'name' | 'id' | 'created_at'>[];
1111
};
1212

13-
export type ListApiKeysResponse = Response<ListApiKeysResponseSuccess>;
13+
export type ListApiKeysResponse =
14+
| {
15+
data: ListApiKeysResponseSuccess;
16+
error: null;
17+
}
18+
| {
19+
data: null;
20+
error: ErrorResponse;
21+
};
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
import type { Response } from '../../interfaces';
1+
import type { ErrorResponse } from '../../interfaces';
22

33
// biome-ignore lint/complexity/noBannedTypes: allow empty types
44
export type RemoveApiKeyResponseSuccess = {};
55

6-
export type RemoveApiKeyResponse = Response<RemoveApiKeyResponseSuccess>;
6+
export type RemoveApiKeyResponse =
7+
| {
8+
data: RemoveApiKeyResponseSuccess;
9+
error: null;
10+
}
11+
| {
12+
data: null;
13+
error: ErrorResponse;
14+
};

0 commit comments

Comments
 (0)