{"version":3,"file":"utils-V2FbmPWk.mjs","names":[],"sources":["../../src/utils/allSettled.ts","../../src/utils/logErrorInDevMode.ts","../../src/utils/runIfFunctionOrReturn.ts","../../src/utils/fastDeepMerge.ts","../../src/utils/timeLimit.ts"],"sourcesContent":["/**\n * A ES6 compatible utility that implements `Promise.allSettled`\n *\n * @internal\n */\nexport function allSettled<T>(\n  iterable: Iterable<Promise<T>>,\n): Promise<({ status: 'fulfilled'; value: T } | { status: 'rejected'; reason: any })[]> {\n  const promises = Array.from(iterable).map(p =>\n    p.then(\n      value => ({ status: 'fulfilled', value }) as const,\n      reason => ({ status: 'rejected', reason }) as const,\n    ),\n  );\n  return Promise.all(promises);\n}\n","import { isDevelopmentEnvironment } from './runtimeEnvironment';\n\nexport const logErrorInDevMode = (message: string) => {\n  if (isDevelopmentEnvironment()) {\n    console.error(`Clerk: ${message}`);\n  }\n};\n","/**\n *\n */\nexport function runIfFunctionOrReturn(o: unknown) {\n  if (typeof o === 'function') {\n    return o();\n  }\n  return o;\n}\n","// Keys that could lead to prototype pollution attacks\nconst DANGEROUS_KEYS = new Set(['__proto__', 'constructor', 'prototype']);\n\n/**\n * Merges 2 objects without creating new object references\n * The merged props will appear on the `target` object\n * If `target` already has a value for a given key it will not be overwritten\n */\nexport const fastDeepMergeAndReplace = (\n  source: Record<any, any> | undefined | null,\n  target: Record<any, any> | undefined | null,\n) => {\n  if (!source || !target) {\n    return;\n  }\n\n  for (const key in source) {\n    // Skip dangerous keys to prevent prototype pollution\n    if (DANGEROUS_KEYS.has(key)) {\n      continue;\n    }\n    if (Object.prototype.hasOwnProperty.call(source, key) && source[key] !== null && typeof source[key] === `object`) {\n      if (target[key] === undefined) {\n        target[key] = new (Object.getPrototypeOf(source[key]).constructor)();\n      }\n      fastDeepMergeAndReplace(source[key], target[key]);\n    } else if (Object.prototype.hasOwnProperty.call(source, key) && source[key] !== undefined) {\n      target[key] = source[key];\n    }\n  }\n};\n\nexport const fastDeepMergeAndKeep = (\n  source: Record<any, any> | undefined | null,\n  target: Record<any, any> | undefined | null,\n) => {\n  if (!source || !target) {\n    return;\n  }\n\n  for (const key in source) {\n    // Skip dangerous keys to prevent prototype pollution\n    if (DANGEROUS_KEYS.has(key)) {\n      continue;\n    }\n    if (Object.prototype.hasOwnProperty.call(source, key) && source[key] !== null && typeof source[key] === `object`) {\n      if (target[key] === undefined) {\n        target[key] = new (Object.getPrototypeOf(source[key]).constructor)();\n      }\n      fastDeepMergeAndKeep(source[key], target[key]);\n    } else if (Object.prototype.hasOwnProperty.call(source, key) && target[key] === undefined) {\n      target[key] = source[key];\n    }\n  }\n};\n","export function timeLimit<T>(\n  value: T | PromiseLike<T>,\n  ms: number,\n  abortController?: Pick<AbortController, 'abort'>,\n): Promise<T> {\n  let timeoutId: ReturnType<typeof setTimeout>;\n\n  const timeoutPromise = new Promise<never>((_, reject) => {\n    timeoutId = setTimeout(() => {\n      const error = new Error(`Timed out after ${ms}ms`);\n      abortController?.abort();\n      reject(error);\n    }, ms);\n\n    // Let a Node process exit while the timeout is still pending; browsers return a number with no unref.\n    (timeoutId as { unref?: () => void }).unref?.();\n  });\n\n  return Promise.race([Promise.resolve(value), timeoutPromise]).finally(() => {\n    clearTimeout(timeoutId);\n  });\n}\n"],"mappings":";;;;;;;;AAKA,SAAgB,WACd,UACsF;CACtF,MAAM,WAAW,MAAM,KAAK,QAAQ,CAAC,CAAC,KAAI,MACxC,EAAE,MACA,WAAU;EAAE,QAAQ;EAAa;CAAM,KACvC,YAAW;EAAE,QAAQ;EAAY;CAAO,EAC1C,CACF;CACA,OAAO,QAAQ,IAAI,QAAQ;AAC7B;;;;ACbA,MAAa,qBAAqB,YAAoB;CACpD,IAAI,yBAAyB,GAC3B,QAAQ,MAAM,UAAU,SAAS;AAErC;;;;;;;ACHA,SAAgB,sBAAsB,GAAY;CAChD,IAAI,OAAO,MAAM,YACf,OAAO,EAAE;CAEX,OAAO;AACT;;;;ACPA,MAAM,iBAAiB,IAAI,IAAI;CAAC;CA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