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