@paypay/mini-app-js-sdk 2.10.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 (47) hide show
  1. package/dist/client/clientUtils.d.ts +8 -1
  2. package/dist/client/coreIframe.d.ts +1 -0
  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 +6 -2
  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 +1 -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 +901 -126
  22. package/dist/model/bridge/getLoginUrl.d.ts +9 -0
  23. package/dist/model/bridge/index.d.ts +47 -0
  24. package/dist/model/bridge/render.d.ts +0 -12
  25. package/dist/model/bridge/renderLoginButton.d.ts +2 -2
  26. package/dist/model/makePayment.d.ts +7 -0
  27. package/dist/package/lottie/index.d.ts +73 -0
  28. package/dist/package/lottie/lottie.d.ts +77 -0
  29. package/dist/resources/en.d.ts +1 -0
  30. package/dist/resources/images.d.ts +2 -0
  31. package/dist/resources/ja.d.ts +1 -0
  32. package/dist/types.d.ts +30 -5
  33. package/dist/utils/analytics.d.ts +3 -1
  34. package/dist/utils/api.d.ts +32 -25
  35. package/dist/utils/browsers.d.ts +3 -0
  36. package/dist/utils/fetch.d.ts +2 -1
  37. package/dist/utils/getLanguage.d.ts +1 -0
  38. package/dist/utils/helper.d.ts +3 -2
  39. package/dist/utils/storage.d.ts +6 -0
  40. package/dist/utils/windowBridge.d.ts +24 -0
  41. package/dist/views/coupon/components/Arrow/index.d.ts +17 -0
  42. package/dist/views/coupon/components/CouponAction/index.d.ts +39 -0
  43. package/dist/views/coupon/components/CouponContainer/index.d.ts +14 -0
  44. package/dist/views/coupon/index.d.ts +38 -0
  45. package/dist/views/coupon/types.d.ts +34 -0
  46. package/dist/views/registerPaymentFeatures/types.d.ts +8 -0
  47. package/package.json +8 -5
@@ -113,6 +113,7 @@ 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";
117
118
  PpLocalStorageKey2["consumedOTT"] = "ppjssdk.consumedOTT";
118
119
  return PpLocalStorageKey2;
@@ -169,7 +170,8 @@ const PPFunctionName = {
169
170
  handleMessageFromNative: "handleMessageFromNative",
170
171
  initKycPassport: "initKycPassport",
171
172
  smsAuth: "smsAuth",
172
- getKycPassportInfo: "getKycPassportInfo"
173
+ getKycPassportInfo: "getKycPassportInfo",
174
+ renderCoupons: "renderCoupons"
173
175
  };
174
176
  const PPUtilFunctionName = {
175
177
  reload: "reload",
@@ -231,84 +233,24 @@ const miniAppSupportedFunctions = [
231
233
  "shortcutExists",
232
234
  "addShortcut",
233
235
  "logAppsFlyerEvent",
234
- "getAllUserAddresses"
236
+ "getAllUserAddresses",
237
+ "getUserPaymentFeatureSettings"
235
238
  ];
236
239
  function url(path) {
237
240
  return "https://image.paypay.ne.jp/miniapps/mini-app-sdk/" + path;
238
241
  }
239
242
  const img_paypayRec = url("icon-paypay-rec.svg");
240
243
  const img_paypayRecWhite = url("icon-paypay-rec-white.svg");
241
- const JS_SDK_VERSION = "2.10.0";
242
- const coreBaseUrl = new URL("https://mini-app-sdk-core.paypay.ne.jp/");
243
- const CORE_IFRAME_ORIGIN = coreBaseUrl.origin;
244
- const CORE_IFRAME_URL = new URL(
245
- `./iframe.html?v=${JS_SDK_VERSION}`,
246
- coreBaseUrl
247
- ).href;
248
- function checkIFrameOrigin(origin) {
249
- return origin === CORE_IFRAME_ORIGIN;
250
- }
251
- function getIconUrl(theme) {
252
- return theme === "red" ? img_paypayRecWhite : img_paypayRec;
253
- }
254
- function convertToString(str) {
255
- return str ? String(str) : "";
256
- }
257
- function generateMessageId() {
258
- return Math.random().toString(36).substring(7);
259
- }
260
- function removeCookie(key, domain) {
261
- api.remove(key);
262
- api.remove(key, { domain });
263
- }
264
- function saveRefreshToken(refreshToken, domain, isSecure) {
265
- removeCookie(PpLocalStorageKey.refreshToken, domain);
266
- return api.set(PpLocalStorageKey.refreshToken, refreshToken, {
267
- domain,
268
- expires: 90,
269
- secure: isSecure
270
- });
271
- }
272
- function saveCodeVerifier(codeVerifier, domain, isSecure) {
273
- removeCookie(PpLocalStorageKey.codeVerifier, domain);
274
- return api.set(PpLocalStorageKey.codeVerifier, codeVerifier, {
275
- domain,
276
- secure: isSecure
277
- });
278
- }
279
- function getRefreshToken() {
280
- return api.get(PpLocalStorageKey.refreshToken) || "";
281
- }
282
- function getCodeVerifier() {
283
- return api.get(PpLocalStorageKey.codeVerifier) || "";
284
- }
285
- function exposeClientJsBridge(jsBridge) {
286
- const global = window;
287
- 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);
288
252
  return false;
289
253
  }
