@mushi-mushi/core 1.22.0 → 1.22.1

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
@@ -1585,8 +1585,21 @@ function getSessionId() {
1585
1585
  }
1586
1586
  function generateSessionId() {
1587
1587
  const timestamp = Date.now().toString(36);
1588
- const random = Math.random().toString(36).slice(2, 8);
1589
- return `ms_${timestamp}_${random}`;
1588
+ return `ms_${timestamp}_${randomSuffix()}`;
1589
+ }
1590
+ function randomSuffix() {
1591
+ const c = typeof crypto !== "undefined" ? crypto : void 0;
1592
+ const bytes = new Uint8Array(4);
1593
+ if (c?.getRandomValues) {
1594
+ c.getRandomValues(bytes);
1595
+ } else {
1596
+ for (let i = 0; i < bytes.length; i++) {
1597
+ bytes[i] = Math.floor(Math.random() * 256);
1598
+ }
1599
+ }
1600
+ let n = 0;
1601
+ for (const b of bytes) n = n * 256 + b >>> 0;
1602
+ return n.toString(36).padStart(6, "0").slice(0, 6);
1590
1603
  }
1591
1604
 
1592
1605
  // src/rate-limiter.ts