@pluve/logger-sdk 0.0.10 → 0.0.12
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/cjs/compress/compression.js +32 -11
- package/dist/cjs/core/loggerSDK.js +9 -7
- package/dist/cjs/core/queueManager.js +20 -6
- package/dist/cjs/index.js +7 -2
- package/dist/cjs/transport/pixelImageTransport.js +1 -2
- package/dist/cjs/transport/transportAdapter.js +30 -13
- package/dist/esm/compress/compression.js +30 -11
- package/dist/esm/core/loggerSDK.js +7 -5
- package/dist/esm/core/queueManager.js +20 -6
- package/dist/esm/index.js +4 -1
- package/dist/esm/transport/pixelImageTransport.js +2 -3
- package/dist/esm/transport/transportAdapter.js +74 -15
- package/dist/types/compress/compression.d.ts +2 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/transport/transportAdapter.d.ts +3 -5
- package/dist/umd/logger-sdk.min.js +1 -1
- package/package.json +1 -2
|
@@ -19,12 +19,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/compress/compression.ts
|
|
20
20
|
var compression_exports = {};
|
|
21
21
|
__export(compression_exports, {
|
|
22
|
+
convert2Base64: () => convert2Base64,
|
|
23
|
+
convert2Base64FromArray: () => convert2Base64FromArray,
|
|
22
24
|
gzipCompress: () => gzipCompress,
|
|
23
25
|
isGzipSupported: () => isGzipSupported
|
|
24
26
|
});
|
|
25
27
|
module.exports = __toCommonJS(compression_exports);
|
|
26
28
|
var import_fflate = require("fflate");
|
|
27
|
-
var import_js_base64 = require("js-base64");
|
|
28
29
|
var import_environment = require("../utils/environment");
|
|
29
30
|
function toUtf8Bytes(s) {
|
|
30
31
|
if (typeof TextEncoder !== "undefined") {
|
|
@@ -53,14 +54,7 @@ async function gzipCompress(data) {
|
|
|
53
54
|
const compressedStream = readable.pipeThrough(gzip);
|
|
54
55
|
const compressedBuffer = await new Response(compressedStream).arrayBuffer();
|
|
55
56
|
const bytes = new Uint8Array(compressedBuffer);
|
|
56
|
-
|
|
57
|
-
for (let i = 0; i < bytes.byteLength; i += 1) {
|
|
58
|
-
binary += String.fromCharCode(bytes[i]);
|
|
59
|
-
}
|
|
60
|
-
if (typeof btoa !== "undefined") {
|
|
61
|
-
return btoa(binary);
|
|
62
|
-
}
|
|
63
|
-
return Buffer.from(binary, "base64").toString("base64");
|
|
57
|
+
return convert2Base64FromArray(bytes);
|
|
64
58
|
} catch (e) {
|
|
65
59
|
console.log("gzipCompress 压缩失败,尝试使用 fflate 库", e);
|
|
66
60
|
}
|
|
@@ -68,17 +62,44 @@ async function gzipCompress(data) {
|
|
|
68
62
|
try {
|
|
69
63
|
const input = toUtf8Bytes(data);
|
|
70
64
|
const compressed = (0, import_fflate.gzipSync)(input);
|
|
71
|
-
return
|
|
65
|
+
return convert2Base64FromArray(compressed);
|
|
72
66
|
} catch (e) {
|
|
73
67
|
console.log("gzipCompress 压缩失败", e);
|
|
74
68
|
}
|
|
75
|
-
return
|
|
69
|
+
return data;
|
|
70
|
+
}
|
|
71
|
+
function convert2Base64FromArray(data) {
|
|
72
|
+
let binary = "";
|
|
73
|
+
for (let i = 0; i < data.length; i += 1) {
|
|
74
|
+
binary += String.fromCharCode(data[i]);
|
|
75
|
+
}
|
|
76
|
+
if (typeof btoa !== "undefined") {
|
|
77
|
+
return btoa(binary);
|
|
78
|
+
}
|
|
79
|
+
if (typeof Buffer !== "undefined") {
|
|
80
|
+
return Buffer.from(binary, "base64").toString("base64");
|
|
81
|
+
}
|
|
82
|
+
throw new Error("convert2Base64FromArray 不支持转换");
|
|
83
|
+
}
|
|
84
|
+
function convert2Base64(data) {
|
|
85
|
+
if (typeof btoa !== "undefined") {
|
|
86
|
+
try {
|
|
87
|
+
return btoa(data);
|
|
88
|
+
} catch {
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (typeof Buffer !== "undefined") {
|
|
92
|
+
return Buffer.from(data, "base64").toString("base64");
|
|
93
|
+
}
|
|
94
|
+
return data;
|
|
76
95
|
}
|
|
77
96
|
function isGzipSupported() {
|
|
78
97
|
return (0, import_environment.isBrowser)() && typeof CompressionStream !== "undefined";
|
|
79
98
|
}
|
|
80
99
|
// Annotate the CommonJS export names for ESM import in node:
|
|
81
100
|
0 && (module.exports = {
|
|
101
|
+
convert2Base64,
|
|
102
|
+
convert2Base64FromArray,
|
|
82
103
|
gzipCompress,
|
|
83
104
|
isGzipSupported
|
|
84
105
|
});
|
|
@@ -140,7 +140,7 @@ var LoggerSDK = class {
|
|
|
140
140
|
debug: this.opts.debug
|
|
141
141
|
});
|
|
142
142
|
}
|
|
143
|
-
this.transporter =
|
|
143
|
+
this.transporter = void 0;
|
|
144
144
|
this.sessionId = (0, import_session.getSessionId)();
|
|
145
145
|
this.envTags = (0, import_environment.collectEnvironmentTags)();
|
|
146
146
|
this.initSDK(this.opts, (data) => {
|
|
@@ -455,8 +455,9 @@ var LoggerSDK = class {
|
|
|
455
455
|
*/
|
|
456
456
|
async sendEvent(event) {
|
|
457
457
|
const sendFn = async () => {
|
|
458
|
-
|
|
459
|
-
|
|
458
|
+
const transporter = this.transporter || await import_transportAdapter.TransportAdapter.getInstance(this.opts).getTransporter();
|
|
459
|
+
this.transporter = transporter;
|
|
460
|
+
await transporter.send({
|
|
460
461
|
appId: event.appId,
|
|
461
462
|
appStage: event.stage,
|
|
462
463
|
items: [
|
|
@@ -469,7 +470,7 @@ var LoggerSDK = class {
|
|
|
469
470
|
throwable: event.throwable
|
|
470
471
|
}
|
|
471
472
|
]
|
|
472
|
-
})
|
|
473
|
+
});
|
|
473
474
|
};
|
|
474
475
|
if (this.opts.enableRetry && this.retryManager) {
|
|
475
476
|
await this.retryManager.executeWithRetry(event.logId, sendFn);
|
|
@@ -505,8 +506,9 @@ var LoggerSDK = class {
|
|
|
505
506
|
if (chunk.length > 0) {
|
|
506
507
|
const batchId = `batch_${(0, import_tools.now)()}_${Math.random().toString(36).substring(2, 9)}_${key}_${i}`;
|
|
507
508
|
const sendFn = async () => {
|
|
508
|
-
|
|
509
|
-
|
|
509
|
+
const transporter = this.transporter || await import_transportAdapter.TransportAdapter.getInstance(this.opts).getTransporter();
|
|
510
|
+
this.transporter = transporter;
|
|
511
|
+
await transporter.send({
|
|
510
512
|
appId: chunk[0].appId,
|
|
511
513
|
appStage: chunk[0].stage,
|
|
512
514
|
items: chunk.map((event) => ({
|
|
@@ -517,7 +519,7 @@ var LoggerSDK = class {
|
|
|
517
519
|
message: event.message,
|
|
518
520
|
throwable: event.throwable
|
|
519
521
|
}))
|
|
520
|
-
})
|
|
522
|
+
});
|
|
521
523
|
};
|
|
522
524
|
const task = this.opts.enableRetry && this.retryManager ? this.retryManager.executeWithRetry(batchId, sendFn) : sendFn();
|
|
523
525
|
tasks.push(task);
|
|
@@ -47,17 +47,31 @@ var QueueManager = class {
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
async loadLocalForage() {
|
|
50
|
+
if (!(0, import_environment.isBrowser)())
|
|
51
|
+
return null;
|
|
50
52
|
try {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
const g = globalThis;
|
|
54
|
+
if (g && g.localforage && typeof g.localforage.getItem === "function") {
|
|
55
|
+
this.localforage = g.localforage;
|
|
56
|
+
return this.localforage;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const mod = await import(
|
|
60
|
+
/* @vite-ignore */
|
|
61
|
+
"localforage"
|
|
62
|
+
);
|
|
63
|
+
this.localforage = mod;
|
|
64
|
+
return this.localforage;
|
|
65
|
+
} catch (e) {
|
|
66
|
+
(0, import_tools.logDebug)(!!this.opts.debug, "localforage dynamic import failed, fallback to localStorage", e);
|
|
67
|
+
this.localforage = null;
|
|
68
|
+
return null;
|
|
56
69
|
}
|
|
57
70
|
} catch (e) {
|
|
58
71
|
(0, import_tools.logDebug)(!!this.opts.debug, "localforage load error", e);
|
|
72
|
+
this.localforage = null;
|
|
73
|
+
return null;
|
|
59
74
|
}
|
|
60
|
-
return null;
|
|
61
75
|
}
|
|
62
76
|
/**
|
|
63
77
|
* 添加日志到队列
|
package/dist/cjs/index.js
CHANGED
|
@@ -19,11 +19,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/index.ts
|
|
20
20
|
var src_exports = {};
|
|
21
21
|
__export(src_exports, {
|
|
22
|
-
LoggerSDK: () => import_loggerSDK.LoggerSDK
|
|
22
|
+
LoggerSDK: () => import_loggerSDK.LoggerSDK,
|
|
23
|
+
gzipCompress: () => import_compression.gzipCompress,
|
|
24
|
+
isGzipSupported: () => import_compression.isGzipSupported
|
|
23
25
|
});
|
|
24
26
|
module.exports = __toCommonJS(src_exports);
|
|
25
27
|
var import_loggerSDK = require("./core/loggerSDK");
|
|
28
|
+
var import_compression = require("./compress/compression");
|
|
26
29
|
// Annotate the CommonJS export names for ESM import in node:
|
|
27
30
|
0 && (module.exports = {
|
|
28
|
-
LoggerSDK
|
|
31
|
+
LoggerSDK,
|
|
32
|
+
gzipCompress,
|
|
33
|
+
isGzipSupported
|
|
29
34
|
});
|
|
@@ -22,7 +22,6 @@ __export(pixelImageTransport_exports, {
|
|
|
22
22
|
PixelImageTransport: () => PixelImageTransport
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(pixelImageTransport_exports);
|
|
25
|
-
var import_js_base64 = require("js-base64");
|
|
26
25
|
var import_environment = require("../utils/environment");
|
|
27
26
|
var import_tools = require("../utils/tools");
|
|
28
27
|
var import_config = require("../config");
|
|
@@ -52,7 +51,7 @@ var PixelImageTransport = class {
|
|
|
52
51
|
(0, import_tools.logDebug)(!!((_g = this.opts) == null ? void 0 : _g.debug), `original body size: ${body.length}, compressed body size: ${compressedBody.length}`);
|
|
53
52
|
(0, import_tools.logDebug)(!!((_h = this.opts) == null ? void 0 : _h.debug), "PixelImage request gzip compress body: ", compressedBody);
|
|
54
53
|
} else {
|
|
55
|
-
compressedBody =
|
|
54
|
+
compressedBody = (0, import_compression.convert2Base64)(body);
|
|
56
55
|
}
|
|
57
56
|
const cacheBuster = `_=${Date.now()}`;
|
|
58
57
|
const qs = `appId=${((_i = this.opts) == null ? void 0 : _i.appId) || ""}&appStage=${((_j = this.opts) == null ? void 0 : _j.logStage) || ""}&${param}=${encodeURIComponent(compressedBody)}&gzip=${((_k = this.opts) == null ? void 0 : _k.enableGzip) ? 1 : 0}&${cacheBuster}`;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
17
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
28
|
|
|
19
29
|
// src/transport/transportAdapter.ts
|
|
@@ -23,14 +33,9 @@ __export(transportAdapter_exports, {
|
|
|
23
33
|
});
|
|
24
34
|
module.exports = __toCommonJS(transportAdapter_exports);
|
|
25
35
|
var import_environment = require("../utils/environment");
|
|
26
|
-
var import_beaconTransport = require("./beaconTransport");
|
|
27
|
-
var import_pixelImageTransport = require("./pixelImageTransport");
|
|
28
|
-
var import_wechatTransport = require("./wechatTransport");
|
|
29
36
|
var TransportAdapter = class {
|
|
30
37
|
constructor(opts) {
|
|
31
|
-
this.
|
|
32
|
-
this.pixelImageTransport = new import_pixelImageTransport.PixelImageTransport(opts);
|
|
33
|
-
this.wechatTransport = new import_wechatTransport.WechatTransport(opts);
|
|
38
|
+
this.opts = opts;
|
|
34
39
|
}
|
|
35
40
|
static getInstance(opts) {
|
|
36
41
|
if (!TransportAdapter.instance) {
|
|
@@ -38,16 +43,28 @@ var TransportAdapter = class {
|
|
|
38
43
|
}
|
|
39
44
|
return TransportAdapter.instance;
|
|
40
45
|
}
|
|
41
|
-
getTransporter() {
|
|
46
|
+
async getTransporter() {
|
|
42
47
|
if ((0, import_environment.isWeChatMiniProgram)()) {
|
|
43
|
-
|
|
48
|
+
const mod = await import(
|
|
49
|
+
/* @vite-ignore */
|
|
50
|
+
"./wechatTransport"
|
|
51
|
+
);
|
|
52
|
+
return new mod.WechatTransport(this.opts);
|
|
44
53
|
}
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
const beaconMod = await import(
|
|
55
|
+
/* @vite-ignore */
|
|
56
|
+
"./beaconTransport"
|
|
57
|
+
);
|
|
58
|
+
const pixelMod = await import(
|
|
59
|
+
/* @vite-ignore */
|
|
60
|
+
"./pixelImageTransport"
|
|
61
|
+
);
|
|
62
|
+
const beacon = new beaconMod.BeaconTransport(this.opts);
|
|
63
|
+
const pixel = new pixelMod.PixelImageTransport(this.opts);
|
|
64
|
+
if (beacon.isSupported()) {
|
|
65
|
+
return beacon;
|
|
49
66
|
}
|
|
50
|
-
return
|
|
67
|
+
return pixel;
|
|
51
68
|
}
|
|
52
69
|
};
|
|
53
70
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -21,7 +21,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
21
21
|
|
|
22
22
|
// src/compress/compression.ts
|
|
23
23
|
import { gzipSync } from "fflate";
|
|
24
|
-
import { Base64 } from "js-base64";
|
|
25
24
|
import { isBrowser } from "../utils/environment";
|
|
26
25
|
function toUtf8Bytes(s) {
|
|
27
26
|
if (typeof TextEncoder !== "undefined") {
|
|
@@ -51,14 +50,7 @@ function gzipCompress(data) {
|
|
|
51
50
|
const compressedStream = readable.pipeThrough(gzip);
|
|
52
51
|
const compressedBuffer = yield new Response(compressedStream).arrayBuffer();
|
|
53
52
|
const bytes = new Uint8Array(compressedBuffer);
|
|
54
|
-
|
|
55
|
-
for (let i = 0; i < bytes.byteLength; i += 1) {
|
|
56
|
-
binary += String.fromCharCode(bytes[i]);
|
|
57
|
-
}
|
|
58
|
-
if (typeof btoa !== "undefined") {
|
|
59
|
-
return btoa(binary);
|
|
60
|
-
}
|
|
61
|
-
return Buffer.from(binary, "base64").toString("base64");
|
|
53
|
+
return convert2Base64FromArray(bytes);
|
|
62
54
|
} catch (e) {
|
|
63
55
|
console.log("gzipCompress 压缩失败,尝试使用 fflate 库", e);
|
|
64
56
|
}
|
|
@@ -66,17 +58,44 @@ function gzipCompress(data) {
|
|
|
66
58
|
try {
|
|
67
59
|
const input = toUtf8Bytes(data);
|
|
68
60
|
const compressed = gzipSync(input);
|
|
69
|
-
return
|
|
61
|
+
return convert2Base64FromArray(compressed);
|
|
70
62
|
} catch (e) {
|
|
71
63
|
console.log("gzipCompress 压缩失败", e);
|
|
72
64
|
}
|
|
73
|
-
return
|
|
65
|
+
return data;
|
|
74
66
|
});
|
|
75
67
|
}
|
|
68
|
+
function convert2Base64FromArray(data) {
|
|
69
|
+
let binary = "";
|
|
70
|
+
for (let i = 0; i < data.length; i += 1) {
|
|
71
|
+
binary += String.fromCharCode(data[i]);
|
|
72
|
+
}
|
|
73
|
+
if (typeof btoa !== "undefined") {
|
|
74
|
+
return btoa(binary);
|
|
75
|
+
}
|
|
76
|
+
if (typeof Buffer !== "undefined") {
|
|
77
|
+
return Buffer.from(binary, "base64").toString("base64");
|
|
78
|
+
}
|
|
79
|
+
throw new Error("convert2Base64FromArray 不支持转换");
|
|
80
|
+
}
|
|
81
|
+
function convert2Base64(data) {
|
|
82
|
+
if (typeof btoa !== "undefined") {
|
|
83
|
+
try {
|
|
84
|
+
return btoa(data);
|
|
85
|
+
} catch (e) {
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (typeof Buffer !== "undefined") {
|
|
89
|
+
return Buffer.from(data, "base64").toString("base64");
|
|
90
|
+
}
|
|
91
|
+
return data;
|
|
92
|
+
}
|
|
76
93
|
function isGzipSupported() {
|
|
77
94
|
return isBrowser() && typeof CompressionStream !== "undefined";
|
|
78
95
|
}
|
|
79
96
|
export {
|
|
97
|
+
convert2Base64,
|
|
98
|
+
convert2Base64FromArray,
|
|
80
99
|
gzipCompress,
|
|
81
100
|
isGzipSupported
|
|
82
101
|
};
|
|
@@ -137,7 +137,7 @@ var LoggerSDK = class {
|
|
|
137
137
|
debug: this.opts.debug
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
|
-
this.transporter =
|
|
140
|
+
this.transporter = void 0;
|
|
141
141
|
this.sessionId = getSessionId();
|
|
142
142
|
this.envTags = collectEnvironmentTags();
|
|
143
143
|
this.initSDK(this.opts, (data) => {
|
|
@@ -461,8 +461,9 @@ var LoggerSDK = class {
|
|
|
461
461
|
sendEvent(event) {
|
|
462
462
|
return __async(this, null, function* () {
|
|
463
463
|
const sendFn = () => __async(this, null, function* () {
|
|
464
|
-
|
|
465
|
-
|
|
464
|
+
const transporter = this.transporter || (yield TransportAdapter.getInstance(this.opts).getTransporter());
|
|
465
|
+
this.transporter = transporter;
|
|
466
|
+
yield transporter.send({
|
|
466
467
|
appId: event.appId,
|
|
467
468
|
appStage: event.stage,
|
|
468
469
|
items: [
|
|
@@ -513,8 +514,9 @@ var LoggerSDK = class {
|
|
|
513
514
|
if (chunk.length > 0) {
|
|
514
515
|
const batchId = `batch_${now()}_${Math.random().toString(36).substring(2, 9)}_${key}_${i}`;
|
|
515
516
|
const sendFn = () => __async(this, null, function* () {
|
|
516
|
-
|
|
517
|
-
|
|
517
|
+
const transporter = this.transporter || (yield TransportAdapter.getInstance(this.opts).getTransporter());
|
|
518
|
+
this.transporter = transporter;
|
|
519
|
+
yield transporter.send({
|
|
518
520
|
appId: chunk[0].appId,
|
|
519
521
|
appStage: chunk[0].stage,
|
|
520
522
|
items: chunk.map((event) => ({
|
|
@@ -65,17 +65,31 @@ var QueueManager = class {
|
|
|
65
65
|
}
|
|
66
66
|
loadLocalForage() {
|
|
67
67
|
return __async(this, null, function* () {
|
|
68
|
+
if (!isBrowser())
|
|
69
|
+
return null;
|
|
68
70
|
try {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
const g = globalThis;
|
|
72
|
+
if (g && g.localforage && typeof g.localforage.getItem === "function") {
|
|
73
|
+
this.localforage = g.localforage;
|
|
74
|
+
return this.localforage;
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const mod = yield Promise.resolve().then(() => __toESM(__require(
|
|
78
|
+
/* @vite-ignore */
|
|
79
|
+
"localforage"
|
|
80
|
+
)));
|
|
81
|
+
this.localforage = mod;
|
|
82
|
+
return this.localforage;
|
|
83
|
+
} catch (e) {
|
|
84
|
+
logDebug(!!this.opts.debug, "localforage dynamic import failed, fallback to localStorage", e);
|
|
85
|
+
this.localforage = null;
|
|
86
|
+
return null;
|
|
74
87
|
}
|
|
75
88
|
} catch (e) {
|
|
76
89
|
logDebug(!!this.opts.debug, "localforage load error", e);
|
|
90
|
+
this.localforage = null;
|
|
91
|
+
return null;
|
|
77
92
|
}
|
|
78
|
-
return null;
|
|
79
93
|
});
|
|
80
94
|
}
|
|
81
95
|
/**
|
package/dist/esm/index.js
CHANGED
|
@@ -20,11 +20,10 @@ var __async = (__this, __arguments, generator) => {
|
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
// src/transport/pixelImageTransport.ts
|
|
23
|
-
import { Base64 } from "js-base64";
|
|
24
23
|
import { isBrowser } from "../utils/environment";
|
|
25
24
|
import { logDebug, now, safeStringify } from "../utils/tools";
|
|
26
25
|
import { getPixelBatchApi } from "../config";
|
|
27
|
-
import { gzipCompress } from "../compress/compression";
|
|
26
|
+
import { convert2Base64, gzipCompress } from "../compress/compression";
|
|
28
27
|
var PixelImageTransport = class {
|
|
29
28
|
constructor(opts) {
|
|
30
29
|
/** 传输器名称 */
|
|
@@ -51,7 +50,7 @@ var PixelImageTransport = class {
|
|
|
51
50
|
logDebug(!!((_g = this.opts) == null ? void 0 : _g.debug), `original body size: ${body.length}, compressed body size: ${compressedBody.length}`);
|
|
52
51
|
logDebug(!!((_h = this.opts) == null ? void 0 : _h.debug), "PixelImage request gzip compress body: ", compressedBody);
|
|
53
52
|
} else {
|
|
54
|
-
compressedBody =
|
|
53
|
+
compressedBody = convert2Base64(body);
|
|
55
54
|
}
|
|
56
55
|
const cacheBuster = `_=${Date.now()}`;
|
|
57
56
|
const qs = `appId=${((_i = this.opts) == null ? void 0 : _i.appId) || ""}&appStage=${((_j = this.opts) == null ? void 0 : _j.logStage) || ""}&${param}=${encodeURIComponent(compressedBody)}&gzip=${((_k = this.opts) == null ? void 0 : _k.enableGzip) ? 1 : 0}&${cacheBuster}`;
|
|
@@ -1,13 +1,58 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
+
}) : x)(function(x) {
|
|
10
|
+
if (typeof require !== "undefined")
|
|
11
|
+
return require.apply(this, arguments);
|
|
12
|
+
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
+
});
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
var __async = (__this, __arguments, generator) => {
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
var fulfilled = (value) => {
|
|
33
|
+
try {
|
|
34
|
+
step(generator.next(value));
|
|
35
|
+
} catch (e) {
|
|
36
|
+
reject(e);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var rejected = (value) => {
|
|
40
|
+
try {
|
|
41
|
+
step(generator.throw(value));
|
|
42
|
+
} catch (e) {
|
|
43
|
+
reject(e);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
47
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
1
51
|
// src/transport/transportAdapter.ts
|
|
2
52
|
import { isWeChatMiniProgram } from "../utils/environment";
|
|
3
|
-
import { BeaconTransport } from "./beaconTransport";
|
|
4
|
-
import { PixelImageTransport } from "./pixelImageTransport";
|
|
5
|
-
import { WechatTransport } from "./wechatTransport";
|
|
6
53
|
var TransportAdapter = class {
|
|
7
54
|
constructor(opts) {
|
|
8
|
-
this.
|
|
9
|
-
this.pixelImageTransport = new PixelImageTransport(opts);
|
|
10
|
-
this.wechatTransport = new WechatTransport(opts);
|
|
55
|
+
this.opts = opts;
|
|
11
56
|
}
|
|
12
57
|
static getInstance(opts) {
|
|
13
58
|
if (!TransportAdapter.instance) {
|
|
@@ -16,15 +61,29 @@ var TransportAdapter = class {
|
|
|
16
61
|
return TransportAdapter.instance;
|
|
17
62
|
}
|
|
18
63
|
getTransporter() {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
64
|
+
return __async(this, null, function* () {
|
|
65
|
+
if (isWeChatMiniProgram()) {
|
|
66
|
+
const mod = yield Promise.resolve().then(() => __toESM(__require(
|
|
67
|
+
/* @vite-ignore */
|
|
68
|
+
"./wechatTransport"
|
|
69
|
+
)));
|
|
70
|
+
return new mod.WechatTransport(this.opts);
|
|
71
|
+
}
|
|
72
|
+
const beaconMod = yield Promise.resolve().then(() => __toESM(__require(
|
|
73
|
+
/* @vite-ignore */
|
|
74
|
+
"./beaconTransport"
|
|
75
|
+
)));
|
|
76
|
+
const pixelMod = yield Promise.resolve().then(() => __toESM(__require(
|
|
77
|
+
/* @vite-ignore */
|
|
78
|
+
"./pixelImageTransport"
|
|
79
|
+
)));
|
|
80
|
+
const beacon = new beaconMod.BeaconTransport(this.opts);
|
|
81
|
+
const pixel = new pixelMod.PixelImageTransport(this.opts);
|
|
82
|
+
if (beacon.isSupported()) {
|
|
83
|
+
return beacon;
|
|
84
|
+
}
|
|
85
|
+
return pixel;
|
|
86
|
+
});
|
|
28
87
|
}
|
|
29
88
|
};
|
|
30
89
|
export {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { Transporter, TransportOptions } from './transport';
|
|
1
|
+
import type { Transporter, TransportOptions } from './transport';
|
|
2
2
|
export declare class TransportAdapter {
|
|
3
3
|
private static instance;
|
|
4
|
-
private
|
|
5
|
-
private pixelImageTransport;
|
|
6
|
-
private wechatTransport;
|
|
4
|
+
private opts;
|
|
7
5
|
private constructor();
|
|
8
6
|
static getInstance(opts: TransportOptions): TransportAdapter;
|
|
9
|
-
getTransporter(): Transporter
|
|
7
|
+
getTransporter(): Promise<Transporter>;
|
|
10
8
|
}
|