290
- global[jsBridgeNamespace] = jsBridge;
291
- return true;
292
- }
293
- function consoleDebugInfo(params) {
294
- console.debug(...params);
295
- }
296
- function isSupportedMiniapp(functionName) {
297
- return miniAppSupportedFunctions.includes(functionName);
298
- }
299
- let runningFunctions = [];
300
- function isFunctionRunning() {
301
- return runningFunctions.length > 0;
302
- }
303
- function functionEnd(messageId) {
304
- runningFunctions = runningFunctions.filter((val) => {
305
- return val !== messageId;
306
- });
307
- }
308
- function functionStart() {
309
- const messageId = generateMessageId();
310
- runningFunctions.push(messageId);
311
- return messageId;
312
254
  }
313
255
  var MiniAppErrorType = /* @__PURE__ */ ((MiniAppErrorType2) => {
314
256
  MiniAppErrorType2["success"] = "SUCCESS";
@@ -374,7 +316,674 @@ var MiniAppErrorType = /* @__PURE__ */ ((MiniAppErrorType2) => {
374
316
  MiniAppErrorType2["noLocationData"] = "NO_LOCATION_DATA";
375
317
  return MiniAppErrorType2;
376
318
  })(MiniAppErrorType || {});
377
- 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 || {});
378
987
  const IFRAME_NAME = "ppmna-iframe";
379
988
  const IFRAME_CONTAINER_NAME = "ppsdk-container";
380
989
  function initCoreIframe() {
@@ -420,6 +1029,9 @@ function getCoreIframe() {
420
1029
  }
421
1030
  return coreIframeLoadingPromise;
422
1031
  }
1032
+ function getCoreIframeWindow() {
1033
+ return getCoreIframe().then((iframe) => iframe == null ? void 0 : iframe.contentWindow).catch(() => null);
1034
+ }
423
1035
  function createIframe() {
424
1036
  return new Promise((resolve, reject) => {
425
1037
  const iframe = document.createElement("iframe");
@@ -441,9 +1053,22 @@ function createIframe() {
441
1053
  container.append(iframe);
442
1054
  });
443
1055
  }
1056
+ const windowBridge = WindowBridge.init({});
444
1057
  let useAllFunctions = false;
1058
+ let initDonePromise;
445
1059
  initCoreIframe();
1060
+ const core = windowBridge.getTargetWindowFunctionProxy(
1061
+ getCoreIframeWindow,
1062
+ CORE_IFRAME_ORIGIN
1063
+ );
1064
+ function getCore() {
1065
+ return core;
1066
+ }
446
1067
  const commonMessageHandler = (e) => {
1068
+ var _a;
1069
+ if ((_a = e.data) == null ? void 0 : _a.forWindowBridge) {
1070
+ return;
1071
+ }
447
1072
  if (!checkIFrameOrigin(e.origin)) {
448
1073
  return;
449
1074
  }
@@ -482,7 +1107,7 @@ function init(params) {
482
1107
  const ott = url2.searchParams.get("one_time_token");
483
1108
  const refreshToken = getRefreshToken();
484
1109
  const codeVerifier = getCodeVerifier();
485
- const clientVersion = "2.10.0";
1110
+ const clientVersion = "2.11.0";
486
1111
  useAllFunctions = !!params.useAllFunctions;
487
1112
  if (token || ott) {
488
1113
  removeTokenFromUrl(url2);
@@ -498,12 +1123,24 @@ function init(params) {
498
1123
  clientVersion,
499
1124
  codeVerifier
500
1125
  };
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
+ };
501
1133
  getCoreIframe().then(() => {
502
- triggerPostMessageToCore(PPFunctionName.init, false, params, initParams);
1134
+ triggerPostMessageToCore(
1135
+ PPFunctionName.init,
1136
+ false,
1137
+ { ...params, complete },
1138
+ initParams
1139
+ );
503
1140
  }).catch(() => {
504
- var _a, _b;
1141
+ var _a;
505
1142
  (_a = params.fail) == null ? void 0 : _a.call(params, { errorCode: MiniAppErrorType.sdkNotInitialized });
506
- (_b = params.complete) == null ? void 0 : _b.call(params);
1143
+ complete();
507
1144
  });
508
1145
  }
509
1146
  function getAuthStatus(params) {
@@ -540,6 +1177,8 @@ function share(params) {
540
1177
  return;
541
1178
  }
542
1179
  const data = {
1180
+ //url: params.imageUrl,
1181
+ //TODO: -> we need to download the imageUrl and try to attach it to `files`
543
1182
  text: params == null ? void 0 : params.text
544
1183
  };
545
1184
  navigator.share(data).then(() => {
@@ -590,15 +1229,115 @@ function render(params) {
590
1229
  addEventListener("message", getRenderMessageHandler);
591
1230
  void postMessageToCore({
592
1231
  name: PPFunctionName.render,
593
- params,
1232
+ params: {
1233
+ ...params,
1234
+ redirectUrl: params.redirectUrl || window.location.href
1235
+ },
594
1236
  messageId
595
1237
  });
596
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
+ );
597
1337
  function scanCode(params) {
598
- var _a;
599
1338
  const scanCodeParams = {
600
1339
  ...params,
601
- redirectUrlOnCancel: (_a = params == null ? void 0 : params.redirectUrlOnCancel) != null ? _a : window.location.href
1340
+ redirectUrlOnCancel: (params == null ? void 0 : params.redirectUrlOnCancel) ?? window.location.href
602
1341
  };
603
1342
  triggerPostMessageToCore(
604
1343
  PPFunctionName.scanCode,
@@ -610,25 +1349,25 @@ function scanCode(params) {
610
1349
  function getSessionData(params) {
611
1350
  var _a, _b;
612
1351
  const value = sessionStorage.getItem(params == null ? void 0 : params.key);
613
- (_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 ?? "" });
614
1353
  (_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
615
1354
  }
616
1355
  function setSessionData(params) {
617
- var _a, _b, _c;
618
- sessionStorage.setItem(params == null ? void 0 : params.key, (_a = params == null ? void 0 : params.value) != null ? _a : "");
619
- (_b = params == null ? void 0 : params.success) == null ? void 0 : _b.call(params);
620
- (_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);
621
1360
  }
622
1361
  function setStorageData(params) {
623
- var _a, _b, _c;
624
- localStorage.setItem(params == null ? void 0 : params.key, (_a = params == null ? void 0 : params.value) != null ? _a : "");
625
- (_b = params == null ? void 0 : params.success) == null ? void 0 : _b.call(params);
626
- (_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);
627
1366
  }
628
1367
  function getStorageData(params) {
629
1368
  var _a, _b;
630
1369
  const value = localStorage.getItem(params == null ? void 0 : params.key);
631
- (_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 ?? "" });
632
1371
  (_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
633
1372
  }
634
1373
  function removeStorageData(params) {
@@ -637,6 +1376,29 @@ function removeStorageData(params) {
637
1376
  (_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params);
638
1377
  (_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
639
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
+ );
640
1402
  function copyToClipboard(params) {
641
1403
  var _a, _b, _c;
642
1404
  const textarea = document.createElement("textarea");
@@ -680,11 +1442,14 @@ function removeTokenFromUrl(url2) {
680
1442
  url2.searchParams.delete("token");
681
1443
  url2.searchParams.delete("one_time_token");
682
1444
  url2.search = url2.searchParams.toString();
683
- history.replaceState(null, "", url2);
1445
+ const newURL = url2.toString().replace(url2.origin, "");
1446
+ history.replaceState(null, "", newURL);
684
1447
  }
685
1448
  function triggerPostMessageToCore(type, showIframeFlag, params, postMessageParams) {
686
1449
  const messageId = functionStart();
687
- showCoreIframe(showIframeFlag);
1450
+ if (showIframeFlag) {
1451
+ showCoreIframe(true);
1452
+ }
688
1453
  const fnMessageHandler = (e) => {
689
1454
  if (!checkIFrameOrigin(e.origin)) {
690
1455
  return;
@@ -703,20 +1468,20 @@ function triggerPostMessageToCore(type, showIframeFlag, params, postMessageParam
703
1468
  });
704
1469
  }
705
1470
  function renderButton(data, params) {
706
- var _a, _b, _c, _d, _e, _f, _g;
1471
+ var _a, _b, _c, _d, _e;
707
1472
  const container = document.getElementById(params.containerId);
708
1473
  const button = document.createElement("button");
709
1474
  button.className = "ppmna-reset-css pp-smartButtonWrapper pp-button";
710
1475
  const iconUrl = getIconUrl(params == null ? void 0 : params.theme);
711
1476
  const cashbackClass = ((_b = (_a = data == null ? void 0 : data.data) == null ? void 0 : _a.cashbackInfo) == null ? void 0 : _b.length) ? "pp-cashback" : "";
712
1477
  const shortTextClass = params.isShortText ? "pp-shortText" : "";
713
- const buttonSize = (_c = params == null ? void 0 : params.buttonSize) != null ? _c : "lg";
714
- 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";
715
1480
  const aTag = document.createElement("a");
716
1481
  aTag.className = `pp-smartBtn pp-${theme} pp-${buttonSize} pp-${convertToString(
717
1482
  params.type
718
1483
  )} pp-${data.preferredLanguage} ${cashbackClass} ${shortTextClass}`;
719
- aTag.href = convertToString(params.url);
1484
+ aTag.href = convertToString(data.data.loginUrl);
720
1485
  const leftSpan = document.createElement("span");
721
1486
  leftSpan.className = "pp-leftSection";
722
1487
  const iconImg = document.createElement("img");
@@ -728,14 +1493,14 @@ function renderButton(data, params) {
728
1493
  btnSpan.className = "pp-btnContent";
729
1494
  const titleSpan = document.createElement("span");
730
1495
  titleSpan.className = "pp-title";
731
- 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;
732
1497
  btnSpan.appendChild(titleSpan);
733
1498
  leftSpan.appendChild(btnSpan);
734
1499
  aTag.append(leftSpan);
735
1500
  const cashbackSpan = document.createElement("span");
736
- 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) {
737
1502
  cashbackSpan.className = "pp-cashbackInfo";
738
- 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;
739
1504
  btnSpan.append(cashbackSpan);
740
1505
  }
741
1506
  if (data.data.avatarUrl) {
@@ -788,11 +1553,13 @@ const clientJsBridge = {
788
1553
  };
789
1554
  exposeClientJsBridge(clientJsBridge);
790
1555
  const clientFunctions = {
1556
+ // functions that run on client, or need special treatment on client
791
1557
  init,
792
1558
  verifyMultiFactorAuthResult,
793
1559
  share,
794
1560
  setTitle,
795
1561
  render,
1562
+ renderCoupons,
796
1563
  scanCode,
797
1564
  copyToClipboard,
798
1565
  getSessionData,
@@ -801,24 +1568,43 @@ const clientFunctions = {
801
1568
  setStorageData,
802
1569
  removeStorageData,
803
1570
  getKycPassportInfo,
804
- getAuthStatus
1571
+ getAuthStatus,
1572
+ logout
805
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"];
806
1585
  const proxy = new Proxy(clientFunctions, {
807
1586
  get(target, prop) {
808
1587
  const functionName = prop;
809
1588
  if (!useAllFunctions) {
810
- {
811
- if (!isSupportedMiniapp(functionName)) {
812
- throw new Error(
813
- `${functionName} is not supported by Mini Apps JS SDK`
814
- );
815
- }
1589
+ if (!isSupportedMiniapp(functionName)) {
1590
+ throw new Error(`${functionName} is not supported by Mini Apps JS SDK`);
816
1591
  }
817
1592
  }
818
- if (Object.prototype.hasOwnProperty.call(target, prop)) {
819
- return target[prop];
820
- }
821
- 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
+ }
822
1608
  triggerPostMessageToCore(
823
1609
  prop,
824
1610
  false,
@@ -828,28 +1614,17 @@ const proxy = new Proxy(clientFunctions, {
828
1614
  };
829
1615
  }
830
1616
  });
831
- async function executePendingFunctionCalls() {
1617
+ function executePendingFunctionCalls() {
832
1618
  const pendingFunctionCalls = window._ppcs;
833
1619
  if (!pendingFunctionCalls) {
834
1620
  return;
835
1621
  }
836
1622
  window._ppcs = void 0;
837
1623
  for (const [functionName, params] of pendingFunctionCalls) {
838
- if (functionName === "init") {
839
- await new Promise((resolve) => {
840
- proxy[functionName]({
841
- ...params,
842
- complete: () => {
843
- var _a;
844
- resolve(true);
845
- (_a = params.complete) == null ? void 0 : _a.call(params);
846
- }
847
- });
848
- }).catch(() => false);
849
- } else {
850
- proxy[functionName](params);
851
- }
1624
+ proxy[functionName](params);
852
1625
  }
853
1626
  }
854
- void executePendingFunctionCalls();
855
- export { proxy as default };
1627
+ executePendingFunctionCalls();
1628
+ export {
1629
+ proxy as default
1630
+ };