githttp-fs-client 1.0.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/LICENSE +22 -0
- package/README.md +34 -0
- package/lib/index.ts +157 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2026 Valerian Saliou
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
|
4
|
+
obtaining a copy of this software and associated documentation
|
|
5
|
+
files (the "Software"), to deal in the Software without
|
|
6
|
+
restriction, including without limitation the rights to use,
|
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the
|
|
9
|
+
Software is furnished to do so, subject to the following
|
|
10
|
+
conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be
|
|
13
|
+
included in all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# node-githttp-fs-client
|
|
2
|
+
|
|
3
|
+
**Git HTTP FS client for Node. Used in pair with Git HTTP FS, a git-backed content management database served over HTTP.**
|
|
4
|
+
|
|
5
|
+
Git HTTP FS Client is used to manage per-tenant Git content databases, over the Git HTTP FS HTTP API. All operations supported by the Git HTTP FS HTTP API are also supported in this client.
|
|
6
|
+
|
|
7
|
+
**🇵🇹 Crafted in Lisbon, Portugal.**
|
|
8
|
+
|
|
9
|
+
## How to install?
|
|
10
|
+
|
|
11
|
+
Include `githttp-fs-client` in your `package.json` dependencies.
|
|
12
|
+
|
|
13
|
+
Alternatively, you can run `npm install githttp-fs-client --save`.
|
|
14
|
+
|
|
15
|
+
## How to use?
|
|
16
|
+
|
|
17
|
+
Then, you can import `githttp-fs-client` and start listing and committing files:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { GitHTTPFSClient } from "../lib/index.ts";
|
|
21
|
+
|
|
22
|
+
const client = new GitHTTPFSClient({
|
|
23
|
+
baseUrl: "http://localhost:5355",
|
|
24
|
+
apiKey: "MySecretAPIKey"
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const files = await client.listFiles("<your_tenant_id_here>");
|
|
28
|
+
|
|
29
|
+
console.log("Listed files:", files);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## What is Git HTTP FS?
|
|
33
|
+
|
|
34
|
+
ℹ️ **Wondering what Git HTTP FS is?** Check out **[crisp-oss/githttp-fs](https://github.com/crisp-oss/githttp-fs)**.
|
package/lib/index.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* node-githttp-fs-client
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2026, Valerian Saliou
|
|
5
|
+
* Author: Valerian Saliou <valerian@valeriansaliou.name>
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for the Git HTTP FS API client.
|
|
10
|
+
*/
|
|
11
|
+
export interface ClientConfig {
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
apiKey: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Defines the API version */
|
|
17
|
+
const VERSION = "v1";
|
|
18
|
+
|
|
19
|
+
/** Defines all HTTP methods */
|
|
20
|
+
const GET = "GET";
|
|
21
|
+
const POST = "POST";
|
|
22
|
+
const PUT = "PUT";
|
|
23
|
+
const DELETE = "DELETE";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Git HTTP FS client, manages files and commits over the Git HTTP FS HTTP API.
|
|
27
|
+
*/
|
|
28
|
+
export class GitHTTPFSClient {
|
|
29
|
+
private baseUrl: string;
|
|
30
|
+
private headers: Record<string, string>;
|
|
31
|
+
|
|
32
|
+
constructor(config: ClientConfig) {
|
|
33
|
+
// Remove trailing slash (if any)
|
|
34
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
35
|
+
|
|
36
|
+
this.headers = {
|
|
37
|
+
"Authorization": `Bearer ${config.apiKey}`,
|
|
38
|
+
"Content-Type": "application/json",
|
|
39
|
+
"Accept": "application/json"
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Helper to handle requests and parse JSON responses.
|
|
45
|
+
*/
|
|
46
|
+
private async request<T>(
|
|
47
|
+
path: string,
|
|
48
|
+
method: "GET" | "POST" | "PUT" | "DELETE",
|
|
49
|
+
body?: any,
|
|
50
|
+
params?: Record<string, string>
|
|
51
|
+
): Promise<T> {
|
|
52
|
+
const url = new URL(`${this.baseUrl}/${VERSION}/${path}`);
|
|
53
|
+
|
|
54
|
+
// Append query parameters
|
|
55
|
+
if (params) {
|
|
56
|
+
Object.entries(params).forEach(([key, value]) =>
|
|
57
|
+
url.searchParams.set(key, value)
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const options: RequestInit = {
|
|
62
|
+
method,
|
|
63
|
+
|
|
64
|
+
headers: this.headers
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
if (body && method !== GET) {
|
|
68
|
+
options.body = JSON.stringify(body);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const response = await fetch(url.toString(), options);
|
|
72
|
+
|
|
73
|
+
if (!response.ok) {
|
|
74
|
+
const errorText = await response.text();
|
|
75
|
+
|
|
76
|
+
throw new Error(`API Error [${response.status}]: ${errorText}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return response.json();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// --- Tenant Operations ---
|
|
83
|
+
|
|
84
|
+
/** Delete entire tenant repository */
|
|
85
|
+
async deleteTenant(tenantId: string) {
|
|
86
|
+
return this.request(
|
|
87
|
+
`${tenantId}`, DELETE
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** List all tracked files (path + size) */
|
|
92
|
+
async listFiles(tenantId: string) {
|
|
93
|
+
return this.request(
|
|
94
|
+
`${tenantId}/files`, GET
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Read file content */
|
|
99
|
+
async getFileContent(tenantId: string, path: string) {
|
|
100
|
+
return this.request(
|
|
101
|
+
`${tenantId}/files/${path}`, GET
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Create or update a file */
|
|
106
|
+
async putFile(tenantId: string, path: string, body: any) {
|
|
107
|
+
return this.request(
|
|
108
|
+
`${tenantId}/files/${path}`, PUT, body
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Delete a file */
|
|
113
|
+
async deleteFile(tenantId: string, path: string) {
|
|
114
|
+
return this.request(
|
|
115
|
+
`${tenantId}/files/${path}`, DELETE
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Move / rename a file */
|
|
120
|
+
async moveFile(tenantId: string, path: string, body: any) {
|
|
121
|
+
return this.request(
|
|
122
|
+
`${tenantId}/files/${path}/move`, POST, body
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// --- Commit Operations ---
|
|
127
|
+
|
|
128
|
+
/** List commits with pagination */
|
|
129
|
+
async listCommits(
|
|
130
|
+
tenantId: string,
|
|
131
|
+
page: number = 1,
|
|
132
|
+
perPage: number = 100
|
|
133
|
+
) {
|
|
134
|
+
const params = {
|
|
135
|
+
page: page.toString(),
|
|
136
|
+
per_page: Math.min(perPage, 500).toString()
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
return this.request(
|
|
140
|
+
`${tenantId}/commits`, GET, undefined, params
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Commit detail with per-file diffs and snapshots */
|
|
145
|
+
async getCommitDetail(tenantId: string, sha: string) {
|
|
146
|
+
return this.request(
|
|
147
|
+
`${tenantId}/commits/${sha}`, GET
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Revert a commit */
|
|
152
|
+
async revertCommit(tenantId: string, sha: string, body: any) {
|
|
153
|
+
return this.request(
|
|
154
|
+
`${tenantId}/commits/${sha}/revert`, POST, body
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "githttp-fs-client",
|
|
3
|
+
"description": "Git HTTP FS client for Node. Used in pair with Git HTTP FS, a git-backed content management database served over HTTP.",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"homepage": "https://github.com/crisp-oss/node-githttp-fs-client",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": {
|
|
9
|
+
"name": "Valerian Saliou",
|
|
10
|
+
"email": "valerian@valeriansaliou.name",
|
|
11
|
+
"url": "https://valeriansaliou.name/"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git://github.com/crisp-oss/node-githttp-fs-client.git"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/crisp-oss/node-githttp-fs-client/issues"
|
|
19
|
+
},
|
|
20
|
+
"licenses": [
|
|
21
|
+
{
|
|
22
|
+
"type": "MIT",
|
|
23
|
+
"url": "https://github.com/crisp-oss/node-githttp-fs-client/blob/master/LICENSE"
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"main": "lib/index.ts",
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">= 23.0.0"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"githttp-fs",
|
|
32
|
+
"git",
|
|
33
|
+
"cms"
|
|
34
|
+
]
|
|
35
|
+
}
|