@descope/web-components-ui 1.0.336 → 1.0.337

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/index.esm.js CHANGED
@@ -7208,6 +7208,53 @@ class RawRecaptcha extends BaseClass {
7208
7208
  return this.enterprise ? window.grecaptcha?.enterprise : window.grecaptcha;
7209
7209
  }
7210
7210
 
7211
+ #getNewToken(grecaptchaInstance, currentNode, recaptchaWidgetId) {
7212
+ if (!this.isConnected) {
7213
+ return;
7214
+ }
7215
+
7216
+ grecaptchaInstance.ready(() => {
7217
+ // clone the node and append it to the body so that it can be used by the grepcaptcha script
7218
+ const cloneNode = currentNode
7219
+ .querySelector('textarea[name^="g-recaptcha-response"]')
7220
+ ?.cloneNode();
7221
+ if (cloneNode) {
7222
+ cloneNode.style.display = 'none';
7223
+ document.body.appendChild(cloneNode);
7224
+ }
7225
+
7226
+ // cleaning up the recaptcha element we added to the body
7227
+ const removeCloneNode = () => {
7228
+ cloneNode.remove();
7229
+ };
7230
+
7231
+ if (!this.siteKey) {
7232
+ return;
7233
+ }
7234
+ // we should pass recaptchaWidgetId, but this does not allow us to run execute multiple times
7235
+ // also calling grecaptchaInstance.reset() does not work
7236
+ const exec = grecaptchaInstance?.execute(recaptchaWidgetId, { action: this.action });
7237
+ exec.then((token, e) => {
7238
+ if (e) {
7239
+ // eslint-disable-next-line no-console
7240
+ console.warn('could not execute recaptcha', e);
7241
+ } else {
7242
+ this.updateComponentsContext({
7243
+ risktoken: token,
7244
+ riskaction: this.action,
7245
+ });
7246
+ // if the component is still connected, we should try to get a new token before the token expires (2 minutes)
7247
+ if (this.isConnected) {
7248
+ setTimeout(() => {
7249
+ this.#getNewToken(grecaptchaInstance, currentNode, recaptchaWidgetId);
7250
+ }, 110000);
7251
+ }
7252
+ }
7253
+ removeCloneNode();
7254
+ });
7255
+ });
7256
+ }
7257
+
7211
7258
  #createOnLoadScript() {
7212
7259
  window.onRecaptchaLoadCallback = () => {
7213
7260
  const currentNode = this.recaptchaEle;
@@ -7224,48 +7271,12 @@ class RawRecaptcha extends BaseClass {
7224
7271
  }
7225
7272
 
7226
7273
  setTimeout(() => {
7227
- // returns recaptchaWidgetId
7228
7274
  const recaptchaWidgetId = grecaptchaInstance.render(currentNode, {
7229
7275
  sitekey: this.siteKey,
7230
7276
  badge: 'inline',
7231
7277
  size: 'invisible',
7232
7278
  });
7233
-
7234
- grecaptchaInstance.ready(() => {
7235
- // clone the node and append it to the body so that it can be used by the grepcaptcha script
7236
- const cloneNode = currentNode
7237
- .querySelector('textarea[name^="g-recaptcha-response"]')
7238
- ?.cloneNode();
7239
- if (cloneNode) {
7240
- cloneNode.style.display = 'none';
7241
- document.body.appendChild(cloneNode);
7242
- }
7243
-
7244
- // cleaning up the recaptcha element we added to the body
7245
- const removeCloneNode = () => {
7246
- cloneNode.remove();
7247
- };
7248
-
7249
- if (this.siteKey) {
7250
- // we should pass recaptchaWidgetId, but this does not allow us to run execute multiple times
7251
- // also calling grecaptchaInstance.reset() does not work
7252
- const exec = grecaptchaInstance?.execute(recaptchaWidgetId, { action: this.action });
7253
- exec
7254
- .then((token) => {
7255
- this.updateComponentsContext({
7256
- risktoken: token,
7257
- riskaction: this.action,
7258
- });
7259
-
7260
- removeCloneNode();
7261
- })
7262
- .catch((e) => {
7263
- removeCloneNode();
7264
- // eslint-disable-next-line no-console
7265
- console.warn('could not execute recaptcha', e);
7266
- });
7267
- }
7268
- });
7279
+ this.#getNewToken(grecaptchaInstance, currentNode, recaptchaWidgetId);
7269
7280
  }, 0);
7270
7281
  };
7271
7282
  }