@bringweb3/chrome-extension-kit 1.3.3 → 1.3.5

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/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var S=Object.defineProperty;var at=Object.getOwnPropertyDescriptor;var ct=Object.getOwnPropertyNames;var mt=Object.prototype.hasOwnProperty;var dt=(t,e)=>{for(var r in e)S(t,r,{get:e[r],enumerable:!0})},lt=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ct(e))!mt.call(t,n)&&n!==r&&S(t,n,{get:()=>e[n],enumerable:!(i=at(e,n))||i.enumerable});return t};var ut=t=>lt(S({},"__esModule",{value:!0}),t);var qt={};dt(qt,{bringInitBackground:()=>it,bringInitContentScript:()=>B,getTurnOff:()=>st,setTurnOff:()=>ot});module.exports=ut(qt);var ft=t=>{let e=new URLSearchParams,{query:r,prefix:i}=t;return Object.entries(r).forEach(([n,o])=>{o&&(i&&(n=`${i}_${n}`),n==="url"?e.append(n,encodeURIComponent(o)):e.append(n,o))}),e.toString()},U=ft;var L={name:"@bringweb3/chrome-extension-kit",version:"1.3.3",description:"Crypto cashback integration kit for crypto outlets extension",main:"dist/index.js",module:"dist/index.mjs",types:"dist/index.d.ts",license:"MIT",private:!1,publishConfig:{access:"public"},repository:{type:"git",url:"https://github.com/Bring-Web3-LTD/chromeExtension.git"},scripts:{watch:"tsup index.ts --env.IFRAME_URL=http://localhost:5173 --format cjs,esm --dts --watch",build:"tsup index.ts --format cjs,esm --dts --minify",lint:"tsc",test:"vitest --coverage",release:"yarn build && changeset publish"},files:["dist","README.md"],devDependencies:{"@changesets/cli":"^2.27.7","@types/chrome":"^0.0.268","@vitest/coverage-v8":"^2.0.5",tsup:"^8.2.1",typescript:"^5.5.3",vitest:"^2.0.5"},keywords:["cashback","crypto","bringweb3"],dependencies:{uuid:"^11.0.3"}};var gt=()=>L.version,b=gt;var ht=({query:t,theme:e,themeMode:r,text:i,iframeUrl:n,page:o,switchWallet:a})=>{let c=chrome.runtime.id,d=`bringweb3-iframe-${c}`,m=document.getElementById(d),f=process?.env?.IFRAME_URL?`${process.env.IFRAME_URL}${o?"/"+o:""}`:n;if(m)return m;let p=U({query:{...t,extensionId:c,v:b(),themeMode:r,textMode:i,switchWallet:String(a)}}),g=e?`&${U({query:e,prefix:"t"})}`:"",l=document.createElement("iframe");return l.id=d,l.src=`${f}?${p}${g}`,l.setAttribute("sandbox","allow-scripts allow-same-origin"),l.style.position="fixed",l.scrolling="no",l.style.overflow="hidden",l.style.width="1px",l.style.height="1px",l.style.right="8px",l.style.borderRadius="10px",l.style.border="none",l.style.cssText+="z-index: 99999999999999 !important;",e?.popupShadow&&(l.style.boxShadow=e.popupShadow),document.documentElement.appendChild(l),l},R=ht;var wt=(t,e)=>{!t||!e||!Object.keys(e).length||Object.entries(e).forEach(([r,i])=>{r in t.style&&(t.style[r]=i)})},K=wt;var Et=t=>{if(!t||!t.length)return;let e=document.createElement("style");document.head.appendChild(e);let r=e.sheet;r?t.forEach(({name:i,rules:n})=>{r.insertRule(`@keyframes ${i} { ${n} }`,r.cssRules.length)}):console.error("Failed to create stylesheet")},F=Et;var h={OPEN:"OPEN",CLOSE:"CLOSE",ACTIVATE:"ACTIVATE",PROMPT_LOGIN:"PROMPT_LOGIN",OPT_OUT:"OPT_OUT",ADD_KEYFRAMES:"ADD_KEYFRAMES",ERASE_NOTIFICATION:"ERASE_NOTIFICATION",OPEN_CASHBACK_PAGE:"OPEN_CASHBACK_PAGE"},At=[h.ACTIVATE],yt=({event:t,iframeEl:e,promptLogin:r})=>{let{data:i}=t,{from:n,action:o,style:a,keyFrames:c,time:d,extensionId:m,url:f,domain:p,redirectUrl:g}=i;if(n==="bringweb3"&&!(m!==chrome.runtime.id&&!At.includes(o)))switch(o){case h.OPEN:K(e,a);break;case h.CLOSE:e&&e.parentNode?.removeChild(e),d&&chrome.runtime.sendMessage({action:o,time:d,domain:p,from:"bringweb3"});break;case h.PROMPT_LOGIN:r();break;case h.ACTIVATE:chrome.runtime.sendMessage({action:o,from:"bringweb3",domain:p,extensionId:m,time:d,redirectUrl:g});break;case h.OPT_OUT:chrome.runtime.sendMessage({action:o,time:d,from:"bringweb3"});break;case h.ERASE_NOTIFICATION:chrome.runtime.sendMessage({action:o,from:"bringweb3"});case h.ADD_KEYFRAMES:F(c);break;case h.OPEN_CASHBACK_PAGE:chrome.runtime.sendMessage({action:o,url:f,from:"bringweb3"});break;default:break}},$=yt;var G=async({iframeEl:t,getWalletAddress:e})=>{if(!t&&(t=document.querySelector(`#bringweb3-iframe-${chrome.runtime.id}`),!t)||!t.contentWindow)return;let r=await e();t.contentWindow.postMessage({action:"WALLET_ADDRESS_UPDATE",walletAddress:r},"*"),chrome.runtime.sendMessage({action:"WALLET_ADDRESS_UPDATE",from:"bringweb3",walletAddress:r})},bt=({walletAddressListeners:t,walletAddressUpdateCallback:e,getWalletAddress:r,iframeEl:i})=>{if(e)e(()=>G({iframeEl:i,getWalletAddress:r}));else if(t)for(let n=0;n<t.length;n++){let o=t[n];o&&window.addEventListener(o,async()=>G({iframeEl:i,getWalletAddress:r}))}},j=bt;var Ot=["www.","www1.","www2."],Tt=t=>{if(!t)return"";t=t.split("://").reverse()[0]||"";for(let e of Ot)t.startsWith(e)&&(t=t.replace(e,""));return t},O=Tt;var M=null,q=!1,vt=async({getWalletAddress:t,promptLogin:e,walletAddressListeners:r,walletAddressUpdateCallback:i,lightTheme:n,darkTheme:o,theme:a,text:c,switchWallet:d=!1})=>{if(window.self===window.top){if(!t||!e||!r?.length&&typeof i!="function")throw new Error("Missing configuration");j({walletAddressListeners:r,walletAddressUpdateCallback:i,getWalletAddress:t,iframeEl:M}),window.addEventListener("message",m=>$({event:m,iframeEl:M,promptLogin:e})),chrome.runtime.onMessage.addListener((m,f,p)=>{if(m?.from!=="bringweb3")return;let{action:g}=m;switch(g){case"GET_WALLET_ADDRESS":return t().then(W=>p({status:"success",walletAddress:W})).catch(W=>p({status:"success",walletAddress:void 0})),!0;case"INJECT":if(m.domain!==O(location.href)||q)return p({status:"Domain already changed"}),!0;let{token:l,iframeUrl:v,userId:x}=m,P={token:l};return x&&(P.userId=x),M=R({query:P,iframeUrl:v,theme:a==="dark"?o:n,themeMode:a||"light",text:c,switchWallet:d,page:m.page}),q=!0,p({status:"success"}),!0;default:console.error(`Unknown action: ${g}`);break}})}},B=vt;var V=t=>{t&&chrome.tabs.create({url:t})};var u=class t{static instance=null;apiEndpoint="";whitelistEndpoint="";apiKey="";constructor(){}static getInstance(){return t.instance||(t.instance=new t),t.instance}setWhitelistEndpoint(e){this.whitelistEndpoint=e}setApiEndpoint(e){this.apiEndpoint=e==="prod"?"https://api.bringweb3.io/v1/extension":"https://sandbox-api.bringweb3.io/v1/extension"}setApiKey(e){this.apiKey=e}getWhitelistEndpoint(){return this.whitelistEndpoint}getApiEndpoint(){if(!this.apiEndpoint)throw new Error("API endpoint not set. Call setApiEndpoint first.");return this.apiEndpoint}getApiKey(){if(!this.apiKey)throw new Error("API key not set. Call setApiKey first.");return this.apiKey}};var xt=async(t,e)=>new Promise((r,i)=>{chrome.storage.local.set({[`bring_${t}`]:e},()=>{chrome.runtime.lastError?i(chrome.runtime.lastError):r()})}),Pt=async t=>new Promise((e,r)=>{chrome.storage.local.get([`bring_${t}`],i=>{chrome.runtime.lastError?r(chrome.runtime.lastError):e(i[`bring_${t}`])})}),Ct=async t=>new Promise((e,r)=>{chrome.storage.local.remove([`bring_${t}`],()=>{chrome.runtime.lastError?r(chrome.runtime.lastError):e()})}),s={set:xt,get:Pt,remove:Ct};var H=require("uuid"),Dt=async()=>{let t=await s.get("id");return t||(t=(0,H.v4)(),s.set("id",t)),t},w=Dt;var It=async t=>{let{path:e,method:r,apiKey:i,params:n}=t;if(!t||!e||!r||!n&&r==="POST"||!i)throw new Error("Missing endpoint or method");let o=u.getInstance().getApiEndpoint();if(o+=e,r==="GET"){let d=new URLSearchParams({...n,version:b(),opt_out:await s.get("optOut")||0,user_id:await w()||"undefined",wallet_address:await s.get("walletAddress")||"undefined"});o+=`?${d.toString()}`}else r==="POST"&&(n={...n,version:b(),optOut:await s.get("optOut")||0,userId:await w()||void 0,walletAddress:n?.walletAddress||await s.get("walletAddress")||void 0});return await(await fetch(o,{method:r,headers:{"Content-Type":"application/json","x-api-key":i},body:r==="POST"?JSON.stringify(n):void 0})).json()},E=It;var _t=async({apiKey:t,body:e})=>await E({path:"/check/popup",apiKey:t,method:"POST",params:e}),Q=_t;var C="updateCache";var J=30*60*1e3,kt=async(t,e)=>{e||(e=J);let r=await s.get("quietDomains");typeof r=="object"?r[t]=Date.now()+e:r={[t]:Date.now()+J},s.set("quietDomains",r)},T=kt;var St=async({apiKey:t,walletAddress:e,cashbackUrl:r,lastActivation:i})=>{let n={walletAddress:e};return i&&(n.lastActivation=i),r&&(n.cashbackUrl=r),await E({path:"/check/notification",apiKey:t,method:"POST",params:n})},Y=St;var Ut=(t,e)=>new Promise((n,o)=>{let a=c=>{chrome.tabs.get(t,d=>{if(chrome.runtime.lastError){n(null);return}chrome.tabs.sendMessage(t,{...e,from:"bringweb3"},m=>{chrome.runtime.lastError?c<4?setTimeout(()=>a(c+1),1e3*Math.pow(2,c)):n(null):n(m||null)})})};a(0)}),A=Ut;var Mt=async t=>{let e=await s.get("walletAddress");try{if(!t){let i=await chrome.tabs.query({active:!0,currentWindow:!0});if(!i||!i[0]||!i[0].id)return e;t=i[0].id}let r=await A(t,{action:"GET_WALLET_ADDRESS"});r?.walletAddress&&e!==r?.walletAddress&&(e=r?.walletAddress,await s.set("walletAddress",e))}catch{}return e},D=Mt;var Nt=async(t,e,r)=>{let i={showNotification:!1,token:"",iframeUrl:""},n=await s.get("notificationCheck");if(n&&Date.now()<n)return i;let o=e?await D(e):await s.get("walletAddress");if(!o)return i;let a=await s.get("lastActivation"),c=await Y({apiKey:t,walletAddress:o,cashbackUrl:r,lastActivation:a});s.set("notificationCheck",c.nextCall);let d={showNotification:c.showNotification,token:c.token,iframeUrl:c.iframeUrl,expiration:c.expiration};return d.showNotification&&await s.set("notification",d),d},I=Nt;var Wt=t=>t?chrome.runtime.getURL(t):"",_=Wt;var Lt=async t=>{let e=u.getInstance().getWhitelistEndpoint(),r={path:"/domains",apiKey:t,method:"GET"};return e&&(r.params={whitelist:encodeURIComponent(e)}),await E(r)},z=Lt;var X=async()=>{try{let t=u.getInstance().getWhitelistEndpoint();if(!t)return[];let e=await fetch(t,{method:"GET",cache:"no-store",headers:{"Cache-Control":"no-store, no-cache, must-revalidate, max-age=0",Pragma:"no-cache"}});if(!e.ok)throw new Error("Failed to fetch whitelist");let r=await e.json();if(!Array.isArray(r))throw new Error("whitelist isn't an array");return r}catch(t){return console.error("Error fetching whitelist:",t),[]}};var Rt=t=>{let e=Date.now();return(t-e)/1e3/60},y=async()=>{let t=await s.get("relevantDomainsCheck"),e=await s.get("relevantDomains"),r=await s.get("redirectsWhitelist"),i=u.getInstance().getApiKey(),n=u.getInstance().getWhitelistEndpoint();if(e?.length&&t&&t>Date.now()&&(!n||n&&r?.length))return e;let o=await z(i),{nextUpdateTimestamp:a,relevantDomains:c}=o;s.set("relevantDomains",c),s.set("relevantDomainsCheck",a),r=await X(),r&&s.set("redirectsWhitelist",r);let d=Rt(a);return chrome.alarms.create(C,{delayInMinutes:d||60*24*2}),c};var Kt=async(t,e)=>{try{let r=u.getInstance().getWhitelistEndpoint();if(r&&!e?.length&&(await y(),e=await s.get("redirectsWhitelist")),!e?.length)return!r;let n=new URL(t).hostname.toLowerCase();return n=n.replace("www.",""),e.includes(n)?!0:e.some(o=>{if(o.startsWith("*.")){let a=o.slice(2);return n.endsWith(a)}return!1})}catch{return console.error("Invalid URL:",t),!1}},k=Kt;var Ft=async(t,e,r,i,n,o,a)=>{if(e===chrome.runtime.id&&await s.set("lastActivation",Date.now()),t&&T(t,n||Date.now()+24*60*60*1e3),o&&a){let c=await s.get("redirectsWhitelist");await k(a,c)&&chrome.tabs.update(o,{url:a})}await I(r,void 0,_(i))},Z=Ft;var tt=async t=>t<0?(await s.remove("optOut"),{isOptedOut:!1}):(await s.set("optOut",Date.now()+t),{isOptedOut:!0}),et=async()=>{let t=await s.get("optOut");return{isOptedOut:!!(t&&t>Date.now())}};var rt=async(t,e,r)=>{await A(t,{action:"INJECT",page:"notification",token:e.token,iframeUrl:e.iframeUrl,userId:await w(),domain:r})},$t=async(t,e,r,i)=>{let n=await s.get("notification");if(n?.expiration<Date.now())await s.remove("notification");else if(n)return await rt(e,n,i);let o=await I(t,e,_(r));if(o.showNotification)return await rt(e,o,i)},nt=$t;var Gt=async t=>{let e=await y();if(!t||!e||!e.length)return"";let r=O(t);for(let i of e)if(r.startsWith(i)){let n=await s.get("quietDomains");return n&&n[i]&&Date.now()<n[i]?"":i}return""},N={},jt=async({identifier:t,apiEndpoint:e,cashbackPagePath:r,whitelistEndpoint:i})=>{if(!t||!e)throw new Error("Missing configuration");if(!["prod","sandbox"].includes(e))throw new Error("unknown apiEndpoint");u.getInstance().setApiEndpoint(e),u.getInstance().setWhitelistEndpoint(i||""),u.getInstance().setApiKey(t),y(),chrome.alarms.onAlarm.addListener(async n=>{let{name:o}=n;switch(o){case C:y();break;default:console.error("alarm with no use case:",o);break}}),chrome.runtime.onMessage.addListener((n,o,a)=>{if(n?.from!=="bringweb3")return;let{action:c}=n;switch(c){case"ACTIVATE":{let{domain:m,extensionId:f,time:p,redirectUrl:g}=n;return Z(m,f,t,r,p,o.tab?.id,g).then(()=>a()),!0}case"GET_OPT_OUT":return et().then(m=>a(m)),!0;case"OPT_OUT":{let{time:m}=n;return tt(m).then(f=>a(f)),!0}case"CLOSE":{let{time:m,domain:f}=n;return f&&(T(f,m),a({message:"domain added to quiet list"})),!0}case"WALLET_ADDRESS_UPDATE":{let{walletAddress:m}=n;return m?s.set("walletAddress",m).then(()=>a(m)):s.remove("walletAddress").then(()=>a({message:"wallet address removed successfully"})),!0}case"ERASE_NOTIFICATION":return s.remove("notification").then(()=>a({message:"notification erased successfully"})),!0;default:return console.warn(`Bring unknown action: ${c}`),!0;case"OPEN_CASHBACK_PAGE":let{url:d}=n;return V(d||r),a({message:"cashback page opened successfully"}),!0}}),chrome.tabs.onUpdated.addListener(async(n,o,a)=>{if(!a?.url?.startsWith("http")||!a.url)return;let c=O(a.url),d=await s.get("optOut");if(d&&d>Date.now())return;d&&(s.remove("optOut"),s.remove("optOutKey"));let m=N[n];if(o.status!=="complete"||c===m)return;N[n]=c;let f=await Gt(a.url);if(!f||!f.length){await nt(t,n,r,c);return}let p=await D(n),{token:g,isValid:l,iframeUrl:v,networkUrl:x}=await Q({apiKey:t,body:{domain:f,url:a.url,address:p}});if(!l){l===!1&&T(f);return}if(!await k(x,await s.get("redirectsWhitelist")))return;let P=await w();A(n,{action:"INJECT",token:g,domain:c,iframeUrl:v,userId:P})}),chrome.tabs.onRemoved.addListener(n=>delete N[n])},it=jt;var st=()=>new Promise((t,e)=>{chrome.runtime.sendMessage({from:"bringweb3",action:"GET_OPT_OUT"},r=>{if(chrome.runtime.lastError){console.error(chrome.runtime.lastError),e(chrome.runtime.lastError);return}t({isTurnedOff:r.isOptedOut})})}),ot=t=>new Promise((e,r)=>{let i=t?Number.MAX_SAFE_INTEGER:-1;chrome.runtime.sendMessage({from:"bringweb3",action:"OPT_OUT",time:i},n=>{if(chrome.runtime.lastError){console.error(chrome.runtime.lastError),r(chrome.runtime.lastError);return}n?e({isTurnedOff:n.isOptedOut}):r("No response received")})});0&&(module.exports={bringInitBackground,bringInitContentScript,getTurnOff,setTurnOff});
1
+ "use strict";var k=Object.defineProperty;var ct=Object.getOwnPropertyDescriptor;var mt=Object.getOwnPropertyNames;var lt=Object.prototype.hasOwnProperty;var dt=(t,e)=>{for(var r in e)k(t,r,{get:e[r],enumerable:!0})},ut=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of mt(e))!lt.call(t,n)&&n!==r&&k(t,n,{get:()=>e[n],enumerable:!(o=ct(e,n))||o.enumerable});return t};var ft=t=>ut(k({},"__esModule",{value:!0}),t);var Ht={};dt(Ht,{bringInitBackground:()=>ot,bringInitContentScript:()=>V,getTurnOff:()=>st,setTurnOff:()=>at});module.exports=ft(Ht);var pt=t=>{let e=new URLSearchParams,{query:r,prefix:o}=t;return Object.entries(r).forEach(([n,i])=>{i&&(o&&(n=`${o}_${n}`),n==="url"?e.append(n,encodeURIComponent(i)):e.append(n,i))}),e.toString()},U=pt;var R={name:"@bringweb3/chrome-extension-kit",version:"1.3.5",description:"Crypto cashback integration kit for crypto outlets extension",main:"dist/index.js",module:"dist/index.mjs",types:"dist/index.d.ts",license:"MIT",private:!1,publishConfig:{access:"public"},repository:{type:"git",url:"https://github.com/Bring-Web3-LTD/chromeExtension.git"},scripts:{watch:"tsup index.ts --env.IFRAME_URL=http://localhost:5173 --format cjs,esm --dts --watch",build:"tsup index.ts --format cjs,esm --dts --minify",lint:"tsc",test:"vitest --coverage",release:"yarn build && changeset publish"},files:["dist","README.md"],devDependencies:{"@changesets/cli":"^2.27.7","@types/chrome":"^0.0.268","@vitest/coverage-v8":"^2.0.5",tsup:"^8.2.1",typescript:"^5.5.3",vitest:"^2.0.5"},keywords:["cashback","crypto","bringweb3"],dependencies:{uuid:"^11.0.3"}};var ht=()=>R.version,b=ht;var wt=({query:t,theme:e,themeMode:r,text:o,iframeUrl:n,page:i,switchWallet:a})=>{let c=chrome.runtime.id,l=`bringweb3-iframe-${c}`,m=document.getElementById(l),f=process?.env?.IFRAME_URL?`${process.env.IFRAME_URL}${i?"/"+i:""}`:n;if(m)return m;let p=U({query:{...t,extensionId:c,v:b(),themeMode:r,textMode:o,switchWallet:String(a)}}),g=e?`&${U({query:e,prefix:"t"})}`:"",d=document.createElement("iframe");return d.id=l,d.src=`${f}?${p}${g}`,d.setAttribute("sandbox","allow-scripts allow-same-origin"),d.style.position="fixed",d.scrolling="no",d.style.overflow="hidden",d.style.width="1px",d.style.height="1px",d.style.right="8px",d.style.borderRadius="10px",d.style.border="none",d.style.cssText+="z-index: 99999999999999 !important;",e?.popupShadow&&(d.style.boxShadow=e.popupShadow),document.documentElement.appendChild(d),d},K=wt;var Et=(t,e)=>{!t||!e||!Object.keys(e).length||Object.entries(e).forEach(([r,o])=>{r in t.style&&(t.style[r]=o)})},F=Et;var At=t=>{if(!t||!t.length)return;let e=document.createElement("style");document.head.appendChild(e);let r=e.sheet;r?t.forEach(({name:o,rules:n})=>{r.insertRule(`@keyframes ${o} { ${n} }`,r.cssRules.length)}):console.error("Failed to create stylesheet")},$=At;var h={OPEN:"OPEN",CLOSE:"CLOSE",ACTIVATE:"ACTIVATE",PROMPT_LOGIN:"PROMPT_LOGIN",OPT_OUT:"OPT_OUT",ADD_KEYFRAMES:"ADD_KEYFRAMES",ERASE_NOTIFICATION:"ERASE_NOTIFICATION",OPEN_CASHBACK_PAGE:"OPEN_CASHBACK_PAGE"},yt=[h.ACTIVATE],bt=({event:t,iframeEl:e,promptLogin:r})=>{let{data:o}=t,{from:n,action:i,style:a,keyFrames:c,time:l,extensionId:m,url:f,domain:p,redirectUrl:g}=o;if(n==="bringweb3"&&!(m!==chrome.runtime.id&&!yt.includes(i)))switch(i){case h.OPEN:F(e,a);break;case h.CLOSE:e&&e.parentNode?.removeChild(e),l&&chrome.runtime.sendMessage({action:i,time:l,domain:p,from:"bringweb3"});break;case h.PROMPT_LOGIN:r();break;case h.ACTIVATE:chrome.runtime.sendMessage({action:i,from:"bringweb3",domain:p,extensionId:m,time:l,redirectUrl:g});break;case h.OPT_OUT:chrome.runtime.sendMessage({action:i,time:l,from:"bringweb3"});break;case h.ERASE_NOTIFICATION:chrome.runtime.sendMessage({action:i,from:"bringweb3"});case h.ADD_KEYFRAMES:$(c);break;case h.OPEN_CASHBACK_PAGE:chrome.runtime.sendMessage({action:i,url:f,from:"bringweb3"});break;default:break}},j=bt;var G=async({iframeEl:t,getWalletAddress:e})=>{if(!t&&(t=document.querySelector(`#bringweb3-iframe-${chrome.runtime.id}`),!t)||!t.contentWindow)return;let r=await e();t.contentWindow.postMessage({action:"WALLET_ADDRESS_UPDATE",walletAddress:r},"*"),chrome.runtime.sendMessage({action:"WALLET_ADDRESS_UPDATE",from:"bringweb3",walletAddress:r})},Ot=({walletAddressListeners:t,walletAddressUpdateCallback:e,getWalletAddress:r,iframeEl:o})=>{if(e)e(()=>G({iframeEl:o,getWalletAddress:r}));else if(t)for(let n=0;n<t.length;n++){let i=t[n];i&&window.addEventListener(i,async()=>G({iframeEl:o,getWalletAddress:r}))}},q=Ot;var Tt=["www.","www1.","www2."],vt=t=>{if(!t)return"";t=t.split("://").reverse()[0]||"";for(let e of Tt)t.startsWith(e)&&(t=t.replace(e,""));return t},P=vt;var M=null,B=!1,xt=async({getWalletAddress:t,promptLogin:e,walletAddressListeners:r,walletAddressUpdateCallback:o,lightTheme:n,darkTheme:i,theme:a,text:c,switchWallet:l=!1})=>{if(window.self===window.top){if(!t||!e||!r?.length&&typeof o!="function")throw new Error("Missing configuration");q({walletAddressListeners:r,walletAddressUpdateCallback:o,getWalletAddress:t,iframeEl:M}),window.addEventListener("message",m=>j({event:m,iframeEl:M,promptLogin:e})),chrome.runtime.onMessage.addListener((m,f,p)=>{if(m?.from!=="bringweb3")return;let{action:g}=m;switch(g){case"GET_WALLET_ADDRESS":return t().then(L=>p({status:"success",walletAddress:L})).catch(L=>p({status:"success",walletAddress:void 0})),!0;case"INJECT":if(m.domain!==P(location.href)||B)return p({status:"Domain already changed"}),!0;let{token:d,iframeUrl:T,userId:v}=m,x={token:d};return v&&(x.userId=v),M=K({query:x,iframeUrl:T,theme:a==="dark"?i:n,themeMode:a||"light",text:c,switchWallet:l,page:m.page}),B=!0,p({status:"success"}),!0;default:console.error(`Unknown action: ${g}`);break}})}},V=xt;var H=t=>{t&&chrome.tabs.create({url:t})};var u=class t{static instance=null;apiEndpoint="";whitelistEndpoint="";apiKey="";constructor(){}static getInstance(){return t.instance||(t.instance=new t),t.instance}setWhitelistEndpoint(e){this.whitelistEndpoint=e}setApiEndpoint(e){this.apiEndpoint=e==="prod"?"https://api.bringweb3.io/v1/extension":"https://sandbox-api.bringweb3.io/v1/extension"}setApiKey(e){this.apiKey=e}getWhitelistEndpoint(){return this.whitelistEndpoint}getApiEndpoint(){if(!this.apiEndpoint)throw new Error("API endpoint not set. Call setApiEndpoint first.");return this.apiEndpoint}getApiKey(){if(!this.apiKey)throw new Error("API key not set. Call setApiKey first.");return this.apiKey}};var Pt=async(t,e)=>new Promise((r,o)=>{chrome.storage.local.set({[`bring_${t}`]:e},()=>{chrome.runtime.lastError?o(chrome.runtime.lastError):r()})}),Dt=async t=>new Promise((e,r)=>{chrome.storage.local.get([`bring_${t}`],o=>{chrome.runtime.lastError?r(chrome.runtime.lastError):e(o[`bring_${t}`])})}),Ct=async t=>new Promise((e,r)=>{chrome.storage.local.remove([`bring_${t}`],()=>{chrome.runtime.lastError?r(chrome.runtime.lastError):e()})}),s={set:Pt,get:Dt,remove:Ct};var Q=require("uuid"),It=async()=>{let t=await s.get("id");return t||(t=(0,Q.v4)(),s.set("id",t)),t},w=It;var St=async t=>{let{path:e,method:r,apiKey:o,params:n}=t;if(!t||!e||!r||!n&&r==="POST"||!o)throw new Error("Missing endpoint or method");let i=u.getInstance().getApiEndpoint();if(i+=e,r==="GET"){let l=new URLSearchParams({...n,version:b(),timestamp:Date.now().toString(),opt_out:await s.get("optOut")||0,user_id:await w()||"undefined",wallet_address:await s.get("walletAddress")||"undefined"});i+=`?${l.toString()}`}else r==="POST"&&(n={...n,version:b(),timestamp:Date.now(),optOut:await s.get("optOut")||0,userId:await w()||void 0,walletAddress:n?.walletAddress||await s.get("walletAddress")||void 0});return await(await fetch(i,{method:r,headers:{"Content-Type":"application/json","x-api-key":o},body:r==="POST"?JSON.stringify(n):void 0})).json()},E=St;var _t=async({apiKey:t,body:e})=>await E({path:"/check/popup",apiKey:t,method:"POST",params:e}),J=_t;var D="updateCache";var Y=30*60*1e3,kt=async(t,e)=>{e||(e=Y);let r=await s.get("quietDomains");typeof r=="object"?r[t]=Date.now()+e:r={[t]:Date.now()+Y},s.set("quietDomains",r)},O=kt;var Ut=async({apiKey:t,walletAddress:e,cashbackUrl:r,lastActivation:o})=>{let n={walletAddress:e};return o&&(n.lastActivation=o),r&&(n.cashbackUrl=r),await E({path:"/check/notification",apiKey:t,method:"POST",params:n})},z=Ut;var Mt=(t,e)=>new Promise((n,i)=>{let a=c=>{chrome.tabs.get(t,l=>{if(chrome.runtime.lastError){n(null);return}chrome.tabs.sendMessage(t,{...e,from:"bringweb3"},m=>{chrome.runtime.lastError?c<4?setTimeout(()=>a(c+1),1e3*Math.pow(2,c)):n(null):n(m||null)})})};a(0)}),A=Mt;var Nt=async t=>{let e=await s.get("walletAddress");try{if(!t){let o=await chrome.tabs.query({active:!0,currentWindow:!0});if(!o||!o[0]||!o[0].id)return e;t=o[0].id}let r=await A(t,{action:"GET_WALLET_ADDRESS"});r?.walletAddress&&e!==r?.walletAddress&&(e=r?.walletAddress,await s.set("walletAddress",e))}catch{}return e},C=Nt;var Wt=async(t,e,r)=>{let o={showNotification:!1,token:"",iframeUrl:""},n=await s.get("notificationCheck");if(n&&Date.now()<n)return o;let i=e?await C(e):await s.get("walletAddress");if(!i)return o;let a=await s.get("lastActivation"),c=await z({apiKey:t,walletAddress:i,cashbackUrl:r,lastActivation:a});s.set("notificationCheck",c.nextCall);let l={showNotification:c.showNotification,token:c.token,iframeUrl:c.iframeUrl,expiration:c.expiration};return l.showNotification&&await s.set("notification",l),l},I=Wt;var Lt=t=>t?chrome.runtime.getURL(t):"",S=Lt;var Rt=async t=>{let e=u.getInstance().getWhitelistEndpoint(),r={path:"/domains",apiKey:t,method:"GET"};return e&&(r.params={whitelist:encodeURIComponent(e)}),await E(r)},X=Rt;var Z=async()=>{try{let t=u.getInstance().getWhitelistEndpoint();if(!t)return[];let e=await fetch(t,{method:"GET",cache:"no-store",headers:{"Cache-Control":"no-store, no-cache, must-revalidate, max-age=0",Pragma:"no-cache"}});if(!e.ok)throw new Error("Failed to fetch whitelist");let r=await e.json();if(!Array.isArray(r))throw new Error("whitelist isn't an array");return r}catch(t){return console.error("Error fetching whitelist:",t),[]}};var Kt=t=>{let e=Date.now();return(t-e)/1e3/60},y=async()=>{let t=await s.get("relevantDomainsCheck"),e=await s.get("relevantDomains"),r=await s.get("redirectsWhitelist"),o=u.getInstance().getApiKey(),n=u.getInstance().getWhitelistEndpoint();if(e?.length&&t&&t>Date.now()&&(!n||n&&r?.length))return e;let i=await X(o),{nextUpdateTimestamp:a,relevantDomains:c}=i;s.set("relevantDomains",c),s.set("relevantDomainsCheck",a),r=await Z(),r&&s.set("redirectsWhitelist",r);let l=Kt(a);return chrome.alarms.create(D,{delayInMinutes:l||60*24*2}),c};var Ft=async(t,e)=>{try{let r=u.getInstance().getWhitelistEndpoint();if(r&&!e?.length&&(await y(),e=await s.get("redirectsWhitelist")),!e?.length)return!r;let n=new URL(t).hostname.toLowerCase();return n=n.replace("www.",""),e.includes(n)?!0:e.some(i=>{if(i.startsWith("*.")){let a=i.slice(2);return n.endsWith(a)}return!1})}catch{return console.error("Invalid URL:",t),!1}},_=Ft;var $t=async(t,e,r,o,n,i,a)=>{if(e===chrome.runtime.id&&await s.set("lastActivation",Date.now()),t&&O(t,n||Date.now()+24*60*60*1e3),i&&a){let c=await s.get("redirectsWhitelist");await _(a,c)&&chrome.tabs.update(i,{url:a})}await I(r,void 0,S(o))},tt=$t;var et=async t=>t<0?(await s.remove("optOut"),{isOptedOut:!1}):(await s.set("optOut",Date.now()+t),{isOptedOut:!0}),rt=async()=>{let t=await s.get("optOut");return{isOptedOut:!!(t&&t>Date.now())}};var nt=async(t,e,r)=>{await A(t,{action:"INJECT",page:"notification",token:e.token,iframeUrl:e.iframeUrl,userId:await w(),domain:r})},jt=async(t,e,r,o)=>{let n=await s.get("notification");if(n?.expiration<Date.now())await s.remove("notification");else if(n)return await nt(e,n,o);let i=await I(t,e,S(r));if(i.showNotification)return await nt(e,i,o)},it=jt;var Gt=t=>t.endsWith("/")?t.slice(0,-1):t,N=Gt;var qt=["www.","www1.","www2."],Bt=async t=>{let e=await y();if(!t||!e||!e.length)return"";let r=null;try{r=new URL(t)}catch{r=new URL(`https://${t}`)}let o=r.hostname,n=N(r.pathname);for(let i of qt)o=o.replace(i,"");for(let i of e){let a=i;i=N(i);let c=!1;i.startsWith("*.")&&(c=!0);let l="/"+i.split("/").slice(1).join("/")||"";if(l!=="/"&&n.startsWith(l)&&(o+=l),o===i||c&&o.endsWith(i.replace("*.",""))){let m=await s.get("quietDomains");return m&&m[i]&&Date.now()<m[i]?"":a}}return""},W={},Vt=async({identifier:t,apiEndpoint:e,cashbackPagePath:r,whitelistEndpoint:o})=>{if(!t||!e)throw new Error("Missing configuration");if(!["prod","sandbox"].includes(e))throw new Error("unknown apiEndpoint");u.getInstance().setApiEndpoint(e),u.getInstance().setWhitelistEndpoint(o||""),u.getInstance().setApiKey(t),y(),chrome.alarms.onAlarm.addListener(async n=>{let{name:i}=n;switch(i){case D:y();break;default:console.error("alarm with no use case:",i);break}}),chrome.runtime.onMessage.addListener((n,i,a)=>{if(n?.from!=="bringweb3")return;let{action:c}=n;switch(c){case"ACTIVATE":{let{domain:m,extensionId:f,time:p,redirectUrl:g}=n;return tt(m,f,t,r,p,i.tab?.id,g).then(()=>a()),!0}case"GET_OPT_OUT":return rt().then(m=>a(m)),!0;case"OPT_OUT":{let{time:m}=n;return et(m).then(f=>a(f)),!0}case"CLOSE":{let{time:m,domain:f}=n;return f&&(O(f,m),a({message:"domain added to quiet list"})),!0}case"WALLET_ADDRESS_UPDATE":{let{walletAddress:m}=n;return m?s.set("walletAddress",m).then(()=>a(m)):s.remove("walletAddress").then(()=>a({message:"wallet address removed successfully"})),!0}case"ERASE_NOTIFICATION":return s.remove("notification").then(()=>a({message:"notification erased successfully"})),!0;default:return console.warn(`Bring unknown action: ${c}`),!0;case"OPEN_CASHBACK_PAGE":let{url:l}=n;return H(l||r),a({message:"cashback page opened successfully"}),!0}}),chrome.tabs.onUpdated.addListener(async(n,i,a)=>{if(!a?.url?.startsWith("http")||!a.url)return;let c=P(a.url),l=await s.get("optOut");if(l&&l>Date.now())return;l&&(s.remove("optOut"),s.remove("optOutKey"));let m=W[n];if(i.status!=="complete"||c===m)return;W[n]=c;let f=await Bt(a.url);if(!f||!f.length){await it(t,n,r,c);return}let p=await C(n),{token:g,isValid:d,iframeUrl:T,networkUrl:v}=await J({apiKey:t,body:{domain:f,url:a.url,address:p}});if(!d){d===!1&&O(f);return}if(!await _(v,await s.get("redirectsWhitelist")))return;let x=await w();A(n,{action:"INJECT",token:g,domain:c,iframeUrl:T,userId:x})}),chrome.tabs.onRemoved.addListener(n=>delete W[n])},ot=Vt;var st=()=>new Promise((t,e)=>{chrome.runtime.sendMessage({from:"bringweb3",action:"GET_OPT_OUT"},r=>{if(chrome.runtime.lastError){console.error(chrome.runtime.lastError),e(chrome.runtime.lastError);return}t({isTurnedOff:r.isOptedOut})})}),at=t=>new Promise((e,r)=>{let o=t?Number.MAX_SAFE_INTEGER:-1;chrome.runtime.sendMessage({from:"bringweb3",action:"OPT_OUT",time:o},n=>{if(chrome.runtime.lastError){console.error(chrome.runtime.lastError),r(chrome.runtime.lastError);return}n?e({isTurnedOff:n.isOptedOut}):r("No response received")})});0&&(module.exports={bringInitBackground,bringInitContentScript,getTurnOff,setTurnOff});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var et=t=>{let e=new URLSearchParams,{query:r,prefix:i}=t;return Object.entries(r).forEach(([n,o])=>{o&&(i&&(n=`${i}_${n}`),n==="url"?e.append(n,encodeURIComponent(o)):e.append(n,o))}),e.toString()},S=et;var W={name:"@bringweb3/chrome-extension-kit",version:"1.3.3",description:"Crypto cashback integration kit for crypto outlets extension",main:"dist/index.js",module:"dist/index.mjs",types:"dist/index.d.ts",license:"MIT",private:!1,publishConfig:{access:"public"},repository:{type:"git",url:"https://github.com/Bring-Web3-LTD/chromeExtension.git"},scripts:{watch:"tsup index.ts --env.IFRAME_URL=http://localhost:5173 --format cjs,esm --dts --watch",build:"tsup index.ts --format cjs,esm --dts --minify",lint:"tsc",test:"vitest --coverage",release:"yarn build && changeset publish"},files:["dist","README.md"],devDependencies:{"@changesets/cli":"^2.27.7","@types/chrome":"^0.0.268","@vitest/coverage-v8":"^2.0.5",tsup:"^8.2.1",typescript:"^5.5.3",vitest:"^2.0.5"},keywords:["cashback","crypto","bringweb3"],dependencies:{uuid:"^11.0.3"}};var nt=()=>W.version,b=nt;var it=({query:t,theme:e,themeMode:r,text:i,iframeUrl:n,page:o,switchWallet:a})=>{let c=chrome.runtime.id,d=`bringweb3-iframe-${c}`,m=document.getElementById(d),f=process?.env?.IFRAME_URL?`${process.env.IFRAME_URL}${o?"/"+o:""}`:n;if(m)return m;let p=S({query:{...t,extensionId:c,v:b(),themeMode:r,textMode:i,switchWallet:String(a)}}),g=e?`&${S({query:e,prefix:"t"})}`:"",l=document.createElement("iframe");return l.id=d,l.src=`${f}?${p}${g}`,l.setAttribute("sandbox","allow-scripts allow-same-origin"),l.style.position="fixed",l.scrolling="no",l.style.overflow="hidden",l.style.width="1px",l.style.height="1px",l.style.right="8px",l.style.borderRadius="10px",l.style.border="none",l.style.cssText+="z-index: 99999999999999 !important;",e?.popupShadow&&(l.style.boxShadow=e.popupShadow),document.documentElement.appendChild(l),l},L=it;var st=(t,e)=>{!t||!e||!Object.keys(e).length||Object.entries(e).forEach(([r,i])=>{r in t.style&&(t.style[r]=i)})},R=st;var ot=t=>{if(!t||!t.length)return;let e=document.createElement("style");document.head.appendChild(e);let r=e.sheet;r?t.forEach(({name:i,rules:n})=>{r.insertRule(`@keyframes ${i} { ${n} }`,r.cssRules.length)}):console.error("Failed to create stylesheet")},K=ot;var h={OPEN:"OPEN",CLOSE:"CLOSE",ACTIVATE:"ACTIVATE",PROMPT_LOGIN:"PROMPT_LOGIN",OPT_OUT:"OPT_OUT",ADD_KEYFRAMES:"ADD_KEYFRAMES",ERASE_NOTIFICATION:"ERASE_NOTIFICATION",OPEN_CASHBACK_PAGE:"OPEN_CASHBACK_PAGE"},at=[h.ACTIVATE],ct=({event:t,iframeEl:e,promptLogin:r})=>{let{data:i}=t,{from:n,action:o,style:a,keyFrames:c,time:d,extensionId:m,url:f,domain:p,redirectUrl:g}=i;if(n==="bringweb3"&&!(m!==chrome.runtime.id&&!at.includes(o)))switch(o){case h.OPEN:R(e,a);break;case h.CLOSE:e&&e.parentNode?.removeChild(e),d&&chrome.runtime.sendMessage({action:o,time:d,domain:p,from:"bringweb3"});break;case h.PROMPT_LOGIN:r();break;case h.ACTIVATE:chrome.runtime.sendMessage({action:o,from:"bringweb3",domain:p,extensionId:m,time:d,redirectUrl:g});break;case h.OPT_OUT:chrome.runtime.sendMessage({action:o,time:d,from:"bringweb3"});break;case h.ERASE_NOTIFICATION:chrome.runtime.sendMessage({action:o,from:"bringweb3"});case h.ADD_KEYFRAMES:K(c);break;case h.OPEN_CASHBACK_PAGE:chrome.runtime.sendMessage({action:o,url:f,from:"bringweb3"});break;default:break}},F=ct;var $=async({iframeEl:t,getWalletAddress:e})=>{if(!t&&(t=document.querySelector(`#bringweb3-iframe-${chrome.runtime.id}`),!t)||!t.contentWindow)return;let r=await e();t.contentWindow.postMessage({action:"WALLET_ADDRESS_UPDATE",walletAddress:r},"*"),chrome.runtime.sendMessage({action:"WALLET_ADDRESS_UPDATE",from:"bringweb3",walletAddress:r})},mt=({walletAddressListeners:t,walletAddressUpdateCallback:e,getWalletAddress:r,iframeEl:i})=>{if(e)e(()=>$({iframeEl:i,getWalletAddress:r}));else if(t)for(let n=0;n<t.length;n++){let o=t[n];o&&window.addEventListener(o,async()=>$({iframeEl:i,getWalletAddress:r}))}},G=mt;var dt=["www.","www1.","www2."],lt=t=>{if(!t)return"";t=t.split("://").reverse()[0]||"";for(let e of dt)t.startsWith(e)&&(t=t.replace(e,""));return t},O=lt;var U=null,j=!1,ut=async({getWalletAddress:t,promptLogin:e,walletAddressListeners:r,walletAddressUpdateCallback:i,lightTheme:n,darkTheme:o,theme:a,text:c,switchWallet:d=!1})=>{if(window.self===window.top){if(!t||!e||!r?.length&&typeof i!="function")throw new Error("Missing configuration");G({walletAddressListeners:r,walletAddressUpdateCallback:i,getWalletAddress:t,iframeEl:U}),window.addEventListener("message",m=>F({event:m,iframeEl:U,promptLogin:e})),chrome.runtime.onMessage.addListener((m,f,p)=>{if(m?.from!=="bringweb3")return;let{action:g}=m;switch(g){case"GET_WALLET_ADDRESS":return t().then(N=>p({status:"success",walletAddress:N})).catch(N=>p({status:"success",walletAddress:void 0})),!0;case"INJECT":if(m.domain!==O(location.href)||j)return p({status:"Domain already changed"}),!0;let{token:l,iframeUrl:v,userId:x}=m,P={token:l};return x&&(P.userId=x),U=L({query:P,iframeUrl:v,theme:a==="dark"?o:n,themeMode:a||"light",text:c,switchWallet:d,page:m.page}),j=!0,p({status:"success"}),!0;default:console.error(`Unknown action: ${g}`);break}})}},ft=ut;var q=t=>{t&&chrome.tabs.create({url:t})};var u=class t{static instance=null;apiEndpoint="";whitelistEndpoint="";apiKey="";constructor(){}static getInstance(){return t.instance||(t.instance=new t),t.instance}setWhitelistEndpoint(e){this.whitelistEndpoint=e}setApiEndpoint(e){this.apiEndpoint=e==="prod"?"https://api.bringweb3.io/v1/extension":"https://sandbox-api.bringweb3.io/v1/extension"}setApiKey(e){this.apiKey=e}getWhitelistEndpoint(){return this.whitelistEndpoint}getApiEndpoint(){if(!this.apiEndpoint)throw new Error("API endpoint not set. Call setApiEndpoint first.");return this.apiEndpoint}getApiKey(){if(!this.apiKey)throw new Error("API key not set. Call setApiKey first.");return this.apiKey}};var pt=async(t,e)=>new Promise((r,i)=>{chrome.storage.local.set({[`bring_${t}`]:e},()=>{chrome.runtime.lastError?i(chrome.runtime.lastError):r()})}),gt=async t=>new Promise((e,r)=>{chrome.storage.local.get([`bring_${t}`],i=>{chrome.runtime.lastError?r(chrome.runtime.lastError):e(i[`bring_${t}`])})}),ht=async t=>new Promise((e,r)=>{chrome.storage.local.remove([`bring_${t}`],()=>{chrome.runtime.lastError?r(chrome.runtime.lastError):e()})}),s={set:pt,get:gt,remove:ht};import{v4 as wt}from"uuid";var Et=async()=>{let t=await s.get("id");return t||(t=wt(),s.set("id",t)),t},w=Et;var At=async t=>{let{path:e,method:r,apiKey:i,params:n}=t;if(!t||!e||!r||!n&&r==="POST"||!i)throw new Error("Missing endpoint or method");let o=u.getInstance().getApiEndpoint();if(o+=e,r==="GET"){let d=new URLSearchParams({...n,version:b(),opt_out:await s.get("optOut")||0,user_id:await w()||"undefined",wallet_address:await s.get("walletAddress")||"undefined"});o+=`?${d.toString()}`}else r==="POST"&&(n={...n,version:b(),optOut:await s.get("optOut")||0,userId:await w()||void 0,walletAddress:n?.walletAddress||await s.get("walletAddress")||void 0});return await(await fetch(o,{method:r,headers:{"Content-Type":"application/json","x-api-key":i},body:r==="POST"?JSON.stringify(n):void 0})).json()},E=At;var yt=async({apiKey:t,body:e})=>await E({path:"/check/popup",apiKey:t,method:"POST",params:e}),B=yt;var C="updateCache";var V=30*60*1e3,bt=async(t,e)=>{e||(e=V);let r=await s.get("quietDomains");typeof r=="object"?r[t]=Date.now()+e:r={[t]:Date.now()+V},s.set("quietDomains",r)},T=bt;var Ot=async({apiKey:t,walletAddress:e,cashbackUrl:r,lastActivation:i})=>{let n={walletAddress:e};return i&&(n.lastActivation=i),r&&(n.cashbackUrl=r),await E({path:"/check/notification",apiKey:t,method:"POST",params:n})},H=Ot;var Tt=(t,e)=>new Promise((n,o)=>{let a=c=>{chrome.tabs.get(t,d=>{if(chrome.runtime.lastError){n(null);return}chrome.tabs.sendMessage(t,{...e,from:"bringweb3"},m=>{chrome.runtime.lastError?c<4?setTimeout(()=>a(c+1),1e3*Math.pow(2,c)):n(null):n(m||null)})})};a(0)}),A=Tt;var vt=async t=>{let e=await s.get("walletAddress");try{if(!t){let i=await chrome.tabs.query({active:!0,currentWindow:!0});if(!i||!i[0]||!i[0].id)return e;t=i[0].id}let r=await A(t,{action:"GET_WALLET_ADDRESS"});r?.walletAddress&&e!==r?.walletAddress&&(e=r?.walletAddress,await s.set("walletAddress",e))}catch{}return e},D=vt;var xt=async(t,e,r)=>{let i={showNotification:!1,token:"",iframeUrl:""},n=await s.get("notificationCheck");if(n&&Date.now()<n)return i;let o=e?await D(e):await s.get("walletAddress");if(!o)return i;let a=await s.get("lastActivation"),c=await H({apiKey:t,walletAddress:o,cashbackUrl:r,lastActivation:a});s.set("notificationCheck",c.nextCall);let d={showNotification:c.showNotification,token:c.token,iframeUrl:c.iframeUrl,expiration:c.expiration};return d.showNotification&&await s.set("notification",d),d},I=xt;var Pt=t=>t?chrome.runtime.getURL(t):"",_=Pt;var Ct=async t=>{let e=u.getInstance().getWhitelistEndpoint(),r={path:"/domains",apiKey:t,method:"GET"};return e&&(r.params={whitelist:encodeURIComponent(e)}),await E(r)},Q=Ct;var J=async()=>{try{let t=u.getInstance().getWhitelistEndpoint();if(!t)return[];let e=await fetch(t,{method:"GET",cache:"no-store",headers:{"Cache-Control":"no-store, no-cache, must-revalidate, max-age=0",Pragma:"no-cache"}});if(!e.ok)throw new Error("Failed to fetch whitelist");let r=await e.json();if(!Array.isArray(r))throw new Error("whitelist isn't an array");return r}catch(t){return console.error("Error fetching whitelist:",t),[]}};var Dt=t=>{let e=Date.now();return(t-e)/1e3/60},y=async()=>{let t=await s.get("relevantDomainsCheck"),e=await s.get("relevantDomains"),r=await s.get("redirectsWhitelist"),i=u.getInstance().getApiKey(),n=u.getInstance().getWhitelistEndpoint();if(e?.length&&t&&t>Date.now()&&(!n||n&&r?.length))return e;let o=await Q(i),{nextUpdateTimestamp:a,relevantDomains:c}=o;s.set("relevantDomains",c),s.set("relevantDomainsCheck",a),r=await J(),r&&s.set("redirectsWhitelist",r);let d=Dt(a);return chrome.alarms.create(C,{delayInMinutes:d||60*24*2}),c};var It=async(t,e)=>{try{let r=u.getInstance().getWhitelistEndpoint();if(r&&!e?.length&&(await y(),e=await s.get("redirectsWhitelist")),!e?.length)return!r;let n=new URL(t).hostname.toLowerCase();return n=n.replace("www.",""),e.includes(n)?!0:e.some(o=>{if(o.startsWith("*.")){let a=o.slice(2);return n.endsWith(a)}return!1})}catch{return console.error("Invalid URL:",t),!1}},k=It;var _t=async(t,e,r,i,n,o,a)=>{if(e===chrome.runtime.id&&await s.set("lastActivation",Date.now()),t&&T(t,n||Date.now()+24*60*60*1e3),o&&a){let c=await s.get("redirectsWhitelist");await k(a,c)&&chrome.tabs.update(o,{url:a})}await I(r,void 0,_(i))},Y=_t;var z=async t=>t<0?(await s.remove("optOut"),{isOptedOut:!1}):(await s.set("optOut",Date.now()+t),{isOptedOut:!0}),X=async()=>{let t=await s.get("optOut");return{isOptedOut:!!(t&&t>Date.now())}};var Z=async(t,e,r)=>{await A(t,{action:"INJECT",page:"notification",token:e.token,iframeUrl:e.iframeUrl,userId:await w(),domain:r})},kt=async(t,e,r,i)=>{let n=await s.get("notification");if(n?.expiration<Date.now())await s.remove("notification");else if(n)return await Z(e,n,i);let o=await I(t,e,_(r));if(o.showNotification)return await Z(e,o,i)},tt=kt;var St=async t=>{let e=await y();if(!t||!e||!e.length)return"";let r=O(t);for(let i of e)if(r.startsWith(i)){let n=await s.get("quietDomains");return n&&n[i]&&Date.now()<n[i]?"":i}return""},M={},Ut=async({identifier:t,apiEndpoint:e,cashbackPagePath:r,whitelistEndpoint:i})=>{if(!t||!e)throw new Error("Missing configuration");if(!["prod","sandbox"].includes(e))throw new Error("unknown apiEndpoint");u.getInstance().setApiEndpoint(e),u.getInstance().setWhitelistEndpoint(i||""),u.getInstance().setApiKey(t),y(),chrome.alarms.onAlarm.addListener(async n=>{let{name:o}=n;switch(o){case C:y();break;default:console.error("alarm with no use case:",o);break}}),chrome.runtime.onMessage.addListener((n,o,a)=>{if(n?.from!=="bringweb3")return;let{action:c}=n;switch(c){case"ACTIVATE":{let{domain:m,extensionId:f,time:p,redirectUrl:g}=n;return Y(m,f,t,r,p,o.tab?.id,g).then(()=>a()),!0}case"GET_OPT_OUT":return X().then(m=>a(m)),!0;case"OPT_OUT":{let{time:m}=n;return z(m).then(f=>a(f)),!0}case"CLOSE":{let{time:m,domain:f}=n;return f&&(T(f,m),a({message:"domain added to quiet list"})),!0}case"WALLET_ADDRESS_UPDATE":{let{walletAddress:m}=n;return m?s.set("walletAddress",m).then(()=>a(m)):s.remove("walletAddress").then(()=>a({message:"wallet address removed successfully"})),!0}case"ERASE_NOTIFICATION":return s.remove("notification").then(()=>a({message:"notification erased successfully"})),!0;default:return console.warn(`Bring unknown action: ${c}`),!0;case"OPEN_CASHBACK_PAGE":let{url:d}=n;return q(d||r),a({message:"cashback page opened successfully"}),!0}}),chrome.tabs.onUpdated.addListener(async(n,o,a)=>{if(!a?.url?.startsWith("http")||!a.url)return;let c=O(a.url),d=await s.get("optOut");if(d&&d>Date.now())return;d&&(s.remove("optOut"),s.remove("optOutKey"));let m=M[n];if(o.status!=="complete"||c===m)return;M[n]=c;let f=await St(a.url);if(!f||!f.length){await tt(t,n,r,c);return}let p=await D(n),{token:g,isValid:l,iframeUrl:v,networkUrl:x}=await B({apiKey:t,body:{domain:f,url:a.url,address:p}});if(!l){l===!1&&T(f);return}if(!await k(x,await s.get("redirectsWhitelist")))return;let P=await w();A(n,{action:"INJECT",token:g,domain:c,iframeUrl:v,userId:P})}),chrome.tabs.onRemoved.addListener(n=>delete M[n])},Mt=Ut;var Nt=()=>new Promise((t,e)=>{chrome.runtime.sendMessage({from:"bringweb3",action:"GET_OPT_OUT"},r=>{if(chrome.runtime.lastError){console.error(chrome.runtime.lastError),e(chrome.runtime.lastError);return}t({isTurnedOff:r.isOptedOut})})}),Wt=t=>new Promise((e,r)=>{let i=t?Number.MAX_SAFE_INTEGER:-1;chrome.runtime.sendMessage({from:"bringweb3",action:"OPT_OUT",time:i},n=>{if(chrome.runtime.lastError){console.error(chrome.runtime.lastError),r(chrome.runtime.lastError);return}n?e({isTurnedOff:n.isOptedOut}):r("No response received")})});export{Mt as bringInitBackground,ft as bringInitContentScript,Nt as getTurnOff,Wt as setTurnOff};
1
+ var rt=t=>{let e=new URLSearchParams,{query:r,prefix:o}=t;return Object.entries(r).forEach(([n,i])=>{i&&(o&&(n=`${o}_${n}`),n==="url"?e.append(n,encodeURIComponent(i)):e.append(n,i))}),e.toString()},k=rt;var L={name:"@bringweb3/chrome-extension-kit",version:"1.3.5",description:"Crypto cashback integration kit for crypto outlets extension",main:"dist/index.js",module:"dist/index.mjs",types:"dist/index.d.ts",license:"MIT",private:!1,publishConfig:{access:"public"},repository:{type:"git",url:"https://github.com/Bring-Web3-LTD/chromeExtension.git"},scripts:{watch:"tsup index.ts --env.IFRAME_URL=http://localhost:5173 --format cjs,esm --dts --watch",build:"tsup index.ts --format cjs,esm --dts --minify",lint:"tsc",test:"vitest --coverage",release:"yarn build && changeset publish"},files:["dist","README.md"],devDependencies:{"@changesets/cli":"^2.27.7","@types/chrome":"^0.0.268","@vitest/coverage-v8":"^2.0.5",tsup:"^8.2.1",typescript:"^5.5.3",vitest:"^2.0.5"},keywords:["cashback","crypto","bringweb3"],dependencies:{uuid:"^11.0.3"}};var it=()=>L.version,b=it;var ot=({query:t,theme:e,themeMode:r,text:o,iframeUrl:n,page:i,switchWallet:a})=>{let c=chrome.runtime.id,l=`bringweb3-iframe-${c}`,m=document.getElementById(l),f=process?.env?.IFRAME_URL?`${process.env.IFRAME_URL}${i?"/"+i:""}`:n;if(m)return m;let p=k({query:{...t,extensionId:c,v:b(),themeMode:r,textMode:o,switchWallet:String(a)}}),g=e?`&${k({query:e,prefix:"t"})}`:"",d=document.createElement("iframe");return d.id=l,d.src=`${f}?${p}${g}`,d.setAttribute("sandbox","allow-scripts allow-same-origin"),d.style.position="fixed",d.scrolling="no",d.style.overflow="hidden",d.style.width="1px",d.style.height="1px",d.style.right="8px",d.style.borderRadius="10px",d.style.border="none",d.style.cssText+="z-index: 99999999999999 !important;",e?.popupShadow&&(d.style.boxShadow=e.popupShadow),document.documentElement.appendChild(d),d},R=ot;var st=(t,e)=>{!t||!e||!Object.keys(e).length||Object.entries(e).forEach(([r,o])=>{r in t.style&&(t.style[r]=o)})},K=st;var at=t=>{if(!t||!t.length)return;let e=document.createElement("style");document.head.appendChild(e);let r=e.sheet;r?t.forEach(({name:o,rules:n})=>{r.insertRule(`@keyframes ${o} { ${n} }`,r.cssRules.length)}):console.error("Failed to create stylesheet")},F=at;var h={OPEN:"OPEN",CLOSE:"CLOSE",ACTIVATE:"ACTIVATE",PROMPT_LOGIN:"PROMPT_LOGIN",OPT_OUT:"OPT_OUT",ADD_KEYFRAMES:"ADD_KEYFRAMES",ERASE_NOTIFICATION:"ERASE_NOTIFICATION",OPEN_CASHBACK_PAGE:"OPEN_CASHBACK_PAGE"},ct=[h.ACTIVATE],mt=({event:t,iframeEl:e,promptLogin:r})=>{let{data:o}=t,{from:n,action:i,style:a,keyFrames:c,time:l,extensionId:m,url:f,domain:p,redirectUrl:g}=o;if(n==="bringweb3"&&!(m!==chrome.runtime.id&&!ct.includes(i)))switch(i){case h.OPEN:K(e,a);break;case h.CLOSE:e&&e.parentNode?.removeChild(e),l&&chrome.runtime.sendMessage({action:i,time:l,domain:p,from:"bringweb3"});break;case h.PROMPT_LOGIN:r();break;case h.ACTIVATE:chrome.runtime.sendMessage({action:i,from:"bringweb3",domain:p,extensionId:m,time:l,redirectUrl:g});break;case h.OPT_OUT:chrome.runtime.sendMessage({action:i,time:l,from:"bringweb3"});break;case h.ERASE_NOTIFICATION:chrome.runtime.sendMessage({action:i,from:"bringweb3"});case h.ADD_KEYFRAMES:F(c);break;case h.OPEN_CASHBACK_PAGE:chrome.runtime.sendMessage({action:i,url:f,from:"bringweb3"});break;default:break}},$=mt;var j=async({iframeEl:t,getWalletAddress:e})=>{if(!t&&(t=document.querySelector(`#bringweb3-iframe-${chrome.runtime.id}`),!t)||!t.contentWindow)return;let r=await e();t.contentWindow.postMessage({action:"WALLET_ADDRESS_UPDATE",walletAddress:r},"*"),chrome.runtime.sendMessage({action:"WALLET_ADDRESS_UPDATE",from:"bringweb3",walletAddress:r})},lt=({walletAddressListeners:t,walletAddressUpdateCallback:e,getWalletAddress:r,iframeEl:o})=>{if(e)e(()=>j({iframeEl:o,getWalletAddress:r}));else if(t)for(let n=0;n<t.length;n++){let i=t[n];i&&window.addEventListener(i,async()=>j({iframeEl:o,getWalletAddress:r}))}},G=lt;var dt=["www.","www1.","www2."],ut=t=>{if(!t)return"";t=t.split("://").reverse()[0]||"";for(let e of dt)t.startsWith(e)&&(t=t.replace(e,""));return t},P=ut;var U=null,q=!1,ft=async({getWalletAddress:t,promptLogin:e,walletAddressListeners:r,walletAddressUpdateCallback:o,lightTheme:n,darkTheme:i,theme:a,text:c,switchWallet:l=!1})=>{if(window.self===window.top){if(!t||!e||!r?.length&&typeof o!="function")throw new Error("Missing configuration");G({walletAddressListeners:r,walletAddressUpdateCallback:o,getWalletAddress:t,iframeEl:U}),window.addEventListener("message",m=>$({event:m,iframeEl:U,promptLogin:e})),chrome.runtime.onMessage.addListener((m,f,p)=>{if(m?.from!=="bringweb3")return;let{action:g}=m;switch(g){case"GET_WALLET_ADDRESS":return t().then(W=>p({status:"success",walletAddress:W})).catch(W=>p({status:"success",walletAddress:void 0})),!0;case"INJECT":if(m.domain!==P(location.href)||q)return p({status:"Domain already changed"}),!0;let{token:d,iframeUrl:T,userId:v}=m,x={token:d};return v&&(x.userId=v),U=R({query:x,iframeUrl:T,theme:a==="dark"?i:n,themeMode:a||"light",text:c,switchWallet:l,page:m.page}),q=!0,p({status:"success"}),!0;default:console.error(`Unknown action: ${g}`);break}})}},pt=ft;var B=t=>{t&&chrome.tabs.create({url:t})};var u=class t{static instance=null;apiEndpoint="";whitelistEndpoint="";apiKey="";constructor(){}static getInstance(){return t.instance||(t.instance=new t),t.instance}setWhitelistEndpoint(e){this.whitelistEndpoint=e}setApiEndpoint(e){this.apiEndpoint=e==="prod"?"https://api.bringweb3.io/v1/extension":"https://sandbox-api.bringweb3.io/v1/extension"}setApiKey(e){this.apiKey=e}getWhitelistEndpoint(){return this.whitelistEndpoint}getApiEndpoint(){if(!this.apiEndpoint)throw new Error("API endpoint not set. Call setApiEndpoint first.");return this.apiEndpoint}getApiKey(){if(!this.apiKey)throw new Error("API key not set. Call setApiKey first.");return this.apiKey}};var gt=async(t,e)=>new Promise((r,o)=>{chrome.storage.local.set({[`bring_${t}`]:e},()=>{chrome.runtime.lastError?o(chrome.runtime.lastError):r()})}),ht=async t=>new Promise((e,r)=>{chrome.storage.local.get([`bring_${t}`],o=>{chrome.runtime.lastError?r(chrome.runtime.lastError):e(o[`bring_${t}`])})}),wt=async t=>new Promise((e,r)=>{chrome.storage.local.remove([`bring_${t}`],()=>{chrome.runtime.lastError?r(chrome.runtime.lastError):e()})}),s={set:gt,get:ht,remove:wt};import{v4 as Et}from"uuid";var At=async()=>{let t=await s.get("id");return t||(t=Et(),s.set("id",t)),t},w=At;var yt=async t=>{let{path:e,method:r,apiKey:o,params:n}=t;if(!t||!e||!r||!n&&r==="POST"||!o)throw new Error("Missing endpoint or method");let i=u.getInstance().getApiEndpoint();if(i+=e,r==="GET"){let l=new URLSearchParams({...n,version:b(),timestamp:Date.now().toString(),opt_out:await s.get("optOut")||0,user_id:await w()||"undefined",wallet_address:await s.get("walletAddress")||"undefined"});i+=`?${l.toString()}`}else r==="POST"&&(n={...n,version:b(),timestamp:Date.now(),optOut:await s.get("optOut")||0,userId:await w()||void 0,walletAddress:n?.walletAddress||await s.get("walletAddress")||void 0});return await(await fetch(i,{method:r,headers:{"Content-Type":"application/json","x-api-key":o},body:r==="POST"?JSON.stringify(n):void 0})).json()},E=yt;var bt=async({apiKey:t,body:e})=>await E({path:"/check/popup",apiKey:t,method:"POST",params:e}),V=bt;var D="updateCache";var H=30*60*1e3,Ot=async(t,e)=>{e||(e=H);let r=await s.get("quietDomains");typeof r=="object"?r[t]=Date.now()+e:r={[t]:Date.now()+H},s.set("quietDomains",r)},O=Ot;var Tt=async({apiKey:t,walletAddress:e,cashbackUrl:r,lastActivation:o})=>{let n={walletAddress:e};return o&&(n.lastActivation=o),r&&(n.cashbackUrl=r),await E({path:"/check/notification",apiKey:t,method:"POST",params:n})},Q=Tt;var vt=(t,e)=>new Promise((n,i)=>{let a=c=>{chrome.tabs.get(t,l=>{if(chrome.runtime.lastError){n(null);return}chrome.tabs.sendMessage(t,{...e,from:"bringweb3"},m=>{chrome.runtime.lastError?c<4?setTimeout(()=>a(c+1),1e3*Math.pow(2,c)):n(null):n(m||null)})})};a(0)}),A=vt;var xt=async t=>{let e=await s.get("walletAddress");try{if(!t){let o=await chrome.tabs.query({active:!0,currentWindow:!0});if(!o||!o[0]||!o[0].id)return e;t=o[0].id}let r=await A(t,{action:"GET_WALLET_ADDRESS"});r?.walletAddress&&e!==r?.walletAddress&&(e=r?.walletAddress,await s.set("walletAddress",e))}catch{}return e},C=xt;var Pt=async(t,e,r)=>{let o={showNotification:!1,token:"",iframeUrl:""},n=await s.get("notificationCheck");if(n&&Date.now()<n)return o;let i=e?await C(e):await s.get("walletAddress");if(!i)return o;let a=await s.get("lastActivation"),c=await Q({apiKey:t,walletAddress:i,cashbackUrl:r,lastActivation:a});s.set("notificationCheck",c.nextCall);let l={showNotification:c.showNotification,token:c.token,iframeUrl:c.iframeUrl,expiration:c.expiration};return l.showNotification&&await s.set("notification",l),l},I=Pt;var Dt=t=>t?chrome.runtime.getURL(t):"",S=Dt;var Ct=async t=>{let e=u.getInstance().getWhitelistEndpoint(),r={path:"/domains",apiKey:t,method:"GET"};return e&&(r.params={whitelist:encodeURIComponent(e)}),await E(r)},J=Ct;var Y=async()=>{try{let t=u.getInstance().getWhitelistEndpoint();if(!t)return[];let e=await fetch(t,{method:"GET",cache:"no-store",headers:{"Cache-Control":"no-store, no-cache, must-revalidate, max-age=0",Pragma:"no-cache"}});if(!e.ok)throw new Error("Failed to fetch whitelist");let r=await e.json();if(!Array.isArray(r))throw new Error("whitelist isn't an array");return r}catch(t){return console.error("Error fetching whitelist:",t),[]}};var It=t=>{let e=Date.now();return(t-e)/1e3/60},y=async()=>{let t=await s.get("relevantDomainsCheck"),e=await s.get("relevantDomains"),r=await s.get("redirectsWhitelist"),o=u.getInstance().getApiKey(),n=u.getInstance().getWhitelistEndpoint();if(e?.length&&t&&t>Date.now()&&(!n||n&&r?.length))return e;let i=await J(o),{nextUpdateTimestamp:a,relevantDomains:c}=i;s.set("relevantDomains",c),s.set("relevantDomainsCheck",a),r=await Y(),r&&s.set("redirectsWhitelist",r);let l=It(a);return chrome.alarms.create(D,{delayInMinutes:l||60*24*2}),c};var St=async(t,e)=>{try{let r=u.getInstance().getWhitelistEndpoint();if(r&&!e?.length&&(await y(),e=await s.get("redirectsWhitelist")),!e?.length)return!r;let n=new URL(t).hostname.toLowerCase();return n=n.replace("www.",""),e.includes(n)?!0:e.some(i=>{if(i.startsWith("*.")){let a=i.slice(2);return n.endsWith(a)}return!1})}catch{return console.error("Invalid URL:",t),!1}},_=St;var _t=async(t,e,r,o,n,i,a)=>{if(e===chrome.runtime.id&&await s.set("lastActivation",Date.now()),t&&O(t,n||Date.now()+24*60*60*1e3),i&&a){let c=await s.get("redirectsWhitelist");await _(a,c)&&chrome.tabs.update(i,{url:a})}await I(r,void 0,S(o))},z=_t;var X=async t=>t<0?(await s.remove("optOut"),{isOptedOut:!1}):(await s.set("optOut",Date.now()+t),{isOptedOut:!0}),Z=async()=>{let t=await s.get("optOut");return{isOptedOut:!!(t&&t>Date.now())}};var tt=async(t,e,r)=>{await A(t,{action:"INJECT",page:"notification",token:e.token,iframeUrl:e.iframeUrl,userId:await w(),domain:r})},kt=async(t,e,r,o)=>{let n=await s.get("notification");if(n?.expiration<Date.now())await s.remove("notification");else if(n)return await tt(e,n,o);let i=await I(t,e,S(r));if(i.showNotification)return await tt(e,i,o)},et=kt;var Ut=t=>t.endsWith("/")?t.slice(0,-1):t,M=Ut;var Mt=["www.","www1.","www2."],Nt=async t=>{let e=await y();if(!t||!e||!e.length)return"";let r=null;try{r=new URL(t)}catch{r=new URL(`https://${t}`)}let o=r.hostname,n=M(r.pathname);for(let i of Mt)o=o.replace(i,"");for(let i of e){let a=i;i=M(i);let c=!1;i.startsWith("*.")&&(c=!0);let l="/"+i.split("/").slice(1).join("/")||"";if(l!=="/"&&n.startsWith(l)&&(o+=l),o===i||c&&o.endsWith(i.replace("*.",""))){let m=await s.get("quietDomains");return m&&m[i]&&Date.now()<m[i]?"":a}}return""},N={},Wt=async({identifier:t,apiEndpoint:e,cashbackPagePath:r,whitelistEndpoint:o})=>{if(!t||!e)throw new Error("Missing configuration");if(!["prod","sandbox"].includes(e))throw new Error("unknown apiEndpoint");u.getInstance().setApiEndpoint(e),u.getInstance().setWhitelistEndpoint(o||""),u.getInstance().setApiKey(t),y(),chrome.alarms.onAlarm.addListener(async n=>{let{name:i}=n;switch(i){case D:y();break;default:console.error("alarm with no use case:",i);break}}),chrome.runtime.onMessage.addListener((n,i,a)=>{if(n?.from!=="bringweb3")return;let{action:c}=n;switch(c){case"ACTIVATE":{let{domain:m,extensionId:f,time:p,redirectUrl:g}=n;return z(m,f,t,r,p,i.tab?.id,g).then(()=>a()),!0}case"GET_OPT_OUT":return Z().then(m=>a(m)),!0;case"OPT_OUT":{let{time:m}=n;return X(m).then(f=>a(f)),!0}case"CLOSE":{let{time:m,domain:f}=n;return f&&(O(f,m),a({message:"domain added to quiet list"})),!0}case"WALLET_ADDRESS_UPDATE":{let{walletAddress:m}=n;return m?s.set("walletAddress",m).then(()=>a(m)):s.remove("walletAddress").then(()=>a({message:"wallet address removed successfully"})),!0}case"ERASE_NOTIFICATION":return s.remove("notification").then(()=>a({message:"notification erased successfully"})),!0;default:return console.warn(`Bring unknown action: ${c}`),!0;case"OPEN_CASHBACK_PAGE":let{url:l}=n;return B(l||r),a({message:"cashback page opened successfully"}),!0}}),chrome.tabs.onUpdated.addListener(async(n,i,a)=>{if(!a?.url?.startsWith("http")||!a.url)return;let c=P(a.url),l=await s.get("optOut");if(l&&l>Date.now())return;l&&(s.remove("optOut"),s.remove("optOutKey"));let m=N[n];if(i.status!=="complete"||c===m)return;N[n]=c;let f=await Nt(a.url);if(!f||!f.length){await et(t,n,r,c);return}let p=await C(n),{token:g,isValid:d,iframeUrl:T,networkUrl:v}=await V({apiKey:t,body:{domain:f,url:a.url,address:p}});if(!d){d===!1&&O(f);return}if(!await _(v,await s.get("redirectsWhitelist")))return;let x=await w();A(n,{action:"INJECT",token:g,domain:c,iframeUrl:T,userId:x})}),chrome.tabs.onRemoved.addListener(n=>delete N[n])},Lt=Wt;var Rt=()=>new Promise((t,e)=>{chrome.runtime.sendMessage({from:"bringweb3",action:"GET_OPT_OUT"},r=>{if(chrome.runtime.lastError){console.error(chrome.runtime.lastError),e(chrome.runtime.lastError);return}t({isTurnedOff:r.isOptedOut})})}),Kt=t=>new Promise((e,r)=>{let o=t?Number.MAX_SAFE_INTEGER:-1;chrome.runtime.sendMessage({from:"bringweb3",action:"OPT_OUT",time:o},n=>{if(chrome.runtime.lastError){console.error(chrome.runtime.lastError),r(chrome.runtime.lastError);return}n?e({isTurnedOff:n.isOptedOut}):r("No response received")})});export{Lt as bringInitBackground,pt as bringInitContentScript,Rt as getTurnOff,Kt as setTurnOff};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bringweb3/chrome-extension-kit",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "description": "Crypto cashback integration kit for crypto outlets extension",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",