Skip to content

Commit e900e13

Browse files
committed
chore: add machines BAPI endpoints
1 parent 68bcb7e commit e900e13

File tree

7 files changed

+102
-0
lines changed

7 files changed

+102
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { joinPaths } from '../../util/path';
2+
import type { PaginatedResourceResponse } from '../resources/Deserializer';
3+
import type { Machine } from '../resources/Machine';
4+
import { AbstractAPI } from './AbstractApi';
5+
6+
const basePath = '/machines';
7+
8+
type CreateMachineParams = {
9+
name: string;
10+
};
11+
12+
type UpdateMachineParams = {
13+
machineId: string;
14+
name: string;
15+
};
16+
17+
type DeleteMachineParams = {
18+
machineId: string;
19+
};
20+
21+
type GetMachineListParams = {
22+
limit?: number;
23+
offset?: number;
24+
query?: string;
25+
};
26+
27+
export class MachineApi extends AbstractAPI {
28+
async list(queryParams: GetMachineListParams = {}) {
29+
return this.request<PaginatedResourceResponse<Machine[]>>({
30+
method: 'GET',
31+
path: basePath,
32+
queryParams,
33+
});
34+
}
35+
36+
async create(bodyParams: CreateMachineParams) {
37+
return this.request<Machine>({
38+
method: 'POST',
39+
path: basePath,
40+
bodyParams,
41+
});
42+
}
43+
44+
async update(params: UpdateMachineParams) {
45+
const { machineId, ...bodyParams } = params;
46+
this.requireId(machineId);
47+
return this.request<Machine>({
48+
method: 'PATCH',
49+
path: joinPaths(basePath, machineId),
50+
bodyParams,
51+
});
52+
}
53+
54+
async delete(params: DeleteMachineParams) {
55+
const { machineId } = params;
56+
this.requireId(machineId);
57+
return this.request<Machine>({
58+
method: 'DELETE',
59+
path: joinPaths(basePath, machineId),
60+
});
61+
}
62+
63+
async get(machineId: string) {
64+
this.requireId(machineId);
65+
return this.request<Machine>({
66+
method: 'GET',
67+
path: joinPaths(basePath, machineId),
68+
});
69+
}
70+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export * from './EmailAddressApi';
1111
export * from './IdPOAuthAccessTokenApi';
1212
export * from './InstanceApi';
1313
export * from './InvitationApi';
14+
export * from './MachineApi';
1415
export * from './MachineTokensApi';
1516
export * from './JwksApi';
1617
export * from './JwtTemplatesApi';

packages/backend/src/api/factory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
InvitationAPI,
1414
JwksAPI,
1515
JwtTemplatesApi,
16+
MachineApi,
1617
MachineTokensApi,
1718
OAuthApplicationsApi,
1819
OrganizationAPI,
@@ -64,6 +65,7 @@ export function createBackendApiClient(options: CreateBackendApiOptions) {
6465
invitations: new InvitationAPI(request),
6566
jwks: new JwksAPI(request),
6667
jwtTemplates: new JwtTemplatesApi(request),
68+
machines: new MachineApi(request),
6769
machineTokens: new MachineTokensApi(
6870
buildRequest({
6971
...options,

packages/backend/src/api/resources/Deserializer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
InstanceSettings,
1616
Invitation,
1717
JwtTemplate,
18+
Machine,
1819
MachineToken,
1920
OauthAccessToken,
2021
OAuthApplication,
@@ -132,6 +133,8 @@ function jsonToObject(item: any): any {
132133
return Invitation.fromJSON(item);
133134
case ObjectType.JwtTemplate:
134135
return JwtTemplate.fromJSON(item);
136+
case ObjectType.Machine:
137+
return Machine.fromJSON(item);
135138
case ObjectType.MachineToken:
136139
return MachineToken.fromJSON(item);
137140
case ObjectType.OauthAccessToken:

packages/backend/src/api/resources/JSON.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const ObjectType = {
3434
InstanceRestrictions: 'instance_restrictions',
3535
InstanceSettings: 'instance_settings',
3636
Invitation: 'invitation',
37+
Machine: 'machine',
3738
MachineToken: 'machine_to_machine_token',
3839
JwtTemplate: 'jwt_template',
3940
OauthAccessToken: 'oauth_access_token',
@@ -698,6 +699,15 @@ export interface SamlAccountConnectionJSON extends ClerkResourceJSON {
698699
updated_at: number;
699700
}
700701

702+
export interface MachineJSON extends ClerkResourceJSON {
703+
object: typeof ObjectType.Machine;
704+
id: string;
705+
name: string;
706+
instance_id: string;
707+
created_at: number;
708+
updated_at: number;
709+
}
710+
701711
export interface MachineTokenJSON extends ClerkResourceJSON {
702712
object: typeof ObjectType.MachineToken;
703713
name: string;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { MachineJSON } from './JSON';
2+
3+
export class Machine {
4+
constructor(
5+
readonly id: string,
6+
readonly name: string,
7+
readonly instanceId: string,
8+
readonly createdAt: number,
9+
readonly updatedAt: number,
10+
) {}
11+
12+
static fromJSON(data: MachineJSON): Machine {
13+
return new Machine(data.id, data.name, data.instance_id, data.created_at, data.updated_at);
14+
}
15+
}

packages/backend/src/api/resources/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export * from './InstanceRestrictions';
3030
export * from './InstanceSettings';
3131
export * from './Invitation';
3232
export * from './JSON';
33+
export * from './Machine';
3334
export * from './MachineToken';
3435
export * from './JwtTemplate';
3536
export * from './OauthAccessToken';

0 commit comments

Comments
 (0)