@@ -4,6 +4,7 @@ import type Y from "yargs"
44import { Yargs } from "https://unpkg.com/[email protected] /browser.mjs" 55import EventEmitter from "eventemitter3"
66import TypedEmitter from "typed-emitter"
7+ import { getSeamClientOptionsWithDefaults , SeamClientOptions } from "../"
78
89const yargsInstance = Yargs ( ) as ReturnType < typeof Y >
910
@@ -13,12 +14,14 @@ type CLIEvents = {
1314
1415class BrowserCLI extends ( EventEmitter as unknown as new ( ) => TypedEmitter < CLIEvents > ) {
1516 private instance = getCLI ( yargsInstance ) . scriptName ( "seam" )
17+ private seamClientOptions : SeamClientOptions
1618
1719 /**
1820 * Use the Seam CLI in the browser!
1921 */
20- constructor ( private apiKey ?: string ) {
22+ constructor ( apiKeyOrOptions ?: string | SeamClientOptions ) {
2123 super ( )
24+ this . seamClientOptions = getSeamClientOptionsWithDefaults ( apiKeyOrOptions )
2225 this . setUpShims ( )
2326 }
2427
@@ -34,15 +37,21 @@ class BrowserCLI extends (EventEmitter as unknown as new () => TypedEmitter<CLIE
3437 async parse ( input : string ) {
3538 this . setUpShims ( )
3639
37- const inputWithKey = input . includes ( "--api-key" )
40+ const { apiKey, endpoint, workspaceId } = this . seamClientOptions
41+
42+ input = input . includes ( "--api-key" ) ? input : `${ input } --api-key ${ apiKey } `
43+ input = input . includes ( "--endpoint" )
44+ ? input
45+ : `${ input } --endpoint ${ endpoint } `
46+ input = input . includes ( "--workspace-id" )
3847 ? input
39- : `${ input } --api-key ${ this . apiKey } `
48+ : `${ input } --workspace-id ${ workspaceId } `
4049
41- const inputWithKeyAndWithoutPrefix = inputWithKey . startsWith ( "seam " )
42- ? inputWithKey . replace ( "seam " , "" )
43- : inputWithKey . startsWith ( "seamapi " )
44- ? inputWithKey . replace ( "seamapi " , "" )
45- : inputWithKey
50+ input = input . startsWith ( "seam " )
51+ ? input . replace ( "seam " , "" )
52+ : input . startsWith ( "seamapi " )
53+ ? input . replace ( "seamapi " , "" )
54+ : input
4655
4756 await new Promise < void > ( ( resolve , reject ) => {
4857 // .parseAsync isn't available in v16, so we listen for the ending newline instead
@@ -55,7 +64,7 @@ class BrowserCLI extends (EventEmitter as unknown as new () => TypedEmitter<CLIE
5564 this . on ( "data" , onData )
5665
5766 this . instance . parse (
58- inputWithKeyAndWithoutPrefix ,
67+ input ,
5968 ( error : Error , _argv : any , output ?: string ) => {
6069 if ( error ) {
6170 this . removeListener ( "data" , onData )
0 commit comments