大侠
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

3691 lines
112 KiB

/**
* @dn-sdk/minigame v1.5.6
* (c) 2025
* @license ISC
*/
function t(t, e, n) {
return (
(e = v(e)) in t
? Object.defineProperty(t, e, {
value: n,
enumerable: !0,
configurable: !0,
writable: !0,
})
: (t[e] = n),
t
);
}
function e(t) {
return (
(function (t) {
if (Array.isArray(t)) return r(t);
})(t) ||
(function (t) {
if (
("undefined" != typeof Symbol && null != t[Symbol.iterator]) ||
null != t["@@iterator"]
)
return Array.from(t);
})(t) ||
n(t) ||
(function () {
throw new TypeError(
"Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.",
);
})()
);
}
function n(t, e) {
if (t) {
if ("string" == typeof t) return r(t, e);
var n = Object.prototype.toString.call(t).slice(8, -1);
return (
"Object" === n && t.constructor && (n = t.constructor.name),
"Map" === n || "Set" === n
? Array.from(t)
: "Arguments" === n ||
/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)
? r(t, e)
: void 0
);
}
}
function r(t, e) {
(null == e || e > t.length) && (e = t.length);
for (var n = 0, r = new Array(e); n < e; n++) r[n] = t[n];
return r;
}
function o(t, e) {
if ("function" != typeof e && null !== e)
throw new TypeError("Super expression must either be null or a function");
((t.prototype = Object.create(e && e.prototype, {
constructor: { value: t, writable: !0, configurable: !0 },
})),
Object.defineProperty(t, "prototype", { writable: !1 }),
e && i(t, e));
}
function i(t, e) {
return (
(i = Object.setPrototypeOf
? Object.setPrototypeOf.bind()
: function (t, e) {
return ((t.__proto__ = e), t);
}),
i(t, e)
);
}
function a(t) {
var e = (function () {
if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
if (Reflect.construct.sham) return !1;
if ("function" == typeof Proxy) return !0;
try {
return (
Boolean.prototype.valueOf.call(
Reflect.construct(Boolean, [], function () {}),
),
!0
);
} catch (t) {
return !1;
}
})();
return function () {
var n,
r = s(t);
if (e) {
var o = s(this).constructor;
n = Reflect.construct(r, arguments, o);
} else n = r.apply(this, arguments);
return u(this, n);
};
}
function u(t, e) {
if (e && ("object" === l(e) || "function" == typeof e)) return e;
if (void 0 !== e)
throw new TypeError(
"Derived constructors may only return object or undefined",
);
return c(t);
}
function c(t) {
if (void 0 === t)
throw new ReferenceError(
"this hasn't been initialised - super() hasn't been called",
);
return t;
}
function s(t) {
return (
(s = Object.setPrototypeOf
? Object.getPrototypeOf.bind()
: function (t) {
return t.__proto__ || Object.getPrototypeOf(t);
}),
s(t)
);
}
function l(t) {
return (
(l =
"function" == typeof Symbol && "symbol" == typeof Symbol.iterator
? function (t) {
return typeof t;
}
: function (t) {
return t &&
"function" == typeof Symbol &&
t.constructor === Symbol &&
t !== Symbol.prototype
? "symbol"
: typeof t;
}),
l(t)
);
}
function f(t, e) {
if (!(t instanceof e))
throw new TypeError("Cannot call a class as a function");
}
function d(t, e) {
for (var n = 0; n < e.length; n++) {
var r = e[n];
((r.enumerable = r.enumerable || !1),
(r.configurable = !0),
"value" in r && (r.writable = !0),
Object.defineProperty(t, v(r.key), r));
}
}
function p(t, e, n) {
return (
e && d(t.prototype, e),
n && d(t, n),
Object.defineProperty(t, "prototype", { writable: !1 }),
t
);
}
function v(t) {
var e = (function (t, e) {
if ("object" !== l(t) || null === t) return t;
var n = t[Symbol.toPrimitive];
if (void 0 !== n) {
var r = n.call(t, e || "default");
if ("object" !== l(r)) return r;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === e ? String : Number)(t);
})(t, "string");
return "symbol" === l(e) ? e : String(e);
}
var h,
_,
y = "LOCAL_ID",
g = "QUEUE_ACTIONS",
m = "CLICK_ID",
A = "QUEUE_LOST_MAP",
R = "REMOTE_CONFIG",
k = "REMOTE_COMMON_CONFIG",
T = "OPENID",
E = { init: "init", reporting: "reporting", fail: "fail" },
S = {
maxSdkInstance: 4,
maxQueueLength: 500,
actionParamMaxLength: 1e4,
autoTrack: !0,
reportThreshold: 5,
reportDelay: 1,
inspectDelay: 30,
cgiBatchSize: 50,
requestConcurrency: 4,
requestTimeout: 1e4,
signVersion: "1.0",
realTimeActionList: ["START_APP", "REGISTER", "PURCHASE"],
},
b = {
JS_RUN_ERROR: "JS_RUN_ERROR",
REQUEST_ERROR: "REQUEST_ERROR",
REQUEST_CONFIG_ERROR: "REQUEST_CONFIG_ERROR",
JS_QUEUE_LOG: "JS_QUEUE_LOG",
PROXY_ERROR: "PROXY_ERROR",
PROXY_POLYFILL: "PROXY_POLYFILL",
QUEUE_LOST_NUM: "QUEUE_LOST_NUM",
REQ_TOTAL: "REQ_TOTAL",
SIGN_ERROR: "SIGN_ERROR",
},
O = "ANDROID",
I = "IOS",
w = "WINDOWS",
C = "OSX",
x = "UNKNOWN",
N = 1e3,
L = 100,
P = 10,
M = "START_APP",
D = "ENTER_FOREGROUND",
U = "ENTER_BACKGROUND",
q = "ADD_TO_WISHLIST",
F = "PURCHASE",
j = "APP_QUIT",
B = "REGISTER",
V = "CREATE_ROLE",
G = "TUTORIAL_FINISH",
K = "TRUE",
Q = "FALSE",
Y = "TENCENT",
W = "BYTEDANCE",
J = "KUAISHOU",
H = "ALIBABA",
z = "BAIDU",
$ = "OTHERS",
X = "UNKNOWN",
Z = "TICKET_INTERVAL_CHANGE",
tt =
((_ = function (t) {
return ""
.concat("@dn-sdk/minigame", "_")
.concat("production", "_")
.concat(t);
}),
{
getSync: function (t) {
var e;
try {
e = wx.getStorageSync(_(t));
} catch (t) {
return (console.error("storage get error", t), e);
}
return e;
},
setSync: function (t, e) {
try {
wx.setStorageSync(_(t), e);
} catch (t) {
return (console.error("storage set error", t), !1);
}
return !0;
},
}),
et = function () {
if (h) return h;
try {
return (h = wx.getSystemInfoSync());
} catch (t) {
return {};
}
},
nt = (function () {
var t;
return function () {
if (!t) {
var e = et(),
n = e.system,
r = void 0 === n ? "" : n,
o = (null == r ? void 0 : r.split(" ")) || [],
i = (function (t) {
if (!t) return x;
var e = (null == t ? void 0 : t.toUpperCase()) || "";
return e.indexOf("ANDROID") > -1
? O
: e.indexOf("IOS") > -1
? I
: e.indexOf("MAC") > -1
? C
: e.indexOf("WINDOWS") > -1
? w
: x;
})(o[0]),
a = (function (t) {
return !t || t.length <= 0
? ""
: 2 === t.length
? t[1]
: 3 === t.length && "Windows" === t[0]
? "".concat(t[1], " ").concat(t[2])
: t[t.length - 1];
})(o);
t = {
benchmark_level: e.benchmarkLevel,
device_brand: e.brand,
screen_height: Math.floor(e.screenHeight),
screen_width: Math.floor(e.screenWidth),
wx_lib_version: e.SDKVersion,
wx_version: e.version,
wx_platform: e.platform,
device_model: e.model,
os: i,
os_version: a,
};
}
return t;
};
})(),
rt = (function () {
var t;
return function () {
try {
if (t) return t;
(t || (t = tt.getSync(y) || ""), t || ((t = mt()), tt.setSync(y, t)));
} catch (t) {}
return t;
};
})();
var ot = (function () {
var t = "unknown",
e = !1;
return function () {
if (!e)
try {
(wx.getNetworkType({
success: function (e) {
t = e.networkType;
},
fail: function () {
t = "unknown";
},
}),
wx.onNetworkStatusChange(function (e) {
t = e.networkType;
}),
(e = !0));
} catch (t) {}
return t;
};
})();
ot();
var it = (function () {
var t = "";
return function () {
return (t || (t = tt.getSync(T) || ""), t);
};
})(),
at = (function () {
var t;
return function () {
if (t) return t;
try {
var e = wx.getAccountInfoSync();
return ht(e.miniProgram) ? (t = e.miniProgram) : {};
} catch (e) {
return {};
}
};
})();
function ut(t) {
var e = null == t ? void 0 : t.query;
if (!ht(e)) return "";
var n = "";
return (
e.gdt_vid || [1045, 1046, 1084].indexOf(null == t ? void 0 : t.scene) > -1
? (n = Y)
: e.clue_token || (e.clickid && e.item_id)
? (n = W)
: e.callback && "kuaishou" === e.ksChannel
? (n = J)
: e.bd_vid || (e.ai && e.d && e.q && e.c)
? (n = z)
: e.uctrackid
? (n = H)
: (e.trackid ||
e.imp ||
([1065, 1069, 1194].indexOf(null == t ? void 0 : t.scene) >
-1 &&
(e.callback || e.u))) &&
(n = $),
n
);
}
function ct(t, e) {
try {
var n = nt(),
r = at(),
o = {
sdk_version: "1.5.6",
sdk_name: "@dn-sdk/minigame",
device_brand: null == n ? void 0 : n.device_brand,
device_model: null == n ? void 0 : n.device_model,
wx_version: null == n ? void 0 : n.wx_version,
wx_lib_version: null == n ? void 0 : n.wx_lib_version,
wx_platform: null == n ? void 0 : n.wx_platform,
os: null == n ? void 0 : n.os,
os_version: null == n ? void 0 : n.os_version,
local_id: rt(),
env_version: null == r ? void 0 : r.envVersion,
appid: null == r ? void 0 : r.appId,
},
i = Object.assign(o, t);
wx.request({
url: "https://api.datanexus.qq.com/data-nexus-trace/log",
data: i,
method: "POST",
timeout: S.requestTimeout,
success: function (t) {
"function" == typeof e &&
200 === (null == t ? void 0 : t.statusCode) &&
e();
},
});
} catch (n) {
xt.error(n);
}
}
var st = (function () {
function t() {
f(this, t);
}
return (
p(t, null, [
{
key: "revise",
value: function (t) {
t > 0 &&
!this.isRevised &&
((this.offsetTime = t - Date.now()), (this.isRevised = !0));
},
},
{
key: "getRevisedcurrentTimeMillis",
value: function () {
return this.isRevised ? Date.now() + this.offsetTime : -1;
},
},
]),
t
);
})();
function lt(t) {
return new Promise(function (e, n) {
wx.request({
method: "POST",
url: "https://api.datanexus.qq.com/data-nexus-config/v1/sdk/config/get",
data: t,
timeout: S.requestTimeout,
success: function (t) {
(ft(t, e, "config/get", n), pt(t));
},
fail: function (t) {
dt(t, "config/get", n);
},
});
});
}
function ft(t, e, n, r) {
var o,
i,
a,
u,
c = null == t ? void 0 : t.statusCode,
s = null == (o = null == t ? void 0 : t.data) ? void 0 : o.code;
if (200 !== c || 0 !== s) {
var l = s;
(200 !== c && (l = "number" == typeof c ? -1 * c : -888),
ct({
log_type: b.REQUEST_CONFIG_ERROR,
message: "cgiName: "
.concat(n, ", statusCode: ")
.concat(c, ", code: ")
.concat(s, ", traceid: ")
.concat(
null == (a = null == t ? void 0 : t.data) ? void 0 : a.trace_id,
),
code: l,
}),
null == r ||
r(null == (u = null == t ? void 0 : t.data) ? void 0 : u.data));
} else e(null == (i = t.data) ? void 0 : i.data);
}
function dt(t, e, n) {
(ct({
log_type: b.REQUEST_CONFIG_ERROR,
message: "cgiName: "
.concat(e, " , message: ")
.concat(null == t ? void 0 : t.errMsg, " "),
code:
"number" == typeof (null == t ? void 0 : t.errno) ? -1 * t.errno : -999,
}),
null == n || n(t));
}
function pt(t) {
var e,
n =
1 *
(null == (e = null == t ? void 0 : t.header) ? void 0 : e["Server-Time"]);
n > 17266752e5 && st.revise(n);
}
((st.offsetTime = 0), (st.isRevised = !1));
var vt = Object.prototype.toString,
ht = function (t) {
return "[object Object]" === vt.call(t);
},
_t = function (t) {
return "[object Array]" === vt.call(t);
},
yt = function (t) {
return "[object Function]" === vt.call(t);
},
gt = new Date().getTime();
function mt() {
var t = new Date().getTime(),
e = Math.abs(1e3 * (t - gt));
return "xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g, function (n) {
var r = 16 * Math.random();
return (
t > 0
? ((r = ((t + r) % 16) | 0), (t = Math.floor(t / 16)))
: ((r = ((e + r) % 16) | 0), (e = Math.floor(e / 16))),
("x" === n ? r : (3 & r) | 8).toString(16).replace(/-/g, "")
);
});
}
var At =
/^v?(?:\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+))?(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i,
Rt = function (t) {
if ("string" != typeof t)
throw new TypeError("Invalid argument expected string");
if (!At.test(t))
throw new Error(
"Invalid argument not valid semver ('".concat(t, "' received)"),
);
},
kt = function (t) {
return isNaN(Number(t)) ? t : Number(t);
},
Tt = function (t) {
var e = t.replace(/^v/, "").replace(/\+.*$/, ""),
n = (function (t, e) {
return -1 === t.indexOf(e) ? t.length : t.indexOf(e);
})(e, "-"),
r = e.substring(0, n).split(".");
return (r.push(e.substring(n + 1)), r);
},
Et = function (t, e) {
[t, e].forEach(Rt);
for (
var n = Tt(t), r = Tt(e), o = 0;
o < Math.max(n.length - 1, r.length - 1);
o++
) {
var i = parseInt(n[o] || "0", 10),
a = parseInt(r[o] || "0", 10);
if (i > a) return 1;
if (a > i) return -1;
}
var u = n[n.length - 1],
c = r[r.length - 1];
if (u && c)
for (
var s = u.split(".").map(kt), l = c.split(".").map(kt), f = 0;
f < Math.max(s.length, l.length);
f++
) {
if (
void 0 === s[f] ||
("string" == typeof l[f] && "number" == typeof s[f])
)
return -1;
if (
void 0 === l[f] ||
("string" == typeof s[f] && "number" == typeof l[f]) ||
s[f] > l[f]
)
return 1;
if (l[f] > s[f]) return -1;
}
else if (u || c) return u ? -1 : 1;
return 0;
},
St = function (t) {
return ht(t)
? ((function (t) {
var e = [
"user_action_set_id",
"secret_key",
"appid",
"openid",
"unionid",
"user_unique_id",
"auto_track",
"auto_attr",
"on_report_fail",
"on_report_complete",
];
for (var n in t)
e.includes(n) ||
xt.warn("Invalid property '".concat(n, "' found in config"));
})(t),
"number" != typeof t.user_action_set_id
? "user_action_set_id 参数需为 number 类型"
: t.user_action_set_id <= 0
? "user_action_set_id 参数需大于 0"
: "string" != typeof t.secret_key
? "secret_key 参数需为 string 类型"
: "" === t.secret_key.trim()
? "缺少 secret_key 参数"
: 32 !== t.secret_key.length
? "secret_key 参数需为 32 位字符串"
: "string" != typeof t.appid
? "appid 参数需为 string 类型"
: "" !== t.appid.trim() || "缺少 appid")
: "初始化参数需为 object 类型";
};
function bt(t) {
return Ot()[t];
}
function Ot() {
return S;
}
function It(t, e) {
return Object.prototype.hasOwnProperty.call(t, e);
}
var wt = function (t) {
try {
return t && "string" == typeof t
? -1 === (t = t.replace(/\s/g, "")).indexOf(".")
? t
: t.split(".").slice(0, 2).join(".")
: "";
} catch (e) {
return t;
}
},
Ct = (function () {
function t() {
f(this, t);
}
return (
p(t, null, [
{
key: "error",
value: function (t) {
for (
var e,
n = arguments.length,
r = new Array(n > 1 ? n - 1 : 0),
o = 1;
o < n;
o++
)
r[o - 1] = arguments[o];
(e = console).error.apply(
e,
["".concat("[@dn-sdk/minigame v1.5.6]", ": ").concat(t)].concat(
r,
),
);
},
},
{
key: "info",
value: function (e) {
for (
var n,
r = arguments.length,
o = new Array(r > 1 ? r - 1 : 0),
i = 1;
i < r;
i++
)
o[i - 1] = arguments[i];
t.debug &&
(n = console).info.apply(
n,
["".concat("[@dn-sdk/minigame v1.5.6]", ": ").concat(e)].concat(
o,
),
);
},
},
{
key: "log",
value: function (e) {
for (
var n,
r = arguments.length,
o = new Array(r > 1 ? r - 1 : 0),
i = 1;
i < r;
i++
)
o[i - 1] = arguments[i];
t.debug &&
(n = console).log.apply(
n,
["".concat("[@dn-sdk/minigame v1.5.6]", ": ").concat(e)].concat(
o,
),
);
},
},
{
key: "warn",
value: function (t) {
for (
var e,
n = arguments.length,
r = new Array(n > 1 ? n - 1 : 0),
o = 1;
o < n;
o++
)
r[o - 1] = arguments[o];
(e = console).warn.apply(
e,
["".concat("[@dn-sdk/minigame v1.5.6]", ": ").concat(t)].concat(
r,
),
);
},
},
{
key: "devLog",
value: function (e) {
for (
var n,
r = arguments.length,
o = new Array(r > 1 ? r - 1 : 0),
i = 1;
i < r;
i++
)
o[i - 1] = arguments[i];
t.isDev &&
(n = console).log.apply(
n,
["".concat("[@dn-sdk/minigame v1.5.6]", ": ").concat(e)].concat(
o,
),
);
},
},
]),
t
);
})(),
xt = Ct;
((xt.debug = !1), (xt.isDev = !1));
var Nt = (function () {
var t;
return function () {
if (!t)
try {
var e = wx.getLaunchOptionsSync(),
n = e.query.gdt_vid || "";
n ? tt.setSync(m, n) : (n = tt.getSync(m) || "");
var r = JSON.stringify(e);
(r.length > 1e4 && (r = JSON.stringify({ cut: 1, scene: e.scene })),
(t = {
source_scene: e.scene,
pkg_channel_id: e.query.wxgamepro || "",
ad_trace_id: n,
launch_options: r,
channel: ut(e),
}));
} catch (e) {
((t = {}), xt.log("获取场景值和渠道号失败", e));
}
return t;
};
})();
function Lt(t, e, n) {
var r = n.value;
return (
(n.value = function () {
for (var n = arguments.length, o = new Array(n), i = 0; i < n; i++)
o[i] = arguments[i];
try {
return r.apply(this, o);
} catch (n) {
try {
(xt.error.apply(
xt,
[
"calling "
.concat(t.constructor.name, ".")
.concat(e, " error with arguments"),
].concat(o),
),
xt.error(n));
var a = {
log_type: b.JS_RUN_ERROR,
message: "[safeExcutable] "
.concat(t.constructor.name, ".")
.concat(e, ": ")
.concat(null == n ? void 0 : n.message),
err_stack: null == n ? void 0 : n.stack,
};
yt(this.reportLog) ? this.reportLog(a) : ct(a);
} catch (a) {}
}
}),
n
);
}
var Pt = Object.defineProperty,
Mt = Object.getOwnPropertyDescriptor,
Dt = function (t, e, n, r) {
for (
var o, i = r > 1 ? void 0 : r ? Mt(e, n) : e, a = t.length - 1;
a >= 0;
a--
)
(o = t[a]) && (i = (r ? o(e, n, i) : o(i)) || i);
return (r && i && Pt(e, n, i), i);
},
Ut = (function () {
function t(e) {
var n = e.userActionSetId,
r = e.maxLength,
o = void 0 === r ? 500 : r;
(f(this, t),
(this.lostActionMaps = {}),
(this.stack = []),
(this.localStorageKey = ""),
(this.localStorageKey = ""
.concat(g, "_")
.concat(null == n ? void 0 : n.toString())),
(this.maxLength = o),
(this.userActionSetId = n),
this.setTimeStamp(),
this.init());
}
return (
p(t, [
{
key: "getItems",
value: function () {
return this.stack;
},
},
{
key: "getStorage",
value: function () {
var t,
e =
(null == (t = tt) ? void 0 : t.getSync(this.localStorageKey)) ||
"[]";
return JSON.parse(e);
},
},
{
key: "reportLostNum",
value: function () {
var t = this,
e = Object.assign({}, this.lostActionMaps),
n = [];
for (var r in e) {
var o = null == r ? void 0 : r.split("_");
n.push({
queue_lost_session_id: o[0],
queue_lost_timestamp: o[1],
queue_lost_num: e[r],
});
}
n.length &&
(this.setTimeStamp(),
n.forEach(function (e) {
var n = Object.assign(
{},
{
user_action_set_id: t.userActionSetId,
log_type: b.QUEUE_LOST_NUM,
},
e,
),
r = null == e ? void 0 : e.queue_lost_session_id,
o = null == e ? void 0 : e.queue_lost_timestamp,
i = "".concat(r, "_").concat(o);
ct(n, function () {
It(t.lostActionMaps, i) &&
(delete t.lostActionMaps[i],
tt.setSync(A, JSON.stringify(t.lostActionMaps)));
});
}));
},
},
{
key: "getLostMaps",
value: function () {
return this.lostActionMaps;
},
},
{
key: "init",
value: function () {
var t = this,
e = this.getStorage(),
n =
null == e
? void 0
: e.map(function (t) {
var e, n;
return t.inner_status ===
(null == (e = E) ? void 0 : e.reporting)
? Object.assign({}, t, {
inner_status: null == (n = E) ? void 0 : n.fail,
is_retry: !0,
retry_count: t.retry_count + 1,
})
: t;
});
((this.stack = n),
(this.lostActionMaps = JSON.parse(tt.getSync(A) || "{}")),
setTimeout(function () {
t.reportLostNum();
}, 1e3));
},
},
{
key: "addItem",
value: function (t) {
var e;
null == (e = null == this ? void 0 : this.stack) || e.push(t);
},
},
{
key: "removeItems",
value: function (t) {
var e,
n =
null == (e = null == this ? void 0 : this.stack)
? void 0
: e.filter(function (e) {
return !(
null != t &&
t.includes(null == e ? void 0 : e.action_id)
);
});
this.stack = n;
},
},
{
key: "updateForReportFail",
value: function (t) {
var e;
this.stack =
null == (e = this.stack)
? void 0
: e.map(function (e) {
var n;
return null != t &&
t.includes(null == e ? void 0 : e.action_id)
? Object.assign({}, e, {
inner_status: null == (n = E) ? void 0 : n.fail,
retry_count: e.retry_count + 1,
is_retry: !0,
})
: e;
});
},
},
{
key: "updateForReporting",
value: function (t) {
var e;
this.stack =
null == (e = this.stack)
? void 0
: e.map(function (e) {
var n;
return null != t &&
t.includes(null == e ? void 0 : e.action_id)
? Object.assign({}, e, {
inner_status: null == (n = E) ? void 0 : n.reporting,
})
: e;
});
},
},
{
key: "updateAllStack",
value: function (t) {
this.stack = t;
},
},
{
key: "updateToStorage",
value: function () {
tt.setSync(this.localStorageKey, JSON.stringify(this.stack));
},
},
{
key: "updateLostAction",
value: function (t) {
if (t) {
var e = "".concat(t, "_").concat(this.timeStamp),
n = this.lostActionMaps[e] || 0;
((this.lostActionMaps[e] = n + 1),
tt.setSync(A, JSON.stringify(this.lostActionMaps)));
}
},
},
{
key: "setTimeStamp",
value: function () {
this.timeStamp = Date.now().toString();
},
},
]),
t
);
})();
(Dt([Lt], Ut.prototype, "getItems", 1),
Dt([Lt], Ut.prototype, "getStorage", 1),
Dt([Lt], Ut.prototype, "reportLostNum", 1),
Dt([Lt], Ut.prototype, "getLostMaps", 1),
Dt([Lt], Ut.prototype, "init", 1),
Dt([Lt], Ut.prototype, "addItem", 1),
Dt([Lt], Ut.prototype, "removeItems", 1),
Dt([Lt], Ut.prototype, "updateForReportFail", 1),
Dt([Lt], Ut.prototype, "updateForReporting", 1),
Dt([Lt], Ut.prototype, "updateAllStack", 1),
Dt([Lt], Ut.prototype, "updateToStorage", 1),
Dt([Lt], Ut.prototype, "updateLostAction", 1));
var qt = p(function t() {
f(this, t);
});
((qt.hasDirectGameMask = !1), (qt.activeDuration = 0));
var Ft = Object.defineProperty,
jt = Object.getOwnPropertyDescriptor,
Bt = function (t, e, n, r) {
for (
var o, i = r > 1 ? void 0 : r ? jt(e, n) : e, a = t.length - 1;
a >= 0;
a--
)
(o = t[a]) && (i = (r ? o(e, n, i) : o(i)) || i);
return (r && i && Ft(e, n, i), i);
},
Vt = (function (t) {
o(n, Ut);
var e = a(n);
function n(t) {
var r,
o = t.userActionSetId,
i = t.maxLength,
a = void 0 === i ? 500 : i,
u = t.ogEvents,
c = void 0 === u ? [] : u;
return (
f(this, n),
((r = e.call(this, { userActionSetId: o, maxLength: a })).ogEvents = c),
r
);
}
return (
p(n, [
{
key: "getReportableActions",
value: function () {
var t =
arguments.length > 0 && void 0 !== arguments[0]
? arguments[0]
: 100,
e = this.getItems(),
n = [];
return (
null == e ||
e.forEach(function (e) {
var r;
(null == n ? void 0 : n.length) < t &&
(null == e ? void 0 : e.inner_status) !==
(null == (r = E) ? void 0 : r.reporting) &&
(null == n || n.push(e));
}),
n
);
},
},
{
key: "addAction",
value: function (t) {
var e = { code: 0, message: "成功", actionId: t.action_id },
n = this.getItems();
if ((null == n ? void 0 : n.length) >= this.maxLength) {
var r = "队列长度超过最大限制".concat(
this.maxLength,
"条,SDK将按照行为优先级排序,丢弃优先级最低的行为事件",
);
(xt.warn(r),
ct({
user_action_set_id: this.userActionSetId,
log_type: b.JS_QUEUE_LOG,
message: "队列长度超过限制",
}));
var o = this.sortQueue(t, n);
xt.debug &&
xt.info(
"超过".concat(this.maxLength, "条按优先级排序的队列:"),
o.concat([]),
);
var i = o.pop();
(this.updateAllStack(o),
this.updateLostAction(
(null == i ? void 0 : i.session_id) || "",
),
(null == i ? void 0 : i.action_id) === t.action_id &&
(e = { code: 103, message: "缓存队列已满,主动丢弃行为" }));
} else this.addItem(t);
return (qt.hasDirectGameMask || this.updateToStorage(), e);
},
},
{
key: "removeActions",
value: function (t) {
(this.removeItems(t), this.updateToStorage());
},
},
{
key: "updateActionsForReportFail",
value: function (t) {
(this.updateForReportFail(t), this.updateToStorage());
},
},
{
key: "updateActionsForReporting",
value: function (t) {
(this.updateForReporting(t), this.updateToStorage());
},
},
{
key: "getReportableActionsLength",
value: function () {
var t = this.getItems().filter(function (t) {
var e;
return (
(null == t ? void 0 : t.inner_status) !==
(null == (e = E) ? void 0 : e.reporting)
);
});
return null == t ? void 0 : t.length;
},
},
{
key: "sortQueue",
value: function (t, e) {
var n = this,
r = {},
o = null == t ? void 0 : t.action_time,
i = e.concat([t]),
a = function (t) {
return (
r[t.action_id] || (r[t.action_id] = n.caculateWeight(o, t)),
r[t.action_id]
);
};
return i.sort(function (t, e) {
return a(e) - a(t);
});
},
},
{
key: "caculateWeight",
value: function (t, e) {
var n,
r = 0,
o = this.formatWeight(t, null == e ? void 0 : e.action_time),
i = o.ogWeight,
a = o.sdkWeight,
u = o.userWeight;
(null != (n = this.ogEvents) &&
n.includes(null == e ? void 0 : e.action_type) &&
(r += i),
null != e && e.is_sdk_auto_track ? (r += a) : (r += u));
var c = t - (null == e ? void 0 : e.action_time) + 1;
return (r = c > 0 ? r + 1 / c : r);
},
},
{
key: "formatWeight",
value: function (t, e) {
var n = N,
r = P,
o = L;
return (
t - e > 2592e6 && ((n /= 100), (r /= 100), (o /= 100)),
{ ogWeight: n, sdkWeight: r, userWeight: o }
);
},
},
]),
n
);
})();
(Bt([Lt], Vt.prototype, "getReportableActions", 1),
Bt([Lt], Vt.prototype, "addAction", 1),
Bt([Lt], Vt.prototype, "removeActions", 1),
Bt([Lt], Vt.prototype, "updateActionsForReportFail", 1),
Bt([Lt], Vt.prototype, "updateActionsForReporting", 1),
Bt([Lt], Vt.prototype, "getReportableActionsLength", 1),
Bt([Lt], Vt.prototype, "sortQueue", 1),
Bt([Lt], Vt.prototype, "caculateWeight", 1),
Bt([Lt], Vt.prototype, "formatWeight", 1));
var Gt = (function () {
function t() {
(f(this, t), (this.events = {}));
}
return (
p(
t,
[
{
key: "subscribe",
value: function (e, n) {
(t.checkCallback(n),
_t(this.events[e])
? this.events[e].push(n)
: (this.events[e] = [n]));
},
},
{
key: "once",
value: function (e, n) {
(t.checkCallback(n), this.subscribe(this.onceEventName(e), n));
},
},
{
key: "unsubscribe",
value: function (e, n) {
(t.checkCallback(n),
_t(this.events[e]) &&
(this.events[e] = this.events[e].filter(function (t) {
return t !== n;
})),
_t(this.events[this.onceEventName(e)]) &&
(this.events[this.onceEventName(e)] = this.events[
this.onceEventName(e)
].filter(function (t) {
return t !== n;
})));
},
},
{
key: "publish",
value: function (t) {
for (
var e = arguments.length,
n = new Array(e > 1 ? e - 1 : 0),
r = 1;
r < e;
r++
)
n[r - 1] = arguments[r];
var o = Date.now();
(_t(this.events[t]) &&
this.events[t].forEach(function (t) {
return t.apply(void 0, [o].concat(n));
}),
_t(this.events[this.onceEventName(t)]) &&
(this.events[this.onceEventName(t)].forEach(function (t) {
return t.apply(void 0, [o].concat(n));
}),
(this.events[this.onceEventName(t)] = [])));
},
},
{
key: "onceEventName",
value: function (t) {
return "once_event_prefix_".concat(t);
},
},
],
[
{
key: "checkCallback",
value: function (e) {
yt(e) || xt.error(t.ERROR_CALLBACK_IS_NOT_A_FUNCTION);
},
},
],
),
t
);
})(),
Kt = Gt;
Kt.ERROR_CALLBACK_IS_NOT_A_FUNCTION = "callback 不是函数";
var Qt = new Kt(),
Yt = [
"REGISTER",
"VIEW_CONTENT",
"ADD_TO_CART",
"PURCHASE",
"COMPLETE_ORDER",
"ADD_TO_WISHLIST",
"START_APP",
"CREATE_ROLE",
"AUTHORIZE",
"TUTORIAL_FINISH",
"START_PAY",
"FINISH_PAY",
],
Wt = "START_APP",
Jt = "TICKET",
Ht = "ENTER_FOREGROUND",
zt = "ENTER_BACKGROUND",
$t = "LOGIN",
Xt = "SHARE",
Zt = "TAP_GAME_CLUB",
te = "CREATE_GAME_CLUB",
ee = "CREATE_GAME_ROOM",
ne = "JOIN_GAME_ROOM",
re = "FINISH_PAY",
oe = "START_PAY",
ie = "ADD_TO_WISHLIST",
ae = ["REGISTER", "START_APP", "RE_ACTIVE"],
ue = ["TICKET", "ENTER_FOREGROUND", "ENTER_BACKGROUND"],
ce = (function () {
function t() {
(f(this, t),
(this.channelClaimActionList = ae),
(this.noClaimActionList = ue),
(this.realTimeActionList = S.realTimeActionList),
(this.ticketInterval = 60),
(this.requestTimeout = S.requestTimeout),
this.loadConfig());
}
return (
p(t, [
{
key: "getChannelClaimActionList",
value: function () {
return this.channelClaimActionList;
},
},
{
key: "getNoClaimActionList",
value: function () {
return this.noClaimActionList;
},
},
{
key: "getRealTimeActionList",
value: function () {
return this.realTimeActionList;
},
},
{
key: "getTicketInterval",
value: function () {
return this.ticketInterval;
},
},
{
key: "getRequestTimeout",
value: function () {
return this.requestTimeout;
},
},
{
key: "loadConfig",
value: function () {
var t = this;
try {
if ("undefined" == typeof wx) return;
if (window["tt"] || window["ks"]){console.warn("平台不支持");return};
var e = tt.getSync(k);
(e && this.updateConfig(e),
lt({
conf_name: "mini_game_sdk_common",
conf_key: "config",
}).then(function (e) {
e && ht(e) && (t.updateConfig(e), tt.setSync(k, e));
}));
} catch (e) {
console.error(e);
}
},
},
{
key: "updateConfig",
value: function (t) {
(t.channelClaimActionList &&
_t(t.channelClaimActionList) &&
(this.channelClaimActionList = t.channelClaimActionList),
t.noClaimActionList &&
_t(t.noClaimActionList) &&
(this.noClaimActionList = t.noClaimActionList),
t.realTimeActionList &&
_t(t.realTimeActionList) &&
(this.realTimeActionList = t.realTimeActionList),
t.ticketInterval &&
"number" == typeof t.ticketInterval &&
t.ticketInterval > 1 &&
t.ticketInterval !== this.ticketInterval &&
((this.ticketInterval = t.ticketInterval), Qt.publish(Z)),
t.requestTimeout &&
"number" == typeof t.requestTimeout &&
t.requestTimeout > 5e3 &&
(this.requestTimeout = t.requestTimeout));
},
},
]),
t
);
})(),
se = new ce(),
le = Wt,
fe = Jt,
de = Ht,
pe = zt,
ve = (function () {
var t = !0,
e = !0,
n = !0,
r = !0,
o = !0,
i = !1;
return function () {
if (!i) {
i = !0;
var a = tt.getSync(R);
if (
((null == a ? void 0 : a.bg) === K
? (t = !0)
: (null == a ? void 0 : a.bg) === Q && (t = !1),
(null == a ? void 0 : a.fg) === K
? (e = !0)
: (null == a ? void 0 : a.fg) === Q && (e = !1),
(null == a ? void 0 : a.st) === K
? (n = !0)
: (null == a ? void 0 : a.st) === Q && (n = !1),
(null == a ? void 0 : a.ti) === K
? (r = !0)
: (null == a ? void 0 : a.ti) === Q && (r = !1),
xt.devLog("当前缓存开关 bgOn,fgOn,stOn,tiOn:", t, e, n, r),
n && Qt.publish(le),
r)
) {
var u = function () {
o && Qt.publish(fe);
},
c = setInterval(u, 1e3 * se.getTicketInterval());
Qt.subscribe(Z, function () {
(c && clearInterval(c),
(c = setInterval(u, 1e3 * se.getTicketInterval())));
});
}
(wx.onShow(function (t) {
if (((o = !0), e)) {
var n = "";
try {
(n = JSON.stringify(t)).length > 1e4 &&
(n = JSON.stringify({ cut: 1, scene: t.scene }));
} catch (t) {}
Qt.publish(de, { enter_options: n });
}
}),
wx.onHide(function () {
if (((o = !1), t)) {
var e = 0;
(0 !== qt.activeDuration &&
((e = Date.now() - qt.activeDuration), (qt.activeDuration = 0)),
Qt.publish(pe, { duration: e > 0 ? e : 0 }));
}
}));
}
};
})(),
he =
"undefined" != typeof globalThis
? globalThis
: "undefined" != typeof window
? window
: "undefined" != typeof global
? global
: "undefined" != typeof self
? self
: {};
function _e(t) {
return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default")
? t.default
: t;
}
var ye,
ge = _e(function () {
var t,
e = null;
function n(t) {
return !!t && ("object" == l(t) || "function" == typeof t);
}
function r(t) {
if (null !== t && !n(t))
throw new TypeError(
"Object prototype may only be an Object or null: " + t,
);
}
var o = Object,
i = !(!o.create && { __proto__: null } instanceof o),
a =
o.create ||
(i
? function (t) {
return (r(t), { __proto__: t });
}
: function (t) {
if ((r(t), null === t))
throw new SyntaxError(
"Native Object.create is required to create objects with null prototype",
);
var e = function () {};
return ((e.prototype = t), new e());
}),
u = function () {
return null;
},
c =
o.getPrototypeOf ||
([].__proto__ === Array.prototype
? function (t) {
var e = t.__proto__;
return n(e) ? e : null;
}
: u);
return (
(t = function (s, l) {
if (void 0 === (this && this instanceof t ? this.constructor : void 0))
throw new TypeError("Constructor Proxy requires 'new'");
if (!n(s) || !n(l))
throw new TypeError(
"Cannot create proxy with a non-object as target or handler",
);
var f = function () {};
((e = function () {
((s = null),
(f = function (t) {
throw new TypeError(
"Cannot perform '".concat(
t,
"' on a proxy that has been revoked",
),
);
}));
}),
setTimeout(function () {
e = null;
}, 0));
var d = l;
for (var p in ((l = {
get: null,
set: null,
apply: null,
construct: null,
}),
d)) {
if (!(p in l))
throw new TypeError(
"Proxy polyfill does not support trap '".concat(p, "'"),
);
l[p] = d[p];
}
"function" == typeof d && (l.apply = d.apply.bind(d));
var v,
h = c(s),
_ = !1,
y = !1;
"function" == typeof s
? ((v = function () {
var t = this && this.constructor === v,
e = Array.prototype.slice.call(arguments);
return (
f(t ? "construct" : "apply"),
t && l.construct
? l.construct.call(this, s, e)
: !t && l.apply
? l.apply(s, this, e)
: t
? (e.unshift(s), new (s.bind.apply(s, e))())
: s.apply(this, e)
);
}),
(_ = !0))
: s instanceof Array
? ((v = []), (y = !0))
: (v = i || null !== h ? a(h) : {});
var g = l.get
? function (t) {
return (f("get"), l.get(this, t, v));
}
: function (t) {
return (f("get"), this[t]);
},
m = l.set
? function (t, e) {
(f("set"), l.set(this, t, e, v));
}
: function (t, e) {
(f("set"), (this[t] = e));
},
A = o.getOwnPropertyNames(s),
R = {};
A.forEach(function (t) {
if ((!_ && !y) || !(t in v)) {
var e = {
enumerable: !!o.getOwnPropertyDescriptor(s, t).enumerable,
get: g.bind(s, t),
set: m.bind(s, t),
};
(o.defineProperty(v, t, e), (R[t] = !0));
}
});
var k = !0;
if (_ || y) {
var T =
o.setPrototypeOf ||
([].__proto__ === Array.prototype
? function (t, e) {
return (r(e), (t.__proto__ = e), t);
}
: u);
(h && T(v, h)) || (k = !1);
}
if (l.get || !k)
for (var E in s)
R[E] || o.defineProperty(v, E, { get: g.bind(s, E) });
return (o.seal(s), o.seal(v), v);
}),
(t.revocable = function (n, r) {
return { proxy: new t(n, r), revoke: e };
}),
t
);
}),
me = {};
try {
ye || (ye = ge());
} catch (h) {
Ee(h);
}
function Ae(t, n, r, o) {
try {
if (!ye || null == t || !t[n]) return;
t[n] = new ye(t[n], {
apply: function (t, n, i) {
var a, u;
o &&
Te(function () {
return o.apply(void 0, e(i));
});
var c = !!(
(null != (a = i[0]) && a.success) ||
(null != (u = i[0]) && u.fail)
);
c &&
["success", "fail"].forEach(function (t) {
if (i[0][t])
try {
i[0][t] = new ye(i[0][t], {
apply: function (n, o, a) {
return (
Te(function () {
return r.apply(void 0, [t, i[0]].concat(e(a)));
}),
n.apply(o, a)
);
},
});
} catch (t) {
Ee(t);
}
});
var s = t.apply(n, i);
return !c &&
s &&
"[object Promise]" === Object.prototype.toString.call(s)
? s
.then(function (t) {
return (
Te(function () {
return r("success", i[0], t);
}),
t
);
})
.catch(function (t) {
throw (
Te(function () {
return r("fail", i[0], t);
}),
t
);
})
: s;
},
});
} catch (t) {
Ee(t);
}
}
function Re(t, n, r) {
try {
if (!ye || null == t || !t[n]) return;
t[n] = new ye(t[n], {
apply: function (t, n, o) {
var i = "function" == typeof o[0];
if (i)
try {
o[0] = new ye(o[0], {
apply: function (t, n, o) {
var i = t.call.apply(t, [n].concat(e(o)));
return (
Te(function () {
return r(i);
}),
i
);
},
});
} catch (t) {
Ee(t);
}
var a = t.call.apply(t, [n].concat(e(o)));
return (
i ||
Te(function () {
return r(a);
}),
a
);
},
});
} catch (t) {
Ee(t);
}
}
function ke(t) {
var n = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "",
r = arguments.length > 2 ? arguments[2] : void 0,
o = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : [],
i = arguments.length > 4 ? arguments[4] : void 0;
try {
if (!ye || null == t || !t[n]) return;
t[n] = new ye(t[n], {
apply: function (t, a, u) {
var c = t.call.apply(t, [a].concat(e(u)));
return (
(!r || !me[n]) &&
(Te(function () {
return null == i ? void 0 : i(c);
}),
o.forEach(function (t) {
var e = t.eventName,
n = t.isAsync,
r = t.proxyEvent;
n ? Ae(c, e, r) : Re(c, e, r);
})),
r && (me[n] = !0),
c
);
},
});
} catch (t) {
Ee(t);
}
}
function Te(t) {
try {
t();
} catch (t) {
Ee(t);
}
}
function Ee(t) {
ct({
log_type: b.PROXY_ERROR,
message: null == t ? void 0 : t.message,
err_stack: null == t ? void 0 : t.stack,
});
}
var Se = $t,
be = ie,
Oe = Xt,
Ie = Zt,
we = te,
Ce = ne,
xe = oe,
Ne = re,
Le = (function () {
var t = !1;
return function () {
t ||
((t = !0),
Ae(wx, "login", function (t) {
"success" === t && Qt.publish(Se);
}),
Re(wx, "onAddToFavorites", function () {
Qt.publish(be);
}),
Re(wx, "onShareTimeline", function () {
Qt.publish(Oe, { target: "TIME_LINE", trigger: "MENU" });
}),
Re(wx, "onShareAppMessage", function () {
Qt.publish(Oe, { target: "APP_MESSAGE", trigger: "MENU" });
}),
Re(wx, "shareAppMessage", function () {
Qt.publish(Oe, { target: "APP_MESSAGE", trigger: "BUTTON" });
}),
ke(
wx,
"createGameClubButton",
!1,
[
{
isAsync: !1,
eventName: "onTap",
proxyEvent: function () {
Qt.publish(Ie);
},
},
],
function () {
Qt.publish(we);
},
),
ke(wx, "getGameServerManager", !0, [
{
isAsync: !0,
eventName: "createRoom",
proxyEvent: function (t) {
"success" === t && Qt.publish("CREATE_GAME_ROOM");
},
},
{
isAsync: !0,
eventName: "joinRoom",
proxyEvent: function (t) {
"success" === t && Qt.publish(Ce);
},
},
]),
Ae(
wx,
"requestMidasPayment",
function (t, e) {
Qt.publish(Ne, {
status: "success" === t ? "SUCCESS" : "FAIL",
quantity: (null == e ? void 0 : e.buyQuantity) || 0,
mode: (null == e ? void 0 : e.mode) || "",
platform: (null == e ? void 0 : e.platform) || "",
no: (null == e ? void 0 : e.outTradeNo) || "",
payType: "Midas",
});
},
function (t) {
Qt.publish(xe, {
quantity: (null == t ? void 0 : t.buyQuantity) || 0,
mode: (null == t ? void 0 : t.mode) || "",
platform: (null == t ? void 0 : t.platform) || "",
no: (null == t ? void 0 : t.outTradeNo) || "",
payType: "Midas",
});
},
),
Ae(
wx,
"requestMidasPaymentGameItem",
function (t, e) {
var n = (e || {}).signData;
Qt.publish(Ne, {
status: "success" === t ? "SUCCESS" : "FAIL",
quantity: (null == n ? void 0 : n.buyQuantity) || 0,
mode: (null == n ? void 0 : n.mode) || "",
platform: (null == n ? void 0 : n.platform) || "",
no: (null == n ? void 0 : n.outTradeNo) || "",
p: (null == n ? void 0 : n.goodsPrice) || 0,
productId: (null == n ? void 0 : n.productId) || "",
payType: "MidasGameItem",
});
},
function (t) {
var e = (t || {}).signData;
Qt.publish(xe, {
quantity: (null == e ? void 0 : e.buyQuantity) || 0,
mode: (null == e ? void 0 : e.mode) || "",
platform: (null == e ? void 0 : e.platform) || "",
no: (null == e ? void 0 : e.outTradeNo) || "",
p: (null == e ? void 0 : e.goodsPrice) || 0,
productId: (null == e ? void 0 : e.productId) || "",
payType: "MidasGameItem",
});
},
));
};
})(),
Pe = (function () {
function t() {
f(this, t);
}
return (
p(t, null, [
{
key: "isEmpty",
value: function (t) {
return null == t || ("string" == typeof t && "" === t.trim());
},
},
{
key: "format",
value: function (t) {
for (
var e = arguments.length, n = new Array(e > 1 ? e - 1 : 0), r = 1;
r < e;
r++
)
n[r - 1] = arguments[r];
return t.replace(/\${(\d+)}/g, function (t, e) {
return n[e];
});
},
},
{
key: "customStringify",
value: function (t) {
var e = [];
try {
return JSON.stringify(t, function (t, n) {
if (void 0 === n) return "undefined";
if ("object" == l(n) && null !== n) {
if (-1 !== e.indexOf(n)) return "[Circular]";
e.push(n);
}
return "bigint" == typeof n ? n.toString() : n;
});
} catch (t) {
return "[Param Error]";
}
},
},
]),
t
);
})(),
Me = /^([a-zA-Z][a-zA-Z\d_]{0,63})$/i,
De = /^ams_reserved_(.*)/i,
Ue = (function () {
function t() {
f(this, t);
}
return (
p(t, null, [
{
key: "validateActionType",
value: function (e) {
return Pe.isEmpty(e)
? (xt.error(t.ERROR_ACTION_TYPE_NULL), !1)
: !!Me.test(e) || (xt.error(t.ERROR_ACTION_TYPE_INVALID), !1);
},
},
{
key: "validateActionParam",
value: function (e) {
if (!e) return !0;
if (!ht(e))
return (xt.error(t.ERROR_ACTION_PARAM_IS_NOT_OBJECT), !1);
for (var n in e) {
if (Pe.isEmpty(n))
return (xt.error(t.ERROR_ACTION_PARAM_KEY_NULL), !1);
if (!Me.test(n))
return (xt.error(t.ERROR_ACTION_PARAM_KEY_INVALID), !1);
De.test(n) && xt.warn(t.WARN_ACTION_PARAM_KEY_RESERVED);
var r = e[n];
if (!t.isValidValue(r))
return (
xt.error(Pe.format(t.ERROR_ACTION_PARAM_VALUE_INVALID, n, r)),
!1
);
if (_t(r)) {
if (!t.isValidArrayValue(r)) {
for (var o = 0; o < r.length; o++)
xt.error(
Pe.format(
t.ERROR_ACTION_PARAM_VALUE_ARRAY_INVALID,
n,
Pe.customStringify(r),
o,
r[o],
),
);
return !1;
}
if (!t.checkArrayElementTypes(r))
return (
xt.error(t.ERROR_ACTION_PARAM_VALUE_ARRAY_TYPE_UNUNIQUE),
!1
);
}
}
return !0;
},
},
{
key: "isValidValue",
value: function (t) {
return (
null == t ||
"string" == typeof t ||
"number" == typeof t ||
"boolean" == typeof t ||
_t(t)
);
},
},
{
key: "isValidArrayValue",
value: function (t) {
for (var e = 0; e < t.length; e++) {
var n = t[e];
if (
"string" != typeof n &&
"number" != typeof n &&
"boolean" != typeof n
)
return !1;
}
return !0;
},
},
{
key: "checkArrayElementTypes",
value: function (t) {
if (!t || t.length <= 1) return !0;
for (var e = l(t[0]), n = 1; n < t.length; n++)
if (l(t[n]) !== e) return !1;
return !0;
},
},
]),
t
);
})(),
qe = Ue;
((qe.ERROR_ACTION_TYPE_NULL = "在track方法中,action_type参数不能为空!"),
(qe.ERROR_ACTION_TYPE_INVALID =
"在track方法中,action_type参数只能包含字母、数字和下划线,且只能以字母开头,长度不能超过64个字符!"),
(qe.ERROR_ACTION_PARAM_KEY_NULL =
"在track方法中,action_param参数的key不能为空!"),
(qe.ERROR_ACTION_PARAM_KEY_INVALID =
"在track方法中,action_param参数的key只能包含字母、数字和下划线,且不能以数字开头,长度不能超过64个字符!"),
(qe.WARN_ACTION_PARAM_KEY_RESERVED =
"SDK内部预留参数的key均以'ams_reserved_'开头,该参数的值会被SDK内部覆盖,请不要使用!"),
(qe.ERROR_ACTION_PARAM_VALUE_INVALID =
"在track方法中,action_param参数的value必须是String/Number/Boolean/Array中的一种![key=${0}, value=${1}]"),
(qe.ERROR_ACTION_PARAM_VALUE_ARRAY_INVALID =
"在track方法中,如果action_param参数中的某个元素的value是Array,那么这个Array中的每个元素必须是String/Number/Boolean中的一种![key=${0}, value=${1}, 数组的第${2}个元素为${3}]"),
(qe.ERROR_ACTION_PARAM_VALUE_ARRAY_TYPE_UNUNIQUE =
"在track方法中,如果action_param参数中的某个元素的value是Array,那么这个Array中所有元素的类型必须是同一种!"),
(qe.ERROR_ACTION_PARAM_IS_NOT_OBJECT = "action_param 参数不是Object"));
var Fe = { exports: {} };
!(function (t) {
!(function (e) {
function n(t, e) {
var n = (65535 & t) + (65535 & e);
return (((t >> 16) + (e >> 16) + (n >> 16)) << 16) | (65535 & n);
}
function r(t, e, r, o, i, a) {
return n(
(function (t, e) {
return (t << e) | (t >>> (32 - e));
})(n(n(e, t), n(o, a)), i),
r,
);
}
function o(t, e, n, o, i, a, u) {
return r((e & n) | (~e & o), t, e, i, a, u);
}
function i(t, e, n, o, i, a, u) {
return r((e & o) | (n & ~o), t, e, i, a, u);
}
function a(t, e, n, o, i, a, u) {
return r(e ^ n ^ o, t, e, i, a, u);
}
function u(t, e, n, o, i, a, u) {
return r(n ^ (e | ~o), t, e, i, a, u);
}
function c(t, e) {
((t[e >> 5] |= 128 << (e % 32)), (t[14 + (((e + 64) >>> 9) << 4)] = e));
var r,
c,
s,
l,
f,
d = 1732584193,
p = -271733879,
v = -1732584194,
h = 271733878;
for (r = 0; r < t.length; r += 16)
((c = d),
(s = p),
(l = v),
(f = h),
(d = o(d, p, v, h, t[r], 7, -680876936)),
(h = o(h, d, p, v, t[r + 1], 12, -389564586)),
(v = o(v, h, d, p, t[r + 2], 17, 606105819)),
(p = o(p, v, h, d, t[r + 3], 22, -1044525330)),
(d = o(d, p, v, h, t[r + 4], 7, -176418897)),
(h = o(h, d, p, v, t[r + 5], 12, 1200080426)),
(v = o(v, h, d, p, t[r + 6], 17, -1473231341)),
(p = o(p, v, h, d, t[r + 7], 22, -45705983)),
(d = o(d, p, v, h, t[r + 8], 7, 1770035416)),
(h = o(h, d, p, v, t[r + 9], 12, -1958414417)),
(v = o(v, h, d, p, t[r + 10], 17, -42063)),
(p = o(p, v, h, d, t[r + 11], 22, -1990404162)),
(d = o(d, p, v, h, t[r + 12], 7, 1804603682)),
(h = o(h, d, p, v, t[r + 13], 12, -40341101)),
(v = o(v, h, d, p, t[r + 14], 17, -1502002290)),
(d = i(
d,
(p = o(p, v, h, d, t[r + 15], 22, 1236535329)),
v,
h,
t[r + 1],
5,
-165796510,
)),
(h = i(h, d, p, v, t[r + 6], 9, -1069501632)),
(v = i(v, h, d, p, t[r + 11], 14, 643717713)),
(p = i(p, v, h, d, t[r], 20, -373897302)),
(d = i(d, p, v, h, t[r + 5], 5, -701558691)),
(h = i(h, d, p, v, t[r + 10], 9, 38016083)),
(v = i(v, h, d, p, t[r + 15], 14, -660478335)),
(p = i(p, v, h, d, t[r + 4], 20, -405537848)),
(d = i(d, p, v, h, t[r + 9], 5, 568446438)),
(h = i(h, d, p, v, t[r + 14], 9, -1019803690)),
(v = i(v, h, d, p, t[r + 3], 14, -187363961)),
(p = i(p, v, h, d, t[r + 8], 20, 1163531501)),
(d = i(d, p, v, h, t[r + 13], 5, -1444681467)),
(h = i(h, d, p, v, t[r + 2], 9, -51403784)),
(v = i(v, h, d, p, t[r + 7], 14, 1735328473)),
(d = a(
d,
(p = i(p, v, h, d, t[r + 12], 20, -1926607734)),
v,
h,
t[r + 5],
4,
-378558,
)),
(h = a(h, d, p, v, t[r + 8], 11, -2022574463)),
(v = a(v, h, d, p, t[r + 11], 16, 1839030562)),
(p = a(p, v, h, d, t[r + 14], 23, -35309556)),
(d = a(d, p, v, h, t[r + 1], 4, -1530992060)),
(h = a(h, d, p, v, t[r + 4], 11, 1272893353)),
(v = a(v, h, d, p, t[r + 7], 16, -155497632)),
(p = a(p, v, h, d, t[r + 10], 23, -1094730640)),
(d = a(d, p, v, h, t[r + 13], 4, 681279174)),
(h = a(h, d, p, v, t[r], 11, -358537222)),
(v = a(v, h, d, p, t[r + 3], 16, -722521979)),
(p = a(p, v, h, d, t[r + 6], 23, 76029189)),
(d = a(d, p, v, h, t[r + 9], 4, -640364487)),
(h = a(h, d, p, v, t[r + 12], 11, -421815835)),
(v = a(v, h, d, p, t[r + 15], 16, 530742520)),
(d = u(
d,
(p = a(p, v, h, d, t[r + 2], 23, -995338651)),
v,
h,
t[r],
6,
-198630844,
)),
(h = u(h, d, p, v, t[r + 7], 10, 1126891415)),
(v = u(v, h, d, p, t[r + 14], 15, -1416354905)),
(p = u(p, v, h, d, t[r + 5], 21, -57434055)),
(d = u(d, p, v, h, t[r + 12], 6, 1700485571)),
(h = u(h, d, p, v, t[r + 3], 10, -1894986606)),
(v = u(v, h, d, p, t[r + 10], 15, -1051523)),
(p = u(p, v, h, d, t[r + 1], 21, -2054922799)),
(d = u(d, p, v, h, t[r + 8], 6, 1873313359)),
(h = u(h, d, p, v, t[r + 15], 10, -30611744)),
(v = u(v, h, d, p, t[r + 6], 15, -1560198380)),
(p = u(p, v, h, d, t[r + 13], 21, 1309151649)),
(d = u(d, p, v, h, t[r + 4], 6, -145523070)),
(h = u(h, d, p, v, t[r + 11], 10, -1120210379)),
(v = u(v, h, d, p, t[r + 2], 15, 718787259)),
(p = u(p, v, h, d, t[r + 9], 21, -343485551)),
(d = n(d, c)),
(p = n(p, s)),
(v = n(v, l)),
(h = n(h, f)));
return [d, p, v, h];
}
function s(t) {
var e,
n = "",
r = 32 * t.length;
for (e = 0; e < r; e += 8)
n += String.fromCharCode((t[e >> 5] >>> (e % 32)) & 255);
return n;
}
function l(t) {
var e,
n = [];
for (n[(t.length >> 2) - 1] = void 0, e = 0; e < n.length; e += 1)
n[e] = 0;
var r = 8 * t.length;
for (e = 0; e < r; e += 8)
n[e >> 5] |= (255 & t.charCodeAt(e / 8)) << (e % 32);
return n;
}
function f(t) {
var e,
n,
r = "0123456789abcdef",
o = "";
for (n = 0; n < t.length; n += 1)
((e = t.charCodeAt(n)),
(o += r.charAt((e >>> 4) & 15) + r.charAt(15 & e)));
return o;
}
function d(t) {
return unescape(encodeURIComponent(t));
}
function p(t) {
return (function (t) {
return s(c(l(t), 8 * t.length));
})(d(t));
}
function v(t, e) {
return (function (t, e) {
var n,
r,
o = l(t),
i = [],
a = [];
for (
i[15] = a[15] = void 0,
o.length > 16 && (o = c(o, 8 * t.length)),
n = 0;
n < 16;
n += 1
)
((i[n] = 909522486 ^ o[n]), (a[n] = 1549556828 ^ o[n]));
return (
(r = c(i.concat(l(e)), 512 + 8 * e.length)),
s(c(a.concat(r), 640))
);
})(d(t), d(e));
}
function h(t, e, n) {
return e
? n
? v(e, t)
: (function (t, e) {
return f(v(t, e));
})(e, t)
: n
? p(t)
: (function (t) {
return f(p(t));
})(t);
}
t.exports ? (t.exports = h) : (e.md5 = h);
})(he);
})(Fe);
var je = _e(Fe.exports),
Be = "function" == typeof btoa,
Ve = "function" == typeof Buffer;
"function" == typeof TextDecoder && new TextDecoder();
var Ge,
Ke = "function" == typeof TextEncoder ? new TextEncoder() : void 0,
Qe = Array.prototype.slice.call(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
);
((Ge = {}),
Qe.forEach(function (t, e) {
return (Ge[t] = e);
}));
var Ye = String.fromCharCode.bind(String);
"function" == typeof Uint8Array.from && Uint8Array.from.bind(Uint8Array);
var We = Be
? function (t) {
return btoa(t);
}
: Ve
? function (t) {
return Buffer.from(t, "binary").toString("base64");
}
: function (t) {
for (
var e, n, r, o, i = "", a = t.length % 3, u = 0;
u < t.length;
) {
if (
(n = t.charCodeAt(u++)) > 255 ||
(r = t.charCodeAt(u++)) > 255 ||
(o = t.charCodeAt(u++)) > 255
)
throw new TypeError("invalid character found");
i +=
Qe[((e = (n << 16) | (r << 8) | o) >> 18) & 63] +
Qe[(e >> 12) & 63] +
Qe[(e >> 6) & 63] +
Qe[63 & e];
}
return a ? i.slice(0, a - 3) + "===".substring(a) : i;
},
Je = Ve
? function (t) {
return Buffer.from(t).toString("base64");
}
: function (t) {
for (var e = [], n = 0, r = t.length; n < r; n += 4096)
e.push(Ye.apply(null, t.subarray(n, n + 4096)));
return We(e.join(""));
},
He = function (t) {
if (t.length < 2)
return (e = t.charCodeAt(0)) < 128
? t
: e < 2048
? Ye(192 | (e >>> 6)) + Ye(128 | (63 & e))
: Ye(224 | ((e >>> 12) & 15)) +
Ye(128 | ((e >>> 6) & 63)) +
Ye(128 | (63 & e));
var e =
65536 + 1024 * (t.charCodeAt(0) - 55296) + (t.charCodeAt(1) - 56320);
return (
Ye(240 | ((e >>> 18) & 7)) +
Ye(128 | ((e >>> 12) & 63)) +
Ye(128 | ((e >>> 6) & 63)) +
Ye(128 | (63 & e))
);
},
ze = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,
$e = Ve
? function (t) {
return Buffer.from(t, "utf8").toString("base64");
}
: Ke
? function (t) {
return Je(Ke.encode(t));
}
: function (t) {
return We(
(function (t) {
return t.replace(ze, He);
})(t),
);
};
var Xe = Object.defineProperty,
Ze = Object.getOwnPropertyDescriptor,
tn = function (t, e, n, r) {
for (
var o, i = r > 1 ? void 0 : r ? Ze(e, n) : e, a = t.length - 1;
a >= 0;
a--
)
(o = t[a]) && (i = (r ? o(e, n, i) : o(i)) || i);
return (r && i && Xe(e, n, i), i);
},
en = (function () {
function t(e) {
var n = this;
(f(this, t),
(this.cgiBatchSize = S.cgiBatchSize),
(this.reportThreshold = S.reportThreshold),
(this.reportDelay = S.reportDelay),
(this.triggerExecuteSend = (function (t) {
var e,
n =
arguments.length > 1 && void 0 !== arguments[1]
? arguments[1]
: 0,
r = [];
return function () {
for (var o = arguments.length, i = new Array(o), a = 0; a < o; a++)
i[a] = arguments[a];
return (
clearTimeout(e),
(e = setTimeout(function () {
var e = t.apply(void 0, i);
(r.forEach(function (t) {
return t(e);
}),
(r = []));
}, n)),
new Promise(function (t) {
return r.push(t);
})
);
};
})(function () {
n.executeSend();
}, 1e3 * this.reportDelay)),
(this.inspectDelay = S.inspectDelay),
(this.inspectTimer = void 0),
(this.isNeedContinueSend = !1),
(this.getBaseInfo = e.getBaseInfo),
(this.reportLog = e.reportLog),
(this.queueManager = e.queueManager),
(this.configManager = e.configManager),
(this.onReportComplete = e.onReportComplete),
(this.onReportFail = e.onReportFail),
this.flushSend(),
this.startInspectTimer());
}
return (
p(
t,
[
{
key: "batchSend",
value: function () {
var t,
e = this.queueManager.getReportableActions(
this.reportThreshold,
);
if (e.length >= this.reportThreshold) this.executeSend();
else {
var n =
(null == (t = this.configManager)
? void 0
: t.getRealTimeActionList()) || S.realTimeActionList;
e.some(function (t) {
return n.indexOf(t.action_type) > -1 && !t.is_retry;
})
? this.executeSend()
: this.triggerExecuteSend();
}
this.startInspectTimer();
},
},
{
key: "flushSend",
value: function () {
this.executeSend();
},
},
{
key: "executeSend",
value: function () {
var e = this;
if (!qt.hasDirectGameMask)
if (t.currentRequestCount >= t.requestConcurrency)
this.isNeedContinueSend = !0;
else {
this.isNeedContinueSend = !1;
var n =
(t.requestConcurrency - t.currentRequestCount) *
this.cgiBatchSize,
r = this.queueManager.getReportableActions(n),
o = this.getBaseInfo();
if (
(!o.openid &&
!o.unionid &&
(xt.warn(
"请尽快调用 setOpenId 或 setUnionId 方法设置用户ID!",
),
(r = r.filter(function (t) {
return null == t ? void 0 : t.ad_trace_id;
}))),
!(r.length <= 0))
) {
(n < this.queueManager.getReportableActionsLength() &&
(this.isNeedContinueSend = !0),
(t.currentRequestCount += Math.ceil(
r.length / this.cgiBatchSize,
)));
for (
var i = [], a = 0;
a < r.length;
a += this.cgiBatchSize
) {
var u = this.generateActionReportParams(
r.slice(a, a + this.cgiBatchSize),
);
i.push(this.report(u));
}
Promise.all(i)
.then(function (t) {
var n = t.some(function (t) {
return t >= 0;
});
e.isNeedContinueSend && n && e.executeSend();
})
.catch(function (t) {
(xt.error(t),
e.reportLog({
message: "executeSend catch: ".concat(t.message),
log_type: b.JS_RUN_ERROR,
err_stack: t.stack,
}));
});
}
}
},
},
{
key: "generateActionReportParams",
value: function (t) {
var e = [],
n = [],
r = this.getBaseInfo();
return (
t.forEach(function (t) {
n.push(t.action_id);
var r = Object.assign({}, t);
(delete r.inner_status, e.push(r));
}),
{ data: { info: r, actions: e }, actionIdList: n }
);
},
},
{
key: "dealSuccessData",
value: function (t, e, n) {
([51001, 51003].indexOf(null == t ? void 0 : t.code) > -1
? this.queueManager.updateActionsForReportFail(e)
: this.queueManager.removeActions(e),
0 !== (null == t ? void 0 : t.code) &&
(this.reportLog({
log_type: b.REQUEST_ERROR,
code: null == t ? void 0 : t.code,
message: "trace_id: "
.concat(null == t ? void 0 : t.trace_id, ",msg: ")
.concat(null == t ? void 0 : t.message),
}),
xt.error("上报失败:", t)),
this.doTrackCallbackFn(this.onReportComplete, t, n),
-1 === [0, 51001, 51003].indexOf(null == t ? void 0 : t.code) &&
this.doTrackCallbackFn(this.onReportFail, t, n));
},
},
{
key: "dealFailData",
value: function (t, e, n) {
(this.queueManager.updateActionsForReportFail(e),
this.reportLog({
log_type: b.REQUEST_ERROR,
code: t.code,
message: t.message,
}),
xt.error("上报失败:", t),
this.doTrackCallbackFn(this.onReportComplete, t, n));
},
},
{
key: "report",
value: function (e) {
var n = this,
r = e.data,
o = e.actionIdList;
return (
this.queueManager.updateActionsForReporting(o),
xt.debug &&
(xt.info(
"上报行为类型: ",
"【".concat(
r.actions
.map(function (t) {
return t.action_type;
})
.join("、"),
"】",
),
),
xt.info("上报请求参数: ", r)),
new Promise(function (e) {
var i,
a,
u,
c,
s,
f,
d,
p,
v = Date.now();
try {
var h = (function (t) {
var e = "",
n = null == t ? void 0 : t.appid,
r = null == t ? void 0 : t.secret_key,
o = null == t ? void 0 : t.sdk_version,
i = null == t ? void 0 : t.timestamp;
if (!(n && r && o && i && 32 === r.length)) return e;
for (var a = je(o + n + i), u = 0; u < 32; u++)
e += u % 2 == 0 ? r[u] : a[u];
return e;
})({
appid:
null == (i = null == r ? void 0 : r.info)
? void 0
: i.appid,
secret_key:
null == (a = null == r ? void 0 : r.info)
? void 0
: a.secret_key,
sdk_version:
null == (u = null == r ? void 0 : r.info)
? void 0
: u.sdk_version,
timestamp: v,
}),
_ = (function (t) {
return arguments.length > 1 &&
void 0 !== arguments[1] &&
arguments[1]
? (function (t) {
return t
.replace(/=/g, "")
.replace(/[+\/]/g, function (t) {
return "+" == t ? "-" : "_";
});
})($e(t))
: $e(t);
})(JSON.stringify(r));
((d = {
"Client-Time": v,
"Sign-Value": je(
_ +
(null == (c = null == r ? void 0 : r.info)
? void 0
: c.user_action_set_id) +
(null == (s = null == r ? void 0 : r.info)
? void 0
: s.secret_key) +
h,
),
"Sign-Version": S.signVersion,
"content-type": "text/plain;charset=UTF-8",
}),
(p = _));
} catch (h) {
((d = { "Client-Time": v }),
(p = r),
n.reportLog({
log_type: b.SIGN_ERROR,
message: "sign error msg: ".concat(
null == h ? void 0 : h.message,
),
err_stack: null == h ? void 0 : h.stack,
}),
xt.error(h));
}
wx.request({
url: "https://api.datanexus.qq.com/data-nexus-cgi/miniprogram",
method: "POST",
timeout:
(null == (f = n.configManager)
? void 0
: f.getRequestTimeout()) || S.requestTimeout,
header: d,
data: p,
success: function (i) {
var a, u;
xt.devLog(
"上报接口返回码:",
null == (a = null == i ? void 0 : i.data)
? void 0
: a.code,
);
var c =
(null == (u = null == i ? void 0 : i.header)
? void 0
: u["Server-Time"]) || -1;
if (
(st.revise(c),
(t.currentRequestCount -= 1),
200 === (null == i ? void 0 : i.statusCode))
)
return (
n.dealSuccessData(null == i ? void 0 : i.data, o, r),
void e((null == i ? void 0 : i.data).code)
);
var s = "";
try {
s =
"object" == l(null == i ? void 0 : i.data)
? JSON.stringify(null == i ? void 0 : i.data)
: null == i
? void 0
: i.data;
} catch (t) {
xt.error(t);
}
var f = {
code:
"number" == typeof (null == i ? void 0 : i.statusCode)
? -1 * i.statusCode
: -888,
message: "statusCode: "
.concat(null == i ? void 0 : i.statusCode, ", data: ")
.concat(s),
};
(n.dealFailData(f, o, r), e(f.code));
},
fail: function (i) {
(xt.devLog("上报失败:", i), (t.currentRequestCount -= 1));
var a = {
code:
"number" == typeof (null == i ? void 0 : i.errno)
? -1 * i.errno
: -999,
message: null == i ? void 0 : i.errMsg,
};
(n.dealFailData(a, o, r), e(a.code));
},
});
})
);
},
},
{
key: "startInspectTimer",
value: function () {
var e = this;
(clearTimeout(this.inspectTimer),
(this.inspectTimer = setTimeout(function () {
(t.currentRequestCount >= t.requestConcurrency &&
(t.currentRequestCount = t.requestConcurrency - 1),
e.executeSend(),
e.startInspectTimer());
}, 1e3 * this.inspectDelay)));
},
},
{
key: "doTrackCallbackFn",
value: function (t, e, n) {
if ("function" == typeof t)
try {
for (var r = [], o = 0; o < n.actions.length; o++)
if (!n.actions[o].is_sdk_auto_track) {
var i = n.actions[o],
a = i.action_type,
u = i.action_param,
c = i.action_id,
s = i.action_time;
r.push({
action_type: a,
action_param: u,
action_id: c,
action_time: s,
});
}
if (r.length) {
var l = n.info,
f = l.user_action_set_id,
d = l.appid,
p = l.openid,
v = l.unionid,
h = l.user_unique_id;
t({
code: null == e ? void 0 : e.code,
message: null == e ? void 0 : e.message,
data: {
actions: r,
info: {
user_action_set_id: f,
appid: d,
openid: p,
unionid: v,
user_unique_id: h,
},
},
});
}
} catch (r) {
xt.error("返回上报回调数据异常:", r);
}
},
},
],
[
{
key: "setRequestConcurrency",
value: function (e) {
"number" == typeof e
? e < 1
? xt.error("网络请求最大并发量不能小于1")
: e > 10
? xt.error("网络请求最大并发量不能大于10")
: (t.requestConcurrency = e)
: xt.error("网络请求最大并发量需设置为数字");
},
},
],
),
t
);
})(),
nn = en;
((nn.currentRequestCount = 0),
(nn.requestConcurrency = S.requestConcurrency),
tn([Lt], nn.prototype, "batchSend", 1),
tn([Lt], nn.prototype, "flushSend", 1),
tn([Lt], nn.prototype, "executeSend", 1));
var rn = Wt,
on = Jt,
an = Ht,
un = zt,
cn = $t,
sn = ie,
ln = Xt,
fn = Zt,
dn = te,
pn = ne,
vn = oe,
hn = re,
_n = ee,
yn = (function () {
function e() {
f(this, e);
}
return (
p(e, [
{
key: "install",
value: function (e, n) {
var r = function (n) {
Qt.subscribe(
n,
(function (n) {
var r =
arguments.length > 1 && void 0 !== arguments[1]
? arguments[1]
: {};
return function (o) {
var i =
arguments.length > 1 && void 0 !== arguments[1]
? arguments[1]
: {};
qt.hasDirectGameMask ||
("ENTER_FOREGROUND" === n &&
(qt.activeDuration = Date.now()),
e.track(
n,
Object.assign(r || {}, i, t(t({}, wn, !0), Cn, o)),
));
};
})(n),
);
};
(r(on),
r(rn),
r(an),
r(un),
"all" === n &&
(r(cn),
r(sn),
r(ln),
r(dn),
r(fn),
r(_n),
r(pn),
r(vn),
r(hn)));
},
},
]),
e
);
})(),
gn = (function () {
function e() {
(f(this, e),
(this.special_method_symbol = Symbol("special_method_symbol")));
}
return (
p(e, [
{
key: "onPurchase",
value: function (t) {
return (
"number" != typeof t && xt.warn("付费金额需要为数字"),
t <= 0 && xt.warn("付费金额需要大于0"),
this.wrapTrack(F, { value: t })
);
},
},
{
key: "onEnterForeground",
value: function () {
return this.wrapTrack(D);
},
},
{
key: "onEnterBackground",
value: function () {
return this.wrapTrack(U);
},
},
{
key: "onAppStart",
value: function () {
return this.wrapTrack(M);
},
},
{
key: "onAppQuit",
value: function () {
return this.wrapTrack(j);
},
},
{
key: "onAddToWishlist",
value: function () {
return this.wrapTrack(q);
},
},
{
key: "wrapTrack",
value: function (e, n) {
return this.track(
e,
Object.assign(n || {}, t({}, this.special_method_symbol, 1)),
);
},
},
]),
e
);
})(),
mn = (function (t) {
o(n, gn);
var e = a(n);
function n() {
return (f(this, n), e.apply(this, arguments));
}
return (
p(n, [
{
key: "onRegister",
value: function () {
return this.wrapTrack(B);
},
},
{
key: "onCreateRole",
value: function (t) {
return (
t && "string" != typeof t && xt.warn("角色名称需要为字符串"),
this.wrapTrack(V, t ? { name: t } : {})
);
},
},
{
key: "onTutorialFinish",
value: function () {
return this.wrapTrack(G);
},
},
]),
n
);
})(),
An = "(如果确认无误,请忽略该提示)",
Rn = (function () {
var t = [];
return {
requestActionList: function () {
try {
lt({ conf_name: "data_nexus_common", conf_key: "action_types" }).then(
function (e) {
_t(e) && (t = e);
},
);
} catch (t) {
xt.error(t);
}
},
getActionList: function () {
return t;
},
};
})();
function kn(t, e) {
try {
t.is_sdk_auto_track ||
((function (t) {
try {
var e = Rn.getActionList();
if (!e.includes(t)) {
var r,
o = (function (t, e) {
var r =
("undefined" != typeof Symbol && t[Symbol.iterator]) ||
t["@@iterator"];
if (!r) {
if (
Array.isArray(t) ||
(r = n(t)) ||
(e && t && "number" == typeof t.length)
) {
r && (t = r);
var o = 0,
i = function () {};
return {
s: i,
n: function () {
return o >= t.length
? { done: !0 }
: { done: !1, value: t[o++] };
},
e: function (t) {
throw t;
},
f: i,
};
}
throw new TypeError(
"Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.",
);
}
var a,
u = !0,
c = !1;
return {
s: function () {
r = r.call(t);
},
n: function () {
var t = r.next();
return ((u = t.done), t);
},
e: function (t) {
((c = !0), (a = t));
},
f: function () {
try {
u || null == r.return || r.return();
} finally {
if (c) throw a;
}
},
};
})(e);
try {
for (o.s(); !(r = o.n()).done; ) {
var i = r.value;
if (Tn(i, t) <= parseInt((0.3 * i.length).toString())) {
xt.warn(
"通过SDK上报的"
.concat(
t,
"行为名称可能有误,请检查该行为类型是否为腾讯广告提供的标准行为!",
)
.concat(An),
);
break;
}
}
} catch (t) {
o.e(t);
} finally {
o.f();
}
}
} catch (e) {
xt.error(e);
}
})(t.action_type),
"minigame" === e
? (function (t, e) {
var n, r, o;
try {
["PURCHASE", "ADD_TO_CART"].includes(t.action_type) &&
t.action_param &&
It(t.action_param, "value") &&
("number" !=
typeof (null == (n = t.action_param) ? void 0 : n.value)
? xt.warn(
"通过SDK上报的".concat(
t.action_type,
"行为携带的金额参数需要为数字!",
),
)
: (null == (r = t.action_param) ? void 0 : r.value) <= 0
? xt.warn(
"通过SDK上报的".concat(
t.action_type,
"行为携带的金额参数需要大于0!",
),
)
: "minigame" === e &&
(null == (o = t.action_param) ? void 0 : o.value) < 100 &&
xt.warn(
"通过SDK上报的"
.concat(
t.action_type,
"行为携带的金额参数可能有误,金额的单位为‘分’,请检查金额是否正确!",
)
.concat(An),
));
} catch (t) {
xt.error(t);
}
})(t, e)
: "miniprogram" === e &&
(function (t) {
try {
var e = null == t ? void 0 : t.action_type,
n = (null == t ? void 0 : t.action_param) || {};
"PURCHASE" === e &&
It(n, "value") &&
("number" != typeof (null == n ? void 0 : n.value)
? xt.warn(
"通过SDK上报的".concat(
e,
"行为携带的金额参数需要为数字!",
),
)
: (null == n ? void 0 : n.value) <= 0 &&
xt.warn(
"通过SDK上报的".concat(
e,
"行为携带的金额参数需要大于0!",
),
));
} catch (e) {
xt.error(e);
}
})(t));
} catch (t) {
xt.error(t);
}
}
function Tn(t, e) {
try {
if (0 === t.length) return e.length;
if (0 === e.length) return t.length;
for (var n = [], r = 0; r <= e.length; r++) n[r] = [r];
for (var o = 0; o <= t.length; o++) n[0][o] = o;
for (var i = 1; i <= e.length; i++)
for (var a = 1; a <= t.length; a++)
e.charAt(i - 1) === t.charAt(a - 1)
? (n[i][a] = n[i - 1][a - 1])
: (n[i][a] = Math.min(
n[i - 1][a - 1] + 1,
n[i][a - 1] + 1,
n[i - 1][a] + 1,
));
return n[e.length][t.length];
} catch (n) {
xt.error(n);
}
}
function En(t) {
try {
t &&
!/^[a-zA-Z0-9_\-]+$/.test(t) &&
xt.warn(
"通过SDK上报的openid:"
.concat(t, "可能有误,请检查openid是否正确!")
.concat(An),
);
} catch (t) {
xt.error(t);
}
}
var Sn = Object.defineProperty,
bn = Object.getOwnPropertyDescriptor,
On = function (t, e, n, r) {
for (
var o, i = r > 1 ? void 0 : r ? bn(e, n) : e, a = t.length - 1;
a >= 0;
a--
)
(o = t[a]) && (i = (r ? o(e, n, i) : o(i)) || i);
return (r && i && Sn(e, n, i), i);
},
In = Symbol("initializedInstance"),
wn = Symbol("autoTrack"),
Cn = Symbol("actionTime"),
xn = (function (e) {
o(r, mn);
var n = a(r);
function r(t) {
var e;
if (
(f(this, r),
((e = n.call(this)).env = "production"),
(e.sdk_version = "1.5.6"),
(e.sdk_name = "@dn-sdk/minigame"),
(e.deviceInfo = {}),
(e.gameInfo = {}),
(e.session_id = ""),
(e.log_id = 0),
(e.inited = !1),
(e.initErrMsg = ""),
null == wx || !wx.createCanvas)
)
return (
(e.initErrMsg = "不支持非微信小游戏中使用"),
xt.error(e.initErrMsg),
u(e)
);
var o = Ot();
if (r[In].length >= o.maxSdkInstance)
return (
(e.initErrMsg = "初始化超过上限"),
xt.error(e.initErrMsg),
u(e)
);
var i = St(t),
a = at();
if (!0 !== i) return ((e.initErrMsg = i), xt.error(i), u(e));
var s = null == a ? void 0 : a.appId;
if (s && s !== t.appid)
return (
(e.initErrMsg = "初始化传入的appid与当前小游戏appid不一致"),
xt.error(e.initErrMsg),
u(e)
);
((e.config = t),
It(t, "auto_track") || (e.config.auto_track = bt("autoTrack")),
(e.openid = t.openid),
(e.unionid = t.unionid),
(e.user_unique_id = t.user_unique_id),
(e.onReportComplete = t.on_report_complete),
(e.onReportFail = t.on_report_fail),
e.saveValidOpenidToStorage());
var l = t.user_action_set_id;
return r[In].includes(l)
? ((e.initErrMsg = "同个数据源[".concat(l, "]只能初始化一次")),
xt.error(e.initErrMsg),
e.reportLog({ log_type: b.JS_RUN_ERROR, message: e.initErrMsg }),
u(e))
: ((e.reportLog = e.reportLog.bind(c(e))),
(e.getTrackBaseInfo = e.getTrackBaseInfo.bind(c(e))),
(qt.activeDuration = Date.now()),
(e.deviceInfo = nt()),
(e.gameInfo = Nt()),
(e.session_id = mt()),
(e.queueManage = new Vt({
userActionSetId: l,
maxLength: o.maxQueueLength,
ogEvents: Yt,
})),
(e.actionReporter = new nn({
getBaseInfo: e.getTrackBaseInfo,
reportLog: e.reportLog,
queueManager: e.queueManage,
configManager: se,
onReportComplete: e.onReportComplete,
onReportFail: e.onReportFail,
})),
(e.inited = !0),
r[In].push(l),
e.useAutoTrack(),
e.doReportOnEnterBackground(),
"release" === (null == a ? void 0 : a.envVersion)
? (xt.info("初始化成功"), u(e))
: ((function (t) {
var e = t.conf_name,
n = t.conf_key,
r = t.sdk_version,
o = t.default_download_url,
i = t.fail_handler;
lt({ conf_name: e, conf_key: n })
.then(function (t) {
if (ht(t)) {
var e = null == t ? void 0 : t.blackVersions,
n = null == t ? void 0 : t.minVersion,
a = null == t ? void 0 : t.bestVersion,
u = null == t ? void 0 : t.downloadUrl,
c = o;
return (
u && /^https/.test(u) && (c = u),
_t(e) && (null == e ? void 0 : e.indexOf(r)) > -1
? (null == i || i(),
void xt.error(
"初始化失败!当前SDK版本存在兼容问题,请尽快升级至最新版!下载地址:".concat(
c,
),
))
: n && Et(r, n) < 0
? (null == i || i(),
void xt.error(
"初始化失败!当前SDK版本过低,请尽快升级至最新版!下载地址:".concat(
c,
),
))
: (a &&
Et(r, a) < 0 &&
xt.warn(
"新版本SDK已上线,强烈建议您升级至最新版,尽早享受新特性!下载地址:".concat(
c,
),
),
void xt.info("初始化成功"))
);
}
xt.info("初始化成功");
})
.catch(function () {
xt.info("初始化成功");
});
})({
conf_name: "mini_game_sdk_common",
conf_key: "version",
sdk_version: e.sdk_version,
default_download_url:
"https://sr-home-1257214331.cos.ap-guangzhou.myqcloud.com/sdk/dn-sdk-minigame/dn-sdk-minigame.zip",
fail_handler: function () {
e.inited = !1;
},
}),
Rn.requestActionList(),
En(t.openid),
u(e)));
}
return (
p(
r,
[
{
key: "getInitResult",
value: function () {
return { inited: this.inited, initErrMsg: this.initErrMsg };
},
},
{
key: "track",
value: function (t, e) {
var n, r;
if (!this.inited || !this.queueManage)
return (
xt.error("上报失败,请先完成初始化"),
{
code: 100,
message:
"未完成初始化或重复初始化导致初始化失败,请先完成初始化",
}
);
var o = qe.validateActionType(t),
i = qe.validateActionParam(e);
if (o && i) {
!this.openid &&
!this.unionid &&
xt.warn("缺少 openid 或 unionid");
var a = bt("actionParamMaxLength");
if (JSON.stringify(e || {}).length > a)
return (
xt.error(
"监测到超过"
.concat(a, "的上报日志:")
.concat(t, " ")
.concat(e),
),
{
code: 102,
message: "action_param 参数过大,不能超过 ".concat(
a,
" 字符",
),
}
);
var u = !(null == e || !e[wn]),
c = this.createAction(t, e || {}, u);
"release" !== (null == (n = at()) ? void 0 : n.envVersion) &&
kn(c, "minigame");
var s = this.queueManage.addAction(c);
return (null == (r = this.actionReporter) || r.batchSend(), s);
}
return {
code: 101,
message: "action_type 或 action_param 参数错误",
};
},
},
{
key: "flush",
value: function () {
var t;
null == (t = this.actionReporter) || t.flushSend();
},
},
{
key: "setOpenId",
value: function (t) {
var e;
if (t && "string" == typeof t)
return (
(this.openid = t),
this.gameInfo.ad_trace_id &&
!tt.getSync(T) &&
Qt.publish("START_APP"),
this.flush(),
this.saveValidOpenidToStorage(),
"release" !== (null == (e = at()) ? void 0 : e.envVersion) &&
En(t),
{ code: 0, message: "成功" }
);
var n = "openid 格式错误";
return (xt.error(n), { code: 101, message: n });
},
},
{
key: "setUnionId",
value: function (t) {
if (t && "string" == typeof t)
return (
(this.unionid = t),
this.flush(),
{ code: 0, message: "成功" }
);
var e = "unionid 格式错误";
return (xt.error(e), { code: 101, message: e });
},
},
{
key: "setUserUniqueId",
value: function (t) {
if (t && "string" == typeof t)
return (
(this.user_unique_id = t),
{ code: 0, message: "成功" }
);
var e = "user_unique_id 格式错误";
return (xt.error(e), { code: 101, message: e });
},
},
{
key: "doReportOnEnterBackground",
value: function () {
var t = this;
wx.onHide(function () {
var e, n;
(null == (e = t.actionReporter) || e.flushSend(),
null == (n = t.queueManage) || n.reportLostNum());
});
},
},
{
key: "getTrackBaseInfo",
value: function () {
var t = at();
return Object.assign(
{},
this.deviceInfo,
(function (t, e) {
var n = {};
return (
e.forEach(function (e) {
It(t, e) && (n[e] = t[e]);
}),
n
);
})(this.config, [
"user_action_set_id",
"appid",
"openid",
"secret_key",
"user_unique_id",
"unionid",
]),
{
local_id: rt(),
sdk_name: this.sdk_name,
sdk_version: this.sdk_version,
openid: this.openid || it(),
unionid: this.unionid,
user_unique_id: this.user_unique_id,
inner_param: {
app_env_version: t.envVersion,
app_version: t.version,
},
},
);
},
},
{
key: "createAction",
value: function (t, e) {
var n =
arguments.length > 2 && void 0 !== arguments[2] && arguments[2];
null != e && e[wn] && delete e[wn];
var r = Date.now();
null != e &&
e[Cn] &&
((r = null == e ? void 0 : e[Cn]), delete e[Cn]);
var o = {
action_id: mt(),
action_param: e,
action_time: r,
action_type: t,
is_retry: !1,
is_sdk_auto_track: n,
retry_count: 0,
revised_action_time: st.getRevisedcurrentTimeMillis(),
log_id: ++this.log_id,
session_id: this.session_id,
pkg_channel_id: this.gameInfo.pkg_channel_id,
source_scene: this.gameInfo.source_scene,
network_type: ot(),
ad_trace_id: this.gameInfo.ad_trace_id,
channel: this.getChannelByActionType(t),
};
return (
null != e &&
e[this.special_method_symbol] &&
(this.addActionInnerParam(o, "is_special_method", !0),
delete e[this.special_method_symbol]),
se.getChannelClaimActionList().indexOf(t) > -1 &&
this.gameInfo.launch_options &&
this.addActionInnerParam(
o,
"launch_options",
this.gameInfo.launch_options,
),
o
);
},
},
{
key: "addActionInnerParam",
value: function (e, n, r) {
e.inner_param && ht(e.inner_param)
? (e.inner_param[n] = r)
: (e.inner_param = t({}, n, r));
},
},
{
key: "getChannelByActionType",
value: function (t) {
var e = "";
return (
se.getChannelClaimActionList().indexOf(t) > -1
? (e = this.gameInfo.channel || "")
: se.getNoClaimActionList().indexOf(t) > -1 && (e = X),
e
);
},
},
{
key: "reportLog",
value: function (t) {
var e,
n,
r = {
user_action_set_id:
null == (e = this.config) ? void 0 : e.user_action_set_id,
appid: null == (n = this.config) ? void 0 : n.appid,
session_id: this.session_id,
};
ct(Object.assign(r, t));
},
},
{
key: "useAutoTrack",
value: function () {
var t;
if (null != (t = this.config) && t.auto_track) {
var e = !0,
n = tt.getSync(R);
((null == n ? void 0 : n.ap) === K
? (e = !0)
: (null == n ? void 0 : n.ap) === Q && (e = !1),
"devtools" === nt().wx_platform && (e = !0),
new yn().install(this, e ? "all" : "lifecycle"),
ve(),
e && Le(),
this.getAutoProxyRemoteConfig());
}
},
},
{
key: "getAutoProxyRemoteConfig",
value: function () {
var t,
e,
n = nt();
n.os &&
n.os_version &&
null != (t = this.config) &&
t.user_action_set_id &&
(function (t) {
return new Promise(function (e) {
wx.request({
method: "POST",
url: "https://api.datanexus.qq.com/data-nexus-config/v1/sdk/minigame/get",
data: t,
timeout: S.requestTimeout,
success: function (t) {
(ft(t, e, "minigame/get"), pt(t));
},
fail: function (t) {
dt(t, "minigame/get");
},
});
});
})({
conf_name: "MG",
conf_param: {
user_action_set_id:
null == (e = this.config) ? void 0 : e.user_action_set_id,
sdk_version: this.sdk_version,
os_type: (null == n ? void 0 : n.os) || "",
os_version: wt(n.os_version),
device_brand: (null == n ? void 0 : n.device_brand) || "",
weixin_lib_version:
(null == n ? void 0 : n.wx_lib_version) || "",
weixin_version: (null == n ? void 0 : n.wx_version) || "",
},
}).then(function (t) {
ht(t) && tt.setSync(R, t);
});
},
},
{
key: "saveValidOpenidToStorage",
value: function () {
this.openid &&
(function (t) {
return /^[a-zA-Z0-9_-]{28,30}$/.test(t);
})(this.openid) &&
tt.setSync(T, this.openid);
},
},
],
[
{
key: "setRequestConcurrency",
value: function (t) {
nn.setRequestConcurrency(t);
},
},
{
key: "setDebug",
value: function (t) {
xt.debug = t;
},
},
],
),
r
);
})(),
Nn = xn;
((Nn[In] = []),
On([Lt], Nn.prototype, "track", 1),
On(
[
Lt,
function (t, e, n) {
var r = n.value;
return (
(n.value = function () {
if (this.inited) {
for (
var t = arguments.length, e = new Array(t), n = 0;
n < t;
n++
)
e[n] = arguments[n];
return r.apply(this, e);
}
xt.error("上报失败,请先完成初始化");
}),
n
);
},
],
Nn.prototype,
"flush",
1,
),
On([Lt], Nn.prototype, "setOpenId", 1),
On([Lt], Nn.prototype, "setUnionId", 1),
On([Lt], Nn.prototype, "setUserUniqueId", 1),
On([Lt], Nn.prototype, "doReportOnEnterBackground", 1),
On([Lt], Nn.prototype, "getTrackBaseInfo", 1),
On([Lt], Nn.prototype, "useAutoTrack", 1));
export { Nn as SDK };