Skip to content

Commit d7b5982

Browse files
committed
Revert "feat: rate limiting information for all responses (#562)"
This reverts commit ee0d2a1.
1 parent a1f0221 commit d7b5982

40 files changed

+680
-588
lines changed

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

Lines changed: 48 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import type { ErrorResponse } from '../interfaces';
22
import { Resend } from '../resend';
3-
import {
4-
mockErrorResponse,
5-
mockSuccessResponse,
6-
} from '../test-utils/mock-fetch';
73
import type {
84
CreateApiKeyOptions,
95
CreateApiKeyResponseSuccess,
@@ -22,8 +18,12 @@ describe('API Keys', () => {
2218
id: '430eed87-632a-4ea6-90db-0aace67ec228',
2319
};
2420

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

2929
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
@@ -37,11 +37,6 @@ describe('API Keys', () => {
3737
"token": "re_PKr4RCko_Lhm9ost2YjNCctnPjbLw8Nqk",
3838
},
3939
"error": null,
40-
"rateLimiting": {
41-
"limit": 2,
42-
"remainingRequests": 2,
43-
"shouldResetAfter": 1,
44-
},
4540
}
4641
`);
4742
});
@@ -55,8 +50,12 @@ describe('API Keys', () => {
5550
name: 'validation_error',
5651
};
5752

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

6261
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
@@ -70,11 +69,6 @@ describe('API Keys', () => {
7069
"message": "String must contain at least 1 character(s)",
7170
"name": "validation_error",
7271
},
73-
"rateLimiting": {
74-
"limit": 2,
75-
"remainingRequests": 2,
76-
"shouldResetAfter": 1,
77-
},
7872
}
7973
`);
8074
});
@@ -91,8 +85,12 @@ describe('API Keys', () => {
9185
id: '430eed87-632a-4ea6-90db-0aace67ec228',
9286
};
9387

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

9896
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
@@ -106,11 +104,6 @@ describe('API Keys', () => {
106104
"token": "re_PKr4RCko_Lhm9ost2YjNCctnPjbLw8Nqk",
107105
},
108106
"error": null,
109-
"rateLimiting": {
110-
"limit": 2,
111-
"remainingRequests": 2,
112-
"shouldResetAfter": 1,
113-
},
114107
}
115108
`);
116109
});
@@ -125,8 +118,12 @@ describe('API Keys', () => {
125118
id: '430eed87-632a-4ea6-90db-0aace67ec228',
126119
};
127120

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

132129
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
@@ -140,11 +137,6 @@ describe('API Keys', () => {
140137
"token": "re_PKr4RCko_Lhm9ost2YjNCctnPjbLw8Nqk",
141138
},
142139
"error": null,
143-
"rateLimiting": {
144-
"limit": 2,
145-
"remainingRequests": 2,
146-
"shouldResetAfter": 1,
147-
},
148140
}
149141
`);
150142
});
@@ -155,8 +147,12 @@ describe('API Keys', () => {
155147
message: 'Access must be "full_access" | "sending_access"',
156148
};
157149

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

162158
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
@@ -175,11 +171,6 @@ describe('API Keys', () => {
175171
"message": "Access must be "full_access" | "sending_access"",
176172
"name": "invalid_access",
177173
},
178-
"rateLimiting": {
179-
"limit": 2,
180-
"remainingRequests": 2,
181-
"shouldResetAfter": 1,
182-
},
183174
}
184175
`);
185176
});
@@ -400,8 +391,12 @@ describe('API Keys', () => {
400391
const response: RemoveApiKeyResponseSuccess = {};
401392

402393
it('removes an api key', async () => {
403-
mockSuccessResponse(response, {
404-
headers: { Authorization: 'Bearer re_924b3rjh2387fbewf823' },
394+
fetchMock.mockOnce(JSON.stringify(response), {
395+
status: 200,
396+
headers: {
397+
'content-type': 'application/json',
398+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
399+
},
405400
});
406401

407402
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
@@ -410,11 +405,6 @@ describe('API Keys', () => {
410405
{
411406
"data": {},
412407
"error": null,
413-
"rateLimiting": {
414-
"limit": 2,
415-
"remainingRequests": 2,
416-
"shouldResetAfter": 1,
417-
},
418408
}
419409
`);
420410
});
@@ -425,8 +415,12 @@ describe('API Keys', () => {
425415
message: 'Something went wrong',
426416
};
427417

428-
mockErrorResponse(response, {
429-
headers: { Authorization: 'Bearer re_924b3rjh2387fbewf823' },
418+
fetchMock.mockOnce(JSON.stringify(response), {
419+
status: 500,
420+
headers: {
421+
'content-type': 'application/json',
422+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
423+
},
430424
});
431425

432426
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
@@ -440,11 +434,6 @@ describe('API Keys', () => {
440434
"message": "Something went wrong",
441435
"name": "application_error",
442436
},
443-
"rateLimiting": {
444-
"limit": 2,
445-
"remainingRequests": 2,
446-
"shouldResetAfter": 1,
447-
},
448437
}
449438
`);
450439
});
@@ -455,8 +444,12 @@ describe('API Keys', () => {
455444
message: 'API key not found',
456445
};
457446

458-
mockErrorResponse(response, {
459-
headers: { Authorization: 'Bearer re_924b3rjh2387fbewf823' },
447+
fetchMock.mockOnce(JSON.stringify(response), {
448+
status: 404,
449+
headers: {
450+
'content-type': 'application/json',
451+
Authorization: 'Bearer re_924b3rjh2387fbewf823',
452+
},
460453
});
461454

462455
const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
@@ -472,11 +465,6 @@ describe('API Keys', () => {
472465
"message": "API key not found",
473466
"name": "not_found",
474467
},
475-
"rateLimiting": {
476-
"limit": 2,
477-
"remainingRequests": 2,
478-
"shouldResetAfter": 1,
479-
},
480468
}
481469
`);
482470
});

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)