next-recaptcha-v3 1.0.1 → 1.0.3

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.
Files changed (40) hide show
  1. package/lib/{cjs/ReCaptcha.d.ts → ReCaptcha.d.ts} +0 -0
  2. package/lib/{cjs/ReCaptchaProvider.d.ts → ReCaptchaProvider.d.ts} +0 -0
  3. package/lib/cjs/ReCaptcha.js +1 -0
  4. package/lib/cjs/ReCaptcha.js.map +1 -0
  5. package/lib/cjs/ReCaptchaProvider.js +1 -0
  6. package/lib/cjs/ReCaptchaProvider.js.map +1 -0
  7. package/lib/cjs/index.js +1 -0
  8. package/lib/cjs/index.js.map +1 -0
  9. package/lib/cjs/recaptcha.types.js +1 -0
  10. package/lib/cjs/recaptcha.types.js.map +1 -0
  11. package/lib/cjs/useReCaptcha.js +1 -0
  12. package/lib/cjs/useReCaptcha.js.map +1 -0
  13. package/lib/cjs/utils.js +1 -0
  14. package/lib/cjs/utils.js.map +1 -0
  15. package/lib/cjs/withReCaptcha.js +1 -0
  16. package/lib/cjs/withReCaptcha.js.map +1 -0
  17. package/lib/{cjs/index.d.ts → index.d.ts} +0 -0
  18. package/lib/index.esm.js +2 -0
  19. package/lib/index.esm.js.map +1 -0
  20. package/lib/index.js +2 -0
  21. package/lib/index.js.map +1 -0
  22. package/lib/{cjs/recaptcha.types.d.ts → recaptcha.types.d.ts} +0 -0
  23. package/lib/{cjs/useReCaptcha.d.ts → useReCaptcha.d.ts} +0 -0
  24. package/lib/{cjs/utils.d.ts → utils.d.ts} +0 -0
  25. package/lib/{cjs/withReCaptcha.d.ts → withReCaptcha.d.ts} +0 -0
  26. package/package.json +23 -15
  27. package/lib/esm/ReCaptcha.d.ts +0 -14
  28. package/lib/esm/ReCaptcha.js +0 -33
  29. package/lib/esm/ReCaptchaProvider.d.ts +0 -26
  30. package/lib/esm/ReCaptchaProvider.js +0 -67
  31. package/lib/esm/index.d.ts +0 -5
  32. package/lib/esm/index.js +0 -5
  33. package/lib/esm/recaptcha.types.d.ts +0 -111
  34. package/lib/esm/recaptcha.types.js +0 -3
  35. package/lib/esm/useReCaptcha.d.ts +0 -10
  36. package/lib/esm/useReCaptcha.js +0 -39
  37. package/lib/esm/utils.d.ts +0 -10
  38. package/lib/esm/utils.js +0 -14
  39. package/lib/esm/withReCaptcha.d.ts +0 -14
  40. package/lib/esm/withReCaptcha.js +0 -19
File without changes
@@ -34,3 +34,4 @@ const ReCaptcha = ({ action, onValidate, validate = true, reCaptchaKey, }) => {
34
34
  return null;
35
35
  };
36
36
  exports.ReCaptcha = ReCaptcha;
37
+ //# sourceMappingURL=ReCaptcha.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReCaptcha.js","sourceRoot":"","sources":["../../src/ReCaptcha.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAkC;AAClC,iDAA8C;AAS9C;;;GAGG;AACH,MAAM,SAAS,GAA6B,CAAC,EAC3C,MAAM,EACN,UAAU,EACV,QAAQ,GAAG,IAAI,EACf,YAAY,GACb,EAAE,EAAE;IACH,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAA,2BAAY,EAAC,YAAY,CAAC,CAAC;IAExD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,CAAC,QAAQ;YAAE,OAAO;QACtB,IAAI,OAAO,gBAAgB,KAAK,UAAU;YAAE,OAAO;QACnD,IAAI,OAAO,UAAU,KAAK,UAAU;YAAE,OAAO;QAE7C,MAAM,sBAAsB,GAAG,GAAS,EAAE;YACxC,MAAM,KAAK,GAAG,MAAM,gBAAgB,CAAC,MAAM,CAAC,CAAC;YAC7C,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC,CAAA,CAAC;QAEF,sBAAsB,EAAE,CAAC;IAC3B,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAErD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEO,8BAAS"}
@@ -96,3 +96,4 @@ const ReCaptchaProvider = (_a) => {
96
96
  react_1.default.createElement(script_1.default, Object.assign({ id: id, src: src, strategy: strategy, onLoad: onLoad, onError: onError }, props))));
97
97
  };
98
98
  exports.ReCaptchaProvider = ReCaptchaProvider;
99
+ //# sourceMappingURL=ReCaptchaProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReCaptchaProvider.js","sourceRoot":"","sources":["../../src/ReCaptchaProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAQe;AACf,yDAAkD;AAElD,mCAAgD;AAahD,MAAM,gBAAgB,GAAG,IAAA,qBAAa,EAAwB;IAC5D,YAAY,EAAE,IAAI;IAClB,UAAU,EAAE,IAAI;IAChB,MAAM,EAAE,KAAK;IACb,KAAK,EAAE,KAAK;CACb,CAAC,CAAC;AA+FM,4CAAgB;AA7FzB,MAAM,mBAAmB,GAAG,GAAG,EAAE;IAC/B,MAAM,MAAM,GAAG,IAAA,kBAAU,EAAC,gBAAgB,CAAC,CAAC;IAC5C,IAAA,qBAAa,EAAC,yBAAyB,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,EAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACxE,IAAA,qBAAa,EAAC,qBAAqB,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,EAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC;IAC/E,IAAA,qBAAa,EAAC,0BAA0B,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,EAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACxE,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAuFyB,kDAAmB;AA5E9C,MAAM,iBAAiB,GA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./ReCaptchaProvider"), exports);
20
20
  __exportStar(require("./useReCaptcha"), exports);
