@firebase/app-check 0.12.0 → 0.13.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.
@@ -51,7 +51,7 @@ export interface AppCheckOptions {
51
51
  /**
52
52
  * A reCAPTCHA V3 provider, reCAPTCHA Enterprise provider, or custom provider.
53
53
  */
54
- provider?: CustomProvider | ReCaptchaV3Provider | ReCaptchaEnterpriseProvider;
54
+ provider: CustomProvider | ReCaptchaV3Provider | ReCaptchaEnterpriseProvider;
55
55
  /**
56
56
  * If set to true, enables automatic background refresh of App Check token.
57
57
  */
@@ -29,7 +29,6 @@ export interface AppCheckState {
29
29
  tokenRefresher?: Refresher;
30
30
  reCAPTCHAState?: ReCAPTCHAState;
31
31
  isTokenAutoRefreshEnabled?: boolean;
32
- internallyInitializedBy?: string;
33
32
  }
34
33
  export interface ReCAPTCHAState {
35
34
  initialized: Deferred<GreCAPTCHA>;
package/dist/index.cjs.js CHANGED
@@ -71,11 +71,6 @@ const EXCHANGE_RECAPTCHA_TOKEN_METHOD = 'exchangeRecaptchaV3Token';
71
71
  const EXCHANGE_RECAPTCHA_ENTERPRISE_TOKEN_METHOD = 'exchangeRecaptchaEnterpriseToken';
72
72
  const EXCHANGE_DEBUG_TOKEN_METHOD = 'exchangeDebugToken';
73
73
  const TOKEN_REFRESH_TIME = {
74
- /**
75
- * The offset time before token natural expiration to run the refresh.
76
- * This is currently 5 minutes.
77
- */
78
- OFFSET_DURATION: 5 * 60 * 1000,
79
74
  /**
80
75
  * This is the first retrial wait after an error. This is currently
81
76
  * 30 seconds.
@@ -226,9 +221,6 @@ const ERRORS = {
226
221
  'different options. To avoid this error, call initializeAppCheck() with the ' +
227
222
  'same options as when it was originally called. This will return the ' +
228
223
  'already initialized instance.',
229
- ["already-internally-initialized" /* AppCheckError.ALREADY_INTERNALLY_INITIALIZED */]: 'App Check has already been automatically initialized by {$initializerName} ' +
230
- 'with default options. If you want to initialize App Check with custom options, ' +
231
- 'call initializeAppCheck() with those options before initializing {$initializerName}.',
232
224
  ["use-before-activation" /* AppCheckError.USE_BEFORE_ACTIVATION */]: 'App Check is being used before initializeAppCheck() is called for FirebaseApp {$appName}. ' +
233
225
  'Call initializeAppCheck() before instantiating other Firebase services.',
234
226
  ["fetch-network-error" /* AppCheckError.FETCH_NETWORK_ERROR */]: 'Fetch failed to connect to a network. Check Internet connection. ' +
@@ -240,8 +232,6 @@ const ERRORS = {
240
232
  ["storage-get" /* AppCheckError.STORAGE_GET */]: 'Error thrown when reading from storage. Original error: {$originalErrorMessage}.',
241
233
  ["storage-set" /* AppCheckError.STORAGE_WRITE */]: 'Error thrown when writing to storage. Original error: {$originalErrorMessage}.',
242
234
  ["recaptcha-error" /* AppCheckError.RECAPTCHA_ERROR */]: 'ReCAPTCHA error.',
243
- ["no-provider" /* AppCheckError.NO_PROVIDER */]: 'No attestation provider was passed to initializeAppCheck() and ' +
244
- 'no ReCAPTCHA Enterprise site key was found in the Firebase config.',
245
235
  ["initial-throttle" /* AppCheckError.INITIAL_THROTTLE */]: `{$httpStatus} error. Attempts allowed again after {$time}`,
246
236
  ["throttled" /* AppCheckError.THROTTLED */]: `Requests throttled due to previous {$httpStatus} error. Attempts allowed again after {$time}`
247
237
  };
@@ -1062,7 +1052,7 @@ function internalFactory(appCheck) {
1062
1052
  }
1063
1053
 
1064
1054
  const name = "@firebase/app-check";
1065
- const version = "0.12.0";
1055
+ const version = "0.13.0";
1066
1056
 
1067
1057
  /**
1068
1058
  * @license
@@ -1501,6 +1491,7 @@ function throwIfThrottled(throttleData) {
1501
1491
  */
1502
1492
  function initializeAppCheck(app$1 = app.getApp(), options) {
1503
1493
  app$1 = util.getModularInstance(app$1);
1494
+ const provider = app._getProvider(app$1, 'app-check');
1504
1495
  // Ensure initializeDebugMode() is only called once.
1505
1496
  if (!getDebugState().initialized) {
1506
1497
  initializeDebugMode();
@@ -1513,53 +1504,23 @@ function initializeAppCheck(app$1 = app.getApp(), options) {
1513
1504
  // Not using logger because I don't think we ever want this accidentally hidden.
1514
1505
  console.log(`App Check debug token: ${token}. You will need to add it to your app's App Check settings in the Firebase console for it to work.`));
1515
1506
  }
1516
- let defaultProvider;
1517
- /**
1518
- * If user did not pass a provider, look for site key in project
1519
- * config and create a default ReCaptchaEnterpriseProvider with it.
1520
- */
1521
- if (!options?.provider && app$1.options.recaptchaSiteKey) {
1522
- defaultProvider = new ReCaptchaEnterpriseProvider(app$1.options.recaptchaSiteKey);
1523
- }
1524
- /**
1525
- * If there's no passed provider and no siteKey in project config,
1526
- * throw.
1527
- */
1528
- if (!options?.provider && !defaultProvider) {
1529
- throw ERROR_FACTORY.create("no-provider" /* AppCheckError.NO_PROVIDER */);
1530
- }
1531
- const initOptions = {
1532
- ...options,
1533
- provider: options?.provider || defaultProvider
1534
- };
1535
- const componentProvider = app._getProvider(app$1, 'app-check');
1536
- if (componentProvider.isInitialized()) {
1537
- const existingInstance = componentProvider.getImmediate();
1538
- const existingOptions = componentProvider.getOptions();
1539
- /**
1540
- * Check if all AppCheckOptions previously passed to initializeAppCheck
1541
- * (`isTokenAutoRefreshEnabled` and `provider`) match those being passed
1542
- * now. If so, return previous existing instance. Otherwise throw error.
1543
- */
1544
- if (existingOptions.isTokenAutoRefreshEnabled ===
1545
- initOptions.isTokenAutoRefreshEnabled &&
1546
- existingOptions.provider?.isEqual(initOptions.provider)) {
1507
+ if (provider.isInitialized()) {
1508
+ const existingInstance = provider.getImmediate();
1509
+ const initialOptions = provider.getOptions();
1510
+ if (initialOptions &&
1511
+ !!initialOptions.isTokenAutoRefreshEnabled ===
1512
+ !!options.isTokenAutoRefreshEnabled &&
1513
+ initialOptions.provider?.isEqual(options.provider)) {
1547
1514
  return existingInstance;
1548
1515
  }
1549
1516
  else {
1550
- if (typeof getStateReference(app$1).internallyInitializedBy === 'string') {
1551
- throw ERROR_FACTORY.create("already-internally-initialized" /* AppCheckError.ALREADY_INTERNALLY_INITIALIZED */, {
1552
- initializerName: getStateReference(app$1)
1553
- .internallyInitializedBy
1554
- });
1555
- }
1556
1517
  throw ERROR_FACTORY.create("already-initialized" /* AppCheckError.ALREADY_INITIALIZED */, {
1557
1518
  appName: app$1.name
1558
1519
  });
1559
1520
  }
1560
1521
  }
1561
- const appCheck = componentProvider.initialize({ options: initOptions });
1562
- _activate(app$1, initOptions.provider, initOptions.isTokenAutoRefreshEnabled);
1522
+ const appCheck = provider.initialize({ options });
1523
+ _activate(app$1, options.provider, options.isTokenAutoRefreshEnabled);
1563
1524
  // If isTokenAutoRefreshEnabled is false, do not send any requests to the
1564
1525
  // exchange endpoint without an explicit call from the user either directly
1565
1526
  // or through another Firebase library (storage, functions, etc.)
@@ -1573,29 +1534,6 @@ function initializeAppCheck(app$1 = app.getApp(), options) {
1573
1534
  }
1574
1535
  return appCheck;
1575
1536
  }
1576
- /**
1577
- * Internal wrapper that sets a state variable flagging that this was
1578
- * initialized under the hood by a product SDK.
1579
- *
1580
- * @internal
1581
- */
1582
- function _initializeAppCheckInternal(
1583
- // String to be used in error message if there is a future conflict.
1584
- // Example: "Firebase AI Logic"
1585
- initializerName, app$1 = app.getApp(), options) {
1586
- const componentProvider = app._getProvider(app$1, 'app-check');
1587
- const previouslyInitialized = componentProvider.isInitialized();
1588
- if (previouslyInitialized) {
1589
- // Product SDKs should accept any previously initialized
1590
- // App Check configuration without error.
1591
- return componentProvider.getImmediate();
1592
- }
1593
- else {
1594
- const appCheck = initializeAppCheck(app$1, options);
1595
- getStateReference(app$1).internallyInitializedBy = initializerName;
1596
- return appCheck;
1597
- }
1598
- }
1599
1537
  /**
1600
1538
  * Activate App Check
1601
1539
  * @param app - Firebase app to activate App Check for.
@@ -1736,6 +1674,22 @@ onCompletion) {
1736
1674
  *
1737
1675
  * @packageDocumentation
1738
1676
  */
1677
+ /**
1678
+ * @license
1679
+ * Copyright 2021 Google LLC
1680
+ *
1681
+ * Licensed under the Apache License, Version 2.0 (the "License");
1682
+ * you may not use this file except in compliance with the License.
1683
+ * You may obtain a copy of the License at
1684
+ *
1685
+ * http://www.apache.org/licenses/LICENSE-2.0
1686
+ *
1687
+ * Unless required by applicable law or agreed to in writing, software
1688
+ * distributed under the License is distributed on an "AS IS" BASIS,
1689
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1690
+ * See the License for the specific language governing permissions and
1691
+ * limitations under the License.
1692
+ */
1739
1693
  const APP_CHECK_NAME = 'app-check';
1740
1694
  const APP_CHECK_NAME_INTERNAL = 'app-check-internal';
1741
1695
  function registerAppCheck() {
@@ -1766,7 +1720,6 @@ registerAppCheck();
1766
1720
  exports.CustomProvider = CustomProvider;
1767
1721
  exports.ReCaptchaEnterpriseProvider = ReCaptchaEnterpriseProvider;
1768
1722
  exports.ReCaptchaV3Provider = ReCaptchaV3Provider;
1769
- exports._initializeAppCheckInternal = _initializeAppCheckInternal;
1770
1723
  exports.getLimitedUseToken = getLimitedUseToken;
1771
1724
  exports.getToken = getToken;
1772
1725
  exports.initializeAppCheck = initializeAppCheck;