@@ -3,28 +3,42 @@ import { ContribPoint, Contributions } from "./model/extension";
33import { CallbackRequest , StateChangeRequest } from "./model/callback" ;
44import { callApi } from "./utils/fetchApiResult" ;
55
6- const serverUrl = "http://localhost:8888" ;
6+ const defaultServerUrl = "http://localhost:8888" ;
7+ const defaultEndpointName = "dashi" ;
78
8- export async function fetchContributions ( ) : Promise < Contributions > {
9- return callApi ( `${ serverUrl } /dashi/contributions` ) ;
9+ export interface ApiOptions {
10+ serverUrl ?: string ;
11+ endpointName ?: string ;
12+ }
13+
14+ export async function fetchContributions ( options ?: ApiOptions ) : Promise < Contributions > {
15+ return callApi ( makeUrl ( "contributions" , options ) ) ;
1016}
1117
1218export async function fetchInitialComponentState (
1319 contribPoint : ContribPoint ,
1420 contribIndex : number ,
1521 inputValues : unknown [ ] ,
22+ options ?: ApiOptions
1623) : Promise < ComponentState > {
17- return callApi ( ` ${ serverUrl } /dashi/ layout/${ contribPoint } /${ contribIndex } `, {
24+ return callApi ( makeUrl ( ` layout/${ contribPoint } /${ contribIndex } `, options ) , {
1825 body : JSON . stringify ( { inputValues } ) ,
1926 method : "post" ,
2027 } ) ;
2128}
2229
2330export async function fetchStateChangeRequests (
2431 callbackRequests : CallbackRequest [ ] ,
32+ options ?: ApiOptions
2533) : Promise < StateChangeRequest [ ] > {
26- return callApi ( ` ${ serverUrl } /dashi/ callback` , {
34+ return callApi ( makeUrl ( " callback" , options ) , {
2735 body : JSON . stringify ( { callbackRequests : callbackRequests } ) ,
2836 method : "post" ,
2937 } ) ;
3038}
39+
40+ function makeUrl ( path : string , options ?: ApiOptions ) : string {
41+ const serverUrl = options ?. serverUrl || defaultServerUrl ;
42+ const endpointName = options ?. endpointName || defaultEndpointName ;
43+ return `${ serverUrl } /${ endpointName } /${ path } `
44+ }
0 commit comments