diff --git a/package.json b/package.json index 455d99f..0e5368f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/models/Certificate.ts b/src/models/Certificate.ts index 25c7acd..3fbc24e 100644 --- a/src/models/Certificate.ts +++ b/src/models/Certificate.ts @@ -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 { - 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 { @@ -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 { 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 { + name?: string } export interface CertificateListItem {