-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(backend,nextjs,clerk-sdk-node): Drop legacy return response in …
…BAPI responses (#2126)
- Loading branch information
Showing
15 changed files
with
161 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
'@clerk/clerk-sdk-node': major | ||
'@clerk/backend': major | ||
'@clerk/nextjs': major | ||
--- | ||
|
||
Change the response payload of Backend API requests to return `{ data, errors }` instead of return the data and throwing on error response. | ||
Code example to keep the same behavior: | ||
```typescript | ||
import { users } from '@clerk/backend'; | ||
import { ClerkAPIResponseError } from '@clerk/shared/error'; | ||
|
||
const { data, errors, clerkTraceId, status, statusText } = await users.getUser('user_deadbeef'); | ||
if(errors){ | ||
throw new ClerkAPIResponseError(statusText, { data: errors, status, clerkTraceId }); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
type ApiResponse<T> = { data: T | null; errors: null | any[] }; | ||
type SuccessApiResponse<T> = { data: T; errors: null }; | ||
type ErrorApiResponse = { data: null; errors: any[]; clerkTraceId: string; status: number; statusText: string }; | ||
export function assertResponse<T>(assert: Assert, resp: ApiResponse<T>): asserts resp is SuccessApiResponse<T> { | ||
assert.equal(resp.errors, null); | ||
} | ||
export function assertErrorResponse<T>(assert: Assert, resp: ApiResponse<T>): asserts resp is ErrorApiResponse { | ||
assert.notEqual(resp.errors, null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,29 @@ | ||
import { organizations, users } from '@clerk/clerk-sdk-node'; | ||
|
||
console.log('Get user to create organization'); | ||
const [creator] = await users.getUserList(); | ||
const { data, errors } = await users.getUserList(); | ||
if (errors) { | ||
throw new Error(errors); | ||
} | ||
|
||
const creator = data[0]; | ||
|
||
console.log('Create organization'); | ||
const organization = await organizations.createOrganization({ | ||
const { data: organization } = await organizations.createOrganization({ | ||
name: 'test-organization', | ||
createdBy: creator.id, | ||
}); | ||
console.log(organization); | ||
|
||
console.log('Update organization metadata'); | ||
const updatedOrganizationMetadata = | ||
await organizations.updateOrganizationMetadata(organization.id, { | ||
const { data: updatedOrganizationMetadata, errors: uomErrors } = await organizations.updateOrganizationMetadata( | ||
organization.id, | ||
{ | ||
publicMetadata: { test: 1 }, | ||
}); | ||
}, | ||
); | ||
if (uomErrors) { | ||
throw new Error(uomErrors); | ||
} | ||
|
||
console.log(updatedOrganizationMetadata); |
Oops, something went wrong.