1+ import { IcePanelClient as Client } from "./Client"
2+ import type { BaseClientOptions } from "./BaseClient"
3+ import * as core from "./core/index"
4+ import type { IcePanelAPIVersion } from "./consts"
5+
6+ export interface IcePanelOptions extends Omit < BaseClientOptions , 'environment' | 'apiKey' | 'authorization' > {
7+ apiVersion : IcePanelAPIVersion
8+ environment ?: core . Supplier < string | undefined >
9+ apiKey ?: core . Supplier < string | undefined >
10+ authorization ?: core . Supplier < string | undefined >
11+ }
12+
13+ export class IcePanelClient extends Client {
14+ constructor ( options : IcePanelOptions ) {
15+ const updatedOptions : BaseClientOptions = {
16+ ...options ,
17+ environment : undefined ,
18+ apiKey : undefined ,
19+ authorization : undefined
20+ }
21+
22+ updatedOptions . baseUrl = async ( ) => {
23+ const baseUrl = options . baseUrl ? await core . Supplier . get ( options . baseUrl ) : undefined
24+ if ( baseUrl ) {
25+ return `https://${ baseUrl } /${ options . apiVersion } `
26+ }
27+ const environment = options . environment ? await core . Supplier . get ( options . environment ) : undefined
28+ if ( environment ) {
29+ return `https://api.${ environment } .icepanel.cloud/${ options . apiVersion } `
30+ }
31+ return `https://api.icepanel.io/${ options . apiVersion } `
32+ }
33+
34+ if ( options . apiKey ) {
35+ updatedOptions . headers = {
36+ ...updatedOptions . headers ,
37+ 'X-API-Key' : options . apiKey
38+ }
39+ }
40+
41+ if ( options . authorization ) {
42+ updatedOptions . headers = {
43+ ...updatedOptions . headers ,
44+ Authorization : options . authorization
45+ }
46+ }
47+
48+ super ( updatedOptions )
49+ }
50+ }
0 commit comments