Added certificate model & improvements
This commit is contained in:
parent
3d4c04fcde
commit
639bfc2ade
8 changed files with 90 additions and 7 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
node_modules
|
||||||
|
lib
|
11
package.json
11
package.json
|
@ -1,8 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "oohost.js",
|
"name": "oohost.js",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"description": "TypeScript library for accessing the oohost API",
|
"description": "TypeScript library for accessing the oohost API",
|
||||||
"main": "src/index.ts",
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "oohost.cz",
|
"author": "oohost.cz",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -13,5 +12,11 @@
|
||||||
"oohost",
|
"oohost",
|
||||||
"webhosting",
|
"webhosting",
|
||||||
"api"
|
"api"
|
||||||
]
|
],
|
||||||
|
"main": "./lib/index.js",
|
||||||
|
"types": "./lib/index.d.ts",
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^20.14.9",
|
||||||
|
"typescript": "^5.5.2"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* Class for requesting API
|
* Class for requesting API
|
||||||
*/
|
*/
|
||||||
export default class API {
|
export class API {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default API endpoint
|
* Default API endpoint
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
import API from "./API";
|
export * from "./API";
|
||||||
|
export * from "./models/Base";
|
||||||
export { API };
|
export * from "./models/User";
|
||||||
|
export * from "./models/Certificate";
|
||||||
|
|
4
src/models/Base.ts
Normal file
4
src/models/Base.ts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import { Response } from "../API";
|
||||||
|
|
||||||
|
export type PromisedData<T> = Promise<Data<T>>;
|
||||||
|
export type Data<T> = [T | null, Response.ExtendedError[]];
|
53
src/models/Certificate.ts
Normal file
53
src/models/Certificate.ts
Normal file
|
@ -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<CertificateDetails> {
|
||||||
|
let r = await API.get("certs/details", {id: this.id});
|
||||||
|
return [ r.get().details ?? null, r.get_errors() ];
|
||||||
|
}
|
||||||
|
|
||||||
|
public async remove(): Promise<Response> {
|
||||||
|
return await API.get("certs/remove", {id: this.id});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async generate(domains: string): Promise<Response> {
|
||||||
|
return await API.get("certs/generate", {id: this.id, domains});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async edit(data: CertificateEdit): Promise<Response> {
|
||||||
|
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
|
||||||
|
}
|
6
src/models/User.ts
Normal file
6
src/models/User.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
export interface UserInclude {
|
||||||
|
id: number,
|
||||||
|
username: string,
|
||||||
|
name: string,
|
||||||
|
email: string
|
||||||
|
}
|
12
tsconfig.json
Normal file
12
tsconfig.json
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "esnext",
|
||||||
|
"strict": true,
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"declaration": true,
|
||||||
|
"outDir": "./lib"
|
||||||
|
},
|
||||||
|
"include": ["src"]
|
||||||
|
}
|
Loading…
Reference in a new issue