const getEnv = (key: string) => { return Deno.env.get(key) }; const baseUrl = getEnv("BASE_INTERNAL_URL") ?? getEnv("BASE_URL") ?? "http://localhost:8000"; const baseUrlApi = (baseUrl ?? '') + "/api"; import type { ApiRequestOptions } from './ApiRequestOptions.ts'; type Headers = Record; type Middleware = (value: T) => T | Promise; type Resolver = (options: ApiRequestOptions) => Promise; export class Interceptors { _fns: Middleware[]; constructor() { this._fns = []; } eject(fn: Middleware): void { const index = this._fns.indexOf(fn); if (index !== -1) { this._fns = [...this._fns.slice(0, index), ...this._fns.slice(index + 1)]; } } use(fn: Middleware): void { this._fns = [...this._fns, fn]; } } export type OpenAPIConfig = { BASE: string; CREDENTIALS: 'include' | 'omit' | 'same-origin'; ENCODE_PATH?: ((path: string) => string) | undefined; HEADERS?: Headers | Resolver | undefined; PASSWORD?: string | Resolver | undefined; TOKEN?: string | Resolver | undefined; USERNAME?: string | Resolver | undefined; VERSION: string; WITH_CREDENTIALS: boolean; interceptors: { request: Interceptors; response: Interceptors; }; }; export const OpenAPI: OpenAPIConfig = { BASE: baseUrlApi, CREDENTIALS: 'include', ENCODE_PATH: undefined, HEADERS: undefined, PASSWORD: undefined, TOKEN: getEnv("WM_TOKEN"), USERNAME: undefined, VERSION: '1.481.0', WITH_CREDENTIALS: true, interceptors: { request: new Interceptors(), response: new Interceptors(), }, };