@hcaptcha/react-hcaptcha 1.17.4 → 2.0.1

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/README.md CHANGED
@@ -98,7 +98,7 @@ import { default as RenamedCaptcha } from '../utils/captcha';
98
98
  You can also use the Provider/Hook pattern:
99
99
 
100
100
  ```js
101
- import { HCaptchaProvider, useHCaptcha } from '@hcaptcha/react-hcaptcha/hooks';
101
+ import { HCaptchaProvider, useHCaptcha } from '@hcaptcha/react-hcaptcha';
102
102
 
103
103
  function App() {
104
104
  return (
@@ -269,9 +269,13 @@ This will be rare, but could happen in the event you are testing offline, or hav
269
269
 
270
270
  #### Scripts
271
271
 
272
- * `npm run start` - will start the demo app with hot reload
273
- * `npm run test` - will test the library: unit tests
274
- * `npm run build` - will build the production version
272
+ * `pnpm run start` - will start the demo app with hot reload
273
+ * `pnpm run test` - will test the library: unit tests
274
+ * `pnpm --filter @hcaptcha-react/lib run combile:build` - will build the production version
275
+
276
+
277
+ #### Environment Variables for Development
278
+ For developing react-hcaptcha itself, create a `.env` in the root directory. `.env.example` shows the variables that can be set. If this file is not present, build variables default to a production configuration.
275
279
 
276
280
 
277
281
  #### Publishing
@@ -0,0 +1,4 @@
1
+ var ae=Object.create;var I=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var he=Object.getPrototypeOf,le=Object.prototype.hasOwnProperty;var ue=(t,e)=>{for(var n in e)I(t,n,{get:e[n],enumerable:!0})},F=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ce(e))!le.call(t,s)&&s!==n&&I(t,s,{get:()=>e[s],enumerable:!(r=oe(e,s))||r.enumerable});return t};var N=(t,e,n)=>(n=t!=null?ae(he(t)):{},F(e||!t||!t.__esModule?I(n,"default",{value:t,enumerable:!0}):n,t)),de=t=>F(I({},"__esModule",{value:!0}),t);var We={};ue(We,{HCaptchaProvider:()=>D,useHCaptcha:()=>M});module.exports=de(We);var z=require("react");var W=require("react"),k=(0,W.createContext)();var M=()=>(0,z.useContext)(k);var g=N(require("react"),1);var _=N(require("react"),1);var pe=Object.defineProperty,fe=Object.defineProperties,me=Object.getOwnPropertyDescriptors,L=Object.getOwnPropertySymbols,G=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,T=(t,e,n)=>e in t?pe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,m=(t,e)=>{for(var n in e||(e={}))G.call(e,n)&&T(t,n,e[n]);if(L)for(var n of L(e))X.call(e,n)&&T(t,n,e[n]);return t},Q=(t,e)=>fe(t,me(e)),ge=(t,e)=>{var n={};for(var r in t)G.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&L)for(var r of L(t))e.indexOf(r)<0&&X.call(t,r)&&(n[r]=t[r]);return n},l=(t,e,n)=>(T(t,typeof e!="symbol"?e+"":e,n),n),R=(t,e,n)=>new Promise((r,s)=>{var i=o=>{try{h(n.next(o))}catch(c){s(c)}},a=o=>{try{h(n.throw(o))}catch(c){s(c)}},h=o=>o.done?r(o.value):Promise.resolve(o.value).then(i,a);h((n=n.apply(t,e)).next())}),ye="hCaptcha-script",q="hCaptchaOnLoad",V="script-error",w="@hCaptcha/loader";function ve(t){return Object.entries(t).filter(([,e])=>e||e===!1).map(([e,n])=>`${encodeURIComponent(e)}=${encodeURIComponent(String(n))}`).join("&")}function Y(t){let e=t&&t.ownerDocument||document,n=e.defaultView||e.parentWindow||window;return{document:e,window:n}}function Z(t){return t||document.head}function xe(t){var e;t.setTag("source",w),t.setTag("url",document.URL),t.setContext("os",{UA:navigator.userAgent}),t.setContext("browser",m({},be())),t.setContext("device",Q(m({},Ee()),{screen_width_pixels:screen.width,screen_height_pixels:screen.height,language:navigator.language,orientation:((e=screen.orientation)==null?void 0:e.type)||"Unknown",processor_count:navigator.hardwareConcurrency,platform:navigator.platform}))}function be(){var t,e,n,r,s,i;let a=navigator.userAgent,h,o;return a.indexOf("Firefox")!==-1?(h="Firefox",o=(t=a.match(/Firefox\/([\d.]+)/))==null?void 0:t[1]):a.indexOf("Edg")!==-1?(h="Microsoft Edge",o=(e=a.match(/Edg\/([\d.]+)/))==null?void 0:e[1]):a.indexOf("Chrome")!==-1&&a.indexOf("Safari")!==-1?(h="Chrome",o=(n=a.match(/Chrome\/([\d.]+)/))==null?void 0:n[1]):a.indexOf("Safari")!==-1&&a.indexOf("Chrome")===-1?(h="Safari",o=(r=a.match(/Version\/([\d.]+)/))==null?void 0:r[1]):a.indexOf("Opera")!==-1||a.indexOf("OPR")!==-1?(h="Opera",o=(s=a.match(/(Opera|OPR)\/([\d.]+)/))==null?void 0:s[2]):a.indexOf("MSIE")!==-1||a.indexOf("Trident")!==-1?(h="Internet Explorer",o=(i=a.match(/(MSIE |rv:)([\d.]+)/))==null?void 0:i[2]):(h="Unknown",o="Unknown"),{name:h,version:o}}function we(t){return new Promise(e=>setTimeout(e,t))}function Ee(){let t=navigator.userAgent,e;t.indexOf("Win")!==-1?e="Windows":t.indexOf("Mac")!==-1?e="Mac":t.indexOf("Linux")!==-1?e="Linux":t.indexOf("Android")!==-1?e="Android":t.indexOf("like Mac")!==-1||t.indexOf("iPhone")!==-1||t.indexOf("iPad")!==-1?e="iOS":e="Unknown";let n;return/Mobile|iPhone|iPod|Android/i.test(t)?n="Mobile":/Tablet|iPad/i.test(t)?n="Tablet":n="Desktop",{model:e,family:e,device:n}}var Ce=class ee{constructor(e){l(this,"_parent"),l(this,"breadcrumbs",[]),l(this,"context",{}),l(this,"extra",{}),l(this,"tags",{}),l(this,"request"),l(this,"user"),this._parent=e}get parent(){return this._parent}child(){return new ee(this)}setRequest(e){return this.request=e,this}removeRequest(){return this.request=void 0,this}addBreadcrumb(e){return typeof e.timestamp>"u"&&(e.timestamp=new Date().toISOString()),this.breadcrumbs.push(e),this}setExtra(e,n){return this.extra[e]=n,this}removeExtra(e){return delete this.extra[e],this}setContext(e,n){return typeof n.type>"u"&&(n.type=e),this.context[e]=n,this}removeContext(e){return delete this.context[e],this}setTags(e){return this.tags=m(m({},this.tags),e),this}setTag(e,n){return this.tags[e]=n,this}removeTag(e){return delete this.tags[e],this}setUser(e){return this.user=e,this}removeUser(){return this.user=void 0,this}toBody(){let e=[],n=this;for(;n;)e.push(n),n=n.parent;return e.reverse().reduce((r,s)=>{var i;return r.breadcrumbs=[...(i=r.breadcrumbs)!=null?i:[],...s.breadcrumbs],r.extra=m(m({},r.extra),s.extra),r.contexts=m(m({},r.contexts),s.context),r.tags=m(m({},r.tags),s.tags),s.user&&(r.user=s.user),s.request&&(r.request=s.request),r},{breadcrumbs:[],extra:{},contexts:{},tags:{},request:void 0,user:void 0})}clear(){this.breadcrumbs=[],this.context={},this.tags={},this.user=void 0}},Re=/^\s*at (?:(.*?) ?\()?((?:file|https?|blob|chrome-extension|address|native|eval|webpack|<anonymous>|[-a-z]+:|.*bundle|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,_e=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:file|https?|blob|chrome|webpack|resource|moz-extension).*?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js))(?::(\d+))?(?::(\d+))?\s*$/i,Oe=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i,Pe=/^(?:(\w+):)\/\/(?:(\w+)(?::(\w+))?@)([\w.-]+)(?::(\d+))?\/(.+)/,j="?",J="An unknown error occurred",Se="0.0.4";function Ie(t){for(let e=0;e<t.length;e++)t[e]=Math.floor(Math.random()*256);return t}function p(t){return(t+256).toString(16).substring(1)}function ke(){let t=Ie(new Array(16));return t[6]=t[6]&15|64,t[8]=t[8]&63|128,p(t[0])+p(t[1])+p(t[2])+p(t[3])+"-"+p(t[4])+p(t[5])+"-"+p(t[6])+p(t[7])+"-"+p(t[8])+p(t[9])+"-"+p(t[10])+p(t[11])+p(t[12])+p(t[13])+p(t[14])+p(t[15])}var je=[[Re,"chrome"],[Oe,"winjs"],[_e,"gecko"]];function Ae(t){var e,n,r,s;if(!t.stack)return null;let i=[],a=(r=(n=(e=t.stack).split)==null?void 0:n.call(e,`
2
+ `))!=null?r:[];for(let h=0;h<a.length;++h){let o=null,c=null,u=null;for(let[y,v]of je)if(c=y.exec(a[h]),c){u=v;break}if(!(!c||!u)){if(u==="chrome")o={filename:(s=c[2])!=null&&s.startsWith("address at ")?c[2].substring(11):c[2],function:c[1]||j,lineno:c[3]?+c[3]:null,colno:c[4]?+c[4]:null};else if(u==="winjs")o={filename:c[2],function:c[1]||j,lineno:+c[3],colno:c[4]?+c[4]:null};else if(u==="gecko")h===0&&!c[5]&&t.columnNumber!==void 0&&i.length>0&&(i[0].column=t.columnNumber+1),o={filename:c[3],function:c[1]||j,lineno:c[4]?+c[4]:null,colno:c[5]?+c[5]:null};else continue;!o.function&&o.lineno&&(o.function=j),i.push(o)}}return i.length?i.reverse():null}function qe(t){let e=Ae(t);return{type:t.name,value:t.message,stacktrace:{frames:e??[]}}}function Le(t){let e=Pe.exec(t),n=e?e.slice(1):[];if(n.length!==6)throw new Error("Invalid DSN");let r=n[5].split("/"),s=r.slice(0,-1).join("/");return n[0]+"://"+n[3]+(n[4]?":"+n[4]:"")+(s?"/"+s:"")+"/api/"+r.pop()+"/envelope/?sentry_version=7&sentry_key="+n[1]+(n[2]?"&sentry_secret="+n[2]:"")}function Me(t,e,n){var r,s;let i=m({event_id:ke().replaceAll("-",""),platform:"javascript",sdk:{name:"@hcaptcha/sentry",version:Se},environment:e,release:n,timestamp:Date.now()/1e3},t.scope.toBody());if(t.type==="exception"){i.message=(s=(r=t.error)==null?void 0:r.message)!=null?s:"Unknown error",i.fingerprint=[i.message];let a=[],h=t.error;for(let o=0;o<5&&h&&(a.push(qe(h)),!(!h.cause||!(h.cause instanceof Error)));o++)h=h.cause;i.exception={values:a.reverse()}}return t.type==="message"&&(i.message=t.message,i.level=t.level),i}function Te(t){if(t instanceof Error)return t;if(typeof t=="string")return new Error(t);if(typeof t=="object"&&t!==null&&!Array.isArray(t)){let n=t,{message:r}=n,s=ge(n,["message"]),i=new Error(typeof r=="string"?r:J);return Object.assign(i,s)}let e=new Error(J);return Object.assign(e,{cause:t})}function Ue(t,e,n){return R(this,null,function*(){var r,s;try{if(typeof fetch<"u"&&typeof AbortSignal<"u"){let i;if(n){let o=new AbortController;i=o.signal,setTimeout(()=>o.abort(),n)}let a=yield fetch(t,Q(m({},e),{signal:i})),h=yield a.text();return{status:a.status,body:h}}return yield new Promise((i,a)=>{var h,o;let c=new XMLHttpRequest;if(c.open((h=e?.method)!=null?h:"GET",t),c.onload=()=>i({status:c.status,body:c.responseText}),c.onerror=()=>a(new Error("XHR Network Error")),e?.headers)for(let[u,y]of Object.entries(e.headers))c.setRequestHeader(u,y);if(n){let u=setTimeout(()=>{c.abort(),a(new Error("Request timed out"))},n);c.onloadend=()=>{clearTimeout(u)}}c.send((o=e?.body)==null?void 0:o.toString())})}catch(i){return{status:0,body:(s=(r=i?.toString)==null?void 0:r.call(i))!=null?s:"Unknown error"}}})}var f,U=(f=class{constructor(t){l(this,"apiURL"),l(this,"dsn"),l(this,"environment"),l(this,"release"),l(this,"sampleRate"),l(this,"debug"),l(this,"_scope"),l(this,"shouldBuffer",!1),l(this,"bufferlimit",20),l(this,"buffer",[]);var e,n,r,s,i;this.environment=t.environment,this.release=t.release,this.sampleRate=(e=t.sampleRate)!=null?e:1,this.debug=(n=t.debug)!=null?n:!1,this._scope=(r=t.scope)!=null?r:new Ce,this.apiURL=Le(t.dsn),this.dsn=t.dsn,this.shouldBuffer=(s=t.buffer)!=null?s:!1,this.bufferlimit=(i=t.bufferLimit)!=null?i:20}static init(t){f._instance||(f._instance=new f(t))}static get instance(){if(!f._instance)throw new Error("Sentry has not been initialized");return f._instance}log(...t){this.debug&&console.log(...t)}get scope(){return this._scope}static get scope(){return f.instance.scope}withScope(t){let e=this._scope.child();t(e)}static withScope(t){f.instance.withScope(t)}captureException(t,e){this.captureEvent({type:"exception",level:"error",error:Te(t),scope:e??this._scope})}static captureException(t,e){f.instance.captureException(t,e)}captureMessage(t,e="info",n){this.captureEvent({type:"message",level:e,message:t,scope:n??this._scope})}static captureMessage(t,e="info",n){f.instance.captureMessage(t,e,n)}captureEvent(t){if(Math.random()>=this.sampleRate){this.log("Dropped event due to sample rate");return}if(this.shouldBuffer){if(this.buffer.length>=this.bufferlimit)return;this.buffer.push(t)}else this.sendEvent(t)}sendEvent(t,e=5e3){return R(this,null,function*(){try{this.log("Sending sentry event",t);let n=Me(t,this.environment,this.release),r={event_id:n.event_id,dsn:this.dsn},s={type:"event"},i=JSON.stringify(r)+`
3
+ `+JSON.stringify(s)+`
4
+ `+JSON.stringify(n),a=yield Ue(this.apiURL,{method:"POST",headers:{"Content-Type":"application/x-sentry-envelope"},body:i},e);this.log("Sentry response",a.status),a.status!==200&&(console.log(a.body),console.error("Failed to send event to Sentry",a))}catch(n){console.error("Failed to send event",n)}})}flush(t=5e3){return R(this,null,function*(){try{this.log("Flushing sentry events",this.buffer.length);let e=this.buffer.splice(0,this.buffer.length).map(n=>this.sendEvent(n,t));yield Promise.all(e),this.log("Flushed all events")}catch(e){console.error("Failed to flush events",e)}})}static flush(t=5e3){return f.instance.flush(t)}static reset(){f._instance=void 0}},l(f,"_instance"),f),He="https://d233059272824702afc8c43834c4912d@sentry.hcaptcha.com/6",Be="2.3.0",De="production";function $e(t=!0){if(!t)return K();U.init({dsn:He,release:Be,environment:De});let e=U.scope;return xe(e),K(e)}function K(t=null){return{addBreadcrumb:e=>{t&&t.addBreadcrumb(e)},captureRequest:e=>{t&&t.setRequest(e)},captureException:e=>{t&&U.captureException(e,t)}}}function Fe({scriptLocation:t,query:e,loadAsync:n=!0,crossOrigin:r="anonymous",apihost:s="https://js.hcaptcha.com",cleanup:i=!1,secureApi:a=!1,scriptSource:h=""}={},o){let c=Z(t),u=Y(c);return new Promise((y,v)=>{let d=u.document.createElement("script");d.id=ye,h?d.src=`${h}?onload=${q}`:a?d.src=`${s}/1/secure-api.js?onload=${q}`:d.src=`${s}/1/api.js?onload=${q}`,d.crossOrigin=r,d.async=n;let E=(x,C)=>{try{!a&&i&&c.removeChild(d),C(x)}catch(S){v(S)}};d.onload=x=>E(x,y),d.onerror=x=>{o&&o(d.src),E(x,v)},d.src+=e!==""?`&${e}`:"",c.appendChild(d)})}var A=[];function Ne(t={cleanup:!1},e){try{e.addBreadcrumb({category:w,message:"hCaptcha loader params",data:t});let n=Z(t.scriptLocation),r=Y(n),s=A.find(({scope:a})=>a===r.window);if(s)return e.addBreadcrumb({category:w,message:"hCaptcha already loaded"}),s.promise;let i=new Promise((a,h)=>R(this,null,function*(){try{r.window[q]=()=>{e.addBreadcrumb({category:w,message:"hCaptcha script called onload function"}),a(r.window.hcaptcha)};let o=ve({custom:t.custom,render:t.render,sentry:t.sentry,assethost:t.assethost,imghost:t.imghost,reportapi:t.reportapi,endpoint:t.endpoint,host:t.host,recaptchacompat:t.recaptchacompat,hl:t.hl,uj:t.uj});yield Fe(m({query:o},t),c=>{e.captureRequest({url:c,method:"GET"})}),e.addBreadcrumb({category:w,message:"hCaptcha loaded",data:s})}catch{e.addBreadcrumb({category:w,message:"hCaptcha failed to load"});let c=A.findIndex(u=>u.scope===r.window);c!==-1&&A.splice(c,1),h(new Error(V))}}));return A.push({promise:i,scope:r.window}),i}catch(n){return e.captureException(n),Promise.reject(new Error(V))}}function te(t,e,n=0){return R(this,null,function*(){var r,s;let i=(r=t.maxRetries)!=null?r:2,a=(s=t.retryDelay)!=null?s:1e3,h=n<i?"Retry loading hCaptcha Api":"Exceeded maximum retries";try{return yield Ne(t,e)}catch(o){return e.addBreadcrumb({category:w,message:h}),n>=i?(e.captureException(o),Promise.reject(o)):(e.addBreadcrumb({category:w,message:`Waiting ${a}ms before retry attempt ${n+1}`}),yield we(a),n+=1,te(t,e,n))}})}function ne(){return R(this,arguments,function*(t={}){let e=$e(t.sentry);return yield te(t,e)})}function H(t){let e=t&&t.ownerDocument||document,n=e.defaultView||e.parentWindow||window;return{document:e,window:n}}function B(t){return t||document.head}var P=class extends _.Component{constructor(e){super(e),this._hcaptcha=void 0,this.renderCaptcha=this.renderCaptcha.bind(this),this.resetCaptcha=this.resetCaptcha.bind(this),this.removeCaptcha=this.removeCaptcha.bind(this),this.isReady=this.isReady.bind(this),this._onReady=null,this.loadCaptcha=this.loadCaptcha.bind(this),this.handleOnLoad=this.handleOnLoad.bind(this),this.handleSubmit=this.handleSubmit.bind(this),this.handleExpire=this.handleExpire.bind(this),this.handleError=this.handleError.bind(this),this.handleOpen=this.handleOpen.bind(this),this.handleClose=this.handleClose.bind(this),this.handleChallengeExpired=this.handleChallengeExpired.bind(this),this.ref=_.createRef(),this.apiScriptRequested=!1,this.sentryHub=null,this.captchaId="",this._pendingExecute=null,this.state={isApiReady:!1,isRemoved:!1,elementId:e.id}}componentDidMount(){let e=B(this.props.scriptLocation),n=H(e);if(this._hcaptcha=n.window.hcaptcha||void 0,typeof this._hcaptcha<"u"){this.setState({isApiReady:!0},()=>{this.renderCaptcha()});return}this.loadCaptcha()}componentWillUnmount(){let e=this._hcaptcha,n=this.captchaId;this._cancelPendingExecute("react-component-unmounted"),this.isReady()&&(e.reset(n),e.remove(n))}shouldComponentUpdate(e,n){return!(this.state.isApiReady!==n.isApiReady||this.state.isRemoved!==n.isRemoved)}componentDidUpdate(e){["sitekey","size","theme","tabindex","languageOverride","endpoint"].every(s=>e[s]===this.props[s])||this.removeCaptcha(()=>{this.renderCaptcha()})}loadCaptcha(){if(this.apiScriptRequested)return;let{apihost:e,assethost:n,endpoint:r,host:s,imghost:i,languageOverride:a,reCaptchaCompat:h,reportapi:o,sentry:c,custom:u,loadAsync:y,scriptLocation:v,scriptSource:d,secureApi:E,cleanup:x=!0,userJourneys:C}=this.props;ne({render:"explicit",apihost:e,assethost:n,endpoint:r,hl:a,host:s,imghost:i,recaptchacompat:h===!1?"off":null,reportapi:o,sentry:c,custom:u,loadAsync:y,scriptLocation:v,scriptSource:d,secureApi:E,cleanup:x,uj:C!==void 0?C:!1}).then(this.handleOnLoad,this.handleError).catch(this.handleError),this.apiScriptRequested=!0}renderCaptcha(e){let{onReady:n}=this.props,{isApiReady:r}=this.state,s=this.captchaId;if(!r||s)return;let i=Object.assign({"open-callback":this.handleOpen,"close-callback":this.handleClose,"error-callback":this.handleError,"chalexpired-callback":this.handleChallengeExpired,"expired-callback":this.handleExpire,callback:this.handleSubmit},this.props,{hl:this.props.hl||this.props.languageOverride,languageOverride:void 0}),h=this._hcaptcha.render(this.ref.current,i);this.captchaId=h,this.setState({isRemoved:!1},()=>{e&&e(),n&&n(),this._onReady&&this._onReady(h)})}resetCaptcha(){let e=this._hcaptcha,n=this.captchaId;this.isReady()&&(e.reset(n),this._cancelPendingExecute("hcaptcha-reset"))}removeCaptcha(e){let n=this._hcaptcha,r=this.captchaId;this._cancelPendingExecute("hcaptcha-removed"),this.isReady()&&this.setState({isRemoved:!0},()=>{this.captchaId="",n.remove(r),e&&e()})}handleOnLoad(){this.setState({isApiReady:!0},()=>{let e=B(this.props.scriptLocation),n=H(e);this._hcaptcha=n.window.hcaptcha,this.renderCaptcha(()=>{let{onLoad:r}=this.props;r&&r()})})}handleSubmit(e){let{onVerify:n}=this.props,{isRemoved:r}=this.state,s=this._hcaptcha,i=this.captchaId;if(typeof s>"u"||r)return;let a=s.getResponse(i),h=s.getRespKey(i);n&&n(a,h)}handleExpire(){let{onExpire:e}=this.props,n=this._hcaptcha,r=this.captchaId;this.isReady()&&(n.reset(r),e&&e())}handleError(e){let{onError:n}=this.props,r=this._hcaptcha,s=this.captchaId;this.isReady()&&r.reset(s),n&&n(e)}isReady(){let{isApiReady:e,isRemoved:n}=this.state;return e&&!n}_cancelPendingExecute(e){if(!this._pendingExecute)return;let n=this._pendingExecute;this._pendingExecute=null;let r=new Error(e);n.reject(r)}handleOpen(){!this.isReady()||!this.props.onOpen||this.props.onOpen()}handleClose(){!this.isReady()||!this.props.onClose||this.props.onClose()}handleChallengeExpired(){!this.isReady()||!this.props.onChalExpired||this.props.onChalExpired()}execute(e=null){e=typeof e=="object"?e:null;try{let n=this._hcaptcha,r=this.captchaId;if(e&&e.async&&this._pendingExecute&&this._cancelPendingExecute("hcaptcha-execute-replaced"),!this.isReady())return e&&e.async?new Promise((i,a)=>{this._pendingExecute={resolve:i,reject:a},this._onReady=h=>{if(this._pendingExecute)try{let o=n.execute(h,e);o&&typeof o.then=="function"?o.then(c=>{this._pendingExecute=null,i(c)}).catch(c=>{this._pendingExecute=null,a(c)}):(this._pendingExecute=null,a(new Error("hcaptcha-execute-no-promise")))}catch(o){this._pendingExecute=null,a(o)}}}):(this._onReady=i=>{n.execute(i,e)},null);let s=n.execute(r,e);return e&&e.async&&s&&typeof s.then=="function"?new Promise((i,a)=>{this._pendingExecute={resolve:i,reject:a},s.then(h=>{this._pendingExecute=null,i(h)}).catch(h=>{this._pendingExecute=null,a(h)})}):s}catch(n){return e&&e.async?Promise.reject(n):null}}close(){let e=this._hcaptcha,n=this.captchaId;if(this._cancelPendingExecute("hcaptcha-closed"),!!this.isReady())return e.close(n)}setData(e){let n=this._hcaptcha,r=this.captchaId;this.isReady()&&(e&&typeof e!="object"&&(e=null),n.setData(r,e))}getResponse(){return this._hcaptcha.getResponse(this.captchaId)}getRespKey(){return this._hcaptcha.getRespKey(this.captchaId)}render(){let{elementId:e}=this.state;return _.createElement("div",{ref:this.ref,id:e})}};var re=P;function D({sitekey:t=null,size:e="normal",theme:n="light",rqdata:r=null,languageOverride:s=null,onVerify:i,onError:a,children:h}){let o=(0,g.useRef)(null),[c,u]=(0,g.useState)(!1),[y,v]=(0,g.useState)(null),[d,E]=(0,g.useState)(null),x=()=>{u(!0)},C=b=>{E(b),a&&a(b)},S=()=>{v(null)},se=b=>{v(b),i&&i(b)},ie=async(b={})=>{try{if(!c)throw new Error("hCaptcha not ready");y&&$();let{response:O}=await o.current.execute({async:!0,...b.rqdata?{rqdata:b.rqdata}:{}});return v(O),O}catch(O){E(O),a&&a(O)}},$=()=>{o?.current?.resetCaptcha()};return(0,g.useEffect)(()=>{r&&o?.current?.setData(r)},[r]),g.default.createElement(k.Provider,{value:{sitekey:t,error:d,token:y,ready:c,executeInstance:ie,resetInstance:$}},h,g.default.createElement(re,{sitekey:t,size:e,theme:n,languageOverride:s,onReady:x,onVerify:se,onExpire:S,onError:C,ref:o}))}
@@ -0,0 +1,4 @@
1
+ var ae=Object.create;var I=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var he=Object.getPrototypeOf,le=Object.prototype.hasOwnProperty;var ue=(t,e)=>{for(var n in e)I(t,n,{get:e[n],enumerable:!0})},N=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ce(e))!le.call(t,s)&&s!==n&&I(t,s,{get:()=>e[s],enumerable:!(r=oe(e,s))||r.enumerable});return t};var W=(t,e,n)=>(n=t!=null?ae(he(t)):{},N(e||!t||!t.__esModule?I(n,"default",{value:t,enumerable:!0}):n,t)),de=t=>N(I({},"__esModule",{value:!0}),t);var We={};ue(We,{HCaptcha:()=>_,HCaptchaProvider:()=>D,default:()=>$,useHCaptcha:()=>B});module.exports=de(We);var O=W(require("react"),1);var pe=Object.defineProperty,fe=Object.defineProperties,me=Object.getOwnPropertyDescriptors,q=Object.getOwnPropertySymbols,K=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable,M=(t,e,n)=>e in t?pe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,m=(t,e)=>{for(var n in e||(e={}))K.call(e,n)&&M(t,n,e[n]);if(q)for(var n of q(e))G.call(e,n)&&M(t,n,e[n]);return t},X=(t,e)=>fe(t,me(e)),ge=(t,e)=>{var n={};for(var r in t)K.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&q)for(var r of q(t))e.indexOf(r)<0&&G.call(t,r)&&(n[r]=t[r]);return n},l=(t,e,n)=>(M(t,typeof e!="symbol"?e+"":e,n),n),R=(t,e,n)=>new Promise((r,s)=>{var i=o=>{try{h(n.next(o))}catch(c){s(c)}},a=o=>{try{h(n.throw(o))}catch(c){s(c)}},h=o=>o.done?r(o.value):Promise.resolve(o.value).then(i,a);h((n=n.apply(t,e)).next())}),ye="hCaptcha-script",A="hCaptchaOnLoad",z="script-error",w="@hCaptcha/loader";function ve(t){return Object.entries(t).filter(([,e])=>e||e===!1).map(([e,n])=>`${encodeURIComponent(e)}=${encodeURIComponent(String(n))}`).join("&")}function Q(t){let e=t&&t.ownerDocument||document,n=e.defaultView||e.parentWindow||window;return{document:e,window:n}}function Y(t){return t||document.head}function xe(t){var e;t.setTag("source",w),t.setTag("url",document.URL),t.setContext("os",{UA:navigator.userAgent}),t.setContext("browser",m({},be())),t.setContext("device",X(m({},Ee()),{screen_width_pixels:screen.width,screen_height_pixels:screen.height,language:navigator.language,orientation:((e=screen.orientation)==null?void 0:e.type)||"Unknown",processor_count:navigator.hardwareConcurrency,platform:navigator.platform}))}function be(){var t,e,n,r,s,i;let a=navigator.userAgent,h,o;return a.indexOf("Firefox")!==-1?(h="Firefox",o=(t=a.match(/Firefox\/([\d.]+)/))==null?void 0:t[1]):a.indexOf("Edg")!==-1?(h="Microsoft Edge",o=(e=a.match(/Edg\/([\d.]+)/))==null?void 0:e[1]):a.indexOf("Chrome")!==-1&&a.indexOf("Safari")!==-1?(h="Chrome",o=(n=a.match(/Chrome\/([\d.]+)/))==null?void 0:n[1]):a.indexOf("Safari")!==-1&&a.indexOf("Chrome")===-1?(h="Safari",o=(r=a.match(/Version\/([\d.]+)/))==null?void 0:r[1]):a.indexOf("Opera")!==-1||a.indexOf("OPR")!==-1?(h="Opera",o=(s=a.match(/(Opera|OPR)\/([\d.]+)/))==null?void 0:s[2]):a.indexOf("MSIE")!==-1||a.indexOf("Trident")!==-1?(h="Internet Explorer",o=(i=a.match(/(MSIE |rv:)([\d.]+)/))==null?void 0:i[2]):(h="Unknown",o="Unknown"),{name:h,version:o}}function we(t){return new Promise(e=>setTimeout(e,t))}function Ee(){let t=navigator.userAgent,e;t.indexOf("Win")!==-1?e="Windows":t.indexOf("Mac")!==-1?e="Mac":t.indexOf("Linux")!==-1?e="Linux":t.indexOf("Android")!==-1?e="Android":t.indexOf("like Mac")!==-1||t.indexOf("iPhone")!==-1||t.indexOf("iPad")!==-1?e="iOS":e="Unknown";let n;return/Mobile|iPhone|iPod|Android/i.test(t)?n="Mobile":/Tablet|iPad/i.test(t)?n="Tablet":n="Desktop",{model:e,family:e,device:n}}var Ce=class Z{constructor(e){l(this,"_parent"),l(this,"breadcrumbs",[]),l(this,"context",{}),l(this,"extra",{}),l(this,"tags",{}),l(this,"request"),l(this,"user"),this._parent=e}get parent(){return this._parent}child(){return new Z(this)}setRequest(e){return this.request=e,this}removeRequest(){return this.request=void 0,this}addBreadcrumb(e){return typeof e.timestamp>"u"&&(e.timestamp=new Date().toISOString()),this.breadcrumbs.push(e),this}setExtra(e,n){return this.extra[e]=n,this}removeExtra(e){return delete this.extra[e],this}setContext(e,n){return typeof n.type>"u"&&(n.type=e),this.context[e]=n,this}removeContext(e){return delete this.context[e],this}setTags(e){return this.tags=m(m({},this.tags),e),this}setTag(e,n){return this.tags[e]=n,this}removeTag(e){return delete this.tags[e],this}setUser(e){return this.user=e,this}removeUser(){return this.user=void 0,this}toBody(){let e=[],n=this;for(;n;)e.push(n),n=n.parent;return e.reverse().reduce((r,s)=>{var i;return r.breadcrumbs=[...(i=r.breadcrumbs)!=null?i:[],...s.breadcrumbs],r.extra=m(m({},r.extra),s.extra),r.contexts=m(m({},r.contexts),s.context),r.tags=m(m({},r.tags),s.tags),s.user&&(r.user=s.user),s.request&&(r.request=s.request),r},{breadcrumbs:[],extra:{},contexts:{},tags:{},request:void 0,user:void 0})}clear(){this.breadcrumbs=[],this.context={},this.tags={},this.user=void 0}},Re=/^\s*at (?:(.*?) ?\()?((?:file|https?|blob|chrome-extension|address|native|eval|webpack|<anonymous>|[-a-z]+:|.*bundle|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,_e=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:file|https?|blob|chrome|webpack|resource|moz-extension).*?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js))(?::(\d+))?(?::(\d+))?\s*$/i,Oe=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i,Pe=/^(?:(\w+):)\/\/(?:(\w+)(?::(\w+))?@)([\w.-]+)(?::(\d+))?\/(.+)/,k="?",V="An unknown error occurred",Se="0.0.4";function Ie(t){for(let e=0;e<t.length;e++)t[e]=Math.floor(Math.random()*256);return t}function p(t){return(t+256).toString(16).substring(1)}function ke(){let t=Ie(new Array(16));return t[6]=t[6]&15|64,t[8]=t[8]&63|128,p(t[0])+p(t[1])+p(t[2])+p(t[3])+"-"+p(t[4])+p(t[5])+"-"+p(t[6])+p(t[7])+"-"+p(t[8])+p(t[9])+"-"+p(t[10])+p(t[11])+p(t[12])+p(t[13])+p(t[14])+p(t[15])}var je=[[Re,"chrome"],[Oe,"winjs"],[_e,"gecko"]];function Ae(t){var e,n,r,s;if(!t.stack)return null;let i=[],a=(r=(n=(e=t.stack).split)==null?void 0:n.call(e,`
2
+ `))!=null?r:[];for(let h=0;h<a.length;++h){let o=null,c=null,u=null;for(let[y,v]of je)if(c=y.exec(a[h]),c){u=v;break}if(!(!c||!u)){if(u==="chrome")o={filename:(s=c[2])!=null&&s.startsWith("address at ")?c[2].substring(11):c[2],function:c[1]||k,lineno:c[3]?+c[3]:null,colno:c[4]?+c[4]:null};else if(u==="winjs")o={filename:c[2],function:c[1]||k,lineno:+c[3],colno:c[4]?+c[4]:null};else if(u==="gecko")h===0&&!c[5]&&t.columnNumber!==void 0&&i.length>0&&(i[0].column=t.columnNumber+1),o={filename:c[3],function:c[1]||k,lineno:c[4]?+c[4]:null,colno:c[5]?+c[5]:null};else continue;!o.function&&o.lineno&&(o.function=k),i.push(o)}}return i.length?i.reverse():null}function qe(t){let e=Ae(t);return{type:t.name,value:t.message,stacktrace:{frames:e??[]}}}function Le(t){let e=Pe.exec(t),n=e?e.slice(1):[];if(n.length!==6)throw new Error("Invalid DSN");let r=n[5].split("/"),s=r.slice(0,-1).join("/");return n[0]+"://"+n[3]+(n[4]?":"+n[4]:"")+(s?"/"+s:"")+"/api/"+r.pop()+"/envelope/?sentry_version=7&sentry_key="+n[1]+(n[2]?"&sentry_secret="+n[2]:"")}function Me(t,e,n){var r,s;let i=m({event_id:ke().replaceAll("-",""),platform:"javascript",sdk:{name:"@hcaptcha/sentry",version:Se},environment:e,release:n,timestamp:Date.now()/1e3},t.scope.toBody());if(t.type==="exception"){i.message=(s=(r=t.error)==null?void 0:r.message)!=null?s:"Unknown error",i.fingerprint=[i.message];let a=[],h=t.error;for(let o=0;o<5&&h&&(a.push(qe(h)),!(!h.cause||!(h.cause instanceof Error)));o++)h=h.cause;i.exception={values:a.reverse()}}return t.type==="message"&&(i.message=t.message,i.level=t.level),i}function Te(t){if(t instanceof Error)return t;if(typeof t=="string")return new Error(t);if(typeof t=="object"&&t!==null&&!Array.isArray(t)){let n=t,{message:r}=n,s=ge(n,["message"]),i=new Error(typeof r=="string"?r:V);return Object.assign(i,s)}let e=new Error(V);return Object.assign(e,{cause:t})}function Ue(t,e,n){return R(this,null,function*(){var r,s;try{if(typeof fetch<"u"&&typeof AbortSignal<"u"){let i;if(n){let o=new AbortController;i=o.signal,setTimeout(()=>o.abort(),n)}let a=yield fetch(t,X(m({},e),{signal:i})),h=yield a.text();return{status:a.status,body:h}}return yield new Promise((i,a)=>{var h,o;let c=new XMLHttpRequest;if(c.open((h=e?.method)!=null?h:"GET",t),c.onload=()=>i({status:c.status,body:c.responseText}),c.onerror=()=>a(new Error("XHR Network Error")),e?.headers)for(let[u,y]of Object.entries(e.headers))c.setRequestHeader(u,y);if(n){let u=setTimeout(()=>{c.abort(),a(new Error("Request timed out"))},n);c.onloadend=()=>{clearTimeout(u)}}c.send((o=e?.body)==null?void 0:o.toString())})}catch(i){return{status:0,body:(s=(r=i?.toString)==null?void 0:r.call(i))!=null?s:"Unknown error"}}})}var f,T=(f=class{constructor(t){l(this,"apiURL"),l(this,"dsn"),l(this,"environment"),l(this,"release"),l(this,"sampleRate"),l(this,"debug"),l(this,"_scope"),l(this,"shouldBuffer",!1),l(this,"bufferlimit",20),l(this,"buffer",[]);var e,n,r,s,i;this.environment=t.environment,this.release=t.release,this.sampleRate=(e=t.sampleRate)!=null?e:1,this.debug=(n=t.debug)!=null?n:!1,this._scope=(r=t.scope)!=null?r:new Ce,this.apiURL=Le(t.dsn),this.dsn=t.dsn,this.shouldBuffer=(s=t.buffer)!=null?s:!1,this.bufferlimit=(i=t.bufferLimit)!=null?i:20}static init(t){f._instance||(f._instance=new f(t))}static get instance(){if(!f._instance)throw new Error("Sentry has not been initialized");return f._instance}log(...t){this.debug&&console.log(...t)}get scope(){return this._scope}static get scope(){return f.instance.scope}withScope(t){let e=this._scope.child();t(e)}static withScope(t){f.instance.withScope(t)}captureException(t,e){this.captureEvent({type:"exception",level:"error",error:Te(t),scope:e??this._scope})}static captureException(t,e){f.instance.captureException(t,e)}captureMessage(t,e="info",n){this.captureEvent({type:"message",level:e,message:t,scope:n??this._scope})}static captureMessage(t,e="info",n){f.instance.captureMessage(t,e,n)}captureEvent(t){if(Math.random()>=this.sampleRate){this.log("Dropped event due to sample rate");return}if(this.shouldBuffer){if(this.buffer.length>=this.bufferlimit)return;this.buffer.push(t)}else this.sendEvent(t)}sendEvent(t,e=5e3){return R(this,null,function*(){try{this.log("Sending sentry event",t);let n=Me(t,this.environment,this.release),r={event_id:n.event_id,dsn:this.dsn},s={type:"event"},i=JSON.stringify(r)+`
3
+ `+JSON.stringify(s)+`
4
+ `+JSON.stringify(n),a=yield Ue(this.apiURL,{method:"POST",headers:{"Content-Type":"application/x-sentry-envelope"},body:i},e);this.log("Sentry response",a.status),a.status!==200&&(console.log(a.body),console.error("Failed to send event to Sentry",a))}catch(n){console.error("Failed to send event",n)}})}flush(t=5e3){return R(this,null,function*(){try{this.log("Flushing sentry events",this.buffer.length);let e=this.buffer.splice(0,this.buffer.length).map(n=>this.sendEvent(n,t));yield Promise.all(e),this.log("Flushed all events")}catch(e){console.error("Failed to flush events",e)}})}static flush(t=5e3){return f.instance.flush(t)}static reset(){f._instance=void 0}},l(f,"_instance"),f),He="https://d233059272824702afc8c43834c4912d@sentry.hcaptcha.com/6",Be="2.3.0",De="production";function $e(t=!0){if(!t)return J();T.init({dsn:He,release:Be,environment:De});let e=T.scope;return xe(e),J(e)}function J(t=null){return{addBreadcrumb:e=>{t&&t.addBreadcrumb(e)},captureRequest:e=>{t&&t.setRequest(e)},captureException:e=>{t&&T.captureException(e,t)}}}function Fe({scriptLocation:t,query:e,loadAsync:n=!0,crossOrigin:r="anonymous",apihost:s="https://js.hcaptcha.com",cleanup:i=!1,secureApi:a=!1,scriptSource:h=""}={},o){let c=Y(t),u=Q(c);return new Promise((y,v)=>{let d=u.document.createElement("script");d.id=ye,h?d.src=`${h}?onload=${A}`:a?d.src=`${s}/1/secure-api.js?onload=${A}`:d.src=`${s}/1/api.js?onload=${A}`,d.crossOrigin=r,d.async=n;let E=(x,C)=>{try{!a&&i&&c.removeChild(d),C(x)}catch(S){v(S)}};d.onload=x=>E(x,y),d.onerror=x=>{o&&o(d.src),E(x,v)},d.src+=e!==""?`&${e}`:"",c.appendChild(d)})}var j=[];function Ne(t={cleanup:!1},e){try{e.addBreadcrumb({category:w,message:"hCaptcha loader params",data:t});let n=Y(t.scriptLocation),r=Q(n),s=j.find(({scope:a})=>a===r.window);if(s)return e.addBreadcrumb({category:w,message:"hCaptcha already loaded"}),s.promise;let i=new Promise((a,h)=>R(this,null,function*(){try{r.window[A]=()=>{e.addBreadcrumb({category:w,message:"hCaptcha script called onload function"}),a(r.window.hcaptcha)};let o=ve({custom:t.custom,render:t.render,sentry:t.sentry,assethost:t.assethost,imghost:t.imghost,reportapi:t.reportapi,endpoint:t.endpoint,host:t.host,recaptchacompat:t.recaptchacompat,hl:t.hl,uj:t.uj});yield Fe(m({query:o},t),c=>{e.captureRequest({url:c,method:"GET"})}),e.addBreadcrumb({category:w,message:"hCaptcha loaded",data:s})}catch{e.addBreadcrumb({category:w,message:"hCaptcha failed to load"});let c=j.findIndex(u=>u.scope===r.window);c!==-1&&j.splice(c,1),h(new Error(z))}}));return j.push({promise:i,scope:r.window}),i}catch(n){return e.captureException(n),Promise.reject(new Error(z))}}function ee(t,e,n=0){return R(this,null,function*(){var r,s;let i=(r=t.maxRetries)!=null?r:2,a=(s=t.retryDelay)!=null?s:1e3,h=n<i?"Retry loading hCaptcha Api":"Exceeded maximum retries";try{return yield Ne(t,e)}catch(o){return e.addBreadcrumb({category:w,message:h}),n>=i?(e.captureException(o),Promise.reject(o)):(e.addBreadcrumb({category:w,message:`Waiting ${a}ms before retry attempt ${n+1}`}),yield we(a),n+=1,ee(t,e,n))}})}function te(){return R(this,arguments,function*(t={}){let e=$e(t.sentry);return yield ee(t,e)})}function U(t){let e=t&&t.ownerDocument||document,n=e.defaultView||e.parentWindow||window;return{document:e,window:n}}function H(t){return t||document.head}var _=class extends O.Component{constructor(e){super(e),this._hcaptcha=void 0,this.renderCaptcha=this.renderCaptcha.bind(this),this.resetCaptcha=this.resetCaptcha.bind(this),this.removeCaptcha=this.removeCaptcha.bind(this),this.isReady=this.isReady.bind(this),this._onReady=null,this.loadCaptcha=this.loadCaptcha.bind(this),this.handleOnLoad=this.handleOnLoad.bind(this),this.handleSubmit=this.handleSubmit.bind(this),this.handleExpire=this.handleExpire.bind(this),this.handleError=this.handleError.bind(this),this.handleOpen=this.handleOpen.bind(this),this.handleClose=this.handleClose.bind(this),this.handleChallengeExpired=this.handleChallengeExpired.bind(this),this.ref=O.createRef(),this.apiScriptRequested=!1,this.sentryHub=null,this.captchaId="",this._pendingExecute=null,this.state={isApiReady:!1,isRemoved:!1,elementId:e.id}}componentDidMount(){let e=H(this.props.scriptLocation),n=U(e);if(this._hcaptcha=n.window.hcaptcha||void 0,typeof this._hcaptcha<"u"){this.setState({isApiReady:!0},()=>{this.renderCaptcha()});return}this.loadCaptcha()}componentWillUnmount(){let e=this._hcaptcha,n=this.captchaId;this._cancelPendingExecute("react-component-unmounted"),this.isReady()&&(e.reset(n),e.remove(n))}shouldComponentUpdate(e,n){return!(this.state.isApiReady!==n.isApiReady||this.state.isRemoved!==n.isRemoved)}componentDidUpdate(e){["sitekey","size","theme","tabindex","languageOverride","endpoint"].every(s=>e[s]===this.props[s])||this.removeCaptcha(()=>{this.renderCaptcha()})}loadCaptcha(){if(this.apiScriptRequested)return;let{apihost:e,assethost:n,endpoint:r,host:s,imghost:i,languageOverride:a,reCaptchaCompat:h,reportapi:o,sentry:c,custom:u,loadAsync:y,scriptLocation:v,scriptSource:d,secureApi:E,cleanup:x=!0,userJourneys:C}=this.props;te({render:"explicit",apihost:e,assethost:n,endpoint:r,hl:a,host:s,imghost:i,recaptchacompat:h===!1?"off":null,reportapi:o,sentry:c,custom:u,loadAsync:y,scriptLocation:v,scriptSource:d,secureApi:E,cleanup:x,uj:C!==void 0?C:!1}).then(this.handleOnLoad,this.handleError).catch(this.handleError),this.apiScriptRequested=!0}renderCaptcha(e){let{onReady:n}=this.props,{isApiReady:r}=this.state,s=this.captchaId;if(!r||s)return;let i=Object.assign({"open-callback":this.handleOpen,"close-callback":this.handleClose,"error-callback":this.handleError,"chalexpired-callback":this.handleChallengeExpired,"expired-callback":this.handleExpire,callback:this.handleSubmit},this.props,{hl:this.props.hl||this.props.languageOverride,languageOverride:void 0}),h=this._hcaptcha.render(this.ref.current,i);this.captchaId=h,this.setState({isRemoved:!1},()=>{e&&e(),n&&n(),this._onReady&&this._onReady(h)})}resetCaptcha(){let e=this._hcaptcha,n=this.captchaId;this.isReady()&&(e.reset(n),this._cancelPendingExecute("hcaptcha-reset"))}removeCaptcha(e){let n=this._hcaptcha,r=this.captchaId;this._cancelPendingExecute("hcaptcha-removed"),this.isReady()&&this.setState({isRemoved:!0},()=>{this.captchaId="",n.remove(r),e&&e()})}handleOnLoad(){this.setState({isApiReady:!0},()=>{let e=H(this.props.scriptLocation),n=U(e);this._hcaptcha=n.window.hcaptcha,this.renderCaptcha(()=>{let{onLoad:r}=this.props;r&&r()})})}handleSubmit(e){let{onVerify:n}=this.props,{isRemoved:r}=this.state,s=this._hcaptcha,i=this.captchaId;if(typeof s>"u"||r)return;let a=s.getResponse(i),h=s.getRespKey(i);n&&n(a,h)}handleExpire(){let{onExpire:e}=this.props,n=this._hcaptcha,r=this.captchaId;this.isReady()&&(n.reset(r),e&&e())}handleError(e){let{onError:n}=this.props,r=this._hcaptcha,s=this.captchaId;this.isReady()&&r.reset(s),n&&n(e)}isReady(){let{isApiReady:e,isRemoved:n}=this.state;return e&&!n}_cancelPendingExecute(e){if(!this._pendingExecute)return;let n=this._pendingExecute;this._pendingExecute=null;let r=new Error(e);n.reject(r)}handleOpen(){!this.isReady()||!this.props.onOpen||this.props.onOpen()}handleClose(){!this.isReady()||!this.props.onClose||this.props.onClose()}handleChallengeExpired(){!this.isReady()||!this.props.onChalExpired||this.props.onChalExpired()}execute(e=null){e=typeof e=="object"?e:null;try{let n=this._hcaptcha,r=this.captchaId;if(e&&e.async&&this._pendingExecute&&this._cancelPendingExecute("hcaptcha-execute-replaced"),!this.isReady())return e&&e.async?new Promise((i,a)=>{this._pendingExecute={resolve:i,reject:a},this._onReady=h=>{if(this._pendingExecute)try{let o=n.execute(h,e);o&&typeof o.then=="function"?o.then(c=>{this._pendingExecute=null,i(c)}).catch(c=>{this._pendingExecute=null,a(c)}):(this._pendingExecute=null,a(new Error("hcaptcha-execute-no-promise")))}catch(o){this._pendingExecute=null,a(o)}}}):(this._onReady=i=>{n.execute(i,e)},null);let s=n.execute(r,e);return e&&e.async&&s&&typeof s.then=="function"?new Promise((i,a)=>{this._pendingExecute={resolve:i,reject:a},s.then(h=>{this._pendingExecute=null,i(h)}).catch(h=>{this._pendingExecute=null,a(h)})}):s}catch(n){return e&&e.async?Promise.reject(n):null}}close(){let e=this._hcaptcha,n=this.captchaId;if(this._cancelPendingExecute("hcaptcha-closed"),!!this.isReady())return e.close(n)}setData(e){let n=this._hcaptcha,r=this.captchaId;this.isReady()&&(e&&typeof e!="object"&&(e=null),n.setData(r,e))}getResponse(){return this._hcaptcha.getResponse(this.captchaId)}getRespKey(){return this._hcaptcha.getRespKey(this.captchaId)}render(){let{elementId:e}=this.state;return O.createElement("div",{ref:this.ref,id:e})}};var re=require("react");var ne=require("react"),L=(0,ne.createContext)();var B=()=>(0,re.useContext)(L);var g=W(require("react"),1);function D({sitekey:t=null,size:e="normal",theme:n="light",rqdata:r=null,languageOverride:s=null,onVerify:i,onError:a,children:h}){let o=(0,g.useRef)(null),[c,u]=(0,g.useState)(!1),[y,v]=(0,g.useState)(null),[d,E]=(0,g.useState)(null),x=()=>{u(!0)},C=b=>{E(b),a&&a(b)},S=()=>{v(null)},se=b=>{v(b),i&&i(b)},ie=async(b={})=>{try{if(!c)throw new Error("hCaptcha not ready");y&&F();let{response:P}=await o.current.execute({async:!0,...b.rqdata?{rqdata:b.rqdata}:{}});return v(P),P}catch(P){E(P),a&&a(P)}},F=()=>{o?.current?.resetCaptcha()};return(0,g.useEffect)(()=>{r&&o?.current?.setData(r)},[r]),g.default.createElement(L.Provider,{value:{sitekey:t,error:d,token:y,ready:c,executeInstance:ie,resetInstance:F}},h,g.default.createElement($,{sitekey:t,size:e,theme:n,languageOverride:s,onReady:x,onVerify:se,onExpire:S,onError:C,ref:o}))}var $=_;
@@ -0,0 +1,4 @@
1
+ var ae=Object.defineProperty;var B=Object.getOwnPropertySymbols;var oe=Object.prototype.hasOwnProperty,ce=Object.prototype.propertyIsEnumerable;var D=(t,e,n)=>e in t?ae(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,$=(t,e)=>{for(var n in e||(e={}))oe.call(e,n)&&D(t,n,e[n]);if(B)for(var n of B(e))ce.call(e,n)&&D(t,n,e[n]);return t};var F=(t,e,n)=>new Promise((r,i)=>{var a=s=>{try{h(n.next(s))}catch(c){i(c)}},o=s=>{try{h(n.throw(s))}catch(c){i(c)}},h=s=>s.done?r(s.value):Promise.resolve(s.value).then(a,o);h((n=n.apply(t,e)).next())});import{useContext as le}from"react";import{createContext as he}from"react";var S=he();var N=()=>le(S);import re,{useEffect as Fe,useRef as Ne,useState as U}from"react";import*as R from"react";var ue=Object.defineProperty,de=Object.defineProperties,pe=Object.getOwnPropertyDescriptors,A=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable,q=(t,e,n)=>e in t?ue(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,g=(t,e)=>{for(var n in e||(e={}))J.call(e,n)&&q(t,n,e[n]);if(A)for(var n of A(e))K.call(e,n)&&q(t,n,e[n]);return t},G=(t,e)=>de(t,pe(e)),fe=(t,e)=>{var n={};for(var r in t)J.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&A)for(var r of A(t))e.indexOf(r)<0&&K.call(t,r)&&(n[r]=t[r]);return n},l=(t,e,n)=>(q(t,typeof e!="symbol"?e+"":e,n),n),C=(t,e,n)=>new Promise((r,i)=>{var a=s=>{try{h(n.next(s))}catch(c){i(c)}},o=s=>{try{h(n.throw(s))}catch(c){i(c)}},h=s=>s.done?r(s.value):Promise.resolve(s.value).then(a,o);h((n=n.apply(t,e)).next())}),me="hCaptcha-script",j="hCaptchaOnLoad",W="script-error",b="@hCaptcha/loader";function ge(t){return Object.entries(t).filter(([,e])=>e||e===!1).map(([e,n])=>`${encodeURIComponent(e)}=${encodeURIComponent(String(n))}`).join("&")}function X(t){let e=t&&t.ownerDocument||document,n=e.defaultView||e.parentWindow||window;return{document:e,window:n}}function Q(t){return t||document.head}function ye(t){var e;t.setTag("source",b),t.setTag("url",document.URL),t.setContext("os",{UA:navigator.userAgent}),t.setContext("browser",g({},ve())),t.setContext("device",G(g({},be()),{screen_width_pixels:screen.width,screen_height_pixels:screen.height,language:navigator.language,orientation:((e=screen.orientation)==null?void 0:e.type)||"Unknown",processor_count:navigator.hardwareConcurrency,platform:navigator.platform}))}function ve(){var t,e,n,r,i,a;let o=navigator.userAgent,h,s;return o.indexOf("Firefox")!==-1?(h="Firefox",s=(t=o.match(/Firefox\/([\d.]+)/))==null?void 0:t[1]):o.indexOf("Edg")!==-1?(h="Microsoft Edge",s=(e=o.match(/Edg\/([\d.]+)/))==null?void 0:e[1]):o.indexOf("Chrome")!==-1&&o.indexOf("Safari")!==-1?(h="Chrome",s=(n=o.match(/Chrome\/([\d.]+)/))==null?void 0:n[1]):o.indexOf("Safari")!==-1&&o.indexOf("Chrome")===-1?(h="Safari",s=(r=o.match(/Version\/([\d.]+)/))==null?void 0:r[1]):o.indexOf("Opera")!==-1||o.indexOf("OPR")!==-1?(h="Opera",s=(i=o.match(/(Opera|OPR)\/([\d.]+)/))==null?void 0:i[2]):o.indexOf("MSIE")!==-1||o.indexOf("Trident")!==-1?(h="Internet Explorer",s=(a=o.match(/(MSIE |rv:)([\d.]+)/))==null?void 0:a[2]):(h="Unknown",s="Unknown"),{name:h,version:s}}function xe(t){return new Promise(e=>setTimeout(e,t))}function be(){let t=navigator.userAgent,e;t.indexOf("Win")!==-1?e="Windows":t.indexOf("Mac")!==-1?e="Mac":t.indexOf("Linux")!==-1?e="Linux":t.indexOf("Android")!==-1?e="Android":t.indexOf("like Mac")!==-1||t.indexOf("iPhone")!==-1||t.indexOf("iPad")!==-1?e="iOS":e="Unknown";let n;return/Mobile|iPhone|iPod|Android/i.test(t)?n="Mobile":/Tablet|iPad/i.test(t)?n="Tablet":n="Desktop",{model:e,family:e,device:n}}var we=class Y{constructor(e){l(this,"_parent"),l(this,"breadcrumbs",[]),l(this,"context",{}),l(this,"extra",{}),l(this,"tags",{}),l(this,"request"),l(this,"user"),this._parent=e}get parent(){return this._parent}child(){return new Y(this)}setRequest(e){return this.request=e,this}removeRequest(){return this.request=void 0,this}addBreadcrumb(e){return typeof e.timestamp>"u"&&(e.timestamp=new Date().toISOString()),this.breadcrumbs.push(e),this}setExtra(e,n){return this.extra[e]=n,this}removeExtra(e){return delete this.extra[e],this}setContext(e,n){return typeof n.type>"u"&&(n.type=e),this.context[e]=n,this}removeContext(e){return delete this.context[e],this}setTags(e){return this.tags=g(g({},this.tags),e),this}setTag(e,n){return this.tags[e]=n,this}removeTag(e){return delete this.tags[e],this}setUser(e){return this.user=e,this}removeUser(){return this.user=void 0,this}toBody(){let e=[],n=this;for(;n;)e.push(n),n=n.parent;return e.reverse().reduce((r,i)=>{var a;return r.breadcrumbs=[...(a=r.breadcrumbs)!=null?a:[],...i.breadcrumbs],r.extra=g(g({},r.extra),i.extra),r.contexts=g(g({},r.contexts),i.context),r.tags=g(g({},r.tags),i.tags),i.user&&(r.user=i.user),i.request&&(r.request=i.request),r},{breadcrumbs:[],extra:{},contexts:{},tags:{},request:void 0,user:void 0})}clear(){this.breadcrumbs=[],this.context={},this.tags={},this.user=void 0}},Ee=/^\s*at (?:(.*?) ?\()?((?:file|https?|blob|chrome-extension|address|native|eval|webpack|<anonymous>|[-a-z]+:|.*bundle|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,Ce=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:file|https?|blob|chrome|webpack|resource|moz-extension).*?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js))(?::(\d+))?(?::(\d+))?\s*$/i,Re=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i,_e=/^(?:(\w+):)\/\/(?:(\w+)(?::(\w+))?@)([\w.-]+)(?::(\d+))?\/(.+)/,I="?",z="An unknown error occurred",Oe="0.0.4";function Pe(t){for(let e=0;e<t.length;e++)t[e]=Math.floor(Math.random()*256);return t}function p(t){return(t+256).toString(16).substring(1)}function Se(){let t=Pe(new Array(16));return t[6]=t[6]&15|64,t[8]=t[8]&63|128,p(t[0])+p(t[1])+p(t[2])+p(t[3])+"-"+p(t[4])+p(t[5])+"-"+p(t[6])+p(t[7])+"-"+p(t[8])+p(t[9])+"-"+p(t[10])+p(t[11])+p(t[12])+p(t[13])+p(t[14])+p(t[15])}var Ie=[[Ee,"chrome"],[Re,"winjs"],[Ce,"gecko"]];function ke(t){var e,n,r,i;if(!t.stack)return null;let a=[],o=(r=(n=(e=t.stack).split)==null?void 0:n.call(e,`
2
+ `))!=null?r:[];for(let h=0;h<o.length;++h){let s=null,c=null,u=null;for(let[y,v]of Ie)if(c=y.exec(o[h]),c){u=v;break}if(!(!c||!u)){if(u==="chrome")s={filename:(i=c[2])!=null&&i.startsWith("address at ")?c[2].substring(11):c[2],function:c[1]||I,lineno:c[3]?+c[3]:null,colno:c[4]?+c[4]:null};else if(u==="winjs")s={filename:c[2],function:c[1]||I,lineno:+c[3],colno:c[4]?+c[4]:null};else if(u==="gecko")h===0&&!c[5]&&t.columnNumber!==void 0&&a.length>0&&(a[0].column=t.columnNumber+1),s={filename:c[3],function:c[1]||I,lineno:c[4]?+c[4]:null,colno:c[5]?+c[5]:null};else continue;!s.function&&s.lineno&&(s.function=I),a.push(s)}}return a.length?a.reverse():null}function je(t){let e=ke(t);return{type:t.name,value:t.message,stacktrace:{frames:e!=null?e:[]}}}function Ae(t){let e=_e.exec(t),n=e?e.slice(1):[];if(n.length!==6)throw new Error("Invalid DSN");let r=n[5].split("/"),i=r.slice(0,-1).join("/");return n[0]+"://"+n[3]+(n[4]?":"+n[4]:"")+(i?"/"+i:"")+"/api/"+r.pop()+"/envelope/?sentry_version=7&sentry_key="+n[1]+(n[2]?"&sentry_secret="+n[2]:"")}function qe(t,e,n){var r,i;let a=g({event_id:Se().replaceAll("-",""),platform:"javascript",sdk:{name:"@hcaptcha/sentry",version:Oe},environment:e,release:n,timestamp:Date.now()/1e3},t.scope.toBody());if(t.type==="exception"){a.message=(i=(r=t.error)==null?void 0:r.message)!=null?i:"Unknown error",a.fingerprint=[a.message];let o=[],h=t.error;for(let s=0;s<5&&h&&(o.push(je(h)),!(!h.cause||!(h.cause instanceof Error)));s++)h=h.cause;a.exception={values:o.reverse()}}return t.type==="message"&&(a.message=t.message,a.level=t.level),a}function Le(t){if(t instanceof Error)return t;if(typeof t=="string")return new Error(t);if(typeof t=="object"&&t!==null&&!Array.isArray(t)){let n=t,{message:r}=n,i=fe(n,["message"]),a=new Error(typeof r=="string"?r:z);return Object.assign(a,i)}let e=new Error(z);return Object.assign(e,{cause:t})}function Me(t,e,n){return C(this,null,function*(){var r,i;try{if(typeof fetch<"u"&&typeof AbortSignal<"u"){let a;if(n){let s=new AbortController;a=s.signal,setTimeout(()=>s.abort(),n)}let o=yield fetch(t,G(g({},e),{signal:a})),h=yield o.text();return{status:o.status,body:h}}return yield new Promise((a,o)=>{var h,s;let c=new XMLHttpRequest;if(c.open((h=e==null?void 0:e.method)!=null?h:"GET",t),c.onload=()=>a({status:c.status,body:c.responseText}),c.onerror=()=>o(new Error("XHR Network Error")),e==null?void 0:e.headers)for(let[u,y]of Object.entries(e.headers))c.setRequestHeader(u,y);if(n){let u=setTimeout(()=>{c.abort(),o(new Error("Request timed out"))},n);c.onloadend=()=>{clearTimeout(u)}}c.send((s=e==null?void 0:e.body)==null?void 0:s.toString())})}catch(a){return{status:0,body:(i=(r=a==null?void 0:a.toString)==null?void 0:r.call(a))!=null?i:"Unknown error"}}})}var m,L=(m=class{constructor(t){l(this,"apiURL"),l(this,"dsn"),l(this,"environment"),l(this,"release"),l(this,"sampleRate"),l(this,"debug"),l(this,"_scope"),l(this,"shouldBuffer",!1),l(this,"bufferlimit",20),l(this,"buffer",[]);var e,n,r,i,a;this.environment=t.environment,this.release=t.release,this.sampleRate=(e=t.sampleRate)!=null?e:1,this.debug=(n=t.debug)!=null?n:!1,this._scope=(r=t.scope)!=null?r:new we,this.apiURL=Ae(t.dsn),this.dsn=t.dsn,this.shouldBuffer=(i=t.buffer)!=null?i:!1,this.bufferlimit=(a=t.bufferLimit)!=null?a:20}static init(t){m._instance||(m._instance=new m(t))}static get instance(){if(!m._instance)throw new Error("Sentry has not been initialized");return m._instance}log(...t){this.debug&&console.log(...t)}get scope(){return this._scope}static get scope(){return m.instance.scope}withScope(t){let e=this._scope.child();t(e)}static withScope(t){m.instance.withScope(t)}captureException(t,e){this.captureEvent({type:"exception",level:"error",error:Le(t),scope:e!=null?e:this._scope})}static captureException(t,e){m.instance.captureException(t,e)}captureMessage(t,e="info",n){this.captureEvent({type:"message",level:e,message:t,scope:n!=null?n:this._scope})}static captureMessage(t,e="info",n){m.instance.captureMessage(t,e,n)}captureEvent(t){if(Math.random()>=this.sampleRate){this.log("Dropped event due to sample rate");return}if(this.shouldBuffer){if(this.buffer.length>=this.bufferlimit)return;this.buffer.push(t)}else this.sendEvent(t)}sendEvent(t,e=5e3){return C(this,null,function*(){try{this.log("Sending sentry event",t);let n=qe(t,this.environment,this.release),r={event_id:n.event_id,dsn:this.dsn},i={type:"event"},a=JSON.stringify(r)+`
3
+ `+JSON.stringify(i)+`
4
+ `+JSON.stringify(n),o=yield Me(this.apiURL,{method:"POST",headers:{"Content-Type":"application/x-sentry-envelope"},body:a},e);this.log("Sentry response",o.status),o.status!==200&&(console.log(o.body),console.error("Failed to send event to Sentry",o))}catch(n){console.error("Failed to send event",n)}})}flush(t=5e3){return C(this,null,function*(){try{this.log("Flushing sentry events",this.buffer.length);let e=this.buffer.splice(0,this.buffer.length).map(n=>this.sendEvent(n,t));yield Promise.all(e),this.log("Flushed all events")}catch(e){console.error("Failed to flush events",e)}})}static flush(t=5e3){return m.instance.flush(t)}static reset(){m._instance=void 0}},l(m,"_instance"),m),Te="https://d233059272824702afc8c43834c4912d@sentry.hcaptcha.com/6",Ue="2.3.0",He="production";function Be(t=!0){if(!t)return V();L.init({dsn:Te,release:Ue,environment:He});let e=L.scope;return ye(e),V(e)}function V(t=null){return{addBreadcrumb:e=>{t&&t.addBreadcrumb(e)},captureRequest:e=>{t&&t.setRequest(e)},captureException:e=>{t&&L.captureException(e,t)}}}function De({scriptLocation:t,query:e,loadAsync:n=!0,crossOrigin:r="anonymous",apihost:i="https://js.hcaptcha.com",cleanup:a=!1,secureApi:o=!1,scriptSource:h=""}={},s){let c=Q(t),u=X(c);return new Promise((y,v)=>{let d=u.document.createElement("script");d.id=me,h?d.src=`${h}?onload=${j}`:o?d.src=`${i}/1/secure-api.js?onload=${j}`:d.src=`${i}/1/api.js?onload=${j}`,d.crossOrigin=r,d.async=n;let w=(x,E)=>{try{!o&&a&&c.removeChild(d),E(x)}catch(P){v(P)}};d.onload=x=>w(x,y),d.onerror=x=>{s&&s(d.src),w(x,v)},d.src+=e!==""?`&${e}`:"",c.appendChild(d)})}var k=[];function $e(t={cleanup:!1},e){try{e.addBreadcrumb({category:b,message:"hCaptcha loader params",data:t});let n=Q(t.scriptLocation),r=X(n),i=k.find(({scope:o})=>o===r.window);if(i)return e.addBreadcrumb({category:b,message:"hCaptcha already loaded"}),i.promise;let a=new Promise((o,h)=>C(this,null,function*(){try{r.window[j]=()=>{e.addBreadcrumb({category:b,message:"hCaptcha script called onload function"}),o(r.window.hcaptcha)};let s=ge({custom:t.custom,render:t.render,sentry:t.sentry,assethost:t.assethost,imghost:t.imghost,reportapi:t.reportapi,endpoint:t.endpoint,host:t.host,recaptchacompat:t.recaptchacompat,hl:t.hl,uj:t.uj});yield De(g({query:s},t),c=>{e.captureRequest({url:c,method:"GET"})}),e.addBreadcrumb({category:b,message:"hCaptcha loaded",data:i})}catch(s){e.addBreadcrumb({category:b,message:"hCaptcha failed to load"});let c=k.findIndex(u=>u.scope===r.window);c!==-1&&k.splice(c,1),h(new Error(W))}}));return k.push({promise:a,scope:r.window}),a}catch(n){return e.captureException(n),Promise.reject(new Error(W))}}function Z(t,e,n=0){return C(this,null,function*(){var r,i;let a=(r=t.maxRetries)!=null?r:2,o=(i=t.retryDelay)!=null?i:1e3,h=n<a?"Retry loading hCaptcha Api":"Exceeded maximum retries";try{return yield $e(t,e)}catch(s){return e.addBreadcrumb({category:b,message:h}),n>=a?(e.captureException(s),Promise.reject(s)):(e.addBreadcrumb({category:b,message:`Waiting ${o}ms before retry attempt ${n+1}`}),yield xe(o),n+=1,Z(t,e,n))}})}function ee(){return C(this,arguments,function*(t={}){let e=Be(t.sentry);return yield Z(t,e)})}function M(t){let e=t&&t.ownerDocument||document,n=e.defaultView||e.parentWindow||window;return{document:e,window:n}}function T(t){return t||document.head}var O=class extends R.Component{constructor(e){super(e),this._hcaptcha=void 0,this.renderCaptcha=this.renderCaptcha.bind(this),this.resetCaptcha=this.resetCaptcha.bind(this),this.removeCaptcha=this.removeCaptcha.bind(this),this.isReady=this.isReady.bind(this),this._onReady=null,this.loadCaptcha=this.loadCaptcha.bind(this),this.handleOnLoad=this.handleOnLoad.bind(this),this.handleSubmit=this.handleSubmit.bind(this),this.handleExpire=this.handleExpire.bind(this),this.handleError=this.handleError.bind(this),this.handleOpen=this.handleOpen.bind(this),this.handleClose=this.handleClose.bind(this),this.handleChallengeExpired=this.handleChallengeExpired.bind(this),this.ref=R.createRef(),this.apiScriptRequested=!1,this.sentryHub=null,this.captchaId="",this._pendingExecute=null,this.state={isApiReady:!1,isRemoved:!1,elementId:e.id}}componentDidMount(){let e=T(this.props.scriptLocation),n=M(e);if(this._hcaptcha=n.window.hcaptcha||void 0,typeof this._hcaptcha!="undefined"){this.setState({isApiReady:!0},()=>{this.renderCaptcha()});return}this.loadCaptcha()}componentWillUnmount(){let e=this._hcaptcha,n=this.captchaId;this._cancelPendingExecute("react-component-unmounted"),this.isReady()&&(e.reset(n),e.remove(n))}shouldComponentUpdate(e,n){return!(this.state.isApiReady!==n.isApiReady||this.state.isRemoved!==n.isRemoved)}componentDidUpdate(e){["sitekey","size","theme","tabindex","languageOverride","endpoint"].every(i=>e[i]===this.props[i])||this.removeCaptcha(()=>{this.renderCaptcha()})}loadCaptcha(){if(this.apiScriptRequested)return;let{apihost:e,assethost:n,endpoint:r,host:i,imghost:a,languageOverride:o,reCaptchaCompat:h,reportapi:s,sentry:c,custom:u,loadAsync:y,scriptLocation:v,scriptSource:d,secureApi:w,cleanup:x=!0,userJourneys:E}=this.props;ee({render:"explicit",apihost:e,assethost:n,endpoint:r,hl:o,host:i,imghost:a,recaptchacompat:h===!1?"off":null,reportapi:s,sentry:c,custom:u,loadAsync:y,scriptLocation:v,scriptSource:d,secureApi:w,cleanup:x,uj:E!==void 0?E:!1}).then(this.handleOnLoad,this.handleError).catch(this.handleError),this.apiScriptRequested=!0}renderCaptcha(e){let{onReady:n}=this.props,{isApiReady:r}=this.state,i=this.captchaId;if(!r||i)return;let a=Object.assign({"open-callback":this.handleOpen,"close-callback":this.handleClose,"error-callback":this.handleError,"chalexpired-callback":this.handleChallengeExpired,"expired-callback":this.handleExpire,callback:this.handleSubmit},this.props,{hl:this.props.hl||this.props.languageOverride,languageOverride:void 0}),h=this._hcaptcha.render(this.ref.current,a);this.captchaId=h,this.setState({isRemoved:!1},()=>{e&&e(),n&&n(),this._onReady&&this._onReady(h)})}resetCaptcha(){let e=this._hcaptcha,n=this.captchaId;this.isReady()&&(e.reset(n),this._cancelPendingExecute("hcaptcha-reset"))}removeCaptcha(e){let n=this._hcaptcha,r=this.captchaId;this._cancelPendingExecute("hcaptcha-removed"),this.isReady()&&this.setState({isRemoved:!0},()=>{this.captchaId="",n.remove(r),e&&e()})}handleOnLoad(){this.setState({isApiReady:!0},()=>{let e=T(this.props.scriptLocation),n=M(e);this._hcaptcha=n.window.hcaptcha,this.renderCaptcha(()=>{let{onLoad:r}=this.props;r&&r()})})}handleSubmit(e){let{onVerify:n}=this.props,{isRemoved:r}=this.state,i=this._hcaptcha,a=this.captchaId;if(typeof i=="undefined"||r)return;let o=i.getResponse(a),h=i.getRespKey(a);n&&n(o,h)}handleExpire(){let{onExpire:e}=this.props,n=this._hcaptcha,r=this.captchaId;this.isReady()&&(n.reset(r),e&&e())}handleError(e){let{onError:n}=this.props,r=this._hcaptcha,i=this.captchaId;this.isReady()&&r.reset(i),n&&n(e)}isReady(){let{isApiReady:e,isRemoved:n}=this.state;return e&&!n}_cancelPendingExecute(e){if(!this._pendingExecute)return;let n=this._pendingExecute;this._pendingExecute=null;let r=new Error(e);n.reject(r)}handleOpen(){!this.isReady()||!this.props.onOpen||this.props.onOpen()}handleClose(){!this.isReady()||!this.props.onClose||this.props.onClose()}handleChallengeExpired(){!this.isReady()||!this.props.onChalExpired||this.props.onChalExpired()}execute(e=null){e=typeof e=="object"?e:null;try{let n=this._hcaptcha,r=this.captchaId;if(e&&e.async&&this._pendingExecute&&this._cancelPendingExecute("hcaptcha-execute-replaced"),!this.isReady())return e&&e.async?new Promise((a,o)=>{this._pendingExecute={resolve:a,reject:o},this._onReady=h=>{if(this._pendingExecute)try{let s=n.execute(h,e);s&&typeof s.then=="function"?s.then(c=>{this._pendingExecute=null,a(c)}).catch(c=>{this._pendingExecute=null,o(c)}):(this._pendingExecute=null,o(new Error("hcaptcha-execute-no-promise")))}catch(s){this._pendingExecute=null,o(s)}}}):(this._onReady=a=>{n.execute(a,e)},null);let i=n.execute(r,e);return e&&e.async&&i&&typeof i.then=="function"?new Promise((a,o)=>{this._pendingExecute={resolve:a,reject:o},i.then(h=>{this._pendingExecute=null,a(h)}).catch(h=>{this._pendingExecute=null,o(h)})}):i}catch(n){return e&&e.async?Promise.reject(n):null}}close(){let e=this._hcaptcha,n=this.captchaId;if(this._cancelPendingExecute("hcaptcha-closed"),!!this.isReady())return e.close(n)}setData(e){let n=this._hcaptcha,r=this.captchaId;this.isReady()&&(e&&typeof e!="object"&&(e=null),n.setData(r,e))}getResponse(){return this._hcaptcha.getResponse(this.captchaId)}getRespKey(){return this._hcaptcha.getRespKey(this.captchaId)}render(){let{elementId:e}=this.state;return R.createElement("div",{ref:this.ref,id:e})}};var te=O;function ne({sitekey:t=null,size:e="normal",theme:n="light",rqdata:r=null,languageOverride:i=null,onVerify:a,onError:o,children:h}){let s=Ne(null),[c,u]=U(!1),[y,v]=U(null),[d,w]=U(null),x=()=>{u(!0)},E=f=>{w(f),o&&o(f)},P=()=>{v(null)},se=f=>{v(f),a&&a(f)},ie=(...mt)=>F(this,[...mt],function*(f={}){try{if(!c)throw new Error("hCaptcha not ready");y&&H();let{response:_}=yield s.current.execute($({async:!0},f.rqdata?{rqdata:f.rqdata}:{}));return v(_),_}catch(_){w(_),o&&o(_)}}),H=()=>{var f;(f=s==null?void 0:s.current)==null||f.resetCaptcha()};return Fe(()=>{var f;r&&((f=s==null?void 0:s.current)==null||f.setData(r))},[r]),re.createElement(S.Provider,{value:{sitekey:t,error:d,token:y,ready:c,executeInstance:ie,resetInstance:H}},h,re.createElement(te,{sitekey:t,size:e,theme:n,languageOverride:i,onReady:x,onVerify:se,onExpire:P,onError:E,ref:s}))}export{ne as HCaptchaProvider,N as useHCaptcha};
@@ -0,0 +1,4 @@
1
+ var ae=Object.defineProperty;var B=Object.getOwnPropertySymbols;var oe=Object.prototype.hasOwnProperty,ce=Object.prototype.propertyIsEnumerable;var D=(t,e,n)=>e in t?ae(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,$=(t,e)=>{for(var n in e||(e={}))oe.call(e,n)&&D(t,n,e[n]);if(B)for(var n of B(e))ce.call(e,n)&&D(t,n,e[n]);return t};var F=(t,e,n)=>new Promise((r,i)=>{var a=s=>{try{h(n.next(s))}catch(c){i(c)}},o=s=>{try{h(n.throw(s))}catch(c){i(c)}},h=s=>s.done?r(s.value):Promise.resolve(s.value).then(a,o);h((n=n.apply(t,e)).next())});import*as R from"react";var he=Object.defineProperty,le=Object.defineProperties,ue=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertySymbols,V=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable,q=(t,e,n)=>e in t?he(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,g=(t,e)=>{for(var n in e||(e={}))V.call(e,n)&&q(t,n,e[n]);if(j)for(var n of j(e))J.call(e,n)&&q(t,n,e[n]);return t},K=(t,e)=>le(t,ue(e)),de=(t,e)=>{var n={};for(var r in t)V.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&j)for(var r of j(t))e.indexOf(r)<0&&J.call(t,r)&&(n[r]=t[r]);return n},l=(t,e,n)=>(q(t,typeof e!="symbol"?e+"":e,n),n),C=(t,e,n)=>new Promise((r,i)=>{var a=s=>{try{h(n.next(s))}catch(c){i(c)}},o=s=>{try{h(n.throw(s))}catch(c){i(c)}},h=s=>s.done?r(s.value):Promise.resolve(s.value).then(a,o);h((n=n.apply(t,e)).next())}),pe="hCaptcha-script",k="hCaptchaOnLoad",N="script-error",b="@hCaptcha/loader";function fe(t){return Object.entries(t).filter(([,e])=>e||e===!1).map(([e,n])=>`${encodeURIComponent(e)}=${encodeURIComponent(String(n))}`).join("&")}function G(t){let e=t&&t.ownerDocument||document,n=e.defaultView||e.parentWindow||window;return{document:e,window:n}}function X(t){return t||document.head}function me(t){var e;t.setTag("source",b),t.setTag("url",document.URL),t.setContext("os",{UA:navigator.userAgent}),t.setContext("browser",g({},ge())),t.setContext("device",K(g({},ve()),{screen_width_pixels:screen.width,screen_height_pixels:screen.height,language:navigator.language,orientation:((e=screen.orientation)==null?void 0:e.type)||"Unknown",processor_count:navigator.hardwareConcurrency,platform:navigator.platform}))}function ge(){var t,e,n,r,i,a;let o=navigator.userAgent,h,s;return o.indexOf("Firefox")!==-1?(h="Firefox",s=(t=o.match(/Firefox\/([\d.]+)/))==null?void 0:t[1]):o.indexOf("Edg")!==-1?(h="Microsoft Edge",s=(e=o.match(/Edg\/([\d.]+)/))==null?void 0:e[1]):o.indexOf("Chrome")!==-1&&o.indexOf("Safari")!==-1?(h="Chrome",s=(n=o.match(/Chrome\/([\d.]+)/))==null?void 0:n[1]):o.indexOf("Safari")!==-1&&o.indexOf("Chrome")===-1?(h="Safari",s=(r=o.match(/Version\/([\d.]+)/))==null?void 0:r[1]):o.indexOf("Opera")!==-1||o.indexOf("OPR")!==-1?(h="Opera",s=(i=o.match(/(Opera|OPR)\/([\d.]+)/))==null?void 0:i[2]):o.indexOf("MSIE")!==-1||o.indexOf("Trident")!==-1?(h="Internet Explorer",s=(a=o.match(/(MSIE |rv:)([\d.]+)/))==null?void 0:a[2]):(h="Unknown",s="Unknown"),{name:h,version:s}}function ye(t){return new Promise(e=>setTimeout(e,t))}function ve(){let t=navigator.userAgent,e;t.indexOf("Win")!==-1?e="Windows":t.indexOf("Mac")!==-1?e="Mac":t.indexOf("Linux")!==-1?e="Linux":t.indexOf("Android")!==-1?e="Android":t.indexOf("like Mac")!==-1||t.indexOf("iPhone")!==-1||t.indexOf("iPad")!==-1?e="iOS":e="Unknown";let n;return/Mobile|iPhone|iPod|Android/i.test(t)?n="Mobile":/Tablet|iPad/i.test(t)?n="Tablet":n="Desktop",{model:e,family:e,device:n}}var xe=class Q{constructor(e){l(this,"_parent"),l(this,"breadcrumbs",[]),l(this,"context",{}),l(this,"extra",{}),l(this,"tags",{}),l(this,"request"),l(this,"user"),this._parent=e}get parent(){return this._parent}child(){return new Q(this)}setRequest(e){return this.request=e,this}removeRequest(){return this.request=void 0,this}addBreadcrumb(e){return typeof e.timestamp>"u"&&(e.timestamp=new Date().toISOString()),this.breadcrumbs.push(e),this}setExtra(e,n){return this.extra[e]=n,this}removeExtra(e){return delete this.extra[e],this}setContext(e,n){return typeof n.type>"u"&&(n.type=e),this.context[e]=n,this}removeContext(e){return delete this.context[e],this}setTags(e){return this.tags=g(g({},this.tags),e),this}setTag(e,n){return this.tags[e]=n,this}removeTag(e){return delete this.tags[e],this}setUser(e){return this.user=e,this}removeUser(){return this.user=void 0,this}toBody(){let e=[],n=this;for(;n;)e.push(n),n=n.parent;return e.reverse().reduce((r,i)=>{var a;return r.breadcrumbs=[...(a=r.breadcrumbs)!=null?a:[],...i.breadcrumbs],r.extra=g(g({},r.extra),i.extra),r.contexts=g(g({},r.contexts),i.context),r.tags=g(g({},r.tags),i.tags),i.user&&(r.user=i.user),i.request&&(r.request=i.request),r},{breadcrumbs:[],extra:{},contexts:{},tags:{},request:void 0,user:void 0})}clear(){this.breadcrumbs=[],this.context={},this.tags={},this.user=void 0}},be=/^\s*at (?:(.*?) ?\()?((?:file|https?|blob|chrome-extension|address|native|eval|webpack|<anonymous>|[-a-z]+:|.*bundle|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,we=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:file|https?|blob|chrome|webpack|resource|moz-extension).*?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js))(?::(\d+))?(?::(\d+))?\s*$/i,Ee=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i,Ce=/^(?:(\w+):)\/\/(?:(\w+)(?::(\w+))?@)([\w.-]+)(?::(\d+))?\/(.+)/,S="?",W="An unknown error occurred",Re="0.0.4";function _e(t){for(let e=0;e<t.length;e++)t[e]=Math.floor(Math.random()*256);return t}function p(t){return(t+256).toString(16).substring(1)}function Oe(){let t=_e(new Array(16));return t[6]=t[6]&15|64,t[8]=t[8]&63|128,p(t[0])+p(t[1])+p(t[2])+p(t[3])+"-"+p(t[4])+p(t[5])+"-"+p(t[6])+p(t[7])+"-"+p(t[8])+p(t[9])+"-"+p(t[10])+p(t[11])+p(t[12])+p(t[13])+p(t[14])+p(t[15])}var Pe=[[be,"chrome"],[Ee,"winjs"],[we,"gecko"]];function Se(t){var e,n,r,i;if(!t.stack)return null;let a=[],o=(r=(n=(e=t.stack).split)==null?void 0:n.call(e,`
2
+ `))!=null?r:[];for(let h=0;h<o.length;++h){let s=null,c=null,u=null;for(let[y,v]of Pe)if(c=y.exec(o[h]),c){u=v;break}if(!(!c||!u)){if(u==="chrome")s={filename:(i=c[2])!=null&&i.startsWith("address at ")?c[2].substring(11):c[2],function:c[1]||S,lineno:c[3]?+c[3]:null,colno:c[4]?+c[4]:null};else if(u==="winjs")s={filename:c[2],function:c[1]||S,lineno:+c[3],colno:c[4]?+c[4]:null};else if(u==="gecko")h===0&&!c[5]&&t.columnNumber!==void 0&&a.length>0&&(a[0].column=t.columnNumber+1),s={filename:c[3],function:c[1]||S,lineno:c[4]?+c[4]:null,colno:c[5]?+c[5]:null};else continue;!s.function&&s.lineno&&(s.function=S),a.push(s)}}return a.length?a.reverse():null}function Ie(t){let e=Se(t);return{type:t.name,value:t.message,stacktrace:{frames:e!=null?e:[]}}}function ke(t){let e=Ce.exec(t),n=e?e.slice(1):[];if(n.length!==6)throw new Error("Invalid DSN");let r=n[5].split("/"),i=r.slice(0,-1).join("/");return n[0]+"://"+n[3]+(n[4]?":"+n[4]:"")+(i?"/"+i:"")+"/api/"+r.pop()+"/envelope/?sentry_version=7&sentry_key="+n[1]+(n[2]?"&sentry_secret="+n[2]:"")}function je(t,e,n){var r,i;let a=g({event_id:Oe().replaceAll("-",""),platform:"javascript",sdk:{name:"@hcaptcha/sentry",version:Re},environment:e,release:n,timestamp:Date.now()/1e3},t.scope.toBody());if(t.type==="exception"){a.message=(i=(r=t.error)==null?void 0:r.message)!=null?i:"Unknown error",a.fingerprint=[a.message];let o=[],h=t.error;for(let s=0;s<5&&h&&(o.push(Ie(h)),!(!h.cause||!(h.cause instanceof Error)));s++)h=h.cause;a.exception={values:o.reverse()}}return t.type==="message"&&(a.message=t.message,a.level=t.level),a}function Ae(t){if(t instanceof Error)return t;if(typeof t=="string")return new Error(t);if(typeof t=="object"&&t!==null&&!Array.isArray(t)){let n=t,{message:r}=n,i=de(n,["message"]),a=new Error(typeof r=="string"?r:W);return Object.assign(a,i)}let e=new Error(W);return Object.assign(e,{cause:t})}function qe(t,e,n){return C(this,null,function*(){var r,i;try{if(typeof fetch<"u"&&typeof AbortSignal<"u"){let a;if(n){let s=new AbortController;a=s.signal,setTimeout(()=>s.abort(),n)}let o=yield fetch(t,K(g({},e),{signal:a})),h=yield o.text();return{status:o.status,body:h}}return yield new Promise((a,o)=>{var h,s;let c=new XMLHttpRequest;if(c.open((h=e==null?void 0:e.method)!=null?h:"GET",t),c.onload=()=>a({status:c.status,body:c.responseText}),c.onerror=()=>o(new Error("XHR Network Error")),e==null?void 0:e.headers)for(let[u,y]of Object.entries(e.headers))c.setRequestHeader(u,y);if(n){let u=setTimeout(()=>{c.abort(),o(new Error("Request timed out"))},n);c.onloadend=()=>{clearTimeout(u)}}c.send((s=e==null?void 0:e.body)==null?void 0:s.toString())})}catch(a){return{status:0,body:(i=(r=a==null?void 0:a.toString)==null?void 0:r.call(a))!=null?i:"Unknown error"}}})}var m,L=(m=class{constructor(t){l(this,"apiURL"),l(this,"dsn"),l(this,"environment"),l(this,"release"),l(this,"sampleRate"),l(this,"debug"),l(this,"_scope"),l(this,"shouldBuffer",!1),l(this,"bufferlimit",20),l(this,"buffer",[]);var e,n,r,i,a;this.environment=t.environment,this.release=t.release,this.sampleRate=(e=t.sampleRate)!=null?e:1,this.debug=(n=t.debug)!=null?n:!1,this._scope=(r=t.scope)!=null?r:new xe,this.apiURL=ke(t.dsn),this.dsn=t.dsn,this.shouldBuffer=(i=t.buffer)!=null?i:!1,this.bufferlimit=(a=t.bufferLimit)!=null?a:20}static init(t){m._instance||(m._instance=new m(t))}static get instance(){if(!m._instance)throw new Error("Sentry has not been initialized");return m._instance}log(...t){this.debug&&console.log(...t)}get scope(){return this._scope}static get scope(){return m.instance.scope}withScope(t){let e=this._scope.child();t(e)}static withScope(t){m.instance.withScope(t)}captureException(t,e){this.captureEvent({type:"exception",level:"error",error:Ae(t),scope:e!=null?e:this._scope})}static captureException(t,e){m.instance.captureException(t,e)}captureMessage(t,e="info",n){this.captureEvent({type:"message",level:e,message:t,scope:n!=null?n:this._scope})}static captureMessage(t,e="info",n){m.instance.captureMessage(t,e,n)}captureEvent(t){if(Math.random()>=this.sampleRate){this.log("Dropped event due to sample rate");return}if(this.shouldBuffer){if(this.buffer.length>=this.bufferlimit)return;this.buffer.push(t)}else this.sendEvent(t)}sendEvent(t,e=5e3){return C(this,null,function*(){try{this.log("Sending sentry event",t);let n=je(t,this.environment,this.release),r={event_id:n.event_id,dsn:this.dsn},i={type:"event"},a=JSON.stringify(r)+`
3
+ `+JSON.stringify(i)+`
4
+ `+JSON.stringify(n),o=yield qe(this.apiURL,{method:"POST",headers:{"Content-Type":"application/x-sentry-envelope"},body:a},e);this.log("Sentry response",o.status),o.status!==200&&(console.log(o.body),console.error("Failed to send event to Sentry",o))}catch(n){console.error("Failed to send event",n)}})}flush(t=5e3){return C(this,null,function*(){try{this.log("Flushing sentry events",this.buffer.length);let e=this.buffer.splice(0,this.buffer.length).map(n=>this.sendEvent(n,t));yield Promise.all(e),this.log("Flushed all events")}catch(e){console.error("Failed to flush events",e)}})}static flush(t=5e3){return m.instance.flush(t)}static reset(){m._instance=void 0}},l(m,"_instance"),m),Le="https://d233059272824702afc8c43834c4912d@sentry.hcaptcha.com/6",Me="2.3.0",Te="production";function Ue(t=!0){if(!t)return z();L.init({dsn:Le,release:Me,environment:Te});let e=L.scope;return me(e),z(e)}function z(t=null){return{addBreadcrumb:e=>{t&&t.addBreadcrumb(e)},captureRequest:e=>{t&&t.setRequest(e)},captureException:e=>{t&&L.captureException(e,t)}}}function He({scriptLocation:t,query:e,loadAsync:n=!0,crossOrigin:r="anonymous",apihost:i="https://js.hcaptcha.com",cleanup:a=!1,secureApi:o=!1,scriptSource:h=""}={},s){let c=X(t),u=G(c);return new Promise((y,v)=>{let d=u.document.createElement("script");d.id=pe,h?d.src=`${h}?onload=${k}`:o?d.src=`${i}/1/secure-api.js?onload=${k}`:d.src=`${i}/1/api.js?onload=${k}`,d.crossOrigin=r,d.async=n;let w=(x,E)=>{try{!o&&a&&c.removeChild(d),E(x)}catch(P){v(P)}};d.onload=x=>w(x,y),d.onerror=x=>{s&&s(d.src),w(x,v)},d.src+=e!==""?`&${e}`:"",c.appendChild(d)})}var I=[];function Be(t={cleanup:!1},e){try{e.addBreadcrumb({category:b,message:"hCaptcha loader params",data:t});let n=X(t.scriptLocation),r=G(n),i=I.find(({scope:o})=>o===r.window);if(i)return e.addBreadcrumb({category:b,message:"hCaptcha already loaded"}),i.promise;let a=new Promise((o,h)=>C(this,null,function*(){try{r.window[k]=()=>{e.addBreadcrumb({category:b,message:"hCaptcha script called onload function"}),o(r.window.hcaptcha)};let s=fe({custom:t.custom,render:t.render,sentry:t.sentry,assethost:t.assethost,imghost:t.imghost,reportapi:t.reportapi,endpoint:t.endpoint,host:t.host,recaptchacompat:t.recaptchacompat,hl:t.hl,uj:t.uj});yield He(g({query:s},t),c=>{e.captureRequest({url:c,method:"GET"})}),e.addBreadcrumb({category:b,message:"hCaptcha loaded",data:i})}catch(s){e.addBreadcrumb({category:b,message:"hCaptcha failed to load"});let c=I.findIndex(u=>u.scope===r.window);c!==-1&&I.splice(c,1),h(new Error(N))}}));return I.push({promise:a,scope:r.window}),a}catch(n){return e.captureException(n),Promise.reject(new Error(N))}}function Y(t,e,n=0){return C(this,null,function*(){var r,i;let a=(r=t.maxRetries)!=null?r:2,o=(i=t.retryDelay)!=null?i:1e3,h=n<a?"Retry loading hCaptcha Api":"Exceeded maximum retries";try{return yield Be(t,e)}catch(s){return e.addBreadcrumb({category:b,message:h}),n>=a?(e.captureException(s),Promise.reject(s)):(e.addBreadcrumb({category:b,message:`Waiting ${o}ms before retry attempt ${n+1}`}),yield ye(o),n+=1,Y(t,e,n))}})}function Z(){return C(this,arguments,function*(t={}){let e=Ue(t.sentry);return yield Y(t,e)})}function M(t){let e=t&&t.ownerDocument||document,n=e.defaultView||e.parentWindow||window;return{document:e,window:n}}function T(t){return t||document.head}var O=class extends R.Component{constructor(e){super(e),this._hcaptcha=void 0,this.renderCaptcha=this.renderCaptcha.bind(this),this.resetCaptcha=this.resetCaptcha.bind(this),this.removeCaptcha=this.removeCaptcha.bind(this),this.isReady=this.isReady.bind(this),this._onReady=null,this.loadCaptcha=this.loadCaptcha.bind(this),this.handleOnLoad=this.handleOnLoad.bind(this),this.handleSubmit=this.handleSubmit.bind(this),this.handleExpire=this.handleExpire.bind(this),this.handleError=this.handleError.bind(this),this.handleOpen=this.handleOpen.bind(this),this.handleClose=this.handleClose.bind(this),this.handleChallengeExpired=this.handleChallengeExpired.bind(this),this.ref=R.createRef(),this.apiScriptRequested=!1,this.sentryHub=null,this.captchaId="",this._pendingExecute=null,this.state={isApiReady:!1,isRemoved:!1,elementId:e.id}}componentDidMount(){let e=T(this.props.scriptLocation),n=M(e);if(this._hcaptcha=n.window.hcaptcha||void 0,typeof this._hcaptcha!="undefined"){this.setState({isApiReady:!0},()=>{this.renderCaptcha()});return}this.loadCaptcha()}componentWillUnmount(){let e=this._hcaptcha,n=this.captchaId;this._cancelPendingExecute("react-component-unmounted"),this.isReady()&&(e.reset(n),e.remove(n))}shouldComponentUpdate(e,n){return!(this.state.isApiReady!==n.isApiReady||this.state.isRemoved!==n.isRemoved)}componentDidUpdate(e){["sitekey","size","theme","tabindex","languageOverride","endpoint"].every(i=>e[i]===this.props[i])||this.removeCaptcha(()=>{this.renderCaptcha()})}loadCaptcha(){if(this.apiScriptRequested)return;let{apihost:e,assethost:n,endpoint:r,host:i,imghost:a,languageOverride:o,reCaptchaCompat:h,reportapi:s,sentry:c,custom:u,loadAsync:y,scriptLocation:v,scriptSource:d,secureApi:w,cleanup:x=!0,userJourneys:E}=this.props;Z({render:"explicit",apihost:e,assethost:n,endpoint:r,hl:o,host:i,imghost:a,recaptchacompat:h===!1?"off":null,reportapi:s,sentry:c,custom:u,loadAsync:y,scriptLocation:v,scriptSource:d,secureApi:w,cleanup:x,uj:E!==void 0?E:!1}).then(this.handleOnLoad,this.handleError).catch(this.handleError),this.apiScriptRequested=!0}renderCaptcha(e){let{onReady:n}=this.props,{isApiReady:r}=this.state,i=this.captchaId;if(!r||i)return;let a=Object.assign({"open-callback":this.handleOpen,"close-callback":this.handleClose,"error-callback":this.handleError,"chalexpired-callback":this.handleChallengeExpired,"expired-callback":this.handleExpire,callback:this.handleSubmit},this.props,{hl:this.props.hl||this.props.languageOverride,languageOverride:void 0}),h=this._hcaptcha.render(this.ref.current,a);this.captchaId=h,this.setState({isRemoved:!1},()=>{e&&e(),n&&n(),this._onReady&&this._onReady(h)})}resetCaptcha(){let e=this._hcaptcha,n=this.captchaId;this.isReady()&&(e.reset(n),this._cancelPendingExecute("hcaptcha-reset"))}removeCaptcha(e){let n=this._hcaptcha,r=this.captchaId;this._cancelPendingExecute("hcaptcha-removed"),this.isReady()&&this.setState({isRemoved:!0},()=>{this.captchaId="",n.remove(r),e&&e()})}handleOnLoad(){this.setState({isApiReady:!0},()=>{let e=T(this.props.scriptLocation),n=M(e);this._hcaptcha=n.window.hcaptcha,this.renderCaptcha(()=>{let{onLoad:r}=this.props;r&&r()})})}handleSubmit(e){let{onVerify:n}=this.props,{isRemoved:r}=this.state,i=this._hcaptcha,a=this.captchaId;if(typeof i=="undefined"||r)return;let o=i.getResponse(a),h=i.getRespKey(a);n&&n(o,h)}handleExpire(){let{onExpire:e}=this.props,n=this._hcaptcha,r=this.captchaId;this.isReady()&&(n.reset(r),e&&e())}handleError(e){let{onError:n}=this.props,r=this._hcaptcha,i=this.captchaId;this.isReady()&&r.reset(i),n&&n(e)}isReady(){let{isApiReady:e,isRemoved:n}=this.state;return e&&!n}_cancelPendingExecute(e){if(!this._pendingExecute)return;let n=this._pendingExecute;this._pendingExecute=null;let r=new Error(e);n.reject(r)}handleOpen(){!this.isReady()||!this.props.onOpen||this.props.onOpen()}handleClose(){!this.isReady()||!this.props.onClose||this.props.onClose()}handleChallengeExpired(){!this.isReady()||!this.props.onChalExpired||this.props.onChalExpired()}execute(e=null){e=typeof e=="object"?e:null;try{let n=this._hcaptcha,r=this.captchaId;if(e&&e.async&&this._pendingExecute&&this._cancelPendingExecute("hcaptcha-execute-replaced"),!this.isReady())return e&&e.async?new Promise((a,o)=>{this._pendingExecute={resolve:a,reject:o},this._onReady=h=>{if(this._pendingExecute)try{let s=n.execute(h,e);s&&typeof s.then=="function"?s.then(c=>{this._pendingExecute=null,a(c)}).catch(c=>{this._pendingExecute=null,o(c)}):(this._pendingExecute=null,o(new Error("hcaptcha-execute-no-promise")))}catch(s){this._pendingExecute=null,o(s)}}}):(this._onReady=a=>{n.execute(a,e)},null);let i=n.execute(r,e);return e&&e.async&&i&&typeof i.then=="function"?new Promise((a,o)=>{this._pendingExecute={resolve:a,reject:o},i.then(h=>{this._pendingExecute=null,a(h)}).catch(h=>{this._pendingExecute=null,o(h)})}):i}catch(n){return e&&e.async?Promise.reject(n):null}}close(){let e=this._hcaptcha,n=this.captchaId;if(this._cancelPendingExecute("hcaptcha-closed"),!!this.isReady())return e.close(n)}setData(e){let n=this._hcaptcha,r=this.captchaId;this.isReady()&&(e&&typeof e!="object"&&(e=null),n.setData(r,e))}getResponse(){return this._hcaptcha.getResponse(this.captchaId)}getRespKey(){return this._hcaptcha.getRespKey(this.captchaId)}render(){let{elementId:e}=this.state;return R.createElement("div",{ref:this.ref,id:e})}};import{useContext as $e}from"react";import{createContext as De}from"react";var A=De();var ee=()=>$e(A);import te,{useEffect as Fe,useRef as Ne,useState as U}from"react";function ne({sitekey:t=null,size:e="normal",theme:n="light",rqdata:r=null,languageOverride:i=null,onVerify:a,onError:o,children:h}){let s=Ne(null),[c,u]=U(!1),[y,v]=U(null),[d,w]=U(null),x=()=>{u(!0)},E=f=>{w(f),o&&o(f)},P=()=>{v(null)},se=f=>{v(f),a&&a(f)},ie=(...mt)=>F(this,[...mt],function*(f={}){try{if(!c)throw new Error("hCaptcha not ready");y&&H();let{response:_}=yield s.current.execute($({async:!0},f.rqdata?{rqdata:f.rqdata}:{}));return v(_),_}catch(_){w(_),o&&o(_)}}),H=()=>{var f;(f=s==null?void 0:s.current)==null||f.resetCaptcha()};return Fe(()=>{var f;r&&((f=s==null?void 0:s.current)==null||f.setData(r))},[r]),te.createElement(A.Provider,{value:{sitekey:t,error:d,token:y,ready:c,executeInstance:ie,resetInstance:H}},h,te.createElement(re,{sitekey:t,size:e,theme:n,languageOverride:i,onReady:x,onVerify:se,onExpire:P,onError:E,ref:s}))}var re=O;export{O as HCaptcha,ne as HCaptchaProvider,re as default,ee as useHCaptcha};
package/package.json CHANGED
@@ -1,77 +1,56 @@
1
1
  {
2
2
  "name": "@hcaptcha/react-hcaptcha",
3
- "version": "1.17.4",
3
+ "description": "A React library for hCaptcha",
4
+ "version": "2.0.1",
5
+ "author": "hCaptcha team and contributors",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/hCaptcha/react-hcaptcha.git"
10
+ },
11
+ "keywords": [
12
+ "hcaptcha",
13
+ "hcaptcha-react",
14
+ "react",
15
+ "captcha"
16
+ ],
4
17
  "types": "types/index.d.ts",
5
- "main": "dist/index.js",
6
- "module": "dist/esm/index.js",
18
+ "main": "lib/dist/cjs/index.js",
19
+ "module": "lib/dist/esm/index.js",
20
+ "typesVersions": {
21
+ "*": {
22
+ "hooks": [
23
+ "types/hooks/index.d.ts"
24
+ ]
25
+ }
26
+ },
7
27
  "exports": {
8
28
  ".": {
9
29
  "types": "./types/index.d.ts",
10
- "import": "./dist/esm/index.js",
11
- "require": "./dist/index.js"
30
+ "import": "./lib/dist/esm/index.js",
31
+ "require": "./lib/dist/cjs/index.js"
12
32
  },
13
33
  "./hooks": {
14
34
  "types": "./types/hooks/index.d.ts",
15
- "import": "./dist/esm/hooks/index.js",
16
- "require": "./dist/hooks/index.js"
35
+ "import": "./lib/dist/esm/hooks/index.js",
36
+ "require": "./lib/dist/cjs/hooks/index.js"
17
37
  }
18
38
  },
19
39
  "files": [
20
- "src",
21
- "dist",
22
- "types"
23
- ],
24
- "description": "A React library for hCaptcha",
25
- "scripts": {
26
- "start": "webpack serve -c ./demo/webpack.config.mjs",
27
- "test": "jest",
28
- "watch": "babel src -d dist --copy-files --watch",
29
- "transpile": "babel src -d dist --copy-files",
30
- "prebuild": "rimraf dist",
31
- "build": "npm run transpile && npm run build:esm",
32
- "build:esm": "cross-env BABEL_ENV=esm babel src -d dist/esm --copy-files && echo '{\"type\":\"module\"}' > dist/esm/package.json",
33
- "prepublishOnly": "npm run build"
34
- },
35
- "peerDependencies": {
36
- "react": ">= 16.3.0",
37
- "react-dom": ">= 16.3.0"
38
- },
39
- "keywords": [
40
- "hcaptcha",
41
- "hcaptcha-react",
42
- "react",
43
- "captcha"
40
+ "README.md",
41
+ "lib/dist",
42
+ "types",
43
+ "!**/*.tsbuildinfo"
44
44
  ],
45
- "author": "hCaptcha team and contributors",
46
- "repository": {
47
- "type": "git",
48
- "url": "https://github.com/hCaptcha/react-hcaptcha.git"
49
- },
50
- "license": "MIT",
51
45
  "devDependencies": {
52
- "@babel/cli": "^7.12.1",
53
- "@babel/core": "^7.12.10",
54
- "@babel/plugin-transform-runtime": "^7.14.5",
55
- "@babel/preset-env": "^7.12.11",
56
- "@babel/preset-react": "^7.12.10",
57
- "@jest/globals": "^29.5.0",
58
- "@types/react": "^16.0.0",
59
- "babel-loader": "^8.2.2",
60
- "babel-plugin-add-module-exports": "^1.0.4",
61
- "cross-env": "^7.0.3",
62
- "html-webpack-plugin": "^5.5.0",
63
- "jest": "^29.5.0",
64
- "jest-environment-jsdom": "^29.5.0",
65
- "react": "^16.14.0",
66
- "react-dom": "^16.14.0",
67
- "rimraf": "^3.0.2",
68
- "wait-for-expect": "^3.0.2",
69
- "webpack": "^5.76.3",
70
- "webpack-cli": "^5.0.1",
71
- "webpack-dev-server": "^5.2.1"
46
+ "@types/node": "^18.19.130",
47
+ "@types/react": "^18.0.0",
48
+ "concurrently": "^9.2.1"
72
49
  },
73
- "dependencies": {
74
- "@babel/runtime": "^7.17.9",
75
- "@hcaptcha/loader": "^2.3.0"
50
+ "scripts": {
51
+ "setup": "pnpm install --prefer-offline && pnpm --filter=@hcaptcha-react/lib run compile:build",
52
+ "start": "concurrently 'pnpm --filter=@hcaptcha-react/lib run compile:watch' 'pnpm --filter=@hcaptcha-react/demo run start'",
53
+ "build": "pnpm --filter=@hcaptcha-react/lib run compile:build",
54
+ "test": "pnpm --filter=@hcaptcha-react/lib run test:unit"
76
55
  }
77
- }
56
+ }
@@ -20,6 +20,5 @@ export interface HCaptchaProviderProps {
20
20
  children?: React.ReactNode;
21
21
  }
22
22
 
23
- export function useHCaptcha(): HCaptchaContextValue;
24
-
25
- export function HCaptchaProvider(props: HCaptchaProviderProps): React.JSX.Element;
23
+ export declare function useHCaptcha(): HCaptchaContextValue;
24
+ export declare function HCaptchaProvider(props: HCaptchaProviderProps): React.ReactElement | null;
package/types/index.d.ts CHANGED
@@ -1,31 +1,30 @@
1
- // Type definitions for @hcaptcha/react-hcaptcha 0.1
1
+ // Type definitions for @hcaptcha/react-hcaptcha 2.0
2
2
  // Project: https://github.com/hCaptcha/react-hcaptcha
3
3
  // Definitions by: Matt Sutkowski <https://github.com/msutkowski>
4
4
  // Original Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
- // TypeScript Version: 2.8
6
5
 
7
6
  import * as React from "react";
8
7
 
9
- interface HCaptchaState {
8
+ export interface HCaptchaState {
10
9
  isApiReady: boolean;
11
10
  isRemoved: boolean;
12
11
  elementId: string;
13
12
  captchaId: string;
14
13
  }
15
14
 
16
- interface HCaptchaProps {
17
- onExpire?: () => any;
18
- onOpen?: () => any;
19
- onClose?: () => any;
20
- onChalExpired?: () => any;
21
- onError?: (event: string) => any;
22
- onVerify?: (token: string, ekey: string) => any;
23
- onLoad?: () => any;
24
- onReady?: () => any;
15
+ export interface HCaptchaProps {
16
+ onExpire?: () => void;
17
+ onOpen?: () => void;
18
+ onClose?: () => void;
19
+ onChalExpired?: () => void;
20
+ onError?: (event: string) => void;
21
+ onVerify?: (token: string, ekey: string) => void;
22
+ onLoad?: () => void;
23
+ onReady?: () => void;
25
24
  languageOverride?: string;
26
25
  sitekey: string;
27
26
  size?: "normal" | "compact" | "invisible";
28
- theme?: "light" | "dark" | "contrast" | Object;
27
+ theme?: "light" | "dark" | "contrast" | object;
29
28
  tabIndex?: number;
30
29
  id?: string;
31
30
  reCaptchaCompat?: boolean;
@@ -45,12 +44,12 @@ interface HCaptchaProps {
45
44
  reportapi?: string;
46
45
  }
47
46
 
48
- interface ExecuteResponse {
47
+ export interface ExecuteResponse {
49
48
  response: string;
50
49
  key: string;
51
50
  }
52
51
 
53
- declare class HCaptcha extends React.Component<HCaptchaProps, HCaptchaState> {
52
+ export declare class HCaptcha extends React.Component<HCaptchaProps, HCaptchaState> {
54
53
  resetCaptcha(): void;
55
54
  renderCaptcha(): void;
56
55
  removeCaptcha(): void;
@@ -58,9 +57,9 @@ declare class HCaptcha extends React.Component<HCaptchaProps, HCaptchaState> {
58
57
  getResponse(): string;
59
58
  setData(data: object): void;
60
59
  isReady(): boolean;
61
- execute(opts: { async: true, rqdata?: string }): Promise<ExecuteResponse>;
62
- execute(opts?: { async: false, rqdata?: string }): void;
63
- execute(opts?: { async?: boolean, rqdata?: string }): Promise<ExecuteResponse> | void;
60
+ execute(opts: { async: true; rqdata?: string }): Promise<ExecuteResponse>;
61
+ execute(opts?: { async: false; rqdata?: string }): void;
62
+ execute(opts?: { async?: boolean; rqdata?: string }): Promise<ExecuteResponse> | void;
64
63
  }
65
64
 
66
- export = HCaptcha;
65
+ export default HCaptcha;
@@ -1,2 +0,0 @@
1
- import { createContext } from "react";
2
- export var HCaptchaContext = /*#__PURE__*/createContext();
@@ -1,120 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
- import _regeneratorRuntime from "@babel/runtime/regenerator";
4
- import React, { useEffect, useRef, useState } from "react";
5
- import HCaptcha from "../index";
6
- import { HCaptchaContext } from "./Context";
7
- export var HCaptchaProvider = function HCaptchaProvider(_ref) {
8
- var _ref$sitekey = _ref.sitekey,
9
- sitekey = _ref$sitekey === void 0 ? null : _ref$sitekey,
10
- _ref$size = _ref.size,
11
- size = _ref$size === void 0 ? "normal" : _ref$size,
12
- _ref$theme = _ref.theme,
13
- theme = _ref$theme === void 0 ? "light" : _ref$theme,
14
- _ref$rqdata = _ref.rqdata,
15
- rqdata = _ref$rqdata === void 0 ? null : _ref$rqdata,
16
- _ref$languageOverride = _ref.languageOverride,
17
- languageOverride = _ref$languageOverride === void 0 ? null : _ref$languageOverride,
18
- onVerify = _ref.onVerify,
19
- onError = _ref.onError,
20
- children = _ref.children;
21
- var hcaptchaRef = useRef(null);
22
- var _useState = useState(false),
23
- ready = _useState[0],
24
- setReady = _useState[1];
25
- var _useState2 = useState(null),
26
- token = _useState2[0],
27
- setToken = _useState2[1];
28
- var _useState3 = useState(null),
29
- error = _useState3[0],
30
- setError = _useState3[1];
31
- var handleReady = function handleReady() {
32
- setReady(true);
33
- };
34
- var handleError = function handleError(error) {
35
- setError(error);
36
- onError && onError(error);
37
- };
38
- var handleExpire = function handleExpire() {
39
- setToken(null);
40
- };
41
- var handleVerify = function handleVerify(token) {
42
- setToken(token);
43
- onVerify && onVerify(token);
44
- };
45
- var executeInstance = /*#__PURE__*/function () {
46
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(config) {
47
- var _yield$hcaptchaRef$cu, response;
48
- return _regeneratorRuntime.wrap(function _callee$(_context) {
49
- while (1) switch (_context.prev = _context.next) {
50
- case 0:
51
- if (config === void 0) {
52
- config = {};
53
- }
54
- _context.prev = 1;
55
- if (ready) {
56
- _context.next = 4;
57
- break;
58
- }
59
- throw new Error("hCaptcha not ready");
60
- case 4:
61
- if (token) {
62
- resetInstance();
63
- }
64
- _context.next = 7;
65
- return hcaptchaRef.current.execute(_extends({
66
- async: true
67
- }, config.rqdata ? {
68
- rqdata: config.rqdata
69
- } : {}));
70
- case 7:
71
- _yield$hcaptchaRef$cu = _context.sent;
72
- response = _yield$hcaptchaRef$cu.response;
73
- setToken(response);
74
- return _context.abrupt("return", response);
75
- case 13:
76
- _context.prev = 13;
77
- _context.t0 = _context["catch"](1);
78
- setError(_context.t0);
79
- onError && onError(_context.t0);
80
- case 17:
81
- case "end":
82
- return _context.stop();
83
- }
84
- }, _callee, null, [[1, 13]]);
85
- }));
86
- return function executeInstance(_x) {
87
- return _ref2.apply(this, arguments);
88
- };
89
- }();
90
- var resetInstance = function resetInstance() {
91
- var _hcaptchaRef$current;
92
- hcaptchaRef == null || (_hcaptchaRef$current = hcaptchaRef.current) == null || _hcaptchaRef$current.resetCaptcha();
93
- };
94
- useEffect(function () {
95
- if (rqdata) {
96
- var _hcaptchaRef$current2;
97
- hcaptchaRef == null || (_hcaptchaRef$current2 = hcaptchaRef.current) == null || _hcaptchaRef$current2.setData(rqdata);
98
- }
99
- }, [rqdata]);
100
- return /*#__PURE__*/React.createElement(HCaptchaContext.Provider, {
101
- value: {
102
- sitekey: sitekey,
103
- error: error,
104
- token: token,
105
- ready: ready,
106
- executeInstance: executeInstance,
107
- resetInstance: resetInstance
108
- }
109
- }, children, /*#__PURE__*/React.createElement(HCaptcha, {
110
- sitekey: sitekey,
111
- size: size,
112
- theme: theme,
113
- languageOverride: languageOverride,
114
- onReady: handleReady,
115
- onVerify: handleVerify,
116
- onExpire: handleExpire,
117
- onError: handleError,
118
- ref: hcaptchaRef
119
- }));
120
- };
@@ -1,2 +0,0 @@
1
- export { useHCaptcha } from "./useHCaptcha";
2
- export { HCaptchaProvider } from "./Provider";
@@ -1,4 +0,0 @@
1
- import { useContext } from "react";
2
-
3
- import { HCaptchaContext } from "./Context";
4
- export const useHCaptcha = () => useContext(HCaptchaContext);