@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.
- package/dist/app-check-public.d.ts +2 -4
- package/dist/app-check.d.ts +2 -10
- package/dist/esm/index.esm.js +28 -74
- package/dist/esm/index.esm.js.map +1 -1
- package/dist/esm/src/api.d.ts +1 -8
- package/dist/esm/src/errors.d.ts +0 -5
- package/dist/esm/src/public-types.d.ts +1 -1
- package/dist/esm/src/state.d.ts +0 -1
- package/dist/index.cjs.js +27 -74
- package/dist/index.cjs.js.map +1 -1
- package/dist/src/api.d.ts +1 -8
- package/dist/src/errors.d.ts +0 -5
- package/dist/src/public-types.d.ts +1 -1
- package/dist/src/state.d.ts +0 -1
- package/package.json +8 -8
|
@@ -37,7 +37,7 @@ export declare interface AppCheckOptions {
|
|
|
37
37
|
/**
|
|
38
38
|
* A reCAPTCHA V3 provider, reCAPTCHA Enterprise provider, or custom provider.
|
|
39
39
|
*/
|
|
40
|
-
provider
|
|
40
|
+
provider: CustomProvider | ReCaptchaV3Provider | ReCaptchaEnterpriseProvider;
|
|
41
41
|
/**
|
|
42
42
|
* If set to true, enables automatic background refresh of App Check token.
|
|
43
43
|
*/
|
|
@@ -144,9 +144,7 @@ export declare function getToken(appCheckInstance: AppCheck, forceRefresh?: bool
|
|
|
144
144
|
* @param options - App Check initialization options
|
|
145
145
|
* @public
|
|
146
146
|
*/
|
|
147
|
-
export declare function initializeAppCheck(app
|
|
148
|
-
|
|
149
|
-
/* Excluded from this release type: _initializeAppCheckInternal */
|
|
147
|
+
export declare function initializeAppCheck(app: FirebaseApp | undefined, options: AppCheckOptions): AppCheck;
|
|
150
148
|
|
|
151
149
|
/**
|
|
152
150
|
* Registers a listener to changes in the token state. There can be more
|
package/dist/app-check.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export declare interface AppCheckOptions {
|
|
|
43
43
|
/**
|
|
44
44
|
* A reCAPTCHA V3 provider, reCAPTCHA Enterprise provider, or custom provider.
|
|
45
45
|
*/
|
|
46
|
-
provider
|
|
46
|
+
provider: CustomProvider | ReCaptchaV3Provider | ReCaptchaEnterpriseProvider;
|
|
47
47
|
/**
|
|
48
48
|
* If set to true, enables automatic background refresh of App Check token.
|
|
49
49
|
*/
|
|
@@ -166,15 +166,7 @@ export declare function getToken(appCheckInstance: AppCheck, forceRefresh?: bool
|
|
|
166
166
|
* @param options - App Check initialization options
|
|
167
167
|
* @public
|
|
168
168
|
*/
|
|
169
|
-
export declare function initializeAppCheck(app
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Internal wrapper that sets a state variable flagging that this was
|
|
173
|
-
* initialized under the hood by a product SDK.
|
|
174
|
-
*
|
|
175
|
-
* @internal
|
|
176
|
-
*/
|
|
177
|
-
export declare function _initializeAppCheckInternal(initializerName: string, app?: FirebaseApp, options?: AppCheckOptions): AppCheck;
|
|
169
|
+
export declare function initializeAppCheck(app: FirebaseApp | undefined, options: AppCheckOptions): AppCheck;
|
|
178
170
|
|
|
179
171
|
/**
|
|
180
172
|
* Registers a listener to changes in the token state. There can be more
|
package/dist/esm/index.esm.js
CHANGED
|
@@ -67,11 +67,6 @@ const EXCHANGE_RECAPTCHA_TOKEN_METHOD = 'exchangeRecaptchaV3Token';
|
|
|
67
67
|
const EXCHANGE_RECAPTCHA_ENTERPRISE_TOKEN_METHOD = 'exchangeRecaptchaEnterpriseToken';
|
|
68
68
|
const EXCHANGE_DEBUG_TOKEN_METHOD = 'exchangeDebugToken';
|
|
69
69
|
const TOKEN_REFRESH_TIME = {
|
|
70
|
-
/**
|
|
71
|
-
* The offset time before token natural expiration to run the refresh.
|
|
72
|
-
* This is currently 5 minutes.
|
|
73
|
-
*/
|
|
74
|
-
OFFSET_DURATION: 5 * 60 * 1000,
|
|
75
70
|
/**
|
|
76
71
|
* This is the first retrial wait after an error. This is currently
|
|
77
72
|
* 30 seconds.
|
|
@@ -222,9 +217,6 @@ const ERRORS = {
|
|
|
222
217
|
'different options. To avoid this error, call initializeAppCheck() with the ' +
|
|
223
218
|
'same options as when it was originally called. This will return the ' +
|
|
224
219
|
'already initialized instance.',
|
|
225
|
-
["already-internally-initialized" /* AppCheckError.ALREADY_INTERNALLY_INITIALIZED */]: 'App Check has already been automatically initialized by {$initializerName} ' +
|
|
226
|
-
'with default options. If you want to initialize App Check with custom options, ' +
|
|
227
|
-
'call initializeAppCheck() with those options before initializing {$initializerName}.',
|
|
228
220
|
["use-before-activation" /* AppCheckError.USE_BEFORE_ACTIVATION */]: 'App Check is being used before initializeAppCheck() is called for FirebaseApp {$appName}. ' +
|
|
229
221
|
'Call initializeAppCheck() before instantiating other Firebase services.',
|
|
230
222
|
["fetch-network-error" /* AppCheckError.FETCH_NETWORK_ERROR */]: 'Fetch failed to connect to a network. Check Internet connection. ' +
|
|
@@ -236,8 +228,6 @@ const ERRORS = {
|
|
|
236
228
|
["storage-get" /* AppCheckError.STORAGE_GET */]: 'Error thrown when reading from storage. Original error: {$originalErrorMessage}.',
|
|
237
229
|
["storage-set" /* AppCheckError.STORAGE_WRITE */]: 'Error thrown when writing to storage. Original error: {$originalErrorMessage}.',
|
|
238
230
|
["recaptcha-error" /* AppCheckError.RECAPTCHA_ERROR */]: 'ReCAPTCHA error.',
|
|
239
|
-
["no-provider" /* AppCheckError.NO_PROVIDER */]: 'No attestation provider was passed to initializeAppCheck() and ' +
|
|
240
|
-
'no ReCAPTCHA Enterprise site key was found in the Firebase config.',
|
|
241
231
|
["initial-throttle" /* AppCheckError.INITIAL_THROTTLE */]: `{$httpStatus} error. Attempts allowed again after {$time}`,
|
|
242
232
|
["throttled" /* AppCheckError.THROTTLED */]: `Requests throttled due to previous {$httpStatus} error. Attempts allowed again after {$time}`
|
|
243
233
|
};
|
|
@@ -1058,7 +1048,7 @@ function internalFactory(appCheck) {
|
|
|
1058
1048
|
}
|
|
1059
1049
|
|
|
1060
1050
|
const name = "@firebase/app-check";
|
|
1061
|
-
const version = "0.
|
|
1051
|
+
const version = "0.13.0";
|
|
1062
1052
|
|
|
1063
1053
|
/**
|
|
1064
1054
|
* @license
|
|
@@ -1497,6 +1487,7 @@ function throwIfThrottled(throttleData) {
|
|
|
1497
1487
|
*/
|
|
1498
1488
|
function initializeAppCheck(app = getApp(), options) {
|
|
1499
1489
|
app = getModularInstance(app);
|
|
1490
|
+
const provider = _getProvider(app, 'app-check');
|
|
1500
1491
|
// Ensure initializeDebugMode() is only called once.
|
|
1501
1492
|
if (!getDebugState().initialized) {
|
|
1502
1493
|
initializeDebugMode();
|
|
@@ -1509,53 +1500,23 @@ function initializeAppCheck(app = getApp(), options) {
|
|
|
1509
1500
|
// Not using logger because I don't think we ever want this accidentally hidden.
|
|
1510
1501
|
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.`));
|
|
1511
1502
|
}
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
}
|
|
1520
|
-
/**
|
|
1521
|
-
* If there's no passed provider and no siteKey in project config,
|
|
1522
|
-
* throw.
|
|
1523
|
-
*/
|
|
1524
|
-
if (!options?.provider && !defaultProvider) {
|
|
1525
|
-
throw ERROR_FACTORY.create("no-provider" /* AppCheckError.NO_PROVIDER */);
|
|
1526
|
-
}
|
|
1527
|
-
const initOptions = {
|
|
1528
|
-
...options,
|
|
1529
|
-
provider: options?.provider || defaultProvider
|
|
1530
|
-
};
|
|
1531
|
-
const componentProvider = _getProvider(app, 'app-check');
|
|
1532
|
-
if (componentProvider.isInitialized()) {
|
|
1533
|
-
const existingInstance = componentProvider.getImmediate();
|
|
1534
|
-
const existingOptions = componentProvider.getOptions();
|
|
1535
|
-
/**
|
|
1536
|
-
* Check if all AppCheckOptions previously passed to initializeAppCheck
|
|
1537
|
-
* (`isTokenAutoRefreshEnabled` and `provider`) match those being passed
|
|
1538
|
-
* now. If so, return previous existing instance. Otherwise throw error.
|
|
1539
|
-
*/
|
|
1540
|
-
if (existingOptions.isTokenAutoRefreshEnabled ===
|
|
1541
|
-
initOptions.isTokenAutoRefreshEnabled &&
|
|
1542
|
-
existingOptions.provider?.isEqual(initOptions.provider)) {
|
|
1503
|
+
if (provider.isInitialized()) {
|
|
1504
|
+
const existingInstance = provider.getImmediate();
|
|
1505
|
+
const initialOptions = provider.getOptions();
|
|
1506
|
+
if (initialOptions &&
|
|
1507
|
+
!!initialOptions.isTokenAutoRefreshEnabled ===
|
|
1508
|
+
!!options.isTokenAutoRefreshEnabled &&
|
|
1509
|
+
initialOptions.provider?.isEqual(options.provider)) {
|
|
1543
1510
|
return existingInstance;
|
|
1544
1511
|
}
|
|
1545
1512
|
else {
|
|
1546
|
-
if (typeof getStateReference(app).internallyInitializedBy === 'string') {
|
|
1547
|
-
throw ERROR_FACTORY.create("already-internally-initialized" /* AppCheckError.ALREADY_INTERNALLY_INITIALIZED */, {
|
|
1548
|
-
initializerName: getStateReference(app)
|
|
1549
|
-
.internallyInitializedBy
|
|
1550
|
-
});
|
|
1551
|
-
}
|
|
1552
1513
|
throw ERROR_FACTORY.create("already-initialized" /* AppCheckError.ALREADY_INITIALIZED */, {
|
|
1553
1514
|
appName: app.name
|
|
1554
1515
|
});
|
|
1555
1516
|
}
|
|
1556
1517
|
}
|
|
1557
|
-
const appCheck =
|
|
1558
|
-
_activate(app,
|
|
1518
|
+
const appCheck = provider.initialize({ options });
|
|
1519
|
+
_activate(app, options.provider, options.isTokenAutoRefreshEnabled);
|
|
1559
1520
|
// If isTokenAutoRefreshEnabled is false, do not send any requests to the
|
|
1560
1521
|
// exchange endpoint without an explicit call from the user either directly
|
|
1561
1522
|
// or through another Firebase library (storage, functions, etc.)
|
|
@@ -1569,29 +1530,6 @@ function initializeAppCheck(app = getApp(), options) {
|
|
|
1569
1530
|
}
|
|
1570
1531
|
return appCheck;
|
|
1571
1532
|
}
|
|
1572
|
-
/**
|
|
1573
|
-
* Internal wrapper that sets a state variable flagging that this was
|
|
1574
|
-
* initialized under the hood by a product SDK.
|
|
1575
|
-
*
|
|
1576
|
-
* @internal
|
|
1577
|
-
*/
|
|
1578
|
-
function _initializeAppCheckInternal(
|
|
1579
|
-
// String to be used in error message if there is a future conflict.
|
|
1580
|
-
// Example: "Firebase AI Logic"
|
|
1581
|
-
initializerName, app = getApp(), options) {
|
|
1582
|
-
const componentProvider = _getProvider(app, 'app-check');
|
|
1583
|
-
const previouslyInitialized = componentProvider.isInitialized();
|
|
1584
|
-
if (previouslyInitialized) {
|
|
1585
|
-
// Product SDKs should accept any previously initialized
|
|
1586
|
-
// App Check configuration without error.
|
|
1587
|
-
return componentProvider.getImmediate();
|
|
1588
|
-
}
|
|
1589
|
-
else {
|
|
1590
|
-
const appCheck = initializeAppCheck(app, options);
|
|
1591
|
-
getStateReference(app).internallyInitializedBy = initializerName;
|
|
1592
|
-
return appCheck;
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
1533
|
/**
|
|
1596
1534
|
* Activate App Check
|
|
1597
1535
|
* @param app - Firebase app to activate App Check for.
|
|
@@ -1732,6 +1670,22 @@ onCompletion) {
|
|
|
1732
1670
|
*
|
|
1733
1671
|
* @packageDocumentation
|
|
1734
1672
|
*/
|
|
1673
|
+
/**
|
|
1674
|
+
* @license
|
|
1675
|
+
* Copyright 2021 Google LLC
|
|
1676
|
+
*
|
|
1677
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1678
|
+
* you may not use this file except in compliance with the License.
|
|
1679
|
+
* You may obtain a copy of the License at
|
|
1680
|
+
*
|
|
1681
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1682
|
+
*
|
|
1683
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1684
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1685
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1686
|
+
* See the License for the specific language governing permissions and
|
|
1687
|
+
* limitations under the License.
|
|
1688
|
+
*/
|
|
1735
1689
|
const APP_CHECK_NAME = 'app-check';
|
|
1736
1690
|
const APP_CHECK_NAME_INTERNAL = 'app-check-internal';
|
|
1737
1691
|
function registerAppCheck() {
|
|
@@ -1759,5 +1713,5 @@ function registerAppCheck() {
|
|
|
1759
1713
|
}
|
|
1760
1714
|
registerAppCheck();
|
|
1761
1715
|
|
|
1762
|
-
export { CustomProvider, ReCaptchaEnterpriseProvider, ReCaptchaV3Provider,
|
|
1716
|
+
export { CustomProvider, ReCaptchaEnterpriseProvider, ReCaptchaV3Provider, getLimitedUseToken, getToken, initializeAppCheck, onTokenChanged, setTokenAutoRefreshEnabled };
|
|
1763
1717
|
//# sourceMappingURL=index.esm.js.map
|