@firebase/remote-config 0.3.15 → 0.4.0

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/index.cjs.js CHANGED
@@ -10,7 +10,7 @@ var tslib = require('tslib');
10
10
  require('@firebase/installations');
11
11
 
12
12
  var name = "@firebase/remote-config";
13
- var version = "0.3.15";
13
+ var version = "0.4.0";
14
14
 
15
15
  /**
16
16
  * @license
@@ -85,25 +85,25 @@ var RC_COMPONENT_NAME = 'remote-config';
85
85
  */
86
86
  var _a;
87
87
  var ERROR_DESCRIPTION_MAP = (_a = {},
88
- _a["registration-window" /* REGISTRATION_WINDOW */] = 'Undefined window object. This SDK only supports usage in a browser environment.',
89
- _a["registration-project-id" /* REGISTRATION_PROJECT_ID */] = 'Undefined project identifier. Check Firebase app initialization.',
90
- _a["registration-api-key" /* REGISTRATION_API_KEY */] = 'Undefined API key. Check Firebase app initialization.',
91
- _a["registration-app-id" /* REGISTRATION_APP_ID */] = 'Undefined app identifier. Check Firebase app initialization.',
92
- _a["storage-open" /* STORAGE_OPEN */] = 'Error thrown when opening storage. Original error: {$originalErrorMessage}.',
93
- _a["storage-get" /* STORAGE_GET */] = 'Error thrown when reading from storage. Original error: {$originalErrorMessage}.',
94
- _a["storage-set" /* STORAGE_SET */] = 'Error thrown when writing to storage. Original error: {$originalErrorMessage}.',
95
- _a["storage-delete" /* STORAGE_DELETE */] = 'Error thrown when deleting from storage. Original error: {$originalErrorMessage}.',
96
- _a["fetch-client-network" /* FETCH_NETWORK */] = 'Fetch client failed to connect to a network. Check Internet connection.' +
88
+ _a["registration-window" /* ErrorCode.REGISTRATION_WINDOW */] = 'Undefined window object. This SDK only supports usage in a browser environment.',
89
+ _a["registration-project-id" /* ErrorCode.REGISTRATION_PROJECT_ID */] = 'Undefined project identifier. Check Firebase app initialization.',
90
+ _a["registration-api-key" /* ErrorCode.REGISTRATION_API_KEY */] = 'Undefined API key. Check Firebase app initialization.',
91
+ _a["registration-app-id" /* ErrorCode.REGISTRATION_APP_ID */] = 'Undefined app identifier. Check Firebase app initialization.',
92
+ _a["storage-open" /* ErrorCode.STORAGE_OPEN */] = 'Error thrown when opening storage. Original error: {$originalErrorMessage}.',
93
+ _a["storage-get" /* ErrorCode.STORAGE_GET */] = 'Error thrown when reading from storage. Original error: {$originalErrorMessage}.',
94
+ _a["storage-set" /* ErrorCode.STORAGE_SET */] = 'Error thrown when writing to storage. Original error: {$originalErrorMessage}.',
95
+ _a["storage-delete" /* ErrorCode.STORAGE_DELETE */] = 'Error thrown when deleting from storage. Original error: {$originalErrorMessage}.',
96
+ _a["fetch-client-network" /* ErrorCode.FETCH_NETWORK */] = 'Fetch client failed to connect to a network. Check Internet connection.' +
97
97
  ' Original error: {$originalErrorMessage}.',
98
- _a["fetch-timeout" /* FETCH_TIMEOUT */] = 'The config fetch request timed out. ' +
98
+ _a["fetch-timeout" /* ErrorCode.FETCH_TIMEOUT */] = 'The config fetch request timed out. ' +
99
99
  ' Configure timeout using "fetchTimeoutMillis" SDK setting.',
100
- _a["fetch-throttle" /* FETCH_THROTTLE */] = 'The config fetch request timed out while in an exponential backoff state.' +
100
+ _a["fetch-throttle" /* ErrorCode.FETCH_THROTTLE */] = 'The config fetch request timed out while in an exponential backoff state.' +
101
101
  ' Configure timeout using "fetchTimeoutMillis" SDK setting.' +
102
102
  ' Unix timestamp in milliseconds when fetch request throttling ends: {$throttleEndTimeMillis}.',
103
- _a["fetch-client-parse" /* FETCH_PARSE */] = 'Fetch client could not parse response.' +
103
+ _a["fetch-client-parse" /* ErrorCode.FETCH_PARSE */] = 'Fetch client could not parse response.' +
104
104
  ' Original error: {$originalErrorMessage}.',
105
- _a["fetch-status" /* FETCH_STATUS */] = 'Fetch server returned an HTTP error status. HTTP status: {$httpStatus}.',
106
- _a["indexed-db-unavailable" /* INDEXED_DB_UNAVAILABLE */] = 'Indexed DB is not supported by current browser',
105
+ _a["fetch-status" /* ErrorCode.FETCH_STATUS */] = 'Fetch server returned an HTTP error status. HTTP status: {$httpStatus}.',
106
+ _a["indexed-db-unavailable" /* ErrorCode.INDEXED_DB_UNAVAILABLE */] = 'Indexed DB is not supported by current browser',
107
107
  _a);