21
21
  __exportStar(require("./withReCaptcha"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,8CAA4B;AAC5B,sDAAoC;AACpC,iDAA+B;AAC/B,kDAAgC"}
@@ -2,3 +2,4 @@
2
2
  // Type definitions for Google Recaptcha 3.0
3
3
  // Copied from: https://github.com/DefinitelyTyped/DefinitelyTyped
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
+ //# sourceMappingURL=recaptcha.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recaptcha.types.js","sourceRoot":"","sources":["../../src/recaptcha.types.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,kEAAkE"}
@@ -40,3 +40,4 @@ const useReCaptcha = (passedReCaptchaKey) => {
40
40
  return Object.assign(Object.assign({}, contextProps), { grecaptcha, reCaptchaKey: siteKey, executeRecaptcha });
41
41
  };
42
42
  exports.useReCaptcha = useReCaptcha;
43
+ //# sourceMappingURL=useReCaptcha.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useReCaptcha.js","sourceRoot":"","sources":["../../src/useReCaptcha.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAoC;AACpC,2DAA0D;AAO1D;;;GAGG;AACH,MAAM,YAAY,GAAG,CAAC,kBAA2B,EAAqB,EAAE;IACtE,MAAM,KAAgD,IAAA,uCAAmB,GAAE,EAArE,EAAE,UAAU,EAAE,YAAY,OAA2C,EAAtC,YAAY,cAA3C,8BAA6C,CAAwB,CAAC;IAE5E,MAAM,OAAO,GAAG,kBAAkB,IAAI,YAAY,CAAC;IAEnD,MAAM,gBAAgB,GAAG,IAAA,mBAAW,EAClC,CAAO,MAAc,EAAE,EAAE;QACvB,IAAI,OAAO,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,OAAO,CAAA,KAAK,UAAU,EAAE;YAC7C,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;SAClD;QAED,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QAE7D,OAAO,MAAM,CAAC;IAChB,CAAC,CAAA,EACD,CAAC,UAAU,EAAE,OAAO,CAAC,CACtB,CAAC;IAEF,uCAAY,YAAY,KAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,gBAAgB,IAAG;AAClF,CAAC,CAAC;AAEO,oCAAY"}
package/lib/cjs/utils.js CHANGED
@@ -16,3 +16,4 @@ const getRecaptchaScriptSrc = ({ reCaptchaKey, language, useRecaptchaNet = false
16
16
  return src;
17
17
  };
18
18
  exports.getRecaptchaScriptSrc = getRecaptchaScriptSrc;
19
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACI,MAAM,qBAAqB,GAAG,CAAC,EACpC,YAAY,EACZ,QAAQ,EACR,eAAe,GAAG,KAAK,EACvB,aAAa,GAAG,KAAK,MAMnB,EAAE,EAAU,EAAE;IAChB,MAAM,QAAQ,GAAG,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,YAAY,CAAC;IAClE,MAAM,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,QAAQ,CAAC;IAE1D,IAAI,GAAG,GAAG,eAAe,QAAQ,cAAc,MAAM,GAAG,CAAC;IACzD,IAAI,YAAY;QAAE,GAAG,IAAI,UAAU,YAAY,EAAE,CAAC;IAClD,IAAI,QAAQ;QAAE,GAAG,IAAI,OAAO,QAAQ,EAAE,CAAC;IAEvC,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAnBW,QAAA,qBAAqB,yBAmBhC"}
@@ -23,3 +23,4 @@ function withReCaptcha(WrappedComponent) {
23
23
  return ComponentWithReCaptca;
24
24
  }
25
25
  exports.withReCaptcha = withReCaptcha;
26
+ //# sourceMappingURL=withReCaptcha.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withReCaptcha.js","sourceRoot":"","sources":["../../src/withReCaptcha.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,iDAA8C;AAK9C;;;GAGG;AACH,SAAS,aAAa,CACpB,gBAAwC;IAExC,wDAAwD;IACxD,MAAM,WAAW,GAAG,gBAAgB,CAAC,WAAW,IAAI,gBAAgB,CAAC,IAAI,IAAI,WAAW,CAAC;IAEzF,+FAA+F;IAC/F,MAAM,qBAAqB,GAAG,CAAC,KAAwC,EAAE,EAAE;QACzE,MAAM,cAAc,GAAG,IAAA,2BAAY,GAAE,CAAC;QAEtC,kEAAkE;QAClE,OAAO,8BAAC,gBAAgB,oBAAK,cAAc,EAAO,KAAW,EAAI,CAAC;IACpE,CAAC,CAAC;IAEF,qBAAqB,CAAC,WAAW,GAAG,iBAAiB,WAAW,GAAG,CAAC;IAEpE,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAEQ,sCAAa"}
File without changes
@@ -0,0 +1,2 @@
1
+ import e,{createContext as t,useContext as r,useDebugValue as n,useState as a,useEffect as o,useCallback as c,useMemo as i}from"react";import l from"next/script";function p(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(n=Object.getOwnPropertySymbols(e);a<n.length;a++)t.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(r[n[a]]=e[n[a]])}return r}function u(e,t,r,n){return new(r||(r=Promise))((function(a,o){function c(e){try{l(n.next(e))}catch(e){o(e)}}function i(e){try{l(n.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(c,i)}l((n=n.apply(e,t||[])).next())}))}const d=t({reCaptchaKey:null,grecaptcha:null,loaded:!1,error:!1}),s=()=>{const e=r(d);return n("grecaptcha available: "+((null==e?void 0:e.loaded)?"Yes":"No")),n("ReCaptcha Script: "+((null==e?void 0:e.loaded)?"Loaded":"Not Loaded")),n("Failed to load Script: "+((null==e?void 0:e.error)?"Yes":"No")),e},h=t=>{var{reCaptchaKey:r,useEnterprise:n=!1,useRecaptchaNet:u=!1,language:s,children:h,id:y="google-recaptcha-v3",strategy:f="afterInteractive",src:v,onLoad:g,onError:w}=t,m=p(t,["reCaptchaKey","useEnterprise","useRecaptchaNet","language","children","id","strategy","src","onLoad","onError"]);const[C,E]=a(null),[b,O]=a(!1),[K,j]=a(!1),x=r||process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY||null,N=v||(({reCaptchaKey:e,language:t,useRecaptchaNet:r=!1,useEnterprise:n=!1}={})=>{let a=`https://www.${r?"recaptcha.net":"google.com"}/recaptcha/${n?"enterprise.js":"api.js"}?`;return e&&(a+=`render=${e}`),t&&(a+=`&hl=${t}`),a})({reCaptchaKey:x,language:s,useRecaptchaNet:u,useEnterprise:n})||null;o((()=>{O(!1),j(!1)}),[N]);const R=c((e=>{var t;const r=n?null===(t=null===window||void 0===window?void 0:window.grecaptcha)||void 0===t?void 0:t.enterprise:null===window||void 0===window?void 0:window.grecaptcha;r&&r.ready((()=>{E(r),O(!0),null==g||g(r,e)}))}),[g,n]);o((()=>R()),[R]);const P=c((e=>{j(!0),null==w||w(e)}),[w]),L=i((()=>({reCaptchaKey:x,grecaptcha:C,loaded:b,error:K})),[x,C,b,K]);return e.createElement(d.Provider,{value:L},h,e.createElement(l,Object.assign({id:y,src:N,strategy:f,onLoad:R,onError:P},m)))},y=e=>{const t=s(),{grecaptcha:r,reCaptchaKey:n}=t,a=p(t,["grecaptcha","reCaptchaKey"]),o=e||n,i=c((e=>u(void 0,void 0,void 0,(function*(){if("function"!=typeof(null==r?void 0:r.execute))throw new Error("Recaptcha has not been loaded");return yield r.execute(o,{action:e})}))),[r,o]);return Object.assign(Object.assign({},a),{grecaptcha:r,reCaptchaKey:o,executeRecaptcha:i})},f=({action:e,onValidate:t,validate:r=!0,reCaptchaKey:n})=>{const{executeRecaptcha:a}=y(n);return o((()=>{if(!r)return;if("function"!=typeof a)return;if("function"!=typeof t)return;u(void 0,void 0,void 0,(function*(){const r=yield a(e);t(r)}))}),[e,t,r,a]),null};function v(t){const r=t.displayName||t.name||"Component",n=r=>{const n=y();return e.createElement(t,Object.assign({},n,r))};return n.displayName=`withReCaptcha(${r})`,n}export{f as ReCaptcha,d as ReCaptchaContext,h as ReCaptchaProvider,y as useReCaptcha,s as useReCaptchaContext,v as withReCaptcha};
2
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":["../node_modules/tslib/tslib.es6.js","../src/utils.ts","../src/ReCaptchaProvider.tsx","../src/useReCaptcha.tsx","../src/ReCaptcha.tsx","../src/withReCaptcha.tsx"],"sourcesContent":["/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n var desc = Object.getOwnPropertyDescriptor(m, k);\r\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\r\n desc = { enumerable: true, get: function() { return m[k]; } };\r\n }\r\n Object.defineProperty(o, k2, desc);\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n\r\nexport function __classPrivateFieldIn(state, receiver) {\r\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n}\r\n","/**\r\n * Function to generate the src for the script tag\r\n * Refs: https://developers.google.com/recaptcha/docs/loading\r\n */\r\nexport const getRecaptchaScriptSrc = ({\r\n reCaptchaKey,\r\n language,\r\n useRecaptchaNet = false,\r\n useEnterprise = false,\r\n}: {\r\n reCaptchaKey?: string;\r\n language?: string;\r\n useRecaptchaNet?: boolean;\r\n useEnterprise?: boolean;\r\n} = {}): string => {\r\n const hostName = useRecaptchaNet ? \"recaptcha.net\" : \"google.com\";\r\n const script = useEnterprise ? \"enterprise.js\" : \"api.js\";\r\n\r\n let src = `https://www.${hostName}/recaptcha/${script}?`;\r\n if (reCaptchaKey) src += `render=${reCaptchaKey}`;\r\n if (language) src += `&hl=${language}`;\r\n\r\n return src;\r\n};\r\n","import React, {\r\n useMemo,\r\n useState,\r\n useEffect,\r\n useCallback,\r\n useContext,\r\n createContext,\r\n useDebugValue,\r\n} from \"react\";\r\nimport Script, { ScriptProps } from \"next/script\";\r\nimport type { IReCaptcha } from \"./recaptcha.types\";\r\nimport { getRecaptchaScriptSrc } from \"./utils\";\r\n\r\ninterface ReCaptchaContextProps {\r\n /** reCAPTCHA_site_key */\r\n readonly reCaptchaKey: string | null;\r\n /** Global ReCaptcha object */\r\n readonly grecaptcha: IReCaptcha | null;\r\n /** Is ReCaptcha script loaded */\r\n readonly loaded: boolean;\r\n /** Is ReCaptcha failed to load */\r\n readonly error: boolean;\r\n}\r\n\r\nconst ReCaptchaContext = createContext<ReCaptchaContextProps>({\r\n reCaptchaKey: null,\r\n grecaptcha: null,\r\n loaded: false,\r\n error: false,\r\n});\r\n\r\nconst useReCaptchaContext = () => {\r\n const values = useContext(ReCaptchaContext);\r\n useDebugValue(`grecaptcha available: ${values?.loaded ? \"Yes\" : \"No\"}`);\r\n useDebugValue(`ReCaptcha Script: ${values?.loaded ? \"Loaded\" : \"Not Loaded\"}`);\r\n useDebugValue(`Failed to load Script: ${values?.error ? \"Yes\" : \"No\"}`);\r\n return values;\r\n};\r\n\r\ninterface ReCaptchaProviderProps extends Partial<Omit<ScriptProps, \"onLoad\">> {\r\n reCaptchaKey?: string;\r\n language?: string;\r\n useRecaptchaNet?: boolean;\r\n useEnterprise?: boolean;\r\n children?: React.ReactNode;\r\n onLoad?: (grecaptcha: IReCaptcha, e: any) => void;\r\n}\r\n\r\nconst ReCaptchaProvider: React.FC<ReCaptchaProviderProps> = ({\r\n reCaptchaKey: passedReCaptchaKey,\r\n\r\n useEnterprise = false,\r\n useRecaptchaNet = false,\r\n language,\r\n children,\r\n\r\n id = \"google-recaptcha-v3\",\r\n strategy = \"afterInteractive\",\r\n\r\n src: passedSrc,\r\n onLoad: passedOnLoad,\r\n onError: passedOnError,\r\n\r\n ...props\r\n}) => {\r\n const [grecaptcha, setGreCaptcha] = useState<IReCaptcha | null>(null);\r\n const [loaded, setLoaded] = useState(false);\r\n const [error, setError] = useState(false);\r\n\r\n const reCaptchaKey = passedReCaptchaKey || process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY || null;\r\n\r\n const src =\r\n passedSrc ||\r\n getRecaptchaScriptSrc({ reCaptchaKey, language, useRecaptchaNet, useEnterprise }) ||\r\n null;\r\n\r\n // Reset state when script src is changed\r\n useEffect(() => {\r\n setLoaded(false);\r\n setError(false);\r\n }, [src]);\r\n\r\n // Handle script load\r\n const onLoad = useCallback(\r\n (e?: any) => {\r\n const grecaptcha = useEnterprise ? window?.grecaptcha?.enterprise : window?.grecaptcha;\r\n\r\n if (grecaptcha) {\r\n grecaptcha.ready(() => {\r\n setGreCaptcha(grecaptcha);\r\n setLoaded(true);\r\n passedOnLoad?.(grecaptcha, e);\r\n });\r\n }\r\n },\r\n [passedOnLoad, useEnterprise],\r\n );\r\n\r\n // Run 'onLoad' function once just in case if grecaptcha is already globally available in window\r\n useEffect(() => onLoad(), [onLoad]);\r\n\r\n // Handle script error\r\n const onError = useCallback(\r\n (e: any) => {\r\n setError(true);\r\n passedOnError?.(e);\r\n },\r\n [passedOnError],\r\n );\r\n\r\n // Prevent unnecessary rerenders\r\n const value = useMemo(\r\n () => ({ reCaptchaKey, grecaptcha, loaded, error }),\r\n [reCaptchaKey, grecaptcha, loaded, error],\r\n );\r\n\r\n return (\r\n <ReCaptchaContext.Provider value={value}>\r\n {children}\r\n <Script id={id} src={src} strategy={strategy} onLoad={onLoad} onError={onError} {...props} />\r\n </ReCaptchaContext.Provider>\r\n );\r\n};\r\n\r\nexport { ReCaptchaContext, useReCaptchaContext, ReCaptchaProvider };\r\nexport type { ReCaptchaContextProps, ReCaptchaProviderProps };\r\n","import { useCallback } from \"react\";\r\nimport { useReCaptchaContext } from \"./ReCaptchaProvider\";\r\nimport type { ReCaptchaContextProps } from \"./ReCaptchaProvider\";\r\n\r\nexport interface useReCaptchaProps extends ReCaptchaContextProps {\r\n executeRecaptcha: (action: string) => Promise<string>;\r\n}\r\n\r\n/** React Hook to generate ReCaptcha token\r\n * @example\r\n * const { executeRecaptcha } = useReCaptcha()\r\n */\r\nconst useReCaptcha = (passedReCaptchaKey?: string): useReCaptchaProps => {\r\n const { grecaptcha, reCaptchaKey, ...contextProps } = useReCaptchaContext();\r\n\r\n const siteKey = passedReCaptchaKey || reCaptchaKey;\r\n\r\n const executeRecaptcha = useCallback(\r\n async (action: string) => {\r\n if (typeof grecaptcha?.execute !== \"function\") {\r\n throw new Error(\"Recaptcha has not been loaded\");\r\n }\r\n\r\n const result = await grecaptcha.execute(siteKey, { action });\r\n\r\n return result;\r\n },\r\n [grecaptcha, siteKey],\r\n );\r\n\r\n return { ...contextProps, grecaptcha, reCaptchaKey: siteKey, executeRecaptcha };\r\n};\r\n\r\nexport { useReCaptcha };\r\n","import { useEffect } from \"react\";\r\nimport { useReCaptcha } from \"./useReCaptcha\";\r\n\r\ninterface ReCaptchaProps {\r\n onValidate: (token: string) => void;\r\n action: string;\r\n validate?: boolean;\r\n reCaptchaKey?: string;\r\n}\r\n\r\n/** React Component to generate ReCaptcha token\r\n * @example\r\n * <ReCaptcha action='form-submit' onValidate={handleToken} />\r\n */\r\nconst ReCaptcha: React.FC<ReCaptchaProps> = ({\r\n action,\r\n onValidate,\r\n validate = true,\r\n reCaptchaKey,\r\n}) => {\r\n const { executeRecaptcha } = useReCaptcha(reCaptchaKey);\r\n\r\n useEffect(() => {\r\n if (!validate) return;\r\n if (typeof executeRecaptcha !== \"function\") return;\r\n if (typeof onValidate !== \"function\") return;\r\n\r\n const handleExecuteRecaptcha = async () => {\r\n const token = await executeRecaptcha(action);\r\n onValidate(token);\r\n };\r\n\r\n handleExecuteRecaptcha();\r\n }, [action, onValidate, validate, executeRecaptcha]);\r\n\r\n return null;\r\n};\r\n\r\nexport { ReCaptcha };\r\nexport type { ReCaptchaProps };\r\n","import React from \"react\";\r\nimport { useReCaptcha } from \"./useReCaptcha\";\r\nimport type { useReCaptchaProps } from \"./useReCaptcha\";\r\n\r\ninterface WithReCaptchaProps extends useReCaptchaProps {}\r\n\r\n/** React HOC to generate ReCaptcha token\r\n * @example\r\n * withReCaptcha(MyComponent)\r\n */\r\nfunction withReCaptcha<T extends WithReCaptchaProps = WithReCaptchaProps>(\r\n WrappedComponent: React.ComponentType<T>,\r\n) {\r\n // Try to create a nice displayName for React Dev Tools.\r\n const displayName = WrappedComponent.displayName || WrappedComponent.name || \"Component\";\r\n\r\n // Creating the inner component. The calculated Props type here is the where the magic happens.\r\n const ComponentWithReCaptca = (props: Omit<T, keyof WithReCaptchaProps>) => {\r\n const reCaptchaProps = useReCaptcha();\r\n\r\n // Pass current token and function to generate it to the component\r\n return <WrappedComponent {...reCaptchaProps} {...(props as T)} />;\r\n };\r\n\r\n ComponentWithReCaptca.displayName = `withReCaptcha(${displayName})`;\r\n\r\n return ComponentWithReCaptca;\r\n}\r\n\r\nexport { withReCaptcha };\r\nexport type { WithReCaptchaProps };\r\n"],"names":["__rest","s","e","t","p","Object","prototype","hasOwnProperty","call","indexOf","getOwnPropertySymbols","i","length","propertyIsEnumerable","__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","value","step","next","rejected","result","done","then","apply","ReCaptchaContext","createContext","reCaptchaKey","grecaptcha","loaded","error","useReCaptchaContext","values","useContext","useDebugValue","ReCaptchaProvider","_a","passedReCaptchaKey","useEnterprise","useRecaptchaNet","language","children","id","strategy","src","passedSrc","onLoad","passedOnLoad","onError","passedOnError","props","setGreCaptcha","useState","setLoaded","setError","process","env","NEXT_PUBLIC_RECAPTCHA_SITE_KEY","getRecaptchaScriptSrc","useEffect","useCallback","window","enterprise","ready","useMemo","React","Provider","createElement","Script","assign","useReCaptcha","contextProps","siteKey","executeRecaptcha","action","execute","Error","ReCaptcha","onValidate","validate","token","withReCaptcha","WrappedComponent","displayName","name","ComponentWithReCaptca","reCaptchaProps"],"mappings":"kKA0CO,SAASA,EAAOC,EAAGC,GACtB,IAAIC,EAAI,CAAA,EACR,IAAK,IAAIC,KAAKH,EAAOI,OAAOC,UAAUC,eAAeC,KAAKP,EAAGG,IAAMF,EAAEO,QAAQL,GAAK,IAC9ED,EAAEC,GAAKH,EAAEG,IACb,GAAS,MAALH,GAAqD,mBAAjCI,OAAOK,sBACtB,KAAIC,EAAI,EAAb,IAAgBP,EAAIC,OAAOK,sBAAsBT,GAAIU,EAAIP,EAAEQ,OAAQD,IAC3DT,EAAEO,QAAQL,EAAEO,IAAM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,WAAEA,EAAUD,aAAEA,GAAYS,EAAKmC,EAA/B7E,EAAA0C,EAAA,CAAA,aAAA,iBAEAoC,EAAUnC,GAAsBV,EAEhC8C,EAAmBb,GAChBc,GAAkBlE,OAAA,OAAA,OAAA,GAAA,YACvB,GAAmC,mBAAxBoB,aAAU,EAAVA,EAAY+C,SACrB,MAAM,IAAIC,MAAM,iCAKlB,aAFqBhD,EAAW+C,QAAQH,EAAS,CAAEE,UAGpD,KACD,CAAC9C,EAAY4C,IAGf,OAAYzE,OAAAsE,OAAAtE,OAAAsE,OAAA,CAAA,EAAAE,IAAc3C,aAAYD,aAAc6C,EAASC,oBAAmB,EChB5EI,EAAsC,EAC1CH,SACAI,aACAC,YAAW,EACXpD,mBAEA,MAAM8C,iBAAEA,GAAqBH,EAAa3C,GAe1C,OAbAgC,GAAU,KACR,IAAKoB,EAAU,OACf,GAAgC,mBAArBN,EAAiC,OAC5C,GAA0B,mBAAfK,EAA2B,OAEItE,OAAA,OAAA,OAAA,GAAA,YACxC,MAAMwE,QAAcP,EAAiBC,GACrCI,EAAWE,EACb,GAEwB,GACvB,CAACN,EAAQI,EAAYC,EAAUN,IAE3B,IAAI,ECzBb,SAASQ,EACPC,GAGA,MAAMC,EAAcD,EAAiBC,aAAeD,EAAiBE,MAAQ,YAGvEC,EAAyBnC,IAC7B,MAAMoC,EAAiBhB,IAGvB,OAAOL,gBAACiB,EAAgBnF,OAAAsE,OAAA,GAAKiB,EAAqBpC,GAAe,EAKnE,OAFAmC,EAAsBF,YAAc,iBAAiBA,KAE9CE,CACT"}
package/lib/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("next/script");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=a(e),n=a(t);function o(e,t){var a={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(a[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(e);n<r.length;n++)t.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(e,r[n])&&(a[r[n]]=e[r[n]])}return a}function c(e,t,a,r){return new(a||(a=Promise))((function(n,o){function c(e){try{l(r.next(e))}catch(e){o(e)}}function u(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof a?t:new a((function(e){e(t)}))).then(c,u)}l((r=r.apply(e,t||[])).next())}))}const u=e.createContext({reCaptchaKey:null,grecaptcha:null,loaded:!1,error:!1}),l=()=>{const t=e.useContext(u);return e.useDebugValue("grecaptcha available: "+((null==t?void 0:t.loaded)?"Yes":"No")),e.useDebugValue("ReCaptcha Script: "+((null==t?void 0:t.loaded)?"Loaded":"Not Loaded")),e.useDebugValue("Failed to load Script: "+((null==t?void 0:t.error)?"Yes":"No")),t},i=t=>{const a=l(),{grecaptcha:r,reCaptchaKey:n}=a,u=o(a,["grecaptcha","reCaptchaKey"]),i=t||n,s=e.useCallback((e=>c(void 0,void 0,void 0,(function*(){if("function"!=typeof(null==r?void 0:r.execute))throw new Error("Recaptcha has not been loaded");return yield r.execute(i,{action:e})}))),[r,i]);return Object.assign(Object.assign({},u),{grecaptcha:r,reCaptchaKey:i,executeRecaptcha:s})};exports.ReCaptcha=({action:t,onValidate:a,validate:r=!0,reCaptchaKey:n})=>{const{executeRecaptcha:o}=i(n);return e.useEffect((()=>{if(!r)return;if("function"!=typeof o)return;if("function"!=typeof a)return;c(void 0,void 0,void 0,(function*(){const e=yield o(t);a(e)}))}),[t,a,r,o]),null},exports.ReCaptchaContext=u,exports.ReCaptchaProvider=t=>{var{reCaptchaKey:a,useEnterprise:c=!1,useRecaptchaNet:l=!1,language:i,children:s,id:p="google-recaptcha-v3",strategy:d="afterInteractive",src:h,onLoad:f,onError:v}=t,y=o(t,["reCaptchaKey","useEnterprise","useRecaptchaNet","language","children","id","strategy","src","onLoad","onError"]);const[g,C]=e.useState(null),[w,b]=e.useState(!1),[x,E]=e.useState(!1),R=a||process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY||null,O=h||(({reCaptchaKey:e,language:t,useRecaptchaNet:a=!1,useEnterprise:r=!1}={})=>{let n=`https://www.${a?"recaptcha.net":"google.com"}/recaptcha/${r?"enterprise.js":"api.js"}?`;return e&&(n+=`render=${e}`),t&&(n+=`&hl=${t}`),n})({reCaptchaKey:R,language:i,useRecaptchaNet:l,useEnterprise:c})||null;e.useEffect((()=>{b(!1),E(!1)}),[O]);const m=e.useCallback((e=>{var t;const a=c?null===(t=null===window||void 0===window?void 0:window.grecaptcha)||void 0===t?void 0:t.enterprise:null===window||void 0===window?void 0:window.grecaptcha;a&&a.ready((()=>{C(a),b(!0),null==f||f(a,e)}))}),[f,c]);e.useEffect((()=>m()),[m]);const j=e.useCallback((e=>{E(!0),null==v||v(e)}),[v]),K=e.useMemo((()=>({reCaptchaKey:R,grecaptcha:g,loaded:w,error:x})),[R,g,w,x]);return r.default.createElement(u.Provider,{value:K},s,r.default.createElement(n.default,Object.assign({id:p,src:O,strategy:d,onLoad:m,onError:j},y)))},exports.useReCaptcha=i,exports.useReCaptchaContext=l,exports.withReCaptcha=function(e){const t=e.displayName||e.name||"Component",a=t=>{const a=i();return r.default.createElement(e,Object.assign({},a,t))};return a.displayName=`withReCaptcha(${t})`,a};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../node_modules/tslib/tslib.es6.js","../src/utils.ts","../src/ReCaptchaProvider.tsx","../src/useReCaptcha.tsx","../src/ReCaptcha.tsx","../src/withReCaptcha.tsx"],"sourcesContent":["/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n var desc = Object.getOwnPropertyDescriptor(m, k);\r\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\r\n desc = { enumerable: true, get: function() { return m[k]; } };\r\n }\r\n Object.defineProperty(o, k2, desc);\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n\r\nexport function __classPrivateFieldIn(state, receiver) {\r\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n}\r\n","/**\r\n * Function to generate the src for the script tag\r\n * Refs: https://developers.google.com/recaptcha/docs/loading\r\n */\r\nexport const getRecaptchaScriptSrc = ({\r\n reCaptchaKey,\r\n language,\r\n useRecaptchaNet = false,\r\n useEnterprise = false,\r\n}: {\r\n reCaptchaKey?: string;\r\n language?: string;\r\n useRecaptchaNet?: boolean;\r\n useEnterprise?: boolean;\r\n} = {}): string => {\r\n const hostName = useRecaptchaNet ? \"recaptcha.net\" : \"google.com\";\r\n const script = useEnterprise ? \"enterprise.js\" : \"api.js\";\r\n\r\n let src = `https://www.${hostName}/recaptcha/${script}?`;\r\n if (reCaptchaKey) src += `render=${reCaptchaKey}`;\r\n if (language) src += `&hl=${language}`;\r\n\r\n return src;\r\n};\r\n","import React, {\r\n useMemo,\r\n useState,\r\n useEffect,\r\n useCallback,\r\n useContext,\r\n createContext,\r\n useDebugValue,\r\n} from \"react\";\r\nimport Script, { ScriptProps } from \"next/script\";\r\nimport type { IReCaptcha } from \"./recaptcha.types\";\r\nimport { getRecaptchaScriptSrc } from \"./utils\";\r\n\r\ninterface ReCaptchaContextProps {\r\n /** reCAPTCHA_site_key */\r\n readonly reCaptchaKey: string | null;\r\n /** Global ReCaptcha object */\r\n readonly grecaptcha: IReCaptcha | null;\r\n /** Is ReCaptcha script loaded */\r\n readonly loaded: boolean;\r\n /** Is ReCaptcha failed to load */\r\n readonly error: boolean;\r\n}\r\n\r\nconst ReCaptchaContext = createContext<ReCaptchaContextProps>({\r\n reCaptchaKey: null,\r\n grecaptcha: null,\r\n loaded: false,\r\n error: false,\r\n});\r\n\r\nconst useReCaptchaContext = () => {\r\n const values = useContext(ReCaptchaContext);\r\n useDebugValue(`grecaptcha available: ${values?.loaded ? \"Yes\" : \"No\"}`);\r\n useDebugValue(`ReCaptcha Script: ${values?.loaded ? \"Loaded\" : \"Not Loaded\"}`);\r\n useDebugValue(`Failed to load Script: ${values?.error ? \"Yes\" : \"No\"}`);\r\n return values;\r\n};\r\n\r\ninterface ReCaptchaProviderProps extends Partial<Omit<ScriptProps, \"onLoad\">> {\r\n reCaptchaKey?: string;\r\n language?: string;\r\n useRecaptchaNet?: boolean;\r\n useEnterprise?: boolean;\r\n children?: React.ReactNode;\r\n onLoad?: (grecaptcha: IReCaptcha, e: any) => void;\r\n}\r\n\r\nconst ReCaptchaProvider: React.FC<ReCaptchaProviderProps> = ({\r\n reCaptchaKey: passedReCaptchaKey,\r\n\r\n useEnterprise = false,\r\n useRecaptchaNet = false,\r\n language,\r\n children,\r\n\r\n id = \"google-recaptcha-v3\",\r\n strategy = \"afterInteractive\",\r\n\r\n src: passedSrc,\r\n onLoad: passedOnLoad,\r\n onError: passedOnError,\r\n\r\n ...props\r\n}) => {\r\n const [grecaptcha, setGreCaptcha] = useState<IReCaptcha | null>(null);\r\n const [loaded, setLoaded] = useState(false);\r\n const [error, setError] = useState(false);\r\n\r\n const reCaptchaKey = passedReCaptchaKey || process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY || null;\r\n\r\n const src =\r\n passedSrc ||\r\n getRecaptchaScriptSrc({ reCaptchaKey, language, useRecaptchaNet, useEnterprise }) ||\r\n null;\r\n\r\n // Reset state when script src is changed\r\n useEffect(() => {\r\n setLoaded(false);\r\n setError(false);\r\n }, [src]);\r\n\r\n // Handle script load\r\n const onLoad = useCallback(\r\n (e?: any) => {\r\n const grecaptcha = useEnterprise ? window?.grecaptcha?.enterprise : window?.grecaptcha;\r\n\r\n if (grecaptcha) {\r\n grecaptcha.ready(() => {\r\n setGreCaptcha(grecaptcha);\r\n setLoaded(true);\r\n passedOnLoad?.(grecaptcha, e);\r\n });\r\n }\r\n },\r\n [passedOnLoad, useEnterprise],\r\n );\r\n\r\n // Run 'onLoad' function once just in case if grecaptcha is already globally available in window\r\n useEffect(() => onLoad(), [onLoad]);\r\n\r\n // Handle script error\r\n const onError = useCallback(\r\n (e: any) => {\r\n setError(true);\r\n passedOnError?.(e);\r\n },\r\n [passedOnError],\r\n );\r\n\r\n // Prevent unnecessary rerenders\r\n const value = useMemo(\r\n () => ({ reCaptchaKey, grecaptcha, loaded, error }),\r\n [reCaptchaKey, grecaptcha, loaded, error],\r\n );\r\n\r\n return (\r\n <ReCaptchaContext.Provider value={value}>\r\n {children}\r\n <Script id={id} src={src} strategy={strategy} onLoad={onLoad} onError={onError} {...props} />\r\n </ReCaptchaContext.Provider>\r\n );\r\n};\r\n\r\nexport { ReCaptchaContext, useReCaptchaContext, ReCaptchaProvider };\r\nexport type { ReCaptchaContextProps, ReCaptchaProviderProps };\r\n","import { useCallback } from \"react\";\r\nimport { useReCaptchaContext } from \"./ReCaptchaProvider\";\r\nimport type { ReCaptchaContextProps } from \"./ReCaptchaProvider\";\r\n\r\nexport interface useReCaptchaProps extends ReCaptchaContextProps {\r\n executeRecaptcha: (action: string) => Promise<string>;\r\n}\r\n\r\n/** React Hook to generate ReCaptcha token\r\n * @example\r\n * const { executeRecaptcha } = useReCaptcha()\r\n */\r\nconst useReCaptcha = (passedReCaptchaKey?: string): useReCaptchaProps => {\r\n const { grecaptcha, reCaptchaKey, ...contextProps } = useReCaptchaContext();\r\n\r\n const siteKey = passedReCaptchaKey || reCaptchaKey;\r\n\r\n const executeRecaptcha = useCallback(\r\n async (action: string) => {\r\n if (typeof grecaptcha?.execute !== \"function\") {\r\n throw new Error(\"Recaptcha has not been loaded\");\r\n }\r\n\r\n const result = await grecaptcha.execute(siteKey, { action });\r\n\r\n return result;\r\n },\r\n [grecaptcha, siteKey],\r\n );\r\n\r\n return { ...contextProps, grecaptcha, reCaptchaKey: siteKey, executeRecaptcha };\r\n};\r\n\r\nexport { useReCaptcha };\r\n","import { useEffect } from \"react\";\r\nimport { useReCaptcha } from \"./useReCaptcha\";\r\n\r\ninterface ReCaptchaProps {\r\n onValidate: (token: string) => void;\r\n action: string;\r\n validate?: boolean;\r\n reCaptchaKey?: string;\r\n}\r\n\r\n/** React Component to generate ReCaptcha token\r\n * @example\r\n * <ReCaptcha action='form-submit' onValidate={handleToken} />\r\n */\r\nconst ReCaptcha: React.FC<ReCaptchaProps> = ({\r\n action,\r\n onValidate,\r\n validate = true,\r\n reCaptchaKey,\r\n}) => {\r\n const { executeRecaptcha } = useReCaptcha(reCaptchaKey);\r\n\r\n useEffect(() => {\r\n if (!validate) return;\r\n if (typeof executeRecaptcha !== \"function\") return;\r\n if (typeof onValidate !== \"function\") return;\r\n\r\n const handleExecuteRecaptcha = async () => {\r\n const token = await executeRecaptcha(action);\r\n onValidate(token);\r\n };\r\n\r\n handleExecuteRecaptcha();\r\n }, [action, onValidate, validate, executeRecaptcha]);\r\n\r\n return null;\r\n};\r\n\r\nexport { ReCaptcha };\r\nexport type { ReCaptchaProps };\r\n","import React from \"react\";\r\nimport { useReCaptcha } from \"./useReCaptcha\";\r\nimport type { useReCaptchaProps } from \"./useReCaptcha\";\r\n\r\ninterface WithReCaptchaProps extends useReCaptchaProps {}\r\n\r\n/** React HOC to generate ReCaptcha token\r\n * @example\r\n * withReCaptcha(MyComponent)\r\n */\r\nfunction withReCaptcha<T extends WithReCaptchaProps = WithReCaptchaProps>(\r\n WrappedComponent: React.ComponentType<T>,\r\n) {\r\n // Try to create a nice displayName for React Dev Tools.\r\n const displayName = WrappedComponent.displayName || WrappedComponent.name || \"Component\";\r\n\r\n // Creating the inner component. The calculated Props type here is the where the magic happens.\r\n const ComponentWithReCaptca = (props: Omit<T, keyof WithReCaptchaProps>) => {\r\n const reCaptchaProps = useReCaptcha();\r\n\r\n // Pass current token and function to generate it to the component\r\n return <WrappedComponent {...reCaptchaProps} {...(props as T)} />;\r\n };\r\n\r\n ComponentWithReCaptca.displayName = `withReCaptcha(${displayName})`;\r\n\r\n return ComponentWithReCaptca;\r\n}\r\n\r\nexport { withReCaptcha };\r\nexport type { WithReCaptchaProps };\r\n"],"names":["__rest","s","e","t","p","Object","prototype","hasOwnProperty","call","indexOf","getOwnPropertySymbols","i","length","propertyIsEnumerable","__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","value","step","next","rejected","result","done","then","apply","ReCaptchaContext","createContext","reCaptchaKey","grecaptcha","loaded","error","useReCaptchaContext","values","useContext","useDebugValue","useReCaptcha","passedReCaptchaKey","_a","contextProps","siteKey","executeRecaptcha","useCallback","action","execute","Error","assign","onValidate","validate","useEffect","token","useEnterprise","useRecaptchaNet","language","children","id","strategy","src","passedSrc","onLoad","passedOnLoad","onError","passedOnError","props","setGreCaptcha","useState","setLoaded","setError","process","env","NEXT_PUBLIC_RECAPTCHA_SITE_KEY","getRecaptchaScriptSrc","window","enterprise","ready","useMemo","React","Provider","createElement","Script","WrappedComponent","displayName","name","ComponentWithReCaptca","reCaptchaProps"],"mappings":"8MA0CO,SAASA,EAAOC,EAAGC,GACtB,IAAIC,EAAI,CAAA,EACR,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F,OAAA8C,OAAA,GAAKsC,EAAqBrB,GAAe,EAKnE,OAFAoB,EAAsBF,YAAc,iBAAiBA,KAE9CE,CACT"}
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-recaptcha-v3",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "🤖 Next.js hook to add Google ReCaptcha to your application",
5
5
  "license": "MIT",
