@paypay/mini-app-js-sdk 2.38.0 → 2.39.0

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.
@@ -346,372 +346,12 @@ function v4(options, buf, offset) {
346
346
  }
347
347
  return stringify(rnds);
348
348
  }
349
- function isIP(hostName) {
350
- return isIPv4(hostName) || isIPv6(hostName);
351
- }
352
- function isIPv4(hostName) {
353
- const expression = /(^\s*(((\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]))\s*$)/;
354
- return expression.test(hostName);
355
- }
356
- function isIPv6(hostName) {
357
- const expression = /(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$)/;
358
- return expression.test(hostName);
359
- }
360
- const secondaryList = [
361
- "ab.ca",
362
- "ac.ac",
363
- "ac.ae",
364
- "ac.at",
365
- "ac.be",
366
- "ac.cn",
367
- "ac.il",
368
- "ac.in",
369
- "ac.jp",
370
- "ac.kr",
371
- "ac.th",
372
- "ac.uk",
373
- "ac.sg",
374
- "ad.jp",
375
- "adm.br",
376
- "adv.br",
377
- "ah.cn",
378
- "am.br",
379
- "arq.br",
380
- "art.br",
381
- "arts.ro",
382
- "asn.au",
383
- "asso.fr",
384
- "asso.mc",
385
- "bc.ca",
386
- "bio.br",
387
- "biz.pl",
388
- "biz.tr",
389
- "bj.cn",
390
- "bel.tr",
391
- "br.com",
392
- "cn.com",
393
- "cng.br",
394
- "cnt.br",
395
- "co.ac",
396
- "co.at",
397
- "co.de",
398
- "co.gl",
399
- "co.hk",
400
- "co.id",
401
- "co.il",
402
- "co.in",
403
- "co.jp",
404
- "co.kr",
405
- "co.mg",
406
- "co.ms",
407
- "co.nz",
408
- "co.th",
409
- "cp.tz",
410
- "co.uk",
411
- "co.ve",
412
- "co.vi",
413
- "co.za",
414
- "com.ag",
415
- "com.ai",
416
- "com.ar",
417
- "com.au",
418
- "com.br",
419
- "com.co",
420
- "com.cn",
421
- "com.cy",
422
- "com.de",
423
- "com.do",
424
- "com.ec",
425
- "com.es",
426
- "com.fj",
427
- "com.fr",
428
- "com.gl",
429
- "com.gt",
430
- "com.hk",
431
- "com.hr",
432
- "com.hu",
433
- "com.kg",
434
- "com.ki",
435
- "com.lc",
436
- "com.mg",
437
- "com.mm",
438
- "com.ms",
439
- "com.mt",
440
- "com.mu",
441
- "com.mx",
442
- "com.my",
443
- "com.na",
444
- "com.nf",
445
- "com.ng",
446
- "com.ni",
447
- "com.pa",
448
- "com.ph",
449
- "com.pl",
450
- "com.pt",
451
- "com.qa",
452
- "com.ro",
453
- "com.ru",
454
- "com.sb",
455
- "com.sc",
456
- "com.sg",
457
- "com.sv",
458
- "com.tr",
459
- "com.tw",
460
- "com.ua",
461
- "com.uy",
462
- "com.ve",
463
- "com.vn",
464
- "cq.cn",
465
- "de.com",
466
- "de.org",
467
- "ecn.br",
468
- "ed.jp",
469
- "edu.au",
470
- "edu.cn",
471
- "edu.hk",
472
- "edu.mm",
473
- "edu.my",
474
- "edu.pl",
475
- "edu.pt",
476
- "edu.qa",
477
- "edu.sg",
478
- "edu.tr",
479
- "edu.tw",
480
- "eng.br",
481
- "ernet.in",
482
- "esp.br",
483
- "etc.br",
484
- "eti.br",
485
- "eu.com",
486
- "eu.int",
487
- "eu.lv",
488
- "firm.in",
489
- "firm.ro",
490
- "fm.br",
491
- "fot.br",
492
- "fst.br",
493
- "g12.br",
494
- "gb.com",
495
- "gb.net",
496
- "gd.cn",
497
- "gen.in",
498
- "go.jp",
499
- "go.kr",
500
- "go.th",
501
- "gov.au",
502
- "gov.az",
503
- "gov.br",
504
- "gov.cn",
505
- "gov.il",
506
- "gov.in",
507
- "gov.mm",
508
- "gov.my",
509
- "gov.qa",
510
- "gov.sg",
511
- "gov.tr",
512
- "gov.tw",
513
- "gov.uk",
514
- "govt.nz",
515
- "gr.jp",
516
- "gs.cn",
517
- "gv.ac",
518
- "gv.at",
519
- "gx.cn",
520
- "gz.cn",
521
- "he.cn",
522
- "hi.cn",
523
- "hk.cn",
524
- "hl.cn",
525
- "hu.com",
526
- "id.au",
527
- "idv.tw",
528
- "in.ua",
529
- "in.th",
530
- "ind.br",
531
- "ind.in",
532
- "inf.br",
533
- "info.pl",
534
- "info.ro",
535
- "info.tr",
536
- "info.ve",
537
- "iwi.nz",
538
- "jl.cn",
539
- "jor.br",
540
- "js.cn",
541
- "jus.br",
542
- "k12.il",
543
- "k12.tr",
544
- "kr.com",
545
- "lel.br",
546
- "lg.jp",
547
- "ln.cn",
548
- "ltd.uk",
549
- "mb.ca",
550
- "me.uk",
551
- "med.br",
552
- "mi.th",
553
- "mil.br",
554
- "mil.uk",
555
- "mo.cn",
556
- "mod.uk",
557
- "muni.il",
558
- "nb.ca",
559
- "ne.jp",
560
- "ne.kr",
561
- "net.ag",
562
- "net.ai",
563
- "net.au",
564
- "net.br",
565
- "net.cn",
566
- "net.do",
567
- "net.gl",
568
- "net.hk",
569
- "net.il",
570
- "net.in",
571
- "net.kg",
572
- "net.ki",
573
- "net.lc",
574
- "net.mg",
575
- "net.mm",
576
- "net.mu",
577
- "net.ni",
578
- "net.nz",
579
- "net.pl",
580
- "net.ru",
581
- "net.sb",
582
- "net.sc",
583
- "net.sg",
584
- "net.th",
585
- "net.tr",
586
- "net.tw",
587
- "net.uk",
588
- "net.ve",
589
- "nf.ca",
590
- "nhs.uk",
591
- "nm.cn",
592
- "nm.kr",
593
- "no.com",
594
- "nom.br",
595
- "nom.ni",
596
- "nom.ro",
597
- "ns.ca",
598
- "nt.ca",
599
- "nt.ro",
600
- "ntr.br",
601
- "nx.cn",
602
- "odo.br",
603
- "off.ai",
604
- "on.ca",
605
- "or.ac",
606
- "or.at",
607
- "or.jp",
608
- "or.kr",
609
- "or.th",
610
- "org.ag",
611
- "org.ai",
612
- "org.au",
613
- "org.br",
614
- "org.cn",
615
- "org.do",
616
- "org.es",
617
- "org.gl",
618
- "org.hk",
619
- "org.in",
620
- "org.kg",
621
- "org.ki",
622
- "org.lc",
623
- "org.mg",
624
- "org.mm",
625
- "org.ms",
626
- "org.nf",
627
- "org.ng",
628
- "org.ni",
629
- "org.nz",
630
- "org.pl",
631
- "org.ro",
632
- "org.ru",
633
- "org.sb",
634
- "org.sc",
635
- "org.sg",
636
- "org.tr",
637
- "org.tw",
638
- "org.uk",
639
- "org.ve",
640
- "pe.ca",
641
- "plc.uk",
642
- "ppg.br",
643
- "pro.br",
644
- "psc.br",
645
- "psi.br",
646
- "qc.ca",
647
- "qc.com",
648
- "qh.cn",
649
- "rec.br",
650
- "rec.ro",
651
- "res.in",
652
- "sa.com",
653
- "sc.cn",
654
- "sch.uk",
655
- "se.com",
656
- "se.net",
657
- "sh.cn",
658
- "sk.ca",
659
- "slg.br",
660
- "sn.cn",
661
- "store.ro",
662
- "tj.cn",
663
- "tm.fr",
664
- "tm.mc",
665
- "tm.ro",
666
- "tmp.br",
667
- "tur.br",
668
- "tv.br",
669
- "tv.tr",
670
- "tw.cn",
671
- "uk.com",
672
- "uk.net",
673
- "us.com",
674
- "uy.com",
675
- "vet.br",
676
- "waw.pl",
677
- "web.ve",
678
- "www.ro",
679
- "xj.cn",
680
- "xz.cn",
681
- "yk.ca",
682
- "yn.cn",
683
- "zj.cn",
684
- "zlg.br"
685
- ];
686
- function parseDomain(domain) {
687
- const splitStr = domain.split(".");
688
- if (isIP(domain) || splitStr.length <= 2) {
689
- return domain;
690
- }
691
- const secondary = splitStr.slice(splitStr.length - 2).join(".");
692
- if (secondaryList.includes(secondary) && splitStr.length >= 3) {
693
- return splitStr.slice(splitStr.length - 3).join(".");
349
+ class PPError extends Error {
350
+ constructor(message, errorCode) {
351
+ super(message);
352
+ this.errorCode = errorCode;
694
353
  }
695
- return splitStr.slice(splitStr.length - 2).join(".");
696
354
  }
697
- function getDomain(subdomainCookieSharing, hostname) {
698
- return subdomainCookieSharing ? parseDomain(hostname) : hostname;
699
- }
700
- const JS_SDK_VERSION = "2.38.0";
701
- const REVISION = "55465a6";
702
- const coreBaseUrl = new URL("https://mini-app-sdk-core.paypay.ne.jp/");
703
- const CORE_IFRAME_ORIGIN = coreBaseUrl.origin;
704
- const CORE_IFRAME_URL = new URL(
705
- `./iframe.html?v=${JS_SDK_VERSION}&rev=${REVISION}`,
706
- coreBaseUrl
707
- ).href;
708
- const COUPON_IFRAME_URL = new URL(
709
- `./coupon/iframe.html?v=${JS_SDK_VERSION}`,
710
- coreBaseUrl
711
- ).href;
712
- const SENTRY_DSN = "https://377b45f154b1fb17d8e98a6ffb67030a@o4505819519320064.ingest.sentry.io/4506579323453440";
713
- const GA_API_SECRET = "fgPKRkdQQvq7XbV4qw3MOQ";
714
- const GA_MEASUREMENT_ID = "G-M64Q2828RR";
715
355
  var MiniAppErrorType = /* @__PURE__ */ ((MiniAppErrorType2) => {
716
356
  MiniAppErrorType2["success"] = "SUCCESS";
717
357
  MiniAppErrorType2["invalidUrl"] = "INVALID_URL";
@@ -784,6 +424,21 @@ var MiniAppErrorType = /* @__PURE__ */ ((MiniAppErrorType2) => {
784
424
  MiniAppErrorType2["sdkUpgradeRequired"] = "SDK_UPGRADE_REQUIRED";
785
425
  return MiniAppErrorType2;
786
426
  })(MiniAppErrorType || {});
427
+ const JS_SDK_VERSION = "2.39.0";
428
+ const REVISION = "c39c952";
429
+ const coreBaseUrl = new URL("https://mini-app-sdk-core.paypay.ne.jp/");
430
+ const CORE_IFRAME_ORIGIN = coreBaseUrl.origin;
431
+ const CORE_IFRAME_URL = new URL(
432
+ `./iframe.html?v=${JS_SDK_VERSION}&rev=${REVISION}`,
433
+ coreBaseUrl
434
+ ).href;
435
+ const COUPON_IFRAME_URL = new URL(
436
+ `./coupon/iframe.html?v=${JS_SDK_VERSION}`,
437
+ coreBaseUrl
438
+ ).href;
439
+ const SENTRY_DSN = "https://377b45f154b1fb17d8e98a6ffb67030a@o4505819519320064.ingest.sentry.io/4506579323453440";
440
+ const GA_API_SECRET = "fgPKRkdQQvq7XbV4qw3MOQ";
441
+ const GA_MEASUREMENT_ID = "G-M64Q2828RR";
787
442
  const objectToString = Object.prototype.toString;
788
443
  function isBuiltin(wat, className) {
789
444
  return objectToString.call(wat) === `[object ${className}]`;
@@ -2105,6 +1760,224 @@ function addBreadcrumbToSentry(breadcrumb) {
2105
1760
  addBreadcrumb(breadcrumb);
2106
1761
  }
2107
1762
  }
1763
+ class WindowBridge {
1764
+ constructor(functions, allowedOrigins) {
1765
+ this.deferredCallbacks = {};
1766
+ this.functions = functions;
1767
+ this.allowedOrigins = allowedOrigins;
1768
+ this.messageEventHandler = this.messageEventHandler.bind(this);
1769
+ this.subscribeToMessageEvent();
1770
+ }
1771
+ /**
1772
+ * Subscribe to message event to handle incoming messages.
1773
+ * These messages can be of two types
1774
+ * 1. A function call from another window
1775
+ * 2. Response of a function call made from this window to another window
1776
+ */
1777
+ subscribeToMessageEvent() {
1778
+ window.addEventListener("message", this.messageEventHandler);
1779
+ }
1780
+ /**
1781
+ * Unsubscribe to message event.
1782
+ */
1783
+ unsubscribeToMessageEvent() {
1784
+ window.removeEventListener("message", this.messageEventHandler);
1785
+ }
1786
+ messageEventHandler(receivedMessageEvent) {
1787
+ var _a;
1788
+ if (!((_a = receivedMessageEvent.data) == null ? void 0 : _a.forWindowBridge)) {
1789
+ return;
1790
+ }
1791
+ if (this.allowedOrigins && !this.allowedOrigins.includes(receivedMessageEvent.origin)) {
1792
+ return this.sendErrorResponse(
1793
+ receivedMessageEvent,
1794
+ `${receivedMessageEvent.origin} is not allowed to make requests`,
1795
+ MiniAppErrorType.originNotAllowed
1796
+ );
1797
+ }
1798
+ if (receivedMessageEvent.data.type === "request") {
1799
+ void this.handleRequest(
1800
+ receivedMessageEvent
1801
+ );
1802
+ } else if (receivedMessageEvent.data.type === "response") {
1803
+ this.handleResponse(
1804
+ receivedMessageEvent
1805
+ );
1806
+ }
1807
+ }
1808
+ handleRequest(receivedMessageEvent) {
1809
+ return __async(this, null, function* () {
1810
+ const functionName = receivedMessageEvent.data.functionName;
1811
+ const functionToInvoke = this.functions[functionName];
1812
+ if (!functionToInvoke) {
1813
+ this.sendErrorResponse(
1814
+ receivedMessageEvent,
1815
+ `Function '${functionName}' does not exists on the target window`,
1816
+ MiniAppErrorType.functionNotFound
1817
+ );
1818
+ }
1819
+ try {
1820
+ this.sendSuccessResponse(
1821
+ receivedMessageEvent,
1822
+ yield functionToInvoke(...receivedMessageEvent.data.params)
1823
+ );
1824
+ } catch (error) {
1825
+ let message = "Some error ocurred while processing the request";
1826
+ let errorCode = MiniAppErrorType.unknown;
1827
+ if (error instanceof PPError) {
1828
+ message = error.message;
1829
+ errorCode = error.errorCode;
1830
+ }
1831
+ this.sendErrorResponse(receivedMessageEvent, message, errorCode);
1832
+ }
1833
+ });
1834
+ }
1835
+ handleResponse(receivedMessageEvent) {
1836
+ if (!this.deferredCallbacks[receivedMessageEvent.data.key]) {
1837
+ console.warn(
1838
+ `Callback for ${receivedMessageEvent.data.functionName} not found`
1839
+ );
1840
+ return;
1841
+ }
1842
+ const [resolve, reject] = this.deferredCallbacks[receivedMessageEvent.data.key];
1843
+ delete this.deferredCallbacks[receivedMessageEvent.data.key];
1844
+ if (receivedMessageEvent.data.status === "success") {
1845
+ resolve(receivedMessageEvent.data.result);
1846
+ } else {
1847
+ reject(
1848
+ new PPError(
1849
+ receivedMessageEvent.data.message,
1850
+ receivedMessageEvent.data.errorCode
1851
+ )
1852
+ );
1853
+ }
1854
+ }
1855
+ sendErrorResponse(receivedMessageEvent, message, errorCode) {
1856
+ sendWindowBridgeErrorToSentry(
1857
+ receivedMessageEvent.data.functionName,
1858
+ message,
1859
+ errorCode
1860
+ );
1861
+ this.sendResponse(receivedMessageEvent, {
1862
+ status: "failure",
1863
+ message,
1864
+ errorCode
1865
+ });
1866
+ }
1867
+ sendSuccessResponse(receivedMessageEvent, result) {
1868
+ this.sendResponse(receivedMessageEvent, {
1869
+ status: "success",
1870
+ result
1871
+ });
1872
+ }
1873
+ sendResponse(receivedMessageEvent, data) {
1874
+ var _a;
1875
+ (_a = receivedMessageEvent.source) == null ? void 0 : _a.postMessage(
1876
+ __spreadValues({
1877
+ forWindowBridge: true,
1878
+ type: "response",
1879
+ key: receivedMessageEvent.data.key,
1880
+ functionName: receivedMessageEvent.data.functionName
1881
+ }, data),
1882
+ // Just a hack to overcome weird function overload mismatch
1883
+ receivedMessageEvent.origin
1884
+ );
1885
+ }
1886
+ /**
1887
+ * A static method to create a new `WindowBridge` instance and enforce singleton pattern
1888
+ * @param functions an objection of functions that can be invoked on the current window
1889
+ * @param allowedOrigins a list of allowed origins from where request can be accepted
1890
+ * @returns `WindowBridge` instance
1891
+ */
1892
+ static init(functions, allowedOrigins) {
1893
+ if (this._instance) {
1894
+ throw new Error(
1895
+ "WindowBridge already initialized, you can't call WindowBridge.init more than once"
1896
+ );
1897
+ }
1898
+ this._instance = new this(functions, allowedOrigins);
1899
+ return this._instance;
1900
+ }
1901
+ /**
1902
+ * Destroy current WindowBridge instance, being used for testing
1903
+ */
1904
+ static destroy() {
1905
+ if (this._instance) {
1906
+ this._instance.unsubscribeToMessageEvent();
1907
+ this._instance = void 0;
1908
+ }
1909
+ }
1910
+ /**
1911
+ * A static method to get an existing `WindowBridge` instance
1912
+ * @returns `WindowBridge` instance
1913
+ */
1914
+ static getBridge() {
1915
+ if (!this._instance) {
1916
+ throw new Error(
1917
+ "WindowBridge not initialized, please call WindowBridge.init before calling WindowBridge.getBridge"
1918
+ );
1919
+ }
1920
+ return this._instance;
1921
+ }
1922
+ /**
1923
+ * A static function that returns a proxy object to invoke functions on a target window.
1924
+ * We can call it multiple times to invoke functions on different windows
1925
+ * @param getTargetWindow a function that returns the target window where we want to invoke functions
1926
+ * @param targetWindowOrigin origin of the target window
1927
+ * @returns a proxy object to call functions from target window as an asynchronous function
1928
+ */
1929
+ static getTargetWindowFunctionProxy(getTargetWindow, targetWindowOrigin) {
1930
+ return WindowBridge.getBridge().getTargetWindowFunctionProxy(
1931
+ getTargetWindow,
1932
+ targetWindowOrigin
1933
+ );
1934
+ }
1935
+ /**
1936
+ * It returns a proxy object to invoke functions on a target window.
1937
+ * We can call it multiple times to invoke functions on different windows
1938
+ * @param getTargetWindow a function that returns the target window where we want to invoke functions
1939
+ * @param targetWindowOrigin origin of the target window
1940
+ * @returns a proxy object to call functions from target window as an asynchronous function
1941
+ */
1942
+ getTargetWindowFunctionProxy(getTargetWindow, targetWindowOrigin) {
1943
+ return new Proxy(this, {
1944
+ get(windowBridgeInstance, functionName) {
1945
+ return (...params) => (
1946
+ // eslint-disable-next-line no-async-promise-executor, @typescript-eslint/no-misused-promises
1947
+ new Promise((resolve, reject) => __async(this, null, function* () {
1948
+ const functionNameString = functionName.toString();
1949
+ const key = `${functionNameString}--${getRandomString()}`;
1950
+ try {
1951
+ const targetWindow = yield getTargetWindow();
1952
+ if (!targetWindow) {
1953
+ throw new Error("Target window is undefined");
1954
+ }
1955
+ windowBridgeInstance.deferredCallbacks[key] = [resolve, reject];
1956
+ targetWindow.postMessage(
1957
+ {
1958
+ forWindowBridge: true,
1959
+ type: "request",
1960
+ functionName: functionNameString,
1961
+ key,
1962
+ params: JSON.parse(JSON.stringify(params))
1963
+ },
1964
+ targetWindowOrigin
1965
+ );
1966
+ } catch (error) {
1967
+ delete windowBridgeInstance.deferredCallbacks[key];
1968
+ reject(
1969
+ new PPError(
1970
+ error.message,
1971
+ MiniAppErrorType.messageSendingFailed
1972
+ )
1973
+ );
1974
+ }
1975
+ }))
1976
+ );
1977
+ }
1978
+ });
1979
+ }
1980
+ }
2108
1981
  let clientId = "";
2109
1982
  function getCurrentClientId() {
2110
1983
  return clientId;
@@ -2172,12 +2045,12 @@ function getKeyWithClientId(baseKey, clientId2) {
2172
2045
  return `${baseKey}.${clientId2 != null ? clientId2 : getCurrentClientId()}`;
2173
2046
  }
2174
2047
  function saveLocalStorage(key, value) {
2175
- removeLocalStorage(key);
2048
+ removeLocalStorage$1(key);
2176
2049
  if (value) {
2177
2050
  return storage.setItem(key, value);
2178
2051
  }
2179
2052
  }
2180
- function removeLocalStorage(key) {
2053
+ function removeLocalStorage$1(key) {
2181
2054
  storage.removeItem(key);
2182
2055
  }
2183
2056
  function saveClientUUID(uuid) {
@@ -2285,38 +2158,14 @@ function getIconUrl(theme) {
2285
2158
  function convertToString(str) {
2286
2159
  return str ? String(str) : "";
2287
2160
  }
2288
- function removeCookie(key, domain) {
2289
- api.remove(key);
2290
- api.remove(key, { domain });
2291
- }
2292
- function saveRefreshToken(refreshToken, domain, isSecure, clientId2) {
2293
- let refreshTokenKey = PpLocalStorageKey.refreshToken;
2294
- if (clientId2) {
2295
- refreshTokenKey = `${refreshTokenKey}.${clientId2}`;
2296
- }
2297
- removeCookie(refreshTokenKey, domain);
2298
- return api.set(refreshTokenKey, refreshToken, {
2299
- domain,
2300
- expires: 90,
2301
- secure: isSecure
2302
- });
2303
- }
2304
- function saveCodeVerifier(codeVerifier, domain, isSecure, expires) {
2305
- removeCookie(PpLocalStorageKey.codeVerifier, domain);
2306
- return api.set(PpLocalStorageKey.codeVerifier, codeVerifier, {
2307
- domain,
2308
- secure: isSecure,
2309
- expires
2310
- });
2311
- }
2312
2161
  function getRefreshToken(clientId2) {
2313
2162
  const refreshTokenWithClientId = api.get(
2314
2163
  `${PpLocalStorageKey.refreshToken}.${clientId2}`
2315
2164
  );
2316
2165
  return refreshTokenWithClientId || api.get(PpLocalStorageKey.refreshToken) || "";
2317
2166
  }
2318
- function getCodeVerifier() {
2319
- return api.get(PpLocalStorageKey.codeVerifier) || "";
2167
+ function getCodeVerifier(clientId2) {
2168
+ return api.get(`${PpLocalStorageKey.codeVerifier}.${clientId2}`) || api.get(PpLocalStorageKey.codeVerifier) || "";
2320
2169
  }
2321
2170
  function exposeClientJsBridge(jsBridge) {
2322
2171
  if (window.hasOwnProperty(jsBridgeNamespace) && window[jsBridgeNamespace] === jsBridge) {
@@ -2390,230 +2239,6 @@ var MiniAppStatusType = /* @__PURE__ */ ((MiniAppStatusType2) => {
2390
2239
  MiniAppStatusType2["connected"] = "CONNECTED";
2391
2240
  return MiniAppStatusType2;
2392
2241
  })(MiniAppStatusType || {});
2393
- class PPError extends Error {
2394
- constructor(message, errorCode) {
2395
- super(message);
2396
- this.errorCode = errorCode;
2397
- }
2398
- }
2399
- class WindowBridge {
2400
- constructor(functions, allowedOrigins) {
2401
- this.deferredCallbacks = {};
2402
- this.functions = functions;
2403
- this.allowedOrigins = allowedOrigins;
2404
- this.messageEventHandler = this.messageEventHandler.bind(this);
2405
- this.subscribeToMessageEvent();
2406
- }
2407
- /**
2408
- * Subscribe to message event to handle incoming messages.
2409
- * These messages can be of two types
2410
- * 1. A function call from another window
2411
- * 2. Response of a function call made from this window to another window
2412
- */
2413
- subscribeToMessageEvent() {
2414
- window.addEventListener("message", this.messageEventHandler);
2415
- }
2416
- /**
2417
- * Unsubscribe to message event.
2418
- */
2419
- unsubscribeToMessageEvent() {
2420
- window.removeEventListener("message", this.messageEventHandler);
2421
- }
2422
- messageEventHandler(receivedMessageEvent) {
2423
- var _a;
2424
- if (!((_a = receivedMessageEvent.data) == null ? void 0 : _a.forWindowBridge)) {
2425
- return;
2426
- }
2427
- if (this.allowedOrigins && !this.allowedOrigins.includes(receivedMessageEvent.origin)) {
2428
- return this.sendErrorResponse(
2429
- receivedMessageEvent,
2430
- `${receivedMessageEvent.origin} is not allowed to make requests`,
2431
- MiniAppErrorType.originNotAllowed
2432
- );
2433
- }
2434
- if (receivedMessageEvent.data.type === "request") {
2435
- void this.handleRequest(
2436
- receivedMessageEvent
2437
- );
2438
- } else if (receivedMessageEvent.data.type === "response") {
2439
- this.handleResponse(
2440
- receivedMessageEvent
2441
- );
2442
- }
2443
- }
2444
- handleRequest(receivedMessageEvent) {
2445
- return __async(this, null, function* () {
2446
- const functionName = receivedMessageEvent.data.functionName;
2447
- const functionToInvoke = this.functions[functionName];
2448
- if (!functionToInvoke) {
2449
- this.sendErrorResponse(
2450
- receivedMessageEvent,
2451
- `Function '${functionName}' does not exists on the target window`,
2452
- MiniAppErrorType.functionNotFound
2453
- );
2454
- }
2455
- try {
2456
- this.sendSuccessResponse(
2457
- receivedMessageEvent,
2458
- yield functionToInvoke(...receivedMessageEvent.data.params)
2459
- );
2460
- } catch (error) {
2461
- let message = "Some error ocurred while processing the request";
2462
- let errorCode = MiniAppErrorType.unknown;
2463
- if (error instanceof PPError) {
2464
- message = error.message;
2465
- errorCode = error.errorCode;
2466
- }
2467
- this.sendErrorResponse(receivedMessageEvent, message, errorCode);
2468
- }
2469
- });
2470
- }
2471
- handleResponse(receivedMessageEvent) {
2472
- if (!this.deferredCallbacks[receivedMessageEvent.data.key]) {
2473
- console.warn(
2474
- `Callback for ${receivedMessageEvent.data.functionName} not found`
2475
- );
2476
- return;
2477
- }
2478
- const [resolve, reject] = this.deferredCallbacks[receivedMessageEvent.data.key];
2479
- delete this.deferredCallbacks[receivedMessageEvent.data.key];
2480
- if (receivedMessageEvent.data.status === "success") {
2481
- resolve(receivedMessageEvent.data.result);
2482
- } else {
2483
- reject(
2484
- new PPError(
2485
- receivedMessageEvent.data.message,
2486
- receivedMessageEvent.data.errorCode
2487
- )
2488
- );
2489
- }
2490
- }
2491
- sendErrorResponse(receivedMessageEvent, message, errorCode) {
2492
- sendWindowBridgeErrorToSentry(
2493
- receivedMessageEvent.data.functionName,
2494
- message,
2495
- errorCode
2496
- );
2497
- this.sendResponse(receivedMessageEvent, {
2498
- status: "failure",
2499
- message,
2500
- errorCode
2501
- });
2502
- }
2503
- sendSuccessResponse(receivedMessageEvent, result) {
2504
- this.sendResponse(receivedMessageEvent, {
2505
- status: "success",
2506
- result
2507
- });
2508
- }
2509
- sendResponse(receivedMessageEvent, data) {
2510
- var _a;
2511
- (_a = receivedMessageEvent.source) == null ? void 0 : _a.postMessage(
2512
- __spreadValues({
2513
- forWindowBridge: true,
2514
- type: "response",
2515
- key: receivedMessageEvent.data.key,
2516
- functionName: receivedMessageEvent.data.functionName
2517
- }, data),
2518
- // Just a hack to overcome weird function overload mismatch
2519
- receivedMessageEvent.origin
2520
- );
2521
- }
2522
- /**
2523
- * A static method to create a new `WindowBridge` instance and enforce singleton pattern
2524
- * @param functions an objection of functions that can be invoked on the current window
2525
- * @param allowedOrigins a list of allowed origins from where request can be accepted
2526
- * @returns `WindowBridge` instance
2527
- */
2528
- static init(functions, allowedOrigins) {
2529
- if (this._instance) {
2530
- throw new Error(
2531
- "WindowBridge already initialized, you can't call WindowBridge.init more than once"
2532
- );
2533
- }
2534
- this._instance = new this(functions, allowedOrigins);
2535
- return this._instance;
2536
- }
2537
- /**
2538
- * Destroy current WindowBridge instance, being used for testing
2539
- */
2540
- static destroy() {
2541
- if (this._instance) {
2542
- this._instance.unsubscribeToMessageEvent();
2543
- this._instance = void 0;
2544
- }
2545
- }
2546
- /**
2547
- * A static method to get an existing `WindowBridge` instance
2548
- * @returns `WindowBridge` instance
2549
- */
2550
- static getBridge() {
2551
- if (!this._instance) {
2552
- throw new Error(
2553
- "WindowBridge not initialized, please call WindowBridge.init before calling WindowBridge.getBridge"
2554
- );
2555
- }
2556
- return this._instance;
2557
- }
2558
- /**
2559
- * A static function that returns a proxy object to invoke functions on a target window.
2560
- * We can call it multiple times to invoke functions on different windows
2561
- * @param getTargetWindow a function that returns the target window where we want to invoke functions
2562
- * @param targetWindowOrigin origin of the target window
2563
- * @returns a proxy object to call functions from target window as an asynchronous function
2564
- */
2565
- static getTargetWindowFunctionProxy(getTargetWindow, targetWindowOrigin) {
2566
- return WindowBridge.getBridge().getTargetWindowFunctionProxy(
2567
- getTargetWindow,
2568
- targetWindowOrigin
2569
- );
2570
- }
2571
- /**
2572
- * It returns a proxy object to invoke functions on a target window.
2573
- * We can call it multiple times to invoke functions on different windows
2574
- * @param getTargetWindow a function that returns the target window where we want to invoke functions
2575
- * @param targetWindowOrigin origin of the target window
2576
- * @returns a proxy object to call functions from target window as an asynchronous function
2577
- */
2578
- getTargetWindowFunctionProxy(getTargetWindow, targetWindowOrigin) {
2579
- return new Proxy(this, {
2580
- get(windowBridgeInstance, functionName) {
2581
- return (...params) => (
2582
- // eslint-disable-next-line no-async-promise-executor, @typescript-eslint/no-misused-promises
2583
- new Promise((resolve, reject) => __async(this, null, function* () {
2584
- const functionNameString = functionName.toString();
2585
- const key = `${functionNameString}--${getRandomString()}`;
2586
- try {
2587
- const targetWindow = yield getTargetWindow();
2588
- if (!targetWindow) {
2589
- throw new Error("Target window is undefined");
2590
- }
2591
- windowBridgeInstance.deferredCallbacks[key] = [resolve, reject];
2592
- targetWindow.postMessage(
2593
- {
2594
- forWindowBridge: true,
2595
- type: "request",
2596
- functionName: functionNameString,
2597
- key,
2598
- params: JSON.parse(JSON.stringify(params))
2599
- },
2600
- targetWindowOrigin
2601
- );
2602
- } catch (error) {
2603
- delete windowBridgeInstance.deferredCallbacks[key];
2604
- reject(
2605
- new PPError(
2606
- error.message,
2607
- MiniAppErrorType.messageSendingFailed
2608
- )
2609
- );
2610
- }
2611
- }))
2612
- );
2613
- }
2614
- });
2615
- }
2616
- }
2617
2242
  const style = "";
2618
2243
  const MinVersion = {
2619
2244
  PRE_TRANSACTION_AUTO_CHARGE: "3.43.0",
@@ -2625,6 +2250,36 @@ const MinVersion = {
2625
2250
  PERFORMANCE_MEASUREMENT: "4.47.0",
2626
2251
  START_MULTIFACTOR_AUTH_PIN_FALLBACK: "4.63.0"
2627
2252
  };
2253
+ function setCookie({ name, value, options }) {
2254
+ return api.set(name, value, options);
2255
+ }
2256
+ function getCookie({ name }) {
2257
+ return api.get(name);
2258
+ }
2259
+ function removeCookie({ name, options }) {
2260
+ return api.remove(name, options);
2261
+ }
2262
+ function setLocalStorage({
2263
+ name,
2264
+ value
2265
+ }) {
2266
+ return localStorage.setItem(name, value);
2267
+ }
2268
+ function getLocalStorage({ name }) {
2269
+ return localStorage.getItem(name);
2270
+ }
2271
+ function removeLocalStorage({ name }) {
2272
+ return localStorage.removeItem(name);
2273
+ }
2274
+ const clientWindowBridgeFunctions = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2275
+ __proto__: null,
2276
+ getCookie,
2277
+ getLocalStorage,
2278
+ removeCookie,
2279
+ removeLocalStorage,
2280
+ setCookie,
2281
+ setLocalStorage
2282
+ }, Symbol.toStringTag, { value: "Module" }));
2628
2283
  const IFRAME_NAME = "ppmna-iframe";
2629
2284
  const IFRAME_CONTAINER_NAME = "ppsdk-container";
2630
2285
  let iframeContainer;
@@ -2705,7 +2360,7 @@ function createIframe() {
2705
2360
  let useAllFunctions = false;
2706
2361
  let clientSdkType;
2707
2362
  let initDonePromise;
2708
- WindowBridge.init({});
2363
+ WindowBridge.init(clientWindowBridgeFunctions, [CORE_IFRAME_ORIGIN]);
2709
2364
  void getCoreIframe();
2710
2365
  function clearInternalInitSyncState() {
2711
2366
  initDonePromise = Promise.resolve(false);
@@ -2741,14 +2396,6 @@ const commonMessageHandler = (e) => {
2741
2396
  window.location.href = linkOption.url;
2742
2397
  }
2743
2398
  }
2744
- if (e.data.name === PPUtilFunctionName.saveRefreshToken) {
2745
- const { refreshToken, domain, isSecure, clientId: clientId2 } = e.data.data;
2746
- saveRefreshToken(refreshToken, domain, isSecure, clientId2);
2747
- }
2748
- if (e.data.name === PPUtilFunctionName.saveCodeVerifier) {
2749
- const { codeVerifier, domain, isSecure, expires } = e.data.data;
2750
- saveCodeVerifier(codeVerifier, domain, isSecure, expires);
2751
- }
2752
2399
  if (e.data.name === PPUtilFunctionName.consoleDebugInfo) {
2753
2400
  const { params } = e.data.data;
2754
2401
  consoleDebugInfo(params);
@@ -2769,8 +2416,8 @@ function init(params) {
2769
2416
  const token = url2.searchParams.get("token");
2770
2417
  const ott = url2.searchParams.get("one_time_token");
2771
2418
  const refreshToken = getRefreshToken(params.clientId);
2772
- const codeVerifier = getCodeVerifier();
2773
- const clientVersion = "2.38.0";
2419
+ const codeVerifier = getCodeVerifier(params.clientId);
2420
+ const clientVersion = "2.39.0";
2774
2421
  useAllFunctions = !!params.useAllFunctions;
2775
2422
  if (token || ott) {
2776
2423
  removeTokenFromUrl(url2);
@@ -3006,13 +2653,7 @@ const logout = promiseToCallback(
3006
2653
  "logout",
3007
2654
  () => __async(void 0, null, function* () {
3008
2655
  try {
3009
- const subdomainCookieSharing = yield core.logout();
3010
- const clientDomain = getDomain(
3011
- subdomainCookieSharing,
3012
- window.location.hostname
3013
- );
3014
- removeCookie(PpLocalStorageKey.refreshToken, clientDomain);
3015
- removeCookie(PpLocalStorageKey.codeVerifier, clientDomain);
2656
+ yield core.logout();
3016
2657
  return { statusCode: MiniAppStatusType.loggedOut };
3017
2658
  } catch (error) {
3018
2659
  throw new PPError(
@@ -3245,8 +2886,8 @@ function executePendingFunctionCalls(client2) {
3245
2886
  }
3246
2887
  }
3247
2888
  const clientProperties = {
3248
- version: "2.38.0",
3249
- revision: "55465a6"
2889
+ version: "2.39.0",
2890
+ revision: "c39c952"
3250
2891
  };
3251
2892
  function getClient({ sdkType }) {
3252
2893
  clientSdkType = sdkType;