{"version":3,"file":"cookieExpiry.mjs","names":[],"sources":["../../../src/utils/cookieExpiry.ts"],"sourcesContent":["import type { ProcessedCookieAttributes } from '@intlayer/types/config';\n\n/**\n * Resolves a normalized cookie `expires` value to an absolute timestamp\n * (epoch ms). The value is produced by the config-build merge step, so it is\n * already unambiguous:\n *\n * - `number` → seconds from now (relative lifetime);\n * - `string` → an absolute ISO date.\n *\n * Returns `undefined` when no usable expiry is provided so callers fall back\n * to a session cookie.\n *\n * @param expires - The normalized `expires` value from the built config.\n * @returns The absolute expiry in epoch milliseconds, or `undefined`.\n */\nexport const resolveExpiresToTimestamp = (\n  expires: ProcessedCookieAttributes['expires']\n): number | undefined => {\n  if (typeof expires === 'number') return Date.now() + expires * 1000;\n  if (typeof expires === 'string') {\n    const time = Date.parse(expires);\n    return Number.isNaN(time) ? undefined : time;\n  }\n  return undefined;\n};\n\n/**\n * Serializes a cookie into a `document.cookie` string. Expiry is emitted as an\n * absolute `Expires=` attribute resolved from the normalized `expires` value.\n *\n * @param name - The cookie name.\n * @param value - The cookie value (URL-encoded by this helper).\n * @param attributes - The normalized cookie attributes.\n * @returns The serialized cookie string.\n */\nexport const buildCookieString = (\n  name: string,\n  value: string,\n  attributes: ProcessedCookieAttributes\n): string => {\n  const parts: string[] = [`${name}=${encodeURIComponent(value)}`];\n\n  if (attributes.path) parts.push(`Path=${attributes.path}`);\n  if (attributes.domain) parts.push(`Domain=${attributes.domain}`);\n  const expiresTimestamp = resolveExpiresToTimestamp(attributes.expires);\n  if (expiresTimestamp !== undefined)\n    parts.push(`Expires=${new Date(expiresTimestamp).toUTCString()}`);\n  if (attributes.secure) parts.push('Secure');\n  if (attributes.sameSite) parts.push(`SameSite=${attributes.sameSite}`);\n  return parts.join('; ');\n};\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,MAAa,6BACX,YACuB;AACvB,KAAI,OAAO,YAAY,SAAU,QAAO,KAAK,KAAK,GAAG,UAAU;AAC/D,KAAI,OAAO,YAAY,UAAU;EAC/B,MAAM,OAAO,KAAK,MAAM,QAAQ;AAChC,SAAO,OAAO,MAAM,KAAK,GAAG,SAAY;;;;;;;;;;;;AAc5C,MAAa,qBACX,MACA,OACA,eACW;CACX,MAAM,QAAkB,CAAC,GAAG,KAAK,GAAG,mBAAmB,MAAM,GAAG;AAEhE,KAAI,WAAW,KAAM,OAAM,KAAK,QAAQ,WAAW,OAAO;AAC1D,KAAI,WAAW,OAAQ,OAAM,KAAK,UAAU,WAAW,SAAS;CAChE,MAAM,mBAAmB,0BAA0B,WAAW,QAAQ;AACtE,KAAI,qBAAqB,OACvB,OAAM,KAAK,WAAW,IAAI,KAAK,iBAAiB,CAAC,aAAa,GAAG;AACnE,KAAI,WAAW,OAAQ,OAAM,KAAK,SAAS;AAC3C,KAAI,WAAW,SAAU,OAAM,KAAK,YAAY,WAAW,WAAW;AACtE,QAAO,MAAM,KAAK,KAAK"}