feat: create type-safe API object for Headscale

This commit is contained in:
Aarnav Tale
2025-11-04 21:05:22 -05:00
parent 1c0561edb8
commit a68aedc297
27 changed files with 1378 additions and 80 deletions
@@ -0,0 +1,41 @@
import { defineApiEndpoints } from '../factory';
export interface PolicyEndpoints {
/**
* Retrieves the current ACL policy from the Headscale instance.
*
* @returns The ACL policy as a string.
*/
getPolicy(): Promise<string>;
/**
* Sets the ACL policy for the Headscale instance.
*
* @param policy The ACL policy as a string.
* @returns The expiration date of the new policy.
*/
setPolicy(policy: string): Promise<Date>;
}
export default defineApiEndpoints<PolicyEndpoints>((client, apiKey) => ({
getPolicy: async () => {
const { policy } = await client.apiFetch<{ policy: string }>(
'GET',
'v1/policy',
apiKey,
);
return policy;
},
setPolicy: async (policy) => {
const { updatedAt } = await client.apiFetch<{ updatedAt: string }>(
'PUT',
'v1/policy',
apiKey,
{ policy },
);
return new Date(updatedAt);
},
}));