@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.
@@ -5,7 +5,7 @@ import { LogLevel, Logger } from '@firebase/logger';
5
5
  import '@firebase/installations';
6
6
 
7
7
  const name = "@firebase/remote-config";
8
- const version = "0.3.15";
8
+ const version = "0.4.0";
9
9
 
10
10
  /**
11
11
  * @license
@@ -78,25 +78,25 @@ const RC_COMPONENT_NAME = 'remote-config';
78
78
  * limitations under the License.
79
79
  */
80
80
  const ERROR_DESCRIPTION_MAP = {
81
- ["registration-window" /* REGISTRATION_WINDOW */]: 'Undefined window object. This SDK only supports usage in a browser environment.',
82
- ["registration-project-id" /* REGISTRATION_PROJECT_ID */]: 'Undefined project identifier. Check Firebase app initialization.',
83
- ["registration-api-key" /* REGISTRATION_API_KEY */]: 'Undefined API key. Check Firebase app initialization.',
84
- ["registration-app-id" /* REGISTRATION_APP_ID */]: 'Undefined app identifier. Check Firebase app initialization.',
85
- ["storage-open" /* STORAGE_OPEN */]: 'Error thrown when opening storage. Original error: {$originalErrorMessage}.',
86
- ["storage-get" /* STORAGE_GET */]: 'Error thrown when reading from storage. Original error: {$originalErrorMessage}.',
87
- ["storage-set" /* STORAGE_SET */]: 'Error thrown when writing to storage. Original error: {$originalErrorMessage}.',
88
- ["storage-delete" /* STORAGE_DELETE */]: 'Error thrown when deleting from storage. Original error: {$originalErrorMessage}.',
89
- ["fetch-client-network" /* FETCH_NETWORK */]: 'Fetch client failed to connect to a network. Check Internet connection.' +
81
+ ["registration-window" /* ErrorCode.REGISTRATION_WINDOW */]: 'Undefined window object. This SDK only supports usage in a browser environment.',
82
+ ["registration-project-id" /* ErrorCode.REGISTRATION_PROJECT_ID */]: 'Undefined project identifier. Check Firebase app initialization.',
83
+ ["registration-api-key" /* ErrorCode.REGISTRATION_API_KEY */]: 'Undefined API key. Check Firebase app initialization.',
84
+ ["registration-app-id" /* ErrorCode.REGISTRATION_APP_ID */]: 'Undefined app identifier. Check Firebase app initialization.',
85
+ ["storage-open" /* ErrorCode.STORAGE_OPEN */]: 'Error thrown when opening storage. Original error: {$originalErrorMessage}.',
86
+ ["storage-get" /* ErrorCode.STORAGE_GET */]: 'Error thrown when reading from storage. Original error: {$originalErrorMessage}.',
87
+ ["storage-set" /* ErrorCode.STORAGE_SET */]: 'Error thrown when writing to storage. Original error: {$originalErrorMessage}.',
88
+ ["storage-delete" /* ErrorCode.STORAGE_DELETE */]: 'Error thrown when deleting from storage. Original error: {$originalErrorMessage}.',
89
+ ["fetch-client-network" /* ErrorCode.FETCH_NETWORK */]: 'Fetch client failed to connect to a network. Check Internet connection.' +
90
90
  ' Original error: {$originalErrorMessage}.',
91
- ["fetch-timeout" /* FETCH_TIMEOUT */]: 'The config fetch request timed out. ' +
91
+ ["fetch-timeout" /* ErrorCode.FETCH_TIMEOUT */]: 'The config fetch request timed out. ' +
92
92
  ' Configure timeout using "fetchTimeoutMillis" SDK setting.',
93
- ["fetch-throttle" /* FETCH_THROTTLE */]: 'The config fetch request timed out while in an exponential backoff state.' +
93
+ ["fetch-throttle" /* ErrorCode.FETCH_THROTTLE */]: 'The config fetch request timed out while in an exponential backoff state.' +
94
94
  ' Configure timeout using "fetchTimeoutMillis" SDK setting.' +
95
95
  ' Unix timestamp in milliseconds when fetch request throttling ends: {$throttleEndTimeMillis}.',
96
- ["fetch-client-parse" /* FETCH_PARSE */]: 'Fetch client could not parse response.' +
96
+ ["fetch-client-parse" /* ErrorCode.FETCH_PARSE */]: 'Fetch client could not parse response.' +
97
97
  ' Original error: {$originalErrorMessage}.',
98
- ["fetch-status" /* FETCH_STATUS */]: 'Fetch server returned an HTTP error status. HTTP status: {$httpStatus}.',
99
- ["indexed-db-unavailable" /* INDEXED_DB_UNAVAILABLE */]: 'Indexed DB is not supported by current browser'
98
+ ["fetch-status" /* ErrorCode.FETCH_STATUS */]: 'Fetch server returned an HTTP error status. HTTP status: {$httpStatus}.',
99
+ ["indexed-db-unavailable" /* ErrorCode.INDEXED_DB_UNAVAILABLE */]: 'Indexed DB is not supported by current browser'
100
100
  };
