UNPKG

capacitor-plugin-recaptcha

Version:
43 lines (37 loc) 1.52 kB
'use strict'; var core = require('@capacitor/core'); var recaptchaV3 = require('recaptcha-v3'); const CapacitorPluginRecaptcha$1 = core.registerPlugin('RecaptchaEnterprise', { web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorPluginRecaptcha()), }); class CapacitorPluginRecaptcha extends core.WebPlugin { /** * Loads the reCAPTCHA SDK for the given siteKey. Should be called during app startup. * @param siteKey The reCAPTCHA site key to use. */ async load(options) { this._recaptcha = await recaptchaV3.load(options.siteKey, { useEnterprise: true }); this._siteKey = options.siteKey; } /** * Executes reCAPTCHA with the previously loaded siteKey. Throws if not loaded. */ async execute(options) { if (!this._recaptcha || !this._siteKey) { throw new Error('reCAPTCHA not loaded. Call load(siteKey) during app startup.'); } try { const token = await this._recaptcha.execute(options.action); return { token, siteKey: this._siteKey }; } catch (err) { throw new Error(`reCAPTCHA execution failed: ${(err === null || err === void 0 ? void 0 : err.message) || JSON.stringify(err)}`); } } } var web = /*#__PURE__*/Object.freeze({ __proto__: null, CapacitorPluginRecaptcha: CapacitorPluginRecaptcha }); exports.CapacitorPluginRecaptcha = CapacitorPluginRecaptcha$1; //# sourceMappingURL=plugin.cjs.js.map