@@ -4,6 +4,7 @@ import type { HttpClient } from '../http_client';
4
4
/** @private */
5
5
export interface ApiClientOptions {
6
6
baseUrl : string ;
7
+ publicBaseUrl : string ;
7
8
resourcePath : string ;
8
9
apifyClient : ApifyClient ;
9
10
httpClient : HttpClient ;
@@ -25,6 +26,8 @@ export abstract class ApiClient {
25
26
26
27
baseUrl : string ;
27
28
29
+ publicBaseUrl : string ;
30
+
28
31
resourcePath : string ;
29
32
30
33
url : string ;
@@ -36,11 +39,12 @@ export abstract class ApiClient {
36
39
params ?: Record < string , unknown > ;
37
40
38
41
constructor ( options : ApiClientOptions ) {
39
- const { baseUrl, apifyClient, httpClient, resourcePath, id, params = { } } = options ;
42
+ const { baseUrl, publicBaseUrl , apifyClient, httpClient, resourcePath, id, params = { } } = options ;
40
43
41
44
this . id = id ;
42
45
this . safeId = id && this . _toSafeId ( id ) ;
43
46
this . baseUrl = baseUrl ;
47
+ this . publicBaseUrl = publicBaseUrl ;
44
48
this . resourcePath = resourcePath ;
45
49
this . url = id ? `${ baseUrl } /${ resourcePath } /${ this . safeId } ` : `${ baseUrl } /${ resourcePath } ` ;
46
50
this . apifyClient = apifyClient ;
@@ -51,6 +55,7 @@ export abstract class ApiClient {
51
55
protected _subResourceOptions < T > ( moreOptions ?: T ) : BaseOptions & T {
52
56
const baseOptions : BaseOptions = {
53
57
baseUrl : this . _url ( ) ,
58
+ publicBaseUrl : this . publicBaseUrl ,
54
59
apifyClient : this . apifyClient ,
55
60
httpClient : this . httpClient ,
56
61
params : this . _params ( ) ,
@@ -62,6 +67,13 @@ export abstract class ApiClient {
62
67
return path ? `${ this . url } /${ path } ` : this . url ;
63
68
}
64
69
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
+
65
77
protected _params < T > ( endpointParams ?: T ) : Record < string , unknown > {
66
78
return { ...this . params , ...endpointParams } ;
67
79
}
@@ -74,6 +86,7 @@ export abstract class ApiClient {
74
86
75
87
export interface BaseOptions {
76
88
baseUrl : string ;
89
+ publicBaseUrl : string ;
77
90
apifyClient : ApifyClient ;
78
91
httpClient : HttpClient ;
79
92
params : Record < string , unknown > ;
0 commit comments