@pluve/logger-sdk 0.0.15 → 0.0.17

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.
@@ -15,7 +15,7 @@ var HttpClient = class {
15
15
  data: JSON.stringify(data),
16
16
  header: {
17
17
  "Content-Type": "application/json",
18
- Authorization: `Bearer ${token}`
18
+ token
19
19
  },
20
20
  success: (res) => resolve({
21
21
  type: "wechat",
@@ -36,7 +36,7 @@ var HttpClient = class {
36
36
  const xhr = new XMLHttpRequest();
37
37
  xhr.open("POST", url, true);
38
38
  xhr.setRequestHeader("Content-Type", "application/json");
39
- xhr.setRequestHeader("Authorization", `Bearer ${token}`);
39
+ xhr.setRequestHeader("token", token);
40
40
  xhr.onreadystatechange = () => {
41
41
  if (xhr.readyState === 4) {
42
42
  if (xhr.status === 200) {
@@ -61,7 +61,7 @@ var HttpClient = class {
61
61
  body: JSON.stringify(data),
62
62
  headers: {
63
63
  "Content-Type": "application/json",
64
- Authorization: `Bearer ${token}`
64
+ token
65
65
  }
66
66
  }).then((res) => resolve({ type: "fetch", response: res })).catch((err) => reject({ type: "fetch", error: err }));
67
67
  });
@@ -12,6 +12,7 @@ import { uuid } from "../utils/uuid";
12
12
  import { HttpClient } from "./httpClient";
13
13
  import { QueueManager } from "./queueManager";
14
14
  import { RetryManager } from "./retryManager";
15
+ import { Md5 } from "../utils/innerMD5";
15
16
  var LoggerSDK = class {
16
17
  constructor() {
17
18
  /** 事件序列编号,用于事件去重 */
@@ -43,7 +44,8 @@ var LoggerSDK = class {
43
44
  init(options) {
44
45
  this.opts = {
45
46
  // endpoint: options.endpoint,
46
- appId: `${options.appId}-frontend` || "unknown",
47
+ appId: `${options.appId}`,
48
+ // 统一与 zadig 部署应用 APPID 保持一致
47
49
  env: options.env || "develop",
48
50
  /** 日志环境 */
49
51
  logStage: options.logStage,
@@ -425,6 +427,10 @@ var LoggerSDK = class {
425
427
  this.sessionId = void 0;
426
428
  LoggerSDK.instance = void 0;
427
429
  }
430
+ generateToken() {
431
+ var _a;
432
+ return ((_a = this.opts) == null ? void 0 : _a.token) || Md5.hashStr(`${this.opts.appId}${this.opts.logStage}${now()}`);
433
+ }
428
434
  // ========== 内部方法 ===========
429
435
  /**
430
436
  * 发送单个事件(带重试)
@@ -433,7 +439,7 @@ var LoggerSDK = class {
433
439
  const sendFn = async () => {
434
440
  const transporter = this.transporter || await TransportAdapter.getInstance(this.opts).getTransporter();
435
441
  this.transporter = transporter;
436
- await transporter.send({
442
+ await transporter.send(this.generateToken(), {
437
443
  appId: event.appId,
438
444
  appStage: event.stage,
439
445
  items: [
@@ -484,7 +490,7 @@ var LoggerSDK = class {
484
490
  const sendFn = async () => {
485
491
  const transporter = this.transporter || await TransportAdapter.getInstance(this.opts).getTransporter();
486
492
  this.transporter = transporter;
487
- await transporter.send({
493
+ await transporter.send(this.generateToken(), {
488
494
  appId: chunk[0].appId,
489
495
  appStage: chunk[0].stage,
490
496
  items: chunk.map((event) => ({
@@ -580,7 +586,7 @@ var LoggerSDK = class {
580
586
  userId: opts.userId,
581
587
  storeCode: opts.storeCode
582
588
  },
583
- opts.token
589
+ this.generateToken()
584
590
  ).then(async (response) => {
585
591
  var _a2, _b, _c;
586
592
  logDebug(!!((_a2 = this.opts) == null ? void 0 : _a2.debug), "Register success", response);
@@ -13,10 +13,10 @@ var BeaconTransport = class {
13
13
  isSupported() {
14
14
  return isBrowser() && typeof navigator !== "undefined" && navigator.sendBeacon && typeof navigator.sendBeacon === "function";
15
15
  }
16
- async send(payload) {
16
+ async send(token, payload) {
17
17
  var _a, _b, _c, _d, _e;
18
18
  let body = typeof payload === "string" ? payload : safeStringify(payload);
19
- const endpoint = getReportApi(((_a = this.opts) == null ? void 0 : _a.env) || "develop");
19
+ const endpoint = `${getReportApi(((_a = this.opts) == null ? void 0 : _a.env) || "develop")}?token=${token}`;
20
20
  let contentType = "application/json";
21
21
  if (((_b = this.opts) == null ? void 0 : _b.enableGzip) && payload.items.length >= ((_c = this.opts) == null ? void 0 : _c.gzipBatchMinSize)) {
22
22
  const compressedItems = await gzipCompress(safeStringify(payload.items));
@@ -13,10 +13,10 @@ var PixelImageTransport = class {
13
13
  isSupported() {
14
14
  return isBrowser() && typeof Image !== "undefined";
15
15
  }
16
- async send(payload) {
16
+ async send(token, payload) {
17
17
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
18
18
  const body = safeStringify(payload.items);
19
- const endpoint = getPixelBatchApi(((_a = this.opts) == null ? void 0 : _a.env) || "develop");
19
+ const endpoint = `${getPixelBatchApi(((_a = this.opts) == null ? void 0 : _a.env) || "develop")}?token=${token}`;
20
20
  const param = "items";
21
21
  const maxLen = ((_b = this.opts) == null ? void 0 : _b.maxPixelUrlLen) || 8192;
22
22
  let compressedBody;
@@ -13,10 +13,10 @@ var WechatTransport = class {
13
13
  isSupported() {
14
14
  return isWeChatMiniProgram();
15
15
  }
16
- async send(payload) {
16
+ async send(token, payload) {
17
17
  var _a, _b, _c, _d, _e;
18
18
  let body = typeof payload === "string" ? payload : safeStringify(payload);
19
- const endpoint = getReportApi(((_a = this.opts) == null ? void 0 : _a.env) || "develop");
19
+ const endpoint = `${getReportApi(((_a = this.opts) == null ? void 0 : _a.env) || "develop")}?token=${token}`;
20
20
  const timeout = 1e4;
21
21
  let contentType = "application/json";
22
22
  if (((_b = this.opts) == null ? void 0 : _b.enableGzip) && payload.items.length >= ((_c = this.opts) == null ? void 0 : _c.gzipBatchMinSize)) {
@@ -0,0 +1,380 @@
1
+ // src/utils/innerMD5.ts
2
+ var EMPTY_STATE = new Int32Array(4);
3
+ var _Md5 = class {
4
+ constructor() {
5
+ this._dataLength = 0;
6
+ this._bufferLength = 0;
7
+ this._state = new Int32Array(4);
8
+ this._buffer = new ArrayBuffer(68);
9
+ this._buffer8 = new Uint8Array(this._buffer, 0, 68);
10
+ this._buffer32 = new Uint32Array(this._buffer, 0, 17);
11
+ this.start();
12
+ }
13
+ static hashStr(str, raw = false) {
14
+ return this.onePassHasher.start().appendStr(str).end(raw);
15
+ }
16
+ static hashAsciiStr(str, raw = false) {
17
+ return this.onePassHasher.start().appendAsciiStr(str).end(raw);
18
+ }
19
+ static _hex(x) {
20
+ const hc = _Md5.hexChars;
21
+ const ho = _Md5.hexOut;
22
+ let n;
23
+ let offset;
24
+ let j;
25
+ let i;
26
+ for (i = 0; i < 4; i += 1) {
27
+ offset = i * 8;
28
+ n = x[i];
29
+ for (j = 0; j < 8; j += 2) {
30
+ ho[offset + 1 + j] = hc.charAt(n & 15);
31
+ n >>>= 4;
32
+ ho[offset + 0 + j] = hc.charAt(n & 15);
33
+ n >>>= 4;
34
+ }
35
+ }
36
+ return ho.join("");
37
+ }
38
+ static _md5cycle(x, k) {
39
+ let a = x[0];
40
+ let b = x[1];
41
+ let c = x[2];
42
+ let d = x[3];
43
+ a += (b & c | ~b & d) + k[0] - 680876936 | 0;
44
+ a = (a << 7 | a >>> 25) + b | 0;
45
+ d += (a & b | ~a & c) + k[1] - 389564586 | 0;
46
+ d = (d << 12 | d >>> 20) + a | 0;
47
+ c += (d & a | ~d & b) + k[2] + 606105819 | 0;
48
+ c = (c << 17 | c >>> 15) + d | 0;
49
+ b += (c & d | ~c & a) + k[3] - 1044525330 | 0;
50
+ b = (b << 22 | b >>> 10) + c | 0;
51
+ a += (b & c | ~b & d) + k[4] - 176418897 | 0;
52
+ a = (a << 7 | a >>> 25) + b | 0;
53
+ d += (a & b | ~a & c) + k[5] + 1200080426 | 0;
54
+ d = (d << 12 | d >>> 20) + a | 0;
55
+ c += (d & a | ~d & b) + k[6] - 1473231341 | 0;
56
+ c = (c << 17 | c >>> 15) + d | 0;
57
+ b += (c & d | ~c & a) + k[7] - 45705983 | 0;
58
+ b = (b << 22 | b >>> 10) + c | 0;
59
+ a += (b & c | ~b & d) + k[8] + 1770035416 | 0;
60
+ a = (a << 7 | a >>> 25) + b | 0;
61
+ d += (a & b | ~a & c) + k[9] - 1958414417 | 0;
62
+ d = (d << 12 | d >>> 20) + a | 0;
63
+ c += (d & a | ~d & b) + k[10] - 42063 | 0;
64
+ c = (c << 17 | c >>> 15) + d | 0;
65
+ b += (c & d | ~c & a) + k[11] - 1990404162 | 0;
66
+ b = (b << 22 | b >>> 10) + c | 0;
67
+ a += (b & c | ~b & d) + k[12] + 1804603682 | 0;
68
+ a = (a << 7 | a >>> 25) + b | 0;
69
+ d += (a & b | ~a & c) + k[13] - 40341101 | 0;
70
+ d = (d << 12 | d >>> 20) + a | 0;
71
+ c += (d & a | ~d & b) + k[14] - 1502002290 | 0;
72
+ c = (c << 17 | c >>> 15) + d | 0;
73
+ b += (c & d | ~c & a) + k[15] + 1236535329 | 0;
74
+ b = (b << 22 | b >>> 10) + c | 0;
75
+ a += (b & d | c & ~d) + k[1] - 165796510 | 0;
76
+ a = (a << 5 | a >>> 27) + b | 0;
77
+ d += (a & c | b & ~c) + k[6] - 1069501632 | 0;
78
+ d = (d << 9 | d >>> 23) + a | 0;
79
+ c += (d & b | a & ~b) + k[11] + 643717713 | 0;
80
+ c = (c << 14 | c >>> 18) + d | 0;
81
+ b += (c & a | d & ~a) + k[0] - 373897302 | 0;
82
+ b = (b << 20 | b >>> 12) + c | 0;
83
+ a += (b & d | c & ~d) + k[5] - 701558691 | 0;
84
+ a = (a << 5 | a >>> 27) + b | 0;
85
+ d += (a & c | b & ~c) + k[10] + 38016083 | 0;
86
+ d = (d << 9 | d >>> 23) + a | 0;
87
+ c += (d & b | a & ~b) + k[15] - 660478335 | 0;
88
+ c = (c << 14 | c >>> 18) + d | 0;
89
+ b += (c & a | d & ~a) + k[4] - 405537848 | 0;
90
+ b = (b << 20 | b >>> 12) + c | 0;
91
+ a += (b & d | c & ~d) + k[9] + 568446438 | 0;
92
+ a = (a << 5 | a >>> 27) + b | 0;
93
+ d += (a & c | b & ~c) + k[14] - 1019803690 | 0;
94
+ d = (d << 9 | d >>> 23) + a | 0;
95
+ c += (d & b | a & ~b) + k[3] - 187363961 | 0;
96
+ c = (c << 14 | c >>> 18) + d | 0;
97
+ b += (c & a | d & ~a) + k[8] + 1163531501 | 0;
98
+ b = (b << 20 | b >>> 12) + c | 0;
99
+ a += (b & d | c & ~d) + k[13] - 1444681467 | 0;
100
+ a = (a << 5 | a >>> 27) + b | 0;
101
+ d += (a & c | b & ~c) + k[2] - 51403784 | 0;
102
+ d = (d << 9 | d >>> 23) + a | 0;
103
+ c += (d & b | a & ~b) + k[7] + 1735328473 | 0;
104
+ c = (c << 14 | c >>> 18) + d | 0;
105
+ b += (c & a | d & ~a) + k[12] - 1926607734 | 0;
106
+ b = (b << 20 | b >>> 12) + c | 0;
107
+ a += (b ^ c ^ d) + k[5] - 378558 | 0;
108
+ a = (a << 4 | a >>> 28) + b | 0;
109
+ d += (a ^ b ^ c) + k[8] - 2022574463 | 0;
110
+ d = (d << 11 | d >>> 21) + a | 0;
111
+ c += (d ^ a ^ b) + k[11] + 1839030562 | 0;
112
+ c = (c << 16 | c >>> 16) + d | 0;
113
+ b += (c ^ d ^ a) + k[14] - 35309556 | 0;
114
+ b = (b << 23 | b >>> 9) + c | 0;
115
+ a += (b ^ c ^ d) + k[1] - 1530992060 | 0;
116
+ a = (a << 4 | a >>> 28) + b | 0;
117
+ d += (a ^ b ^ c) + k[4] + 1272893353 | 0;
118
+ d = (d << 11 | d >>> 21) + a | 0;
119
+ c += (d ^ a ^ b) + k[7] - 155497632 | 0;
120
+ c = (c << 16 | c >>> 16) + d | 0;
121
+ b += (c ^ d ^ a) + k[10] - 1094730640 | 0;
122
+ b = (b << 23 | b >>> 9) + c | 0;
123
+ a += (b ^ c ^ d) + k[13] + 681279174 | 0;
124
+ a = (a << 4 | a >>> 28) + b | 0;
125
+ d += (a ^ b ^ c) + k[0] - 358537222 | 0;
126
+ d = (d << 11 | d >>> 21) + a | 0;
127
+ c += (d ^ a ^ b) + k[3] - 722521979 | 0;
128
+ c = (c << 16 | c >>> 16) + d | 0;
129
+ b += (c ^ d ^ a) + k[6] + 76029189 | 0;
130
+ b = (b << 23 | b >>> 9) + c | 0;
131
+ a += (b ^ c ^ d) + k[9] - 640364487 | 0;
132
+ a = (a << 4 | a >>> 28) + b | 0;
133
+ d += (a ^ b ^ c) + k[12] - 421815835 | 0;
134
+ d = (d << 11 | d >>> 21) + a | 0;
135
+ c += (d ^ a ^ b) + k[15] + 530742520 | 0;
136
+ c = (c << 16 | c >>> 16) + d | 0;
137
+ b += (c ^ d ^ a) + k[2] - 995338651 | 0;
138
+ b = (b << 23 | b >>> 9) + c | 0;
139
+ a += (c ^ (b | ~d)) + k[0] - 198630844 | 0;
140
+ a = (a << 6 | a >>> 26) + b | 0;
141
+ d += (b ^ (a | ~c)) + k[7] + 1126891415 | 0;
142
+ d = (d << 10 | d >>> 22) + a | 0;
143
+ c += (a ^ (d | ~b)) + k[14] - 1416354905 | 0;
144
+ c = (c << 15 | c >>> 17) + d | 0;
145
+ b += (d ^ (c | ~a)) + k[5] - 57434055 | 0;
146
+ b = (b << 21 | b >>> 11) + c | 0;
147
+ a += (c ^ (b | ~d)) + k[12] + 1700485571 | 0;
148
+ a = (a << 6 | a >>> 26) + b | 0;
149
+ d += (b ^ (a | ~c)) + k[3] - 1894986606 | 0;
150
+ d = (d << 10 | d >>> 22) + a | 0;
151
+ c += (a ^ (d | ~b)) + k[10] - 1051523 | 0;
152
+ c = (c << 15 | c >>> 17) + d | 0;
153
+ b += (d ^ (c | ~a)) + k[1] - 2054922799 | 0;
154
+ b = (b << 21 | b >>> 11) + c | 0;
155
+ a += (c ^ (b | ~d)) + k[8] + 1873313359 | 0;
156
+ a = (a << 6 | a >>> 26) + b | 0;
157
+ d += (b ^ (a | ~c)) + k[15] - 30611744 | 0;
158
+ d = (d << 10 | d >>> 22) + a | 0;
159
+ c += (a ^ (d | ~b)) + k[6] - 1560198380 | 0;
160
+ c = (c << 15 | c >>> 17) + d | 0;
161
+ b += (d ^ (c | ~a)) + k[13] + 1309151649 | 0;
162
+ b = (b << 21 | b >>> 11) + c | 0;
163
+ a += (c ^ (b | ~d)) + k[4] - 145523070 | 0;
164
+ a = (a << 6 | a >>> 26) + b | 0;
165
+ d += (b ^ (a | ~c)) + k[11] - 1120210379 | 0;
166
+ d = (d << 10 | d >>> 22) + a | 0;
167
+ c += (a ^ (d | ~b)) + k[2] + 718787259 | 0;
168
+ c = (c << 15 | c >>> 17) + d | 0;
169
+ b += (d ^ (c | ~a)) + k[9] - 343485551 | 0;
170
+ b = (b << 21 | b >>> 11) + c | 0;
171
+ x[0] = a + x[0] | 0;
172
+ x[1] = b + x[1] | 0;
173
+ x[2] = c + x[2] | 0;
174
+ x[3] = d + x[3] | 0;
175
+ }
176
+ /**
177
+ * Initialise buffer to be hashed
178
+ */
179
+ start() {
180
+ this._dataLength = 0;
181
+ this._bufferLength = 0;
182
+ this._state.set(_Md5.stateIdentity);
183
+ return this;
184
+ }
185
+ // Char to code point to to array conversion:
186
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt
187
+ // #Example.3A_Fixing_charCodeAt_to_handle_non-Basic-Multilingual-Plane_characters_if_their_presence_earlier_in_the_string_is_unknown
188
+ /**
189
+ * Append a UTF-8 string to the hash buffer
190
+ * @param str String to append
191
+ */
192
+ appendStr(str) {
193
+ const buf8 = this._buffer8;
194
+ const buf32 = this._buffer32;
195
+ let bufLen = this._bufferLength;
196
+ let code;
197
+ let i;
198
+ for (i = 0; i < str.length; i += 1) {
199
+ code = str.charCodeAt(i);
200
+ if (code < 128) {
201
+ buf8[bufLen++] = code;
202
+ } else if (code < 2048) {
203
+ buf8[bufLen++] = (code >>> 6) + 192;
204
+ buf8[bufLen++] = code & 63 | 128;
205
+ } else if (code < 55296 || code > 56319) {
206
+ buf8[bufLen++] = (code >>> 12) + 224;
207
+ buf8[bufLen++] = code >>> 6 & 63 | 128;
208
+ buf8[bufLen++] = code & 63 | 128;
209
+ } else {
210
+ code = (code - 55296) * 1024 + (str.charCodeAt(++i) - 56320) + 65536;
211
+ if (code > 1114111) {
212
+ throw new Error(
213
+ "Unicode standard supports code points up to U+10FFFF"
214
+ );
215
+ }
216
+ buf8[bufLen++] = (code >>> 18) + 240;
217
+ buf8[bufLen++] = code >>> 12 & 63 | 128;
218
+ buf8[bufLen++] = code >>> 6 & 63 | 128;
219
+ buf8[bufLen++] = code & 63 | 128;
220
+ }
221
+ if (bufLen >= 64) {
222
+ this._dataLength += 64;
223
+ _Md5._md5cycle(this._state, buf32);
224
+ bufLen -= 64;
225
+ buf32[0] = buf32[16];
226
+ }
227
+ }
228
+ this._bufferLength = bufLen;
229
+ return this;
230
+ }
231
+ /**
232
+ * Append an ASCII string to the hash buffer
233
+ * @param str String to append
234
+ */
235
+ appendAsciiStr(str) {
236
+ const buf8 = this._buffer8;
237
+ const buf32 = this._buffer32;
238
+ let bufLen = this._bufferLength;
239
+ let i;
240
+ let j = 0;
241
+ for (; ; ) {
242
+ i = Math.min(str.length - j, 64 - bufLen);
243
+ while (i--) {
244
+ buf8[bufLen++] = str.charCodeAt(j++);
245
+ }
246
+ if (bufLen < 64) {
247
+ break;
248
+ }
249
+ this._dataLength += 64;
250
+ _Md5._md5cycle(this._state, buf32);
251
+ bufLen = 0;
252
+ }
253
+ this._bufferLength = bufLen;
254
+ return this;
255
+ }
256
+ /**
257
+ * Append a byte array to the hash buffer
258
+ * @param input array to append
259
+ */
260
+ appendByteArray(input) {
261
+ const buf8 = this._buffer8;
262
+ const buf32 = this._buffer32;
263
+ let bufLen = this._bufferLength;
264
+ let i;
265
+ let j = 0;
266
+ for (; ; ) {
267
+ i = Math.min(input.length - j, 64 - bufLen);
268
+ while (i--) {
269
+ buf8[bufLen++] = input[j++];
270
+ }
271
+ if (bufLen < 64) {
272
+ break;
273
+ }
274
+ this._dataLength += 64;
275
+ _Md5._md5cycle(this._state, buf32);
276
+ bufLen = 0;
277
+ }
278
+ this._bufferLength = bufLen;
279
+ return this;
280
+ }
281
+ /**
282
+ * Get the state of the hash buffer
283
+ */
284
+ getState() {
285
+ const s = this._state;
286
+ return {
287
+ buffer: String.fromCharCode.apply(null, Array.from(this._buffer8)),
288
+ buflen: this._bufferLength,
289
+ length: this._dataLength,
290
+ state: [s[0], s[1], s[2], s[3]]
291
+ };
292
+ }
293
+ /**
294
+ * Override the current state of the hash buffer
295
+ * @param state New hash buffer state
296
+ */
297
+ setState(state) {
298
+ const buf = state.buffer;
299
+ const x = state.state;
300
+ const s = this._state;
301
+ let i;
302
+ this._dataLength = state.length;
303
+ this._bufferLength = state.buflen;
304
+ s[0] = x[0];
305
+ s[1] = x[1];
306
+ s[2] = x[2];
307
+ s[3] = x[3];
308
+ for (i = 0; i < buf.length; i += 1) {
309
+ this._buffer8[i] = buf.charCodeAt(i);
310
+ }
311
+ }
312
+ /**
313
+ * Hash the current state of the hash buffer and return the result
314
+ * @param raw Whether to return the value as an `Int32Array`
315
+ */
316
+ end(raw = false) {
317
+ const bufLen = this._bufferLength;
318
+ const buf8 = this._buffer8;
319
+ const buf32 = this._buffer32;
320
+ const i = (bufLen >> 2) + 1;
321
+ this._dataLength += bufLen;
322
+ const dataBitsLen = this._dataLength * 8;
323
+ buf8[bufLen] = 128;
324
+ buf8[bufLen + 1] = buf8[bufLen + 2] = buf8[bufLen + 3] = 0;
325
+ buf32.set(_Md5.buffer32Identity.subarray(i), i);
326
+ if (bufLen > 55) {
327
+ _Md5._md5cycle(this._state, buf32);
328
+ buf32.set(_Md5.buffer32Identity);
329
+ }
330
+ if (dataBitsLen <= 4294967295) {
331
+ buf32[14] = dataBitsLen;
332
+ } else {
333
+ const matches = dataBitsLen.toString(16).match(/(.*?)(.{0,8})$/);
334
+ if (matches === null)
335
+ return raw ? EMPTY_STATE : "";
336
+ const lo = parseInt(matches[2], 16);
337
+ const hi = parseInt(matches[1], 16) || 0;
338
+ buf32[14] = lo;
339
+ buf32[15] = hi;
340
+ }
341
+ _Md5._md5cycle(this._state, buf32);
342
+ return raw ? this._state : _Md5._hex(this._state);
343
+ }
344
+ };
345
+ var Md5 = _Md5;
346
+ // Private Static Variables
347
+ Md5.stateIdentity = new Int32Array([
348
+ 1732584193,
349
+ -271733879,
350
+ -1732584194,
351
+ 271733878
352
+ ]);
353
+ Md5.buffer32Identity = new Int32Array([
354
+ 0,
355
+ 0,
356
+ 0,
357
+ 0,
358
+ 0,
359
+ 0,
360
+ 0,
361
+ 0,
362
+ 0,
363
+ 0,
364
+ 0,
365
+ 0,
366
+ 0,
367
+ 0,
368
+ 0,
369
+ 0
370
+ ]);
371
+ Md5.hexChars = "0123456789abcdef";
372
+ Md5.hexOut = [];
373
+ // Permanent instance is to use for one-call hashing
374
+ Md5.onePassHasher = new _Md5();
375
+ if (Md5.hashStr("hello") !== "5d41402abc4b2a76b9719d911017c592") {
376
+ throw new Error("Md5 self test failed.");
377
+ }
378
+ export {
379
+ Md5
380
+ };
@@ -1,4 +1,4 @@
1
- export declare type HttpClientResponse = {
1
+ export type HttpClientResponse = {
2
2
  type: 'xhr' | 'fetch' | 'wechat';
3
3
  response?: any;
4
4
  error?: any;
@@ -64,6 +64,7 @@ export declare class LoggerSDK {
64
64
  * 销毁实例
65
65
  */
66
66
  destroy(): Promise<void>;
67
+ private generateToken;
67
68
  /**
68
69
  * 发送单个事件(带重试)
69
70
  */
@@ -1,5 +1,5 @@
1
1
  import { LogEvent } from '../types/logEvent';
2
- declare type LocalForageLike = {
2
+ type LocalForageLike = {
3
3
  getItem: (key: string) => Promise<any>;
4
4
  setItem: (key: string, value: any) => Promise<any>;
5
5
  removeItem: (key: string) => Promise<any>;
@@ -7,5 +7,5 @@ export declare class BeaconTransport implements Transporter {
7
7
  private opts?;
8
8
  constructor(opts: TransportOptions);
9
9
  isSupported(): boolean;
10
- send(payload: ReportData): Promise<void>;
10
+ send(token: string, payload: ReportData): Promise<void>;
11
11
  }
@@ -7,5 +7,5 @@ export declare class PixelImageTransport implements Transporter {
7
7
  private opts?;
8
8
  constructor(opts: TransportOptions);
9
9
  isSupported(): boolean;
10
- send(payload: ReportData): Promise<void>;
10
+ send(token: string, payload: ReportData): Promise<void>;
11
11
  }
@@ -10,5 +10,5 @@ export interface Transporter {
10
10
  /** 是否支持当前环境 */
11
11
  isSupported(): boolean;
12
12
  /** 发送数据 */
13
- send(payload: ReportData): Promise<void>;
13
+ send(token: string, payload: ReportData): Promise<void>;
14
14
  }
@@ -7,5 +7,5 @@ export declare class WechatTransport implements Transporter {
7
7
  private opts?;
8
8
  constructor(opts: TransportOptions);
9
9
  isSupported(): boolean;
10
- send(payload: ReportData): Promise<void>;
10
+ send(token: string, payload: ReportData): Promise<void>;
11
11
  }
@@ -1,8 +1,8 @@
1
1
  /** 环境类型 */
2
- export declare type Env = 'develop' | 'testing' | 'product';
3
- export declare type Stage = 'develop' | 'testing' | 'sit' | 'yace' | 'product';
2
+ export type Env = 'develop' | 'testing' | 'product';
3
+ export type Stage = 'develop' | 'testing' | 'sit' | 'yace' | 'product';
4
4
  /** 平台类型 */
5
- export declare type PlatformType = 'browser' | 'wechat' | 'unknown';
5
+ export type PlatformType = 'browser' | 'wechat' | 'unknown';
6
6
  /** 环境信息 */
7
7
  export interface EnvironmentInfo {
8
8
  platform: PlatformType;
@@ -36,18 +36,18 @@ export interface StackFrame {
36
36
  column: number;
37
37
  function?: string;
38
38
  }
39
- export declare type BaseErrorInfo = {
39
+ export type BaseErrorInfo = {
40
40
  type: 'js' | 'promise' | 'resource';
41
41
  message: string;
42
42
  stack: StackFrame[];
43
43
  throwable?: string;
44
44
  };
45
- export declare type ReportData = {
45
+ export type ReportData = {
46
46
  appId: string;
47
47
  appStage: Stage;
48
48
  items: ReportItem[];
49
49
  };
50
- export declare type ReportItem = {
50
+ export type ReportItem = {
51
51
  level: LogEventLevel;
52
52
  traceId?: string;
53
53
  frontendId: string;
@@ -1,2 +1,2 @@
1
1
  /** 日志级别 */
2
- export declare type LogEventLevel = 'INFO' | 'WARN' | 'ERROR' | 'FATAL';
2
+ export type LogEventLevel = 'INFO' | 'WARN' | 'ERROR' | 'FATAL';
@@ -1,5 +1,5 @@
1
1
  import { LogEventLevel } from './logEventLevel';
2
- export declare type TrackOptions = {
2
+ export type TrackOptions = {
3
3
  message: string;
4
4
  error?: Error | unknown;
5
5
  traceId?: string;
@@ -0,0 +1,70 @@
1
+ interface HasherState {
2
+ buffer: string;
3
+ buflen: number;
4
+ length: number;
5
+ state: number[];
6
+ }
7
+ export declare class Md5 {
8
+ /**
9
+ * Hash a UTF-8 string on the spot
10
+ * @param str String to hash
11
+ * @param raw Whether to return the value as an `Int32Array`
12
+ */
13
+ static hashStr(str: string, raw?: false): string;
14
+ static hashStr(str: string, raw: true): Int32Array;
15
+ /**
16
+ * Hash a ASCII string on the spot
17
+ * @param str String to hash
18
+ * @param raw Whether to return the value as an `Int32Array`
19
+ */
20
+ static hashAsciiStr(str: string, raw?: false): string;
21
+ static hashAsciiStr(str: string, raw: true): Int32Array;
22
+ private static stateIdentity;
23
+ private static buffer32Identity;
24
+ private static hexChars;
25
+ private static hexOut;
26
+ private static onePassHasher;
27
+ private static _hex;
28
+ private static _md5cycle;
29
+ private _dataLength;
30
+ private _bufferLength;
31
+ private _state;
32
+ private _buffer;
33
+ private _buffer8;
34
+ private _buffer32;
35
+ constructor();
36
+ /**
37
+ * Initialise buffer to be hashed
38
+ */
39
+ start(): this;
40
+ /**
41
+ * Append a UTF-8 string to the hash buffer
42
+ * @param str String to append
43
+ */
44
+ appendStr(str: string): this;
45
+ /**
46
+ * Append an ASCII string to the hash buffer
47
+ * @param str String to append
48
+ */
49
+ appendAsciiStr(str: string): this;
50
+ /**
51
+ * Append a byte array to the hash buffer
52
+ * @param input array to append
53
+ */
54
+ appendByteArray(input: Uint8Array): this;
55
+ /**
56
+ * Get the state of the hash buffer
57
+ */
58
+ getState(): HasherState;
59
+ /**
60
+ * Override the current state of the hash buffer
61
+ * @param state New hash buffer state
62
+ */
63
+ setState(state: HasherState): void;
64
+ /**
65
+ * Hash the current state of the hash buffer and return the result
66
+ * @param raw Whether to return the value as an `Int32Array`
67
+ */
68
+ end(raw?: boolean): Int32Array | string;
69
+ }
70
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluve/logger-sdk",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "logger sdk",
5
5
  "keywords": [
6
6
  "logger"
@@ -44,10 +44,10 @@
44
44
  "url": "https://gitlab.pharmacyyf.com/frontend-common/pluve-lib.git"
45
45
  },
46
46
  "scripts": {
47
- "init-install": "yarn install",
47
+ "init-install": "pnpm install",
48
48
  "build-types": "tsc -p tsconfig.types.json",
49
49
  "typecheck": "tsc -p tsconfig.json",
50
- "build": "yarn build-types && father build",
50
+ "build": "pnpm run build-types && father build",
51
51
  "test": "vitest run",
52
52
  "test:watch": "vitest",
53
53
  "test:coverage": "vitest run --coverage",