@paynext/sdk 1.0.10 → 1.0.12

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.d.ts CHANGED
@@ -220,7 +220,7 @@ export declare interface LoadedResult {
220
220
  error?: CheckoutError;
221
221
  }
222
222
 
223
- export declare type Locale = 'ar' | 'en' | 'bg' | 'cs' | 'da' | 'de' | 'el' | 'es' | 'et' | 'fi' | 'fil' | 'fr' | 'hr' | 'hu' | 'id' | 'it' | 'ja' | 'ko' | 'lt' | 'lv' | 'ms' | 'ru' | 'mt' | 'no' | 'nl' | 'pl' | 'pt' | 'ro' | 'uk' | 'sk' | 'sl' | 'sv' | 'th' | 'tr' | 'vi' | 'zh';
223
+ export declare type Locale = 'ar' | 'en' | 'bg' | 'cs' | 'da' | 'de' | 'el' | 'es' | 'et' | 'fi' | 'fil' | 'fr' | 'hr' | 'hu' | 'id' | 'it' | 'ja' | 'ko' | 'lt' | 'lv' | 'ms' | 'ru' | 'mt' | 'no' | 'nl' | 'pl' | 'pt' | 'ro' | 'uk' | 'sk' | 'sl' | 'sv' | 'th' | 'tr' | 'vi' | 'zh' | 'sr' | 'is' | 'nl-BE';
224
224
 
