mon-reactive-h5 1.0.6
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/LICENSE +21 -0
- package/README.md +310 -0
- package/dist/BatchReporter.d.ts +56 -0
- package/dist/BatchReporter.js +231 -0
- package/dist/BatchReporter.js.map +1 -0
- package/dist/MonitorSDK.d.ts +141 -0
- package/dist/MonitorSDK.js +913 -0
- package/dist/MonitorSDK.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +150 -0
- package/dist/index.js.map +1 -0
- package/dist/packages/basic-sdk.d.ts +18 -0
- package/dist/packages/basic-sdk.js +73 -0
- package/dist/packages/basic-sdk.js.map +1 -0
- package/dist/packages/index.d.ts +16 -0
- package/dist/packages/index.js +98 -0
- package/dist/packages/index.js.map +1 -0
- package/dist/packages/premium-sdk.d.ts +69 -0
- package/dist/packages/premium-sdk.js +236 -0
- package/dist/packages/premium-sdk.js.map +1 -0
- package/dist/packages/standard-sdk.d.ts +22 -0
- package/dist/packages/standard-sdk.js +78 -0
- package/dist/packages/standard-sdk.js.map +1 -0
- package/dist/reporters.d.ts +32 -0
- package/dist/reporters.js +204 -0
- package/dist/reporters.js.map +1 -0
- package/dist/types.d.ts +120 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
5
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
7
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
8
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
9
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
10
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
11
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
12
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
13
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
14
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
15
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
16
|
+
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
17
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
18
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
19
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
20
|
+
function _inherits(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 && _setPrototypeOf(t, e); }
|
|
21
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
22
|
+
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
23
|
+
return mod && mod.__esModule ? mod : {
|
|
24
|
+
"default": mod
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", {
|
|
28
|
+
value: true
|
|
29
|
+
});
|
|
30
|
+
exports.PremiumSDK = void 0;
|
|
31
|
+
exports.createPremiumSDK = createPremiumSDK;
|
|
32
|
+
var MonitorSDK_1 = __importDefault(require("../MonitorSDK"));
|
|
33
|
+
/**
|
|
34
|
+
* 高级版SDK
|
|
35
|
+
* 包含所有监控功能,并添加高级特性
|
|
36
|
+
*/
|
|
37
|
+
var PremiumSDK = /*#__PURE__*/function (_MonitorSDK_1$default) {
|
|
38
|
+
function PremiumSDK(config) {
|
|
39
|
+
var _this;
|
|
40
|
+
_classCallCheck(this, PremiumSDK);
|
|
41
|
+
_this = _callSuper(this, PremiumSDK, [Object.assign(Object.assign({}, config), {
|
|
42
|
+
// 高级版默认配置:更高的采样率
|
|
43
|
+
sampleRates: Object.assign({
|
|
44
|
+
pageview: 1,
|
|
45
|
+
jserror: 1,
|
|
46
|
+
api: 0.5,
|
|
47
|
+
resource: 0.8,
|
|
48
|
+
custom: 0.8
|
|
49
|
+
}, config.sampleRates)
|
|
50
|
+
})]);
|
|
51
|
+
_this.customEvents = {};
|
|
52
|
+
_this.performanceMetrics = {};
|
|
53
|
+
_this.userId = config.userId;
|
|
54
|
+
_this.initAdvancedFeatures();
|
|
55
|
+
console.log('PremiumSDK initialized for app:', config.appId);
|
|
56
|
+
return _this;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 初始化高级特性
|
|
60
|
+
*/
|
|
61
|
+
_inherits(PremiumSDK, _MonitorSDK_1$default);
|
|
62
|
+
return _createClass(PremiumSDK, [{
|
|
63
|
+
key: "initAdvancedFeatures",
|
|
64
|
+
value: function initAdvancedFeatures() {
|
|
65
|
+
this.initUserTracking();
|
|
66
|
+
this.initCustomPerformanceMonitoring();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 初始化用户追踪
|
|
70
|
+
*/
|
|
71
|
+
}, {
|
|
72
|
+
key: "initUserTracking",
|
|
73
|
+
value: function initUserTracking() {
|
|
74
|
+
// 尝试从localStorage获取用户ID
|
|
75
|
+
if (!this.userId) {
|
|
76
|
+
var storedUserId = localStorage.getItem('monitor_sdk_user_id');
|
|
77
|
+
if (storedUserId) {
|
|
78
|
+
this.userId = storedUserId;
|
|
79
|
+
} else {
|
|
80
|
+
// 生成新的用户ID并存储
|
|
81
|
+
this.userId = this.generateUserId();
|
|
82
|
+
localStorage.setItem('monitor_sdk_user_id', this.userId);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 生成用户ID
|
|
88
|
+
*/
|
|
89
|
+
}, {
|
|
90
|
+
key: "generateUserId",
|
|
91
|
+
value: function generateUserId() {
|
|
92
|
+
return "user_".concat(Date.now(), "_").concat(Math.random().toString(36).substring(2, 15));
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 初始化自定义性能监控
|
|
96
|
+
*/
|
|
97
|
+
}, {
|
|
98
|
+
key: "initCustomPerformanceMonitoring",
|
|
99
|
+
value: function initCustomPerformanceMonitoring() {
|
|
100
|
+
// 预留自定义性能监控接口
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 设置用户ID
|
|
104
|
+
*/
|
|
105
|
+
}, {
|
|
106
|
+
key: "setUserId",
|
|
107
|
+
value: function setUserId(userId) {
|
|
108
|
+
this.userId = userId;
|
|
109
|
+
localStorage.setItem('monitor_sdk_user_id', userId);
|
|
110
|
+
console.log('User ID set:', userId);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 获取用户ID
|
|
114
|
+
*/
|
|
115
|
+
}, {
|
|
116
|
+
key: "getUserId",
|
|
117
|
+
value: function getUserId() {
|
|
118
|
+
return this.userId;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* 记录自定义性能指标
|
|
122
|
+
*/
|
|
123
|
+
}, {
|
|
124
|
+
key: "recordPerformanceMetric",
|
|
125
|
+
value: function recordPerformanceMetric(metricName, value) {
|
|
126
|
+
if (!this.performanceMetrics[metricName]) {
|
|
127
|
+
this.performanceMetrics[metricName] = [];
|
|
128
|
+
}
|
|
129
|
+
this.performanceMetrics[metricName].push(value);
|
|
130
|
+
// 每5个指标上报一次统计数据
|
|
131
|
+
if (this.performanceMetrics[metricName].length >= 5) {
|
|
132
|
+
this.reportPerformanceMetric(metricName);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* 上报性能指标
|
|
137
|
+
*/
|
|
138
|
+
}, {
|
|
139
|
+
key: "reportPerformanceMetric",
|
|
140
|
+
value: function reportPerformanceMetric(metricName) {
|
|
141
|
+
var values = this.performanceMetrics[metricName];
|
|
142
|
+
if (!values || values.length === 0) return;
|
|
143
|
+
var avgValue = values.reduce(function (sum, val) {
|
|
144
|
+
return sum + val;
|
|
145
|
+
}, 0) / values.length;
|
|
146
|
+
var maxValue = Math.max.apply(Math, _toConsumableArray(values));
|
|
147
|
+
var minValue = Math.min.apply(Math, _toConsumableArray(values));
|
|
148
|
+
this.reportCustomEvent('performance_metric', {
|
|
149
|
+
metricName: metricName,
|
|
150
|
+
avgValue: avgValue,
|
|
151
|
+
maxValue: maxValue,
|
|
152
|
+
minValue: minValue,
|
|
153
|
+
count: values.length
|
|
154
|
+
});
|
|
155
|
+
// 清空已上报的数据
|
|
156
|
+
this.performanceMetrics[metricName] = [];
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* 开始计时
|
|
160
|
+
*/
|
|
161
|
+
}, {
|
|
162
|
+
key: "startTime",
|
|
163
|
+
value: function startTime(key) {
|
|
164
|
+
if (!this.customEvents[key]) {
|
|
165
|
+
this.customEvents[key] = [];
|
|
166
|
+
}
|
|
167
|
+
this.customEvents[key].push({
|
|
168
|
+
startTime: Date.now()
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* 结束计时并上报
|
|
173
|
+
*/
|
|
174
|
+
}, {
|
|
175
|
+
key: "endTime",
|
|
176
|
+
value: function endTime(key, additionalData) {
|
|
177
|
+
if (!this.customEvents[key] || this.customEvents[key].length === 0) {
|
|
178
|
+
console.warn("No start time recorded for key: ".concat(key));
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
var event = this.customEvents[key].pop();
|
|
182
|
+
var duration = Date.now() - event.startTime;
|
|
183
|
+
this.reportCustomEvent('timing', Object.assign({
|
|
184
|
+
key: key,
|
|
185
|
+
duration: duration
|
|
186
|
+
}, additionalData));
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* 记录业务错误
|
|
190
|
+
*/
|
|
191
|
+
}, {
|
|
192
|
+
key: "recordBusinessError",
|
|
193
|
+
value: function recordBusinessError(errorName, errorData) {
|
|
194
|
+
this.reportCustomEvent('business_error', {
|
|
195
|
+
errorName: errorName,
|
|
196
|
+
errorData: errorData,
|
|
197
|
+
timestamp: Date.now(),
|
|
198
|
+
pageUrl: window.location.href
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* 上报用户行为事件
|
|
203
|
+
*/
|
|
204
|
+
}, {
|
|
205
|
+
key: "trackUserAction",
|
|
206
|
+
value: function trackUserAction(actionName, actionData) {
|
|
207
|
+
this.reportCustomEvent('user_action', {
|
|
208
|
+
actionName: actionName,
|
|
209
|
+
actionData: actionData,
|
|
210
|
+
timestamp: Date.now(),
|
|
211
|
+
pageUrl: window.location.href
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* 手动上报性能数据
|
|
216
|
+
*/
|
|
217
|
+
}, {
|
|
218
|
+
key: "reportPerformanceData",
|
|
219
|
+
value: function reportPerformanceData() {
|
|
220
|
+
var _this2 = this;
|
|
221
|
+
// 上报所有缓存的性能指标
|
|
222
|
+
Object.keys(this.performanceMetrics).forEach(function (metricName) {
|
|
223
|
+
_this2.reportPerformanceMetric(metricName);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}]);
|
|
227
|
+
}(MonitorSDK_1.default);
|
|
228
|
+
exports.PremiumSDK = PremiumSDK;
|
|
229
|
+
/**
|
|
230
|
+
* 创建高级版SDK实例的工厂函数
|
|
231
|
+
*/
|
|
232
|
+
function createPremiumSDK(config) {
|
|
233
|
+
return new PremiumSDK(config);
|
|
234
|
+
}
|
|
235
|
+
exports.default = PremiumSDK;
|
|
236
|
+
//# sourceMappingURL=premium-sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"premium-sdk.js","names":["exports","createPremiumSDK","MonitorSDK_1","__importDefault","require","PremiumSDK","_MonitorSDK_1$default","config","_this","_classCallCheck","_callSuper","Object","assign","sampleRates","pageview","jserror","api","resource","custom","customEvents","performanceMetrics","userId","initAdvancedFeatures","console","log","appId","_inherits","_createClass","key","value","initUserTracking","initCustomPerformanceMonitoring","storedUserId","localStorage","getItem","generateUserId","setItem","concat","Date","now","Math","random","toString","substring","setUserId","getUserId","recordPerformanceMetric","metricName","push","length","reportPerformanceMetric","values","avgValue","reduce","sum","val","maxValue","max","apply","_toConsumableArray","minValue","min","reportCustomEvent","count","startTime","endTime","additionalData","warn","event","pop","duration","recordBusinessError","errorName","errorData","timestamp","pageUrl","window","location","href","trackUserAction","actionName","actionData","reportPerformanceData","_this2","keys","forEach","default"],"sources":["../../packages/premium-sdk.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiMAA,OAAA,CAAAC,gBAAA,GAAAA,gBAAA;AAjMA,IAAAC,YAAA,GAAAC,eAAA,CAAAC,OAAA;AAGA;;;;AAAA,IAIaC,UAAW,0BAAAC,qBAAA;EAKtB,SAAAD,WAAYE,MAAwB;IAAA,IAAAC,KAAA;IAAAC,eAAA,OAAAJ,UAAA;IAClCG,KAAA,GAAAE,UAAA,OAAAL,UAAA,GAAKM,MAAA,CAAAC,MAAA,CAAAD,MAAA,CAAAC,MAAA,KACAL,MAAM;MACT;MACAM,WAAW,EAAAF,MAAA,CAAAC,MAAA;QACTE,QAAQ,EAAE,CAAC;QACXC,OAAO,EAAE,CAAC;QACVC,GAAG,EAAE,GAAG;QACRC,QAAQ,EAAE,GAAG;QACbC,MAAM,EAAE;MAAG,GACRX,MAAM,CAACM,WAAW;IAAA;IAdnBL,KAAA,CAAAW,YAAY,GAA0B,EAAE;IACxCX,KAAA,CAAAY,kBAAkB,GAA6B,EAAE;IAiBvDZ,KAAA,CAAKa,MAAM,GAAGd,MAAM,CAACc,MAAM;IA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版SDK
|
|
5
|
+
* 包含完整监控功能:页面浏览、JS错误、API请求、资源错误
|
|
6
|
+
*/
|
|
7
|
+
export declare class StandardSDK extends MonitorSDK {
|
|
8
|
+
constructor(config: MonitorSDKConfig);
|
|
9
|
+
/**
|
|
10
|
+
* 增强的API监控配置
|
|
11
|
+
*/
|
|
12
|
+
enableFullApiMonitoring(): void;
|
|
13
|
+
/**
|
|
14
|
+
* 增强的资源监控配置
|
|
15
|
+
*/
|
|
16
|
+
enableFullResourceMonitoring(): void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 创建标准版SDK实例的工厂函数
|
|
20
|
+
*/
|
|
21
|
+
export declare function createStandardSDK(config: MonitorSDKConfig): StandardSDK;
|
|
22
|
+
export default StandardSDK;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
5
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
6
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
8
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
9
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
10
|
+
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
11
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
12
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
13
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
14
|
+
function _inherits(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 && _setPrototypeOf(t, e); }
|
|
15
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
16
|
+
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
17
|
+
return mod && mod.__esModule ? mod : {
|
|
18
|
+
"default": mod
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", {
|
|
22
|
+
value: true
|
|
23
|
+
});
|
|
24
|
+
exports.StandardSDK = void 0;
|
|
25
|
+
exports.createStandardSDK = createStandardSDK;
|
|
26
|
+
var MonitorSDK_1 = __importDefault(require("../MonitorSDK"));
|
|
27
|
+
/**
|
|
28
|
+
* 标准版SDK
|
|
29
|
+
* 包含完整监控功能:页面浏览、JS错误、API请求、资源错误
|
|
30
|
+
*/
|
|
31
|
+
var StandardSDK = /*#__PURE__*/function (_MonitorSDK_1$default) {
|
|
32
|
+
function StandardSDK(config) {
|
|
33
|
+
var _this;
|
|
34
|
+
_classCallCheck(this, StandardSDK);
|
|
35
|
+
_this = _callSuper(this, StandardSDK, [Object.assign(Object.assign({}, config), {
|
|
36
|
+
// 标准版默认配置:合理的采样率设置
|
|
37
|
+
sampleRates: Object.assign({
|
|
38
|
+
pageview: 1,
|
|
39
|
+
jserror: 1,
|
|
40
|
+
api: 0.3,
|
|
41
|
+
resource: 0.5
|
|
42
|
+
}, config.sampleRates)
|
|
43
|
+
})]);
|
|
44
|
+
console.log('StandardSDK initialized for app:', config.appId);
|
|
45
|
+
return _this;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 增强的API监控配置
|
|
49
|
+
*/
|
|
50
|
+
_inherits(StandardSDK, _MonitorSDK_1$default);
|
|
51
|
+
return _createClass(StandardSDK, [{
|
|
52
|
+
key: "enableFullApiMonitoring",
|
|
53
|
+
value: function enableFullApiMonitoring() {
|
|
54
|
+
// 设置API监控为100%采样
|
|
55
|
+
this.sampleRates.api = 1;
|
|
56
|
+
console.log('Full API monitoring enabled');
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 增强的资源监控配置
|
|
60
|
+
*/
|
|
61
|
+
}, {
|
|
62
|
+
key: "enableFullResourceMonitoring",
|
|
63
|
+
value: function enableFullResourceMonitoring() {
|
|
64
|
+
// 设置资源监控为100%采样
|
|
65
|
+
this.sampleRates.resource = 1;
|
|
66
|
+
console.log('Full resource monitoring enabled');
|
|
67
|
+
}
|
|
68
|
+
}]);
|
|
69
|
+
}(MonitorSDK_1.default);
|
|
70
|
+
exports.StandardSDK = StandardSDK;
|
|
71
|
+
/**
|
|
72
|
+
* 创建标准版SDK实例的工厂函数
|
|
73
|
+
*/
|
|
74
|
+
function createStandardSDK(config) {
|
|
75
|
+
return new StandardSDK(config);
|
|
76
|
+
}
|
|
77
|
+
exports.default = StandardSDK;
|
|
78
|
+
//# sourceMappingURL=standard-sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standard-sdk.js","names":["exports","createStandardSDK","MonitorSDK_1","__importDefault","require","StandardSDK","_MonitorSDK_1$default","config","_this","_classCallCheck","_callSuper","Object","assign","sampleRates","pageview","jserror","api","resource","console","log","appId","_inherits","_createClass","key","value","enableFullApiMonitoring","enableFullResourceMonitoring","default"],"sources":["../../packages/standard-sdk.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA8CAA,OAAA,CAAAC,iBAAA,GAAAA,iBAAA;AA9CA,IAAAC,YAAA,GAAAC,eAAA,CAAAC,OAAA;AAGA;;;;AAAA,IAIaC,WAAY,0BAAAC,qBAAA;EACvB,SAAAD,YAAYE,MAAwB;IAAA,IAAAC,KAAA;IAAAC,eAAA,OAAAJ,WAAA;IAClCG,KAAA,GAAAE,UAAA,OAAAL,WAAA,GAAKM,MAAA,CAAAC,MAAA,CAAAD,MAAA,CAAAC,MAAA,KACAL,MAAM;MACT;MACAM,WAAW,EAAAF,MAAA,CAAAC,MAAA;QACTE,QAAQ,EAAE,CAAC;QACXC,OAAO,EAAE,CAAC;QACVC,GAAG,EAAE,GAAG;QACRC,QAAQ,EAAE;MAAG,GACVV,MAAM,CAACM,WAAW;IAAA;IAIzBK,OAAO,CAACC,GAAG,CAAC,kCAAkC,EAAEZ,MAAM,CAACa,KAAK,CAAC;IAAC,OAAAZ,KAAA;EAChE;EAEA;;;EAAAa,SAAA,CAAAhB,WAAA,EAAAC,qBAAA;EAAA,OAAAgB,YAAA,CAAAjB,WAAA;IAAAkB,GAAA;IAAAC,KAAA,EAGO,SAAAC,uBAAuBA,CAAA;MAC5B;MACA,IAAI,CAACZ,WAAW,CAACG,GAAG,GAAG,CAAC;MACxBE,OAAO,CAACC,GAAG,CAAC,6BAA6B,CAAC;IAC5C;IAEA;;;EAAA;IAAAI,GAAA;IAAAC,KAAA,EAGO,SAAAE,4BAA4BA,CAAA;MACjC;MACA,IAAI,CAACb,WAAW,CAACI,QAAQ,GAAG,CAAC;MAC7BC,OAAO,CAACC,GAAG,CAAC,kCAAkC,CAAC;IACjD;EAAC;AAAA,EAjC8BjB,YAAA,CAAAyB,OAAU;AAA3C3B,OAAA,CAAAK,WAAA,GAAAA,WAAA;AAoCA;;;AAGA,SAAgBJ,iBAAiBA,CAACM,MAAwB;EACxD,OAAO,IAAIF,WAAW,CAACE,MAAM,CAAC;AAChC;AAEAP,OAAA,CAAA2B,OAAA,GAAetB,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BaseReportData, ReportResult } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* 使用img标签方式上报数据
|
|
4
|
+
* @param data 上报数据
|
|
5
|
+
* @param url 上报地址(优先使用,为空时使用默认接口)
|
|
6
|
+
* @returns 是否上报成功
|
|
7
|
+
*/
|
|
8
|
+
export declare function reportByImg(data: BaseReportData, url: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* 使用sendBeacon方式上报数据
|
|
11
|
+
* @param data 上报数据
|
|
12
|
+
* @param url 上报地址(优先使用,为空时使用默认接口)
|
|
13
|
+
* @returns 是否上报成功
|
|
14
|
+
*/
|
|
15
|
+
export declare function reportByBeacon(data: BaseReportData, url: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* 使用接口方式上报数据
|
|
18
|
+
* @param data 上报数据
|
|
19
|
+
* @param url 上报地址(优先使用,为空时使用默认接口)
|
|
20
|
+
* @param options 配置项
|
|
21
|
+
* @returns Promise<ReportResult>
|
|
22
|
+
*/
|
|
23
|
+
export declare function reportByApi(data: BaseReportData, url: string, options?: {
|
|
24
|
+
timeout?: number;
|
|
25
|
+
}): Promise<ReportResult>;
|
|
26
|
+
/**
|
|
27
|
+
* 带降级策略的上报方法
|
|
28
|
+
* @param data 上报数据
|
|
29
|
+
* @param url 上报地址
|
|
30
|
+
* @returns 是否至少有一种上报方式成功
|
|
31
|
+
*/
|
|
32
|
+
export declare function reportWithFallback(data: BaseReportData, url: string): Promise<boolean>;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
4
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
5
|
+
var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
|
|
6
|
+
function adopt(value) {
|
|
7
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator["throw"](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
28
|
+
}
|
|
29
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
Object.defineProperty(exports, "__esModule", {
|
|
33
|
+
value: true
|
|
34
|
+
});
|
|
35
|
+
exports.reportByImg = reportByImg;
|
|
36
|
+
exports.reportByBeacon = reportByBeacon;
|
|
37
|
+
exports.reportByApi = reportByApi;
|
|
38
|
+
exports.reportWithFallback = reportWithFallback;
|
|
39
|
+
/**
|
|
40
|
+
* 使用img标签方式上报数据
|
|
41
|
+
* @param data 上报数据
|
|
42
|
+
* @param url 上报地址(优先使用,为空时使用默认接口)
|
|
43
|
+
* @returns 是否上报成功
|
|
44
|
+
*/
|
|
45
|
+
function reportByImg(data, url) {
|
|
46
|
+
try {
|
|
47
|
+
var img = new Image();
|
|
48
|
+
var params = encodeURIComponent(JSON.stringify(data));
|
|
49
|
+
// 优先使用传入的url,为空时使用默认接口
|
|
50
|
+
var imgReportUrl = url + '/v1/report/collectImg';
|
|
51
|
+
img.src = "".concat(imgReportUrl, "?data=").concat(params);
|
|
52
|
+
img.onload = img.onerror = function () {
|
|
53
|
+
// 清理引用
|
|
54
|
+
img.onload = img.onerror = null;
|
|
55
|
+
};
|
|
56
|
+
return true;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.error('img上报失败:', error);
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 使用sendBeacon方式上报数据
|
|
64
|
+
* @param data 上报数据
|
|
65
|
+
* @param url 上报地址(优先使用,为空时使用默认接口)
|
|
66
|
+
* @returns 是否上报成功
|
|
67
|
+
*/
|
|
68
|
+
function reportByBeacon(data, url) {
|
|
69
|
+
try {
|
|
70
|
+
if (navigator.sendBeacon) {
|
|
71
|
+
var blob = new Blob([JSON.stringify(data)], {
|
|
72
|
+
type: 'application/json'
|
|
73
|
+
});
|
|
74
|
+
// 优先使用传入的url,为空时使用默认接口
|
|
75
|
+
var apiReportUrl = url + '/v1/report/collect';
|
|
76
|
+
return navigator.sendBeacon(apiReportUrl, blob);
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
console.error('sendBeacon上报失败:', error);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 使用接口方式上报数据
|
|
86
|
+
* @param data 上报数据
|
|
87
|
+
* @param url 上报地址(优先使用,为空时使用默认接口)
|
|
88
|
+
* @param options 配置项
|
|
89
|
+
* @returns Promise<ReportResult>
|
|
90
|
+
*/
|
|
91
|
+
function reportByApi(data_1, url_1) {
|
|
92
|
+
return __awaiter(this, arguments, void 0, function (data, url) {
|
|
93
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
94
|
+
return /*#__PURE__*/_regenerator().m(function _callee() {
|
|
95
|
+
var controller, timeoutId, apiReportUrl, response, result, _t;
|
|
96
|
+
return _regenerator().w(function (_context) {
|
|
97
|
+
while (1) switch (_context.p = _context.n) {
|
|
98
|
+
case 0:
|
|
99
|
+
_context.p = 0;
|
|
100
|
+
controller = new AbortController();
|
|
101
|
+
timeoutId = setTimeout(function () {
|
|
102
|
+
return controller.abort();
|
|
103
|
+
}, options.timeout || 5000); // 优先使用传入的url,为空时使用默认接口
|
|
104
|
+
apiReportUrl = url || '/api/report/collect';
|
|
105
|
+
_context.n = 1;
|
|
106
|
+
return fetch(apiReportUrl, {
|
|
107
|
+
method: 'POST',
|
|
108
|
+
headers: {
|
|
109
|
+
'Content-Type': 'application/json',
|
|
110
|
+
'x-sdk-internal': 'true' // 添加SDK内部请求标记,避免被SDK自身的fetch拦截器拦截
|
|
111
|
+
},
|
|
112
|
+
body: JSON.stringify(data),
|
|
113
|
+
signal: controller.signal
|
|
114
|
+
});
|
|
115
|
+
case 1:
|
|
116
|
+
response = _context.v;
|
|
117
|
+
clearTimeout(timeoutId);
|
|
118
|
+
if (response.ok) {
|
|
119
|
+
_context.n = 2;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
throw new Error("HTTP error! status: ".concat(response.status));
|
|
123
|
+
case 2:
|
|
124
|
+
_context.n = 3;
|
|
125
|
+
return response.json();
|
|
126
|
+
case 3:
|
|
127
|
+
result = _context.v;
|
|
128
|
+
return _context.a(2, {
|
|
129
|
+
success: true,
|
|
130
|
+
data: result
|
|
131
|
+
});
|
|
132
|
+
case 4:
|
|
133
|
+
_context.p = 4;
|
|
134
|
+
_t = _context.v;
|
|
135
|
+
console.error('接口上报失败:', _t);
|
|
136
|
+
return _context.a(2, {
|
|
137
|
+
success: false,
|
|
138
|
+
error: _t
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}, _callee, null, [[0, 4]]);
|
|
142
|
+
})();
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 带降级策略的上报方法
|
|
147
|
+
* @param data 上报数据
|
|
148
|
+
* @param url 上报地址
|
|
149
|
+
* @returns 是否至少有一种上报方式成功
|
|
150
|
+
*/
|
|
151
|
+
function reportWithFallback(data, url) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee2() {
|
|
153
|
+
var blob, success, img, params, imgReportUrl, apiReportUrl, _t2, _t3;
|
|
154
|
+
return _regenerator().w(function (_context2) {
|
|
155
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
156
|
+
case 0:
|
|
157
|
+
if (!navigator.sendBeacon) {
|
|
158
|
+
_context2.n = 1;
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
blob = new Blob([JSON.stringify(data)], {
|
|
162
|
+
type: 'application/json'
|
|
163
|
+
});
|
|
164
|
+
success = navigator.sendBeacon(url, blob);
|
|
165
|
+
if (!success) {
|
|
166
|
+
_context2.n = 1;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
return _context2.a(2, true);
|
|
170
|
+
case 1:
|
|
171
|
+
_context2.p = 1;
|
|
172
|
+
img = new Image();
|
|
173
|
+
params = encodeURIComponent(JSON.stringify(data)); // 优先使用传入的url,为空时使用默认接口
|
|
174
|
+
imgReportUrl = url + '/v1/report/collectImg';
|
|
175
|
+
img.src = "".concat(imgReportUrl, "?data=").concat(params);
|
|
176
|
+
return _context2.a(2, true);
|
|
177
|
+
case 2:
|
|
178
|
+
_context2.p = 2;
|
|
179
|
+
_t2 = _context2.v;
|
|
180
|
+
_context2.p = 3;
|
|
181
|
+
// 优先使用传入的url,为空时使用默认接口
|
|
182
|
+
apiReportUrl = url + '/v1/report/collect';
|
|
183
|
+
_context2.n = 4;
|
|
184
|
+
return fetch(apiReportUrl, {
|
|
185
|
+
method: 'POST',
|
|
186
|
+
headers: {
|
|
187
|
+
'Content-Type': 'application/json',
|
|
188
|
+
'x-sdk-internal': 'true' // 添加SDK内部请求标记,避免被SDK自身的fetch拦截器拦截
|
|
189
|
+
},
|
|
190
|
+
body: JSON.stringify(data),
|
|
191
|
+
keepalive: true // 尝试使用keepalive
|
|
192
|
+
});
|
|
193
|
+
case 4:
|
|
194
|
+
return _context2.a(2, true);
|
|
195
|
+
case 5:
|
|
196
|
+
_context2.p = 5;
|
|
197
|
+
_t3 = _context2.v;
|
|
198
|
+
console.error('所有上报方式均失败:', _t3);
|
|
199
|
+
return _context2.a(2, false);
|
|
200
|
+
}
|
|
201
|
+
}, _callee2, null, [[3, 5], [1, 2]]);
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=reporters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reporters.js","names":["exports","reportByImg","reportByBeacon","reportByApi","reportWithFallback","data","url","img","Image","params","encodeURIComponent","JSON","stringify","imgReportUrl","src","concat","onload","onerror","error","console","navigator","sendBeacon","blob","Blob","type","apiReportUrl","data_1","url_1","options","arguments","length","undefined","_regenerator","m","_callee","controller","timeoutId","response","result","_t","w","_context","p","n","AbortController","setTimeout","abort","timeout","fetch","method","headers","body","signal","v","clearTimeout","ok","Error","status","json","a","success","_context2","_t2","keepalive","_t3","_callee2"],"sources":["../reporters.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQAA,OAAA,CAAAC,WAAA,GAAAA,WAAA;AAwBAD,OAAA,CAAAE,cAAA,GAAAA,cAAA;AAsBAF,OAAA,CAAAG,WAAA,GAAAA,WAAA;AA+CAH,OAAA,CAAAI,kBAAA,GAAAA,kBAAA;AAnGA;;;;;;AAMA,SAAgBH,WAAWA,CAACI,IAAoB,EAAEC,GAAW;EAC3D,IAAI;IACF,IAAMC,GAAG,GAAG,IAAIC,KAAK,EAAE;IACvB,IAAMC,MAAM,GAAGC,kBAAkB,CAACC,IAAI,CAACC,SAAS,CAACP,IAAI,CAAC,CAAC;IACvD;IACA,IAAMQ,YAAY,GAAGP,GAAG,GAAG,uBAAuB;IAClDC,GAAG,CAACO,GAAG,MAAAC,MAAA,CAAMF,YAAY,YAAAE,MAAA,CAASN,MAAM,CAAE;IAC1CF,GAAG,CAACS,MAAM,GAAGT,GAAG,CAACU,OAAO,GAAG;MACzB;MACAV,GAAG,CAACS,MAAM,GAAGT,GAAG,CAACU,OAAO,GAAG,IAAI;I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