@@ -2,15 +2,30 @@ import { ConfigCatConsoleLogger } from "./ConfigCatLogger";
2
2
import { IConfigCatLogger , IAutoPollOptions , ILazyLoadingOptions , IManualPollOptions , LogLevel } from "./index" ;
3
3
import COMMON_VERSION from "./Version" ;
4
4
5
+
6
+ /** Control the location of the config.json files containing your feature flags and settings within the ConfigCat CDN. */
7
+ export enum DataGovernance {
8
+ /** Select this if your feature flags are published to all global CDN nodes. */
9
+ Global = 0 ,
10
+ /** Select this if your feature flags are published to CDN nodes only in the EU. */
11
+ EuOnly = 1
12
+ }
13
+
5
14
export interface IOptions {
6
15
logger ?: IConfigCatLogger ;
7
16
requestTimeoutMs ?: number ;
8
17
baseUrl ?: string ;
18
+ /** You can set a base_url if you want to use a proxy server between your application and ConfigCat */
9
19
proxy ?: string ;
20
+ /** Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
21
+ * https://app.configcat.com/organization/data-governance (Only Organization Admins have access) */
22
+ dataGovernance ?: DataGovernance ;
10
23
}
11
24
12
25
export abstract class OptionsBase implements IOptions {
13
26
27
+ private configFileName = "config_v5" ;
28
+
14
29
public logger : IConfigCatLogger = new ConfigCatConsoleLogger ( LogLevel . Warn ) ;
15
30
16
31
public apiKey : string ;
@@ -19,25 +34,38 @@ export abstract class OptionsBase implements IOptions {
19
34
20
35
public requestTimeoutMs : number = 30000 ;
21
36
22
- public baseUrl : string = "https://cdn.configcat.com" ;
37
+ public baseUrl : string ;
38
+
39
+ public baseUrlOverriden : boolean = false ;
23
40
24
41
public proxy : string = "" ;
25
42
43
+ public dataGovernance : DataGovernance ;
44
+
26
45
constructor ( apiKey : string , clientVersion : string , options : IOptions ) {
27
46
if ( ! apiKey ) {
28
47
throw new Error ( "Invalid 'apiKey' value" ) ;
29
48
}
30
49
31
50
this . apiKey = apiKey ;
32
51
this . clientVersion = clientVersion ;
52
+ this . dataGovernance = options ?. dataGovernance ?? DataGovernance . Global ;
53
+
54
+ switch ( this . dataGovernance ) {
55
+ case DataGovernance . EuOnly :
56
+ this . baseUrl = "https://cdn-eu.configcat.com" ;
57
+ break ;
58
+ default :
59
+ this . baseUrl = "https://cdn-global.configcat.com" ;
60
+ break ;
61
+ }
33
62
34
- if ( options )
35
- {
63
+ if ( options ) {
36
64
if ( options . logger ) {
37
65
this . logger = options . logger ;
38
66
}
39
67
40
- if ( options . requestTimeoutMs ) {
68
+ if ( options . requestTimeoutMs ) {
41
69
if ( options . requestTimeoutMs < 0 ) {
42
70
throw new Error ( "Invalid 'requestTimeoutMs' value" ) ;
43
71
}
@@ -47,6 +75,7 @@ export abstract class OptionsBase implements IOptions {
47
75
48
76
if ( options . baseUrl ) {
49
77
this . baseUrl = options . baseUrl ;
78
+ this . baseUrlOverriden = true ;
50
79
}
51
80
52
81
if ( options . proxy ) {
@@ -56,14 +85,20 @@ export abstract class OptionsBase implements IOptions {
56
85
}
57
86
58
87
getUrl ( ) : string {
59
- return this . baseUrl + "/configuration-files/" + this . apiKey + "/config_v4.json" ;
88
+ return this . baseUrl + "/configuration-files/" + this . apiKey + "/" + this . configFileName + ".json" ;
89
+ }
90
+
91
+ getCacheKey ( ) : string {
92
+ return "js_" + this . configFileName + "_" + this . apiKey ;
60
93
}
61
94
}
62
95
63
96
export class AutoPollOptions extends OptionsBase implements IAutoPollOptions {
64
97
98
+ /** The client's poll interval in seconds. Default: 60 seconds. */
65
99
public pollIntervalSeconds : number = 60 ;
66
100
101
+ /** You can subscribe to configuration changes with this callback */
67
102
public configChanged : ( ) => void = ( ) => { } ;
68
103
69
104
constructor ( apiKey : string , options : IAutoPollOptions ) {
@@ -95,6 +130,7 @@ export class ManualPollOptions extends OptionsBase implements IManualPollOptions
95
130
96
131
export class LazyLoadOptions extends OptionsBase implements ILazyLoadingOptions {
97
132
133
+ /** The cache TTL. */
98
134
public cacheTimeToLiveSeconds : number = 60 ;
99
135
100
136
constructor ( apiKey : string , options : ILazyLoadingOptions ) {
0 commit comments