@paynext/sdk 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.es.js CHANGED
@@ -31,7 +31,7 @@ async function P(r, e = 1) {
31
31
  }
32
32
  const E = setTimeout(() => {
33
33
  l(), w(new n("SDK script loading timeout", !0));
34
- }, 1e4), s = document.createElement("script");
34
+ }, 12e3), s = document.createElement("script");
35
35
  s.src = o, s.crossOrigin = "anonymous", s.async = !0, s.setAttribute("data-paynext-sdk", "true");
36
36
  const l = () => {
37
37
  clearTimeout(E), s.onload = null, s.onerror = null;
@@ -58,8 +58,8 @@ async function P(r, e = 1) {
58
58
  throw new n("PayNextSDK not found in window after load", !0);
59
59
  return u;
60
60
  } catch (i) {
61
- if ((i instanceof n ? i.retryable : !0) && e < 3)
62
- return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1000ms...`, i), await K(1e3 * e), P(r, e + 1);
61
+ if ((i instanceof n ? i.retryable : !0) && e < 5)
62
+ return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`, i), await K(1500 * e), P(r, e + 1);
63
63
  throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`, i), i;
64
64
  }
65
65
  }
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(o,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(o=typeof globalThis<"u"?globalThis:o||self,i(o["PayNext SDK"]={}))})(this,(function(o){"use strict";var T=Object.defineProperty;var g=(o,i,d)=>i in o?T(o,i,{enumerable:!0,configurable:!0,writable:!0,value:d}):o[i]=d;var h=(o,i,d)=>g(o,typeof i!="symbol"?i+"":i,d);const i="https://cdn-sdk-dev.paynext.com/index.cdn.js",d="https://cdn-sdk.paynext.com/index.cdn.js";let l=null,u=null;class r extends Error{constructor(e,t=!0){super(e),this.retryable=t,this.name="SDKLoadError"}}const D="PayNextSDK";function y(){return typeof window>"u"?null:window[D]}function A(n){typeof window>"u"||(window[D]=n)}function K(n){return new Promise(e=>setTimeout(e,n))}async function S(n,e=1){const s=(n?.toLowerCase()?.includes("develop")||n?.toLowerCase()?.includes("staging")?"develop":"production")==="develop"?i:d;try{const a=y();if(a)return a;await new Promise((m,P)=>{if(document.querySelector(`script[src="${s}"]`)){m();return}const R=setTimeout(()=>{f(),P(new r("SDK script loading timeout",!0))},1e4),c=document.createElement("script");c.src=s,c.crossOrigin="anonymous",c.async=!0,c.setAttribute("data-paynext-sdk","true");const f=()=>{clearTimeout(R),c.onload=null,c.onerror=null};c.onload=()=>{f(),m()},c.onerror=x=>{console.error("[PayNext CDN] Script load error:",x),f();try{c.parentNode&&c.parentNode.removeChild(c)}catch(_){console.warn("[PayNext CDN] Failed to remove script:",_)}P(new r("Failed to load SDK script from CDN",!0))};try{document.head.appendChild(c)}catch{f(),P(new r("Failed to append script to document",!1))}});const w=y();if(!w)throw new r("PayNextSDK not found in window after load",!0);return w}catch(a){if((a instanceof r?a.retryable:!0)&&e<3)return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1000ms...`,a),await K(1e3*e),S(n,e+1);throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`,a),a}}async function E(n){if(u)return u;if(l)return l;if(typeof window>"u")throw new r("PayNext SDK can only be loaded in browser environment",!1);const e=y();return e?(u=e,u):(l=(async()=>{try{const t=await S(n);return u=t,A(t),t}catch(t){throw l=null,t}})(),l)}class p{constructor(){h(this,"cdnInstance",null);h(this,"initPromise",null);h(this,"isDestroyed",!1);h(this,"errorBoundary",null)}setErrorHandler(e){this.errorBoundary=e}handleError(e,t){const s=`[PayNext SDK Error - ${t}]: ${e.message}`;if(console.error(s,e),this.errorBoundary)try{this.errorBoundary(e)}catch(a){console.error("[PayNext SDK] Error in custom error handler:",a)}}async initialize(e){if(this.isDestroyed)throw new r("Cannot initialize destroyed SDK instance",!1);return this.initPromise?this.initPromise:(this.initPromise=(async()=>{try{const t=await E(e);if(!t||!t.PayNextCheckout)throw new r("PayNextCheckout not found in loaded SDK module",!1);try{this.cdnInstance=new t.PayNextCheckout}catch(s){throw new r(`Failed to instantiate PayNextCheckout: ${s instanceof Error?s.message:"Unknown error"}`,!1)}}catch(t){throw this.initPromise=null,t}})(),this.initPromise)}assertReady(){if(this.isDestroyed)throw new r("SDK instance has been destroyed",!1);if(!this.initPromise)throw new r("SDK initialization not started",!1);if(!this.cdnInstance)throw new r("SDK instance not created",!1)}async mount(e,t){try{if(!e||typeof e!="string")throw new r("Invalid containerId provided",!1);if(!t||!t.environment)throw new r("Invalid config provided",!1);if(!document.getElementById(e))throw new r(`Container element with id "${e}" not found`,!1);await this.initialize(t.environment),this.assertReady(),await this.cdnInstance.mount(e,t)}catch(s){const a=s instanceof r?s:new r(s instanceof Error?s.message:"Unknown mount error",!0);throw this.handleError(a,"mount"),a}}async unmount(){try{if(this.isDestroyed){console.warn("[PayNext SDK] Instance already destroyed");return}if(!this.cdnInstance){console.warn("[PayNext SDK] No instance to unmount");return}try{typeof this.cdnInstance.unmount=="function"&&await this.cdnInstance.unmount()}catch(e){const t=e instanceof Error?e:new Error(String(e));this.handleError(t,"unmount")}this.cdnInstance=null,this.initPromise=null}catch(e){const t=e instanceof Error?e:new Error(String(e));this.handleError(t,"unmount")}}static async preload(e){try{await E(e)}catch(t){throw console.error("[PayNext SDK] Preload failed:",t),t}}}const C={preload:p.preload};var N=(n=>(n.PAYPAL="PAYPAL",n.APPLE_PAY="APPLEPAY",n.GOOGLE_PAY="GPAY",n.CARD="CARD",n.VENMO="VENMO",n.CASHAPP="CASHAPP",n))(N||{});o.PayNextCheckout=p,o.PayNextSDK=C,o.PaymentMethod=N,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(o,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(o=typeof globalThis<"u"?globalThis:o||self,i(o["PayNext SDK"]={}))})(this,(function(o){"use strict";var T=Object.defineProperty;var g=(o,i,d)=>i in o?T(o,i,{enumerable:!0,configurable:!0,writable:!0,value:d}):o[i]=d;var h=(o,i,d)=>g(o,typeof i!="symbol"?i+"":i,d);const i="https://cdn-sdk-dev.paynext.com/index.cdn.js",d="https://cdn-sdk.paynext.com/index.cdn.js";let l=null,u=null;class r extends Error{constructor(e,t=!0){super(e),this.retryable=t,this.name="SDKLoadError"}}const D="PayNextSDK";function y(){return typeof window>"u"?null:window[D]}function A(n){typeof window>"u"||(window[D]=n)}function K(n){return new Promise(e=>setTimeout(e,n))}async function S(n,e=1){const s=(n?.toLowerCase()?.includes("develop")||n?.toLowerCase()?.includes("staging")?"develop":"production")==="develop"?i:d;try{const a=y();if(a)return a;await new Promise((m,P)=>{if(document.querySelector(`script[src="${s}"]`)){m();return}const R=setTimeout(()=>{f(),P(new r("SDK script loading timeout",!0))},12e3),c=document.createElement("script");c.src=s,c.crossOrigin="anonymous",c.async=!0,c.setAttribute("data-paynext-sdk","true");const f=()=>{clearTimeout(R),c.onload=null,c.onerror=null};c.onload=()=>{f(),m()},c.onerror=x=>{console.error("[PayNext CDN] Script load error:",x),f();try{c.parentNode&&c.parentNode.removeChild(c)}catch(_){console.warn("[PayNext CDN] Failed to remove script:",_)}P(new r("Failed to load SDK script from CDN",!0))};try{document.head.appendChild(c)}catch{f(),P(new r("Failed to append script to document",!1))}});const w=y();if(!w)throw new r("PayNextSDK not found in window after load",!0);return w}catch(a){if((a instanceof r?a.retryable:!0)&&e<5)return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`,a),await K(1500*e),S(n,e+1);throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`,a),a}}async function E(n){if(u)return u;if(l)return l;if(typeof window>"u")throw new r("PayNext SDK can only be loaded in browser environment",!1);const e=y();return e?(u=e,u):(l=(async()=>{try{const t=await S(n);return u=t,A(t),t}catch(t){throw l=null,t}})(),l)}class p{constructor(){h(this,"cdnInstance",null);h(this,"initPromise",null);h(this,"isDestroyed",!1);h(this,"errorBoundary",null)}setErrorHandler(e){this.errorBoundary=e}handleError(e,t){const s=`[PayNext SDK Error - ${t}]: ${e.message}`;if(console.error(s,e),this.errorBoundary)try{this.errorBoundary(e)}catch(a){console.error("[PayNext SDK] Error in custom error handler:",a)}}async initialize(e){if(this.isDestroyed)throw new r("Cannot initialize destroyed SDK instance",!1);return this.initPromise?this.initPromise:(this.initPromise=(async()=>{try{const t=await E(e);if(!t||!t.PayNextCheckout)throw new r("PayNextCheckout not found in loaded SDK module",!1);try{this.cdnInstance=new t.PayNextCheckout}catch(s){throw new r(`Failed to instantiate PayNextCheckout: ${s instanceof Error?s.message:"Unknown error"}`,!1)}}catch(t){throw this.initPromise=null,t}})(),this.initPromise)}assertReady(){if(this.isDestroyed)throw new r("SDK instance has been destroyed",!1);if(!this.initPromise)throw new r("SDK initialization not started",!1);if(!this.cdnInstance)throw new r("SDK instance not created",!1)}async mount(e,t){try{if(!e||typeof e!="string")throw new r("Invalid containerId provided",!1);if(!t||!t.environment)throw new r("Invalid config provided",!1);if(!document.getElementById(e))throw new r(`Container element with id "${e}" not found`,!1);await this.initialize(t.environment),this.assertReady(),await this.cdnInstance.mount(e,t)}catch(s){const a=s instanceof r?s:new r(s instanceof Error?s.message:"Unknown mount error",!0);throw this.handleError(a,"mount"),a}}async unmount(){try{if(this.isDestroyed){console.warn("[PayNext SDK] Instance already destroyed");return}if(!this.cdnInstance){console.warn("[PayNext SDK] No instance to unmount");return}try{typeof this.cdnInstance.unmount=="function"&&await this.cdnInstance.unmount()}catch(e){const t=e instanceof Error?e:new Error(String(e));this.handleError(t,"unmount")}this.cdnInstance=null,this.initPromise=null}catch(e){const t=e instanceof Error?e:new Error(String(e));this.handleError(t,"unmount")}}static async preload(e){try{await E(e)}catch(t){throw console.error("[PayNext SDK] Preload failed:",t),t}}}const C={preload:p.preload};var N=(n=>(n.PAYPAL="PAYPAL",n.APPLE_PAY="APPLEPAY",n.GOOGLE_PAY="GPAY",n.CARD="CARD",n.VENMO="VENMO",n.CASHAPP="CASHAPP",n))(N||{});o.PayNextCheckout=p,o.PayNextSDK=C,o.PaymentMethod=N,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paynext/sdk",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "PayNext SDK - Payment processing with automatic CDN loading",
5
5
  "type": "module",
6
6
  "main": "dist/index.es.js",