@@ -168,22 +168,36 @@ export class Seam extends Routes {
168168 } ) : Promise < APIResponse < ClientSessionResponse > > {
169169 const { apiKey, endpoint, axiosOptions } =
170170 getSeamClientOptionsWithDefaults ( options )
171- let headers : AxiosRequestHeaders = {
172- ...axiosOptions ?. headers ,
171+
172+ if ( ! options . userIdentifierKey ) {
173+ throw new Error ( "userIdentifierKey is required" )
173174 }
174175
175- if ( options . publishableKey ?. startsWith ( "seam_pk" ) ) {
176- // frontend mode
177- headers [ "seam-publishable-key" ] = options . publishableKey
178- } else if ( apiKey ?. startsWith ( "seam_" ) ) {
179- // backend mode
180- headers [ "seam-api-key" ] = apiKey
176+ const getKeyHeaders = ( ) : AxiosRequestHeaders => {
177+ const { publishableKey } = options
178+ if ( publishableKey ) {
179+ if ( ! publishableKey . startsWith ( "seam_pk" ) ) {
180+ throw new Error ( "Invalid publishableKey" )
181+ }
182+ return { "seam-publishable-key" : publishableKey }
183+ }
184+
185+ if ( apiKey ) {
186+ if ( ! apiKey ?. startsWith ( "seam_" ) ) {
187+ throw new Error ( "Invalid apiKey" )
188+ }
189+ return { "seam-api-key" : apiKey }
190+ }
191+
192+ throw new Error ( "Must provide a publishableKey or apiKey" )
181193 }
182- if ( options . userIdentifierKey ) {
183- headers [ "seam-user-identifier-key" ] = options . userIdentifierKey
184- } else {
185- throw new Error ( "userIdentifierKey is required" )
194+
195+ const headers = {
196+ "seam-user-identifier-key" : options . userIdentifierKey ,
197+ ...getKeyHeaders ( ) ,
198+ ...axiosOptions ?. headers ,
186199 }
200+
187201 const client = axios . create ( {
188202 ...axiosOptions ,
189203 baseURL : endpoint ,
0 commit comments