@paynext/sdk 0.0.101 → 0.0.102

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.umd.js CHANGED
@@ -52,7 +52,7 @@ React keys must be passed directly to JSX without using spread:
52
52
 
53
53
  💡 Note:
54
54
  If "Actual parallel execution time" ≈ "Longest button init" → buttons load in parallel ✅
55
- If "Actual parallel execution time" ≈ "Sum of durations" → buttons load sequentially ⚠️`,"color: #666;"),console.groupEnd()}init(){return W(this,null,function*(){this.config.state.transaction.subscribe(()=>{this.config.service.ev.isReady&&this.initPaymentMethods().catch(console.error)}),this.config.state.checkout.subscribe(()=>{this.config.service.ev.isReady&&this.initPaymentMethods().catch(console.error)}),this.config.service.ev.addEventListener("ready",()=>{this.initPaymentMethods().catch(console.error)})})}initApple(t){return W(this,null,function*(){const e=performance.now(),r="Apple Pay";if(!this.applePay){t==null||t.remove(),this.performanceMetrics.set(r,{start:e,end:performance.now(),duration:performance.now()-e,status:"Skipped (not configured)"});return}this.isAppleReady=!1;try{if(yield this.applePay.init({onError:i=>{this.events.error.emit(i),t==null||t.remove(),this.attempted.delete(Y.APPLE_PAY)},onCancel:()=>{this.events.cancel.emit(),this.attempted.delete(Y.APPLE_PAY)},onSuccess:i=>{this.events.success.emit(J(H({},i),{type:"apple"})),this.attempted.delete(Y.APPLE_PAY)}})){const i=this.applePay.render();t==null||t.appendChild(i);const s=()=>{this.attempted.has(Y.APPLE_PAY)||(this.attempted.add(Y.APPLE_PAY),this.events.onPaymentAttempt.emit(Y.APPLE_PAY))};i.addEventListener("pointerdown",s,{capture:!0}),i.addEventListener("click",s,{capture:!0}),i.addEventListener("keydown",c=>{((c==null?void 0:c.key)==="Enter"||(c==null?void 0:c.key)===" ")&&s()},{capture:!0}),i.addEventListener("focusin",s,{capture:!0}),t==null||t.addEventListener("pointerdown",s,{capture:!0}),t==null||t.addEventListener("click",s,{capture:!0}),t==null||t.addEventListener("focusin",s,{capture:!0});const o=performance.now();this.performanceMetrics.set(r,{start:e,end:o,duration:o-e,status:"✓ Rendered"})}else{t==null||t.remove();const i=performance.now();this.performanceMetrics.set(r,{start:e,end:i,duration:i-e,status:"✗ Not supported"})}}catch(a){console.error(a),t==null||t.remove();const i=performance.now();this.performanceMetrics.set(r,{start:e,end:i,duration:i-e,status:"✗ Error"})}finally{this.isAppleReady=!0}})}initGoogle(t){return W(this,null,function*(){const e=performance.now(),r="Google Pay";if(!this.googlePay){t==null||t.remove(),this.performanceMetrics.set(r,{start:e,end:performance.now(),duration:performance.now()-e,status:"Skipped (not configured)"});return}this.isGoogleReady=!1;try{if(yield this.googlePay.init({onError:i=>{this.events.error.emit(i),t==null||t.remove(),this.attempted.delete(Y.GOOGLE_PAY)},onCancel:()=>{this.events.cancel.emit(),this.attempted.delete(Y.GOOGLE_PAY)},onSuccess:i=>{this.events.success.emit(J(H({},i),{type:"google"})),this.attempted.delete(Y.GOOGLE_PAY)}})){const i=this.googlePay.render();t==null||t.appendChild(i);const s=()=>{this.attempted.has(Y.GOOGLE_PAY)||(this.attempted.add(Y.GOOGLE_PAY),this.events.onPaymentAttempt.emit(Y.GOOGLE_PAY))};i.addEventListener("pointerdown",s,{capture:!0}),i.addEventListener("click",s,{capture:!0}),i.addEventListener("keydown",c=>{((c==null?void 0:c.key)==="Enter"||(c==null?void 0:c.key)===" ")&&s()},{capture:!0}),i.addEventListener("focusin",s,{capture:!0}),t==null||t.addEventListener("pointerdown",s,{capture:!0}),t==null||t.addEventListener("click",s,{capture:!0}),t==null||t.addEventListener("focusin",s,{capture:!0});const o=performance.now();this.performanceMetrics.set(r,{start:e,end:o,duration:o-e,status:"✓ Rendered"})}else{t==null||t.remove();const i=performance.now();this.performanceMetrics.set(r,{start:e,end:i,duration:i-e,status:"✗ Not supported"})}}catch(a){console.error(a),t==null||t.remove();const i=performance.now();this.performanceMetrics.set(r,{start:e,end:i,duration:i-e,status:"✗ Error"})}finally{this.isGoogleReady=!0}})}initPayPal(t){return W(this,null,function*(){const e=performance.now(),r="PayPal";if(!this.paypal){t==null||t.remove(),this.performanceMetrics.set(r,{start:e,end:performance.now(),duration:performance.now()-e,status:"Skipped (not configured)"});return}this.isPayPalReady=!1;try{const a=this.paypal.render();if(t==null||t.appendChild(a),yield this.paypal.init({onError:s=>{this.events.error.emit(s),this.attempted.delete(Y.PAYPAL)},onCancel:()=>{this.events.cancel.emit(),this.attempted.delete(Y.PAYPAL)},onSuccess:s=>{this.events.success.emit({paypalId:s,type:"paypal"}),this.attempted.delete(Y.PAYPAL)}})){const s=performance.now();this.performanceMetrics.set(r,{start:e,end:s,duration:s-e,status:"✓ Rendered"})}else{t==null||t.remove();const s=performance.now();this.performanceMetrics.set(r,{start:e,end:s,duration:s-e,status:"✗ Not supported"})}}catch(a){t==null||t.remove();const i=performance.now();this.performanceMetrics.set(r,{start:e,end:i,duration:i-e,status:"✗ Error"})}finally{this.isPayPalReady=!0}})}initBraintreeVenmo(t){return W(this,null,function*(){const e=performance.now(),r="Venmo";if(!this.braintree){t==null||t.remove(),this.performanceMetrics.set(r,{start:e,end:performance.now(),duration:performance.now()-e,status:"Skipped (not configured)"});return}this.isBraintreeReady=!1;try{if(yield this.braintree.init({onError:i=>{this.events.error.emit(i),t==null||t.remove()},onCancel:()=>this.events.cancel.emit(),onSuccess:i=>{this.events.success.emit({nonce:i==null?void 0:i.nonce,type:"venmo"})}})){const i=this.braintree.render();t==null||t.appendChild(i);const s=performance.now();this.performanceMetrics.set(r,{start:e,end:s,duration:s-e,status:"✓ Rendered"})}else{t==null||t.remove();const i=performance.now();this.performanceMetrics.set(r,{start:e,end:i,duration:i-e,status:"✗ Not supported"})}}catch(a){console.error(a),t==null||t.remove();const i=performance.now();this.performanceMetrics.set(r,{start:e,end:i,duration:i-e,status:"✗ Error"})}finally{this.isBraintreeReady=!0}})}initCard(t){return W(this,null,function*(){const e=performance.now(),r="Card";if(!this.card){t==null||t.remove(),this.performanceMetrics.set(r,{start:e,end:performance.now(),duration:performance.now()-e,status:"Skipped (not configured)"});return}t==null||t.appendChild(this.card.render());const a=performance.now();this.performanceMetrics.set(r,{start:e,end:a,duration:a-e,status:"✓ Rendered"})})}waitForElementVisible(t,e=150){return!t||!(t instanceof HTMLElement)?Promise.resolve():new Promise(r=>{const a=performance.now(),i=()=>{const s=t.getBoundingClientRect();if(s.width>0&&s.height>0||performance.now()-a>=e)return r();requestAnimationFrame(i)};requestAnimationFrame(i)})}initPaymentMethods(){return W(this,null,function*(){const t=this.config.state.transaction.getState(),e=Bc(Mc,(t==null?void 0:t.checkout_config)||[],(h,p)=>h.type===p.type),r=this.config.state.checkout.getState();let a=e.filter(({is_active:h})=>h);(r==null?void 0:r.variant)==="default"&&(a=a.filter(({type:h})=>h!==Y.CARD)),this.initializeButtonInstances(a),this.buttons.innerHTML="";const i=a.sort((h,p)=>h.order-p.order),s=new Map;for(const{type:h}of i){const p=document.createElement("div");this.buttons.appendChild(p),s.set(h,p)}const o=performance.now(),c=i.map(({type:h})=>{const p=s.get(h);switch(h){case Y.APPLE_PAY:return this.initApple(p);case Y.GOOGLE_PAY:return this.initGoogle(p);case Y.PAYPAL:return this.initPayPal(p);case Y.VENMO:return this.initBraintreeVenmo(p);case Y.CARD:return this.initCard(p);default:throw new Error("Unknown button type")}});yield Promise.all(c);const l=performance.now(),d=l-o;this.performanceMetrics.set("__parallel_total__",{start:o,end:l,duration:d,status:"Parallel execution"});const u=[];for(const h of s.values()){const p=h.firstElementChild;p&&u.push(this.waitForElementVisible(p))}yield Promise.all(u),this.handleReady()})}initializeButtonInstances(t){const e=t.map(({type:r})=>r);e.includes(Y.APPLE_PAY)&&!this.applePay&&(this.applePay=new Sc(this.config)),e.includes(Y.GOOGLE_PAY)&&!this.googlePay&&(this.googlePay=new Dc(this.config)),e.includes(Y.PAYPAL)&&!this.paypal&&(this.paypal=new Vc(this.config),this.paypal.addEventListener("onPaymentAttempt",r=>this.events.onPaymentAttempt.emit(r))),e.includes(Y.VENMO)&&!this.braintree&&(this.braintree=new Hc(this.config),this.braintree.addEventListener("onPaymentAttempt",r=>this.events.onPaymentAttempt.emit(r))),e.includes(Y.CARD)&&!this.card&&(this.card=new Uc(this.config),this.card.addEventListener(()=>{this.events.open.emit()}))}handleReady(){this.isAppleReady&&this.isGoogleReady&&this.isPayPalReady&&this.isBraintreeReady&&(this.logPerformanceMetrics(),this.events.ready.emit())}addEventListener(t,e){return this.events[t].addListener(e)}showButton(){this.buttons.classList.remove(yn.hidden)}render(){return this.buttons}}class Wc{constructor(t){C(this,"template",`
55
+ If "Actual parallel execution time" ≈ "Sum of durations" → buttons load sequentially ⚠️`,"color: #666;"),console.groupEnd()}init(){return W(this,null,function*(){this.config.state.transaction.subscribe(()=>{this.config.service.ev.isReady&&this.initPaymentMethods().catch(console.error)}),this.config.state.checkout.subscribe(()=>{this.config.service.ev.isReady&&this.initPaymentMethods().catch(console.error)}),this.config.service.ev.addEventListener("ready",()=>{this.initPaymentMethods().catch(console.error)})})}initApple(t){return W(this,null,function*(){const e=performance.now(),r="Apple Pay";if(!this.applePay){t==null||t.remove(),this.performanceMetrics.set(r,{start:e,end:performance.now(),duration:performance.now()-e,status:"Skipped (not configured)"});return}this.isAppleReady=!1;try{if(yield this.applePay.init({onError:i=>{this.events.error.emit(i),console.log("Apple Pay error:",i),this.attempted.delete(Y.APPLE_PAY)},onCancel:()=>{this.events.cancel.emit(),this.attempted.delete(Y.APPLE_PAY)},onSuccess:i=>{this.events.success.emit(J(H({},i),{type:"apple"})),this.attempted.delete(Y.APPLE_PAY)}})){const i=this.applePay.render();t==null||t.appendChild(i);const s=()=>{this.attempted.has(Y.APPLE_PAY)||(this.attempted.add(Y.APPLE_PAY),this.events.onPaymentAttempt.emit(Y.APPLE_PAY))};i.addEventListener("pointerdown",s,{capture:!0}),i.addEventListener("click",s,{capture:!0}),i.addEventListener("keydown",c=>{((c==null?void 0:c.key)==="Enter"||(c==null?void 0:c.key)===" ")&&s()},{capture:!0}),i.addEventListener("focusin",s,{capture:!0}),t==null||t.addEventListener("pointerdown",s,{capture:!0}),t==null||t.addEventListener("click",s,{capture:!0}),t==null||t.addEventListener("focusin",s,{capture:!0});const o=performance.now();this.performanceMetrics.set(r,{start:e,end:o,duration:o-e,status:"✓ Rendered"})}else{t==null||t.remove();const i=performance.now();this.performanceMetrics.set(r,{start:e,end:i,duration:i-e,status:"✗ Not supported"})}}catch(a){console.error(a),t==null||t.remove();const i=performance.now();this.performanceMetrics.set(r,{start:e,end:i,duration:i-e,status:"✗ Error"})}finally{this.isAppleReady=!0}})}initGoogle(t){return W(this,null,function*(){const e=performance.now(),r="Google Pay";if(!this.googlePay){t==null||t.remove(),this.performanceMetrics.set(r,{start:e,end:performance.now(),duration:performance.now()-e,status:"Skipped (not configured)"});return}this.isGoogleReady=!1;try{if(yield this.googlePay.init({onError:i=>{this.events.error.emit(i),t==null||t.remove(),this.attempted.delete(Y.GOOGLE_PAY)},onCancel:()=>{this.events.cancel.emit(),this.attempted.delete(Y.GOOGLE_PAY)},onSuccess:i=>{this.events.success.emit(J(H({},i),{type:"google"})),this.attempted.delete(Y.GOOGLE_PAY)}})){const i=this.googlePay.render();t==null||t.appendChild(i);const s=()=>{this.attempted.has(Y.GOOGLE_PAY)||(this.attempted.add(Y.GOOGLE_PAY),this.events.onPaymentAttempt.emit(Y.GOOGLE_PAY))};i.addEventListener("pointerdown",s,{capture:!0}),i.addEventListener("click",s,{capture:!0}),i.addEventListener("keydown",c=>{((c==null?void 0:c.key)==="Enter"||(c==null?void 0:c.key)===" ")&&s()},{capture:!0}),i.addEventListener("focusin",s,{capture:!0}),t==null||t.addEventListener("pointerdown",s,{capture:!0}),t==null||t.addEventListener("click",s,{capture:!0}),t==null||t.addEventListener("focusin",s,{capture:!0});const o=performance.now();this.performanceMetrics.set(r,{start:e,end:o,duration:o-e,status:"✓ Rendered"})}else{t==null||t.remove();const i=performance.now();this.performanceMetrics.set(r,{start:e,end:i,duration:i-e,status:"✗ Not supported"})}}catch(a){console.error(a),t==null||t.remove();const i=performance.now();this.performanceMetrics.set(r,{start:e,end:i,duration:i-e,status:"✗ Error"})}finally{this.isGoogleReady=!0}})}initPayPal(t){return W(this,null,function*(){const e=performance.now(),r="PayPal";if(!this.paypal){t==null||t.remove(),this.performanceMetrics.set(r,{start:e,end:performance.now(),duration:performance.now()-e,status:"Skipped (not configured)"});return}this.isPayPalReady=!1;try{const a=this.paypal.render();if(t==null||t.appendChild(a),yield this.paypal.init({onError:s=>{this.events.error.emit(s),this.attempted.delete(Y.PAYPAL)},onCancel:()=>{this.events.cancel.emit(),this.attempted.delete(Y.PAYPAL)},onSuccess:s=>{this.events.success.emit({paypalId:s,type:"paypal"}),this.attempted.delete(Y.PAYPAL)}})){const s=performance.now();this.performanceMetrics.set(r,{start:e,end:s,duration:s-e,status:"✓ Rendered"})}else{t==null||t.remove();const s=performance.now();this.performanceMetrics.set(r,{start:e,end:s,duration:s-e,status:"✗ Not supported"})}}catch(a){t==null||t.remove();const i=performance.now();this.performanceMetrics.set(r,{start:e,end:i,duration:i-e,status:"✗ Error"})}finally{this.isPayPalReady=!0}})}initBraintreeVenmo(t){return W(this,null,function*(){const e=performance.now(),r="Venmo";if(!this.braintree){t==null||t.remove(),this.performanceMetrics.set(r,{start:e,end:performance.now(),duration:performance.now()-e,status:"Skipped (not configured)"});return}this.isBraintreeReady=!1;try{if(yield this.braintree.init({onError:i=>{this.events.error.emit(i),t==null||t.remove()},onCancel:()=>this.events.cancel.emit(),onSuccess:i=>{this.events.success.emit({nonce:i==null?void 0:i.nonce,type:"venmo"})}})){const i=this.braintree.render();t==null||t.appendChild(i);const s=performance.now();this.performanceMetrics.set(r,{start:e,end:s,duration:s-e,status:"✓ Rendered"})}else{t==null||t.remove();const i=performance.now();this.performanceMetrics.set(r,{start:e,end:i,duration:i-e,status:"✗ Not supported"})}}catch(a){console.error(a),t==null||t.remove();const i=performance.now();this.performanceMetrics.set(r,{start:e,end:i,duration:i-e,status:"✗ Error"})}finally{this.isBraintreeReady=!0}})}initCard(t){return W(this,null,function*(){const e=performance.now(),r="Card";if(!this.card){t==null||t.remove(),this.performanceMetrics.set(r,{start:e,end:performance.now(),duration:performance.now()-e,status:"Skipped (not configured)"});return}t==null||t.appendChild(this.card.render());const a=performance.now();this.performanceMetrics.set(r,{start:e,end:a,duration:a-e,status:"✓ Rendered"})})}waitForElementVisible(t,e=150){return!t||!(t instanceof HTMLElement)?Promise.resolve():new Promise(r=>{const a=performance.now(),i=()=>{const s=t.getBoundingClientRect();if(s.width>0&&s.height>0||performance.now()-a>=e)return r();requestAnimationFrame(i)};requestAnimationFrame(i)})}initPaymentMethods(){return W(this,null,function*(){const t=this.config.state.transaction.getState(),e=Bc(Mc,(t==null?void 0:t.checkout_config)||[],(h,p)=>h.type===p.type),r=this.config.state.checkout.getState();let a=e.filter(({is_active:h})=>h);(r==null?void 0:r.variant)==="default"&&(a=a.filter(({type:h})=>h!==Y.CARD)),this.initializeButtonInstances(a),this.buttons.innerHTML="";const i=a.sort((h,p)=>h.order-p.order),s=new Map;for(const{type:h}of i){const p=document.createElement("div");this.buttons.appendChild(p),s.set(h,p)}const o=performance.now(),c=i.map(({type:h})=>{const p=s.get(h);switch(h){case Y.APPLE_PAY:return this.initApple(p);case Y.GOOGLE_PAY:return this.initGoogle(p);case Y.PAYPAL:return this.initPayPal(p);case Y.VENMO:return this.initBraintreeVenmo(p);case Y.CARD:return this.initCard(p);default:throw new Error("Unknown button type")}});yield Promise.all(c);const l=performance.now(),d=l-o;this.performanceMetrics.set("__parallel_total__",{start:o,end:l,duration:d,status:"Parallel execution"});const u=[];for(const h of s.values()){const p=h.firstElementChild;p&&u.push(this.waitForElementVisible(p))}yield Promise.all(u),this.handleReady()})}initializeButtonInstances(t){const e=t.map(({type:r})=>r);e.includes(Y.APPLE_PAY)&&!this.applePay&&(this.applePay=new Sc(this.config)),e.includes(Y.GOOGLE_PAY)&&!this.googlePay&&(this.googlePay=new Dc(this.config)),e.includes(Y.PAYPAL)&&!this.paypal&&(this.paypal=new Vc(this.config),this.paypal.addEventListener("onPaymentAttempt",r=>this.events.onPaymentAttempt.emit(r))),e.includes(Y.VENMO)&&!this.braintree&&(this.braintree=new Hc(this.config),this.braintree.addEventListener("onPaymentAttempt",r=>this.events.onPaymentAttempt.emit(r))),e.includes(Y.CARD)&&!this.card&&(this.card=new Uc(this.config),this.card.addEventListener(()=>{this.events.open.emit()}))}handleReady(){this.isAppleReady&&this.isGoogleReady&&this.isPayPalReady&&this.isBraintreeReady&&(this.logPerformanceMetrics(),this.events.ready.emit())}addEventListener(t,e){return this.events[t].addListener(e)}showButton(){this.buttons.classList.remove(yn.hidden)}render(){return this.buttons}}class Wc{constructor(t){C(this,"template",`
56
56
  <svg
57
57
  xmlns='http://www.w3.org/2000/svg'
58
58
  width='24'