1- import axios , { type Axios } from 'axios'
1+ import type { Axios } from 'axios'
22
3- import { getAuthHeaders } from './auth .js'
3+ import { createAxiosClient } from './axios .js'
44import {
55 InvalidSeamHttpOptionsError ,
66 isSeamHttpOptionsWithApiKey ,
99 type SeamHttpOptionsWithApiKey ,
1010 type SeamHttpOptionsWithClientSessionToken ,
1111} from './client-options.js'
12- import { LegacyWorkspaces } from './legacy/workspaces.js'
13- import { Workspaces } from './routes/workspaces.js'
12+ import { LegacyWorkspacesHttp } from './legacy/workspaces.js'
13+ import { parseOptions } from './parse-options.js'
14+ import { WorkspacesHttp } from './routes/workspaces.js'
1415
1516export class SeamHttp {
1617 client : Axios
@@ -20,18 +21,7 @@ export class SeamHttp {
2021 constructor ( apiKeyOrOptions : string | SeamHttpOptions ) {
2122 const options = parseOptions ( apiKeyOrOptions )
2223 this . #legacy = options . enableLegacyMethodBehaivor
23-
24- // TODO: axiosRetry? Allow options to configure this if so
25- this . client = axios . create ( {
26- baseURL : options . endpoint ,
27- withCredentials : isSeamHttpOptionsWithClientSessionToken ( options ) ,
28- ...options . axiosOptions ,
29- headers : {
30- ...getAuthHeaders ( options ) ,
31- ...options . axiosOptions . headers ,
32- // TODO: User-Agent
33- } ,
34- } )
24+ this . client = createAxiosClient ( options )
3525 }
3626
3727 static fromApiKey (
@@ -66,37 +56,8 @@ export class SeamHttp {
6656 // Better to implement error handling and wrapping in an error handler.
6757 // makeRequest
6858
69- get workspaces ( ) : Workspaces {
70- const workspaces = new Workspaces ( this . client )
71- if ( this . #legacy) return new LegacyWorkspaces ( this . client )
72- return workspaces
73- }
74- }
75-
76- const parseOptions = (
77- apiKeyOrOptions : string | SeamHttpOptions ,
78- ) : Required < SeamHttpOptions > => {
79- const options =
80- typeof apiKeyOrOptions === 'string'
81- ? { apiKey : apiKeyOrOptions }
82- : apiKeyOrOptions
83-
84- const endpoint =
85- options . endpoint ??
86- globalThis . process ?. env ?. [ 'SEAM_ENDPOINT' ] ??
87- globalThis . process ?. env ?. [ 'SEAM_API_URL' ] ??
88- 'https://connect.getseam.com'
89-
90- const apiKey =
91- 'apiKey' in options
92- ? options . apiKey
93- : globalThis . process ?. env ?. [ 'SEAM_API_KEY' ]
94-
95- return {
96- ...options ,
97- ...( apiKey != null ? { apiKey } : { } ) ,
98- endpoint,
99- axiosOptions : options . axiosOptions ?? { } ,
100- enableLegacyMethodBehaivor : false ,
59+ get workspaces ( ) : WorkspacesHttp {
60+ if ( this . #legacy) return new LegacyWorkspacesHttp ( this . client )
61+ return new WorkspacesHttp ( this . client )
10162 }
10263}
0 commit comments