@paypay/mini-app-js-sdk 2.40.0 → 2.46.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/README.md +0 -5
- package/dist/client/clientUtils.d.ts +1 -0
- package/dist/client/index.d.ts +11 -6
- package/dist/core/coreFunctions/fetchCoupons.d.ts +4 -0
- package/dist/core/coreFunctions/getLoginUrl.d.ts +4 -0
- package/dist/core/coreFunctions/index.d.ts +17 -7
- package/dist/core/coreFunctions/logEvent.d.ts +4 -0
- package/dist/core/coreFunctions/markAsReady.d.ts +4 -0
- package/dist/core/coreFunctions/middlewares/initRequired.d.ts +2 -0
- package/dist/core/coreFunctions/middlewares/loginRequired.d.ts +2 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/environment-variables.d.ts +0 -1
- package/dist/jsbridge-core/jsbridge.d.ts +4 -5
- package/dist/mini-app-api.d.ts +4 -4
- package/dist/mini-app-js-sdk.browser.js +2 -2
- package/dist/mini-app-js-sdk.es.js +555 -1069
- package/dist/model/bridge/getPlatformInformation.d.ts +1 -1
- package/dist/model/bridge/renderPayButton.d.ts +0 -6
- package/dist/model/miniAppError.d.ts +2 -5
- package/dist/resources/locales/topup/index.d.ts +2 -0
- package/dist/resources/locales/topup/ja.d.ts +1 -0
- package/dist/types/checkPaymentMethod.d.ts +1 -1
- package/dist/types/getKycInformation.d.ts +3 -3
- package/dist/types/getKycPassportInfo.d.ts +2 -2
- package/dist/types/getPlatformInformation.d.ts +0 -1
- package/dist/types/init.d.ts +2 -1
- package/dist/types/makePayment.d.ts +419 -0
- package/dist/types/topup.d.ts +1 -1
- package/dist/types.d.ts +8 -2
- package/dist/utils/analytics.d.ts +1 -0
- package/dist/utils/api.d.ts +0 -1
- package/dist/utils/helper.d.ts +2 -2
- package/dist/utils/minimumAppVersion.d.ts +0 -5
- package/dist/utils/minimumJSSDKVersion.d.ts +1 -0
- package/dist/utils/windowBridge.d.ts +24 -3
- package/dist/views/coupon/components/CouponAction/index.d.ts +25 -5
- package/dist/views/coupon/index.d.ts +25 -5
- package/dist/views/registerPaymentFeatures/types.d.ts +1 -1
- package/package.json +54 -66
- package/dist/composition-api/useShowUpdateWarningKycPassport.d.ts +0 -4
- package/dist/model/makePayment.d.ts +0 -428
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
!function(){"use strict";try{if("undefined"!=typeof document){var p=document.createElement("style");p.appendChild(document.createTextNode(".ppmna-reset-css{all:initial}.ppmna-reset-css *{text-align:unset;color:unset;background:initial;background-color:transparent;margin:revert;padding:revert;font-weight:revert;font-style:unset;font-size:unset;-webkit-user-select:none;user-select:none;border:unset;border-radius:revert;vertical-align:unset;word-break:unset;outline:none;box-sizing:content-box}.ppmna-reset-css * img{display:inline-block}.ppmna-reset-css * input,.ppmna-reset-css * select{-webkit-user-select:auto;user-select:auto}.ppmna-reset-css * li{list-style:none}.ppmna-reset-css * :where(*:not(svg,svg *)){all:revert}.pp-smartButtonWrapper .pp-smartBtn{display:flex;align-items:center;border-radius:8px;border:none;font-size:14px;font-weight:600;line-height:22px;color:#fff;padding:0;width:100%;height:44px;margin:auto;-webkit-tap-highlight-color:transparent;text-decoration:none;box-sizing:border-box}.pp-smartButtonWrapper .pp-smartBtn.pp-sm .pp-leftSection .pp-btnContent{flex-direction:column}.pp-smartButtonWrapper .pp-smartBtn.pp-light{background:#fff;color:#242323}.pp-smartButtonWrapper .pp-smartBtn.pp-dark{background:#000}.pp-smartButtonWrapper .pp-smartBtn.pp-red{background:#f03}.pp-smartButtonWrapper .pp-smartBtn.pp-login{min-width:180px}.pp-smartButtonWrapper .pp-smartBtn.pp-login.pp-sm{width:180px!important}.pp-smartButtonWrapper .pp-smartBtn.pp-login.pp-light{border:1px solid #e4e4e8}.pp-smartButtonWrapper .pp-smartBtn.pp-login.pp-light .pp-userProfile{margin-right:4px}.pp-smartButtonWrapper .pp-smartBtn.pp-login .pp-leftSection .pp-btnContent{display:grid}.pp-smartButtonWrapper .pp-smartBtn.pp-pay{min-width:160px}.pp-smartButtonWrapper .pp-smartBtn.pp-pay.pp-light{border:1px solid #dddddd}.pp-smartButtonWrapper .pp-smartBtn.pp-pay.pp-light .pp-cashbackInfo{color:#ff954c;background:#fff0e5}.pp-smartButtonWrapper .pp-smartBtn.pp-pay.pp-red .pp-cashbackInfo{color:#f03}.pp-smartButtonWrapper .pp-smartBtn.pp-pay.pp-ja .pp-cashbackInfo{padding:2px 16px}.pp-smartButtonWrapper .pp-smartBtn.pp-pay.pp-sm{width:160px!important}.pp-smartButtonWrapper .pp-smartBtn.pp-pay.pp-sm.pp-cashback{height:66px;flex-direction:column;justify-content:center}.pp-smartButtonWrapper .pp-smartBtn.pp-pay.pp-sm .pp-cashbackInfo{margin:8px 0 0}.pp-smartButtonWrapper .pp-smartBtn.pp-pay .pp-leftSection .pp-img{width:24px;height:24px}.pp-smartButtonWrapper .pp-smartBtn.pp-pay.pp-shortText{font-size:16px}.pp-smartButtonWrapper .pp-smartBtn.pp-pay.pp-sm .pp-smartButtonWrapper .pp-smartBtn.pp-pay.pp-cashback .pp-leftSection .pp-btnContent,.pp-smartButtonWrapper .pp-smartBtn.pp-pay.pp-shortText .pp-leftSection .pp-btnContent{margin-left:4px}.pp-smartButtonWrapper .pp-smartBtn .pp-leftSection{display:flex;justify-content:center;align-items:center;width:100%;box-sizing:border-box;padding:0 8px}.pp-smartButtonWrapper .pp-smartBtn .pp-leftSection .pp-img{width:20px;height:20px;display:inline-block}.pp-smartButtonWrapper .pp-smartBtn .pp-leftSection .pp-btnContent{margin-left:8px}.pp-smartButtonWrapper .pp-smartBtn .pp-leftSection .pp-btnContent .pp-title{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.pp-smartButtonWrapper .pp-smartBtn .pp-cashbackInfo{font-size:12px;color:#242323;background:#fff;line-height:14px;padding:2px 8px;border-radius:9px;margin-left:8px}.pp-smartButtonWrapper .pp-smartBtn .pp-userProfile{width:34px;height:34px;border-radius:50%;margin-right:5px}.pp-smartButtonWrapper.pp-button{padding:0;margin:0;background:none;border:none;width:100%;border-radius:8px;-webkit-tap-highlight-color:transparent;font-family:revert!important}.pp-smartButtonWrapper.pp-button *{font-family:revert!important}")),document.head.appendChild(p)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}}();
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __defProps = Object.defineProperties;
|
|
4
4
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
@@ -38,7 +38,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
38
38
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
39
39
|
});
|
|
40
40
|
};
|
|
41
|
-
/*! js-cookie v3.0.
|
|
41
|
+
/*! js-cookie v3.0.5 | MIT */
|
|
42
42
|
function assign(target) {
|
|
43
43
|
for (var i = 1; i < arguments.length; i++) {
|
|
44
44
|
var source = arguments[i];
|
|
@@ -63,7 +63,7 @@ var defaultConverter = {
|
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
function init$1(converter, defaultAttributes) {
|
|
66
|
-
function set(
|
|
66
|
+
function set(name, value, attributes) {
|
|
67
67
|
if (typeof document === "undefined") {
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
@@ -74,7 +74,7 @@ function init$1(converter, defaultAttributes) {
|
|
|
74
74
|
if (attributes.expires) {
|
|
75
75
|
attributes.expires = attributes.expires.toUTCString();
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
name = encodeURIComponent(name).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
|
|
78
78
|
var stringifiedAttributes = "";
|
|
79
79
|
for (var attributeName in attributes) {
|
|
80
80
|
if (!attributes[attributeName]) {
|
|
@@ -86,10 +86,10 @@ function init$1(converter, defaultAttributes) {
|
|
|
86
86
|
}
|
|
87
87
|
stringifiedAttributes += "=" + attributes[attributeName].split(";")[0];
|
|
88
88
|
}
|
|
89
|
-
return document.cookie =
|
|
89
|
+
return document.cookie = name + "=" + converter.write(value, name) + stringifiedAttributes;
|
|
90
90
|
}
|
|
91
|
-
function get(
|
|
92
|
-
if (typeof document === "undefined" || arguments.length && !
|
|
91
|
+
function get(name) {
|
|
92
|
+
if (typeof document === "undefined" || arguments.length && !name) {
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
95
95
|
var cookies = document.cookie ? document.cookie.split("; ") : [];
|
|
@@ -98,23 +98,23 @@ function init$1(converter, defaultAttributes) {
|
|
|
98
98
|
var parts = cookies[i].split("=");
|
|
99
99
|
var value = parts.slice(1).join("=");
|
|
100
100
|
try {
|
|
101
|
-
var
|
|
102
|
-
jar[
|
|
103
|
-
if (
|
|
101
|
+
var found = decodeURIComponent(parts[0]);
|
|
102
|
+
jar[found] = converter.read(value, found);
|
|
103
|
+
if (name === found) {
|
|
104
104
|
break;
|
|
105
105
|
}
|
|
106
106
|
} catch (e) {
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
return
|
|
109
|
+
return name ? jar[name] : jar;
|
|
110
110
|
}
|
|
111
111
|
return Object.create(
|
|
112
112
|
{
|
|
113
113
|
set,
|
|
114
114
|
get,
|
|
115
|
-
remove: function(
|
|
115
|
+
remove: function(name, attributes) {
|
|
116
116
|
set(
|
|
117
|
-
|
|
117
|
+
name,
|
|
118
118
|
"",
|
|
119
119
|
assign({}, attributes, {
|
|
120
120
|
expires: -1
|
|
@@ -155,6 +155,7 @@ var PpLocalStorageKey = /* @__PURE__ */ ((PpLocalStorageKey2) => {
|
|
|
155
155
|
PpLocalStorageKey2["claimCouponImmediately"] = "ppjssdk.claimCouponImmediately";
|
|
156
156
|
PpLocalStorageKey2["merchant"] = "ppjssdk.merchant";
|
|
157
157
|
PpLocalStorageKey2["consumedOTT"] = "ppjssdk.consumedOTT";
|
|
158
|
+
PpLocalStorageKey2["initializedAt"] = "ppjssdk.initializedAt";
|
|
158
159
|
return PpLocalStorageKey2;
|
|
159
160
|
})(PpLocalStorageKey || {});
|
|
160
161
|
const PPFunctionResult = {
|
|
@@ -304,47 +305,6 @@ function url(path) {
|
|
|
304
305
|
}
|
|
305
306
|
const img_paypayRec = url("icon-paypay-rec.svg");
|
|
306
307
|
const img_paypayRecWhite = url("icon-paypay-rec-white.svg");
|
|
307
|
-
var getRandomValues;
|
|
308
|
-
var rnds8 = new Uint8Array(16);
|
|
309
|
-
function rng() {
|
|
310
|
-
if (!getRandomValues) {
|
|
311
|
-
getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== "undefined" && typeof msCrypto.getRandomValues === "function" && msCrypto.getRandomValues.bind(msCrypto);
|
|
312
|
-
if (!getRandomValues) {
|
|
313
|
-
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
return getRandomValues(rnds8);
|
|
317
|
-
}
|
|
318
|
-
const REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
319
|
-
function validate(uuid) {
|
|
320
|
-
return typeof uuid === "string" && REGEX.test(uuid);
|
|
321
|
-
}
|
|
322
|
-
var byteToHex = [];
|
|
323
|
-
for (var i = 0; i < 256; ++i) {
|
|
324
|
-
byteToHex.push((i + 256).toString(16).substr(1));
|
|
325
|
-
}
|
|
326
|
-
function stringify(arr) {
|
|
327
|
-
var offset = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
|
|
328
|
-
var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
|
329
|
-
if (!validate(uuid)) {
|
|
330
|
-
throw TypeError("Stringified UUID is invalid");
|
|
331
|
-
}
|
|
332
|
-
return uuid;
|
|
333
|
-
}
|
|
334
|
-
function v4(options, buf, offset) {
|
|
335
|
-
options = options || {};
|
|
336
|
-
var rnds = options.random || (options.rng || rng)();
|
|
337
|
-
rnds[6] = rnds[6] & 15 | 64;
|
|
338
|
-
rnds[8] = rnds[8] & 63 | 128;
|
|
339
|
-
if (buf) {
|
|
340
|
-
offset = offset || 0;
|
|
341
|
-
for (var i = 0; i < 16; ++i) {
|
|
342
|
-
buf[offset + i] = rnds[i];
|
|
343
|
-
}
|
|
344
|
-
return buf;
|
|
345
|
-
}
|
|
346
|
-
return stringify(rnds);
|
|
347
|
-
}
|
|
348
308
|
class PPError extends Error {
|
|
349
309
|
constructor(message, errorCode) {
|
|
350
310
|
super(message);
|
|
@@ -421,10 +381,11 @@ var MiniAppErrorType = /* @__PURE__ */ ((MiniAppErrorType2) => {
|
|
|
421
381
|
MiniAppErrorType2["merchantTimeout"] = "MERCHANT_TIMEOUT";
|
|
422
382
|
MiniAppErrorType2["rateLimitExceeded"] = "RATE_LIMIT_EXCEEDED";
|
|
423
383
|
MiniAppErrorType2["sdkUpgradeRequired"] = "SDK_UPGRADE_REQUIRED";
|
|
384
|
+
MiniAppErrorType2["authorizationNeeded"] = "AUTHORIZATION_NEEDED";
|
|
424
385
|
return MiniAppErrorType2;
|
|
425
386
|
})(MiniAppErrorType || {});
|
|
426
|
-
const JS_SDK_VERSION = "2.
|
|
427
|
-
const REVISION = "
|
|
387
|
+
const JS_SDK_VERSION = "2.46.0";
|
|
388
|
+
const REVISION = "bd28c67";
|
|
428
389
|
const coreBaseUrl = new URL("https://mini-app-sdk-core.paypay.ne.jp/");
|
|
429
390
|
const CORE_IFRAME_ORIGIN = coreBaseUrl.origin;
|
|
430
391
|
const CORE_IFRAME_URL = new URL(
|
|
@@ -436,36 +397,25 @@ const COUPON_IFRAME_URL = new URL(
|
|
|
436
397
|
coreBaseUrl
|
|
437
398
|
).href;
|
|
438
399
|
const SENTRY_DSN = "https://377b45f154b1fb17d8e98a6ffb67030a@o4505819519320064.ingest.sentry.io/4506579323453440";
|
|
439
|
-
const
|
|
440
|
-
const
|
|
441
|
-
const objectToString = Object.prototype.toString;
|
|
442
|
-
function isBuiltin(wat, className) {
|
|
443
|
-
return objectToString.call(wat) === `[object ${className}]`;
|
|
444
|
-
}
|
|
445
|
-
function isPlainObject(wat) {
|
|
446
|
-
return isBuiltin(wat, "Object");
|
|
447
|
-
}
|
|
448
|
-
function isThenable(wat) {
|
|
449
|
-
return Boolean(wat && wat.then && typeof wat.then === "function");
|
|
450
|
-
}
|
|
451
|
-
function isGlobalObj(obj) {
|
|
452
|
-
return obj && obj.Math == Math ? obj : void 0;
|
|
453
|
-
}
|
|
454
|
-
const GLOBAL_OBJ = typeof globalThis == "object" && isGlobalObj(globalThis) || // eslint-disable-next-line no-restricted-globals
|
|
455
|
-
typeof window == "object" && isGlobalObj(window) || typeof self == "object" && isGlobalObj(self) || typeof global == "object" && isGlobalObj(global) || function() {
|
|
456
|
-
return this;
|
|
457
|
-
}() || {};
|
|
458
|
-
function getGlobalObject() {
|
|
459
|
-
return GLOBAL_OBJ;
|
|
460
|
-
}
|
|
400
|
+
const SDK_VERSION = "8.45.1";
|
|
401
|
+
const GLOBAL_OBJ = globalThis;
|
|
461
402
|
function getGlobalSingleton(name, creator, obj) {
|
|
462
|
-
const gbl =
|
|
403
|
+
const gbl = GLOBAL_OBJ;
|
|
463
404
|
const __SENTRY__ = gbl.__SENTRY__ = gbl.__SENTRY__ || {};
|
|
464
|
-
const
|
|
465
|
-
return
|
|
405
|
+
const versionedCarrier = __SENTRY__[SDK_VERSION] = __SENTRY__[SDK_VERSION] || {};
|
|
406
|
+
return versionedCarrier[name] || (versionedCarrier[name] = creator());
|
|
466
407
|
}
|
|
408
|
+
const DEBUG_BUILD = typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__;
|
|
467
409
|
const PREFIX = "Sentry Logger ";
|
|
468
|
-
const CONSOLE_LEVELS = [
|
|
410
|
+
const CONSOLE_LEVELS = [
|
|
411
|
+
"debug",
|
|
412
|
+
"info",
|
|
413
|
+
"warn",
|
|
414
|
+
"error",
|
|
415
|
+
"log",
|
|
416
|
+
"assert",
|
|
417
|
+
"trace"
|
|
418
|
+
];
|
|
469
419
|
const originalConsoleMethods = {};
|
|
470
420
|
function consoleSandbox(callback) {
|
|
471
421
|
if (!("console" in GLOBAL_OBJ)) {
|
|
@@ -498,7 +448,7 @@ function makeLogger() {
|
|
|
498
448
|
},
|
|
499
449
|
isEnabled: () => enabled
|
|
500
450
|
};
|
|
501
|
-
if (
|
|
451
|
+
if (DEBUG_BUILD) {
|
|
502
452
|
CONSOLE_LEVELS.forEach((name) => {
|
|
503
453
|
logger2[name] = (...args) => {
|
|
504
454
|
if (enabled) {
|
|
@@ -515,241 +465,56 @@ function makeLogger() {
|
|
|
515
465
|
}
|
|
516
466
|
return logger2;
|
|
517
467
|
}
|
|
518
|
-
const logger = makeLogger
|
|
519
|
-
function
|
|
520
|
-
|
|
521
|
-
return
|
|
522
|
-
}
|
|
523
|
-
function _dropUndefinedKeys(inputValue, memoizationMap) {
|
|
524
|
-
if (isPlainObject(inputValue)) {
|
|
525
|
-
const memoVal = memoizationMap.get(inputValue);
|
|
526
|
-
if (memoVal !== void 0) {
|
|
527
|
-
return memoVal;
|
|
528
|
-
}
|
|
529
|
-
const returnValue = {};
|
|
530
|
-
memoizationMap.set(inputValue, returnValue);
|
|
531
|
-
for (const key of Object.keys(inputValue)) {
|
|
532
|
-
if (typeof inputValue[key] !== "undefined") {
|
|
533
|
-
returnValue[key] = _dropUndefinedKeys(inputValue[key], memoizationMap);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
return returnValue;
|
|
537
|
-
}
|
|
538
|
-
if (Array.isArray(inputValue)) {
|
|
539
|
-
const memoVal = memoizationMap.get(inputValue);
|
|
540
|
-
if (memoVal !== void 0) {
|
|
541
|
-
return memoVal;
|
|
542
|
-
}
|
|
543
|
-
const returnValue = [];
|
|
544
|
-
memoizationMap.set(inputValue, returnValue);
|
|
545
|
-
inputValue.forEach((item) => {
|
|
546
|
-
returnValue.push(_dropUndefinedKeys(item, memoizationMap));
|
|
547
|
-
});
|
|
548
|
-
return returnValue;
|
|
549
|
-
}
|
|
550
|
-
return inputValue;
|
|
468
|
+
const logger = getGlobalSingleton("logger", makeLogger);
|
|
469
|
+
function getMainCarrier() {
|
|
470
|
+
getSentryCarrier(GLOBAL_OBJ);
|
|
471
|
+
return GLOBAL_OBJ;
|
|
551
472
|
}
|
|
552
|
-
function
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
try {
|
|
557
|
-
if (crypto2 && crypto2.randomUUID) {
|
|
558
|
-
return crypto2.randomUUID().replace(/-/g, "");
|
|
559
|
-
}
|
|
560
|
-
if (crypto2 && crypto2.getRandomValues) {
|
|
561
|
-
getRandomByte = () => crypto2.getRandomValues(new Uint8Array(1))[0];
|
|
562
|
-
}
|
|
563
|
-
} catch (_) {
|
|
564
|
-
}
|
|
565
|
-
return ([1e7] + 1e3 + 4e3 + 8e3 + 1e11).replace(
|
|
566
|
-
/[018]/g,
|
|
567
|
-
(c) => (
|
|
568
|
-
// eslint-disable-next-line no-bitwise
|
|
569
|
-
(c ^ (getRandomByte() & 15) >> c / 4).toString(16)
|
|
570
|
-
)
|
|
571
|
-
);
|
|
473
|
+
function getSentryCarrier(carrier) {
|
|
474
|
+
const __SENTRY__ = carrier.__SENTRY__ = carrier.__SENTRY__ || {};
|
|
475
|
+
__SENTRY__.version = __SENTRY__.version || SDK_VERSION;
|
|
476
|
+
return __SENTRY__[SDK_VERSION] = __SENTRY__[SDK_VERSION] || {};
|
|
572
477
|
}
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
States2[States2["RESOLVED"] = RESOLVED] = "RESOLVED";
|
|
591
|
-
const REJECTED = 2;
|
|
592
|
-
States2[States2["REJECTED"] = REJECTED] = "REJECTED";
|
|
593
|
-
})(States || (States = {}));
|
|
594
|
-
class SyncPromise {
|
|
595
|
-
constructor(executor) {
|
|
596
|
-
SyncPromise.prototype.__init.call(this);
|
|
597
|
-
SyncPromise.prototype.__init2.call(this);
|
|
598
|
-
SyncPromise.prototype.__init3.call(this);
|
|
599
|
-
SyncPromise.prototype.__init4.call(this);
|
|
600
|
-
this._state = States.PENDING;
|
|
601
|
-
this._handlers = [];
|
|
602
|
-
try {
|
|
603
|
-
executor(this._resolve, this._reject);
|
|
604
|
-
} catch (e) {
|
|
605
|
-
this._reject(e);
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
/** JSDoc */
|
|
609
|
-
then(onfulfilled, onrejected) {
|
|
610
|
-
return new SyncPromise((resolve, reject) => {
|
|
611
|
-
this._handlers.push([
|
|
612
|
-
false,
|
|
613
|
-
(result) => {
|
|
614
|
-
if (!onfulfilled) {
|
|
615
|
-
resolve(result);
|
|
616
|
-
} else {
|
|
617
|
-
try {
|
|
618
|
-
resolve(onfulfilled(result));
|
|
619
|
-
} catch (e) {
|
|
620
|
-
reject(e);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
},
|
|
624
|
-
(reason) => {
|
|
625
|
-
if (!onrejected) {
|
|
626
|
-
reject(reason);
|
|
627
|
-
} else {
|
|
628
|
-
try {
|
|
629
|
-
resolve(onrejected(reason));
|
|
630
|
-
} catch (e) {
|
|
631
|
-
reject(e);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
]);
|
|
636
|
-
this._executeHandlers();
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
/** JSDoc */
|
|
640
|
-
catch(onrejected) {
|
|
641
|
-
return this.then((val) => val, onrejected);
|
|
642
|
-
}
|
|
643
|
-
/** JSDoc */
|
|
644
|
-
finally(onfinally) {
|
|
645
|
-
return new SyncPromise((resolve, reject) => {
|
|
646
|
-
let val;
|
|
647
|
-
let isRejected;
|
|
648
|
-
return this.then(
|
|
649
|
-
(value) => {
|
|
650
|
-
isRejected = false;
|
|
651
|
-
val = value;
|
|
652
|
-
if (onfinally) {
|
|
653
|
-
onfinally();
|
|
654
|
-
}
|
|
655
|
-
},
|
|
656
|
-
(reason) => {
|
|
657
|
-
isRejected = true;
|
|
658
|
-
val = reason;
|
|
659
|
-
if (onfinally) {
|
|
660
|
-
onfinally();
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
).then(() => {
|
|
664
|
-
if (isRejected) {
|
|
665
|
-
reject(val);
|
|
666
|
-
return;
|
|
667
|
-
}
|
|
668
|
-
resolve(val);
|
|
669
|
-
});
|
|
478
|
+
const objectToString = Object.prototype.toString;
|
|
479
|
+
function isBuiltin(wat, className) {
|
|
480
|
+
return objectToString.call(wat) === `[object ${className}]`;
|
|
481
|
+
}
|
|
482
|
+
function isPlainObject(wat) {
|
|
483
|
+
return isBuiltin(wat, "Object");
|
|
484
|
+
}
|
|
485
|
+
function isThenable(wat) {
|
|
486
|
+
return Boolean(wat && wat.then && typeof wat.then === "function");
|
|
487
|
+
}
|
|
488
|
+
function addNonEnumerableProperty(obj, name, value) {
|
|
489
|
+
try {
|
|
490
|
+
Object.defineProperty(obj, name, {
|
|
491
|
+
// enumerable: false, // the default, so we can save on bundle size by not explicitly setting it
|
|
492
|
+
value,
|
|
493
|
+
writable: true,
|
|
494
|
+
configurable: true
|
|
670
495
|
});
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
__init() {
|
|
674
|
-
this._resolve = (value) => {
|
|
675
|
-
this._setResult(States.RESOLVED, value);
|
|
676
|
-
};
|
|
677
|
-
}
|
|
678
|
-
/** JSDoc */
|
|
679
|
-
__init2() {
|
|
680
|
-
this._reject = (reason) => {
|
|
681
|
-
this._setResult(States.REJECTED, reason);
|
|
682
|
-
};
|
|
683
|
-
}
|
|
684
|
-
/** JSDoc */
|
|
685
|
-
__init3() {
|
|
686
|
-
this._setResult = (state, value) => {
|
|
687
|
-
if (this._state !== States.PENDING) {
|
|
688
|
-
return;
|
|
689
|
-
}
|
|
690
|
-
if (isThenable(value)) {
|
|
691
|
-
void value.then(this._resolve, this._reject);
|
|
692
|
-
return;
|
|
693
|
-
}
|
|
694
|
-
this._state = state;
|
|
695
|
-
this._value = value;
|
|
696
|
-
this._executeHandlers();
|
|
697
|
-
};
|
|
698
|
-
}
|
|
699
|
-
/** JSDoc */
|
|
700
|
-
__init4() {
|
|
701
|
-
this._executeHandlers = () => {
|
|
702
|
-
if (this._state === States.PENDING) {
|
|
703
|
-
return;
|
|
704
|
-
}
|
|
705
|
-
const cachedHandlers = this._handlers.slice();
|
|
706
|
-
this._handlers = [];
|
|
707
|
-
cachedHandlers.forEach((handler) => {
|
|
708
|
-
if (handler[0]) {
|
|
709
|
-
return;
|
|
710
|
-
}
|
|
711
|
-
if (this._state === States.RESOLVED) {
|
|
712
|
-
handler[1](this._value);
|
|
713
|
-
}
|
|
714
|
-
if (this._state === States.REJECTED) {
|
|
715
|
-
handler[2](this._value);
|
|
716
|
-
}
|
|
717
|
-
handler[0] = true;
|
|
718
|
-
});
|
|
719
|
-
};
|
|
496
|
+
} catch (o_O) {
|
|
497
|
+
DEBUG_BUILD && logger.log(`Failed to add non-enumerable property "${name}" to object`, obj);
|
|
720
498
|
}
|
|
721
499
|
}
|
|
722
|
-
const
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
}
|
|
726
|
-
function
|
|
727
|
-
const { performance } =
|
|
500
|
+
const ONE_SECOND_IN_MS = 1e3;
|
|
501
|
+
function dateTimestampInSeconds() {
|
|
502
|
+
return Date.now() / ONE_SECOND_IN_MS;
|
|
503
|
+
}
|
|
504
|
+
function createUnixTimestampInSecondsFunc() {
|
|
505
|
+
const { performance } = GLOBAL_OBJ;
|
|
728
506
|
if (!performance || !performance.now) {
|
|
729
|
-
return
|
|
507
|
+
return dateTimestampInSeconds;
|
|
730
508
|
}
|
|
731
|
-
const
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
timeOrigin
|
|
509
|
+
const approxStartingTimeOrigin = Date.now() - performance.now();
|
|
510
|
+
const timeOrigin = performance.timeOrigin == void 0 ? approxStartingTimeOrigin : performance.timeOrigin;
|
|
511
|
+
return () => {
|
|
512
|
+
return (timeOrigin + performance.now()) / ONE_SECOND_IN_MS;
|
|
735
513
|
};
|
|
736
514
|
}
|
|
737
|
-
|
|
738
|
-
try {
|
|
739
|
-
const perfHooks = dynamicRequire(module, "perf_hooks");
|
|
740
|
-
return perfHooks.performance;
|
|
741
|
-
} catch (_) {
|
|
742
|
-
return void 0;
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
const platformPerformance = isNodeEnv() ? getNodePerformance() : getBrowserPerformance();
|
|
746
|
-
const timestampSource = platformPerformance === void 0 ? dateTimestampSource : {
|
|
747
|
-
nowSeconds: () => (platformPerformance.timeOrigin + platformPerformance.now()) / 1e3
|
|
748
|
-
};
|
|
749
|
-
const dateTimestampInSeconds = dateTimestampSource.nowSeconds.bind(dateTimestampSource);
|
|
750
|
-
const timestampInSeconds = timestampSource.nowSeconds.bind(timestampSource);
|
|
515
|
+
const timestampInSeconds = createUnixTimestampInSecondsFunc();
|
|
751
516
|
(() => {
|
|
752
|
-
const { performance } =
|
|
517
|
+
const { performance } = GLOBAL_OBJ;
|
|
753
518
|
if (!performance || !performance.now) {
|
|
754
519
|
return void 0;
|
|
755
520
|
}
|
|
@@ -771,43 +536,30 @@ const timestampInSeconds = timestampSource.nowSeconds.bind(timestampSource);
|
|
|
771
536
|
}
|
|
772
537
|
return dateNow;
|
|
773
538
|
})();
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
} else {
|
|
789
|
-
void notifyEventProcessors(processors, result, hint, index + 1).then(resolve).then(null, reject);
|
|
790
|
-
}
|
|
539
|
+
function uuid4() {
|
|
540
|
+
const gbl = GLOBAL_OBJ;
|
|
541
|
+
const crypto = gbl.crypto || gbl.msCrypto;
|
|
542
|
+
let getRandomByte = () => Math.random() * 16;
|
|
543
|
+
try {
|
|
544
|
+
if (crypto && crypto.randomUUID) {
|
|
545
|
+
return crypto.randomUUID().replace(/-/g, "");
|
|
546
|
+
}
|
|
547
|
+
if (crypto && crypto.getRandomValues) {
|
|
548
|
+
getRandomByte = () => {
|
|
549
|
+
const typedArray = new Uint8Array(1);
|
|
550
|
+
crypto.getRandomValues(typedArray);
|
|
551
|
+
return typedArray[0];
|
|
552
|
+
};
|
|
791
553
|
}
|
|
792
|
-
})
|
|
793
|
-
}
|
|
794
|
-
function makeSession(context) {
|
|
795
|
-
const startingTime = timestampInSeconds();
|
|
796
|
-
const session = {
|
|
797
|
-
sid: uuid4(),
|
|
798
|
-
init: true,
|
|
799
|
-
timestamp: startingTime,
|
|
800
|
-
started: startingTime,
|
|
801
|
-
duration: 0,
|
|
802
|
-
status: "ok",
|
|
803
|
-
errors: 0,
|
|
804
|
-
ignoreDuration: false,
|
|
805
|
-
toJSON: () => sessionToJSON(session)
|
|
806
|
-
};
|
|
807
|
-
if (context) {
|
|
808
|
-
updateSession(session, context);
|
|
554
|
+
} catch (_) {
|
|
809
555
|
}
|
|
810
|
-
return
|
|
556
|
+
return ("10000000100040008000" + 1e11).replace(
|
|
557
|
+
/[018]/g,
|
|
558
|
+
(c) => (
|
|
559
|
+
// eslint-disable-next-line no-bitwise
|
|
560
|
+
(c ^ (getRandomByte() & 15) >> c / 4).toString(16)
|
|
561
|
+
)
|
|
562
|
+
);
|
|
811
563
|
}
|
|
812
564
|
function updateSession(session, context = {}) {
|
|
813
565
|
if (context.user) {
|
|
@@ -864,40 +616,43 @@ function updateSession(session, context = {}) {
|
|
|
864
616
|
session.status = context.status;
|
|
865
617
|
}
|
|
866
618
|
}
|
|
867
|
-
function
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
errors: session.errors,
|
|
885
|
-
did: typeof session.did === "number" || typeof session.did === "string" ? `${session.did}` : void 0,
|
|
886
|
-
duration: session.duration,
|
|
887
|
-
abnormal_mechanism: session.abnormal_mechanism,
|
|
888
|
-
attrs: {
|
|
889
|
-
release: session.release,
|
|
890
|
-
environment: session.environment,
|
|
891
|
-
ip_address: session.ipAddress,
|
|
892
|
-
user_agent: session.userAgent
|
|
619
|
+
function generateTraceId() {
|
|
620
|
+
return uuid4();
|
|
621
|
+
}
|
|
622
|
+
function generateSpanId() {
|
|
623
|
+
return uuid4().substring(16);
|
|
624
|
+
}
|
|
625
|
+
function merge(initialObj, mergeObj, levels = 2) {
|
|
626
|
+
if (!mergeObj || typeof mergeObj !== "object" || levels <= 0) {
|
|
627
|
+
return mergeObj;
|
|
628
|
+
}
|
|
629
|
+
if (initialObj && mergeObj && Object.keys(mergeObj).length === 0) {
|
|
630
|
+
return initialObj;
|
|
631
|
+
}
|
|
632
|
+
const output = __spreadValues({}, initialObj);
|
|
633
|
+
for (const key in mergeObj) {
|
|
634
|
+
if (Object.prototype.hasOwnProperty.call(mergeObj, key)) {
|
|
635
|
+
output[key] = merge(output[key], mergeObj[key], levels - 1);
|
|
893
636
|
}
|
|
894
|
-
}
|
|
637
|
+
}
|
|
638
|
+
return output;
|
|
639
|
+
}
|
|
640
|
+
const SCOPE_SPAN_FIELD = "_sentrySpan";
|
|
641
|
+
function _setSpanForScope(scope, span) {
|
|
642
|
+
if (span) {
|
|
643
|
+
addNonEnumerableProperty(scope, SCOPE_SPAN_FIELD, span);
|
|
644
|
+
} else {
|
|
645
|
+
delete scope[SCOPE_SPAN_FIELD];
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
function _getSpanForScope(scope) {
|
|
649
|
+
return scope[SCOPE_SPAN_FIELD];
|
|
895
650
|
}
|
|
896
651
|
const DEFAULT_MAX_BREADCRUMBS = 100;
|
|
897
|
-
class
|
|
652
|
+
class ScopeClass {
|
|
898
653
|
/** Flag if notifying is happening. */
|
|
899
654
|
/** Callback for client to receive scope changes. */
|
|
900
|
-
/** Callback list that will be called
|
|
655
|
+
/** Callback list that will be called during event processing. */
|
|
901
656
|
/** Array of breadcrumbs. */
|
|
902
657
|
/** User */
|
|
903
658
|
/** Tags */
|
|
@@ -911,11 +666,17 @@ class Scope {
|
|
|
911
666
|
*/
|
|
912
667
|
/** Fingerprint */
|
|
913
668
|
/** Severity */
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
669
|
+
/**
|
|
670
|
+
* Transaction Name
|
|
671
|
+
*
|
|
672
|
+
* IMPORTANT: The transaction name on the scope has nothing to do with root spans/transaction objects.
|
|
673
|
+
* It's purpose is to assign a transaction to the scope that's added to non-transaction events.
|
|
674
|
+
*/
|
|
917
675
|
/** Session */
|
|
918
676
|
/** Request Mode Session Status */
|
|
677
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
678
|
+
/** The client on this scope */
|
|
679
|
+
/** Contains the last event id of a captured event. */
|
|
919
680
|
// NOTE: Any field which gets added here should get added not only to the constructor but also to the `clone` method.
|
|
920
681
|
constructor() {
|
|
921
682
|
this._notifyingListeners = false;
|
|
@@ -928,36 +689,66 @@ class Scope {
|
|
|
928
689
|
this._extra = {};
|
|
929
690
|
this._contexts = {};
|
|
930
691
|
this._sdkProcessingMetadata = {};
|
|
931
|
-
this._propagationContext =
|
|
692
|
+
this._propagationContext = {
|
|
693
|
+
traceId: generateTraceId(),
|
|
694
|
+
spanId: generateSpanId()
|
|
695
|
+
};
|
|
932
696
|
}
|
|
933
697
|
/**
|
|
934
|
-
*
|
|
935
|
-
* @param scope to clone.
|
|
698
|
+
* @inheritDoc
|
|
936
699
|
*/
|
|
937
|
-
|
|
938
|
-
const newScope = new
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
newScope.
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
newScope._session = scope._session;
|
|
948
|
-
newScope._transactionName = scope._transactionName;
|
|
949
|
-
newScope._fingerprint = scope._fingerprint;
|
|
950
|
-
newScope._eventProcessors = [...scope._eventProcessors];
|
|
951
|
-
newScope._requestSession = scope._requestSession;
|
|
952
|
-
newScope._attachments = [...scope._attachments];
|
|
953
|
-
newScope._sdkProcessingMetadata = __spreadValues({}, scope._sdkProcessingMetadata);
|
|
954
|
-
newScope._propagationContext = __spreadValues({}, scope._propagationContext);
|
|
700
|
+
clone() {
|
|
701
|
+
const newScope = new ScopeClass();
|
|
702
|
+
newScope._breadcrumbs = [...this._breadcrumbs];
|
|
703
|
+
newScope._tags = __spreadValues({}, this._tags);
|
|
704
|
+
newScope._extra = __spreadValues({}, this._extra);
|
|
705
|
+
newScope._contexts = __spreadValues({}, this._contexts);
|
|
706
|
+
if (this._contexts.flags) {
|
|
707
|
+
newScope._contexts.flags = {
|
|
708
|
+
values: [...this._contexts.flags.values]
|
|
709
|
+
};
|
|
955
710
|
}
|
|
711
|
+
newScope._user = this._user;
|
|
712
|
+
newScope._level = this._level;
|
|
713
|
+
newScope._session = this._session;
|
|
714
|
+
newScope._transactionName = this._transactionName;
|
|
715
|
+
newScope._fingerprint = this._fingerprint;
|
|
716
|
+
newScope._eventProcessors = [...this._eventProcessors];
|
|
717
|
+
newScope._requestSession = this._requestSession;
|
|
718
|
+
newScope._attachments = [...this._attachments];
|
|
719
|
+
newScope._sdkProcessingMetadata = __spreadValues({}, this._sdkProcessingMetadata);
|
|
720
|
+
newScope._propagationContext = __spreadValues({}, this._propagationContext);
|
|
721
|
+
newScope._client = this._client;
|
|
722
|
+
newScope._lastEventId = this._lastEventId;
|
|
723
|
+
_setSpanForScope(newScope, _getSpanForScope(this));
|
|
956
724
|
return newScope;
|
|
957
725
|
}
|
|
958
726
|
/**
|
|
959
|
-
*
|
|
960
|
-
|
|
727
|
+
* @inheritDoc
|
|
728
|
+
*/
|
|
729
|
+
setClient(client2) {
|
|
730
|
+
this._client = client2;
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* @inheritDoc
|
|
734
|
+
*/
|
|
735
|
+
setLastEventId(lastEventId) {
|
|
736
|
+
this._lastEventId = lastEventId;
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* @inheritDoc
|
|
740
|
+
*/
|
|
741
|
+
getClient() {
|
|
742
|
+
return this._client;
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* @inheritDoc
|
|
746
|
+
*/
|
|
747
|
+
lastEventId() {
|
|
748
|
+
return this._lastEventId;
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* @inheritDoc
|
|
961
752
|
*/
|
|
962
753
|
addScopeListener(callback) {
|
|
963
754
|
this._scopeListeners.push(callback);
|
|
@@ -973,7 +764,12 @@ class Scope {
|
|
|
973
764
|
* @inheritDoc
|
|
974
765
|
*/
|
|
975
766
|
setUser(user) {
|
|
976
|
-
this._user = user || {
|
|
767
|
+
this._user = user || {
|
|
768
|
+
email: void 0,
|
|
769
|
+
id: void 0,
|
|
770
|
+
ip_address: void 0,
|
|
771
|
+
username: void 0
|
|
772
|
+
};
|
|
977
773
|
if (this._session) {
|
|
978
774
|
updateSession(this._session, { user });
|
|
979
775
|
}
|
|
@@ -989,12 +785,14 @@ class Scope {
|
|
|
989
785
|
/**
|
|
990
786
|
* @inheritDoc
|
|
991
787
|
*/
|
|
788
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
992
789
|
getRequestSession() {
|
|
993
790
|
return this._requestSession;
|
|
994
791
|
}
|
|
995
792
|
/**
|
|
996
793
|
* @inheritDoc
|
|
997
794
|
*/
|
|
795
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
998
796
|
setRequestSession(requestSession) {
|
|
999
797
|
this._requestSession = requestSession;
|
|
1000
798
|
return this;
|
|
@@ -1067,27 +865,6 @@ class Scope {
|
|
|
1067
865
|
this._notifyScopeListeners();
|
|
1068
866
|
return this;
|
|
1069
867
|
}
|
|
1070
|
-
/**
|
|
1071
|
-
* @inheritDoc
|
|
1072
|
-
*/
|
|
1073
|
-
setSpan(span) {
|
|
1074
|
-
this._span = span;
|
|
1075
|
-
this._notifyScopeListeners();
|
|
1076
|
-
return this;
|
|
1077
|
-
}
|
|
1078
|
-
/**
|
|
1079
|
-
* @inheritDoc
|
|
1080
|
-
*/
|
|
1081
|
-
getSpan() {
|
|
1082
|
-
return this._span;
|
|
1083
|
-
}
|
|
1084
|
-
/**
|
|
1085
|
-
* @inheritDoc
|
|
1086
|
-
*/
|
|
1087
|
-
getTransaction() {
|
|
1088
|
-
const span = this.getSpan();
|
|
1089
|
-
return span && span.transaction;
|
|
1090
|
-
}
|
|
1091
868
|
/**
|
|
1092
869
|
* @inheritDoc
|
|
1093
870
|
*/
|
|
@@ -1113,49 +890,29 @@ class Scope {
|
|
|
1113
890
|
if (!captureContext) {
|
|
1114
891
|
return this;
|
|
1115
892
|
}
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
893
|
+
const scopeToMerge = typeof captureContext === "function" ? captureContext(this) : captureContext;
|
|
894
|
+
const [scopeInstance, requestSession] = scopeToMerge instanceof Scope ? (
|
|
895
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
896
|
+
[scopeToMerge.getScopeData(), scopeToMerge.getRequestSession()]
|
|
897
|
+
) : isPlainObject(scopeToMerge) ? [captureContext, captureContext.requestSession] : [];
|
|
898
|
+
const { tags, extra, user, contexts, level, fingerprint = [], propagationContext } = scopeInstance || {};
|
|
899
|
+
this._tags = __spreadValues(__spreadValues({}, this._tags), tags);
|
|
900
|
+
this._extra = __spreadValues(__spreadValues({}, this._extra), extra);
|
|
901
|
+
this._contexts = __spreadValues(__spreadValues({}, this._contexts), contexts);
|
|
902
|
+
if (user && Object.keys(user).length) {
|
|
903
|
+
this._user = user;
|
|
1119
904
|
}
|
|
1120
|
-
if (
|
|
1121
|
-
this.
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
this._fingerprint = captureContext._fingerprint;
|
|
1132
|
-
}
|
|
1133
|
-
if (captureContext._requestSession) {
|
|
1134
|
-
this._requestSession = captureContext._requestSession;
|
|
1135
|
-
}
|
|
1136
|
-
if (captureContext._propagationContext) {
|
|
1137
|
-
this._propagationContext = captureContext._propagationContext;
|
|
1138
|
-
}
|
|
1139
|
-
} else if (isPlainObject(captureContext)) {
|
|
1140
|
-
captureContext = captureContext;
|
|
1141
|
-
this._tags = __spreadValues(__spreadValues({}, this._tags), captureContext.tags);
|
|
1142
|
-
this._extra = __spreadValues(__spreadValues({}, this._extra), captureContext.extra);
|
|
1143
|
-
this._contexts = __spreadValues(__spreadValues({}, this._contexts), captureContext.contexts);
|
|
1144
|
-
if (captureContext.user) {
|
|
1145
|
-
this._user = captureContext.user;
|
|
1146
|
-
}
|
|
1147
|
-
if (captureContext.level) {
|
|
1148
|
-
this._level = captureContext.level;
|
|
1149
|
-
}
|
|
1150
|
-
if (captureContext.fingerprint) {
|
|
1151
|
-
this._fingerprint = captureContext.fingerprint;
|
|
1152
|
-
}
|
|
1153
|
-
if (captureContext.requestSession) {
|
|
1154
|
-
this._requestSession = captureContext.requestSession;
|
|
1155
|
-
}
|
|
1156
|
-
if (captureContext.propagationContext) {
|
|
1157
|
-
this._propagationContext = captureContext.propagationContext;
|
|
1158
|
-
}
|
|
905
|
+
if (level) {
|
|
906
|
+
this._level = level;
|
|
907
|
+
}
|
|
908
|
+
if (fingerprint.length) {
|
|
909
|
+
this._fingerprint = fingerprint;
|
|
910
|
+
}
|
|
911
|
+
if (propagationContext) {
|
|
912
|
+
this._propagationContext = propagationContext;
|
|
913
|
+
}
|
|
914
|
+
if (requestSession) {
|
|
915
|
+
this._requestSession = requestSession;
|
|
1159
916
|
}
|
|
1160
917
|
return this;
|
|
1161
918
|
}
|
|
@@ -1172,11 +929,11 @@ class Scope {
|
|
|
1172
929
|
this._transactionName = void 0;
|
|
1173
930
|
this._fingerprint = void 0;
|
|
1174
931
|
this._requestSession = void 0;
|
|
1175
|
-
this._span = void 0;
|
|
1176
932
|
this._session = void 0;
|
|
1177
|
-
this
|
|
933
|
+
_setSpanForScope(this, void 0);
|
|
1178
934
|
this._attachments = [];
|
|
1179
|
-
this.
|
|
935
|
+
this.setPropagationContext({ traceId: generateTraceId() });
|
|
936
|
+
this._notifyScopeListeners();
|
|
1180
937
|
return this;
|
|
1181
938
|
}
|
|
1182
939
|
/**
|
|
@@ -1217,12 +974,6 @@ class Scope {
|
|
|
1217
974
|
this._attachments.push(attachment);
|
|
1218
975
|
return this;
|
|
1219
976
|
}
|
|
1220
|
-
/**
|
|
1221
|
-
* @inheritDoc
|
|
1222
|
-
*/
|
|
1223
|
-
getAttachments() {
|
|
1224
|
-
return this._attachments;
|
|
1225
|
-
}
|
|
1226
977
|
/**
|
|
1227
978
|
* @inheritDoc
|
|
1228
979
|
*/
|
|
@@ -1230,70 +981,39 @@ class Scope {
|
|
|
1230
981
|
this._attachments = [];
|
|
1231
982
|
return this;
|
|
1232
983
|
}
|
|
1233
|
-
/**
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
}
|
|
1250
|
-
if (this._contexts && Object.keys(this._contexts).length) {
|
|
1251
|
-
event.contexts = __spreadValues(__spreadValues({}, this._contexts), event.contexts);
|
|
1252
|
-
}
|
|
1253
|
-
if (this._level) {
|
|
1254
|
-
event.level = this._level;
|
|
1255
|
-
}
|
|
1256
|
-
if (this._transactionName) {
|
|
1257
|
-
event.transaction = this._transactionName;
|
|
1258
|
-
}
|
|
1259
|
-
if (this._span) {
|
|
1260
|
-
event.contexts = __spreadValues({ trace: this._span.getTraceContext() }, event.contexts);
|
|
1261
|
-
const transaction = this._span.transaction;
|
|
1262
|
-
if (transaction) {
|
|
1263
|
-
event.sdkProcessingMetadata = __spreadValues({
|
|
1264
|
-
dynamicSamplingContext: transaction.getDynamicSamplingContext()
|
|
1265
|
-
}, event.sdkProcessingMetadata);
|
|
1266
|
-
const transactionName = transaction.name;
|
|
1267
|
-
if (transactionName) {
|
|
1268
|
-
event.tags = __spreadValues({ transaction: transactionName }, event.tags);
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
}
|
|
1272
|
-
this._applyFingerprint(event);
|
|
1273
|
-
const scopeBreadcrumbs = this._getBreadcrumbs();
|
|
1274
|
-
const breadcrumbs = [...event.breadcrumbs || [], ...scopeBreadcrumbs];
|
|
1275
|
-
event.breadcrumbs = breadcrumbs.length > 0 ? breadcrumbs : void 0;
|
|
1276
|
-
event.sdkProcessingMetadata = __spreadProps(__spreadValues(__spreadValues({}, event.sdkProcessingMetadata), this._sdkProcessingMetadata), {
|
|
1277
|
-
propagationContext: this._propagationContext
|
|
1278
|
-
});
|
|
1279
|
-
return notifyEventProcessors(
|
|
1280
|
-
[...additionalEventProcessors || [], ...getGlobalEventProcessors(), ...this._eventProcessors],
|
|
1281
|
-
event,
|
|
1282
|
-
hint
|
|
1283
|
-
);
|
|
984
|
+
/** @inheritDoc */
|
|
985
|
+
getScopeData() {
|
|
986
|
+
return {
|
|
987
|
+
breadcrumbs: this._breadcrumbs,
|
|
988
|
+
attachments: this._attachments,
|
|
989
|
+
contexts: this._contexts,
|
|
990
|
+
tags: this._tags,
|
|
991
|
+
extra: this._extra,
|
|
992
|
+
user: this._user,
|
|
993
|
+
level: this._level,
|
|
994
|
+
fingerprint: this._fingerprint || [],
|
|
995
|
+
eventProcessors: this._eventProcessors,
|
|
996
|
+
propagationContext: this._propagationContext,
|
|
997
|
+
sdkProcessingMetadata: this._sdkProcessingMetadata,
|
|
998
|
+
transactionName: this._transactionName,
|
|
999
|
+
span: _getSpanForScope(this)
|
|
1000
|
+
};
|
|
1284
1001
|
}
|
|
1285
1002
|
/**
|
|
1286
|
-
*
|
|
1003
|
+
* @inheritDoc
|
|
1287
1004
|
*/
|
|
1288
1005
|
setSDKProcessingMetadata(newData) {
|
|
1289
|
-
this._sdkProcessingMetadata =
|
|
1006
|
+
this._sdkProcessingMetadata = merge(this._sdkProcessingMetadata, newData, 2);
|
|
1290
1007
|
return this;
|
|
1291
1008
|
}
|
|
1292
1009
|
/**
|
|
1293
1010
|
* @inheritDoc
|
|
1294
1011
|
*/
|
|
1295
1012
|
setPropagationContext(context) {
|
|
1296
|
-
this._propagationContext =
|
|
1013
|
+
this._propagationContext = __spreadValues({
|
|
1014
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
1015
|
+
spanId: generateSpanId()
|
|
1016
|
+
}, context);
|
|
1297
1017
|
return this;
|
|
1298
1018
|
}
|
|
1299
1019
|
/**
|
|
@@ -1302,167 +1022,49 @@ class Scope {
|
|
|
1302
1022
|
getPropagationContext() {
|
|
1303
1023
|
return this._propagationContext;
|
|
1304
1024
|
}
|
|
1305
|
-
/**
|
|
1306
|
-
* Get the breadcrumbs for this scope.
|
|
1307
|
-
*/
|
|
1308
|
-
_getBreadcrumbs() {
|
|
1309
|
-
return this._breadcrumbs;
|
|
1310
|
-
}
|
|
1311
|
-
/**
|
|
1312
|
-
* This will be called on every set call.
|
|
1313
|
-
*/
|
|
1314
|
-
_notifyScopeListeners() {
|
|
1315
|
-
if (!this._notifyingListeners) {
|
|
1316
|
-
this._notifyingListeners = true;
|
|
1317
|
-
this._scopeListeners.forEach((callback) => {
|
|
1318
|
-
callback(this);
|
|
1319
|
-
});
|
|
1320
|
-
this._notifyingListeners = false;
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
/**
|
|
1324
|
-
* Applies fingerprint from the scope to the event if there's one,
|
|
1325
|
-
* uses message if there's one instead or get rid of empty fingerprint
|
|
1326
|
-
*/
|
|
1327
|
-
_applyFingerprint(event) {
|
|
1328
|
-
event.fingerprint = event.fingerprint ? arrayify(event.fingerprint) : [];
|
|
1329
|
-
if (this._fingerprint) {
|
|
1330
|
-
event.fingerprint = event.fingerprint.concat(this._fingerprint);
|
|
1331
|
-
}
|
|
1332
|
-
if (event.fingerprint && !event.fingerprint.length) {
|
|
1333
|
-
delete event.fingerprint;
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
function generatePropagationContext() {
|
|
1338
|
-
return {
|
|
1339
|
-
traceId: uuid4(),
|
|
1340
|
-
spanId: uuid4().substring(16)
|
|
1341
|
-
};
|
|
1342
|
-
}
|
|
1343
|
-
const API_VERSION = 4;
|
|
1344
|
-
const DEFAULT_BREADCRUMBS = 100;
|
|
1345
|
-
class Hub {
|
|
1346
|
-
/** Is a {@link Layer}[] containing the client and scope */
|
|
1347
|
-
/** Contains the last event id of a captured event. */
|
|
1348
|
-
/**
|
|
1349
|
-
* Creates a new instance of the hub, will push one {@link Layer} into the
|
|
1350
|
-
* internal stack on creation.
|
|
1351
|
-
*
|
|
1352
|
-
* @param client bound to the hub.
|
|
1353
|
-
* @param scope bound to the hub.
|
|
1354
|
-
* @param version number, higher number means higher priority.
|
|
1355
|
-
*/
|
|
1356
|
-
constructor(client2, scope = new Scope(), _version = API_VERSION) {
|
|
1357
|
-
this._version = _version;
|
|
1358
|
-
this._stack = [{ scope }];
|
|
1359
|
-
if (client2) {
|
|
1360
|
-
this.bindClient(client2);
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
/**
|
|
1364
|
-
* @inheritDoc
|
|
1365
|
-
*/
|
|
1366
|
-
isOlderThan(version) {
|
|
1367
|
-
return this._version < version;
|
|
1368
|
-
}
|
|
1369
|
-
/**
|
|
1370
|
-
* @inheritDoc
|
|
1371
|
-
*/
|
|
1372
|
-
bindClient(client2) {
|
|
1373
|
-
const top = this.getStackTop();
|
|
1374
|
-
top.client = client2;
|
|
1375
|
-
if (client2 && client2.setupIntegrations) {
|
|
1376
|
-
client2.setupIntegrations();
|
|
1377
|
-
}
|
|
1378
|
-
}
|
|
1379
|
-
/**
|
|
1380
|
-
* @inheritDoc
|
|
1381
|
-
*/
|
|
1382
|
-
pushScope() {
|
|
1383
|
-
const scope = Scope.clone(this.getScope());
|
|
1384
|
-
this.getStack().push({
|
|
1385
|
-
client: this.getClient(),
|
|
1386
|
-
scope
|
|
1387
|
-
});
|
|
1388
|
-
return scope;
|
|
1389
|
-
}
|
|
1390
|
-
/**
|
|
1391
|
-
* @inheritDoc
|
|
1392
|
-
*/
|
|
1393
|
-
popScope() {
|
|
1394
|
-
if (this.getStack().length <= 1)
|
|
1395
|
-
return false;
|
|
1396
|
-
return !!this.getStack().pop();
|
|
1397
|
-
}
|
|
1398
|
-
/**
|
|
1399
|
-
* @inheritDoc
|
|
1400
|
-
*/
|
|
1401
|
-
withScope(callback) {
|
|
1402
|
-
const scope = this.pushScope();
|
|
1403
|
-
try {
|
|
1404
|
-
callback(scope);
|
|
1405
|
-
} finally {
|
|
1406
|
-
this.popScope();
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1409
|
-
/**
|
|
1410
|
-
* @inheritDoc
|
|
1411
|
-
*/
|
|
1412
|
-
getClient() {
|
|
1413
|
-
return this.getStackTop().client;
|
|
1414
|
-
}
|
|
1415
|
-
/** Returns the scope of the top stack. */
|
|
1416
|
-
getScope() {
|
|
1417
|
-
return this.getStackTop().scope;
|
|
1418
|
-
}
|
|
1419
|
-
/** Returns the scope stack for domains or the process. */
|
|
1420
|
-
getStack() {
|
|
1421
|
-
return this._stack;
|
|
1422
|
-
}
|
|
1423
|
-
/** Returns the topmost scope layer in the order domain > local > process. */
|
|
1424
|
-
getStackTop() {
|
|
1425
|
-
return this._stack[this._stack.length - 1];
|
|
1426
|
-
}
|
|
1427
1025
|
/**
|
|
1428
1026
|
* @inheritDoc
|
|
1429
1027
|
*/
|
|
1430
1028
|
captureException(exception, hint) {
|
|
1431
|
-
const eventId =
|
|
1029
|
+
const eventId = hint && hint.event_id ? hint.event_id : uuid4();
|
|
1030
|
+
if (!this._client) {
|
|
1031
|
+
logger.warn("No client configured on scope - will not capture exception!");
|
|
1032
|
+
return eventId;
|
|
1033
|
+
}
|
|
1432
1034
|
const syntheticException = new Error("Sentry syntheticException");
|
|
1433
|
-
this.
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
);
|
|
1444
|
-
});
|
|
1035
|
+
this._client.captureException(
|
|
1036
|
+
exception,
|
|
1037
|
+
__spreadProps(__spreadValues({
|
|
1038
|
+
originalException: exception,
|
|
1039
|
+
syntheticException
|
|
1040
|
+
}, hint), {
|
|
1041
|
+
event_id: eventId
|
|
1042
|
+
}),
|
|
1043
|
+
this
|
|
1044
|
+
);
|
|
1445
1045
|
return eventId;
|
|
1446
1046
|
}
|
|
1447
1047
|
/**
|
|
1448
1048
|
* @inheritDoc
|
|
1449
1049
|
*/
|
|
1450
1050
|
captureMessage(message, level, hint) {
|
|
1451
|
-
const eventId =
|
|
1051
|
+
const eventId = hint && hint.event_id ? hint.event_id : uuid4();
|
|
1052
|
+
if (!this._client) {
|
|
1053
|
+
logger.warn("No client configured on scope - will not capture message!");
|
|
1054
|
+
return eventId;
|
|
1055
|
+
}
|
|
1452
1056
|
const syntheticException = new Error(message);
|
|
1453
|
-
this.
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
);
|
|
1465
|
-
});
|
|
1057
|
+
this._client.captureMessage(
|
|
1058
|
+
message,
|
|
1059
|
+
level,
|
|
1060
|
+
__spreadProps(__spreadValues({
|
|
1061
|
+
originalException: message,
|
|
1062
|
+
syntheticException
|
|
1063
|
+
}, hint), {
|
|
1064
|
+
event_id: eventId
|
|
1065
|
+
}),
|
|
1066
|
+
this
|
|
1067
|
+
);
|
|
1466
1068
|
return eventId;
|
|
1467
1069
|
}
|
|
1468
1070
|
/**
|
|
@@ -1470,273 +1072,192 @@ class Hub {
|
|
|
1470
1072
|
*/
|
|
1471
1073
|
captureEvent(event, hint) {
|
|
1472
1074
|
const eventId = hint && hint.event_id ? hint.event_id : uuid4();
|
|
1473
|
-
if (!
|
|
1474
|
-
|
|
1075
|
+
if (!this._client) {
|
|
1076
|
+
logger.warn("No client configured on scope - will not capture event!");
|
|
1077
|
+
return eventId;
|
|
1475
1078
|
}
|
|
1476
|
-
this.
|
|
1477
|
-
client2.captureEvent(event, __spreadProps(__spreadValues({}, hint), { event_id: eventId }), scope);
|
|
1478
|
-
});
|
|
1079
|
+
this._client.captureEvent(event, __spreadProps(__spreadValues({}, hint), { event_id: eventId }), this);
|
|
1479
1080
|
return eventId;
|
|
1480
1081
|
}
|
|
1481
1082
|
/**
|
|
1482
|
-
*
|
|
1483
|
-
*/
|
|
1484
|
-
lastEventId() {
|
|
1485
|
-
return this._lastEventId;
|
|
1486
|
-
}
|
|
1487
|
-
/**
|
|
1488
|
-
* @inheritDoc
|
|
1083
|
+
* This will be called on every set call.
|
|
1489
1084
|
*/
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
const timestamp = dateTimestampInSeconds();
|
|
1498
|
-
const mergedBreadcrumb = __spreadValues({ timestamp }, breadcrumb);
|
|
1499
|
-
const finalBreadcrumb = beforeBreadcrumb ? consoleSandbox(() => beforeBreadcrumb(mergedBreadcrumb, hint)) : mergedBreadcrumb;
|
|
1500
|
-
if (finalBreadcrumb === null)
|
|
1501
|
-
return;
|
|
1502
|
-
if (client2.emit) {
|
|
1503
|
-
client2.emit("beforeAddBreadcrumb", finalBreadcrumb, hint);
|
|
1085
|
+
_notifyScopeListeners() {
|
|
1086
|
+
if (!this._notifyingListeners) {
|
|
1087
|
+
this._notifyingListeners = true;
|
|
1088
|
+
this._scopeListeners.forEach((callback) => {
|
|
1089
|
+
callback(this);
|
|
1090
|
+
});
|
|
1091
|
+
this._notifyingListeners = false;
|
|
1504
1092
|
}
|
|
1505
|
-
scope.addBreadcrumb(finalBreadcrumb, maxBreadcrumbs);
|
|
1506
|
-
}
|
|
1507
|
-
/**
|
|
1508
|
-
* @inheritDoc
|
|
1509
|
-
*/
|
|
1510
|
-
setUser(user) {
|
|
1511
|
-
this.getScope().setUser(user);
|
|
1512
1093
|
}
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
setTag(key, value) {
|
|
1529
|
-
this.getScope().setTag(key, value);
|
|
1530
|
-
}
|
|
1531
|
-
/**
|
|
1532
|
-
* @inheritDoc
|
|
1533
|
-
*/
|
|
1534
|
-
setExtra(key, extra) {
|
|
1535
|
-
this.getScope().setExtra(key, extra);
|
|
1536
|
-
}
|
|
1537
|
-
/**
|
|
1538
|
-
* @inheritDoc
|
|
1539
|
-
*/
|
|
1540
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1541
|
-
setContext(name, context) {
|
|
1542
|
-
this.getScope().setContext(name, context);
|
|
1543
|
-
}
|
|
1544
|
-
/**
|
|
1545
|
-
* @inheritDoc
|
|
1546
|
-
*/
|
|
1547
|
-
configureScope(callback) {
|
|
1548
|
-
const { scope, client: client2 } = this.getStackTop();
|
|
1549
|
-
if (client2) {
|
|
1550
|
-
callback(scope);
|
|
1094
|
+
}
|
|
1095
|
+
const Scope = ScopeClass;
|
|
1096
|
+
function getDefaultCurrentScope() {
|
|
1097
|
+
return getGlobalSingleton("defaultCurrentScope", () => new Scope());
|
|
1098
|
+
}
|
|
1099
|
+
function getDefaultIsolationScope() {
|
|
1100
|
+
return getGlobalSingleton("defaultIsolationScope", () => new Scope());
|
|
1101
|
+
}
|
|
1102
|
+
class AsyncContextStack {
|
|
1103
|
+
constructor(scope, isolationScope) {
|
|
1104
|
+
let assignedScope;
|
|
1105
|
+
if (!scope) {
|
|
1106
|
+
assignedScope = new Scope();
|
|
1107
|
+
} else {
|
|
1108
|
+
assignedScope = scope;
|
|
1551
1109
|
}
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
const oldHub = makeMain(this);
|
|
1558
|
-
try {
|
|
1559
|
-
callback(this);
|
|
1560
|
-
} finally {
|
|
1561
|
-
makeMain(oldHub);
|
|
1110
|
+
let assignedIsolationScope;
|
|
1111
|
+
if (!isolationScope) {
|
|
1112
|
+
assignedIsolationScope = new Scope();
|
|
1113
|
+
} else {
|
|
1114
|
+
assignedIsolationScope = isolationScope;
|
|
1562
1115
|
}
|
|
1116
|
+
this._stack = [{ scope: assignedScope }];
|
|
1117
|
+
this._isolationScope = assignedIsolationScope;
|
|
1563
1118
|
}
|
|
1564
1119
|
/**
|
|
1565
|
-
*
|
|
1120
|
+
* Fork a scope for the stack.
|
|
1566
1121
|
*/
|
|
1567
|
-
|
|
1568
|
-
const
|
|
1569
|
-
|
|
1570
|
-
return null;
|
|
1122
|
+
withScope(callback) {
|
|
1123
|
+
const scope = this._pushScope();
|
|
1124
|
+
let maybePromiseResult;
|
|
1571
1125
|
try {
|
|
1572
|
-
|
|
1573
|
-
} catch (
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
}
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
);
|
|
1589
|
-
} else {
|
|
1590
|
-
console.warn(`Tracing extension 'startTransaction' has not been added. Call 'addTracingExtensions' before calling 'init':
|
|
1591
|
-
Sentry.addTracingExtensions();
|
|
1592
|
-
Sentry.init({...});
|
|
1593
|
-
`);
|
|
1594
|
-
}
|
|
1595
|
-
}
|
|
1596
|
-
return result;
|
|
1597
|
-
}
|
|
1598
|
-
/**
|
|
1599
|
-
* @inheritDoc
|
|
1600
|
-
*/
|
|
1601
|
-
traceHeaders() {
|
|
1602
|
-
return this._callExtensionMethod("traceHeaders");
|
|
1603
|
-
}
|
|
1604
|
-
/**
|
|
1605
|
-
* @inheritDoc
|
|
1606
|
-
*/
|
|
1607
|
-
captureSession(endSession = false) {
|
|
1608
|
-
if (endSession) {
|
|
1609
|
-
return this.endSession();
|
|
1126
|
+
maybePromiseResult = callback(scope);
|
|
1127
|
+
} catch (e) {
|
|
1128
|
+
this._popScope();
|
|
1129
|
+
throw e;
|
|
1130
|
+
}
|
|
1131
|
+
if (isThenable(maybePromiseResult)) {
|
|
1132
|
+
return maybePromiseResult.then(
|
|
1133
|
+
(res) => {
|
|
1134
|
+
this._popScope();
|
|
1135
|
+
return res;
|
|
1136
|
+
},
|
|
1137
|
+
(e) => {
|
|
1138
|
+
this._popScope();
|
|
1139
|
+
throw e;
|
|
1140
|
+
}
|
|
1141
|
+
);
|
|
1610
1142
|
}
|
|
1611
|
-
this.
|
|
1143
|
+
this._popScope();
|
|
1144
|
+
return maybePromiseResult;
|
|
1612
1145
|
}
|
|
1613
1146
|
/**
|
|
1614
|
-
*
|
|
1147
|
+
* Get the client of the stack.
|
|
1615
1148
|
*/
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
const scope = layer.scope;
|
|
1619
|
-
const session = scope.getSession();
|
|
1620
|
-
if (session) {
|
|
1621
|
-
closeSession(session);
|
|
1622
|
-
}
|
|
1623
|
-
this._sendSessionUpdate();
|
|
1624
|
-
scope.setSession();
|
|
1149
|
+
getClient() {
|
|
1150
|
+
return this.getStackTop().client;
|
|
1625
1151
|
}
|
|
1626
1152
|
/**
|
|
1627
|
-
*
|
|
1153
|
+
* Returns the scope of the top stack.
|
|
1628
1154
|
*/
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
const { release, environment = DEFAULT_ENVIRONMENT } = client2 && client2.getOptions() || {};
|
|
1632
|
-
const { userAgent } = GLOBAL_OBJ.navigator || {};
|
|
1633
|
-
const session = makeSession(__spreadValues(__spreadValues({
|
|
1634
|
-
release,
|
|
1635
|
-
environment,
|
|
1636
|
-
user: scope.getUser()
|
|
1637
|
-
}, userAgent && { userAgent }), context));
|
|
1638
|
-
const currentSession = scope.getSession && scope.getSession();
|
|
1639
|
-
if (currentSession && currentSession.status === "ok") {
|
|
1640
|
-
updateSession(currentSession, { status: "exited" });
|
|
1641
|
-
}
|
|
1642
|
-
this.endSession();
|
|
1643
|
-
scope.setSession(session);
|
|
1644
|
-
return session;
|
|
1155
|
+
getScope() {
|
|
1156
|
+
return this.getStackTop().scope;
|
|
1645
1157
|
}
|
|
1646
1158
|
/**
|
|
1647
|
-
*
|
|
1648
|
-
* when Tracing is used.
|
|
1159
|
+
* Get the isolation scope for the stack.
|
|
1649
1160
|
*/
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
const options = client2 && client2.getOptions();
|
|
1653
|
-
return Boolean(options && options.sendDefaultPii);
|
|
1161
|
+
getIsolationScope() {
|
|
1162
|
+
return this._isolationScope;
|
|
1654
1163
|
}
|
|
1655
1164
|
/**
|
|
1656
|
-
*
|
|
1165
|
+
* Returns the topmost scope layer in the order domain > local > process.
|
|
1657
1166
|
*/
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
const session = scope.getSession();
|
|
1661
|
-
if (session && client2 && client2.captureSession) {
|
|
1662
|
-
client2.captureSession(session);
|
|
1663
|
-
}
|
|
1167
|
+
getStackTop() {
|
|
1168
|
+
return this._stack[this._stack.length - 1];
|
|
1664
1169
|
}
|
|
1665
1170
|
/**
|
|
1666
|
-
*
|
|
1667
|
-
*
|
|
1668
|
-
* @param method The method to call on the client.
|
|
1669
|
-
* @param args Arguments to pass to the client function.
|
|
1171
|
+
* Push a scope to the stack.
|
|
1670
1172
|
*/
|
|
1671
|
-
|
|
1672
|
-
const
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1173
|
+
_pushScope() {
|
|
1174
|
+
const scope = this.getScope().clone();
|
|
1175
|
+
this._stack.push({
|
|
1176
|
+
client: this.getClient(),
|
|
1177
|
+
scope
|
|
1178
|
+
});
|
|
1179
|
+
return scope;
|
|
1676
1180
|
}
|
|
1677
1181
|
/**
|
|
1678
|
-
*
|
|
1182
|
+
* Pop a scope from the stack.
|
|
1679
1183
|
*/
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
const carrier = getMainCarrier();
|
|
1684
|
-
const sentry = carrier.__SENTRY__;
|
|
1685
|
-
if (sentry && sentry.extensions && typeof sentry.extensions[method] === "function") {
|
|
1686
|
-
return sentry.extensions[method].apply(this, args);
|
|
1687
|
-
}
|
|
1688
|
-
(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && logger.warn(`Extension method ${method} couldn't be found, doing nothing.`);
|
|
1184
|
+
_popScope() {
|
|
1185
|
+
if (this._stack.length <= 1) return false;
|
|
1186
|
+
return !!this._stack.pop();
|
|
1689
1187
|
}
|
|
1690
1188
|
}
|
|
1691
|
-
function
|
|
1692
|
-
GLOBAL_OBJ.__SENTRY__ = GLOBAL_OBJ.__SENTRY__ || {
|
|
1693
|
-
extensions: {},
|
|
1694
|
-
hub: void 0
|
|
1695
|
-
};
|
|
1696
|
-
return GLOBAL_OBJ;
|
|
1697
|
-
}
|
|
1698
|
-
function makeMain(hub) {
|
|
1189
|
+
function getAsyncContextStack() {
|
|
1699
1190
|
const registry = getMainCarrier();
|
|
1700
|
-
const
|
|
1701
|
-
|
|
1702
|
-
return oldHub;
|
|
1191
|
+
const sentry = getSentryCarrier(registry);
|
|
1192
|
+
return sentry.stack = sentry.stack || new AsyncContextStack(getDefaultCurrentScope(), getDefaultIsolationScope());
|
|
1703
1193
|
}
|
|
1704
|
-
function
|
|
1705
|
-
|
|
1706
|
-
if (registry.__SENTRY__ && registry.__SENTRY__.acs) {
|
|
1707
|
-
const hub = registry.__SENTRY__.acs.getCurrentHub();
|
|
1708
|
-
if (hub) {
|
|
1709
|
-
return hub;
|
|
1710
|
-
}
|
|
1711
|
-
}
|
|
1712
|
-
return getGlobalHub(registry);
|
|
1194
|
+
function withScope(callback) {
|
|
1195
|
+
return getAsyncContextStack().withScope(callback);
|
|
1713
1196
|
}
|
|
1714
|
-
function
|
|
1715
|
-
|
|
1716
|
-
|
|
1197
|
+
function withSetScope(scope, callback) {
|
|
1198
|
+
const stack = getAsyncContextStack();
|
|
1199
|
+
return stack.withScope(() => {
|
|
1200
|
+
stack.getStackTop().scope = scope;
|
|
1201
|
+
return callback(scope);
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
function withIsolationScope(callback) {
|
|
1205
|
+
return getAsyncContextStack().withScope(() => {
|
|
1206
|
+
return callback(getAsyncContextStack().getIsolationScope());
|
|
1207
|
+
});
|
|
1208
|
+
}
|
|
1209
|
+
function getStackAsyncContextStrategy() {
|
|
1210
|
+
return {
|
|
1211
|
+
withIsolationScope,
|
|
1212
|
+
withScope,
|
|
1213
|
+
withSetScope,
|
|
1214
|
+
withSetIsolationScope: (_isolationScope, callback) => {
|
|
1215
|
+
return withIsolationScope(callback);
|
|
1216
|
+
},
|
|
1217
|
+
getCurrentScope: () => getAsyncContextStack().getScope(),
|
|
1218
|
+
getIsolationScope: () => getAsyncContextStack().getIsolationScope()
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
1221
|
+
function getAsyncContextStrategy(carrier) {
|
|
1222
|
+
const sentry = getSentryCarrier(carrier);
|
|
1223
|
+
if (sentry.acs) {
|
|
1224
|
+
return sentry.acs;
|
|
1717
1225
|
}
|
|
1718
|
-
return
|
|
1226
|
+
return getStackAsyncContextStrategy();
|
|
1719
1227
|
}
|
|
1720
|
-
function
|
|
1721
|
-
|
|
1228
|
+
function getCurrentScope() {
|
|
1229
|
+
const carrier = getMainCarrier();
|
|
1230
|
+
const acs = getAsyncContextStrategy(carrier);
|
|
1231
|
+
return acs.getCurrentScope();
|
|
1722
1232
|
}
|
|
1723
|
-
function
|
|
1724
|
-
|
|
1233
|
+
function getIsolationScope() {
|
|
1234
|
+
const carrier = getMainCarrier();
|
|
1235
|
+
const acs = getAsyncContextStrategy(carrier);
|
|
1236
|
+
return acs.getIsolationScope();
|
|
1725
1237
|
}
|
|
1726
|
-
function
|
|
1727
|
-
|
|
1728
|
-
return false;
|
|
1729
|
-
const __SENTRY__ = carrier.__SENTRY__ = carrier.__SENTRY__ || {};
|
|
1730
|
-
__SENTRY__.hub = hub;
|
|
1731
|
-
return true;
|
|
1238
|
+
function getClient$1() {
|
|
1239
|
+
return getCurrentScope().getClient();
|
|
1732
1240
|
}
|
|
1733
1241
|
function captureMessage(message, captureContext) {
|
|
1734
|
-
const level =
|
|
1735
|
-
const context =
|
|
1736
|
-
return
|
|
1242
|
+
const level = captureContext;
|
|
1243
|
+
const context = void 0;
|
|
1244
|
+
return getCurrentScope().captureMessage(message, level, context);
|
|
1737
1245
|
}
|
|
1738
|
-
|
|
1739
|
-
|
|
1246
|
+
const DEFAULT_BREADCRUMBS = 100;
|
|
1247
|
+
function addBreadcrumb(breadcrumb, hint) {
|
|
1248
|
+
const client2 = getClient$1();
|
|
1249
|
+
const isolationScope = getIsolationScope();
|
|
1250
|
+
if (!client2) return;
|
|
1251
|
+
const { beforeBreadcrumb = null, maxBreadcrumbs = DEFAULT_BREADCRUMBS } = client2.getOptions();
|
|
1252
|
+
if (maxBreadcrumbs <= 0) return;
|
|
1253
|
+
const timestamp = dateTimestampInSeconds();
|
|
1254
|
+
const mergedBreadcrumb = __spreadValues({ timestamp }, breadcrumb);
|
|
1255
|
+
const finalBreadcrumb = beforeBreadcrumb ? consoleSandbox(() => beforeBreadcrumb(mergedBreadcrumb, hint)) : mergedBreadcrumb;
|
|
1256
|
+
if (finalBreadcrumb === null) return;
|
|
1257
|
+
if (client2.emit) {
|
|
1258
|
+
client2.emit("beforeAddBreadcrumb", finalBreadcrumb, hint);
|
|
1259
|
+
}
|
|
1260
|
+
isolationScope.addBreadcrumb(finalBreadcrumb, maxBreadcrumbs);
|
|
1740
1261
|
}
|
|
1741
1262
|
const errorsToIgnore = [
|
|
1742
1263
|
MiniAppErrorType.sdkNotInitialized,
|
|
@@ -1759,11 +1280,30 @@ function addBreadcrumbToSentry(breadcrumb) {
|
|
|
1759
1280
|
addBreadcrumb(breadcrumb);
|
|
1760
1281
|
}
|
|
1761
1282
|
}
|
|
1283
|
+
function middlewareHandler(middlewares, message, messageHandler, params) {
|
|
1284
|
+
let index = -1;
|
|
1285
|
+
const next = (_params) => __async(this, null, function* () {
|
|
1286
|
+
++index;
|
|
1287
|
+
if (index < middlewares.length) {
|
|
1288
|
+
const nextMiddleware = middlewares[index];
|
|
1289
|
+
return yield nextMiddleware(message, _params, next);
|
|
1290
|
+
}
|
|
1291
|
+
return messageHandler(..._params);
|
|
1292
|
+
});
|
|
1293
|
+
return next(params);
|
|
1294
|
+
}
|
|
1295
|
+
const deepClone = (obj) => {
|
|
1296
|
+
if (typeof obj !== "object" || obj === null) {
|
|
1297
|
+
return obj;
|
|
1298
|
+
}
|
|
1299
|
+
return JSON.parse(JSON.stringify(obj));
|
|
1300
|
+
};
|
|
1762
1301
|
class WindowBridge {
|
|
1763
|
-
constructor(functions, allowedOrigins) {
|
|
1302
|
+
constructor(functions, allowedOrigins, middlewares = []) {
|
|
1764
1303
|
this.deferredCallbacks = {};
|
|
1765
1304
|
this.functions = functions;
|
|
1766
1305
|
this.allowedOrigins = allowedOrigins;
|
|
1306
|
+
this.middlewares = middlewares;
|
|
1767
1307
|
this.messageEventHandler = this.messageEventHandler.bind(this);
|
|
1768
1308
|
this.subscribeToMessageEvent();
|
|
1769
1309
|
}
|
|
@@ -1787,7 +1327,7 @@ class WindowBridge {
|
|
|
1787
1327
|
if (!((_a = receivedMessageEvent.data) == null ? void 0 : _a.forWindowBridge)) {
|
|
1788
1328
|
return;
|
|
1789
1329
|
}
|
|
1790
|
-
if (this.allowedOrigins && !this.allowedOrigins.includes(receivedMessageEvent.origin)) {
|
|
1330
|
+
if (this.allowedOrigins && receivedMessageEvent.data.type === "request" && !this.allowedOrigins.includes(receivedMessageEvent.origin)) {
|
|
1791
1331
|
return this.sendErrorResponse(
|
|
1792
1332
|
receivedMessageEvent,
|
|
1793
1333
|
`${receivedMessageEvent.origin} is not allowed to make requests`,
|
|
@@ -1806,6 +1346,7 @@ class WindowBridge {
|
|
|
1806
1346
|
}
|
|
1807
1347
|
handleRequest(receivedMessageEvent) {
|
|
1808
1348
|
return __async(this, null, function* () {
|
|
1349
|
+
var _a;
|
|
1809
1350
|
const functionName = receivedMessageEvent.data.functionName;
|
|
1810
1351
|
const functionToInvoke = this.functions[functionName];
|
|
1811
1352
|
if (!functionToInvoke) {
|
|
@@ -1818,14 +1359,21 @@ class WindowBridge {
|
|
|
1818
1359
|
try {
|
|
1819
1360
|
this.sendSuccessResponse(
|
|
1820
1361
|
receivedMessageEvent,
|
|
1821
|
-
yield
|
|
1362
|
+
yield middlewareHandler(
|
|
1363
|
+
[...this.middlewares, ...(_a = functionToInvoke.middlewares) != null ? _a : []],
|
|
1364
|
+
receivedMessageEvent,
|
|
1365
|
+
functionToInvoke,
|
|
1366
|
+
deepClone(receivedMessageEvent.data.params)
|
|
1367
|
+
)
|
|
1822
1368
|
);
|
|
1823
1369
|
} catch (error) {
|
|
1824
|
-
let message = "Some error
|
|
1370
|
+
let message = "Some error occurred while processing the request";
|
|
1825
1371
|
let errorCode = MiniAppErrorType.unknown;
|
|
1826
1372
|
if (error instanceof PPError) {
|
|
1827
1373
|
message = error.message;
|
|
1828
1374
|
errorCode = error.errorCode;
|
|
1375
|
+
} else {
|
|
1376
|
+
console.error(error);
|
|
1829
1377
|
}
|
|
1830
1378
|
this.sendErrorResponse(receivedMessageEvent, message, errorCode);
|
|
1831
1379
|
}
|
|
@@ -1877,7 +1425,7 @@ class WindowBridge {
|
|
|
1877
1425
|
type: "response",
|
|
1878
1426
|
key: receivedMessageEvent.data.key,
|
|
1879
1427
|
functionName: receivedMessageEvent.data.functionName
|
|
1880
|
-
}, data),
|
|
1428
|
+
}, deepClone(data)),
|
|
1881
1429
|
// Just a hack to overcome weird function overload mismatch
|
|
1882
1430
|
receivedMessageEvent.origin
|
|
1883
1431
|
);
|
|
@@ -1888,13 +1436,13 @@ class WindowBridge {
|
|
|
1888
1436
|
* @param allowedOrigins a list of allowed origins from where request can be accepted
|
|
1889
1437
|
* @returns `WindowBridge` instance
|
|
1890
1438
|
*/
|
|
1891
|
-
static init(functions, allowedOrigins) {
|
|
1439
|
+
static init(functions, allowedOrigins, middlewares = []) {
|
|
1892
1440
|
if (this._instance) {
|
|
1893
1441
|
throw new Error(
|
|
1894
1442
|
"WindowBridge already initialized, you can't call WindowBridge.init more than once"
|
|
1895
1443
|
);
|
|
1896
1444
|
}
|
|
1897
|
-
this._instance = new this(functions, allowedOrigins);
|
|
1445
|
+
this._instance = new this(functions, allowedOrigins, middlewares);
|
|
1898
1446
|
return this._instance;
|
|
1899
1447
|
}
|
|
1900
1448
|
/**
|
|
@@ -1958,7 +1506,7 @@ class WindowBridge {
|
|
|
1958
1506
|
type: "request",
|
|
1959
1507
|
functionName: functionNameString,
|
|
1960
1508
|
key,
|
|
1961
|
-
params:
|
|
1509
|
+
params: deepClone(params)
|
|
1962
1510
|
},
|
|
1963
1511
|
targetWindowOrigin
|
|
1964
1512
|
);
|
|
@@ -1977,17 +1525,22 @@ class WindowBridge {
|
|
|
1977
1525
|
});
|
|
1978
1526
|
}
|
|
1979
1527
|
}
|
|
1980
|
-
let clientId = "";
|
|
1981
|
-
function getCurrentClientId() {
|
|
1982
|
-
return clientId;
|
|
1983
|
-
}
|
|
1984
|
-
const KEY_INITIALIZED_AT = "ppjssdk.initializedAt";
|
|
1985
1528
|
class LocalStorageProxy {
|
|
1986
1529
|
constructor() {
|
|
1530
|
+
var _a;
|
|
1987
1531
|
this.useLocalStorage = true;
|
|
1988
1532
|
this.memoryStorage = {};
|
|
1989
1533
|
try {
|
|
1990
|
-
localStorage.setItem(
|
|
1534
|
+
localStorage.setItem(
|
|
1535
|
+
PpLocalStorageKey.initializedAt,
|
|
1536
|
+
Date.now().toString()
|
|
1537
|
+
);
|
|
1538
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
1539
|
+
const key = localStorage.key(i);
|
|
1540
|
+
if (key != null) {
|
|
1541
|
+
this.memoryStorage[key] = (_a = localStorage.getItem(key)) != null ? _a : "";
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1991
1544
|
} catch (e) {
|
|
1992
1545
|
this.useLocalStorage = false;
|
|
1993
1546
|
}
|
|
@@ -1996,7 +1549,7 @@ class LocalStorageProxy {
|
|
|
1996
1549
|
var _a;
|
|
1997
1550
|
if (this.useLocalStorage) {
|
|
1998
1551
|
try {
|
|
1999
|
-
if (localStorage.getItem(
|
|
1552
|
+
if (localStorage.getItem(PpLocalStorageKey.initializedAt) != null) {
|
|
2000
1553
|
return localStorage.getItem(key);
|
|
2001
1554
|
} else {
|
|
2002
1555
|
console.debug("local storage value has lost unexpectedly.");
|
|
@@ -2033,118 +1586,16 @@ class LocalStorageProxy {
|
|
|
2033
1586
|
clear() {
|
|
2034
1587
|
try {
|
|
2035
1588
|
localStorage.clear();
|
|
2036
|
-
localStorage.setItem(
|
|
1589
|
+
localStorage.setItem(
|
|
1590
|
+
PpLocalStorageKey.initializedAt,
|
|
1591
|
+
Date.now().toString()
|
|
1592
|
+
);
|
|
2037
1593
|
} catch (e) {
|
|
2038
1594
|
}
|
|
2039
1595
|
this.memoryStorage = {};
|
|
2040
1596
|
}
|
|
2041
1597
|
}
|
|
2042
|
-
|
|
2043
|
-
function getKeyWithClientId(baseKey, clientId2) {
|
|
2044
|
-
return `${baseKey}.${clientId2 != null ? clientId2 : getCurrentClientId()}`;
|
|
2045
|
-
}
|
|
2046
|
-
function saveLocalStorage(key, value) {
|
|
2047
|
-
removeLocalStorage$1(key);
|
|
2048
|
-
if (value) {
|
|
2049
|
-
return storage.setItem(key, value);
|
|
2050
|
-
}
|
|
2051
|
-
}
|
|
2052
|
-
function removeLocalStorage$1(key) {
|
|
2053
|
-
storage.removeItem(key);
|
|
2054
|
-
}
|
|
2055
|
-
function saveClientUUID(uuid) {
|
|
2056
|
-
saveLocalStorage(getKeyWithClientId(PpLocalStorageKey.clientUUID), uuid);
|
|
2057
|
-
}
|
|
2058
|
-
function getClientUUID() {
|
|
2059
|
-
let uuid = storage.getItem(getKeyWithClientId(PpLocalStorageKey.clientUUID)) || "";
|
|
2060
|
-
if (!validate(uuid)) {
|
|
2061
|
-
uuid = v4();
|
|
2062
|
-
saveClientUUID(uuid);
|
|
2063
|
-
}
|
|
2064
|
-
return uuid;
|
|
2065
|
-
}
|
|
2066
|
-
function getAppDetail(clientId2) {
|
|
2067
|
-
const val = storage.getItem(
|
|
2068
|
-
getKeyWithClientId(PpLocalStorageKey.appDetail, clientId2)
|
|
2069
|
-
);
|
|
2070
|
-
if (val == null) {
|
|
2071
|
-
return null;
|
|
2072
|
-
}
|
|
2073
|
-
return JSON.parse(val);
|
|
2074
|
-
}
|
|
2075
|
-
let timeoutId = null;
|
|
2076
|
-
let eventsQueue = [];
|
|
2077
|
-
function sendEvents() {
|
|
2078
|
-
var _a;
|
|
2079
|
-
const events = eventsQueue;
|
|
2080
|
-
eventsQueue = [];
|
|
2081
|
-
timeoutId = null;
|
|
2082
|
-
const url2 = `https://www.google-analytics.com/mp/collect?api_secret=${GA_API_SECRET}&measurement_id=${GA_MEASUREMENT_ID}`;
|
|
2083
|
-
const body = JSON.stringify({
|
|
2084
|
-
client_id: getClientUUID(),
|
|
2085
|
-
events,
|
|
2086
|
-
user_id: (_a = getAppDetail()) == null ? void 0 : _a.externalUserId
|
|
2087
|
-
});
|
|
2088
|
-
if (navigator.sendBeacon) {
|
|
2089
|
-
navigator.sendBeacon(url2, body);
|
|
2090
|
-
} else {
|
|
2091
|
-
void fetch(url2, {
|
|
2092
|
-
method: "POST",
|
|
2093
|
-
keepalive: true,
|
|
2094
|
-
body
|
|
2095
|
-
}).catch(console.warn);
|
|
2096
|
-
}
|
|
2097
|
-
}
|
|
2098
|
-
getRandomString();
|
|
2099
|
-
document.addEventListener("visibilitychange", () => {
|
|
2100
|
-
if (document.visibilityState === "hidden") {
|
|
2101
|
-
if (eventsQueue.length > 0) {
|
|
2102
|
-
if (timeoutId) {
|
|
2103
|
-
clearTimeout(timeoutId);
|
|
2104
|
-
}
|
|
2105
|
-
sendEvents();
|
|
2106
|
-
}
|
|
2107
|
-
}
|
|
2108
|
-
});
|
|
2109
|
-
({
|
|
2110
|
-
UNAUTHORIZED: MiniAppErrorType.notAuthorized,
|
|
2111
|
-
BAD_REQUEST: MiniAppErrorType.badRequest,
|
|
2112
|
-
MISSING_REQUEST_PARAMS: MiniAppErrorType.badRequestInsufficientParameter,
|
|
2113
|
-
OP_OUT_OF_SCOPE: MiniAppErrorType.insufficientScope,
|
|
2114
|
-
MINI_APP_SCOPE_NOT_FOUND: MiniAppErrorType.insufficientScope
|
|
2115
|
-
});
|
|
2116
|
-
function getAppVersion() {
|
|
2117
|
-
var _a, _b, _c, _d;
|
|
2118
|
-
let appVersion = null;
|
|
2119
|
-
const appVersionSplit = navigator.userAgent.split(" PayPayMiniApp/");
|
|
2120
|
-
if (appVersionSplit.length > 1) {
|
|
2121
|
-
const versionData = (_a = appVersionSplit[1].split(" ")[0]) != null ? _a : null;
|
|
2122
|
-
appVersion = versionData ? versionData.split("-")[0] : appVersion;
|
|
2123
|
-
appVersion = (_d = (_c = (_b = appVersion == null ? void 0 : appVersion.split(".")) == null ? void 0 : _b.slice(0, 3)) == null ? void 0 : _c.join(".")) != null ? _d : null;
|
|
2124
|
-
}
|
|
2125
|
-
return appVersion;
|
|
2126
|
-
}
|
|
2127
|
-
function semVerCompare(a, b) {
|
|
2128
|
-
const [majorA, minorA, patchA] = a.split(".").map((v) => Number.parseInt(v));
|
|
2129
|
-
const [majorB, minorB, patchB] = b.split(".").map((v) => Number.parseInt(v));
|
|
2130
|
-
if (majorA !== majorB) {
|
|
2131
|
-
return majorA > majorB;
|
|
2132
|
-
}
|
|
2133
|
-
if (minorA !== minorB) {
|
|
2134
|
-
return minorA > minorB;
|
|
2135
|
-
}
|
|
2136
|
-
return patchA > patchB;
|
|
2137
|
-
}
|
|
2138
|
-
function checkVersion(minVersion) {
|
|
2139
|
-
const appVersion = getAppVersion();
|
|
2140
|
-
if (!appVersion) {
|
|
2141
|
-
return false;
|
|
2142
|
-
}
|
|
2143
|
-
if (minVersion === appVersion) {
|
|
2144
|
-
return true;
|
|
2145
|
-
}
|
|
2146
|
-
return semVerCompare(appVersion, minVersion);
|
|
2147
|
-
}
|
|
1598
|
+
new LocalStorageProxy();
|
|
2148
1599
|
function getRandomString() {
|
|
2149
1600
|
return Math.random().toString(36).substring(7);
|
|
2150
1601
|
}
|
|
@@ -2157,14 +1608,14 @@ function getIconUrl(theme) {
|
|
|
2157
1608
|
function convertToString(str) {
|
|
2158
1609
|
return str ? String(str) : "";
|
|
2159
1610
|
}
|
|
2160
|
-
function getRefreshToken(
|
|
1611
|
+
function getRefreshToken(clientId) {
|
|
2161
1612
|
const refreshTokenWithClientId = api.get(
|
|
2162
|
-
`${PpLocalStorageKey.refreshToken}.${
|
|
1613
|
+
`${PpLocalStorageKey.refreshToken}.${clientId}`
|
|
2163
1614
|
);
|
|
2164
1615
|
return refreshTokenWithClientId || api.get(PpLocalStorageKey.refreshToken) || "";
|
|
2165
1616
|
}
|
|
2166
|
-
function getCodeVerifier(
|
|
2167
|
-
return api.get(`${PpLocalStorageKey.codeVerifier}.${
|
|
1617
|
+
function getCodeVerifier(clientId) {
|
|
1618
|
+
return api.get(`${PpLocalStorageKey.codeVerifier}.${clientId}`) || api.get(PpLocalStorageKey.codeVerifier) || "";
|
|
2168
1619
|
}
|
|
2169
1620
|
function exposeClientJsBridge(jsBridge) {
|
|
2170
1621
|
if (window.hasOwnProperty(jsBridgeNamespace) && window[jsBridgeNamespace] === jsBridge) {
|
|
@@ -2228,6 +1679,35 @@ function promiseToCallback(functionName, target, getCore2, getLoggingParams) {
|
|
|
2228
1679
|
});
|
|
2229
1680
|
};
|
|
2230
1681
|
}
|
|
1682
|
+
const INIT_STATUS_CODE_REMAP = {
|
|
1683
|
+
[MiniAppErrorType.sdkNotInitialized]: MiniAppErrorType.authorizationNeeded,
|
|
1684
|
+
[MiniAppErrorType.tokenNotFound]: MiniAppErrorType.authorizationNeeded,
|
|
1685
|
+
[MiniAppErrorType.tokenExpired]: MiniAppErrorType.tokenExpired
|
|
1686
|
+
};
|
|
1687
|
+
function callbackToPromise(target, functionName) {
|
|
1688
|
+
return (params = {}) => {
|
|
1689
|
+
return new Promise((resolve, reject) => {
|
|
1690
|
+
target(__spreadProps(__spreadValues({}, params), {
|
|
1691
|
+
success: (result) => {
|
|
1692
|
+
var _a;
|
|
1693
|
+
resolve(result);
|
|
1694
|
+
(_a = params.success) == null ? void 0 : _a.call(params, result);
|
|
1695
|
+
},
|
|
1696
|
+
fail: (error) => {
|
|
1697
|
+
var _a;
|
|
1698
|
+
if (functionName === "init" && INIT_STATUS_CODE_REMAP[error.errorCode]) {
|
|
1699
|
+
resolve({
|
|
1700
|
+
statusCode: INIT_STATUS_CODE_REMAP[error.errorCode]
|
|
1701
|
+
});
|
|
1702
|
+
} else {
|
|
1703
|
+
reject(error);
|
|
1704
|
+
}
|
|
1705
|
+
(_a = params.fail) == null ? void 0 : _a.call(params, error);
|
|
1706
|
+
}
|
|
1707
|
+
}));
|
|
1708
|
+
});
|
|
1709
|
+
};
|
|
1710
|
+
}
|
|
2231
1711
|
var MiniAppStatusType = /* @__PURE__ */ ((MiniAppStatusType2) => {
|
|
2232
1712
|
MiniAppStatusType2["validToken"] = "TOKEN_VALID";
|
|
2233
1713
|
MiniAppStatusType2["initialized"] = "INITIALIZED";
|
|
@@ -2238,16 +1718,6 @@ var MiniAppStatusType = /* @__PURE__ */ ((MiniAppStatusType2) => {
|
|
|
2238
1718
|
MiniAppStatusType2["connected"] = "CONNECTED";
|
|
2239
1719
|
return MiniAppStatusType2;
|
|
2240
1720
|
})(MiniAppStatusType || {});
|
|
2241
|
-
const style = "";
|
|
2242
|
-
const MinVersion = {
|
|
2243
|
-
PRE_TRANSACTION_AUTO_CHARGE: "3.43.0",
|
|
2244
|
-
FALLBACK_PAYMENT_METHOD: "3.61.0",
|
|
2245
|
-
OS_HOME_SCREEN_ICON: "3.71.0",
|
|
2246
|
-
START_MULTIFACTOR_AUTH_ANDROID_FIX: "3.67.0",
|
|
2247
|
-
KYC_PASSPORT: "3.72.0",
|
|
2248
|
-
PERFORMANCE_MEASUREMENT: "4.47.0",
|
|
2249
|
-
START_MULTIFACTOR_AUTH_PIN_FALLBACK: "4.63.0"
|
|
2250
|
-
};
|
|
2251
1721
|
function setCookie({ name, value, options }) {
|
|
2252
1722
|
return api.set(name, value, options);
|
|
2253
1723
|
}
|
|
@@ -2419,7 +1889,7 @@ addEventListener("popstate", () => {
|
|
|
2419
1889
|
function init(params) {
|
|
2420
1890
|
const refreshToken = getRefreshToken(params.clientId);
|
|
2421
1891
|
const codeVerifier = getCodeVerifier(params.clientId);
|
|
2422
|
-
const clientVersion = "2.
|
|
1892
|
+
const clientVersion = "2.46.0";
|
|
2423
1893
|
useAllFunctions = !!params.useAllFunctions;
|
|
2424
1894
|
const initParams = {
|
|
2425
1895
|
env: params.env,
|
|
@@ -2497,21 +1967,22 @@ function setTitle(params) {
|
|
|
2497
1967
|
(_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
|
|
2498
1968
|
}
|
|
2499
1969
|
function render(params) {
|
|
2500
|
-
var _a;
|
|
2501
|
-
if (!
|
|
2502
|
-
(_a = params
|
|
1970
|
+
var _a, _b;
|
|
1971
|
+
if (!params.containerId || !document.getElementById(params.containerId)) {
|
|
1972
|
+
(_a = params.fail) == null ? void 0 : _a.call(params, {
|
|
2503
1973
|
errorCode: MiniAppErrorType.badRequestInsufficientParameter
|
|
2504
1974
|
});
|
|
1975
|
+
(_b = params.complete) == null ? void 0 : _b.call(params);
|
|
2505
1976
|
return console.error("Invalid container Id");
|
|
2506
1977
|
}
|
|
2507
1978
|
const messageId = functionStart();
|
|
2508
1979
|
const getRenderMessageHandler = (e) => {
|
|
2509
|
-
var _a2,
|
|
1980
|
+
var _a2, _b2, _c;
|
|
2510
1981
|
if (!checkIFrameOrigin(e.origin) || e.data.name !== PPFunctionName.render || e.data.messageId !== messageId) {
|
|
2511
1982
|
return;
|
|
2512
1983
|
}
|
|
2513
1984
|
const info = (_a2 = e.data) == null ? void 0 : _a2.data;
|
|
2514
|
-
const data = (
|
|
1985
|
+
const data = (_b2 = e.data) == null ? void 0 : _b2.data;
|
|
2515
1986
|
if (e.data.result === PPFunctionResult.success) {
|
|
2516
1987
|
renderButton(data, params);
|
|
2517
1988
|
if (info.type === "pay" && (data == null ? void 0 : data.isJustLoggedIn) && params.autoInvoke && (data == null ? void 0 : data.isLoggedIn)) {
|
|
@@ -2565,7 +2036,7 @@ const renderCoupons = promiseToCallback(
|
|
|
2565
2036
|
iframeElement.style.cssText = "width:100%;height: 0;border: none;transition: height 300ms ease-in;display: block;";
|
|
2566
2037
|
yield new Promise((resolve, reject) => {
|
|
2567
2038
|
iframeElement.onload = () => resolve(true);
|
|
2568
|
-
iframeElement.onerror = () => reject(
|
|
2039
|
+
iframeElement.onerror = () => reject(new Error("Failed to load coupon iframe"));
|
|
2569
2040
|
containerElement.innerHTML = "";
|
|
2570
2041
|
containerElement.append(iframeElement);
|
|
2571
2042
|
});
|
|
@@ -2686,7 +2157,11 @@ function copyToClipboard(params) {
|
|
|
2686
2157
|
textarea.setSelectionRange(0, textarea.value.length);
|
|
2687
2158
|
const result = document.execCommand("copy");
|
|
2688
2159
|
document.body.removeChild(textarea);
|
|
2689
|
-
|
|
2160
|
+
if (result) {
|
|
2161
|
+
(_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params);
|
|
2162
|
+
} else {
|
|
2163
|
+
(_b = params == null ? void 0 : params.fail) == null ? void 0 : _b.call(params, { errorCode: MiniAppErrorType.other });
|
|
2164
|
+
}
|
|
2690
2165
|
(_c = params.complete) == null ? void 0 : _c.call(params);
|
|
2691
2166
|
}
|
|
2692
2167
|
function receiveMessageFromIframe(messageData, params, eventHandler) {
|
|
@@ -2805,9 +2280,6 @@ function renderButton(data, params) {
|
|
|
2805
2280
|
const markAsReady = promiseToCallback(
|
|
2806
2281
|
"markAsReady",
|
|
2807
2282
|
() => __async(void 0, null, function* () {
|
|
2808
|
-
if (checkVersion(MinVersion.PERFORMANCE_MEASUREMENT)) {
|
|
2809
|
-
window.location.href = "paypay://miniappPerformance/ready";
|
|
2810
|
-
}
|
|
2811
2283
|
yield core.markAsReady();
|
|
2812
2284
|
}),
|
|
2813
2285
|
getCore
|
|
@@ -2870,14 +2342,20 @@ function executePendingFunctionCalls(client2) {
|
|
|
2870
2342
|
return;
|
|
2871
2343
|
}
|
|
2872
2344
|
window._ppcs = void 0;
|
|
2873
|
-
for (const [functionName, params] of pendingFunctionCalls) {
|
|
2874
|
-
client2[functionName](params);
|
|
2345
|
+
for (const [functionName, params, resolve] of pendingFunctionCalls) {
|
|
2346
|
+
const resultPromise = client2[functionName](params);
|
|
2347
|
+
if (resolve) {
|
|
2348
|
+
resolve(resultPromise);
|
|
2349
|
+
}
|
|
2875
2350
|
}
|
|
2876
2351
|
}
|
|
2877
2352
|
const clientProperties = {
|
|
2878
|
-
version: "2.
|
|
2879
|
-
revision: "
|
|
2353
|
+
version: "2.46.0",
|
|
2354
|
+
revision: "bd28c67"
|
|
2880
2355
|
};
|
|
2356
|
+
function isInitClientParams(params) {
|
|
2357
|
+
return params.clientId !== void 0;
|
|
2358
|
+
}
|
|
2881
2359
|
function getClient({ sdkType }) {
|
|
2882
2360
|
clientSdkType = sdkType;
|
|
2883
2361
|
const isSupportedFunction = sdkType === SdkType.MiniApp ? isSupportedMiniapp : isSupportedSmartpayment;
|
|
@@ -2894,28 +2372,36 @@ function getClient({ sdkType }) {
|
|
|
2894
2372
|
);
|
|
2895
2373
|
}
|
|
2896
2374
|
}
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
if (
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2375
|
+
function callSdkFunction(params) {
|
|
2376
|
+
return __async(this, null, function* () {
|
|
2377
|
+
var _a, _b;
|
|
2378
|
+
if (!initExemptedFunctions.includes(functionName) && !(yield initDonePromise)) {
|
|
2379
|
+
if (autoInitFunctions.includes(functionName) && isInitClientParams(params)) {
|
|
2380
|
+
init({
|
|
2381
|
+
clientId: params.clientId,
|
|
2382
|
+
env: params.env
|
|
2383
|
+
});
|
|
2384
|
+
yield initDonePromise;
|
|
2385
|
+
} else {
|
|
2386
|
+
(_a = params.fail) == null ? void 0 : _a.call(params, {
|
|
2387
|
+
errorCode: MiniAppErrorType.sdkNotInitialized
|
|
2388
|
+
});
|
|
2389
|
+
(_b = params.complete) == null ? void 0 : _b.call(params);
|
|
2390
|
+
return;
|
|
2391
|
+
}
|
|
2907
2392
|
}
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
);
|
|
2918
|
-
}
|
|
2393
|
+
if (Object.prototype.hasOwnProperty.call(target, functionName)) {
|
|
2394
|
+
return target[functionName](params);
|
|
2395
|
+
}
|
|
2396
|
+
triggerPostMessageToCore(
|
|
2397
|
+
prop,
|
|
2398
|
+
false,
|
|
2399
|
+
params,
|
|
2400
|
+
params
|
|
2401
|
+
);
|
|
2402
|
+
});
|
|
2403
|
+
}
|
|
2404
|
+
return callbackToPromise(callSdkFunction, functionName);
|
|
2919
2405
|
}
|
|
2920
2406
|
});
|
|
2921
2407
|
const client2 = proxy;
|