Improved Certificate class

This commit is contained in:
Filip Znachor 2024-07-01 19:02:20 +02:00
parent 774de8365e
commit dcb0c014f2
2 changed files with 24 additions and 9 deletions

View file

@ -1,6 +1,6 @@
{
"name": "oohost.js",
"version": "0.0.4",
"version": "0.0.5",
"description": "TypeScript library for accessing the oohost API",
"license": "MIT",
"author": "oohost.cz",

View file

@ -1,6 +1,5 @@
import { API, Response } from "../API";
import { APIList } from "../APIList";
import { PromisedData } from "./Base";
import { UserInclude } from "./User";
export class Certificate {
@ -11,9 +10,10 @@ export class Certificate {
this.id = id;
}
public async getDetails(): PromisedData<CertificateDetails> {
let r = await API.get("certs/details", {id: this.id});
return [ r.get().details ?? null, r.getErrors() ];
public async getDetails() {
let res = await API.get("certs/details", {id: this.id});
let details: CertificateDetails | null = res.get().details ?? null;
return {details, res};
}
public async remove(): Promise<Response> {
@ -28,16 +28,31 @@ export class Certificate {
return await API.get("certs/edit", {id: this.id, ...data});
}
public static async add(name: string, private_key: string, certificate: string) {
let res = await API.get("certs/add", {name, private_key, certificate});
let id: number | null = res.success ? res.get().info.id : null;
return {id, res};
}
public static async generate(domains: string) {
let res = await API.get("certs/generate", {domains});
let data: CertificateData | null = res.success ? res.get().certificate : null;
return {data, res};
}
public static getList(): APIList<CertificateListItem> {
return new APIList("certs/list");
}
}
export interface CertificateEdit {
name?: string,
private_key?: string,
certificate?: string
export interface CertificateData {
private_key: string,
certificate: string
}
export interface CertificateEdit extends Partial<CertificateData> {
name?: string
}
export interface CertificateListItem {