11import version from 'lib/version.js'
22
33import { getAuthHeaders } from './auth.js'
4- import type { ClientOptions } from './client.js'
4+ import type { Client , ClientOptions } from './client.js'
55import {
66 isSeamHttpMultiWorkspaceOptionsWithClient ,
77 isSeamHttpOptionsWithClient ,
88 isSeamHttpOptionsWithClientSessionToken ,
99 type SeamHttpMultiWorkspaceOptions ,
1010 type SeamHttpOptions ,
11+ type SeamHttpRequestOptions ,
1112} from './options.js'
1213
1314const defaultEndpoint = 'https://connect.getseam.com'
@@ -21,15 +22,20 @@ export type Options =
2122 | SeamHttpMultiWorkspaceOptions
2223 | ( SeamHttpOptions & { publishableKey ?: string } )
2324
25+ type ParsedOptions = Required <
26+ ( ClientOptions | { client : Client } ) & SeamHttpRequestOptions
27+ >
28+
2429export const parseOptions = (
2530 apiKeyOrOptions : string | Options ,
26- ) : ClientOptions => {
31+ ) : ParsedOptions => {
2732 const options = getNormalizedOptions ( apiKeyOrOptions )
2833
2934 if ( isSeamHttpOptionsWithClient ( options ) ) return options
3035 if ( isSeamHttpMultiWorkspaceOptionsWithClient ( options ) ) return options
3136
3237 return {
38+ ...options ,
3339 axiosOptions : {
3440 baseURL : options . endpoint ?? getEndpointFromEnv ( ) ?? defaultEndpoint ,
3541 withCredentials : isSeamHttpOptionsWithClientSessionToken ( options ) ,
@@ -48,20 +54,30 @@ export const parseOptions = (
4854
4955const getNormalizedOptions = (
5056 apiKeyOrOptions : string | Options ,
51- ) : SeamHttpOptions => {
57+ ) : SeamHttpOptions & Required < SeamHttpRequestOptions > => {
5258 const options =
5359 typeof apiKeyOrOptions === 'string'
5460 ? { apiKey : apiKeyOrOptions }
5561 : apiKeyOrOptions
5662
57- if ( isSeamHttpOptionsWithClient ( options ) ) return options
63+ const requestOptions = {
64+ waitForActionAttempt : options . waitForActionAttempt ?? false ,
65+ }
66+
67+ if ( isSeamHttpOptionsWithClient ( options ) ) {
68+ return {
69+ ...options ,
70+ ...requestOptions ,
71+ }
72+ }
5873
5974 const apiKey =
6075 'apiKey' in options ? options . apiKey : getApiKeyFromEnv ( options )
6176
6277 return {
6378 ...options ,
6479 ...( apiKey != null ? { apiKey } : { } ) ,
80+ ...requestOptions ,
6581 }
6682}
6783
@@ -80,3 +96,26 @@ const getEndpointFromEnv = (): string | null | undefined => {
8096 globalThis . process ?. env ?. SEAM_API_URL
8197 )
8298}
99+
100+ export const limitToSeamHttpRequestOptions = (
101+ options : Required < SeamHttpRequestOptions > ,
102+ ) : Required < SeamHttpRequestOptions > => {
103+ return Object . keys ( options )
104+ . filter ( isSeamHttpRequestOption )
105+ . reduce (
106+ ( obj , key ) => ( {
107+ ...obj ,
108+ [ key ] : options [ key ] ,
109+ } ) ,
110+ { } ,
111+ ) as Required < SeamHttpRequestOptions >
112+ }
113+
114+ export const isSeamHttpRequestOption = (
115+ key : string ,
116+ ) : key is keyof SeamHttpRequestOptions => {
117+ const keys : Record < keyof SeamHttpRequestOptions , true > = {
118+ waitForActionAttempt : true ,
119+ }
120+ return Object . keys ( keys ) . includes ( key )
121+ }
0 commit comments