Skip to content

Commit 57e0972

Browse files
authored
chore(clerk-js): Remove fallback data for paginated endpoint methods (clerk#2491)
* chore(clerk-js): Remove fallback data for paginated endpoint methods We want to allow developers to be able to catch the error themselves * chore(clerk-js): Add changeset
1 parent b9b51f7 commit 57e0972

5 files changed

Lines changed: 74 additions & 108 deletions

File tree

.changeset/modern-plums-invent.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@clerk/clerk-js': minor
3+
---
4+
5+
Remove fallback data and allow promise to throw for paginated endpoint methods.
6+
Affected methods:
7+
- Organization.getDomains
8+
- Organization.getInvitations
9+
- Organization.getMembershipRequests
10+
- Organization.getMemberships
11+
- User.getOrganizationInvitations
12+
- User.getOrganizationSuggestions
13+
- User.getOrganizationMemberships

packages/clerk-js/src/core/resources/Organization.ts

Lines changed: 35 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,14 @@ export class Organization extends BaseResource implements OrganizationResource {
114114
{
115115
forceUpdateClient: true,
116116
},
117-
)
118-
.then(res => {
119-
const { data: invites, total_count } =
120-
res?.response as unknown as ClerkPaginatedResponse<OrganizationDomainJSON>;
121-
122-
return {
123-
total_count,
124-
data: invites.map(domain => new OrganizationDomain(domain)),
125-
};
126-
})
127-
.catch(() => ({
128-
total_count: 0,
129-
data: [],
130-
}));
117+
).then(res => {
118+
const { data: invites, total_count } = res?.response as unknown as ClerkPaginatedResponse<OrganizationDomainJSON>;
119+
120+
return {
121+
total_count,
122+
data: invites.map(domain => new OrganizationDomain(domain)),
123+
};
124+
});
131125
};
132126

133127
getDomain = async ({ domainId }: { domainId: string }): Promise<OrganizationDomainResource> => {
@@ -147,20 +141,15 @@ export class Organization extends BaseResource implements OrganizationResource {
147141
path: `/organizations/${this.id}/membership_requests`,
148142
method: 'GET',
149143
search: convertPageToOffset(getRequestParam),
150-
})
151-
.then(res => {
152-
const { data: requests, total_count } =
153-
res?.response as unknown as ClerkPaginatedResponse<OrganizationMembershipRequestJSON>;
154-
155-
return {
156-
total_count,
157-
data: requests.map(request => new OrganizationMembershipRequest(request)),
158-
};
159-
})
160-
.catch(() => ({
161-
total_count: 0,
162-
data: [],
163-
}));
144+
}).then(res => {
145+
const { data: requests, total_count } =
146+
res?.response as unknown as ClerkPaginatedResponse<OrganizationMembershipRequestJSON>;
147+
148+
return {
149+
total_count,
150+
data: requests.map(request => new OrganizationMembershipRequest(request)),
151+
};
152+
});
164153
};
165154

166155
createDomain = async (name: string): Promise<OrganizationDomainResource> => {
@@ -174,22 +163,15 @@ export class Organization extends BaseResource implements OrganizationResource {
174163
// `paginated` is used in some legacy endpoints to support clerk paginated responses
175164
// The parameter will be dropped in FAPI v2
176165
search: convertPageToOffset({ ...getMembershipsParams, paginated: true }),
177-
})
178-
.then(res => {
179-
const { data: suggestions, total_count } =
180-
res?.response as unknown as ClerkPaginatedResponse<OrganizationMembershipJSON>;
181-
182-
return {
183-
total_count,
184-
data: suggestions.map(suggestion => new OrganizationMembership(suggestion)),
185-
};
186-
})
187-
.catch(() => {
188-
return {
189-
total_count: 0,
190-
data: [],
191-
};
192-
});
166+
}).then(res => {
167+
const { data: suggestions, total_count } =
168+
res?.response as unknown as ClerkPaginatedResponse<OrganizationMembershipJSON>;
169+
170+
return {
171+
total_count,
172+
data: suggestions.map(suggestion => new OrganizationMembership(suggestion)),
173+
};
174+
});
193175
};
194176

