@bringweb3/chrome-extension-kit 1.0.9 → 1.0.10
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 +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var g=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var K=(e,t)=>{for(var n in t)g(e,n,{get:t[n],enumerable:!0})},J=(e,t,n,
|
|
1
|
+
"use strict";var g=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var K=(e,t)=>{for(var n in t)g(e,n,{get:t[n],enumerable:!0})},J=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of F(t))!V.call(e,s)&&s!==n&&g(e,s,{get:()=>t[s],enumerable:!(r=W(t,s))||r.enumerable});return e};var Q=e=>J(g({},"__esModule",{value:!0}),e);var fe={};K(fe,{bringInitBackground:()=>U,bringInitContentScript:()=>R});module.exports=Q(fe);var B=e=>{let t=new URLSearchParams,{query:n,prefix:r}=e;return Object.entries(n).forEach(([s,i])=>{i&&(r&&(s=`${r}_${s}`),s==="url"?t.append(s,encodeURIComponent(i)):t.append(s,i))}),t.toString()},h=B;var T={name:"@bringweb3/chrome-extension-kit",version:"1.0.10",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"},scripts:{watch:"tsup index.ts --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"}};var H=()=>T.version,k=H;var Y=({query:e,theme:t,iframeSrc:n})=>{let r=chrome.runtime.id,s=h({query:{...e,extensionId:r,v:k()}}),i=t?`&${h({query:t,prefix:"t"})}`:"",o=document.createElement("iframe");return o.id=`bringweb3-iframe:${r}`,o.src=`${n}?${s}${i}`,o.setAttribute("sandbox","allow-popups allow-scripts allow-same-origin allow-top-navigation-by-user-activation"),o.style.position="fixed",o.scrolling="no",o.style.overflow="hidden",o.style.width="1px",o.style.height="1px",o.style.right="8px",o.style.borderRadius="10px",o.style.border="none",o.style.cssText+="z-index: 99999999999999 !important;",t?.popupShadow&&(o.style.boxShadow=t.popupShadow),document.documentElement.appendChild(o),o},v=Y;var z=(e,t)=>{!e||!t||!Object.keys(t).length||Object.entries(t).forEach(([n,r])=>{n in e.style&&(e.style[n]=r)})},D=z;var X=e=>{if(!e||!e.length)return;let t=document.createElement("style");document.head.appendChild(t);let n=t.sheet;n?e.forEach(({name:r,rules:s})=>{n.insertRule(`@keyframes ${r} { ${s} }`,n.cssRules.length)}):console.error("Failed to create stylesheet")},C=X;var u={OPEN:"OPEN",CLOSE:"CLOSE",ACTIVATE:"ACTIVATE",PROMPT_LOGIN:"PROMPT_LOGIN",OPT_OUT:"OPT_OUT",ADD_KEYFRAMES:"ADD_KEYFRAMES"},Z=[u.ACTIVATE],ee=({event:e,iframeEl:t,promptLogin:n})=>{let{data:r}=e,{from:s,action:i,style:o,keyFrames:a,time:c,extensionId:l}=r;if(s==="bringweb3"&&!(l!==chrome.runtime.id&&!Z.includes(i)))switch(i){case u.OPEN:D(t,o);break;case u.CLOSE:t&&t.parentNode?.removeChild(t),c&&chrome.runtime.sendMessage({action:i,time:c,from:"bringweb3"});break;case u.PROMPT_LOGIN:n();break;case u.ACTIVATE:chrome.runtime.sendMessage({action:i,from:"bringweb3"});break;case u.OPT_OUT:chrome.runtime.sendMessage({action:i,time:c,from:"bringweb3"});break;case u.ADD_KEYFRAMES:C(a);break;default:break}},P=ee;var te=({walletAddressListeners:e,getWalletAddress:t,iframeEl:n})=>{for(let r=0;r<e.length;r++){let s=e[r];s&&window.addEventListener(s,async i=>{if(!n&&(n=document.querySelector(`#bringweb3-iframe:${chrome.runtime.id}`),!n)||!n.contentWindow)return;let o=await t();n.contentWindow.postMessage({action:"WALLET_ADDRESS_UPDATE",walletAddress:o},"*")})}},S=te;var w=null,O=!1,ne=async({getWalletAddress:e,promptLogin:t,walletAddressListeners:n,customTheme:r,iframeEndpoint:s})=>{if(!e||!t||!n?.length||!s)throw new Error("Missing configuration");S({walletAddressListeners:n,getWalletAddress:e,iframeEl:w}),window.addEventListener("message",i=>P({event:i,iframeEl:w,promptLogin:t})),chrome.runtime.onMessage.addListener((i,o,a)=>{let{action:c}=i;switch(c){case"GET_WALLET_ADDRESS":return e().then(p=>a({status:"success",walletAddress:p})).catch(p=>a({status:"success",walletAddress:void 0})),!0;case"INJECT":if(O)return;let{token:l,page:f}=i;return w=v({query:{token:l},iframeSrc:f==="notification"?`${s}notification`:s,theme:r}),O=!0,a({status:"success"}),!0;default:console.error(`Unknown action: ${c}`);break}})},R=ne;var m=class e{static instance=null;apiEndpoint="";constructor(){}static getInstance(){return e.instance||(e.instance=new e),e.instance}setApiEndpoint(t){this.apiEndpoint=t==="prod"?"https://api.bringweb3.io/v1/extension":"https://sandbox-api.bringweb3.io/v1/extension"}getApiEndpoint(){if(!this.apiEndpoint)throw new Error("API endpoint not set. Call setApiEndpoint first.");return this.apiEndpoint}};var re=async e=>{let t=m.getInstance().getApiEndpoint();return await(await fetch(`${t}/domains`,{headers:{"x-api-key":e}})).json()},I=re;var se=async({apiKey:e,body:t})=>{let n=m.getInstance().getApiEndpoint();return await(await fetch(`${n}/check/popup`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":e},body:JSON.stringify(t)})).json()},L=se;var ie=async({apiKey:e,walletAddress:t,cashbackUrl:n})=>{let r=m.getInstance().getApiEndpoint(),s={walletAddress:t};return n&&(s.cashbackUrl=n),await(await fetch(`${r}/check/notification`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":e},body:JSON.stringify(s)})).json()},M=ie;var y="updateCache";var oe=async(e,t)=>new Promise((n,r)=>{chrome.storage.local.set({[`bring_${e}`]:t},()=>{chrome.runtime.lastError?r(chrome.runtime.lastError):n()})}),ae=async e=>new Promise((t,n)=>{chrome.storage.local.get([`bring_${e}`],r=>{chrome.runtime.lastError?n(chrome.runtime.lastError):t(r[`bring_${e}`])})}),ce=async e=>new Promise((t,n)=>{chrome.storage.local.remove([`bring_${e}`],()=>{chrome.runtime.lastError?n(chrome.runtime.lastError):t()})}),d={set:oe,get:ae,remove:ce};var N=30*60*1e3,$=async e=>{let t=await d.get("walletAddress");try{if(!e){let r=await chrome.tabs.query({active:!0,currentWindow:!0});if(!r||!r[0]||!r[0].id)return t;e=r[0].id}let n=await b(e,{action:"GET_WALLET_ADDRESS"});n?.walletAddress&&t!==n?.walletAddress&&(t=n?.walletAddress,await d.set("walletAddress",t))}catch{}return t},de=e=>{let t=Date.now();return(e-t)/1e3/60},A=async e=>{let t=await I(e);d.set("relevantDomains",t.relevantDomains);let{nextUpdateTimestamp:n}=t,r=de(n);return chrome.alarms.create(y,{delayInMinutes:r||60*24*2}),t.relevantDomains},le=async(e,t,n,r)=>{let s={showNotification:!1,token:""},i=await d.get("notificationCheck");if(i?.check&&Date.now()<i.check)return s;let o=await $(t);if(!o)return s;let a=await M({apiKey:e,walletAddress:o,cashbackUrl:n}),c={check:r?a.nextRequestTimestampActivated:a.nextRequestTimestampRegular,nextRequestTimestampActivated:a.nextRequestTimestampActivated,nextRequestTimestampRegular:a.nextRequestTimestampRegular};return d.set("notificationCheck",c),{showNotification:a.showNotification,token:a.token}},me=e=>e.replace(/^(https?:\/\/)?(www\.)?/,""),_=async(e,t)=>{let n=await d.get("relevantDomains");if(n===void 0&&(n=await A(t)),!e||!n||!n.length)return"";let r=me(e);for(let s of n)if(r.startsWith(s)){let i=await d.get("quietDomains");return i&&i[s]&&Date.now()<i[s]?"":s}return""},j=async(e,t)=>{t||(t=N);let n=await d.get("quietDomains");typeof n=="object"?n[e]=Date.now()+t:n={[e]:Date.now()+N},d.set("quietDomains",n)},ue=e=>e?chrome.runtime.getURL(e):void 0,b=async(e,t)=>{for(let s=0;s<5;s++)try{let i=await chrome.tabs.get(e);return chrome.runtime.lastError?void 0:await chrome.tabs.sendMessage(e,t)}catch{s<4&&await new Promise(o=>setTimeout(o,1e3*Math.pow(2,s)))}},q=async(e,t,n)=>{let r=await le(e,t,ue(n));r.showNotification&&await b(t,{action:"INJECT",token:r.token,page:"notification"})},E={},pe=async({identifier:e,apiEndpoint:t,cashbackPagePath:n})=>{if(!e||!t)throw new Error("Missing configuration");if(!["prod","sandbox"].includes(t))throw new Error("unknown apiEndpoint");m.getInstance().setApiEndpoint(t),A(e),chrome.alarms.onAlarm.addListener(async r=>{let{name:s}=r;switch(s){case y:A(e);break;default:console.error("alarm with no use case:",s);break}}),chrome.runtime.onMessage.addListener(async(r,s)=>{let{action:i,time:o,from:a}=r;if(a==="bringweb3")switch(i){case"ACTIVATE":let c=await d.get("notificationCheck");if(!c.check||!c.nextRequestTimestampActivated)break;c.check=c.nextRequestTimestampActivated,d.set("notificationCheck",c);break;case"OPT_OUT":d.set("optOut",Date.now()+o);break;case"CLOSE":let l=await _(s.tab?.url||s.origin,e);if(!l)break;j(l,o);break;default:console.warn(`Bring unknown action: ${i}`);break}}),chrome.tabs.onUpdated.addListener(async(r,s,i)=>{let o=await d.get("optOut");if(o&&o>Date.now()){await q(e,r,n);return}if(!i.url)return;let a=i.url.replace("www.",""),c=E[r];if(s.status!=="complete"||a===c)return;E[r]=a;let l=await _(i.url,e);if(!l||!l.length){await q(e,r,n);return}let f=await $(r),{token:p,isValid:x}=await L({apiKey:e,body:{domain:l,url:i.url,address:f}});if(!x){x===!1&&j(l);return}b(r,{action:"INJECT",token:p,domain:a})}),chrome.tabs.onRemoved.addListener(r=>delete E[r])},U=pe;0&&(module.exports={bringInitBackground,bringInitContentScript});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var q=e=>{let t=new URLSearchParams,{query:n,prefix:
|
|
1
|
+
var q=e=>{let t=new URLSearchParams,{query:n,prefix:r}=e;return Object.entries(n).forEach(([s,i])=>{i&&(r&&(s=`${r}_${s}`),s==="url"?t.append(s,encodeURIComponent(i)):t.append(s,i))}),t.toString()},g=q;var x={name:"@bringweb3/chrome-extension-kit",version:"1.0.10",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"},scripts:{watch:"tsup index.ts --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"}};var U=()=>x.version,T=U;var W=({query:e,theme:t,iframeSrc:n})=>{let r=chrome.runtime.id,s=g({query:{...e,extensionId:r,v:T()}}),i=t?`&${g({query:t,prefix:"t"})}`:"",o=document.createElement("iframe");return o.id=`bringweb3-iframe:${r}`,o.src=`${n}?${s}${i}`,o.setAttribute("sandbox","allow-popups allow-scripts allow-same-origin allow-top-navigation-by-user-activation"),o.style.position="fixed",o.scrolling="no",o.style.overflow="hidden",o.style.width="1px",o.style.height="1px",o.style.right="8px",o.style.borderRadius="10px",o.style.border="none",o.style.cssText+="z-index: 99999999999999 !important;",t?.popupShadow&&(o.style.boxShadow=t.popupShadow),document.documentElement.appendChild(o),o},k=W;var F=(e,t)=>{!e||!t||!Object.keys(t).length||Object.entries(t).forEach(([n,r])=>{n in e.style&&(e.style[n]=r)})},v=F;var V=e=>{if(!e||!e.length)return;let t=document.createElement("style");document.head.appendChild(t);let n=t.sheet;n?e.forEach(({name:r,rules:s})=>{n.insertRule(`@keyframes ${r} { ${s} }`,n.cssRules.length)}):console.error("Failed to create stylesheet")},D=V;var u={OPEN:"OPEN",CLOSE:"CLOSE",ACTIVATE:"ACTIVATE",PROMPT_LOGIN:"PROMPT_LOGIN",OPT_OUT:"OPT_OUT",ADD_KEYFRAMES:"ADD_KEYFRAMES"},K=[u.ACTIVATE],J=({event:e,iframeEl:t,promptLogin:n})=>{let{data:r}=e,{from:s,action:i,style:o,keyFrames:a,time:c,extensionId:l}=r;if(s==="bringweb3"&&!(l!==chrome.runtime.id&&!K.includes(i)))switch(i){case u.OPEN:v(t,o);break;case u.CLOSE:t&&t.parentNode?.removeChild(t),c&&chrome.runtime.sendMessage({action:i,time:c,from:"bringweb3"});break;case u.PROMPT_LOGIN:n();break;case u.ACTIVATE:chrome.runtime.sendMessage({action:i,from:"bringweb3"});break;case u.OPT_OUT:chrome.runtime.sendMessage({action:i,time:c,from:"bringweb3"});break;case u.ADD_KEYFRAMES:D(a);break;default:break}},C=J;var Q=({walletAddressListeners:e,getWalletAddress:t,iframeEl:n})=>{for(let r=0;r<e.length;r++){let s=e[r];s&&window.addEventListener(s,async i=>{if(!n&&(n=document.querySelector(`#bringweb3-iframe:${chrome.runtime.id}`),!n)||!n.contentWindow)return;let o=await t();n.contentWindow.postMessage({action:"WALLET_ADDRESS_UPDATE",walletAddress:o},"*")})}},P=Q;var h=null,S=!1,B=async({getWalletAddress:e,promptLogin:t,walletAddressListeners:n,customTheme:r,iframeEndpoint:s})=>{if(!e||!t||!n?.length||!s)throw new Error("Missing configuration");P({walletAddressListeners:n,getWalletAddress:e,iframeEl:h}),window.addEventListener("message",i=>C({event:i,iframeEl:h,promptLogin:t})),chrome.runtime.onMessage.addListener((i,o,a)=>{let{action:c}=i;switch(c){case"GET_WALLET_ADDRESS":return e().then(p=>a({status:"success",walletAddress:p})).catch(p=>a({status:"success",walletAddress:void 0})),!0;case"INJECT":if(S)return;let{token:l,page:f}=i;return h=k({query:{token:l},iframeSrc:f==="notification"?`${s}notification`:s,theme:r}),S=!0,a({status:"success"}),!0;default:console.error(`Unknown action: ${c}`);break}})},G=B;var m=class e{static instance=null;apiEndpoint="";constructor(){}static getInstance(){return e.instance||(e.instance=new e),e.instance}setApiEndpoint(t){this.apiEndpoint=t==="prod"?"https://api.bringweb3.io/v1/extension":"https://sandbox-api.bringweb3.io/v1/extension"}getApiEndpoint(){if(!this.apiEndpoint)throw new Error("API endpoint not set. Call setApiEndpoint first.");return this.apiEndpoint}};var H=async e=>{let t=m.getInstance().getApiEndpoint();return await(await fetch(`${t}/domains`,{headers:{"x-api-key":e}})).json()},O=H;var Y=async({apiKey:e,body:t})=>{let n=m.getInstance().getApiEndpoint();return await(await fetch(`${n}/check/popup`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":e},body:JSON.stringify(t)})).json()},R=Y;var z=async({apiKey:e,walletAddress:t,cashbackUrl:n})=>{let r=m.getInstance().getApiEndpoint(),s={walletAddress:t};return n&&(s.cashbackUrl=n),await(await fetch(`${r}/check/notification`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":e},body:JSON.stringify(s)})).json()},I=z;var w="updateCache";var X=async(e,t)=>new Promise((n,r)=>{chrome.storage.local.set({[`bring_${e}`]:t},()=>{chrome.runtime.lastError?r(chrome.runtime.lastError):n()})}),Z=async e=>new Promise((t,n)=>{chrome.storage.local.get([`bring_${e}`],r=>{chrome.runtime.lastError?n(chrome.runtime.lastError):t(r[`bring_${e}`])})}),ee=async e=>new Promise((t,n)=>{chrome.storage.local.remove([`bring_${e}`],()=>{chrome.runtime.lastError?n(chrome.runtime.lastError):t()})}),d={set:X,get:Z,remove:ee};var L=30*60*1e3,j=async e=>{let t=await d.get("walletAddress");try{if(!e){let r=await chrome.tabs.query({active:!0,currentWindow:!0});if(!r||!r[0]||!r[0].id)return t;e=r[0].id}let n=await A(e,{action:"GET_WALLET_ADDRESS"});n?.walletAddress&&t!==n?.walletAddress&&(t=n?.walletAddress,await d.set("walletAddress",t))}catch{}return t},te=e=>{let t=Date.now();return(e-t)/1e3/60},E=async e=>{let t=await O(e);d.set("relevantDomains",t.relevantDomains);let{nextUpdateTimestamp:n}=t,r=te(n);return chrome.alarms.create(w,{delayInMinutes:r||60*24*2}),t.relevantDomains},ne=async(e,t,n,r)=>{let s={showNotification:!1,token:""},i=await d.get("notificationCheck");if(i?.check&&Date.now()<i.check)return s;let o=await j(t);if(!o)return s;let a=await I({apiKey:e,walletAddress:o,cashbackUrl:n}),c={check:r?a.nextRequestTimestampActivated:a.nextRequestTimestampRegular,nextRequestTimestampActivated:a.nextRequestTimestampActivated,nextRequestTimestampRegular:a.nextRequestTimestampRegular};return d.set("notificationCheck",c),{showNotification:a.showNotification,token:a.token}},re=e=>e.replace(/^(https?:\/\/)?(www\.)?/,""),M=async(e,t)=>{let n=await d.get("relevantDomains");if(n===void 0&&(n=await E(t)),!e||!n||!n.length)return"";let r=re(e);for(let s of n)if(r.startsWith(s)){let i=await d.get("quietDomains");return i&&i[s]&&Date.now()<i[s]?"":s}return""},N=async(e,t)=>{t||(t=L);let n=await d.get("quietDomains");typeof n=="object"?n[e]=Date.now()+t:n={[e]:Date.now()+L},d.set("quietDomains",n)},se=e=>e?chrome.runtime.getURL(e):void 0,A=async(e,t)=>{for(let s=0;s<5;s++)try{let i=await chrome.tabs.get(e);return chrome.runtime.lastError?void 0:await chrome.tabs.sendMessage(e,t)}catch{s<4&&await new Promise(o=>setTimeout(o,1e3*Math.pow(2,s)))}},_=async(e,t,n)=>{let r=await ne(e,t,se(n));r.showNotification&&await A(t,{action:"INJECT",token:r.token,page:"notification"})},y={},ie=async({identifier:e,apiEndpoint:t,cashbackPagePath:n})=>{if(!e||!t)throw new Error("Missing configuration");if(!["prod","sandbox"].includes(t))throw new Error("unknown apiEndpoint");m.getInstance().setApiEndpoint(t),E(e),chrome.alarms.onAlarm.addListener(async r=>{let{name:s}=r;switch(s){case w:E(e);break;default:console.error("alarm with no use case:",s);break}}),chrome.runtime.onMessage.addListener(async(r,s)=>{let{action:i,time:o,from:a}=r;if(a==="bringweb3")switch(i){case"ACTIVATE":let c=await d.get("notificationCheck");if(!c.check||!c.nextRequestTimestampActivated)break;c.check=c.nextRequestTimestampActivated,d.set("notificationCheck",c);break;case"OPT_OUT":d.set("optOut",Date.now()+o);break;case"CLOSE":let l=await M(s.tab?.url||s.origin,e);if(!l)break;N(l,o);break;default:console.warn(`Bring unknown action: ${i}`);break}}),chrome.tabs.onUpdated.addListener(async(r,s,i)=>{let o=await d.get("optOut");if(o&&o>Date.now()){await _(e,r,n);return}if(!i.url)return;let a=i.url.replace("www.",""),c=y[r];if(s.status!=="complete"||a===c)return;y[r]=a;let l=await M(i.url,e);if(!l||!l.length){await _(e,r,n);return}let f=await j(r),{token:p,isValid:b}=await R({apiKey:e,body:{domain:l,url:i.url,address:f}});if(!b){b===!1&&N(l);return}A(r,{action:"INJECT",token:p,domain:a})}),chrome.tabs.onRemoved.addListener(r=>delete y[r])},oe=ie;export{oe as bringInitBackground,G as bringInitContentScript};
|