@paypay/mini-app-js-sdk 2.8.0 → 2.11.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.
Files changed (49) hide show
  1. package/dist/client/clientUtils.d.ts +9 -4
  2. package/dist/client/coreIframe.d.ts +2 -1
  3. package/dist/client/index.d.ts +10 -1
  4. package/dist/client/supportedFunctionsList.d.ts +2 -2
  5. package/dist/core/coreFunctions/claimCoupon.d.ts +6 -0
  6. package/dist/core/coreFunctions/fetchCoupons.d.ts +8 -0
  7. package/dist/core/coreFunctions/index.d.ts +4 -0
  8. package/dist/core/coreFunctions/logEvent.d.ts +12 -0
  9. package/dist/core/coreFunctions/logout.d.ts +1 -0
  10. package/dist/core/coreUtils.d.ts +10 -3
  11. package/dist/core/coupon/couponFunctions/index.d.ts +1 -0
  12. package/dist/core/coupon/couponFunctions/renderCoupons.d.ts +9 -0
  13. package/dist/core/coupon/index.d.ts +3 -0
  14. package/dist/core/index.d.ts +5 -0
  15. package/dist/environment-variables.d.ts +4 -0
  16. package/dist/index.d.ts +3 -0
  17. package/dist/jsbridge-core/lib/browser.d.ts +3 -0
  18. package/dist/jsbridge-core/paypay-jsbridge.d.ts +16 -0
  19. package/dist/mini-app-js-sdk.browser.js +1 -1
  20. package/dist/mini-app-js-sdk.d.ts +10 -0
  21. package/dist/mini-app-js-sdk.es.js +937 -176
  22. package/dist/model/bridge/getConfigure.d.ts +2 -2
  23. package/dist/model/bridge/getLoginUrl.d.ts +9 -0
  24. package/dist/model/bridge/index.d.ts +47 -0
  25. package/dist/model/bridge/render.d.ts +0 -12
  26. package/dist/model/bridge/renderLoginButton.d.ts +2 -2
  27. package/dist/model/makePayment.d.ts +7 -0
  28. package/dist/package/button/index.d.ts +1 -1
  29. package/dist/package/lottie/index.d.ts +73 -0
  30. package/dist/package/lottie/lottie.d.ts +77 -0
  31. package/dist/resources/en.d.ts +1 -0
  32. package/dist/resources/images.d.ts +2 -0
  33. package/dist/resources/ja.d.ts +1 -0
  34. package/dist/types.d.ts +34 -8
  35. package/dist/utils/analytics.d.ts +3 -1
  36. package/dist/utils/api.d.ts +32 -25
  37. package/dist/utils/browsers.d.ts +3 -0
  38. package/dist/utils/fetch.d.ts +2 -1
  39. package/dist/utils/getLanguage.d.ts +1 -0
  40. package/dist/utils/helper.d.ts +3 -3
  41. package/dist/utils/storage.d.ts +8 -0
  42. package/dist/utils/windowBridge.d.ts +24 -0
  43. package/dist/views/coupon/components/Arrow/index.d.ts +17 -0
  44. package/dist/views/coupon/components/CouponAction/index.d.ts +39 -0
  45. package/dist/views/coupon/components/CouponContainer/index.d.ts +14 -0
  46. package/dist/views/coupon/index.d.ts +38 -0
  47. package/dist/views/coupon/types.d.ts +34 -0
  48. package/dist/views/registerPaymentFeatures/types.d.ts +9 -0
  49. package/package.json +15 -11
@@ -113,7 +113,9 @@ var PpLocalStorageKey = /* @__PURE__ */ ((PpLocalStorageKey2) => {
113
113
  PpLocalStorageKey2["clientOrigin"] = "ppjssdk.clientOrigin";
114
114
  PpLocalStorageKey2["clientVersion"] = "ppjssdk.clientVersion";
115
115
  PpLocalStorageKey2["debugMode"] = "ppjssdk.debugMode";
116
+ PpLocalStorageKey2["claimCouponImmediately"] = "ppjssdk.claimCouponImmediately";
116
117
  PpLocalStorageKey2["merchant"] = "ppjssdk.merchant";
118
+ PpLocalStorageKey2["consumedOTT"] = "ppjssdk.consumedOTT";
117
119
  return PpLocalStorageKey2;
118
120
  })(PpLocalStorageKey || {});
