Skip to content

Commit 12962bc

Browse files
authored
chore(types,clerk-js,backend): Re-use common pagination types (clerk#2210)
* chore(types,clerk-js): Rename ClerkPaginationParams to ClerkPaginationRequest * chore(types,clerk-js): Use ClerkPaginationParams type as base pagination type * chore(clerk-js): Drop unused import * chore(types): Extract pagination types to separate module * chore(backend,types): Re-use ClerkPaginationRequest as base pagination type * chore(repo): Add changeset
1 parent 63713c3 commit 12962bc

13 files changed

Lines changed: 95 additions & 142 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@clerk/clerk-js': minor
3+
'@clerk/backend': minor
4+
'@clerk/types': minor
5+
---
6+
7+
Re-use common pagination types for consistency across types.
8+
9+
Types introduced in `@clerk/types`:
10+
- `ClerkPaginationRequest` : describes pagination related props in request payload
11+
- `ClerkPaginatedResponse` : describes pagination related props in response body
12+
- `ClerkPaginationParams` : describes pagination related props in api client method params

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { ClerkPaginationRequest } from '@clerk/types';
2+
13
import runtime from '../../runtime';
24
import { joinPaths } from '../../util/path';
35
import type {
@@ -16,12 +18,10 @@ type MetadataParams<TPublic = OrganizationPublicMetadata, TPrivate = Organizatio
1618
privateMetadata?: TPrivate;
1719
};
1820

19-
type GetOrganizationListParams = {
20-
limit?: number;
21-
offset?: number;
21+
type GetOrganizationListParams = ClerkPaginationRequest<{
2222
includeMembersCount?: boolean;
2323
query?: string;
24-
};
24+
}>;
2525

2626
type CreateParams = {
2727
name: string;
@@ -46,11 +46,9 @@ type UpdateLogoParams = {
4646

4747
type UpdateMetadataParams = MetadataParams;
4848

49-
type GetOrganizationMembershipListParams = {
49+
type GetOrganizationMembershipListParams = ClerkPaginationRequest<{
5050
organizationId: string;
51-
limit?: number;
52-
offset?: number;
53-
};
51+
}>;
5452

5553
type CreateOrganizationMembershipParams = {
5654
organizationId: string;
@@ -79,12 +77,10 @@ type CreateOrganizationInvitationParams = {
7977
publicMetadata?: OrganizationInvitationPublicMetadata;
8078
};
8179

82-
type GetOrganizationInvitationListParams = {
80+
type GetOrganizationInvitationListParams = ClerkPaginationRequest<{
8381
organizationId: string;
8482
status?: OrganizationInvitationStatus[];
85-
limit?: number;
86-
offset?: number;
87-
};
83+
}>;
8884

8985
type GetOrganizationInvitationParams = {
9086
organizationId: string;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
import type { ClerkPaginationRequest } from '@clerk/types';
2+
13
import { joinPaths } from '../../util/path';
24
import type { DeletedObject, Permission } from '../resources';
35
import { AbstractAPI } from './AbstractApi';
46

57
const basePath = '/organizations_permissions';
68

7-
type GetOrganizationPermissionListParams = {
8-
limit?: number;
9-
offset?: number;
9+
type GetOrganizationPermissionListParams = ClerkPaginationRequest<{
1010
query?: string;
1111
orderBy?: string;
12-
};
12+
}>;
1313

1414
type CreateParams = {
1515
name: string;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
import type { ClerkPaginationRequest } from '@clerk/types';
2+
13
import { joinPaths } from '../../util/path';
24
import type { DeletedObject, Role } from '../resources';
35
import { AbstractAPI } from './AbstractApi';
46

57
const basePath = '/organizations_roles';
68

7-
type GetRoleListParams = {
8-
limit?: number;
9-
offset?: number;
9+
type GetRoleListParams = ClerkPaginationRequest<{
1010
query?: string;
1111
order_by?: string;
12-
};
12+
}>;
1313

1414
type CreateParams = {
1515
/**

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { OAuthProvider } from '@clerk/types';
1+
import type { ClerkPaginationRequest, OAuthProvider } from '@clerk/types';
22

33
import runtime from '../../runtime';
44
import { joinPaths } from '../../util/path';
@@ -17,11 +17,11 @@ type UserCountParams = {
1717
externalId?: string[];
1818
};
1919

20-
type UserListParams = UserCountParams & {
21-
limit?: number;
22-
offset?: number;
23-
orderBy?: 'created_at' | 'updated_at' | '+created_at' | '+updated_at' | '-created_at' | '-updated_at';
24-
};
20+
type UserListParams = ClerkPaginationRequest<
21+
UserCountParams & {
22+
orderBy?: 'created_at' | 'updated_at' | '+created_at' | '+updated_at' | '-created_at' | '-updated_at';
23+
}
24+
>;
2525

2626
type UserMetadataParams = {
2727
publicMetadata?: UserPublicMetadata;
@@ -77,11 +77,9 @@ interface UpdateUserParams extends UserMetadataParams {
7777
createdAt?: Date;
7878
}
7979

80-
type GetOrganizationMembershipListParams = {
80+
type GetOrganizationMembershipListParams = ClerkPaginationRequest<{
8181
userId: string;
82-
limit?: number;
83-
offset?: number;
84-
};
82+
}>;
8583

8684
type VerifyPasswordParams = {
8785
userId: string;

packages/clerk-js/src/ui.retheme/components/CreateOrganization/CreateOrganization.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CreateOrganizationModalProps, CreateOrganizationProps } from '@clerk/types';
1+
import type { CreateOrganizationModalProps } from '@clerk/types';
22

33
import { withOrganizationsEnabledGuard } from '../../common';
44
import { ComponentContext, withCoreUserGuard } from '../../contexts';

packages/clerk-js/src/utils/pagesToOffset.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import type { ClerkPaginationParams } from '@clerk/types';
1+
import type { ClerkPaginationParams, ClerkPaginationRequest } from '@clerk/types';
22

3-
type Pages = {
4-
initialPage?: number;
5-
pageSize?: number;
6-
};
73
function getNonUndefinedValues<T>(obj: Record<string, T>): Record<string, T> {
84
return Object.keys(obj).reduce((result, key) => {
95
if (obj[key] !== undefined) {
@@ -12,8 +8,10 @@ function getNonUndefinedValues<T>(obj: Record<string, T>): Record<string, T> {
128
return result;
139
}, {} as Record<string, T>);
1410
}
15-
export function convertPageToOffset<T extends Pages | undefined>(pageParams: T): ClerkPaginationParams {
16-
const { pageSize, initialPage, ...restParams } = pageParams || {};
11+
export function convertPageToOffset<T extends ClerkPaginationParams | undefined>(
12+
pageParams: T,
13+
): ClerkPaginationRequest {
14+
const { pageSize, initialPage, ...restParams } = pageParams || ({} as ClerkPaginationParams);
1715
const _pageSize = pageSize ?? 10;
1816
const _initialPage = initialPage ?? 1;
1917

packages/types/src/api.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,3 @@ export interface ClerkRuntimeError {
2323
code: string;
2424
message: string;
2525
}
26-
27-
/**
28-
* Pagination params
29-
*/
30-
export interface ClerkPaginationParams {
31-
limit?: number;
32-
offset?: number;
33-
}
34-
35-
/**
36-
* Pagination params
37-
*/
38-
export interface ClerkPaginatedResponse<T> {
39-
data: T[];
40-
total_count: number;
41-
}

packages/types/src/index.retheme.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ export * from './verification';
5353
export * from './web3';
5454
export * from './web3Wallet';
5555
export * from './customPages';
56+
export * from './pagination';

packages/types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ export * from './verification';
5353
export * from './web3';
5454
export * from './web3Wallet';
5555
export * from './customPages';
56+
export * from './pagination';

0 commit comments

Comments
 (0)