@starfish-codes/hellgate 3.9.0 → 3.9.1

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.
@@ -1,25 +1,28 @@
1
- function re(t) {
2
- return Array.isArray(t) ? t.filter(Boolean) : Object.fromEntries(Object.entries(t).map(([e, r]) => [
1
+ function x(i) {
2
+ return Array.isArray(i) ? i.filter(Boolean) : Object.fromEntries(Object.entries(i).map(([e, t]) => [
3
3
  e,
4
- typeof r == "object" && r && !Array.isArray(r) ? re(r) : r
5
- ]).filter(([e, r]) => typeof r == "object" && r && !Array.isArray(r) ? !!Object.keys(r).length : r != null && r != null));
4
+ typeof t == "object" && t && !Array.isArray(t) ? x(t) : t
5
+ ]).filter(([e, t]) => typeof t == "object" && t && !Array.isArray(t) ? !!Object.keys(t).length : t != null && t != null));
6
6
  }
7
- function C(t, e) {
8
- const r = { ...t, ...e }, n = Object.keys(r);
9
- for (const i of n) {
10
- const a = t[i], s = e[i];
11
- typeof a == "object" && !Array.isArray(a) && a && typeof s == "object" && !Array.isArray(s) && s && (r[i] = C(a, s));
7
+ function h(i, e) {
8
+ const t = { ...i, ...e }, r = Object.keys(t);
9
+ for (const n of r) {
10
+ const a = i[n], s = e[n];
11
+ typeof a == "object" && !Array.isArray(a) && a && typeof s == "object" && !Array.isArray(s) && s && (t[n] = h(a, s));
12
12
  }
13
- return r;
13
+ return t;
14
+ }
15
+ function E(i) {
16
+ if (!i.ok)
17
+ throw i;
18
+ return i.json();
14
19
  }
15
- function V(t) {
16
- if (!t.ok)
17
- throw t;
18
- return t.json();
20
+ function C(i) {
21
+ return `https://${window.HG_IFRAME_HOST ?? "sdk.hellgate.io"}/web/${i}/iframe/`;
19
22
  }
20
- const xe = 2e3;
21
- class He {
22
- constructor(e, r) {
23
+ const N = 2e3;
24
+ class F {
25
+ constructor(e, t) {
23
26
  Object.defineProperty(this, "session", {
24
27
  enumerable: !0,
25
28
  configurable: !0,
@@ -79,40 +82,40 @@ class He {
79
82
  enumerable: !0,
80
83
  configurable: !0,
81
84
  writable: !0,
82
- value: (n) => {
83
- this.decoupledAuthHandlers.push(n);
85
+ value: (r) => {
86
+ this.decoupledAuthHandlers.push(r);
84
87
  }
85
88
  }), Object.defineProperty(this, "onStartChallenge", {
86
89
  enumerable: !0,
87
90
  configurable: !0,
88
91
  writable: !0,
89
- value: (n) => {
90
- this.onStartHandler = n;
92
+ value: (r) => {
93
+ this.onStartHandler = r;
91
94
  }
92
95
  }), Object.defineProperty(this, "onChallengeFinished", {
93
96
  enumerable: !0,
94
97
  configurable: !0,
95
98
  writable: !0,
96
- value: (n) => {
97
- this.onFinishHandler = n;
99
+ value: (r) => {
100
+ this.onFinishHandler = r;
98
101
  }
99
102
  }), Object.defineProperty(this, "sessionStateHandle", {
100
103
  enumerable: !0,
101
104
  configurable: !0,
102
105
  writable: !0,
103
- value: (n) => {
104
- var i, a;
105
- switch (n.next_action) {
106
+ value: (r) => {
107
+ var n, a;
108
+ switch (r.next_action) {
106
109
  case "3ds_check": {
107
- this.initCheck3DSIframes(n.data.threeds_server_callback_url, n.data.mon_url);
110
+ this.initCheck3DSIframes(r.data.threeds_server_callback_url, r.data.mon_url);
108
111
  break;
109
112
  }
110
113
  case "3ds_challenge": {
111
- (i = this.onStartHandler) == null || i.call(this), this.disposeCheck3DSIframe(), this.startChallenge(n.data.challenge_url, n.data.result_mon_url);
114
+ (n = this.onStartHandler) == null || n.call(this), this.disposeCheck3DSIframe(), this.startChallenge(r.data.challenge_url, r.data.result_mon_url);
112
115
  break;
113
116
  }
114
117
  case "3ds_challenge_decoupled": {
115
- this.startDecoupledAuth(n.data.cardholder_info, n.data.result_mon_url, n.data.transaction_id);
118
+ this.startDecoupledAuth(r.data.cardholder_info, r.data.result_mon_url, r.data.transaction_id);
116
119
  break;
117
120
  }
118
121
  case null: {
@@ -121,820 +124,98 @@ class He {
121
124
  }
122
125
  }
123
126
  }
124
- }), this.domContainer = r.domContainer ?? I(), this.disposers.push(this.session.onStateChange(this.sessionStateHandle)), this.labelText = r.labelText;
127
+ }), this.domContainer = t.domContainer ?? p(), this.disposers.push(this.session.onStateChange(this.sessionStateHandle)), this.labelText = t.labelText;
125
128
  }
126
129
  dispose() {
127
130
  this.disposers.forEach((e) => e()), this.check3dsIframeDisposers.forEach((e) => e());
128
131
  }
129
- initCheck3DSIframes(e, r) {
130
- const n = I();
131
- n.insertAdjacentHTML("beforeend", `<iframe id="check_3ds_${this.iframeId}" width="0" height="0" style="border:0;visibility: hidden;" src="${e}"></iframe>`);
132
- const i = n.querySelector(`#check_3ds_${this.iframeId}`);
133
- if (i) {
132
+ initCheck3DSIframes(e, t) {
133
+ const r = p();
134
+ r.insertAdjacentHTML("beforeend", `<iframe id="check_3ds_${this.iframeId}" width="0" height="0" style="border:0;visibility: hidden;" src="${e}"></iframe>`);
135
+ const n = r.querySelector(`#check_3ds_${this.iframeId}`);
136
+ if (n) {
134
137
  const a = (s) => {
135
- s.source === i.contentWindow && this.session.completeAction({ action: "3ds_check", result: s.data });
138
+ s.source === n.contentWindow && this.session.completeAction({ action: "3ds_check", result: s.data });
136
139
  };
137
- window.addEventListener("message", a), this.check3dsIframeDisposers.push(() => window.removeEventListener("message", a), () => i.remove());
140
+ window.addEventListener("message", a), this.check3dsIframeDisposers.push(() => window.removeEventListener("message", a), () => n.remove());
138
141
  }
139
- if (r) {
140
- n.insertAdjacentHTML("beforeend", `<iframe id="mon_${this.iframeId}" width="0" height="0" style="border:0;visibility: hidden;" src="${r}"></iframe>`);
141
- const a = n.querySelector(`#mon_${this.iframeId}`);
142
+ if (t) {
143
+ r.insertAdjacentHTML("beforeend", `<iframe id="mon_${this.iframeId}" width="0" height="0" style="border:0;visibility: hidden;" src="${t}"></iframe>`);
144
+ const a = r.querySelector(`#mon_${this.iframeId}`);
142
145
  a && this.disposers.push(() => a.remove());
143
146
  }
144
147
  }
145
148
  disposeCheck3DSIframe() {
146
149
  this.check3dsIframeDisposers.forEach((e) => e()), this.check3dsIframeDisposers = [];
147
150
  }
148
- startChallenge(e, r) {
149
- const n = I(), i = `<div style="display: flex; flex-direction: column; gap: 10px; align-items: center; ${this.domContainer === n ? 'border:0; max-width: 800px; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width:100% " ' : 'border:0;" width="100%" height="100%"'}><iframe id="cha_${this.iframeId}" src="${e}" width="100%" height="500"></iframe>${this.labelText ? '<span id="tds_label_text" style="font-size: large;">' + this.labelText + "</span>" : ""}<div>`;
150
- this.domContainer.insertAdjacentHTML("beforeend", this.domContainer === n ? `<div id="cha_${this.iframeId}_wrap" style="background: #fff; position: fixed; left: 0; top: 0; width: 100%; height: 100%; z-index: 10000;">${i}</div>` : i);
151
+ startChallenge(e, t) {
152
+ const r = p(), n = `<div style="display: flex; flex-direction: column; gap: 10px; align-items: center; ${this.domContainer === r ? 'border:0; max-width: 800px; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width:100% " ' : 'border:0;" width="100%" height="100%"'}><iframe id="cha_${this.iframeId}" src="${e}" width="100%" height="500"></iframe>${this.labelText ? '<span id="tds_label_text" style="font-size: large;">' + this.labelText + "</span>" : ""}<div>`;
153
+ this.domContainer.insertAdjacentHTML("beforeend", this.domContainer === r ? `<div id="cha_${this.iframeId}_wrap" style="background: #fff; position: fixed; left: 0; top: 0; width: 100%; height: 100%; z-index: 10000;">${n}</div>` : n);
151
154
  const a = this.domContainer.querySelector(`#cha_${this.iframeId}`), s = this.domContainer.querySelector(`#cha_${this.iframeId}_wrap`);
152
155
  if (!a)
153
156
  throw new Error("3DS Challenge Iframe initialization failed");
154
157
  this.disposers.push(() => {
155
158
  a.remove(), s == null || s.remove();
156
159
  });
157
- const o = new Promise((u) => {
158
- const d = (h) => {
159
- h.source !== a.contentWindow || h.data.event !== "AuthResultReady" || u(h.data);
160
+ const o = new Promise((c) => {
161
+ const d = (u) => {
162
+ u.source !== a.contentWindow || u.data.event !== "AuthResultReady" || c({
163
+ ...u.data,
164
+ requestor_trans_id: u.data.requestor_trans_id ?? u.data.requestorTransId,
165
+ // TODO: remove this field after the backend is updated
166
+ requestorTransId: void 0,
167
+ param: u.data.param || void 0
168
+ });
160
169
  };
161
170
  window.addEventListener("message", d), this.disposers.push(() => window.removeEventListener("message", d));
162
- }), c = new Promise((u) => {
163
- const d = this.startAuthResultPolling(r, (h) => {
164
- h.event === "AuthResultReady" && (d(), u({
165
- requestor_trans_id: h.threeDSRequestorTransID,
166
- event: h.event
171
+ }), l = new Promise((c) => {
172
+ const d = this.startAuthResultPolling(t, (u) => {
173
+ u.event === "AuthResultReady" && (d(), c({
174
+ requestor_trans_id: u.threeDSRequestorTransID,
175
+ event: u.event
167
176
  }));
168
177
  });
169
178
  });
170
- Promise.any([o, c]).then((u) => {
179
+ Promise.any([o, l]).then((c) => {
171
180
  this.session.completeAction({
172
181
  action: "3ds_challenge",
173
- result: u
182
+ result: c
174
183
  });
175
184
  });
176
185
  }
177
- startDecoupledAuth(e, r, n) {
178
- this.transactionId || (this.transactionId = n), this.decoupledAuthHandlers.forEach((a) => a(e));
179
- const i = this.startAuthResultPolling(r, (a) => {
186
+ startDecoupledAuth(e, t, r) {
187
+ this.transactionId || (this.transactionId = r), this.decoupledAuthHandlers.forEach((a) => a(e));
188
+ const n = this.startAuthResultPolling(t, (a) => {
180
189
  a.event === "AuthResultReady" && (this.session.completeAction({
181
190
  action: "3ds_challenge_decoupled",
182
191
  result: { ...a, event: a.event }
183
- }), i());
192
+ }), n());
184
193
  });
185
194
  }
186
- startAuthResultPolling(e, r) {
187
- return window.clearTimeout(this.resultPollingTimer), this.resultPollingTimer = window.setTimeout(() => fetch(e).then((n) => V(n)).then((n) => {
188
- this.startAuthResultPolling(e, r), r(n);
195
+ startAuthResultPolling(e, t) {
196
+ return window.clearTimeout(this.resultPollingTimer), this.resultPollingTimer = window.setTimeout(() => fetch(e).then((r) => E(r)).then((r) => {
197
+ this.startAuthResultPolling(e, t), t(r);
189
198
  }).catch(() => {
190
- }), xe), () => window.clearTimeout(this.resultPollingTimer);
199
+ }), N), () => window.clearTimeout(this.resultPollingTimer);
191
200
  }
192
201
  }
193
- function I() {
202
+ function p() {
194
203
  return document.body;
195
204
  }
196
- const f = crypto, A = (t) => t instanceof CryptoKey, Ke = async (t, e) => {
197
- const r = `SHA-${t.slice(-3)}`;
198
- return new Uint8Array(await f.subtle.digest(r, e));
199
- }, O = new TextEncoder(), ne = new TextDecoder(), R = 2 ** 32;
200
- function M(...t) {
201
- const e = t.reduce((i, { length: a }) => i + a, 0), r = new Uint8Array(e);
202
- let n = 0;
203
- for (const i of t)
204
- r.set(i, n), n += i.length;
205
- return r;
206
- }
207
- function Te(t, e) {
208
- return M(O.encode(t), new Uint8Array([0]), e);
209
- }
210
- function J(t, e, r) {
211
- if (e < 0 || e >= R)
212
- throw new RangeError(`value must be >= 0 and <= ${R - 1}. Received ${e}`);
213
- t.set([e >>> 24, e >>> 16, e >>> 8, e & 255], r);
214
- }
215
- function De(t) {
216
- const e = Math.floor(t / R), r = t % R, n = new Uint8Array(8);
217
- return J(n, e, 0), J(n, r, 4), n;
218
- }
219
- function Y(t) {
220
- const e = new Uint8Array(4);
221
- return J(e, t), e;
222
- }
223
- function U(t) {
224
- return M(Y(t.length), t);
225
- }
226
- async function Me(t, e, r) {
227
- const n = Math.ceil((e >> 3) / 32), i = new Uint8Array(n * 32);
228
- for (let a = 0; a < n; a++) {
229
- const s = new Uint8Array(4 + t.length + r.length);
230
- s.set(Y(a + 1)), s.set(t, 4), s.set(r, 4 + t.length), i.set(await Ke("sha256", s), a * 32);
231
- }
232
- return i.slice(0, e >> 3);
233
- }
234
- const je = (t) => {
235
- let e = t;
236
- typeof e == "string" && (e = O.encode(e));
237
- const r = 32768, n = [];
238
- for (let i = 0; i < e.length; i += r)
239
- n.push(String.fromCharCode.apply(null, e.subarray(i, i + r)));
240
- return btoa(n.join(""));
241
- }, w = (t) => je(t).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_"), Re = (t) => {
242
- const e = atob(t), r = new Uint8Array(e.length);
243
- for (let n = 0; n < e.length; n++)
244
- r[n] = e.charCodeAt(n);
245
- return r;
246
- }, ie = (t) => {
247
- let e = t;
248
- e instanceof Uint8Array && (e = ne.decode(e)), e = e.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
249
- try {
250
- return Re(e);
251
- } catch {
252
- throw new TypeError("The input to be decoded is not correctly encoded.");
253
- }
254
- };
255
- class ae extends Error {
256
- static get code() {
257
- return "ERR_JOSE_GENERIC";
258
- }
259
- constructor(e) {
260
- var r;
261
- super(e), this.code = "ERR_JOSE_GENERIC", this.name = this.constructor.name, (r = Error.captureStackTrace) == null || r.call(Error, this, this.constructor);
262
- }
263
- }
264
- class b extends ae {
265
- constructor() {
266
- super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
267
- }
268
- static get code() {
269
- return "ERR_JOSE_NOT_SUPPORTED";
270
- }
271
- }
272
- class P extends ae {
273
- constructor() {
274
- super(...arguments), this.code = "ERR_JWE_INVALID";
275
- }
276
- static get code() {
277
- return "ERR_JWE_INVALID";
278
- }
279
- }
280
- const k = f.getRandomValues.bind(f);
281
- function se(t) {
282
- switch (t) {
283
- case "A128GCM":
284
- case "A128GCMKW":
285
- case "A192GCM":
286
- case "A192GCMKW":
287
- case "A256GCM":
288
- case "A256GCMKW":
289
- return 96;
290
- case "A128CBC-HS256":
291
- case "A192CBC-HS384":
292
- case "A256CBC-HS512":
293
- return 128;
294
- default:
295
- throw new b(`Unsupported JWE Algorithm: ${t}`);
296
- }
297
- }
298
- const Ie = (t) => k(new Uint8Array(se(t) >> 3)), Ue = (t, e) => {
299
- if (e.length << 3 !== se(t))
300
- throw new P("Invalid Initialization Vector length");
301
- }, Z = (t, e) => {
302
- const r = t.byteLength << 3;
303
- if (r !== e)
304
- throw new P(`Invalid Content Encryption Key length. Expected ${e} bits, got ${r} bits`);
305
- };
306
- function S(t, e = "algorithm.name") {
307
- return new TypeError(`CryptoKey does not support this operation, its ${e} must be ${t}`);
308
- }
309
- function j(t, e) {
310
- return t.name === e;
311
- }
312
- function $e(t) {
313
- return parseInt(t.name.slice(4), 10);
314
- }
315
- function We(t, e) {
316
- if (e.length && !e.some((r) => t.usages.includes(r))) {
317
- let r = "CryptoKey does not support this operation, its usages must include ";
318
- if (e.length > 2) {
319
- const n = e.pop();
320
- r += `one of ${e.join(", ")}, or ${n}.`;
321
- } else e.length === 2 ? r += `one of ${e[0]} or ${e[1]}.` : r += `${e[0]}.`;
322
- throw new TypeError(r);
323
- }
324
- }
325
- function T(t, e, ...r) {
326
- switch (e) {
327
- case "A128GCM":
328
- case "A192GCM":
329
- case "A256GCM": {
330
- if (!j(t.algorithm, "AES-GCM"))
331
- throw S("AES-GCM");
332
- const n = parseInt(e.slice(1, 4), 10);
333
- if (t.algorithm.length !== n)
334
- throw S(n, "algorithm.length");
335
- break;
336
- }
337
- case "A128KW":
338
- case "A192KW":
339
- case "A256KW": {
340
- if (!j(t.algorithm, "AES-KW"))
341
- throw S("AES-KW");
342
- const n = parseInt(e.slice(1, 4), 10);
343
- if (t.algorithm.length !== n)
344
- throw S(n, "algorithm.length");
345
- break;
346
- }
347
- case "ECDH": {
348
- switch (t.algorithm.name) {
349
- case "ECDH":
350
- case "X25519":
351
- case "X448":
352
- break;
353
- default:
354
- throw S("ECDH, X25519, or X448");
355
- }
356
- break;
357
- }
358
- case "PBES2-HS256+A128KW":
359
- case "PBES2-HS384+A192KW":
360
- case "PBES2-HS512+A256KW":
361
- if (!j(t.algorithm, "PBKDF2"))
362
- throw S("PBKDF2");
363
- break;
364
- case "RSA-OAEP":
365
- case "RSA-OAEP-256":
366
- case "RSA-OAEP-384":
367
- case "RSA-OAEP-512": {
368
- if (!j(t.algorithm, "RSA-OAEP"))
369
- throw S("RSA-OAEP");
370
- const n = parseInt(e.slice(9), 10) || 1;
371
- if ($e(t.algorithm.hash) !== n)
372
- throw S(`SHA-${n}`, "algorithm.hash");
373
- break;
374
- }
375
- default:
376
- throw new TypeError("CryptoKey does not support this operation");
377
- }
378
- We(t, r);
379
- }
380
- function oe(t, e, ...r) {
381
- var n;
382
- if (r.length > 2) {
383
- const i = r.pop();
384
- t += `one of type ${r.join(", ")}, or ${i}.`;
385
- } else r.length === 2 ? t += `one of type ${r[0]} or ${r[1]}.` : t += `of type ${r[0]}.`;
386
- return e == null ? t += ` Received ${e}` : typeof e == "function" && e.name ? t += ` Received function ${e.name}` : typeof e == "object" && e != null && (n = e.constructor) != null && n.name && (t += ` Received an instance of ${e.constructor.name}`), t;
387
- }
388
- const _ = (t, ...e) => oe("Key must be ", t, ...e);
389
- function ce(t, e, ...r) {
390
- return oe(`Key for the ${t} algorithm must be `, e, ...r);
391
- }
392
- const le = (t) => A(t) ? !0 : (t == null ? void 0 : t[Symbol.toStringTag]) === "KeyObject", g = ["CryptoKey"], Ne = (...t) => {
393
- const e = t.filter(Boolean);
394
- if (e.length === 0 || e.length === 1)
395
- return !0;
396
- let r;
397
- for (const n of e) {
398
- const i = Object.keys(n);
399
- if (!r || r.size === 0) {
400
- r = new Set(i);
401
- continue;
402
- }
403
- for (const a of i) {
404
- if (r.has(a))
405
- return !1;
406
- r.add(a);
407
- }
408
- }
409
- return !0;
410
- };
411
- function Le(t) {
412
- return typeof t == "object" && t !== null;
413
- }
414
- function Fe(t) {
415
- if (!Le(t) || Object.prototype.toString.call(t) !== "[object Object]")
416
- return !1;
417
- if (Object.getPrototypeOf(t) === null)
418
- return !0;
419
- let e = t;
420
- for (; Object.getPrototypeOf(e) !== null; )
421
- e = Object.getPrototypeOf(e);
422
- return Object.getPrototypeOf(t) === e;
423
- }
424
- const ue = [
425
- { hash: "SHA-256", name: "HMAC" },
426
- !0,
427
- ["sign"]
428
- ];
429
- function Be(t, e) {
430
- if (t.algorithm.length !== parseInt(e.slice(1, 4), 10))
431
- throw new TypeError(`Invalid key size for alg: ${e}`);
432
- }
433
- function Ve(t, e, r) {
434
- if (A(t))
435
- return T(t, e, r), t;
436
- if (t instanceof Uint8Array)
437
- return f.subtle.importKey("raw", t, "AES-KW", !0, [r]);
438
- throw new TypeError(_(t, ...g, "Uint8Array"));
439
- }
440
- const z = async (t, e, r) => {
441
- const n = await Ve(e, t, "wrapKey");
442
- Be(n, t);
443
- const i = await f.subtle.importKey("raw", r, ...ue);
444
- return new Uint8Array(await f.subtle.wrapKey("raw", i, n, "AES-KW"));
445
- };
446
- async function Je(t, e, r, n, i = new Uint8Array(0), a = new Uint8Array(0)) {
447
- if (!A(t))
448
- throw new TypeError(_(t, ...g));
449
- if (T(t, "ECDH"), !A(e))
450
- throw new TypeError(_(e, ...g));
451
- T(e, "ECDH", "deriveBits");
452
- const s = M(U(O.encode(r)), U(i), U(a), Y(n));
453
- let o;
454
- t.algorithm.name === "X25519" ? o = 256 : t.algorithm.name === "X448" ? o = 448 : o = Math.ceil(parseInt(t.algorithm.namedCurve.substr(-3), 10) / 8) << 3;
455
- const c = new Uint8Array(await f.subtle.deriveBits({
456
- name: t.algorithm.name,
457
- public: t
458
- }, e, o));
459
- return Me(c, n, s);
460
- }
461
- async function ze(t) {
462
- if (!A(t))
463
- throw new TypeError(_(t, ...g));
464
- return f.subtle.generateKey(t.algorithm, !0, ["deriveBits"]);
465
- }
466
- function Ge(t) {
467
- if (!A(t))
468
- throw new TypeError(_(t, ...g));
469
- return ["P-256", "P-384", "P-521"].includes(t.algorithm.namedCurve) || t.algorithm.name === "X25519" || t.algorithm.name === "X448";
470
- }
471
- function Ye(t) {
472
- if (!(t instanceof Uint8Array) || t.length < 8)
473
- throw new P("PBES2 Salt Input must be 8 or more octets");
474
- }
475
- function ke(t, e) {
476
- if (t instanceof Uint8Array)
477
- return f.subtle.importKey("raw", t, "PBKDF2", !1, ["deriveBits"]);
478
- if (A(t))
479
- return T(t, e, "deriveBits", "deriveKey"), t;
480
- throw new TypeError(_(t, ...g, "Uint8Array"));
481
- }
482
- async function qe(t, e, r, n) {
483
- Ye(t);
484
- const i = Te(e, t), a = parseInt(e.slice(13, 16), 10), s = {
485
- hash: `SHA-${e.slice(8, 11)}`,
486
- iterations: r,
487
- name: "PBKDF2",
488
- salt: i
489
- }, o = {
490
- length: a,
491
- name: "AES-KW"
492
- }, c = await ke(n, e);
493
- if (c.usages.includes("deriveBits"))
494
- return new Uint8Array(await f.subtle.deriveBits(s, c, a));
495
- if (c.usages.includes("deriveKey"))
496
- return f.subtle.deriveKey(s, c, o, !1, ["wrapKey", "unwrapKey"]);
497
- throw new TypeError('PBKDF2 key "usages" must include "deriveBits" or "deriveKey"');
498
- }
499
- const Xe = async (t, e, r, n = 2048, i = k(new Uint8Array(16))) => {
500
- const a = await qe(i, t, n, e);
501
- return { encryptedKey: await z(t.slice(-6), a, r), p2c: n, p2s: w(i) };
502
- };
503
- function Q(t) {
504
- switch (t) {
505
- case "RSA-OAEP":
506
- case "RSA-OAEP-256":
507
- case "RSA-OAEP-384":
508
- case "RSA-OAEP-512":
509
- return "RSA-OAEP";
510
- default:
511
- throw new b(`alg ${t} is not supported either by JOSE or your javascript runtime`);
512
- }
513
- }
514
- const Ze = (t, e) => {
515
- if (t.startsWith("RS") || t.startsWith("PS")) {
516
- const { modulusLength: r } = e.algorithm;
517
- if (typeof r != "number" || r < 2048)
518
- throw new TypeError(`${t} requires key modulusLength to be 2048 bits or larger`);
519
- }
520
- }, Qe = async (t, e, r) => {
521
- if (!A(e))
522
- throw new TypeError(_(e, ...g));
523
- if (T(e, t, "encrypt", "wrapKey"), Ze(t, e), e.usages.includes("encrypt"))
524
- return new Uint8Array(await f.subtle.encrypt(Q(t), e, r));
525
- if (e.usages.includes("wrapKey")) {
526
- const n = await f.subtle.importKey("raw", r, ...ue);
527
- return new Uint8Array(await f.subtle.wrapKey("raw", n, e, Q(t)));
528
- }
529
- throw new TypeError('RSA-OAEP key "usages" must include "encrypt" or "wrapKey" for this operation');
530
- };
531
- function et(t) {
532
- let e, r;
533
- switch (t.kty) {
534
- case "RSA": {
535
- switch (t.alg) {
536
- case "PS256":
537
- case "PS384":
538
- case "PS512":
539
- e = { name: "RSA-PSS", hash: `SHA-${t.alg.slice(-3)}` }, r = t.d ? ["sign"] : ["verify"];
540
- break;
541
- case "RS256":
542
- case "RS384":
543
- case "RS512":
544
- e = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${t.alg.slice(-3)}` }, r = t.d ? ["sign"] : ["verify"];
545
- break;
546
- case "RSA-OAEP":
547
- case "RSA-OAEP-256":
548
- case "RSA-OAEP-384":
549
- case "RSA-OAEP-512":
550
- e = {
551
- name: "RSA-OAEP",
552
- hash: `SHA-${parseInt(t.alg.slice(-3), 10) || 1}`
553
- }, r = t.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
554
- break;
555
- default:
556
- throw new b('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
557
- }
558
- break;
559
- }
560
- case "EC": {
561
- switch (t.alg) {
562
- case "ES256":
563
- e = { name: "ECDSA", namedCurve: "P-256" }, r = t.d ? ["sign"] : ["verify"];
564
- break;
565
- case "ES384":
566
- e = { name: "ECDSA", namedCurve: "P-384" }, r = t.d ? ["sign"] : ["verify"];
567
- break;
568
- case "ES512":
569
- e = { name: "ECDSA", namedCurve: "P-521" }, r = t.d ? ["sign"] : ["verify"];
570
- break;
571
- case "ECDH-ES":
572
- case "ECDH-ES+A128KW":
573
- case "ECDH-ES+A192KW":
574
- case "ECDH-ES+A256KW":
575
- e = { name: "ECDH", namedCurve: t.crv }, r = t.d ? ["deriveBits"] : [];
576
- break;
577
- default:
578
- throw new b('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
579
- }
580
- break;
581
- }
582
- case "OKP": {
583
- switch (t.alg) {
584
- case "EdDSA":
585
- e = { name: t.crv }, r = t.d ? ["sign"] : ["verify"];
586
- break;
587
- case "ECDH-ES":
588
- case "ECDH-ES+A128KW":
589
- case "ECDH-ES+A192KW":
590
- case "ECDH-ES+A256KW":
591
- e = { name: t.crv }, r = t.d ? ["deriveBits"] : [];
592
- break;
593
- default:
594
- throw new b('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
595
- }
596
- break;
597
- }
598
- default:
599
- throw new b('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
600
- }
601
- return { algorithm: e, keyUsages: r };
602
- }
603
- const de = async (t) => {
604
- if (!t.alg)
605
- throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
606
- const { algorithm: e, keyUsages: r } = et(t), n = [
607
- e,
608
- t.ext ?? !1,
609
- t.key_ops ?? r
610
- ], i = { ...t };
611
- return delete i.alg, delete i.use, f.subtle.importKey("jwk", i, ...n);
612
- }, he = (t) => ie(t);
613
- let $, W;
614
- const fe = (t) => (t == null ? void 0 : t[Symbol.toStringTag]) === "KeyObject", pe = async (t, e, r, n) => {
615
- let i = t.get(e);
616
- if (i != null && i[n])
617
- return i[n];
618
- const a = await de({ ...r, alg: n });
619
- return i ? i[n] = a : t.set(e, { [n]: a }), a;
620
- }, tt = (t, e) => {
621
- if (fe(t)) {
622
- let r = t.export({ format: "jwk" });
623
- return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ? he(r.k) : (W || (W = /* @__PURE__ */ new WeakMap()), pe(W, t, r, e));
624
- }
625
- return t;
626
- }, rt = (t, e) => {
627
- if (fe(t)) {
628
- let r = t.export({ format: "jwk" });
629
- return r.k ? he(r.k) : ($ || ($ = /* @__PURE__ */ new WeakMap()), pe($, t, r, e));
630
- }
631
- return t;
632
- }, N = { normalizePublicKey: tt, normalizePrivateKey: rt };
633
- function me(t) {
634
- switch (t) {
635
- case "A128GCM":
636
- return 128;
637
- case "A192GCM":
638
- return 192;
639
- case "A256GCM":
640
- case "A128CBC-HS256":
641
- return 256;
642
- case "A192CBC-HS384":
643
- return 384;
644
- case "A256CBC-HS512":
645
- return 512;
646
- default:
647
- throw new b(`Unsupported JWE Algorithm: ${t}`);
648
- }
649
- }
650
- const D = (t) => k(new Uint8Array(me(t) >> 3));
651
- async function nt(t, e) {
652
- if (!Fe(t))
653
- throw new TypeError("JWK must be an object");
654
- switch (t.kty) {
655
- case "oct":
656
- if (typeof t.k != "string" || !t.k)
657
- throw new TypeError('missing "k" (Key Value) Parameter value');
658
- return ie(t.k);
659
- case "RSA":
660
- if (t.oth !== void 0)
661
- throw new b('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
662
- case "EC":
663
- case "OKP":
664
- return de({ ...t, alg: e });
665
- default:
666
- throw new b('Unsupported "kty" (Key Type) Parameter value');
667
- }
668
- }
669
- const G = (t) => t == null ? void 0 : t[Symbol.toStringTag], it = (t, e) => {
670
- if (!(e instanceof Uint8Array)) {
671
- if (!le(e))
672
- throw new TypeError(ce(t, e, ...g, "Uint8Array"));
673
- if (e.type !== "secret")
674
- throw new TypeError(`${G(e)} instances for symmetric algorithms must be of type "secret"`);
675
- }
676
- }, at = (t, e, r) => {
677
- if (!le(e))
678
- throw new TypeError(ce(t, e, ...g));
679
- if (e.type === "secret")
680
- throw new TypeError(`${G(e)} instances for asymmetric algorithms must not be of type "secret"`);
681
- if (e.algorithm, e.algorithm && r === "encrypt" && e.type === "private")
682
- throw new TypeError(`${G(e)} instances for asymmetric algorithm encryption must be of type "public"`);
683
- }, st = (t, e, r) => {
684
- t.startsWith("HS") || t === "dir" || t.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(t) ? it(t, e) : at(t, e, r);
685
- };
686
- async function ot(t, e, r, n, i) {
687
- if (!(r instanceof Uint8Array))
688
- throw new TypeError(_(r, "Uint8Array"));
689
- const a = parseInt(t.slice(1, 4), 10), s = await f.subtle.importKey("raw", r.subarray(a >> 3), "AES-CBC", !1, ["encrypt"]), o = await f.subtle.importKey("raw", r.subarray(0, a >> 3), {
690
- hash: `SHA-${a << 1}`,
691
- name: "HMAC"
692
- }, !1, ["sign"]), c = new Uint8Array(await f.subtle.encrypt({
693
- iv: n,
694
- name: "AES-CBC"
695
- }, s, e)), u = M(i, n, c, De(i.length << 3)), d = new Uint8Array((await f.subtle.sign("HMAC", o, u)).slice(0, a >> 3));
696
- return { ciphertext: c, tag: d, iv: n };
697
- }
698
- async function ct(t, e, r, n, i) {
699
- let a;
700
- r instanceof Uint8Array ? a = await f.subtle.importKey("raw", r, "AES-GCM", !1, ["encrypt"]) : (T(r, t, "encrypt"), a = r);
701
- const s = new Uint8Array(await f.subtle.encrypt({
702
- additionalData: i,
703
- iv: n,
704
- name: "AES-GCM",
705
- tagLength: 128
706
- }, a, e)), o = s.slice(-16);
707
- return { ciphertext: s.slice(0, -16), tag: o, iv: n };
708
- }
709
- const be = async (t, e, r, n, i) => {
710
- if (!A(r) && !(r instanceof Uint8Array))
711
- throw new TypeError(_(r, ...g, "Uint8Array"));
712
- switch (n ? Ue(t, n) : n = Ie(t), t) {
713
- case "A128CBC-HS256":
714
- case "A192CBC-HS384":
715
- case "A256CBC-HS512":
716
- return r instanceof Uint8Array && Z(r, parseInt(t.slice(-3), 10)), ot(t, e, r, n, i);
717
- case "A128GCM":
718
- case "A192GCM":
719
- case "A256GCM":
720
- return r instanceof Uint8Array && Z(r, parseInt(t.slice(1, 4), 10)), ct(t, e, r, n, i);
721
- default:
722
- throw new b("Unsupported JWE Content Encryption Algorithm");
723
- }
724
- };
725
- async function lt(t, e, r, n) {
726
- const i = t.slice(0, 7), a = await be(i, r, e, n, new Uint8Array(0));
727
- return {
728
- encryptedKey: a.ciphertext,
729
- iv: w(a.iv),
730
- tag: w(a.tag)
731
- };
732
- }
733
- function ut(t, e, r, n, i) {
734
- if (i.crit !== void 0 && (n == null ? void 0 : n.crit) === void 0)
735
- throw new t('"crit" (Critical) Header Parameter MUST be integrity protected');
736
- if (!n || n.crit === void 0)
737
- return /* @__PURE__ */ new Set();
738
- if (!Array.isArray(n.crit) || n.crit.length === 0 || n.crit.some((s) => typeof s != "string" || s.length === 0))
739
- throw new t('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
740
- let a;
741
- r !== void 0 ? a = new Map([...Object.entries(r), ...e.entries()]) : a = e;
742
- for (const s of n.crit) {
743
- if (!a.has(s))
744
- throw new b(`Extension Header Parameter "${s}" is not recognized`);
745
- if (i[s] === void 0)
746
- throw new t(`Extension Header Parameter "${s}" is missing`);
747
- if (a.get(s) && n[s] === void 0)
748
- throw new t(`Extension Header Parameter "${s}" MUST be integrity protected`);
749
- }
750
- return new Set(n.crit);
751
- }
752
- const dt = async (t) => {
753
- if (t instanceof Uint8Array)
754
- return {
755
- kty: "oct",
756
- k: w(t)
757
- };
758
- if (!A(t))
759
- throw new TypeError(_(t, ...g, "Uint8Array"));
760
- if (!t.extractable)
761
- throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
762
- const { ext: e, key_ops: r, alg: n, use: i, ...a } = await f.subtle.exportKey("jwk", t);
763
- return a;
764
- };
765
- async function ht(t) {
766
- return dt(t);
767
- }
768
- async function ft(t, e, r, n, i = {}) {
769
- var c;
770
- let a, s, o;
771
- switch (st(t, r, "encrypt"), r = await ((c = N.normalizePublicKey) == null ? void 0 : c.call(N, r, t)) || r, t) {
772
- case "dir": {
773
- o = r;
774
- break;
775
- }
776
- case "ECDH-ES":
777
- case "ECDH-ES+A128KW":
778
- case "ECDH-ES+A192KW":
779
- case "ECDH-ES+A256KW": {
780
- if (!Ge(r))
781
- throw new b("ECDH with the provided key is not allowed or not supported by your javascript runtime");
782
- const { apu: u, apv: d } = i;
783
- let { epk: h } = i;
784
- h || (h = (await ze(r)).privateKey);
785
- const { x: p, y: E, crv: l, kty: m } = await ht(h), X = await Je(r, h, t === "ECDH-ES" ? e : t, t === "ECDH-ES" ? me(e) : parseInt(t.slice(-5, -2), 10), u, d);
786
- if (s = { epk: { x: p, crv: l, kty: m } }, m === "EC" && (s.epk.y = E), u && (s.apu = w(u)), d && (s.apv = w(d)), t === "ECDH-ES") {
787
- o = X;
788
- break;
789
- }
790
- o = n || D(e);
791
- const Oe = t.slice(-6);
792
- a = await z(Oe, X, o);
793
- break;
794
- }
795
- case "RSA1_5":
796
- case "RSA-OAEP":
797
- case "RSA-OAEP-256":
798
- case "RSA-OAEP-384":
799
- case "RSA-OAEP-512": {
800
- o = n || D(e), a = await Qe(t, r, o);
801
- break;
802
- }
803
- case "PBES2-HS256+A128KW":
804
- case "PBES2-HS384+A192KW":
805
- case "PBES2-HS512+A256KW": {
806
- o = n || D(e);
807
- const { p2c: u, p2s: d } = i;
808
- ({ encryptedKey: a, ...s } = await Xe(t, r, o, u, d));
809
- break;
810
- }
811
- case "A128KW":
812
- case "A192KW":
813
- case "A256KW": {
814
- o = n || D(e), a = await z(t, r, o);
815
- break;
816
- }
817
- case "A128GCMKW":
818
- case "A192GCMKW":
819
- case "A256GCMKW": {
820
- o = n || D(e);
821
- const { iv: u } = i;
822
- ({ encryptedKey: a, ...s } = await lt(t, r, o, u));
823
- break;
824
- }
825
- default:
826
- throw new b('Invalid or unsupported "alg" (JWE Algorithm) header value');
827
- }
828
- return { cek: o, encryptedKey: a, parameters: s };
829
- }
830
- const pt = Symbol();
831
- class mt {
832
- constructor(e) {
833
- if (!(e instanceof Uint8Array))
834
- throw new TypeError("plaintext must be an instance of Uint8Array");
835
- this._plaintext = e;
836
- }
837
- setKeyManagementParameters(e) {
838
- if (this._keyManagementParameters)
839
- throw new TypeError("setKeyManagementParameters can only be called once");
840
- return this._keyManagementParameters = e, this;
841
- }
842
- setProtectedHeader(e) {
843
- if (this._protectedHeader)
844
- throw new TypeError("setProtectedHeader can only be called once");
845
- return this._protectedHeader = e, this;
846
- }
847
- setSharedUnprotectedHeader(e) {
848
- if (this._sharedUnprotectedHeader)
849
- throw new TypeError("setSharedUnprotectedHeader can only be called once");
850
- return this._sharedUnprotectedHeader = e, this;
851
- }
852
- setUnprotectedHeader(e) {
853
- if (this._unprotectedHeader)
854
- throw new TypeError("setUnprotectedHeader can only be called once");
855
- return this._unprotectedHeader = e, this;
856
- }
857
- setAdditionalAuthenticatedData(e) {
858
- return this._aad = e, this;
859
- }
860
- setContentEncryptionKey(e) {
861
- if (this._cek)
862
- throw new TypeError("setContentEncryptionKey can only be called once");
863
- return this._cek = e, this;
864
- }
865
- setInitializationVector(e) {
866
- if (this._iv)
867
- throw new TypeError("setInitializationVector can only be called once");
868
- return this._iv = e, this;
869
- }
870
- async encrypt(e, r) {
871
- if (!this._protectedHeader && !this._unprotectedHeader && !this._sharedUnprotectedHeader)
872
- throw new P("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");
873
- if (!Ne(this._protectedHeader, this._unprotectedHeader, this._sharedUnprotectedHeader))
874
- throw new P("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
875
- const n = {
876
- ...this._protectedHeader,
877
- ...this._unprotectedHeader,
878
- ...this._sharedUnprotectedHeader
879
- };
880
- if (ut(P, /* @__PURE__ */ new Map(), r == null ? void 0 : r.crit, this._protectedHeader, n), n.zip !== void 0)
881
- throw new b('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
882
- const { alg: i, enc: a } = n;
883
- if (typeof i != "string" || !i)
884
- throw new P('JWE "alg" (Algorithm) Header Parameter missing or invalid');
885
- if (typeof a != "string" || !a)
886
- throw new P('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');
887
- let s;
888
- if (this._cek && (i === "dir" || i === "ECDH-ES"))
889
- throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${i}`);
890
- let o;
891
- {
892
- let m;
893
- ({ cek: o, encryptedKey: s, parameters: m } = await ft(i, a, e, this._cek, this._keyManagementParameters)), m && (r && pt in r ? this._unprotectedHeader ? this._unprotectedHeader = { ...this._unprotectedHeader, ...m } : this.setUnprotectedHeader(m) : this._protectedHeader ? this._protectedHeader = { ...this._protectedHeader, ...m } : this.setProtectedHeader(m));
894
- }
895
- let c, u, d;
896
- this._protectedHeader ? u = O.encode(w(JSON.stringify(this._protectedHeader))) : u = O.encode(""), this._aad ? (d = w(this._aad), c = M(u, O.encode("."), O.encode(d))) : c = u;
897
- const { ciphertext: h, tag: p, iv: E } = await be(a, this._plaintext, o, this._iv, c), l = {
898
- ciphertext: w(h)
899
- };
900
- return E && (l.iv = w(E)), p && (l.tag = w(p)), s && (l.encrypted_key = w(s)), d && (l.aad = d), this._protectedHeader && (l.protected = ne.decode(u)), this._sharedUnprotectedHeader && (l.unprotected = this._sharedUnprotectedHeader), this._unprotectedHeader && (l.header = this._unprotectedHeader), l;
901
- }
902
- }
903
- class bt {
904
- constructor(e) {
905
- this._flattened = new mt(e);
906
- }
907
- setContentEncryptionKey(e) {
908
- return this._flattened.setContentEncryptionKey(e), this;
909
- }
910
- setInitializationVector(e) {
911
- return this._flattened.setInitializationVector(e), this;
912
- }
913
- setProtectedHeader(e) {
914
- return this._flattened.setProtectedHeader(e), this;
915
- }
916
- setKeyManagementParameters(e) {
917
- return this._flattened.setKeyManagementParameters(e), this;
918
- }
919
- async encrypt(e, r) {
920
- const n = await this._flattened.encrypt(e, r);
921
- return [n.protected, n.encrypted_key, n.iv, n.ciphertext, n.tag].join(".");
922
- }
923
- }
924
- const L = {
205
+ const y = {
925
206
  base: {
926
207
  ":disabled": {
927
208
  backgroundColor: "transparent"
928
209
  }
929
210
  }
930
- }, yt = "DOM Element was not found";
931
- var ee;
932
- (function(t) {
933
- t.NOT_COMPLETE = "NOT_COMPLETE", t.SCHEME_NOT_SUPPORTED = "SCHEME_NOT_SUPPORTED", t.LUHN_CHECK_FAILED = "LUHN_CHECK_FAILED", t.INVALID_EXPIRY_DATE = "INVALID_EXPIRY_DATE";
934
- })(ee || (ee = {}));
935
- const ye = (t) => t != null, wt = "v3.9.0";
936
- class x {
937
- constructor(e, r) {
211
+ }, k = "DOM Element was not found";
212
+ var O;
213
+ (function(i) {
214
+ i.NOT_COMPLETE = "NOT_COMPLETE", i.SCHEME_NOT_SUPPORTED = "SCHEME_NOT_SUPPORTED", i.LUHN_CHECK_FAILED = "LUHN_CHECK_FAILED", i.INVALID_EXPIRY_DATE = "INVALID_EXPIRY_DATE";
215
+ })(O || (O = {}));
216
+ const S = (i) => i != null, R = "v3.9.1";
217
+ class f {
218
+ constructor(e) {
938
219
  if (Object.defineProperty(this, "options", {
939
220
  enumerable: !0,
940
221
  configurable: !0,
@@ -955,16 +236,21 @@ class x {
955
236
  configurable: !0,
956
237
  writable: !0,
957
238
  value: { ready: [], blur: [], focus: [], keydown: [], change: [] }
239
+ }), Object.defineProperty(this, "key", {
240
+ enumerable: !0,
241
+ configurable: !0,
242
+ writable: !0,
243
+ value: ""
958
244
  }), Object.defineProperty(this, "update", {
959
245
  enumerable: !0,
960
246
  configurable: !0,
961
247
  writable: !0,
962
- value: async ({ ...n }) => {
963
- this.iframe && ye(n.height) && (this.iframe.height = n.height), this.iframePostMessage({
248
+ value: async ({ ...t }) => {
249
+ this.iframe && S(t.height) && (this.iframe.height = t.height), this.iframePostMessage({
964
250
  type: "update",
965
251
  data: {
966
- ...n,
967
- value: n.value ? this.putValue(n.value) ?? void 0 : void 0
252
+ ...t,
253
+ value: t.value ? this.putValue(t.value) ?? void 0 : void 0
968
254
  }
969
255
  });
970
256
  }
@@ -994,61 +280,42 @@ class x {
994
280
  configurable: !0,
995
281
  writable: !0,
996
282
  value: () => {
997
- var n;
998
- (n = this.iframe) == null || n.remove(), this.iframe = null;
283
+ var t;
284
+ (t = this.iframe) == null || t.remove(), this.iframe = null;
999
285
  }
1000
- }), this.IFRAME_BASE_URL = Et(wt), !this.IFRAME_BASE_URL)
286
+ }), this.IFRAME_BASE_URL = C(R), !this.IFRAME_BASE_URL)
1001
287
  throw new Error("IFRAME_BASE_URL not found");
1002
- r && F.set(this, { key: r });
1003
288
  }
1004
289
  mount(e) {
1005
- const r = typeof e == "string" ? document.querySelector(e) : e;
1006
- if (!r)
1007
- throw new Error(`${yt}: ${e}`);
1008
- r.innerHTML = `<iframe width="100%" height="29" src="${this.IFRAME_BASE_URL}?field=${this.type}&origin=${location.origin}"></iframe>`, this.iframe = r.querySelector("iframe");
1009
- const n = (i) => {
290
+ const t = typeof e == "string" ? document.querySelector(e) : e;
291
+ if (!t)
292
+ throw new Error(`${k}: ${e}`);
293
+ t.innerHTML = `<iframe width="100%" height="29" src="${this.IFRAME_BASE_URL}?field=${this.type}&origin=${location.origin}"></iframe>`, this.iframe = t.querySelector("iframe");
294
+ const r = (n) => {
1010
295
  var a;
1011
- if (!(i.source !== ((a = this.iframe) == null ? void 0 : a.contentWindow) || i.data.element !== this.type))
1012
- if (i.data.type === "change") {
1013
- const s = this.extractValue(i.data.data.value), o = { ...i.data.data };
1014
- delete o.value;
1015
- const c = F.get(this);
1016
- c && (c.value = s), this.emitEvent({
1017
- ...i.data,
1018
- data: o
1019
- });
1020
- } else
1021
- this.emitEvent(i.data);
296
+ n.source !== ((a = this.iframe) == null ? void 0 : a.contentWindow) || n.data.element !== this.type || this.emitEvent(n.data);
1022
297
  };
1023
- return window.addEventListener("message", n), new Promise((i) => {
1024
- this.on("ready", () => {
1025
- this.update(this.options), i();
298
+ return window.addEventListener("message", r), new Promise((n) => {
299
+ this.on("ready", (a) => {
300
+ this.key = a.key, this.update(this.options), n();
1026
301
  });
1027
302
  });
1028
303
  }
1029
- on(e, r) {
1030
- return this.subscriptions[e].push(r), {
1031
- unsubscribe: () => this.subscriptions[e].splice(this.subscriptions[e].indexOf(r), 1)
304
+ on(e, t) {
305
+ return this.subscriptions[e].push(t), {
306
+ unsubscribe: () => this.subscriptions[e].splice(this.subscriptions[e].indexOf(t), 1)
1032
307
  };
1033
308
  }
1034
- secureValue(e) {
1035
- const r = F.get(this);
1036
- return (r == null ? void 0 : r.key) !== e ? null : (r == null ? void 0 : r.value) ?? null;
1037
- }
1038
309
  emitEvent(e) {
1039
- var r;
1040
- (r = this.subscriptions[e.type]) == null || r.forEach((n) => n(e.data));
310
+ var t;
311
+ (t = this.subscriptions[e.type]) == null || t.forEach((r) => r(e.data));
1041
312
  }
1042
313
  iframePostMessage(e) {
1043
- var r, n;
1044
- (n = (r = this.iframe) == null ? void 0 : r.contentWindow) == null || n.postMessage(e, this.IFRAME_BASE_URL);
314
+ var t, r;
315
+ (r = (t = this.iframe) == null ? void 0 : t.contentWindow) == null || r.postMessage(e, this.IFRAME_BASE_URL);
1045
316
  }
1046
317
  }
1047
- function Et(t) {
1048
- return `https://${window.HG_IFRAME_HOST ?? "sdk.hellgate.io"}/web/${t}/iframe/`;
1049
- }
1050
- const F = /* @__PURE__ */ new Map();
1051
- class gt extends x {
318
+ class $ extends f {
1052
319
  constructor() {
1053
320
  super(...arguments), Object.defineProperty(this, "type", {
1054
321
  enumerable: !0,
@@ -1059,22 +326,22 @@ class gt extends x {
1059
326
  enumerable: !0,
1060
327
  configurable: !0,
1061
328
  writable: !0,
1062
- value: we
329
+ value: j
1063
330
  }), Object.defineProperty(this, "putValue", {
1064
331
  enumerable: !0,
1065
332
  configurable: !0,
1066
333
  writable: !0,
1067
- value: Ee
334
+ value: A
1068
335
  });
1069
336
  }
1070
337
  }
1071
- function we(t) {
1072
- return t ? Number(t) : null;
338
+ function j(i) {
339
+ return i ? Number(i) : null;
1073
340
  }
1074
- function Ee(t) {
1075
- return t ? t < 10 ? `0${t}` : String(t) : null;
341
+ function A(i) {
342
+ return i ? i < 10 ? `0${i}` : String(i) : null;
1076
343
  }
1077
- class At extends x {
344
+ class U extends f {
1078
345
  constructor() {
1079
346
  super(...arguments), Object.defineProperty(this, "type", {
1080
347
  enumerable: !0,
@@ -1085,38 +352,38 @@ class At extends x {
1085
352
  enumerable: !0,
1086
353
  configurable: !0,
1087
354
  writable: !0,
1088
- value: ge
355
+ value: H
1089
356
  }), Object.defineProperty(this, "putValue", {
1090
357
  enumerable: !0,
1091
358
  configurable: !0,
1092
359
  writable: !0,
1093
- value: Ae
360
+ value: D
1094
361
  });
1095
362
  }
1096
363
  }
1097
- function ge(t) {
1098
- if (!t)
364
+ function H(i) {
365
+ if (!i)
1099
366
  return null;
1100
- const e = Number(t);
367
+ const e = Number(i);
1101
368
  return e > 10 ? +`20${e}` : null;
1102
369
  }
1103
- function Ae(t) {
1104
- return t ? t >= 100 ? String(t).slice(-2) : String(t) : null;
370
+ function D(i) {
371
+ return i ? i >= 100 ? String(i).slice(-2) : String(i) : null;
1105
372
  }
1106
- function _e(t) {
1107
- const [e = null, r = null] = (t ?? "").split("/").map((n) => n.trim());
373
+ function T(i) {
374
+ const [e = null, t = null] = (i ?? "").split("/").map((r) => r.trim());
1108
375
  return {
1109
- month: we(e),
1110
- year: ge(r)
376
+ month: j(e),
377
+ year: H(t)
1111
378
  };
1112
379
  }
1113
- function Se(t) {
1114
- if (!t)
380
+ function M(i) {
381
+ if (!i)
1115
382
  return null;
1116
- const { month: e, year: r } = t;
1117
- return [Ee(e), Ae(r)].filter(ye).join(" / ");
383
+ const { month: e, year: t } = i;
384
+ return [A(e), D(t)].filter(S).join(" / ");
1118
385
  }
1119
- class _t extends x {
386
+ class V extends f {
1120
387
  constructor() {
1121
388
  super(...arguments), Object.defineProperty(this, "type", {
1122
389
  enumerable: !0,
@@ -1127,22 +394,22 @@ class _t extends x {
1127
394
  enumerable: !0,
1128
395
  configurable: !0,
1129
396
  writable: !0,
1130
- value: _e
397
+ value: T
1131
398
  }), Object.defineProperty(this, "putValue", {
1132
399
  enumerable: !0,
1133
400
  configurable: !0,
1134
401
  writable: !0,
1135
- value: Se
402
+ value: M
1136
403
  });
1137
404
  }
1138
405
  }
1139
- function Ce(t) {
1140
- return (t == null ? void 0 : t.replaceAll(" ", "")) ?? null;
406
+ function I(i) {
407
+ return (i == null ? void 0 : i.replaceAll(" ", "")) ?? null;
1141
408
  }
1142
- function St(t) {
1143
- return t;
409
+ function z(i) {
410
+ return i;
1144
411
  }
1145
- class Ct extends x {
412
+ class B extends f {
1146
413
  constructor() {
1147
414
  super(...arguments), Object.defineProperty(this, "type", {
1148
415
  enumerable: !0,
@@ -1153,16 +420,16 @@ class Ct extends x {
1153
420
  enumerable: !0,
1154
421
  configurable: !0,
1155
422
  writable: !0,
1156
- value: Ce
423
+ value: I
1157
424
  }), Object.defineProperty(this, "putValue", {
1158
425
  enumerable: !0,
1159
426
  configurable: !0,
1160
427
  writable: !0,
1161
- value: St
428
+ value: z
1162
429
  });
1163
430
  }
1164
431
  }
1165
- class Pt extends x {
432
+ class Y extends f {
1166
433
  constructor() {
1167
434
  super(...arguments), Object.defineProperty(this, "type", {
1168
435
  enumerable: !0,
@@ -1174,8 +441,8 @@ class Pt extends x {
1174
441
  configurable: !0,
1175
442
  writable: !0,
1176
443
  value: (e) => e ? {
1177
- number: e.cardNumber ? Ce(e.cardNumber) : null,
1178
- expiry_date: e.cardExpirationDate ? _e(e.cardExpirationDate) : null,
444
+ number: e.cardNumber ? I(e.cardNumber) : null,
445
+ expiry_date: e.cardExpirationDate ? T(e.cardExpirationDate) : null,
1179
446
  cvc: e.cardVerificationCode ?? null
1180
447
  } : null
1181
448
  }), Object.defineProperty(this, "putValue", {
@@ -1184,13 +451,13 @@ class Pt extends x {
1184
451
  writable: !0,
1185
452
  value: (e) => e ? {
1186
453
  cardNumber: e.number ? e.number : null,
1187
- cardExpirationDate: e.expiry_date ? Se(e.expiry_date) : null,
454
+ cardExpirationDate: e.expiry_date ? M(e.expiry_date) : null,
1188
455
  cardVerificationCode: e.cvc ?? null
1189
456
  } : null
1190
457
  });
1191
458
  }
1192
459
  }
1193
- class vt extends x {
460
+ class q extends f {
1194
461
  constructor() {
1195
462
  super(...arguments), Object.defineProperty(this, "type", {
1196
463
  enumerable: !0,
@@ -1210,7 +477,7 @@ class vt extends x {
1210
477
  });
1211
478
  }
1212
479
  }
1213
- class Pe extends x {
480
+ class K extends f {
1214
481
  constructor() {
1215
482
  super(...arguments), Object.defineProperty(this, "type", {
1216
483
  enumerable: !0,
@@ -1230,46 +497,48 @@ class Pe extends x {
1230
497
  });
1231
498
  }
1232
499
  }
1233
- function v(t, e, r) {
1234
- switch (t) {
500
+ function b(i, e) {
501
+ switch (i) {
1235
502
  case "card":
1236
- return new Pt(e, r);
503
+ return new Y(e);
1237
504
  case "cardNumber":
1238
- return new Ct(e, r);
505
+ return new B(e);
1239
506
  case "cardExpirationDate":
1240
- return new _t(e, r);
507
+ return new V(e);
1241
508
  case "cardExpirationMonth":
1242
- return new gt(e, r);
509
+ return new $(e);
1243
510
  case "cardExpirationYear":
1244
- return new At(e, r);
511
+ return new U(e);
1245
512
  case "cardVerificationCode":
1246
- return new vt(e, r);
513
+ return new q(e);
1247
514
  case "text":
1248
- return new Pe(e, r);
515
+ return new K(e);
1249
516
  default:
1250
- ASSERT_EXHAUSTIVE(t);
517
+ ASSERT_EXHAUSTIVE(i);
1251
518
  }
1252
519
  }
1253
- function Ot() {
1254
- return Date.now().toString(36) + Math.random().toString(36).slice(2);
1255
- }
1256
- function te(t) {
520
+ function P(i) {
1257
521
  return [
1258
- t.issuer_identification_number,
1259
- "".padEnd(t.account_number_length - t.issuer_identification_number.length - t.account_number_last_four.length, "*"),
1260
- t.account_number_last_four
522
+ i.issuer_identification_number,
523
+ "".padEnd(i.account_number_length - i.issuer_identification_number.length - i.account_number_last_four.length, "*"),
524
+ i.account_number_last_four
1261
525
  ].join(" ");
1262
526
  }
1263
- class q {
1264
- static async init(e) {
1265
- return new q(e);
527
+ class w {
528
+ static async init(e, t) {
529
+ return new w(e, t);
1266
530
  }
1267
- constructor(e) {
531
+ constructor(e, t) {
1268
532
  Object.defineProperty(this, "session", {
1269
533
  enumerable: !0,
1270
534
  configurable: !0,
1271
535
  writable: !0,
1272
536
  value: e
537
+ }), Object.defineProperty(this, "coordinator", {
538
+ enumerable: !0,
539
+ configurable: !0,
540
+ writable: !0,
541
+ value: t
1273
542
  }), Object.defineProperty(this, "state", {
1274
543
  enumerable: !0,
1275
544
  configurable: !0,
@@ -1303,18 +572,15 @@ class q {
1303
572
  var s;
1304
573
  if (this.hasFormElements())
1305
574
  throw new Error("Form elements can't be initialized twice. You can call `reset()` method or create new Hellgate client.");
1306
- const n = K.get(this);
1307
- if (!n)
1308
- throw new Error("Secure key not found");
1309
- const i = C({
575
+ const n = h({
1310
576
  disabled: !1,
1311
577
  autocomplete: "on",
1312
- style: { ...L }
578
+ style: { ...y }
1313
579
  }, r);
1314
580
  if (this.session.isNextAction("refresh_security_code") && ((s = this.session.state) != null && s.data)) {
1315
581
  const o = this.session.state.data;
1316
- i.cvcOnly = !0, i.value = {
1317
- number: te(o),
582
+ n.cvcOnly = !0, n.value = {
583
+ number: P(o),
1318
584
  expiry_date: {
1319
585
  month: (o == null ? void 0 : o.expiry_month) ?? null,
1320
586
  year: (o == null ? void 0 : o.expiry_year) ?? null
@@ -1322,7 +588,7 @@ class q {
1322
588
  cvc: null
1323
589
  };
1324
590
  }
1325
- const a = v("card", i, n);
591
+ const a = b("card", n);
1326
592
  return this.cardElements.card = {
1327
593
  element: a,
1328
594
  state: this.createFieldDefaultState()
@@ -1333,16 +599,13 @@ class q {
1333
599
  configurable: !0,
1334
600
  writable: !0,
1335
601
  value: (r = {}) => {
1336
- const n = K.get(this);
1337
- if (!n)
1338
- throw new Error("Secure key not found");
1339
- const i = {
602
+ const n = {
1340
603
  disabled: !1,
1341
604
  autocomplete: "on",
1342
- style: { ...L }
1343
- }, a = v("text", {
1344
- ...C(i, { ...r })
1345
- }, n);
605
+ style: { ...y }
606
+ }, a = b("text", {
607
+ ...h(n, { ...r })
608
+ });
1346
609
  return this.textElements.push(a), a;
1347
610
  }
1348
611
  }), Object.defineProperty(this, "tokenize", {
@@ -1350,25 +613,20 @@ class q {
1350
613
  configurable: !0,
1351
614
  writable: !0,
1352
615
  value: async (r) => {
1353
- var o, c;
1354
- if (((o = this.session.state) == null ? void 0 : o.next_action) !== "tokenize_card")
1355
- throw new Error(`The session's next_action='${(c = this.session.state) == null ? void 0 : c.next_action}'. tokenize() is available only if next_action='tokenize_card'`);
1356
- const n = this.getFormValue(), i = this.extractAdditionalData(r);
1357
- if (!n)
1358
- throw new Error("Form elements must be initialized before tokenization");
1359
- const a = this.getCardDataValidationError();
1360
- if (a)
1361
- throw a;
1362
- if (!n.number || !n.expiration_month || !n.expiration_year || !n.cvc)
1363
- throw new Error("Card data is not complete");
1364
- const s = this.session.state.data;
1365
- return this.encryptCardData({
1366
- account_number: n.number,
1367
- expiry_month: n.expiration_month,
1368
- expiry_year: n.expiration_year,
1369
- security_code: n.cvc,
1370
- additional_data: i
1371
- }, s.jwk);
616
+ var a, s;
617
+ if (((a = this.session.state) == null ? void 0 : a.next_action) !== "tokenize_card")
618
+ throw new Error(`The session's next_action='${(s = this.session.state) == null ? void 0 : s.next_action}'. tokenize() is available only if next_action='tokenize_card'`);
619
+ const n = this.getCardDataValidationError();
620
+ if (n)
621
+ throw n;
622
+ return this.coordinator.postMessage({
623
+ type: "card:tokenize",
624
+ additionalData: this.serializeAdditionalData(r)
625
+ }), new Promise((o) => {
626
+ this.coordinator.onMessage("card:tokenize:response", (l) => {
627
+ o(l.success ? l.result : null);
628
+ });
629
+ });
1372
630
  }
1373
631
  }), Object.defineProperty(this, "onStateChange", {
1374
632
  enumerable: !0,
@@ -1389,7 +647,7 @@ class q {
1389
647
  configurable: !0,
1390
648
  writable: !0,
1391
649
  value: () => {
1392
- Object.values(this.cardElements).forEach((r) => r == null ? void 0 : r.element.unmount()), this.textElements.forEach((r) => r == null ? void 0 : r.unmount()), this.cardElements = {}, this.textElements = [];
650
+ Object.values(this.cardElements).forEach((r) => r == null ? void 0 : r.element.unmount()), this.textElements.forEach((r) => r == null ? void 0 : r.unmount()), this.cardElements = {}, this.textElements = [], this.state = this.createFieldDefaultState();
1393
651
  }
1394
652
  }), Object.defineProperty(this, "dispose", {
1395
653
  enumerable: !0,
@@ -1405,187 +663,130 @@ class q {
1405
663
  value: async (r = {}) => {
1406
664
  if (!this.hasFormElements())
1407
665
  throw new Error("Card form must be initialized and completed before processing");
666
+ const n = this.getCardDataValidationError();
667
+ if (n)
668
+ throw n;
1408
669
  if (this.session.isNextAction("refresh_security_code"))
1409
670
  return this.refreshSecurityCode();
1410
671
  this.disableFormElements(!0);
1411
672
  try {
1412
- const n = await this.tokenize(r);
1413
- if (!n)
1414
- throw new Error("Tokenization failed");
1415
- return await this.session.completeAction({
1416
- action: "tokenize_card",
1417
- result: n
673
+ return this.coordinator.postMessage({
674
+ type: "card:process",
675
+ additionalData: this.serializeAdditionalData(r)
676
+ }), new Promise((a, s) => {
677
+ this.coordinator.onMessage("card:process:response", (o) => {
678
+ o.result && o.success ? a(o.result) : s(new Error(o.error));
679
+ });
1418
680
  });
1419
- } catch (n) {
1420
- throw this.disableFormElements(!1), n;
681
+ } catch (a) {
682
+ throw this.disableFormElements(!1), a;
1421
683
  }
1422
684
  }
1423
- }), K.set(this, Ot()), this.cvcOnlyEnabled = this.session.isNextAction("refresh_security_code");
685
+ }), this.cvcOnlyEnabled = this.session.isNextAction("refresh_security_code");
1424
686
  }
1425
687
  createFormFields(e = {}) {
1426
- var u, d;
688
+ var l, c;
1427
689
  if (this.hasFormElements())
1428
690
  throw new Error("Form elements can't be initialized twice. You can call `reset()` method or create new Hellgate client.");
1429
- const r = K.get(this);
1430
- if (!r)
1431
- throw new Error("Secure key not found");
1432
- const n = {
691
+ const t = {
1433
692
  disabled: this.cvcOnlyEnabled,
1434
693
  autocomplete: "on",
1435
- style: { ...L }
1436
- }, { cardNumber: i = {}, securityCode: a = {}, ...s } = e, o = v("cardNumber", {
1437
- ...C(n, {
1438
- ...s,
1439
- ...i,
694
+ style: { ...y }
695
+ }, { cardNumber: r = {}, securityCode: n = {}, ...a } = e, s = b("cardNumber", {
696
+ ...h(t, {
697
+ ...a,
698
+ ...r,
1440
699
  cvcOnly: this.cvcOnlyEnabled,
1441
- value: this.session.isNextAction("refresh_security_code") && ((u = this.session.state) != null && u.data) ? te(this.session.state.data) : null
700
+ value: this.session.isNextAction("refresh_security_code") && ((l = this.session.state) != null && l.data) ? P(this.session.state.data) : null
1442
701
  })
1443
- }, r), c = v("cardVerificationCode", {
1444
- ...C({
1445
- ...n,
702
+ }), o = b("cardVerificationCode", {
703
+ ...h({
704
+ ...t,
1446
705
  disabled: !1,
1447
706
  autofocus: this.cvcOnlyEnabled
1448
707
  }, {
1449
- ...s,
1450
- ...a
708
+ ...a,
709
+ ...n
1451
710
  })
1452
- }, r);
1453
- if (o.on("change", (h) => {
1454
- const p = h.cardBrand;
1455
- c.update({ cardType: p });
711
+ });
712
+ if (s.on("change", (d) => {
713
+ const u = d.cardBrand;
714
+ o.update({ cardType: u });
1456
715
  }), this.cardElements = {
1457
716
  cardNumber: {
1458
- element: o,
717
+ element: s,
1459
718
  state: this.createFieldDefaultState()
1460
719
  },
1461
720
  cardVerificationCode: {
1462
- element: c,
721
+ element: o,
1463
722
  state: this.createFieldDefaultState()
1464
723
  }
1465
724
  }, this.addElementStateListener("cardNumber"), this.addElementStateListener("cardVerificationCode"), e.expiryDateElement === "separate") {
1466
- const { expiryMonth: h = {}, expiryYear: p = {} } = e, E = v("cardExpirationMonth", {
1467
- ...C(n, {
1468
- ...s,
1469
- ...h
725
+ const { expiryMonth: d = {}, expiryYear: u = {} } = e, _ = b("cardExpirationMonth", {
726
+ ...h(t, {
727
+ ...a,
728
+ ...d
1470
729
  })
1471
- }, r), l = v("cardExpirationYear", {
1472
- ...C(n, {
1473
- ...s,
1474
- ...p
730
+ }), v = b("cardExpirationYear", {
731
+ ...h(t, {
732
+ ...a,
733
+ ...u
1475
734
  })
1476
- }, r);
1477
- return l.on("change", () => {
1478
- const m = y(this, l);
1479
- E.update({
1480
- expiryYear: m ? String(y(this, l)) : void 0
1481
- });
1482
- }), this.cardElements.cardExpirationMonth = {
1483
- element: E,
735
+ });
736
+ return this.cardElements.cardExpirationMonth = {
737
+ element: _,
1484
738
  state: this.createFieldDefaultState()
1485
739
  }, this.cardElements.cardExpirationYear = {
1486
- element: l,
740
+ element: v,
1487
741
  state: this.createFieldDefaultState()
1488
- }, this.addElementStateListener("cardExpirationMonth"), this.addElementStateListener("cardExpirationYear"), { cardNumber: o, expiryMonth: E, expiryYear: l, securityCode: c };
742
+ }, this.addElementStateListener("cardExpirationMonth"), this.addElementStateListener("cardExpirationYear"), { cardNumber: s, expiryMonth: _, expiryYear: v, securityCode: o };
1489
743
  } else {
1490
- const { expiryDate: h = {} } = e, p = v("cardExpirationDate", {
1491
- ...C(n, {
1492
- ...s,
1493
- ...h,
1494
- value: this.session.isNextAction("refresh_security_code") && ((d = this.session.state) != null && d.data) ? {
744
+ const { expiryDate: d = {} } = e, u = b("cardExpirationDate", {
745
+ ...h(t, {
746
+ ...a,
747
+ ...d,
748
+ value: this.session.isNextAction("refresh_security_code") && ((c = this.session.state) != null && c.data) ? {
1495
749
  month: this.session.state.data.expiry_month,
1496
750
  year: this.session.state.data.expiry_year
1497
751
  } : null
1498
752
  })
1499
- }, r);
753
+ });
1500
754
  return this.cardElements.cardExpirationDate = {
1501
- element: p,
755
+ element: u,
1502
756
  state: this.createFieldDefaultState()
1503
- }, this.addElementStateListener("cardExpirationDate"), { cardNumber: o, expiryDate: p, securityCode: c };
757
+ }, this.addElementStateListener("cardExpirationDate"), { cardNumber: s, expiryDate: u, securityCode: o };
1504
758
  }
1505
759
  }
1506
760
  async refreshSecurityCode() {
1507
- const e = this.getFormValue();
1508
- if (!(e != null && e.cvc))
1509
- throw new Error("cvc field was not filled");
1510
- if (!this.session.isNextAction("refresh_security_code") || !this.session.state)
1511
- throw new Error("refreshSecurityCode() is available only if next_action=refresh_security_code");
1512
- this.disableFormElements(!0);
1513
- const r = await this.encryptCardData({ security_code: e.cvc }, this.session.state.data.jwk);
1514
- return this.session.completeAction({
1515
- action: "refresh_security_code",
1516
- result: { ...r }
1517
- }).catch((n) => {
1518
- if (this.disableFormElements(!1), n instanceof Error)
1519
- throw n;
1520
- return { status: "failure", data: n };
761
+ return this.coordinator.postMessage({
762
+ type: "card:refresh_security_code"
763
+ }), new Promise((e, t) => {
764
+ this.coordinator.onMessage("card:refresh_security_code:response", (r) => {
765
+ r.result ? e(r.result) : t(new Error(r.error));
766
+ });
1521
767
  });
1522
768
  }
1523
- getFormValue() {
1524
- var c, u, d, h, p, E;
1525
- const { card: e, cardNumber: r, cardExpirationDate: n, cardExpirationMonth: i, cardExpirationYear: a, cardVerificationCode: s } = this.cardElements;
1526
- let o;
1527
- if (e) {
1528
- const l = y(this, e.element);
1529
- o = {
1530
- number: (l == null ? void 0 : l.number) ?? null,
1531
- expiration_month: ((c = l == null ? void 0 : l.expiry_date) == null ? void 0 : c.month) ?? null,
1532
- expiration_year: ((u = l == null ? void 0 : l.expiry_date) == null ? void 0 : u.year) ?? null,
1533
- cvc: (l == null ? void 0 : l.cvc) ?? null
1534
- };
1535
- }
1536
- if (r && s && (n && (o = {
1537
- number: ((d = y(this, r.element)) == null ? void 0 : d.replaceAll(" ", "")) ?? null,
1538
- expiration_month: ((h = y(this, n.element)) == null ? void 0 : h.month) ?? null,
1539
- expiration_year: ((p = y(this, n.element)) == null ? void 0 : p.year) ?? null,
1540
- cvc: y(this, s.element)
1541
- }), i && a)) {
1542
- const l = y(this, i.element), m = y(this, a.element);
1543
- o = {
1544
- number: ((E = y(this, r.element)) == null ? void 0 : E.replaceAll(" ", "")) ?? null,
1545
- expiration_month: l ? Number(l) : null,
1546
- expiration_year: m ? Number(m) : null,
1547
- cvc: y(this, s.element)
1548
- };
1549
- }
1550
- return o;
1551
- }
1552
769
  hasFormElements() {
1553
770
  return !!Object.keys(this.cardElements).length;
1554
771
  }
1555
772
  disableFormElements(e) {
1556
- Object.values(this.cardElements).forEach(({ element: r }) => {
1557
- r.update({ disabled: e });
1558
- });
1559
- }
1560
- extractAdditionalData({ cardholder_name: e, billing_address: r = {} }) {
1561
- return re({
1562
- cardholder_name: H(this, e),
1563
- billing_address: {
1564
- line1: H(this, r.line1),
1565
- line2: H(this, r.line2),
1566
- line3: H(this, r.line3),
1567
- city: H(this, r.city),
1568
- postal_code: H(this, r.postal_code)
1569
- }
773
+ Object.values(this.cardElements).forEach(({ element: t }) => {
774
+ t.update({ disabled: e });
1570
775
  });
1571
776
  }
1572
- async encryptCardData(e, r) {
1573
- const n = await nt(r, "RSA-OAEP"), i = JSON.stringify(e), a = new TextEncoder().encode(i);
1574
- return { enc_payload: await new bt(a).setProtectedHeader({ alg: "RSA-OAEP", enc: "A256GCM" }).encrypt(n) };
1575
- }
1576
777
  addElementStateListener(e) {
1577
- const r = this.cardElements[e];
1578
- r && r.element.on("change", (n) => {
1579
- r.state = n, this.updateFormState();
778
+ const t = this.cardElements[e];
779
+ t && t.element.on("change", (r) => {
780
+ t.state = r, this.updateFormState();
1580
781
  });
1581
782
  }
1582
783
  updateFormState() {
1583
784
  const e = this.cvcOnlyEnabled && this.cardElements.cardVerificationCode ? [this.cardElements.cardVerificationCode] : Object.values(this.cardElements);
1584
- e.length ? this.state = e.reduce((r, { state: n }) => (r.valid = !!r.valid && !!n.valid, r.complete = !!r.complete && !!n.complete, r.empty = !!r.empty && !!n.empty, r.error = r.error || n.error, r.errorCode = r.errorCode || n.errorCode, r), {
785
+ e.length ? this.state = e.reduce((t, { state: r }) => (t.valid = !!t.valid && !!r.valid, t.complete = !!t.complete && !!r.complete, t.empty = !!t.empty && !!r.empty, t.error = t.error || r.error, t.errorCode = t.errorCode || r.errorCode, t), {
1585
786
  valid: !0,
1586
787
  complete: !0,
1587
788
  empty: !0
1588
- }) : this.state = this.createFieldDefaultState(), this.stateChangeHandlers.forEach((r) => r(this.state));
789
+ }) : this.state = this.createFieldDefaultState(), this.stateChangeHandlers.forEach((t) => t(this.state));
1589
790
  }
1590
791
  createFieldDefaultState() {
1591
792
  return {
@@ -1594,6 +795,18 @@ class q {
1594
795
  valid: !1
1595
796
  };
1596
797
  }
798
+ serializeAdditionalData({ cardholder_name: e, billing_address: t = {} }) {
799
+ return x({
800
+ cardholder_name: m(e),
801
+ billing_address: {
802
+ line1: m(t.line1),
803
+ line2: m(t.line2),
804
+ line3: m(t.line3),
805
+ city: m(t.city),
806
+ postal_code: m(t.postal_code)
807
+ }
808
+ });
809
+ }
1597
810
  getCardDataValidationError() {
1598
811
  if (!this.state.complete)
1599
812
  return new Error(this.state.error ?? "Card data is not complete");
@@ -1601,22 +814,96 @@ class q {
1601
814
  return new Error(`Card data is not valid. ${this.state.error}`);
1602
815
  }
1603
816
  }
1604
- const K = /* @__PURE__ */ new Map();
1605
- function y(t, e) {
1606
- const r = K.get(t);
1607
- return r ? e.secureValue(r) : null;
817
+ function m(i) {
818
+ if (typeof i == "string")
819
+ return i;
820
+ if (i != null && i.key)
821
+ return { key: i.key };
1608
822
  }
1609
- function H(t, e) {
1610
- const r = K.get(t);
1611
- return e instanceof Pe && r ? y(t, e) ?? void 0 : e;
823
+ const W = "v3.9.1";
824
+ class G {
825
+ constructor() {
826
+ if (Object.defineProperty(this, "iframe", {
827
+ enumerable: !0,
828
+ configurable: !0,
829
+ writable: !0,
830
+ value: null
831
+ }), Object.defineProperty(this, "iframeBaseUrl", {
832
+ enumerable: !0,
833
+ configurable: !0,
834
+ writable: !0,
835
+ value: void 0
836
+ }), Object.defineProperty(this, "messageHandler", {
837
+ enumerable: !0,
838
+ configurable: !0,
839
+ writable: !0,
840
+ value: null
841
+ }), Object.defineProperty(this, "init", {
842
+ enumerable: !0,
843
+ configurable: !0,
844
+ writable: !0,
845
+ value: async (e, t, r) => (window.fetchMocker = { a: 1 }, new Promise((n, a) => {
846
+ r == null || r.signal.addEventListener("abort", () => {
847
+ const l = new Error("Coordinator init aborted");
848
+ l.name = "AbortError", a(l), this.dispose();
849
+ });
850
+ const s = document.createElement("div");
851
+ s.setAttribute("style", "position:absolute;width:0;height:0;overflow:hidden;"), s.setAttribute("data-hg-coordinator", ""), document.body.appendChild(s);
852
+ const o = `${this.iframeBaseUrl}?type=coordinator&sessionId=${e}&apiBaseUrl=${t}&origin=${encodeURIComponent(location.origin)}`;
853
+ if (s.innerHTML = `<iframe src="${o}" width="0" height="0" style="border:none;" tabindex="-1" aria-hidden="true"></iframe>`, this.iframe = s.querySelector("iframe"), !this.iframe) {
854
+ a(new Error("Failed to create coordinator iframe"));
855
+ return;
856
+ }
857
+ this.messageHandler = (l) => {
858
+ var c, d, u;
859
+ if (l.source === ((c = this.iframe) == null ? void 0 : c.contentWindow)) {
860
+ if (((d = l.data) == null ? void 0 : d.type) === "coordinator:ready") {
861
+ n();
862
+ return;
863
+ }
864
+ if (((u = l.data) == null ? void 0 : u.type) === "coordinator:error") {
865
+ a(l.data.error);
866
+ return;
867
+ }
868
+ }
869
+ }, window.addEventListener("message", this.messageHandler), this.iframe.addEventListener("error", () => {
870
+ a(new Error("Coordinator iframe failed to load"));
871
+ });
872
+ }))
873
+ }), this.iframeBaseUrl = C(W), !this.iframeBaseUrl)
874
+ throw new Error("IFRAME_BASE_URL not found");
875
+ }
876
+ /**
877
+ * Send a command to the coordinator iframe.
878
+ * Only commands and configuration — never card data.
879
+ */
880
+ postMessage(e) {
881
+ var t, r;
882
+ (r = (t = this.iframe) == null ? void 0 : t.contentWindow) == null || r.postMessage(e, this.iframeBaseUrl);
883
+ }
884
+ onMessage(e, t) {
885
+ window.addEventListener("message", (r) => {
886
+ var n, a;
887
+ r.source === ((n = this.iframe) == null ? void 0 : n.contentWindow) && ((a = r.data) == null ? void 0 : a.type) === e && t(r.data);
888
+ });
889
+ }
890
+ /**
891
+ * Clean up the coordinator iframe and all associated resources.
892
+ */
893
+ dispose() {
894
+ var t;
895
+ this.postMessage({ type: "coordinator:dispose" }), this.messageHandler && (window.removeEventListener("message", this.messageHandler), this.messageHandler = null);
896
+ const e = (t = this.iframe) == null ? void 0 : t.parentElement;
897
+ this.iframe = null, e == null || e.remove();
898
+ }
1612
899
  }
1613
- class xt {
1614
- constructor(e = "https://api.hellgate.io", r = new AbortController()) {
900
+ class X {
901
+ constructor(e = "https://api.hellgate.io", t = new AbortController()) {
1615
902
  Object.defineProperty(this, "abortCtrl", {
1616
903
  enumerable: !0,
1617
904
  configurable: !0,
1618
905
  writable: !0,
1619
- value: r
906
+ value: t
1620
907
  }), Object.defineProperty(this, "baseUrl", {
1621
908
  enumerable: !0,
1622
909
  configurable: !0,
@@ -1627,26 +914,26 @@ class xt {
1627
914
  getSession(e) {
1628
915
  return fetch(`${this.baseUrl}/sessions/${e}`, {
1629
916
  signal: this.abortCtrl.signal
1630
- }).then((r) => V(r));
917
+ }).then((t) => E(t));
1631
918
  }
1632
- completeAction(e, r) {
919
+ completeAction(e, t) {
1633
920
  return fetch(`${this.baseUrl}/sessions/${e}/complete-action`, {
1634
921
  method: "POST",
1635
922
  headers: {
1636
923
  "Content-Type": "application/json"
1637
924
  },
1638
925
  mode: "cors",
1639
- body: JSON.stringify(r),
926
+ body: JSON.stringify(t),
1640
927
  signal: this.abortCtrl.signal
1641
- }).then((n) => V(n));
928
+ }).then((r) => E(r));
1642
929
  }
1643
930
  cancelAll() {
1644
931
  this.abortCtrl.abort();
1645
932
  }
1646
933
  }
1647
- const Ht = 2e3;
1648
- class Kt {
1649
- constructor(e, r) {
934
+ const J = 2e3;
935
+ class Q {
936
+ constructor(e, t) {
1650
937
  Object.defineProperty(this, "id", {
1651
938
  enumerable: !0,
1652
939
  configurable: !0,
@@ -1656,7 +943,7 @@ class Kt {
1656
943
  enumerable: !0,
1657
944
  configurable: !0,
1658
945
  writable: !0,
1659
- value: r
946
+ value: t
1660
947
  }), Object.defineProperty(this, "state", {
1661
948
  enumerable: !0,
1662
949
  configurable: !0,
@@ -1681,47 +968,47 @@ class Kt {
1681
968
  enumerable: !0,
1682
969
  configurable: !0,
1683
970
  writable: !0,
1684
- value: async () => new Promise((n, i) => {
971
+ value: async () => new Promise((r, n) => {
1685
972
  const a = this.onStateChange((s) => {
1686
- s.next_action !== "wait" && (n(s), a());
973
+ s.next_action !== "wait" && (r(s), a());
1687
974
  });
1688
975
  this.updateSessionState().catch((s) => {
1689
- s instanceof Response && s.status === 404 && i(new Error(`Session ${this.id} doesn't exist or has expired`)), i(s);
976
+ s instanceof Response && s.status === 404 && n(new Error(`Session ${this.id} doesn't exist or has expired`)), n(s);
1690
977
  });
1691
978
  })
1692
979
  }), Object.defineProperty(this, "onStateChange", {
1693
980
  enumerable: !0,
1694
981
  configurable: !0,
1695
982
  writable: !0,
1696
- value: (n) => (this.stateChangeHandlers.push(n), this.state && n(this.state), () => this.stateChangeHandlers = this.stateChangeHandlers.filter((i) => i !== n))
983
+ value: (r) => (this.stateChangeHandlers.push(r), this.state && r(this.state), () => this.stateChangeHandlers = this.stateChangeHandlers.filter((n) => n !== r))
1697
984
  }), Object.defineProperty(this, "onClose", {
1698
985
  enumerable: !0,
1699
986
  configurable: !0,
1700
987
  writable: !0,
1701
- value: (n) => {
1702
- var i;
1703
- return ((i = this.state) == null ? void 0 : i.next_action) === null ? (n(B(this.state)), () => {
1704
- }) : (this.onCloseHandlers.push(n), () => this.onCloseHandlers = this.onCloseHandlers.filter((a) => a !== n));
988
+ value: (r) => {
989
+ var n;
990
+ return ((n = this.state) == null ? void 0 : n.next_action) === null ? (r(g(this.state)), () => {
991
+ }) : (this.onCloseHandlers.push(r), () => this.onCloseHandlers = this.onCloseHandlers.filter((a) => a !== r));
1705
992
  }
1706
993
  }), Object.defineProperty(this, "completeAction", {
1707
994
  enumerable: !0,
1708
995
  configurable: !0,
1709
996
  writable: !0,
1710
- value: async (n) => {
1711
- const i = this.state;
997
+ value: async (r) => {
998
+ const n = this.state;
1712
999
  return new Promise((a, s) => {
1713
- const o = this.onStateChange((c) => {
1714
- c.next_action !== (i == null ? void 0 : i.next_action) && c.next_action === null && (a(B(c)), o());
1000
+ const o = this.onStateChange((l) => {
1001
+ l.next_action !== (n == null ? void 0 : n.next_action) && l.next_action === null && (a(g(l)), o());
1715
1002
  });
1716
- this.api.completeAction(this.id, n).then((c) => this.newStateHandle(c, s)).catch(async (c) => s(await Tt(c)));
1003
+ this.api.completeAction(this.id, r).then((l) => this.newStateHandle(l, s)).catch(async (l) => s(await Z(l)));
1717
1004
  });
1718
1005
  }
1719
1006
  }), Object.defineProperty(this, "completeSession", {
1720
1007
  enumerable: !0,
1721
1008
  configurable: !0,
1722
1009
  writable: !0,
1723
- value: (n) => {
1724
- this.onCloseHandlers.forEach((i) => i(n)), this.stop();
1010
+ value: (r) => {
1011
+ this.onCloseHandlers.forEach((n) => n(r)), this.stop();
1725
1012
  }
1726
1013
  }), Object.defineProperty(this, "dispose", {
1727
1014
  enumerable: !0,
@@ -1733,46 +1020,51 @@ class Kt {
1733
1020
  });
1734
1021
  }
1735
1022
  isNextAction(e) {
1736
- var r;
1737
- return ((r = this.state) == null ? void 0 : r.next_action) === e;
1023
+ var t;
1024
+ return ((t = this.state) == null ? void 0 : t.next_action) === e;
1738
1025
  }
1739
1026
  stop() {
1740
1027
  window.clearTimeout(this.pollingTimer), this.stateChangeHandlers = [], this.onCloseHandlers = [];
1741
1028
  }
1742
1029
  async updateSessionState(e) {
1743
- const r = await this.api.getSession(this.id);
1744
- this.newStateHandle(r, e);
1030
+ const t = await this.api.getSession(this.id);
1031
+ this.newStateHandle(t, e);
1745
1032
  }
1746
- newStateHandle(e, r) {
1747
- var n;
1033
+ newStateHandle(e, t) {
1034
+ var r;
1748
1035
  switch (!e.next_action && e.status && (e.next_action = null), e.next_action) {
1749
1036
  case "wait": {
1750
- window.clearTimeout(this.pollingTimer), this.pollingTimer = window.setTimeout(() => this.updateSessionState(r).catch((i) => {
1751
- i instanceof Response && i.status === 404 && (r == null || r(new Error(`Session ${this.id} has expired`)));
1752
- }), Ht);
1037
+ window.clearTimeout(this.pollingTimer), this.pollingTimer = window.setTimeout(() => this.updateSessionState(t).catch((n) => {
1038
+ n instanceof Response && n.status === 404 && (t == null || t(new Error(`Session ${this.id} has expired`)));
1039
+ }), J);
1753
1040
  break;
1754
1041
  }
1755
1042
  }
1756
- e.next_action !== ((n = this.state) == null ? void 0 : n.next_action) && this.stateChangeHandlers.forEach((i) => i(e)), e.next_action === null && this.completeSession(B(e)), this.state = e;
1043
+ e.next_action !== ((r = this.state) == null ? void 0 : r.next_action) && this.stateChangeHandlers.forEach((n) => n(e)), e.next_action === null && this.completeSession(g(e)), this.state = e;
1757
1044
  }
1758
1045
  }
1759
- async function Tt(t) {
1760
- return !t.ok && t.status >= 400 && t.status <= 500 ? t.json() : t;
1046
+ async function Z(i) {
1047
+ return !i.ok && i.status >= 400 && i.status <= 500 ? i.json() : i;
1761
1048
  }
1762
- function B(t) {
1763
- const e = { ...t };
1049
+ function g(i) {
1050
+ const e = { ...i };
1764
1051
  return delete e.next_action, e;
1765
1052
  }
1766
- const Dt = {
1053
+ const ee = {
1767
1054
  base_url: "https://api.hellgate.io"
1768
1055
  };
1769
- class ve {
1770
- constructor(e, r) {
1056
+ class L {
1057
+ constructor(e, t, r) {
1771
1058
  Object.defineProperty(this, "session", {
1772
1059
  enumerable: !0,
1773
1060
  configurable: !0,
1774
1061
  writable: !0,
1775
1062
  value: e
1063
+ }), Object.defineProperty(this, "coordinator", {
1064
+ enumerable: !0,
1065
+ configurable: !0,
1066
+ writable: !0,
1067
+ value: t
1776
1068
  }), Object.defineProperty(this, "paymentFlowHandlers", {
1777
1069
  enumerable: !0,
1778
1070
  configurable: !0,
@@ -1783,7 +1075,7 @@ class ve {
1783
1075
  configurable: !0,
1784
1076
  writable: !0,
1785
1077
  value: () => {
1786
- this.session.dispose(), Object.values(this.paymentFlowHandlers).forEach((n) => n == null ? void 0 : n.dispose());
1078
+ this.session.dispose(), this.coordinator.dispose(), Object.values(this.paymentFlowHandlers).forEach((n) => n == null ? void 0 : n.dispose());
1787
1079
  }
1788
1080
  }), Object.defineProperty(this, "onSessionComplete", {
1789
1081
  enumerable: !0,
@@ -1797,46 +1089,47 @@ class ve {
1797
1089
  use(e) {
1798
1090
  return this.paymentFlowHandlers[e];
1799
1091
  }
1800
- static async init(e, r = {}) {
1801
- const { session: n, cardHandler: i, handler3DS: a } = await this.initHandlers(e, r);
1802
- return new ve(n, {
1803
- CARD: i,
1804
- "3DS": a
1092
+ static async init(e, t = {}) {
1093
+ const { session: r, coordinator: n, cardHandler: a, handler3DS: s } = await this.initHandlers(e, t);
1094
+ return new L(r, n, {
1095
+ CARD: a,
1096
+ "3DS": s
1805
1097
  });
1806
1098
  }
1807
- static async initHandlers(e, r) {
1808
- const n = {
1809
- ...Dt,
1810
- ...r
1811
- }, i = new xt(n.base_url, n.abortCtrl), a = new Kt(e, i);
1812
- await a.init();
1813
- const s = a.isNextAction("tokenize_card") || a.isNextAction("refresh_security_code") ? await this.createCardHandler(a) : void 0, o = this.create3DSHandler(a, r);
1814
- return { session: a, cardHandler: s, handler3DS: o };
1815
- }
1816
- static createCardHandler(e) {
1817
- return q.init(e);
1818
- }
1819
- static create3DSHandler(e, r) {
1820
- return new He(e, {
1821
- domContainer: r.challenge_3ds_container,
1822
- labelText: r.challenge_3ds_label_text
1099
+ static async initHandlers(e, t) {
1100
+ const r = {
1101
+ ...ee,
1102
+ ...t
1103
+ }, n = new X(r.base_url, r.abortCtrl), a = new Q(e, n), s = new G();
1104
+ s.onMessage("coordinator:session_state_change", (c) => {
1105
+ c.state.next_action !== "wait" && a.newStateHandle(c.state);
1106
+ }), await s.init(e, r.base_url, r.abortCtrl);
1107
+ const o = a.isNextAction("tokenize_card") || a.isNextAction("refresh_security_code") ? await this.createCardHandler(a, s) : void 0, l = this.create3DSHandler(a, t);
1108
+ return { session: a, coordinator: s, cardHandler: o, handler3DS: l };
1109
+ }
1110
+ static createCardHandler(e, t) {
1111
+ return w.init(e, t);
1112
+ }
1113
+ static create3DSHandler(e, t) {
1114
+ return new F(e, {
1115
+ domContainer: t.challenge_3ds_container,
1116
+ labelText: t.challenge_3ds_label_text
1823
1117
  });
1824
1118
  }
1825
1119
  }
1826
1120
  globalThis.HellgateSDK && (globalThis.Hellgate = globalThis.HellgateSDK.Hellgate, delete globalThis.HellgateSDK);
1827
1121
  export {
1828
- Pt as CardElement,
1829
- _t as CardExpirationDateElement,
1830
- Ct as CardNumberElement,
1831
- vt as CardVerificationCodeElement,
1832
- ve as Hellgate,
1833
- He as Hellgate3DSHandler,
1834
- q as HellgateCardHandler,
1835
- Pe as TextElement,
1836
- v as createElement,
1837
- Ce as extractCardNumberValue,
1838
- _e as extractExpiryDateValue,
1839
- St as putCardNumberValue,
1840
- Se as putExpiryDateValue,
1841
- Ot as uid
1122
+ Y as CardElement,
1123
+ V as CardExpirationDateElement,
1124
+ B as CardNumberElement,
1125
+ q as CardVerificationCodeElement,
1126
+ L as Hellgate,
1127
+ F as Hellgate3DSHandler,
1128
+ w as HellgateCardHandler,
1129
+ K as TextElement,
1130
+ b as createElement,
1131
+ I as extractCardNumberValue,
1132
+ T as extractExpiryDateValue,
1133
+ z as putCardNumberValue,
1134
+ M as putExpiryDateValue
1842
1135
  };