react-grecaptcha-v3
Version:
Google Recaptcha V3 for React.js based application. Keep website performance high while prioritizing security.
1 lines • 7.11 kB
Source Map (JSON)
{"version":3,"sources":["/home/runner/work/react-grecaptcha-v3/react-grecaptcha-v3/dist/useHandleNextInQueue.cjs","../src/useHandleNextInQueue.ts"],"names":["__create","Object","create","__defProp","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__getProtoOf","getPrototypeOf","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toESM","mod","isNodeMode","__esModule","value","__toCommonJS","useHandleNextInQueue_exports","default","useHandleNextInQueue_default","module","exports","import_react","require","import_subscribeEvent","unknownToError","err","fallbackMsg","msg","Error","message","useHandleNextInQueue","siteKey","queueRef","useCallback","item","current","shift","action","onComplete","onError","subscribeEvent","window","execute","grecaptcha","then","catch"],"mappings":"AAAA;;;;;;;;;;;;AACA,IAAIA,WAAWC,OAAOC,MAAM;AAC5B,IAAIC,YAAYF,OAAOG,cAAc;AACrC,IAAIC,mBAAmBJ,OAAOK,wBAAwB;AACtD,IAAIC,oBAAoBN,OAAOO,mBAAmB;AAClD,IAAIC,eAAeR,OAAOS,cAAc;AACxC,IAAIC,eAAeV,OAAOW,SAAS,CAACC,cAAc;AAClD,IAAIC,WAAW,SAACC,QAAQC;IACtB,IAAK,IAAIC,QAAQD,IACfb,UAAUY,QAAQE,MAAM;QAAEC,KAAKF,GAAG,CAACC,KAAK;QAAEE,YAAY;IAAK;AAC/D;AACA,IAAIC,cAAc,SAACC,IAAIC,MAAMC,QAAQC;IACnC,IAAIF,QAAQ,CAAA,OAAOA,qCAAP,SAAOA,KAAG,MAAM,YAAY,OAAOA,SAAS,YAAY;YAC7D,kCAAA,2BAAA;;;gBAAA,IAAIG,MAAJ;gBACH,IAAI,CAACd,aAAae,IAAI,CAACL,IAAII,QAAQA,QAAQF,QACzCpB,UAAUkB,IAAII,KAAK;oBAAEP,KA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,UAAYL,KAAZK;YAE5B,CAAA,GAAAhB,sBAAAiB,OAAAA,EAAe;oBACKC;;gBAAhB,IAAMC,mBAAUD,qBAAAA,OAAOE,UAAA,cAAPF,yCAAAA,mBAAmBC,OAAA,uCAAW;gBAC9C,IAAIA,YAAY,MAAM;oBAClBA,QAAQX,SAAS;wBAAEM,QAAAA;oBAAO,GACrBO,IAAA,CAAKN,YACLO,KAAA,CAAM,SAACpB;wBACJc,QAAQf,eAAeC;oBAC3B;oBACJ;gBACJ;gBACAc,QAAQ,IAAIX,MAAM;YACtB;QACJ;QAtBA,IAAIG,YAAY,MAAM;YAClB;QACJ;QACA;;;gBAmBS,MAAA;IACb,GAAG;QAACC;QAAUD;KAAQ;;AAC1B,IAAOb,+BAAQY","sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useHandleNextInQueue_exports = {};\n__export(useHandleNextInQueue_exports, {\n default: () => useHandleNextInQueue_default\n});\nmodule.exports = __toCommonJS(useHandleNextInQueue_exports);\nvar import_react = require(\"react\");\nvar import_subscribeEvent = __toESM(require(\"./subscribeEvent\"), 1);\nconst unknownToError = (err, fallbackMsg = \"Unexpected error\") => {\n const msg = err instanceof Error ? err.message : typeof err === \"string\" ? err : fallbackMsg;\n return new Error(msg);\n};\nconst useHandleNextInQueue = (siteKey, queueRef) => (0, import_react.useCallback)(() => {\n if (siteKey === null) {\n return;\n }\n do {\n const item = queueRef.current.shift();\n if (item === void 0) {\n break;\n }\n const { action, onComplete, onError } = item;\n (0, import_subscribeEvent.default)(() => {\n const execute = window.grecaptcha?.execute ?? null;\n if (execute !== null) {\n execute(siteKey, { action }).then(onComplete).catch((err) => {\n onError(unknownToError(err));\n });\n return;\n }\n onError(new Error(\"Bad execute().\"));\n });\n } while (true);\n}, [queueRef, siteKey]);\nvar useHandleNextInQueue_default = useHandleNextInQueue;\n","import { type RefObject, useCallback } from 'react'\nimport subscribeEvent from './subscribeEvent'\nimport type { QueueItem } from './useQueueRef'\nconst unknownToError = (\n err: unknown,\n fallbackMsg = 'Unexpected error'\n): Error => {\n const msg =\n err instanceof Error\n ? err.message\n : typeof err === 'string'\n ? err\n : fallbackMsg\n return new Error(msg)\n}\n\nconst useHandleNextInQueue = (\n siteKey: string | null,\n queueRef: RefObject<QueueItem[]>\n): (() => void) =>\n useCallback(() => {\n if (siteKey === null) {\n return\n }\n do {\n const item = queueRef.current.shift()\n if (item === undefined) {\n break\n }\n const { action, onComplete, onError } = item\n\n subscribeEvent(() => {\n const execute = window.grecaptcha?.execute ?? null\n if (execute !== null) {\n execute(siteKey, { action })\n .then(onComplete)\n .catch((err: unknown) => {\n onError(unknownToError(err))\n })\n return\n }\n onError(new Error('Bad execute().'))\n })\n } while (true)\n }, [queueRef, siteKey])\nexport default useHandleNextInQueue\n"]}