@hasna/configs-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +78 -0
- package/package.json +32 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
class ConfigsClient {
|
|
3
|
+
baseUrl;
|
|
4
|
+
headers;
|
|
5
|
+
constructor(opts = {}) {
|
|
6
|
+
this.baseUrl = (opts.baseUrl ?? "http://localhost:3457").replace(/\/$/, "");
|
|
7
|
+
this.headers = { "Content-Type": "application/json" };
|
|
8
|
+
if (opts.apiKey)
|
|
9
|
+
this.headers["Authorization"] = `Bearer ${opts.apiKey}`;
|
|
10
|
+
}
|
|
11
|
+
async req(method, path, body) {
|
|
12
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
13
|
+
method,
|
|
14
|
+
headers: this.headers,
|
|
15
|
+
body: body !== undefined ? JSON.stringify(body) : undefined
|
|
16
|
+
});
|
|
17
|
+
const data = await res.json();
|
|
18
|
+
if (!res.ok)
|
|
19
|
+
throw new Error(data.error ?? `HTTP ${res.status}`);
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
async listConfigs(filter) {
|
|
23
|
+
const params = new URLSearchParams;
|
|
24
|
+
if (filter?.category)
|
|
25
|
+
params.set("category", filter.category);
|
|
26
|
+
if (filter?.agent)
|
|
27
|
+
params.set("agent", filter.agent);
|
|
28
|
+
if (filter?.kind)
|
|
29
|
+
params.set("kind", filter.kind);
|
|
30
|
+
if (filter?.search)
|
|
31
|
+
params.set("search", filter.search);
|
|
32
|
+
if (filter?.fields)
|
|
33
|
+
params.set("fields", filter.fields);
|
|
34
|
+
const qs = params.toString() ? `?${params}` : "";
|
|
35
|
+
return this.req("GET", `/api/configs${qs}`);
|
|
36
|
+
}
|
|
37
|
+
async getConfig(idOrSlug) {
|
|
38
|
+
return this.req("GET", `/api/configs/${idOrSlug}`);
|
|
39
|
+
}
|
|
40
|
+
async createConfig(input) {
|
|
41
|
+
return this.req("POST", "/api/configs", input);
|
|
42
|
+
}
|
|
43
|
+
async updateConfig(idOrSlug, input) {
|
|
44
|
+
return this.req("PUT", `/api/configs/${idOrSlug}`, input);
|
|
45
|
+
}
|
|
46
|
+
async deleteConfig(idOrSlug) {
|
|
47
|
+
await this.req("DELETE", `/api/configs/${idOrSlug}`);
|
|
48
|
+
}
|
|
49
|
+
async applyConfig(idOrSlug, dryRun = false) {
|
|
50
|
+
return this.req("POST", `/api/configs/${idOrSlug}/apply`, { dry_run: dryRun });
|
|
51
|
+
}
|
|
52
|
+
async syncDirectory(dir, direction = "from_disk", dryRun = false) {
|
|
53
|
+
return this.req("POST", "/api/sync", { dir, direction, dry_run: dryRun });
|
|
54
|
+
}
|
|
55
|
+
async listProfiles() {
|
|
56
|
+
return this.req("GET", "/api/profiles");
|
|
57
|
+
}
|
|
58
|
+
async getProfile(idOrSlug) {
|
|
59
|
+
return this.req("GET", `/api/profiles/${idOrSlug}`);
|
|
60
|
+
}
|
|
61
|
+
async applyProfile(idOrSlug, dryRun = false) {
|
|
62
|
+
return this.req("POST", `/api/profiles/${idOrSlug}/apply`, { dry_run: dryRun });
|
|
63
|
+
}
|
|
64
|
+
async listMachines() {
|
|
65
|
+
return this.req("GET", "/api/machines");
|
|
66
|
+
}
|
|
67
|
+
async getStats() {
|
|
68
|
+
return this.req("GET", "/api/stats");
|
|
69
|
+
}
|
|
70
|
+
async health() {
|
|
71
|
+
return this.req("GET", "/health");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
var src_default = ConfigsClient;
|
|
75
|
+
export {
|
|
76
|
+
src_default as default,
|
|
77
|
+
ConfigsClient
|
|
78
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hasna/configs-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Zero-dependency TypeScript client for @hasna/configs REST API",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": ["dist", "README.md"],
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/hasna/open-configs.git"
|
|
21
|
+
},
|
|
22
|
+
"author": "Andrei Hasna <andrei@hasna.com>",
|
|
23
|
+
"license": "Apache-2.0",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"typescript": "^5.7.3",
|
|
26
|
+
"@types/bun": "^1.2.4"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "bun build src/index.ts --outdir dist --target browser && tsc --emitDeclarationOnly --outDir dist",
|
|
30
|
+
"typecheck": "tsc --noEmit"
|
|
31
|
+
}
|
|
32
|
+
}
|