@leanbase-giangnd/js 0.0.1 → 0.0.2
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/LICENSE +37 -0
- package/dist/index.cjs +26 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +26 -5
- package/dist/index.mjs.map +1 -1
- package/dist/leanbase.iife.js +31 -7
- package/dist/leanbase.iife.js.map +1 -1
- package/package.json +46 -47
- package/src/extensions/replay/external/lazy-loaded-session-recorder.ts +2 -4
- package/src/leanbase.ts +26 -0
- package/src/version.ts +1 -1
package/dist/leanbase.iife.js
CHANGED
|
@@ -966,7 +966,7 @@ var leanbase = (function () {
|
|
|
966
966
|
};
|
|
967
967
|
if (this.historicalMigration) data.historical_migration = true;
|
|
968
968
|
const payload = JSON.stringify(data);
|
|
969
|
-
const url = `${this.host}/batch/`;
|
|
969
|
+
const url = this.isSnapshotOnlyBatch(data.batch) ? `${this.host}/s/` : `${this.host}/batch/`;
|
|
970
970
|
const gzippedPayload = this.disableCompression ? null : await gzipCompress(payload, this.isDebug);
|
|
971
971
|
const fetchOptions = {
|
|
972
972
|
method: 'POST',
|
|
@@ -1035,6 +1035,9 @@ var leanbase = (function () {
|
|
|
1035
1035
|
if (customUserAgent && '' !== customUserAgent) headers['User-Agent'] = customUserAgent;
|
|
1036
1036
|
return headers;
|
|
1037
1037
|
}
|
|
1038
|
+
isSnapshotOnlyBatch(batch) {
|
|
1039
|
+
return batch.length > 0 && batch.every((m)=>m && '$snapshot' === m.event);
|
|
1040
|
+
}
|
|
1038
1041
|
async _flush() {
|
|
1039
1042
|
this.clearFlushTimer();
|
|
1040
1043
|
await this._initPromise;
|
|
@@ -1058,7 +1061,7 @@ var leanbase = (function () {
|
|
|
1058
1061
|
};
|
|
1059
1062
|
if (this.historicalMigration) data.historical_migration = true;
|
|
1060
1063
|
const payload = JSON.stringify(data);
|
|
1061
|
-
const url = `${this.host}/batch/`;
|
|
1064
|
+
const url = this.isSnapshotOnlyBatch(batchMessages) ? `${this.host}/s/` : `${this.host}/batch/`;
|
|
1062
1065
|
const gzippedPayload = this.disableCompression ? null : await gzipCompress(payload, this.isDebug);
|
|
1063
1066
|
const fetchOptions = {
|
|
1064
1067
|
method: 'POST',
|
|
@@ -2860,7 +2863,7 @@ var leanbase = (function () {
|
|
|
2860
2863
|
}
|
|
2861
2864
|
};
|
|
2862
2865
|
|
|
2863
|
-
var version = "0.0.
|
|
2866
|
+
var version = "0.0.2";
|
|
2864
2867
|
var packageInfo = {
|
|
2865
2868
|
version: version};
|
|
2866
2869
|
|
|
@@ -12508,14 +12511,12 @@ var leanbase = (function () {
|
|
|
12508
12511
|
}
|
|
12509
12512
|
_snapshotUrl() {
|
|
12510
12513
|
const host = this._instance.config.host || '';
|
|
12511
|
-
// Ensure endpoint is set; default to /s/ if not provided or malformed
|
|
12512
|
-
const endpoint = this._endpoint || '/s/';
|
|
12513
12514
|
try {
|
|
12514
12515
|
// eslint-disable-next-line compat/compat
|
|
12515
|
-
return new URL(
|
|
12516
|
+
return new URL(this._endpoint, host).href;
|
|
12516
12517
|
} catch {
|
|
12517
12518
|
const normalizedHost = host.endsWith('/') ? host.slice(0, -1) : host;
|
|
12518
|
-
const normalizedEndpoint =
|
|
12519
|
+
const normalizedEndpoint = this._endpoint.startsWith('/') ? this._endpoint.slice(1) : this._endpoint;
|
|
12519
12520
|
return `${normalizedHost}/${normalizedEndpoint}`;
|
|
12520
12521
|
}
|
|
12521
12522
|
}
|
|
@@ -13159,6 +13160,29 @@ var leanbase = (function () {
|
|
|
13159
13160
|
if (!fetchFn) {
|
|
13160
13161
|
return Promise.reject(new Error('Fetch API is not available in this environment.'));
|
|
13161
13162
|
}
|
|
13163
|
+
try {
|
|
13164
|
+
const isPost = !options.method || options.method.toUpperCase() === 'POST';
|
|
13165
|
+
const isBatchEndpoint = typeof url === 'string' && url.endsWith('/batch/');
|
|
13166
|
+
if (isPost && isBatchEndpoint && options && options.body) {
|
|
13167
|
+
let parsed = null;
|
|
13168
|
+
try {
|
|
13169
|
+
const bodyString = typeof options.body === 'string' ? options.body : String(options.body);
|
|
13170
|
+
parsed = JSON.parse(bodyString);
|
|
13171
|
+
} catch {
|
|
13172
|
+
parsed = null;
|
|
13173
|
+
}
|
|
13174
|
+
if (parsed && isArray(parsed.batch)) {
|
|
13175
|
+
const hasSnapshot = parsed.batch.some(item => item && item.event === '$snapshot');
|
|
13176
|
+
if (hasSnapshot) {
|
|
13177
|
+
const host = this.config && this.config.host || '';
|
|
13178
|
+
const newUrl = host ? `${host.replace(/\/$/, '')}/s/` : url;
|
|
13179
|
+
return fetchFn(newUrl, options);
|
|
13180
|
+
}
|
|
13181
|
+
}
|
|
13182
|
+
}
|
|
13183
|
+
} catch {
|
|
13184
|
+
return fetchFn(url, options);
|
|
13185
|
+
}
|
|
13162
13186
|
return fetchFn(url, options);
|
|
13163
13187
|
}
|
|
13164
13188
|
setConfig(config) {
|