@ohbug/core 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +29 -0
- package/dist/index.js +131 -10
- package/dist/index.mjs +131 -10
- package/package.json +3 -3
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { OhbugClientConstructor, OhbugEventWithMethods, OhbugExtension } from '@ohbug/types';
|
|
2
|
+
|
|
3
|
+
declare const Client: OhbugClientConstructor;
|
|
4
|
+
|
|
5
|
+
declare function isEvent(eventLike: any): eventLike is OhbugEventWithMethods<any>;
|
|
6
|
+
|
|
7
|
+
declare function defineExtension(extension: OhbugExtension): OhbugExtension;
|
|
8
|
+
|
|
9
|
+
declare const enum EventTypes {
|
|
10
|
+
UNCAUGHT_ERROR = "uncaughtError",
|
|
11
|
+
RESOURCE_ERROR = "resourceError",
|
|
12
|
+
UNHANDLEDREJECTION_ERROR = "unhandledrejectionError",
|
|
13
|
+
AJAX_ERROR = "ajaxError",
|
|
14
|
+
FETCH_ERROR = "fetchError",
|
|
15
|
+
WEBSOCKET_ERROR = "websocketError",
|
|
16
|
+
UNKNOWN_ERROR = "unknownError",
|
|
17
|
+
MESSAGE = "message",
|
|
18
|
+
FEEDBACK = "feedback",
|
|
19
|
+
VIEW = "view",
|
|
20
|
+
REACT = "react",
|
|
21
|
+
VUE = "vue",
|
|
22
|
+
ANGULAR = "angular",
|
|
23
|
+
MINIAPP_ERROR = "miniappError",
|
|
24
|
+
MINIAPP_UNHANDLEDREJECTION_ERROR = "miniappUnhandledrejectionError",
|
|
25
|
+
MINIAPP_PAGENOTFOUND_ERROR = "miniappPagenotfoundError",
|
|
26
|
+
MINIAPP_MEMORYWARNING_ERROR = "miniappMemorywarningError"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { Client, EventTypes, defineExtension, isEvent };
|
package/dist/index.js
CHANGED
|
@@ -51,6 +51,7 @@ var import_utils4 = require("@ohbug/utils");
|
|
|
51
51
|
// src/config.ts
|
|
52
52
|
var import_utils = require("@ohbug/utils");
|
|
53
53
|
var schema = {
|
|
54
|
+
// base
|
|
54
55
|
apiKey: {
|
|
55
56
|
defaultValue: void 0,
|
|
56
57
|
message: "is required",
|
|
@@ -79,8 +80,9 @@ var schema = {
|
|
|
79
80
|
maxActions: {
|
|
80
81
|
defaultValue: 30,
|
|
81
82
|
message: "should be a number between 0 and 100",
|
|
82
|
-
validate: (value) => value === void 0 || (0, import_utils.isNumber)(value) && value >=
|
|
83
|
+
validate: (value) => value === void 0 || (0, import_utils.isNumber)(value) && value >= 0 && value <= 100
|
|
83
84
|
},
|
|
85
|
+
// hooks
|
|
84
86
|
onEvent: {
|
|
85
87
|
defaultValue: (event) => event,
|
|
86
88
|
message: "should be a function",
|
|
@@ -92,6 +94,7 @@ var schema = {
|
|
|
92
94
|
message: "should be a function",
|
|
93
95
|
validate: (value) => value === void 0 || (0, import_utils.isFunction)(value)
|
|
94
96
|
},
|
|
97
|
+
// utils
|
|
95
98
|
logger: {
|
|
96
99
|
defaultValue: import_utils.logger,
|
|
97
100
|
message: "should be null or an object with methods { log, info, warn, error }",
|
|
@@ -100,6 +103,7 @@ var schema = {
|
|
|
100
103
|
true
|
|
101
104
|
)
|
|
102
105
|
},
|
|
106
|
+
// data
|
|
103
107
|
user: {
|
|
104
108
|
defaultValue: void 0,
|
|
105
109
|
message: "should be an object and have up to 6 attributes",
|
|
@@ -123,7 +127,7 @@ var Action = class {
|
|
|
123
127
|
__publicField(this, "message");
|
|
124
128
|
__publicField(this, "data");
|
|
125
129
|
this.type = type;
|
|
126
|
-
this.timestamp = timestamp || new Date().toISOString();
|
|
130
|
+
this.timestamp = timestamp || (/* @__PURE__ */ new Date()).toISOString();
|
|
127
131
|
this.message = message;
|
|
128
132
|
this.data = data;
|
|
129
133
|
}
|
|
@@ -211,6 +215,17 @@ var Event = class {
|
|
|
211
215
|
get __isOhbugEvent() {
|
|
212
216
|
return true;
|
|
213
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Add an action.
|
|
220
|
+
* Once the threshold is reached, the oldest actions will be deleted.
|
|
221
|
+
* 新增一个动作。
|
|
222
|
+
* 一旦达到阈值,最老的 Action 将被删除。
|
|
223
|
+
*
|
|
224
|
+
* @param message
|
|
225
|
+
* @param data
|
|
226
|
+
* @param type
|
|
227
|
+
* @param timestamp
|
|
228
|
+
*/
|
|
214
229
|
addAction(message, data, type, timestamp) {
|
|
215
230
|
var _a, _b;
|
|
216
231
|
const actions = this.actions;
|
|
@@ -218,14 +233,25 @@ var Event = class {
|
|
|
218
233
|
const targetData = data || {};
|
|
219
234
|
const targetType = (0, import_utils2.isString)(type) ? type : "";
|
|
220
235
|
const action = new Action(targetMessage, targetData, targetType, timestamp);
|
|
221
|
-
|
|
222
|
-
|
|
236
|
+
const maxActions = (_b = (_a = this.__client) == null ? void 0 : _a.__config.maxActions) != null ? _b : 30;
|
|
237
|
+
if (maxActions > 0) {
|
|
238
|
+
if (actions.length >= maxActions) {
|
|
239
|
+
actions.shift();
|
|
240
|
+
}
|
|
241
|
+
actions.push(action);
|
|
223
242
|
}
|
|
224
|
-
actions.push(action);
|
|
225
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* Get current user information
|
|
246
|
+
* 获取当前的用户信息
|
|
247
|
+
*/
|
|
226
248
|
getUser() {
|
|
227
249
|
return this.user;
|
|
228
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Set current user information
|
|
253
|
+
* 设置当前的用户信息
|
|
254
|
+
*/
|
|
229
255
|
setUser(user) {
|
|
230
256
|
var _a;
|
|
231
257
|
if ((0, import_utils2.isObject)(user) && Object.keys(user).length <= 6) {
|
|
@@ -238,12 +264,31 @@ var Event = class {
|
|
|
238
264
|
));
|
|
239
265
|
return void 0;
|
|
240
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Add metadata
|
|
269
|
+
* 新增 metadata
|
|
270
|
+
*
|
|
271
|
+
* @param section
|
|
272
|
+
* @param data
|
|
273
|
+
*/
|
|
241
274
|
addMetadata(section, data) {
|
|
242
275
|
return addMetadata(this.metadata, section, data);
|
|
243
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* Get metadata
|
|
279
|
+
* 获取 metadata
|
|
280
|
+
*
|
|
281
|
+
* @param section
|
|
282
|
+
*/
|
|
244
283
|
getMetadata(section) {
|
|
245
284
|
return getMetadata(this.metadata, section);
|
|
246
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* Delete metadata
|
|
288
|
+
* 删除 metadata
|
|
289
|
+
*
|
|
290
|
+
* @param section
|
|
291
|
+
*/
|
|
247
292
|
deleteMetadata(section) {
|
|
248
293
|
return deleteMetadata(this.metadata, section);
|
|
249
294
|
}
|
|
@@ -282,7 +327,7 @@ var Event = class {
|
|
|
282
327
|
};
|
|
283
328
|
function createEvent(values, client) {
|
|
284
329
|
const { apiKey, appVersion, appType, releaseStage } = client.__config;
|
|
285
|
-
const timestamp = new Date().toISOString();
|
|
330
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
286
331
|
const device = client.__device(client);
|
|
287
332
|
let category;
|
|
288
333
|
let type;
|
|
@@ -390,13 +435,15 @@ var Client = class Client2 {
|
|
|
390
435
|
config: baseConfig,
|
|
391
436
|
schema: schema2 = schema,
|
|
392
437
|
device,
|
|
393
|
-
notifier
|
|
438
|
+
notifier,
|
|
439
|
+
destroy
|
|
394
440
|
}) {
|
|
395
441
|
__publicField(this, "__sdk");
|
|
396
442
|
__publicField(this, "__config");
|
|
397
443
|
__publicField(this, "__logger");
|
|
398
444
|
__publicField(this, "__device");
|
|
399
445
|
__publicField(this, "__notifier");
|
|
446
|
+
__publicField(this, "__destroy");
|
|
400
447
|
__publicField(this, "__extensions");
|
|
401
448
|
__publicField(this, "__actions");
|
|
402
449
|
__publicField(this, "__user");
|
|
@@ -407,6 +454,7 @@ var Client = class Client2 {
|
|
|
407
454
|
this.__logger = config.logger;
|
|
408
455
|
this.__device = device;
|
|
409
456
|
this.__notifier = notifier;
|
|
457
|
+
this.__destroy = destroy;
|
|
410
458
|
this.__extensions = [];
|
|
411
459
|
this.__actions = [];
|
|
412
460
|
this.__user = config.user;
|
|
@@ -420,16 +468,47 @@ var Client = class Client2 {
|
|
|
420
468
|
this.__logger.warn(getConfigErrorMessage(errors, baseConfig));
|
|
421
469
|
}
|
|
422
470
|
}
|
|
471
|
+
/**
|
|
472
|
+
* Load extension
|
|
473
|
+
* 加载扩展
|
|
474
|
+
*
|
|
475
|
+
* @param extension
|
|
476
|
+
*/
|
|
423
477
|
use(extension) {
|
|
424
478
|
var _a;
|
|
425
479
|
this.__extensions.push(extension);
|
|
426
480
|
(_a = extension.onSetup) == null ? void 0 : _a.call(extension, this);
|
|
427
481
|
return this;
|
|
428
482
|
}
|
|
483
|
+
destroy() {
|
|
484
|
+
var _a;
|
|
485
|
+
if (this.__destroy) {
|
|
486
|
+
this.__logger.info(
|
|
487
|
+
"%c @ohbug/core %c has been destroyed %c",
|
|
488
|
+
"background:#333; padding: 2px 1px; color: #FFF",
|
|
489
|
+
"background:#FF6F61; padding: 2px 1px; color: #FFF",
|
|
490
|
+
"background:transparent"
|
|
491
|
+
);
|
|
492
|
+
return (_a = this.__destroy) == null ? void 0 : _a.call(this);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Create an event, you will get a data body containing device actions and other information
|
|
497
|
+
* 创建事件,将会得到一个含有 device actions 等信息的数据体
|
|
498
|
+
*
|
|
499
|
+
* @param value
|
|
500
|
+
*/
|
|
429
501
|
createEvent(value) {
|
|
430
502
|
const event = createEvent(value, this);
|
|
431
503
|
return handleEventCreated(event, this);
|
|
432
504
|
}
|
|
505
|
+
/**
|
|
506
|
+
* Used to trigger the reporting interface
|
|
507
|
+
* 用于触发上报接口
|
|
508
|
+
*
|
|
509
|
+
* @param eventLike
|
|
510
|
+
* @param beforeNotify
|
|
511
|
+
*/
|
|
433
512
|
notify(eventLike, beforeNotify) {
|
|
434
513
|
let event;
|
|
435
514
|
if (Boolean(eventLike) && !isEvent(eventLike)) {
|
|
@@ -441,20 +520,43 @@ var Client = class Client2 {
|
|
|
441
520
|
event = beforeNotify(event);
|
|
442
521
|
return notify(event, this);
|
|
443
522
|
}
|
|
523
|
+
/**
|
|
524
|
+
* Add an action.
|
|
525
|
+
* Once the threshold is reached, the oldest actions will be deleted.
|
|
526
|
+
* 新增一个动作。
|
|
527
|
+
* 一旦达到阈值,最老的 Action 将被删除。
|
|
528
|
+
*
|
|
529
|
+
* @param message
|
|
530
|
+
* @param data
|
|
531
|
+
* @param type
|
|
532
|
+
* @param timestamp
|
|
533
|
+
*/
|
|
444
534
|
addAction(message, data, type, timestamp) {
|
|
535
|
+
var _a;
|
|
445
536
|
const actions = this.__actions;
|
|
446
537
|
const targetMessage = (0, import_utils4.isString)(message) ? message : "";
|
|
447
538
|
const targetData = data || {};
|
|
448
539
|
const targetType = (0, import_utils4.isString)(type) ? type : "";
|
|
449
540
|
const action = new Action(targetMessage, targetData, targetType, timestamp);
|
|
450
|
-
|
|
451
|
-
|
|
541
|
+
const maxActions = (_a = this.__config.maxActions) != null ? _a : 30;
|
|
542
|
+
if (maxActions > 0) {
|
|
543
|
+
if (actions.length >= maxActions) {
|
|
544
|
+
actions.shift();
|
|
545
|
+
}
|
|
546
|
+
actions.push(action);
|
|
452
547
|
}
|
|
453
|
-
actions.push(action);
|
|
454
548
|
}
|
|
549
|
+
/**
|
|
550
|
+
* Get current user information
|
|
551
|
+
* 获取当前的用户信息
|
|
552
|
+
*/
|
|
455
553
|
getUser() {
|
|
456
554
|
return this.__user;
|
|
457
555
|
}
|
|
556
|
+
/**
|
|
557
|
+
* Set current user information
|
|
558
|
+
* 设置当前的用户信息
|
|
559
|
+
*/
|
|
458
560
|
setUser(user) {
|
|
459
561
|
if ((0, import_utils4.isObject)(user) && Object.keys(user).length <= 6) {
|
|
460
562
|
this.__user = __spreadValues(__spreadValues({}, this.__user), user);
|
|
@@ -466,12 +568,31 @@ var Client = class Client2 {
|
|
|
466
568
|
));
|
|
467
569
|
return void 0;
|
|
468
570
|
}
|
|
571
|
+
/**
|
|
572
|
+
* Add metadata
|
|
573
|
+
* 新增 metadata
|
|
574
|
+
*
|
|
575
|
+
* @param section
|
|
576
|
+
* @param data
|
|
577
|
+
*/
|
|
469
578
|
addMetadata(section, data) {
|
|
470
579
|
return addMetadata(this.__metadata, section, data);
|
|
471
580
|
}
|
|
581
|
+
/**
|
|
582
|
+
* Get metadata
|
|
583
|
+
* 获取 metadata
|
|
584
|
+
*
|
|
585
|
+
* @param section
|
|
586
|
+
*/
|
|
472
587
|
getMetadata(section) {
|
|
473
588
|
return getMetadata(this.__metadata, section);
|
|
474
589
|
}
|
|
590
|
+
/**
|
|
591
|
+
* Delete metadata
|
|
592
|
+
* 删除 metadata
|
|
593
|
+
*
|
|
594
|
+
* @param section
|
|
595
|
+
*/
|
|
475
596
|
deleteMetadata(section) {
|
|
476
597
|
return deleteMetadata(this.__metadata, section);
|
|
477
598
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -25,6 +25,7 @@ import { isObject as isObject3, isString as isString3 } from "@ohbug/utils";
|
|
|
25
25
|
// src/config.ts
|
|
26
26
|
import { isFunction, isNumber, isObject, isString, logger } from "@ohbug/utils";
|
|
27
27
|
var schema = {
|
|
28
|
+
// base
|
|
28
29
|
apiKey: {
|
|
29
30
|
defaultValue: void 0,
|
|
30
31
|
message: "is required",
|
|
@@ -53,8 +54,9 @@ var schema = {
|
|
|
53
54
|
maxActions: {
|
|
54
55
|
defaultValue: 30,
|
|
55
56
|
message: "should be a number between 0 and 100",
|
|
56
|
-
validate: (value) => value === void 0 || isNumber(value) && value >=
|
|
57
|
+
validate: (value) => value === void 0 || isNumber(value) && value >= 0 && value <= 100
|
|
57
58
|
},
|
|
59
|
+
// hooks
|
|
58
60
|
onEvent: {
|
|
59
61
|
defaultValue: (event) => event,
|
|
60
62
|
message: "should be a function",
|
|
@@ -66,6 +68,7 @@ var schema = {
|
|
|
66
68
|
message: "should be a function",
|
|
67
69
|
validate: (value) => value === void 0 || isFunction(value)
|
|
68
70
|
},
|
|
71
|
+
// utils
|
|
69
72
|
logger: {
|
|
70
73
|
defaultValue: logger,
|
|
71
74
|
message: "should be null or an object with methods { log, info, warn, error }",
|
|
@@ -74,6 +77,7 @@ var schema = {
|
|
|
74
77
|
true
|
|
75
78
|
)
|
|
76
79
|
},
|
|
80
|
+
// data
|
|
77
81
|
user: {
|
|
78
82
|
defaultValue: void 0,
|
|
79
83
|
message: "should be an object and have up to 6 attributes",
|
|
@@ -97,7 +101,7 @@ var Action = class {
|
|
|
97
101
|
__publicField(this, "message");
|
|
98
102
|
__publicField(this, "data");
|
|
99
103
|
this.type = type;
|
|
100
|
-
this.timestamp = timestamp || new Date().toISOString();
|
|
104
|
+
this.timestamp = timestamp || (/* @__PURE__ */ new Date()).toISOString();
|
|
101
105
|
this.message = message;
|
|
102
106
|
this.data = data;
|
|
103
107
|
}
|
|
@@ -185,6 +189,17 @@ var Event = class {
|
|
|
185
189
|
get __isOhbugEvent() {
|
|
186
190
|
return true;
|
|
187
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Add an action.
|
|
194
|
+
* Once the threshold is reached, the oldest actions will be deleted.
|
|
195
|
+
* 新增一个动作。
|
|
196
|
+
* 一旦达到阈值,最老的 Action 将被删除。
|
|
197
|
+
*
|
|
198
|
+
* @param message
|
|
199
|
+
* @param data
|
|
200
|
+
* @param type
|
|
201
|
+
* @param timestamp
|
|
202
|
+
*/
|
|
188
203
|
addAction(message, data, type, timestamp) {
|
|
189
204
|
var _a, _b;
|
|
190
205
|
const actions = this.actions;
|
|
@@ -192,14 +207,25 @@ var Event = class {
|
|
|
192
207
|
const targetData = data || {};
|
|
193
208
|
const targetType = isString2(type) ? type : "";
|
|
194
209
|
const action = new Action(targetMessage, targetData, targetType, timestamp);
|
|
195
|
-
|
|
196
|
-
|
|
210
|
+
const maxActions = (_b = (_a = this.__client) == null ? void 0 : _a.__config.maxActions) != null ? _b : 30;
|
|
211
|
+
if (maxActions > 0) {
|
|
212
|
+
if (actions.length >= maxActions) {
|
|
213
|
+
actions.shift();
|
|
214
|
+
}
|
|
215
|
+
actions.push(action);
|
|
197
216
|
}
|
|
198
|
-
actions.push(action);
|
|
199
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Get current user information
|
|
220
|
+
* 获取当前的用户信息
|
|
221
|
+
*/
|
|
200
222
|
getUser() {
|
|
201
223
|
return this.user;
|
|
202
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Set current user information
|
|
227
|
+
* 设置当前的用户信息
|
|
228
|
+
*/
|
|
203
229
|
setUser(user) {
|
|
204
230
|
var _a;
|
|
205
231
|
if (isObject2(user) && Object.keys(user).length <= 6) {
|
|
@@ -212,12 +238,31 @@ var Event = class {
|
|
|
212
238
|
));
|
|
213
239
|
return void 0;
|
|
214
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Add metadata
|
|
243
|
+
* 新增 metadata
|
|
244
|
+
*
|
|
245
|
+
* @param section
|
|
246
|
+
* @param data
|
|
247
|
+
*/
|
|
215
248
|
addMetadata(section, data) {
|
|
216
249
|
return addMetadata(this.metadata, section, data);
|
|
217
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Get metadata
|
|
253
|
+
* 获取 metadata
|
|
254
|
+
*
|
|
255
|
+
* @param section
|
|
256
|
+
*/
|
|
218
257
|
getMetadata(section) {
|
|
219
258
|
return getMetadata(this.metadata, section);
|
|
220
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* Delete metadata
|
|
262
|
+
* 删除 metadata
|
|
263
|
+
*
|
|
264
|
+
* @param section
|
|
265
|
+
*/
|
|
221
266
|
deleteMetadata(section) {
|
|
222
267
|
return deleteMetadata(this.metadata, section);
|
|
223
268
|
}
|
|
@@ -256,7 +301,7 @@ var Event = class {
|
|
|
256
301
|
};
|
|
257
302
|
function createEvent(values, client) {
|
|
258
303
|
const { apiKey, appVersion, appType, releaseStage } = client.__config;
|
|
259
|
-
const timestamp = new Date().toISOString();
|
|
304
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
260
305
|
const device = client.__device(client);
|
|
261
306
|
let category;
|
|
262
307
|
let type;
|
|
@@ -364,13 +409,15 @@ var Client = class Client2 {
|
|
|
364
409
|
config: baseConfig,
|
|
365
410
|
schema: schema2 = schema,
|
|
366
411
|
device,
|
|
367
|
-
notifier
|
|
412
|
+
notifier,
|
|
413
|
+
destroy
|
|
368
414
|
}) {
|
|
369
415
|
__publicField(this, "__sdk");
|
|
370
416
|
__publicField(this, "__config");
|
|
371
417
|
__publicField(this, "__logger");
|
|
372
418
|
__publicField(this, "__device");
|
|
373
419
|
__publicField(this, "__notifier");
|
|
420
|
+
__publicField(this, "__destroy");
|
|
374
421
|
__publicField(this, "__extensions");
|
|
375
422
|
__publicField(this, "__actions");
|
|
376
423
|
__publicField(this, "__user");
|
|
@@ -381,6 +428,7 @@ var Client = class Client2 {
|
|
|
381
428
|
this.__logger = config.logger;
|
|
382
429
|
this.__device = device;
|
|
383
430
|
this.__notifier = notifier;
|
|
431
|
+
this.__destroy = destroy;
|
|
384
432
|
this.__extensions = [];
|
|
385
433
|
this.__actions = [];
|
|
386
434
|
this.__user = config.user;
|
|
@@ -394,16 +442,47 @@ var Client = class Client2 {
|
|
|
394
442
|
this.__logger.warn(getConfigErrorMessage(errors, baseConfig));
|
|
395
443
|
}
|
|
396
444
|
}
|
|
445
|
+
/**
|
|
446
|
+
* Load extension
|
|
447
|
+
* 加载扩展
|
|
448
|
+
*
|
|
449
|
+
* @param extension
|
|
450
|
+
*/
|
|
397
451
|
use(extension) {
|
|
398
452
|
var _a;
|
|
399
453
|
this.__extensions.push(extension);
|
|
400
454
|
(_a = extension.onSetup) == null ? void 0 : _a.call(extension, this);
|
|
401
455
|
return this;
|
|
402
456
|
}
|
|
457
|
+
destroy() {
|
|
458
|
+
var _a;
|
|
459
|
+
if (this.__destroy) {
|
|
460
|
+
this.__logger.info(
|
|
461
|
+
"%c @ohbug/core %c has been destroyed %c",
|
|
462
|
+
"background:#333; padding: 2px 1px; color: #FFF",
|
|
463
|
+
"background:#FF6F61; padding: 2px 1px; color: #FFF",
|
|
464
|
+
"background:transparent"
|
|
465
|
+
);
|
|
466
|
+
return (_a = this.__destroy) == null ? void 0 : _a.call(this);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Create an event, you will get a data body containing device actions and other information
|
|
471
|
+
* 创建事件,将会得到一个含有 device actions 等信息的数据体
|
|
472
|
+
*
|
|
473
|
+
* @param value
|
|
474
|
+
*/
|
|
403
475
|
createEvent(value) {
|
|
404
476
|
const event = createEvent(value, this);
|
|
405
477
|
return handleEventCreated(event, this);
|
|
406
478
|
}
|
|
479
|
+
/**
|
|
480
|
+
* Used to trigger the reporting interface
|
|
481
|
+
* 用于触发上报接口
|
|
482
|
+
*
|
|
483
|
+
* @param eventLike
|
|
484
|
+
* @param beforeNotify
|
|
485
|
+
*/
|
|
407
486
|
notify(eventLike, beforeNotify) {
|
|
408
487
|
let event;
|
|
409
488
|
if (Boolean(eventLike) && !isEvent(eventLike)) {
|
|
@@ -415,20 +494,43 @@ var Client = class Client2 {
|
|
|
415
494
|
event = beforeNotify(event);
|
|
416
495
|
return notify(event, this);
|
|
417
496
|
}
|
|
497
|
+
/**
|
|
498
|
+
* Add an action.
|
|
499
|
+
* Once the threshold is reached, the oldest actions will be deleted.
|
|
500
|
+
* 新增一个动作。
|
|
501
|
+
* 一旦达到阈值,最老的 Action 将被删除。
|
|
502
|
+
*
|
|
503
|
+
* @param message
|
|
504
|
+
* @param data
|
|
505
|
+
* @param type
|
|
506
|
+
* @param timestamp
|
|
507
|
+
*/
|
|
418
508
|
addAction(message, data, type, timestamp) {
|
|
509
|
+
var _a;
|
|
419
510
|
const actions = this.__actions;
|
|
420
511
|
const targetMessage = isString3(message) ? message : "";
|
|
421
512
|
const targetData = data || {};
|
|
422
513
|
const targetType = isString3(type) ? type : "";
|
|
423
514
|
const action = new Action(targetMessage, targetData, targetType, timestamp);
|
|
424
|
-
|
|
425
|
-
|
|
515
|
+
const maxActions = (_a = this.__config.maxActions) != null ? _a : 30;
|
|
516
|
+
if (maxActions > 0) {
|
|
517
|
+
if (actions.length >= maxActions) {
|
|
518
|
+
actions.shift();
|
|
519
|
+
}
|
|
520
|
+
actions.push(action);
|
|
426
521
|
}
|
|
427
|
-
actions.push(action);
|
|
428
522
|
}
|
|
523
|
+
/**
|
|
524
|
+
* Get current user information
|
|
525
|
+
* 获取当前的用户信息
|
|
526
|
+
*/
|
|
429
527
|
getUser() {
|
|
430
528
|
return this.__user;
|
|
431
529
|
}
|
|
530
|
+
/**
|
|
531
|
+
* Set current user information
|
|
532
|
+
* 设置当前的用户信息
|
|
533
|
+
*/
|
|
432
534
|
setUser(user) {
|
|
433
535
|
if (isObject3(user) && Object.keys(user).length <= 6) {
|
|
434
536
|
this.__user = __spreadValues(__spreadValues({}, this.__user), user);
|
|
@@ -440,12 +542,31 @@ var Client = class Client2 {
|
|
|
440
542
|
));
|
|
441
543
|
return void 0;
|
|
442
544
|
}
|
|
545
|
+
/**
|
|
546
|
+
* Add metadata
|
|
547
|
+
* 新增 metadata
|
|
548
|
+
*
|
|
549
|
+
* @param section
|
|
550
|
+
* @param data
|
|
551
|
+
*/
|
|
443
552
|
addMetadata(section, data) {
|
|
444
553
|
return addMetadata(this.__metadata, section, data);
|
|
445
554
|
}
|
|
555
|
+
/**
|
|
556
|
+
* Get metadata
|
|
557
|
+
* 获取 metadata
|
|
558
|
+
*
|
|
559
|
+
* @param section
|
|
560
|
+
*/
|
|
446
561
|
getMetadata(section) {
|
|
447
562
|
return getMetadata(this.__metadata, section);
|
|
448
563
|
}
|
|
564
|
+
/**
|
|
565
|
+
* Delete metadata
|
|
566
|
+
* 删除 metadata
|
|
567
|
+
*
|
|
568
|
+
* @param section
|
|
569
|
+
*/
|
|
449
570
|
deleteMetadata(section) {
|
|
450
571
|
return deleteMetadata(this.__metadata, section);
|
|
451
572
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohbug/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Responsible for managing Ohbug's workflow",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "chenyueban <jasonchan0527@gmail.com>",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@ohbug/types": "2.
|
|
34
|
-
"@ohbug/utils": "2.0.
|
|
33
|
+
"@ohbug/types": "2.2.0",
|
|
34
|
+
"@ohbug/utils": "2.0.7"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "tsup",
|