Added domain model, repo improvements

This commit is contained in:
Filip Znachor 2024-07-02 21:57:40 +02:00
parent dcb0c014f2
commit a018f01d2a
5 changed files with 61 additions and 1 deletions

2
.npmignore Normal file
View file

@ -0,0 +1,2 @@
src/
!lib/**

3
README.md Normal file
View file

@ -0,0 +1,3 @@
# oohost.js
TypeScript library for accessing the oohost API

View file

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

View file

@ -2,4 +2,5 @@ export * from "./API";
export * from "./APIList";
export * from "./models/Base";
export * from "./models/User";
export * from "./models/Domain";
export * from "./models/Certificate";

54
src/models/Domain.ts Normal file
View file

@ -0,0 +1,54 @@
import { API, Response } from "../API";
import { APIList } from "../APIList";
import { UserInclude } from "./User";
export class Domain {
public readonly selector: DomainSelector = {};
constructor(selector: string) {
let id = parseInt(selector);
if (Number.isInteger(id)) {
this.selector.id = id;
} else {
this.selector.domain = selector;
}
}
public async getDetails() {
let res = await API.get("domains/details", {...this.selector});
let details: DomainDetails | null = res.get().details ?? null;
return {details, res};
}
public async remove(): Promise<Response> {
return await API.get("domains/remove", {...this.selector});
}
public static async add(domain: string) {
let res = await API.get("domains/add", {domain});
let id: number | null = res.success ? res.get().info.id : null;
return {id, res};
}
public static getList(): APIList<DomainListItem> {
return new APIList("domains/list");
}
}
export interface DomainSelector {
id?: number,
domain?: string
}
export interface DomainListItem {
id: number,
domain: string,
status: number,
created_at: string,
updated_at: string,
User: UserInclude
}
export type DomainDetails = DomainListItem;