@firebase/app-check 0.11.4 → 0.12.0-20260615181107
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 +4 -2
- package/dist/app-check.d.ts +10 -2
- package/dist/esm/index.esm.js +71 -12
- package/dist/esm/index.esm.js.map +1 -1
- package/dist/esm/src/api.d.ts +8 -1
- package/dist/esm/src/errors.d.ts +5 -0
- package/dist/esm/src/public-types.d.ts +1 -1
- package/dist/esm/src/state.d.ts +1 -0
- package/dist/index.cjs.js +71 -11
- package/dist/index.cjs.js.map +1 -1
- package/dist/src/api.d.ts +8 -1
- package/dist/src/errors.d.ts +5 -0
- package/dist/src/public-types.d.ts +1 -1
- package/dist/src/state.d.ts +1 -0
- package/package.json +3 -3
package/dist/esm/src/errors.d.ts
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import { ErrorFactory } from '@firebase/util';
|
|
18
18
|
export declare const enum AppCheckError {
|
|
19
19
|
ALREADY_INITIALIZED = "already-initialized",
|
|
20
|
+
ALREADY_INTERNALLY_INITIALIZED = "already-internally-initialized",
|
|
20
21
|
USE_BEFORE_ACTIVATION = "use-before-activation",
|
|
21
22
|
FETCH_NETWORK_ERROR = "fetch-network-error",
|
|
22
23
|
FETCH_PARSE_ERROR = "fetch-parse-error",
|
|
@@ -25,6 +26,7 @@ export declare const enum AppCheckError {
|
|
|
25
26
|
STORAGE_GET = "storage-get",
|
|
26
27
|
STORAGE_WRITE = "storage-set",
|
|
27
28
|
RECAPTCHA_ERROR = "recaptcha-error",
|
|
29
|
+
NO_PROVIDER = "no-provider",
|
|
28
30
|
INITIAL_THROTTLE = "initial-throttle",
|
|
29
31
|
THROTTLED = "throttled"
|
|
30
32
|
}
|
|
@@ -32,6 +34,9 @@ interface ErrorParams {
|
|
|
32
34
|
[AppCheckError.ALREADY_INITIALIZED]: {
|
|
33
35
|
appName: string;
|
|
34
36
|
};
|
|
37
|
+
[AppCheckError.ALREADY_INTERNALLY_INITIALIZED]: {
|
|
38
|
+
initializerName: string;
|
|
39
|
+
};
|
|
35
40
|
[AppCheckError.USE_BEFORE_ACTIVATION]: {
|
|
36
41
|
appName: string;
|
|
37
42
|
};
|
|
@@ -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
|
|
54
|
+
provider?: CustomProvider | ReCaptchaV3Provider | ReCaptchaEnterpriseProvider;
|
|
55
55
|
/**
|
|
56
56
|
* If set to true, enables automatic background refresh of App Check token.
|
|
57
57
|
*/
|
package/dist/esm/src/state.d.ts
CHANGED
package/dist/index.cjs.js
CHANGED
|
@@ -226,6 +226,9 @@ const ERRORS = {
|
|
|
226
226
|
'different options. To avoid this error, call initializeAppCheck() with the ' +
|
|
227
227
|
'same options as when it was originally called. This will return the ' +
|
|
228
228
|
'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}.',
|
|
229
232
|
["use-before-activation" /* AppCheckError.USE_BEFORE_ACTIVATION */]: 'App Check is being used before initializeAppCheck() is called for FirebaseApp {$appName}. ' +
|
|
230
233
|
'Call initializeAppCheck() before instantiating other Firebase services.',
|
|
231
234
|
["fetch-network-error" /* AppCheckError.FETCH_NETWORK_ERROR */]: 'Fetch failed to connect to a network. Check Internet connection. ' +
|
|
@@ -237,6 +240,8 @@ const ERRORS = {
|
|
|
237
240
|
["storage-get" /* AppCheckError.STORAGE_GET */]: 'Error thrown when reading from storage. Original error: {$originalErrorMessage}.',
|
|
238
241
|
["storage-set" /* AppCheckError.STORAGE_WRITE */]: 'Error thrown when writing to storage. Original error: {$originalErrorMessage}.',
|
|
239
242
|
["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.',
|
|
240
245
|
["initial-throttle" /* AppCheckError.INITIAL_THROTTLE */]: `{$httpStatus} error. Attempts allowed again after {$time}`,
|
|
241
246
|
["throttled" /* AppCheckError.THROTTLED */]: `Requests throttled due to previous {$httpStatus} error. Attempts allowed again after {$time}`
|
|
242
247
|
};
|
|
@@ -1057,7 +1062,7 @@ function internalFactory(appCheck) {
|
|
|
1057
1062
|
}
|
|
1058
1063
|
|
|
1059
1064
|
const name = "@firebase/app-check";
|
|
1060
|
-
const version = "0.
|
|
1065
|
+
const version = "0.12.0-20260615181107";
|
|
1061
1066
|
|
|
1062
1067
|
/**
|
|
1063
1068
|
* @license
|
|
@@ -1191,7 +1196,8 @@ function loadReCAPTCHAV3Script(onload) {
|
|
|
1191
1196
|
}
|
|
1192
1197
|
function loadReCAPTCHAEnterpriseScript(onload) {
|
|
1193
1198
|
const script = document.createElement('script');
|
|
1194
|
-
|
|
1199
|
+
// This param is required when we plan to render a widget explicitly.
|
|
1200
|
+
script.src = RECAPTCHA_ENTERPRISE_URL + '?render=explicit';
|
|
1195
1201
|
script.onload = onload;
|
|
1196
1202
|
document.head.appendChild(script);
|
|
1197
1203
|
}
|
|
@@ -1495,7 +1501,6 @@ function throwIfThrottled(throttleData) {
|
|
|
1495
1501
|
*/
|
|
1496
1502
|
function initializeAppCheck(app$1 = app.getApp(), options) {
|
|
1497
1503
|
app$1 = util.getModularInstance(app$1);
|
|
1498
|
-
const provider = app._getProvider(app$1, 'app-check');
|
|
1499
1504
|
// Ensure initializeDebugMode() is only called once.
|
|
1500
1505
|
if (!getDebugState().initialized) {
|
|
1501
1506
|
initializeDebugMode();
|
|
@@ -1508,22 +1513,53 @@ function initializeAppCheck(app$1 = app.getApp(), options) {
|
|
|
1508
1513
|
// Not using logger because I don't think we ever want this accidentally hidden.
|
|
1509
1514
|
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.`));
|
|
1510
1515
|
}
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
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)) {
|
|
1517
1547
|
return existingInstance;
|
|
1518
1548
|
}
|
|
1519
1549
|
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
|
+
}
|
|
1520
1556
|
throw ERROR_FACTORY.create("already-initialized" /* AppCheckError.ALREADY_INITIALIZED */, {
|
|
1521
1557
|
appName: app$1.name
|
|
1522
1558
|
});
|
|
1523
1559
|
}
|
|
1524
1560
|
}
|
|
1525
|
-
const appCheck =
|
|
1526
|
-
_activate(app$1,
|
|
1561
|
+
const appCheck = componentProvider.initialize({ options: initOptions });
|
|
1562
|
+
_activate(app$1, initOptions.provider, initOptions.isTokenAutoRefreshEnabled);
|
|
1527
1563
|
// If isTokenAutoRefreshEnabled is false, do not send any requests to the
|
|
1528
1564
|
// exchange endpoint without an explicit call from the user either directly
|
|
1529
1565
|
// or through another Firebase library (storage, functions, etc.)
|
|
@@ -1537,6 +1573,29 @@ function initializeAppCheck(app$1 = app.getApp(), options) {
|
|
|
1537
1573
|
}
|
|
1538
1574
|
return appCheck;
|
|
1539
1575
|
}
|
|
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
|
+
}
|
|
1540
1599
|
/**
|
|
1541
1600
|
* Activate App Check
|
|
1542
1601
|
* @param app - Firebase app to activate App Check for.
|
|
@@ -1707,6 +1766,7 @@ registerAppCheck();
|
|
|
1707
1766
|
exports.CustomProvider = CustomProvider;
|
|
1708
1767
|
exports.ReCaptchaEnterpriseProvider = ReCaptchaEnterpriseProvider;
|
|
1709
1768
|
exports.ReCaptchaV3Provider = ReCaptchaV3Provider;
|
|
1769
|
+
exports._initializeAppCheckInternal = _initializeAppCheckInternal;
|
|
1710
1770
|
exports.getLimitedUseToken = getLimitedUseToken;
|
|
1711
1771
|
exports.getToken = getToken;
|
|
1712
1772
|
exports.initializeAppCheck = initializeAppCheck;
|