101
101
  const ERROR_FACTORY = new ErrorFactory('remoteconfig' /* service */, 'Remote Config' /* service name */, ERROR_DESCRIPTION_MAP);
102
102
  // Note how this is like typeof/instanceof, but for ErrorCode.
@@ -256,7 +256,7 @@ async function fetchConfig(remoteConfig) {
256
256
  await rc._storageCache.setLastFetchStatus('success');
257
257
  }
258
258
  catch (e) {
259
- const lastFetchStatus = hasErrorCode(e, "fetch-throttle" /* FETCH_THROTTLE */)
259
+ const lastFetchStatus = hasErrorCode(e, "fetch-throttle" /* ErrorCode.FETCH_THROTTLE */)
260
260
  ? 'throttle'
261
261
  : 'failure';
262
262
  await rc._storageCache.setLastFetchStatus(lastFetchStatus);
@@ -535,7 +535,6 @@ class RestClient {
535
535
  * @throws a {@link ErrorCode.FETCH_STATUS} error if the service returns an HTTP error status.
536
536
  */
537
537
  async fetch(request) {
538
- var _a, _b, _c;
539
538
  const [installationId, installationToken] = await Promise.all([
540
539
  this.firebaseInstallations.getId(),
541
540
  this.firebaseInstallations.getToken()
@@ -581,12 +580,12 @@ class RestClient {
581
580
  response = await fetchPromise;
582
581
  }
583
582
  catch (originalError) {
584
- let errorCode = "fetch-client-network" /* FETCH_NETWORK */;
585
- if (((_a = originalError) === null || _a === void 0 ? void 0 : _a.name) === 'AbortError') {
586
- errorCode = "fetch-timeout" /* FETCH_TIMEOUT */;
583
+ let errorCode = "fetch-client-network" /* ErrorCode.FETCH_NETWORK */;
584
+ if ((originalError === null || originalError === void 0 ? void 0 : originalError.name) === 'AbortError') {
585
+ errorCode = "fetch-timeout" /* ErrorCode.FETCH_TIMEOUT */;
587
586
  }
588
587
  throw ERROR_FACTORY.create(errorCode, {
589
- originalErrorMessage: (_b = originalError) === null || _b === void 0 ? void 0 : _b.message
588
+ originalErrorMessage: originalError === null || originalError === void 0 ? void 0 : originalError.message
590
589
  });
591
590
  }
592
591
  let status = response.status;
@@ -602,8 +601,8 @@ class RestClient {
602
601
  responseBody = await response.json();
603
602
  }
604
603
  catch (originalError) {
605
- throw ERROR_FACTORY.create("fetch-client-parse" /* FETCH_PARSE */, {
606
- originalErrorMessage: (_c = originalError) === null || _c === void 0 ? void 0 : _c.message
604
+ throw ERROR_FACTORY.create("fetch-client-parse" /* ErrorCode.FETCH_PARSE */, {
605
+ originalErrorMessage: originalError === null || originalError === void 0 ? void 0 : originalError.message
607
606
  });
608
607
  }
609
608
  config = responseBody['entries'];
@@ -625,7 +624,7 @@ class RestClient {
625
624
  // differentiating success states (200 from 304; the state body param is undefined in a
626
625
  // standard 304).
627
626
  if (status !== 304 && status !== 200) {
628
- throw ERROR_FACTORY.create("fetch-status" /* FETCH_STATUS */, {
627
+ throw ERROR_FACTORY.create("fetch-status" /* ErrorCode.FETCH_STATUS */, {
629
628
  httpStatus: status
630
629
  });
631
630
  }
@@ -670,7 +669,7 @@ function setAbortableTimeout(signal, throttleEndTimeMillis) {
670
669
  signal.addEventListener(() => {
671
670
  clearTimeout(timeout);
672
671
  // If the request completes before this timeout, the rejection has no effect.
673
- reject(ERROR_FACTORY.create("fetch-throttle" /* FETCH_THROTTLE */, {
672
+ reject(ERROR_FACTORY.create("fetch-throttle" /* ErrorCode.FETCH_THROTTLE */, {
674
673
  throttleEndTimeMillis
675
674
  }));
676
675
  });
@@ -830,10 +829,9 @@ class RemoteConfig {
830
829
  * Converts an error event associated with a {@link IDBRequest} to a {@link FirebaseError}.
831
830
  */
832
831
  function toFirebaseError(event, errorCode) {
833
- var _a;
834
832
  const originalError = event.target.error || undefined;
835
833
  return ERROR_FACTORY.create(errorCode, {
836
- originalErrorMessage: originalError && ((_a = originalError) === null || _a === void 0 ? void 0 : _a.message)
834
+ originalErrorMessage: originalError && (originalError === null || originalError === void 0 ? void 0 : originalError.message)
837
835
  });
838
836
  }
839
837
  /**
@@ -852,11 +850,10 @@ const DB_VERSION = 1;
852
850
  // Visible for testing.
853
851
  function openDatabase() {
854
852
  return new Promise((resolve, reject) => {
855
- var _a;
856
853
  try {
857
854
  const request = indexedDB.open(DB_NAME, DB_VERSION);
858
855
  request.onerror = event => {
859
- reject(toFirebaseError(event, "storage-open" /* STORAGE_OPEN */));
856
+ reject(toFirebaseError(event, "storage-open" /* ErrorCode.STORAGE_OPEN */));
860
857
  };
861
858
  request.onsuccess = event => {
862
859
  resolve(event.target.result);
@@ -877,8 +874,8 @@ function openDatabase() {
877
874
  };
878
875
  }
879
876
  catch (error) {
880
- reject(ERROR_FACTORY.create("storage-open" /* STORAGE_OPEN */, {
881
- originalErrorMessage: (_a = error) === null || _a === void 0 ? void 0 : _a.message
877
+ reject(ERROR_FACTORY.create("storage-open" /* ErrorCode.STORAGE_OPEN */, {
878
+ originalErrorMessage: error === null || error === void 0 ? void 0 : error.message
882
879
  }));
883
880
  }
884
881
  });
@@ -942,14 +939,13 @@ class Storage {
942
939
  async get(key) {
943
940
  const db = await this.openDbPromise;
944
941
  return new Promise((resolve, reject) => {
945
- var _a;
946
942
  const transaction = db.transaction([APP_NAMESPACE_STORE], 'readonly');
947
943
  const objectStore = transaction.objectStore(APP_NAMESPACE_STORE);
948
944
  const compositeKey = this.createCompositeKey(key);
949
945
  try {
950
946
  const request = objectStore.get(compositeKey);
951
947
  request.onerror = event => {
952
- reject(toFirebaseError(event, "storage-get" /* STORAGE_GET */));
948
+ reject(toFirebaseError(event, "storage-get" /* ErrorCode.STORAGE_GET */));
953
949
  };
954
950
  request.onsuccess = event => {
955
951
  const result = event.target.result;
@@ -962,8 +958,8 @@ class Storage {
962
958
  };
963
959
  }
964
960
  catch (e) {
965
- reject(ERROR_FACTORY.create("storage-get" /* STORAGE_GET */, {
966
- originalErrorMessage: (_a = e) === null || _a === void 0 ? void 0 : _a.message
961
+ reject(ERROR_FACTORY.create("storage-get" /* ErrorCode.STORAGE_GET */, {
962
+ originalErrorMessage: e === null || e === void 0 ? void 0 : e.message
967
963
  }));
968
964
  }
969
965
  });
@@ -971,7 +967,6 @@ class Storage {
971
967
  async set(key, value) {
972
968
  const db = await this.openDbPromise;
973
969
  return new Promise((resolve, reject) => {
974
- var _a;
975
970
  const transaction = db.transaction([APP_NAMESPACE_STORE], 'readwrite');
976
971
  const objectStore = transaction.objectStore(APP_NAMESPACE_STORE);
977
972
  const compositeKey = this.createCompositeKey(key);
@@ -981,15 +976,15 @@ class Storage {
981
976
  value
982
977
  });
983
978
  request.onerror = (event) => {
984
- reject(toFirebaseError(event, "storage-set" /* STORAGE_SET */));
979
+ reject(toFirebaseError(event, "storage-set" /* ErrorCode.STORAGE_SET */));
985
980
  };
986
981
  request.onsuccess = () => {
987
982
  resolve();
988
983
  };
989
984
  }
990
985
  catch (e) {
991
- reject(ERROR_FACTORY.create("storage-set" /* STORAGE_SET */, {
992
- originalErrorMessage: (_a = e) === null || _a === void 0 ? void 0 : _a.message
986
+ reject(ERROR_FACTORY.create("storage-set" /* ErrorCode.STORAGE_SET */, {
987
+ originalErrorMessage: e === null || e === void 0 ? void 0 : e.message
993
988
  }));
994
989
  }
995
990
  });
@@ -997,22 +992,21 @@ class Storage {
997
992
  async delete(key) {
998
993
  const db = await this.openDbPromise;
999
994
  return new Promise((resolve, reject) => {
1000
- var _a;
1001
995
  const transaction = db.transaction([APP_NAMESPACE_STORE], 'readwrite');
1002
996
  const objectStore = transaction.objectStore(APP_NAMESPACE_STORE);
1003
997
  const compositeKey = this.createCompositeKey(key);
1004
998
  try {
1005
999
  const request = objectStore.delete(compositeKey);
1006
1000
  request.onerror = (event) => {
1007
- reject(toFirebaseError(event, "storage-delete" /* STORAGE_DELETE */));
1001
+ reject(toFirebaseError(event, "storage-delete" /* ErrorCode.STORAGE_DELETE */));
1008
1002
  };
1009
1003
  request.onsuccess = () => {
1010
1004
  resolve();
1011
1005
  };
1012
1006
  }
1013
1007
  catch (e) {
1014
- reject(ERROR_FACTORY.create("storage-delete" /* STORAGE_DELETE */, {
1015
- originalErrorMessage: (_a = e) === null || _a === void 0 ? void 0 : _a.message
1008
+ reject(ERROR_FACTORY.create("storage-delete" /* ErrorCode.STORAGE_DELETE */, {
1009
+ originalErrorMessage: e === null || e === void 0 ? void 0 : e.message
1016
1010
  }));
1017
1011
  }
1018
1012
  });
@@ -1118,7 +1112,7 @@ class StorageCache {
1118
1112
  * limitations under the License.
1119
1113
  */
1120
1114
  function registerRemoteConfig() {
1121
- _registerComponent(new Component(RC_COMPONENT_NAME, remoteConfigFactory, "PUBLIC" /* PUBLIC */).setMultipleInstances(true));
1115
+ _registerComponent(new Component(RC_COMPONENT_NAME, remoteConfigFactory, "PUBLIC" /* ComponentType.PUBLIC */).setMultipleInstances(true));
1122
1116
  registerVersion(name, version);
1123
1117
  // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
1124
1118
  registerVersion(name, version, 'esm2017');
@@ -1132,22 +1126,22 @@ function registerRemoteConfig() {
1132
1126
  .getImmediate();
1133
1127
  // Guards against the SDK being used in non-browser environments.
1134
1128
  if (typeof window === 'undefined') {
1135
- throw ERROR_FACTORY.create("registration-window" /* REGISTRATION_WINDOW */);
1129
+ throw ERROR_FACTORY.create("registration-window" /* ErrorCode.REGISTRATION_WINDOW */);
1136
1130
  }
1137
1131
  // Guards against the SDK being used when indexedDB is not available.
1138
1132
  if (!isIndexedDBAvailable()) {
1139
- throw ERROR_FACTORY.create("indexed-db-unavailable" /* INDEXED_DB_UNAVAILABLE */);
1133
+ throw ERROR_FACTORY.create("indexed-db-unavailable" /* ErrorCode.INDEXED_DB_UNAVAILABLE */);
1140
1134
  }
1141
1135
  // Normalizes optional inputs.
1142
1136
  const { projectId, apiKey, appId } = app.options;
1143
1137
  if (!projectId) {
1144
- throw ERROR_FACTORY.create("registration-project-id" /* REGISTRATION_PROJECT_ID */);
1138
+ throw ERROR_FACTORY.create("registration-project-id" /* ErrorCode.REGISTRATION_PROJECT_ID */);
1145
1139
  }
1146
1140
  if (!apiKey) {
1147
- throw ERROR_FACTORY.create("registration-api-key" /* REGISTRATION_API_KEY */);
1141
+ throw ERROR_FACTORY.create("registration-api-key" /* ErrorCode.REGISTRATION_API_KEY */);
1148
1142
  }
1149
1143
  if (!appId) {
1150
- throw ERROR_FACTORY.create("registration-app-id" /* REGISTRATION_APP_ID */);
1144
+ throw ERROR_FACTORY.create("registration-app-id" /* ErrorCode.REGISTRATION_APP_ID */);
1151
1145
  }
1152
1146
  namespace = namespace || 'firebase';
1153
1147
  const storage = new Storage(appId, app.name, namespace);