108
108
  var ERROR_FACTORY = new util.ErrorFactory('remoteconfig' /* service */, 'Remote Config' /* service name */, ERROR_DESCRIPTION_MAP);
109
109
  // Note how this is like typeof/instanceof, but for ErrorCode.
@@ -283,7 +283,7 @@ function fetchConfig(remoteConfig) {
283
283
  return [3 /*break*/, 6];
284
284
  case 4:
285
285
  e_1 = _a.sent();
286
- lastFetchStatus = hasErrorCode(e_1, "fetch-throttle" /* FETCH_THROTTLE */)
286
+ lastFetchStatus = hasErrorCode(e_1, "fetch-throttle" /* ErrorCode.FETCH_THROTTLE */)
287
287
  ? 'throttle'
288
288
  : 'failure';
289
289
  return [4 /*yield*/, rc._storageCache.setLastFetchStatus(lastFetchStatus)];
@@ -366,7 +366,7 @@ function getString(remoteConfig, key) {
366
366
  function getValue(remoteConfig, key) {
367
367
  var rc = util.getModularInstance(remoteConfig);
368
368
  if (!rc._isInitializationComplete) {
369
- rc._logger.debug("A value was requested for key \"" + key + "\" before SDK initialization completed." +
369
+ rc._logger.debug("A value was requested for key \"".concat(key, "\" before SDK initialization completed.") +
370
370
  ' Await on ensureInitialized if the intent was to get a previously activated value.');
371
371
  }
372
372
  var activeConfig = rc._storageCache.getActiveConfig();
@@ -376,7 +376,7 @@ function getValue(remoteConfig, key) {
376
376
  else if (rc.defaultConfig && rc.defaultConfig[key] !== undefined) {
377
377
  return new Value('default', String(rc.defaultConfig[key]));
378
378
  }
379
- rc._logger.debug("Returning static value for key \"" + key + "\"." +
379
+ rc._logger.debug("Returning static value for key \"".concat(key, "\".") +
380
380
  ' Define a default or remote value if this is unintentional.');
381
381
  return new Value('static');
382
382
  }
@@ -459,9 +459,9 @@ var CachingClient = /** @class */ (function () {
459
459
  var cacheAgeMillis = Date.now() - lastSuccessfulFetchTimestampMillis;
460
460
  var isCachedDataFresh = cacheAgeMillis <= cacheMaxAgeMillis;
461
461
  this.logger.debug('Config fetch cache check.' +
462
- (" Cache age millis: " + cacheAgeMillis + ".") +
463
- (" Cache max age millis (minimumFetchIntervalMillis setting): " + cacheMaxAgeMillis + ".") +
464
- (" Is cache hit: " + isCachedDataFresh + "."));
462
+ " Cache age millis: ".concat(cacheAgeMillis, ".") +
463
+ " Cache max age millis (minimumFetchIntervalMillis setting): ".concat(cacheMaxAgeMillis, ".") +
464
+ " Is cache hit: ".concat(isCachedDataFresh, "."));
465
465
  return isCachedDataFresh;
466
466
  };
467
467
  CachingClient.prototype.fetch = function (request) {
@@ -581,20 +581,19 @@ var RestClient = /** @class */ (function () {
581
581
  * @throws a {@link ErrorCode.FETCH_STATUS} error if the service returns an HTTP error status.
582
582
  */
583
583
  RestClient.prototype.fetch = function (request) {
584
- var _a, _b, _c;
585
584
  return tslib.__awaiter(this, void 0, void 0, function () {
586
- var _d, installationId, installationToken, urlBase, url, headers, requestBody, options, fetchPromise, timeoutPromise, response, originalError_1, errorCode, status, responseEtag, config, state, responseBody, originalError_2;
587
- return tslib.__generator(this, function (_e) {
588
- switch (_e.label) {
585
+ var _a, installationId, installationToken, urlBase, url, headers, requestBody, options, fetchPromise, timeoutPromise, response, originalError_1, errorCode, status, responseEtag, config, state, responseBody, originalError_2;
586
+ return tslib.__generator(this, function (_b) {
587
+ switch (_b.label) {
589
588
  case 0: return [4 /*yield*/, Promise.all([
590
589
  this.firebaseInstallations.getId(),
591
590
  this.firebaseInstallations.getToken()
592
591
  ])];
593
592
  case 1:
594
- _d = _e.sent(), installationId = _d[0], installationToken = _d[1];
593
+ _a = _b.sent(), installationId = _a[0], installationToken = _a[1];
595
594
  urlBase = window.FIREBASE_REMOTE_CONFIG_URL_BASE ||
596
595
  'https://firebaseremoteconfig.googleapis.com';
597
- url = urlBase + "/v1/projects/" + this.projectId + "/namespaces/" + this.namespace + ":fetch?key=" + this.apiKey;
596
+ url = "".concat(urlBase, "/v1/projects/").concat(this.projectId, "/namespaces/").concat(this.namespace, ":fetch?key=").concat(this.apiKey);
598
597
  headers = {
599
598
  'Content-Type': 'application/json',
600
599
  'Content-Encoding': 'gzip',
@@ -626,46 +625,46 @@ var RestClient = /** @class */ (function () {
626
625
  reject(error);
627
626
  });
628
627
  });
629
- _e.label = 2;
628
+ _b.label = 2;
630
629
  case 2:
631
- _e.trys.push([2, 5, , 6]);
630
+ _b.trys.push([2, 5, , 6]);
632
631
  return [4 /*yield*/, Promise.race([fetchPromise, timeoutPromise])];
633
632
  case 3:
634
- _e.sent();
633
+ _b.sent();
635
634
  return [4 /*yield*/, fetchPromise];
636
635
  case 4:
637
- response = _e.sent();
636
+ response = _b.sent();
638
637
  return [3 /*break*/, 6];
639
638
  case 5:
640
- originalError_1 = _e.sent();
641
- errorCode = "fetch-client-network" /* FETCH_NETWORK */;
642
- if (((_a = originalError_1) === null || _a === void 0 ? void 0 : _a.name) === 'AbortError') {
643
- errorCode = "fetch-timeout" /* FETCH_TIMEOUT */;
639
+ originalError_1 = _b.sent();
640
+ errorCode = "fetch-client-network" /* ErrorCode.FETCH_NETWORK */;
641
+ if ((originalError_1 === null || originalError_1 === void 0 ? void 0 : originalError_1.name) === 'AbortError') {
642
+ errorCode = "fetch-timeout" /* ErrorCode.FETCH_TIMEOUT */;
644
643
  }
645
644
  throw ERROR_FACTORY.create(errorCode, {
646
- originalErrorMessage: (_b = originalError_1) === null || _b === void 0 ? void 0 : _b.message
645
+ originalErrorMessage: originalError_1 === null || originalError_1 === void 0 ? void 0 : originalError_1.message
647
646
  });
648
647
  case 6:
649
648
  status = response.status;
650
649
  responseEtag = response.headers.get('ETag') || undefined;
651
650
  if (!(response.status === 200)) return [3 /*break*/, 11];
652
651
  responseBody = void 0;
653
- _e.label = 7;
652
+ _b.label = 7;
654
653
  case 7:
655
- _e.trys.push([7, 9, , 10]);
654
+ _b.trys.push([7, 9, , 10]);
656
655
  return [4 /*yield*/, response.json()];
657
656
  case 8:
658
- responseBody = _e.sent();
657
+ responseBody = _b.sent();
659
658
  return [3 /*break*/, 10];
660
659
  case 9:
661
- originalError_2 = _e.sent();
662
- throw ERROR_FACTORY.create("fetch-client-parse" /* FETCH_PARSE */, {
663
- originalErrorMessage: (_c = originalError_2) === null || _c === void 0 ? void 0 : _c.message
660
+ originalError_2 = _b.sent();
661
+ throw ERROR_FACTORY.create("fetch-client-parse" /* ErrorCode.FETCH_PARSE */, {
662
+ originalErrorMessage: originalError_2 === null || originalError_2 === void 0 ? void 0 : originalError_2.message
664
663
  });
665
664
  case 10:
666
665
  config = responseBody['entries'];
667
666
  state = responseBody['state'];
668
- _e.label = 11;
667
+ _b.label = 11;
669
668
  case 11:
670
669
  // Normalizes based on legacy state.
671
670
  if (state === 'INSTANCE_STATE_UNSPECIFIED') {
@@ -683,7 +682,7 @@ var RestClient = /** @class */ (function () {
683
682
  // differentiating success states (200 from 304; the state body param is undefined in a
684
683
  // standard 304).
685
684
  if (status !== 304 && status !== 200) {
686
- throw ERROR_FACTORY.create("fetch-status" /* FETCH_STATUS */, {
685
+ throw ERROR_FACTORY.create("fetch-status" /* ErrorCode.FETCH_STATUS */, {
687
686
  httpStatus: status
688
687
  });
689
688
  }
@@ -732,7 +731,7 @@ function setAbortableTimeout(signal, throttleEndTimeMillis) {
732
731
  signal.addEventListener(function () {
733
732
  clearTimeout(timeout);
734
733
  // If the request completes before this timeout, the rejection has no effect.
735
- reject(ERROR_FACTORY.create("fetch-throttle" /* FETCH_THROTTLE */, {
734
+ reject(ERROR_FACTORY.create("fetch-throttle" /* ErrorCode.FETCH_THROTTLE */, {
736
735
  throttleEndTimeMillis: throttleEndTimeMillis
737
736
  }));
738
737
  });
@@ -934,10 +933,9 @@ var RemoteConfig = /** @class */ (function () {
934
933
  * Converts an error event associated with a {@link IDBRequest} to a {@link FirebaseError}.
935
934
  */
936
935
  function toFirebaseError(event, errorCode) {
937
- var _a;
938
936
  var originalError = event.target.error || undefined;
939
937
  return ERROR_FACTORY.create(errorCode, {
940
- originalErrorMessage: originalError && ((_a = originalError) === null || _a === void 0 ? void 0 : _a.message)
938
+ originalErrorMessage: originalError && (originalError === null || originalError === void 0 ? void 0 : originalError.message)
941
939
  });
942
940
  }
943
941
  /**
@@ -956,11 +954,10 @@ var DB_VERSION = 1;
956
954
  // Visible for testing.
957
955
  function openDatabase() {
958
956
  return new Promise(function (resolve, reject) {
959
- var _a;
960
957
  try {
961
958
  var request = indexedDB.open(DB_NAME, DB_VERSION);
962
959
  request.onerror = function (event) {
963
- reject(toFirebaseError(event, "storage-open" /* STORAGE_OPEN */));
960
+ reject(toFirebaseError(event, "storage-open" /* ErrorCode.STORAGE_OPEN */));
964
961
  };
965
962
  request.onsuccess = function (event) {
966
963
  resolve(event.target.result);
@@ -981,8 +978,8 @@ function openDatabase() {
981
978
  };
982
979
  }
983
980
  catch (error) {
984
- reject(ERROR_FACTORY.create("storage-open" /* STORAGE_OPEN */, {
985
- originalErrorMessage: (_a = error) === null || _a === void 0 ? void 0 : _a.message
981
+ reject(ERROR_FACTORY.create("storage-open" /* ErrorCode.STORAGE_OPEN */, {
982
+ originalErrorMessage: error === null || error === void 0 ? void 0 : error.message
986
983
  }));
987
984
  }
988
985
  });
@@ -1054,14 +1051,13 @@ var Storage = /** @class */ (function () {
1054
1051
  case 1:
1055
1052
  db = _a.sent();
1056
1053
  return [2 /*return*/, new Promise(function (resolve, reject) {
1057
- var _a;
1058
1054
  var transaction = db.transaction([APP_NAMESPACE_STORE], 'readonly');
1059
1055
  var objectStore = transaction.objectStore(APP_NAMESPACE_STORE);
1060
1056
  var compositeKey = _this.createCompositeKey(key);
1061
1057
  try {
1062
1058
  var request = objectStore.get(compositeKey);
1063
1059
  request.onerror = function (event) {
1064
- reject(toFirebaseError(event, "storage-get" /* STORAGE_GET */));
1060
+ reject(toFirebaseError(event, "storage-get" /* ErrorCode.STORAGE_GET */));
1065
1061
  };
1066
1062
  request.onsuccess = function (event) {
1067
1063
  var result = event.target.result;
@@ -1074,8 +1070,8 @@ var Storage = /** @class */ (function () {
1074
1070
  };
1075
1071
  }
1076
1072
  catch (e) {
1077
- reject(ERROR_FACTORY.create("storage-get" /* STORAGE_GET */, {
1078
- originalErrorMessage: (_a = e) === null || _a === void 0 ? void 0 : _a.message
1073
+ reject(ERROR_FACTORY.create("storage-get" /* ErrorCode.STORAGE_GET */, {
1074
+ originalErrorMessage: e === null || e === void 0 ? void 0 : e.message
1079
1075
  }));
1080
1076
  }
1081
1077
  })];
@@ -1093,7 +1089,6 @@ var Storage = /** @class */ (function () {
1093
1089
  case 1:
1094
1090
  db = _a.sent();
1095
1091
  return [2 /*return*/, new Promise(function (resolve, reject) {
1096
- var _a;
1097
1092
  var transaction = db.transaction([APP_NAMESPACE_STORE], 'readwrite');
1098
1093
  var objectStore = transaction.objectStore(APP_NAMESPACE_STORE);
1099
1094
  var compositeKey = _this.createCompositeKey(key);
@@ -1103,15 +1098,15 @@ var Storage = /** @class */ (function () {
1103
1098
  value: value
1104
1099
  });
1105
1100
  request.onerror = function (event) {
1106
- reject(toFirebaseError(event, "storage-set" /* STORAGE_SET */));
1101
+ reject(toFirebaseError(event, "storage-set" /* ErrorCode.STORAGE_SET */));
1107
1102
  };
1108
1103
  request.onsuccess = function () {
1109
1104
  resolve();
1110
1105
  };
1111
1106
  }
1112
1107
  catch (e) {
1113
- reject(ERROR_FACTORY.create("storage-set" /* STORAGE_SET */, {
1114
- originalErrorMessage: (_a = e) === null || _a === void 0 ? void 0 : _a.message
1108
+ reject(ERROR_FACTORY.create("storage-set" /* ErrorCode.STORAGE_SET */, {
1109
+ originalErrorMessage: e === null || e === void 0 ? void 0 : e.message
1115
1110
  }));
1116
1111
  }
1117
1112
  })];
@@ -1129,22 +1124,21 @@ var Storage = /** @class */ (function () {
1129
1124
  case 1:
1130
1125
  db = _a.sent();
1131
1126
  return [2 /*return*/, new Promise(function (resolve, reject) {
1132
- var _a;
1133
1127
  var transaction = db.transaction([APP_NAMESPACE_STORE], 'readwrite');
1134
1128
  var objectStore = transaction.objectStore(APP_NAMESPACE_STORE);
1135
1129
  var compositeKey = _this.createCompositeKey(key);
1136
1130
  try {
1137
1131
  var request = objectStore.delete(compositeKey);
1138
1132
  request.onerror = function (event) {
1139
- reject(toFirebaseError(event, "storage-delete" /* STORAGE_DELETE */));
1133
+ reject(toFirebaseError(event, "storage-delete" /* ErrorCode.STORAGE_DELETE */));
1140
1134
  };
1141
1135
  request.onsuccess = function () {
1142
1136
  resolve();
1143
1137
  };
1144
1138
  }
1145
1139
  catch (e) {
1146
- reject(ERROR_FACTORY.create("storage-delete" /* STORAGE_DELETE */, {
1147
- originalErrorMessage: (_a = e) === null || _a === void 0 ? void 0 : _a.message
1140
+ reject(ERROR_FACTORY.create("storage-delete" /* ErrorCode.STORAGE_DELETE */, {
1141
+ originalErrorMessage: e === null || e === void 0 ? void 0 : e.message
1148
1142
  }));
1149
1143
  }
1150
1144
  })];
@@ -1265,7 +1259,7 @@ var StorageCache = /** @class */ (function () {
1265
1259
  * limitations under the License.
1266
1260
  */
1267
1261
  function registerRemoteConfig() {
1268
- app._registerComponent(new component.Component(RC_COMPONENT_NAME, remoteConfigFactory, "PUBLIC" /* PUBLIC */).setMultipleInstances(true));
1262
+ app._registerComponent(new component.Component(RC_COMPONENT_NAME, remoteConfigFactory, "PUBLIC" /* ComponentType.PUBLIC */).setMultipleInstances(true));
1269
1263
  app.registerVersion(name, version);
1270
1264
  // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
1271
1265
  app.registerVersion(name, version, 'cjs5');
@@ -1280,22 +1274,22 @@ function registerRemoteConfig() {
1280
1274
  .getImmediate();
1281
1275
  // Guards against the SDK being used in non-browser environments.
1282
1276
  if (typeof window === 'undefined') {
1283
- throw ERROR_FACTORY.create("registration-window" /* REGISTRATION_WINDOW */);
1277
+ throw ERROR_FACTORY.create("registration-window" /* ErrorCode.REGISTRATION_WINDOW */);
1284
1278
  }
1285
1279
  // Guards against the SDK being used when indexedDB is not available.
1286
1280
  if (!util.isIndexedDBAvailable()) {
1287
- throw ERROR_FACTORY.create("indexed-db-unavailable" /* INDEXED_DB_UNAVAILABLE */);
1281
+ throw ERROR_FACTORY.create("indexed-db-unavailable" /* ErrorCode.INDEXED_DB_UNAVAILABLE */);
1288
1282
  }
1289
1283
  // Normalizes optional inputs.
1290
1284
  var _b = app$1.options, projectId = _b.projectId, apiKey = _b.apiKey, appId = _b.appId;
1291
1285
  if (!projectId) {
1292
- throw ERROR_FACTORY.create("registration-project-id" /* REGISTRATION_PROJECT_ID */);
1286
+ throw ERROR_FACTORY.create("registration-project-id" /* ErrorCode.REGISTRATION_PROJECT_ID */);
1293
1287
  }
1294
1288
  if (!apiKey) {
1295
- throw ERROR_FACTORY.create("registration-api-key" /* REGISTRATION_API_KEY */);
1289
+ throw ERROR_FACTORY.create("registration-api-key" /* ErrorCode.REGISTRATION_API_KEY */);
1296
1290
  }
1297
1291
  if (!appId) {
1298
- throw ERROR_FACTORY.create("registration-app-id" /* REGISTRATION_APP_ID */);
1292
+ throw ERROR_FACTORY.create("registration-app-id" /* ErrorCode.REGISTRATION_APP_ID */);
1299
1293
  }
1300
1294
  namespace = namespace || 'firebase';
1301
1295
  var storage = new Storage(appId, app$1.name, namespace);