6
6
  "author": "Roman Zhuravlov",
@@ -15,13 +15,14 @@
15
15
  "react",
16
16
  "hook"
17
17
  ],
18
- "main": "./lib/cjs/index.js",
19
- "module": "./lib/esm/index.js",
20
- "types": "./lib/esm/index.d.ts",
18
+ "main": "lib/index.js",
19
+ "module": "lib/index.esm.js",
20
+ "types": "lib/index.d.ts",
21
21
  "files": [
22
- "/lib"
22
+ "lib"
23
23
  ],
24
24
  "scripts": {
25
+ "rollup": "rollup -c",
25
26
  "build": "yarn build:esm && yarn build:cjs",
26
27
  "build:esm": "tsc",
27
28
  "build:cjs": "tsc --module commonjs --outDir lib/cjs",
@@ -30,7 +31,8 @@
30
31
  "lint-fix": "eslint --fix",
31
32
  "fix": "npm run prettier && npm run lint-fix",
32
33
  "pre-commit": "npm run lint && lint-staged",
33
- "post-commit": "git update-index --again"
34
+ "post-commit": "git update-index --again",
35
+ "prepublishOnly": "npm run rollup"
34
36
  },
35
37
  "peerDependencies": {
36
38
  "next": ">=11.0.0",
@@ -41,23 +43,29 @@
41
43
  "node": ">=12.22.0"
42
44
  },
