Skip to content

Commit 8fbe238

Browse files
dimklpanteliselef
andauthored
fix(backend): Request paginated responses from BAPI (clerk#3276)
ref: clerk#3271 Co-authored-by: panteliselef <panteliselef@outlook.com>
1 parent 8ba8a0c commit 8fbe238

8 files changed

Lines changed: 45 additions & 25 deletions

File tree

.changeset/clever-buckets-exist.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@clerk/backend': patch
3+
---
4+
5+
Fix the following `@clerk/backend` methods to populate their paginated responses:
6+
- `clerkClient.allowListIndentifiers.getAllowlistIdentifierList()`
7+
- `clerkClient.clients.getClientList()`
8+
- `clerkClient.invitations.getInvitationList`
9+
- `clerkClient.redirectUrls.getRedirectUrlList()`
10+
- `clerkClient.sessions.getSessionList()`
11+
- `clerkClient.users.getUserOauthAccessToken()`

packages/backend/src/api/__tests__/factory.test.ts

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -214,37 +214,43 @@ export default (QUnit: QUnit) => {
214214
});
215215

216216
test('successfully retrieves user access tokens from backend API for a specific provider', async assert => {
217-
const fakeResponse = [
218-
{
219-
external_account_id: 'eac_2dYS7stz9bgxQsSRvNqEAHhuxvW',
220-
object: 'oauth_access_token',
221-
token: '<token>',
222-
provider: 'oauth_google',
223-
public_metadata: {},
224-
label: null,
225-
scopes: ['email', 'profile'],
226-
},
227-
];
217+
const fakeResponse = {
218+
data: [
219+
{
220+
external_account_id: 'eac_2dYS7stz9bgxQsSRvNqEAHhuxvW',
221+
object: 'oauth_access_token',
222+
token: '<token>',
223+
provider: 'oauth_google',
224+
public_metadata: {},
225+
label: null,
226+
scopes: ['email', 'profile'],
227+
},
228+
],
229+
total_count: 1,
230+
};
228231

229232
fakeFetch = sinon.stub(runtime, 'fetch');
230233
fakeFetch.onCall(0).returns(jsonOk(fakeResponse));
231234

232235
const response = await apiClient.users.getUserOauthAccessToken('user_deadbeef', 'oauth_google');
233236

234-
assert.equal(response[0].externalAccountId, 'eac_2dYS7stz9bgxQsSRvNqEAHhuxvW');
235-
assert.equal(response[0].provider, 'oauth_google');
236-
assert.equal(response[0].token, '<token>');
237-
assert.deepEqual(response[0].scopes, ['email', 'profile']);
237+
assert.equal(response.data[0].externalAccountId, 'eac_2dYS7stz9bgxQsSRvNqEAHhuxvW');
238+
assert.equal(response.data[0].provider, 'oauth_google');
239+
assert.equal(response.data[0].token, '<token>');
240+
assert.deepEqual(response.data[0].scopes, ['email', 'profile']);
238241

239242
assert.ok(
240-
fakeFetch.calledOnceWith('https://api.clerk.test/v1/users/user_deadbeef/oauth_access_tokens/oauth_google', {
241-
method: 'GET',
242-
headers: {
243-
Authorization: 'Bearer deadbeef',
244-
'Content-Type': 'application/json',
245-
'User-Agent': '@clerk/backend@0.0.0-test',
243+
fakeFetch.calledOnceWith(
244+
'https://api.clerk.test/v1/users/user_deadbeef/oauth_access_tokens/oauth_google?paginated=true',
245+
{
246+
method: 'GET',
247+
headers: {
248+
Authorization: 'Bearer deadbeef',
249+
'Content-Type': 'application/json',
250+
'User-Agent': '@clerk/backend@0.0.0-test',
251+
},
246252
},
247-
}),
253+
),
248254
);
249255
});
250256
});

packages/backend/src/api/endpoints/AllowlistIdentifierApi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export class AllowlistIdentifierAPI extends AbstractAPI {
1515
return this.request<PaginatedResourceResponse<AllowlistIdentifier[]>>({
1616
method: 'GET',
1717
path: basePath,
18+
queryParams: { paginated: true },
1819
});
1920
}
2021

packages/backend/src/api/endpoints/ClientApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class ClientAPI extends AbstractAPI {
1212
return this.request<PaginatedResourceResponse<Client[]>>({
1313
method: 'GET',
1414
path: basePath,
15-
queryParams: params,
15+
queryParams: { ...params, paginated: true },
1616
});
1717
}
1818

packages/backend/src/api/endpoints/InvitationApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class InvitationAPI extends AbstractAPI {
3535
return this.request<PaginatedResourceResponse<Invitation[]>>({
3636
method: 'GET',
3737
path: basePath,
38-
queryParams: params,
38+
queryParams: { ...params, paginated: true },
3939
});
4040
}
4141

packages/backend/src/api/endpoints/RedirectUrlApi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class RedirectUrlAPI extends AbstractAPI {
1414
return this.request<PaginatedResourceResponse<RedirectUrl[]>>({
1515
method: 'GET',
1616
path: basePath,
17+
queryParams: { paginated: true },
1718
});
1819
}
1920

packages/backend/src/api/endpoints/SessionApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class SessionAPI extends AbstractAPI {
1919
return this.request<PaginatedResourceResponse<Session[]>>({
2020
method: 'GET',
2121
path: basePath,
22-
queryParams: params,
22+
queryParams: { ...params, paginated: true },
2323
});
2424
}
2525

packages/backend/src/api/endpoints/UserApi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ export class UserAPI extends AbstractAPI {
197197
return this.request<PaginatedResourceResponse<OauthAccessToken[]>>({
198198
method: 'GET',
199199
path: joinPaths(basePath, userId, 'oauth_access_tokens', provider),
200+
queryParams: { paginated: true },
200201
});
201202
}
202203

0 commit comments

Comments
 (0)