@paynext/sdk 1.0.20 → 1.0.21

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
@@ -1,9 +1,9 @@
1
- var N = Object.defineProperty;
2
- var C = (n, e, t) => e in n ? N(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
1
+ var x = Object.defineProperty;
2
+ var C = (n, e, t) => e in n ? x(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
3
  var d = (n, e, t) => C(n, typeof e != "symbol" ? e + "" : e, t);
4
- const x = "https://cdn-sdk-dev.paynext.com/index.cdn.js", k = "https://cdn-sdk.paynext.com/index.cdn.js";
5
- let w = null, h = null;
6
- function T() {
4
+ const T = "https://cdn-sdk-dev.paynext.com/index.cdn.js", k = "https://cdn-sdk.paynext.com/index.cdn.js";
5
+ let y = null, w = null;
6
+ function g() {
7
7
  const n = navigator.connection || navigator.mozConnection || navigator.webkitConnection, e = {
8
8
  online: navigator.onLine,
9
9
  documentHidden: document.hidden,
@@ -12,107 +12,107 @@ function T() {
12
12
  };
13
13
  return n && (e.connectionType = n.type, e.effectiveType = n.effectiveType, e.downlink = n.downlink, e.rtt = n.rtt, e.saveData = n.saveData), navigator.onLine ? document.hidden ? e.likelyCause = "background_tab" : n?.effectiveType === "slow-2g" || n?.effectiveType === "2g" ? e.likelyCause = "slow_connection" : n?.downlink !== void 0 && n.downlink < 0.5 && (e.likelyCause = "poor_bandwidth") : e.likelyCause = "offline", e;
14
14
  }
15
- function g(n) {
15
+ function K(n) {
16
16
  const e = [];
17
17
  return n.likelyCause && e.push(`cause=${n.likelyCause}`), e.push(`online=${n.online}`), e.push(`hidden=${n.documentHidden}`), n.effectiveType && e.push(`net=${n.effectiveType}`), n.downlink !== void 0 && e.push(`downlink=${n.downlink}Mbps`), n.rtt !== void 0 && e.push(`rtt=${n.rtt}ms`), e.join(", ");
18
18
  }
19
- class o extends Error {
20
- constructor(t, r = !0, i = !1) {
21
- const u = i && typeof window < "u" ? T() : null, c = u ? `${t} [${g(u)}]` : t;
22
- super(c);
19
+ class r extends Error {
20
+ constructor(t, o = !0, i = !1) {
21
+ const s = i && typeof window < "u" ? g() : null, D = s ? `${t} [${K(s)}]` : t;
22
+ super(D);
23
23
  d(this, "diagnostics");
24
- this.retryable = r, this.name = "SDKLoadError", this.diagnostics = u;
24
+ this.retryable = o, this.name = "SDKLoadError", this.diagnostics = s;
25
25
  }
26
26
  }
27
- const P = "PayNextSDK";
27
+ const v = "PayNextSDK";
28
28
  function p() {
29
- return typeof window > "u" ? null : window[P];
29
+ return typeof window > "u" ? null : window[v];
30
30
  }
31
- function K(n) {
32
- typeof window > "u" || (window[P] = n);
31
+ function L(n) {
32
+ typeof window > "u" || (window[v] = n);
33
33
  }
34
34
  function S(n) {
35
35
  return new Promise((e) => setTimeout(e, n));
36
36
  }
37
- async function L(n = 5e3) {
37
+ async function _(n = 5e3) {
38
38
  const t = Math.ceil(n / 50);
39
- for (let r = 0; r < t; r++) {
39
+ for (let o = 0; o < t; o++) {
40
40
  const i = p();
41
41
  if (i)
42
42
  return i;
43
43
  await S(50);
44
44
  }
45
- throw new o("PayNextSDK not found in window after waiting", !0, !0);
45
+ throw new r("PayNextSDK not found in window after waiting", !0, !0);
46
46
  }
47
- async function v(n, e = 1) {
48
- const r = (n?.toLowerCase()?.includes("develop") || n?.toLowerCase()?.includes("staging") ? "develop" : "production") === "develop" ? x : k;
47
+ async function A(n, e = 1) {
48
+ const t = n?.toLowerCase(), i = (t?.includes("develop") || t?.includes("staging") || t?.includes("preview") ? "develop" : "production") === "develop" ? T : k;
49
49
  try {
50
- const i = p();
51
- return i || (await new Promise((c, f) => {
52
- const a = document.querySelector(`script[src="${r}"]`);
53
- if (a) {
50
+ const s = p();
51
+ return s || (await new Promise((h, u) => {
52
+ const c = document.querySelector(`script[src="${i}"]`);
53
+ if (c) {
54
54
  if (p()) {
55
- c();
55
+ h();
56
56
  return;
57
57
  }
58
- const y = setTimeout(() => {
59
- a.removeEventListener("load", l), a.removeEventListener("error", E), f(new o("Existing SDK script loading timeout", !0, !0));
58
+ const f = setTimeout(() => {
59
+ c.removeEventListener("load", l), c.removeEventListener("error", E), u(new r("Existing SDK script loading timeout", !0, !0));
60
60
  }, 15e3), l = () => {
61
- clearTimeout(y), a.removeEventListener("load", l), a.removeEventListener("error", E), c();
61
+ clearTimeout(f), c.removeEventListener("load", l), c.removeEventListener("error", E), h();
62
62
  }, E = () => {
63
- clearTimeout(y), a.removeEventListener("load", l), a.removeEventListener("error", E), f(new o("Existing SDK script failed to load", !0, !0));
63
+ clearTimeout(f), c.removeEventListener("load", l), c.removeEventListener("error", E), u(new r("Existing SDK script failed to load", !0, !0));
64
64
  };
65
- a.addEventListener("load", l), a.addEventListener("error", E);
65
+ c.addEventListener("load", l), c.addEventListener("error", E);
66
66
  return;
67
67
  }
68
- const A = setTimeout(() => {
69
- m(), f(new o("SDK script loading timeout", !0, !0));
70
- }, 15e3), s = document.createElement("script");
71
- s.src = r, s.crossOrigin = "anonymous", s.async = !0, s.setAttribute("data-paynext-sdk", "true");
68
+ const N = setTimeout(() => {
69
+ m(), u(new r("SDK script loading timeout", !0, !0));
70
+ }, 15e3), a = document.createElement("script");
71
+ a.src = i, a.crossOrigin = "anonymous", a.async = !0, a.setAttribute("data-paynext-sdk", "true");
72
72
  const m = () => {
73
- clearTimeout(A), s.onload = null, s.onerror = null;
73
+ clearTimeout(N), a.onload = null, a.onerror = null;
74
74
  };
75
- s.onload = () => {
76
- m(), c();
77
- }, s.onerror = (y) => {
78
- console.error("[PayNext CDN] Script load error:", y), m();
75
+ a.onload = () => {
76
+ m(), h();
77
+ }, a.onerror = (f) => {
78
+ console.error("[PayNext CDN] Script load error:", f), m();
79
79
  try {
80
- s.parentNode && s.parentNode.removeChild(s);
80
+ a.parentNode && a.parentNode.removeChild(a);
81
81
  } catch (l) {
82
82
  console.warn("[PayNext CDN] Failed to remove script:", l);
83
83
  }
84
- f(new o("Failed to load SDK script from CDN", !0, !0));
84
+ u(new r("Failed to load SDK script from CDN", !0, !0));
85
85
  };
86
86
  try {
87
- document.head.appendChild(s);
87
+ document.head.appendChild(a);
88
88
  } catch {
89
- m(), f(new o("Failed to append script to document", !1));
89
+ m(), u(new r("Failed to append script to document", !1));
90
90
  }
91
- }), await L(5e3));
92
- } catch (i) {
93
- if ((i instanceof o ? i.retryable : !0) && e < 5)
94
- return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`, i), await S(1500 * e), v(n, e + 1);
95
- throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`, i), i;
91
+ }), await _(5e3));
92
+ } catch (s) {
93
+ if ((s instanceof r ? s.retryable : !0) && e < 5)
94
+ return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`, s), await S(1500 * e), A(n, e + 1);
95
+ throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`, s), s;
96
96
  }
97
97
  }
98
- async function D(n) {
99
- if (h)
100
- return h;
98
+ async function P(n) {
101
99
  if (w)
102
100
  return w;
101
+ if (y)
102
+ return y;
103
103
  if (typeof window > "u")
104
- throw new o("PayNext SDK can only be loaded in browser environment", !1);
104
+ throw new r("PayNext SDK can only be loaded in browser environment", !1);
105
105
  const e = p();
106
- return e ? (h = e, h) : (w = (async () => {
106
+ return e ? (w = e, w) : (y = (async () => {
107
107
  try {
108
- const t = await v(n);
109
- return h = t, K(t), t;
108
+ const t = await A(n);
109
+ return w = t, L(t), t;
110
110
  } catch (t) {
111
- throw w = null, t;
111
+ throw y = null, t;
112
112
  }
113
- })(), w);
113
+ })(), y);
114
114
  }
115
- class _ {
115
+ class I {
116
116
  constructor() {
117
117
  d(this, "cdnInstance", null);
118
118
  d(this, "initPromise", null);
@@ -125,8 +125,8 @@ class _ {
125
125
  }
126
126
  // handle error
127
127
  handleError(e, t) {
128
- const r = `[PayNext SDK Error - ${t}]: ${e.message}`;
129
- if (console.error(r, e), this.errorBoundary)
128
+ const o = `[PayNext SDK Error - ${t}]: ${e.message}`;
129
+ if (console.error(o, e), this.errorBoundary)
130
130
  try {
131
131
  this.errorBoundary(e);
132
132
  } catch (i) {
@@ -136,17 +136,17 @@ class _ {
136
136
  // initialize
137
137
  async initialize(e) {
138
138
  if (this.isDestroyed)
139
- throw new o("Cannot initialize destroyed SDK instance", !1);
139
+ throw new r("Cannot initialize destroyed SDK instance", !1);
140
140
  return this.initPromise ? this.initPromise : (this.initPromise = (async () => {
141
141
  try {
142
- const t = await D(e);
142
+ const t = await P(e);
143
143
  if (!t || !t.PayNextCheckout)
144
- throw new o("PayNextCheckout not found in loaded SDK module", !1);
144
+ throw new r("PayNextCheckout not found in loaded SDK module", !1);
145
145
  try {
146
146
  this.cdnInstance = new t.PayNextCheckout();
147
- } catch (r) {
148
- throw new o(
149
- `Failed to instantiate PayNextCheckout: ${r instanceof Error ? r.message : "Unknown error"}`,
147
+ } catch (o) {
148
+ throw new r(
149
+ `Failed to instantiate PayNextCheckout: ${o instanceof Error ? o.message : "Unknown error"}`,
150
150
  !1
151
151
  );
152
152
  }
@@ -158,25 +158,25 @@ class _ {
158
158
  // assert ready
159
159
  assertReady() {
160
160
  if (this.isDestroyed)
161
- throw new o("SDK instance has been destroyed", !1);
161
+ throw new r("SDK instance has been destroyed", !1);
162
162
  if (!this.initPromise)
163
- throw new o("SDK initialization not started", !1);
163
+ throw new r("SDK initialization not started", !1);
164
164
  if (!this.cdnInstance)
165
- throw new o("SDK instance not created", !1);
165
+ throw new r("SDK instance not created", !1);
166
166
  }
167
167
  // mount
168
168
  async mount(e, t) {
169
169
  try {
170
170
  if (!e || typeof e != "string")
171
- throw new o("Invalid containerId provided", !1);
171
+ throw new r("Invalid containerId provided", !1);
172
172
  if (!t || !t.environment)
173
- throw new o("Invalid config provided", !1);
173
+ throw new r("Invalid config provided", !1);
174
174
  if (!document.getElementById(e))
175
- throw new o(`Container element with id "${e}" not found`, !1);
175
+ throw new r(`Container element with id "${e}" not found`, !1);
176
176
  await this.initialize(t.environment), this.assertReady(), await this.cdnInstance.mount(e, t);
177
- } catch (r) {
178
- const i = r instanceof o ? r : new o(
179
- r instanceof Error ? r.message : "Unknown mount error",
177
+ } catch (o) {
178
+ const i = o instanceof r ? o : new r(
179
+ o instanceof Error ? o.message : "Unknown mount error",
180
180
  !0
181
181
  );
182
182
  throw this.handleError(i, "mount"), i;
@@ -195,8 +195,8 @@ class _ {
195
195
  }
196
196
  typeof this.cdnInstance.setPaymentsEnabled == "function" && this.cdnInstance.setPaymentsEnabled(e);
197
197
  } catch (t) {
198
- const r = t instanceof Error ? t : new Error(String(t));
199
- this.handleError(r, "setPaymentsEnabled");
198
+ const o = t instanceof Error ? t : new Error(String(t));
199
+ this.handleError(o, "setPaymentsEnabled");
200
200
  }
201
201
  }
202
202
  // unmount
@@ -225,18 +225,18 @@ class _ {
225
225
  // preload SDK
226
226
  static async preload(e) {
227
227
  try {
228
- await D(e);
228
+ await P(e);
229
229
  } catch (t) {
230
230
  throw console.error("[PayNext SDK] Preload failed:", t), t;
231
231
  }
232
232
  }
233
233
  }
234
- const R = {
235
- preload: _.preload
234
+ const b = {
235
+ preload: I.preload
236
236
  };
237
- var I = /* @__PURE__ */ ((n) => (n.PAYPAL = "PAYPAL", n.APPLE_PAY = "APPLEPAY", n.GOOGLE_PAY = "GPAY", n.CARD = "CARD", n.VENMO = "VENMO", n.CASHAPP = "CASHAPP", n.AMAZONPAY = "AMAZONPAY", n.PIX_AUTOMATICO = "PIX_AUTOMATICO", n))(I || {});
237
+ var M = /* @__PURE__ */ ((n) => (n.PAYPAL = "PAYPAL", n.APPLE_PAY = "APPLEPAY", n.GOOGLE_PAY = "GPAY", n.CARD = "CARD", n.VENMO = "VENMO", n.CASHAPP = "CASHAPP", n.AMAZONPAY = "AMAZONPAY", n.PIX_AUTOMATICO = "PIX_AUTOMATICO", n))(M || {});
238
238
  export {
239
- _ as PayNextCheckout,
240
- R as PayNextSDK,
241
- I as PaymentMethod
239
+ I as PayNextCheckout,
240
+ b as PayNextSDK,
241
+ M as PaymentMethod
242
242
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(s,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(s=typeof globalThis<"u"?globalThis:s||self,a(s["PayNext SDK"]={}))})(this,(function(s){"use strict";var M=Object.defineProperty;var b=(s,a,l)=>a in s?M(s,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):s[a]=l;var y=(s,a,l)=>b(s,typeof a!="symbol"?a+"":a,l);const a="https://cdn-sdk-dev.paynext.com/index.cdn.js",l="https://cdn-sdk.paynext.com/index.cdn.js";let h=null,w=null;function k(){const n=navigator.connection||navigator.mozConnection||navigator.webkitConnection,e={online:navigator.onLine,documentHidden:document.hidden,userAgent:navigator.userAgent,timestamp:new Date().toISOString()};return n&&(e.connectionType=n.type,e.effectiveType=n.effectiveType,e.downlink=n.downlink,e.rtt=n.rtt,e.saveData=n.saveData),navigator.onLine?document.hidden?e.likelyCause="background_tab":n?.effectiveType==="slow-2g"||n?.effectiveType==="2g"?e.likelyCause="slow_connection":n?.downlink!==void 0&&n.downlink<.5&&(e.likelyCause="poor_bandwidth"):e.likelyCause="offline",e}function g(n){const e=[];return n.likelyCause&&e.push(`cause=${n.likelyCause}`),e.push(`online=${n.online}`),e.push(`hidden=${n.documentHidden}`),n.effectiveType&&e.push(`net=${n.effectiveType}`),n.downlink!==void 0&&e.push(`downlink=${n.downlink}Mbps`),n.rtt!==void 0&&e.push(`rtt=${n.rtt}ms`),e.join(", ")}class o extends Error{constructor(t,r=!0,i=!1){const m=i&&typeof window<"u"?k():null,u=m?`${t} [${g(m)}]`:t;super(u);y(this,"diagnostics");this.retryable=r,this.name="SDKLoadError",this.diagnostics=m}}const v="PayNextSDK";function P(){return typeof window>"u"?null:window[v]}function K(n){typeof window>"u"||(window[v]=n)}function A(n){return new Promise(e=>setTimeout(e,n))}async function L(n=5e3){const t=Math.ceil(n/50);for(let r=0;r<t;r++){const i=P();if(i)return i;await A(50)}throw new o("PayNextSDK not found in window after waiting",!0,!0)}async function N(n,e=1){const r=(n?.toLowerCase()?.includes("develop")||n?.toLowerCase()?.includes("staging")?"develop":"production")==="develop"?a:l;try{const i=P();return i||(await new Promise((u,E)=>{const d=document.querySelector(`script[src="${r}"]`);if(d){if(P()){u();return}const p=setTimeout(()=>{d.removeEventListener("load",f),d.removeEventListener("error",S),E(new o("Existing SDK script loading timeout",!0,!0))},15e3),f=()=>{clearTimeout(p),d.removeEventListener("load",f),d.removeEventListener("error",S),u()},S=()=>{clearTimeout(p),d.removeEventListener("load",f),d.removeEventListener("error",S),E(new o("Existing SDK script failed to load",!0,!0))};d.addEventListener("load",f),d.addEventListener("error",S);return}const I=setTimeout(()=>{D(),E(new o("SDK script loading timeout",!0,!0))},15e3),c=document.createElement("script");c.src=r,c.crossOrigin="anonymous",c.async=!0,c.setAttribute("data-paynext-sdk","true");const D=()=>{clearTimeout(I),c.onload=null,c.onerror=null};c.onload=()=>{D(),u()},c.onerror=p=>{console.error("[PayNext CDN] Script load error:",p),D();try{c.parentNode&&c.parentNode.removeChild(c)}catch(f){console.warn("[PayNext CDN] Failed to remove script:",f)}E(new o("Failed to load SDK script from CDN",!0,!0))};try{document.head.appendChild(c)}catch{D(),E(new o("Failed to append script to document",!1))}}),await L(5e3))}catch(i){if((i instanceof o?i.retryable:!0)&&e<5)return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`,i),await A(1500*e),N(n,e+1);throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`,i),i}}async function x(n){if(w)return w;if(h)return h;if(typeof window>"u")throw new o("PayNext SDK can only be loaded in browser environment",!1);const e=P();return e?(w=e,w):(h=(async()=>{try{const t=await N(n);return w=t,K(t),t}catch(t){throw h=null,t}})(),h)}class C{constructor(){y(this,"cdnInstance",null);y(this,"initPromise",null);y(this,"isDestroyed",!1);y(this,"errorBoundary",null)}setErrorHandler(e){this.errorBoundary=e}handleError(e,t){const r=`[PayNext SDK Error - ${t}]: ${e.message}`;if(console.error(r,e),this.errorBoundary)try{this.errorBoundary(e)}catch(i){console.error("[PayNext SDK] Error in custom error handler:",i)}}async initialize(e){if(this.isDestroyed)throw new o("Cannot initialize destroyed SDK instance",!1);return this.initPromise?this.initPromise:(this.initPromise=(async()=>{try{const t=await x(e);if(!t||!t.PayNextCheckout)throw new o("PayNextCheckout not found in loaded SDK module",!1);try{this.cdnInstance=new t.PayNextCheckout}catch(r){throw new o(`Failed to instantiate PayNextCheckout: ${r instanceof Error?r.message:"Unknown error"}`,!1)}}catch(t){throw this.initPromise=null,t}})(),this.initPromise)}assertReady(){if(this.isDestroyed)throw new o("SDK instance has been destroyed",!1);if(!this.initPromise)throw new o("SDK initialization not started",!1);if(!this.cdnInstance)throw new o("SDK instance not created",!1)}async mount(e,t){try{if(!e||typeof e!="string")throw new o("Invalid containerId provided",!1);if(!t||!t.environment)throw new o("Invalid config provided",!1);if(!document.getElementById(e))throw new o(`Container element with id "${e}" not found`,!1);await this.initialize(t.environment),this.assertReady(),await this.cdnInstance.mount(e,t)}catch(r){const i=r instanceof o?r:new o(r instanceof Error?r.message:"Unknown mount error",!0);throw this.handleError(i,"mount"),i}}setPaymentsEnabled(e){try{if(this.isDestroyed){console.warn("[PayNext SDK] setPaymentsEnabled called on destroyed instance");return}if(!this.cdnInstance){console.warn("[PayNext SDK] setPaymentsEnabled called before mount");return}typeof this.cdnInstance.setPaymentsEnabled=="function"&&this.cdnInstance.setPaymentsEnabled(e)}catch(t){const r=t instanceof Error?t:new Error(String(t));this.handleError(r,"setPaymentsEnabled")}}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 x(e)}catch(t){throw console.error("[PayNext SDK] Preload failed:",t),t}}}const _={preload:C.preload};var T=(n=>(n.PAYPAL="PAYPAL",n.APPLE_PAY="APPLEPAY",n.GOOGLE_PAY="GPAY",n.CARD="CARD",n.VENMO="VENMO",n.CASHAPP="CASHAPP",n.AMAZONPAY="AMAZONPAY",n.PIX_AUTOMATICO="PIX_AUTOMATICO",n))(T||{});s.PayNextCheckout=C,s.PayNextSDK=_,s.PaymentMethod=T,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(i,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(i=typeof globalThis<"u"?globalThis:i||self,s(i["PayNext SDK"]={}))})(this,(function(i){"use strict";var b=Object.defineProperty;var R=(i,s,u)=>s in i?b(i,s,{enumerable:!0,configurable:!0,writable:!0,value:u}):i[s]=u;var y=(i,s,u)=>R(i,typeof s!="symbol"?s+"":s,u);const s="https://cdn-sdk-dev.paynext.com/index.cdn.js",u="https://cdn-sdk.paynext.com/index.cdn.js";let h=null,w=null;function g(){const n=navigator.connection||navigator.mozConnection||navigator.webkitConnection,e={online:navigator.onLine,documentHidden:document.hidden,userAgent:navigator.userAgent,timestamp:new Date().toISOString()};return n&&(e.connectionType=n.type,e.effectiveType=n.effectiveType,e.downlink=n.downlink,e.rtt=n.rtt,e.saveData=n.saveData),navigator.onLine?document.hidden?e.likelyCause="background_tab":n?.effectiveType==="slow-2g"||n?.effectiveType==="2g"?e.likelyCause="slow_connection":n?.downlink!==void 0&&n.downlink<.5&&(e.likelyCause="poor_bandwidth"):e.likelyCause="offline",e}function K(n){const e=[];return n.likelyCause&&e.push(`cause=${n.likelyCause}`),e.push(`online=${n.online}`),e.push(`hidden=${n.documentHidden}`),n.effectiveType&&e.push(`net=${n.effectiveType}`),n.downlink!==void 0&&e.push(`downlink=${n.downlink}Mbps`),n.rtt!==void 0&&e.push(`rtt=${n.rtt}ms`),e.join(", ")}class r extends Error{constructor(t,o=!0,a=!1){const c=a&&typeof window<"u"?g():null,v=c?`${t} [${K(c)}]`:t;super(v);y(this,"diagnostics");this.retryable=o,this.name="SDKLoadError",this.diagnostics=c}}const A="PayNextSDK";function E(){return typeof window>"u"?null:window[A]}function L(n){typeof window>"u"||(window[A]=n)}function N(n){return new Promise(e=>setTimeout(e,n))}async function _(n=5e3){const t=Math.ceil(n/50);for(let o=0;o<t;o++){const a=E();if(a)return a;await N(50)}throw new r("PayNextSDK not found in window after waiting",!0,!0)}async function T(n,e=1){const t=n?.toLowerCase(),a=(t?.includes("develop")||t?.includes("staging")||t?.includes("preview")?"develop":"production")==="develop"?s:u;try{const c=E();return c||(await new Promise((P,m)=>{const l=document.querySelector(`script[src="${a}"]`);if(l){if(E()){P();return}const p=setTimeout(()=>{l.removeEventListener("load",f),l.removeEventListener("error",S),m(new r("Existing SDK script loading timeout",!0,!0))},15e3),f=()=>{clearTimeout(p),l.removeEventListener("load",f),l.removeEventListener("error",S),P()},S=()=>{clearTimeout(p),l.removeEventListener("load",f),l.removeEventListener("error",S),m(new r("Existing SDK script failed to load",!0,!0))};l.addEventListener("load",f),l.addEventListener("error",S);return}const M=setTimeout(()=>{D(),m(new r("SDK script loading timeout",!0,!0))},15e3),d=document.createElement("script");d.src=a,d.crossOrigin="anonymous",d.async=!0,d.setAttribute("data-paynext-sdk","true");const D=()=>{clearTimeout(M),d.onload=null,d.onerror=null};d.onload=()=>{D(),P()},d.onerror=p=>{console.error("[PayNext CDN] Script load error:",p),D();try{d.parentNode&&d.parentNode.removeChild(d)}catch(f){console.warn("[PayNext CDN] Failed to remove script:",f)}m(new r("Failed to load SDK script from CDN",!0,!0))};try{document.head.appendChild(d)}catch{D(),m(new r("Failed to append script to document",!1))}}),await _(5e3))}catch(c){if((c instanceof r?c.retryable:!0)&&e<5)return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`,c),await N(1500*e),T(n,e+1);throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`,c),c}}async function x(n){if(w)return w;if(h)return h;if(typeof window>"u")throw new r("PayNext SDK can only be loaded in browser environment",!1);const e=E();return e?(w=e,w):(h=(async()=>{try{const t=await T(n);return w=t,L(t),t}catch(t){throw h=null,t}})(),h)}class C{constructor(){y(this,"cdnInstance",null);y(this,"initPromise",null);y(this,"isDestroyed",!1);y(this,"errorBoundary",null)}setErrorHandler(e){this.errorBoundary=e}handleError(e,t){const o=`[PayNext SDK Error - ${t}]: ${e.message}`;if(console.error(o,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 x(e);if(!t||!t.PayNextCheckout)throw new r("PayNextCheckout not found in loaded SDK module",!1);try{this.cdnInstance=new t.PayNextCheckout}catch(o){throw new r(`Failed to instantiate PayNextCheckout: ${o instanceof Error?o.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(o){const a=o instanceof r?o:new r(o instanceof Error?o.message:"Unknown mount error",!0);throw this.handleError(a,"mount"),a}}setPaymentsEnabled(e){try{if(this.isDestroyed){console.warn("[PayNext SDK] setPaymentsEnabled called on destroyed instance");return}if(!this.cdnInstance){console.warn("[PayNext SDK] setPaymentsEnabled called before mount");return}typeof this.cdnInstance.setPaymentsEnabled=="function"&&this.cdnInstance.setPaymentsEnabled(e)}catch(t){const o=t instanceof Error?t:new Error(String(t));this.handleError(o,"setPaymentsEnabled")}}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 x(e)}catch(t){throw console.error("[PayNext SDK] Preload failed:",t),t}}}const I={preload:C.preload};var k=(n=>(n.PAYPAL="PAYPAL",n.APPLE_PAY="APPLEPAY",n.GOOGLE_PAY="GPAY",n.CARD="CARD",n.VENMO="VENMO",n.CASHAPP="CASHAPP",n.AMAZONPAY="AMAZONPAY",n.PIX_AUTOMATICO="PIX_AUTOMATICO",n))(k||{});i.PayNextCheckout=C,i.PayNextSDK=I,i.PaymentMethod=k,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paynext/sdk",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "PayNext SDK - Payment processing with automatic CDN loading",
5
5
  "type": "module",
6
6
  "main": "dist/index.es.js",
@@ -86,8 +86,10 @@
86
86
  "eslint-plugin-react-hooks": "^7.0.1",
87
87
  "eslint-plugin-react-refresh": "^0.4.24",
88
88
  "globals": "^16.5.0",
89
+ "happy-dom": "^20.10.6",
89
90
  "json5": "^2.2.3",
90
91
  "motion": "^12.23.24",
92
+ "msw": "^2.14.6",
91
93
  "prettier": "^3.6.2",
92
94
  "prettier-plugin-tailwindcss": "^0.6.9",
93
95
  "react": "^19.2.0",