Skip to content

Commit b81083e

Browse files
jaredpiedtcoderabbitai[bot]
authored andcommitted
fix(backend): Fix clerk.samlConnections.getSamlConnectionList return type (#6332)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent c59baae commit b81083e

File tree

4 files changed

+60
-37
lines changed

4 files changed

+60
-37
lines changed

.changeset/young-steaks-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/backend': patch
3+
---
4+
5+
Update `clerk.samlConnections.getSamlConnectionList()` to return paginated data and export the `SamlConnection` type.

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

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,36 @@ describe('SamlConnectionAPI', () => {
1212

1313
describe('getSamlConnectionList', () => {
1414
it('successfully fetches SAML connections with all parameters', async () => {
15-
const mockSamlConnectionsResponse = [
16-
{
17-
object: 'saml_connection',
18-
id: 'samlc_123',
19-
name: 'Test Connection',
20-
provider: 'saml_custom',
21-
domain: 'test.example.com',
22-
organization_id: 'org_123',
23-
created_at: 1672531200000,
24-
updated_at: 1672531200000,
25-
active: true,
26-
sync_user_attributes: false,
27-
allow_subdomains: false,
28-
allow_idp_initiated: false,
29-
idp_entity_id: 'entity_123',
30-
idp_sso_url: 'https://idp.example.com/sso',
31-
idp_certificate: 'cert_data',
32-
idp_metadata_url: null,
33-
idp_metadata: null,
34-
attribute_mapping: {
35-
user_id: 'userId',
36-
email_address: 'email',
37-
first_name: 'firstName',
38-
last_name: 'lastName',
15+
const mockSamlConnectionsResponse = {
16+
data: [
17+
{
18+
object: 'saml_connection',
19+
id: 'samlc_123',
20+
name: 'Test Connection',
21+
provider: 'saml_custom',
22+
domain: 'test.example.com',
23+
organization_id: 'org_123',
24+
created_at: 1672531200000,
25+
updated_at: 1672531200000,
26+
active: true,
27+
sync_user_attributes: false,
28+
allow_subdomains: false,
29+
allow_idp_initiated: false,
30+
idp_entity_id: 'entity_123',
31+
idp_sso_url: 'https://idp.example.com/sso',
32+
idp_certificate: 'cert_data',
33+
idp_metadata_url: null,
34+
idp_metadata: null,
35+
attribute_mapping: {
36+
user_id: 'userId',
37+
email_address: 'email',
38+
first_name: 'firstName',
39+
last_name: 'lastName',
40+
},
3941
},
40-
},
41-
];
42+
],
43+
total_count: 1,
44+
};
4245

4346
server.use(
4447
http.get(
@@ -50,7 +53,7 @@ describe('SamlConnectionAPI', () => {
5053
expect(url.searchParams.get('limit')).toBe('5');
5154
expect(url.searchParams.get('offset')).toBe('10');
5255
expect(url.searchParams.getAll('organization_id')).toEqual(['+org_123', '-org_456']);
53-
return HttpResponse.json({ data: mockSamlConnectionsResponse });
56+
return HttpResponse.json(mockSamlConnectionsResponse);
5457
}),
5558
),
5659
);
@@ -63,10 +66,11 @@ describe('SamlConnectionAPI', () => {
6366
offset: 10,
6467
});
6568

66-
expect(response).toHaveLength(1);
67-
expect(response[0].id).toBe('samlc_123');
68-
expect(response[0].name).toBe('Test Connection');
69-
expect(response[0].organizationId).toBe('org_123');
69+
expect(response.data).toHaveLength(1);
70+
expect(response.data[0].id).toBe('samlc_123');
71+
expect(response.data[0].name).toBe('Test Connection');
72+
expect(response.data[0].organizationId).toBe('org_123');
73+
expect(response.totalCount).toBe(1);
7074
});
7175
});
7276
});

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
1-
import type { SamlIdpSlug } from '@clerk/types';
1+
import type { ClerkPaginationRequest, SamlIdpSlug } from '@clerk/types';
22

33
import { joinPaths } from '../../util/path';
44
import type { SamlConnection } from '../resources';
5+
import type { PaginatedResourceResponse } from '../resources/Deserializer';
56
import { AbstractAPI } from './AbstractApi';
67
import type { WithSign } from './util-types';
78

89
const basePath = '/saml_connections';
910

10-
type SamlConnectionListParams = {
11-
limit?: number;
12-
offset?: number;
11+
type SamlConnectionListParams = ClerkPaginationRequest<{
12+
/**
13+
* Returns SAML connections that have a name that matches the given query, via case-insensitive partial match.
14+
*/
1315
query?: string;
16+
17+
/**
18+
* Sorts SAML connections by phone_number, email_address, created_at, first_name, last_name or username.
19+
* By prepending one of those values with + or -, we can choose to sort in ascending (ASC) or descending (DESC) order.
20+
*/
1421
orderBy?: WithSign<'phone_number' | 'email_address' | 'created_at' | 'first_name' | 'last_name' | 'username'>;
22+
23+
/**
24+
* Returns SAML connections that have an associated organization ID to the given organizations.
25+
* For each organization id, the + and - can be prepended to the id, which denote whether the
26+
* respective organization should be included or excluded from the result set. Accepts up to 100 organization ids.
27+
*/
1528
organizationId?: WithSign<string>[];
16-
};
29+
}>;
1730

1831
type CreateSamlConnectionParams = {
1932
name: string;
@@ -57,7 +70,7 @@ type UpdateSamlConnectionParams = {
5770

5871
export class SamlConnectionAPI extends AbstractAPI {
5972
public async getSamlConnectionList(params: SamlConnectionListParams = {}) {
60-
return this.request<SamlConnection[]>({
73+
return this.request<PaginatedResourceResponse<SamlConnection[]>>({
6174
method: 'GET',
6275
path: basePath,
6376
queryParams: params,

packages/backend/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export type {
131131
OrganizationMembershipPublicUserData,
132132
OrganizationSettings,
133133
PhoneNumber,
134+
SamlConnection,
134135
Session,
135136
SignInToken,
136137
SignUpAttempt,

0 commit comments

Comments
 (0)