Skip to content

Commit

Permalink
fix(backend): Request paginated responses from BAPI (#3276)
Browse files Browse the repository at this point in the history
ref: #3271

Co-authored-by: panteliselef <[email protected]>
  • Loading branch information
dimkl and panteliselef committed May 1, 2024
1 parent 8ba8a0c commit 8fbe238
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 25 deletions.
11 changes: 11 additions & 0 deletions .changeset/clever-buckets-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@clerk/backend': patch
---

Fix the following `@clerk/backend` methods to populate their paginated responses:
- `clerkClient.allowListIndentifiers.getAllowlistIdentifierList()`
- `clerkClient.clients.getClientList()`
- `clerkClient.invitations.getInvitationList`
- `clerkClient.redirectUrls.getRedirectUrlList()`
- `clerkClient.sessions.getSessionList()`
- `clerkClient.users.getUserOauthAccessToken()`
50 changes: 28 additions & 22 deletions packages/backend/src/api/__tests__/factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,37 +214,43 @@ export default (QUnit: QUnit) => {
});

test('successfully retrieves user access tokens from backend API for a specific provider', async assert => {
const fakeResponse = [
{
external_account_id: 'eac_2dYS7stz9bgxQsSRvNqEAHhuxvW',
object: 'oauth_access_token',
token: '<token>',
provider: 'oauth_google',
public_metadata: {},
label: null,
scopes: ['email', 'profile'],
},
];
const fakeResponse = {
data: [
{
external_account_id: 'eac_2dYS7stz9bgxQsSRvNqEAHhuxvW',
object: 'oauth_access_token',
token: '<token>',
provider: 'oauth_google',
public_metadata: {},
label: null,
scopes: ['email', 'profile'],
},
],
total_count: 1,
};

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

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

assert.equal(response[0].externalAccountId, 'eac_2dYS7stz9bgxQsSRvNqEAHhuxvW');
assert.equal(response[0].provider, 'oauth_google');
assert.equal(response[0].token, '<token>');
assert.deepEqual(response[0].scopes, ['email', 'profile']);
assert.equal(response.data[0].externalAccountId, 'eac_2dYS7stz9bgxQsSRvNqEAHhuxvW');
assert.equal(response.data[0].provider, 'oauth_google');
assert.equal(response.data[0].token, '<token>');
assert.deepEqual(response.data[0].scopes, ['email', 'profile']);

assert.ok(
fakeFetch.calledOnceWith('https://api.clerk.test/v1/users/user_deadbeef/oauth_access_tokens/oauth_google', {
method: 'GET',
headers: {
Authorization: 'Bearer deadbeef',
'Content-Type': 'application/json',
'User-Agent': '@clerk/[email protected]',
fakeFetch.calledOnceWith(
'https://api.clerk.test/v1/users/user_deadbeef/oauth_access_tokens/oauth_google?paginated=true',
{
method: 'GET',
headers: {
Authorization: 'Bearer deadbeef',
'Content-Type': 'application/json',
'User-Agent': '@clerk/[email protected]',
},
},
}),
),
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class AllowlistIdentifierAPI extends AbstractAPI {
return this.request<PaginatedResourceResponse<AllowlistIdentifier[]>>({
method: 'GET',
path: basePath,
queryParams: { paginated: true },
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/api/endpoints/ClientApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class ClientAPI extends AbstractAPI {
return this.request<PaginatedResourceResponse<Client[]>>({
method: 'GET',
path: basePath,
queryParams: params,
queryParams: { ...params, paginated: true },
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/api/endpoints/InvitationApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class InvitationAPI extends AbstractAPI {
return this.request<PaginatedResourceResponse<Invitation[]>>({
method: 'GET',
path: basePath,
queryParams: params,
queryParams: { ...params, paginated: true },
});
}

Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/api/endpoints/RedirectUrlApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class RedirectUrlAPI extends AbstractAPI {
return this.request<PaginatedResourceResponse<RedirectUrl[]>>({
method: 'GET',
path: basePath,
queryParams: { paginated: true },
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/api/endpoints/SessionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class SessionAPI extends AbstractAPI {
return this.request<PaginatedResourceResponse<Session[]>>({
method: 'GET',
path: basePath,
queryParams: params,
queryParams: { ...params, paginated: true },
});
}

Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/api/endpoints/UserApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export class UserAPI extends AbstractAPI {
return this.request<PaginatedResourceResponse<OauthAccessToken[]>>({
method: 'GET',
path: joinPaths(basePath, userId, 'oauth_access_tokens', provider),
queryParams: { paginated: true },
});
}

Expand Down

0 comments on commit 8fbe238

Please sign in to comment.