@firebase/app-check 0.5.17 → 0.6.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.
@@ -212,22 +212,22 @@ function sleep(ms) {
212
212
  * limitations under the License.
213
213
  */
214
214
  const ERRORS = {
215
- ["already-initialized" /* ALREADY_INITIALIZED */]: 'You have already called initializeAppCheck() for FirebaseApp {$appName} with ' +
215
+ ["already-initialized" /* AppCheckError.ALREADY_INITIALIZED */]: 'You have already called initializeAppCheck() for FirebaseApp {$appName} with ' +
216
216
  'different options. To avoid this error, call initializeAppCheck() with the ' +
217
217
  'same options as when it was originally called. This will return the ' +
218
218
  'already initialized instance.',
219
- ["use-before-activation" /* USE_BEFORE_ACTIVATION */]: 'App Check is being used before initializeAppCheck() is called for FirebaseApp {$appName}. ' +
219
+ ["use-before-activation" /* AppCheckError.USE_BEFORE_ACTIVATION */]: 'App Check is being used before initializeAppCheck() is called for FirebaseApp {$appName}. ' +
220
220
  'Call initializeAppCheck() before instantiating other Firebase services.',
221
- ["fetch-network-error" /* FETCH_NETWORK_ERROR */]: 'Fetch failed to connect to a network. Check Internet connection. ' +
221
+ ["fetch-network-error" /* AppCheckError.FETCH_NETWORK_ERROR */]: 'Fetch failed to connect to a network. Check Internet connection. ' +
222
222
  'Original error: {$originalErrorMessage}.',
223
- ["fetch-parse-error" /* FETCH_PARSE_ERROR */]: 'Fetch client could not parse response.' +
223
+ ["fetch-parse-error" /* AppCheckError.FETCH_PARSE_ERROR */]: 'Fetch client could not parse response.' +
224
224
  ' Original error: {$originalErrorMessage}.',
225
- ["fetch-status-error" /* FETCH_STATUS_ERROR */]: 'Fetch server returned an HTTP error status. HTTP status: {$httpStatus}.',
226
- ["storage-open" /* STORAGE_OPEN */]: 'Error thrown when opening storage. Original error: {$originalErrorMessage}.',
227
- ["storage-get" /* STORAGE_GET */]: 'Error thrown when reading from storage. Original error: {$originalErrorMessage}.',
228
- ["storage-set" /* STORAGE_WRITE */]: 'Error thrown when writing to storage. Original error: {$originalErrorMessage}.',
229
- ["recaptcha-error" /* RECAPTCHA_ERROR */]: 'ReCAPTCHA error.',
230
- ["throttled" /* THROTTLED */]: `Requests throttled due to {$httpStatus} error. Attempts allowed again after {$time}`
225
+ ["fetch-status-error" /* AppCheckError.FETCH_STATUS_ERROR */]: 'Fetch server returned an HTTP error status. HTTP status: {$httpStatus}.',
226
+ ["storage-open" /* AppCheckError.STORAGE_OPEN */]: 'Error thrown when opening storage. Original error: {$originalErrorMessage}.',
227
+ ["storage-get" /* AppCheckError.STORAGE_GET */]: 'Error thrown when reading from storage. Original error: {$originalErrorMessage}.',
228
+ ["storage-set" /* AppCheckError.STORAGE_WRITE */]: 'Error thrown when writing to storage. Original error: {$originalErrorMessage}.',
229
+ ["recaptcha-error" /* AppCheckError.RECAPTCHA_ERROR */]: 'ReCAPTCHA error.',
230
+ ["throttled" /* AppCheckError.THROTTLED */]: `Requests throttled due to {$httpStatus} error. Attempts allowed again after {$time}`
231
231
  };
232
232
  const ERROR_FACTORY = new ErrorFactory('appCheck', 'AppCheck', ERRORS);
233
233
 
@@ -256,7 +256,7 @@ function getRecaptcha(isEnterprise = false) {
256
256
  }
257
257
  function ensureActivated(app) {
258
258
  if (!getStateReference(app).activated) {
259
- throw ERROR_FACTORY.create("use-before-activation" /* USE_BEFORE_ACTIVATION */, {
259
+ throw ERROR_FACTORY.create("use-before-activation" /* AppCheckError.USE_BEFORE_ACTIVATION */, {
260
260
  appName: app.name
261
261
  });
262
262
  }
@@ -301,7 +301,6 @@ function pad(value) {
301
301
  * limitations under the License.
302
302
  */
303
303
  async function exchangeToken({ url, body }, heartbeatServiceProvider) {
304
- var _a, _b;
305
304
  const headers = {
306
305
  'Content-Type': 'application/json'
307
306
  };
@@ -325,12 +324,12 @@ async function exchangeToken({ url, body }, heartbeatServiceProvider) {
325
324
  response = await fetch(url, options);
326
325
  }
327
326
  catch (originalError) {
328
- throw ERROR_FACTORY.create("fetch-network-error" /* FETCH_NETWORK_ERROR */, {
329
- originalErrorMessage: (_a = originalError) === null || _a === void 0 ? void 0 : _a.message
327
+ throw ERROR_FACTORY.create("fetch-network-error" /* AppCheckError.FETCH_NETWORK_ERROR */, {
328
+ originalErrorMessage: originalError === null || originalError === void 0 ? void 0 : originalError.message
330
329
  });
331
330
  }
332
331
  if (response.status !== 200) {
333
- throw ERROR_FACTORY.create("fetch-status-error" /* FETCH_STATUS_ERROR */, {
332
+ throw ERROR_FACTORY.create("fetch-status-error" /* AppCheckError.FETCH_STATUS_ERROR */, {
334
333
  httpStatus: response.status
335
334
  });
336
335
  }
@@ -340,15 +339,15 @@ async function exchangeToken({ url, body }, heartbeatServiceProvider) {
340
339
  responseBody = await response.json();
341
340
  }
342
341
  catch (originalError) {
343
- throw ERROR_FACTORY.create("fetch-parse-error" /* FETCH_PARSE_ERROR */, {
344
- originalErrorMessage: (_b = originalError) === null || _b === void 0 ? void 0 : _b.message
342
+ throw ERROR_FACTORY.create("fetch-parse-error" /* AppCheckError.FETCH_PARSE_ERROR */, {
343
+ originalErrorMessage: originalError === null || originalError === void 0 ? void 0 : originalError.message
345
344
  });
346
345
  }
347
346
  // Protobuf duration format.
348
347
  // https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/Duration
349
348
  const match = responseBody.ttl.match(/^([\d.]+)(s)$/);
350
349
  if (!match || !match[2] || isNaN(Number(match[1]))) {
351
- throw ERROR_FACTORY.create("fetch-parse-error" /* FETCH_PARSE_ERROR */, {
350
+ throw ERROR_FACTORY.create("fetch-parse-error" /* AppCheckError.FETCH_PARSE_ERROR */, {
352
351
  originalErrorMessage: `ttl field (timeToLive) is not in standard Protobuf Duration ` +
353
352
  `format: ${responseBody.ttl}`
354
353
  });
@@ -416,7 +415,6 @@ function getDBPromise() {
416
415
  return dbPromise;
417
416
  }
418
417
  dbPromise = new Promise((resolve, reject) => {
419
- var _a;
420
418
  try {
421
419
  const request = indexedDB.open(DB_NAME, DB_VERSION);
422
420
  request.onsuccess = event => {
@@ -424,7 +422,7 @@ function getDBPromise() {
424
422
  };
425
423
  request.onerror = event => {
426
424
  var _a;
427
- reject(ERROR_FACTORY.create("storage-open" /* STORAGE_OPEN */, {
425
+ reject(ERROR_FACTORY.create("storage-open" /* AppCheckError.STORAGE_OPEN */, {
428
426
  originalErrorMessage: (_a = event.target.error) === null || _a === void 0 ? void 0 : _a.message
429
427
  }));
430
428
  };
@@ -444,8 +442,8 @@ function getDBPromise() {
444
442
  };
445
443
  }
446
444
  catch (e) {
447
- reject(ERROR_FACTORY.create("storage-open" /* STORAGE_OPEN */, {
448
- originalErrorMessage: (_a = e) === null || _a === void 0 ? void 0 : _a.message
445
+ reject(ERROR_FACTORY.create("storage-open" /* AppCheckError.STORAGE_OPEN */, {
446
+ originalErrorMessage: e === null || e === void 0 ? void 0 : e.message
449
447
  }));
450
448
  }
451
449
  });
@@ -477,7 +475,7 @@ async function write(key, value) {
477
475
  };
478
476
  transaction.onerror = event => {
479
477
  var _a;
480
- reject(ERROR_FACTORY.create("storage-set" /* STORAGE_WRITE */, {
478
+ reject(ERROR_FACTORY.create("storage-set" /* AppCheckError.STORAGE_WRITE */, {
481
479
  originalErrorMessage: (_a = event.target.error) === null || _a === void 0 ? void 0 : _a.message
482
480
  }));
483
481
  };
@@ -500,7 +498,7 @@ async function read(key) {
500
498
  };
501
499
  transaction.onerror = event => {
502
500
  var _a;
503
- reject(ERROR_FACTORY.create("storage-get" /* STORAGE_GET */, {
501
+ reject(ERROR_FACTORY.create("storage-get" /* AppCheckError.STORAGE_GET */, {
504
502
  originalErrorMessage: (_a = event.target.error) === null || _a === void 0 ? void 0 : _a.message
505
503
  }));
506
504
  };
@@ -771,7 +769,7 @@ async function getToken$2(appCheck, forceRefresh = false) {
771
769
  token = await getStateReference(app).exchangeTokenPromise;
772
770
  }
773
771
  catch (e) {
774
- if (e.code === `appCheck/${"throttled" /* THROTTLED */}`) {
772
+ if (e.code === `appCheck/${"throttled" /* AppCheckError.THROTTLED */}`) {
775
773
  // Warn if throttled, but do not treat it as an error.
776
774
  logger.warn(e.message);
777
775
  }
@@ -941,7 +939,7 @@ function notifyTokenListeners(app, token) {
941
939
  const observers = getStateReference(app).tokenObservers;
942
940
  for (const observer of observers) {
943
941
  try {
944
- if (observer.type === "EXTERNAL" /* EXTERNAL */ && token.error != null) {
942
+ if (observer.type === "EXTERNAL" /* ListenerType.EXTERNAL */ && token.error != null) {
945
943
  // If this listener was added by a 3P call, send any token error to
946
944
  // the supplied error handler. A 3P observer always has an error
947
945
  // handler.
@@ -1007,13 +1005,13 @@ function factory(app, heartbeatServiceProvider) {
1007
1005
  function internalFactory(appCheck) {
1008
1006
  return {
1009
1007
  getToken: forceRefresh => getToken$2(appCheck, forceRefresh),
1010
- addTokenListener: listener => addTokenListener(appCheck, "INTERNAL" /* INTERNAL */, listener),
1008
+ addTokenListener: listener => addTokenListener(appCheck, "INTERNAL" /* ListenerType.INTERNAL */, listener),
1011
1009
  removeTokenListener: listener => removeTokenListener(appCheck.app, listener)
1012
1010
  };
1013
1011
  }
1014
1012
 
1015
1013
  const name = "@firebase/app-check";
1016
- const version = "0.5.17";
1014
+ const version = "0.6.0";
1017
1015
 
1018
1016
  /**
1019
1017
  * @license
@@ -1188,16 +1186,16 @@ class ReCaptchaV3Provider {
1188
1186
  // and therefore this._app and this._heartbeatServiceProvider are available.
1189
1187
  const attestedClaimsToken = await getToken$1(this._app).catch(_e => {
1190
1188
  // reCaptcha.execute() throws null which is not very descriptive.
1191
- throw ERROR_FACTORY.create("recaptcha-error" /* RECAPTCHA_ERROR */);
1189
+ throw ERROR_FACTORY.create("recaptcha-error" /* AppCheckError.RECAPTCHA_ERROR */);
1192
1190
  });
1193
1191
  let result;
1194
1192
  try {
1195
1193
  result = await exchangeToken(getExchangeRecaptchaV3TokenRequest(this._app, attestedClaimsToken), this._heartbeatServiceProvider);
1196
1194
  }
1197
1195
  catch (e) {
1198
- if ((_a = e.code) === null || _a === void 0 ? void 0 : _a.includes("fetch-status-error" /* FETCH_STATUS_ERROR */)) {
1196
+ if ((_a = e.code) === null || _a === void 0 ? void 0 : _a.includes("fetch-status-error" /* AppCheckError.FETCH_STATUS_ERROR */)) {
1199
1197
  this._throttleData = setBackoff(Number((_b = e.customData) === null || _b === void 0 ? void 0 : _b.httpStatus), this._throttleData);
1200
- throw ERROR_FACTORY.create("throttled" /* THROTTLED */, {
1198
+ throw ERROR_FACTORY.create("throttled" /* AppCheckError.THROTTLED */, {
1201
1199
  time: getDurationString(this._throttleData.allowRequestsAfter - Date.now()),
1202
1200
  httpStatus: this._throttleData.httpStatus
1203
1201
  });
@@ -1262,16 +1260,16 @@ class ReCaptchaEnterpriseProvider {
1262
1260
  // and therefore this._app and this._heartbeatServiceProvider are available.
1263
1261
  const attestedClaimsToken = await getToken$1(this._app).catch(_e => {
1264
1262
  // reCaptcha.execute() throws null which is not very descriptive.
1265
- throw ERROR_FACTORY.create("recaptcha-error" /* RECAPTCHA_ERROR */);
1263
+ throw ERROR_FACTORY.create("recaptcha-error" /* AppCheckError.RECAPTCHA_ERROR */);
1266
1264
  });
1267
1265
  let result;
1268
1266
  try {
1269
1267
  result = await exchangeToken(getExchangeRecaptchaEnterpriseTokenRequest(this._app, attestedClaimsToken), this._heartbeatServiceProvider);
1270
1268
  }
1271
1269
  catch (e) {
1272
- if ((_a = e.code) === null || _a === void 0 ? void 0 : _a.includes("fetch-status-error" /* FETCH_STATUS_ERROR */)) {
1270
+ if ((_a = e.code) === null || _a === void 0 ? void 0 : _a.includes("fetch-status-error" /* AppCheckError.FETCH_STATUS_ERROR */)) {
1273
1271
  this._throttleData = setBackoff(Number((_b = e.customData) === null || _b === void 0 ? void 0 : _b.httpStatus), this._throttleData);
1274
- throw ERROR_FACTORY.create("throttled" /* THROTTLED */, {
1272
+ throw ERROR_FACTORY.create("throttled" /* AppCheckError.THROTTLED */, {
1275
1273
  time: getDurationString(this._throttleData.allowRequestsAfter - Date.now()),
1276
1274
  httpStatus: this._throttleData.httpStatus
1277
1275
  });
@@ -1395,7 +1393,7 @@ function throwIfThrottled(throttleData) {
1395
1393
  if (throttleData) {
1396
1394
  if (Date.now() - throttleData.allowRequestsAfter <= 0) {
1397
1395
  // If before, throw.
1398
- throw ERROR_FACTORY.create("throttled" /* THROTTLED */, {
1396
+ throw ERROR_FACTORY.create("throttled" /* AppCheckError.THROTTLED */, {
1399
1397
  time: getDurationString(throttleData.allowRequestsAfter - Date.now()),
1400
1398
  httpStatus: throttleData.httpStatus
1401
1399
  });
@@ -1449,7 +1447,7 @@ function initializeAppCheck(app = getApp(), options) {
1449
1447
  return existingInstance;
1450
1448
  }
1451
1449
  else {
1452
- throw ERROR_FACTORY.create("already-initialized" /* ALREADY_INITIALIZED */, {
1450
+ throw ERROR_FACTORY.create("already-initialized" /* AppCheckError.ALREADY_INITIALIZED */, {
1453
1451
  appName: app.name
1454
1452
  });
1455
1453
  }
@@ -1465,7 +1463,7 @@ function initializeAppCheck(app = getApp(), options) {
1465
1463
  // requests the token.
1466
1464
  // Listener function does not need to do anything, its base functionality
1467
1465
  // of calling getToken() already fetches token and writes it to memory/storage.
1468
- addTokenListener(appCheck, "INTERNAL" /* INTERNAL */, () => { });
1466
+ addTokenListener(appCheck, "INTERNAL" /* ListenerType.INTERNAL */, () => { });
1469
1467
  }
1470
1468
  return appCheck;
1471
1469
  }
@@ -1570,7 +1568,7 @@ onCompletion) {
1570
1568
  else if (onError) {
1571
1569
  errorFn = onError;
1572
1570
  }
1573
- addTokenListener(appCheckInstance, "EXTERNAL" /* EXTERNAL */, nextFn, errorFn);
1571
+ addTokenListener(appCheckInstance, "EXTERNAL" /* ListenerType.EXTERNAL */, nextFn, errorFn);
1574
1572
  return () => removeTokenListener(appCheckInstance.app, nextFn);
1575
1573
  }
1576
1574
 
@@ -1588,8 +1586,8 @@ function registerAppCheck() {
1588
1586
  const app = container.getProvider('app').getImmediate();
1589
1587
  const heartbeatServiceProvider = container.getProvider('heartbeat');
1590
1588
  return factory(app, heartbeatServiceProvider);
1591
- }, "PUBLIC" /* PUBLIC */)
1592
- .setInstantiationMode("EXPLICIT" /* EXPLICIT */)
1589
+ }, "PUBLIC" /* ComponentType.PUBLIC */)
1590
+ .setInstantiationMode("EXPLICIT" /* InstantiationMode.EXPLICIT */)
1593
1591
  /**
1594
1592
  * Initialize app-check-internal after app-check is initialized to make AppCheck available to
1595
1593
  * other Firebase SDKs
@@ -1601,7 +1599,7 @@ function registerAppCheck() {
1601
1599
  _registerComponent(new Component(APP_CHECK_NAME_INTERNAL, container => {
1602
1600
  const appCheck = container.getProvider('app-check').getImmediate();
1603
1601
  return internalFactory(appCheck);
1604
- }, "PUBLIC" /* PUBLIC */).setInstantiationMode("EXPLICIT" /* EXPLICIT */));
1602
+ }, "PUBLIC" /* ComponentType.PUBLIC */).setInstantiationMode("EXPLICIT" /* InstantiationMode.EXPLICIT */));
1605
1603
  registerVersion(name, version);
1606
1604
  }
1607
1605
  registerAppCheck();