@@ -15,10 +15,12 @@ import { convertPageToOffsetSearchParams } from '@/utils/convertPageToOffsetSear
1515import { APIKey , BaseResource } from '../../resources/internal' ;
1616
1717export class APIKeys implements APIKeysNamespace {
18+ static readonly #pathRoot = '/api_keys' ;
19+
1820 /**
1921 * Returns the base options for the FAPI proxy requests.
2022 */
21- private async getBaseFapiProxyOptions ( ) : Promise < FapiRequestInit > {
23+ async # getBaseFapiProxyOptions( ) : Promise < FapiRequestInit > {
2224 const token = await BaseResource . clerk . session ?. getToken ( ) ;
2325 if ( ! token ) {
2426 throw new ClerkRuntimeError ( 'No valid session token available' , { code : 'no_session_token' } ) ;
@@ -27,7 +29,7 @@ export class APIKeys implements APIKeysNamespace {
2729 return {
2830 // Set to an empty string because FAPI Proxy does not include the version in the path.
2931 pathPrefix : '' ,
30- // Set the session token as a Bearer token in the Authorization header for authentication .
32+ // FAPI Proxy looks for the session token in the Authorization header.
3133 headers : {
3234 Authorization : `Bearer ${ token } ` ,
3335 'Content-Type' : 'application/json' ,
@@ -37,11 +39,19 @@ export class APIKeys implements APIKeysNamespace {
3739 } ;
3840 }
3941
42+ /**
43+ * Retrieves a paginated list of API keys.
44+ *
45+ * The subject (owner) is resolved in the following order:
46+ * 1. Explicit `subject` param (user or organization ID)
47+ * 2. Active organization ID
48+ * 3. Current user ID
49+ */
4050 async getAll ( params ?: GetAPIKeysParams ) : Promise < ClerkPaginatedResponse < APIKeyResource > > {
4151 return BaseResource . _fetch ( {
42- ...( await this . getBaseFapiProxyOptions ( ) ) ,
52+ ...( await this . # getBaseFapiProxyOptions( ) ) ,
4353 method : 'GET' ,
44- path : '/api_keys' ,
54+ path : APIKeys . #pathRoot ,
4555 search : convertPageToOffsetSearchParams ( {
4656 ...params ,
4757 subject : params ?. subject ?? BaseResource . clerk . organization ?. id ?? BaseResource . clerk . user ?. id ?? '' ,
@@ -59,8 +69,8 @@ export class APIKeys implements APIKeysNamespace {
5969
6070 async create ( params : CreateAPIKeyParams ) : Promise < APIKeyResource > {
6171 const json = ( await BaseResource . _fetch < ApiKeyJSON > ( {
62- ...( await this . getBaseFapiProxyOptions ( ) ) ,
63- path : '/api_keys' ,
72+ ...( await this . # getBaseFapiProxyOptions( ) ) ,
73+ path : APIKeys . #pathRoot ,
6474 method : 'POST' ,
6575 body : JSON . stringify ( {
6676 type : 'api_key' ,
@@ -76,9 +86,9 @@ export class APIKeys implements APIKeysNamespace {
7686
7787 async revoke ( params : RevokeAPIKeyParams ) : Promise < APIKeyResource > {
7888 const json = ( await BaseResource . _fetch < ApiKeyJSON > ( {
79- ...( await this . getBaseFapiProxyOptions ( ) ) ,
89+ ...( await this . # getBaseFapiProxyOptions( ) ) ,
8090 method : 'POST' ,
81- path : `/api_keys /${ params . apiKeyID } /revoke` ,
91+ path : `${ APIKeys . #pathRoot } /${ params . apiKeyID } /revoke` ,
8292 body : JSON . stringify ( {
8393 revocation_reason : params . revocationReason ,
8494 } ) ,
0 commit comments