43
45
  "dependencies": {
44
- "next": "^12.1.6",
46
+ "next": "^12.2.5",
45
47
  "react": "^18.2.0",
46
48
  "react-dom": "^18.2.0"
47
49
  },
48
50
  "devDependencies": {
49
- "@types/node": "^18.0.0",
50
- "@types/react": "^18.0.14",
51
- "@types/react-dom": "^18.0.5",
52
- "@typescript-eslint/eslint-plugin": "^5.28.0",
53
- "@typescript-eslint/parser": "^5.28.0",
54
- "eslint": "^8.18.0",
55
- "eslint-config-next": "^12.1.6",
51
+ "@rollup/plugin-commonjs": "^22.0.2",
52
+ "@rollup/plugin-node-resolve": "^13.3.0",
53
+ "@types/node": "^18.7.5",
54
+ "@types/react": "^18.0.17",
55
+ "@types/react-dom": "^18.0.6",
56
+ "@typescript-eslint/eslint-plugin": "^5.33.1",
57
+ "@typescript-eslint/parser": "^5.33.1",
58
+ "eslint": "^8.22.0",
59
+ "eslint-config-next": "^12.2.5",
56
60
  "eslint-config-prettier": "^8.5.0",
57
61
  "husky": "^8.0.1",
58
- "lint-staged": "^13.0.2",
62
+ "lint-staged": "^13.0.3",
59
63
  "prettier": "^2.7.1",
60
64
  "pretty-quick": "^3.1.3",
65
+ "rollup": "^2.78.0",
66
+ "rollup-plugin-peer-deps-external": "^2.2.4",
67
+ "rollup-plugin-terser": "^7.0.2",
68
+ "rollup-plugin-typescript2": "^0.32.1",
61
69
  "typescript": "^4.7.4"
62
70
  },
