@firebase/remote-config 0.4.10 → 0.4.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.esm2017.js +1193 -1193
- package/dist/esm/index.esm2017.js.map +1 -1
- package/dist/esm/src/api.d.ts +115 -115
- package/dist/esm/src/api2.d.ts +40 -40
- package/dist/esm/src/client/caching_client.d.ts +45 -45
- package/dist/esm/src/client/remote_config_fetch_client.d.ts +123 -123
- package/dist/esm/src/client/rest_client.d.ts +40 -40
- package/dist/esm/src/client/retrying_client.d.ts +49 -49
- package/dist/esm/src/constants.d.ts +17 -17
- package/dist/esm/src/errors.d.ts +62 -62
- package/dist/esm/src/index.d.ts +14 -14
- package/dist/esm/src/language.d.ts +26 -26
- package/dist/esm/src/public_types.d.ts +128 -128
- package/dist/esm/src/register.d.ts +2 -2
- package/dist/esm/src/remote_config.d.ts +79 -79
- package/dist/esm/src/storage/storage.d.ts +76 -76
- package/dist/esm/src/storage/storage_cache.d.ts +48 -48
- package/dist/esm/src/value.d.ts +26 -26
- package/dist/esm/test/client/caching_client.test.d.ts +17 -17
- package/dist/esm/test/client/rest_client.test.d.ts +17 -17
- package/dist/esm/test/client/retrying_client.test.d.ts +17 -17
- package/dist/esm/test/errors.test.d.ts +17 -17
- package/dist/esm/test/language.test.d.ts +17 -17
- package/dist/esm/test/remote_config.test.d.ts +17 -17
- package/dist/esm/test/setup.d.ts +17 -17
- package/dist/esm/test/storage/storage.test.d.ts +17 -17
- package/dist/esm/test/storage/storage_cache.test.d.ts +17 -17
- package/dist/esm/test/value.test.d.ts +17 -17
- package/dist/index.cjs.js +1193 -1193
- package/dist/index.cjs.js.map +1 -1
- package/dist/src/api.d.ts +115 -115
- package/dist/src/api2.d.ts +40 -40
- package/dist/src/client/caching_client.d.ts +45 -45
- package/dist/src/client/remote_config_fetch_client.d.ts +123 -123
- package/dist/src/client/rest_client.d.ts +40 -40
- package/dist/src/client/retrying_client.d.ts +49 -49
- package/dist/src/constants.d.ts +17 -17
- package/dist/src/errors.d.ts +62 -62
- package/dist/src/index.d.ts +14 -14
- package/dist/src/language.d.ts +26 -26
- package/dist/src/public_types.d.ts +128 -128
- package/dist/src/register.d.ts +2 -2
- package/dist/src/remote_config.d.ts +79 -79
- package/dist/src/storage/storage.d.ts +76 -76
- package/dist/src/storage/storage_cache.d.ts +48 -48
- package/dist/src/value.d.ts +26 -26
- package/dist/test/client/caching_client.test.d.ts +17 -17
- package/dist/test/client/rest_client.test.d.ts +17 -17
- package/dist/test/client/retrying_client.test.d.ts +17 -17
- package/dist/test/errors.test.d.ts +17 -17
- package/dist/test/language.test.d.ts +17 -17
- package/dist/test/remote_config.test.d.ts +17 -17
- package/dist/test/setup.d.ts +17 -17
- package/dist/test/storage/storage.test.d.ts +17 -17
- package/dist/test/storage/storage_cache.test.d.ts +17 -17
- package/dist/test/value.test.d.ts +17 -17
- package/package.json +7 -7
package/dist/esm/src/api.d.ts
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2020 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
import { FirebaseApp } from '@firebase/app';
|
|
18
|
-
import { LogLevel as RemoteConfigLogLevel, RemoteConfig, Value } from './public_types';
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
* @param app - The {@link @firebase/app#FirebaseApp} instance.
|
|
22
|
-
* @returns A {@link RemoteConfig} instance.
|
|
23
|
-
*
|
|
24
|
-
* @public
|
|
25
|
-
*/
|
|
26
|
-
export declare function getRemoteConfig(app?: FirebaseApp): RemoteConfig;
|
|
27
|
-
/**
|
|
28
|
-
* Makes the last fetched config available to the getters.
|
|
29
|
-
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
30
|
-
* @returns A `Promise` which resolves to true if the current call activated the fetched configs.
|
|
31
|
-
* If the fetched configs were already activated, the `Promise` will resolve to false.
|
|
32
|
-
*
|
|
33
|
-
* @public
|
|
34
|
-
*/
|
|
35
|
-
export declare function activate(remoteConfig: RemoteConfig): Promise<boolean>;
|
|
36
|
-
/**
|
|
37
|
-
* Ensures the last activated config are available to the getters.
|
|
38
|
-
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
39
|
-
*
|
|
40
|
-
* @returns A `Promise` that resolves when the last activated config is available to the getters.
|
|
41
|
-
* @public
|
|
42
|
-
*/
|
|
43
|
-
export declare function ensureInitialized(remoteConfig: RemoteConfig): Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* Fetches and caches configuration from the Remote Config service.
|
|
46
|
-
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
47
|
-
* @public
|
|
48
|
-
*/
|
|
49
|
-
export declare function fetchConfig(remoteConfig: RemoteConfig): Promise<void>;
|
|
50
|
-
/**
|
|
51
|
-
* Gets all config.
|
|
52
|
-
*
|
|
53
|
-
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
54
|
-
* @returns All config.
|
|
55
|
-
*
|
|
56
|
-
* @public
|
|
57
|
-
*/
|
|
58
|
-
export declare function getAll(remoteConfig: RemoteConfig): Record<string, Value>;
|
|
59
|
-
/**
|
|
60
|
-
* Gets the value for the given key as a boolean.
|
|
61
|
-
*
|
|
62
|
-
* Convenience method for calling <code>remoteConfig.getValue(key).asBoolean()</code>.
|
|
63
|
-
*
|
|
64
|
-
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
65
|
-
* @param key - The name of the parameter.
|
|
66
|
-
*
|
|
67
|
-
* @returns The value for the given key as a boolean.
|
|
68
|
-
* @public
|
|
69
|
-
*/
|
|
70
|
-
export declare function getBoolean(remoteConfig: RemoteConfig, key: string): boolean;
|
|
71
|
-
/**
|
|
72
|
-
* Gets the value for the given key as a number.
|
|
73
|
-
*
|
|
74
|
-
* Convenience method for calling <code>remoteConfig.getValue(key).asNumber()</code>.
|
|
75
|
-
*
|
|
76
|
-
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
77
|
-
* @param key - The name of the parameter.
|
|
78
|
-
*
|
|
79
|
-
* @returns The value for the given key as a number.
|
|
80
|
-
*
|
|
81
|
-
* @public
|
|
82
|
-
*/
|
|
83
|
-
export declare function getNumber(remoteConfig: RemoteConfig, key: string): number;
|
|
84
|
-
/**
|
|
85
|
-
* Gets the value for the given key as a string.
|
|
86
|
-
* Convenience method for calling <code>remoteConfig.getValue(key).asString()</code>.
|
|
87
|
-
*
|
|
88
|
-
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
89
|
-
* @param key - The name of the parameter.
|
|
90
|
-
*
|
|
91
|
-
* @returns The value for the given key as a string.
|
|
92
|
-
*
|
|
93
|
-
* @public
|
|
94
|
-
*/
|
|
95
|
-
export declare function getString(remoteConfig: RemoteConfig, key: string): string;
|
|
96
|
-
/**
|
|
97
|
-
* Gets the {@link Value} for the given key.
|
|
98
|
-
*
|
|
99
|
-
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
100
|
-
* @param key - The name of the parameter.
|
|
101
|
-
*
|
|
102
|
-
* @returns The value for the given key.
|
|
103
|
-
*
|
|
104
|
-
* @public
|
|
105
|
-
*/
|
|
106
|
-
export declare function getValue(remoteConfig: RemoteConfig, key: string): Value;
|
|
107
|
-
/**
|
|
108
|
-
* Defines the log level to use.
|
|
109
|
-
*
|
|
110
|
-
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
111
|
-
* @param logLevel - The log level to set.
|
|
112
|
-
*
|
|
113
|
-
* @public
|
|
114
|
-
*/
|
|
115
|
-
export declare function setLogLevel(remoteConfig: RemoteConfig, logLevel: RemoteConfigLogLevel): void;
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2020 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { FirebaseApp } from '@firebase/app';
|
|
18
|
+
import { LogLevel as RemoteConfigLogLevel, RemoteConfig, Value } from './public_types';
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param app - The {@link @firebase/app#FirebaseApp} instance.
|
|
22
|
+
* @returns A {@link RemoteConfig} instance.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare function getRemoteConfig(app?: FirebaseApp): RemoteConfig;
|
|
27
|
+
/**
|
|
28
|
+
* Makes the last fetched config available to the getters.
|
|
29
|
+
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
30
|
+
* @returns A `Promise` which resolves to true if the current call activated the fetched configs.
|
|
31
|
+
* If the fetched configs were already activated, the `Promise` will resolve to false.
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export declare function activate(remoteConfig: RemoteConfig): Promise<boolean>;
|
|
36
|
+
/**
|
|
37
|
+
* Ensures the last activated config are available to the getters.
|
|
38
|
+
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
39
|
+
*
|
|
40
|
+
* @returns A `Promise` that resolves when the last activated config is available to the getters.
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
export declare function ensureInitialized(remoteConfig: RemoteConfig): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Fetches and caches configuration from the Remote Config service.
|
|
46
|
+
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export declare function fetchConfig(remoteConfig: RemoteConfig): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Gets all config.
|
|
52
|
+
*
|
|
53
|
+
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
54
|
+
* @returns All config.
|
|
55
|
+
*
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
export declare function getAll(remoteConfig: RemoteConfig): Record<string, Value>;
|
|
59
|
+
/**
|
|
60
|
+
* Gets the value for the given key as a boolean.
|
|
61
|
+
*
|
|
62
|
+
* Convenience method for calling <code>remoteConfig.getValue(key).asBoolean()</code>.
|
|
63
|
+
*
|
|
64
|
+
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
65
|
+
* @param key - The name of the parameter.
|
|
66
|
+
*
|
|
67
|
+
* @returns The value for the given key as a boolean.
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
export declare function getBoolean(remoteConfig: RemoteConfig, key: string): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Gets the value for the given key as a number.
|
|
73
|
+
*
|
|
74
|
+
* Convenience method for calling <code>remoteConfig.getValue(key).asNumber()</code>.
|
|
75
|
+
*
|
|
76
|
+
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
77
|
+
* @param key - The name of the parameter.
|
|
78
|
+
*
|
|
79
|
+
* @returns The value for the given key as a number.
|
|
80
|
+
*
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
export declare function getNumber(remoteConfig: RemoteConfig, key: string): number;
|
|
84
|
+
/**
|
|
85
|
+
* Gets the value for the given key as a string.
|
|
86
|
+
* Convenience method for calling <code>remoteConfig.getValue(key).asString()</code>.
|
|
87
|
+
*
|
|
88
|
+
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
89
|
+
* @param key - The name of the parameter.
|
|
90
|
+
*
|
|
91
|
+
* @returns The value for the given key as a string.
|
|
92
|
+
*
|
|
93
|
+
* @public
|
|
94
|
+
*/
|
|
95
|
+
export declare function getString(remoteConfig: RemoteConfig, key: string): string;
|
|
96
|
+
/**
|
|
97
|
+
* Gets the {@link Value} for the given key.
|
|
98
|
+
*
|
|
99
|
+
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
100
|
+
* @param key - The name of the parameter.
|
|
101
|
+
*
|
|
102
|
+
* @returns The value for the given key.
|
|
103
|
+
*
|
|
104
|
+
* @public
|
|
105
|
+
*/
|
|
106
|
+
export declare function getValue(remoteConfig: RemoteConfig, key: string): Value;
|
|
107
|
+
/**
|
|
108
|
+
* Defines the log level to use.
|
|
109
|
+
*
|
|
110
|
+
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
111
|
+
* @param logLevel - The log level to set.
|
|
112
|
+
*
|
|
113
|
+
* @public
|
|
114
|
+
*/
|
|
115
|
+
export declare function setLogLevel(remoteConfig: RemoteConfig, logLevel: RemoteConfigLogLevel): void;
|
package/dist/esm/src/api2.d.ts
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2020 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
import { RemoteConfig } from './public_types';
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* Performs fetch and activate operations, as a convenience.
|
|
21
|
-
*
|
|
22
|
-
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
23
|
-
*
|
|
24
|
-
* @returns A `Promise` which resolves to true if the current call activated the fetched configs.
|
|
25
|
-
* If the fetched configs were already activated, the `Promise` will resolve to false.
|
|
26
|
-
*
|
|
27
|
-
* @public
|
|
28
|
-
*/
|
|
29
|
-
export declare function fetchAndActivate(remoteConfig: RemoteConfig): Promise<boolean>;
|
|
30
|
-
/**
|
|
31
|
-
* This method provides two different checks:
|
|
32
|
-
*
|
|
33
|
-
* 1. Check if IndexedDB exists in the browser environment.
|
|
34
|
-
* 2. Check if the current browser context allows IndexedDB `open()` calls.
|
|
35
|
-
*
|
|
36
|
-
* @returns A `Promise` which resolves to true if a {@link RemoteConfig} instance
|
|
37
|
-
* can be initialized in this environment, or false if it cannot.
|
|
38
|
-
* @public
|
|
39
|
-
*/
|
|
40
|
-
export declare function isSupported(): Promise<boolean>;
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2020 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { RemoteConfig } from './public_types';
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* Performs fetch and activate operations, as a convenience.
|
|
21
|
+
*
|
|
22
|
+
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
23
|
+
*
|
|
24
|
+
* @returns A `Promise` which resolves to true if the current call activated the fetched configs.
|
|
25
|
+
* If the fetched configs were already activated, the `Promise` will resolve to false.
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export declare function fetchAndActivate(remoteConfig: RemoteConfig): Promise<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* This method provides two different checks:
|
|
32
|
+
*
|
|
33
|
+
* 1. Check if IndexedDB exists in the browser environment.
|
|
34
|
+
* 2. Check if the current browser context allows IndexedDB `open()` calls.
|
|
35
|
+
*
|
|
36
|
+
* @returns A `Promise` which resolves to true if a {@link RemoteConfig} instance
|
|
37
|
+
* can be initialized in this environment, or false if it cannot.
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
export declare function isSupported(): Promise<boolean>;
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2019 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
import { StorageCache } from '../storage/storage_cache';
|
|
18
|
-
import { FetchResponse, RemoteConfigFetchClient, FetchRequest } from './remote_config_fetch_client';
|
|
19
|
-
import { Storage } from '../storage/storage';
|
|
20
|
-
import { Logger } from '@firebase/logger';
|
|
21
|
-
/**
|
|
22
|
-
* Implements the {@link RemoteConfigClient} abstraction with success response caching.
|
|
23
|
-
*
|
|
24
|
-
* <p>Comparable to the browser's Cache API for responses, but the Cache API requires a Service
|
|
25
|
-
* Worker, which requires HTTPS, which would significantly complicate SDK installation. Also, the
|
|
26
|
-
* Cache API doesn't support matching entries by time.
|
|
27
|
-
*/
|
|
28
|
-
export declare class CachingClient implements RemoteConfigFetchClient {
|
|
29
|
-
private readonly client;
|
|
30
|
-
private readonly storage;
|
|
31
|
-
private readonly storageCache;
|
|
32
|
-
private readonly logger;
|
|
33
|
-
constructor(client: RemoteConfigFetchClient, storage: Storage, storageCache: StorageCache, logger: Logger);
|
|
34
|
-
/**
|
|
35
|
-
* Returns true if the age of the cached fetched configs is less than or equal to
|
|
36
|
-
* {@link Settings#minimumFetchIntervalInSeconds}.
|
|
37
|
-
*
|
|
38
|
-
* <p>This is comparable to passing `headers = { 'Cache-Control': max-age <maxAge> }` to the
|
|
39
|
-
* native Fetch API.
|
|
40
|
-
*
|
|
41
|
-
* <p>Visible for testing.
|
|
42
|
-
*/
|
|
43
|
-
isCachedDataFresh(cacheMaxAgeMillis: number, lastSuccessfulFetchTimestampMillis: number | undefined): boolean;
|
|
44
|
-
fetch(request: FetchRequest): Promise<FetchResponse>;
|
|
45
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2019 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { StorageCache } from '../storage/storage_cache';
|
|
18
|
+
import { FetchResponse, RemoteConfigFetchClient, FetchRequest } from './remote_config_fetch_client';
|
|
19
|
+
import { Storage } from '../storage/storage';
|
|
20
|
+
import { Logger } from '@firebase/logger';
|
|
21
|
+
/**
|
|
22
|
+
* Implements the {@link RemoteConfigClient} abstraction with success response caching.
|
|
23
|
+
*
|
|
24
|
+
* <p>Comparable to the browser's Cache API for responses, but the Cache API requires a Service
|
|
25
|
+
* Worker, which requires HTTPS, which would significantly complicate SDK installation. Also, the
|
|
26
|
+
* Cache API doesn't support matching entries by time.
|
|
27
|
+
*/
|
|
28
|
+
export declare class CachingClient implements RemoteConfigFetchClient {
|
|
29
|
+
private readonly client;
|
|
30
|
+
private readonly storage;
|
|
31
|
+
private readonly storageCache;
|
|
32
|
+
private readonly logger;
|
|
33
|
+
constructor(client: RemoteConfigFetchClient, storage: Storage, storageCache: StorageCache, logger: Logger);
|
|
34
|
+
/**
|
|
35
|
+
* Returns true if the age of the cached fetched configs is less than or equal to
|
|
36
|
+
* {@link Settings#minimumFetchIntervalInSeconds}.
|
|
37
|
+
*
|
|
38
|
+
* <p>This is comparable to passing `headers = { 'Cache-Control': max-age <maxAge> }` to the
|
|
39
|
+
* native Fetch API.
|
|
40
|
+
*
|
|
41
|
+
* <p>Visible for testing.
|
|
42
|
+
*/
|
|
43
|
+
isCachedDataFresh(cacheMaxAgeMillis: number, lastSuccessfulFetchTimestampMillis: number | undefined): boolean;
|
|
44
|
+
fetch(request: FetchRequest): Promise<FetchResponse>;
|
|
45
|
+
}
|
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2019 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* Defines a client, as in https://en.wikipedia.org/wiki/Client%E2%80%93server_model, for the
|
|
19
|
-
* Remote Config server (https://firebase.google.com/docs/reference/remote-config/rest).
|
|
20
|
-
*
|
|
21
|
-
* <p>Abstracts throttle, response cache and network implementation details.
|
|
22
|
-
*
|
|
23
|
-
* <p>Modeled after the native {@link GlobalFetch} interface, which is relatively modern and
|
|
24
|
-
* convenient, but simplified for Remote Config's use case.
|
|
25
|
-
*
|
|
26
|
-
* Disambiguation: {@link GlobalFetch} interface and the Remote Config service define "fetch"
|
|
27
|
-
* methods. The RestClient uses the former to make HTTP calls. This interface abstracts the latter.
|
|
28
|
-
*/
|
|
29
|
-
export interface RemoteConfigFetchClient {
|
|
30
|
-
/**
|
|
31
|
-
* @throws if response status is not 200 or 304.
|
|
32
|
-
*/
|
|
33
|
-
fetch(request: FetchRequest): Promise<FetchResponse>;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Defines a self-descriptive reference for config key-value pairs.
|
|
37
|
-
*/
|
|
38
|
-
export interface FirebaseRemoteConfigObject {
|
|
39
|
-
[key: string]: string;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Shims a minimal AbortSignal.
|
|
43
|
-
*
|
|
44
|
-
* <p>AbortController's AbortSignal conveniently decouples fetch timeout logic from other aspects
|
|
45
|
-
* of networking, such as retries. Firebase doesn't use AbortController enough to justify a
|
|
46
|
-
* polyfill recommendation, like we do with the Fetch API, but this minimal shim can easily be
|
|
47
|
-
* swapped out if/when we do.
|
|
48
|
-
*/
|
|
49
|
-
export declare class RemoteConfigAbortSignal {
|
|
50
|
-
listeners: Array<() => void>;
|
|
51
|
-
addEventListener(listener: () => void): void;
|
|
52
|
-
abort(): void;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Defines per-request inputs for the Remote Config fetch request.
|
|
56
|
-
*
|
|
57
|
-
* <p>Modeled after the native {@link Request} interface, but simplified for Remote Config's
|
|
58
|
-
* use case.
|
|
59
|
-
*/
|
|
60
|
-
export interface FetchRequest {
|
|
61
|
-
/**
|
|
62
|
-
* Uses cached config if it is younger than this age.
|
|
63
|
-
*
|
|
64
|
-
* <p>Required because it's defined by settings, which always have a value.
|
|
65
|
-
*
|
|
66
|
-
* <p>Comparable to passing `headers = { 'Cache-Control': max-age <maxAge> }` to the native
|
|
67
|
-
* Fetch API.
|
|
68
|
-
*/
|
|
69
|
-
cacheMaxAgeMillis: number;
|
|
70
|
-
/**
|
|
71
|
-
* An event bus for the signal to abort a request.
|
|
72
|
-
*
|
|
73
|
-
* <p>Required because all requests should be abortable.
|
|
74
|
-
*
|
|
75
|
-
* <p>Comparable to the native
|
|
76
|
-
* Fetch API's "signal" field on its request configuration object
|
|
77
|
-
* https://fetch.spec.whatwg.org/#dom-requestinit-signal.
|
|
78
|
-
*
|
|
79
|
-
* <p>Disambiguation: Remote Config commonly refers to API inputs as
|
|
80
|
-
* "signals". See the private ConfigFetchRequestBody interface for those:
|
|
81
|
-
* http://google3/firebase/remote_config/web/src/core/rest_client.ts?l=14&rcl=255515243.
|
|
82
|
-
*/
|
|
83
|
-
signal: RemoteConfigAbortSignal;
|
|
84
|
-
/**
|
|
85
|
-
* The ETag header value from the last response.
|
|
86
|
-
*
|
|
87
|
-
* <p>Optional in case this is the first request.
|
|
88
|
-
*
|
|
89
|
-
* <p>Comparable to passing `headers = { 'If-None-Match': <eTag> }` to the native Fetch API.
|
|
90
|
-
*/
|
|
91
|
-
eTag?: string;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Defines a successful response (200 or 304).
|
|
95
|
-
*
|
|
96
|
-
* <p>Modeled after the native {@link Response} interface, but simplified for Remote Config's
|
|
97
|
-
* use case.
|
|
98
|
-
*/
|
|
99
|
-
export interface FetchResponse {
|
|
100
|
-
/**
|
|
101
|
-
* The HTTP status, which is useful for differentiating success responses with data from
|
|
102
|
-
* those without.
|
|
103
|
-
*
|
|
104
|
-
* <p>{@link RemoteConfigClient} is modeled after the native {@link GlobalFetch} interface, so
|
|
105
|
-
* HTTP status is first-class.
|
|
106
|
-
*
|
|
107
|
-
* <p>Disambiguation: the fetch response returns a legacy "state" value that is redundant with the
|
|
108
|
-
* HTTP status code. The former is normalized into the latter.
|
|
109
|
-
*/
|
|
110
|
-
status: number;
|
|
111
|
-
/**
|
|
112
|
-
* Defines the ETag response header value.
|
|
113
|
-
*
|
|
114
|
-
* <p>Only defined for 200 and 304 responses.
|
|
115
|
-
*/
|
|
116
|
-
eTag?: string;
|
|
117
|
-
/**
|
|
118
|
-
* Defines the map of parameters returned as "entries" in the fetch response body.
|
|
119
|
-
*
|
|
120
|
-
* <p>Only defined for 200 responses.
|
|
121
|
-
*/
|
|
122
|
-
config?: FirebaseRemoteConfigObject;
|
|
123
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2019 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Defines a client, as in https://en.wikipedia.org/wiki/Client%E2%80%93server_model, for the
|
|
19
|
+
* Remote Config server (https://firebase.google.com/docs/reference/remote-config/rest).
|
|
20
|
+
*
|
|
21
|
+
* <p>Abstracts throttle, response cache and network implementation details.
|
|
22
|
+
*
|
|
23
|
+
* <p>Modeled after the native {@link GlobalFetch} interface, which is relatively modern and
|
|
24
|
+
* convenient, but simplified for Remote Config's use case.
|
|
25
|
+
*
|
|
26
|
+
* Disambiguation: {@link GlobalFetch} interface and the Remote Config service define "fetch"
|
|
27
|
+
* methods. The RestClient uses the former to make HTTP calls. This interface abstracts the latter.
|
|
28
|
+
*/
|
|
29
|
+
export interface RemoteConfigFetchClient {
|
|
30
|
+
/**
|
|
31
|
+
* @throws if response status is not 200 or 304.
|
|
32
|
+
*/
|
|
33
|
+
fetch(request: FetchRequest): Promise<FetchResponse>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Defines a self-descriptive reference for config key-value pairs.
|
|
37
|
+
*/
|
|
38
|
+
export interface FirebaseRemoteConfigObject {
|
|
39
|
+
[key: string]: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Shims a minimal AbortSignal.
|
|
43
|
+
*
|
|
44
|
+
* <p>AbortController's AbortSignal conveniently decouples fetch timeout logic from other aspects
|
|
45
|
+
* of networking, such as retries. Firebase doesn't use AbortController enough to justify a
|
|
46
|
+
* polyfill recommendation, like we do with the Fetch API, but this minimal shim can easily be
|
|
47
|
+
* swapped out if/when we do.
|
|
48
|
+
*/
|
|
49
|
+
export declare class RemoteConfigAbortSignal {
|
|
50
|
+
listeners: Array<() => void>;
|
|
51
|
+
addEventListener(listener: () => void): void;
|
|
52
|
+
abort(): void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Defines per-request inputs for the Remote Config fetch request.
|
|
56
|
+
*
|
|
57
|
+
* <p>Modeled after the native {@link Request} interface, but simplified for Remote Config's
|
|
58
|
+
* use case.
|
|
59
|
+
*/
|
|
60
|
+
export interface FetchRequest {
|
|
61
|
+
/**
|
|
62
|
+
* Uses cached config if it is younger than this age.
|
|
63
|
+
*
|
|
64
|
+
* <p>Required because it's defined by settings, which always have a value.
|
|
65
|
+
*
|
|
66
|
+
* <p>Comparable to passing `headers = { 'Cache-Control': max-age <maxAge> }` to the native
|
|
67
|
+
* Fetch API.
|
|
68
|
+
*/
|
|
69
|
+
cacheMaxAgeMillis: number;
|
|
70
|
+
/**
|
|
71
|
+
* An event bus for the signal to abort a request.
|
|
72
|
+
*
|
|
73
|
+
* <p>Required because all requests should be abortable.
|
|
74
|
+
*
|
|
75
|
+
* <p>Comparable to the native
|
|
76
|
+
* Fetch API's "signal" field on its request configuration object
|
|
77
|
+
* https://fetch.spec.whatwg.org/#dom-requestinit-signal.
|
|
78
|
+
*
|
|
79
|
+
* <p>Disambiguation: Remote Config commonly refers to API inputs as
|
|
80
|
+
* "signals". See the private ConfigFetchRequestBody interface for those:
|
|
81
|
+
* http://google3/firebase/remote_config/web/src/core/rest_client.ts?l=14&rcl=255515243.
|
|
82
|
+
*/
|
|
83
|
+
signal: RemoteConfigAbortSignal;
|
|
84
|
+
/**
|
|
85
|
+
* The ETag header value from the last response.
|
|
86
|
+
*
|
|
87
|
+
* <p>Optional in case this is the first request.
|
|
88
|
+
*
|
|
89
|
+
* <p>Comparable to passing `headers = { 'If-None-Match': <eTag> }` to the native Fetch API.
|
|
90
|
+
*/
|
|
91
|
+
eTag?: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Defines a successful response (200 or 304).
|
|
95
|
+
*
|
|
96
|
+
* <p>Modeled after the native {@link Response} interface, but simplified for Remote Config's
|
|
97
|
+
* use case.
|
|
98
|
+
*/
|
|
99
|
+
export interface FetchResponse {
|
|
100
|
+
/**
|
|
101
|
+
* The HTTP status, which is useful for differentiating success responses with data from
|
|
102
|
+
* those without.
|
|
103
|
+
*
|
|
104
|
+
* <p>{@link RemoteConfigClient} is modeled after the native {@link GlobalFetch} interface, so
|
|
105
|
+
* HTTP status is first-class.
|
|
106
|
+
*
|
|
107
|
+
* <p>Disambiguation: the fetch response returns a legacy "state" value that is redundant with the
|
|
108
|
+
* HTTP status code. The former is normalized into the latter.
|
|
109
|
+
*/
|
|
110
|
+
status: number;
|
|
111
|
+
/**
|
|
112
|
+
* Defines the ETag response header value.
|
|
113
|
+
*
|
|
114
|
+
* <p>Only defined for 200 and 304 responses.
|
|
115
|
+
*/
|
|
116
|
+
eTag?: string;
|
|
117
|
+
/**
|
|
118
|
+
* Defines the map of parameters returned as "entries" in the fetch response body.
|
|
119
|
+
*
|
|
120
|
+
* <p>Only defined for 200 responses.
|
|
121
|
+
*/
|
|
122
|
+
config?: FirebaseRemoteConfigObject;
|
|
123
|
+
}
|