diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..491fc35 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +lib diff --git a/package.json b/package.json index 9068635..7cc48af 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,7 @@ { "name": "oohost.js", - "version": "0.0.1", + "version": "0.0.2", "description": "TypeScript library for accessing the oohost API", - "main": "src/index.ts", "license": "MIT", "author": "oohost.cz", "repository": { @@ -13,5 +12,11 @@ "oohost", "webhosting", "api" - ] + ], + "main": "./lib/index.js", + "types": "./lib/index.d.ts", + "devDependencies": { + "@types/node": "^20.14.9", + "typescript": "^5.5.2" + } } diff --git a/src/API.ts b/src/API.ts index 0217070..c38d938 100644 --- a/src/API.ts +++ b/src/API.ts @@ -1,7 +1,7 @@ /** * Class for requesting API */ -export default class API { +export class API { /** * Default API endpoint diff --git a/src/index.ts b/src/index.ts index 89ced82..1b58939 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ -import API from "./API"; - -export { API }; +export * from "./API"; +export * from "./models/Base"; +export * from "./models/User"; +export * from "./models/Certificate"; diff --git a/src/models/Base.ts b/src/models/Base.ts new file mode 100644 index 0000000..3594813 --- /dev/null +++ b/src/models/Base.ts @@ -0,0 +1,4 @@ +import { Response } from "../API"; + +export type PromisedData = Promise>; +export type Data = [T | null, Response.ExtendedError[]]; diff --git a/src/models/Certificate.ts b/src/models/Certificate.ts new file mode 100644 index 0000000..f44a587 --- /dev/null +++ b/src/models/Certificate.ts @@ -0,0 +1,53 @@ +import { API, Response } from "../API"; +import { PromisedData } from "./Base"; +import { UserInclude } from "./User"; + +export class Certificate { + + public readonly id: number; + + constructor(id: number) { + this.id = id; + } + + public async getDetails(): PromisedData { + let r = await API.get("certs/details", {id: this.id}); + return [ r.get().details ?? null, r.get_errors() ]; + } + + public async remove(): Promise { + return await API.get("certs/remove", {id: this.id}); + } + + public async generate(domains: string): Promise { + return await API.get("certs/generate", {id: this.id, domains}); + } + + public async edit(data: CertificateEdit): Promise { + return await API.get("certs/edit", {id: this.id, ...data}); + } + +} + +export interface CertificateEdit { + name?: string, + private_key?: string, + certificate?: string +} + +export interface CertificateListItem { + id: number, + name: string, + domain: string, + auto_renew: boolean, + expiration_date: string, + created_at: string, + updated_at: string, + user_id: number, + User: UserInclude +} + +export interface CertificateDetails extends CertificateListItem { + private_key: string, + certificate: string +} diff --git a/src/models/User.ts b/src/models/User.ts new file mode 100644 index 0000000..429da9b --- /dev/null +++ b/src/models/User.ts @@ -0,0 +1,6 @@ +export interface UserInclude { + id: number, + username: string, + name: string, + email: string +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..13df6df --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "target": "esnext", + "strict": true, + "moduleResolution": "node", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "declaration": true, + "outDir": "./lib" + }, + "include": ["src"] +}