119
121
  const PPFunctionResult = {
@@ -168,7 +170,8 @@ const PPFunctionName = {
168
170
  handleMessageFromNative: "handleMessageFromNative",
169
171
  initKycPassport: "initKycPassport",
170
172
  smsAuth: "smsAuth",
171
- getKycPassportInfo: "getKycPassportInfo"
173
+ getKycPassportInfo: "getKycPassportInfo",
174
+ renderCoupons: "renderCoupons"
172
175
  };
173
176
  const PPUtilFunctionName = {
174
177
  reload: "reload",
@@ -230,102 +233,24 @@ const miniAppSupportedFunctions = [
230
233
  "shortcutExists",
231
234
  "addShortcut",
232
235
  "logAppsFlyerEvent",
233
- "getAllUserAddresses"
236
+ "getAllUserAddresses",
237
+ "getUserPaymentFeatureSettings"
234
238
  ];
235
239
  function url(path) {
236
240
  return "https://image.paypay.ne.jp/miniapps/mini-app-sdk/" + path;
237
241
  }
238
242
  const img_paypayRec = url("icon-paypay-rec.svg");
239
243
  const img_paypayRecWhite = url("icon-paypay-rec-white.svg");
240
- function checkIFrameOrigin(origin, env2, coreVersion2) {
241
- return origin === getIframeOrigin(env2, coreVersion2);
242
- }
243
- function getIframeOrigin(env2, coreVersion2) {
244
- const iframeUrl = new URL(getIframeUrl(env2, coreVersion2));
245
- return iframeUrl.origin;
246
- }
247
- function getIframeUrl(env2, coreVersion2) {
248
- const version = "2.8.0";
249
- return `${getUrl()}?v=${version}`;
250
- function getUrl() {
251
- switch (env2) {
252
- case "staging":
253
- case "sandbox":
254
- case "canary":
255
- case "qa": {
256
- if (coreVersion2 === "staging") {
257
- return "https://mini-app-sdk-core.paypay.ne.jp/dev/stg/iframe.html";
258
- } else {
259
- return "https://mini-app-sdk-core.paypay.ne.jp/iframe.html";
260
- }
261
- }
262
- case "production":
263
- default:
264
- return "https://mini-app-sdk-core.paypay.ne.jp/iframe.html";
265
- }
266
- }
267
- }
268
- function getIconUrl(theme) {
269
- return theme === "red" ? img_paypayRecWhite : img_paypayRec;
270
- }
271
- function convertToString(str) {
272
- return str ? String(str) : "";
273
- }
274
- function generateMessageId() {
275
- return Math.random().toString(36).substring(7);
276
- }
277
- function removeCookie(key, domain) {
278
- api.remove(key);
279
- api.remove(key, { domain });
280
- }
281
- function saveRefreshToken(refreshToken, domain, isSecure) {
282
- removeCookie(PpLocalStorageKey.refreshToken, domain);
283
- return api.set(PpLocalStorageKey.refreshToken, refreshToken, {
284
- domain,
285
- expires: 90,
286
- secure: isSecure
287
- });
288
- }
289
- function saveCodeVerifier(codeVerifier, domain, isSecure) {
290
- removeCookie(PpLocalStorageKey.codeVerifier, domain);
291
- return api.set(PpLocalStorageKey.codeVerifier, codeVerifier, {
292
- domain,
293
- secure: isSecure
294
- });
295
- }
296
- function getRefreshToken() {
297
- return api.get(PpLocalStorageKey.refreshToken) || "";
298
- }
299
- function getCodeVerifier() {
300
- return api.get(PpLocalStorageKey.codeVerifier) || "";
301
- }
302
- function exposeClientJsBridge(jsBridge) {
303
- const global = window;
304
- if (global.hasOwnProperty(jsBridgeNamespace) && global[jsBridgeNamespace] === jsBridge) {
244
+ if (!isEnableLocalStorage())
245
+ ;
246
+ function isEnableLocalStorage() {
247
+ try {
248
+ localStorage.getItem("ppjssdk.canWriteToLocalStorage");
249
+ return true;
250
+ } catch (e) {
251
+ console.log(e);
305
252
  return false;
306
253
  }
307
- global[jsBridgeNamespace] = jsBridge;
308
- return true;
309
- }
310
- function consoleDebugInfo(params) {
311
- console.debug(...params);
312
- }
313
- function isSupportedMiniapp(functionName) {
314
- return miniAppSupportedFunctions.includes(functionName);
315
- }
316
- let runningFunctions = [];
317
- function isFunctionRunning() {
318
- return runningFunctions.length > 0;
319
- }
320
- function functionEnd(messageId) {
321
- runningFunctions = runningFunctions.filter((val) => {
322
- return val !== messageId;
323
- });
324
- }
325
- function functionStart() {
326
- const messageId = generateMessageId();
327
- runningFunctions.push(messageId);
328
- return messageId;
329
254
  }
330
255
  var MiniAppErrorType = /* @__PURE__ */ ((MiniAppErrorType2) => {
331
256
  MiniAppErrorType2["success"] = "SUCCESS";
@@ -391,17 +316,684 @@ var MiniAppErrorType = /* @__PURE__ */ ((MiniAppErrorType2) => {
391
316
  MiniAppErrorType2["noLocationData"] = "NO_LOCATION_DATA";
392
317
  return MiniAppErrorType2;
393
318
  })(MiniAppErrorType || {});
394
- var style = "";
319
+ function isIP(hostName) {
320
+ return isIPv4(hostName) || isIPv6(hostName);
321
+ }
322
+ function isIPv4(hostName) {
323
+ 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*$)/;
324
+ return expression.test(hostName);
325
+ }
326
+ function isIPv6(hostName) {
327
+ 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*$)/;
328
+ return expression.test(hostName);
329
+ }
330
+ const secondaryList = [
331
+ "ab.ca",
332
+ "ac.ac",
333
+ "ac.ae",
334
+ "ac.at",
335
+ "ac.be",
336
+ "ac.cn",
337
+ "ac.il",
338
+ "ac.in",
339
+ "ac.jp",
340
+ "ac.kr",
341
+ "ac.th",
342
+ "ac.uk",
343
+ "ac.sg",
344
+ "ad.jp",
345
+ "adm.br",
346
+ "adv.br",
347
+ "ah.cn",
348
+ "am.br",
349
+ "arq.br",
350
+ "art.br",
351
+ "arts.ro",
352
+ "asn.au",
353
+ "asso.fr",
354
+ "asso.mc",
355
+ "bc.ca",
356
+ "bio.br",
357
+ "biz.pl",
358
+ "biz.tr",
359
+ "bj.cn",
360
+ "bel.tr",
361
+ "br.com",
362
+ "cn.com",
363
+ "cng.br",
364
+ "cnt.br",
365
+ "co.ac",
366
+ "co.at",
367
+ "co.de",
368
+ "co.gl",
369
+ "co.hk",
370
+ "co.id",
371
+ "co.il",
372
+ "co.in",
373
+ "co.jp",
374
+ "co.kr",
375
+ "co.mg",
376
+ "co.ms",
377
+ "co.nz",
378
+ "co.th",
379
+ "cp.tz",
380
+ "co.uk",
381
+ "co.ve",
382
+ "co.vi",
383
+ "co.za",
384
+ "com.ag",
385
+ "com.ai",
386
+ "com.ar",
387
+ "com.au",
388
+ "com.br",
389
+ "com.co",
390
+ "com.cn",
391
+ "com.cy",
392
+ "com.de",
393
+ "com.do",
394
+ "com.ec",
395
+ "com.es",
396
+ "com.fj",
397
+ "com.fr",
398
+ "com.gl",
399
+ "com.gt",
400
+ "com.hk",
401
+ "com.hr",
402
+ "com.hu",
403
+ "com.kg",
404
+ "com.ki",
405
+ "com.lc",
406
+ "com.mg",
407
+ "com.mm",
408
+ "com.ms",
409
+ "com.mt",
410
+ "com.mu",
411
+ "com.mx",
412
+ "com.my",
413
+ "com.na",
414
+ "com.nf",
415
+ "com.ng",
416
+ "com.ni",
417
+ "com.pa",
418
+ "com.ph",
419
+ "com.pl",
420
+ "com.pt",
421
+ "com.qa",
422
+ "com.ro",
423
+ "com.ru",
424
+ "com.sb",
425
+ "com.sc",
426
+ "com.sg",
427
+ "com.sv",
428
+ "com.tr",
429
+ "com.tw",
430
+ "com.ua",
431
+ "com.uy",
432
+ "com.ve",
433
+ "com.vn",
434
+ "cq.cn",
435
+ "de.com",
436
+ "de.org",
437
+ "ecn.br",
438
+ "ed.jp",
439
+ "edu.au",
440
+ "edu.cn",
441
+ "edu.hk",
442
+ "edu.mm",
443
+ "edu.my",
444
+ "edu.pl",
445
+ "edu.pt",
446
+ "edu.qa",
447
+ "edu.sg",
448
+ "edu.tr",
449
+ "edu.tw",
450
+ "eng.br",
451
+ "ernet.in",
452
+ "esp.br",
453
+ "etc.br",
454
+ "eti.br",
455
+ "eu.com",
456
+ "eu.int",
457
+ "eu.lv",
458
+ "firm.in",
459
+ "firm.ro",
460
+ "fm.br",
461
+ "fot.br",
462
+ "fst.br",
463
+ "g12.br",
464
+ "gb.com",
465
+ "gb.net",
466
+ "gd.cn",
467
+ "gen.in",
468
+ "go.jp",
469
+ "go.kr",
470
+ "go.th",
471
+ "gov.au",
472
+ "gov.az",
473
+ "gov.br",
474
+ "gov.cn",
475
+ "gov.il",
476
+ "gov.in",
477
+ "gov.mm",
478
+ "gov.my",
479
+ "gov.qa",
480
+ "gov.sg",
481
+ "gov.tr",
482
+ "gov.tw",
483
+ "gov.uk",
484
+ "govt.nz",
485
+ "gr.jp",
486
+ "gs.cn",
487
+ "gv.ac",
488
+ "gv.at",
489
+ "gx.cn",
490
+ "gz.cn",
491
+ "he.cn",
492
+ "hi.cn",
493
+ "hk.cn",
494
+ "hl.cn",
495
+ "hu.com",
496
+ "id.au",
497
+ "idv.tw",
498
+ "in.ua",
499
+ "in.th",
500
+ "ind.br",
501
+ "ind.in",
502
+ "inf.br",
503
+ "info.pl",
504
+ "info.ro",
505
+ "info.tr",
506
+ "info.ve",
507
+ "iwi.nz",
508
+ "jl.cn",
509
+ "jor.br",
510
+ "js.cn",
511
+ "jus.br",
512
+ "k12.il",
513
+ "k12.tr",
514
+ "kr.com",
515
+ "lel.br",
516
+ "lg.jp",
517
+ "ln.cn",
518
+ "ltd.uk",
519
+ "mb.ca",
520
+ "me.uk",
521
+ "med.br",
522
+ "mi.th",
523
+ "mil.br",
524
+ "mil.uk",
525
+ "mo.cn",
526
+ "mod.uk",
527
+ "muni.il",
528
+ "nb.ca",
529
+ "ne.jp",
530
+ "ne.kr",
531
+ "net.ag",
532
+ "net.ai",
533
+ "net.au",
534
+ "net.br",
535
+ "net.cn",
536
+ "net.do",
537
+ "net.gl",
538
+ "net.hk",
539
+ "net.il",
540
+ "net.in",
541
+ "net.kg",
542
+ "net.ki",
543
+ "net.lc",
544
+ "net.mg",
545
+ "net.mm",
546
+ "net.mu",
547
+ "net.ni",
548
+ "net.nz",
549
+ "net.pl",
550
+ "net.ru",
551
+ "net.sb",
552
+ "net.sc",
553
+ "net.sg",
554
+ "net.th",
555
+ "net.tr",
556
+ "net.tw",
557
+ "net.uk",
558
+ "net.ve",
559
+ "nf.ca",
560
+ "nhs.uk",
561
+ "nm.cn",
562
+ "nm.kr",
563
+ "no.com",
564
+ "nom.br",
565
+ "nom.ni",
566
+ "nom.ro",
567
+ "ns.ca",
568
+ "nt.ca",
569
+ "nt.ro",
570
+ "ntr.br",
571
+ "nx.cn",
572
+ "odo.br",
573
+ "off.ai",
574
+ "on.ca",
575
+ "or.ac",
576
+ "or.at",
577
+ "or.jp",
578
+ "or.kr",
579
+ "or.th",
580
+ "org.ag",
581
+ "org.ai",
582
+ "org.au",
583
+ "org.br",
584
+ "org.cn",
585
+ "org.do",
586
+ "org.es",
587
+ "org.gl",
588
+ "org.hk",
589
+ "org.in",
590
+ "org.kg",
591
+ "org.ki",
592
+ "org.lc",
593
+ "org.mg",
594
+ "org.mm",
595
+ "org.ms",
596
+ "org.nf",
597
+ "org.ng",
598
+ "org.ni",
599
+ "org.nz",
600
+ "org.pl",
601
+ "org.ro",
602
+ "org.ru",
603
+ "org.sb",
604
+ "org.sc",
605
+ "org.sg",
606
+ "org.tr",
607
+ "org.tw",
608
+ "org.uk",
609
+ "org.ve",
610
+ "pe.ca",
611
+ "plc.uk",
612
+ "ppg.br",
613
+ "pro.br",
614
+ "psc.br",
615
+ "psi.br",
616
+ "qc.ca",
617
+ "qc.com",
618
+ "qh.cn",
619
+ "rec.br",
620
+ "rec.ro",
621
+ "res.in",
622
+ "sa.com",
623
+ "sc.cn",
624
+ "sch.uk",
625
+ "se.com",
626
+ "se.net",
627
+ "sh.cn",
628
+ "sk.ca",
629
+ "slg.br",
630
+ "sn.cn",
631
+ "store.ro",
632
+ "tj.cn",
633
+ "tm.fr",
634
+ "tm.mc",
635
+ "tm.ro",
636
+ "tmp.br",
637
+ "tur.br",
638
+ "tv.br",
639
+ "tv.tr",
640
+ "tw.cn",
641
+ "uk.com",
642
+ "uk.net",
643
+ "us.com",
644
+ "uy.com",
645
+ "vet.br",
646
+ "waw.pl",
647
+ "web.ve",
648
+ "www.ro",
649
+ "xj.cn",
650
+ "xz.cn",
651
+ "yk.ca",
652
+ "yn.cn",
653
+ "zj.cn",
654
+ "zlg.br"
655
+ ];
656
+ function parseDomain(domain) {
657
+ const splitStr = domain.split(".");
658
+ if (isIP(domain) || splitStr.length <= 2) {
659
+ return domain;
660
+ }
661
+ const secondary = splitStr.slice(splitStr.length - 2).join(".");
662
+ if (secondaryList.includes(secondary) && splitStr.length >= 3) {
663
+ return splitStr.slice(splitStr.length - 3).join(".");
664
+ }
665
+ return splitStr.slice(splitStr.length - 2).join(".");
666
+ }
667
+ function getDomain(subdomainCookieSharing, hostname) {
668
+ return subdomainCookieSharing ? parseDomain(hostname) : hostname;
669
+ }
670
+ function getRandomString() {
671
+ return Math.random().toString(36).substring(7);
672
+ }
673
+ const JS_SDK_VERSION = "2.11.0";
674
+ const coreBaseUrl = new URL("https://mini-app-sdk-core.paypay.ne.jp/");
675
+ const CORE_IFRAME_ORIGIN = coreBaseUrl.origin;
676
+ const CORE_IFRAME_URL = new URL(
677
+ `./iframe.html?v=${JS_SDK_VERSION}`,
678
+ coreBaseUrl
679
+ ).href;
680
+ const COUPON_IFRAME_URL = new URL(
681
+ `./coupon/iframe.html?v=${JS_SDK_VERSION}`,
682
+ coreBaseUrl
683
+ ).href;
684
+ function checkIFrameOrigin(origin) {
685
+ return origin === CORE_IFRAME_ORIGIN;
686
+ }
687
+ function getIconUrl(theme) {
688
+ return theme === "red" ? img_paypayRecWhite : img_paypayRec;
689
+ }
690
+ function convertToString(str) {
691
+ return str ? String(str) : "";
692
+ }
693
+ function removeCookie(key, domain) {
694
+ api.remove(key);
695
+ api.remove(key, { domain });
696
+ }
697
+ function saveRefreshToken(refreshToken, domain, isSecure) {
698
+ removeCookie(PpLocalStorageKey.refreshToken, domain);
699
+ return api.set(PpLocalStorageKey.refreshToken, refreshToken, {
700
+ domain,
701
+ expires: 90,
702
+ secure: isSecure
703
+ });
704
+ }
705
+ function saveCodeVerifier(codeVerifier, domain, isSecure) {
706
+ removeCookie(PpLocalStorageKey.codeVerifier, domain);
707
+ return api.set(PpLocalStorageKey.codeVerifier, codeVerifier, {
708
+ domain,
709
+ secure: isSecure
710
+ });
711
+ }
712
+ function getRefreshToken() {
713
+ return api.get(PpLocalStorageKey.refreshToken) || "";
714
+ }
715
+ function getCodeVerifier() {
716
+ return api.get(PpLocalStorageKey.codeVerifier) || "";
717
+ }
718
+ function exposeClientJsBridge(jsBridge) {
719
+ const global = window;
720
+ if (
721
+ // eslint-disable-next-line no-prototype-builtins, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
722
+ global.hasOwnProperty(jsBridgeNamespace) && // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
723
+ global[jsBridgeNamespace] === jsBridge
724
+ ) {
725
+ return false;
726
+ }
727
+ global[jsBridgeNamespace] = jsBridge;
728
+ return true;
729
+ }
730
+ function consoleDebugInfo(params) {
731
+ console.debug(...params);
732
+ }
733
+ function isSupportedMiniapp(functionName) {
734
+ return miniAppSupportedFunctions.includes(functionName);
735
+ }
736
+ let runningFunctions = [];
737
+ function isFunctionRunning() {
738
+ return runningFunctions.length > 0;
739
+ }
740
+ function functionEnd(messageId) {
741
+ runningFunctions = runningFunctions.filter((val) => {
742
+ return val !== messageId;
743
+ });
744
+ }
745
+ function functionStart() {
746
+ const messageId = getRandomString();
747
+ runningFunctions.push(messageId);
748
+ return messageId;
749
+ }
750
+ class ClientError extends Error {
751
+ constructor(message, payload) {
752
+ super(message);
753
+ this.payload = payload;
754
+ }
755
+ }
756
+ function promiseToCallback(functionName, target, getCore2, getLoggingParams) {
757
+ return function(params = {}) {
758
+ const core2 = getCore2();
759
+ const loggingParams = getLoggingParams == null ? void 0 : getLoggingParams(params);
760
+ void core2.logEvent({
761
+ event_action: `pp_${functionName}_called`,
762
+ ...loggingParams
763
+ });
764
+ target(params).then((result) => {
765
+ var _a;
766
+ void core2.logEvent({
767
+ event_action: `pp_${functionName}_success`,
768
+ ...loggingParams
769
+ });
770
+ (_a = params.success) == null ? void 0 : _a.call(params, result);
771
+ }).catch((error) => {
772
+ var _a;
773
+ console.error(error.message);
774
+ void core2.logEvent({
775
+ event_action: `pp_${functionName}_fail`,
776
+ error_value: error.payload.errorCode,
777
+ ...loggingParams
778
+ });
779
+ (_a = params.fail) == null ? void 0 : _a.call(params, error.payload);
780
+ }).finally(() => {
781
+ var _a;
782
+ (_a = params.complete) == null ? void 0 : _a.call(params);
783
+ });
784
+ };
785
+ }
786
+ class WindowBridge {
787
+ constructor(functions, allowedOrigins) {
788
+ this.deferredCallbacks = {};
789
+ this.functions = functions;
790
+ this.allowedOrigins = allowedOrigins;
791
+ this.subscribeToMessageEvent();
792
+ }
793
+ /**
794
+ * Subscribe to message event to handle incoming messages.
795
+ * These messages can be of two types
796
+ * 1. A function call from another window
797
+ * 2. Response of a function call made from this window to another window
798
+ */
799
+ subscribeToMessageEvent() {
800
+ window.addEventListener(
801
+ "message",
802
+ (receivedMessageEvent) => {
803
+ var _a;
804
+ if (!((_a = receivedMessageEvent.data) == null ? void 0 : _a.forWindowBridge)) {
805
+ return;
806
+ }
807
+ if (this.allowedOrigins && !this.allowedOrigins.includes(receivedMessageEvent.origin)) {
808
+ return this.sendErrorResponse(
809
+ receivedMessageEvent,
810
+ "originNotAllowed",
811
+ `${receivedMessageEvent.origin} is not allowed to make requests`
812
+ );
813
+ }
814
+ if (receivedMessageEvent.data.type === "request") {
815
+ void this.handleRequest(
816
+ receivedMessageEvent
817
+ );
818
+ } else if (receivedMessageEvent.data.type === "response") {
819
+ this.handleResponse(
820
+ receivedMessageEvent
821
+ );
822
+ }
823
+ }
824
+ );
825
+ }
826
+ async handleRequest(receivedMessageEvent) {
827
+ const functionToInvoke = this.functions[receivedMessageEvent.data.functionName];
828
+ if (!functionToInvoke) {
829
+ this.sendErrorResponse(
830
+ receivedMessageEvent,
831
+ "functionNotFound"
832
+ /* functionNotFound */
833
+ );
834
+ }
835
+ try {
836
+ this.sendSuccessResponse(
837
+ receivedMessageEvent,
838
+ await functionToInvoke(...receivedMessageEvent.data.params)
839
+ );
840
+ } catch (error) {
841
+ this.sendErrorResponse(
842
+ receivedMessageEvent,
843
+ "runTimeError",
844
+ error.message
845
+ );
846
+ }
847
+ }
848
+ handleResponse(receivedMessageEvent) {
849
+ if (!this.deferredCallbacks[receivedMessageEvent.data.key]) {
850
+ console.warn(
851
+ `Callback for ${receivedMessageEvent.data.functionName} not found`
852
+ );
853
+ return;
854
+ }
855
+ const [resolve, reject] = this.deferredCallbacks[receivedMessageEvent.data.key];
856
+ delete this.deferredCallbacks[receivedMessageEvent.data.key];
857
+ if (receivedMessageEvent.data.status === "success") {
858
+ resolve(receivedMessageEvent.data.result);
859
+ } else {
860
+ reject({
861
+ code: receivedMessageEvent.data.code,
862
+ message: receivedMessageEvent.data.message
863
+ });
864
+ }
865
+ }
866
+ sendErrorResponse(receivedMessageEvent, code, message) {
867
+ this.sendResponse(receivedMessageEvent, {
868
+ status: "failure",
869
+ code,
870
+ message
871
+ });
872
+ }
873
+ sendSuccessResponse(receivedMessageEvent, result) {
874
+ this.sendResponse(receivedMessageEvent, {
875
+ status: "success",
876
+ result
877
+ });
878
+ }
879
+ sendResponse(receivedMessageEvent, data) {
880
+ var _a;
881
+ (_a = receivedMessageEvent.source) == null ? void 0 : _a.postMessage(
882
+ {
883
+ forWindowBridge: true,
884
+ type: "response",
885
+ key: receivedMessageEvent.data.key,
886
+ functionName: receivedMessageEvent.data.functionName,
887
+ ...data
888
+ },
889
+ // Just a hack to overcome weird function overload mismatch
890
+ receivedMessageEvent.origin
891
+ );
892
+ }
893
+ /**
894
+ * A static method to create a new `WindowBridge` instance and enforce singleton pattern
895
+ * @param functions an objection of functions that can be invoked on the current window
896
+ * @param allowedOrigins a list of allowed origins from where request can be accepted
897
+ * @returns `WindowBridge` instance
898
+ */
899
+ static init(functions, allowedOrigins) {
900
+ if (this._instance) {
901
+ throw new Error(
902
+ "WindowBridge already initialized, you can't call WindowBridge.init twice"
903
+ );
904
+ }
905
+ this._instance = new this(functions, allowedOrigins);
906
+ return this._instance;
907
+ }
908
+ /**
909
+ * A static method to get an existing `WindowBridge` instance
910
+ * @returns `WindowBridge` instance
911
+ */
912
+ static getBridge() {
913
+ if (!this._instance) {
914
+ throw new Error(
915
+ "WindowBridge not initialized, please call WindowBridge.init before calling WindowBridge.getBridge"
916
+ );
917
+ }
918
+ return this._instance;
919
+ }
920
+ /**
921
+ * A static function that returns a proxy object to invoke functions on a target window.
922
+ * We can call it multiple times to invoke functions on different windows
923
+ * @param getTargetWindow a function that returns the target window where we want to invoke functions
924
+ * @param targetWindowOrigin origin of the target window
925
+ * @returns a proxy object to call functions from target window as an asynchronous function
926
+ */
927
+ static getTargetWindowFunctionProxy(getTargetWindow, targetWindowOrigin) {
928
+ return WindowBridge.getBridge().getTargetWindowFunctionProxy(
929
+ getTargetWindow,
930
+ targetWindowOrigin
931
+ );
932
+ }
933
+ /**
934
+ * It returns a proxy object to invoke functions on a target window.
935
+ * We can call it multiple times to invoke functions on different windows
936
+ * @param getTargetWindow a function that returns the target window where we want to invoke functions
937
+ * @param targetWindowOrigin origin of the target window
938
+ * @returns a proxy object to call functions from target window as an asynchronous function
939
+ */
940
+ getTargetWindowFunctionProxy(getTargetWindow, targetWindowOrigin) {
941
+ return new Proxy(this, {
942
+ get(windowBridgeInstance, functionName) {
943
+ return (...params) => (
944
+ // eslint-disable-next-line no-async-promise-executor, @typescript-eslint/no-misused-promises
945
+ new Promise(async (resolve, reject) => {
946
+ const functionNameString = functionName.toString();
947
+ const key = `${functionNameString}--${getRandomString()}`;
948
+ try {
949
+ const targetWindow = await getTargetWindow();
950
+ if (!targetWindow) {
951
+ throw new Error("Target window is undefined");
952
+ }
953
+ targetWindow.postMessage(
954
+ {
955
+ forWindowBridge: true,
956
+ type: "request",
957
+ functionName: functionNameString,
958
+ key,
959
+ params
960
+ },
961
+ targetWindowOrigin
962
+ );
963
+ windowBridgeInstance.deferredCallbacks[key] = [resolve, reject];
964
+ } catch (error) {
965
+ reject({
966
+ code: "messageSendingFailed",
967
+ message: error.message
968
+ });
969
+ }
970
+ })
971
+ );
972
+ }
973
+ });
974
+ }
975
+ }
976
+ const style = "";
977
+ var MiniAppStatusType = /* @__PURE__ */ ((MiniAppStatusType2) => {
978
+ MiniAppStatusType2["validToken"] = "TOKEN_VALID";
979
+ MiniAppStatusType2["initialized"] = "INITIALIZED";
980
+ MiniAppStatusType2["emailRegistered"] = "EMAIL_REGISTERED";
981
+ MiniAppStatusType2["emailNotVerified"] = "EMAIL_NOT_VERIFIED";
982
+ MiniAppStatusType2["success"] = "SUCCESS";
983
+ MiniAppStatusType2["loggedOut"] = "LOGGED_OUT";
984
+ MiniAppStatusType2["connected"] = "CONNECTED";
985
+ return MiniAppStatusType2;
986
+ })(MiniAppStatusType || {});
395
987
  const IFRAME_NAME = "ppmna-iframe";
396
988
  const IFRAME_CONTAINER_NAME = "ppsdk-container";
397
- let _env;
398
- let _coreVersion;
399
- let _zIndex;
400
- function initCoreIframe(env2, coreVersion2, zIndex) {
401
- _env = env2;
402
- _coreVersion = coreVersion2;
403
- _zIndex = zIndex;
404
- getCoreIframe();
989
+ function initCoreIframe() {
990
+ if (document.readyState === "loading") {
991
+ document.addEventListener("DOMContentLoaded", () => {
992
+ void getCoreIframe();
993
+ });
994
+ } else {
995
+ void getCoreIframe();
996
+ }
405
997
  }
406
998
  let iframeContainer;
407
999
  function getCoreIframeContainer() {
@@ -422,7 +1014,7 @@ function createIframeContainer() {
422
1014
  container.style.height = "100%";
423
1015
  container.style.top = "0";
424
1016
  container.style.left = "0";
425
- container.style.zIndex = _zIndex || "2147483637";
1017
+ container.style.zIndex = "2147483637";
426
1018
  document.body.appendChild(container);
427
1019
  return container;
428
1020
  }
@@ -437,10 +1029,13 @@ function getCoreIframe() {
437
1029
  }
438
1030
  return coreIframeLoadingPromise;
439
1031
  }
1032
+ function getCoreIframeWindow() {
1033
+ return getCoreIframe().then((iframe) => iframe == null ? void 0 : iframe.contentWindow).catch(() => null);
1034
+ }
440
1035
  function createIframe() {
441
1036
  return new Promise((resolve, reject) => {
442
1037
  const iframe = document.createElement("iframe");
443
- iframe.setAttribute("src", getIframeUrl(_env, _coreVersion));
1038
+ iframe.setAttribute("src", CORE_IFRAME_URL);
444
1039
  iframe.setAttribute("name", IFRAME_NAME);
445
1040
  iframe.setAttribute("id", IFRAME_NAME);
446
1041
  iframe.setAttribute("class", IFRAME_NAME);
@@ -458,11 +1053,23 @@ function createIframe() {
458
1053
  container.append(iframe);
459
1054
  });
460
1055
  }
461
- let env;
1056
+ const windowBridge = WindowBridge.init({});
462
1057
  let useAllFunctions = false;
463
- let coreVersion = "";
1058
+ let initDonePromise;
1059
+ initCoreIframe();
1060
+ const core = windowBridge.getTargetWindowFunctionProxy(
1061
+ getCoreIframeWindow,
1062
+ CORE_IFRAME_ORIGIN
1063
+ );
1064
+ function getCore() {
1065
+ return core;
1066
+ }
464
1067
  const commonMessageHandler = (e) => {
465
- if (!checkIFrameOrigin(e.origin, env, coreVersion)) {
1068
+ var _a;
1069
+ if ((_a = e.data) == null ? void 0 : _a.forWindowBridge) {
1070
+ return;
1071
+ }
1072
+ if (!checkIFrameOrigin(e.origin)) {
466
1073
  return;
467
1074
  }
468
1075
  if (e.data.name === PPUtilFunctionName.reload) {
@@ -495,18 +1102,16 @@ const commonMessageHandler = (e) => {
495
1102
  };
496
1103
  addEventListener("message", commonMessageHandler);
497
1104
  function init(params) {
498
- coreVersion = params.coreVersion;
499
1105
  const url2 = new URL(window.location.href);
500
1106
  const token = url2.searchParams.get("token");
501
1107
  const ott = url2.searchParams.get("one_time_token");
502
1108
  const refreshToken = getRefreshToken();
503
1109
  const codeVerifier = getCodeVerifier();
504
- const clientVersion = "2.8.0";
1110
+ const clientVersion = "2.11.0";
505
1111
  useAllFunctions = !!params.useAllFunctions;
506
1112
  if (token || ott) {
507
1113
  removeTokenFromUrl(url2);
508
1114
  }
509
- env = params.env;
510
1115
  const initParams = {
511
1116
  env: params.env,
512
1117
  mode: params.mode,
@@ -518,8 +1123,25 @@ function init(params) {
518
1123
  clientVersion,
519
1124
  codeVerifier
520
1125
  };
521
- initCoreIframe(env, coreVersion, params.zIndex);
522
- triggerPostMessageToCore(PPFunctionName.init, false, params, initParams);
1126
+ let initDonePromiseResolve;
1127
+ initDonePromise = new Promise((resolve) => initDonePromiseResolve = resolve);
1128
+ const complete = () => {
1129
+ var _a;
1130
+ initDonePromiseResolve(true);
1131
+ (_a = params.complete) == null ? void 0 : _a.call(params);
1132
+ };
1133
+ getCoreIframe().then(() => {
1134
+ triggerPostMessageToCore(
1135
+ PPFunctionName.init,
1136
+ false,
1137
+ { ...params, complete },
1138
+ initParams
1139
+ );
1140
+ }).catch(() => {
1141
+ var _a;
1142
+ (_a = params.fail) == null ? void 0 : _a.call(params, { errorCode: MiniAppErrorType.sdkNotInitialized });
1143
+ complete();
1144
+ });
523
1145
  }
524
1146
  function getAuthStatus(params) {
525
1147
  const url2 = window.location.href;
@@ -555,6 +1177,8 @@ function share(params) {
555
1177
  return;
556
1178
  }
557
1179
  const data = {
1180
+ //url: params.imageUrl,
1181
+ //TODO: -> we need to download the imageUrl and try to attach it to `files`
558
1182
  text: params == null ? void 0 : params.text
559
1183
  };
560
1184
  navigator.share(data).then(() => {
@@ -584,7 +1208,7 @@ function render(params) {
584
1208
  const messageId = functionStart();
585
1209
  const getRenderMessageHandler = (e) => {
586
1210
  var _a2, _b;
587
- if (!checkIFrameOrigin(e.origin, env, coreVersion) || e.data.name !== PPFunctionName.render || e.data.messageId !== messageId) {
1211
+ if (!checkIFrameOrigin(e.origin) || e.data.name !== PPFunctionName.render || e.data.messageId !== messageId) {
588
1212
  return;
589
1213
  }
590
1214
  const info = (_a2 = e.data) == null ? void 0 : _a2.data;
@@ -603,17 +1227,117 @@ function render(params) {
603
1227
  }
604
1228
  };
605
1229
  addEventListener("message", getRenderMessageHandler);
606
- postMessageToCore({
1230
+ void postMessageToCore({
607
1231
  name: PPFunctionName.render,
608
- params,
1232
+ params: {
1233
+ ...params,
1234
+ redirectUrl: params.redirectUrl || window.location.href
1235
+ },
609
1236
  messageId
610
1237
  });
611
1238
  }
1239
+ const renderCoupons = promiseToCallback(
1240
+ "renderCoupons",
1241
+ async (params) => {
1242
+ const {
1243
+ merchant: merchantId,
1244
+ couponId,
1245
+ containerId,
1246
+ postLoginRedirectUrl = window.location.href,
1247
+ postLoginRedirectType,
1248
+ locale
1249
+ } = params;
1250
+ const containerElement = document.getElementById(containerId);
1251
+ if (!containerElement) {
1252
+ throw new ClientError("Invalid coupon container Id", {
1253
+ errorCode: MiniAppErrorType.badRequestInsufficientParameter
1254
+ });
1255
+ }
1256
+ const coupons = await core.fetchCoupons({
1257
+ merchantId,
1258
+ couponId,
1259
+ postLoginRedirectUrl,
1260
+ postLoginRedirectType
1261
+ }).catch(() => {
1262
+ throw new ClientError(
1263
+ `An error occurred while fetching coupons, merchantId=${merchantId} and couponId=${couponId}`,
1264
+ {
1265
+ errorCode: MiniAppErrorType.unknown
1266
+ }
1267
+ );
1268
+ });
1269
+ if (coupons.length === 0) {
1270
+ throw new ClientError(
1271
+ `No coupon found for merchantId=${merchantId} and couponId=${couponId}`,
1272
+ {
1273
+ errorCode: MiniAppErrorType.notAvailable
1274
+ }
1275
+ );
1276
+ }
1277
+ const firstCoupon = coupons[0];
1278
+ const currentTimeStamp = (/* @__PURE__ */ new Date()).getTime();
1279
+ if (new Date(firstCoupon.liveStartDate).getTime() > currentTimeStamp) {
1280
+ throw new ClientError("Coupon is not live yet", {
1281
+ errorCode: MiniAppErrorType.invalidData
1282
+ });
1283
+ }
1284
+ if (new Date(firstCoupon.liveEndDate).getTime() < currentTimeStamp) {
1285
+ throw new ClientError("Coupon has expired", {
1286
+ errorCode: MiniAppErrorType.invalidData
1287
+ });
1288
+ }
1289
+ if (firstCoupon.status !== "SCHEDULED") {
1290
+ throw new ClientError(
1291
+ `Coupon status is ${firstCoupon.status} that is not valid`,
1292
+ {
1293
+ errorCode: MiniAppErrorType.invalidData
1294
+ }
1295
+ );
1296
+ }
1297
+ try {
1298
+ const iframeElement = document.createElement("iframe");
1299
+ iframeElement.src = COUPON_IFRAME_URL;
1300
+ iframeElement.style.cssText = "width:100%;height: 0;border: none;transition: height 300ms ease-in;display: block;";
1301
+ await new Promise((resolve, reject) => {
1302
+ iframeElement.onload = () => resolve(true);
1303
+ iframeElement.onerror = () => reject(false);
1304
+ containerElement.innerHTML = "";
1305
+ containerElement.append(iframeElement);
1306
+ });
1307
+ iframeElement.onload = null;
1308
+ iframeElement.onerror = null;
1309
+ window.addEventListener(
1310
+ "message",
1311
+ ({ data, source }) => {
1312
+ if ((data == null ? void 0 : data.eventName) === "update-iframe-height" && iframeElement.contentWindow === source) {
1313
+ iframeElement.style.height = `${data.height}px`;
1314
+ }
1315
+ }
1316
+ );
1317
+ const couponFunctions = windowBridge.getTargetWindowFunctionProxy(
1318
+ () => iframeElement.contentWindow,
1319
+ CORE_IFRAME_ORIGIN
1320
+ );
1321
+ await couponFunctions.renderCoupons({ coupons, merchantId, locale });
1322
+ } catch (error) {
1323
+ throw new ClientError(
1324
+ `An error ocurred while displaying coupons, merchantId=${merchantId}, couponId=${couponId}, error=${error}`,
1325
+ {
1326
+ errorCode: MiniAppErrorType.unknown
1327
+ }
1328
+ );
1329
+ }
1330
+ },
1331
+ getCore,
1332
+ (params) => ({
1333
+ event_label_suffix: params.merchant,
1334
+ event_label2: params.couponId
1335
+ })
1336
+ );
612
1337
  function scanCode(params) {
613
- var _a;
614
1338
  const scanCodeParams = {
615
1339
  ...params,
616
- redirectUrlOnCancel: (_a = params == null ? void 0 : params.redirectUrlOnCancel) != null ? _a : window.location.href
1340
+ redirectUrlOnCancel: (params == null ? void 0 : params.redirectUrlOnCancel) ?? window.location.href
617
1341
  };
618
1342
  triggerPostMessageToCore(
619
1343
  PPFunctionName.scanCode,
@@ -625,25 +1349,25 @@ function scanCode(params) {
625
1349
  function getSessionData(params) {
626
1350
  var _a, _b;
627
1351
  const value = sessionStorage.getItem(params == null ? void 0 : params.key);
628
- (_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params, { [params == null ? void 0 : params.key]: value != null ? value : "" });
1352
+ (_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params, { [params == null ? void 0 : params.key]: value ?? "" });
629
1353
  (_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
630
1354
  }
631
1355
  function setSessionData(params) {
632
- var _a, _b, _c;
633
- sessionStorage.setItem(params == null ? void 0 : params.key, (_a = params == null ? void 0 : params.value) != null ? _a : "");
634
- (_b = params == null ? void 0 : params.success) == null ? void 0 : _b.call(params);
635
- (_c = params == null ? void 0 : params.complete) == null ? void 0 : _c.call(params);
1356
+ var _a, _b;
1357
+ sessionStorage.setItem(params == null ? void 0 : params.key, (params == null ? void 0 : params.value) ?? "");
1358
+ (_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params);
1359
+ (_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
636
1360
  }
637
1361
  function setStorageData(params) {
638
- var _a, _b, _c;
639
- localStorage.setItem(params == null ? void 0 : params.key, (_a = params == null ? void 0 : params.value) != null ? _a : "");
640
- (_b = params == null ? void 0 : params.success) == null ? void 0 : _b.call(params);
641
- (_c = params == null ? void 0 : params.complete) == null ? void 0 : _c.call(params);
1362
+ var _a, _b;
1363
+ localStorage.setItem(params == null ? void 0 : params.key, (params == null ? void 0 : params.value) ?? "");
1364
+ (_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params);
1365
+ (_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
642
1366
  }
643
1367
  function getStorageData(params) {
644
1368
  var _a, _b;
645
1369
  const value = localStorage.getItem(params == null ? void 0 : params.key);
646
- (_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params, { [params == null ? void 0 : params.key]: value != null ? value : "" });
1370
+ (_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params, { [params == null ? void 0 : params.key]: value ?? "" });
647
1371
  (_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
648
1372
  }
649
1373
  function removeStorageData(params) {
@@ -652,6 +1376,29 @@ function removeStorageData(params) {
652
1376
  (_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params);
653
1377
  (_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
654
1378
  }
1379
+ const logout = promiseToCallback(
1380
+ "logout",
1381
+ async () => {
1382
+ try {
1383
+ const subdomainCookieSharing = await core.logout();
1384
+ const clientDomain = getDomain(
1385
+ subdomainCookieSharing,
1386
+ window.location.hostname
1387
+ );
1388
+ removeCookie(PpLocalStorageKey.refreshToken, clientDomain);
1389
+ removeCookie(PpLocalStorageKey.codeVerifier, clientDomain);
1390
+ return { statusCode: MiniAppStatusType.loggedOut };
1391
+ } catch (error) {
1392
+ throw new ClientError(
1393
+ `An error ocurred while trying to logout the user, error=${error}`,
1394
+ {
1395
+ errorCode: MiniAppErrorType.unknown
1396
+ }
1397
+ );
1398
+ }
1399
+ },
1400
+ getCore
1401
+ );
655
1402
  function copyToClipboard(params) {
656
1403
  var _a, _b, _c;
657
1404
  const textarea = document.createElement("textarea");
@@ -688,20 +1435,23 @@ async function postMessageToCore(messageData) {
688
1435
  const iframe = await getCoreIframe().catch(() => void 0);
689
1436
  (_a = iframe == null ? void 0 : iframe.contentWindow) == null ? void 0 : _a.postMessage(
690
1437
  JSON.parse(JSON.stringify(messageData)),
691
- getIframeOrigin(env)
1438
+ CORE_IFRAME_ORIGIN
692
1439
  );
693
1440
  }
694
1441
  function removeTokenFromUrl(url2) {
695
1442
  url2.searchParams.delete("token");
696
1443
  url2.searchParams.delete("one_time_token");
697
1444
  url2.search = url2.searchParams.toString();
698
- history.replaceState(null, "", url2);
1445
+ const newURL = url2.toString().replace(url2.origin, "");
1446
+ history.replaceState(null, "", newURL);
699
1447
  }
700
1448
  function triggerPostMessageToCore(type, showIframeFlag, params, postMessageParams) {
701
1449
  const messageId = functionStart();
702
- showCoreIframe(showIframeFlag);
1450
+ if (showIframeFlag) {
1451
+ showCoreIframe(true);
1452
+ }
703
1453
  const fnMessageHandler = (e) => {
704
- if (!checkIFrameOrigin(e.origin, env, coreVersion)) {
1454
+ if (!checkIFrameOrigin(e.origin)) {
705
1455
  return;
706
1456
  }
707
1457
  if (e.data.name === type) {
@@ -711,27 +1461,27 @@ function triggerPostMessageToCore(type, showIframeFlag, params, postMessageParam
711
1461
  }
712
1462
  };
713
1463
  addEventListener("message", fnMessageHandler);
714
- postMessageToCore({
1464
+ void postMessageToCore({
715
1465
  name: type,
716
1466
  params: postMessageParams,
717
1467
  messageId
718
1468
  });
719
1469
  }
720
1470
  function renderButton(data, params) {
721
- var _a, _b, _c, _d, _e, _f, _g;
1471
+ var _a, _b, _c, _d, _e;
722
1472
  const container = document.getElementById(params.containerId);
723
1473
  const button = document.createElement("button");
724
1474
  button.className = "ppmna-reset-css pp-smartButtonWrapper pp-button";
725
1475
  const iconUrl = getIconUrl(params == null ? void 0 : params.theme);
726
1476
  const cashbackClass = ((_b = (_a = data == null ? void 0 : data.data) == null ? void 0 : _a.cashbackInfo) == null ? void 0 : _b.length) ? "pp-cashback" : "";
727
1477
  const shortTextClass = params.isShortText ? "pp-shortText" : "";
728
- const buttonSize = (_c = params == null ? void 0 : params.buttonSize) != null ? _c : "lg";
729
- const theme = (_d = params == null ? void 0 : params.theme) != null ? _d : "light";
1478
+ const buttonSize = (params == null ? void 0 : params.buttonSize) ?? "lg";
1479
+ const theme = (params == null ? void 0 : params.theme) ?? "light";
730
1480
  const aTag = document.createElement("a");
731
1481
  aTag.className = `pp-smartBtn pp-${theme} pp-${buttonSize} pp-${convertToString(
732
1482
  params.type
733
1483
  )} pp-${data.preferredLanguage} ${cashbackClass} ${shortTextClass}`;
734
- aTag.href = convertToString(params.url);
1484
+ aTag.href = convertToString(data.data.loginUrl);
735
1485
  const leftSpan = document.createElement("span");
736
1486
  leftSpan.className = "pp-leftSection";
737
1487
  const iconImg = document.createElement("img");
@@ -743,14 +1493,14 @@ function renderButton(data, params) {
743
1493
  btnSpan.className = "pp-btnContent";
744
1494
  const titleSpan = document.createElement("span");
745
1495
  titleSpan.className = "pp-title";
746
- titleSpan.innerText = (_e = data == null ? void 0 : data.data) == null ? void 0 : _e.title;
1496
+ titleSpan.innerText = (_c = data == null ? void 0 : data.data) == null ? void 0 : _c.title;
747
1497
  btnSpan.appendChild(titleSpan);
748
1498
  leftSpan.appendChild(btnSpan);
749
1499
  aTag.append(leftSpan);
750
1500
  const cashbackSpan = document.createElement("span");
751
- if ((_f = data == null ? void 0 : data.data) == null ? void 0 : _f.cashbackInfo) {
1501
+ if ((_d = data == null ? void 0 : data.data) == null ? void 0 : _d.cashbackInfo) {
752
1502
  cashbackSpan.className = "pp-cashbackInfo";
753
- cashbackSpan.innerText = (_g = data == null ? void 0 : data.data) == null ? void 0 : _g.cashbackInfo;
1503
+ cashbackSpan.innerText = (_e = data == null ? void 0 : data.data) == null ? void 0 : _e.cashbackInfo;
754
1504
  btnSpan.append(cashbackSpan);
755
1505
  }
756
1506
  if (data.data.avatarUrl) {
@@ -784,29 +1534,32 @@ function renderButton(data, params) {
784
1534
  }
785
1535
  }
786
1536
  const clientJsBridge = {
787
- _handleMessageFromNative: async (json) => {
788
- var _a;
789
- const iframe = await getCoreIframe();
790
- (_a = iframe == null ? void 0 : iframe.contentWindow) == null ? void 0 : _a.postMessage(
791
- JSON.parse(
792
- JSON.stringify({
793
- name: PPFunctionName.handleMessageFromNative,
794
- params: {
795
- json
796
- }
797
- })
798
- ),
799
- getIframeOrigin(env)
800
- );
1537
+ _handleMessageFromNative: (json) => {
1538
+ void getCoreIframe().then((iframe) => {
1539
+ var _a;
1540
+ (_a = iframe == null ? void 0 : iframe.contentWindow) == null ? void 0 : _a.postMessage(
1541
+ JSON.parse(
1542
+ JSON.stringify({
1543
+ name: PPFunctionName.handleMessageFromNative,
1544
+ params: {
1545
+ json
1546
+ }
1547
+ })
1548
+ ),
1549
+ CORE_IFRAME_ORIGIN
1550
+ );
1551
+ });
801
1552
  }
802
1553
  };
803
1554
  exposeClientJsBridge(clientJsBridge);
804
1555
  const clientFunctions = {
1556
+ // functions that run on client, or need special treatment on client
805
1557
  init,
806
1558
  verifyMultiFactorAuthResult,
807
1559
  share,
808
1560
  setTitle,
809
1561
  render,
1562
+ renderCoupons,
810
1563
  scanCode,
811
1564
  copyToClipboard,
812
1565
  getSessionData,
@@ -815,24 +1568,43 @@ const clientFunctions = {
815
1568
  setStorageData,
816
1569
  removeStorageData,
817
1570
  getKycPassportInfo,
818
- getAuthStatus
1571
+ getAuthStatus,
1572
+ logout
819
1573
  };
1574
+ const initExemptedFunctions = [
1575
+ "init",
1576
+ "setTitle",
1577
+ "copyToClipboard",
1578
+ "getSessionData",
1579
+ "setSessionData",
1580
+ "getStorageData",
1581
+ "setStorageData",
1582
+ "removeStorageData"
1583
+ ];
1584
+ const autoInitFunctions = ["renderCoupons"];
820
1585
  const proxy = new Proxy(clientFunctions, {
821
1586
  get(target, prop) {
822
1587
  const functionName = prop;
823
1588
  if (!useAllFunctions) {
824
- {
825
- if (!isSupportedMiniapp(functionName)) {
826
- throw new Error(
827
- `${functionName} is not supported by Mini Apps JS SDK`
828
- );
829
- }
1589
+ if (!isSupportedMiniapp(functionName)) {
1590
+ throw new Error(`${functionName} is not supported by Mini Apps JS SDK`);
830
1591
  }
831
1592
  }
832
- if (Object.prototype.hasOwnProperty.call(target, prop)) {
833
- return target[prop];
834
- }
835
- return (params) => {
1593
+ return async (params) => {
1594
+ var _a, _b;
1595
+ if (!initExemptedFunctions.includes(functionName) && !await initDonePromise) {
1596
+ if (autoInitFunctions.includes(functionName) && params.clientId) {
1597
+ init({ clientId: params.clientId, env: params.env });
1598
+ await initDonePromise;
1599
+ } else {
1600
+ (_a = params.fail) == null ? void 0 : _a.call(params, { errorCode: MiniAppErrorType.sdkNotInitialized });
1601
+ (_b = params.complete) == null ? void 0 : _b.call(params);
1602
+ return;
1603
+ }
1604
+ }
1605
+ if (Object.prototype.hasOwnProperty.call(target, functionName)) {
1606
+ return target[functionName](params);
1607
+ }
836
1608
  triggerPostMessageToCore(
837
1609
  prop,
838
1610
  false,
@@ -842,28 +1614,17 @@ const proxy = new Proxy(clientFunctions, {
842
1614
  };
843
1615
  }
844
1616
  });
845
- async function executePendingFunctionCalls() {
1617
+ function executePendingFunctionCalls() {
846
1618
  const pendingFunctionCalls = window._ppcs;
847
1619
  if (!pendingFunctionCalls) {
848
1620
  return;
849
1621
  }
850
1622
  window._ppcs = void 0;
851
1623
  for (const [functionName, params] of pendingFunctionCalls) {
852
- if (functionName === "init") {
853
- await new Promise((resolve) => {
854
- proxy[functionName]({
855
- ...params,
856
- complete: () => {
857
- var _a;
858
- resolve(true);
859
- (_a = params.complete) == null ? void 0 : _a.call(params);
860
- }
861
- });
862
- }).catch(() => false);
863
- } else {
864
- proxy[functionName](params);
865
- }
1624
+ proxy[functionName](params);
866
1625
  }
867
1626
  }
868
1627
  executePendingFunctionCalls();
869
- export { proxy as default };
1628
+ export {
1629
+ proxy as default
1630
+ };