Skip to content

Commit 06c8514

Browse files
committed
chore: use a more readable option for bapi proxy methods
1 parent 2c4c4b1 commit 06c8514

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed

packages/backend/src/api/factory.ts

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,46 +37,40 @@ export type ApiClient = ReturnType<typeof createBackendApiClient>;
3737
export function createBackendApiClient(options: CreateBackendApiOptions) {
3838
const request = buildRequest(options);
3939

40-
// Using "/" instead of an actual version since they're bapi-proxy endpoints.
41-
// bapi-proxy connects directly to C1 without URL versioning,
42-
// while API versioning is handled through the Clerk-API-Version header.
43-
const bapiProxyMethods = {
44-
machineTokens: new MachineTokensApi(
45-
buildRequest({
46-
...options,
47-
apiVersion: '/',
48-
requireSecretKey: false,
49-
}),
50-
),
51-
idPOAuthAccessToken: new IdPOAuthAccessTokenApi(
52-
buildRequest({
53-
...options,
54-
apiVersion: '/',
55-
}),
56-
),
57-
apiKeys: new APIKeysAPI(
58-
buildRequest({
59-
...options,
60-
apiVersion: '/',
61-
}),
62-
),
63-
};
64-
6540
return {
6641
__experimental_accountlessApplications: new AccountlessApplicationAPI(
6742
buildRequest({ ...options, requireSecretKey: false }),
6843
),
6944
actorTokens: new ActorTokenAPI(request),
7045
allowlistIdentifiers: new AllowlistIdentifierAPI(request),
46+
apiKeys: new APIKeysAPI(
47+
buildRequest({
48+
...options,
49+
skipApiVersionInUrl: true,
50+
}),
51+
),
7152
betaFeatures: new BetaFeaturesAPI(request),
7253
blocklistIdentifiers: new BlocklistIdentifierAPI(request),
7354
clients: new ClientAPI(request),
7455
domains: new DomainAPI(request),
7556
emailAddresses: new EmailAddressAPI(request),
57+
idPOAuthAccessToken: new IdPOAuthAccessTokenApi(
58+
buildRequest({
59+
...options,
60+
skipApiVersionInUrl: true,
61+
}),
62+
),
7663
instance: new InstanceAPI(request),
7764
invitations: new InvitationAPI(request),
7865
jwks: new JwksAPI(request),
7966
jwtTemplates: new JwtTemplatesApi(request),
67+
machineTokens: new MachineTokensApi(
68+
buildRequest({
69+
...options,
70+
skipApiVersionInUrl: true,
71+
requireSecretKey: false,
72+
}),
73+
),
8074
oauthApplications: new OAuthApplicationsApi(request),
8175
organizations: new OrganizationAPI(request),
8276
phoneNumbers: new PhoneNumberAPI(request),
@@ -90,6 +84,5 @@ export function createBackendApiClient(options: CreateBackendApiOptions) {
9084
users: new UserAPI(request),
9185
waitlistEntries: new WaitlistEntryAPI(request),
9286
webhooks: new WebhookAPI(request),
93-
...bapiProxyMethods,
9487
};
9588
}

packages/backend/src/api/request.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ type BuildRequestOptions = {
5757
* @default true
5858
*/
5959
requireSecretKey?: boolean;
60+
/**
61+
* If true, omits the API version from the request URL path.
62+
* This is required for bapi-proxy endpoints, which do not use versioning in the URL.
63+
*
64+
* Note: API versioning for these endpoints is instead handled via the `Clerk-API-Version` HTTP header.
65+
*
66+
* @default false
67+
*/
68+
skipApiVersionInUrl?: boolean;
6069
};
6170

6271
export function buildRequest(options: BuildRequestOptions) {
@@ -67,14 +76,15 @@ export function buildRequest(options: BuildRequestOptions) {
6776
apiUrl = API_URL,
6877
apiVersion = API_VERSION,
6978
userAgent = USER_AGENT,
79+
skipApiVersionInUrl = false,
7080
} = options;
7181
const { path, method, queryParams, headerParams, bodyParams, formData } = requestOptions;
7282

7383
if (requireSecretKey) {
7484
assertValidSecretKey(secretKey);
7585
}
7686

77-
const url = joinPaths(apiUrl, apiVersion, path);
87+
const url = skipApiVersionInUrl ? joinPaths(apiUrl, path) : joinPaths(apiUrl, apiVersion, path);
7888

7989
// Build final URL with search parameters
8090
const finalUrl = new URL(url);

0 commit comments

Comments
 (0)