@paypay/mini-app-js-sdk 2.10.0 → 2.12.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.
- package/dist/client/clientUtils.d.ts +8 -1
- package/dist/client/coreIframe.d.ts +1 -0
- package/dist/client/index.d.ts +10 -1
- package/dist/client/supportedFunctionsList.d.ts +2 -2
- package/dist/core/coreFunctions/claimCoupon.d.ts +6 -0
- package/dist/core/coreFunctions/fetchCoupons.d.ts +8 -0
- package/dist/core/coreFunctions/index.d.ts +4 -0
- package/dist/core/coreFunctions/logEvent.d.ts +12 -0
- package/dist/core/coreFunctions/logout.d.ts +1 -0
- package/dist/core/coreUtils.d.ts +6 -2
- package/dist/core/coupon/couponFunctions/index.d.ts +1 -0
- package/dist/core/coupon/couponFunctions/renderCoupons.d.ts +9 -0
- package/dist/core/coupon/index.d.ts +3 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/environment-variables.d.ts +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/jsbridge-core/lib/browser.d.ts +3 -0
- package/dist/jsbridge-core/paypay-jsbridge.d.ts +16 -0
- package/dist/mini-app-js-sdk.browser.js +1 -1
- package/dist/mini-app-js-sdk.d.ts +10 -0
- package/dist/mini-app-js-sdk.es.js +898 -126
- package/dist/model/bridge/getLoginUrl.d.ts +9 -0
- package/dist/model/bridge/index.d.ts +47 -0
- package/dist/model/bridge/render.d.ts +0 -12
- package/dist/model/bridge/renderLoginButton.d.ts +2 -2
- package/dist/model/makePayment.d.ts +7 -0
- package/dist/package/button/index.d.ts +1 -1
- package/dist/package/lottie/index.d.ts +73 -0
- package/dist/package/lottie/lottie.d.ts +77 -0
- package/dist/resources/en.d.ts +1 -0
- package/dist/resources/images.d.ts +2 -0
- package/dist/resources/ja.d.ts +1 -0
- package/dist/types.d.ts +30 -5
- package/dist/utils/analytics.d.ts +3 -1
- package/dist/utils/api.d.ts +32 -25
- package/dist/utils/browsers.d.ts +3 -0
- package/dist/utils/fetch.d.ts +2 -1
- package/dist/utils/getLanguage.d.ts +1 -0
- package/dist/utils/helper.d.ts +3 -2
- package/dist/utils/storage.d.ts +6 -0
- package/dist/utils/windowBridge.d.ts +24 -0
- package/dist/views/coupon/components/Arrow/index.d.ts +17 -0
- package/dist/views/coupon/components/CouponAction/index.d.ts +39 -0
- package/dist/views/coupon/components/CouponContainer/index.d.ts +14 -0
- package/dist/views/coupon/index.d.ts +38 -0
- package/dist/views/coupon/types.d.ts +34 -0
- package/dist/views/registerPaymentFeatures/types.d.ts +8 -0
- 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
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
)
|
|
248
|
-
|
|
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,675 @@ var MiniAppErrorType = /* @__PURE__ */ ((MiniAppErrorType2) => {
|
|
|
374
316
|
MiniAppErrorType2["noLocationData"] = "NO_LOCATION_DATA";
|
|
375
317
|
return MiniAppErrorType2;
|
|
376
318
|
})(MiniAppErrorType || {});
|
|
377
|
-
|
|
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.12.0";
|
|
674
|
+
const REVISION = "12c80ef";
|
|
675
|
+
const coreBaseUrl = new URL("https://mini-app-sdk-core.paypay.ne.jp/");
|
|
676
|
+
const CORE_IFRAME_ORIGIN = coreBaseUrl.origin;
|
|
677
|
+
const CORE_IFRAME_URL = new URL(
|
|
678
|
+
`./iframe.html?v=${JS_SDK_VERSION}&rev=${REVISION}`,
|
|
679
|
+
coreBaseUrl
|
|
680
|
+
).href;
|
|
681
|
+
const COUPON_IFRAME_URL = new URL(
|
|
682
|
+
`./coupon/iframe.html?v=${JS_SDK_VERSION}`,
|
|
683
|
+
coreBaseUrl
|
|
684
|
+
).href;
|
|
685
|
+
function checkIFrameOrigin(origin) {
|
|
686
|
+
return origin === CORE_IFRAME_ORIGIN;
|
|
687
|
+
}
|
|
688
|
+
function getIconUrl(theme) {
|
|
689
|
+
return theme === "red" ? img_paypayRecWhite : img_paypayRec;
|
|
690
|
+
}
|
|
691
|
+
function convertToString(str) {
|
|
692
|
+
return str ? String(str) : "";
|
|
693
|
+
}
|
|
694
|
+
function removeCookie(key, domain) {
|
|
695
|
+
api.remove(key);
|
|
696
|
+
api.remove(key, { domain });
|
|
697
|
+
}
|
|
698
|
+
function saveRefreshToken(refreshToken, domain, isSecure) {
|
|
699
|
+
removeCookie(PpLocalStorageKey.refreshToken, domain);
|
|
700
|
+
return api.set(PpLocalStorageKey.refreshToken, refreshToken, {
|
|
701
|
+
domain,
|
|
702
|
+
expires: 90,
|
|
703
|
+
secure: isSecure
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
function saveCodeVerifier(codeVerifier, domain, isSecure) {
|
|
707
|
+
removeCookie(PpLocalStorageKey.codeVerifier, domain);
|
|
708
|
+
return api.set(PpLocalStorageKey.codeVerifier, codeVerifier, {
|
|
709
|
+
domain,
|
|
710
|
+
secure: isSecure
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
function getRefreshToken() {
|
|
714
|
+
return api.get(PpLocalStorageKey.refreshToken) || "";
|
|
715
|
+
}
|
|
716
|
+
function getCodeVerifier() {
|
|
717
|
+
return api.get(PpLocalStorageKey.codeVerifier) || "";
|
|
718
|
+
}
|
|
719
|
+
function exposeClientJsBridge(jsBridge) {
|
|
720
|
+
const global = window;
|
|
721
|
+
if (
|
|
722
|
+
// eslint-disable-next-line no-prototype-builtins, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
723
|
+
global.hasOwnProperty(jsBridgeNamespace) && // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
724
|
+
global[jsBridgeNamespace] === jsBridge
|
|
725
|
+
) {
|
|
726
|
+
return false;
|
|
727
|
+
}
|
|
728
|
+
global[jsBridgeNamespace] = jsBridge;
|
|
729
|
+
return true;
|
|
730
|
+
}
|
|
731
|
+
function consoleDebugInfo(params) {
|
|
732
|
+
console.debug(...params);
|
|
733
|
+
}
|
|
734
|
+
function isSupportedMiniapp(functionName) {
|
|
735
|
+
return miniAppSupportedFunctions.includes(functionName);
|
|
736
|
+
}
|
|
737
|
+
let runningFunctions = [];
|
|
738
|
+
function isFunctionRunning() {
|
|
739
|
+
return runningFunctions.length > 0;
|
|
740
|
+
}
|
|
741
|
+
function functionEnd(messageId) {
|
|
742
|
+
runningFunctions = runningFunctions.filter((val) => {
|
|
743
|
+
return val !== messageId;
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
function functionStart() {
|
|
747
|
+
const messageId = getRandomString();
|
|
748
|
+
runningFunctions.push(messageId);
|
|
749
|
+
return messageId;
|
|
750
|
+
}
|
|
751
|
+
class ClientError extends Error {
|
|
752
|
+
constructor(message, payload) {
|
|
753
|
+
super(message);
|
|
754
|
+
this.payload = payload;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
function promiseToCallback(functionName, target, getCore2, getLoggingParams) {
|
|
758
|
+
return function(params = {}) {
|
|
759
|
+
const core2 = getCore2();
|
|
760
|
+
const loggingParams = getLoggingParams == null ? void 0 : getLoggingParams(params);
|
|
761
|
+
void core2.logEvent({
|
|
762
|
+
event_action: `pp_${functionName}_called`,
|
|
763
|
+
...loggingParams
|
|
764
|
+
});
|
|
765
|
+
target(params).then((result) => {
|
|
766
|
+
var _a;
|
|
767
|
+
void core2.logEvent({
|
|
768
|
+
event_action: `pp_${functionName}_success`,
|
|
769
|
+
...loggingParams
|
|
770
|
+
});
|
|
771
|
+
(_a = params.success) == null ? void 0 : _a.call(params, result);
|
|
772
|
+
}).catch((error) => {
|
|
773
|
+
var _a;
|
|
774
|
+
console.error(error.message);
|
|
775
|
+
void core2.logEvent({
|
|
776
|
+
event_action: `pp_${functionName}_fail`,
|
|
777
|
+
error_value: error.payload.errorCode,
|
|
778
|
+
...loggingParams
|
|
779
|
+
});
|
|
780
|
+
(_a = params.fail) == null ? void 0 : _a.call(params, error.payload);
|
|
781
|
+
}).finally(() => {
|
|
782
|
+
var _a;
|
|
783
|
+
(_a = params.complete) == null ? void 0 : _a.call(params);
|
|
784
|
+
});
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
class WindowBridge {
|
|
788
|
+
constructor(functions, allowedOrigins) {
|
|
789
|
+
this.deferredCallbacks = {};
|
|
790
|
+
this.functions = functions;
|
|
791
|
+
this.allowedOrigins = allowedOrigins;
|
|
792
|
+
this.subscribeToMessageEvent();
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Subscribe to message event to handle incoming messages.
|
|
796
|
+
* These messages can be of two types
|
|
797
|
+
* 1. A function call from another window
|
|
798
|
+
* 2. Response of a function call made from this window to another window
|
|
799
|
+
*/
|
|
800
|
+
subscribeToMessageEvent() {
|
|
801
|
+
window.addEventListener(
|
|
802
|
+
"message",
|
|
803
|
+
(receivedMessageEvent) => {
|
|
804
|
+
var _a;
|
|
805
|
+
if (!((_a = receivedMessageEvent.data) == null ? void 0 : _a.forWindowBridge)) {
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
if (this.allowedOrigins && !this.allowedOrigins.includes(receivedMessageEvent.origin)) {
|
|
809
|
+
return this.sendErrorResponse(
|
|
810
|
+
receivedMessageEvent,
|
|
811
|
+
"originNotAllowed",
|
|
812
|
+
`${receivedMessageEvent.origin} is not allowed to make requests`
|
|
813
|
+
);
|
|
814
|
+
}
|
|
815
|
+
if (receivedMessageEvent.data.type === "request") {
|
|
816
|
+
void this.handleRequest(
|
|
817
|
+
receivedMessageEvent
|
|
818
|
+
);
|
|
819
|
+
} else if (receivedMessageEvent.data.type === "response") {
|
|
820
|
+
this.handleResponse(
|
|
821
|
+
receivedMessageEvent
|
|
822
|
+
);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
);
|
|
826
|
+
}
|
|
827
|
+
async handleRequest(receivedMessageEvent) {
|
|
828
|
+
const functionToInvoke = this.functions[receivedMessageEvent.data.functionName];
|
|
829
|
+
if (!functionToInvoke) {
|
|
830
|
+
this.sendErrorResponse(
|
|
831
|
+
receivedMessageEvent,
|
|
832
|
+
"functionNotFound"
|
|
833
|
+
/* functionNotFound */
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
try {
|
|
837
|
+
this.sendSuccessResponse(
|
|
838
|
+
receivedMessageEvent,
|
|
839
|
+
await functionToInvoke(...receivedMessageEvent.data.params)
|
|
840
|
+
);
|
|
841
|
+
} catch (error) {
|
|
842
|
+
this.sendErrorResponse(
|
|
843
|
+
receivedMessageEvent,
|
|
844
|
+
"runTimeError",
|
|
845
|
+
error.message
|
|
846
|
+
);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
handleResponse(receivedMessageEvent) {
|
|
850
|
+
if (!this.deferredCallbacks[receivedMessageEvent.data.key]) {
|
|
851
|
+
console.warn(
|
|
852
|
+
`Callback for ${receivedMessageEvent.data.functionName} not found`
|
|
853
|
+
);
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
const [resolve, reject] = this.deferredCallbacks[receivedMessageEvent.data.key];
|
|
857
|
+
delete this.deferredCallbacks[receivedMessageEvent.data.key];
|
|
858
|
+
if (receivedMessageEvent.data.status === "success") {
|
|
859
|
+
resolve(receivedMessageEvent.data.result);
|
|
860
|
+
} else {
|
|
861
|
+
reject({
|
|
862
|
+
code: receivedMessageEvent.data.code,
|
|
863
|
+
message: receivedMessageEvent.data.message
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
sendErrorResponse(receivedMessageEvent, code, message) {
|
|
868
|
+
this.sendResponse(receivedMessageEvent, {
|
|
869
|
+
status: "failure",
|
|
870
|
+
code,
|
|
871
|
+
message
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
sendSuccessResponse(receivedMessageEvent, result) {
|
|
875
|
+
this.sendResponse(receivedMessageEvent, {
|
|
876
|
+
status: "success",
|
|
877
|
+
result
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
sendResponse(receivedMessageEvent, data) {
|
|
881
|
+
var _a;
|
|
882
|
+
(_a = receivedMessageEvent.source) == null ? void 0 : _a.postMessage(
|
|
883
|
+
{
|
|
884
|
+
forWindowBridge: true,
|
|
885
|
+
type: "response",
|
|
886
|
+
key: receivedMessageEvent.data.key,
|
|
887
|
+
functionName: receivedMessageEvent.data.functionName,
|
|
888
|
+
...data
|
|
889
|
+
},
|
|
890
|
+
// Just a hack to overcome weird function overload mismatch
|
|
891
|
+
receivedMessageEvent.origin
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* A static method to create a new `WindowBridge` instance and enforce singleton pattern
|
|
896
|
+
* @param functions an objection of functions that can be invoked on the current window
|
|
897
|
+
* @param allowedOrigins a list of allowed origins from where request can be accepted
|
|
898
|
+
* @returns `WindowBridge` instance
|
|
899
|
+
*/
|
|
900
|
+
static init(functions, allowedOrigins) {
|
|
901
|
+
if (this._instance) {
|
|
902
|
+
throw new Error(
|
|
903
|
+
"WindowBridge already initialized, you can't call WindowBridge.init twice"
|
|
904
|
+
);
|
|
905
|
+
}
|
|
906
|
+
this._instance = new this(functions, allowedOrigins);
|
|
907
|
+
return this._instance;
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* A static method to get an existing `WindowBridge` instance
|
|
911
|
+
* @returns `WindowBridge` instance
|
|
912
|
+
*/
|
|
913
|
+
static getBridge() {
|
|
914
|
+
if (!this._instance) {
|
|
915
|
+
throw new Error(
|
|
916
|
+
"WindowBridge not initialized, please call WindowBridge.init before calling WindowBridge.getBridge"
|
|
917
|
+
);
|
|
918
|
+
}
|
|
919
|
+
return this._instance;
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* A static function that returns a proxy object to invoke functions on a target window.
|
|
923
|
+
* We can call it multiple times to invoke functions on different windows
|
|
924
|
+
* @param getTargetWindow a function that returns the target window where we want to invoke functions
|
|
925
|
+
* @param targetWindowOrigin origin of the target window
|
|
926
|
+
* @returns a proxy object to call functions from target window as an asynchronous function
|
|
927
|
+
*/
|
|
928
|
+
static getTargetWindowFunctionProxy(getTargetWindow, targetWindowOrigin) {
|
|
929
|
+
return WindowBridge.getBridge().getTargetWindowFunctionProxy(
|
|
930
|
+
getTargetWindow,
|
|
931
|
+
targetWindowOrigin
|
|
932
|
+
);
|
|
933
|
+
}
|
|
934
|
+
/**
|
|
935
|
+
* It returns a proxy object to invoke functions on a target window.
|
|
936
|
+
* We can call it multiple times to invoke functions on different windows
|
|
937
|
+
* @param getTargetWindow a function that returns the target window where we want to invoke functions
|
|
938
|
+
* @param targetWindowOrigin origin of the target window
|
|
939
|
+
* @returns a proxy object to call functions from target window as an asynchronous function
|
|
940
|
+
*/
|
|
941
|
+
getTargetWindowFunctionProxy(getTargetWindow, targetWindowOrigin) {
|
|
942
|
+
return new Proxy(this, {
|
|
943
|
+
get(windowBridgeInstance, functionName) {
|
|
944
|
+
return (...params) => (
|
|
945
|
+
// eslint-disable-next-line no-async-promise-executor, @typescript-eslint/no-misused-promises
|
|
946
|
+
new Promise(async (resolve, reject) => {
|
|
947
|
+
const functionNameString = functionName.toString();
|
|
948
|
+
const key = `${functionNameString}--${getRandomString()}`;
|
|
949
|
+
try {
|
|
950
|
+
const targetWindow = await getTargetWindow();
|
|
951
|
+
if (!targetWindow) {
|
|
952
|
+
throw new Error("Target window is undefined");
|
|
953
|
+
}
|
|
954
|
+
targetWindow.postMessage(
|
|
955
|
+
{
|
|
956
|
+
forWindowBridge: true,
|
|
957
|
+
type: "request",
|
|
958
|
+
functionName: functionNameString,
|
|
959
|
+
key,
|
|
960
|
+
params
|
|
961
|
+
},
|
|
962
|
+
targetWindowOrigin
|
|
963
|
+
);
|
|
964
|
+
windowBridgeInstance.deferredCallbacks[key] = [resolve, reject];
|
|
965
|
+
} catch (error) {
|
|
966
|
+
reject({
|
|
967
|
+
code: "messageSendingFailed",
|
|
968
|
+
message: error.message
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
})
|
|
972
|
+
);
|
|
973
|
+
}
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
const style = "";
|
|
978
|
+
var MiniAppStatusType = /* @__PURE__ */ ((MiniAppStatusType2) => {
|
|
979
|
+
MiniAppStatusType2["validToken"] = "TOKEN_VALID";
|
|
980
|
+
MiniAppStatusType2["initialized"] = "INITIALIZED";
|
|
981
|
+
MiniAppStatusType2["emailRegistered"] = "EMAIL_REGISTERED";
|
|
982
|
+
MiniAppStatusType2["emailNotVerified"] = "EMAIL_NOT_VERIFIED";
|
|
983
|
+
MiniAppStatusType2["success"] = "SUCCESS";
|
|
984
|
+
MiniAppStatusType2["loggedOut"] = "LOGGED_OUT";
|
|
985
|
+
MiniAppStatusType2["connected"] = "CONNECTED";
|
|
986
|
+
return MiniAppStatusType2;
|
|
987
|
+
})(MiniAppStatusType || {});
|
|
378
988
|
const IFRAME_NAME = "ppmna-iframe";
|
|
379
989
|
const IFRAME_CONTAINER_NAME = "ppsdk-container";
|
|
380
990
|
function initCoreIframe() {
|
|
@@ -420,6 +1030,9 @@ function getCoreIframe() {
|
|
|
420
1030
|
}
|
|
421
1031
|
return coreIframeLoadingPromise;
|
|
422
1032
|
}
|
|
1033
|
+
function getCoreIframeWindow() {
|
|
1034
|
+
return getCoreIframe().then((iframe) => iframe == null ? void 0 : iframe.contentWindow).catch(() => null);
|
|
1035
|
+
}
|
|
423
1036
|
function createIframe() {
|
|
424
1037
|
return new Promise((resolve, reject) => {
|
|
425
1038
|
const iframe = document.createElement("iframe");
|
|
@@ -441,9 +1054,22 @@ function createIframe() {
|
|
|
441
1054
|
container.append(iframe);
|
|
442
1055
|
});
|
|
443
1056
|
}
|
|
1057
|
+
const windowBridge = WindowBridge.init({});
|
|
444
1058
|
let useAllFunctions = false;
|
|
1059
|
+
let initDonePromise;
|
|
445
1060
|
initCoreIframe();
|
|
1061
|
+
const core = windowBridge.getTargetWindowFunctionProxy(
|
|
1062
|
+
getCoreIframeWindow,
|
|
1063
|
+
CORE_IFRAME_ORIGIN
|
|
1064
|
+
);
|
|
1065
|
+
function getCore() {
|
|
1066
|
+
return core;
|
|
1067
|
+
}
|
|
446
1068
|
const commonMessageHandler = (e) => {
|
|
1069
|
+
var _a;
|
|
1070
|
+
if ((_a = e.data) == null ? void 0 : _a.forWindowBridge) {
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
447
1073
|
if (!checkIFrameOrigin(e.origin)) {
|
|
448
1074
|
return;
|
|
449
1075
|
}
|
|
@@ -482,7 +1108,7 @@ function init(params) {
|
|
|
482
1108
|
const ott = url2.searchParams.get("one_time_token");
|
|
483
1109
|
const refreshToken = getRefreshToken();
|
|
484
1110
|
const codeVerifier = getCodeVerifier();
|
|
485
|
-
const clientVersion = "2.
|
|
1111
|
+
const clientVersion = "2.12.0";
|
|
486
1112
|
useAllFunctions = !!params.useAllFunctions;
|
|
487
1113
|
if (token || ott) {
|
|
488
1114
|
removeTokenFromUrl(url2);
|
|
@@ -498,12 +1124,24 @@ function init(params) {
|
|
|
498
1124
|
clientVersion,
|
|
499
1125
|
codeVerifier
|
|
500
1126
|
};
|
|
1127
|
+
let initDonePromiseResolve;
|
|
1128
|
+
initDonePromise = new Promise((resolve) => initDonePromiseResolve = resolve);
|
|
1129
|
+
const complete = () => {
|
|
1130
|
+
var _a;
|
|
1131
|
+
initDonePromiseResolve(true);
|
|
1132
|
+
(_a = params.complete) == null ? void 0 : _a.call(params);
|
|
1133
|
+
};
|
|
501
1134
|
getCoreIframe().then(() => {
|
|
502
|
-
triggerPostMessageToCore(
|
|
1135
|
+
triggerPostMessageToCore(
|
|
1136
|
+
PPFunctionName.init,
|
|
1137
|
+
false,
|
|
1138
|
+
{ ...params, complete },
|
|
1139
|
+
initParams
|
|
1140
|
+
);
|
|
503
1141
|
}).catch(() => {
|
|
504
|
-
var _a
|
|
1142
|
+
var _a;
|
|
505
1143
|
(_a = params.fail) == null ? void 0 : _a.call(params, { errorCode: MiniAppErrorType.sdkNotInitialized });
|
|
506
|
-
|
|
1144
|
+
complete();
|
|
507
1145
|
});
|
|
508
1146
|
}
|
|
509
1147
|
function getAuthStatus(params) {
|
|
@@ -540,6 +1178,8 @@ function share(params) {
|
|
|
540
1178
|
return;
|
|
541
1179
|
}
|
|
542
1180
|
const data = {
|
|
1181
|
+
//url: params.imageUrl,
|
|
1182
|
+
//TODO: -> we need to download the imageUrl and try to attach it to `files`
|
|
543
1183
|
text: params == null ? void 0 : params.text
|
|
544
1184
|
};
|
|
545
1185
|
navigator.share(data).then(() => {
|
|
@@ -590,15 +1230,110 @@ function render(params) {
|
|
|
590
1230
|
addEventListener("message", getRenderMessageHandler);
|
|
591
1231
|
void postMessageToCore({
|
|
592
1232
|
name: PPFunctionName.render,
|
|
593
|
-
params
|
|
1233
|
+
params: {
|
|
1234
|
+
...params,
|
|
1235
|
+
redirectUrl: params.redirectUrl || window.location.href
|
|
1236
|
+
},
|
|
594
1237
|
messageId
|
|
595
1238
|
});
|
|
596
1239
|
}
|
|
1240
|
+
const renderCoupons = promiseToCallback(
|
|
1241
|
+
"renderCoupons",
|
|
1242
|
+
async (params) => {
|
|
1243
|
+
const {
|
|
1244
|
+
merchant: merchantId,
|
|
1245
|
+
couponId,
|
|
1246
|
+
containerId,
|
|
1247
|
+
postLoginRedirectUrl = window.location.href,
|
|
1248
|
+
postLoginRedirectType,
|
|
1249
|
+
locale
|
|
1250
|
+
} = params;
|
|
1251
|
+
const containerElement = document.getElementById(containerId);
|
|
1252
|
+
if (!containerElement) {
|
|
1253
|
+
throw new ClientError("Invalid coupon container Id", {
|
|
1254
|
+
errorCode: MiniAppErrorType.badRequestInsufficientParameter
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
const coupons = await core.fetchCoupons({
|
|
1258
|
+
merchantId,
|
|
1259
|
+
couponId,
|
|
1260
|
+
postLoginRedirectUrl,
|
|
1261
|
+
postLoginRedirectType
|
|
1262
|
+
}).catch(() => {
|
|
1263
|
+
throw new ClientError(
|
|
1264
|
+
`An error occurred while fetching coupons, merchantId=${merchantId} and couponId=${couponId}`,
|
|
1265
|
+
{
|
|
1266
|
+
errorCode: MiniAppErrorType.unknown
|
|
1267
|
+
}
|
|
1268
|
+
);
|
|
1269
|
+
});
|
|
1270
|
+
if (coupons.length === 0) {
|
|
1271
|
+
throw new ClientError(
|
|
1272
|
+
`No coupon found for merchantId=${merchantId} and couponId=${couponId}`,
|
|
1273
|
+
{
|
|
1274
|
+
errorCode: MiniAppErrorType.notAvailable
|
|
1275
|
+
}
|
|
1276
|
+
);
|
|
1277
|
+
}
|
|
1278
|
+
const firstCoupon = coupons[0];
|
|
1279
|
+
const currentTimeStamp = (/* @__PURE__ */ new Date()).getTime();
|
|
1280
|
+
if (new Date(firstCoupon.liveEndDate).getTime() < currentTimeStamp) {
|
|
1281
|
+
throw new ClientError("Coupon has expired", {
|
|
1282
|
+
errorCode: MiniAppErrorType.invalidData
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
1285
|
+
if (firstCoupon.status !== "SCHEDULED") {
|
|
1286
|
+
throw new ClientError(
|
|
1287
|
+
`Coupon status is ${firstCoupon.status} that is not valid`,
|
|
1288
|
+
{
|
|
1289
|
+
errorCode: MiniAppErrorType.invalidData
|
|
1290
|
+
}
|
|
1291
|
+
);
|
|
1292
|
+
}
|
|
1293
|
+
try {
|
|
1294
|
+
const iframeElement = document.createElement("iframe");
|
|
1295
|
+
iframeElement.src = COUPON_IFRAME_URL;
|
|
1296
|
+
iframeElement.style.cssText = "width:100%;height: 0;border: none;transition: height 300ms ease-in;display: block;";
|
|
1297
|
+
await new Promise((resolve, reject) => {
|
|
1298
|
+
iframeElement.onload = () => resolve(true);
|
|
1299
|
+
iframeElement.onerror = () => reject(false);
|
|
1300
|
+
containerElement.innerHTML = "";
|
|
1301
|
+
containerElement.append(iframeElement);
|
|
1302
|
+
});
|
|
1303
|
+
iframeElement.onload = null;
|
|
1304
|
+
iframeElement.onerror = null;
|
|
1305
|
+
window.addEventListener(
|
|
1306
|
+
"message",
|
|
1307
|
+
({ data, source }) => {
|
|
1308
|
+
if ((data == null ? void 0 : data.eventName) === "update-iframe-height" && iframeElement.contentWindow === source) {
|
|
1309
|
+
iframeElement.style.height = `${data.height}px`;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
);
|
|
1313
|
+
const couponFunctions = windowBridge.getTargetWindowFunctionProxy(
|
|
1314
|
+
() => iframeElement.contentWindow,
|
|
1315
|
+
CORE_IFRAME_ORIGIN
|
|
1316
|
+
);
|
|
1317
|
+
await couponFunctions.renderCoupons({ coupons, merchantId, locale });
|
|
1318
|
+
} catch (error) {
|
|
1319
|
+
throw new ClientError(
|
|
1320
|
+
`An error ocurred while displaying coupons, merchantId=${merchantId}, couponId=${couponId}, error=${error}`,
|
|
1321
|
+
{
|
|
1322
|
+
errorCode: MiniAppErrorType.unknown
|
|
1323
|
+
}
|
|
1324
|
+
);
|
|
1325
|
+
}
|
|
1326
|
+
},
|
|
1327
|
+
getCore,
|
|
1328
|
+
(params) => ({
|
|
1329
|
+
event_label_suffix: params.merchant,
|
|
1330
|
+
event_label2: params.couponId
|
|
1331
|
+
})
|
|
1332
|
+
);
|
|
597
1333
|
function scanCode(params) {
|
|
598
|
-
var _a;
|
|
599
1334
|
const scanCodeParams = {
|
|
600
1335
|
...params,
|
|
601
|
-
redirectUrlOnCancel: (
|
|
1336
|
+
redirectUrlOnCancel: (params == null ? void 0 : params.redirectUrlOnCancel) ?? window.location.href
|
|
602
1337
|
};
|
|
603
1338
|
triggerPostMessageToCore(
|
|
604
1339
|
PPFunctionName.scanCode,
|
|
@@ -610,25 +1345,25 @@ function scanCode(params) {
|
|
|
610
1345
|
function getSessionData(params) {
|
|
611
1346
|
var _a, _b;
|
|
612
1347
|
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
|
|
1348
|
+
(_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params, { [params == null ? void 0 : params.key]: value ?? "" });
|
|
614
1349
|
(_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
|
|
615
1350
|
}
|
|
616
1351
|
function setSessionData(params) {
|
|
617
|
-
var _a, _b
|
|
618
|
-
sessionStorage.setItem(params == null ? void 0 : params.key, (
|
|
619
|
-
(
|
|
620
|
-
(
|
|
1352
|
+
var _a, _b;
|
|
1353
|
+
sessionStorage.setItem(params == null ? void 0 : params.key, (params == null ? void 0 : params.value) ?? "");
|
|
1354
|
+
(_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params);
|
|
1355
|
+
(_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
|
|
621
1356
|
}
|
|
622
1357
|
function setStorageData(params) {
|
|
623
|
-
var _a, _b
|
|
624
|
-
localStorage.setItem(params == null ? void 0 : params.key, (
|
|
625
|
-
(
|
|
626
|
-
(
|
|
1358
|
+
var _a, _b;
|
|
1359
|
+
localStorage.setItem(params == null ? void 0 : params.key, (params == null ? void 0 : params.value) ?? "");
|
|
1360
|
+
(_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params);
|
|
1361
|
+
(_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
|
|
627
1362
|
}
|
|
628
1363
|
function getStorageData(params) {
|
|
629
1364
|
var _a, _b;
|
|
630
1365
|
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
|
|
1366
|
+
(_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params, { [params == null ? void 0 : params.key]: value ?? "" });
|
|
632
1367
|
(_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
|
|
633
1368
|
}
|
|
634
1369
|
function removeStorageData(params) {
|
|
@@ -637,6 +1372,29 @@ function removeStorageData(params) {
|
|
|
637
1372
|
(_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params);
|
|
638
1373
|
(_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
|
|
639
1374
|
}
|
|
1375
|
+
const logout = promiseToCallback(
|
|
1376
|
+
"logout",
|
|
1377
|
+
async () => {
|
|
1378
|
+
try {
|
|
1379
|
+
const subdomainCookieSharing = await core.logout();
|
|
1380
|
+
const clientDomain = getDomain(
|
|
1381
|
+
subdomainCookieSharing,
|
|
1382
|
+
window.location.hostname
|
|
1383
|
+
);
|
|
1384
|
+
removeCookie(PpLocalStorageKey.refreshToken, clientDomain);
|
|
1385
|
+
removeCookie(PpLocalStorageKey.codeVerifier, clientDomain);
|
|
1386
|
+
return { statusCode: MiniAppStatusType.loggedOut };
|
|
1387
|
+
} catch (error) {
|
|
1388
|
+
throw new ClientError(
|
|
1389
|
+
`An error ocurred while trying to logout the user, error=${error}`,
|
|
1390
|
+
{
|
|
1391
|
+
errorCode: MiniAppErrorType.unknown
|
|
1392
|
+
}
|
|
1393
|
+
);
|
|
1394
|
+
}
|
|
1395
|
+
},
|
|
1396
|
+
getCore
|
|
1397
|
+
);
|
|
640
1398
|
function copyToClipboard(params) {
|
|
641
1399
|
var _a, _b, _c;
|
|
642
1400
|
const textarea = document.createElement("textarea");
|
|
@@ -680,11 +1438,14 @@ function removeTokenFromUrl(url2) {
|
|
|
680
1438
|
url2.searchParams.delete("token");
|
|
681
1439
|
url2.searchParams.delete("one_time_token");
|
|
682
1440
|
url2.search = url2.searchParams.toString();
|
|
683
|
-
|
|
1441
|
+
const newURL = url2.toString().replace(url2.origin, "");
|
|
1442
|
+
history.replaceState(null, "", newURL);
|
|
684
1443
|
}
|
|
685
1444
|
function triggerPostMessageToCore(type, showIframeFlag, params, postMessageParams) {
|
|
686
1445
|
const messageId = functionStart();
|
|
687
|
-
|
|
1446
|
+
if (showIframeFlag) {
|
|
1447
|
+
showCoreIframe(true);
|
|
1448
|
+
}
|
|
688
1449
|
const fnMessageHandler = (e) => {
|
|
689
1450
|
if (!checkIFrameOrigin(e.origin)) {
|
|
690
1451
|
return;
|
|
@@ -703,20 +1464,20 @@ function triggerPostMessageToCore(type, showIframeFlag, params, postMessageParam
|
|
|
703
1464
|
});
|
|
704
1465
|
}
|
|
705
1466
|
function renderButton(data, params) {
|
|
706
|
-
var _a, _b, _c, _d, _e
|
|
1467
|
+
var _a, _b, _c, _d, _e;
|
|
707
1468
|
const container = document.getElementById(params.containerId);
|
|
708
1469
|
const button = document.createElement("button");
|
|
709
1470
|
button.className = "ppmna-reset-css pp-smartButtonWrapper pp-button";
|
|
710
1471
|
const iconUrl = getIconUrl(params == null ? void 0 : params.theme);
|
|
711
1472
|
const cashbackClass = ((_b = (_a = data == null ? void 0 : data.data) == null ? void 0 : _a.cashbackInfo) == null ? void 0 : _b.length) ? "pp-cashback" : "";
|
|
712
1473
|
const shortTextClass = params.isShortText ? "pp-shortText" : "";
|
|
713
|
-
const buttonSize = (
|
|
714
|
-
const theme = (
|
|
1474
|
+
const buttonSize = (params == null ? void 0 : params.buttonSize) ?? "lg";
|
|
1475
|
+
const theme = (params == null ? void 0 : params.theme) ?? "light";
|
|
715
1476
|
const aTag = document.createElement("a");
|
|
716
1477
|
aTag.className = `pp-smartBtn pp-${theme} pp-${buttonSize} pp-${convertToString(
|
|
717
1478
|
params.type
|
|
718
1479
|
)} pp-${data.preferredLanguage} ${cashbackClass} ${shortTextClass}`;
|
|
719
|
-
aTag.href = convertToString(
|
|
1480
|
+
aTag.href = convertToString(data.data.loginUrl);
|
|
720
1481
|
const leftSpan = document.createElement("span");
|
|
721
1482
|
leftSpan.className = "pp-leftSection";
|
|
722
1483
|
const iconImg = document.createElement("img");
|
|
@@ -728,14 +1489,14 @@ function renderButton(data, params) {
|
|
|
728
1489
|
btnSpan.className = "pp-btnContent";
|
|
729
1490
|
const titleSpan = document.createElement("span");
|
|
730
1491
|
titleSpan.className = "pp-title";
|
|
731
|
-
titleSpan.innerText = (
|
|
1492
|
+
titleSpan.innerText = (_c = data == null ? void 0 : data.data) == null ? void 0 : _c.title;
|
|
732
1493
|
btnSpan.appendChild(titleSpan);
|
|
733
1494
|
leftSpan.appendChild(btnSpan);
|
|
734
1495
|
aTag.append(leftSpan);
|
|
735
1496
|
const cashbackSpan = document.createElement("span");
|
|
736
|
-
if ((
|
|
1497
|
+
if ((_d = data == null ? void 0 : data.data) == null ? void 0 : _d.cashbackInfo) {
|
|
737
1498
|
cashbackSpan.className = "pp-cashbackInfo";
|
|
738
|
-
cashbackSpan.innerText = (
|
|
1499
|
+
cashbackSpan.innerText = (_e = data == null ? void 0 : data.data) == null ? void 0 : _e.cashbackInfo;
|
|
739
1500
|
btnSpan.append(cashbackSpan);
|
|
740
1501
|
}
|
|
741
1502
|
if (data.data.avatarUrl) {
|
|
@@ -788,11 +1549,13 @@ const clientJsBridge = {
|
|
|
788
1549
|
};
|
|
789
1550
|
exposeClientJsBridge(clientJsBridge);
|
|
790
1551
|
const clientFunctions = {
|
|
1552
|
+
// functions that run on client, or need special treatment on client
|
|
791
1553
|
init,
|
|
792
1554
|
verifyMultiFactorAuthResult,
|
|
793
1555
|
share,
|
|
794
1556
|
setTitle,
|
|
795
1557
|
render,
|
|
1558
|
+
renderCoupons,
|
|
796
1559
|
scanCode,
|
|
797
1560
|
copyToClipboard,
|
|
798
1561
|
getSessionData,
|
|
@@ -801,24 +1564,43 @@ const clientFunctions = {
|
|
|
801
1564
|
setStorageData,
|
|
802
1565
|
removeStorageData,
|
|
803
1566
|
getKycPassportInfo,
|
|
804
|
-
getAuthStatus
|
|
1567
|
+
getAuthStatus,
|
|
1568
|
+
logout
|
|
805
1569
|
};
|
|
1570
|
+
const initExemptedFunctions = [
|
|
1571
|
+
"init",
|
|
1572
|
+
"setTitle",
|
|
1573
|
+
"copyToClipboard",
|
|
1574
|
+
"getSessionData",
|
|
1575
|
+
"setSessionData",
|
|
1576
|
+
"getStorageData",
|
|
1577
|
+
"setStorageData",
|
|
1578
|
+
"removeStorageData"
|
|
1579
|
+
];
|
|
1580
|
+
const autoInitFunctions = ["renderCoupons"];
|
|
806
1581
|
const proxy = new Proxy(clientFunctions, {
|
|
807
1582
|
get(target, prop) {
|
|
808
1583
|
const functionName = prop;
|
|
809
1584
|
if (!useAllFunctions) {
|
|
810
|
-
{
|
|
811
|
-
|
|
812
|
-
throw new Error(
|
|
813
|
-
`${functionName} is not supported by Mini Apps JS SDK`
|
|
814
|
-
);
|
|
815
|
-
}
|
|
1585
|
+
if (!isSupportedMiniapp(functionName)) {
|
|
1586
|
+
throw new Error(`${functionName} is not supported by Mini Apps JS SDK`);
|
|
816
1587
|
}
|
|
817
1588
|
}
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
1589
|
+
return async (params) => {
|
|
1590
|
+
var _a, _b;
|
|
1591
|
+
if (!initExemptedFunctions.includes(functionName) && !await initDonePromise) {
|
|
1592
|
+
if (autoInitFunctions.includes(functionName) && params.clientId) {
|
|
1593
|
+
init({ clientId: params.clientId, env: params.env });
|
|
1594
|
+
await initDonePromise;
|
|
1595
|
+
} else {
|
|
1596
|
+
(_a = params.fail) == null ? void 0 : _a.call(params, { errorCode: MiniAppErrorType.sdkNotInitialized });
|
|
1597
|
+
(_b = params.complete) == null ? void 0 : _b.call(params);
|
|
1598
|
+
return;
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
if (Object.prototype.hasOwnProperty.call(target, functionName)) {
|
|
1602
|
+
return target[functionName](params);
|
|
1603
|
+
}
|
|
822
1604
|
triggerPostMessageToCore(
|
|
823
1605
|
prop,
|
|
824
1606
|
false,
|
|
@@ -828,28 +1610,18 @@ const proxy = new Proxy(clientFunctions, {
|
|
|
828
1610
|
};
|
|
829
1611
|
}
|
|
830
1612
|
});
|
|
831
|
-
|
|
1613
|
+
function executePendingFunctionCalls() {
|
|
832
1614
|
const pendingFunctionCalls = window._ppcs;
|
|
833
1615
|
if (!pendingFunctionCalls) {
|
|
834
1616
|
return;
|
|
835
1617
|
}
|
|
836
1618
|
window._ppcs = void 0;
|
|
837
1619
|
for (const [functionName, params] of pendingFunctionCalls) {
|
|
838
|
-
|
|
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
|
-
}
|
|
1620
|
+
proxy[functionName](params);
|
|
852
1621
|
}
|
|
853
1622
|
}
|
|
854
|
-
|
|
855
|
-
|
|
1623
|
+
executePendingFunctionCalls();
|
|
1624
|
+
proxy.revision = "12c80ef";
|
|
1625
|
+
export {
|
|
1626
|
+
proxy as default
|
|
1627
|
+
};
|