@strayl/coregit 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/branches.d.ts +17 -0
- package/dist/branches.d.ts.map +1 -0
- package/dist/branches.js +21 -0
- package/dist/branches.js.map +1 -0
- package/dist/commits.d.ts +13 -0
- package/dist/commits.d.ts.map +1 -0
- package/dist/commits.js +21 -0
- package/dist/commits.js.map +1 -0
- package/dist/diff.d.ts +8 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +10 -0
- package/dist/diff.js.map +1 -0
- package/dist/files.d.ts +10 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +17 -0
- package/dist/files.js.map +1 -0
- package/dist/http.d.ts +11 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +69 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/repos.d.ts +14 -0
- package/dist/repos.d.ts.map +1 -0
- package/dist/repos.js +27 -0
- package/dist/repos.js.map +1 -0
- package/dist/snapshots.d.ts +14 -0
- package/dist/snapshots.d.ts.map +1 -0
- package/dist/snapshots.js +21 -0
- package/dist/snapshots.js.map +1 -0
- package/dist/types.d.ts +194 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/usage.d.ts +9 -0
- package/dist/usage.d.ts.map +1 -0
- package/dist/usage.js +19 -0
- package/dist/usage.js.map +1 -0
- package/package.json +37 -0
- package/src/branches.ts +37 -0
- package/src/commits.ts +28 -0
- package/src/diff.ts +11 -0
- package/src/files.ts +25 -0
- package/src/http.ts +82 -0
- package/src/index.ts +55 -0
- package/src/repos.ts +37 -0
- package/src/snapshots.ts +37 -0
- package/src/types.ts +239 -0
- package/src/usage.ts +24 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/usage.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HttpClient } from "./http";
|
|
2
|
+
import type { CoregitResult, PaginationOptions, UsageDetailsResponse, UsageSummary } from "./types";
|
|
3
|
+
export declare class UsageClient {
|
|
4
|
+
private http;
|
|
5
|
+
constructor(http: HttpClient);
|
|
6
|
+
summary(period?: string): Promise<CoregitResult<UsageSummary>>;
|
|
7
|
+
details(opts?: PaginationOptions): Promise<CoregitResult<UsageDetailsResponse>>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB,qBAAa,WAAW;IACV,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAEpC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;IAK9D,OAAO,CAAC,IAAI,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,aAAa,CAAC,oBAAoB,CAAC,CAAC;CAOhF"}
|
package/dist/usage.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class UsageClient {
|
|
2
|
+
constructor(http) {
|
|
3
|
+
this.http = http;
|
|
4
|
+
}
|
|
5
|
+
summary(period) {
|
|
6
|
+
const qs = period ? `?period=${encodeURIComponent(period)}` : "";
|
|
7
|
+
return this.http.request("GET", `/v1/usage${qs}`);
|
|
8
|
+
}
|
|
9
|
+
details(opts) {
|
|
10
|
+
const params = new URLSearchParams();
|
|
11
|
+
if (opts?.limit !== undefined)
|
|
12
|
+
params.set("limit", String(opts.limit));
|
|
13
|
+
if (opts?.offset !== undefined)
|
|
14
|
+
params.set("offset", String(opts.offset));
|
|
15
|
+
const qs = params.toString();
|
|
16
|
+
return this.http.request("GET", `/v1/usage/details${qs ? `?${qs}` : ""}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,WAAW;IACtB,YAAoB,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAExC,OAAO,CAAC,MAAe;QACrB,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,WAAW,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjE,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAe,KAAK,EAAE,YAAY,EAAE,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,OAAO,CAAC,IAAwB;QAC9B,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;QACrC,IAAI,IAAI,EAAE,KAAK,KAAK,SAAS;YAAE,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QACvE,IAAI,IAAI,EAAE,MAAM,KAAK,SAAS;YAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1E,MAAM,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAuB,KAAK,EAAE,oBAAoB,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAClG,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@strayl/coregit",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official TypeScript SDK for the Coregit API",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"src"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.json"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"coregit",
|
|
24
|
+
"git",
|
|
25
|
+
"api",
|
|
26
|
+
"sdk",
|
|
27
|
+
"serverless"
|
|
28
|
+
],
|
|
29
|
+
"author": "Strayl",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"typescript": "^5.8.3"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/branches.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { HttpClient } from "./http";
|
|
2
|
+
import type {
|
|
3
|
+
Branch,
|
|
4
|
+
BranchListResponse,
|
|
5
|
+
CoregitResult,
|
|
6
|
+
CreateBranchInput,
|
|
7
|
+
MergeInput,
|
|
8
|
+
MergeResult,
|
|
9
|
+
} from "./types";
|
|
10
|
+
|
|
11
|
+
export class BranchesClient {
|
|
12
|
+
constructor(private http: HttpClient) {}
|
|
13
|
+
|
|
14
|
+
create(repoSlug: string, input: CreateBranchInput): Promise<CoregitResult<Branch & { created: boolean }>> {
|
|
15
|
+
return this.http.request("POST", `/v1/repos/${encodeURIComponent(repoSlug)}/branches`, input);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
list(repoSlug: string): Promise<CoregitResult<BranchListResponse>> {
|
|
19
|
+
return this.http.request<BranchListResponse>("GET", `/v1/repos/${encodeURIComponent(repoSlug)}/branches`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get(repoSlug: string, name: string): Promise<CoregitResult<Branch>> {
|
|
23
|
+
return this.http.request<Branch>("GET", `/v1/repos/${encodeURIComponent(repoSlug)}/branches/${encodeURIComponent(name)}`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
delete(repoSlug: string, name: string): Promise<CoregitResult<{ deleted: boolean; name: string }>> {
|
|
27
|
+
return this.http.request("DELETE", `/v1/repos/${encodeURIComponent(repoSlug)}/branches/${encodeURIComponent(name)}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
merge(repoSlug: string, sourceBranch: string, opts?: MergeInput): Promise<CoregitResult<MergeResult>> {
|
|
31
|
+
return this.http.request<MergeResult>(
|
|
32
|
+
"POST",
|
|
33
|
+
`/v1/repos/${encodeURIComponent(repoSlug)}/branches/${encodeURIComponent(sourceBranch)}/merge`,
|
|
34
|
+
opts,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/commits.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { HttpClient } from "./http";
|
|
2
|
+
import type {
|
|
3
|
+
Commit,
|
|
4
|
+
CommitListResponse,
|
|
5
|
+
CommitResult,
|
|
6
|
+
CoregitResult,
|
|
7
|
+
CreateCommitInput,
|
|
8
|
+
} from "./types";
|
|
9
|
+
|
|
10
|
+
export class CommitsClient {
|
|
11
|
+
constructor(private http: HttpClient) {}
|
|
12
|
+
|
|
13
|
+
create(repoSlug: string, input: CreateCommitInput): Promise<CoregitResult<CommitResult>> {
|
|
14
|
+
return this.http.request<CommitResult>("POST", `/v1/repos/${encodeURIComponent(repoSlug)}/commits`, input);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
list(repoSlug: string, opts?: { ref?: string; limit?: number }): Promise<CoregitResult<CommitListResponse>> {
|
|
18
|
+
const params = new URLSearchParams();
|
|
19
|
+
if (opts?.ref) params.set("ref", opts.ref);
|
|
20
|
+
if (opts?.limit !== undefined) params.set("limit", String(opts.limit));
|
|
21
|
+
const qs = params.toString();
|
|
22
|
+
return this.http.request<CommitListResponse>("GET", `/v1/repos/${encodeURIComponent(repoSlug)}/commits${qs ? `?${qs}` : ""}`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get(repoSlug: string, sha: string): Promise<CoregitResult<Commit>> {
|
|
26
|
+
return this.http.request<Commit>("GET", `/v1/repos/${encodeURIComponent(repoSlug)}/commits/${sha}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/diff.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HttpClient } from "./http";
|
|
2
|
+
import type { CoregitResult, DiffResponse } from "./types";
|
|
3
|
+
|
|
4
|
+
export class DiffClient {
|
|
5
|
+
constructor(private http: HttpClient) {}
|
|
6
|
+
|
|
7
|
+
compare(repoSlug: string, base: string, head: string): Promise<CoregitResult<DiffResponse>> {
|
|
8
|
+
const params = new URLSearchParams({ base, head });
|
|
9
|
+
return this.http.request<DiffResponse>("GET", `/v1/repos/${encodeURIComponent(repoSlug)}/diff?${params}`);
|
|
10
|
+
}
|
|
11
|
+
}
|
package/src/files.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { HttpClient } from "./http";
|
|
2
|
+
import type {
|
|
3
|
+
BlobResponse,
|
|
4
|
+
CoregitResult,
|
|
5
|
+
RefsResponse,
|
|
6
|
+
TreeResponse,
|
|
7
|
+
} from "./types";
|
|
8
|
+
|
|
9
|
+
export class FilesClient {
|
|
10
|
+
constructor(private http: HttpClient) {}
|
|
11
|
+
|
|
12
|
+
tree(repoSlug: string, ref?: string, path?: string): Promise<CoregitResult<TreeResponse>> {
|
|
13
|
+
const refPart = ref ? `/${encodeURIComponent(ref)}` : "";
|
|
14
|
+
const pathPart = path ? `/${path}` : "";
|
|
15
|
+
return this.http.request<TreeResponse>("GET", `/v1/repos/${encodeURIComponent(repoSlug)}/tree${refPart}${pathPart}`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
blob(repoSlug: string, ref: string, path: string): Promise<CoregitResult<BlobResponse>> {
|
|
19
|
+
return this.http.request<BlobResponse>("GET", `/v1/repos/${encodeURIComponent(repoSlug)}/blob/${encodeURIComponent(ref)}/${path}`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
refs(repoSlug: string): Promise<CoregitResult<RefsResponse>> {
|
|
23
|
+
return this.http.request<RefsResponse>("GET", `/v1/repos/${encodeURIComponent(repoSlug)}/refs`);
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/http.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { FetchLike, CoregitResult, CoregitError } from "./types";
|
|
2
|
+
|
|
3
|
+
export function resolveFetch(custom?: FetchLike): FetchLike {
|
|
4
|
+
if (custom) return custom;
|
|
5
|
+
if (typeof fetch === "function") {
|
|
6
|
+
return fetch.bind(globalThis);
|
|
7
|
+
}
|
|
8
|
+
throw new Error("fetch is not available. Provide a custom implementation via options.fetch");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function toCoregitError(status: number, payload?: any): CoregitError {
|
|
12
|
+
if (payload && typeof payload === "object") {
|
|
13
|
+
if (typeof payload.error === "string") {
|
|
14
|
+
return { message: payload.error, status };
|
|
15
|
+
}
|
|
16
|
+
if (payload.error?.message) {
|
|
17
|
+
return { message: String(payload.error.message), code: payload.error.code, status };
|
|
18
|
+
}
|
|
19
|
+
if (payload.message) {
|
|
20
|
+
return { message: String(payload.message), status };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return { message: "Request failed", status };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class HttpClient {
|
|
27
|
+
private fetch: FetchLike;
|
|
28
|
+
private baseUrl: string;
|
|
29
|
+
private apiKey: string;
|
|
30
|
+
|
|
31
|
+
constructor(baseUrl: string, apiKey: string, fetchImpl: FetchLike) {
|
|
32
|
+
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
33
|
+
this.apiKey = apiKey;
|
|
34
|
+
this.fetch = fetchImpl;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async request<T>(
|
|
38
|
+
method: string,
|
|
39
|
+
path: string,
|
|
40
|
+
body?: unknown,
|
|
41
|
+
): Promise<CoregitResult<T>> {
|
|
42
|
+
const headers: Record<string, string> = {
|
|
43
|
+
"x-api-key": this.apiKey,
|
|
44
|
+
};
|
|
45
|
+
if (body !== undefined) {
|
|
46
|
+
headers["Content-Type"] = "application/json";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const response = await this.fetch(`${this.baseUrl}${path}`, {
|
|
50
|
+
method,
|
|
51
|
+
headers,
|
|
52
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const contentType = response.headers.get("content-type");
|
|
56
|
+
let payload: any = null;
|
|
57
|
+
if (contentType && contentType.includes("application/json")) {
|
|
58
|
+
payload = await response.json();
|
|
59
|
+
} else {
|
|
60
|
+
const text = await response.text();
|
|
61
|
+
try {
|
|
62
|
+
payload = JSON.parse(text);
|
|
63
|
+
} catch {
|
|
64
|
+
payload = null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!response.ok) {
|
|
69
|
+
return {
|
|
70
|
+
data: null,
|
|
71
|
+
error: toCoregitError(response.status, payload),
|
|
72
|
+
status: response.status,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
data: payload as T,
|
|
78
|
+
error: null,
|
|
79
|
+
status: response.status,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { HttpClient, resolveFetch } from "./http";
|
|
2
|
+
import { ReposClient } from "./repos";
|
|
3
|
+
import { BranchesClient } from "./branches";
|
|
4
|
+
import { CommitsClient } from "./commits";
|
|
5
|
+
import { FilesClient } from "./files";
|
|
6
|
+
import { DiffClient } from "./diff";
|
|
7
|
+
import { SnapshotsClient } from "./snapshots";
|
|
8
|
+
import { UsageClient } from "./usage";
|
|
9
|
+
import type { CoregitClientOptions } from "./types";
|
|
10
|
+
|
|
11
|
+
const DEFAULT_BASE_URL = "https://api.coregit.dev";
|
|
12
|
+
|
|
13
|
+
export class CoregitClient {
|
|
14
|
+
readonly repos: ReposClient;
|
|
15
|
+
readonly branches: BranchesClient;
|
|
16
|
+
readonly commits: CommitsClient;
|
|
17
|
+
readonly files: FilesClient;
|
|
18
|
+
readonly diff: DiffClient;
|
|
19
|
+
readonly snapshots: SnapshotsClient;
|
|
20
|
+
readonly usage: UsageClient;
|
|
21
|
+
|
|
22
|
+
constructor(options: CoregitClientOptions) {
|
|
23
|
+
if (!options.apiKey) {
|
|
24
|
+
throw new Error("apiKey is required to initialize CoregitClient");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const fetchImpl = resolveFetch(options.fetch);
|
|
28
|
+
const http = new HttpClient(
|
|
29
|
+
options.baseUrl ?? DEFAULT_BASE_URL,
|
|
30
|
+
options.apiKey,
|
|
31
|
+
fetchImpl,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
this.repos = new ReposClient(http);
|
|
35
|
+
this.branches = new BranchesClient(http);
|
|
36
|
+
this.commits = new CommitsClient(http);
|
|
37
|
+
this.files = new FilesClient(http);
|
|
38
|
+
this.diff = new DiffClient(http);
|
|
39
|
+
this.snapshots = new SnapshotsClient(http);
|
|
40
|
+
this.usage = new UsageClient(http);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function createCoregitClient(options: CoregitClientOptions): CoregitClient {
|
|
45
|
+
return new CoregitClient(options);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export * from "./types";
|
|
49
|
+
export { ReposClient } from "./repos";
|
|
50
|
+
export { BranchesClient } from "./branches";
|
|
51
|
+
export { CommitsClient } from "./commits";
|
|
52
|
+
export { FilesClient } from "./files";
|
|
53
|
+
export { DiffClient } from "./diff";
|
|
54
|
+
export { SnapshotsClient } from "./snapshots";
|
|
55
|
+
export { UsageClient } from "./usage";
|
package/src/repos.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { HttpClient } from "./http";
|
|
2
|
+
import type {
|
|
3
|
+
CoregitResult,
|
|
4
|
+
CreateRepoInput,
|
|
5
|
+
PaginationOptions,
|
|
6
|
+
Repo,
|
|
7
|
+
RepoListResponse,
|
|
8
|
+
UpdateRepoInput,
|
|
9
|
+
} from "./types";
|
|
10
|
+
|
|
11
|
+
export class ReposClient {
|
|
12
|
+
constructor(private http: HttpClient) {}
|
|
13
|
+
|
|
14
|
+
create(input: CreateRepoInput): Promise<CoregitResult<Repo>> {
|
|
15
|
+
return this.http.request<Repo>("POST", "/v1/repos", input);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
list(opts?: PaginationOptions): Promise<CoregitResult<RepoListResponse>> {
|
|
19
|
+
const params = new URLSearchParams();
|
|
20
|
+
if (opts?.limit !== undefined) params.set("limit", String(opts.limit));
|
|
21
|
+
if (opts?.offset !== undefined) params.set("offset", String(opts.offset));
|
|
22
|
+
const qs = params.toString();
|
|
23
|
+
return this.http.request<RepoListResponse>("GET", `/v1/repos${qs ? `?${qs}` : ""}`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get(slug: string): Promise<CoregitResult<Repo>> {
|
|
27
|
+
return this.http.request<Repo>("GET", `/v1/repos/${encodeURIComponent(slug)}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
update(slug: string, input: UpdateRepoInput): Promise<CoregitResult<Repo>> {
|
|
31
|
+
return this.http.request<Repo>("PATCH", `/v1/repos/${encodeURIComponent(slug)}`, input);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
delete(slug: string): Promise<CoregitResult<{ deleted: boolean }>> {
|
|
35
|
+
return this.http.request<{ deleted: boolean }>("DELETE", `/v1/repos/${encodeURIComponent(slug)}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/snapshots.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { HttpClient } from "./http";
|
|
2
|
+
import type {
|
|
3
|
+
CoregitResult,
|
|
4
|
+
CreateSnapshotInput,
|
|
5
|
+
RestoreInput,
|
|
6
|
+
RestoreResult,
|
|
7
|
+
Snapshot,
|
|
8
|
+
SnapshotListResponse,
|
|
9
|
+
} from "./types";
|
|
10
|
+
|
|
11
|
+
export class SnapshotsClient {
|
|
12
|
+
constructor(private http: HttpClient) {}
|
|
13
|
+
|
|
14
|
+
create(repoSlug: string, input: CreateSnapshotInput): Promise<CoregitResult<Snapshot>> {
|
|
15
|
+
return this.http.request<Snapshot>("POST", `/v1/repos/${encodeURIComponent(repoSlug)}/snapshots`, input);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
list(repoSlug: string): Promise<CoregitResult<SnapshotListResponse>> {
|
|
19
|
+
return this.http.request<SnapshotListResponse>("GET", `/v1/repos/${encodeURIComponent(repoSlug)}/snapshots`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get(repoSlug: string, name: string): Promise<CoregitResult<Snapshot>> {
|
|
23
|
+
return this.http.request<Snapshot>("GET", `/v1/repos/${encodeURIComponent(repoSlug)}/snapshots/${encodeURIComponent(name)}`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
delete(repoSlug: string, name: string): Promise<CoregitResult<{ deleted: boolean }>> {
|
|
27
|
+
return this.http.request("DELETE", `/v1/repos/${encodeURIComponent(repoSlug)}/snapshots/${encodeURIComponent(name)}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
restore(repoSlug: string, name: string, opts?: RestoreInput): Promise<CoregitResult<RestoreResult>> {
|
|
31
|
+
return this.http.request<RestoreResult>(
|
|
32
|
+
"POST",
|
|
33
|
+
`/v1/repos/${encodeURIComponent(repoSlug)}/snapshots/${encodeURIComponent(name)}/restore`,
|
|
34
|
+
opts,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
export type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
2
|
+
|
|
3
|
+
export interface CoregitClientOptions {
|
|
4
|
+
apiKey: string;
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
fetch?: FetchLike;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface CoregitResult<T> {
|
|
10
|
+
data: T | null;
|
|
11
|
+
error: CoregitError | null;
|
|
12
|
+
status: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface CoregitError {
|
|
16
|
+
message: string;
|
|
17
|
+
code?: string;
|
|
18
|
+
status?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// --- Repos ---
|
|
22
|
+
|
|
23
|
+
export interface CreateRepoInput {
|
|
24
|
+
slug: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
default_branch?: string;
|
|
27
|
+
visibility?: "public" | "private";
|
|
28
|
+
init?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface UpdateRepoInput {
|
|
32
|
+
description?: string;
|
|
33
|
+
visibility?: "public" | "private";
|
|
34
|
+
default_branch?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface Repo {
|
|
38
|
+
id: string;
|
|
39
|
+
slug: string;
|
|
40
|
+
description: string | null;
|
|
41
|
+
default_branch: string;
|
|
42
|
+
visibility: string;
|
|
43
|
+
git_url: string;
|
|
44
|
+
api_url: string;
|
|
45
|
+
created_at: string;
|
|
46
|
+
updated_at?: string;
|
|
47
|
+
is_empty?: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface RepoListResponse {
|
|
51
|
+
repos: Repo[];
|
|
52
|
+
limit: number;
|
|
53
|
+
offset: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// --- Branches ---
|
|
57
|
+
|
|
58
|
+
export interface CreateBranchInput {
|
|
59
|
+
name: string;
|
|
60
|
+
from?: string;
|
|
61
|
+
from_sha?: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface Branch {
|
|
65
|
+
name: string;
|
|
66
|
+
sha: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface BranchListResponse {
|
|
70
|
+
branches: Branch[];
|
|
71
|
+
default_branch: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface MergeInput {
|
|
75
|
+
target?: string;
|
|
76
|
+
strategy?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface MergeResult {
|
|
80
|
+
merged: boolean;
|
|
81
|
+
sha: string;
|
|
82
|
+
strategy: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// --- Commits ---
|
|
86
|
+
|
|
87
|
+
export interface FileChange {
|
|
88
|
+
path: string;
|
|
89
|
+
content?: string;
|
|
90
|
+
encoding?: "utf-8" | "base64";
|
|
91
|
+
action?: "delete";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface CreateCommitInput {
|
|
95
|
+
branch: string;
|
|
96
|
+
message: string;
|
|
97
|
+
author: { name: string; email: string };
|
|
98
|
+
changes: FileChange[];
|
|
99
|
+
parent_sha?: string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface CommitResult {
|
|
103
|
+
sha: string;
|
|
104
|
+
tree_sha: string;
|
|
105
|
+
branch: string;
|
|
106
|
+
parent: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface Commit {
|
|
110
|
+
sha: string;
|
|
111
|
+
message: string;
|
|
112
|
+
tree: string;
|
|
113
|
+
author_name: string;
|
|
114
|
+
author_email: string;
|
|
115
|
+
timestamp: number;
|
|
116
|
+
parents: string[];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface CommitListResponse {
|
|
120
|
+
commits: Commit[];
|
|
121
|
+
ref: string;
|
|
122
|
+
has_more: boolean;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// --- Files ---
|
|
126
|
+
|
|
127
|
+
export interface TreeEntry {
|
|
128
|
+
name: string;
|
|
129
|
+
path: string;
|
|
130
|
+
type: "folder" | "file";
|
|
131
|
+
sha: string;
|
|
132
|
+
mode: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface TreeResponse {
|
|
136
|
+
items: TreeEntry[];
|
|
137
|
+
path: string;
|
|
138
|
+
ref: string;
|
|
139
|
+
sha: string;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface BlobResponse {
|
|
143
|
+
content: string;
|
|
144
|
+
encoding: "utf-8" | "base64";
|
|
145
|
+
path: string;
|
|
146
|
+
sha: string;
|
|
147
|
+
size: number;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface Ref {
|
|
151
|
+
name: string;
|
|
152
|
+
sha: string;
|
|
153
|
+
type: "branch" | "tag";
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export interface RefsResponse {
|
|
157
|
+
branches: Ref[];
|
|
158
|
+
tags: Ref[];
|
|
159
|
+
default_branch: string;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// --- Diff ---
|
|
163
|
+
|
|
164
|
+
export interface DiffFile {
|
|
165
|
+
path: string;
|
|
166
|
+
status: "added" | "removed" | "modified";
|
|
167
|
+
old_sha: string | null;
|
|
168
|
+
new_sha: string | null;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface DiffResponse {
|
|
172
|
+
base: string;
|
|
173
|
+
head: string;
|
|
174
|
+
files: DiffFile[];
|
|
175
|
+
total_files_changed: number;
|
|
176
|
+
total_additions: number;
|
|
177
|
+
total_deletions: number;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// --- Snapshots ---
|
|
181
|
+
|
|
182
|
+
export interface CreateSnapshotInput {
|
|
183
|
+
name: string;
|
|
184
|
+
branch?: string;
|
|
185
|
+
metadata?: Record<string, unknown>;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export interface Snapshot {
|
|
189
|
+
name: string;
|
|
190
|
+
branch: string;
|
|
191
|
+
commit_sha: string;
|
|
192
|
+
metadata: Record<string, unknown> | null;
|
|
193
|
+
created_at: string;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface SnapshotListResponse {
|
|
197
|
+
snapshots: Snapshot[];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export interface RestoreInput {
|
|
201
|
+
target_branch?: string;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface RestoreResult {
|
|
205
|
+
restored: boolean;
|
|
206
|
+
branch: string;
|
|
207
|
+
sha: string;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// --- Usage ---
|
|
211
|
+
|
|
212
|
+
export interface UsageSummary {
|
|
213
|
+
period: string;
|
|
214
|
+
api_calls: number;
|
|
215
|
+
repos_created: number;
|
|
216
|
+
storage_bytes: number;
|
|
217
|
+
git_transfer_bytes: number;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export interface UsageEvent {
|
|
221
|
+
id: number;
|
|
222
|
+
event_type: string;
|
|
223
|
+
quantity: number;
|
|
224
|
+
metadata: Record<string, unknown> | null;
|
|
225
|
+
recorded_at: string;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export interface UsageDetailsResponse {
|
|
229
|
+
events: UsageEvent[];
|
|
230
|
+
limit: number;
|
|
231
|
+
offset: number;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// --- Pagination ---
|
|
235
|
+
|
|
236
|
+
export interface PaginationOptions {
|
|
237
|
+
limit?: number;
|
|
238
|
+
offset?: number;
|
|
239
|
+
}
|
package/src/usage.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { HttpClient } from "./http";
|
|
2
|
+
import type {
|
|
3
|
+
CoregitResult,
|
|
4
|
+
PaginationOptions,
|
|
5
|
+
UsageDetailsResponse,
|
|
6
|
+
UsageSummary,
|
|
7
|
+
} from "./types";
|
|
8
|
+
|
|
9
|
+
export class UsageClient {
|
|
10
|
+
constructor(private http: HttpClient) {}
|
|
11
|
+
|
|
12
|
+
summary(period?: string): Promise<CoregitResult<UsageSummary>> {
|
|
13
|
+
const qs = period ? `?period=${encodeURIComponent(period)}` : "";
|
|
14
|
+
return this.http.request<UsageSummary>("GET", `/v1/usage${qs}`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
details(opts?: PaginationOptions): Promise<CoregitResult<UsageDetailsResponse>> {
|
|
18
|
+
const params = new URLSearchParams();
|
|
19
|
+
if (opts?.limit !== undefined) params.set("limit", String(opts.limit));
|
|
20
|
+
if (opts?.offset !== undefined) params.set("offset", String(opts.offset));
|
|
21
|
+
const qs = params.toString();
|
|
22
|
+
return this.http.request<UsageDetailsResponse>("GET", `/v1/usage/details${qs ? `?${qs}` : ""}`);
|
|
23
|
+
}
|
|
24
|
+
}
|