@mushi-mushi/core 1.22.0 → 1.22.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/dist/index.js CHANGED
@@ -1235,6 +1235,7 @@ function createOfflineQueue(config = {}) {
1235
1235
  }
1236
1236
  function startAutoSync(client) {
1237
1237
  if (!enabled || !syncOnReconnect || typeof window === "undefined") return;
1238
+ if (syncCleanup) stopAutoSync();
1238
1239
  const tryFlush = () => {
1239
1240
  if (navigator.onLine) {
1240
1241
  flush(client).catch((err) => {
@@ -1585,8 +1586,21 @@ function getSessionId() {
1585
1586
  }
1586
1587
  function generateSessionId() {
1587
1588
  const timestamp = Date.now().toString(36);
1588
- const random = Math.random().toString(36).slice(2, 8);
1589
- return `ms_${timestamp}_${random}`;
1589
+ return `ms_${timestamp}_${randomSuffix()}`;
1590
+ }
1591
+ function randomSuffix() {
1592
+ const c = typeof crypto !== "undefined" ? crypto : void 0;
1593
+ const bytes = new Uint8Array(4);
1594
+ if (c?.getRandomValues) {
1595
+ c.getRandomValues(bytes);
1596
+ } else {
1597
+ for (let i = 0; i < bytes.length; i++) {
1598
+ bytes[i] = Math.floor(Math.random() * 256);
1599
+ }
1600
+ }
1601
+ let n = 0;
1602
+ for (const b of bytes) n = n * 256 + b >>> 0;
1603
+ return n.toString(36).padStart(6, "0").slice(0, 6);
1590
1604
  }
1591
1605
 
1592
1606
  // src/rate-limiter.ts