@pybara/donate-widget 1.0.0-beta.1 → 1.0.0-beta.3
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/README.md +3 -1
- package/dist/pybara-donate.iife.js +2 -2
- package/dist/pybara-donate.js +4 -4
- package/dist/widget.d.ts +2 -1
- package/options.schema.json +150 -0
- package/package.json +6 -9
package/README.md
CHANGED
|
@@ -100,6 +100,8 @@ The one exception is AutoStable: if you have a token converted to a stablecoin a
|
|
|
100
100
|
| `staging` | `boolean` | `false` | Use Pybara's staging environment, for testing |
|
|
101
101
|
| `debug` | `boolean` | `false` | Log details to the console |
|
|
102
102
|
|
|
103
|
+
The same options are published as a JSON Schema at [docs.pybara.com/donate-widget/options.schema.json](https://docs.pybara.com/donate-widget/options.schema.json) — for editors and agents that validate a config before writing it. A copy ships in the package as `options.schema.json`, versioned with the code.
|
|
104
|
+
|
|
103
105
|
### Example with options
|
|
104
106
|
|
|
105
107
|
```js
|
|
@@ -137,7 +139,7 @@ On a site with a strict Content Security Policy, allow:
|
|
|
137
139
|
|
|
138
140
|
## Learn more
|
|
139
141
|
|
|
140
|
-
[docs.pybara.com](https://docs.pybara.com/widget/overview/)
|
|
142
|
+
[docs.pybara.com](https://docs.pybara.com/donate-widget/overview/)
|
|
141
143
|
|
|
142
144
|
## License
|
|
143
145
|
|
|
@@ -452,7 +452,7 @@ ic-request`),new TextEncoder().encode(`\vic-response`)),_i=(new TextEncoder().en
|
|
|
452
452
|
--pybara-donate-primary-bg-hover: color-mix(in srgb, var(--pybara-donate-primary-strong) 9%, var(--pybara-donate-surface));
|
|
453
453
|
}
|
|
454
454
|
|
|
455
|
-
`;function fu(e,t){let n=e=>{let t=/^(\d+)-(\d+)$/.exec(e);return t?[Number(t[1]),Number(t[2])]:null},r=n(e),i=n(t);return!r||!i?!1:r[0]>i[0]||r[0]===i[0]&&r[1]>=i[1]}async function pu(e){let t=await fetch(e);if(!t.ok)throw Error(`HTTP ${t.status} from ${e}`);return await t.json()}async function mu(e,t,n,r){let i=Pe[e],a=`https://${i.admin_core}.raw.icp0.io/widget-config`,o=`https://${i.admin_regs}.raw.icp0.io/widget-terms?site_url=${encodeURIComponent(t)}&principal=${encodeURIComponent(n)}`,s,c;try{[s,c]=await Promise.all([pu(a),pu(o)])}catch(e){return{show:!1,reason:`could not read the widget's configuration (${e instanceof Error?e.message:String(e)})`}}let l=s.kill_switch?.plugins??{};return l[r.widget]?.enabled===!0?!c.signed||!c.version?{show:!1,reason:`${t} has not accepted the widget's terms in Pybara Wallet (Manage › Sites › Add a site without a plugin)`}:fu(c.version,`1-0`)?{show:!0,recurring:l[r.recurring]?.enabled===!0}:{show:!1,reason:`this widget version requires terms 1-0, and ${t} accepted ${c.version}: accept the new terms in Pybara Wallet (Manage › Sites)`}:{show:!1,reason:`the widget is switched off by Pybara for now`}}function hu(e){if(typeof e!=`string`)return null;let t=e.trim();if(t.length===4&&t[0]===`#`){let e=parseInt(t[1]+t[1],16),n=parseInt(t[2]+t[2],16),r=parseInt(t[3]+t[3],16);return Number.isNaN(e)||Number.isNaN(n)||Number.isNaN(r)?null:[e,n,r]}if(t.length===7&&t[0]===`#`){let e=parseInt(t.slice(1,3),16),n=parseInt(t.slice(3,5),16),r=parseInt(t.slice(5,7),16);return Number.isNaN(e)||Number.isNaN(n)||Number.isNaN(r)?null:[e,n,r]}return null}function gu([e,t,n]){let r=e=>{let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4};return .2126*r(e)+.7152*r(t)+.0722*r(n)}function _u(e,t){let n=gu(e),r=gu(t),i=Math.max(n,r),a=Math.min(n,r);return(i+.05)/(a+.05)}function vu(e,t,n){return[Math.round(e[0]+(t[0]-e[0])*n),Math.round(e[1]+(t[1]-e[1])*n),Math.round(e[2]+(t[2]-e[2])*n)]}function yu(e,t,n){let r=e;for(let i=1;i<=20;i++){if(_u(r,t)>=3)return r;r=vu(e,n,i*.05)}return r}function bu(e){return gu(e)<=.45?`#ffffff`:`#1a1a2e`}function xu(e){if(!e||e===`transparent`)return null;let t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)(?:\s*,\s*([\d.]+))?\s*\)/);return!t||t[4]!==void 0&&parseFloat(t[4])===0?null:[parseInt(t[1],10),parseInt(t[2],10),parseInt(t[3],10)]}function Su(e,t,n){let r=hu(t);if(!r)return;let i=n===`dark`?[28,34,42]:[255,255,255],a=n===`dark`?[255,255,255]:[26,26,46];e.style.setProperty(`--pybara-donate-contrast`,bu(r));let o=yu(r,i,a);e.style.setProperty(`--pybara-donate-primary-strong`,`rgb(${o[0]}, ${o[1]}, ${o[2]})`)}function Cu(e){let t=e;for(;t;){let e=getComputedStyle(t).backgroundColor,n=xu(e);if(n)return gu(n)<.4?`dark`:`light`;t=t.parentElement}return null}var wu={widget:`widget-donate`,recurring:`widget-donate-recurring`};function Tu(e,t,n){if(t||e===void 0)return 0;let r=au[n]??2592e3;return Math.ceil(e*ou/r)}function Eu(){let e=crypto.getRandomValues(new Uint8Array(16));return btoa(String.fromCharCode(...e))}var Du=`Pybara Sans`;async function Ou(e){if(e&&typeof FontFace<`u`){for(let e of document.fonts)if(e.family===Du)return;try{let t=new FontFace(Du,`url(${e}) format('woff2')`,{weight:`100 900`,style:`normal`,display:`swap`});await t.load(),document.fonts.add(t)}catch{}}}var ku=`<svg xmlns="http://www.w3.org/2000/svg" width="949.4" height="1000" viewBox="0 0 949.4 1000"><path fill="#fff" d="M849.6,223c-28.4-2.2-56.7-4-85.5.2-25.8,3.8-47.2,16.3-62.1,37s-6.2,16-9,23.9c-5.5,15.9-3.6,33,2.7,48.8,4.3,10.9,12.9,13.9,19.5,20.6,31.9,32.5,62.1,2.8,99.8-1.7.7,5.8-.9,11.2-2.1,16.4-9.8,40.6-26.6,79.1-53.6,111.9-16.3,19.8-34.7,36.4-57.7,47.4-22.4,10.8-38.5-9.3-53.9-22.2-.8,9.1-5.1,14.2-12.8,16.5-71.4,21.1-138,38-198.1,83.9-17.7,13.5-33.1,27.3-47.7,44.1-56.9,65.4-86.1,148.8-84,236.3-25.6-10.5-47.5-24.5-68.8-39.6-123.4-87.6-182.8-240.3-154.2-388.7,14.8-76.9,49.6-148.7,102.4-206.1,1.2,19.1,1.4,38.1.2,58.3,9.4-11.2,66.2-61.2,68.4-65.3l2.6-4.9c31.9-32.4,35.8-85.6,10.2-123.7-10.7-15.9-26.2-25.5-45.8-27.3,17.7-17,47.6-6.2,66,5.2,15.2,9.4,26.9,21.7,39.4,35.2,80.2-25.6,154.6-26.9,237.7-15,86,12.3,167.8,39.3,243.7,81.3,15.6,8.6,29.4,17.3,42.7,27.6h0ZM498.8,263.4l33.7-15.2c-7.5-7.9-15.7-13.2-19-22.2-4.5-12.6-8.6-24.2-17.8-34.1-14.4-15.6-36.8-22.2-56.8-13.9-22.4,9.3-35.7,30.3-36.5,54.3l-19.4,2c11.6,20.1,31.8,33.7,55.3,38.4,20.5,4.1,40.7-.4,60.5-9.3h0Z"/><path fill="#696969" d="M255.7,239.7l-2.6,4.9c-2.2,4.1-58.9,54.1-68.4,65.3,1.2-20.2,1-39.1-.2-58.3s-.3-26-2.7-40.1-2.4-34.2,4.4-49.3c5.7-12.7,19-17,31.2-11.5,16.2,7.4,23,25.5,18,42.4-4.1,13.7-.9,27.4,9.4,36.7l10.8,9.8h.1Z"/><path fill="#fff" d="M872.7,349.3c-.9,38-2.8,115.8-21.7,150.3-17.9-41.7-25.4-85.9-25.2-129.8,0-4.2.7-8.8,1.5-13.4s4.7-6.7,9.2-5.8l15,2.9c8,1.5,14.8-.2,21.1-4.1h.1Z"/><path fill="#010101" d="M498.8,263.4c-19.8,8.9-39.9,13.4-60.5,9.3-23.5-4.7-43.7-18.2-55.3-38.4l19.4-2c.8-24.1,14.1-45,36.5-54.3,20-8.3,42.4-1.7,56.8,13.9s13.3,21.5,17.8,34.1c3.2,9.1,11.5,14.4,19,22.2l-33.7,15.2h0Z"/><g><path fill="#010101" d="M856.4,577.4c-11.1,43.3-64.7,59.2-103.9,62.8-23,2.1-40.4-12.2-43-36.4-10.4,15-14,31.2-16.7,48.5-8.4,66,23.9,135.7,69.1,182.9-158.3,165.9-410,170.9-581.9,24.1-93-79.9-148.5-198.4-149.6-321.7-.9-108,37.8-220.1,109.7-301.7-15.9-66.6,10.6-186.5,89-199.4,40.5-6.7,80.4,15.6,109.2,41.9,88-23.8,185.5-19.6,274,0,85.6,19,180,54.1,252.8,103.1,36.6,24.6,49.7,62.4,48.6,105.6l-2.4,92.9c-.9,33.7-5.2,66-13.3,98.5-4.3,17.3-11,32.8-20.6,47.6-3.1,4.8-9.3,8.3-11.4,13.5l-9.7,37.8h.1ZM255.7,239.7l-10.8-9.8c-10.3-9.3-13.4-23.1-9.4-36.7,5-16.9-1.8-35-18-42.4-12.2-5.5-25.5-1.2-31.2,11.5-6.8,15.1-7.2,32.6-4.4,49.3s1.8,27,2.7,40.1c-52.8,57.4-87.6,129.3-102.4,206.1-28.7,148.4,30.8,301.1,154.2,388.7,21.3,15.1,43.2,29,68.8,39.6-2.1-87.5,27.1-170.9,84-236.3,14.6-16.8,30-30.6,47.7-44.1,60.1-45.9,126.7-62.9,198.1-83.9,7.6-2.3,12-7.4,12.8-16.5,15.5,13,31.5,33,53.9,22.2,22.9-11,41.3-27.6,57.7-47.4,27-32.8,43.8-71.2,53.6-111.9,2.8,4.5,8.6,3.6,12.9,1.5-.3,43.9,7.2,88,25.2,129.8,18.9-34.4,20.7-112.2,21.7-150.3s1-4.4.2-7.3c-14.4,2.5-30,.1-35.9-14.7-9.9-24.9,24.9-41.8,31-61.5,4.9-16-6.9-33.8-18.4-42.8-13.3-10.3-27.1-19-42.7-27.6-75.9-42-157.7-68.9-243.7-81.3-83.1-11.9-157.5-10.7-237.7,15-12.5-13.5-24.2-25.8-39.4-35.2-18.4-11.4-48.3-22.1-66-5.2,19.5,1.9,35.1,11.4,45.8,27.3,25.6,38.1,21.7,91.3-10.2,123.7h0ZM818.5,581.1c7.2-24.2,8.4-48.1,11.4-72.3l-19.2-53.8-16.7,137.6c7.3-.2,21.9-2.5,24.6-11.5h0ZM752.4,595.3c9.1.5,15.3.2,23.1-.5,7.7-39.3,15.1-78,18.4-119.6-12.2,15.1-22.1,29.9-34.8,43.2-3.9,4.1-5.2,8.3-5.1,14,.2,21.3-.4,41.8-1.5,62.8h-.1Z"/><path fill="#fff" d="M752.4,595.3c1.1-21,1.7-41.5,1.5-62.8,0-5.7,1.2-9.9,5.1-14,12.7-13.4,22.6-28.1,34.8-43.2-3.3,41.6-10.6,80.3-18.4,119.6-7.8.7-13.9,1-23.1.5h.1Z"/><path fill="#fff" d="M818.5,581.1c-2.7,9-17.3,11.3-24.6,11.5l16.7-137.6,19.2,53.8c-2.9,24.2-4.1,48.1-11.4,72.3h0Z"/><g><path fill="#696969" d="M849.6,223c11.5,8.9,23.3,26.7,18.4,42.8-6,19.7-40.8,36.6-31,61.5,5.9,14.8,21.5,17.2,35.9,14.7.8,2.9-.2,5.2-.2,7.3-6.3,3.9-13.1,5.6-21.1,4.1l-15-2.9c-4.5-.9-8.4,1.2-9.2,5.8-.8,4.6-1.4,9.2-1.5,13.4-4.4,2-10.1,2.9-12.9-1.5,1.2-5.2,2.9-10.6,2.1-16.4-37.7,4.5-67.9,34.2-99.8,1.7,0-1.1,1.6-1.2,2.9-.7,19.9,7.3,34.3,5,44.6-13.8,10.6-19.6,25.4-1.4,37.4-13.6,9.7-9.9-4.5-33.9-13-40.6-6.2-4.9-13.1-8.4-19.5-12.8-11.3-7.8-24.6-3.9-31.3,8.2s-5.7,9.8-11.6,7.7c-6.8-2.5-13.7-1.8-21.1-2.8-3.8-.5-7.1-3.9-10.6-1.1,2.7-7.9,3.2-15.9,9-23.9,15-20.7,36.3-33.2,62.1-37,28.8-4.2,57.1-2.5,85.5-.2h-.1Z"/><path fill="#010101" d="M715.2,353.5c-6.6-6.7-15.2-9.7-19.5-20.6-6.3-15.8-8.2-32.9-2.7-48.8,3.5-2.8,6.8.6,10.6,1.1,7.4.9,14.2.3,21.1,2.8,5.9,2.1,9.3-3.6,11.6-7.7,6.7-12.1,20-16,31.3-8.2,6.4,4.4,13.3,7.9,19.5,12.8,8.5,6.7,22.7,30.7,13,40.6-11.9,12.2-26.7-6-37.4,13.6-10.2,18.9-24.7,21.1-44.6,13.8s-3-.3-2.9.7h0Z"/></g></g></svg>`,Au=class{constructor(e){this.shadowRoot=null,this.adminClient=null,this.modal=null,this.donated=!1,this.amountSelector=null,this.recurringOptions=null,this.submitBtn=null,this.errorEl=null,this.fiatRate=1,this.themeObserver=null,this.themeMqCleanup=null,this.userConfig=e,this.config=cu(e),this.strings=Xl(this.config.locale),this.state={selectedAmount:null,customAmount:``,recurring:{enabled:!1,frequency:this.config.defaultFrequency,duration_in_months:this.config.defaultDurationInMonths??void 0,is_unlimited:this.config.defaultDurationInMonths===null},isModalOpen:!1}}async mount(){let e=typeof this.config.target==`string`?document.querySelector(this.config.target):this.config.target;if(!e)throw Error(`[pybara-donate] Target element not found: ${this.config.target}`);if(!this.userConfig.pluginVersion){let e=await mu(this.config.staging?`staging`:`prod`,window.location.origin,this.config.recipientPrincipal,wu);if(!e.show){console.info(`[pybara-donate] Not shown: ${e.reason}.`);return}e.recurring||(this.config.allowRecurring=!1)}Ou(this.config.fontUrl);let t=document.createElement(`div`);t.className=`pybara-donate-host`,this.shadowRoot=t.attachShadow({mode:`open`});let n=document.createElement(`style`);n.textContent=du,this.shadowRoot.appendChild(n);let r=this.config.theme===`auto`?Cu(e)??(window.matchMedia?.(`(prefers-color-scheme: dark)`).matches?`dark`:`light`):this.config.theme;if(t.dataset.theme=r,t.style.setProperty(`--pybara-donate-primary`,this.config.primaryColor),hu(this.config.primaryColor)||this.log(`primaryColor "${this.config.primaryColor}" is not hex — contrast clamp skipped, CSS fallbacks apply`),Su(t,this.config.primaryColor,r),this.config.theme===`auto`){let n=!1,r=()=>{n||(n=!0,requestAnimationFrame(()=>{n=!1;let r=Cu(e)??(window.matchMedia?.(`(prefers-color-scheme: dark)`).matches?`dark`:`light`);r!==t.dataset.theme&&(t.dataset.theme=r,Su(t,this.config.primaryColor,r))}))},i={attributes:!0,attributeFilter:[`class`,`data-theme`,`data-color-scheme`,`data-bs-theme`,`data-mode`,`data-color-mode`,`style`]};this.themeObserver=new MutationObserver(r),this.themeObserver.observe(document.documentElement,i),this.themeObserver.observe(document.body,i);let a=window.matchMedia?.(`(prefers-color-scheme: dark)`);a&&(a.addEventListener(`change`,r),this.themeMqCleanup=()=>a.removeEventListener(`change`,r))}let i=this.buildWidgetDOM();this.shadowRoot.appendChild(i),e.appendChild(t),await this.initAdminClient(),this.preconnectWallet(),this.initCheckoutModal(),this.log(`Widget mounted successfully`)}preconnectWallet(){let e=Ne[this.config.staging?`staging`:`prod`];if(document.head.querySelector(`link[rel="preconnect"][href="${e}"]`))return;let t=document.createElement(`link`);t.rel=`preconnect`,t.href=e,document.head.appendChild(t)}initCheckoutModal(){let e=this.config.staging?`staging`:`prod`;this.modal=new Ul({walletUrl:Ne[e],context:`donation`,...this.config.thankYouMessage?{thankYouMessage:this.config.thankYouMessage}:{},onSuccess:e=>{this.log(`Donation successful — Block: ${e.blockIndex}, Token: ${e.token}`),this.donated=!0;let t=this.state.selectedAmount??0,n={blockHeight:BigInt(e.blockIndex),token:e.token,amount:t.toFixed(2),recurring:this.state.recurring.enabled,frequency:this.state.recurring.enabled?this.state.recurring.frequency:void 0,duration_in_months:this.state.recurring.enabled?this.state.recurring.duration_in_months:void 0,is_unlimited:this.state.recurring.enabled?this.state.recurring.is_unlimited:!1,donorPrincipal:e.payerPrincipal,recipientPrincipal:this.config.recipientPrincipal};this.userConfig.onSuccess&&this.userConfig.onSuccess(n)},onError:e=>{this.state.isModalOpen=!1,console.error(`[pybara-donate] Payment error:`,e),this.userConfig.onError&&this.userConfig.onError(e),this.initCheckoutModal()},onClose:()=>{if(this.state.isModalOpen=!1,this.donated){if(this.donated=!1,this.config.thankYouRedirectUrl){window.location.href=this.config.thankYouRedirectUrl;return}}else this.userConfig.onClose&&this.userConfig.onClose();this.initCheckoutModal()}})}buildWidgetDOM(){let e=document.createElement(`div`);if(e.className=`pybara-donate`,this.config.title||this.config.description){let t=document.createElement(`div`);if(t.className=`pybara-donate__intro`,this.config.title){let e=document.createElement(`h3`);e.className=`pybara-donate__title`,e.textContent=this.config.title,t.appendChild(e)}if(this.config.description){let e=document.createElement(`p`);e.className=`pybara-donate__description`,e.textContent=this.config.description,t.appendChild(e)}e.appendChild(t)}this.amountSelector=new lu({presetAmounts:this.config.presetAmounts,allowCustom:this.config.allowCustom,currencySymbol:tu(this.config.currency),customPlaceholder:this.strings.amount.customPlaceholder,onAmountChange:e=>{this.state.selectedAmount=e,this.updateSubmitState()}}),e.appendChild(this.amountSelector.render()),this.config.allowRecurring&&(this.recurringOptions=new uu({defaultFrequency:this.config.defaultFrequency,defaultDurationInMonths:this.config.defaultDurationInMonths??12,defaultIsUnlimited:this.config.defaultDurationInMonths===null,strings:this.strings.recurring,onChange:e=>{this.state.recurring=e,this.updateSubmitState()}}),e.appendChild(this.recurringOptions.render())),this.errorEl=document.createElement(`div`),this.errorEl.className=`pybara-donate__error`,this.errorEl.style.display=`none`,e.appendChild(this.errorEl),this.submitBtn=document.createElement(`button`),this.submitBtn.type=`button`,this.submitBtn.className=`pybara-donate__submit`,this.submitBtn.textContent=this.config.buttonLabel,this.submitBtn.disabled=!0,this.submitBtn.addEventListener(`click`,()=>this.handleDonate()),e.appendChild(this.submitBtn);let t=this.config.tokens.map(e=>`<div class="pybara-donate__footer-token"><img src="https://assets.pybara.com/images/tokens/${e.toLowerCase()}.svg" alt="${e}" loading="lazy" width="20" height="20"></div>`).join(``),n=document.createElement(`div`);return n.className=`pybara-donate__footer`,n.innerHTML=`
|
|
455
|
+
`;function fu(e,t){let n=e=>{let t=/^(\d+)-(\d+)$/.exec(e);return t?[Number(t[1]),Number(t[2])]:null},r=n(e),i=n(t);return!r||!i?!1:r[0]>i[0]||r[0]===i[0]&&r[1]>=i[1]}async function pu(e){let t=await fetch(e);if(!t.ok)throw Error(`HTTP ${t.status} from ${e}`);return await t.json()}async function mu(e,t,n,r){let i=Pe[e],a=`https://${i.admin_core}.raw.icp0.io/widget-config`,o=`https://${i.admin_regs}.raw.icp0.io/widget-terms?site_url=${encodeURIComponent(t)}&principal=${encodeURIComponent(n)}`,s,c;try{[s,c]=await Promise.all([pu(a),pu(o)])}catch(e){return{show:!1,reason:`could not read the widget's configuration (${e instanceof Error?e.message:String(e)})`}}let l=s.kill_switch?.plugins??{};return l[r.widget]?.enabled===!0?!c.signed||!c.version?{show:!1,reason:`${t} has not accepted the widget's terms in Pybara Wallet (Manage › Sites › Add a site without a plugin)`}:fu(c.version,`1-0`)?{show:!0,recurring:l[r.recurring]?.enabled===!0}:{show:!1,reason:`this widget version requires terms 1-0, and ${t} accepted ${c.version}: accept the new terms in Pybara Wallet (Manage › Sites)`}:{show:!1,reason:`the widget is switched off by Pybara for now`}}function hu(e){if(typeof e!=`string`)return null;let t=e.trim();if(t.length===4&&t[0]===`#`){let e=parseInt(t[1]+t[1],16),n=parseInt(t[2]+t[2],16),r=parseInt(t[3]+t[3],16);return Number.isNaN(e)||Number.isNaN(n)||Number.isNaN(r)?null:[e,n,r]}if(t.length===7&&t[0]===`#`){let e=parseInt(t.slice(1,3),16),n=parseInt(t.slice(3,5),16),r=parseInt(t.slice(5,7),16);return Number.isNaN(e)||Number.isNaN(n)||Number.isNaN(r)?null:[e,n,r]}return null}function gu([e,t,n]){let r=e=>{let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4};return .2126*r(e)+.7152*r(t)+.0722*r(n)}function _u(e,t){let n=gu(e),r=gu(t),i=Math.max(n,r),a=Math.min(n,r);return(i+.05)/(a+.05)}function vu(e,t,n){return[Math.round(e[0]+(t[0]-e[0])*n),Math.round(e[1]+(t[1]-e[1])*n),Math.round(e[2]+(t[2]-e[2])*n)]}function yu(e,t,n){let r=e;for(let i=1;i<=20;i++){if(_u(r,t)>=3)return r;r=vu(e,n,i*.05)}return r}function bu(e){return gu(e)<=.45?`#ffffff`:`#1a1a2e`}function xu(e){if(!e||e===`transparent`)return null;let t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)(?:\s*,\s*([\d.]+))?\s*\)/);return!t||t[4]!==void 0&&parseFloat(t[4])===0?null:[parseInt(t[1],10),parseInt(t[2],10),parseInt(t[3],10)]}function Su(e,t,n){let r=hu(t);if(!r)return;let i=n===`dark`?[28,34,42]:[255,255,255],a=n===`dark`?[255,255,255]:[26,26,46];e.style.setProperty(`--pybara-donate-contrast`,bu(r));let o=yu(r,i,a);e.style.setProperty(`--pybara-donate-primary-strong`,`rgb(${o[0]}, ${o[1]}, ${o[2]})`)}function Cu(e){let t=e;for(;t;){let e=getComputedStyle(t).backgroundColor,n=xu(e);if(n)return gu(n)<.4?`dark`:`light`;t=t.parentElement}return null}var wu={widget:`widget-donate`,recurring:`widget-donate-recurring`};function Tu(e,t,n){if(t||e===void 0)return 0;let r=au[n]??2592e3;return Math.ceil(e*ou/r)}function Eu(){let e=crypto.getRandomValues(new Uint8Array(16));return btoa(String.fromCharCode(...e))}var Du=`Pybara Sans`;async function Ou(e){if(e&&typeof FontFace<`u`){for(let e of document.fonts)if(e.family===Du)return;try{let t=new FontFace(Du,`url(${e}) format('woff2')`,{weight:`100 900`,style:`normal`,display:`swap`});await t.load(),document.fonts.add(t)}catch{}}}var ku=`<svg xmlns="http://www.w3.org/2000/svg" width="949.4" height="1000" viewBox="0 0 949.4 1000"><path fill="#fff" d="M849.6,223c-28.4-2.2-56.7-4-85.5.2-25.8,3.8-47.2,16.3-62.1,37s-6.2,16-9,23.9c-5.5,15.9-3.6,33,2.7,48.8,4.3,10.9,12.9,13.9,19.5,20.6,31.9,32.5,62.1,2.8,99.8-1.7.7,5.8-.9,11.2-2.1,16.4-9.8,40.6-26.6,79.1-53.6,111.9-16.3,19.8-34.7,36.4-57.7,47.4-22.4,10.8-38.5-9.3-53.9-22.2-.8,9.1-5.1,14.2-12.8,16.5-71.4,21.1-138,38-198.1,83.9-17.7,13.5-33.1,27.3-47.7,44.1-56.9,65.4-86.1,148.8-84,236.3-25.6-10.5-47.5-24.5-68.8-39.6-123.4-87.6-182.8-240.3-154.2-388.7,14.8-76.9,49.6-148.7,102.4-206.1,1.2,19.1,1.4,38.1.2,58.3,9.4-11.2,66.2-61.2,68.4-65.3l2.6-4.9c31.9-32.4,35.8-85.6,10.2-123.7-10.7-15.9-26.2-25.5-45.8-27.3,17.7-17,47.6-6.2,66,5.2,15.2,9.4,26.9,21.7,39.4,35.2,80.2-25.6,154.6-26.9,237.7-15,86,12.3,167.8,39.3,243.7,81.3,15.6,8.6,29.4,17.3,42.7,27.6h0ZM498.8,263.4l33.7-15.2c-7.5-7.9-15.7-13.2-19-22.2-4.5-12.6-8.6-24.2-17.8-34.1-14.4-15.6-36.8-22.2-56.8-13.9-22.4,9.3-35.7,30.3-36.5,54.3l-19.4,2c11.6,20.1,31.8,33.7,55.3,38.4,20.5,4.1,40.7-.4,60.5-9.3h0Z"/><path fill="#696969" d="M255.7,239.7l-2.6,4.9c-2.2,4.1-58.9,54.1-68.4,65.3,1.2-20.2,1-39.1-.2-58.3s-.3-26-2.7-40.1-2.4-34.2,4.4-49.3c5.7-12.7,19-17,31.2-11.5,16.2,7.4,23,25.5,18,42.4-4.1,13.7-.9,27.4,9.4,36.7l10.8,9.8h.1Z"/><path fill="#fff" d="M872.7,349.3c-.9,38-2.8,115.8-21.7,150.3-17.9-41.7-25.4-85.9-25.2-129.8,0-4.2.7-8.8,1.5-13.4s4.7-6.7,9.2-5.8l15,2.9c8,1.5,14.8-.2,21.1-4.1h.1Z"/><path fill="#010101" d="M498.8,263.4c-19.8,8.9-39.9,13.4-60.5,9.3-23.5-4.7-43.7-18.2-55.3-38.4l19.4-2c.8-24.1,14.1-45,36.5-54.3,20-8.3,42.4-1.7,56.8,13.9s13.3,21.5,17.8,34.1c3.2,9.1,11.5,14.4,19,22.2l-33.7,15.2h0Z"/><g><path fill="#010101" d="M856.4,577.4c-11.1,43.3-64.7,59.2-103.9,62.8-23,2.1-40.4-12.2-43-36.4-10.4,15-14,31.2-16.7,48.5-8.4,66,23.9,135.7,69.1,182.9-158.3,165.9-410,170.9-581.9,24.1-93-79.9-148.5-198.4-149.6-321.7-.9-108,37.8-220.1,109.7-301.7-15.9-66.6,10.6-186.5,89-199.4,40.5-6.7,80.4,15.6,109.2,41.9,88-23.8,185.5-19.6,274,0,85.6,19,180,54.1,252.8,103.1,36.6,24.6,49.7,62.4,48.6,105.6l-2.4,92.9c-.9,33.7-5.2,66-13.3,98.5-4.3,17.3-11,32.8-20.6,47.6-3.1,4.8-9.3,8.3-11.4,13.5l-9.7,37.8h.1ZM255.7,239.7l-10.8-9.8c-10.3-9.3-13.4-23.1-9.4-36.7,5-16.9-1.8-35-18-42.4-12.2-5.5-25.5-1.2-31.2,11.5-6.8,15.1-7.2,32.6-4.4,49.3s1.8,27,2.7,40.1c-52.8,57.4-87.6,129.3-102.4,206.1-28.7,148.4,30.8,301.1,154.2,388.7,21.3,15.1,43.2,29,68.8,39.6-2.1-87.5,27.1-170.9,84-236.3,14.6-16.8,30-30.6,47.7-44.1,60.1-45.9,126.7-62.9,198.1-83.9,7.6-2.3,12-7.4,12.8-16.5,15.5,13,31.5,33,53.9,22.2,22.9-11,41.3-27.6,57.7-47.4,27-32.8,43.8-71.2,53.6-111.9,2.8,4.5,8.6,3.6,12.9,1.5-.3,43.9,7.2,88,25.2,129.8,18.9-34.4,20.7-112.2,21.7-150.3s1-4.4.2-7.3c-14.4,2.5-30,.1-35.9-14.7-9.9-24.9,24.9-41.8,31-61.5,4.9-16-6.9-33.8-18.4-42.8-13.3-10.3-27.1-19-42.7-27.6-75.9-42-157.7-68.9-243.7-81.3-83.1-11.9-157.5-10.7-237.7,15-12.5-13.5-24.2-25.8-39.4-35.2-18.4-11.4-48.3-22.1-66-5.2,19.5,1.9,35.1,11.4,45.8,27.3,25.6,38.1,21.7,91.3-10.2,123.7h0ZM818.5,581.1c7.2-24.2,8.4-48.1,11.4-72.3l-19.2-53.8-16.7,137.6c7.3-.2,21.9-2.5,24.6-11.5h0ZM752.4,595.3c9.1.5,15.3.2,23.1-.5,7.7-39.3,15.1-78,18.4-119.6-12.2,15.1-22.1,29.9-34.8,43.2-3.9,4.1-5.2,8.3-5.1,14,.2,21.3-.4,41.8-1.5,62.8h-.1Z"/><path fill="#fff" d="M752.4,595.3c1.1-21,1.7-41.5,1.5-62.8,0-5.7,1.2-9.9,5.1-14,12.7-13.4,22.6-28.1,34.8-43.2-3.3,41.6-10.6,80.3-18.4,119.6-7.8.7-13.9,1-23.1.5h.1Z"/><path fill="#fff" d="M818.5,581.1c-2.7,9-17.3,11.3-24.6,11.5l16.7-137.6,19.2,53.8c-2.9,24.2-4.1,48.1-11.4,72.3h0Z"/><g><path fill="#696969" d="M849.6,223c11.5,8.9,23.3,26.7,18.4,42.8-6,19.7-40.8,36.6-31,61.5,5.9,14.8,21.5,17.2,35.9,14.7.8,2.9-.2,5.2-.2,7.3-6.3,3.9-13.1,5.6-21.1,4.1l-15-2.9c-4.5-.9-8.4,1.2-9.2,5.8-.8,4.6-1.4,9.2-1.5,13.4-4.4,2-10.1,2.9-12.9-1.5,1.2-5.2,2.9-10.6,2.1-16.4-37.7,4.5-67.9,34.2-99.8,1.7,0-1.1,1.6-1.2,2.9-.7,19.9,7.3,34.3,5,44.6-13.8,10.6-19.6,25.4-1.4,37.4-13.6,9.7-9.9-4.5-33.9-13-40.6-6.2-4.9-13.1-8.4-19.5-12.8-11.3-7.8-24.6-3.9-31.3,8.2s-5.7,9.8-11.6,7.7c-6.8-2.5-13.7-1.8-21.1-2.8-3.8-.5-7.1-3.9-10.6-1.1,2.7-7.9,3.2-15.9,9-23.9,15-20.7,36.3-33.2,62.1-37,28.8-4.2,57.1-2.5,85.5-.2h-.1Z"/><path fill="#010101" d="M715.2,353.5c-6.6-6.7-15.2-9.7-19.5-20.6-6.3-15.8-8.2-32.9-2.7-48.8,3.5-2.8,6.8.6,10.6,1.1,7.4.9,14.2.3,21.1,2.8,5.9,2.1,9.3-3.6,11.6-7.7,6.7-12.1,20-16,31.3-8.2,6.4,4.4,13.3,7.9,19.5,12.8,8.5,6.7,22.7,30.7,13,40.6-11.9,12.2-26.7-6-37.4,13.6-10.2,18.9-24.7,21.1-44.6,13.8s-3-.3-2.9.7h0Z"/></g></g></svg>`,Au=class{constructor(e,t){this.shadowRoot=null,this.adminClient=null,this.modal=null,this.donated=!1,this.amountSelector=null,this.recurringOptions=null,this.submitBtn=null,this.errorEl=null,this.fiatRate=1,this.themeObserver=null,this.themeMqCleanup=null,this.userConfig=e,this.onDestroy=t??null,this.config=cu(e),this.strings=Xl(this.config.locale),this.state={selectedAmount:null,customAmount:``,recurring:{enabled:!1,frequency:this.config.defaultFrequency,duration_in_months:this.config.defaultDurationInMonths??void 0,is_unlimited:this.config.defaultDurationInMonths===null},isModalOpen:!1}}async mount(){let e=typeof this.config.target==`string`?document.querySelector(this.config.target):this.config.target;if(!e)throw Error(`[pybara-donate] Target element not found: ${this.config.target}`);if(!this.userConfig.pluginVersion){let e=await mu(this.config.staging?`staging`:`prod`,window.location.origin,this.config.recipientPrincipal,wu);if(!e.show){console.info(`[pybara-donate] Not shown: ${e.reason}.`);return}e.recurring||(this.config.allowRecurring=!1)}Ou(this.config.fontUrl);let t=document.createElement(`div`);t.className=`pybara-donate-host`,this.shadowRoot=t.attachShadow({mode:`open`});let n=document.createElement(`style`);n.textContent=du,this.shadowRoot.appendChild(n);let r=this.config.theme===`auto`?Cu(e)??(window.matchMedia?.(`(prefers-color-scheme: dark)`).matches?`dark`:`light`):this.config.theme;if(t.dataset.theme=r,t.style.setProperty(`--pybara-donate-primary`,this.config.primaryColor),hu(this.config.primaryColor)||this.log(`primaryColor "${this.config.primaryColor}" is not hex — contrast clamp skipped, CSS fallbacks apply`),Su(t,this.config.primaryColor,r),this.config.theme===`auto`){let n=!1,r=()=>{n||(n=!0,requestAnimationFrame(()=>{n=!1;let r=Cu(e)??(window.matchMedia?.(`(prefers-color-scheme: dark)`).matches?`dark`:`light`);r!==t.dataset.theme&&(t.dataset.theme=r,Su(t,this.config.primaryColor,r))}))},i={attributes:!0,attributeFilter:[`class`,`data-theme`,`data-color-scheme`,`data-bs-theme`,`data-mode`,`data-color-mode`,`style`]};this.themeObserver=new MutationObserver(r),this.themeObserver.observe(document.documentElement,i),this.themeObserver.observe(document.body,i);let a=window.matchMedia?.(`(prefers-color-scheme: dark)`);a&&(a.addEventListener(`change`,r),this.themeMqCleanup=()=>a.removeEventListener(`change`,r))}let i=this.buildWidgetDOM();this.shadowRoot.appendChild(i),e.appendChild(t),await this.initAdminClient(),this.preconnectWallet(),this.initCheckoutModal(),this.log(`Widget mounted successfully`)}preconnectWallet(){let e=Ne[this.config.staging?`staging`:`prod`];if(document.head.querySelector(`link[rel="preconnect"][href="${e}"]`))return;let t=document.createElement(`link`);t.rel=`preconnect`,t.href=e,document.head.appendChild(t)}initCheckoutModal(){let e=this.config.staging?`staging`:`prod`;this.modal=new Ul({walletUrl:Ne[e],context:`donation`,...this.config.thankYouMessage?{thankYouMessage:this.config.thankYouMessage}:{},onSuccess:e=>{this.log(`Donation successful — Block: ${e.blockIndex}, Token: ${e.token}`),this.donated=!0;let t=this.state.selectedAmount??0,n={blockHeight:BigInt(e.blockIndex),token:e.token,amount:t.toFixed(2),recurring:this.state.recurring.enabled,frequency:this.state.recurring.enabled?this.state.recurring.frequency:void 0,duration_in_months:this.state.recurring.enabled?this.state.recurring.duration_in_months:void 0,is_unlimited:this.state.recurring.enabled?this.state.recurring.is_unlimited:!1,donorPrincipal:e.payerPrincipal,recipientPrincipal:this.config.recipientPrincipal};this.userConfig.onSuccess&&this.userConfig.onSuccess(n)},onError:e=>{this.state.isModalOpen=!1,console.error(`[pybara-donate] Payment error:`,e),this.userConfig.onError&&this.userConfig.onError(e),this.initCheckoutModal()},onClose:()=>{if(this.state.isModalOpen=!1,this.donated){if(this.donated=!1,this.config.thankYouRedirectUrl){window.location.href=this.config.thankYouRedirectUrl;return}}else this.userConfig.onClose&&this.userConfig.onClose();this.initCheckoutModal()}})}buildWidgetDOM(){let e=document.createElement(`div`);if(e.className=`pybara-donate`,this.config.title||this.config.description){let t=document.createElement(`div`);if(t.className=`pybara-donate__intro`,this.config.title){let e=document.createElement(`h3`);e.className=`pybara-donate__title`,e.textContent=this.config.title,t.appendChild(e)}if(this.config.description){let e=document.createElement(`p`);e.className=`pybara-donate__description`,e.textContent=this.config.description,t.appendChild(e)}e.appendChild(t)}this.amountSelector=new lu({presetAmounts:this.config.presetAmounts,allowCustom:this.config.allowCustom,currencySymbol:tu(this.config.currency),customPlaceholder:this.strings.amount.customPlaceholder,onAmountChange:e=>{this.state.selectedAmount=e,this.updateSubmitState()}}),e.appendChild(this.amountSelector.render()),this.config.allowRecurring&&(this.recurringOptions=new uu({defaultFrequency:this.config.defaultFrequency,defaultDurationInMonths:this.config.defaultDurationInMonths??12,defaultIsUnlimited:this.config.defaultDurationInMonths===null,strings:this.strings.recurring,onChange:e=>{this.state.recurring=e,this.updateSubmitState()}}),e.appendChild(this.recurringOptions.render())),this.errorEl=document.createElement(`div`),this.errorEl.className=`pybara-donate__error`,this.errorEl.style.display=`none`,e.appendChild(this.errorEl),this.submitBtn=document.createElement(`button`),this.submitBtn.type=`button`,this.submitBtn.className=`pybara-donate__submit`,this.submitBtn.textContent=this.config.buttonLabel,this.submitBtn.disabled=!0,this.submitBtn.addEventListener(`click`,()=>this.handleDonate()),e.appendChild(this.submitBtn);let t=this.config.tokens.map(e=>`<div class="pybara-donate__footer-token"><img src="https://assets.pybara.com/images/tokens/${e.toLowerCase()}.svg" alt="${e}" loading="lazy" width="20" height="20"></div>`).join(``),n=document.createElement(`div`);return n.className=`pybara-donate__footer`,n.innerHTML=`
|
|
456
456
|
<a href="https://pybara.com" target="_blank" rel="noopener noreferrer" class="pybara-donate__footer-brand">
|
|
457
457
|
<div class="pybara-donate__footer-logo">${ku}</div>
|
|
458
458
|
<div class="pybara-donate__footer-brand-text">
|
|
@@ -461,4 +461,4 @@ ic-request`),new TextEncoder().encode(`\vic-response`)),_i=(new TextEncoder().en
|
|
|
461
461
|
</div>
|
|
462
462
|
</a>
|
|
463
463
|
<div class="pybara-donate__footer-tokens">${t}</div>
|
|
464
|
-
`,e.appendChild(n),e}async initAdminClient(){try{let e=this.config.staging?`staging`:`prod`;if(this.adminClient=new El({adminCoreCanisterId:Pe[e].admin_core,debug:this.config.debug}),await this.adminClient.init(),await this.adminClient.getPybaraAdminConfig(),this.adminClient.getRecipientDataWithCache(this.config.siteUrl).catch(()=>{}),this.config.currency!==`USD`){let e=await this.adminClient.getFiatRate(this.config.currency);e===null?console.warn(`[pybara-donate] Could not fetch ${this.config.currency}/USD rate — amounts will be treated as USD`):(this.fiatRate=e,this.log(`Fiat rate: 1 ${this.config.currency} = $${e.toFixed(4)} USD`))}this.log(`Admin client initialized`)}catch(e){console.error(`[pybara-donate] Failed to init admin client:`,e)}}updateSubmitState(){if(!this.submitBtn)return;let e=this.state.selectedAmount,t=e!==null&&e>=.5;if(this.submitBtn.disabled=!t,t&&e!==null){let t=this.state.recurring.enabled?` / ${this.state.recurring.frequency}`:``,n=tu(this.config.currency);this.submitBtn.textContent=`${this.config.buttonLabel} ${n}${e.toFixed(2)}${t}`}else this.submitBtn.textContent=this.config.buttonLabel;this.hideError()}buildSdkFields(e){let t=[[`site_url`,this.config.siteUrl],[`site_name`,this.config.siteName],[`donation_amount_usd`,Math.round(e*1e4).toString()],[`donation_type`,this.state.recurring.enabled?`recurring`:`oneTime`],[`platform`,`pybara-donate`]],n=(e,n)=>{n!==void 0&&n!==``&&t.push([e,n])};return n(`donation_amount_local`,this.state.selectedAmount===null?void 0:Math.round(this.state.selectedAmount*1e4).toString()),n(`donation_local_currency`,this.config.currency),n(`site_country`,this.userConfig.siteCountry),n(`donor_is_anonymous`,this.userConfig.donorIsAnonymous?.toString()),n(`donor_message`,this.userConfig.donorMessage),n(`donor_first_name`,this.userConfig.donorFirstName),n(`donor_last_name`,this.userConfig.donorLastName),n(`donor_email`,this.userConfig.donorEmail),n(`donor_company`,this.userConfig.donorCompany),n(`donor_country`,this.userConfig.donorCountry),n(`donor_address_line_1`,this.userConfig.donorAddressLine1),n(`donor_address_line_2`,this.userConfig.donorAddressLine2),n(`donor_address_city`,this.userConfig.donorAddressCity),n(`donor_address_state`,this.userConfig.donorAddressState),n(`donor_address_postal_code`,this.userConfig.donorAddressPostalCode),n(`donor_address_country`,this.userConfig.donorAddressCountry),n(`donor_tos_version`,this.userConfig.donorTosVersion),n(`donor_tos_accepted_at`,this.userConfig.donorTosAcceptedAt),n(`recipient_tos_version`,this.userConfig.recipientTosVersion),n(`recipient_tos_accepted_at`,this.userConfig.recipientTosAcceptedAt),n(`plugin_version`,this.userConfig.pluginVersion),t}async handleDonate(){let e=this.state.selectedAmount;if(e===null||e<.5){this.showError(Zl(this.strings.errors.minimumDonation,{symbol:tu(this.config.currency),amount:su.toFixed(2)}));return}if(!this.state.isModalOpen){this.state.isModalOpen=!0,this.log(`Opening checkout — $${e} ${this.state.recurring.enabled?`(recurring)`:`(one-time)`}`);try{let t=e*this.fiatRate,n=!1;try{this.adminClient&&await this.adminClient.getRecipientDataWithCache(this.config.siteUrl)}catch(e){console.warn(`[pybara-donate] Recipient access validation failed:`,e),n=!0}this.modal||this.initCheckoutModal();let r=this.modal;if(!r)throw Error(`CheckoutModal failed to initialize`);n?(r.renderTerminalState(`This recipient is currently unable to accept donations.`),this.initCheckoutModal()):await r.show({modalData:{amountUSD:t,beneficiary:this.config.recipientPrincipal,salt:Eu(),reference:this.config.siteName},recurring:this.state.recurring.enabled?{frequency:this.state.recurring.frequency,totalPulls:Tu(this.state.recurring.duration_in_months,this.state.recurring.is_unlimited,this.state.recurring.frequency),...this.state.recurring.is_unlimited?{}:{durationMonths:this.state.recurring.duration_in_months}}:void 0,sdkFields:this.buildSdkFields(t)})}catch(e){this.state.isModalOpen=!1,console.error(`[pybara-donate] Failed to open checkout:`,e),this.showError(this.strings.widget.errorGeneric)}}}showError(e){this.errorEl&&(this.errorEl.textContent=e,this.errorEl.style.display=`block`)}hideError(){this.errorEl&&(this.errorEl.style.display=`none`)}log(e){this.config.debug&&console.log(`[pybara-donate] ${e}`)}destroy(){this.themeObserver?.disconnect(),this.themeObserver=null,this.themeMqCleanup?.(),this.themeMqCleanup=null,this.shadowRoot?.host&&this.shadowRoot.host.remove(),this.adminClient=null,this.shadowRoot=null,this.log(`Widget destroyed`)}},ju=new Map;function Mu(e){let t=typeof e.target==`string`?e.target:e.target.id||`pybara-${Date.now()}`;ju.has(t)&&ju.get(t)?.destroy();let n=new Au(e);return ju.set(t,n),n.mount().catch(e=>{console.error(`[pybara-donate] Mount failed:`,e)}),n}function Nu(){for(let e of ju.values())e.destroy();ju.clear()}return e.DonationWidget=Au,e.destroyAll=Nu,e.init=Mu,e})({});
|
|
464
|
+
`,e.appendChild(n),e}async initAdminClient(){try{let e=this.config.staging?`staging`:`prod`;if(this.adminClient=new El({adminCoreCanisterId:Pe[e].admin_core,debug:this.config.debug}),await this.adminClient.init(),await this.adminClient.getPybaraAdminConfig(),this.adminClient.getRecipientDataWithCache(this.config.siteUrl).catch(()=>{}),this.config.currency!==`USD`){let e=await this.adminClient.getFiatRate(this.config.currency);e===null?console.warn(`[pybara-donate] Could not fetch ${this.config.currency}/USD rate — amounts will be treated as USD`):(this.fiatRate=e,this.log(`Fiat rate: 1 ${this.config.currency} = $${e.toFixed(4)} USD`))}this.log(`Admin client initialized`)}catch(e){console.error(`[pybara-donate] Failed to init admin client:`,e)}}updateSubmitState(){if(!this.submitBtn)return;let e=this.state.selectedAmount,t=e!==null&&e>=.5;if(this.submitBtn.disabled=!t,t&&e!==null){let t=this.state.recurring.enabled?` / ${this.state.recurring.frequency}`:``,n=tu(this.config.currency);this.submitBtn.textContent=`${this.config.buttonLabel} ${n}${e.toFixed(2)}${t}`}else this.submitBtn.textContent=this.config.buttonLabel;this.hideError()}buildSdkFields(e){let t=[[`site_url`,this.config.siteUrl],[`site_name`,this.config.siteName],[`donation_amount_usd`,Math.round(e*1e4).toString()],[`donation_type`,this.state.recurring.enabled?`recurring`:`oneTime`],[`platform`,`pybara-donate`]],n=(e,n)=>{n!==void 0&&n!==``&&t.push([e,n])};return n(`donation_amount_local`,this.state.selectedAmount===null?void 0:Math.round(this.state.selectedAmount*1e4).toString()),n(`donation_local_currency`,this.config.currency),n(`site_country`,this.userConfig.siteCountry),n(`donor_is_anonymous`,this.userConfig.donorIsAnonymous?.toString()),n(`donor_message`,this.userConfig.donorMessage),n(`donor_first_name`,this.userConfig.donorFirstName),n(`donor_last_name`,this.userConfig.donorLastName),n(`donor_email`,this.userConfig.donorEmail),n(`donor_company`,this.userConfig.donorCompany),n(`donor_country`,this.userConfig.donorCountry),n(`donor_address_line_1`,this.userConfig.donorAddressLine1),n(`donor_address_line_2`,this.userConfig.donorAddressLine2),n(`donor_address_city`,this.userConfig.donorAddressCity),n(`donor_address_state`,this.userConfig.donorAddressState),n(`donor_address_postal_code`,this.userConfig.donorAddressPostalCode),n(`donor_address_country`,this.userConfig.donorAddressCountry),n(`donor_tos_version`,this.userConfig.donorTosVersion),n(`donor_tos_accepted_at`,this.userConfig.donorTosAcceptedAt),n(`recipient_tos_version`,this.userConfig.recipientTosVersion),n(`recipient_tos_accepted_at`,this.userConfig.recipientTosAcceptedAt),n(`plugin_version`,this.userConfig.pluginVersion),t}async handleDonate(){let e=this.state.selectedAmount;if(e===null||e<.5){this.showError(Zl(this.strings.errors.minimumDonation,{symbol:tu(this.config.currency),amount:su.toFixed(2)}));return}if(!this.state.isModalOpen){this.state.isModalOpen=!0,this.log(`Opening checkout — $${e} ${this.state.recurring.enabled?`(recurring)`:`(one-time)`}`);try{let t=e*this.fiatRate,n=!1;try{this.adminClient&&await this.adminClient.getRecipientDataWithCache(this.config.siteUrl)}catch(e){console.warn(`[pybara-donate] Recipient access validation failed:`,e),n=!0}this.modal||this.initCheckoutModal();let r=this.modal;if(!r)throw Error(`CheckoutModal failed to initialize`);n?(r.renderTerminalState(`This recipient is currently unable to accept donations.`),this.initCheckoutModal()):await r.show({modalData:{amountUSD:t,beneficiary:this.config.recipientPrincipal,salt:Eu(),reference:this.config.siteName},recurring:this.state.recurring.enabled?{frequency:this.state.recurring.frequency,totalPulls:Tu(this.state.recurring.duration_in_months,this.state.recurring.is_unlimited,this.state.recurring.frequency),...this.state.recurring.is_unlimited?{}:{durationMonths:this.state.recurring.duration_in_months}}:void 0,sdkFields:this.buildSdkFields(t)})}catch(e){this.state.isModalOpen=!1,console.error(`[pybara-donate] Failed to open checkout:`,e),this.showError(this.strings.widget.errorGeneric)}}}showError(e){this.errorEl&&(this.errorEl.textContent=e,this.errorEl.style.display=`block`)}hideError(){this.errorEl&&(this.errorEl.style.display=`none`)}log(e){this.config.debug&&console.log(`[pybara-donate] ${e}`)}destroy(){this.themeObserver?.disconnect(),this.themeObserver=null,this.themeMqCleanup?.(),this.themeMqCleanup=null,this.shadowRoot?.host&&this.shadowRoot.host.remove(),this.adminClient=null,this.shadowRoot=null,this.onDestroy?.(),this.log(`Widget destroyed`)}},ju=new Map;function Mu(e){let t=typeof e.target==`string`?e.target:e.target.id||`pybara-${Date.now()}`;ju.has(t)&&ju.get(t)?.destroy();let n=new Au(e,()=>ju.delete(t));return ju.set(t,n),n.mount().catch(e=>{console.error(`[pybara-donate] Mount failed:`,e)}),n}function Nu(){for(let e of ju.values())e.destroy();ju.clear()}return e.DonationWidget=Au,e.destroyAll=Nu,e.init=Mu,e})({});
|
package/dist/pybara-donate.js
CHANGED
|
@@ -8395,8 +8395,8 @@ async function Du(e) {
|
|
|
8395
8395
|
}
|
|
8396
8396
|
}
|
|
8397
8397
|
var Ou = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"949.4\" height=\"1000\" viewBox=\"0 0 949.4 1000\"><path fill=\"#fff\" d=\"M849.6,223c-28.4-2.2-56.7-4-85.5.2-25.8,3.8-47.2,16.3-62.1,37s-6.2,16-9,23.9c-5.5,15.9-3.6,33,2.7,48.8,4.3,10.9,12.9,13.9,19.5,20.6,31.9,32.5,62.1,2.8,99.8-1.7.7,5.8-.9,11.2-2.1,16.4-9.8,40.6-26.6,79.1-53.6,111.9-16.3,19.8-34.7,36.4-57.7,47.4-22.4,10.8-38.5-9.3-53.9-22.2-.8,9.1-5.1,14.2-12.8,16.5-71.4,21.1-138,38-198.1,83.9-17.7,13.5-33.1,27.3-47.7,44.1-56.9,65.4-86.1,148.8-84,236.3-25.6-10.5-47.5-24.5-68.8-39.6-123.4-87.6-182.8-240.3-154.2-388.7,14.8-76.9,49.6-148.7,102.4-206.1,1.2,19.1,1.4,38.1.2,58.3,9.4-11.2,66.2-61.2,68.4-65.3l2.6-4.9c31.9-32.4,35.8-85.6,10.2-123.7-10.7-15.9-26.2-25.5-45.8-27.3,17.7-17,47.6-6.2,66,5.2,15.2,9.4,26.9,21.7,39.4,35.2,80.2-25.6,154.6-26.9,237.7-15,86,12.3,167.8,39.3,243.7,81.3,15.6,8.6,29.4,17.3,42.7,27.6h0ZM498.8,263.4l33.7-15.2c-7.5-7.9-15.7-13.2-19-22.2-4.5-12.6-8.6-24.2-17.8-34.1-14.4-15.6-36.8-22.2-56.8-13.9-22.4,9.3-35.7,30.3-36.5,54.3l-19.4,2c11.6,20.1,31.8,33.7,55.3,38.4,20.5,4.1,40.7-.4,60.5-9.3h0Z\"/><path fill=\"#696969\" d=\"M255.7,239.7l-2.6,4.9c-2.2,4.1-58.9,54.1-68.4,65.3,1.2-20.2,1-39.1-.2-58.3s-.3-26-2.7-40.1-2.4-34.2,4.4-49.3c5.7-12.7,19-17,31.2-11.5,16.2,7.4,23,25.5,18,42.4-4.1,13.7-.9,27.4,9.4,36.7l10.8,9.8h.1Z\"/><path fill=\"#fff\" d=\"M872.7,349.3c-.9,38-2.8,115.8-21.7,150.3-17.9-41.7-25.4-85.9-25.2-129.8,0-4.2.7-8.8,1.5-13.4s4.7-6.7,9.2-5.8l15,2.9c8,1.5,14.8-.2,21.1-4.1h.1Z\"/><path fill=\"#010101\" d=\"M498.8,263.4c-19.8,8.9-39.9,13.4-60.5,9.3-23.5-4.7-43.7-18.2-55.3-38.4l19.4-2c.8-24.1,14.1-45,36.5-54.3,20-8.3,42.4-1.7,56.8,13.9s13.3,21.5,17.8,34.1c3.2,9.1,11.5,14.4,19,22.2l-33.7,15.2h0Z\"/><g><path fill=\"#010101\" d=\"M856.4,577.4c-11.1,43.3-64.7,59.2-103.9,62.8-23,2.1-40.4-12.2-43-36.4-10.4,15-14,31.2-16.7,48.5-8.4,66,23.9,135.7,69.1,182.9-158.3,165.9-410,170.9-581.9,24.1-93-79.9-148.5-198.4-149.6-321.7-.9-108,37.8-220.1,109.7-301.7-15.9-66.6,10.6-186.5,89-199.4,40.5-6.7,80.4,15.6,109.2,41.9,88-23.8,185.5-19.6,274,0,85.6,19,180,54.1,252.8,103.1,36.6,24.6,49.7,62.4,48.6,105.6l-2.4,92.9c-.9,33.7-5.2,66-13.3,98.5-4.3,17.3-11,32.8-20.6,47.6-3.1,4.8-9.3,8.3-11.4,13.5l-9.7,37.8h.1ZM255.7,239.7l-10.8-9.8c-10.3-9.3-13.4-23.1-9.4-36.7,5-16.9-1.8-35-18-42.4-12.2-5.5-25.5-1.2-31.2,11.5-6.8,15.1-7.2,32.6-4.4,49.3s1.8,27,2.7,40.1c-52.8,57.4-87.6,129.3-102.4,206.1-28.7,148.4,30.8,301.1,154.2,388.7,21.3,15.1,43.2,29,68.8,39.6-2.1-87.5,27.1-170.9,84-236.3,14.6-16.8,30-30.6,47.7-44.1,60.1-45.9,126.7-62.9,198.1-83.9,7.6-2.3,12-7.4,12.8-16.5,15.5,13,31.5,33,53.9,22.2,22.9-11,41.3-27.6,57.7-47.4,27-32.8,43.8-71.2,53.6-111.9,2.8,4.5,8.6,3.6,12.9,1.5-.3,43.9,7.2,88,25.2,129.8,18.9-34.4,20.7-112.2,21.7-150.3s1-4.4.2-7.3c-14.4,2.5-30,.1-35.9-14.7-9.9-24.9,24.9-41.8,31-61.5,4.9-16-6.9-33.8-18.4-42.8-13.3-10.3-27.1-19-42.7-27.6-75.9-42-157.7-68.9-243.7-81.3-83.1-11.9-157.5-10.7-237.7,15-12.5-13.5-24.2-25.8-39.4-35.2-18.4-11.4-48.3-22.1-66-5.2,19.5,1.9,35.1,11.4,45.8,27.3,25.6,38.1,21.7,91.3-10.2,123.7h0ZM818.5,581.1c7.2-24.2,8.4-48.1,11.4-72.3l-19.2-53.8-16.7,137.6c7.3-.2,21.9-2.5,24.6-11.5h0ZM752.4,595.3c9.1.5,15.3.2,23.1-.5,7.7-39.3,15.1-78,18.4-119.6-12.2,15.1-22.1,29.9-34.8,43.2-3.9,4.1-5.2,8.3-5.1,14,.2,21.3-.4,41.8-1.5,62.8h-.1Z\"/><path fill=\"#fff\" d=\"M752.4,595.3c1.1-21,1.7-41.5,1.5-62.8,0-5.7,1.2-9.9,5.1-14,12.7-13.4,22.6-28.1,34.8-43.2-3.3,41.6-10.6,80.3-18.4,119.6-7.8.7-13.9,1-23.1.5h.1Z\"/><path fill=\"#fff\" d=\"M818.5,581.1c-2.7,9-17.3,11.3-24.6,11.5l16.7-137.6,19.2,53.8c-2.9,24.2-4.1,48.1-11.4,72.3h0Z\"/><g><path fill=\"#696969\" d=\"M849.6,223c11.5,8.9,23.3,26.7,18.4,42.8-6,19.7-40.8,36.6-31,61.5,5.9,14.8,21.5,17.2,35.9,14.7.8,2.9-.2,5.2-.2,7.3-6.3,3.9-13.1,5.6-21.1,4.1l-15-2.9c-4.5-.9-8.4,1.2-9.2,5.8-.8,4.6-1.4,9.2-1.5,13.4-4.4,2-10.1,2.9-12.9-1.5,1.2-5.2,2.9-10.6,2.1-16.4-37.7,4.5-67.9,34.2-99.8,1.7,0-1.1,1.6-1.2,2.9-.7,19.9,7.3,34.3,5,44.6-13.8,10.6-19.6,25.4-1.4,37.4-13.6,9.7-9.9-4.5-33.9-13-40.6-6.2-4.9-13.1-8.4-19.5-12.8-11.3-7.8-24.6-3.9-31.3,8.2s-5.7,9.8-11.6,7.7c-6.8-2.5-13.7-1.8-21.1-2.8-3.8-.5-7.1-3.9-10.6-1.1,2.7-7.9,3.2-15.9,9-23.9,15-20.7,36.3-33.2,62.1-37,28.8-4.2,57.1-2.5,85.5-.2h-.1Z\"/><path fill=\"#010101\" d=\"M715.2,353.5c-6.6-6.7-15.2-9.7-19.5-20.6-6.3-15.8-8.2-32.9-2.7-48.8,3.5-2.8,6.8.6,10.6,1.1,7.4.9,14.2.3,21.1,2.8,5.9,2.1,9.3-3.6,11.6-7.7,6.7-12.1,20-16,31.3-8.2,6.4,4.4,13.3,7.9,19.5,12.8,8.5,6.7,22.7,30.7,13,40.6-11.9,12.2-26.7-6-37.4,13.6-10.2,18.9-24.7,21.1-44.6,13.8s-3-.3-2.9.7h0Z\"/></g></g></svg>", ku = class {
|
|
8398
|
-
constructor(e) {
|
|
8399
|
-
this.shadowRoot = null, this.adminClient = null, this.modal = null, this.donated = !1, this.amountSelector = null, this.recurringOptions = null, this.submitBtn = null, this.errorEl = null, this.fiatRate = 1, this.themeObserver = null, this.themeMqCleanup = null, this.userConfig = e, this.config = su(e), this.strings = Yl(this.config.locale), this.state = {
|
|
8398
|
+
constructor(e, t) {
|
|
8399
|
+
this.shadowRoot = null, this.adminClient = null, this.modal = null, this.donated = !1, this.amountSelector = null, this.recurringOptions = null, this.submitBtn = null, this.errorEl = null, this.fiatRate = 1, this.themeObserver = null, this.themeMqCleanup = null, this.userConfig = e, this.onDestroy = t ?? null, this.config = su(e), this.strings = Yl(this.config.locale), this.state = {
|
|
8400
8400
|
selectedAmount: null,
|
|
8401
8401
|
customAmount: "",
|
|
8402
8402
|
recurring: {
|
|
@@ -8621,13 +8621,13 @@ var Ou = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"949.4\" height=\"100
|
|
|
8621
8621
|
this.config.debug && console.log(`[pybara-donate] ${e}`);
|
|
8622
8622
|
}
|
|
8623
8623
|
destroy() {
|
|
8624
|
-
this.themeObserver?.disconnect(), this.themeObserver = null, this.themeMqCleanup?.(), this.themeMqCleanup = null, this.shadowRoot?.host && this.shadowRoot.host.remove(), this.adminClient = null, this.shadowRoot = null, this.log("Widget destroyed");
|
|
8624
|
+
this.themeObserver?.disconnect(), this.themeObserver = null, this.themeMqCleanup?.(), this.themeMqCleanup = null, this.shadowRoot?.host && this.shadowRoot.host.remove(), this.adminClient = null, this.shadowRoot = null, this.onDestroy?.(), this.log("Widget destroyed");
|
|
8625
8625
|
}
|
|
8626
8626
|
}, Au = /* @__PURE__ */ new Map();
|
|
8627
8627
|
function ju(e) {
|
|
8628
8628
|
let t = typeof e.target == "string" ? e.target : e.target.id || `pybara-${Date.now()}`;
|
|
8629
8629
|
Au.has(t) && Au.get(t)?.destroy();
|
|
8630
|
-
let n = new ku(e);
|
|
8630
|
+
let n = new ku(e, () => Au.delete(t));
|
|
8631
8631
|
return Au.set(t, n), n.mount().catch((e) => {
|
|
8632
8632
|
console.error("[pybara-donate] Mount failed:", e);
|
|
8633
8633
|
}), n;
|
package/dist/widget.d.ts
CHANGED
|
@@ -17,7 +17,8 @@ export declare class DonationWidget {
|
|
|
17
17
|
private strings;
|
|
18
18
|
private themeObserver;
|
|
19
19
|
private themeMqCleanup;
|
|
20
|
-
|
|
20
|
+
private onDestroy;
|
|
21
|
+
constructor(userConfig: DonationWidgetConfig, onDestroy?: () => void);
|
|
21
22
|
/** Mount the widget into the target element */
|
|
22
23
|
mount(): Promise<void>;
|
|
23
24
|
/** Injects <link rel="preconnect"> for the wallet origin into the host page's own <head> — a one-time hint, safe even if this widget mounts more than once on the same page. */
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://docs.pybara.com/donate-widget/options.schema.json",
|
|
4
|
+
"title": "PybaraDonate.init() options",
|
|
5
|
+
"description": "Options for PybaraDonate.init() / new DonationWidget() in @pybara/donate-widget. The widget stays hidden until the site is verified in Pybara Wallet and its owner has accepted the widget terms.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"required": ["target", "recipientPrincipal", "siteUrl", "siteName"],
|
|
9
|
+
"properties": {
|
|
10
|
+
"target": {
|
|
11
|
+
"type": "string",
|
|
12
|
+
"description": "CSS selector of the mount point, e.g. '#pybara-donate'. (An HTMLElement is also accepted in JS but is not expressible in JSON.)"
|
|
13
|
+
},
|
|
14
|
+
"recipientPrincipal": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"description": "Recipient's principal ID — the wallet that receives donations."
|
|
17
|
+
},
|
|
18
|
+
"siteUrl": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"format": "uri",
|
|
21
|
+
"description": "Site origin, e.g. 'https://example.com'. Must match the site verified in Pybara Wallet; it is the registry key in the recipient registry."
|
|
22
|
+
},
|
|
23
|
+
"siteName": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"description": "Display name for the site, e.g. 'Example Charity'."
|
|
26
|
+
},
|
|
27
|
+
"presetAmounts": {
|
|
28
|
+
"type": "array",
|
|
29
|
+
"items": { "type": "number", "minimum": 0.5 },
|
|
30
|
+
"maxItems": 6,
|
|
31
|
+
"default": [5, 10, 25, 50],
|
|
32
|
+
"description": "Preset donation amounts in the display currency."
|
|
33
|
+
},
|
|
34
|
+
"allowCustom": {
|
|
35
|
+
"type": "boolean",
|
|
36
|
+
"default": true,
|
|
37
|
+
"description": "Allow a custom amount input."
|
|
38
|
+
},
|
|
39
|
+
"allowRecurring": {
|
|
40
|
+
"type": "boolean",
|
|
41
|
+
"default": true,
|
|
42
|
+
"description": "Show the recurring donation option."
|
|
43
|
+
},
|
|
44
|
+
"defaultFrequency": {
|
|
45
|
+
"enum": ["weekly", "monthly", "yearly", "every2min"],
|
|
46
|
+
"default": "monthly",
|
|
47
|
+
"description": "Preselected recurring frequency. 'every2min' is a test frequency."
|
|
48
|
+
},
|
|
49
|
+
"defaultDurationInMonths": {
|
|
50
|
+
"enum": [3, 6, 12, 24, null],
|
|
51
|
+
"default": 12,
|
|
52
|
+
"description": "Preselected recurring duration in months; null means no end date."
|
|
53
|
+
},
|
|
54
|
+
"tokens": {
|
|
55
|
+
"type": "array",
|
|
56
|
+
"items": { "type": "string" },
|
|
57
|
+
"default": ["ckUSDC", "ckUSDT", "ckBTC", "ckETH", "ICP"],
|
|
58
|
+
"description": "Token symbols offered to the donor."
|
|
59
|
+
},
|
|
60
|
+
"title": {
|
|
61
|
+
"type": "string",
|
|
62
|
+
"description": "Widget title, above the amount selector."
|
|
63
|
+
},
|
|
64
|
+
"description": {
|
|
65
|
+
"type": "string",
|
|
66
|
+
"description": "Text below the title."
|
|
67
|
+
},
|
|
68
|
+
"thankYouMessage": {
|
|
69
|
+
"type": "string",
|
|
70
|
+
"description": "Message shown after a successful donation."
|
|
71
|
+
},
|
|
72
|
+
"thankYouRedirectUrl": {
|
|
73
|
+
"type": "string",
|
|
74
|
+
"format": "uri",
|
|
75
|
+
"description": "URL the donor is sent to after a successful donation."
|
|
76
|
+
},
|
|
77
|
+
"buttonLabel": {
|
|
78
|
+
"type": "string",
|
|
79
|
+
"description": "Donate button label. Left out, it says Donate in the widget's language."
|
|
80
|
+
},
|
|
81
|
+
"primaryColor": {
|
|
82
|
+
"type": "string",
|
|
83
|
+
"pattern": "^#[0-9a-fA-F]{6}$",
|
|
84
|
+
"default": "#7c3aed",
|
|
85
|
+
"description": "Accent color (hex) for buttons, selected states and links. Match the site's accent."
|
|
86
|
+
},
|
|
87
|
+
"theme": {
|
|
88
|
+
"enum": ["light", "dark", "auto"],
|
|
89
|
+
"default": "light",
|
|
90
|
+
"description": "'auto' samples the surrounding page background at mount. Prefer it unless the site fixes its own scheme."
|
|
91
|
+
},
|
|
92
|
+
"currency": {
|
|
93
|
+
"type": "string",
|
|
94
|
+
"pattern": "^[A-Za-z]{3}$",
|
|
95
|
+
"default": "USD",
|
|
96
|
+
"description": "Display currency (ISO 4217). Amounts are shown in it and converted to USD for payment."
|
|
97
|
+
},
|
|
98
|
+
"locale": {
|
|
99
|
+
"type": "string",
|
|
100
|
+
"description": "Locale override (e.g. 'fr'); auto-detected by default."
|
|
101
|
+
},
|
|
102
|
+
"staging": {
|
|
103
|
+
"type": "boolean",
|
|
104
|
+
"default": false,
|
|
105
|
+
"description": "Use the staging environment. Never set on a live site."
|
|
106
|
+
},
|
|
107
|
+
"debug": {
|
|
108
|
+
"type": "boolean",
|
|
109
|
+
"default": false,
|
|
110
|
+
"description": "Enable debug logging."
|
|
111
|
+
},
|
|
112
|
+
"fontUrl": {
|
|
113
|
+
"type": "string",
|
|
114
|
+
"description": "Absolute or relative URL of a self-hosted woff2 file. When omitted, no font is loaded."
|
|
115
|
+
},
|
|
116
|
+
"siteCountry": {
|
|
117
|
+
"type": "string",
|
|
118
|
+
"pattern": "^[A-Za-z]{2}$",
|
|
119
|
+
"description": "Site base country (ISO 3166-1 alpha-2)."
|
|
120
|
+
},
|
|
121
|
+
"donorIsAnonymous": {
|
|
122
|
+
"type": "boolean",
|
|
123
|
+
"description": "Hide donor name/details from recipient-facing displays."
|
|
124
|
+
},
|
|
125
|
+
"donorMessage": { "type": "string", "description": "Free-text message from donor to recipient." },
|
|
126
|
+
"donorFirstName": { "type": "string" },
|
|
127
|
+
"donorLastName": { "type": "string" },
|
|
128
|
+
"donorEmail": {
|
|
129
|
+
"type": "string",
|
|
130
|
+
"format": "email",
|
|
131
|
+
"description": "Donor's email, stored for the receipt feature; never publicly displayed."
|
|
132
|
+
},
|
|
133
|
+
"donorCompany": { "type": "string" },
|
|
134
|
+
"donorCountry": { "type": "string" },
|
|
135
|
+
"donorAddressLine1": { "type": "string", "description": "Donor mailing address — all address fields are required together when provided." },
|
|
136
|
+
"donorAddressLine2": { "type": "string" },
|
|
137
|
+
"donorAddressCity": { "type": "string" },
|
|
138
|
+
"donorAddressState": { "type": "string" },
|
|
139
|
+
"donorAddressPostalCode": { "type": "string" },
|
|
140
|
+
"donorAddressCountry": { "type": "string" },
|
|
141
|
+
"donorTosVersion": { "type": "string", "description": "TOS version the donor accepted, e.g. '1-0'." },
|
|
142
|
+
"donorTosAcceptedAt": { "type": "string", "format": "date-time", "description": "ISO 8601 UTC timestamp of donor TOS acceptance." },
|
|
143
|
+
"recipientTosVersion": { "type": "string", "description": "TOS version the site operator accepted." },
|
|
144
|
+
"recipientTosAcceptedAt": { "type": "string", "format": "date-time", "description": "ISO 8601 UTC timestamp of recipient TOS acceptance." },
|
|
145
|
+
"pluginVersion": { "type": "string", "description": "Plugin/integration version forwarding this donation, e.g. '1.2.0'." },
|
|
146
|
+
"onSuccess": { "description": "Function, not expressible in JSON — callback after a successful donation, called with the DonationResult." },
|
|
147
|
+
"onError": { "description": "Function, not expressible in JSON — callback on donation error, called with an Error." },
|
|
148
|
+
"onClose": { "description": "Function, not expressible in JSON — callback when the widget is closed or cancelled." }
|
|
149
|
+
}
|
|
150
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pybara/donate-widget",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
4
4
|
"description": "Embeddable donation widget for Internet Computer crypto payments",
|
|
5
5
|
"author": "Pybara",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"import": "./dist/pybara-donate.js"
|
|
15
15
|
},
|
|
16
16
|
"./dist/pybara-donate.iife.js": "./dist/pybara-donate.iife.js",
|
|
17
|
+
"./options.schema.json": "./options.schema.json",
|
|
17
18
|
"./package.json": "./package.json"
|
|
18
19
|
},
|
|
19
20
|
"jsdelivr": "dist/pybara-donate.iife.js",
|
|
@@ -21,7 +22,8 @@
|
|
|
21
22
|
"files": [
|
|
22
23
|
"dist/pybara-donate.iife.js",
|
|
23
24
|
"dist/pybara-donate.js",
|
|
24
|
-
"dist/**/*.d.ts"
|
|
25
|
+
"dist/**/*.d.ts",
|
|
26
|
+
"options.schema.json"
|
|
25
27
|
],
|
|
26
28
|
"scripts": {
|
|
27
29
|
"build": "vite build",
|
|
@@ -30,7 +32,7 @@
|
|
|
30
32
|
"translate": "node scripts/translate-locale.mjs",
|
|
31
33
|
"update:pybara": "npm install -D @pybara/pybara-sdk@github:pybara/pybara-sdk @pybara/pybara-ux@github:pybara/pybara-ux",
|
|
32
34
|
"prepublishOnly": "npm run type-check && npm run build",
|
|
33
|
-
"release:tag": "git tag donate@$npm_package_version && git push origin donate@$npm_package_version"
|
|
35
|
+
"release:tag": "git tag donate-widget@$npm_package_version && git push origin donate-widget@$npm_package_version"
|
|
34
36
|
},
|
|
35
37
|
"devDependencies": {
|
|
36
38
|
"@biomejs/biome": "2.5.15",
|
|
@@ -54,12 +56,7 @@
|
|
|
54
56
|
"embeddable",
|
|
55
57
|
"widget"
|
|
56
58
|
],
|
|
57
|
-
"homepage": "https://docs.pybara.com/widget/overview/",
|
|
58
|
-
"repository": {
|
|
59
|
-
"type": "git",
|
|
60
|
-
"url": "git+https://github.com/pybara/pybara-widget.git",
|
|
61
|
-
"directory": "packages/donate"
|
|
62
|
-
},
|
|
59
|
+
"homepage": "https://docs.pybara.com/donate-widget/overview/",
|
|
63
60
|
"publishConfig": {
|
|
64
61
|
"access": "public"
|
|
65
62
|
}
|