15
15
* limitations under the License.
16
16
*/
17
17
18
- import { SettingsService } from './settings_service' ;
19
18
import {
20
- SDK_VERSION ,
19
+ CONFIG_EXPIRY_LOCAL_STORAGE_KEY ,
21
20
CONFIG_LOCAL_STORAGE_KEY ,
22
- CONFIG_EXPIRY_LOCAL_STORAGE_KEY
21
+ SDK_VERSION
23
22
} from '../constants' ;
24
- import { Api } from './api_service' ;
25
- import { getAuthTokenPromise } from './iid_service' ;
26
23
import { consoleLogger } from '../utils/console_logger' ;
27
24
import { ERROR_FACTORY , ErrorCode } from '../utils/errors' ;
28
25
26
+ import { Api } from './api_service' ;
27
+ import { getAuthTokenPromise } from './iid_service' ;
28
+ import { SettingsService } from './settings_service' ;
29
+
29
30
const REMOTE_CONFIG_SDK_VERSION = '0.0.1' ;
30
31
31
32
interface SecondaryConfig {
@@ -71,12 +72,16 @@ export function getConfig(iid: string): Promise<void> {
71
72
. then ( config => processConfig ( config ) )
72
73
. then (
73
74
config => storeConfig ( config ) ,
74
- /** Do nothing for error, use defaults set in settings service. */ ( ) => { }
75
+ /** Do nothing for error, use defaults set in settings service. */
76
+ ( ) => { }
75
77
) ;
76
78
}
77
79
78
80
function getStoredConfig ( ) : RemoteConfigResponse | undefined {
79
81
const localStorage = Api . getInstance ( ) . localStorage ;
82
+ if ( ! localStorage ) {
83
+ return ;
84
+ }
80
85
const expiryString = localStorage . getItem ( CONFIG_EXPIRY_LOCAL_STORAGE_KEY ) ;
81
86
if ( ! expiryString || ! configValid ( expiryString ) ) {
82
87
return ;
@@ -95,10 +100,11 @@ function getStoredConfig(): RemoteConfigResponse | undefined {
95
100
}
96
101
97
102
function storeConfig ( config : RemoteConfigResponse | undefined ) : void {
98
- if ( ! config ) {
103
+ const localStorage = Api . getInstance ( ) . localStorage ;
104
+ if ( ! config || ! localStorage ) {
99
105
return ;
100
106
}
101
- const localStorage = Api . getInstance ( ) . localStorage ;
107
+
102
108
localStorage . setItem ( CONFIG_LOCAL_STORAGE_KEY , JSON . stringify ( config ) ) ;
103
109
localStorage . setItem (
104
110
CONFIG_EXPIRY_LOCAL_STORAGE_KEY ,
@@ -122,9 +128,7 @@ function getRemoteConfig(
122
128
const configEndPoint = `https://firebaseremoteconfig.googleapis.com/v1/projects/${ projectId } /namespaces/fireperf:fetch?key=${ SettingsService . getInstance ( ) . getApiKey ( ) } ` ;
123
129
const request = new Request ( configEndPoint , {
124
130
method : 'POST' ,
125
- headers : {
126
- Authorization : `${ FIS_AUTH_PREFIX } ${ authToken } `
127
- } ,
131
+ headers : { Authorization : `${ FIS_AUTH_PREFIX } ${ authToken } ` } ,
128
132
/* eslint-disable camelcase */
129
133
body : JSON . stringify ( {
130
134
app_instance_id : iid ,
@@ -163,7 +167,8 @@ function processConfig(
163
167
const settingsServiceInstance = SettingsService . getInstance ( ) ;
164
168
const entries = config . entries || { } ;
165
169
if ( entries . fpr_enabled !== undefined ) {
166
- // TODO: Change the assignment of loggingEnabled once the received type is known.
170
+ // TODO: Change the assignment of loggingEnabled once the received type is
171
+ // known.
167
172
settingsServiceInstance . loggingEnabled =
168
173
String ( entries . fpr_enabled ) === 'true' ;
169
174
} else if ( SECONDARY_CONFIGS . loggingEnabled !== undefined ) {
0 commit comments