@morefin/cashier-bootstrapper 0.3.5 → 0.3.6
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 +7 -0
- package/dist/index.js +53 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,9 @@ export declare class CashierBootstrapper {
|
|
|
18
18
|
private redirectOverlayPanel?;
|
|
19
19
|
private redirectOverlayIframe?;
|
|
20
20
|
private overlayPositionSyncHandler?;
|
|
21
|
+
private managedRedirectTab?;
|
|
22
|
+
private managedRedirectTabTransactionId?;
|
|
23
|
+
private managedRedirectTabCheckIntervalId?;
|
|
21
24
|
private origin;
|
|
22
25
|
private ready;
|
|
23
26
|
private readonly fullConfig;
|
|
@@ -41,6 +44,10 @@ export declare class CashierBootstrapper {
|
|
|
41
44
|
private normalizeRedirectTarget;
|
|
42
45
|
private normalizeRedirectMethod;
|
|
43
46
|
private normalizeRedirectParameters;
|
|
47
|
+
private openManagedRedirectTab;
|
|
48
|
+
private openManagedRedirectTabWithPost;
|
|
49
|
+
private trackManagedRedirectTab;
|
|
50
|
+
private clearManagedRedirectTabWatcher;
|
|
44
51
|
private openPopupWithPost;
|
|
45
52
|
private writePostFormToWindow;
|
|
46
53
|
private submitPostForm;
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ const DEFAULT_IFRAME_ALLOW = 'geolocation *;camera *;payment *;clipboard-read *;
|
|
|
2
2
|
const CASHIER_PATH = '/cashier';
|
|
3
3
|
const FINGERPRINT_CDN = 'https://cdn.jsdelivr.net/npm/@fingerprintjs/fingerprintjs@4/dist/fp.min.js';
|
|
4
4
|
const CASHIER_REDIRECT_EVENT = 'CASHIER_REDIRECT';
|
|
5
|
+
const CASHIER_REDIRECT_TAB_CLOSED_EVENT = 'CASHIER_REDIRECT_TAB_CLOSED';
|
|
5
6
|
const TOP_URL_REPLACE_EVENT = 'TOP_URL_REPLACE';
|
|
6
7
|
const CASHIER_IFRAME_OVERLAY_CLOSE_EVENT = 'CASHIER_IFRAME_OVERLAY_CLOSE';
|
|
7
8
|
const CASHIER_RESULT_EVENT = 'CASHIER_RESULT';
|
|
@@ -335,6 +336,7 @@ export class CashierBootstrapper {
|
|
|
335
336
|
const redirectTarget = this.normalizeRedirectTarget(redirectPayload.target);
|
|
336
337
|
const redirectMethod = this.normalizeRedirectMethod(redirectPayload.method);
|
|
337
338
|
const redirectParameters = this.normalizeRedirectParameters(redirectPayload.parameters);
|
|
339
|
+
const transactionId = this.asString(redirectPayload.transactionId);
|
|
338
340
|
if (typeof redirectUrl !== 'string' || redirectUrl.trim() === '') {
|
|
339
341
|
return;
|
|
340
342
|
}
|
|
@@ -354,12 +356,12 @@ export class CashierBootstrapper {
|
|
|
354
356
|
case 'tab':
|
|
355
357
|
console.log('[CashierBootstrapper] Handling redirect target "tab".', { redirectUrl, redirectMethod, redirectParameters });
|
|
356
358
|
if (redirectMethod === 'POST') {
|
|
357
|
-
if (!this.
|
|
359
|
+
if (!this.openManagedRedirectTabWithPost(redirectUrl, redirectParameters, transactionId)) {
|
|
358
360
|
this.submitPostForm(redirectUrl, redirectParameters, '_blank');
|
|
359
361
|
}
|
|
360
362
|
}
|
|
361
363
|
else {
|
|
362
|
-
|
|
364
|
+
this.openManagedRedirectTab(redirectUrl, transactionId);
|
|
363
365
|
}
|
|
364
366
|
break;
|
|
365
367
|
case 'window':
|
|
@@ -492,6 +494,55 @@ export class CashierBootstrapper {
|
|
|
492
494
|
return acc;
|
|
493
495
|
}, {});
|
|
494
496
|
}
|
|
497
|
+
openManagedRedirectTab(url, transactionId) {
|
|
498
|
+
if (typeof window === 'undefined') {
|
|
499
|
+
return false;
|
|
500
|
+
}
|
|
501
|
+
const popup = window.open(url, '_blank');
|
|
502
|
+
if (!popup) {
|
|
503
|
+
return false;
|
|
504
|
+
}
|
|
505
|
+
this.trackManagedRedirectTab(popup, transactionId);
|
|
506
|
+
return true;
|
|
507
|
+
}
|
|
508
|
+
openManagedRedirectTabWithPost(url, parameters, transactionId) {
|
|
509
|
+
if (typeof window === 'undefined') {
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
const popup = window.open('', '_blank');
|
|
513
|
+
if (!popup) {
|
|
514
|
+
return false;
|
|
515
|
+
}
|
|
516
|
+
if (!this.writePostFormToWindow(popup, url, parameters)) {
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
519
|
+
this.trackManagedRedirectTab(popup, transactionId);
|
|
520
|
+
return true;
|
|
521
|
+
}
|
|
522
|
+
trackManagedRedirectTab(tab, transactionId) {
|
|
523
|
+
this.clearManagedRedirectTabWatcher();
|
|
524
|
+
this.managedRedirectTab = tab;
|
|
525
|
+
this.managedRedirectTabTransactionId = transactionId;
|
|
526
|
+
this.managedRedirectTabCheckIntervalId = setInterval(() => {
|
|
527
|
+
if (!this.managedRedirectTab?.closed) {
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
const closedTransactionId = this.managedRedirectTabTransactionId;
|
|
531
|
+
this.managedRedirectTab = null;
|
|
532
|
+
this.managedRedirectTabTransactionId = undefined;
|
|
533
|
+
this.clearManagedRedirectTabWatcher();
|
|
534
|
+
this.postMessage(CASHIER_REDIRECT_TAB_CLOSED_EVENT, {
|
|
535
|
+
transactionId: closedTransactionId
|
|
536
|
+
});
|
|
537
|
+
}, 500);
|
|
538
|
+
}
|
|
539
|
+
clearManagedRedirectTabWatcher() {
|
|
540
|
+
if (this.managedRedirectTabCheckIntervalId === undefined) {
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
clearInterval(this.managedRedirectTabCheckIntervalId);
|
|
544
|
+
this.managedRedirectTabCheckIntervalId = undefined;
|
|
545
|
+
}
|
|
495
546
|
openPopupWithPost(url, parameters) {
|
|
496
547
|
if (typeof window === 'undefined') {
|
|
497
548
|
return false;
|