@paynext/sdk 1.0.12 → 1.0.13
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 +2 -1
- package/dist/index.es.js +111 -95
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.es.js
CHANGED
|
@@ -1,115 +1,131 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
const
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
var C = Object.defineProperty;
|
|
2
|
+
var N = (t, e, n) => e in t ? C(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
3
|
+
var d = (t, e, n) => N(t, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
+
const k = "https://cdn-sdk-dev.paynext.com/index.cdn.js", x = "https://cdn-sdk.paynext.com/index.cdn.js";
|
|
5
|
+
let h = null, y = null;
|
|
6
|
+
function L() {
|
|
7
|
+
const t = navigator.connection || navigator.mozConnection || navigator.webkitConnection, e = {
|
|
8
|
+
online: navigator.onLine,
|
|
9
|
+
documentHidden: document.hidden,
|
|
10
|
+
userAgent: navigator.userAgent,
|
|
11
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
12
|
+
};
|
|
13
|
+
return t && (e.connectionType = t.type, e.effectiveType = t.effectiveType, e.downlink = t.downlink, e.rtt = t.rtt, e.saveData = t.saveData), navigator.onLine ? document.hidden ? e.likelyCause = "background_tab" : t?.effectiveType === "slow-2g" || t?.effectiveType === "2g" ? e.likelyCause = "slow_connection" : t?.downlink !== void 0 && t.downlink < 0.5 && (e.likelyCause = "poor_bandwidth") : e.likelyCause = "offline", e;
|
|
14
|
+
}
|
|
15
|
+
function g(t) {
|
|
16
|
+
const e = [];
|
|
17
|
+
return t.likelyCause && e.push(`cause=${t.likelyCause}`), e.push(`online=${t.online}`), e.push(`hidden=${t.documentHidden}`), t.effectiveType && e.push(`net=${t.effectiveType}`), t.downlink !== void 0 && e.push(`downlink=${t.downlink}Mbps`), t.rtt !== void 0 && e.push(`rtt=${t.rtt}ms`), e.join(", ");
|
|
18
|
+
}
|
|
19
|
+
class r extends Error {
|
|
20
|
+
constructor(n, o = !0, i = !1) {
|
|
21
|
+
const u = i && typeof window < "u" ? L() : null, c = u ? `${n} [${g(u)}]` : n;
|
|
22
|
+
super(c);
|
|
23
|
+
d(this, "diagnostics");
|
|
24
|
+
this.retryable = o, this.name = "SDKLoadError", this.diagnostics = u;
|
|
9
25
|
}
|
|
10
26
|
}
|
|
11
|
-
const
|
|
12
|
-
function
|
|
13
|
-
return typeof window > "u" ? null : window[
|
|
27
|
+
const v = "PayNextSDK";
|
|
28
|
+
function D() {
|
|
29
|
+
return typeof window > "u" ? null : window[v];
|
|
14
30
|
}
|
|
15
|
-
function
|
|
16
|
-
typeof window > "u" || (window[
|
|
31
|
+
function T(t) {
|
|
32
|
+
typeof window > "u" || (window[v] = t);
|
|
17
33
|
}
|
|
18
|
-
function
|
|
19
|
-
return new Promise((e) => setTimeout(e,
|
|
34
|
+
function P(t) {
|
|
35
|
+
return new Promise((e) => setTimeout(e, t));
|
|
20
36
|
}
|
|
21
|
-
async function
|
|
22
|
-
const
|
|
23
|
-
for (let o = 0; o <
|
|
24
|
-
const i =
|
|
37
|
+
async function K(t = 5e3) {
|
|
38
|
+
const n = Math.ceil(t / 50);
|
|
39
|
+
for (let o = 0; o < n; o++) {
|
|
40
|
+
const i = D();
|
|
25
41
|
if (i)
|
|
26
42
|
return i;
|
|
27
|
-
await
|
|
43
|
+
await P(50);
|
|
28
44
|
}
|
|
29
|
-
throw new
|
|
45
|
+
throw new r("PayNextSDK not found in window after waiting", !0, !0);
|
|
30
46
|
}
|
|
31
|
-
async function
|
|
32
|
-
const o = (
|
|
47
|
+
async function S(t, e = 1) {
|
|
48
|
+
const o = (t?.toLowerCase()?.includes("develop") || t?.toLowerCase()?.includes("staging") ? "develop" : "production") === "develop" ? k : x;
|
|
33
49
|
try {
|
|
34
|
-
const i =
|
|
35
|
-
return i || (await new Promise((
|
|
50
|
+
const i = D();
|
|
51
|
+
return i || (await new Promise((c, f) => {
|
|
36
52
|
const a = document.querySelector(`script[src="${o}"]`);
|
|
37
53
|
if (a) {
|
|
38
|
-
if (
|
|
39
|
-
|
|
54
|
+
if (D()) {
|
|
55
|
+
c();
|
|
40
56
|
return;
|
|
41
57
|
}
|
|
42
|
-
const
|
|
43
|
-
a.removeEventListener("load",
|
|
44
|
-
}, 15e3),
|
|
45
|
-
clearTimeout(
|
|
46
|
-
},
|
|
47
|
-
clearTimeout(
|
|
58
|
+
const w = setTimeout(() => {
|
|
59
|
+
a.removeEventListener("load", l), a.removeEventListener("error", p), f(new r("Existing SDK script loading timeout", !0, !0));
|
|
60
|
+
}, 15e3), l = () => {
|
|
61
|
+
clearTimeout(w), a.removeEventListener("load", l), a.removeEventListener("error", p), c();
|
|
62
|
+
}, p = () => {
|
|
63
|
+
clearTimeout(w), a.removeEventListener("load", l), a.removeEventListener("error", p), f(new r("Existing SDK script failed to load", !0, !0));
|
|
48
64
|
};
|
|
49
|
-
a.addEventListener("load",
|
|
65
|
+
a.addEventListener("load", l), a.addEventListener("error", p);
|
|
50
66
|
return;
|
|
51
67
|
}
|
|
52
|
-
const
|
|
53
|
-
|
|
68
|
+
const A = setTimeout(() => {
|
|
69
|
+
m(), f(new r("SDK script loading timeout", !0, !0));
|
|
54
70
|
}, 15e3), s = document.createElement("script");
|
|
55
71
|
s.src = o, s.crossOrigin = "anonymous", s.async = !0, s.setAttribute("data-paynext-sdk", "true");
|
|
56
|
-
const
|
|
57
|
-
clearTimeout(
|
|
72
|
+
const m = () => {
|
|
73
|
+
clearTimeout(A), s.onload = null, s.onerror = null;
|
|
58
74
|
};
|
|
59
75
|
s.onload = () => {
|
|
60
|
-
|
|
61
|
-
}, s.onerror = (
|
|
62
|
-
console.error("[PayNext CDN] Script load error:",
|
|
76
|
+
m(), c();
|
|
77
|
+
}, s.onerror = (w) => {
|
|
78
|
+
console.error("[PayNext CDN] Script load error:", w), m();
|
|
63
79
|
try {
|
|
64
80
|
s.parentNode && s.parentNode.removeChild(s);
|
|
65
|
-
} catch (
|
|
66
|
-
console.warn("[PayNext CDN] Failed to remove script:",
|
|
81
|
+
} catch (l) {
|
|
82
|
+
console.warn("[PayNext CDN] Failed to remove script:", l);
|
|
67
83
|
}
|
|
68
|
-
|
|
84
|
+
f(new r("Failed to load SDK script from CDN", !0, !0));
|
|
69
85
|
};
|
|
70
86
|
try {
|
|
71
87
|
document.head.appendChild(s);
|
|
72
88
|
} catch {
|
|
73
|
-
|
|
89
|
+
m(), f(new r("Failed to append script to document", !1));
|
|
74
90
|
}
|
|
75
|
-
}), await
|
|
91
|
+
}), await K(5e3));
|
|
76
92
|
} catch (i) {
|
|
77
|
-
if ((i instanceof
|
|
78
|
-
return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`, i), await
|
|
93
|
+
if ((i instanceof r ? i.retryable : !0) && e < 5)
|
|
94
|
+
return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`, i), await P(1500 * e), S(t, e + 1);
|
|
79
95
|
throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`, i), i;
|
|
80
96
|
}
|
|
81
97
|
}
|
|
82
|
-
async function
|
|
98
|
+
async function E(t) {
|
|
99
|
+
if (y)
|
|
100
|
+
return y;
|
|
83
101
|
if (h)
|
|
84
102
|
return h;
|
|
85
|
-
if (w)
|
|
86
|
-
return w;
|
|
87
103
|
if (typeof window > "u")
|
|
88
|
-
throw new
|
|
89
|
-
const e =
|
|
90
|
-
return e ? (
|
|
104
|
+
throw new r("PayNext SDK can only be loaded in browser environment", !1);
|
|
105
|
+
const e = D();
|
|
106
|
+
return e ? (y = e, y) : (h = (async () => {
|
|
91
107
|
try {
|
|
92
|
-
const
|
|
93
|
-
return
|
|
94
|
-
} catch (
|
|
95
|
-
throw
|
|
108
|
+
const n = await S(t);
|
|
109
|
+
return y = n, T(n), n;
|
|
110
|
+
} catch (n) {
|
|
111
|
+
throw h = null, n;
|
|
96
112
|
}
|
|
97
|
-
})(),
|
|
113
|
+
})(), h);
|
|
98
114
|
}
|
|
99
|
-
class
|
|
115
|
+
class _ {
|
|
100
116
|
constructor() {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
117
|
+
d(this, "cdnInstance", null);
|
|
118
|
+
d(this, "initPromise", null);
|
|
119
|
+
d(this, "isDestroyed", !1);
|
|
120
|
+
d(this, "errorBoundary", null);
|
|
105
121
|
}
|
|
106
122
|
// set error handler
|
|
107
123
|
setErrorHandler(e) {
|
|
108
124
|
this.errorBoundary = e;
|
|
109
125
|
}
|
|
110
126
|
// handle error
|
|
111
|
-
handleError(e,
|
|
112
|
-
const o = `[PayNext SDK Error - ${
|
|
127
|
+
handleError(e, n) {
|
|
128
|
+
const o = `[PayNext SDK Error - ${n}]: ${e.message}`;
|
|
113
129
|
if (console.error(o, e), this.errorBoundary)
|
|
114
130
|
try {
|
|
115
131
|
this.errorBoundary(e);
|
|
@@ -120,46 +136,46 @@ class R {
|
|
|
120
136
|
// initialize
|
|
121
137
|
async initialize(e) {
|
|
122
138
|
if (this.isDestroyed)
|
|
123
|
-
throw new
|
|
139
|
+
throw new r("Cannot initialize destroyed SDK instance", !1);
|
|
124
140
|
return this.initPromise ? this.initPromise : (this.initPromise = (async () => {
|
|
125
141
|
try {
|
|
126
|
-
const
|
|
127
|
-
if (!
|
|
128
|
-
throw new
|
|
142
|
+
const n = await E(e);
|
|
143
|
+
if (!n || !n.PayNextCheckout)
|
|
144
|
+
throw new r("PayNextCheckout not found in loaded SDK module", !1);
|
|
129
145
|
try {
|
|
130
|
-
this.cdnInstance = new
|
|
146
|
+
this.cdnInstance = new n.PayNextCheckout();
|
|
131
147
|
} catch (o) {
|
|
132
|
-
throw new
|
|
148
|
+
throw new r(
|
|
133
149
|
`Failed to instantiate PayNextCheckout: ${o instanceof Error ? o.message : "Unknown error"}`,
|
|
134
150
|
!1
|
|
135
151
|
);
|
|
136
152
|
}
|
|
137
|
-
} catch (
|
|
138
|
-
throw this.initPromise = null,
|
|
153
|
+
} catch (n) {
|
|
154
|
+
throw this.initPromise = null, n;
|
|
139
155
|
}
|
|
140
156
|
})(), this.initPromise);
|
|
141
157
|
}
|
|
142
158
|
// assert ready
|
|
143
159
|
assertReady() {
|
|
144
160
|
if (this.isDestroyed)
|
|
145
|
-
throw new
|
|
161
|
+
throw new r("SDK instance has been destroyed", !1);
|
|
146
162
|
if (!this.initPromise)
|
|
147
|
-
throw new
|
|
163
|
+
throw new r("SDK initialization not started", !1);
|
|
148
164
|
if (!this.cdnInstance)
|
|
149
|
-
throw new
|
|
165
|
+
throw new r("SDK instance not created", !1);
|
|
150
166
|
}
|
|
151
167
|
// mount
|
|
152
|
-
async mount(e,
|
|
168
|
+
async mount(e, n) {
|
|
153
169
|
try {
|
|
154
170
|
if (!e || typeof e != "string")
|
|
155
|
-
throw new
|
|
156
|
-
if (!
|
|
157
|
-
throw new
|
|
171
|
+
throw new r("Invalid containerId provided", !1);
|
|
172
|
+
if (!n || !n.environment)
|
|
173
|
+
throw new r("Invalid config provided", !1);
|
|
158
174
|
if (!document.getElementById(e))
|
|
159
|
-
throw new
|
|
160
|
-
await this.initialize(
|
|
175
|
+
throw new r(`Container element with id "${e}" not found`, !1);
|
|
176
|
+
await this.initialize(n.environment), this.assertReady(), await this.cdnInstance.mount(e, n);
|
|
161
177
|
} catch (o) {
|
|
162
|
-
const i = o instanceof
|
|
178
|
+
const i = o instanceof r ? o : new r(
|
|
163
179
|
o instanceof Error ? o.message : "Unknown mount error",
|
|
164
180
|
!0
|
|
165
181
|
);
|
|
@@ -180,30 +196,30 @@ class R {
|
|
|
180
196
|
try {
|
|
181
197
|
typeof this.cdnInstance.unmount == "function" && await this.cdnInstance.unmount();
|
|
182
198
|
} catch (e) {
|
|
183
|
-
const
|
|
184
|
-
this.handleError(
|
|
199
|
+
const n = e instanceof Error ? e : new Error(String(e));
|
|
200
|
+
this.handleError(n, "unmount");
|
|
185
201
|
}
|
|
186
202
|
this.cdnInstance = null, this.initPromise = null;
|
|
187
203
|
} catch (e) {
|
|
188
|
-
const
|
|
189
|
-
this.handleError(
|
|
204
|
+
const n = e instanceof Error ? e : new Error(String(e));
|
|
205
|
+
this.handleError(n, "unmount");
|
|
190
206
|
}
|
|
191
207
|
}
|
|
192
208
|
// preload SDK
|
|
193
209
|
static async preload(e) {
|
|
194
210
|
try {
|
|
195
|
-
await
|
|
196
|
-
} catch (
|
|
197
|
-
throw console.error("[PayNext SDK] Preload failed:",
|
|
211
|
+
await E(e);
|
|
212
|
+
} catch (n) {
|
|
213
|
+
throw console.error("[PayNext SDK] Preload failed:", n), n;
|
|
198
214
|
}
|
|
199
215
|
}
|
|
200
216
|
}
|
|
201
217
|
const I = {
|
|
202
|
-
preload:
|
|
218
|
+
preload: _.preload
|
|
203
219
|
};
|
|
204
|
-
var
|
|
220
|
+
var R = /* @__PURE__ */ ((t) => (t.PAYPAL = "PAYPAL", t.APPLE_PAY = "APPLEPAY", t.GOOGLE_PAY = "GPAY", t.CARD = "CARD", t.VENMO = "VENMO", t.CASHAPP = "CASHAPP", t))(R || {});
|
|
205
221
|
export {
|
|
206
|
-
|
|
222
|
+
_ as PayNextCheckout,
|
|
207
223
|
I as PayNextSDK,
|
|
208
|
-
|
|
224
|
+
R as PaymentMethod
|
|
209
225
|
};
|
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
|
|
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 R=Object.defineProperty;var I=(s,a,l)=>a in s?R(s,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):s[a]=l;var y=(s,a,l)=>I(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 T(){const t=navigator.connection||navigator.mozConnection||navigator.webkitConnection,e={online:navigator.onLine,documentHidden:document.hidden,userAgent:navigator.userAgent,timestamp:new Date().toISOString()};return t&&(e.connectionType=t.type,e.effectiveType=t.effectiveType,e.downlink=t.downlink,e.rtt=t.rtt,e.saveData=t.saveData),navigator.onLine?document.hidden?e.likelyCause="background_tab":t?.effectiveType==="slow-2g"||t?.effectiveType==="2g"?e.likelyCause="slow_connection":t?.downlink!==void 0&&t.downlink<.5&&(e.likelyCause="poor_bandwidth"):e.likelyCause="offline",e}function g(t){const e=[];return t.likelyCause&&e.push(`cause=${t.likelyCause}`),e.push(`online=${t.online}`),e.push(`hidden=${t.documentHidden}`),t.effectiveType&&e.push(`net=${t.effectiveType}`),t.downlink!==void 0&&e.push(`downlink=${t.downlink}Mbps`),t.rtt!==void 0&&e.push(`rtt=${t.rtt}ms`),e.join(", ")}class o extends Error{constructor(n,r=!0,i=!1){const m=i&&typeof window<"u"?T():null,u=m?`${n} [${g(m)}]`:n;super(u);y(this,"diagnostics");this.retryable=r,this.name="SDKLoadError",this.diagnostics=m}}const v="PayNextSDK";function E(){return typeof window>"u"?null:window[v]}function K(t){typeof window>"u"||(window[v]=t)}function N(t){return new Promise(e=>setTimeout(e,t))}async function L(t=5e3){const n=Math.ceil(t/50);for(let r=0;r<n;r++){const i=E();if(i)return i;await N(50)}throw new o("PayNextSDK not found in window after waiting",!0,!0)}async function x(t,e=1){const r=(t?.toLowerCase()?.includes("develop")||t?.toLowerCase()?.includes("staging")?"develop":"production")==="develop"?a:l;try{const i=E();return i||(await new Promise((u,p)=>{const d=document.querySelector(`script[src="${r}"]`);if(d){if(E()){u();return}const D=setTimeout(()=>{d.removeEventListener("load",f),d.removeEventListener("error",S),p(new o("Existing SDK script loading timeout",!0,!0))},15e3),f=()=>{clearTimeout(D),d.removeEventListener("load",f),d.removeEventListener("error",S),u()},S=()=>{clearTimeout(D),d.removeEventListener("load",f),d.removeEventListener("error",S),p(new o("Existing SDK script failed to load",!0,!0))};d.addEventListener("load",f),d.addEventListener("error",S);return}const M=setTimeout(()=>{P(),p(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 P=()=>{clearTimeout(M),c.onload=null,c.onerror=null};c.onload=()=>{P(),u()},c.onerror=D=>{console.error("[PayNext CDN] Script load error:",D),P();try{c.parentNode&&c.parentNode.removeChild(c)}catch(f){console.warn("[PayNext CDN] Failed to remove script:",f)}p(new o("Failed to load SDK script from CDN",!0,!0))};try{document.head.appendChild(c)}catch{P(),p(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 N(1500*e),x(t,e+1);throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`,i),i}}async function C(t){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=E();return e?(w=e,w):(h=(async()=>{try{const n=await x(t);return w=n,K(n),n}catch(n){throw h=null,n}})(),h)}class k{constructor(){y(this,"cdnInstance",null);y(this,"initPromise",null);y(this,"isDestroyed",!1);y(this,"errorBoundary",null)}setErrorHandler(e){this.errorBoundary=e}handleError(e,n){const r=`[PayNext SDK Error - ${n}]: ${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 n=await C(e);if(!n||!n.PayNextCheckout)throw new o("PayNextCheckout not found in loaded SDK module",!1);try{this.cdnInstance=new n.PayNextCheckout}catch(r){throw new o(`Failed to instantiate PayNextCheckout: ${r instanceof Error?r.message:"Unknown error"}`,!1)}}catch(n){throw this.initPromise=null,n}})(),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,n){try{if(!e||typeof e!="string")throw new o("Invalid containerId provided",!1);if(!n||!n.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(n.environment),this.assertReady(),await this.cdnInstance.mount(e,n)}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}}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 n=e instanceof Error?e:new Error(String(e));this.handleError(n,"unmount")}this.cdnInstance=null,this.initPromise=null}catch(e){const n=e instanceof Error?e:new Error(String(e));this.handleError(n,"unmount")}}static async preload(e){try{await C(e)}catch(n){throw console.error("[PayNext SDK] Preload failed:",n),n}}}const _={preload:k.preload};var A=(t=>(t.PAYPAL="PAYPAL",t.APPLE_PAY="APPLEPAY",t.GOOGLE_PAY="GPAY",t.CARD="CARD",t.VENMO="VENMO",t.CASHAPP="CASHAPP",t))(A||{});s.PayNextCheckout=k,s.PayNextSDK=_,s.PaymentMethod=A,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
|