@@ -108,17 +108,47 @@ export type GetAccountByIdOpts = {
108108} ;
109109
110110/**
111- * Parameters for the retrieval of an account from the Connect API
111+ * Options used to determine the external user and account to be used in Connect Proxy API
112112 */
113- export type MakeProxyRequestOpts = {
113+ export type ProxyApiOpts = {
114114 /**
115- * Whether to retrieve the account's credentials or not.
115+ * Search parameters to be added to the proxy request. external_user_id and account_id are required.
116+ */
117+ searchParams : Record < string , string > ;
118+ } ;
119+
120+ /**
121+ * fetch-like options for the Target of the Connect Proxy Api Request
122+ */
123+ export type ProxyTargetApiOpts = {
124+ /**
125+ * http method for the request
116126 */
117127 method : string ;
128+ /**
129+ * http headers for the request
130+ */
118131 headers ?: Record < string , string > ;
132+ /**
133+ * http body for the request
134+ */
119135 body ?: string ;
120136} ;
121137
138+ /**
139+ * object that contains the url and options for the target of the Connect Proxy Api Request
140+ */
141+ export type ProxyTargetApiRequest = {
142+ /**
143+ * URL for the target of the request. Search parameters must be included here.
144+ */
145+ url : string ;
146+ /**
147+ * fetch-like options for the target of the Connect Proxy Request
148+ */
149+ options : ProxyTargetApiOpts ;
150+ } ;
151+
122152/**
123153 * Creates a new instance of BackendClient with the provided options.
124154 *
@@ -388,30 +418,30 @@ export class BackendClient extends BaseClient {
388418 }
389419
390420 /**
391- * Makes a proxy request to a URL with the specified query parameters and options.
421+ * Makes a proxy request to the target app API with the specified query parameters and options.
392422 *
393423 * @returns A promise resolving to the response from the downstream service
394424 */
395- public makeProxyRequest ( url : string , query : Record < string , string | boolean | number | null > , opts : MakeProxyRequestOpts ) : Promise < string > {
396- const url64 = btoa ( url ) . replace ( / \+ / g, "-" )
425+ public makeProxyRequest ( proxyOptions : ProxyApiOpts , targetRequest : ProxyTargetApiRequest ) : Promise < string > {
426+ const url64 = btoa ( targetRequest . url ) . replace ( / \+ / g, "-" )
397427 . replace ( / \/ / g, "_" )
398428 . replace ( / = + $ / , "" ) ;
399429
400- const headers = opts . headers || { } ;
430+ const headers = targetRequest . options . headers || { } ;
401431
402432 const newHeaders = Object . keys ( headers ) . reduce < { [ key : string ] : string } > ( ( acc , key ) => {
403433 acc [ `x-pd-proxy-${ key } ` ] = headers [ key ] ;
404434 return acc ;
405435 } , { } ) ;
406436
407437 const newOpts : RequestOptions = {
408- method : opts . method ,
438+ method : targetRequest . options . method ,
409439 headers : newHeaders ,
410- params : query ,
440+ params : proxyOptions . searchParams ,
411441 }
412442
413- if ( opts . body ) {
414- newOpts . body = opts . body
443+ if ( targetRequest . options . body ) {
444+ newOpts . body = targetRequest . options . body
415445 }
416446
417447 return this . makeConnectRequest ( `/proxy/${ url64 } ` , newOpts ) ;
0 commit comments