@firebase/app-check 0.6.4 → 0.6.5-canary.253b998fc

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.
@@ -1011,7 +1011,7 @@ function internalFactory(appCheck) {
1011
1011
  }
1012
1012
 
1013
1013
  const name = "@firebase/app-check";
1014
- const version = "0.6.4";
1014
+ const version = "0.6.5-canary.253b998fc";
1015
1015
 
1016
1016
  /**
1017
1017
  * @license
@@ -1121,7 +1121,15 @@ async function getToken$1(app) {
1121
1121
  function renderInvisibleWidget(app, siteKey, grecaptcha, container) {
1122
1122
  const widgetId = grecaptcha.render(container, {
1123
1123
  sitekey: siteKey,
1124
- size: 'invisible'
1124
+ size: 'invisible',
1125
+ // Success callback - set state
1126
+ callback: () => {
1127
+ getStateReference(app).reCAPTCHAState.succeeded = true;
1128
+ },
1129
+ // Failure callback - set state
1130
+ 'error-callback': () => {
1131
+ getStateReference(app).reCAPTCHAState.succeeded = false;
1132
+ }
1125
1133
  });
1126
1134
  const state = getStateReference(app);
1127
1135
  state.reCAPTCHAState = Object.assign(Object.assign({}, state.reCAPTCHAState), { // state.reCAPTCHAState is set in the initialize()
@@ -1180,7 +1188,7 @@ class ReCaptchaV3Provider {
1180
1188
  * @internal
1181
1189
  */
1182
1190
  async getToken() {
1183
- var _a, _b;
1191
+ var _a, _b, _c;
1184
1192
  throwIfThrottled(this._throttleData);
1185
1193
  // Top-level `getToken()` has already checked that App Check is initialized
1186
1194
  // and therefore this._app and this._heartbeatServiceProvider are available.
@@ -1188,13 +1196,17 @@ class ReCaptchaV3Provider {
1188
1196
  // reCaptcha.execute() throws null which is not very descriptive.
1189
1197
  throw ERROR_FACTORY.create("recaptcha-error" /* AppCheckError.RECAPTCHA_ERROR */);
1190
1198
  });
1199
+ // Check if a failure state was set by the recaptcha "error-callback".
1200
+ if (!((_a = getStateReference(this._app).reCAPTCHAState) === null || _a === void 0 ? void 0 : _a.succeeded)) {
1201
+ throw ERROR_FACTORY.create("recaptcha-error" /* AppCheckError.RECAPTCHA_ERROR */);
1202
+ }
1191
1203
  let result;
1192
1204
  try {
1193
1205
  result = await exchangeToken(getExchangeRecaptchaV3TokenRequest(this._app, attestedClaimsToken), this._heartbeatServiceProvider);
1194
1206
  }
1195
1207
  catch (e) {
1196
- if ((_a = e.code) === null || _a === void 0 ? void 0 : _a.includes("fetch-status-error" /* AppCheckError.FETCH_STATUS_ERROR */)) {
1197
- this._throttleData = setBackoff(Number((_b = e.customData) === null || _b === void 0 ? void 0 : _b.httpStatus), this._throttleData);
1208
+ if ((_b = e.code) === null || _b === void 0 ? void 0 : _b.includes("fetch-status-error" /* AppCheckError.FETCH_STATUS_ERROR */)) {
1209
+ this._throttleData = setBackoff(Number((_c = e.customData) === null || _c === void 0 ? void 0 : _c.httpStatus), this._throttleData);
1198
1210
  throw ERROR_FACTORY.create("throttled" /* AppCheckError.THROTTLED */, {
1199
1211
  time: getDurationString(this._throttleData.allowRequestsAfter - Date.now()),
1200
1212
  httpStatus: this._throttleData.httpStatus
@@ -1254,7 +1266,7 @@ class ReCaptchaEnterpriseProvider {
1254
1266
  * @internal
1255
1267
  */
1256
1268
  async getToken() {
1257
- var _a, _b;
1269
+ var _a, _b, _c;
1258
1270
  throwIfThrottled(this._throttleData);
1259
1271
  // Top-level `getToken()` has already checked that App Check is initialized
1260
1272
  // and therefore this._app and this._heartbeatServiceProvider are available.
@@ -1262,13 +1274,17 @@ class ReCaptchaEnterpriseProvider {
1262
1274
  // reCaptcha.execute() throws null which is not very descriptive.
1263
1275
  throw ERROR_FACTORY.create("recaptcha-error" /* AppCheckError.RECAPTCHA_ERROR */);
1264
1276
  });
1277
+ // Check if a failure state was set by the recaptcha "error-callback".
1278
+ if (!((_a = getStateReference(this._app).reCAPTCHAState) === null || _a === void 0 ? void 0 : _a.succeeded)) {
1279
+ throw ERROR_FACTORY.create("recaptcha-error" /* AppCheckError.RECAPTCHA_ERROR */);
1280
+ }
1265
1281
  let result;
1266
1282
  try {
1267
1283
  result = await exchangeToken(getExchangeRecaptchaEnterpriseTokenRequest(this._app, attestedClaimsToken), this._heartbeatServiceProvider);
1268
1284
  }
1269
1285
  catch (e) {
1270
- if ((_a = e.code) === null || _a === void 0 ? void 0 : _a.includes("fetch-status-error" /* AppCheckError.FETCH_STATUS_ERROR */)) {
1271
- this._throttleData = setBackoff(Number((_b = e.customData) === null || _b === void 0 ? void 0 : _b.httpStatus), this._throttleData);
1286
+ if ((_b = e.code) === null || _b === void 0 ? void 0 : _b.includes("fetch-status-error" /* AppCheckError.FETCH_STATUS_ERROR */)) {
1287
+ this._throttleData = setBackoff(Number((_c = e.customData) === null || _c === void 0 ? void 0 : _c.httpStatus), this._throttleData);
1272
1288
  throw ERROR_FACTORY.create("throttled" /* AppCheckError.THROTTLED */, {
1273
1289
  time: getDurationString(this._throttleData.allowRequestsAfter - Date.now()),
1274
1290
  httpStatus: this._throttleData.httpStatus