import CJS_COMPAT_NODE_URL_7akq6ta4tq from 'node:url';
import CJS_COMPAT_NODE_PATH_7akq6ta4tq from 'node:path';
import CJS_COMPAT_NODE_MODULE_7akq6ta4tq from "node:module";

var __filename = CJS_COMPAT_NODE_URL_7akq6ta4tq.fileURLToPath(import.meta.url);
var __dirname = CJS_COMPAT_NODE_PATH_7akq6ta4tq.dirname(__filename);
var require = CJS_COMPAT_NODE_MODULE_7akq6ta4tq.createRequire(import.meta.url);

// ------------------------------------------------------------
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
// ------------------------------------------------------------

// src/telemetry/session-id.ts
import { cache } from "storybook/internal/common";

// ../../node_modules/nanoid/index.js
import { randomFillSync } from "crypto";

// ../../node_modules/nanoid/url-alphabet/index.js
var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";

// ../../node_modules/nanoid/index.js
var POOL_SIZE_MULTIPLIER = 128, pool, poolOffset, fillPool = (bytes) => {
  !pool || pool.length < bytes ? (pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER), randomFillSync(pool), poolOffset = 0) : poolOffset + bytes > pool.length && (randomFillSync(pool), poolOffset = 0), poolOffset += bytes;
};
var nanoid = (size = 21) => {
  fillPool(size -= 0);
  let id = "";
  for (let i = poolOffset - size; i < poolOffset; i++)
    id += urlAlphabet[pool[i] & 63];
  return id;
};

// src/telemetry/session-id.ts
var SESSION_TIMEOUT = 1e3 * 60 * 60 * 2, sessionId, resetSessionIdForTest = (val = void 0) => {
  sessionId = val;
}, getSessionId = async () => {
  let now = Date.now();
  if (!sessionId) {
    let session = await cache.get("session");
    session && session.lastUsed >= now - SESSION_TIMEOUT ? sessionId = session.id : sessionId = nanoid();
  }
  return await cache.set("session", { id: sessionId, lastUsed: now }), sessionId;
};

export {
  nanoid,
  SESSION_TIMEOUT,
  resetSessionIdForTest,
  getSessionId
};
