@dropins/tools 0.26.0-alpha227 → 0.26.0-alpha229
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/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name": "@dropins/tools", "version": "0.26.0-
|
|
1
|
+
{"name": "@dropins/tools", "version": "0.26.0-alpha229"}
|
package/recaptcha.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{FetchGraphQL as
|
|
1
|
+
import{FetchGraphQL as h}from"./fetch-graphql.js";const o={failedFetch:"Failed to fetch config from backend with status:",failedSetStorageConfig:"Failed to set storage config",failedGetStorageConfig:"Configuration could not be loaded.",failedExecutionRecaptcha:"Recaptcha execution failed",failedInitializing:"An error occurred while initializing ReCaptcha:"},g={PLACE_ORDER:"placeOrder",CONTACT:"contactUs",CUSTOMER_LOGIN:"generateCustomerToken",CUSTOMER_FORGOT_PASSWORD:"requestPasswordResetEmail",CUSTOMER_CREATE:"createCustomerV2",CUSTOMER_EDIT:"updateCustomerV2",NEWSLETTER:"subscribeEmailToNewsletter",PRODUCT_REVIEW:"createProductReview",SENDFRIEND:"SENDFRIEND",BRAINTREE:"BRAINTREE"},l=(a,e)=>{if(a&&a.forms){const t=a.forms.concat(e).map(r=>typeof r!="string"?{...r,enabledBadgePlace:!1}:{badgeId:g[r],enabledBadgePlace:!1});return{...a,forms:[...new Set(t)]}}return{}},c=async(a,e=1,t=1e3)=>{const r=sessionStorage.getItem(a);return r!==null?JSON.parse(r):e>0?(await new Promise(i=>setTimeout(i,t)),c(a,e-1,t)):null},f=(a,e,t)=>{if(!a||!e.website_key)return null;try{sessionStorage.setItem(a,JSON.stringify(e))}catch(r){return t&&console.error(o.failedSetStorageConfig,r),null}},{failedExecutionRecaptcha:s}=o,p=async a=>{if(!window.grecaptcha)return Promise.reject(s);try{return await window.grecaptcha.execute(a,{action:"click"})}catch(e){return Promise.reject(`${s} : ${e}`)}},u=()=>new Promise(a=>{const e=new MutationObserver((r,i)=>{window.grecaptcha&&(i.disconnect(),a(!0))}),t={childList:!0,subtree:!0,attributes:!0};e.observe(document.body,t)}),_=async(a,e,t)=>(window.grecaptcha||await u(),grecaptcha.ready(()=>{const r=document.querySelectorAll(`#${a}`);if(!r.length)return null;r.forEach(i=>i.id=`${i.id}_${Math.random().toString(36)}`),r.forEach(i=>{if(i.innerHTML==="")try{grecaptcha.render(i.id,{sitekey:e.website_key,badge:e.badge_position,size:"invisible"})}catch(d){t&&console.error(d)}})})),C=`query {
|
|
2
2
|
recaptchaV3Config {
|
|
3
3
|
is_enabled
|
|
4
4
|
website_key
|
|
@@ -8,4 +8,4 @@ import{FetchGraphQL as p}from"./fetch-graphql.js";const o={failedFetch:"Failed t
|
|
|
8
8
|
failure_message
|
|
9
9
|
forms
|
|
10
10
|
}
|
|
11
|
-
}`,n=new
|
|
11
|
+
}`,n=new h().getMethods();class b{constructor(){var e;this._enableReCAPTCHA=!1,this._recaptchaBackendEndpoint=((e=n.getConfig())==null?void 0:e.endpoint)||"",this._recaptchaScriptUrl="https://www.google.com/recaptcha/api.js",this._configStorageKey="recaptchaConfig",this._logger=!1}async _updateBadgePosition(e,t){if((t==null?void 0:t.badge_position)!=="inline")return null;await _(e,t,this._logger)}async _addRecaptchaScript(){const e=await this._loadConfig();if(!document.getElementById("recaptchaId")&&e){const t=e.website_key,r=e.badge_position==="inline";if(!t)return;const i=document.createElement("script");i.setAttribute("id","recaptchaId"),i.src=r?`${this._recaptchaScriptUrl}?render=${t}&badge=none`:`${this._recaptchaScriptUrl}?render=${t}&badge=${e.badge_position}`,document.head.appendChild(i)}}async _fetchStoreConfig(){var e;try{const t=await n.fetchGraphQl(C,{method:"GET",cache:"force-cache"});if((e=t==null?void 0:t.errors)!=null&&e.length){this._logger&&console.error(t.errors[0].message);return}return t}catch(t){this._logger&&console.error(`${o.failedFetch}:`,t)}}async _loadConfig(){const e=await c(this._configStorageKey);return e?(this._enableReCAPTCHA=!!e.is_enabled,e):(this._logger&&console.error(o.failedGetStorageConfig),null)}setEndpoint(e){e&&(this._recaptchaBackendEndpoint=e,n.setEndpoint(e))}async setConfig(e){var t;try{const r=await this._fetchStoreConfig();if(!((t=r==null?void 0:r.data)!=null&&t.recaptchaV3Config)){sessionStorage.removeItem(this._configStorageKey);return}const i=l(r.data.recaptchaV3Config,e);f(this._configStorageKey,i,this._logger)}catch(r){this._logger&&console.error(o.failedSetStorageConfig,r),sessionStorage.removeItem(this._configStorageKey)}}async initReCaptcha(){try{const e=await this._loadConfig();if(!(e!=null&&e.forms)||!e.is_enabled)return;await this._addRecaptchaScript();for(let t=0;t<e.forms.length;t++){const r=e.forms[t];await this._updateBadgePosition(r.badgeId,e)}}catch(e){this._logger&&console.error(o.failedInitializing,e)}}async verifyReCaptcha(){try{const e=await this._loadConfig();return!(e!=null&&e.forms)||!e.website_key||!e.is_enabled?void 0:await p(e.website_key)}catch(e){this._logger&&console.error(e)}}enableLogger(e){this._logger=e}getMethods(){return{enableLogger:this.enableLogger.bind(this),setEndpoint:this.setEndpoint.bind(this),setConfig:this.setConfig.bind(this),initReCaptcha:this.initReCaptcha.bind(this),verifyReCaptcha:this.verifyReCaptcha.bind(this)}}}const m=new b,{initReCaptcha:R,verifyReCaptcha:y,setEndpoint:S,setConfig:E,enableLogger:T}=m.getMethods();export{b as RecaptchaModule,T as enableLogger,R as initReCaptcha,n as recaptchaFetchApi,E as setConfig,S as setEndpoint,y as verifyReCaptcha};
|
|
@@ -19,7 +19,8 @@ export declare class RecaptchaModule {
|
|
|
19
19
|
_recaptchaBackendEndpoint: string;
|
|
20
20
|
_recaptchaScriptUrl: string;
|
|
21
21
|
_configStorageKey: string;
|
|
22
|
-
|
|
22
|
+
_logger: boolean;
|
|
23
|
+
_updateBadgePosition(badgeId: string, config: ReCaptchaV3ModifyProps): Promise<void | null>;
|
|
23
24
|
_addRecaptchaScript(): Promise<void>;
|
|
24
25
|
_fetchStoreConfig(): Promise<ReCaptchaV3Response | undefined>;
|
|
25
26
|
_loadConfig(): Promise<ReCaptchaV3ModifyProps | null>;
|
|
@@ -27,13 +28,15 @@ export declare class RecaptchaModule {
|
|
|
27
28
|
setConfig(configList: PropsFormTypes[]): Promise<void>;
|
|
28
29
|
initReCaptcha(): Promise<void>;
|
|
29
30
|
verifyReCaptcha(): Promise<string | undefined>;
|
|
31
|
+
enableLogger(logger: boolean): void;
|
|
30
32
|
getMethods(): {
|
|
33
|
+
enableLogger: (logger: boolean) => void;
|
|
31
34
|
setEndpoint: (url: string) => void;
|
|
32
35
|
setConfig: (configList: PropsFormTypes[]) => Promise<void>;
|
|
33
36
|
initReCaptcha: () => Promise<void>;
|
|
34
37
|
verifyReCaptcha: () => Promise<string | undefined>;
|
|
35
38
|
};
|
|
36
39
|
}
|
|
37
|
-
declare const initReCaptcha: () => Promise<void>, verifyReCaptcha: () => Promise<string | undefined>, setEndpoint: (url: string) => void, setConfig: (configList: PropsFormTypes[]) => Promise<void
|
|
38
|
-
export { setEndpoint, setConfig, initReCaptcha, verifyReCaptcha };
|
|
40
|
+
declare const initReCaptcha: () => Promise<void>, verifyReCaptcha: () => Promise<string | undefined>, setEndpoint: (url: string) => void, setConfig: (configList: PropsFormTypes[]) => Promise<void>, enableLogger: (logger: boolean) => void;
|
|
41
|
+
export { setEndpoint, setConfig, initReCaptcha, verifyReCaptcha, enableLogger };
|
|
39
42
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReCaptchaV3InitProps, ReCaptchaV3ModifyProps } from '../types/recaptcha.types';
|
|
2
2
|
|
|
3
3
|
declare const getConfigStorage: (storageKey: string, retries?: number, delay?: number) => Promise<ReCaptchaV3ModifyProps | null>;
|
|
4
|
-
declare const setConfigStorage: (storageKey: string, config: ReCaptchaV3InitProps) => null | undefined;
|
|
4
|
+
declare const setConfigStorage: (storageKey: string, config: ReCaptchaV3InitProps, logger: boolean) => null | undefined;
|
|
5
5
|
export { getConfigStorage, setConfigStorage };
|
|
6
6
|
//# sourceMappingURL=_storageConfig.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const getRecaptchaToken: (websiteKey: string) => Promise<string>;
|
|
2
2
|
export declare const waitForReCaptcha: () => Promise<unknown>;
|
|
3
|
-
export declare const verifyReCaptchaLoad: (badgeId: string, config: any) => Promise<void>;
|
|
3
|
+
export declare const verifyReCaptchaLoad: (badgeId: string, config: any, logger: boolean) => Promise<void>;
|
|
4
4
|
//# sourceMappingURL=recaptcha.service.d.ts.map
|