{"version":3,"file":"generateConfigurationContent.mjs","names":[],"sources":["../../../src/writeConfiguration/generateConfigurationContent.ts"],"sourcesContent":["import { BUILT_CONFIG_KEYS } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\n\n/**\n * Generates the source of the `.intlayer/config/configuration.{mjs,cjs}` file\n * that bundler integrations alias `@intlayer/config/built` to.\n *\n * The emitted named exports are derived from {@link BUILT_CONFIG_KEYS}, the same\n * canonical list `built.ts` uses, so the aliased file always exposes exactly the\n * exports consumers import — preventing `MISSING_EXPORT` errors when a new\n * configuration section (e.g. `analytics`) is added.\n *\n * ## Why `editor.clientSecret` is never emitted\n *\n * This file is what a bundle *inlines*. Every framework integration installs the\n * same alias for the client and the server build, so anything written here that\n * a client module imports ends up in a public asset — and `editor` is imported\n * by browser code (the provider, the analytics SDK, the visual editor).\n *\n * `clientSecret` grants full project-scoped API access, so it is stripped here\n * rather than in each integration: a per-bundler fix only protects the bundlers\n * we patched, while stripping it at the source protects every consumer,\n * including ones that build their own alias.\n *\n * Server-side code reads the secret from `@intlayer/config/secrets`, whose\n * `browser` export condition resolves to an empty stub in browser builds.\n *\n * @param configuration - The fully resolved Intlayer configuration.\n * @param format - Module format to emit (`esm` for `.mjs`, `cjs` for `.cjs`).\n * @returns The file content as a string.\n */\nexport const generateConfigurationContent = (\n  configuration: IntlayerConfig,\n  format: 'cjs' | 'esm'\n): string => {\n  let fileContent = '';\n\n  const { clientSecret: _clientSecret, ...editorWithoutSecret } =\n    configuration.editor;\n\n  const values: Record<string, unknown> = {\n    ...configuration,\n    editor: editorWithoutSecret,\n  };\n\n  for (const key of BUILT_CONFIG_KEYS) {\n    const value = values[key];\n    fileContent += `const ${key} = ${JSON.stringify(value, null, 2)};\\n`;\n  }\n\n  if (format === 'esm') {\n    fileContent += `\\nexport { ${BUILT_CONFIG_KEYS.join(', ')} };\\n`;\n  } else {\n    fileContent += '\\n';\n    for (const key of BUILT_CONFIG_KEYS) {\n      fileContent += `module.exports.${key} = ${key};\\n`;\n    }\n  }\n\n  return fileContent;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,gCACX,eACA,WACW;CACX,IAAI,cAAc;CAElB,MAAM,EAAE,cAAc,eAAe,GAAG,wBACtC,cAAc;CAEhB,MAAM,SAAkC;EACtC,GAAG;EACH,QAAQ;CACV;CAEA,KAAK,MAAM,OAAO,mBAAmB;EACnC,MAAM,QAAQ,OAAO;EACrB,eAAe,SAAS,IAAI,KAAK,KAAK,UAAU,OAAO,MAAM,CAAC,EAAE;CAClE;CAEA,IAAI,WAAW,OACb,eAAe,cAAc,kBAAkB,KAAK,IAAI,EAAE;MACrD;EACL,eAAe;EACf,KAAK,MAAM,OAAO,mBAChB,eAAe,kBAAkB,IAAI,KAAK,IAAI;CAElD;CAEA,OAAO;AACT"}