225
225
  export declare enum PaymentMethod {
226
226
  PAYPAL = "PAYPAL",
package/dist/index.es.js CHANGED
@@ -1,91 +1,107 @@
1
- var p = Object.defineProperty;
2
- var N = (r, e, t) => e in r ? p(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var a = (r, e, t) => N(r, typeof e != "symbol" ? e + "" : e, t);
4
- const x = "https://cdn-sdk-dev.paynext.com/index.cdn.js", A = "https://cdn-sdk.paynext.com/index.cdn.js";
5
- let c = null, d = null;
1
+ var A = Object.defineProperty;
2
+ var v = (r, e, t) => e in r ? A(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var u = (r, e, t) => v(r, typeof e != "symbol" ? e + "" : e, t);
4
+ const K = "https://cdn-sdk-dev.paynext.com/index.cdn.js", L = "https://cdn-sdk.paynext.com/index.cdn.js";
5
+ let w = null, h = null;
6
6
  class n extends Error {
7
7
  constructor(e, t = !0) {
8
8
  super(e), this.retryable = t, this.name = "SDKLoadError";
9
9
  }
10
10
  }
11
- const D = "PayNextSDK";
12
- function y() {
13
- return typeof window > "u" ? null : window[D];
11
+ const P = "PayNextSDK";
12
+ function E() {
13
+ return typeof window > "u" ? null : window[P];
14
14
  }
15
15
  function C(r) {
16
- typeof window > "u" || (window[D] = r);
16
+ typeof window > "u" || (window[P] = r);
17
17
  }
18
- function K(r) {
18
+ function S(r) {
19
19
  return new Promise((e) => setTimeout(e, r));
20
20
  }
21
- async function P(r, e = 1) {
22
- const o = (r?.toLowerCase()?.includes("develop") || r?.toLowerCase()?.includes("staging") ? "develop" : "production") === "develop" ? x : A;
23
- try {
24
- const i = y();
21
+ async function _(r = 5e3) {
22
+ const t = Math.ceil(r / 50);
23
+ for (let o = 0; o < t; o++) {
24
+ const i = E();
25
25
  if (i)
26
26
  return i;
27
- await new Promise((h, w) => {
28
- if (document.querySelector(`script[src="${o}"]`)) {
29
- h();
27
+ await S(50);
28
+ }
29
+ throw new n("PayNextSDK not found in window after waiting", !0);
30
+ }
31
+ async function p(r, e = 1) {
32
+ const o = (r?.toLowerCase()?.includes("develop") || r?.toLowerCase()?.includes("staging") ? "develop" : "production") === "develop" ? K : L;
33
+ try {
34
+ const i = E();
35
+ return i || (await new Promise((y, d) => {
36
+ const a = document.querySelector(`script[src="${o}"]`);
37
+ if (a) {
38
+ if (E()) {
39
+ y();
40
+ return;
41
+ }
42
+ const l = setTimeout(() => {
43
+ a.removeEventListener("load", c), a.removeEventListener("error", m), d(new n("Existing SDK script loading timeout", !0));
44
+ }, 15e3), c = () => {
45
+ clearTimeout(l), a.removeEventListener("load", c), a.removeEventListener("error", m), y();
46
+ }, m = () => {
47
+ clearTimeout(l), a.removeEventListener("load", c), a.removeEventListener("error", m), d(new n("Existing SDK script failed to load", !0));
48
+ };
49
+ a.addEventListener("load", c), a.addEventListener("error", m);
30
50
  return;
31
51
  }
32
- const E = setTimeout(() => {
33
- l(), w(new n("SDK script loading timeout", !0));
34
- }, 12e3), s = document.createElement("script");
52
+ const x = setTimeout(() => {
53
+ f(), d(new n("SDK script loading timeout", !0));
54
+ }, 15e3), s = document.createElement("script");
35
55
  s.src = o, s.crossOrigin = "anonymous", s.async = !0, s.setAttribute("data-paynext-sdk", "true");
36
- const l = () => {
37
- clearTimeout(E), s.onload = null, s.onerror = null;
56
+ const f = () => {
57
+ clearTimeout(x), s.onload = null, s.onerror = null;
38
58
  };
39
59
  s.onload = () => {
40
- l(), h();
41
- }, s.onerror = (f) => {
42
- console.error("[PayNext CDN] Script load error:", f), l();
60
+ f(), y();
61
+ }, s.onerror = (l) => {
62
+ console.error("[PayNext CDN] Script load error:", l), f();
43
63
  try {
44
64
  s.parentNode && s.parentNode.removeChild(s);
45
- } catch (S) {
46
- console.warn("[PayNext CDN] Failed to remove script:", S);
65
+ } catch (c) {
66
+ console.warn("[PayNext CDN] Failed to remove script:", c);
47
67
  }
48
- w(new n("Failed to load SDK script from CDN", !0));
68
+ d(new n("Failed to load SDK script from CDN", !0));
49
69
  };
50
70
  try {
51
71
  document.head.appendChild(s);
52
72
  } catch {
53
- l(), w(new n("Failed to append script to document", !1));
73
+ f(), d(new n("Failed to append script to document", !1));
54
74
  }
55
- });
56
- const u = y();
57
- if (!u)
58
- throw new n("PayNextSDK not found in window after load", !0);
59
- return u;
75
+ }), await _(5e3));
60
76
  } catch (i) {
61
77
  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);
78
+ return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`, i), await S(1500 * e), p(r, e + 1);
63
79
  throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`, i), i;
64
80
  }
65
81
  }
66
- async function m(r) {
67
- if (d)
68
- return d;
69
- if (c)
70
- return c;
82
+ async function D(r) {
83
+ if (h)
84
+ return h;
85
+ if (w)
86
+ return w;
71
87
  if (typeof window > "u")
72
88
  throw new n("PayNext SDK can only be loaded in browser environment", !1);
73
- const e = y();
74
- return e ? (d = e, d) : (c = (async () => {
89
+ const e = E();
90
+ return e ? (h = e, h) : (w = (async () => {
75
91
  try {
76
- const t = await P(r);
77
- return d = t, C(t), t;
92
+ const t = await p(r);
93
+ return h = t, C(t), t;
78
94
  } catch (t) {
79
- throw c = null, t;
95
+ throw w = null, t;
80
96
  }
81
- })(), c);
97
+ })(), w);
82
98
  }
83
99
  class R {
84
100
  constructor() {
85
- a(this, "cdnInstance", null);
86
- a(this, "initPromise", null);
87
- a(this, "isDestroyed", !1);
88
- a(this, "errorBoundary", null);
101
+ u(this, "cdnInstance", null);
102
+ u(this, "initPromise", null);
103
+ u(this, "isDestroyed", !1);
104
+ u(this, "errorBoundary", null);
89
105
  }
90
106
  // set error handler
91
107
  setErrorHandler(e) {
@@ -107,7 +123,7 @@ class R {
107
123
  throw new n("Cannot initialize destroyed SDK instance", !1);
108
124
  return this.initPromise ? this.initPromise : (this.initPromise = (async () => {
109
125
  try {
110
- const t = await m(e);
126
+ const t = await D(e);
111
127
  if (!t || !t.PayNextCheckout)
112
128
  throw new n("PayNextCheckout not found in loaded SDK module", !1);
113
129
  try {
@@ -176,18 +192,18 @@ class R {
176
192
  // preload SDK
177
193
  static async preload(e) {
178
194
  try {
179
- await m(e);
195
+ await D(e);
180
196
  } catch (t) {
181
197
  throw console.error("[PayNext SDK] Preload failed:", t), t;
182
198
  }
183
199
  }
184
200
  }
185
- const T = {
201
+ const I = {
186
202
  preload: R.preload
187
203
  };
188
- var _ = /* @__PURE__ */ ((r) => (r.PAYPAL = "PAYPAL", r.APPLE_PAY = "APPLEPAY", r.GOOGLE_PAY = "GPAY", r.CARD = "CARD", r.VENMO = "VENMO", r.CASHAPP = "CASHAPP", r))(_ || {});
204
+ var T = /* @__PURE__ */ ((r) => (r.PAYPAL = "PAYPAL", r.APPLE_PAY = "APPLEPAY", r.GOOGLE_PAY = "GPAY", r.CARD = "CARD", r.VENMO = "VENMO", r.CASHAPP = "CASHAPP", r))(T || {});
189
205
  export {
190
206
  R as PayNextCheckout,
191
- T as PayNextSDK,
192
- _ as PaymentMethod
207
+ I as PayNextSDK,
208
+ T as PaymentMethod
193
209
  };
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))},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"})}));
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 g=Object.defineProperty;var M=(s,a,l)=>a in s?g(s,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):s[a]=l;var m=(s,a,l)=>M(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 f=null,h=null;class r extends Error{constructor(e,t=!0){super(e),this.retryable=t,this.name="SDKLoadError"}}const p="PayNextSDK";function E(){return typeof window>"u"?null:window[p]}function L(n){typeof window>"u"||(window[p]=n)}function N(n){return new Promise(e=>setTimeout(e,n))}async function C(n=5e3){const t=Math.ceil(n/50);for(let o=0;o<t;o++){const i=E();if(i)return i;await N(50)}throw new r("PayNextSDK not found in window after waiting",!0)}async function x(n,e=1){const o=(n?.toLowerCase()?.includes("develop")||n?.toLowerCase()?.includes("staging")?"develop":"production")==="develop"?a:l;try{const i=E();return i||(await new Promise((D,y)=>{const c=document.querySelector(`script[src="${o}"]`);if(c){if(E()){D();return}const w=setTimeout(()=>{c.removeEventListener("load",u),c.removeEventListener("error",S),y(new r("Existing SDK script loading timeout",!0))},15e3),u=()=>{clearTimeout(w),c.removeEventListener("load",u),c.removeEventListener("error",S),D()},S=()=>{clearTimeout(w),c.removeEventListener("load",u),c.removeEventListener("error",S),y(new r("Existing SDK script failed to load",!0))};c.addEventListener("load",u),c.addEventListener("error",S);return}const R=setTimeout(()=>{P(),y(new r("SDK script loading timeout",!0))},15e3),d=document.createElement("script");d.src=o,d.crossOrigin="anonymous",d.async=!0,d.setAttribute("data-paynext-sdk","true");const P=()=>{clearTimeout(R),d.onload=null,d.onerror=null};d.onload=()=>{P(),D()},d.onerror=w=>{console.error("[PayNext CDN] Script load error:",w),P();try{d.parentNode&&d.parentNode.removeChild(d)}catch(u){console.warn("[PayNext CDN] Failed to remove script:",u)}y(new r("Failed to load SDK script from CDN",!0))};try{document.head.appendChild(d)}catch{P(),y(new r("Failed to append script to document",!1))}}),await C(5e3))}catch(i){if((i instanceof r?i.retryable:!0)&&e<5)return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`,i),await N(1500*e),x(n,e+1);throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`,i),i}}async function v(n){if(h)return h;if(f)return f;if(typeof window>"u")throw new r("PayNext SDK can only be loaded in browser environment",!1);const e=E();return e?(h=e,h):(f=(async()=>{try{const t=await x(n);return h=t,L(t),t}catch(t){throw f=null,t}})(),f)}class A{constructor(){m(this,"cdnInstance",null);m(this,"initPromise",null);m(this,"isDestroyed",!1);m(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(i){console.error("[PayNext SDK] Error in custom error handler:",i)}}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 v(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 i=o instanceof r?o:new r(o instanceof Error?o.message:"Unknown mount error",!0);throw this.handleError(i,"mount"),i}}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 v(e)}catch(t){throw console.error("[PayNext SDK] Preload failed:",t),t}}}const T={preload:A.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))(K||{});s.PayNextCheckout=A,s.PayNextSDK=T,s.PaymentMethod=K,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paynext/sdk",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "PayNext SDK - Payment processing with automatic CDN loading",
5
5
  "type": "module",
6
6
  "main": "dist/index.es.js",
@@ -61,7 +61,7 @@
61
61
  },
62
62
  "devDependencies": {
63
63
  "@eslint/js": "^9.39.1",
64
- "@evervault/js": "^2.6.0",
64
+ "@evervault/js": "^2.9.0",
65
65
  "@heroui/react": "^2.8.5",
66
66
  "@paypal/paypal-js": "^8.4.2",
67
67
  "@paypal/react-paypal-js": "^8.9.2",