api-client: move base api and session to internal subfolder
This commit is contained in:
parent
4755787b69
commit
afe9917169
2 changed files with 14 additions and 8 deletions
|
@ -1,11 +1,12 @@
|
|||
import { CobaltResponseType, type CobaltAPIResponse } from "./types/response";
|
||||
import type { CobaltRequest } from "./types/request";
|
||||
import { CobaltReachabilityError } from "./types/errors";
|
||||
import { CobaltResponseType, type CobaltAPIResponse } from "../types/response";
|
||||
import type { CobaltRequest } from "../types/request";
|
||||
import { CobaltReachabilityError } from "../types/errors";
|
||||
|
||||
export default class CobaltAPI {
|
||||
export default class BaseCobaltAPI {
|
||||
#baseURL: string;
|
||||
#userAgent: string | undefined;
|
||||
|
||||
constructor(baseURL: string) {
|
||||
constructor(baseURL: string, userAgent?: string) {
|
||||
const url = new URL(baseURL);
|
||||
|
||||
if (baseURL !== url.origin && baseURL !== `${url.origin}/`) {
|
||||
|
@ -13,9 +14,14 @@ export default class CobaltAPI {
|
|||
}
|
||||
|
||||
this.#baseURL = url.origin;
|
||||
this.#userAgent = userAgent;
|
||||
}
|
||||
|
||||
async request(data: CobaltRequest, headers: Record<string, string>) {
|
||||
protected async _request(data: CobaltRequest, headers: Record<string, string>) {
|
||||
if (this.#userAgent) {
|
||||
headers['user-agent'] = this.#userAgent;
|
||||
}
|
||||
|
||||
const response: CobaltAPIResponse = await fetch(this.#baseURL, {
|
||||
method: 'POST',
|
||||
redirect: 'manual',
|
|
@ -1,5 +1,5 @@
|
|||
import { CobaltSession, CobaltResponseType, CobaltSessionResponse } from "./types/response";
|
||||
import { CobaltReachabilityError } from "./types/errors";
|
||||
import { CobaltSession, CobaltResponseType, CobaltSessionResponse } from "../types/response";
|
||||
import { CobaltReachabilityError } from "../types/errors";
|
||||
|
||||
const currentTime = () => Math.floor(new Date().getTime() / 1000);
|
||||
const EXPIRY_THRESHOLD_SECONDS = 2;
|
Loading…
Reference in a new issue