63
71
  "lint-staged": {
@@ -1,14 +0,0 @@
1
- /// <reference types="react" />
2
- interface ReCaptchaProps {
3
- onValidate: (token: string) => void;
4
- action: string;
5
- validate?: boolean;
6
- reCaptchaKey?: string;
7
- }
8
- /** React Component to generate ReCaptcha token
9
- * @example
10
- * <ReCaptcha action='form-submit' onValidate={handleToken} />
11
- */
12
- declare const ReCaptcha: React.FC<ReCaptchaProps>;
13
- export { ReCaptcha };
14
- export type { ReCaptchaProps };
@@ -1,33 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { useEffect } from "react";
11
- import { useReCaptcha } from "./useReCaptcha";
12
- /** React Component to generate ReCaptcha token
13
- * @example
14
- * <ReCaptcha action='form-submit' onValidate={handleToken} />
15
- */
16
- const ReCaptcha = ({ action, onValidate, validate = true, reCaptchaKey, }) => {
17
- const { executeRecaptcha } = useReCaptcha(reCaptchaKey);
18
- useEffect(() => {
19
- if (!validate)
20
- return;
21
- if (typeof executeRecaptcha !== "function")
22
- return;
23
- if (typeof onValidate !== "function")
24
- return;
25
- const handleExecuteRecaptcha = () => __awaiter(void 0, void 0, void 0, function* () {
26
- const token = yield executeRecaptcha(action);
27
- onValidate(token);
28
- });
29
- handleExecuteRecaptcha();
30
- }, [action, onValidate, validate, executeRecaptcha]);
31
- return null;
32
- };
33
- export { ReCaptcha };
@@ -1,26 +0,0 @@
1
- import React from "react";
2
- import { ScriptProps } from "next/script";
3
- import type { IReCaptcha } from "./recaptcha.types";
4
- interface ReCaptchaContextProps {
5
- /** reCAPTCHA_site_key */
6
- readonly reCaptchaKey: string | null;
7
- /** Global ReCaptcha object */
8
- readonly grecaptcha: IReCaptcha | null;
9
- /** Is ReCaptcha script loaded */
10
- readonly loaded: boolean;
11
- /** Is ReCaptcha failed to load */
12
- readonly error: boolean;
13
- }
14
- declare const ReCaptchaContext: React.Context<ReCaptchaContextProps>;
15
- declare const useReCaptchaContext: () => ReCaptchaContextProps;
16
- interface ReCaptchaProviderProps extends Partial<Omit<ScriptProps, "onLoad">> {
17
- reCaptchaKey?: string;
18
- language?: string;
19
- useRecaptchaNet?: boolean;
20
- useEnterprise?: boolean;
21
- children?: React.ReactNode;
22
- onLoad?: (grecaptcha: IReCaptcha, e: any) => void;
23
- }
24
- declare const ReCaptchaProvider: React.FC<ReCaptchaProviderProps>;
25
- export { ReCaptchaContext, useReCaptchaContext, ReCaptchaProvider };
26
- export type { ReCaptchaContextProps, ReCaptchaProviderProps };
@@ -1,67 +0,0 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
- import React, { useMemo, useState, useEffect, useCallback, useContext, createContext, useDebugValue, } from "react";
13
- import Script from "next/script";
14
- import { getRecaptchaScriptSrc } from "./utils";
15
- const ReCaptchaContext = createContext({
16
- reCaptchaKey: null,
17
- grecaptcha: null,
18
- loaded: false,
19
- error: false,
20
- });
21
- const useReCaptchaContext = () => {
22
- const values = useContext(ReCaptchaContext);
23
- useDebugValue(`grecaptcha available: ${(values === null || values === void 0 ? void 0 : values.loaded) ? "Yes" : "No"}`);
24
- useDebugValue(`ReCaptcha Script: ${(values === null || values === void 0 ? void 0 : values.loaded) ? "Loaded" : "Not Loaded"}`);
25
- useDebugValue(`Failed to load Script: ${(values === null || values === void 0 ? void 0 : values.error) ? "Yes" : "No"}`);
26
- return values;
27
- };
28
- const ReCaptchaProvider = (_a) => {
29
- var { reCaptchaKey: passedReCaptchaKey, useEnterprise = false, useRecaptchaNet = false, language, children, id = "google-recaptcha-v3", strategy = "afterInteractive", src: passedSrc, onLoad: passedOnLoad, onError: passedOnError } = _a, props = __rest(_a, ["reCaptchaKey", "useEnterprise", "useRecaptchaNet", "language", "children", "id", "strategy", "src", "onLoad", "onError"]);
30
- const [grecaptcha, setGreCaptcha] = useState(null);
31
- const [loaded, setLoaded] = useState(false);
32
- const [error, setError] = useState(false);
33
- const reCaptchaKey = passedReCaptchaKey || process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY || null;
34
- const src = passedSrc ||
35
- getRecaptchaScriptSrc({ reCaptchaKey, language, useRecaptchaNet, useEnterprise }) ||
36
- null;
37
- // Reset state when script src is changed
38
- useEffect(() => {
39
- setLoaded(false);
40
- setError(false);
41
- }, [src]);
42
- // Handle script load
43
- const onLoad = useCallback((e) => {
44
- var _a;
45
- const grecaptcha = useEnterprise ? (_a = window === null || window === void 0 ? void 0 : window.grecaptcha) === null || _a === void 0 ? void 0 : _a.enterprise : window === null || window === void 0 ? void 0 : window.grecaptcha;
46
- if (grecaptcha) {
47
- grecaptcha.ready(() => {
48
- setGreCaptcha(grecaptcha);
49
- setLoaded(true);
50
- passedOnLoad === null || passedOnLoad === void 0 ? void 0 : passedOnLoad(grecaptcha, e);
51
- });
52
- }
53
- }, [passedOnLoad, useEnterprise]);
54
- // Run 'onLoad' function once just in case if grecaptcha is already globally available in window
55
- useEffect(() => onLoad(), [onLoad]);
56
- // Handle script error
57
- const onError = useCallback((e) => {
58
- setError(true);
59
- passedOnError === null || passedOnError === void 0 ? void 0 : passedOnError(e);
60
- }, [passedOnError]);
61
- // Prevent unnecessary rerenders
62
- const value = useMemo(() => ({ reCaptchaKey, grecaptcha, loaded, error }), [reCaptchaKey, grecaptcha, loaded, error]);
63
- return (React.createElement(ReCaptchaContext.Provider, { value: value },
64
- children,
65
- React.createElement(Script, Object.assign({ id: id, src: src, strategy: strategy, onLoad: onLoad, onError: onError }, props))));
66
- };
67
- export { ReCaptchaContext, useReCaptchaContext, ReCaptchaProvider };
@@ -1,5 +0,0 @@
1
- export * from "./recaptcha.types";
2
- export * from "./ReCaptcha";
3
- export * from "./ReCaptchaProvider";
4
- export * from "./useReCaptcha";
5
- export * from "./withReCaptcha";
package/lib/esm/index.js DELETED
@@ -1,5 +0,0 @@
1
- export * from "./recaptcha.types";
2
- export * from "./ReCaptcha";
3
- export * from "./ReCaptchaProvider";
4
- export * from "./useReCaptcha";
5
- export * from "./withReCaptcha";
@@ -1,111 +0,0 @@
1
- export interface Action {
2
- /**
3
- * the name of the action. Actions may only contain alphanumeric characters and slashes, and must not be user-specific.
4
- */
5
- action: string;
6
- }
7
- export declare type Theme = "light" | "dark";
8
- export declare type Type = "image" | "audio";
9
- export declare type Size = "normal" | "compact" | "invisible";
10
- export declare type Badge = "bottomright" | "bottomleft" | "inline";
11
- export interface Parameters {
12
- /**
13
- * Your sitekey.
14
- */
15
- sitekey?: string | undefined;
16
- /**
17
- * Optional. The color theme of the widget.
18
- * Accepted values: "light", "dark"
19
- * @default "light"
20
- */
21
- theme?: Theme | undefined;
22
- /**
23
- * Optional. The type of CAPTCHA to serve.
24
- * Accepted values: "audio", "image"
25
- * @default "image"
26
- */
27
- type?: Type | undefined;
28
- /**
29
- * Optional. The size of the widget.
30
- * Accepted values: "compact", "normal", "invisible".
31
- * @default "compact"
32
- */
33
- size?: Size | undefined;
34
- /**
35
- * Optional. The tabindex of the widget and challenge.
36
- * If other elements in your page use tabindex, it should be set to make user navigation easier.
37
- */
38
- tabindex?: number | undefined;
39
- /**
40
- * Optional. The badge location for g-recaptcha with size of "invisible".
41
- *
42
- * @default "bottomright"
43
- */
44
- badge?: Badge | undefined;
45
- /**
46
- * Optional. Invisible reCAPTCHA only. For plugin owners to not interfere with existing reCAPTCHA installations on a page.
47
- * If true, this reCAPTCHA instance will be part of a separate ID space.
48
- *
49
- * @default false
50
- */
51
- isolated?: boolean | undefined;
52
- /**
53
- * Optional. Your callback function that's executed when the user submits a successful CAPTCHA response.
54
- * The user's response, g-recaptcha-response, will be the input for your callback function.
55
- */
56
- callback?(response: string): void;
57
- /**
58
- * Optional. Your callback function that's executed when the reCAPTCHA response expires and the user needs to solve a new CAPTCHA.
59
- */
60
- "expired-callback"?(): void;
61
- /**
62
- * Optional. Your callback function that's executed when reCAPTCHA encounters an error (usually network connectivity) and cannot continue until connectivity is restored.
63
- * If you specify this function, you are responsible for informing the user that they should retry.
64
- */
65
- "error-callback"?(): void;
66
- }
67
- export interface IReCaptcha {
68
- /**
69
- * Renders the container as a reCAPTCHA widget and returns the ID of the newly created widget.
70
- * @param container The HTML element to render the reCAPTCHA widget. Specify either the ID of the container (string) or the DOM element itself.
71
- * @param parameters An object containing parameters as key=value pairs, for example, {"sitekey": "your_site_key", "theme": "light"}. See @see render parameters.
72
- * @param inherit Invisible reCAPTCHA only. Use existing data-* attributes on the element if the corresponding parameter is not specified.
73
- * The values in parameters will take precedence over the attributes.
74
- * @return the ID of the newly created widget.
75
- */
76
- render(container: string | HTMLElement, parameters?: Parameters, inherit?: boolean): number;
77
- /**
78
- * Resets the reCAPTCHA widget.
79
- * @param opt_widget_id Optional widget ID, defaults to the first widget created if unspecified.
80
- */
81
- reset(opt_widget_id?: number): void;
82
- /**
83
- * Gets the response for the reCAPTCHA widget.
84
- * @param opt_widget_id Optional widget ID, defaults to the first widget created if unspecified.
85
- * @return the response of the reCAPTCHA widget.
86
- */
87
- getResponse(opt_widget_id?: number): string;
88
- /**
89
- * Programatically invoke the reCAPTCHA check. Used if the invisible reCAPTCHA is on a div instead of a button.
90
- * @param opt_widget_id Optional widget ID, defaults to the first widget created if unspecified.
91
- */
92
- execute(opt_widget_id?: number): PromiseLike<void>;
93
- /**
94
- * Programatically invoke the reCAPTCHA check. Used if the invisible reCAPTCHA is on a div instead of a button.
95
- * @param siteKey the key of your site
96
- * @param action the action
97
- *
98
- * @return a promise-like object containing the token
99
- */
100
- execute(siteKey: string, action: Action): PromiseLike<string>;
101
- /**
102
- * will run the given function as soon as the reCAPTCHA library has loaded
103
- * @param callback the function to coll
104
- */
105
- ready(callback: () => void): void;
106
- }
107
- declare global {
108
- var grecaptcha: IReCaptcha & {
109
- enterprise: IReCaptcha;
110
- };
111
- }
@@ -1,3 +0,0 @@
1
- // Type definitions for Google Recaptcha 3.0
2
- // Copied from: https://github.com/DefinitelyTyped/DefinitelyTyped
3
- export {};
@@ -1,10 +0,0 @@
1
- import type { ReCaptchaContextProps } from "./ReCaptchaProvider";
2
- export interface useReCaptchaProps extends ReCaptchaContextProps {
3
- executeRecaptcha: (action: string) => Promise<string>;
4
- }
5
- /** React Hook to generate ReCaptcha token
6
- * @example
7
- * const { executeRecaptcha } = useReCaptcha()
8
- */
9
- declare const useReCaptcha: (passedReCaptchaKey?: string) => useReCaptchaProps;
10
- export { useReCaptcha };
@@ -1,39 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __rest = (this && this.__rest) || function (s, e) {
11
- var t = {};
12
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
- t[p] = s[p];
14
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
- t[p[i]] = s[p[i]];
18
- }
19
- return t;
20
- };
21
- import { useCallback } from "react";
22
- import { useReCaptchaContext } from "./ReCaptchaProvider";
23
- /** React Hook to generate ReCaptcha token
24
- * @example
25
- * const { executeRecaptcha } = useReCaptcha()
26
- */
27
- const useReCaptcha = (passedReCaptchaKey) => {
28
- const _a = useReCaptchaContext(), { grecaptcha, reCaptchaKey } = _a, contextProps = __rest(_a, ["grecaptcha", "reCaptchaKey"]);
29
- const siteKey = passedReCaptchaKey || reCaptchaKey;
30
- const executeRecaptcha = useCallback((action) => __awaiter(void 0, void 0, void 0, function* () {
31
- if (typeof (grecaptcha === null || grecaptcha === void 0 ? void 0 : grecaptcha.execute) !== "function") {
32
- throw new Error("Recaptcha has not been loaded");
33
- }
34
- const result = yield grecaptcha.execute(siteKey, { action });
35
- return result;
36
- }), [grecaptcha, siteKey]);
37
- return Object.assign(Object.assign({}, contextProps), { grecaptcha, reCaptchaKey: siteKey, executeRecaptcha });
38
- };
39
- export { useReCaptcha };
@@ -1,10 +0,0 @@
1
- /**
2
- * Function to generate the src for the script tag
3
- * Refs: https://developers.google.com/recaptcha/docs/loading
4
- */
5
- export declare const getRecaptchaScriptSrc: ({ reCaptchaKey, language, useRecaptchaNet, useEnterprise, }?: {
6
- reCaptchaKey?: string;
7
- language?: string;
8
- useRecaptchaNet?: boolean;
9
- useEnterprise?: boolean;
10
- }) => string;
package/lib/esm/utils.js DELETED
@@ -1,14 +0,0 @@
1
- /**
2
- * Function to generate the src for the script tag
3
- * Refs: https://developers.google.com/recaptcha/docs/loading
4
- */
5
- export const getRecaptchaScriptSrc = ({ reCaptchaKey, language, useRecaptchaNet = false, useEnterprise = false, } = {}) => {
6
- const hostName = useRecaptchaNet ? "recaptcha.net" : "google.com";
7
- const script = useEnterprise ? "enterprise.js" : "api.js";
8
- let src = `https://www.${hostName}/recaptcha/${script}?`;
9
- if (reCaptchaKey)
10
- src += `render=${reCaptchaKey}`;
11
- if (language)
12
- src += `&hl=${language}`;
13
- return src;
14
- };
@@ -1,14 +0,0 @@
1
- import React from "react";
2
- import type { useReCaptchaProps } from "./useReCaptcha";
3
- interface WithReCaptchaProps extends useReCaptchaProps {
4
- }
5
- /** React HOC to generate ReCaptcha token
6
- * @example
7
- * withReCaptcha(MyComponent)
8
- */
9
- declare function withReCaptcha<T extends WithReCaptchaProps = WithReCaptchaProps>(WrappedComponent: React.ComponentType<T>): {
10
- (props: Omit<T, keyof WithReCaptchaProps>): JSX.Element;
11
- displayName: string;
12
- };
13
- export { withReCaptcha };
14
- export type { WithReCaptchaProps };
@@ -1,19 +0,0 @@
1
- import React from "react";
2
- import { useReCaptcha } from "./useReCaptcha";
3
- /** React HOC to generate ReCaptcha token
4
- * @example
5
- * withReCaptcha(MyComponent)
6
- */
7
- function withReCaptcha(WrappedComponent) {
8
- // Try to create a nice displayName for React Dev Tools.
9
- const displayName = WrappedComponent.displayName || WrappedComponent.name || "Component";
10
- // Creating the inner component. The calculated Props type here is the where the magic happens.
11
- const ComponentWithReCaptca = (props) => {
12
- const reCaptchaProps = useReCaptcha();
13
- // Pass current token and function to generate it to the component
14
- return React.createElement(WrappedComponent, Object.assign({}, reCaptchaProps, props));
15
- };
16
- ComponentWithReCaptca.displayName = `withReCaptcha(${displayName})`;
17
- return ComponentWithReCaptca;
18
- }
19
- export { withReCaptcha };