Skip to content

Commit 2c4c4b1

Browse files
committed
chore: clean up
1 parent 5c2299b commit 2c4c4b1

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

packages/backend/src/api/endpoints/MachineTokensApi.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,37 @@ type RevokeMachineTokenParams = WithMachineTokenSecret<{
2929
}>;
3030

3131
export class MachineTokensApi extends AbstractAPI {
32-
/**
33-
* Attaches the machine token secret as an Authorization header if present.
34-
*/
35-
#withMachineTokenSecretHeader<T extends WithMachineTokenSecret<unknown>>(
32+
#withMachineTokenSecretHeader(
3633
options: ClerkBackendApiRequestOptions,
37-
params: T,
34+
machineTokenSecret?: string | null,
3835
): ClerkBackendApiRequestOptions {
39-
if (params.machineTokenSecret) {
36+
if (machineTokenSecret) {
4037
return {
4138
...options,
4239
headerParams: {
43-
Authorization: `Bearer ${params.machineTokenSecret}`,
40+
Authorization: `Bearer ${machineTokenSecret}`,
4441
},
4542
};
4643
}
4744
return options;
4845
}
4946

5047
async create(params: CreateMachineTokenParams) {
48+
const { machineTokenSecret, ...bodyParams } = params;
5149
return this.request<MachineToken>(
5250
this.#withMachineTokenSecretHeader(
5351
{
5452
method: 'POST',
5553
path: basePath,
56-
bodyParams: params,
54+
bodyParams,
5755
},
58-
params,
56+
machineTokenSecret,
5957
),
6058
);
6159
}
6260

6361
async update(params: UpdateMachineTokenParams) {
64-
const { m2mTokenId, ...bodyParams } = params;
62+
const { m2mTokenId, machineTokenSecret, ...bodyParams } = params;
6563
this.requireId(m2mTokenId);
6664
return this.request<MachineToken>(
6765
this.#withMachineTokenSecretHeader(
@@ -70,13 +68,13 @@ export class MachineTokensApi extends AbstractAPI {
7068
path: joinPaths(basePath, m2mTokenId),
7169
bodyParams,
7270
},
73-
params,
71+
machineTokenSecret,
7472
),
7573
);
7674
}
7775

7876
async revoke(params: RevokeMachineTokenParams) {
79-
const { m2mTokenId, ...bodyParams } = params;
77+
const { m2mTokenId, machineTokenSecret, ...bodyParams } = params;
8078
this.requireId(m2mTokenId);
8179
return this.request<MachineToken>(
8280
this.#withMachineTokenSecretHeader(
@@ -85,7 +83,7 @@ export class MachineTokensApi extends AbstractAPI {
8583
path: joinPaths(basePath, m2mTokenId, 'revoke'),
8684
bodyParams,
8785
},
88-
params,
86+
machineTokenSecret,
8987
),
9088
);
9189
}

packages/backend/src/api/factory.ts

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

40-
return {
41-
__experimental_accountlessApplications: new AccountlessApplicationAPI(
42-
buildRequest({ ...options, requireSecretKey: false }),
43-
),
44-
actorTokens: new ActorTokenAPI(request),
45-
allowlistIdentifiers: new AllowlistIdentifierAPI(request),
46-
betaFeatures: new BetaFeaturesAPI(request),
47-
blocklistIdentifiers: new BlocklistIdentifierAPI(request),
48-
clients: new ClientAPI(request),
49-
domains: new DomainAPI(request),
50-
emailAddresses: new EmailAddressAPI(request),
51-
instance: new InstanceAPI(request),
52-
invitations: new InvitationAPI(request),
53-
// Using "/" instead of an actual version since they're bapi-proxy endpoints.
54-
// bapi-proxy connects directly to C1 without URL versioning,
55-
// while API versioning is handled through the Clerk-API-Version header.
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 = {
5644
machineTokens: new MachineTokensApi(
5745
buildRequest({
5846
...options,
@@ -72,6 +60,21 @@ export function createBackendApiClient(options: CreateBackendApiOptions) {
7260
apiVersion: '/',
7361
}),
7462
),
63+
};
64+
65+
return {
66+
__experimental_accountlessApplications: new AccountlessApplicationAPI(
67+
buildRequest({ ...options, requireSecretKey: false }),
68+
),
69+
actorTokens: new ActorTokenAPI(request),
70+
allowlistIdentifiers: new AllowlistIdentifierAPI(request),
71+
betaFeatures: new BetaFeaturesAPI(request),
72+
blocklistIdentifiers: new BlocklistIdentifierAPI(request),
73+
clients: new ClientAPI(request),
74+
domains: new DomainAPI(request),
75+
emailAddresses: new EmailAddressAPI(request),
76+
instance: new InstanceAPI(request),
77+
invitations: new InvitationAPI(request),
7578
jwks: new JwksAPI(request),
7679
jwtTemplates: new JwtTemplatesApi(request),
7780
oauthApplications: new OAuthApplicationsApi(request),
@@ -87,5 +90,6 @@ export function createBackendApiClient(options: CreateBackendApiOptions) {
8790
users: new UserAPI(request),
8891
waitlistEntries: new WaitlistEntryAPI(request),
8992
webhooks: new WebhookAPI(request),
93+
...bapiProxyMethods,
9094
};
9195
}

0 commit comments

Comments
 (0)