@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
|
@@ -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,7 +144,9 @@ 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
|
|
147
|
+
export declare function initializeAppCheck(app?: FirebaseApp, options?: AppCheckOptions): AppCheck;
|
|
148
|
+
|
|
149
|
+
/* Excluded from this release type: _initializeAppCheckInternal */
|
|
148
150
|
|
|
149
151
|
/**
|
|
150
152
|
* 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,7 +166,15 @@ 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
|
|
169
|
+
export declare function initializeAppCheck(app?: FirebaseApp, options?: AppCheckOptions): AppCheck;
|
|
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;
|
|
170
178
|
|
|
171
179
|
/**
|
|
172
180
|
* Registers a listener to changes in the token state. There can be more
|
package/dist/esm/index.esm.js
CHANGED
|
@@ -222,6 +222,9 @@ const ERRORS = {
|
|
|
222
222
|
'different options. To avoid this error, call initializeAppCheck() with the ' +
|
|
223
223
|
'same options as when it was originally called. This will return the ' +
|
|
224
224
|
'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}.',
|
|
225
228
|
["use-before-activation" /* AppCheckError.USE_BEFORE_ACTIVATION */]: 'App Check is being used before initializeAppCheck() is called for FirebaseApp {$appName}. ' +
|
|
226
229
|
'Call initializeAppCheck() before instantiating other Firebase services.',
|
|
227
230
|
["fetch-network-error" /* AppCheckError.FETCH_NETWORK_ERROR */]: 'Fetch failed to connect to a network. Check Internet connection. ' +
|
|
@@ -233,6 +236,8 @@ const ERRORS = {
|
|
|
233
236
|
["storage-get" /* AppCheckError.STORAGE_GET */]: 'Error thrown when reading from storage. Original error: {$originalErrorMessage}.',
|
|
234
237
|
["storage-set" /* AppCheckError.STORAGE_WRITE */]: 'Error thrown when writing to storage. Original error: {$originalErrorMessage}.',
|
|
235
238
|
["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.',
|
|
236
241
|
["initial-throttle" /* AppCheckError.INITIAL_THROTTLE */]: `{$httpStatus} error. Attempts allowed again after {$time}`,
|
|
237
242
|
["throttled" /* AppCheckError.THROTTLED */]: `Requests throttled due to previous {$httpStatus} error. Attempts allowed again after {$time}`
|
|
238
243
|
};
|
|
@@ -1053,7 +1058,7 @@ function internalFactory(appCheck) {
|
|
|
1053
1058
|
}
|
|
1054
1059
|
|
|
1055
1060
|
const name = "@firebase/app-check";
|
|
1056
|
-
const version = "0.
|
|
1061
|
+
const version = "0.12.0-20260615181107";
|
|
1057
1062
|
|
|
1058
1063
|
/**
|
|
1059
1064
|
* @license
|
|
@@ -1187,7 +1192,8 @@ function loadReCAPTCHAV3Script(onload) {
|
|
|
1187
1192
|
}
|
|
1188
1193
|
function loadReCAPTCHAEnterpriseScript(onload) {
|
|
1189
1194
|
const script = document.createElement('script');
|
|
1190
|
-
|
|
1195
|
+
// This param is required when we plan to render a widget explicitly.
|
|
1196
|
+
script.src = RECAPTCHA_ENTERPRISE_URL + '?render=explicit';
|
|
1191
1197
|
script.onload = onload;
|
|
1192
1198
|
document.head.appendChild(script);
|
|
1193
1199
|
}
|
|
@@ -1491,7 +1497,6 @@ function throwIfThrottled(throttleData) {
|
|
|
1491
1497
|
*/
|
|
1492
1498
|
function initializeAppCheck(app = getApp(), options) {
|
|
1493
1499
|
app = getModularInstance(app);
|
|
1494
|
-
const provider = _getProvider(app, 'app-check');
|
|
1495
1500
|
// Ensure initializeDebugMode() is only called once.
|
|
1496
1501
|
if (!getDebugState().initialized) {
|
|
1497
1502
|
initializeDebugMode();
|
|
@@ -1504,22 +1509,53 @@ function initializeAppCheck(app = getApp(), options) {
|
|
|
1504
1509
|
// Not using logger because I don't think we ever want this accidentally hidden.
|
|
1505
1510
|
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.`));
|
|
1506
1511
|
}
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1512
|
+
let defaultProvider;
|
|
1513
|
+
/**
|
|
1514
|
+
* If user did not pass a provider, look for site key in project
|
|
1515
|
+
* config and create a default ReCaptchaEnterpriseProvider with it.
|
|
1516
|
+
*/
|
|
1517
|
+
if (!options?.provider && app.options.recaptchaSiteKey) {
|
|
1518
|
+
defaultProvider = new ReCaptchaEnterpriseProvider(app.options.recaptchaSiteKey);
|
|
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)) {
|
|
1513
1543
|
return existingInstance;
|
|
1514
1544
|
}
|
|
1515
1545
|
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
|
+
}
|
|
1516
1552
|
throw ERROR_FACTORY.create("already-initialized" /* AppCheckError.ALREADY_INITIALIZED */, {
|
|
1517
1553
|
appName: app.name
|
|
1518
1554
|
});
|
|
1519
1555
|
}
|
|
1520
1556
|
}
|
|
1521
|
-
const appCheck =
|
|
1522
|
-
_activate(app,
|
|
1557
|
+
const appCheck = componentProvider.initialize({ options: initOptions });
|
|
1558
|
+
_activate(app, initOptions.provider, initOptions.isTokenAutoRefreshEnabled);
|
|
1523
1559
|
// If isTokenAutoRefreshEnabled is false, do not send any requests to the
|
|
1524
1560
|
// exchange endpoint without an explicit call from the user either directly
|
|
1525
1561
|
// or through another Firebase library (storage, functions, etc.)
|
|
@@ -1533,6 +1569,29 @@ function initializeAppCheck(app = getApp(), options) {
|
|
|
1533
1569
|
}
|
|
1534
1570
|
return appCheck;
|
|
1535
1571
|
}
|
|
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
|
+
}
|
|
1536
1595
|
/**
|
|
1537
1596
|
* Activate App Check
|
|
1538
1597
|
* @param app - Firebase app to activate App Check for.
|
|
@@ -1700,5 +1759,5 @@ function registerAppCheck() {
|
|
|
1700
1759
|
}
|
|
1701
1760
|
registerAppCheck();
|
|
1702
1761
|
|
|
1703
|
-
export { CustomProvider, ReCaptchaEnterpriseProvider, ReCaptchaV3Provider, getLimitedUseToken, getToken, initializeAppCheck, onTokenChanged, setTokenAutoRefreshEnabled };
|
|
1762
|
+
export { CustomProvider, ReCaptchaEnterpriseProvider, ReCaptchaV3Provider, _initializeAppCheckInternal, getLimitedUseToken, getToken, initializeAppCheck, onTokenChanged, setTokenAutoRefreshEnabled };
|
|
1704
1763
|
//# sourceMappingURL=index.esm.js.map
|