{"version":3,"file":"sitecore-content-sdk-angular-config.mjs","sources":["../../src/config/define-config.ts","../../src/config/sitecore-content-sdk-angular-config.ts"],"sourcesContent":["import type { DeepRequired, SitecoreConfigInput } from '@sitecore-content-sdk/content/config';\r\nimport { defineConfig as baseDefineConfig } from '@sitecore-content-sdk/content/config';\r\nimport type { ExpressRequest, ExpressResponse } from './http-types';\r\n\r\n/**\r\n * Link-prefetch strategy for `scRouterLink`/`scRichText` links:\r\n * - `'eager'` (default) — prefetch as soon as the link renders.\r\n * - `'hover'` — prefetch only once the pointer dwells on the link (see `delayMs`); starts\r\n *   disabled and is enabled the moment the user shows intent.\r\n * - `'off'` — never prefetch.\r\n * @public\r\n */\r\nexport type LinkPrefetchMode = 'eager' | 'hover' | 'off';\r\n/**\r\n * Reads `process.env` when running under Node; otherwise returns an empty object.\r\n * @returns {Record<string, string | undefined>} Environment map for merging into config.\r\n */\r\nfunction getProcessEnv(): Record<string, string | undefined> {\r\n  // Use globalThis so we do not need @types/node (lib tsconfig uses \"types\": []).\r\n  const env = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process\r\n    ?.env;\r\n  return env ? env : {};\r\n}\r\n\r\n/**\r\n * Sitecore configuration input for Angular apps. Extends the base\r\n * {@link SitecoreConfigInput} with an `angular` section. `redirects.locales` is intentionally\r\n * omitted from the input — it is derived from `angular.locales` so there is a single\r\n * source of truth for the locale list.\r\n * @public\r\n */\r\nexport interface AngularSitecoreConfigInput extends Omit<SitecoreConfigInput, 'multisite'> {\r\n  /** Angular-specific configuration. */\r\n  angular?: {\r\n    /**\r\n     * Locales supported by the Angular app.\r\n     * `defaultLanguage` is prepended automatically when absent.\r\n     */\r\n    locales?: string[];\r\n    /**\r\n     * Configuration for the ISR-like cache. Both fields default when omitted\r\n     * (`enabled: true`, `revalidate: 300`).\r\n     */\r\n    loadersCache?: {\r\n      /** Whether the cache is enabled. */\r\n      enabled?: boolean;\r\n      /** The global revalidate time in seconds. */\r\n      revalidate?: number;\r\n    };\r\n    /**\r\n     * Configuration for loader prefetch on `scRouterLink`/`scRichText` links. Both fields\r\n     * default when omitted (`mode: 'eager'`, `delayMs: 100`). Can be overridden per-link via\r\n     * each directive's `prefetch` input.\r\n     */\r\n    linkPrefetch?: {\r\n      /** Prefetch strategy. See {@link LinkPrefetchMode}. */\r\n      mode?: LinkPrefetchMode;\r\n      /** Hover dwell time (ms) before prefetch fires when `mode: 'hover'`. */\r\n      delayMs?: number;\r\n    };\r\n  };\r\n  multisite?: {\r\n    enabled?: boolean;\r\n    /**\r\n     * Function used to determine if site should be resolved from sc_site cookie when present\r\n     */\r\n    useCookieResolution?: (req?: ExpressRequest, res?: ExpressResponse) => boolean;\r\n  };\r\n}\r\n\r\n/**\r\n * Resolved Sitecore configuration for Angular apps. Extends the fully-resolved\r\n * {@link SitecoreConfig}; structurally still a `SitecoreConfig`, so existing callers that\r\n * type the value as `SitecoreConfig` continue to work. `redirects.locales` is intentionally\r\n * omitted at the type level — read the canonical locale list from `angular.locales`.\r\n * @public\r\n */\r\nexport type AngularSitecoreConfig = DeepRequired<AngularSitecoreConfigInput>;\r\n\r\n/** Defaults applied to `angular.loadersCache` when input omits fields. */\r\nconst DEFAULT_ISR_CACHE = { enabled: true, revalidate: 300 } as const;\r\n\r\n/**\r\n * Defaults applied to `angular.linkPrefetch` when input omits fields. `mode: 'eager'` prefetches\r\n * on render unless a consumer opts into `'hover'` or disables it with `'off'`.\r\n */\r\nconst DEFAULT_LINK_PREFETCH = { mode: 'eager', delayMs: 100 } as const;\r\n\r\n/**\r\n * Ensures `defaultLanguage` is present in the locales list (prepended when missing) and\r\n * returns an empty-input fallback of `[defaultLanguage]`.\r\n * @param {string[]} input - Locales from `sitecore.config` (may be empty).\r\n * @param {string} defaultLanguage - Resolved `defaultLanguage` from the base config.\r\n * @returns {string[]} Locales with `defaultLanguage` guaranteed.\r\n */\r\nfunction resolveLocales(input: string[], defaultLanguage: string): string[] {\r\n  if (!input || input.length === 0) {\r\n    return [defaultLanguage];\r\n  }\r\n  if (input.includes(defaultLanguage)) {\r\n    return [...input];\r\n  }\r\n  return [defaultLanguage, ...input];\r\n}\r\n\r\n/**\r\n * Merges `clientEnv` (browser-safe `environment*.ts`) with `process.env` for server-only variables,\r\n * then delegates to the base content `defineConfig` and adds the Angular-specific config layer.\r\n *\r\n * - `angular.locales` is the single source of truth for the locale list; `defaultLanguage` is\r\n *   added when missing.\r\n * - `redirects.locales` is overwritten from `angular.locales` so the redirects proxy stays in sync.\r\n *\r\n * On Node/SSR, load `.env` in the app entry before importing `sitecore.config` (see\r\n * `load-env.ts` in the sample).\r\n * @param {AngularSitecoreConfigInput} [config] - Base Sitecore configuration input.\r\n * @param {Record<string, string | undefined>} [clientEnv] - Browser-safe env from `environment*.ts`.\r\n * @returns {AngularSitecoreConfig} Fully merged Sitecore configuration for Angular.\r\n * @public\r\n */\r\nexport function defineConfig(\r\n  config: AngularSitecoreConfigInput = {},\r\n  clientEnv: Record<string, string | undefined> = {}\r\n): AngularSitecoreConfig {\r\n  const { angular, ...baseInput } = config;\r\n  const scConfig = baseDefineConfig(baseInput as SitecoreConfigInput, {\r\n    ...clientEnv,\r\n    ...getProcessEnv(),\r\n  });\r\n\r\n  const locales = resolveLocales(angular?.locales ?? [], scConfig.defaultLanguage);\r\n\r\n  scConfig.redirects.locales = locales;\r\n\r\n  const loadersCache = {\r\n    enabled: angular?.loadersCache?.enabled ?? DEFAULT_ISR_CACHE.enabled,\r\n    revalidate: angular?.loadersCache?.revalidate ?? DEFAULT_ISR_CACHE.revalidate,\r\n  };\r\n\r\n  const linkPrefetch = {\r\n    mode: angular?.linkPrefetch?.mode ?? DEFAULT_LINK_PREFETCH.mode,\r\n    delayMs: angular?.linkPrefetch?.delayMs ?? DEFAULT_LINK_PREFETCH.delayMs,\r\n  };\r\n\r\n  return {\r\n    ...scConfig,\r\n    angular: { locales, loadersCache, linkPrefetch },\r\n  } as AngularSitecoreConfig;\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\n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