-
Notifications
You must be signed in to change notification settings - Fork 381
feat(clerk-js,clerk-react,nextjs): Introduce <APIKeys />
AIO component
#5858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 120 commits
Commits
Show all changes
136 commits
Select commit
Hold shift + click to select a range
cbee2b1
chore: set initial files for new component
wobsoriano c5c254d
chore: add resources and test methods
wobsoriano a1dfa60
chore(clerk-js): Remove Clerk.commerce (#5846)
brkalow cb1961e
chore: add simple table with calls to fapi
wobsoriano 44cfd15
chore: use built in components
wobsoriano 3a6d206
chore: add fake form
wobsoriano e4d26a5
chore: fix bad rebase
wobsoriano 6a914c5
chore: fix bad rebase
wobsoriano beb0a44
chore: add create api key func
wobsoriano 7294f7e
chore: add prop types and improve fetching
wobsoriano b2ff5a4
chore: add React component
wobsoriano 83789d0
chore: accept props
wobsoriano de59b53
chore: add copy button functionality
wobsoriano 3b4c715
chore: fetch secret on clipboard copy
wobsoriano b15610e
chore: add api key revokation
wobsoriano a0feb7a
chore: set minimum fields
wobsoriano a8a4f2f
chore: add pagination and improve form
wobsoriano ae65149
chore: try refetch
wobsoriano 4b25f0f
chore: fix revalidation and more styling
wobsoriano 69925f7
chore: rename component to <ApiKeys />
wobsoriano 8de8219
chore: add expiration field
wobsoriano 7c7e3e0
chore: add api keys component or user and org profile
wobsoriano f19825c
chore: add missing org profile sidebar nav
wobsoriano fb78ddc
chore: clean up props
wobsoriano 0b2712c
chore: clean up props
wobsoriano ece97b3
chore: add api key secret fetcher and clean up components
wobsoriano bdecb55
chore: adjust table heading widths
wobsoriano 1e338ec
chore: improve secret fetching
wobsoriano 277b98c
chore: improve secret fetching
wobsoriano 5faa5cf
chore: add locales
wobsoriano 4377046
chore: action locales
wobsoriano 137860c
chore: add locales to api keys page in user and org profile
wobsoriano 5523b1a
chore: switch to swr for fetching
wobsoriano 944ec76
chore: clean up fetchers and mutations
wobsoriano af99cab
chore: add initial error handling
wobsoriano b5c92e6
chore: add footer
wobsoriano 0ee39fc
chore: add save button locale
wobsoriano 57bf204
chore: fix close form btn
wobsoriano 00d6d0b
chore: use description field and add custom expiration
wobsoriano f49a918
chore: add last used field
wobsoriano 8ff06fe
chore: remove unused function
wobsoriano 0f05f25
chore: add card width
wobsoriano 7266d96
chore: add card width
wobsoriano 6708873
chore: add custom page locales
wobsoriano 6143e08
chore: rename component to APIKeys
wobsoriano bc0670a
Update packages/clerk-js/src/ui/components/ApiKeys/ApiKeysTable.tsx
wobsoriano 2bdc6ff
Update packages/clerk-js/src/ui/components/ApiKeys/ApiKeysTable.tsx
wobsoriano 2a0f715
Update packages/clerk-js/src/ui/components/ApiKeys/ApiKeysTable.tsx
wobsoriano 0692f77
Update packages/clerk-js/src/ui/components/ApiKeys/ApiKeysTable.tsx
wobsoriano 92c4c1d
Update packages/clerk-js/src/ui/components/ApiKeys/ApiKeysTable.tsx
wobsoriano 75bc440
chore: adjustments to fetch calls
wobsoriano 171a72b
chore: apply design suggestions
wobsoriano f520d87
chore: remove extra margin
wobsoriano 14fa49b
chore: introduce revoke confirm dialog
wobsoriano 44a3fe7
chore: make form and table responsive
wobsoriano c45b106
chore: clean up name casing
wobsoriano d0b4f05
chore: export APIKeys in nextjs
wobsoriano 0b6de03
chore: fix merge conflicts
wobsoriano ee41a27
chore: add changeset
wobsoriano 2b8096b
chore: update code icon
wobsoriano 3375760
Update packages/clerk-js/src/ui/components/ApiKeys/ApiKeys.tsx
wobsoriano cd50d3e
chore: adjustments to table padding
wobsoriano d705977
chore: prevent layout shift in date input and segmented control buttons
wobsoriano 0130c63
chore: move segmented control styling to root
wobsoriano 6d25929
chore(clerk-js,types): Conditionally render API Keys page based on en…
wobsoriano 163ff71
chore: remove unused component
wobsoriano 2e38987
fix types
wobsoriano 3cbf876
fix types
wobsoriano 398cbfb
chore: update changesets
wobsoriano 26c11b8
chore: fix snapshot tests
wobsoriano 518dbbb
chore: fix react-router snapshot tests
wobsoriano 4aea430
chore: fix chrome-extension snapshot tests
wobsoriano aa0adf6
chore: fix typedoc tests
wobsoriano c23d4b0
Update ApiKeysTable.tsx
wobsoriano 8d09a9f
Update packages/localizations/src/de-DE.ts
wobsoriano 6857961
Update packages/localizations/src/de-DE.ts
wobsoriano 3380f9a
Update packages/localizations/src/de-DE.ts
wobsoriano bdef2fe
Update packages/localizations/src/de-DE.ts
wobsoriano aa69753
Update packages/localizations/src/de-DE.ts
wobsoriano 87926e4
Update .changeset/ninety-candles-sleep.md
wobsoriano 28894eb
Update .changeset/fluffy-numbers-stick.md
wobsoriano aac35e7
Apply suggestions from code review
wobsoriano 3f7b3b2
fix: pass correct subject when used inside pages
wobsoriano d54ea6c
chore: update bundlewatch config
wobsoriano f0efd21
remove barrel files
wobsoriano 24cb76d
chore: avoid barrel files
wobsoriano 7a52029
Merge branch 'main' into rob/robo-20-manage-api-keys
wobsoriano 062b2fe
fix incorrect merge
wobsoriano a996bbc
mark methods as experimental
wobsoriano 666c0cb
adjust bundle size
wobsoriano bb96131
Merge branch 'main' into rob/robo-20-manage-api-keys
wobsoriano 58b72f2
Merge branch 'main' into rob/robo-20-manage-api-keys
wobsoriano b180828
chore(clerk-js): Move API Keys methods to its own module (#6089)
wobsoriano 2f87215
chore: localize time ago
wobsoriano e1e5b22
Merge branch 'main' into rob/robo-20-manage-api-keys
wobsoriano 49643a4
chore: fix environment snapshot test
wobsoriano 7874acc
chore: bundlewatch adjustment
wobsoriano 44b06ca
Revert locale files to main except en-US and de-DE; keep customizations
wobsoriano cdeb9cb
chore: bundlewatch adjustment
wobsoriano 3412b97
chore: bundlewatch adjustment
wobsoriano cee9cfa
chore: bundlewatch adjustment
wobsoriano 9075be8
chore: type improvements
wobsoriano f568296
chore: fix remix snapshot tests
wobsoriano 796ba7a
chore: pass error to be handled by client
wobsoriano 09de7f8
fix revoke revalidation
wobsoriano 7463647
Update packages/clerk-js/src/ui/components/ApiKeys/ApiKeys.tsx
wobsoriano 90c3203
chore: revert
wobsoriano 328a9ec
Merge branch 'main' into rob/robo-20-manage-api-keys
wobsoriano 2d686b6
test: accommodate new snapshot test
wobsoriano 2bfa305
chore: adjust bundlewatch config
wobsoriano 6e73c4d
accommodate test file suffix changes
wobsoriano 46ddfe9
Merge branch 'main' into rob/robo-20-manage-api-keys
wobsoriano 7438cfb
chore: fix formatting
wobsoriano f2b0e1d
Update packages/clerk-js/src/core/resources/__tests__/Environment.spe…
wobsoriano 37c91b9
chore: add session token check
wobsoriano 195b770
chore: adjust bundlewatch config
wobsoriano 5e2c11e
chore: make sure api keys feature is enabled before mounting
wobsoriano 3952dd6
chore: adjust bundlewatch config
wobsoriano 8eda216
chore: adjust bundlewatch config
wobsoriano 906c587
chore: adjust bundlewatch config
wobsoriano 4d7db36
Merge branch 'main' into rob/robo-20-manage-api-keys
wobsoriano bb83927
chore: add telemetry and internal snapshot
wobsoriano d3380b1
chore: fix conflicts
wobsoriano 8d2c81c
chore: adjust bundlewatch config
wobsoriano 48204ab
chore: adjust bundlewatch config
wobsoriano 40e8ad5
chore: do not swallow errors in methods
wobsoriano 1244f0a
chore: bring back early access message
wobsoriano 3eae712
chore: adjust bundlewatch config
wobsoriano 6ca472d
Apply suggestions from code review
wobsoriano c075164
chore: address suggestions
wobsoriano 9d8462f
chore: adjust bundlewatch config
wobsoriano 10da0b5
chore: address top level date locale
wobsoriano a0edca2
Apply suggestions from code review
wobsoriano a1b2821
Merge branch 'main' into rob/robo-20-manage-api-keys
wobsoriano ab7f878
chore: adjust bundlewatch config
wobsoriano b1e175c
chore: adjust bundlewatch config
wobsoriano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,6 @@ | ||
--- | ||
'@clerk/localizations': patch | ||
'@clerk/types': patch | ||
--- | ||
|
||
Add TypeScript types and en-US localization for upcoming `<APIKeys />` component. This component will initially be in early access. |
This file contains hidden or 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,7 @@ | ||
--- | ||
'@clerk/clerk-js': minor | ||
'@clerk/nextjs': minor | ||
'@clerk/clerk-react': minor | ||
--- | ||
|
||
Add `<APIKeys />` component. This component will initially be in early access and not recommended for production usage just yet. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,103 @@ | ||
import type { | ||
ApiKeyJSON, | ||
APIKeyResource, | ||
APIKeysNamespace, | ||
CreateAPIKeyParams, | ||
GetAPIKeysParams, | ||
RevokeAPIKeyParams, | ||
} from '@clerk/types'; | ||
|
||
import type { FapiRequestInit } from '@/core/fapiClient'; | ||
|
||
import { APIKey, BaseResource, ClerkRuntimeError } from '../../resources/internal'; | ||
|
||
export class APIKeys implements APIKeysNamespace { | ||
/** | ||
* Returns the base options for the FAPI proxy requests. | ||
*/ | ||
private async getBaseFapiProxyOptions(): Promise<FapiRequestInit> { | ||
const token = await BaseResource.clerk.session?.getToken(); | ||
if (!token) { | ||
throw new ClerkRuntimeError('No valid session token available', { code: 'no_session_token' }); | ||
} | ||
|
||
return { | ||
// Set to an empty string because FAPI Proxy does not include the version in the path. | ||
pathPrefix: '', | ||
// Set the session token as a Bearer token in the Authorization header for authentication. | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
// Set to `same-origin` to ensure cookies and credentials are sent with requests, avoiding CORS issues. | ||
credentials: 'same-origin', | ||
}; | ||
} | ||
|
||
async getAll(params?: GetAPIKeysParams): Promise<APIKeyResource[]> { | ||
return BaseResource.clerk | ||
.getFapiClient() | ||
.request<{ api_keys: ApiKeyJSON[] }>({ | ||
...(await this.getBaseFapiProxyOptions()), | ||
method: 'GET', | ||
path: '/api_keys', | ||
search: { | ||
subject: params?.subject ?? BaseResource.clerk.organization?.id ?? BaseResource.clerk.user?.id ?? '', | ||
}, | ||
}) | ||
.then(res => { | ||
const apiKeysJSON = res.payload as unknown as { api_keys: ApiKeyJSON[] }; | ||
return apiKeysJSON.api_keys.map(json => new APIKey(json)); | ||
}) | ||
.catch(() => []); | ||
} | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
async getSecret(id: string): Promise<string> { | ||
return BaseResource.clerk | ||
.getFapiClient() | ||
.request<{ secret: string }>({ | ||
...(await this.getBaseFapiProxyOptions()), | ||
method: 'GET', | ||
path: `/api_keys/${id}/secret`, | ||
}) | ||
.then(res => { | ||
const { secret } = res.payload as unknown as { secret: string }; | ||
return secret; | ||
}) | ||
.catch(() => ''); | ||
} | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
async create(params: CreateAPIKeyParams): Promise<APIKeyResource> { | ||
const json = ( | ||
await BaseResource._fetch<ApiKeyJSON>({ | ||
...(await this.getBaseFapiProxyOptions()), | ||
path: '/api_keys', | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
type: params.type ?? 'api_key', | ||
name: params.name, | ||
subject: params.subject ?? BaseResource.clerk.organization?.id ?? BaseResource.clerk.user?.id ?? '', | ||
description: params.description, | ||
seconds_until_expiration: params.secondsUntilExpiration, | ||
}), | ||
}) | ||
)?.response as ApiKeyJSON; | ||
|
||
return new APIKey(json); | ||
} | ||
wobsoriano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
async revoke(params: RevokeAPIKeyParams): Promise<APIKeyResource> { | ||
const json = ( | ||
await BaseResource._fetch<ApiKeyJSON>({ | ||
...(await this.getBaseFapiProxyOptions()), | ||
method: 'POST', | ||
path: `/api_keys/${params.apiKeyID}/revoke`, | ||
body: JSON.stringify({ | ||
revocation_reason: params.revocationReason, | ||
}), | ||
}) | ||
)?.response as ApiKeyJSON; | ||
|
||
return new APIKey(json); | ||
} | ||
wobsoriano marked this conversation as resolved.
Show resolved
Hide resolved
wobsoriano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains hidden or 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,52 @@ | ||
import type { ApiKeyJSON, APIKeyResource } from '@clerk/types'; | ||
|
||
import { unixEpochToDate } from '../../utils/date'; | ||
import { BaseResource } from './internal'; | ||
|
||
export class APIKey extends BaseResource implements APIKeyResource { | ||
pathRoot = '/api_keys'; | ||
|
||
id!: string; | ||
type!: string; | ||
name!: string; | ||
subject!: string; | ||
scopes!: string[]; | ||
claims!: Record<string, any> | null; | ||
revoked!: boolean; | ||
revocationReason!: string | null; | ||
expired!: boolean; | ||
expiration!: Date | null; | ||
createdBy!: string | null; | ||
description!: string | null; | ||
lastUsedAt!: Date | null; | ||
createdAt!: Date; | ||
updatedAt!: Date; | ||
|
||
constructor(data: ApiKeyJSON) { | ||
super(); | ||
this.fromJSON(data); | ||
} | ||
|
||
protected fromJSON(data: ApiKeyJSON | null): this { | ||
if (!data) { | ||
return this; | ||
} | ||
|
||
this.id = data.id; | ||
this.type = data.type; | ||
this.name = data.name; | ||
this.subject = data.subject; | ||
this.scopes = data.scopes; | ||
this.claims = data.claims; | ||
this.revoked = data.revoked; | ||
this.revocationReason = data.revocation_reason; | ||
this.expired = data.expired; | ||
this.expiration = data.expiration ? unixEpochToDate(data.expiration) : null; | ||
this.createdBy = data.created_by; | ||
this.description = data.description; | ||
this.lastUsedAt = data.last_used_at ? unixEpochToDate(data.last_used_at) : null; | ||
this.updatedAt = unixEpochToDate(data.updated_at); | ||
wobsoriano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.createdAt = unixEpochToDate(data.created_at); | ||
return this; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ This seems to be missing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's do it, added! |
||
} |
This file contains hidden or 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,31 @@ | ||
import type { APIKeysSettingsJSON, APIKeysSettingsJSONSnapshot, APIKeysSettingsResource } from '@clerk/types'; | ||
|
||
import { BaseResource } from './internal'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export class APIKeySettings extends BaseResource implements APIKeysSettingsResource { | ||
enabled: boolean = false; | ||
|
||
public constructor(data: APIKeysSettingsJSON | APIKeysSettingsJSONSnapshot | null = null) { | ||
super(); | ||
this.fromJSON(data); | ||
} | ||
|
||
protected fromJSON(data: APIKeysSettingsJSON | APIKeysSettingsJSONSnapshot | null): this { | ||
if (!data) { | ||
return this; | ||
} | ||
|
||
this.enabled = this.withDefault(data.enabled, false); | ||
|
||
return this; | ||
} | ||
|
||
public __internal_toSnapshot(): APIKeysSettingsJSONSnapshot { | ||
return { | ||
enabled: this.enabled, | ||
} as APIKeysSettingsJSONSnapshot; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a telemetry record here?
Example:
javascript/packages/clerk-js/src/core/clerk.ts
Line 758 in 48be55b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I missed this, thanks! added