mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-10-18 19:30:27 +08:00
Remove session client and other non used methods from httpd-client
This commit is contained in:
@@ -10,7 +10,6 @@ import type {
|
||||
} from "./lib/project.js";
|
||||
import type {
|
||||
Config,
|
||||
SuccessResponse,
|
||||
CodeLocation,
|
||||
Range,
|
||||
SeedingPolicy,
|
||||
@@ -47,13 +46,11 @@ import { z, array, literal, number, object, string, union } from "zod";
|
||||
|
||||
import * as project from "./lib/project.js";
|
||||
import * as profile from "./lib/profile.js";
|
||||
import * as session from "./lib/session.js";
|
||||
import { Fetcher } from "./lib/fetcher.js";
|
||||
import {
|
||||
nodeConfigSchema,
|
||||
scopeSchema,
|
||||
seedingPolicySchema,
|
||||
successResponseSchema,
|
||||
} from "./lib/shared.js";
|
||||
|
||||
export type {
|
||||
@@ -154,7 +151,6 @@ export class HttpdClient {
|
||||
public baseUrl: BaseUrl;
|
||||
public project: project.Client;
|
||||
public profile: profile.Client;
|
||||
public session: session.Client;
|
||||
|
||||
public constructor(baseUrl: BaseUrl) {
|
||||
this.baseUrl = baseUrl;
|
||||
@@ -162,7 +158,6 @@ export class HttpdClient {
|
||||
|
||||
this.project = new project.Client(this.#fetcher);
|
||||
this.profile = new profile.Client(this.#fetcher);
|
||||
this.session = new session.Client(this.#fetcher);
|
||||
}
|
||||
|
||||
public changePort(port: number): void {
|
||||
@@ -227,38 +222,6 @@ export class HttpdClient {
|
||||
);
|
||||
}
|
||||
|
||||
public async seedById(
|
||||
id: string,
|
||||
authToken: string,
|
||||
options?: RequestOptions,
|
||||
): Promise<SuccessResponse> {
|
||||
return this.#fetcher.fetchOk(
|
||||
{
|
||||
method: "PUT",
|
||||
path: `node/policies/repos/${id}`,
|
||||
headers: { Authorization: `Bearer ${authToken}` },
|
||||
options,
|
||||
},
|
||||
successResponseSchema,
|
||||
);
|
||||
}
|
||||
|
||||
public async stopSeedingById(
|
||||
id: string,
|
||||
authToken: string,
|
||||
options?: RequestOptions,
|
||||
): Promise<SuccessResponse> {
|
||||
return this.#fetcher.fetchOk(
|
||||
{
|
||||
method: "DELETE",
|
||||
path: `node/policies/repos/${id}`,
|
||||
headers: { Authorization: `Bearer ${authToken}` },
|
||||
options,
|
||||
},
|
||||
successResponseSchema,
|
||||
);
|
||||
}
|
||||
|
||||
public async getNode(options?: RequestOptions): Promise<Node> {
|
||||
return this.#fetcher.fetchOk(
|
||||
{
|
||||
|
||||
+4
-106
@@ -1,19 +1,8 @@
|
||||
import type { ZodSchema } from "zod";
|
||||
import type { Fetcher, RequestOptions } from "./fetcher.js";
|
||||
import type { Embed } from "./project/comment.js";
|
||||
import type { Commit, Commits } from "./project/commit.js";
|
||||
import type {
|
||||
Issue,
|
||||
IssueCreated,
|
||||
IssueUpdateAction,
|
||||
} from "./project/issue.js";
|
||||
import type {
|
||||
Patch,
|
||||
PatchCreate,
|
||||
PatchCreated,
|
||||
PatchUpdateAction,
|
||||
} from "./project/patch.js";
|
||||
import type { SuccessResponse } from "./shared.js";
|
||||
import type { Issue } from "./project/issue.js";
|
||||
import type { Patch } from "./project/patch.js";
|
||||
|
||||
import {
|
||||
array,
|
||||
@@ -27,7 +16,6 @@ import {
|
||||
union,
|
||||
z,
|
||||
} from "zod";
|
||||
import { successResponseSchema } from "./shared.js";
|
||||
|
||||
import {
|
||||
commitHeaderSchema,
|
||||
@@ -36,18 +24,8 @@ import {
|
||||
diffBlobSchema,
|
||||
diffSchema,
|
||||
} from "./project/commit.js";
|
||||
|
||||
import {
|
||||
issueCreatedSchema,
|
||||
issueSchema,
|
||||
issuesSchema,
|
||||
} from "./project/issue.js";
|
||||
|
||||
import {
|
||||
patchCreatedSchema,
|
||||
patchSchema,
|
||||
patchesSchema,
|
||||
} from "./project/patch.js";
|
||||
import { issueSchema, issuesSchema } from "./project/issue.js";
|
||||
import { patchSchema, patchesSchema } from "./project/patch.js";
|
||||
|
||||
const projectSchema = object({
|
||||
id: string(),
|
||||
@@ -386,49 +364,6 @@ export class Client {
|
||||
);
|
||||
}
|
||||
|
||||
public async createIssue(
|
||||
id: string,
|
||||
body: {
|
||||
title: string;
|
||||
description: string;
|
||||
assignees: string[];
|
||||
embeds: Embed[];
|
||||
labels: string[];
|
||||
},
|
||||
authToken: string,
|
||||
options?: RequestOptions,
|
||||
): Promise<IssueCreated> {
|
||||
return this.#fetcher.fetchOk(
|
||||
{
|
||||
method: "POST",
|
||||
path: `projects/${id}/issues`,
|
||||
headers: { Authorization: `Bearer ${authToken}` },
|
||||
body,
|
||||
options,
|
||||
},
|
||||
issueCreatedSchema,
|
||||
);
|
||||
}
|
||||
|
||||
public async updateIssue(
|
||||
id: string,
|
||||
issueId: string,
|
||||
body: IssueUpdateAction,
|
||||
authToken: string,
|
||||
options?: RequestOptions,
|
||||
): Promise<SuccessResponse> {
|
||||
return this.#fetcher.fetchOk(
|
||||
{
|
||||
method: "PATCH",
|
||||
path: `projects/${id}/issues/${issueId}`,
|
||||
headers: { Authorization: `Bearer ${authToken}` },
|
||||
body,
|
||||
options,
|
||||
},
|
||||
successResponseSchema,
|
||||
);
|
||||
}
|
||||
|
||||
public async getPatchById(
|
||||
id: string,
|
||||
patchId: string,
|
||||
@@ -463,41 +398,4 @@ export class Client {
|
||||
patchesSchema,
|
||||
);
|
||||
}
|
||||
|
||||
public async createPatch(
|
||||
id: string,
|
||||
body: PatchCreate,
|
||||
authToken: string,
|
||||
options?: RequestOptions,
|
||||
): Promise<PatchCreated> {
|
||||
return this.#fetcher.fetchOk(
|
||||
{
|
||||
method: "POST",
|
||||
path: `projects/${id}/patches`,
|
||||
headers: { Authorization: `Bearer ${authToken}` },
|
||||
body,
|
||||
options,
|
||||
},
|
||||
patchCreatedSchema,
|
||||
);
|
||||
}
|
||||
|
||||
public async updatePatch(
|
||||
id: string,
|
||||
patchId: string,
|
||||
body: PatchUpdateAction,
|
||||
authToken: string,
|
||||
options?: RequestOptions,
|
||||
): Promise<SuccessResponse> {
|
||||
return this.#fetcher.fetchOk(
|
||||
{
|
||||
method: "PATCH",
|
||||
path: `projects/${id}/patches/${patchId}`,
|
||||
headers: { Authorization: `Bearer ${authToken}` },
|
||||
body,
|
||||
options,
|
||||
},
|
||||
successResponseSchema,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
import type { Fetcher, RequestOptions } from "./fetcher.js";
|
||||
import type { SuccessResponse } from "./shared.js";
|
||||
import type { z } from "zod";
|
||||
|
||||
import { number, object, string } from "zod";
|
||||
|
||||
import { successResponseSchema } from "./shared.js";
|
||||
|
||||
export const sessionPayloadSchema = object({
|
||||
sessionId: string(),
|
||||
signature: string(),
|
||||
publicKey: string(),
|
||||
});
|
||||
|
||||
export type SessionPayload = z.infer<typeof sessionPayloadSchema>;
|
||||
|
||||
const sessionSchema = object({
|
||||
sessionId: string(),
|
||||
status: string(),
|
||||
publicKey: string(),
|
||||
alias: string(),
|
||||
issuedAt: number(),
|
||||
expiresAt: number(),
|
||||
});
|
||||
|
||||
export type Session = z.infer<typeof sessionSchema>;
|
||||
|
||||
export class Client {
|
||||
#fetcher: Fetcher;
|
||||
|
||||
public constructor(fetcher: Fetcher) {
|
||||
this.#fetcher = fetcher;
|
||||
}
|
||||
|
||||
public async getById(id: string, options?: RequestOptions): Promise<Session> {
|
||||
return this.#fetcher.fetchOk(
|
||||
{
|
||||
method: "GET",
|
||||
path: `sessions/${id}`,
|
||||
options,
|
||||
},
|
||||
sessionSchema,
|
||||
);
|
||||
}
|
||||
|
||||
public async create(options?: RequestOptions): Promise<Session> {
|
||||
return this.#fetcher.fetchOk(
|
||||
{
|
||||
method: "POST",
|
||||
path: "sessions",
|
||||
options,
|
||||
},
|
||||
sessionSchema,
|
||||
);
|
||||
}
|
||||
|
||||
public async update(
|
||||
id: string,
|
||||
body: {
|
||||
sig: string;
|
||||
pk: string;
|
||||
},
|
||||
options?: RequestOptions,
|
||||
): Promise<SuccessResponse> {
|
||||
return this.#fetcher.fetchOk(
|
||||
{
|
||||
method: "PUT",
|
||||
path: `sessions/${id}`,
|
||||
body,
|
||||
options,
|
||||
},
|
||||
successResponseSchema,
|
||||
);
|
||||
}
|
||||
|
||||
public async delete(
|
||||
id: string,
|
||||
options?: RequestOptions,
|
||||
): Promise<SuccessResponse> {
|
||||
return this.#fetcher.fetchOk(
|
||||
{
|
||||
method: "DELETE",
|
||||
path: `sessions/${id}`,
|
||||
headers: { Authorization: `Bearer ${id}` },
|
||||
options,
|
||||
},
|
||||
successResponseSchema,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ZodSchema, z } from "zod";
|
||||
import type { z } from "zod";
|
||||
|
||||
import { array, boolean, literal, number, object, string, union } from "zod";
|
||||
|
||||
@@ -6,10 +6,6 @@ export interface SuccessResponse {
|
||||
success: true;
|
||||
}
|
||||
|
||||
export const successResponseSchema = object({
|
||||
success: literal(true),
|
||||
}) satisfies ZodSchema<SuccessResponse>;
|
||||
|
||||
export const scopeSchema = union([literal("followed"), literal("all")]);
|
||||
|
||||
export const seedingPolicySchema = union([
|
||||
|
||||
Reference in New Issue
Block a user