@pluve/logger-sdk 0.0.1
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 +108 -0
- package/dist/cjs/dbQueue.d.ts +10 -0
- package/dist/cjs/dbQueue.js +88 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +29 -0
- package/dist/cjs/loggerSDK.d.ts +29 -0
- package/dist/cjs/loggerSDK.js +426 -0
- package/dist/cjs/storeAdapter.d.ts +7 -0
- package/dist/cjs/storeAdapter.js +64 -0
- package/dist/cjs/transportAdapter.d.ts +5 -0
- package/dist/cjs/transportAdapter.js +109 -0
- package/dist/cjs/types.d.ts +35 -0
- package/dist/cjs/types.js +17 -0
- package/dist/cjs/utils.d.ts +5 -0
- package/dist/cjs/utils.js +69 -0
- package/dist/esm/dbQueue.d.ts +10 -0
- package/dist/esm/dbQueue.js +194 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/loggerSDK.d.ts +29 -0
- package/dist/esm/loggerSDK.js +761 -0
- package/dist/esm/storeAdapter.d.ts +7 -0
- package/dist/esm/storeAdapter.js +139 -0
- package/dist/esm/transportAdapter.d.ts +5 -0
- package/dist/esm/transportAdapter.js +142 -0
- package/dist/esm/types.d.ts +35 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils.d.ts +5 -0
- package/dist/esm/utils.js +53 -0
- package/dist/umd/logger-sdk.min.js +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface StorageAdapter {
|
|
2
|
+
get(): Promise<string | null>;
|
|
3
|
+
set(val: string): Promise<void>;
|
|
4
|
+
remove(): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
export declare function browserStorage(key: string): StorageAdapter;
|
|
7
|
+
export declare function wechatStorage(key: string): StorageAdapter;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/storeAdapter.ts
|
|
20
|
+
var storeAdapter_exports = {};
|
|
21
|
+
__export(storeAdapter_exports, {
|
|
22
|
+
browserStorage: () => browserStorage,
|
|
23
|
+
wechatStorage: () => wechatStorage
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(storeAdapter_exports);
|
|
26
|
+
function browserStorage(key) {
|
|
27
|
+
return {
|
|
28
|
+
async get() {
|
|
29
|
+
return Promise.resolve(localStorage.getItem(key));
|
|
30
|
+
},
|
|
31
|
+
async set(val) {
|
|
32
|
+
localStorage.setItem(key, val);
|
|
33
|
+
return Promise.resolve();
|
|
34
|
+
},
|
|
35
|
+
async remove() {
|
|
36
|
+
localStorage.removeItem(key);
|
|
37
|
+
return Promise.resolve();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function wechatStorage(key) {
|
|
42
|
+
return {
|
|
43
|
+
async get() {
|
|
44
|
+
return new Promise((res) => {
|
|
45
|
+
wx.getStorage({ key, success: (r) => res(r.data), fail: () => res(null) });
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
async set(val) {
|
|
49
|
+
return new Promise((res) => {
|
|
50
|
+
wx.setStorage({ key, data: val, success: () => res(void 0), fail: () => res(void 0) });
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
async remove() {
|
|
54
|
+
return new Promise((res) => {
|
|
55
|
+
wx.removeStorage({ key, success: () => res(void 0), fail: () => res(void 0) });
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
browserStorage,
|
|
63
|
+
wechatStorage
|
|
64
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/transportAdapter.ts
|
|
20
|
+
var transportAdapter_exports = {};
|
|
21
|
+
__export(transportAdapter_exports, {
|
|
22
|
+
defaultTransport: () => defaultTransport
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(transportAdapter_exports);
|
|
25
|
+
var import_utils = require("./utils");
|
|
26
|
+
async function defaultTransport(payload, opts) {
|
|
27
|
+
var _a;
|
|
28
|
+
const body = typeof payload === "string" ? payload : (0, import_utils.safeStringify)(payload);
|
|
29
|
+
const timeout = (opts == null ? void 0 : opts.timeout) || 1e4;
|
|
30
|
+
const endpoint = opts && opts.endpoint ? opts.endpoint : ((_a = opts.endpoints) == null ? void 0 : _a.default) || "";
|
|
31
|
+
if ((0, import_utils.isBrowser)() && typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function" && (opts == null ? void 0 : opts.useBeacon)) {
|
|
32
|
+
const blob = new Blob([body], { type: "application/json" });
|
|
33
|
+
const ok = navigator.sendBeacon(endpoint || "", blob);
|
|
34
|
+
if (ok)
|
|
35
|
+
return Promise.resolve();
|
|
36
|
+
return Promise.reject(new Error("sendBeacon failed"));
|
|
37
|
+
}
|
|
38
|
+
if ((0, import_utils.isWeChatMiniProgram)()) {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
let timer = null;
|
|
41
|
+
wx.request({
|
|
42
|
+
url: endpoint || "",
|
|
43
|
+
method: "POST",
|
|
44
|
+
data: body,
|
|
45
|
+
header: { "Content-Type": "application/json", ...opts && opts.globalHeaders ? opts.globalHeaders : {} },
|
|
46
|
+
success() {
|
|
47
|
+
if (timer)
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
resolve();
|
|
50
|
+
},
|
|
51
|
+
fail(err) {
|
|
52
|
+
if (timer)
|
|
53
|
+
clearTimeout(timer);
|
|
54
|
+
reject(err);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
timer = setTimeout(() => reject(new Error("timeout")), timeout);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if ((0, import_utils.isBrowser)() && (opts == null ? void 0 : opts.usePixel)) {
|
|
61
|
+
const param = (opts == null ? void 0 : opts.pixelParam) || "data";
|
|
62
|
+
const cacheBuster = `_=${(0, import_utils.now)()}`;
|
|
63
|
+
const urlBase = endpoint || "";
|
|
64
|
+
const qs = `${param}=${encodeURIComponent(body)}&${cacheBuster}`;
|
|
65
|
+
const url = urlBase.includes("?") ? `${urlBase}&${qs}` : `${urlBase}?${qs}`;
|
|
66
|
+
const maxLen = (opts == null ? void 0 : opts.maxPixelUrlLen) || 1900;
|
|
67
|
+
if (url.length > maxLen) {
|
|
68
|
+
} else {
|
|
69
|
+
const img = new Image();
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
let timer = null;
|
|
72
|
+
img.onload = () => {
|
|
73
|
+
if (timer)
|
|
74
|
+
clearTimeout(timer);
|
|
75
|
+
resolve();
|
|
76
|
+
};
|
|
77
|
+
img.onerror = () => {
|
|
78
|
+
if (timer)
|
|
79
|
+
clearTimeout(timer);
|
|
80
|
+
reject(new Error("pixel error"));
|
|
81
|
+
};
|
|
82
|
+
timer = setTimeout(() => reject(new Error("timeout")), timeout);
|
|
83
|
+
img.src = url;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (typeof fetch === "function") {
|
|
88
|
+
const controller = typeof AbortController !== "undefined" ? new AbortController() : null;
|
|
89
|
+
if (controller)
|
|
90
|
+
setTimeout(() => controller.abort(), timeout);
|
|
91
|
+
return fetch(endpoint || "", {
|
|
92
|
+
method: "POST",
|
|
93
|
+
headers: { "Content-Type": "application/json", ...opts && opts.globalHeaders ? opts.globalHeaders : {}, ...opts && opts.headers ? opts.headers : {} },
|
|
94
|
+
body,
|
|
95
|
+
// 在页面关闭场景提供尽力传输能力(非标准环境忽略)
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
keepalive: (opts == null ? void 0 : opts.useBeacon) ? true : void 0,
|
|
98
|
+
signal: controller ? controller.signal : void 0
|
|
99
|
+
}).then((res) => {
|
|
100
|
+
if (!res.ok)
|
|
101
|
+
throw new Error("network response not ok");
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return Promise.reject(new Error("no transport available"));
|
|
105
|
+
}
|
|
106
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
+
0 && (module.exports = {
|
|
108
|
+
defaultTransport
|
|
109
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type Env = 'h5' | 'wechat' | 'unknown';
|
|
2
|
+
export type LogEventType = 'event' | 'error' | 'pageview' | 'perf' | 'custom';
|
|
3
|
+
export type LogEventLevel = 'info' | 'warn' | 'error' | 'debug';
|
|
4
|
+
export interface SDKOptions {
|
|
5
|
+
endpoints: Partial<Record<'info' | 'warn' | 'error' | 'default', string>>;
|
|
6
|
+
appId?: string;
|
|
7
|
+
env?: Env;
|
|
8
|
+
batchSize?: number;
|
|
9
|
+
flushInterval?: number;
|
|
10
|
+
retryCount?: number;
|
|
11
|
+
retryBase?: number;
|
|
12
|
+
storageKey?: string;
|
|
13
|
+
maxCacheSize?: number;
|
|
14
|
+
timeout?: number;
|
|
15
|
+
debug?: boolean;
|
|
16
|
+
transport?: (payload: any, opts?: SDKOptions & {
|
|
17
|
+
endpoint?: string;
|
|
18
|
+
headers?: Record<string, string>;
|
|
19
|
+
}) => Promise<void>;
|
|
20
|
+
globalHeaders?: Record<string, string>;
|
|
21
|
+
enableAutoPV?: boolean;
|
|
22
|
+
enablePerf?: boolean;
|
|
23
|
+
useBeacon?: boolean;
|
|
24
|
+
usePixel?: boolean;
|
|
25
|
+
pixelParam?: string;
|
|
26
|
+
maxPixelUrlLen?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface LogEvent {
|
|
29
|
+
type: LogEventType;
|
|
30
|
+
time: number;
|
|
31
|
+
user?: Record<string, any>;
|
|
32
|
+
ctx?: Record<string, any>;
|
|
33
|
+
level?: LogEventLevel;
|
|
34
|
+
seq?: number;
|
|
35
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
|
|
15
|
+
// src/types.ts
|
|
16
|
+
var types_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/utils.ts
|
|
20
|
+
var utils_exports = {};
|
|
21
|
+
__export(utils_exports, {
|
|
22
|
+
isBrowser: () => isBrowser,
|
|
23
|
+
isIndexedDBAvailable: () => isIndexedDBAvailable,
|
|
24
|
+
isWeChatMiniProgram: () => isWeChatMiniProgram,
|
|
25
|
+
now: () => now,
|
|
26
|
+
safeStringify: () => safeStringify
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(utils_exports);
|
|
29
|
+
var now = () => Date.now();
|
|
30
|
+
function isWeChatMiniProgram() {
|
|
31
|
+
try {
|
|
32
|
+
return typeof wx !== "undefined" && typeof wx.request === "function";
|
|
33
|
+
} catch (e) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function isBrowser() {
|
|
38
|
+
try {
|
|
39
|
+
return typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
40
|
+
} catch (e) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function safeStringify(obj) {
|
|
45
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
46
|
+
return JSON.stringify(obj, function(_k, v) {
|
|
47
|
+
if (v && typeof v === "object") {
|
|
48
|
+
if (seen.has(v))
|
|
49
|
+
return "[Circular]";
|
|
50
|
+
seen.add(v);
|
|
51
|
+
}
|
|
52
|
+
return v;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function isIndexedDBAvailable() {
|
|
56
|
+
try {
|
|
57
|
+
return typeof indexedDB !== "undefined";
|
|
58
|
+
} catch (e) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
isBrowser,
|
|
65
|
+
isIndexedDBAvailable,
|
|
66
|
+
isWeChatMiniProgram,
|
|
67
|
+
now,
|
|
68
|
+
safeStringify
|
|
69
|
+
});
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
7
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
8
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
10
|
+
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); }
|
|
11
|
+
/*
|
|
12
|
+
* @Author : 黄震 huangzhen@yfpharmacy.com
|
|
13
|
+
* @Date : 2025-11-21 14:32:51
|
|
14
|
+
* @LastEditors : 黄震 huangzhen@yfpharmacy.com
|
|
15
|
+
* @LastEditTime : 2025-11-21 14:38:50
|
|
16
|
+
* @Description : 描述
|
|
17
|
+
* Copyright (c) 2025 by 益丰大药房连锁股份有限公司, All Rights Reserved.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { isBrowser, isIndexedDBAvailable } from "./utils";
|
|
21
|
+
|
|
22
|
+
// IndexedDB 轻量队列:作为 localStorage 的冗余通道
|
|
23
|
+
var IDBQueue = /*#__PURE__*/function () {
|
|
24
|
+
function IDBQueue() {
|
|
25
|
+
var dbName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'logger_sdk_db';
|
|
26
|
+
var storeName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'queue';
|
|
27
|
+
_classCallCheck(this, IDBQueue);
|
|
28
|
+
_defineProperty(this, "dbName", void 0);
|
|
29
|
+
_defineProperty(this, "storeName", void 0);
|
|
30
|
+
_defineProperty(this, "db", null);
|
|
31
|
+
this.dbName = dbName;
|
|
32
|
+
this.storeName = storeName;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 打开数据库并初始化对象仓库
|
|
36
|
+
_createClass(IDBQueue, [{
|
|
37
|
+
key: "open",
|
|
38
|
+
value: function () {
|
|
39
|
+
var _open = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
40
|
+
var _this = this;
|
|
41
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
42
|
+
while (1) switch (_context.prev = _context.next) {
|
|
43
|
+
case 0:
|
|
44
|
+
if (!(!isBrowser() || !isIndexedDBAvailable())) {
|
|
45
|
+
_context.next = 2;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
return _context.abrupt("return");
|
|
49
|
+
case 2:
|
|
50
|
+
if (!this.db) {
|
|
51
|
+
_context.next = 4;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
return _context.abrupt("return");
|
|
55
|
+
case 4:
|
|
56
|
+
return _context.abrupt("return", new Promise(function (resolve, reject) {
|
|
57
|
+
var req = indexedDB.open(_this.dbName, 1);
|
|
58
|
+
req.onupgradeneeded = function () {
|
|
59
|
+
var db = req.result;
|
|
60
|
+
if (!db.objectStoreNames.contains(_this.storeName)) db.createObjectStore(_this.storeName, {
|
|
61
|
+
autoIncrement: true
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
req.onsuccess = function () {
|
|
65
|
+
_this.db = req.result;
|
|
66
|
+
resolve();
|
|
67
|
+
};
|
|
68
|
+
req.onerror = function () {
|
|
69
|
+
return reject(req.error);
|
|
70
|
+
};
|
|
71
|
+
}));
|
|
72
|
+
case 5:
|
|
73
|
+
case "end":
|
|
74
|
+
return _context.stop();
|
|
75
|
+
}
|
|
76
|
+
}, _callee, this);
|
|
77
|
+
}));
|
|
78
|
+
function open() {
|
|
79
|
+
return _open.apply(this, arguments);
|
|
80
|
+
}
|
|
81
|
+
return open;
|
|
82
|
+
}() // 入队:追加一条记录
|
|
83
|
+
}, {
|
|
84
|
+
key: "add",
|
|
85
|
+
value: function () {
|
|
86
|
+
var _add = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(item) {
|
|
87
|
+
var _this2 = this;
|
|
88
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
89
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
90
|
+
case 0:
|
|
91
|
+
if (this.db) {
|
|
92
|
+
_context2.next = 2;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
return _context2.abrupt("return");
|
|
96
|
+
case 2:
|
|
97
|
+
return _context2.abrupt("return", new Promise(function (res, rej) {
|
|
98
|
+
var tx = _this2.db.transaction(_this2.storeName, 'readwrite');
|
|
99
|
+
var st = tx.objectStore(_this2.storeName);
|
|
100
|
+
var r = st.add(item);
|
|
101
|
+
r.onsuccess = function () {
|
|
102
|
+
return res();
|
|
103
|
+
};
|
|
104
|
+
r.onerror = function () {
|
|
105
|
+
return rej(r.error);
|
|
106
|
+
};
|
|
107
|
+
}));
|
|
108
|
+
case 3:
|
|
109
|
+
case "end":
|
|
110
|
+
return _context2.stop();
|
|
111
|
+
}
|
|
112
|
+
}, _callee2, this);
|
|
113
|
+
}));
|
|
114
|
+
function add(_x) {
|
|
115
|
+
return _add.apply(this, arguments);
|
|
116
|
+
}
|
|
117
|
+
return add;
|
|
118
|
+
}() // 读取全部记录(调试/回溯用)
|
|
119
|
+
}, {
|
|
120
|
+
key: "getAll",
|
|
121
|
+
value: function () {
|
|
122
|
+
var _getAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
123
|
+
var _this3 = this;
|
|
124
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
125
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
126
|
+
case 0:
|
|
127
|
+
if (this.db) {
|
|
128
|
+
_context3.next = 2;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
return _context3.abrupt("return", []);
|
|
132
|
+
case 2:
|
|
133
|
+
return _context3.abrupt("return", new Promise(function (res, rej) {
|
|
134
|
+
var tx = _this3.db.transaction(_this3.storeName, 'readonly');
|
|
135
|
+
var st = tx.objectStore(_this3.storeName);
|
|
136
|
+
var req = st.getAll();
|
|
137
|
+
req.onsuccess = function () {
|
|
138
|
+
return res(req.result || []);
|
|
139
|
+
};
|
|
140
|
+
req.onerror = function () {
|
|
141
|
+
return rej(req.error);
|
|
142
|
+
};
|
|
143
|
+
}));
|
|
144
|
+
case 3:
|
|
145
|
+
case "end":
|
|
146
|
+
return _context3.stop();
|
|
147
|
+
}
|
|
148
|
+
}, _callee3, this);
|
|
149
|
+
}));
|
|
150
|
+
function getAll() {
|
|
151
|
+
return _getAll.apply(this, arguments);
|
|
152
|
+
}
|
|
153
|
+
return getAll;
|
|
154
|
+
}() // 清空队列:发送成功后用于兜底清理
|
|
155
|
+
}, {
|
|
156
|
+
key: "clear",
|
|
157
|
+
value: function () {
|
|
158
|
+
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
159
|
+
var _this4 = this;
|
|
160
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
161
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
162
|
+
case 0:
|
|
163
|
+
if (this.db) {
|
|
164
|
+
_context4.next = 2;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
return _context4.abrupt("return");
|
|
168
|
+
case 2:
|
|
169
|
+
return _context4.abrupt("return", new Promise(function (res, rej) {
|
|
170
|
+
var tx = _this4.db.transaction(_this4.storeName, 'readwrite');
|
|
171
|
+
var st = tx.objectStore(_this4.storeName);
|
|
172
|
+
var req = st.clear();
|
|
173
|
+
req.onsuccess = function () {
|
|
174
|
+
return res(undefined);
|
|
175
|
+
};
|
|
176
|
+
req.onerror = function () {
|
|
177
|
+
return rej(req.error);
|
|
178
|
+
};
|
|
179
|
+
}));
|
|
180
|
+
case 3:
|
|
181
|
+
case "end":
|
|
182
|
+
return _context4.stop();
|
|
183
|
+
}
|
|
184
|
+
}, _callee4, this);
|
|
185
|
+
}));
|
|
186
|
+
function clear() {
|
|
187
|
+
return _clear.apply(this, arguments);
|
|
188
|
+
}
|
|
189
|
+
return clear;
|
|
190
|
+
}()
|
|
191
|
+
}]);
|
|
192
|
+
return IDBQueue;
|
|
193
|
+
}();
|
|
194
|
+
export { IDBQueue as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { LoggerSDK } from './loggerSDK';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author : 黄震 huangzhen@yfpharmacy.com
|
|
3
|
+
* @Date : 2025-11-21 14:25:26
|
|
4
|
+
* @LastEditors : 黄震 huangzhen@yfpharmacy.com
|
|
5
|
+
* @LastEditTime : 2025-12-02 15:09:28
|
|
6
|
+
* @Description : 描述
|
|
7
|
+
* Copyright (c) 2025 by 益丰大药房连锁股份有限公司, All Rights Reserved.
|
|
8
|
+
*/
|
|
9
|
+
export { LoggerSDK } from "./loggerSDK";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { LogEvent, SDKOptions } from './types';
|
|
2
|
+
export declare class LoggerSDK {
|
|
3
|
+
private opts;
|
|
4
|
+
private env;
|
|
5
|
+
private inMemoryQueue;
|
|
6
|
+
private seq;
|
|
7
|
+
private timerId;
|
|
8
|
+
private storage;
|
|
9
|
+
private closed;
|
|
10
|
+
private idbQueue;
|
|
11
|
+
private flushing;
|
|
12
|
+
constructor(options: SDKOptions);
|
|
13
|
+
private logDebug;
|
|
14
|
+
private loadFromStorage;
|
|
15
|
+
private persistToStorage;
|
|
16
|
+
private startTimer;
|
|
17
|
+
private stopTimer;
|
|
18
|
+
track(event: Partial<LogEvent>, headers?: Record<string, string>): Promise<void>;
|
|
19
|
+
flush(extraHeaders?: Record<string, string>): Promise<void>;
|
|
20
|
+
flushAll(): Promise<void>;
|
|
21
|
+
identify(user: Record<string, any>): Promise<void>;
|
|
22
|
+
setCommon(params: Record<string, any>): Promise<void>;
|
|
23
|
+
destroy(): void;
|
|
24
|
+
private attachGlobalHandlers;
|
|
25
|
+
private installAutoPV;
|
|
26
|
+
private collectPerf;
|
|
27
|
+
private flushBeacon;
|
|
28
|
+
}
|
|
29
|
+
export default LoggerSDK;
|