@@ -4,6 +4,7 @@ import type { HttpClient } from '../http_client';
44/** @private */
55export interface ApiClientOptions {
66 baseUrl : string ;
7+ publicBaseUrl : string ;
78 resourcePath : string ;
89 apifyClient : ApifyClient ;
910 httpClient : HttpClient ;
@@ -25,6 +26,8 @@ export abstract class ApiClient {
2526
2627 baseUrl : string ;
2728
29+ publicBaseUrl : string ;
30+
2831 resourcePath : string ;
2932
3033 url : string ;
@@ -36,11 +39,12 @@ export abstract class ApiClient {
3639 params ?: Record < string , unknown > ;
3740
3841 constructor ( options : ApiClientOptions ) {
39- const { baseUrl, apifyClient, httpClient, resourcePath, id, params = { } } = options ;
42+ const { baseUrl, publicBaseUrl , apifyClient, httpClient, resourcePath, id, params = { } } = options ;
4043
4144 this . id = id ;
4245 this . safeId = id && this . _toSafeId ( id ) ;
4346 this . baseUrl = baseUrl ;
47+ this . publicBaseUrl = publicBaseUrl ;
4448 this . resourcePath = resourcePath ;
4549 this . url = id ? `${ baseUrl } /${ resourcePath } /${ this . safeId } ` : `${ baseUrl } /${ resourcePath } ` ;
4650 this . apifyClient = apifyClient ;
@@ -51,6 +55,7 @@ export abstract class ApiClient {
5155 protected _subResourceOptions < T > ( moreOptions ?: T ) : BaseOptions & T {
5256 const baseOptions : BaseOptions = {
5357 baseUrl : this . _url ( ) ,
58+ publicBaseUrl : this . publicBaseUrl ,
5459 apifyClient : this . apifyClient ,
5560 httpClient : this . httpClient ,
5661 params : this . _params ( ) ,
@@ -62,6 +67,13 @@ export abstract class ApiClient {
6267 return path ? `${ this . url } /${ path } ` : this . url ;
6368 }
6469
70+ protected _publicUrl ( path ?: string ) : string {
71+ const url = this . id
72+ ? `${ this . publicBaseUrl } /${ this . resourcePath } /${ this . safeId } `
73+ : `${ this . publicBaseUrl } /${ this . resourcePath } ` ;
74+ return path ? `${ url } /${ path } ` : url ;
75+ }
76+
6577 protected _params < T > ( endpointParams ?: T ) : Record < string , unknown > {
6678 return { ...this . params , ...endpointParams } ;
6779 }
@@ -74,6 +86,7 @@ export abstract class ApiClient {
7486
7587export interface BaseOptions {
7688 baseUrl : string ;
89+ publicBaseUrl : string ;
7790 apifyClient : ApifyClient ;
7891 httpClient : HttpClient ;
7992 params : Record < string , unknown > ;
0 commit comments