195177
getInvitations = async (
@@ -204,20 +186,15 @@ export class Organization extends BaseResource implements OrganizationResource {
204186
{
205187
forceUpdateClient: true,
206188
},
207-
)
208-
.then(res => {
209-
const { data: requests, total_count } =
210-
res?.response as unknown as ClerkPaginatedResponse<OrganizationInvitationJSON>;
211-
212-
return {
213-
total_count,
214-
data: requests.map(request => new OrganizationInvitation(request)),
215-
};
216-
})
217-
.catch(() => ({
218-
total_count: 0,
219-
data: [],
220-
}));
189+
).then(res => {
190+
const { data: requests, total_count } =
191+
res?.response as unknown as ClerkPaginatedResponse<OrganizationInvitationJSON>;
192+
193+
return {
194+
total_count,
195+
data: requests.map(request => new OrganizationInvitation(request)),
196+
};
197+
});
221198
};
222199

223200
addMember = async ({ userId, role }: AddMemberParams) => {

packages/clerk-js/src/core/resources/OrganizationMembership.ts

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,16 @@ export class OrganizationMembership extends BaseResource implements Organization
3434
// `paginated` is used in some legacy endpoints to support clerk paginated responses
3535
// The parameter will be dropped in FAPI v2
3636
search: convertPageToOffset({ ...retrieveMembershipsParams, paginated: true }),
37-
})
38-
.then(res => {
39-
if (!res?.response) {
40-
return {
41-
total_count: 0,
42-
data: [],
43-
};
44-
}
45-
46-
// TODO: Fix typing
47-
const { data: suggestions, total_count } =
48-
res.response as unknown as ClerkPaginatedResponse<OrganizationMembershipJSON>;
49-
50-
return {
51-
total_count,
52-
data: suggestions.map(suggestion => new OrganizationMembership(suggestion)),
53-
};
54-
})
55-
.catch(() => {
56-
return {
57-
total_count: 0,
58-
data: [],
59-
};
60-
});
37+
}).then(res => {
38+
// TODO: Fix typing
39+
const { data: suggestions, total_count } =
40+
res?.response as unknown as ClerkPaginatedResponse<OrganizationMembershipJSON>;
41+
42+
return {
43+
total_count,
44+
data: suggestions.map(suggestion => new OrganizationMembership(suggestion)),
45+
};
46+
});
6147
};
6248

6349
destroy = async (): Promise<OrganizationMembership> => {

packages/clerk-js/src/core/resources/OrganizationSuggestion.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,15 @@ export class OrganizationSuggestion extends BaseResource implements Organization
3030
path: '/me/organization_suggestions',
3131
method: 'GET',
3232
search: convertPageToOffset(params),
33-
})
34-
.then(res => {
35-
const { data: suggestions, total_count } =
36-
res?.response as unknown as ClerkPaginatedResponse<OrganizationSuggestionJSON>;
33+
}).then(res => {
34+
const { data: suggestions, total_count } =
35+
res?.response as unknown as ClerkPaginatedResponse<OrganizationSuggestionJSON>;
3736

38-
return {
39-
total_count,
40-
data: suggestions.map(suggestion => new OrganizationSuggestion(suggestion)),
41-
};
42-
})
43-
.catch(() => ({
44-
total_count: 0,
45-
data: [],
46-
}));
37+
return {
38+
total_count,
39+
data: suggestions.map(suggestion => new OrganizationSuggestion(suggestion)),
40+
};
41+
});
4742
}
4843

4944
accept = async (): Promise<OrganizationSuggestionResource> => {

packages/clerk-js/src/core/resources/UserOrganizationInvitation.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,15 @@ export class UserOrganizationInvitation extends BaseResource implements UserOrga
2828
path: '/me/organization_invitations',
2929
method: 'GET',
3030
search: convertPageToOffset(params),
31-
})
32-
.then(res => {
33-
const { data: invites, total_count } =
34-
res?.response as unknown as ClerkPaginatedResponse<UserOrganizationInvitationJSON>;
31+
}).then(res => {
32+
const { data: invites, total_count } =
33+
res?.response as unknown as ClerkPaginatedResponse<UserOrganizationInvitationJSON>;
3534

36-
return {
37-
total_count,
38-
data: invites.map(invitation => new UserOrganizationInvitation(invitation)),
39-
};
40-
})
41-
.catch(() => ({
42-
total_count: 0,
43-
data: [],
44-
}));
35+
return {
36+
total_count,
37+
data: invites.map(invitation => new UserOrganizationInvitation(invitation)),
38+
};
39+
});
4540
}
4641

4742
constructor(data: UserOrganizationInvitationJSON) {

0 commit comments

Comments
 (0)