@ohbug/core 1.1.5 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/dist/index.d.ts +38 -4
- package/dist/index.js +495 -0
- package/dist/index.mjs +471 -0
- package/package.json +22 -20
- package/src/action.ts +23 -0
- package/src/client.ts +210 -0
- package/src/config.ts +75 -0
- package/src/event.ts +276 -0
- package/src/extension.ts +8 -0
- package/src/index.ts +5 -0
- package/src/lib/getErrorMessage.ts +17 -0
- package/src/lib/metaData.ts +21 -0
- package/src/lib/verifyConfig.ts +37 -0
- package/src/notify.ts +38 -0
- package/src/types.ts +27 -0
- package/dist/action.d.ts +0 -9
- package/dist/action.d.ts.map +0 -1
- package/dist/client.d.ts +0 -3
- package/dist/client.d.ts.map +0 -1
- package/dist/config.d.ts +0 -3
- package/dist/config.d.ts.map +0 -1
- package/dist/event.d.ts +0 -81
- package/dist/event.d.ts.map +0 -1
- package/dist/extension.d.ts +0 -12
- package/dist/extension.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/lib/getErrorMessage.d.ts +0 -4
- package/dist/lib/getErrorMessage.d.ts.map +0 -1
- package/dist/lib/metaData.d.ts +0 -5
- package/dist/lib/metaData.d.ts.map +0 -1
- package/dist/lib/verifyConfig.d.ts +0 -8
- package/dist/lib/verifyConfig.d.ts.map +0 -1
- package/dist/notify.d.ts +0 -9
- package/dist/notify.d.ts.map +0 -1
- package/dist/ohbug-core.cjs.js +0 -687
- package/dist/ohbug-core.esm.js +0 -680
- package/dist/ohbug-core.esm.min.js +0 -29
- package/dist/ohbug-core.umd.js +0 -693
- package/dist/ohbug-core.umd.min.js +0 -29
package/README.md
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@ohbug/core)
|
|
4
4
|
[](https://bundlephobia.com/result?p=@ohbug/core)
|
|
5
|
-
[](https://github.com/prettier/prettier)
|
|
6
5
|
|
|
7
6
|
English | [简体中文](./README-zh_CN.md)
|
|
8
7
|
|
|
@@ -13,5 +12,5 @@ ohbug's core module is responsible for managing ohbug's workflow.
|
|
|
13
12
|
## Installation
|
|
14
13
|
|
|
15
14
|
```
|
|
16
|
-
|
|
15
|
+
pnpm instal @ohbug/core
|
|
17
16
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { OhbugClientConstructor, OhbugEventWithMethods, OhbugExtension, OhbugExtensionUI } 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
|
+
declare function createExtensionUI(extensionUI: OhbugExtensionUI): OhbugExtensionUI;
|
|
9
|
+
|
|
10
|
+
declare const enum EventTypes {
|
|
11
|
+
UNCAUGHT_ERROR = "uncaughtError",
|
|
12
|
+
RESOURCE_ERROR = "resourceError",
|
|
13
|
+
UNHANDLEDREJECTION_ERROR = "unhandledrejectionError",
|
|
14
|
+
AJAX_ERROR = "ajaxError",
|
|
15
|
+
FETCH_ERROR = "fetchError",
|
|
16
|
+
WEBSOCKET_ERROR = "websocketError",
|
|
17
|
+
UNKNOWN_ERROR = "unknownError",
|
|
18
|
+
MESSAGE = "message",
|
|
19
|
+
FEEDBACK = "feedback",
|
|
20
|
+
VIEW = "view",
|
|
21
|
+
REACT = "react",
|
|
22
|
+
VUE = "vue",
|
|
23
|
+
ANGULAR = "angular",
|
|
24
|
+
MINIAPP_ERROR = "miniappError",
|
|
25
|
+
MINIAPP_UNHANDLEDREJECTION_ERROR = "miniappUnhandledrejectionError",
|
|
26
|
+
MINIAPP_PAGENOTFOUND_ERROR = "miniappPagenotfoundError",
|
|
27
|
+
MINIAPP_MEMORYWARNING_ERROR = "miniappMemorywarningError"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type types_EventTypes = EventTypes;
|
|
31
|
+
declare const types_EventTypes: typeof EventTypes;
|
|
32
|
+
declare namespace types {
|
|
33
|
+
export {
|
|
34
|
+
types_EventTypes as EventTypes,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { Client, EventTypes, createExtensionUI, defineExtension, isEvent, types };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
22
|
+
};
|
|
23
|
+
var __copyProps = (to, from, except, desc) => {
|
|
24
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
25
|
+
for (let key of __getOwnPropNames(from))
|
|
26
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
27
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
28
|
+
}
|
|
29
|
+
return to;
|
|
30
|
+
};
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
|
|
33
|
+
// src/index.ts
|
|
34
|
+
var src_exports = {};
|
|
35
|
+
__export(src_exports, {
|
|
36
|
+
Client: () => Client,
|
|
37
|
+
EventTypes: () => EventTypes,
|
|
38
|
+
createExtensionUI: () => createExtensionUI,
|
|
39
|
+
defineExtension: () => defineExtension,
|
|
40
|
+
isEvent: () => isEvent,
|
|
41
|
+
types: () => types_exports
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(src_exports);
|
|
44
|
+
|
|
45
|
+
// src/client.ts
|
|
46
|
+
var import_utils4 = require("@ohbug/utils");
|
|
47
|
+
|
|
48
|
+
// src/config.ts
|
|
49
|
+
var import_utils = require("@ohbug/utils");
|
|
50
|
+
var schema = {
|
|
51
|
+
apiKey: {
|
|
52
|
+
defaultValue: void 0,
|
|
53
|
+
message: "is required",
|
|
54
|
+
validate: (value) => Boolean(value) && (0, import_utils.isString)(value)
|
|
55
|
+
},
|
|
56
|
+
appVersion: {
|
|
57
|
+
defaultValue: void 0,
|
|
58
|
+
message: "should be a string",
|
|
59
|
+
validate: (value) => value === void 0 || (0, import_utils.isString)(value)
|
|
60
|
+
},
|
|
61
|
+
appType: {
|
|
62
|
+
defaultValue: void 0,
|
|
63
|
+
message: "should be a string",
|
|
64
|
+
validate: (value) => value === void 0 || (0, import_utils.isString)(value)
|
|
65
|
+
},
|
|
66
|
+
releaseStage: {
|
|
67
|
+
defaultValue: "production",
|
|
68
|
+
message: "should be a string",
|
|
69
|
+
validate: (value) => value === void 0 || (0, import_utils.isString)(value)
|
|
70
|
+
},
|
|
71
|
+
endpoint: {
|
|
72
|
+
defaultValue: "http://localhost:6660",
|
|
73
|
+
message: "should be a string",
|
|
74
|
+
validate: (value) => value === void 0 || (0, import_utils.isString)(value)
|
|
75
|
+
},
|
|
76
|
+
maxActions: {
|
|
77
|
+
defaultValue: 30,
|
|
78
|
+
message: "should be a number between 0 and 100",
|
|
79
|
+
validate: (value) => value === void 0 || (0, import_utils.isNumber)(value) && value >= 1 && value <= 100
|
|
80
|
+
},
|
|
81
|
+
created: {
|
|
82
|
+
defaultValue: (event) => event,
|
|
83
|
+
message: "should be a function",
|
|
84
|
+
validate: (value) => value === void 0 || (0, import_utils.isFunction)(value)
|
|
85
|
+
},
|
|
86
|
+
notified: {
|
|
87
|
+
defaultValue: () => {
|
|
88
|
+
},
|
|
89
|
+
message: "should be a function",
|
|
90
|
+
validate: (value) => value === void 0 || (0, import_utils.isFunction)(value)
|
|
91
|
+
},
|
|
92
|
+
logger: {
|
|
93
|
+
defaultValue: import_utils.logger,
|
|
94
|
+
message: "should be null or an object with methods { log, info, warn, error }",
|
|
95
|
+
validate: (value) => value === void 0 || value && ["log", "info", "warn", "error"].reduce((accumulator, method) => accumulator && typeof value[method] === "function", true)
|
|
96
|
+
},
|
|
97
|
+
user: {
|
|
98
|
+
defaultValue: void 0,
|
|
99
|
+
message: "should be an object and have up to 6 attributes",
|
|
100
|
+
validate: (value) => value === void 0 || (0, import_utils.isObject)(value) && Object.keys(value).length <= 6
|
|
101
|
+
},
|
|
102
|
+
metaData: {
|
|
103
|
+
defaultValue: void 0,
|
|
104
|
+
message: "should be an object",
|
|
105
|
+
validate: (value) => value === void 0 || (0, import_utils.isObject)(value)
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// src/event.ts
|
|
110
|
+
var import_utils2 = require("@ohbug/utils");
|
|
111
|
+
|
|
112
|
+
// src/action.ts
|
|
113
|
+
var Action = class {
|
|
114
|
+
type;
|
|
115
|
+
timestamp;
|
|
116
|
+
message;
|
|
117
|
+
data;
|
|
118
|
+
constructor(message, data, type, timestamp) {
|
|
119
|
+
this.type = type;
|
|
120
|
+
this.timestamp = timestamp || new Date().toISOString();
|
|
121
|
+
this.message = message;
|
|
122
|
+
this.data = data;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// src/lib/getErrorMessage.ts
|
|
127
|
+
function getConfigErrorMessage(errors, config) {
|
|
128
|
+
return new Error(`Invalid configuration
|
|
129
|
+
${Object.keys(errors).map((key) => {
|
|
130
|
+
return `- ${key} ${errors[key]}, got ${JSON.stringify(config[key])}`;
|
|
131
|
+
}).join("\n")}
|
|
132
|
+
`);
|
|
133
|
+
}
|
|
134
|
+
function getErrorMessage(message, data) {
|
|
135
|
+
return new Error(`Invalid data
|
|
136
|
+
- ${message}, got ${JSON.stringify(data)}`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// src/lib/metaData.ts
|
|
140
|
+
function addMetaData(map, section, data) {
|
|
141
|
+
if (!section)
|
|
142
|
+
return;
|
|
143
|
+
map[section] = data;
|
|
144
|
+
}
|
|
145
|
+
function getMetaData(map, section) {
|
|
146
|
+
if (map[section])
|
|
147
|
+
return map[section];
|
|
148
|
+
return void 0;
|
|
149
|
+
}
|
|
150
|
+
function deleteMetaData(map, section) {
|
|
151
|
+
if (map[section])
|
|
152
|
+
return delete map[section];
|
|
153
|
+
return void 0;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/event.ts
|
|
157
|
+
var Event = class {
|
|
158
|
+
apiKey;
|
|
159
|
+
appVersion;
|
|
160
|
+
appType;
|
|
161
|
+
timestamp;
|
|
162
|
+
category;
|
|
163
|
+
type;
|
|
164
|
+
sdk;
|
|
165
|
+
device;
|
|
166
|
+
detail;
|
|
167
|
+
user;
|
|
168
|
+
actions;
|
|
169
|
+
metaData;
|
|
170
|
+
releaseStage;
|
|
171
|
+
__client;
|
|
172
|
+
constructor(values, client) {
|
|
173
|
+
const {
|
|
174
|
+
apiKey,
|
|
175
|
+
appVersion,
|
|
176
|
+
appType,
|
|
177
|
+
releaseStage,
|
|
178
|
+
timestamp,
|
|
179
|
+
category,
|
|
180
|
+
type,
|
|
181
|
+
sdk,
|
|
182
|
+
detail,
|
|
183
|
+
device,
|
|
184
|
+
user,
|
|
185
|
+
actions,
|
|
186
|
+
metaData
|
|
187
|
+
} = values;
|
|
188
|
+
this.apiKey = apiKey;
|
|
189
|
+
this.appVersion = appVersion;
|
|
190
|
+
this.appType = appType;
|
|
191
|
+
this.releaseStage = releaseStage;
|
|
192
|
+
this.timestamp = timestamp;
|
|
193
|
+
this.category = category;
|
|
194
|
+
this.type = type;
|
|
195
|
+
this.sdk = sdk;
|
|
196
|
+
this.detail = detail;
|
|
197
|
+
this.device = device;
|
|
198
|
+
this.user = user;
|
|
199
|
+
this.actions = actions;
|
|
200
|
+
this.metaData = metaData != null ? metaData : {};
|
|
201
|
+
this.__client = client;
|
|
202
|
+
}
|
|
203
|
+
get __isOhbugEvent() {
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
addAction(message, data, type, timestamp) {
|
|
207
|
+
var _a, _b;
|
|
208
|
+
const actions = this.actions;
|
|
209
|
+
const targetMessage = (0, import_utils2.isString)(message) ? message : "";
|
|
210
|
+
const targetData = data || {};
|
|
211
|
+
const targetType = (0, import_utils2.isString)(type) ? type : "";
|
|
212
|
+
const action = new Action(targetMessage, targetData, targetType, timestamp);
|
|
213
|
+
if (actions.length >= ((_b = (_a = this.__client) == null ? void 0 : _a.__config.maxActions) != null ? _b : 30))
|
|
214
|
+
actions.shift();
|
|
215
|
+
actions.push(action);
|
|
216
|
+
}
|
|
217
|
+
getUser() {
|
|
218
|
+
return this.user;
|
|
219
|
+
}
|
|
220
|
+
setUser(user) {
|
|
221
|
+
var _a;
|
|
222
|
+
if ((0, import_utils2.isObject)(user) && Object.keys(user).length <= 6) {
|
|
223
|
+
this.user = __spreadValues(__spreadValues({}, this.user), user);
|
|
224
|
+
return this.getUser();
|
|
225
|
+
}
|
|
226
|
+
(_a = this.__client) == null ? void 0 : _a.__logger.error(getErrorMessage("setUser should be an object and have up to 6 attributes", user));
|
|
227
|
+
return void 0;
|
|
228
|
+
}
|
|
229
|
+
addMetaData(section, data) {
|
|
230
|
+
return addMetaData(this.metaData, section, data);
|
|
231
|
+
}
|
|
232
|
+
getMetaData(section) {
|
|
233
|
+
return getMetaData(this.metaData, section);
|
|
234
|
+
}
|
|
235
|
+
deleteMetaData(section) {
|
|
236
|
+
return deleteMetaData(this.metaData, section);
|
|
237
|
+
}
|
|
238
|
+
toJSON() {
|
|
239
|
+
const {
|
|
240
|
+
apiKey,
|
|
241
|
+
appVersion,
|
|
242
|
+
appType,
|
|
243
|
+
timestamp,
|
|
244
|
+
category,
|
|
245
|
+
type,
|
|
246
|
+
sdk,
|
|
247
|
+
device,
|
|
248
|
+
detail,
|
|
249
|
+
user,
|
|
250
|
+
actions,
|
|
251
|
+
metaData,
|
|
252
|
+
releaseStage
|
|
253
|
+
} = this;
|
|
254
|
+
return {
|
|
255
|
+
apiKey,
|
|
256
|
+
appVersion,
|
|
257
|
+
appType,
|
|
258
|
+
timestamp,
|
|
259
|
+
category,
|
|
260
|
+
type,
|
|
261
|
+
sdk,
|
|
262
|
+
device,
|
|
263
|
+
detail,
|
|
264
|
+
user,
|
|
265
|
+
actions,
|
|
266
|
+
metaData,
|
|
267
|
+
releaseStage
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
function createEvent(values, client) {
|
|
272
|
+
const { apiKey, appVersion, appType, releaseStage } = client.__config;
|
|
273
|
+
const timestamp = new Date().toISOString();
|
|
274
|
+
const device = client.__device(client);
|
|
275
|
+
let category;
|
|
276
|
+
let type;
|
|
277
|
+
let detail;
|
|
278
|
+
if ((0, import_utils2.isObject)(values) && Object.prototype.hasOwnProperty.call(values, "type") && Object.prototype.hasOwnProperty.call(values, "detail")) {
|
|
279
|
+
category = values.category || "error";
|
|
280
|
+
type = values.type;
|
|
281
|
+
detail = values.detail;
|
|
282
|
+
} else {
|
|
283
|
+
category = "error";
|
|
284
|
+
type = "unknownError";
|
|
285
|
+
detail = values;
|
|
286
|
+
}
|
|
287
|
+
return new Event({
|
|
288
|
+
apiKey,
|
|
289
|
+
appVersion,
|
|
290
|
+
appType,
|
|
291
|
+
timestamp,
|
|
292
|
+
category,
|
|
293
|
+
type,
|
|
294
|
+
sdk: client.__sdk,
|
|
295
|
+
device,
|
|
296
|
+
user: client.__user,
|
|
297
|
+
detail,
|
|
298
|
+
actions: client.__actions,
|
|
299
|
+
metaData: client.__metaData,
|
|
300
|
+
releaseStage
|
|
301
|
+
}, client);
|
|
302
|
+
}
|
|
303
|
+
function handleEventCreated(event, client) {
|
|
304
|
+
const funcs = [
|
|
305
|
+
client.__config.created,
|
|
306
|
+
...client.__extensions.map(({ created }) => created)
|
|
307
|
+
].filter((v) => (0, import_utils2.isFunction)(v));
|
|
308
|
+
if (funcs.length === 0)
|
|
309
|
+
return event;
|
|
310
|
+
return funcs.reduce((previous, current) => {
|
|
311
|
+
if (previous && (0, import_utils2.isFunction)(current))
|
|
312
|
+
return current(previous, client);
|
|
313
|
+
return null;
|
|
314
|
+
}, event);
|
|
315
|
+
}
|
|
316
|
+
function isEvent(eventLike) {
|
|
317
|
+
return Boolean(eventLike == null ? void 0 : eventLike.__isOhbugEvent);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// src/notify.ts
|
|
321
|
+
var import_utils3 = require("@ohbug/utils");
|
|
322
|
+
function handleNotified(event, client) {
|
|
323
|
+
const funcs = [
|
|
324
|
+
client.__config.notified,
|
|
325
|
+
...client.__extensions.filter(({ notified }) => (0, import_utils3.isFunction)(notified)).map(({ notified }) => notified)
|
|
326
|
+
];
|
|
327
|
+
funcs.forEach((func) => func == null ? void 0 : func(event, client));
|
|
328
|
+
}
|
|
329
|
+
async function notify(event, client) {
|
|
330
|
+
try {
|
|
331
|
+
let result = null;
|
|
332
|
+
if (event) {
|
|
333
|
+
result = await client.__notifier(event);
|
|
334
|
+
handleNotified(event, client);
|
|
335
|
+
}
|
|
336
|
+
return result;
|
|
337
|
+
} catch (e) {
|
|
338
|
+
client.__logger.error(e);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// src/lib/verifyConfig.ts
|
|
343
|
+
function verifyConfig(config, schema2) {
|
|
344
|
+
const keys = Object.keys(schema2);
|
|
345
|
+
return keys.reduce((accumulator, key) => {
|
|
346
|
+
const configValue = config[key];
|
|
347
|
+
const { defaultValue, message, validate } = schema2[key];
|
|
348
|
+
if (configValue !== void 0) {
|
|
349
|
+
const valid = validate(configValue);
|
|
350
|
+
if (valid) {
|
|
351
|
+
accumulator.config[key] = configValue;
|
|
352
|
+
} else {
|
|
353
|
+
accumulator.config[key] = defaultValue;
|
|
354
|
+
accumulator.errors[key] = message;
|
|
355
|
+
}
|
|
356
|
+
} else {
|
|
357
|
+
accumulator.config[key] = defaultValue;
|
|
358
|
+
}
|
|
359
|
+
return accumulator;
|
|
360
|
+
}, {
|
|
361
|
+
config: {},
|
|
362
|
+
errors: {}
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// src/client.ts
|
|
367
|
+
var Client = class Client2 {
|
|
368
|
+
__sdk;
|
|
369
|
+
__config;
|
|
370
|
+
__logger;
|
|
371
|
+
__device;
|
|
372
|
+
__notifier;
|
|
373
|
+
__extensions;
|
|
374
|
+
__actions;
|
|
375
|
+
__user;
|
|
376
|
+
__metaData;
|
|
377
|
+
constructor({
|
|
378
|
+
sdk,
|
|
379
|
+
config: baseConfig,
|
|
380
|
+
schema: schema2 = schema,
|
|
381
|
+
device,
|
|
382
|
+
notifier
|
|
383
|
+
}) {
|
|
384
|
+
const { config, errors } = verifyConfig(baseConfig, schema2);
|
|
385
|
+
this.__sdk = sdk;
|
|
386
|
+
this.__config = config;
|
|
387
|
+
this.__logger = config.logger;
|
|
388
|
+
this.__device = device;
|
|
389
|
+
this.__notifier = notifier;
|
|
390
|
+
this.__extensions = [];
|
|
391
|
+
this.__actions = [];
|
|
392
|
+
this.__user = config.user;
|
|
393
|
+
this.__metaData = {};
|
|
394
|
+
if ((0, import_utils4.isObject)(config.metaData)) {
|
|
395
|
+
Object.keys(config.metaData).forEach((key) => {
|
|
396
|
+
this.addMetaData(key, config.metaData[key]);
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
if (Object.keys(errors).length)
|
|
400
|
+
this.__logger.warn(getConfigErrorMessage(errors, baseConfig));
|
|
401
|
+
}
|
|
402
|
+
use(extension) {
|
|
403
|
+
var _a;
|
|
404
|
+
this.__extensions.push(extension);
|
|
405
|
+
(_a = extension.setup) == null ? void 0 : _a.call(extension, this);
|
|
406
|
+
return this;
|
|
407
|
+
}
|
|
408
|
+
createEvent(value) {
|
|
409
|
+
const event = createEvent(value, this);
|
|
410
|
+
return handleEventCreated(event, this);
|
|
411
|
+
}
|
|
412
|
+
notify(eventLike, beforeNotify) {
|
|
413
|
+
let event;
|
|
414
|
+
if (Boolean(eventLike) && !isEvent(eventLike))
|
|
415
|
+
event = this.createEvent(eventLike);
|
|
416
|
+
else
|
|
417
|
+
event = eventLike;
|
|
418
|
+
if (beforeNotify)
|
|
419
|
+
event = beforeNotify(event);
|
|
420
|
+
return notify(event, this);
|
|
421
|
+
}
|
|
422
|
+
addAction(message, data, type, timestamp) {
|
|
423
|
+
const actions = this.__actions;
|
|
424
|
+
const targetMessage = (0, import_utils4.isString)(message) ? message : "";
|
|
425
|
+
const targetData = data || {};
|
|
426
|
+
const targetType = (0, import_utils4.isString)(type) ? type : "";
|
|
427
|
+
const action = new Action(targetMessage, targetData, targetType, timestamp);
|
|
428
|
+
if (actions.length >= this.__config.maxActions)
|
|
429
|
+
actions.shift();
|
|
430
|
+
actions.push(action);
|
|
431
|
+
}
|
|
432
|
+
getUser() {
|
|
433
|
+
return this.__user;
|
|
434
|
+
}
|
|
435
|
+
setUser(user) {
|
|
436
|
+
if ((0, import_utils4.isObject)(user) && Object.keys(user).length <= 6) {
|
|
437
|
+
this.__user = __spreadValues(__spreadValues({}, this.__user), user);
|
|
438
|
+
return this.getUser();
|
|
439
|
+
}
|
|
440
|
+
this.__logger.warn(getErrorMessage("setUser should be an object and have up to 6 attributes", user));
|
|
441
|
+
return void 0;
|
|
442
|
+
}
|
|
443
|
+
addMetaData(section, data) {
|
|
444
|
+
return addMetaData(this.__metaData, section, data);
|
|
445
|
+
}
|
|
446
|
+
getMetaData(section) {
|
|
447
|
+
return getMetaData(this.__metaData, section);
|
|
448
|
+
}
|
|
449
|
+
deleteMetaData(section) {
|
|
450
|
+
return deleteMetaData(this.__metaData, section);
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
// src/extension.ts
|
|
455
|
+
function defineExtension(extension) {
|
|
456
|
+
return extension;
|
|
457
|
+
}
|
|
458
|
+
function createExtensionUI(extensionUI) {
|
|
459
|
+
return extensionUI;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// src/types.ts
|
|
463
|
+
var types_exports = {};
|
|
464
|
+
__export(types_exports, {
|
|
465
|
+
EventTypes: () => EventTypes
|
|
466
|
+
});
|
|
467
|
+
var EventTypes = /* @__PURE__ */ ((EventTypes2) => {
|
|
468
|
+
EventTypes2["UNCAUGHT_ERROR"] = "uncaughtError";
|
|
469
|
+
EventTypes2["RESOURCE_ERROR"] = "resourceError";
|
|
470
|
+
EventTypes2["UNHANDLEDREJECTION_ERROR"] = "unhandledrejectionError";
|
|
471
|
+
EventTypes2["AJAX_ERROR"] = "ajaxError";
|
|
472
|
+
EventTypes2["FETCH_ERROR"] = "fetchError";
|
|
473
|
+
EventTypes2["WEBSOCKET_ERROR"] = "websocketError";
|
|
474
|
+
EventTypes2["UNKNOWN_ERROR"] = "unknownError";
|
|
475
|
+
EventTypes2["MESSAGE"] = "message";
|
|
476
|
+
EventTypes2["FEEDBACK"] = "feedback";
|
|
477
|
+
EventTypes2["VIEW"] = "view";
|
|
478
|
+
EventTypes2["REACT"] = "react";
|
|
479
|
+
EventTypes2["VUE"] = "vue";
|
|
480
|
+
EventTypes2["ANGULAR"] = "angular";
|
|
481
|
+
EventTypes2["MINIAPP_ERROR"] = "miniappError";
|
|
482
|
+
EventTypes2["MINIAPP_UNHANDLEDREJECTION_ERROR"] = "miniappUnhandledrejectionError";
|
|
483
|
+
EventTypes2["MINIAPP_PAGENOTFOUND_ERROR"] = "miniappPagenotfoundError";
|
|
484
|
+
EventTypes2["MINIAPP_MEMORYWARNING_ERROR"] = "miniappMemorywarningError";
|
|
485
|
+
return EventTypes2;
|
|
486
|
+
})(EventTypes || {});
|
|
487
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
488
|
+
0 && (module.exports = {
|
|
489
|
+
Client,
|
|
490
|
+
EventTypes,
|
|
491
|
+
createExtensionUI,
|
|
492
|
+
defineExtension,
|
|
493
|
+
isEvent,
|
|
494
|
+
types
|
|
495
|
+
});
|