@intlayer/cli 8.4.1 → 8.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/dist/cjs/auth/login.cjs +2 -2
  2. package/dist/cjs/auth/login.cjs.map +1 -1
  3. package/dist/cjs/extract.cjs +1 -1
  4. package/dist/cjs/extract.cjs.map +1 -1
  5. package/dist/cjs/fill/fill.cjs +1 -1
  6. package/dist/cjs/fill/fill.cjs.map +1 -1
  7. package/dist/cjs/fill/listTranslationsTasks.cjs +1 -1
  8. package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -1
  9. package/dist/cjs/fill/translateDictionary.cjs +1 -1
  10. package/dist/cjs/fill/translateDictionary.cjs.map +1 -1
  11. package/dist/cjs/pull.cjs +1 -1
  12. package/dist/cjs/pull.cjs.map +1 -1
  13. package/dist/cjs/push/pullLog.cjs +3 -3
  14. package/dist/cjs/push/pullLog.cjs.map +1 -1
  15. package/dist/cjs/push/push.cjs +1 -1
  16. package/dist/cjs/push/push.cjs.map +1 -1
  17. package/dist/cjs/pushLog.cjs +3 -3
  18. package/dist/cjs/pushLog.cjs.map +1 -1
  19. package/dist/cjs/reviewDoc/reviewDoc.cjs +1 -1
  20. package/dist/cjs/reviewDoc/reviewDoc.cjs.map +1 -1
  21. package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs +1 -1
  22. package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs.map +1 -1
  23. package/dist/cjs/test/test.cjs +1 -1
  24. package/dist/cjs/test/test.cjs.map +1 -1
  25. package/dist/cjs/translateDoc/translateDoc.cjs +1 -1
  26. package/dist/cjs/translateDoc/translateDoc.cjs.map +1 -1
  27. package/dist/cjs/translateDoc/translateFile.cjs +2 -2
  28. package/dist/cjs/translateDoc/translateFile.cjs.map +1 -1
  29. package/dist/cjs/utils/checkAccess.cjs +1 -1
  30. package/dist/cjs/utils/checkAccess.cjs.map +1 -1
  31. package/dist/cjs/utils/setupAI.cjs +1 -1
  32. package/dist/cjs/utils/setupAI.cjs.map +1 -1
  33. package/dist/esm/auth/login.mjs +1 -1
  34. package/dist/esm/auth/login.mjs.map +1 -1
  35. package/dist/esm/extract.mjs +1 -1
  36. package/dist/esm/extract.mjs.map +1 -1
  37. package/dist/esm/fill/fill.mjs +1 -1
  38. package/dist/esm/fill/fill.mjs.map +1 -1
  39. package/dist/esm/fill/listTranslationsTasks.mjs +1 -1
  40. package/dist/esm/fill/listTranslationsTasks.mjs.map +1 -1
  41. package/dist/esm/fill/translateDictionary.mjs +1 -1
  42. package/dist/esm/fill/translateDictionary.mjs.map +1 -1
  43. package/dist/esm/pull.mjs +1 -1
  44. package/dist/esm/pull.mjs.map +1 -1
  45. package/dist/esm/push/pullLog.mjs +1 -1
  46. package/dist/esm/push/pullLog.mjs.map +1 -1
  47. package/dist/esm/push/push.mjs +1 -1
  48. package/dist/esm/push/push.mjs.map +1 -1
  49. package/dist/esm/pushLog.mjs +1 -1
  50. package/dist/esm/pushLog.mjs.map +1 -1
  51. package/dist/esm/reviewDoc/reviewDoc.mjs +1 -1
  52. package/dist/esm/reviewDoc/reviewDoc.mjs.map +1 -1
  53. package/dist/esm/reviewDoc/reviewDocBlockAware.mjs +1 -1
  54. package/dist/esm/reviewDoc/reviewDocBlockAware.mjs.map +1 -1
  55. package/dist/esm/test/test.mjs +1 -1
  56. package/dist/esm/test/test.mjs.map +1 -1
  57. package/dist/esm/translateDoc/translateDoc.mjs +1 -1
  58. package/dist/esm/translateDoc/translateDoc.mjs.map +1 -1
  59. package/dist/esm/translateDoc/translateFile.mjs +1 -1
  60. package/dist/esm/translateDoc/translateFile.mjs.map +1 -1
  61. package/dist/esm/utils/checkAccess.mjs +1 -1
  62. package/dist/esm/utils/checkAccess.mjs.map +1 -1
  63. package/dist/esm/utils/setupAI.mjs +1 -1
  64. package/dist/esm/utils/setupAI.mjs.map +1 -1
  65. package/dist/types/auth/login.d.ts.map +1 -1
  66. package/dist/types/extract.d.ts.map +1 -1
  67. package/dist/types/pull.d.ts.map +1 -1
  68. package/dist/types/push/pullLog.d.ts.map +1 -1
  69. package/dist/types/push/push.d.ts.map +1 -1
  70. package/dist/types/setupAI-Bosjx7ah.d.ts.map +1 -1
  71. package/dist/types/utils/checkAccess.d.ts.map +1 -1
  72. package/package.json +12 -12
@@ -1 +1 @@
1
- {"version":3,"file":"checkAccess.cjs","names":["ANSIColors"],"sources":["../../../src/utils/checkAccess.ts"],"sourcesContent":["import type { AIOptions } from '@intlayer/api';\nimport { getIntlayerAPIProxy } from '@intlayer/api';\nimport { ANSIColors, colorize, getAppLogger } from '@intlayer/config/logger';\nimport { extractErrorMessage } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { checkConfigConsistency } from './checkConfigConsistency';\n\nexport const checkCMSAuth = async (\n configuration: IntlayerConfig,\n shouldCheckConfigConsistency: boolean = true\n): Promise<boolean> => {\n const appLogger = getAppLogger(configuration);\n\n const hasCMSAuth =\n configuration.editor.clientId && configuration.editor.clientSecret;\n if (!hasCMSAuth) {\n appLogger(\n [\n 'CMS auth not provided. You can either retreive the CMS access key on',\n colorize('https://intlayer.org/dahboard', ANSIColors.GREY),\n colorize('(see doc:', ANSIColors.GREY_DARK),\n colorize('https://intlayer.org/doc/concept/cms', ANSIColors.GREY),\n colorize(')', ANSIColors.GREY_DARK),\n '.',\n ],\n {\n level: 'error',\n }\n );\n\n return false;\n }\n const intlayerAPI = getIntlayerAPIProxy(undefined, configuration);\n\n try {\n const result = await intlayerAPI.oAuth.getOAuth2AccessToken();\n\n const project = result.data?.project;\n\n if (!project) {\n appLogger('Project not found');\n\n return true;\n }\n\n if (project.configuration && shouldCheckConfigConsistency) {\n try {\n let remoteConfigToCheck = project.configuration;\n\n // Remove server-side computed flags (apiKeyConfigured)\n // We use destructuring + spread to avoid the 'delete' operator (performance)\n if (\n remoteConfigToCheck.ai &&\n 'apiKeyConfigured' in remoteConfigToCheck.ai\n ) {\n const { apiKeyConfigured, ...restAi } = remoteConfigToCheck.ai as any;\n\n remoteConfigToCheck = {\n ...remoteConfigToCheck,\n ai: restAi,\n };\n }\n\n // Recursively check if project.configuration (subset) matches configuration (superset)\n checkConfigConsistency(remoteConfigToCheck, configuration);\n } catch {\n appLogger(\n [\n 'Remote configuration is not up to date. The project configuration does not match the local configuration.',\n 'You can push the configuration by running',\n colorize('npx intlayer configuration push', ANSIColors.CYAN),\n colorize('(see doc:', ANSIColors.GREY_DARK),\n colorize(\n 'https://intlayer.org/doc/concept/cli/push',\n ANSIColors.GREY\n ),\n colorize(')', ANSIColors.GREY_DARK),\n '.',\n ],\n {\n level: 'warn',\n }\n );\n }\n }\n } catch (error) {\n const message = extractErrorMessage(error);\n\n appLogger(message, {\n level: 'error',\n });\n return false;\n }\n\n return true;\n};\n\nexport const checkAIAccess = async (\n configuration: IntlayerConfig,\n aiOptions?: AIOptions,\n shouldCheckConfigConsistency: boolean = true\n): Promise<boolean> => {\n const appLogger = getAppLogger(configuration);\n\n const hasCMSAuth = Boolean(\n configuration.editor.clientId && configuration.editor.clientSecret\n );\n const isOllama =\n configuration.ai?.provider === 'ollama' || aiOptions?.provider === 'ollama';\n const hasHisOwnAIAPIKey = Boolean(\n configuration.ai?.apiKey || aiOptions?.apiKey\n );\n\n if (hasHisOwnAIAPIKey || isOllama) {\n return true;\n }\n\n // User need to provide either his own AI API key or the CMS auth\n if (!hasCMSAuth) {\n appLogger(\n [\n 'AI options or API key not provided. You can either retreive the CMS access key on',\n colorize('https://intlayer.org/dahboard', ANSIColors.GREY),\n colorize('(see doc:', ANSIColors.GREY_DARK),\n colorize('https://intlayer.org/doc/concept/cms', ANSIColors.GREY),\n colorize(')', ANSIColors.GREY_DARK),\n '. Alternatively, you can add your own OpenAI API key in the settings',\n colorize('(see doc:', ANSIColors.GREY_DARK),\n colorize(\n 'https://intlayer.org/doc/concept/configuration',\n ANSIColors.GREY\n ),\n colorize(')', ANSIColors.GREY_DARK),\n '.',\n ],\n {\n level: 'error',\n }\n );\n\n return false;\n }\n\n // If the user do not have his own AI API key, we need to check the CMS auth\n return await checkCMSAuth(configuration, shouldCheckConfigConsistency);\n};\n"],"mappings":"4PAOA,MAAa,EAAe,MAC1B,EACA,EAAwC,KACnB,CACrB,IAAM,GAAA,EAAA,EAAA,cAAyB,EAAc,CAI7C,GAAI,EADF,EAAc,OAAO,UAAY,EAAc,OAAO,cAgBtD,OAdA,EACE,CACE,sFACS,gCAAiCA,EAAAA,WAAW,KAAK,gBACjD,YAAaA,EAAAA,WAAW,UAAU,gBAClC,uCAAwCA,EAAAA,WAAW,KAAK,gBACxD,IAAKA,EAAAA,WAAW,UAAU,CACnC,IACD,CACD,CACE,MAAO,QACR,CACF,CAEM,GAET,IAAM,GAAA,EAAA,EAAA,qBAAkC,IAAA,GAAW,EAAc,CAEjE,GAAI,CAGF,IAAM,GAFS,MAAM,EAAY,MAAM,sBAAsB,EAEtC,MAAM,QAE7B,GAAI,CAAC,EAGH,OAFA,EAAU,oBAAoB,CAEvB,GAGT,GAAI,EAAQ,eAAiB,EAC3B,GAAI,CACF,IAAI,EAAsB,EAAQ,cAIlC,GACE,EAAoB,IACpB,qBAAsB,EAAoB,GAC1C,CACA,GAAM,CAAE,mBAAkB,GAAG,GAAW,EAAoB,GAE5D,EAAsB,CACpB,GAAG,EACH,GAAI,EACL,CAIH,EAAA,uBAAuB,EAAqB,EAAc,MACpD,CACN,EACE,CACE,4GACA,2DACS,kCAAmCA,EAAAA,WAAW,KAAK,gBACnD,YAAaA,EAAAA,WAAW,UAAU,gBAEzC,4CACAA,EAAAA,WAAW,KACZ,gBACQ,IAAKA,EAAAA,WAAW,UAAU,CACnC,IACD,CACD,CACE,MAAO,OACR,CACF,QAGE,EAAO,CAMd,OAHA,GAAA,EAAA,EAAA,qBAFoC,EAAM,CAEvB,CACjB,MAAO,QACR,CAAC,CACK,GAGT,MAAO,IAGI,EAAgB,MAC3B,EACA,EACA,EAAwC,KACnB,CACrB,IAAM,GAAA,EAAA,EAAA,cAAyB,EAAc,CAEvC,EAAa,GACjB,EAAc,OAAO,UAAY,EAAc,OAAO,cAElD,EACJ,EAAc,IAAI,WAAa,UAAY,GAAW,WAAa,SAoCrE,OAlCE,EAAc,IAAI,QAAU,GAAW,QAGhB,EAChB,GAIJ,EA0BE,MAAM,EAAa,EAAe,EAA6B,EAzBpE,EACE,CACE,mGACS,gCAAiCA,EAAAA,WAAW,KAAK,gBACjD,YAAaA,EAAAA,WAAW,UAAU,gBAClC,uCAAwCA,EAAAA,WAAW,KAAK,gBACxD,IAAKA,EAAAA,WAAW,UAAU,CACnC,sFACS,YAAaA,EAAAA,WAAW,UAAU,gBAEzC,iDACAA,EAAAA,WAAW,KACZ,gBACQ,IAAKA,EAAAA,WAAW,UAAU,CACnC,IACD,CACD,CACE,MAAO,QACR,CACF,CAEM"}
1
+ {"version":3,"file":"checkAccess.cjs","names":["ANSIColors"],"sources":["../../../src/utils/checkAccess.ts"],"sourcesContent":["import type { AIOptions } from '@intlayer/api';\nimport { getIntlayerAPIProxy } from '@intlayer/api';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { extractErrorMessage } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { checkConfigConsistency } from './checkConfigConsistency';\n\nexport const checkCMSAuth = async (\n configuration: IntlayerConfig,\n shouldCheckConfigConsistency: boolean = true\n): Promise<boolean> => {\n const appLogger = getAppLogger(configuration);\n\n const hasCMSAuth =\n configuration.editor.clientId && configuration.editor.clientSecret;\n if (!hasCMSAuth) {\n appLogger(\n [\n 'CMS auth not provided. You can either retreive the CMS access key on',\n colorize('https://intlayer.org/dahboard', ANSIColors.GREY),\n colorize('(see doc:', ANSIColors.GREY_DARK),\n colorize('https://intlayer.org/doc/concept/cms', ANSIColors.GREY),\n colorize(')', ANSIColors.GREY_DARK),\n '.',\n ],\n {\n level: 'error',\n }\n );\n\n return false;\n }\n const intlayerAPI = getIntlayerAPIProxy(undefined, configuration);\n\n try {\n const result = await intlayerAPI.oAuth.getOAuth2AccessToken();\n\n const project = result.data?.project;\n\n if (!project) {\n appLogger('Project not found');\n\n return true;\n }\n\n if (project.configuration && shouldCheckConfigConsistency) {\n try {\n let remoteConfigToCheck = project.configuration;\n\n // Remove server-side computed flags (apiKeyConfigured)\n // We use destructuring + spread to avoid the 'delete' operator (performance)\n if (\n remoteConfigToCheck.ai &&\n 'apiKeyConfigured' in remoteConfigToCheck.ai\n ) {\n const { apiKeyConfigured, ...restAi } = remoteConfigToCheck.ai as any;\n\n remoteConfigToCheck = {\n ...remoteConfigToCheck,\n ai: restAi,\n };\n }\n\n // Recursively check if project.configuration (subset) matches configuration (superset)\n checkConfigConsistency(remoteConfigToCheck, configuration);\n } catch {\n appLogger(\n [\n 'Remote configuration is not up to date. The project configuration does not match the local configuration.',\n 'You can push the configuration by running',\n colorize('npx intlayer configuration push', ANSIColors.CYAN),\n colorize('(see doc:', ANSIColors.GREY_DARK),\n colorize(\n 'https://intlayer.org/doc/concept/cli/push',\n ANSIColors.GREY\n ),\n colorize(')', ANSIColors.GREY_DARK),\n '.',\n ],\n {\n level: 'warn',\n }\n );\n }\n }\n } catch (error) {\n const message = extractErrorMessage(error);\n\n appLogger(message, {\n level: 'error',\n });\n return false;\n }\n\n return true;\n};\n\nexport const checkAIAccess = async (\n configuration: IntlayerConfig,\n aiOptions?: AIOptions,\n shouldCheckConfigConsistency: boolean = true\n): Promise<boolean> => {\n const appLogger = getAppLogger(configuration);\n\n const hasCMSAuth = Boolean(\n configuration.editor.clientId && configuration.editor.clientSecret\n );\n const isOllama =\n configuration.ai?.provider === 'ollama' || aiOptions?.provider === 'ollama';\n const hasHisOwnAIAPIKey = Boolean(\n configuration.ai?.apiKey || aiOptions?.apiKey\n );\n\n if (hasHisOwnAIAPIKey || isOllama) {\n return true;\n }\n\n // User need to provide either his own AI API key or the CMS auth\n if (!hasCMSAuth) {\n appLogger(\n [\n 'AI options or API key not provided. You can either retreive the CMS access key on',\n colorize('https://intlayer.org/dahboard', ANSIColors.GREY),\n colorize('(see doc:', ANSIColors.GREY_DARK),\n colorize('https://intlayer.org/doc/concept/cms', ANSIColors.GREY),\n colorize(')', ANSIColors.GREY_DARK),\n '. Alternatively, you can add your own OpenAI API key in the settings',\n colorize('(see doc:', ANSIColors.GREY_DARK),\n colorize(\n 'https://intlayer.org/doc/concept/configuration',\n ANSIColors.GREY\n ),\n colorize(')', ANSIColors.GREY_DARK),\n '.',\n ],\n {\n level: 'error',\n }\n );\n\n return false;\n }\n\n // If the user do not have his own AI API key, we need to check the CMS auth\n return await checkCMSAuth(configuration, shouldCheckConfigConsistency);\n};\n"],"mappings":"gTAQA,MAAa,EAAe,MAC1B,EACA,EAAwC,KACnB,CACrB,IAAM,GAAA,EAAA,EAAA,cAAyB,EAAc,CAI7C,GAAI,EADF,EAAc,OAAO,UAAY,EAAc,OAAO,cAgBtD,OAdA,EACE,CACE,sFACS,gCAAiCA,EAAW,KAAK,gBACjD,YAAaA,EAAW,UAAU,gBAClC,uCAAwCA,EAAW,KAAK,gBACxD,IAAKA,EAAW,UAAU,CACnC,IACD,CACD,CACE,MAAO,QACR,CACF,CAEM,GAET,IAAM,GAAA,EAAA,EAAA,qBAAkC,IAAA,GAAW,EAAc,CAEjE,GAAI,CAGF,IAAM,GAFS,MAAM,EAAY,MAAM,sBAAsB,EAEtC,MAAM,QAE7B,GAAI,CAAC,EAGH,OAFA,EAAU,oBAAoB,CAEvB,GAGT,GAAI,EAAQ,eAAiB,EAC3B,GAAI,CACF,IAAI,EAAsB,EAAQ,cAIlC,GACE,EAAoB,IACpB,qBAAsB,EAAoB,GAC1C,CACA,GAAM,CAAE,mBAAkB,GAAG,GAAW,EAAoB,GAE5D,EAAsB,CACpB,GAAG,EACH,GAAI,EACL,CAIH,EAAA,uBAAuB,EAAqB,EAAc,MACpD,CACN,EACE,CACE,4GACA,2DACS,kCAAmCA,EAAW,KAAK,gBACnD,YAAaA,EAAW,UAAU,gBAEzC,4CACAA,EAAW,KACZ,gBACQ,IAAKA,EAAW,UAAU,CACnC,IACD,CACD,CACE,MAAO,OACR,CACF,QAGE,EAAO,CAMd,OAHA,GAAA,EAAA,EAAA,qBAFoC,EAAM,CAEvB,CACjB,MAAO,QACR,CAAC,CACK,GAGT,MAAO,IAGI,EAAgB,MAC3B,EACA,EACA,EAAwC,KACnB,CACrB,IAAM,GAAA,EAAA,EAAA,cAAyB,EAAc,CAEvC,EAAa,GACjB,EAAc,OAAO,UAAY,EAAc,OAAO,cAElD,EACJ,EAAc,IAAI,WAAa,UAAY,GAAW,WAAa,SAoCrE,OAlCE,EAAc,IAAI,QAAU,GAAW,QAGhB,EAChB,GAIJ,EA0BE,MAAM,EAAa,EAAe,EAA6B,EAzBpE,EACE,CACE,mGACS,gCAAiCA,EAAW,KAAK,gBACjD,YAAaA,EAAW,UAAU,gBAClC,uCAAwCA,EAAW,KAAK,gBACxD,IAAKA,EAAW,UAAU,CACnC,sFACS,YAAaA,EAAW,UAAU,gBAEzC,iDACAA,EAAW,KACZ,gBACQ,IAAKA,EAAW,UAAU,CACnC,IACD,CACD,CACE,MAAO,QACR,CACF,CAEM"}
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../chunk-Bmb41Sf3.cjs`);const e=require(`./checkAccess.cjs`);let t=require(`@intlayer/config/logger`);globalThis.AI_SDK_LOG_WARNINGS=!1;const n=(e,n)=>{n([(0,t.colorize)(`Provider:`,t.ANSIColors.GREY_DARK),(0,t.colorize)(e?.provider??`(default)`,t.ANSIColors.BLUE),(0,t.colorize)(`- Model:`,t.ANSIColors.GREY_DARK),(0,t.colorize)(e?.model??`(default)`,t.ANSIColors.BLUE),(0,t.colorize)(`- API Key:`,t.ANSIColors.GREY_DARK),(0,t.colorize)(e?.apiKey?`✓`:`(not set)`,t.ANSIColors.BLUE)])},r=async(r,i)=>{let a=(0,t.getAppLogger)(r);if(i?.apiKey||i?.provider===`ollama`||r.ai?.apiKey||r.ai?.provider===`ollama`){let o;try{o=await import(`@intlayer/ai`)}catch{a([(0,t.colorize)(`Using your API key, you can install the`,t.ANSIColors.GREY),(0,t.colorize)(`@intlayer/ai`,t.ANSIColors.GREY_LIGHT),(0,t.colorize)(`package to run the process locally, with no dependency on the Intlayer server`,t.ANSIColors.GREY)],{level:`warn`});let o=await e.checkAIAccess(r,i);return n(i??{},a),{isCustomAI:!1,hasAIAccess:o}}a([(0,t.colorize)(`@intlayer/ai`,t.ANSIColors.GREY_LIGHT),(0,t.colorize)(`found - Run process locally`,t.ANSIColors.GREY_DARK)]);let s=await o.getAIConfig({userOptions:i,accessType:[`public`]});return n(i??{},a),{aiClient:o,aiConfig:s,isCustomAI:!0,hasAIAccess:!0}}let o=await e.checkAIAccess(r,i);return n(i??{},a),{isCustomAI:!1,hasAIAccess:o}};exports.setupAI=r;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`),t=require(`./checkAccess.cjs`);let n=require(`@intlayer/config/colors`);n=e.t(n);let r=require(`@intlayer/config/logger`);globalThis.AI_SDK_LOG_WARNINGS=!1;const i=(e,t)=>{t([(0,r.colorize)(`Provider:`,n.GREY_DARK),(0,r.colorize)(e?.provider??`(default)`,n.BLUE),(0,r.colorize)(`- Model:`,n.GREY_DARK),(0,r.colorize)(e?.model??`(default)`,n.BLUE),(0,r.colorize)(`- API Key:`,n.GREY_DARK),(0,r.colorize)(e?.apiKey?`✓`:`(not set)`,n.BLUE)])},a=async(e,a)=>{let o=(0,r.getAppLogger)(e);if(a?.apiKey||a?.provider===`ollama`||e.ai?.apiKey||e.ai?.provider===`ollama`){let s;try{s=await import(`@intlayer/ai`)}catch{o([(0,r.colorize)(`Using your API key, you can install the`,n.GREY),(0,r.colorize)(`@intlayer/ai`,n.GREY_LIGHT),(0,r.colorize)(`package to run the process locally, with no dependency on the Intlayer server`,n.GREY)],{level:`warn`});let s=await t.checkAIAccess(e,a);return i(a??{},o),{isCustomAI:!1,hasAIAccess:s}}o([(0,r.colorize)(`@intlayer/ai`,n.GREY_LIGHT),(0,r.colorize)(`found - Run process locally`,n.GREY_DARK)]);let c=await s.getAIConfig({userOptions:a,accessType:[`public`]});return i(a??{},o),{aiClient:s,aiConfig:c,isCustomAI:!0,hasAIAccess:!0}}let s=await t.checkAIAccess(e,a);return i(a??{},o),{isCustomAI:!1,hasAIAccess:s}};exports.setupAI=a;
2
2
  //# sourceMappingURL=setupAI.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"setupAI.cjs","names":["ANSIColors","checkAIAccess"],"sources":["../../../src/utils/setupAI.ts"],"sourcesContent":["import type { AIConfig, AIOptions } from '@intlayer/ai';\nimport {\n ANSIColors,\n colorize,\n getAppLogger,\n type logger,\n} from '@intlayer/config/logger';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { checkAIAccess } from './checkAccess';\n\nexport type AIClient = typeof import('@intlayer/ai');\n\ntype SetupAIResult = {\n aiClient?: AIClient;\n aiConfig?: AIConfig;\n isCustomAI: boolean;\n hasAIAccess: boolean;\n};\n\n// Disable warnings from the AI SDK\nglobalThis.AI_SDK_LOG_WARNINGS = false;\n\nconst logAIConfig = (aiOptions: AIOptions, appLogger: typeof logger) => {\n appLogger([\n colorize('Provider:', ANSIColors.GREY_DARK),\n colorize(aiOptions?.provider ?? '(default)', ANSIColors.BLUE),\n colorize('- Model:', ANSIColors.GREY_DARK),\n colorize(aiOptions?.model ?? '(default)', ANSIColors.BLUE),\n colorize('- API Key:', ANSIColors.GREY_DARK),\n colorize(aiOptions?.apiKey ? '✓' : '(not set)', ANSIColors.BLUE),\n ]);\n};\n\n/**\n * Checks if the @intlayer/ai package is available and configured when an API key is provided.\n * If API key is present but package is missing, logs a warning.\n * Also checks if the user has access to AI (either via local key or CMS auth).\n */\nexport const setupAI = async (\n configuration: IntlayerConfig,\n aiOptions?: AIOptions\n): Promise<SetupAIResult | undefined> => {\n const appLogger = getAppLogger(configuration);\n\n const isLocalAI =\n aiOptions?.apiKey ||\n aiOptions?.provider === 'ollama' ||\n configuration.ai?.apiKey ||\n configuration.ai?.provider === 'ollama';\n\n if (isLocalAI) {\n // Try to import the AI package for local AI usage\n let aiClient: AIClient | undefined;\n\n try {\n aiClient = await import('@intlayer/ai');\n } catch {\n // Package not installed - log warning and fall back to backend\n appLogger(\n [\n colorize('Using your API key, you can install the', ANSIColors.GREY),\n colorize('@intlayer/ai', ANSIColors.GREY_LIGHT),\n colorize(\n 'package to run the process locally, with no dependency on the Intlayer server',\n ANSIColors.GREY\n ),\n ],\n {\n level: 'warn',\n }\n );\n\n // Fall back to backend API check\n const hasAIAccess = await checkAIAccess(configuration, aiOptions);\n logAIConfig(aiOptions ?? {}, appLogger);\n return {\n isCustomAI: false,\n hasAIAccess,\n };\n }\n\n // Package found - now configure it (errors here should propagate, not fall back)\n appLogger([\n colorize('@intlayer/ai', ANSIColors.GREY_LIGHT),\n colorize('found - Run process locally', ANSIColors.GREY_DARK),\n ]);\n\n const aiConfig = await aiClient.getAIConfig({\n userOptions: aiOptions,\n accessType: ['public'],\n });\n\n logAIConfig(aiOptions ?? {}, appLogger);\n\n return {\n aiClient,\n aiConfig,\n isCustomAI: true,\n hasAIAccess: true, // Local AI always has access\n };\n }\n\n // No local AI configured - use backend API\n const hasAIAccess = await checkAIAccess(configuration, aiOptions);\n logAIConfig(aiOptions ?? {}, appLogger);\n\n return {\n isCustomAI: false,\n hasAIAccess,\n };\n};\n"],"mappings":"kLAoBA,WAAW,oBAAsB,GAEjC,MAAM,GAAe,EAAsB,IAA6B,CACtE,EAAU,gBACC,YAAaA,EAAAA,WAAW,UAAU,gBAClC,GAAW,UAAY,YAAaA,EAAAA,WAAW,KAAK,gBACpD,WAAYA,EAAAA,WAAW,UAAU,gBACjC,GAAW,OAAS,YAAaA,EAAAA,WAAW,KAAK,gBACjD,aAAcA,EAAAA,WAAW,UAAU,gBACnC,GAAW,OAAS,IAAM,YAAaA,EAAAA,WAAW,KAAK,CACjE,CAAC,EAQS,EAAU,MACrB,EACA,IACuC,CACvC,IAAM,GAAA,EAAA,EAAA,cAAyB,EAAc,CAQ7C,GALE,GAAW,QACX,GAAW,WAAa,UACxB,EAAc,IAAI,QAClB,EAAc,IAAI,WAAa,SAElB,CAEb,IAAI,EAEJ,GAAI,CACF,EAAW,MAAM,OAAO,qBAClB,CAEN,EACE,gBACW,0CAA2CA,EAAAA,WAAW,KAAK,gBAC3D,eAAgBA,EAAAA,WAAW,WAAW,gBAE7C,gFACAA,EAAAA,WAAW,KACZ,CACF,CACD,CACE,MAAO,OACR,CACF,CAGD,IAAM,EAAc,MAAMC,EAAAA,cAAc,EAAe,EAAU,CAEjE,OADA,EAAY,GAAa,EAAE,CAAE,EAAU,CAChC,CACL,WAAY,GACZ,cACD,CAIH,EAAU,EAAA,EAAA,EAAA,UACC,eAAgBD,EAAAA,WAAW,WAAW,EAAA,EAAA,EAAA,UACtC,8BAA+BA,EAAAA,WAAW,UAAU,CAC9D,CAAC,CAEF,IAAM,EAAW,MAAM,EAAS,YAAY,CAC1C,YAAa,EACb,WAAY,CAAC,SAAS,CACvB,CAAC,CAIF,OAFA,EAAY,GAAa,EAAE,CAAE,EAAU,CAEhC,CACL,WACA,WACA,WAAY,GACZ,YAAa,GACd,CAIH,IAAM,EAAc,MAAMC,EAAAA,cAAc,EAAe,EAAU,CAGjE,OAFA,EAAY,GAAa,EAAE,CAAE,EAAU,CAEhC,CACL,WAAY,GACZ,cACD"}
1
+ {"version":3,"file":"setupAI.cjs","names":["ANSIColors","checkAIAccess"],"sources":["../../../src/utils/setupAI.ts"],"sourcesContent":["import type { AIConfig, AIOptions } from '@intlayer/ai';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger, type logger } from '@intlayer/config/logger';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { checkAIAccess } from './checkAccess';\n\nexport type AIClient = typeof import('@intlayer/ai');\n\ntype SetupAIResult = {\n aiClient?: AIClient;\n aiConfig?: AIConfig;\n isCustomAI: boolean;\n hasAIAccess: boolean;\n};\n\n// Disable warnings from the AI SDK\nglobalThis.AI_SDK_LOG_WARNINGS = false;\n\nconst logAIConfig = (aiOptions: AIOptions, appLogger: typeof logger) => {\n appLogger([\n colorize('Provider:', ANSIColors.GREY_DARK),\n colorize(aiOptions?.provider ?? '(default)', ANSIColors.BLUE),\n colorize('- Model:', ANSIColors.GREY_DARK),\n colorize(aiOptions?.model ?? '(default)', ANSIColors.BLUE),\n colorize('- API Key:', ANSIColors.GREY_DARK),\n colorize(aiOptions?.apiKey ? '✓' : '(not set)', ANSIColors.BLUE),\n ]);\n};\n\n/**\n * Checks if the @intlayer/ai package is available and configured when an API key is provided.\n * If API key is present but package is missing, logs a warning.\n * Also checks if the user has access to AI (either via local key or CMS auth).\n */\nexport const setupAI = async (\n configuration: IntlayerConfig,\n aiOptions?: AIOptions\n): Promise<SetupAIResult | undefined> => {\n const appLogger = getAppLogger(configuration);\n\n const isLocalAI =\n aiOptions?.apiKey ||\n aiOptions?.provider === 'ollama' ||\n configuration.ai?.apiKey ||\n configuration.ai?.provider === 'ollama';\n\n if (isLocalAI) {\n // Try to import the AI package for local AI usage\n let aiClient: AIClient | undefined;\n\n try {\n aiClient = await import('@intlayer/ai');\n } catch {\n // Package not installed - log warning and fall back to backend\n appLogger(\n [\n colorize('Using your API key, you can install the', ANSIColors.GREY),\n colorize('@intlayer/ai', ANSIColors.GREY_LIGHT),\n colorize(\n 'package to run the process locally, with no dependency on the Intlayer server',\n ANSIColors.GREY\n ),\n ],\n {\n level: 'warn',\n }\n );\n\n // Fall back to backend API check\n const hasAIAccess = await checkAIAccess(configuration, aiOptions);\n logAIConfig(aiOptions ?? {}, appLogger);\n return {\n isCustomAI: false,\n hasAIAccess,\n };\n }\n\n // Package found - now configure it (errors here should propagate, not fall back)\n appLogger([\n colorize('@intlayer/ai', ANSIColors.GREY_LIGHT),\n colorize('found - Run process locally', ANSIColors.GREY_DARK),\n ]);\n\n const aiConfig = await aiClient.getAIConfig({\n userOptions: aiOptions,\n accessType: ['public'],\n });\n\n logAIConfig(aiOptions ?? {}, appLogger);\n\n return {\n aiClient,\n aiConfig,\n isCustomAI: true,\n hasAIAccess: true, // Local AI always has access\n };\n }\n\n // No local AI configured - use backend API\n const hasAIAccess = await checkAIAccess(configuration, aiOptions);\n logAIConfig(aiOptions ?? {}, appLogger);\n\n return {\n isCustomAI: false,\n hasAIAccess,\n };\n};\n"],"mappings":"sOAgBA,WAAW,oBAAsB,GAEjC,MAAM,GAAe,EAAsB,IAA6B,CACtE,EAAU,gBACC,YAAaA,EAAW,UAAU,gBAClC,GAAW,UAAY,YAAaA,EAAW,KAAK,gBACpD,WAAYA,EAAW,UAAU,gBACjC,GAAW,OAAS,YAAaA,EAAW,KAAK,gBACjD,aAAcA,EAAW,UAAU,gBACnC,GAAW,OAAS,IAAM,YAAaA,EAAW,KAAK,CACjE,CAAC,EAQS,EAAU,MACrB,EACA,IACuC,CACvC,IAAM,GAAA,EAAA,EAAA,cAAyB,EAAc,CAQ7C,GALE,GAAW,QACX,GAAW,WAAa,UACxB,EAAc,IAAI,QAClB,EAAc,IAAI,WAAa,SAElB,CAEb,IAAI,EAEJ,GAAI,CACF,EAAW,MAAM,OAAO,qBAClB,CAEN,EACE,gBACW,0CAA2CA,EAAW,KAAK,gBAC3D,eAAgBA,EAAW,WAAW,gBAE7C,gFACAA,EAAW,KACZ,CACF,CACD,CACE,MAAO,OACR,CACF,CAGD,IAAM,EAAc,MAAMC,EAAAA,cAAc,EAAe,EAAU,CAEjE,OADA,EAAY,GAAa,EAAE,CAAE,EAAU,CAChC,CACL,WAAY,GACZ,cACD,CAIH,EAAU,EAAA,EAAA,EAAA,UACC,eAAgBD,EAAW,WAAW,EAAA,EAAA,EAAA,UACtC,8BAA+BA,EAAW,UAAU,CAC9D,CAAC,CAEF,IAAM,EAAW,MAAM,EAAS,YAAY,CAC1C,YAAa,EACb,WAAY,CAAC,SAAS,CACvB,CAAC,CAIF,OAFA,EAAY,GAAa,EAAE,CAAE,EAAU,CAEhC,CACL,WACA,WACA,WAAY,GACZ,YAAa,GACd,CAIH,IAAM,EAAc,MAAMC,EAAAA,cAAc,EAAe,EAAU,CAGjE,OAFA,EAAY,GAAa,EAAE,CAAE,EAAU,CAEhC,CACL,WAAY,GACZ,cACD"}
@@ -1,4 +1,4 @@
1
- import{openBrowser as e}from"../utils/openBrowser.mjs";import{logConfigDetails as t}from"@intlayer/chokidar/cli";import{ANSIColors as n,colorize as r,colorizePath as i,getAppLogger as a}from"@intlayer/config/logger";import{getConfiguration as o}from"@intlayer/config/node";import s from"node:http";import{URL as c}from"node:url";const l=async l=>{let u=o(l.configOptions);t(l?.configOptions);let d=a(u),f=l.cmsUrl??u.editor.cmsURL;return new Promise(t=>{let a=s.createServer((e,o)=>{let s=new c(e.url??``,`http://${e.headers.host}`);if(o.setHeader(`Access-Control-Allow-Origin`,`*`),o.setHeader(`Access-Control-Allow-Methods`,`GET, OPTIONS`),o.setHeader(`Access-Control-Allow-Headers`,`Content-Type`),e.method===`OPTIONS`){o.writeHead(204),o.end();return}if(s.pathname===`/callback`){let e=s.searchParams.get(`clientId`),c=s.searchParams.get(`clientSecret`);e&&c?(d(``),d(`Log in successful. Client ID and Client Secret received.`),d(``),d([`1. Insert the Client ID and Client Secret in your`,i(`.env`),`file:`]),d(r(`--------------------------------`,n.GREY_DARK)),d([r(`INTLAYER_CLIENT_ID=`,n.GREY_LIGHT),r(e,n.BLUE)].join(``)),d([r(`INTLAYER_CLIENT_SECRET=`,n.GREY_LIGHT),r(c,n.BLUE)].join(``)),d(r(`--------------------------------`,n.GREY_DARK)),d(``),d(`2. Insert in your Intlayer configuration file:`),d(r(`--------------------------------`,n.GREY_DARK)),[`${n.GREY_LIGHT}{`,` editor: {`,` cmsURL: '${i(f,void 0,n.GREY_LIGHT)}',`,` clientId: '${r(`process.env.INTLAYER_CLIENT_ID`,n.BLUE,n.GREY_LIGHT)}',`,` clientSecret: '${r(`process.env.INTLAYER_CLIENT_SECRET`,n.BLUE,n.GREY_LIGHT)}',`,` },`,`}`].forEach(e=>{d(e)}),d(r(`--------------------------------`,n.GREY_DARK)),o.writeHead(200,{"Content-Type":`text/html`}),o.end(`
1
+ import{openBrowser as e}from"../utils/openBrowser.mjs";import{logConfigDetails as t}from"@intlayer/chokidar/cli";import*as n from"@intlayer/config/colors";import{colorize as r,colorizePath as i,getAppLogger as a}from"@intlayer/config/logger";import{getConfiguration as o}from"@intlayer/config/node";import s from"node:http";import{URL as c}from"node:url";const l=async l=>{let u=o(l.configOptions);t(l?.configOptions);let d=a(u),f=l.cmsUrl??u.editor.cmsURL;return new Promise(t=>{let a=s.createServer((e,o)=>{let s=new c(e.url??``,`http://${e.headers.host}`);if(o.setHeader(`Access-Control-Allow-Origin`,`*`),o.setHeader(`Access-Control-Allow-Methods`,`GET, OPTIONS`),o.setHeader(`Access-Control-Allow-Headers`,`Content-Type`),e.method===`OPTIONS`){o.writeHead(204),o.end();return}if(s.pathname===`/callback`){let e=s.searchParams.get(`clientId`),c=s.searchParams.get(`clientSecret`);e&&c?(d(``),d(`Log in successful. Client ID and Client Secret received.`),d(``),d([`1. Insert the Client ID and Client Secret in your`,i(`.env`),`file:`]),d(r(`--------------------------------`,n.GREY_DARK)),d([r(`INTLAYER_CLIENT_ID=`,n.GREY_LIGHT),r(e,n.BLUE)].join(``)),d([r(`INTLAYER_CLIENT_SECRET=`,n.GREY_LIGHT),r(c,n.BLUE)].join(``)),d(r(`--------------------------------`,n.GREY_DARK)),d(``),d(`2. Insert in your Intlayer configuration file:`),d(r(`--------------------------------`,n.GREY_DARK)),[`${n.GREY_LIGHT}{`,` editor: {`,` cmsURL: '${i(f,void 0,n.GREY_LIGHT)}',`,` clientId: '${r(`process.env.INTLAYER_CLIENT_ID`,n.BLUE,n.GREY_LIGHT)}',`,` clientSecret: '${r(`process.env.INTLAYER_CLIENT_SECRET`,n.BLUE,n.GREY_LIGHT)}',`,` },`,`}`].forEach(e=>{d(e)}),d(r(`--------------------------------`,n.GREY_DARK)),o.writeHead(200,{"Content-Type":`text/html`}),o.end(`
2
2
  <!DOCTYPE html>
3
3
  <html lang="en" data-theme="dark">
4
4
  <head>
@@ -1 +1 @@
1
- {"version":3,"file":"login.mjs","names":[],"sources":["../../../src/auth/login.ts"],"sourcesContent":["import http from 'node:http';\nimport { URL } from 'node:url';\nimport { logConfigDetails } from '@intlayer/chokidar/cli';\nimport {\n ANSIColors,\n colorize,\n colorizePath,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { openBrowser } from '../utils/openBrowser';\n\ntype LoginOptions = {\n cmsUrl?: string;\n configOptions?: GetConfigurationOptions;\n};\n\nexport const login = async (options: LoginOptions) => {\n const configuration = getConfiguration(options.configOptions);\n logConfigDetails(options?.configOptions);\n\n const logger = getAppLogger(configuration);\n\n const cmsUrl = options.cmsUrl ?? configuration.editor.cmsURL;\n\n return new Promise<void>((resolve) => {\n const server = http.createServer((req, res) => {\n const url = new URL(req.url ?? '', `http://${req.headers.host}`);\n\n // Set CORS headers\n res.setHeader('Access-Control-Allow-Origin', '*');\n res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');\n res.setHeader('Access-Control-Allow-Headers', 'Content-Type');\n\n if (req.method === 'OPTIONS') {\n res.writeHead(204);\n res.end();\n return;\n }\n\n if (url.pathname === '/callback') {\n const clientId = url.searchParams.get('clientId');\n const clientSecret = url.searchParams.get('clientSecret');\n\n if (clientId && clientSecret) {\n logger('');\n logger('Log in successful. Client ID and Client Secret received.');\n\n logger('');\n logger([\n '1. Insert the Client ID and Client Secret in your',\n colorizePath('.env'),\n 'file:',\n ]);\n logger(\n colorize('--------------------------------', ANSIColors.GREY_DARK)\n );\n logger(\n [\n colorize('INTLAYER_CLIENT_ID=', ANSIColors.GREY_LIGHT),\n colorize(clientId, ANSIColors.BLUE),\n ].join('')\n );\n logger(\n [\n colorize('INTLAYER_CLIENT_SECRET=', ANSIColors.GREY_LIGHT),\n colorize(clientSecret, ANSIColors.BLUE),\n ].join('')\n );\n logger(\n colorize('--------------------------------', ANSIColors.GREY_DARK)\n );\n logger('');\n logger('2. Insert in your Intlayer configuration file:');\n logger(\n colorize('--------------------------------', ANSIColors.GREY_DARK)\n );\n [\n `${ANSIColors.GREY_LIGHT}{`,\n ` editor: {`,\n ` cmsURL: '${colorizePath(cmsUrl, undefined, ANSIColors.GREY_LIGHT)}',`,\n ` clientId: '${colorize('process.env.INTLAYER_CLIENT_ID', ANSIColors.BLUE, ANSIColors.GREY_LIGHT)}',`,\n ` clientSecret: '${colorize('process.env.INTLAYER_CLIENT_SECRET', ANSIColors.BLUE, ANSIColors.GREY_LIGHT)}',`,\n ` },`,\n `}`,\n ].forEach((line) => {\n logger(line);\n });\n logger(\n colorize('--------------------------------', ANSIColors.GREY_DARK)\n );\n\n res.writeHead(200, { 'Content-Type': 'text/html' });\n res.end(`\n <!DOCTYPE html>\n <html lang=\"en\" data-theme=\"dark\">\n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Intlayer CLI Login</title>\n <style>\n :root {\n --color-background: rgba(23, 23, 23);\n --color-card: rgba(39, 39, 39);\n --color-text: rgba(255, 245, 237);\n --color-neutral: rgba(93, 93, 93);\n --font-sans: \"Inter\", -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;\n }\n \n * {\n box-sizing: border-box;\n }\n \n body {\n font-family: var(--font-sans);\n display: flex;\n align-items: center;\n justify-content: center;\n min-height: 100vh;\n margin: 0;\n padding: 1rem;\n background-color: var(--color-background);\n color: var(--color-text);\n }\n \n .container {\n text-align: center;\n padding: 2rem;\n border-radius: 1rem;\n background-color: var(--color-card);\n box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);\n max-width: 400px;\n width: 100%;\n }\n \n h1 {\n margin: 0 0 1rem 0;\n font-size: 1.5rem;\n font-weight: 700;\n color: var(--color-text);\n }\n \n p {\n color: var(--color-neutral);\n margin: 0 0 1.5rem 0;\n line-height: 1.5;\n }\n </style>\n </head>\n <body>\n <div class=\"container\">\n <h1>Login Successful</h1>\n <p>You have successfully logged in to Intlayer CLI. You can now close this tab and return to your terminal.</p>\n </div>\n <script>\n // Attempt to close the window\n window.close();\n \n // Fallback: if window.close() doesn't work, show a message\n setTimeout(() => {\n window.close();\n }, 1000);\n </script>\n </body>\n </html>\n `);\n\n server.close(() => {\n resolve();\n process.exit(0);\n });\n } else {\n res.writeHead(400, { 'Content-Type': 'text/plain' });\n res.end('Missing parameters');\n }\n } else {\n res.writeHead(404, { 'Content-Type': 'text/plain' });\n res.end('Not found');\n }\n });\n\n server.listen(0, () => {\n const address = server.address();\n const port = typeof address === 'object' && address ? address.port : 0;\n const state = Math.random().toString(36).substring(7);\n\n const websiteUrl =\n cmsUrl ?? process.env.INTLAYER_SITE_URL ?? 'http://localhost:3000';\n const loginUrl = `${websiteUrl}/en/auth/cli-login?port=${port}&state=${state}`;\n\n logger('Opening browser for login...');\n logger(`If browser does not open, visit: ${colorizePath(loginUrl)}`);\n\n openBrowser(loginUrl);\n });\n });\n};\n"],"mappings":"yUAoBA,MAAa,EAAQ,KAAO,IAA0B,CACpD,IAAM,EAAgB,EAAiB,EAAQ,cAAc,CAC7D,EAAiB,GAAS,cAAc,CAExC,IAAM,EAAS,EAAa,EAAc,CAEpC,EAAS,EAAQ,QAAU,EAAc,OAAO,OAEtD,OAAO,IAAI,QAAe,GAAY,CACpC,IAAM,EAAS,EAAK,cAAc,EAAK,IAAQ,CAC7C,IAAM,EAAM,IAAI,EAAI,EAAI,KAAO,GAAI,UAAU,EAAI,QAAQ,OAAO,CAOhE,GAJA,EAAI,UAAU,8BAA+B,IAAI,CACjD,EAAI,UAAU,+BAAgC,eAAe,CAC7D,EAAI,UAAU,+BAAgC,eAAe,CAEzD,EAAI,SAAW,UAAW,CAC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AAqB,OAG/B,EAAI,UAAU,IAAK,CAAE,eAAgB,aAAc,CAAC,CACpD,EAAI,IAAI,YAAY,EAEtB,CAEF,EAAO,OAAO,MAAS,CACrB,IAAM,EAAU,EAAO,SAAS,CAC1B,EAAO,OAAO,GAAY,UAAY,EAAU,EAAQ,KAAO,EAC/D,EAAQ,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,UAAU,EAAE,CAI/C,EAAW,GADf,GAAU,QAAQ,IAAI,mBAAqB,wBACd,0BAA0B,EAAK,SAAS,IAEvE,EAAO,+BAA+B,CACtC,EAAO,oCAAoC,EAAa,EAAS,GAAG,CAEpE,EAAY,EAAS,EACrB,EACF"}
1
+ {"version":3,"file":"login.mjs","names":[],"sources":["../../../src/auth/login.ts"],"sourcesContent":["import http from 'node:http';\nimport { URL } from 'node:url';\nimport { logConfigDetails } from '@intlayer/chokidar/cli';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, colorizePath, getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { openBrowser } from '../utils/openBrowser';\n\ntype LoginOptions = {\n cmsUrl?: string;\n configOptions?: GetConfigurationOptions;\n};\n\nexport const login = async (options: LoginOptions) => {\n const configuration = getConfiguration(options.configOptions);\n logConfigDetails(options?.configOptions);\n\n const logger = getAppLogger(configuration);\n\n const cmsUrl = options.cmsUrl ?? configuration.editor.cmsURL;\n\n return new Promise<void>((resolve) => {\n const server = http.createServer((req, res) => {\n const url = new URL(req.url ?? '', `http://${req.headers.host}`);\n\n // Set CORS headers\n res.setHeader('Access-Control-Allow-Origin', '*');\n res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');\n res.setHeader('Access-Control-Allow-Headers', 'Content-Type');\n\n if (req.method === 'OPTIONS') {\n res.writeHead(204);\n res.end();\n return;\n }\n\n if (url.pathname === '/callback') {\n const clientId = url.searchParams.get('clientId');\n const clientSecret = url.searchParams.get('clientSecret');\n\n if (clientId && clientSecret) {\n logger('');\n logger('Log in successful. Client ID and Client Secret received.');\n\n logger('');\n logger([\n '1. Insert the Client ID and Client Secret in your',\n colorizePath('.env'),\n 'file:',\n ]);\n logger(\n colorize('--------------------------------', ANSIColors.GREY_DARK)\n );\n logger(\n [\n colorize('INTLAYER_CLIENT_ID=', ANSIColors.GREY_LIGHT),\n colorize(clientId, ANSIColors.BLUE),\n ].join('')\n );\n logger(\n [\n colorize('INTLAYER_CLIENT_SECRET=', ANSIColors.GREY_LIGHT),\n colorize(clientSecret, ANSIColors.BLUE),\n ].join('')\n );\n logger(\n colorize('--------------------------------', ANSIColors.GREY_DARK)\n );\n logger('');\n logger('2. Insert in your Intlayer configuration file:');\n logger(\n colorize('--------------------------------', ANSIColors.GREY_DARK)\n );\n [\n `${ANSIColors.GREY_LIGHT}{`,\n ` editor: {`,\n ` cmsURL: '${colorizePath(cmsUrl, undefined, ANSIColors.GREY_LIGHT)}',`,\n ` clientId: '${colorize('process.env.INTLAYER_CLIENT_ID', ANSIColors.BLUE, ANSIColors.GREY_LIGHT)}',`,\n ` clientSecret: '${colorize('process.env.INTLAYER_CLIENT_SECRET', ANSIColors.BLUE, ANSIColors.GREY_LIGHT)}',`,\n ` },`,\n `}`,\n ].forEach((line) => {\n logger(line);\n });\n logger(\n colorize('--------------------------------', ANSIColors.GREY_DARK)\n );\n\n res.writeHead(200, { 'Content-Type': 'text/html' });\n res.end(`\n <!DOCTYPE html>\n <html lang=\"en\" data-theme=\"dark\">\n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Intlayer CLI Login</title>\n <style>\n :root {\n --color-background: rgba(23, 23, 23);\n --color-card: rgba(39, 39, 39);\n --color-text: rgba(255, 245, 237);\n --color-neutral: rgba(93, 93, 93);\n --font-sans: \"Inter\", -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;\n }\n \n * {\n box-sizing: border-box;\n }\n \n body {\n font-family: var(--font-sans);\n display: flex;\n align-items: center;\n justify-content: center;\n min-height: 100vh;\n margin: 0;\n padding: 1rem;\n background-color: var(--color-background);\n color: var(--color-text);\n }\n \n .container {\n text-align: center;\n padding: 2rem;\n border-radius: 1rem;\n background-color: var(--color-card);\n box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);\n max-width: 400px;\n width: 100%;\n }\n \n h1 {\n margin: 0 0 1rem 0;\n font-size: 1.5rem;\n font-weight: 700;\n color: var(--color-text);\n }\n \n p {\n color: var(--color-neutral);\n margin: 0 0 1.5rem 0;\n line-height: 1.5;\n }\n </style>\n </head>\n <body>\n <div class=\"container\">\n <h1>Login Successful</h1>\n <p>You have successfully logged in to Intlayer CLI. You can now close this tab and return to your terminal.</p>\n </div>\n <script>\n // Attempt to close the window\n window.close();\n \n // Fallback: if window.close() doesn't work, show a message\n setTimeout(() => {\n window.close();\n }, 1000);\n </script>\n </body>\n </html>\n `);\n\n server.close(() => {\n resolve();\n process.exit(0);\n });\n } else {\n res.writeHead(400, { 'Content-Type': 'text/plain' });\n res.end('Missing parameters');\n }\n } else {\n res.writeHead(404, { 'Content-Type': 'text/plain' });\n res.end('Not found');\n }\n });\n\n server.listen(0, () => {\n const address = server.address();\n const port = typeof address === 'object' && address ? address.port : 0;\n const state = Math.random().toString(36).substring(7);\n\n const websiteUrl =\n cmsUrl ?? process.env.INTLAYER_SITE_URL ?? 'http://localhost:3000';\n const loginUrl = `${websiteUrl}/en/auth/cli-login?port=${port}&state=${state}`;\n\n logger('Opening browser for login...');\n logger(`If browser does not open, visit: ${colorizePath(loginUrl)}`);\n\n openBrowser(loginUrl);\n });\n });\n};\n"],"mappings":"mWAgBA,MAAa,EAAQ,KAAO,IAA0B,CACpD,IAAM,EAAgB,EAAiB,EAAQ,cAAc,CAC7D,EAAiB,GAAS,cAAc,CAExC,IAAM,EAAS,EAAa,EAAc,CAEpC,EAAS,EAAQ,QAAU,EAAc,OAAO,OAEtD,OAAO,IAAI,Q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AAE,eAAgB,YAAa,CAAC,CACnD,EAAI,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAwEN,CAEF,EAAO,UAAY,CACjB,GAAS,CACT,QAAQ,KAAK,EAAE,EACf,GAEF,EAAI,UAAU,IAAK,CAAE,eAAgB,aAAc,CAAC,CACpD,EAAI,IAAI,qBAAqB,OAG/B,EAAI,UAAU,IAAK,CAAE,eAAgB,aAAc,CAAC,CACpD,EAAI,IAAI,YAAY,EAEtB,CAEF,EAAO,OAAO,MAAS,CACrB,IAAM,EAAU,EAAO,SAAS,CAC1B,EAAO,OAAO,GAAY,UAAY,EAAU,EAAQ,KAAO,EAC/D,EAAQ,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,UAAU,EAAE,CAI/C,EAAW,GADf,GAAU,QAAQ,IAAI,mBAAqB,wBACd,0BAA0B,EAAK,SAAS,IAEvE,EAAO,+BAA+B,CACtC,EAAO,oCAAoC,EAAa,EAAS,GAAG,CAEpE,EAAY,EAAS,EACrB,EACF"}
@@ -1,2 +1,2 @@
1
- import{existsSync as e}from"node:fs";import{relative as t,resolve as n}from"node:path";import{detectPackageName as r,extractContent as i}from"@intlayer/babel";import{prepareIntlayer as a}from"@intlayer/chokidar/build";import{logConfigDetails as o}from"@intlayer/chokidar/cli";import{buildComponentFilesList as s}from"@intlayer/chokidar/utils";import{ANSIColors as c,colorize as l,colorizePath as u,getAppLogger as d,x as f}from"@intlayer/config/logger";import{getConfiguration as p}from"@intlayer/config/node";import{getUnmergedDictionaries as m}from"@intlayer/unmerged-dictionaries-entry";import h from"enquirer";const g=async g=>{let _=p(g.configOptions);o(g?.configOptions);let v=d(_),{baseDir:y}=_.system,{output:b}=_.compiler,x=e=>u(t(y,e));if(!b){v(`${f} No output configuration found. Add a ${l(`compiler.output`,c.BLUE)} in your configuration.`,{level:`error`});return}let S=r(y),C=g.files??[];if(C.length===0){let e=s(_).map(e=>({value:e,label:t(y,e)}));if(e.length===0){v(`No extractable files found in the project.`);return}let n=`__select_all__`,r;try{let t=Math.max((process.stdout.columns||80)-15,20),i=e=>e.length>t?`...${e.slice(-(t-3))}`:e,{files:a}=await h.prompt({type:`autocomplete`,name:`files`,message:`Select files to extract (Type to search):`,multiple:!0,limit:40,choices:[{name:n,message:`────── Select all ──────`},...e.map(e=>({name:e.value,message:i(e.label)}))],async toggle(e,t){if(!(!e||e.disabled))return e.enabled=t??!e.enabled,e.name===n&&this.choices.filter(e=>e.name!==n).forEach(t=>{t.enabled=e.enabled}),this.render()},format(){return this.state?.submitted&&this.options?.multiple?`${this.selected.filter(e=>e.name!==n).length} file(s) selected`:this.input??``}});r=a.filter(e=>e!==n)}catch{r=Symbol(`cancel`)}typeof r==`symbol`&&process.exit(0),C=r}if(C.length===0){v(`No files selected for extraction.`);return}let w=C.map(e=>n(y,e)).filter(t=>e(t)?!0:(v(`File not found: ${x(t)}`),!1));if(w.length===0)return;let T=m(_);await Promise.all(w.map(async e=>{try{await i(e,S,{unmergedDictionaries:T,configuration:_,codeOnly:g.codeOnly,declarationOnly:g.declarationOnly})}catch(t){v(`Failed to transform ${e}: ${t.message}`)}})),await a(_)};export{g as extract};
1
+ import{existsSync as e}from"node:fs";import{relative as t,resolve as n}from"node:path";import{detectPackageName as r,extractContent as i}from"@intlayer/babel";import{prepareIntlayer as a}from"@intlayer/chokidar/build";import{logConfigDetails as o}from"@intlayer/chokidar/cli";import{buildComponentFilesList as s,formatPath as c}from"@intlayer/chokidar/utils";import*as l from"@intlayer/config/colors";import{colorize as u,getAppLogger as d,x as f}from"@intlayer/config/logger";import{getConfiguration as p}from"@intlayer/config/node";import{getUnmergedDictionaries as m}from"@intlayer/unmerged-dictionaries-entry";import h from"enquirer";const g=async g=>{let _=p(g.configOptions);o(g?.configOptions);let v=d(_),{baseDir:y}=_.system,{output:b}=_.compiler;if(!b){v(`${f} No output configuration found. Add a ${u(`compiler.output`,l.BLUE)} in your configuration.`,{level:`error`});return}let x=r(y),S=g.files??[];if(S.length===0){let e=s(_).map(e=>({value:e,label:t(y,e)}));if(e.length===0){v(`No extractable files found in the project.`);return}let n=`__select_all__`,r;try{let t=Math.max((process.stdout.columns||80)-15,20),i=e=>e.length>t?`...${e.slice(-(t-3))}`:e,{files:a}=await h.prompt({type:`autocomplete`,name:`files`,message:`Select files to extract (Type to search):`,multiple:!0,limit:40,choices:[{name:n,message:`────── Select all ──────`},...e.map(e=>({name:e.value,message:i(e.label)}))],async toggle(e,t){if(!(!e||e.disabled))return e.enabled=t??!e.enabled,e.name===n&&this.choices.filter(e=>e.name!==n).forEach(t=>{t.enabled=e.enabled}),this.render()},format(){return this.state?.submitted&&this.options?.multiple?`${this.selected.filter(e=>e.name!==n).length} file(s) selected`:this.input??``}});r=a.filter(e=>e!==n)}catch{r=Symbol(`cancel`)}typeof r==`symbol`&&process.exit(0),S=r}if(S.length===0){v(`No files selected for extraction.`);return}let C=S.map(e=>n(y,e)).filter(t=>e(t)?!0:(v(`File not found: ${c(t)}`),!1));if(C.length===0)return;let w=m(_);await Promise.all(C.map(async e=>{try{await i(e,x,{unmergedDictionaries:w,configuration:_,codeOnly:g.codeOnly,declarationOnly:g.declarationOnly})}catch(t){v(`Failed to transform ${e}: ${t.message}`)}})),await a(_)};export{g as extract};
2
2
  //# sourceMappingURL=extract.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract.mjs","names":[],"sources":["../../src/extract.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { relative, resolve } from 'node:path';\nimport {\n detectPackageName,\n extractContent,\n type PackageName,\n} from '@intlayer/babel';\nimport { prepareIntlayer } from '@intlayer/chokidar/build';\nimport { logConfigDetails } from '@intlayer/chokidar/cli';\nimport { buildComponentFilesList } from '@intlayer/chokidar/utils';\nimport {\n ANSIColors,\n colorize,\n colorizePath,\n getAppLogger,\n x,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport type { FilePathPattern } from '@intlayer/types/filePathPattern';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport enquirer from 'enquirer';\n\ntype ExtractOptions = {\n files?: string[];\n output?: FilePathPattern;\n configOptions?: GetConfigurationOptions;\n codeOnly?: boolean;\n declarationOnly?: boolean;\n};\n\nexport const extract = async (options: ExtractOptions) => {\n const configuration = getConfiguration(options.configOptions);\n\n logConfigDetails(options?.configOptions);\n\n const appLogger = getAppLogger(configuration);\n\n const { baseDir } = configuration.system;\n const { output } = configuration.compiler;\n\n const formatPath = (path: string) => {\n const relativePath = relative(baseDir, path);\n return colorizePath(relativePath);\n };\n\n if (!output) {\n appLogger(\n `${x} No output configuration found. Add a ${colorize('compiler.output', ANSIColors.BLUE)} in your configuration.`,\n {\n level: 'error',\n }\n );\n return;\n }\n\n // Detect package\n const packageName: PackageName = detectPackageName(baseDir);\n\n let filesToExtract = options.files ?? [];\n\n if (filesToExtract.length === 0) {\n // Await all promises simultaneously\n const fileList = buildComponentFilesList(configuration);\n\n // Flatten the nested arrays and remove duplicates\n // Relative paths for selection\n const choices = fileList.map((file) => {\n const relPath = relative(baseDir, file);\n return {\n value: file,\n label: relPath,\n };\n });\n\n if (choices.length === 0) {\n appLogger('No extractable files found in the project.');\n return;\n }\n\n const SELECT_ALL = '__select_all__';\n\n type PromptChoice = {\n name: string;\n enabled: boolean;\n disabled?: boolean | string;\n };\n\n type PromptContext = {\n choices: PromptChoice[];\n render(): void | Promise<void>;\n state: { submitted: boolean };\n selected: PromptChoice[];\n input: string;\n options: { multiple?: boolean };\n };\n\n let selectedFiles: string[] | symbol;\n try {\n const maxLen = Math.max((process.stdout.columns || 80) - 15, 20);\n const truncatePath = (path: string) =>\n path.length > maxLen ? `...${path.slice(-(maxLen - 3))}` : path;\n\n const { files: enquirerSelectedFiles } = await enquirer.prompt<{\n files: string[];\n }>({\n type: 'autocomplete',\n name: 'files',\n message: 'Select files to extract (Type to search):',\n multiple: true,\n // @ts-ignore limit exist but is not typed\n limit: 40,\n choices: [\n { name: SELECT_ALL, message: '────── Select all ──────' },\n ...choices.map((choice) => ({\n name: choice.value,\n message: truncatePath(choice.label),\n })),\n ],\n async toggle(\n this: PromptContext,\n choice: PromptChoice,\n enabled?: boolean\n ) {\n if (!choice || choice.disabled) return;\n choice.enabled = enabled == null ? !choice.enabled : enabled;\n\n if (choice.name === SELECT_ALL) {\n this.choices\n .filter((choiceEl) => choiceEl.name !== SELECT_ALL)\n .forEach((choiceEl) => {\n choiceEl.enabled = choice.enabled;\n });\n }\n\n return this.render();\n },\n format(this: PromptContext) {\n if (this.state?.submitted && this.options?.multiple) {\n return `${this.selected.filter((s) => s.name !== SELECT_ALL).length} file(s) selected`;\n }\n return this.input ?? '';\n },\n });\n\n selectedFiles = enquirerSelectedFiles.filter((f) => f !== SELECT_ALL);\n } catch {\n selectedFiles = Symbol('cancel');\n }\n\n if (typeof selectedFiles === 'symbol') {\n // User cancelled\n process.exit(0);\n }\n\n filesToExtract = selectedFiles as string[];\n }\n\n if (filesToExtract.length === 0) {\n appLogger('No files selected for extraction.');\n return;\n }\n\n const absoluteFiles = filesToExtract\n .map((file) => resolve(baseDir, file))\n .filter((file) => {\n if (!existsSync(file)) {\n appLogger(`File not found: ${formatPath(file)}`);\n return false;\n }\n return true;\n });\n\n if (absoluteFiles.length === 0) {\n return;\n }\n\n const unmergedDictionaries = getUnmergedDictionaries(configuration);\n\n await Promise.all(\n absoluteFiles.map(async (filePath) => {\n try {\n await extractContent(filePath, packageName, {\n unmergedDictionaries,\n configuration,\n codeOnly: options.codeOnly,\n declarationOnly: options.declarationOnly,\n });\n } catch (error) {\n appLogger(\n `Failed to transform ${filePath}: ${(error as Error).message}`\n );\n }\n })\n );\n\n await prepareIntlayer(configuration); // Prepare Intlayer to apply the changes\n};\n"],"mappings":"smBAiCA,MAAa,EAAU,KAAO,IAA4B,CACxD,IAAM,EAAgB,EAAiB,EAAQ,cAAc,CAE7D,EAAiB,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K,SAAS,SAClC,GAAG,KAAK,SAAS,OAAQ,GAAM,EAAE,OAAS,EAAW,CAAC,OAAO,mBAE/D,KAAK,OAAS,IAExB,CAAC,CAEF,EAAgB,EAAsB,OAAQ,GAAM,IAAM,EAAW,MAC/D,CACN,EAAgB,OAAO,SAAS,CAG9B,OAAO,GAAkB,UAE3B,QAAQ,KAAK,EAAE,CAGjB,EAAiB,EAGnB,GAAI,EAAe,SAAW,EAAG,CAC/B,EAAU,oCAAoC,CAC9C,OAGF,IAAM,EAAgB,EACnB,IAAK,GAAS,EAAQ,EAAS,EAAK,CAAC,CACrC,OAAQ,GACF,EAAW,EAAK,CAId,IAHL,EAAU,mBAAmB,EAAW,EAAK,GAAG,CACzC,IAGT,CAEJ,GAAI,EAAc,SAAW,EAC3B,OAGF,IAAM,EAAuB,EAAwB,EAAc,CAEnE,MAAM,QAAQ,IACZ,EAAc,IAAI,KAAO,IAAa,CACpC,GAAI,CACF,MAAM,EAAe,EAAU,EAAa,CAC1C,uBACA,gBACA,SAAU,EAAQ,SAClB,gBAAiB,EAAQ,gBAC1B,CAAC,OACK,EAAO,CACd,EACE,uBAAuB,EAAS,IAAK,EAAgB,UACtD,GAEH,CACH,CAED,MAAM,EAAgB,EAAc"}
1
+ {"version":3,"file":"extract.mjs","names":[],"sources":["../../src/extract.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { relative, resolve } from 'node:path';\nimport {\n detectPackageName,\n extractContent,\n type PackageName,\n} from '@intlayer/babel';\nimport { prepareIntlayer } from '@intlayer/chokidar/build';\nimport { logConfigDetails } from '@intlayer/chokidar/cli';\nimport { buildComponentFilesList, formatPath } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger, x } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport type { FilePathPattern } from '@intlayer/types/filePathPattern';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport enquirer from 'enquirer';\n\ntype ExtractOptions = {\n files?: string[];\n output?: FilePathPattern;\n configOptions?: GetConfigurationOptions;\n codeOnly?: boolean;\n declarationOnly?: boolean;\n};\n\nexport const extract = async (options: ExtractOptions) => {\n const configuration = getConfiguration(options.configOptions);\n\n logConfigDetails(options?.configOptions);\n\n const appLogger = getAppLogger(configuration);\n\n const { baseDir } = configuration.system;\n const { output } = configuration.compiler;\n\n if (!output) {\n appLogger(\n `${x} No output configuration found. Add a ${colorize('compiler.output', ANSIColors.BLUE)} in your configuration.`,\n {\n level: 'error',\n }\n );\n return;\n }\n\n // Detect package\n const packageName: PackageName = detectPackageName(baseDir);\n\n let filesToExtract = options.files ?? [];\n\n if (filesToExtract.length === 0) {\n // Await all promises simultaneously\n const fileList = buildComponentFilesList(configuration);\n\n // Flatten the nested arrays and remove duplicates\n // Relative paths for selection\n const choices = fileList.map((file) => {\n const relPath = relative(baseDir, file);\n\n return {\n value: file,\n label: relPath,\n };\n });\n\n if (choices.length === 0) {\n appLogger('No extractable files found in the project.');\n return;\n }\n\n const SELECT_ALL = '__select_all__';\n\n type PromptChoice = {\n name: string;\n enabled: boolean;\n disabled?: boolean | string;\n };\n\n type PromptContext = {\n choices: PromptChoice[];\n render(): void | Promise<void>;\n state: { submitted: boolean };\n selected: PromptChoice[];\n input: string;\n options: { multiple?: boolean };\n };\n\n let selectedFiles: string[] | symbol;\n try {\n const maxLen = Math.max((process.stdout.columns || 80) - 15, 20);\n const truncatePath = (path: string) =>\n path.length > maxLen ? `...${path.slice(-(maxLen - 3))}` : path;\n\n const { files: enquirerSelectedFiles } = await enquirer.prompt<{\n files: string[];\n }>({\n type: 'autocomplete',\n name: 'files',\n message: 'Select files to extract (Type to search):',\n multiple: true,\n // @ts-ignore limit exist but is not typed\n limit: 40,\n choices: [\n { name: SELECT_ALL, message: '────── Select all ──────' },\n ...choices.map((choice) => ({\n name: choice.value,\n message: truncatePath(choice.label),\n })),\n ],\n async toggle(\n this: PromptContext,\n choice: PromptChoice,\n enabled?: boolean\n ) {\n if (!choice || choice.disabled) return;\n choice.enabled = enabled == null ? !choice.enabled : enabled;\n\n if (choice.name === SELECT_ALL) {\n this.choices\n .filter((choiceEl) => choiceEl.name !== SELECT_ALL)\n .forEach((choiceEl) => {\n choiceEl.enabled = choice.enabled;\n });\n }\n\n return this.render();\n },\n format(this: PromptContext) {\n if (this.state?.submitted && this.options?.multiple) {\n return `${this.selected.filter((s) => s.name !== SELECT_ALL).length} file(s) selected`;\n }\n return this.input ?? '';\n },\n });\n\n selectedFiles = enquirerSelectedFiles.filter((f) => f !== SELECT_ALL);\n } catch {\n selectedFiles = Symbol('cancel');\n }\n\n if (typeof selectedFiles === 'symbol') {\n // User cancelled\n process.exit(0);\n }\n\n filesToExtract = selectedFiles as string[];\n }\n\n if (filesToExtract.length === 0) {\n appLogger('No files selected for extraction.');\n return;\n }\n\n const absoluteFiles = filesToExtract\n .map((file) => resolve(baseDir, file))\n .filter((file) => {\n if (!existsSync(file)) {\n appLogger(`File not found: ${formatPath(file)}`);\n return false;\n }\n return true;\n });\n\n if (absoluteFiles.length === 0) {\n return;\n }\n\n const unmergedDictionaries = getUnmergedDictionaries(configuration);\n\n await Promise.all(\n absoluteFiles.map(async (filePath) => {\n try {\n await extractContent(filePath, packageName, {\n unmergedDictionaries,\n configuration,\n codeOnly: options.codeOnly,\n declarationOnly: options.declarationOnly,\n });\n } catch (error) {\n appLogger(\n `Failed to transform ${filePath}: ${(error as Error).message}`\n );\n }\n })\n );\n\n await prepareIntlayer(configuration); // Prepare Intlayer to apply the changes\n};\n"],"mappings":"8nBA4BA,MAAa,EAAU,KAAO,IAA4B,CACxD,IAAM,EAAgB,EAAiB,EAAQ,cAAc,CAE7D,EAAiB,GAAS,cAAc,CAExC,IAAM,EAAY,EAAa,EAAc,CAEvC,CAAE,WAAY,EAAc,OAC5B,CAAE,UAAW,EAAc,SAEjC,GAAI,CAAC,EAAQ,CACX,EACE,GAAG,EAAE,w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AG9B,OAAO,GAAkB,UAE3B,QAAQ,KAAK,EAAE,CAGjB,EAAiB,EAGnB,GAAI,EAAe,SAAW,EAAG,CAC/B,EAAU,oCAAoC,CAC9C,OAGF,IAAM,EAAgB,EACnB,IAAK,GAAS,EAAQ,EAAS,EAAK,CAAC,CACrC,OAAQ,GACF,EAAW,EAAK,CAId,IAHL,EAAU,mBAAmB,EAAW,EAAK,GAAG,CACzC,IAGT,CAEJ,GAAI,EAAc,SAAW,EAC3B,OAGF,IAAM,EAAuB,EAAwB,EAAc,CAEnE,MAAM,QAAQ,IACZ,EAAc,IAAI,KAAO,IAAa,CACpC,GAAI,CACF,MAAM,EAAe,EAAU,EAAa,CAC1C,uBACA,gBACA,SAAU,EAAQ,SAClB,gBAAiB,EAAQ,gBAC1B,CAAC,OACK,EAAO,CACd,EACE,uBAAuB,EAAS,IAAK,EAAgB,UACtD,GAEH,CACH,CAED,MAAM,EAAgB,EAAc"}
@@ -1,2 +1,2 @@
1
- import{ensureArray as e,getTargetUnmergedDictionaries as t}from"../getTargetDictionary.mjs";import{setupAI as n}from"../utils/setupAI.mjs";import{listTranslationsTasks as r}from"./listTranslationsTasks.mjs";import{translateDictionary as i}from"./translateDictionary.mjs";import{writeFill as a}from"./writeFill.mjs";import{basename as o,relative as s}from"node:path";import{prepareIntlayer as c,writeContentDeclaration as l}from"@intlayer/chokidar/build";import{logConfigDetails as u}from"@intlayer/chokidar/cli";import{formatPath as d,getGlobalLimiter as f,getTaskLimiter as p}from"@intlayer/chokidar/utils";import{ANSIColors as m,colorize as h,colorizeKey as g,colorizePath as _,getAppLogger as v}from"@intlayer/config/logger";import{getConfiguration as y}from"@intlayer/config/node";const b=async b=>{let x=y(b?.configOptions);u(b?.configOptions);let S=v(x);b?.build===!0?await c(x,{forceRun:!0}):b?.build===void 0&&await c(x);let{defaultLocale:C,locales:w}=x.internationalization,T=b?.mode??`complete`,E=b?.sourceLocale??C,D=b?.outputLocales?e(b.outputLocales):w,O=await n(x,b?.aiOptions);if(!O?.hasAIAccess)return;let{aiClient:k,aiConfig:A}=O,j=await t(b),M=new Set;j.forEach(e=>{M.add(e.key)});let N=Array.from(M);if(S([`Affected dictionary keys for processing:`,N.length>0?N.map(e=>g(e)).join(`, `):h(`No keys found`,m.YELLOW)]),N.length===0)return;let P=r(j.map(e=>e.localId),D,T,E,x),F=b?.nbConcurrentTranslations??7,I=f(F),L=p(Math.max(1,Math.min(b?.nbConcurrentTasks??F,P.length))),R=P.map(e=>L(async()=>{let t=s(x?.content?.baseDir??process.cwd(),e?.dictionaryFilePath??``);S(`${e.dictionaryPreset} Processing ${_(o(t))}`,{level:`info`});let n=await i(e,x,{mode:T,aiOptions:b?.aiOptions,fillMetadata:!b?.skipMetadata,onHandle:I,aiClient:k,aiConfig:A});if(!n?.dictionaryOutput)return;let{dictionaryOutput:r,sourceLocale:c}=n,u=typeof r.fill==`string`||typeof r.fill==`object`,f=typeof r.locale==`string`,p=u?r.fill:f?x.dictionary?.fill??!0:!1;typeof p==`string`||typeof p==`object`?await a({...r,fill:p},D,[c],x):(await l(r,x),r.filePath&&S(`${e.dictionaryPreset} Content declaration written to ${d(o(r.filePath))}`,{level:`info`}))}));await Promise.all(R),await I.onIdle()};export{b as fill};
1
+ import{ensureArray as e,getTargetUnmergedDictionaries as t}from"../getTargetDictionary.mjs";import{setupAI as n}from"../utils/setupAI.mjs";import{listTranslationsTasks as r}from"./listTranslationsTasks.mjs";import{translateDictionary as i}from"./translateDictionary.mjs";import{writeFill as a}from"./writeFill.mjs";import{basename as o,relative as s}from"node:path";import{prepareIntlayer as c,writeContentDeclaration as l}from"@intlayer/chokidar/build";import{logConfigDetails as u}from"@intlayer/chokidar/cli";import{formatPath as d,getGlobalLimiter as f,getTaskLimiter as p}from"@intlayer/chokidar/utils";import*as m from"@intlayer/config/colors";import{colorize as h,colorizeKey as g,colorizePath as _,getAppLogger as v}from"@intlayer/config/logger";import{getConfiguration as y}from"@intlayer/config/node";const b=async b=>{let x=y(b?.configOptions);u(b?.configOptions);let S=v(x);b?.build===!0?await c(x,{forceRun:!0}):b?.build===void 0&&await c(x);let{defaultLocale:C,locales:w}=x.internationalization,T=b?.mode??`complete`,E=b?.sourceLocale??C,D=b?.outputLocales?e(b.outputLocales):w,O=await n(x,b?.aiOptions);if(!O?.hasAIAccess)return;let{aiClient:k,aiConfig:A}=O,j=await t(b),M=new Set;j.forEach(e=>{M.add(e.key)});let N=Array.from(M);if(S([`Affected dictionary keys for processing:`,N.length>0?N.map(e=>g(e)).join(`, `):h(`No keys found`,m.YELLOW)]),N.length===0)return;let P=r(j.map(e=>e.localId),D,T,E,x),F=b?.nbConcurrentTranslations??7,I=f(F),L=p(Math.max(1,Math.min(b?.nbConcurrentTasks??F,P.length))),R=P.map(e=>L(async()=>{let t=s(x?.content?.baseDir??process.cwd(),e?.dictionaryFilePath??``);S(`${e.dictionaryPreset} Processing ${_(o(t))}`,{level:`info`});let n=await i(e,x,{mode:T,aiOptions:b?.aiOptions,fillMetadata:!b?.skipMetadata,onHandle:I,aiClient:k,aiConfig:A});if(!n?.dictionaryOutput)return;let{dictionaryOutput:r,sourceLocale:c}=n,u=typeof r.fill==`string`||typeof r.fill==`object`,f=typeof r.locale==`string`,p=u?r.fill:f?x.dictionary?.fill??!0:!1;typeof p==`string`||typeof p==`object`?await a({...r,fill:p},D,[c],x):(await l(r,x),r.filePath&&S(`${e.dictionaryPreset} Content declaration written to ${d(o(r.filePath))}`,{level:`info`}))}));await Promise.all(R),await I.onIdle()};export{b as fill};
2
2
  //# sourceMappingURL=fill.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"fill.mjs","names":[],"sources":["../../../src/fill/fill.ts"],"sourcesContent":["import { basename, relative } from 'node:path';\nimport type { AIOptions } from '@intlayer/api';\nimport {\n prepareIntlayer,\n writeContentDeclaration,\n} from '@intlayer/chokidar/build';\nimport {\n type ListGitFilesOptions,\n logConfigDetails,\n} from '@intlayer/chokidar/cli';\nimport {\n formatPath,\n getGlobalLimiter,\n getTaskLimiter,\n} from '@intlayer/chokidar/utils';\nimport {\n ANSIColors,\n colorize,\n colorizeKey,\n colorizePath,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport {\n ensureArray,\n type GetTargetDictionaryOptions,\n getTargetUnmergedDictionaries,\n} from '../getTargetDictionary';\nimport { setupAI } from '../utils/setupAI';\nimport {\n listTranslationsTasks,\n type TranslationTask,\n} from './listTranslationsTasks';\nimport { translateDictionary } from './translateDictionary';\nimport { writeFill } from './writeFill';\n\nconst NB_CONCURRENT_TRANSLATIONS = 7;\n\n// Arguments for the fill function\nexport type FillOptions = {\n sourceLocale?: Locale;\n outputLocales?: Locale | Locale[];\n mode?: 'complete' | 'review';\n gitOptions?: ListGitFilesOptions;\n aiOptions?: AIOptions; // Added aiOptions to be passed to translateJSON\n verbose?: boolean;\n nbConcurrentTranslations?: number;\n nbConcurrentTasks?: number; // NEW: number of tasks that may run at once\n build?: boolean;\n skipMetadata?: boolean;\n} & GetTargetDictionaryOptions;\n\n/**\n * Fill translations based on the provided options.\n */\nexport const fill = async (options?: FillOptions): Promise<void> => {\n const configuration = getConfiguration(options?.configOptions);\n logConfigDetails(options?.configOptions);\n\n const appLogger = getAppLogger(configuration);\n\n if (options?.build === true) {\n await prepareIntlayer(configuration, { forceRun: true });\n } else if (typeof options?.build === 'undefined') {\n await prepareIntlayer(configuration);\n }\n\n const { defaultLocale, locales } = configuration.internationalization;\n const mode = options?.mode ?? 'complete';\n const baseLocale = options?.sourceLocale ?? defaultLocale;\n\n const outputLocales = options?.outputLocales\n ? ensureArray(options.outputLocales)\n : locales;\n\n const aiResult = await setupAI(configuration, options?.aiOptions);\n\n if (!aiResult?.hasAIAccess) return;\n\n const { aiClient, aiConfig } = aiResult;\n\n const targetUnmergedDictionaries =\n await getTargetUnmergedDictionaries(options);\n\n const affectedDictionaryKeys = new Set<string>();\n targetUnmergedDictionaries.forEach((dict) => {\n affectedDictionaryKeys.add(dict.key);\n });\n\n const keysToProcess = Array.from(affectedDictionaryKeys);\n\n appLogger([\n 'Affected dictionary keys for processing:',\n keysToProcess.length > 0\n ? keysToProcess.map((key) => colorizeKey(key)).join(', ')\n : colorize('No keys found', ANSIColors.YELLOW),\n ]);\n\n if (keysToProcess.length === 0) return;\n\n /**\n * List the translations tasks\n *\n * Create a list of per-locale dictionaries to translate\n *\n * In 'complete' mode, filter only the missing locales to translate\n */\n const translationTasks: TranslationTask[] = listTranslationsTasks(\n targetUnmergedDictionaries.map((dictionary) => dictionary.localId!),\n outputLocales,\n mode,\n baseLocale,\n configuration\n );\n\n // AI calls in flight at once (translateJSON + metadata audit)\n const nbConcurrentTranslations =\n options?.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS;\n const globalLimiter = getGlobalLimiter(nbConcurrentTranslations);\n\n // NEW: number of *tasks* that may run at once (start/prepare/log/write)\n const nbConcurrentTasks = Math.max(\n 1,\n Math.min(\n options?.nbConcurrentTasks ?? nbConcurrentTranslations,\n translationTasks.length\n )\n );\n\n const taskLimiter = getTaskLimiter(nbConcurrentTasks);\n\n const runners = translationTasks.map((task) =>\n taskLimiter(async () => {\n const relativePath = relative(\n configuration?.content?.baseDir ?? process.cwd(),\n task?.dictionaryFilePath ?? ''\n );\n\n // log AFTER acquiring a task slot\n appLogger(\n `${task.dictionaryPreset} Processing ${colorizePath(basename(relativePath))}`,\n { level: 'info' }\n );\n\n const translationTaskResult = await translateDictionary(\n task,\n configuration,\n {\n mode,\n aiOptions: options?.aiOptions,\n fillMetadata: !options?.skipMetadata,\n onHandle: globalLimiter, // <= AI calls go through here\n aiClient,\n aiConfig,\n }\n );\n\n if (!translationTaskResult?.dictionaryOutput) return;\n\n const { dictionaryOutput, sourceLocale } = translationTaskResult;\n\n // Determine if we should write to separate files\n // - If dictionary has explicit fill setting (string or object), use it\n // - If dictionary is per-locale AND has no explicit fill=false, use global fill config\n // - If dictionary is multilingual (no locale property), always write to same file\n const hasDictionaryLevelFill =\n typeof dictionaryOutput.fill === 'string' ||\n typeof dictionaryOutput.fill === 'object';\n\n const isPerLocale = typeof dictionaryOutput.locale === 'string';\n\n const effectiveFill = hasDictionaryLevelFill\n ? dictionaryOutput.fill\n : isPerLocale\n ? (configuration.dictionary?.fill ?? true)\n : false; // Multilingual dictionaries don't use fill by default\n\n const isFillOtherFile =\n typeof effectiveFill === 'string' || typeof effectiveFill === 'object';\n\n if (isFillOtherFile) {\n await writeFill(\n {\n ...dictionaryOutput,\n // Ensure fill is set on the dictionary for writeFill to use\n fill: effectiveFill,\n },\n outputLocales,\n [sourceLocale],\n configuration\n );\n } else {\n await writeContentDeclaration(dictionaryOutput, configuration);\n\n if (dictionaryOutput.filePath) {\n appLogger(\n `${task.dictionaryPreset} Content declaration written to ${formatPath(basename(dictionaryOutput.filePath))}`,\n { level: 'info' }\n );\n }\n }\n })\n );\n\n await Promise.all(runners);\n await (globalLimiter as any).onIdle();\n};\n"],"mappings":"ixBAqCA,MAmBa,EAAO,KAAO,IAAyC,CAClE,IAAM,EAAgB,EAAiB,GAAS,cAAc,CAC9D,EAAiB,GAAS,cAAc,CAExC,IAAM,EAAY,EAAa,EAAc,CAEzC,GAAS,QAAU,GACrB,MAAM,EAAgB,EAAe,CAAE,SAAU,GAAM,CAAC,CACxC,GAAS,QAAU,QACnC,MAAM,EAAgB,EAAc,CAGtC,GAAM,CAAE,gBAAe,WAAY,EAAc,qBAC3C,EAAO,GAAS,MAAQ,WACxB,EAAa,GAAS,cAAgB,EAEtC,EAAgB,GAAS,cAC3B,EAAY,EAAQ,cAAc,CAClC,EAEE,EAAW,MAAM,EAAQ,EAAe,GAAS,UAAU,CAEjE,GAAI,CAAC,GAAU,YAAa,OAE5B,GAAM,CAAE,WAAU,YAAa,EAEzB,EACJ,MAAM,EAA8B,EAAQ,CAExC,EAAyB,IAAI,IACnC,EAA2B,QAAS,GAAS,CAC3C,EAAuB,IAAI,EAAK,IAAI,EACpC,CAEF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AC1G,CAAE,MAAO,OAAQ,CAClB,GAGL,CACH,CAED,MAAM,QAAQ,IAAI,EAAQ,CAC1B,MAAO,EAAsB,QAAQ"}
1
+ {"version":3,"file":"fill.mjs","names":[],"sources":["../../../src/fill/fill.ts"],"sourcesContent":["import { basename, relative } from 'node:path';\nimport type { AIOptions } from '@intlayer/api';\nimport {\n prepareIntlayer,\n writeContentDeclaration,\n} from '@intlayer/chokidar/build';\nimport {\n type ListGitFilesOptions,\n logConfigDetails,\n} from '@intlayer/chokidar/cli';\nimport {\n formatPath,\n getGlobalLimiter,\n getTaskLimiter,\n} from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colorize,\n colorizeKey,\n colorizePath,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport {\n ensureArray,\n type GetTargetDictionaryOptions,\n getTargetUnmergedDictionaries,\n} from '../getTargetDictionary';\nimport { setupAI } from '../utils/setupAI';\nimport {\n listTranslationsTasks,\n type TranslationTask,\n} from './listTranslationsTasks';\nimport { translateDictionary } from './translateDictionary';\nimport { writeFill } from './writeFill';\n\nconst NB_CONCURRENT_TRANSLATIONS = 7;\n\n// Arguments for the fill function\nexport type FillOptions = {\n sourceLocale?: Locale;\n outputLocales?: Locale | Locale[];\n mode?: 'complete' | 'review';\n gitOptions?: ListGitFilesOptions;\n aiOptions?: AIOptions; // Added aiOptions to be passed to translateJSON\n verbose?: boolean;\n nbConcurrentTranslations?: number;\n nbConcurrentTasks?: number; // NEW: number of tasks that may run at once\n build?: boolean;\n skipMetadata?: boolean;\n} & GetTargetDictionaryOptions;\n\n/**\n * Fill translations based on the provided options.\n */\nexport const fill = async (options?: FillOptions): Promise<void> => {\n const configuration = getConfiguration(options?.configOptions);\n logConfigDetails(options?.configOptions);\n\n const appLogger = getAppLogger(configuration);\n\n if (options?.build === true) {\n await prepareIntlayer(configuration, { forceRun: true });\n } else if (typeof options?.build === 'undefined') {\n await prepareIntlayer(configuration);\n }\n\n const { defaultLocale, locales } = configuration.internationalization;\n const mode = options?.mode ?? 'complete';\n const baseLocale = options?.sourceLocale ?? defaultLocale;\n\n const outputLocales = options?.outputLocales\n ? ensureArray(options.outputLocales)\n : locales;\n\n const aiResult = await setupAI(configuration, options?.aiOptions);\n\n if (!aiResult?.hasAIAccess) return;\n\n const { aiClient, aiConfig } = aiResult;\n\n const targetUnmergedDictionaries =\n await getTargetUnmergedDictionaries(options);\n\n const affectedDictionaryKeys = new Set<string>();\n targetUnmergedDictionaries.forEach((dict) => {\n affectedDictionaryKeys.add(dict.key);\n });\n\n const keysToProcess = Array.from(affectedDictionaryKeys);\n\n appLogger([\n 'Affected dictionary keys for processing:',\n keysToProcess.length > 0\n ? keysToProcess.map((key) => colorizeKey(key)).join(', ')\n : colorize('No keys found', ANSIColors.YELLOW),\n ]);\n\n if (keysToProcess.length === 0) return;\n\n /**\n * List the translations tasks\n *\n * Create a list of per-locale dictionaries to translate\n *\n * In 'complete' mode, filter only the missing locales to translate\n */\n const translationTasks: TranslationTask[] = listTranslationsTasks(\n targetUnmergedDictionaries.map((dictionary) => dictionary.localId!),\n outputLocales,\n mode,\n baseLocale,\n configuration\n );\n\n // AI calls in flight at once (translateJSON + metadata audit)\n const nbConcurrentTranslations =\n options?.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS;\n const globalLimiter = getGlobalLimiter(nbConcurrentTranslations);\n\n // NEW: number of *tasks* that may run at once (start/prepare/log/write)\n const nbConcurrentTasks = Math.max(\n 1,\n Math.min(\n options?.nbConcurrentTasks ?? nbConcurrentTranslations,\n translationTasks.length\n )\n );\n\n const taskLimiter = getTaskLimiter(nbConcurrentTasks);\n\n const runners = translationTasks.map((task) =>\n taskLimiter(async () => {\n const relativePath = relative(\n configuration?.content?.baseDir ?? process.cwd(),\n task?.dictionaryFilePath ?? ''\n );\n\n // log AFTER acquiring a task slot\n appLogger(\n `${task.dictionaryPreset} Processing ${colorizePath(basename(relativePath))}`,\n { level: 'info' }\n );\n\n const translationTaskResult = await translateDictionary(\n task,\n configuration,\n {\n mode,\n aiOptions: options?.aiOptions,\n fillMetadata: !options?.skipMetadata,\n onHandle: globalLimiter, // <= AI calls go through here\n aiClient,\n aiConfig,\n }\n );\n\n if (!translationTaskResult?.dictionaryOutput) return;\n\n const { dictionaryOutput, sourceLocale } = translationTaskResult;\n\n // Determine if we should write to separate files\n // - If dictionary has explicit fill setting (string or object), use it\n // - If dictionary is per-locale AND has no explicit fill=false, use global fill config\n // - If dictionary is multilingual (no locale property), always write to same file\n const hasDictionaryLevelFill =\n typeof dictionaryOutput.fill === 'string' ||\n typeof dictionaryOutput.fill === 'object';\n\n const isPerLocale = typeof dictionaryOutput.locale === 'string';\n\n const effectiveFill = hasDictionaryLevelFill\n ? dictionaryOutput.fill\n : isPerLocale\n ? (configuration.dictionary?.fill ?? true)\n : false; // Multilingual dictionaries don't use fill by default\n\n const isFillOtherFile =\n typeof effectiveFill === 'string' || typeof effectiveFill === 'object';\n\n if (isFillOtherFile) {\n await writeFill(\n {\n ...dictionaryOutput,\n // Ensure fill is set on the dictionary for writeFill to use\n fill: effectiveFill,\n },\n outputLocales,\n [sourceLocale],\n configuration\n );\n } else {\n await writeContentDeclaration(dictionaryOutput, configuration);\n\n if (dictionaryOutput.filePath) {\n appLogger(\n `${task.dictionaryPreset} Content declaration written to ${formatPath(basename(dictionaryOutput.filePath))}`,\n { level: 'info' }\n );\n }\n }\n })\n );\n\n await Promise.all(runners);\n await (globalLimiter as any).onIdle();\n};\n"],"mappings":"2yBAqCA,MAmBa,EAAO,KAAO,IAAyC,CAClE,IAAM,EAAgB,EAAiB,GAAS,cAAc,CAC9D,EAAiB,GAAS,cAAc,CAExC,IAAM,EAAY,EAAa,EAAc,CAEzC,GAAS,QAAU,GACrB,MAAM,EAAgB,EAAe,CAAE,SAAU,GAAM,CAAC,CACxC,GAAS,QAAU,QACnC,MAAM,EAAgB,E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OAAO,EAAiB,MAAS,UACjC,OAAO,EAAiB,MAAS,SAE7B,EAAc,OAAO,EAAiB,QAAW,SAEjD,EAAgB,EAClB,EAAiB,KACjB,EACG,EAAc,YAAY,MAAQ,GACnC,GAGJ,OAAO,GAAkB,UAAY,OAAO,GAAkB,SAG9D,MAAM,EACJ,CACE,GAAG,EAEH,KAAM,EACP,CACD,EACA,CAAC,EAAa,CACd,EACD,EAED,MAAM,EAAwB,EAAkB,EAAc,CAE1D,EAAiB,UACnB,EACE,GAAG,EAAK,iBAAiB,kCAAkC,EAAW,EAAS,EAAiB,SAAS,CAAC,GAC1G,CAAE,MAAO,OAAQ,CAClB,GAGL,CACH,CAED,MAAM,QAAQ,IAAI,EAAQ,CAC1B,MAAO,EAAsB,QAAQ"}
@@ -1,2 +1,2 @@
1
- import{listMissingTranslationsWithConfig as e}from"../test/listMissingTranslations.mjs";import{basename as t}from"node:path";import{formatLocale as n}from"@intlayer/chokidar/utils";import{ANSIColors as r,colon as i,colorize as a,colorizeKey as o,colorizePath as s,getAppLogger as c}from"@intlayer/config/logger";import{getUnmergedDictionaries as l}from"@intlayer/unmerged-dictionaries-entry";import{getFilterTranslationsOnlyDictionary as u}from"@intlayer/core/plugins";import{getDictionaries as d}from"@intlayer/dictionaries-entry";const f=(f,p,m,h,g)=>{let _=c(g),v=d(g),y=l(g),b=Object.values(y).flat().filter(e=>f.includes(e.localId)),{missingTranslations:x}=e(g),S=Math.max(...b.map(e=>e.key.length)),C=[];for(let e of b){let c=i([` - `,a(`[`,r.GREY_DARK),o(e.key),a(`]`,r.GREY_DARK)].join(``),{colSize:S+6}),l=e.key,d=e.localId,f=v[l];if((e.filled??!1)===!0||(e.fill??g.dictionary?.fill??!1)===!1)continue;let y=e.locale??h;if(!f){_(`${c} Dictionary not found in dictionariesRecord. Skipping.`,{level:`warn`});continue}if(!e.filePath){_(`${c} Dictionary has no file path. Skipping.`,{level:`warn`});continue}let b=u(f,y);if(Object.keys(b).length===0){_(`${c} No content found for dictionary in source locale ${n(y)}. Skipping translation for this dictionary.`,{level:`warn`});continue}let w=p;if(m===`complete`&&(w=x.find(e=>e.key===l)?.locales.filter(e=>p.includes(e))??[]),w.length===0){_(`${c} ${a(`No locales to fill, Skipping`,r.GREY_DARK)} ${s(t(e.filePath))}`,{level:`warn`});continue}C.push({dictionaryKey:l,dictionaryLocalId:d,sourceLocale:y,targetLocales:w,dictionaryPreset:c,dictionaryFilePath:e.filePath})}return C};export{f as listTranslationsTasks};
1
+ import{listMissingTranslationsWithConfig as e}from"../test/listMissingTranslations.mjs";import{basename as t}from"node:path";import{formatLocale as n}from"@intlayer/chokidar/utils";import*as r from"@intlayer/config/colors";import{colon as i,colorize as a,colorizeKey as o,colorizePath as s,getAppLogger as c}from"@intlayer/config/logger";import{getUnmergedDictionaries as l}from"@intlayer/unmerged-dictionaries-entry";import{getFilterTranslationsOnlyDictionary as u}from"@intlayer/core/plugins";import{getDictionaries as d}from"@intlayer/dictionaries-entry";const f=(f,p,m,h,g)=>{let _=c(g),v=d(g),y=l(g),b=Object.values(y).flat().filter(e=>f.includes(e.localId)),{missingTranslations:x}=e(g),S=Math.max(...b.map(e=>e.key.length)),C=[];for(let e of b){let c=i([` - `,a(`[`,r.GREY_DARK),o(e.key),a(`]`,r.GREY_DARK)].join(``),{colSize:S+6}),l=e.key,d=e.localId,f=v[l];if((e.filled??!1)===!0||(e.fill??g.dictionary?.fill??!1)===!1)continue;let y=e.locale??h;if(!f){_(`${c} Dictionary not found in dictionariesRecord. Skipping.`,{level:`warn`});continue}if(!e.filePath){_(`${c} Dictionary has no file path. Skipping.`,{level:`warn`});continue}let b=u(f,y);if(Object.keys(b).length===0){_(`${c} No content found for dictionary in source locale ${n(y)}. Skipping translation for this dictionary.`,{level:`warn`});continue}let w=p;if(m===`complete`&&(w=x.find(e=>e.key===l)?.locales.filter(e=>p.includes(e))??[]),w.length===0){_(`${c} ${a(`No locales to fill, Skipping`,r.GREY_DARK)} ${s(t(e.filePath))}`,{level:`warn`});continue}C.push({dictionaryKey:l,dictionaryLocalId:d,sourceLocale:y,targetLocales:w,dictionaryPreset:c,dictionaryFilePath:e.filePath})}return C};export{f as listTranslationsTasks};
2
2
  //# sourceMappingURL=listTranslationsTasks.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"listTranslationsTasks.mjs","names":[],"sources":["../../../src/fill/listTranslationsTasks.ts"],"sourcesContent":["import { basename } from 'node:path';\nimport { formatLocale } from '@intlayer/chokidar/utils';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeKey,\n colorizePath,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { getFilterTranslationsOnlyDictionary } from '@intlayer/core/plugins';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Dictionary, LocalDictionaryId } from '@intlayer/types/dictionary';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport { listMissingTranslationsWithConfig } from '../test';\n\nexport type TranslationTask = {\n dictionaryKey: string;\n dictionaryLocalId: LocalDictionaryId;\n sourceLocale: Locale;\n targetLocales: Locale[];\n dictionaryPreset: string;\n dictionaryFilePath: string;\n};\n\nexport const listTranslationsTasks = (\n localIds: LocalDictionaryId[],\n outputLocales: Locale[],\n mode: 'complete' | 'review',\n baseLocale: Locale,\n configuration: IntlayerConfig\n): TranslationTask[] => {\n const appLogger = getAppLogger(configuration);\n\n const mergedDictionariesRecord = getDictionaries(configuration);\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n\n const allFlatDictionaries = Object.values(unmergedDictionariesRecord).flat();\n const dictionariesToProcess = allFlatDictionaries.filter((dictionary) =>\n localIds.includes(dictionary.localId!)\n );\n\n const { missingTranslations } =\n listMissingTranslationsWithConfig(configuration);\n\n const maxKeyLength = Math.max(\n ...dictionariesToProcess.map((dictionary) => dictionary.key.length)\n );\n\n const translationTasks: TranslationTask[] = [];\n\n for (const targetUnmergedDictionary of dictionariesToProcess) {\n const dictionaryPreset = colon(\n [\n ' - ',\n colorize('[', ANSIColors.GREY_DARK),\n colorizeKey(targetUnmergedDictionary.key),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: maxKeyLength + 6 }\n );\n\n const dictionaryKey = targetUnmergedDictionary.key;\n const dictionaryLocalId = targetUnmergedDictionary.localId!;\n const mainDictionaryToProcess: Dictionary =\n mergedDictionariesRecord[dictionaryKey];\n const dictionaryFilled = targetUnmergedDictionary.filled ?? false;\n\n if (dictionaryFilled === true) {\n continue;\n }\n\n const dictionaryFill =\n targetUnmergedDictionary.fill ?? configuration.dictionary?.fill ?? false;\n\n if (dictionaryFill === false) continue;\n\n const sourceLocale: Locale = (targetUnmergedDictionary.locale ??\n baseLocale) as Locale;\n\n if (!mainDictionaryToProcess) {\n appLogger(\n `${dictionaryPreset} Dictionary not found in dictionariesRecord. Skipping.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n if (!targetUnmergedDictionary.filePath) {\n appLogger(`${dictionaryPreset} Dictionary has no file path. Skipping.`, {\n level: 'warn',\n });\n continue;\n }\n\n const sourceLocaleContent = getFilterTranslationsOnlyDictionary(\n mainDictionaryToProcess,\n sourceLocale\n );\n\n if (\n Object.keys(sourceLocaleContent as Record<string, unknown>).length === 0\n ) {\n appLogger(\n `${dictionaryPreset} No content found for dictionary in source locale ${formatLocale(sourceLocale)}. Skipping translation for this dictionary.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n /**\n * In 'complete' mode, filter only the missing locales to translate\n *\n * Skip the dictionary if there are no missing locales to translate\n */\n let outputLocalesList: Locale[] = outputLocales as Locale[];\n\n if (mode === 'complete') {\n outputLocalesList =\n missingTranslations\n .find(\n (missingTranslation) => missingTranslation.key === dictionaryKey\n )\n ?.locales.filter((locale) => outputLocales.includes(locale)) ?? [];\n }\n\n if (outputLocalesList.length === 0) {\n appLogger(\n `${dictionaryPreset} ${colorize('No locales to fill, Skipping', ANSIColors.GREY_DARK)} ${colorizePath(basename(targetUnmergedDictionary.filePath))}`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n translationTasks.push({\n dictionaryKey,\n dictionaryLocalId,\n sourceLocale,\n targetLocales: outputLocalesList,\n dictionaryPreset,\n dictionaryFilePath: targetUnmergedDictionary.filePath,\n });\n }\n\n // Return the list of tasks to execute\n return translationTasks;\n};\n"],"mappings":"ohBA2BA,MAAa,GACX,EACA,EACA,EACA,EACA,IACsB,CACtB,IAAM,EAAY,EAAa,EAAc,CAEvC,EAA2B,EAAgB,EAAc,CACzD,EAA6B,EAAwB,EAAc,CAGnE,EADsB,OAAO,OAAO,EAA2B,CAAC,MAAM,CAC1B,OAAQ,GACxD,EAAS,SAAS,EAAW,QAAS,CACvC,CAEK,CAAE,uBACN,EAAkC,EAAc,CAE5C,EAAe,KAAK,IACxB,GAAG,EAAsB,IAAK,GAAe,EAAW,IAAI,OAAO,CACpE,CAEK,EAAsC,EAAE,CAE9C,IAAK,IAAM,KAA4B,EAAuB,CAC5D,IAAM,EAAmB,EACvB,CACE,MACA,EAAS,IAAK,EAAW,UAAU,CACnC,EAAY,EAAyB,IAAI,CACzC,EAAS,IAAK,EAAW,UAAU,CACpC,CAAC,KAAK,GAAG,CACV,CAAE,QAAS,EAAe,EAAG,CAC9B,CAEK,EAAgB,EAAyB,IACzC,EAAoB,EAAyB,QAC7C,EACJ,EAAyB,GAU3B,IATyB,EAAyB,QAAU,MAEnC,KAKvB,EAAyB,MAAQ,EAAc,YAAY,MAAQ,MAE9C,GAAO,SAE9B,IAAM,EAAwB,EAAyB,QACrD,EAEF,GAAI,CAAC,EAAyB,CAC5B,EACE,GAAG,EAAiB,wDACpB,CACE,MAAO,OACR,CACF,CACD,SAGF,GAAI,CAAC,EAAyB,SAAU,CACtC,EAAU,GAAG,EAAiB,yCAA0C,CACtE,MAAO,OACR,CAAC,CACF,SAGF,IAAM,EAAsB,EAC1B,EACA,EACD,CAED,GACE,OAAO,KAAK,EAA+C,CAAC,SAAW,EACvE,CACA,EACE,GAAG,EAAiB,oDAAoD,EAAa,EAAa,CAAC,6CACnG,CACE,MAAO,OACR,CACF,CACD,SAQF,IAAI,EAA8B,EAWlC,GATI,IAAS,aACX,EACE,EACG,KACE,GAAuB,EAAmB,MAAQ,EACpD,EACC,QAAQ,OAAQ,GAAW,EAAc,SAAS,EAAO,CAAC,EAAI,EAAE,EAGpE,EAAkB,SAAW,EAAG,CAClC,EACE,GAAG,EAAiB,GAAG,EAAS,+BAAgC,EAAW,UAAU,CAAC,GAAG,EAAa,EAAS,EAAyB,SAAS,CAAC,GAClJ,CACE,MAAO,OACR,CACF,CACD,SAGF,EAAiB,KAAK,CACpB,gBACA,oBACA,eACA,cAAe,EACf,mBACA,mBAAoB,EAAyB,SAC9C,CAAC,CAIJ,OAAO"}
1
+ {"version":3,"file":"listTranslationsTasks.mjs","names":[],"sources":["../../../src/fill/listTranslationsTasks.ts"],"sourcesContent":["import { basename } from 'node:path';\nimport { formatLocale } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colon,\n colorize,\n colorizeKey,\n colorizePath,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { getFilterTranslationsOnlyDictionary } from '@intlayer/core/plugins';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary, LocalDictionaryId } from '@intlayer/types/dictionary';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport { listMissingTranslationsWithConfig } from '../test';\n\nexport type TranslationTask = {\n dictionaryKey: string;\n dictionaryLocalId: LocalDictionaryId;\n sourceLocale: Locale;\n targetLocales: Locale[];\n dictionaryPreset: string;\n dictionaryFilePath: string;\n};\n\nexport const listTranslationsTasks = (\n localIds: LocalDictionaryId[],\n outputLocales: Locale[],\n mode: 'complete' | 'review',\n baseLocale: Locale,\n configuration: IntlayerConfig\n): TranslationTask[] => {\n const appLogger = getAppLogger(configuration);\n\n const mergedDictionariesRecord = getDictionaries(configuration);\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n\n const allFlatDictionaries = Object.values(unmergedDictionariesRecord).flat();\n const dictionariesToProcess = allFlatDictionaries.filter((dictionary) =>\n localIds.includes(dictionary.localId!)\n );\n\n const { missingTranslations } =\n listMissingTranslationsWithConfig(configuration);\n\n const maxKeyLength = Math.max(\n ...dictionariesToProcess.map((dictionary) => dictionary.key.length)\n );\n\n const translationTasks: TranslationTask[] = [];\n\n for (const targetUnmergedDictionary of dictionariesToProcess) {\n const dictionaryPreset = colon(\n [\n ' - ',\n colorize('[', ANSIColors.GREY_DARK),\n colorizeKey(targetUnmergedDictionary.key),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: maxKeyLength + 6 }\n );\n\n const dictionaryKey = targetUnmergedDictionary.key;\n const dictionaryLocalId = targetUnmergedDictionary.localId!;\n const mainDictionaryToProcess: Dictionary =\n mergedDictionariesRecord[dictionaryKey];\n const dictionaryFilled = targetUnmergedDictionary.filled ?? false;\n\n if (dictionaryFilled === true) {\n continue;\n }\n\n const dictionaryFill =\n targetUnmergedDictionary.fill ?? configuration.dictionary?.fill ?? false;\n\n if (dictionaryFill === false) continue;\n\n const sourceLocale: Locale = (targetUnmergedDictionary.locale ??\n baseLocale) as Locale;\n\n if (!mainDictionaryToProcess) {\n appLogger(\n `${dictionaryPreset} Dictionary not found in dictionariesRecord. Skipping.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n if (!targetUnmergedDictionary.filePath) {\n appLogger(`${dictionaryPreset} Dictionary has no file path. Skipping.`, {\n level: 'warn',\n });\n continue;\n }\n\n const sourceLocaleContent = getFilterTranslationsOnlyDictionary(\n mainDictionaryToProcess,\n sourceLocale\n );\n\n if (\n Object.keys(sourceLocaleContent as Record<string, unknown>).length === 0\n ) {\n appLogger(\n `${dictionaryPreset} No content found for dictionary in source locale ${formatLocale(sourceLocale)}. Skipping translation for this dictionary.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n /**\n * In 'complete' mode, filter only the missing locales to translate\n *\n * Skip the dictionary if there are no missing locales to translate\n */\n let outputLocalesList: Locale[] = outputLocales as Locale[];\n\n if (mode === 'complete') {\n outputLocalesList =\n missingTranslations\n .find(\n (missingTranslation) => missingTranslation.key === dictionaryKey\n )\n ?.locales.filter((locale) => outputLocales.includes(locale)) ?? [];\n }\n\n if (outputLocalesList.length === 0) {\n appLogger(\n `${dictionaryPreset} ${colorize('No locales to fill, Skipping', ANSIColors.GREY_DARK)} ${colorizePath(basename(targetUnmergedDictionary.filePath))}`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n translationTasks.push({\n dictionaryKey,\n dictionaryLocalId,\n sourceLocale,\n targetLocales: outputLocalesList,\n dictionaryPreset,\n dictionaryFilePath: targetUnmergedDictionary.filePath,\n });\n }\n\n // Return the list of tasks to execute\n return translationTasks;\n};\n"],"mappings":"8iBA2BA,MAAa,GACX,EACA,EACA,EACA,EACA,IACsB,CACtB,IAAM,EAAY,EAAa,EAAc,CAEvC,EAA2B,EAAgB,EAAc,CACzD,EAA6B,EAAwB,EAAc,CAGnE,EADsB,OAAO,OAAO,EAA2B,CAAC,MAAM,CAC1B,OAAQ,GACxD,EAAS,SAAS,EAAW,QAAS,CACvC,CAEK,CAAE,uBACN,EAAkC,EAAc,CAE5C,EAAe,KAAK,IACxB,GAAG,EAAsB,IAAK,GAAe,EAAW,IAAI,OAAO,CACpE,CAEK,EAAsC,EAAE,CAE9C,IAAK,IAAM,KAA4B,EAAuB,CAC5D,IAAM,EAAmB,EACvB,CACE,MACA,EAAS,IAAK,EAAW,UAAU,CACnC,EAAY,EAAyB,IAAI,CACzC,EAAS,IAAK,EAAW,UAAU,CACpC,CAAC,KAAK,GAAG,CACV,CAAE,QAAS,EAAe,EAAG,CAC9B,CAEK,EAAgB,EAAyB,IACzC,EAAoB,EAAyB,QAC7C,EACJ,EAAyB,GAU3B,IATyB,EAAyB,QAAU,MAEnC,KAKvB,EAAyB,MAAQ,EAAc,YAAY,MAAQ,MAE9C,GAAO,SAE9B,IAAM,EAAwB,EAAyB,QACrD,EAEF,GAAI,CAAC,EAAyB,CAC5B,EACE,GAAG,EAAiB,wDACpB,CACE,MAAO,OACR,CACF,CACD,SAGF,GAAI,CAAC,EAAyB,SAAU,CACtC,EAAU,GAAG,EAAiB,yCAA0C,CACtE,MAAO,OACR,CAAC,CACF,SAGF,IAAM,EAAsB,EAC1B,EACA,EACD,CAED,GACE,OAAO,KAAK,EAA+C,CAAC,SAAW,EACvE,CACA,EACE,GAAG,EAAiB,oDAAoD,EAAa,EAAa,CAAC,6CACnG,CACE,MAAO,OACR,CACF,CACD,SAQF,IAAI,EAA8B,EAWlC,GATI,IAAS,aACX,EACE,EACG,KACE,GAAuB,EAAmB,MAAQ,EACpD,EACC,QAAQ,OAAQ,GAAW,EAAc,SAAS,EAAO,CAAC,EAAI,EAAE,EAGpE,EAAkB,SAAW,EAAG,CAClC,EACE,GAAG,EAAiB,GAAG,EAAS,+BAAgC,EAAW,UAAU,CAAC,GAAG,EAAa,EAAS,EAAyB,SAAS,CAAC,GAClJ,CACE,MAAO,OACR,CACF,CACD,SAGF,EAAiB,KAAK,CACpB,gBACA,oBACA,eACA,cAAe,EACf,mBACA,mBAAoB,EAAyB,SAC9C,CAAC,CAIJ,OAAO"}
@@ -1,2 +1,2 @@
1
- import{deepMergeContent as e}from"./deepMergeContent.mjs";import{getFilterMissingContentPerLocale as t}from"./getFilterMissingContentPerLocale.mjs";import{basename as n}from"node:path";import{chunkJSON as r,formatLocale as i,mergeChunks as a,reconstructFromSingleChunk as o,reduceObjectFormat as s,verifyIdenticObjectFormat as c}from"@intlayer/chokidar/utils";import{ANSIColors as l,colon as u,colorize as d,colorizeNumber as f,colorizePath as p,getAppLogger as m}from"@intlayer/config/logger";import{getUnmergedDictionaries as h}from"@intlayer/unmerged-dictionaries-entry";import{getFilterMissingTranslationsDictionary as g,getMultilingualDictionary as _,getPerLocaleDictionary as v,insertContentInDictionary as y}from"@intlayer/core/plugins";import{getIntlayerAPIProxy as b}from"@intlayer/api";import{retryManager as x}from"@intlayer/config/utils";const S=e=>!e.description||!e.title||!e.tags,C=e=>{if(typeof e!=`object`||!e||Array.isArray(e))return{content:e,nulls:void 0,hasNulls:!1};let t={},n={},r=!1;for(let[i,a]of Object.entries(e))if(a===null)n[i]=null,r=!0;else{let e=C(a);t[i]=e.content,e.hasNulls&&(n[i]=e.nulls,r=!0)}return{content:t,nulls:r?n:void 0,hasNulls:r}},w=1e3*10;let T=0;const E=async(E,D,O)=>{let k=m(D),A=b(void 0,D),{mode:j,aiOptions:M,fillMetadata:N,aiClient:P,aiConfig:F}={mode:`complete`,fillMetadata:!0,...O},I=()=>{T=0,O?.onSuccess?.()};return await x(async()=>{let m=h(D),b=m[E.dictionaryKey].find(e=>e.localId===E.dictionaryLocalId);if(!b)return k(`${E.dictionaryPreset}Dictionary not found in unmergedDictionariesRecord. Skipping.`,{level:`warn`}),{...E,dictionaryOutput:null};let L;if(N&&(S(b)||j===`review`)){let e=v(b,D.internationalization.defaultLocale);k(`${E.dictionaryPreset} Filling missing metadata for ${p(n(b.filePath))}`,{level:`info`});let t=async()=>P&&F?{data:await P.auditDictionaryMetadata({fileContent:JSON.stringify(e),aiConfig:F})}:await A.ai.auditContentDeclarationMetadata({fileContent:JSON.stringify(e),aiOptions:M});L=(O?.onHandle?await O.onHandle(t):await t()).data?.fileContent}let R=await Promise.all(E.targetLocales.map(async h=>{let _=structuredClone(b),y;if(typeof b.locale==`string`){let e=b.filePath?.replace(RegExp(`/${E.sourceLocale}/`,`g`),`/${h}/`),n=e?m[E.dictionaryKey]?.find(t=>t.filePath===e&&t.locale===h):void 0;y=n??{key:b.key,content:{},filePath:e,locale:h},j===`complete`&&(_=t(_,n))}else j===`complete`&&(_=g(_,h)),_=v(_,E.sourceLocale),y=v(b,h);let S=u([d(`[`,l.GREY_DARK),i(h),d(`]`,l.GREY_DARK)].join(``),{colSize:18}),D=(e,t)=>t<=1?``:u([d(`[`,l.GREY_DARK),f(e+1),d(`/${t}`,l.GREY_DARK),d(`]`,l.GREY_DARK)].join(``),{colSize:5});k(`${E.dictionaryPreset}${S} Preparing ${p(n(y.filePath))}`,{level:`info`});let N=typeof _.content==`object`&&_.content!==null||Array.isArray(_.content),{content:R,nulls:z}=C(N?_.content:{__INTLAYER_ROOT_PRIMITIVE_CONTENT__:_.content}),B=r(R,7e3),V=B.length;V>1&&k(`${E.dictionaryPreset}${S} Split into ${f(V)} chunks for translation`,{level:`info`});let H=[],U=B.map(e=>{let t=D(e.index,e.total);V>1&&k(`${E.dictionaryPreset}${S}${t} Translating chunk`,{level:`info`});let n=o(e),r=s(N?y.content:{__INTLAYER_ROOT_PRIMITIVE_CONTENT__:y.content},n),i=async()=>await x(async()=>{let e;if(e=P&&F?await P.translateJSON({entryFileContent:n,presetOutputContent:r,dictionaryDescription:_.description??L?.description??``,entryLocale:E.sourceLocale,outputLocale:h,mode:j,aiConfig:F}):await A.ai.translateJSON({entryFileContent:n,presetOutputContent:r,dictionaryDescription:_.description??L?.description??``,entryLocale:E.sourceLocale,outputLocale:h,mode:j,aiOptions:M}).then(e=>e.data),!e?.fileContent)throw Error(`No content result`);let{isIdentic:t}=c(e.fileContent,n);if(!t)throw Error(`Translation result does not match expected format`);return I(),e.fileContent},{maxRetry:3,delay:w,onError:({error:t,attempt:n,maxRetry:r})=>{let i=D(e.index,e.total);k(`${E.dictionaryPreset}${S}${i} ${d(`Error filling:`,l.RED)} ${d(typeof t==`string`?t:JSON.stringify(t),l.GREY_DARK)} - Attempt ${f(n+1)} of ${f(r)}`,{level:`error`}),T+=1,T>=10&&(k(`There is something wrong.`,{level:`error`}),process.exit(1))}})();return(O?.onHandle?O.onHandle(i):i()).then(t=>({chunk:e,result:t}))});(await Promise.all(U)).sort((e,t)=>e.chunk.index-t.chunk.index).forEach(({result:e})=>{H.push(e)});let W=a(H);z&&(W=e(W,z));let G={..._,content:W}.content;return N||(G=G?.__INTLAYER_ROOT_PRIMITIVE_CONTENT__),typeof b.locale==`string`&&(G=e(y.content??{},G)),[h,G]})),z=Object.fromEntries(R),B={..._(b.locale?{...b,key:b.key,content:{}}:b),locale:void 0,...L};for(let e of E.targetLocales)z[e]&&(B=y(B,z[e],e));if(k(`${E.dictionaryPreset} ${d(`Translation completed successfully`,l.GREEN)} for ${p(n(B.filePath))}`,{level:`info`}),b.locale&&(b.fill===!0||b.fill===void 0)&&b.location===`local`){let e=b.filePath.split(`.`).slice(0,-1),t=e[e.length-1];return JSON.parse(JSON.stringify({...E,dictionaryOutput:{...B,fill:void 0,filled:!0}}).replaceAll(RegExp(`\\.${t}\\.[a-zA-Z0-9]+`,`g`),`.filled.${t}.json`))}return{...E,dictionaryOutput:B}},{maxRetry:2,delay:w,onError:({error:e,attempt:t,maxRetry:n})=>k(`${E.dictionaryPreset} ${d(`Error:`,l.RED)} ${d(typeof e==`string`?e:JSON.stringify(e),l.GREY_DARK)} - Attempt ${f(t+1)} of ${f(n)}`,{level:`error`}),onMaxTryReached:({error:e})=>k(`${E.dictionaryPreset} ${d(`Maximum number of retries reached:`,l.RED)} ${d(typeof e==`string`?e:JSON.stringify(e),l.GREY_DARK)}`,{level:`error`})})()};export{E as translateDictionary};
1
+ import{deepMergeContent as e}from"./deepMergeContent.mjs";import{getFilterMissingContentPerLocale as t}from"./getFilterMissingContentPerLocale.mjs";import{basename as n}from"node:path";import{chunkJSON as r,formatLocale as i,mergeChunks as a,reconstructFromSingleChunk as o,reduceObjectFormat as s,verifyIdenticObjectFormat as c}from"@intlayer/chokidar/utils";import*as l from"@intlayer/config/colors";import{colon as u,colorize as d,colorizeNumber as f,colorizePath as p,getAppLogger as m}from"@intlayer/config/logger";import{getUnmergedDictionaries as h}from"@intlayer/unmerged-dictionaries-entry";import{getFilterMissingTranslationsDictionary as g,getMultilingualDictionary as _,getPerLocaleDictionary as v,insertContentInDictionary as y}from"@intlayer/core/plugins";import{getIntlayerAPIProxy as b}from"@intlayer/api";import{retryManager as x}from"@intlayer/config/utils";const S=e=>!e.description||!e.title||!e.tags,C=e=>{if(typeof e!=`object`||!e||Array.isArray(e))return{content:e,nulls:void 0,hasNulls:!1};let t={},n={},r=!1;for(let[i,a]of Object.entries(e))if(a===null)n[i]=null,r=!0;else{let e=C(a);t[i]=e.content,e.hasNulls&&(n[i]=e.nulls,r=!0)}return{content:t,nulls:r?n:void 0,hasNulls:r}},w=1e3*10;let T=0;const E=async(E,D,O)=>{let k=m(D),A=b(void 0,D),{mode:j,aiOptions:M,fillMetadata:N,aiClient:P,aiConfig:F}={mode:`complete`,fillMetadata:!0,...O},I=()=>{T=0,O?.onSuccess?.()};return await x(async()=>{let m=h(D),b=m[E.dictionaryKey].find(e=>e.localId===E.dictionaryLocalId);if(!b)return k(`${E.dictionaryPreset}Dictionary not found in unmergedDictionariesRecord. Skipping.`,{level:`warn`}),{...E,dictionaryOutput:null};let L;if(N&&(S(b)||j===`review`)){let e=v(b,D.internationalization.defaultLocale);k(`${E.dictionaryPreset} Filling missing metadata for ${p(n(b.filePath))}`,{level:`info`});let t=async()=>P&&F?{data:await P.auditDictionaryMetadata({fileContent:JSON.stringify(e),aiConfig:F})}:await A.ai.auditContentDeclarationMetadata({fileContent:JSON.stringify(e),aiOptions:M});L=(O?.onHandle?await O.onHandle(t):await t()).data?.fileContent}let R=await Promise.all(E.targetLocales.map(async h=>{let _=structuredClone(b),y;if(typeof b.locale==`string`){let e=b.filePath?.replace(RegExp(`/${E.sourceLocale}/`,`g`),`/${h}/`),n=e?m[E.dictionaryKey]?.find(t=>t.filePath===e&&t.locale===h):void 0;y=n??{key:b.key,content:{},filePath:e,locale:h},j===`complete`&&(_=t(_,n))}else j===`complete`&&(_=g(_,h)),_=v(_,E.sourceLocale),y=v(b,h);let S=u([d(`[`,l.GREY_DARK),i(h),d(`]`,l.GREY_DARK)].join(``),{colSize:18}),D=(e,t)=>t<=1?``:u([d(`[`,l.GREY_DARK),f(e+1),d(`/${t}`,l.GREY_DARK),d(`]`,l.GREY_DARK)].join(``),{colSize:5});k(`${E.dictionaryPreset}${S} Preparing ${p(n(y.filePath))}`,{level:`info`});let N=typeof _.content==`object`&&_.content!==null||Array.isArray(_.content),{content:R,nulls:z}=C(N?_.content:{__INTLAYER_ROOT_PRIMITIVE_CONTENT__:_.content}),B=r(R,7e3),V=B.length;V>1&&k(`${E.dictionaryPreset}${S} Split into ${f(V)} chunks for translation`,{level:`info`});let H=[],U=B.map(e=>{let t=D(e.index,e.total);V>1&&k(`${E.dictionaryPreset}${S}${t} Translating chunk`,{level:`info`});let n=o(e),r=s(N?y.content:{__INTLAYER_ROOT_PRIMITIVE_CONTENT__:y.content},n),i=async()=>await x(async()=>{let e;if(e=P&&F?await P.translateJSON({entryFileContent:n,presetOutputContent:r,dictionaryDescription:_.description??L?.description??``,entryLocale:E.sourceLocale,outputLocale:h,mode:j,aiConfig:F}):await A.ai.translateJSON({entryFileContent:n,presetOutputContent:r,dictionaryDescription:_.description??L?.description??``,entryLocale:E.sourceLocale,outputLocale:h,mode:j,aiOptions:M}).then(e=>e.data),!e?.fileContent)throw Error(`No content result`);let{isIdentic:t}=c(e.fileContent,n);if(!t)throw Error(`Translation result does not match expected format`);return I(),e.fileContent},{maxRetry:3,delay:w,onError:({error:t,attempt:n,maxRetry:r})=>{let i=D(e.index,e.total);k(`${E.dictionaryPreset}${S}${i} ${d(`Error filling:`,l.RED)} ${d(typeof t==`string`?t:JSON.stringify(t),l.GREY_DARK)} - Attempt ${f(n+1)} of ${f(r)}`,{level:`error`}),T+=1,T>=10&&(k(`There is something wrong.`,{level:`error`}),process.exit(1))}})();return(O?.onHandle?O.onHandle(i):i()).then(t=>({chunk:e,result:t}))});(await Promise.all(U)).sort((e,t)=>e.chunk.index-t.chunk.index).forEach(({result:e})=>{H.push(e)});let W=a(H);z&&(W=e(W,z));let G={..._,content:W}.content;return N||(G=G?.__INTLAYER_ROOT_PRIMITIVE_CONTENT__),typeof b.locale==`string`&&(G=e(y.content??{},G)),[h,G]})),z=Object.fromEntries(R),B={..._(b.locale?{...b,key:b.key,content:{}}:b),locale:void 0,...L};for(let e of E.targetLocales)z[e]&&(B=y(B,z[e],e));if(k(`${E.dictionaryPreset} ${d(`Translation completed successfully`,l.GREEN)} for ${p(n(B.filePath))}`,{level:`info`}),b.locale&&(b.fill===!0||b.fill===void 0)&&b.location===`local`){let e=b.filePath.split(`.`).slice(0,-1),t=e[e.length-1];return JSON.parse(JSON.stringify({...E,dictionaryOutput:{...B,fill:void 0,filled:!0}}).replaceAll(RegExp(`\\.${t}\\.[a-zA-Z0-9]+`,`g`),`.filled.${t}.json`))}return{...E,dictionaryOutput:B}},{maxRetry:2,delay:w,onError:({error:e,attempt:t,maxRetry:n})=>k(`${E.dictionaryPreset} ${d(`Error:`,l.RED)} ${d(typeof e==`string`?e:JSON.stringify(e),l.GREY_DARK)} - Attempt ${f(t+1)} of ${f(n)}`,{level:`error`}),onMaxTryReached:({error:e})=>k(`${E.dictionaryPreset} ${d(`Maximum number of retries reached:`,l.RED)} ${d(typeof e==`string`?e:JSON.stringify(e),l.GREY_DARK)}`,{level:`error`})})()};export{E as translateDictionary};
2
2
  //# sourceMappingURL=translateDictionary.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"translateDictionary.mjs","names":[],"sources":["../../../src/fill/translateDictionary.ts"],"sourcesContent":["import { basename } from 'node:path';\nimport type { AIConfig } from '@intlayer/ai';\nimport { type AIOptions, getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n chunkJSON,\n formatLocale,\n type JsonChunk,\n mergeChunks,\n reconstructFromSingleChunk,\n reduceObjectFormat,\n verifyIdenticObjectFormat,\n} from '@intlayer/chokidar/utils';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n colorizePath,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { retryManager } from '@intlayer/config/utils';\nimport {\n getFilterMissingTranslationsDictionary,\n getMultilingualDictionary,\n getPerLocaleDictionary,\n insertContentInDictionary,\n} from '@intlayer/core/plugins';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport type { AIClient } from '../utils/setupAI';\nimport { deepMergeContent } from './deepMergeContent';\nimport { getFilterMissingContentPerLocale } from './getFilterMissingContentPerLocale';\nimport type { TranslationTask } from './listTranslationsTasks';\n\ntype TranslateDictionaryResult = TranslationTask & {\n dictionaryOutput: Dictionary | null;\n};\n\ntype TranslateDictionaryOptions = {\n mode: 'complete' | 'review';\n aiOptions?: AIOptions;\n fillMetadata?: boolean;\n onHandle?: ReturnType<\n typeof import('@intlayer/chokidar/utils').getGlobalLimiter\n >;\n onSuccess?: () => void;\n onError?: (error: unknown) => void;\n getAbortError?: () => Error | null;\n aiClient?: AIClient;\n aiConfig?: AIConfig;\n};\n\nconst hasMissingMetadata = (dictionary: Dictionary) =>\n !dictionary.description || !dictionary.title || !dictionary.tags;\n\n/**\n * Recursively strips null values from an object, returning the cleaned content\n * and a separate object containing only the null-valued paths so they can be\n * re-injected after AI translation (nulls don't need translation).\n */\nconst stripNullValues = (\n obj: any\n): { content: any; nulls: any; hasNulls: boolean } => {\n if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {\n return { content: obj, nulls: undefined, hasNulls: false };\n }\n\n const content: any = {};\n const nulls: any = {};\n let hasNulls = false;\n\n for (const [key, value] of Object.entries(obj)) {\n if (value === null) {\n nulls[key] = null;\n hasNulls = true;\n } else {\n const child = stripNullValues(value);\n content[key] = child.content;\n if (child.hasNulls) {\n nulls[key] = child.nulls;\n hasNulls = true;\n }\n }\n }\n\n return { content, nulls: hasNulls ? nulls : undefined, hasNulls };\n};\n\nconst CHUNK_SIZE = 7000; // GPT-5 Mini safe input size\nconst GROUP_MAX_RETRY = 2;\nconst MAX_RETRY = 3;\nconst RETRY_DELAY = 1000 * 10; // 10 seconds\n\nconst MAX_FOLLOWING_ERRORS = 10; // 10 errors in a row, hard exit the process\nlet followingErrors = 0;\n\nexport const translateDictionary = async (\n task: TranslationTask,\n configuration: IntlayerConfig,\n options?: TranslateDictionaryOptions\n): Promise<TranslateDictionaryResult> => {\n const appLogger = getAppLogger(configuration);\n const intlayerAPI = getIntlayerAPIProxy(undefined, configuration);\n\n const { mode, aiOptions, fillMetadata, aiClient, aiConfig } = {\n mode: 'complete',\n fillMetadata: true,\n ...options,\n } as const;\n\n const notifySuccess = () => {\n followingErrors = 0;\n options?.onSuccess?.();\n };\n\n const result = await retryManager(\n async () => {\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n\n const baseUnmergedDictionary: Dictionary | undefined =\n unmergedDictionariesRecord[task.dictionaryKey].find(\n (dict) => dict.localId === task.dictionaryLocalId\n );\n\n if (!baseUnmergedDictionary) {\n appLogger(\n `${task.dictionaryPreset}Dictionary not found in unmergedDictionariesRecord. Skipping.`,\n {\n level: 'warn',\n }\n );\n return { ...task, dictionaryOutput: null };\n }\n\n let metadata:\n | Pick<Dictionary, 'description' | 'title' | 'tags'>\n | undefined;\n\n if (\n fillMetadata &&\n (hasMissingMetadata(baseUnmergedDictionary) || mode === 'review')\n ) {\n const defaultLocaleDictionary = getPerLocaleDictionary(\n baseUnmergedDictionary,\n configuration.internationalization.defaultLocale\n );\n\n appLogger(\n `${task.dictionaryPreset} Filling missing metadata for ${colorizePath(basename(baseUnmergedDictionary.filePath!))}`,\n {\n level: 'info',\n }\n );\n\n const runAudit = async () => {\n if (aiClient && aiConfig) {\n const result = await aiClient.auditDictionaryMetadata({\n fileContent: JSON.stringify(defaultLocaleDictionary),\n aiConfig,\n });\n\n return {\n data: result,\n };\n }\n\n return await intlayerAPI.ai.auditContentDeclarationMetadata({\n fileContent: JSON.stringify(defaultLocaleDictionary),\n aiOptions,\n });\n };\n\n const metadataResult = options?.onHandle\n ? await options.onHandle(runAudit)\n : await runAudit();\n\n metadata = metadataResult.data?.fileContent;\n }\n\n const translatedContentResults = await Promise.all(\n task.targetLocales.map(async (targetLocale) => {\n /**\n * In complete mode, for large dictionaries, we want to filter all content that is already translated\n *\n * targetLocale: fr\n *\n * { test1: t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' } }) -> {}\n * { test2: t({ ar: 'Hello', en: 'Hello' }) } -> { test2: t({ ar: 'Hello', en: 'Hello' }) }\n *\n */\n // Reset to base dictionary for each locale to ensure we filter from the original\n let dictionaryToProcess = structuredClone(baseUnmergedDictionary);\n\n let targetLocaleDictionary: Dictionary;\n\n if (typeof baseUnmergedDictionary.locale === 'string') {\n // For per-locale files, the content is already in simple JSON format (not translation nodes)\n // The base dictionary is already the source locale content\n\n // Load the existing target locale dictionary\n const targetLocaleFilePath =\n baseUnmergedDictionary.filePath?.replace(\n new RegExp(`/${task.sourceLocale}/`, 'g'),\n `/${targetLocale}/`\n );\n\n // Find the target locale dictionary in unmerged dictionaries\n const targetUnmergedDictionary = targetLocaleFilePath\n ? unmergedDictionariesRecord[task.dictionaryKey]?.find(\n (dict) =>\n dict.filePath === targetLocaleFilePath &&\n dict.locale === targetLocale\n )\n : undefined;\n\n targetLocaleDictionary = targetUnmergedDictionary ?? {\n key: baseUnmergedDictionary.key,\n content: {},\n filePath: targetLocaleFilePath,\n locale: targetLocale,\n };\n\n // In complete mode, filter out already translated content\n if (mode === 'complete') {\n dictionaryToProcess = getFilterMissingContentPerLocale(\n dictionaryToProcess,\n targetUnmergedDictionary\n );\n }\n } else {\n // For multilingual dictionaries\n if (mode === 'complete') {\n // Remove all nodes that don't have any content to translate\n dictionaryToProcess = getFilterMissingTranslationsDictionary(\n dictionaryToProcess,\n targetLocale\n );\n }\n\n dictionaryToProcess = getPerLocaleDictionary(\n dictionaryToProcess,\n task.sourceLocale\n );\n\n targetLocaleDictionary = getPerLocaleDictionary(\n baseUnmergedDictionary,\n targetLocale\n );\n }\n\n const localePreset = colon(\n [\n colorize('[', ANSIColors.GREY_DARK),\n formatLocale(targetLocale),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: 18 }\n );\n\n const createChunkPreset = (\n chunkIndex: number,\n totalChunks: number\n ) => {\n if (totalChunks <= 1) return '';\n return colon(\n [\n colorize('[', ANSIColors.GREY_DARK),\n colorizeNumber(chunkIndex + 1),\n colorize(`/${totalChunks}`, ANSIColors.GREY_DARK),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: 5 }\n );\n };\n\n appLogger(\n `${task.dictionaryPreset}${localePreset} Preparing ${colorizePath(basename(targetLocaleDictionary.filePath!))}`,\n {\n level: 'info',\n }\n );\n\n const isContentStructured =\n (typeof dictionaryToProcess.content === 'object' &&\n dictionaryToProcess.content !== null) ||\n Array.isArray(dictionaryToProcess.content);\n\n const rawContentToProcess = isContentStructured\n ? dictionaryToProcess.content\n : {\n __INTLAYER_ROOT_PRIMITIVE_CONTENT__:\n dictionaryToProcess.content,\n };\n\n // Strip null values before sending to AI — nulls need no translation\n // and confuse the model. They will be re-injected after merging.\n const { content: contentToProcess, nulls: strippedNullValues } =\n stripNullValues(rawContentToProcess);\n\n const chunkedJsonContent: JsonChunk[] = chunkJSON(\n contentToProcess as unknown as Record<string, any>,\n CHUNK_SIZE\n );\n\n const nbOfChunks = chunkedJsonContent.length;\n\n if (nbOfChunks > 1) {\n appLogger(\n `${task.dictionaryPreset}${localePreset} Split into ${colorizeNumber(nbOfChunks)} chunks for translation`,\n {\n level: 'info',\n }\n );\n }\n\n const chunkResult: JsonChunk[] = [];\n\n // Process chunks in parallel (globally throttled) to allow concurrent translation\n const chunkPromises = chunkedJsonContent.map((chunk) => {\n const chunkPreset = createChunkPreset(chunk.index, chunk.total);\n\n if (nbOfChunks > 1) {\n appLogger(\n `${task.dictionaryPreset}${localePreset}${chunkPreset} Translating chunk`,\n {\n level: 'info',\n }\n );\n }\n\n // Reconstruct partial JSON content from this chunk's patches\n const chunkContent = reconstructFromSingleChunk(chunk);\n const presetOutputContent = reduceObjectFormat(\n isContentStructured\n ? targetLocaleDictionary.content\n : {\n __INTLAYER_ROOT_PRIMITIVE_CONTENT__:\n targetLocaleDictionary.content,\n },\n chunkContent\n ) as unknown as JSON;\n\n const executeTranslation = async () => {\n return await retryManager(\n async () => {\n let translationResult: any;\n\n if (aiClient && aiConfig) {\n translationResult = await aiClient.translateJSON({\n entryFileContent: chunkContent as unknown as JSON,\n presetOutputContent,\n dictionaryDescription:\n dictionaryToProcess.description ??\n metadata?.description ??\n '',\n entryLocale: task.sourceLocale,\n outputLocale: targetLocale,\n mode,\n aiConfig,\n });\n } else {\n translationResult = await intlayerAPI.ai\n .translateJSON({\n entryFileContent: chunkContent as unknown as JSON,\n presetOutputContent,\n dictionaryDescription:\n dictionaryToProcess.description ??\n metadata?.description ??\n '',\n entryLocale: task.sourceLocale,\n outputLocale: targetLocale,\n mode,\n aiOptions,\n })\n .then((result) => result.data);\n }\n\n if (!translationResult?.fileContent) {\n throw new Error('No content result');\n }\n\n const { isIdentic } = verifyIdenticObjectFormat(\n translationResult.fileContent,\n chunkContent\n );\n\n if (!isIdentic) {\n throw new Error(\n 'Translation result does not match expected format'\n );\n }\n\n notifySuccess();\n return translationResult.fileContent;\n },\n {\n maxRetry: MAX_RETRY,\n delay: RETRY_DELAY,\n onError: ({ error, attempt, maxRetry }) => {\n const chunkPreset = createChunkPreset(\n chunk.index,\n chunk.total\n );\n appLogger(\n `${task.dictionaryPreset}${localePreset}${chunkPreset} ${colorize('Error filling:', ANSIColors.RED)} ${colorize(typeof error === 'string' ? error : JSON.stringify(error), ANSIColors.GREY_DARK)} - Attempt ${colorizeNumber(attempt + 1)} of ${colorizeNumber(maxRetry)}`,\n {\n level: 'error',\n }\n );\n\n followingErrors += 1;\n\n if (followingErrors >= MAX_FOLLOWING_ERRORS) {\n appLogger(`There is something wrong.`, {\n level: 'error',\n });\n process.exit(1); // 1 for error\n }\n },\n }\n )();\n };\n\n const wrapped = options?.onHandle\n ? options.onHandle(executeTranslation) // queued in global limiter\n : executeTranslation(); // no global limiter\n\n return wrapped.then((result) => ({ chunk, result }));\n });\n\n // Wait for all chunks for this locale in parallel (still capped by global limiter)\n const chunkResults = await Promise.all(chunkPromises);\n\n // Maintain order\n chunkResults\n .sort((chunkA, chunkB) => chunkA.chunk.index - chunkB.chunk.index)\n .forEach(({ result }) => {\n chunkResult.push(result);\n });\n\n // Merge partial JSON objects produced from each chunk into a single object\n let mergedContent = mergeChunks(chunkResult);\n\n // Re-inject null values that were stripped before AI translation\n if (strippedNullValues) {\n mergedContent = deepMergeContent(mergedContent, strippedNullValues);\n }\n\n const merged = {\n ...dictionaryToProcess,\n content: mergedContent,\n };\n\n // For per-locale files, merge the newly translated content with existing target content\n let finalContent = merged.content;\n\n if (!isContentStructured) {\n finalContent = (finalContent as any)\n ?.__INTLAYER_ROOT_PRIMITIVE_CONTENT__;\n }\n\n if (typeof baseUnmergedDictionary.locale === 'string') {\n // Deep merge: existing content + newly translated content\n finalContent = deepMergeContent(\n targetLocaleDictionary.content ?? {},\n finalContent\n );\n }\n\n return [targetLocale, finalContent] as const;\n })\n );\n\n const translatedContent: Partial<Record<Locale, Dictionary['content']>> =\n Object.fromEntries(translatedContentResults);\n\n const baseDictionary = baseUnmergedDictionary.locale\n ? {\n ...baseUnmergedDictionary,\n key: baseUnmergedDictionary.key!,\n content: {},\n }\n : baseUnmergedDictionary;\n\n let dictionaryOutput: Dictionary = {\n ...getMultilingualDictionary(baseDictionary),\n locale: undefined, // Ensure the dictionary is multilingual\n ...metadata,\n };\n\n for (const targetLocale of task.targetLocales) {\n if (translatedContent[targetLocale]) {\n dictionaryOutput = insertContentInDictionary(\n dictionaryOutput,\n translatedContent[targetLocale],\n targetLocale\n );\n }\n }\n\n appLogger(\n `${task.dictionaryPreset} ${colorize('Translation completed successfully', ANSIColors.GREEN)} for ${colorizePath(basename(dictionaryOutput.filePath!))}`,\n {\n level: 'info',\n }\n );\n\n if (\n baseUnmergedDictionary.locale &&\n (baseUnmergedDictionary.fill === true ||\n baseUnmergedDictionary.fill === undefined) &&\n baseUnmergedDictionary.location === 'local'\n ) {\n const dictionaryFilePath = baseUnmergedDictionary\n .filePath!.split('.')\n .slice(0, -1);\n\n const contentIndex = dictionaryFilePath[dictionaryFilePath.length - 1];\n\n return JSON.parse(\n JSON.stringify({\n ...task,\n dictionaryOutput: {\n ...dictionaryOutput,\n fill: undefined,\n filled: true,\n },\n }).replaceAll(\n new RegExp(`\\\\.${contentIndex}\\\\.[a-zA-Z0-9]+`, 'g'),\n `.filled.${contentIndex}.json`\n )\n );\n }\n\n return {\n ...task,\n dictionaryOutput,\n };\n },\n {\n maxRetry: GROUP_MAX_RETRY,\n delay: RETRY_DELAY,\n onError: ({ error, attempt, maxRetry }) =>\n appLogger(\n `${task.dictionaryPreset} ${colorize('Error:', ANSIColors.RED)} ${colorize(typeof error === 'string' ? error : JSON.stringify(error), ANSIColors.GREY_DARK)} - Attempt ${colorizeNumber(attempt + 1)} of ${colorizeNumber(maxRetry)}`,\n {\n level: 'error',\n }\n ),\n onMaxTryReached: ({ error }) =>\n appLogger(\n `${task.dictionaryPreset} ${colorize('Maximum number of retries reached:', ANSIColors.RED)} ${colorize(typeof error === 'string' ? error : JSON.stringify(error), ANSIColors.GREY_DARK)}`,\n {\n level: 'error',\n }\n ),\n }\n )();\n\n return result as TranslateDictionaryResult;\n};\n"],"mappings":"k1BAsDA,MAAM,EAAsB,GAC1B,CAAC,EAAW,aAAe,CAAC,EAAW,OAAS,CAAC,EAAW,KAOxD,EACJ,GACoD,CACpD,GAAI,OAAO,GAAQ,WAAY,GAAgB,MAAM,QAAQ,EAAI,CAC/D,MAAO,CAAE,QAAS,EAAK,MAAO,IAAA,GAAW,SAAU,GAAO,CAG5D,IAAM,EAAe,EAAE,CACjB,EAAa,EAAE,CACjB,EAAW,GAEf,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,EAAI,CAC5C,GAAI,IAAU,KACZ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,EAAqB,EACxB,SAAU,MAAM,IAAI,CACpB,MAAM,EAAG,GAAG,CAET,EAAe,EAAmB,EAAmB,OAAS,GAEpE,OAAO,KAAK,MACV,KAAK,UAAU,CACb,GAAG,EACH,iBAAkB,CAChB,GAAG,EACH,KAAM,IAAA,GACN,OAAQ,GACT,CACF,CAAC,CAAC,WACG,OAAO,MAAM,EAAa,iBAAkB,IAAI,CACpD,WAAW,EAAa,OACzB,CACF,CAGH,MAAO,CACL,GAAG,EACH,mBACD,EAEH,CACE,SAAU,EACV,MAAO,EACP,SAAU,CAAE,QAAO,UAAS,cAC1B,EACE,GAAG,EAAK,iBAAiB,GAAG,EAAS,SAAU,EAAW,IAAI,CAAC,GAAG,EAAS,OAAO,GAAU,SAAW,EAAQ,KAAK,UAAU,EAAM,CAAE,EAAW,UAAU,CAAC,aAAa,EAAe,EAAU,EAAE,CAAC,MAAM,EAAe,EAAS,GACnO,CACE,MAAO,QACR,CACF,CACH,iBAAkB,CAAE,WAClB,EACE,GAAG,EAAK,iBAAiB,GAAG,EAAS,qCAAsC,EAAW,IAAI,CAAC,GAAG,EAAS,OAAO,GAAU,SAAW,EAAQ,KAAK,UAAU,EAAM,CAAE,EAAW,UAAU,GACvL,CACE,MAAO,QACR,CACF,CACJ,CACF,EAAE"}
1
+ {"version":3,"file":"translateDictionary.mjs","names":[],"sources":["../../../src/fill/translateDictionary.ts"],"sourcesContent":["import { basename } from 'node:path';\nimport type { AIConfig } from '@intlayer/ai';\nimport { type AIOptions, getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n chunkJSON,\n formatLocale,\n type JsonChunk,\n mergeChunks,\n reconstructFromSingleChunk,\n reduceObjectFormat,\n verifyIdenticObjectFormat,\n} from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colon,\n colorize,\n colorizeNumber,\n colorizePath,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { retryManager } from '@intlayer/config/utils';\nimport {\n getFilterMissingTranslationsDictionary,\n getMultilingualDictionary,\n getPerLocaleDictionary,\n insertContentInDictionary,\n} from '@intlayer/core/plugins';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport type { AIClient } from '../utils/setupAI';\nimport { deepMergeContent } from './deepMergeContent';\nimport { getFilterMissingContentPerLocale } from './getFilterMissingContentPerLocale';\nimport type { TranslationTask } from './listTranslationsTasks';\n\ntype TranslateDictionaryResult = TranslationTask & {\n dictionaryOutput: Dictionary | null;\n};\n\ntype TranslateDictionaryOptions = {\n mode: 'complete' | 'review';\n aiOptions?: AIOptions;\n fillMetadata?: boolean;\n onHandle?: ReturnType<\n typeof import('@intlayer/chokidar/utils').getGlobalLimiter\n >;\n onSuccess?: () => void;\n onError?: (error: unknown) => void;\n getAbortError?: () => Error | null;\n aiClient?: AIClient;\n aiConfig?: AIConfig;\n};\n\nconst hasMissingMetadata = (dictionary: Dictionary) =>\n !dictionary.description || !dictionary.title || !dictionary.tags;\n\n/**\n * Recursively strips null values from an object, returning the cleaned content\n * and a separate object containing only the null-valued paths so they can be\n * re-injected after AI translation (nulls don't need translation).\n */\nconst stripNullValues = (\n obj: any\n): { content: any; nulls: any; hasNulls: boolean } => {\n if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {\n return { content: obj, nulls: undefined, hasNulls: false };\n }\n\n const content: any = {};\n const nulls: any = {};\n let hasNulls = false;\n\n for (const [key, value] of Object.entries(obj)) {\n if (value === null) {\n nulls[key] = null;\n hasNulls = true;\n } else {\n const child = stripNullValues(value);\n content[key] = child.content;\n if (child.hasNulls) {\n nulls[key] = child.nulls;\n hasNulls = true;\n }\n }\n }\n\n return { content, nulls: hasNulls ? nulls : undefined, hasNulls };\n};\n\nconst CHUNK_SIZE = 7000; // GPT-5 Mini safe input size\nconst GROUP_MAX_RETRY = 2;\nconst MAX_RETRY = 3;\nconst RETRY_DELAY = 1000 * 10; // 10 seconds\n\nconst MAX_FOLLOWING_ERRORS = 10; // 10 errors in a row, hard exit the process\nlet followingErrors = 0;\n\nexport const translateDictionary = async (\n task: TranslationTask,\n configuration: IntlayerConfig,\n options?: TranslateDictionaryOptions\n): Promise<TranslateDictionaryResult> => {\n const appLogger = getAppLogger(configuration);\n const intlayerAPI = getIntlayerAPIProxy(undefined, configuration);\n\n const { mode, aiOptions, fillMetadata, aiClient, aiConfig } = {\n mode: 'complete',\n fillMetadata: true,\n ...options,\n } as const;\n\n const notifySuccess = () => {\n followingErrors = 0;\n options?.onSuccess?.();\n };\n\n const result = await retryManager(\n async () => {\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n\n const baseUnmergedDictionary: Dictionary | undefined =\n unmergedDictionariesRecord[task.dictionaryKey].find(\n (dict) => dict.localId === task.dictionaryLocalId\n );\n\n if (!baseUnmergedDictionary) {\n appLogger(\n `${task.dictionaryPreset}Dictionary not found in unmergedDictionariesRecord. Skipping.`,\n {\n level: 'warn',\n }\n );\n return { ...task, dictionaryOutput: null };\n }\n\n let metadata:\n | Pick<Dictionary, 'description' | 'title' | 'tags'>\n | undefined;\n\n if (\n fillMetadata &&\n (hasMissingMetadata(baseUnmergedDictionary) || mode === 'review')\n ) {\n const defaultLocaleDictionary = getPerLocaleDictionary(\n baseUnmergedDictionary,\n configuration.internationalization.defaultLocale\n );\n\n appLogger(\n `${task.dictionaryPreset} Filling missing metadata for ${colorizePath(basename(baseUnmergedDictionary.filePath!))}`,\n {\n level: 'info',\n }\n );\n\n const runAudit = async () => {\n if (aiClient && aiConfig) {\n const result = await aiClient.auditDictionaryMetadata({\n fileContent: JSON.stringify(defaultLocaleDictionary),\n aiConfig,\n });\n\n return {\n data: result,\n };\n }\n\n return await intlayerAPI.ai.auditContentDeclarationMetadata({\n fileContent: JSON.stringify(defaultLocaleDictionary),\n aiOptions,\n });\n };\n\n const metadataResult = options?.onHandle\n ? await options.onHandle(runAudit)\n : await runAudit();\n\n metadata = metadataResult.data?.fileContent;\n }\n\n const translatedContentResults = await Promise.all(\n task.targetLocales.map(async (targetLocale) => {\n /**\n * In complete mode, for large dictionaries, we want to filter all content that is already translated\n *\n * targetLocale: fr\n *\n * { test1: t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' } }) -> {}\n * { test2: t({ ar: 'Hello', en: 'Hello' }) } -> { test2: t({ ar: 'Hello', en: 'Hello' }) }\n *\n */\n // Reset to base dictionary for each locale to ensure we filter from the original\n let dictionaryToProcess = structuredClone(baseUnmergedDictionary);\n\n let targetLocaleDictionary: Dictionary;\n\n if (typeof baseUnmergedDictionary.locale === 'string') {\n // For per-locale files, the content is already in simple JSON format (not translation nodes)\n // The base dictionary is already the source locale content\n\n // Load the existing target locale dictionary\n const targetLocaleFilePath =\n baseUnmergedDictionary.filePath?.replace(\n new RegExp(`/${task.sourceLocale}/`, 'g'),\n `/${targetLocale}/`\n );\n\n // Find the target locale dictionary in unmerged dictionaries\n const targetUnmergedDictionary = targetLocaleFilePath\n ? unmergedDictionariesRecord[task.dictionaryKey]?.find(\n (dict) =>\n dict.filePath === targetLocaleFilePath &&\n dict.locale === targetLocale\n )\n : undefined;\n\n targetLocaleDictionary = targetUnmergedDictionary ?? {\n key: baseUnmergedDictionary.key,\n content: {},\n filePath: targetLocaleFilePath,\n locale: targetLocale,\n };\n\n // In complete mode, filter out already translated content\n if (mode === 'complete') {\n dictionaryToProcess = getFilterMissingContentPerLocale(\n dictionaryToProcess,\n targetUnmergedDictionary\n );\n }\n } else {\n // For multilingual dictionaries\n if (mode === 'complete') {\n // Remove all nodes that don't have any content to translate\n dictionaryToProcess = getFilterMissingTranslationsDictionary(\n dictionaryToProcess,\n targetLocale\n );\n }\n\n dictionaryToProcess = getPerLocaleDictionary(\n dictionaryToProcess,\n task.sourceLocale\n );\n\n targetLocaleDictionary = getPerLocaleDictionary(\n baseUnmergedDictionary,\n targetLocale\n );\n }\n\n const localePreset = colon(\n [\n colorize('[', ANSIColors.GREY_DARK),\n formatLocale(targetLocale),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: 18 }\n );\n\n const createChunkPreset = (\n chunkIndex: number,\n totalChunks: number\n ) => {\n if (totalChunks <= 1) return '';\n return colon(\n [\n colorize('[', ANSIColors.GREY_DARK),\n colorizeNumber(chunkIndex + 1),\n colorize(`/${totalChunks}`, ANSIColors.GREY_DARK),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: 5 }\n );\n };\n\n appLogger(\n `${task.dictionaryPreset}${localePreset} Preparing ${colorizePath(basename(targetLocaleDictionary.filePath!))}`,\n {\n level: 'info',\n }\n );\n\n const isContentStructured =\n (typeof dictionaryToProcess.content === 'object' &&\n dictionaryToProcess.content !== null) ||\n Array.isArray(dictionaryToProcess.content);\n\n const rawContentToProcess = isContentStructured\n ? dictionaryToProcess.content\n : {\n __INTLAYER_ROOT_PRIMITIVE_CONTENT__:\n dictionaryToProcess.content,\n };\n\n // Strip null values before sending to AI — nulls need no translation\n // and confuse the model. They will be re-injected after merging.\n const { content: contentToProcess, nulls: strippedNullValues } =\n stripNullValues(rawContentToProcess);\n\n const chunkedJsonContent: JsonChunk[] = chunkJSON(\n contentToProcess as unknown as Record<string, any>,\n CHUNK_SIZE\n );\n\n const nbOfChunks = chunkedJsonContent.length;\n\n if (nbOfChunks > 1) {\n appLogger(\n `${task.dictionaryPreset}${localePreset} Split into ${colorizeNumber(nbOfChunks)} chunks for translation`,\n {\n level: 'info',\n }\n );\n }\n\n const chunkResult: JsonChunk[] = [];\n\n // Process chunks in parallel (globally throttled) to allow concurrent translation\n const chunkPromises = chunkedJsonContent.map((chunk) => {\n const chunkPreset = createChunkPreset(chunk.index, chunk.total);\n\n if (nbOfChunks > 1) {\n appLogger(\n `${task.dictionaryPreset}${localePreset}${chunkPreset} Translating chunk`,\n {\n level: 'info',\n }\n );\n }\n\n // Reconstruct partial JSON content from this chunk's patches\n const chunkContent = reconstructFromSingleChunk(chunk);\n const presetOutputContent = reduceObjectFormat(\n isContentStructured\n ? targetLocaleDictionary.content\n : {\n __INTLAYER_ROOT_PRIMITIVE_CONTENT__:\n targetLocaleDictionary.content,\n },\n chunkContent\n ) as unknown as JSON;\n\n const executeTranslation = async () => {\n return await retryManager(\n async () => {\n let translationResult: any;\n\n if (aiClient && aiConfig) {\n translationResult = await aiClient.translateJSON({\n entryFileContent: chunkContent as unknown as JSON,\n presetOutputContent,\n dictionaryDescription:\n dictionaryToProcess.description ??\n metadata?.description ??\n '',\n entryLocale: task.sourceLocale,\n outputLocale: targetLocale,\n mode,\n aiConfig,\n });\n } else {\n translationResult = await intlayerAPI.ai\n .translateJSON({\n entryFileContent: chunkContent as unknown as JSON,\n presetOutputContent,\n dictionaryDescription:\n dictionaryToProcess.description ??\n metadata?.description ??\n '',\n entryLocale: task.sourceLocale,\n outputLocale: targetLocale,\n mode,\n aiOptions,\n })\n .then((result) => result.data);\n }\n\n if (!translationResult?.fileContent) {\n throw new Error('No content result');\n }\n\n const { isIdentic } = verifyIdenticObjectFormat(\n translationResult.fileContent,\n chunkContent\n );\n\n if (!isIdentic) {\n throw new Error(\n 'Translation result does not match expected format'\n );\n }\n\n notifySuccess();\n return translationResult.fileContent;\n },\n {\n maxRetry: MAX_RETRY,\n delay: RETRY_DELAY,\n onError: ({ error, attempt, maxRetry }) => {\n const chunkPreset = createChunkPreset(\n chunk.index,\n chunk.total\n );\n appLogger(\n `${task.dictionaryPreset}${localePreset}${chunkPreset} ${colorize('Error filling:', ANSIColors.RED)} ${colorize(typeof error === 'string' ? error : JSON.stringify(error), ANSIColors.GREY_DARK)} - Attempt ${colorizeNumber(attempt + 1)} of ${colorizeNumber(maxRetry)}`,\n {\n level: 'error',\n }\n );\n\n followingErrors += 1;\n\n if (followingErrors >= MAX_FOLLOWING_ERRORS) {\n appLogger(`There is something wrong.`, {\n level: 'error',\n });\n process.exit(1); // 1 for error\n }\n },\n }\n )();\n };\n\n const wrapped = options?.onHandle\n ? options.onHandle(executeTranslation) // queued in global limiter\n : executeTranslation(); // no global limiter\n\n return wrapped.then((result) => ({ chunk, result }));\n });\n\n // Wait for all chunks for this locale in parallel (still capped by global limiter)\n const chunkResults = await Promise.all(chunkPromises);\n\n // Maintain order\n chunkResults\n .sort((chunkA, chunkB) => chunkA.chunk.index - chunkB.chunk.index)\n .forEach(({ result }) => {\n chunkResult.push(result);\n });\n\n // Merge partial JSON objects produced from each chunk into a single object\n let mergedContent = mergeChunks(chunkResult);\n\n // Re-inject null values that were stripped before AI translation\n if (strippedNullValues) {\n mergedContent = deepMergeContent(mergedContent, strippedNullValues);\n }\n\n const merged = {\n ...dictionaryToProcess,\n content: mergedContent,\n };\n\n // For per-locale files, merge the newly translated content with existing target content\n let finalContent = merged.content;\n\n if (!isContentStructured) {\n finalContent = (finalContent as any)\n ?.__INTLAYER_ROOT_PRIMITIVE_CONTENT__;\n }\n\n if (typeof baseUnmergedDictionary.locale === 'string') {\n // Deep merge: existing content + newly translated content\n finalContent = deepMergeContent(\n targetLocaleDictionary.content ?? {},\n finalContent\n );\n }\n\n return [targetLocale, finalContent] as const;\n })\n );\n\n const translatedContent: Partial<Record<Locale, Dictionary['content']>> =\n Object.fromEntries(translatedContentResults);\n\n const baseDictionary = baseUnmergedDictionary.locale\n ? {\n ...baseUnmergedDictionary,\n key: baseUnmergedDictionary.key!,\n content: {},\n }\n : baseUnmergedDictionary;\n\n let dictionaryOutput: Dictionary = {\n ...getMultilingualDictionary(baseDictionary),\n locale: undefined, // Ensure the dictionary is multilingual\n ...metadata,\n };\n\n for (const targetLocale of task.targetLocales) {\n if (translatedContent[targetLocale]) {\n dictionaryOutput = insertContentInDictionary(\n dictionaryOutput,\n translatedContent[targetLocale],\n targetLocale\n );\n }\n }\n\n appLogger(\n `${task.dictionaryPreset} ${colorize('Translation completed successfully', ANSIColors.GREEN)} for ${colorizePath(basename(dictionaryOutput.filePath!))}`,\n {\n level: 'info',\n }\n );\n\n if (\n baseUnmergedDictionary.locale &&\n (baseUnmergedDictionary.fill === true ||\n baseUnmergedDictionary.fill === undefined) &&\n baseUnmergedDictionary.location === 'local'\n ) {\n const dictionaryFilePath = baseUnmergedDictionary\n .filePath!.split('.')\n .slice(0, -1);\n\n const contentIndex = dictionaryFilePath[dictionaryFilePath.length - 1];\n\n return JSON.parse(\n JSON.stringify({\n ...task,\n dictionaryOutput: {\n ...dictionaryOutput,\n fill: undefined,\n filled: true,\n },\n }).replaceAll(\n new RegExp(`\\\\.${contentIndex}\\\\.[a-zA-Z0-9]+`, 'g'),\n `.filled.${contentIndex}.json`\n )\n );\n }\n\n return {\n ...task,\n dictionaryOutput,\n };\n },\n {\n maxRetry: GROUP_MAX_RETRY,\n delay: RETRY_DELAY,\n onError: ({ error, attempt, maxRetry }) =>\n appLogger(\n `${task.dictionaryPreset} ${colorize('Error:', ANSIColors.RED)} ${colorize(typeof error === 'string' ? error : JSON.stringify(error), ANSIColors.GREY_DARK)} - Attempt ${colorizeNumber(attempt + 1)} of ${colorizeNumber(maxRetry)}`,\n {\n level: 'error',\n }\n ),\n onMaxTryReached: ({ error }) =>\n appLogger(\n `${task.dictionaryPreset} ${colorize('Maximum number of retries reached:', ANSIColors.RED)} ${colorize(typeof error === 'string' ? error : JSON.stringify(error), ANSIColors.GREY_DARK)}`,\n {\n level: 'error',\n }\n ),\n }\n )();\n\n return result as TranslateDictionaryResult;\n};\n"],"mappings":"42BAsDA,MAAM,EAAsB,GAC1B,CAAC,EAAW,aAAe,CAAC,EAAW,OAAS,CAAC,EAAW,KAOxD,EACJ,GACoD,CACpD,GAAI,OAAO,GAAQ,WAAY,GAAgB,MAAM,QAAQ,EAAI,CAC/D,MAAO,CAAE,QAAS,EAAK,MAAO,IAAA,GAAW,SAAU,GAAO,CAG5D,IAAM,EAAe,EAAE,CACjB,EAAa,EAAE,CACjB,EAAW,GAEf,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,EAAI,CAC5C,GAAI,IAAU,KACZ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,EAAqB,EACxB,SAAU,MAAM,IAAI,CACpB,MAAM,EAAG,GAAG,CAET,EAAe,EAAmB,EAAmB,OAAS,GAEpE,OAAO,KAAK,MACV,KAAK,UAAU,CACb,GAAG,EACH,iBAAkB,CAChB,GAAG,EACH,KAAM,IAAA,GACN,OAAQ,GACT,CACF,CAAC,CAAC,WACG,OAAO,MAAM,EAAa,iBAAkB,IAAI,CACpD,WAAW,EAAa,OACzB,CACF,CAGH,MAAO,CACL,GAAG,EACH,mBACD,EAEH,CACE,SAAU,EACV,MAAO,EACP,SAAU,CAAE,QAAO,UAAS,cAC1B,EACE,GAAG,EAAK,iBAAiB,GAAG,EAAS,SAAU,EAAW,IAAI,CAAC,GAAG,EAAS,OAAO,GAAU,SAAW,EAAQ,KAAK,UAAU,EAAM,CAAE,EAAW,UAAU,CAAC,aAAa,EAAe,EAAU,EAAE,CAAC,MAAM,EAAe,EAAS,GACnO,CACE,MAAO,QACR,CACF,CACH,iBAAkB,CAAE,WAClB,EACE,GAAG,EAAK,iBAAiB,GAAG,EAAS,qCAAsC,EAAW,IAAI,CAAC,GAAG,EAAS,OAAO,GAAU,SAAW,EAAQ,KAAK,UAAU,EAAM,CAAE,EAAW,UAAU,GACvL,CACE,MAAO,QACR,CACF,CACJ,CACF,EAAE"}
package/dist/esm/pull.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{checkCMSAuth as e}from"./utils/checkAccess.mjs";import{PullLogger as t}from"./push/pullLog.mjs";import{existsSync as n}from"node:fs";import{join as r}from"node:path";import{writeContentDeclaration as i}from"@intlayer/chokidar/build";import{logConfigDetails as a}from"@intlayer/chokidar/cli";import{parallelize as o}from"@intlayer/chokidar/utils";import{ANSIColors as s,getAppLogger as c}from"@intlayer/config/logger";import{getConfiguration as l}from"@intlayer/config/node";import{getUnmergedDictionaries as u}from"@intlayer/unmerged-dictionaries-entry";import{getIntlayerAPIProxy as d}from"@intlayer/api";import{getProjectRequire as f}from"@intlayer/config/utils";const p=async p=>{let m=c(p?.configOptions?.override);try{let c=l(p?.configOptions);if(a(p?.configOptions),!await e(c))return;let h=d(void 0,c),g=u(c),_=await h.dictionary.getDictionariesUpdateTimestamp();if(!_.data)throw Error(`No distant dictionaries found`);let v=_.data;p?.dictionaries&&(v=Object.fromEntries(Object.entries(v).filter(([e])=>p.dictionaries?.includes(e)))),v=Object.fromEntries(Object.entries(v).filter(([e])=>{let t=g[e]?.[0]?.location??c.dictionary?.location??`remote`;return t===`remote`||t===`hybrid`}));let y=r(c.system.mainDir,`remote_dictionaries.cjs`),b=c.build?.require??f(),x=n(y)?b(y):{},S=Object.entries(v),C=S.filter(([e,t])=>{if(!t)return!0;let n=typeof t==`object`?t.updatedAt:t,r=x[e];if(!r)return!0;let i=r?.updatedAt,a=typeof i==`number`?i:i?new Date(i).getTime():void 0;return typeof a==`number`?n>a:!0}).map(([e])=>e),w=S.filter(([e,t])=>{let n=typeof t==`object`?t.updatedAt:t,r=x[e]?.updatedAt,i=typeof r==`number`?r:r?new Date(r).getTime():void 0;return typeof i==`number`&&typeof n==`number`&&i>=n}).map(([e])=>e);if(S.length===0){m(`No dictionaries to fetch`,{level:`error`});return}m(`Fetching dictionaries:`);let T=[...w.map(e=>({dictionaryKey:e,status:`imported`})),...C.map(e=>({dictionaryKey:e,status:`pending`}))],E=new t;E.update(T.map(e=>({dictionaryKey:e.dictionaryKey,status:e.status})));let D=[];await o(T,async e=>{let t=e.status===`imported`||e.status===`up-to-date`;t||(e.status=`fetching`,E.update([{dictionaryKey:e.dictionaryKey,status:`fetching`}]));try{let n;if(t&&(n=x[e.dictionaryKey]),n||=(await h.dictionary.getDictionary(e.dictionaryKey)).data,!n)throw Error(`Dictionary ${e.dictionaryKey} not found on remote`);let r=g[e.dictionaryKey]?.find(e=>e.location===`hybrid`);r&&(n={...n,location:`hybrid`,filePath:r.filePath,localId:r.localId});let{status:a}=await i(n,c,p);e.status=a,E.update([{dictionaryKey:e.dictionaryKey,status:a}]),D.push(n)}catch(t){e.status=`error`,e.error=t,e.errorMessage=`Error fetching dictionary ${e.dictionaryKey}: ${t}`,E.update([{dictionaryKey:e.dictionaryKey,status:`error`}])}},5),E.finish();let O=e=>{switch(e){case`fetched`:case`imported`:case`updated`:case`up-to-date`:case`reimported in JSON`:case`new content file`:return`✔`;case`error`:return`✖`;default:return`⏲`}},k=e=>{switch(e){case`fetched`:case`imported`:case`updated`:case`up-to-date`:return s.GREEN;case`reimported in JSON`:case`new content file`:return s.YELLOW;case`error`:return s.RED;default:return s.BLUE}};for(let e of T){let t=O(e.status),n=k(e.status);m(` - ${e.dictionaryKey} ${s.GREY}[${n}${t} ${e.status}${s.GREY}]${s.RESET}`)}for(let e of T)e.errorMessage&&m(e.errorMessage,{level:`error`})}catch(e){m(e,{level:`error`})}};export{p as pull};
1
+ import{checkCMSAuth as e}from"./utils/checkAccess.mjs";import{PullLogger as t}from"./push/pullLog.mjs";import{existsSync as n}from"node:fs";import{join as r}from"node:path";import{writeContentDeclaration as i}from"@intlayer/chokidar/build";import{logConfigDetails as a}from"@intlayer/chokidar/cli";import{parallelize as o}from"@intlayer/chokidar/utils";import*as s from"@intlayer/config/colors";import{getAppLogger as c}from"@intlayer/config/logger";import{getConfiguration as l}from"@intlayer/config/node";import{getUnmergedDictionaries as u}from"@intlayer/unmerged-dictionaries-entry";import{getIntlayerAPIProxy as d}from"@intlayer/api";import{getProjectRequire as f}from"@intlayer/config/utils";const p=async p=>{let m=c(p?.configOptions?.override);try{let c=l(p?.configOptions);if(a(p?.configOptions),!await e(c))return;let h=d(void 0,c),g=u(c),_=await h.dictionary.getDictionariesUpdateTimestamp();if(!_.data)throw Error(`No distant dictionaries found`);let v=_.data;p?.dictionaries&&(v=Object.fromEntries(Object.entries(v).filter(([e])=>p.dictionaries?.includes(e)))),v=Object.fromEntries(Object.entries(v).filter(([e])=>{let t=g[e]?.[0]?.location??c.dictionary?.location??`remote`;return t===`remote`||t===`hybrid`}));let y=r(c.system.mainDir,`remote_dictionaries.cjs`),b=c.build?.require??f(),x=n(y)?b(y):{},S=Object.entries(v),C=S.filter(([e,t])=>{if(!t)return!0;let n=typeof t==`object`?t.updatedAt:t,r=x[e];if(!r)return!0;let i=r?.updatedAt,a=typeof i==`number`?i:i?new Date(i).getTime():void 0;return typeof a==`number`?n>a:!0}).map(([e])=>e),w=S.filter(([e,t])=>{let n=typeof t==`object`?t.updatedAt:t,r=x[e]?.updatedAt,i=typeof r==`number`?r:r?new Date(r).getTime():void 0;return typeof i==`number`&&typeof n==`number`&&i>=n}).map(([e])=>e);if(S.length===0){m(`No dictionaries to fetch`,{level:`error`});return}m(`Fetching dictionaries:`);let T=[...w.map(e=>({dictionaryKey:e,status:`imported`})),...C.map(e=>({dictionaryKey:e,status:`pending`}))],E=new t;E.update(T.map(e=>({dictionaryKey:e.dictionaryKey,status:e.status})));let D=[];await o(T,async e=>{let t=e.status===`imported`||e.status===`up-to-date`;t||(e.status=`fetching`,E.update([{dictionaryKey:e.dictionaryKey,status:`fetching`}]));try{let n;if(t&&(n=x[e.dictionaryKey]),n||=(await h.dictionary.getDictionary(e.dictionaryKey)).data,!n)throw Error(`Dictionary ${e.dictionaryKey} not found on remote`);let r=g[e.dictionaryKey]?.find(e=>e.location===`hybrid`);r&&(n={...n,location:`hybrid`,filePath:r.filePath,localId:r.localId});let{status:a}=await i(n,c,p);e.status=a,E.update([{dictionaryKey:e.dictionaryKey,status:a}]),D.push(n)}catch(t){e.status=`error`,e.error=t,e.errorMessage=`Error fetching dictionary ${e.dictionaryKey}: ${t}`,E.update([{dictionaryKey:e.dictionaryKey,status:`error`}])}},5),E.finish();let O=e=>{switch(e){case`fetched`:case`imported`:case`updated`:case`up-to-date`:case`reimported in JSON`:case`new content file`:return`✔`;case`error`:return`✖`;default:return`⏲`}},k=e=>{switch(e){case`fetched`:case`imported`:case`updated`:case`up-to-date`:return s.GREEN;case`reimported in JSON`:case`new content file`:return s.YELLOW;case`error`:return s.RED;default:return s.BLUE}};for(let e of T){let t=O(e.status),n=k(e.status);m(` - ${e.dictionaryKey} ${s.GREY}[${n}${t} ${e.status}${s.GREY}]${s.RESET}`)}for(let e of T)e.errorMessage&&m(e.errorMessage,{level:`error`})}catch(e){m(e,{level:`error`})}};export{p as pull};
2
2
  //# sourceMappingURL=pull.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"pull.mjs","names":[],"sources":["../../src/pull.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n type DictionaryStatus,\n writeContentDeclaration,\n} from '@intlayer/chokidar/build';\nimport { logConfigDetails } from '@intlayer/chokidar/cli';\nimport { parallelize } from '@intlayer/chokidar/utils';\nimport { ANSIColors, getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { getProjectRequire } from '@intlayer/config/utils';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport { PullLogger, type PullStatus } from './push/pullLog';\nimport { checkCMSAuth } from './utils/checkAccess';\n\ntype PullOptions = {\n dictionaries?: string[];\n newDictionariesPath?: string;\n configOptions?: GetConfigurationOptions;\n};\n\ntype DictionariesStatus = {\n dictionaryKey: string;\n status: DictionaryStatus | 'pending' | 'fetching' | 'error';\n error?: Error;\n errorMessage?: string;\n};\n\n/**\n * Fetch distant dictionaries and write them locally,\n * with progress indicators and concurrency control.\n */\nexport const pull = async (options?: PullOptions): Promise<void> => {\n const appLogger = getAppLogger(options?.configOptions?.override);\n\n try {\n const config = getConfiguration(options?.configOptions);\n logConfigDetails(options?.configOptions);\n\n const hasCMSAuth = await checkCMSAuth(config);\n\n if (!hasCMSAuth) return;\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, config);\n\n const unmergedDictionariesRecord = getUnmergedDictionaries(config);\n\n // Get remote update timestamps map\n const getDictionariesUpdateTimestampResult =\n await intlayerAPI.dictionary.getDictionariesUpdateTimestamp();\n\n if (!getDictionariesUpdateTimestampResult.data) {\n throw new Error('No distant dictionaries found');\n }\n\n let distantDictionariesUpdateTimeStamp: Record<string, any> =\n getDictionariesUpdateTimestampResult.data;\n\n // Optional filtering by requested dictionaries\n if (options?.dictionaries) {\n distantDictionariesUpdateTimeStamp = Object.fromEntries(\n Object.entries(distantDictionariesUpdateTimeStamp).filter(([key]) =>\n options.dictionaries?.includes(key)\n )\n );\n }\n\n // Filter by location\n distantDictionariesUpdateTimeStamp = Object.fromEntries(\n Object.entries(distantDictionariesUpdateTimeStamp).filter(([key]) => {\n const localDictionaries = unmergedDictionariesRecord[key];\n const location =\n localDictionaries?.[0]?.location ??\n config.dictionary?.location ??\n 'remote';\n\n return location === 'remote' || location === 'hybrid';\n })\n );\n\n // Load local cached remote dictionaries (if any)\n const remoteDictionariesPath = join(\n config.system.mainDir,\n 'remote_dictionaries.cjs'\n );\n const requireFunction = config.build?.require ?? getProjectRequire();\n const remoteDictionariesRecord: Record<string, any> = existsSync(\n remoteDictionariesPath\n )\n ? (requireFunction(remoteDictionariesPath) as any)\n : {};\n\n // Determine which keys need fetching by comparing updatedAt with local cache\n const entries = Object.entries(distantDictionariesUpdateTimeStamp);\n const keysToFetch = entries\n .filter(([key, remoteUpdatedAtValue]) => {\n if (!remoteUpdatedAtValue) return true;\n\n const remoteUpdatedAt =\n typeof remoteUpdatedAtValue === 'object'\n ? (remoteUpdatedAtValue as any).updatedAt\n : remoteUpdatedAtValue;\n\n const local = (remoteDictionariesRecord as any)[key];\n if (!local) return true;\n const localUpdatedAtRaw = (local as any)?.updatedAt as\n | number\n | string\n | undefined;\n const localUpdatedAt =\n typeof localUpdatedAtRaw === 'number'\n ? localUpdatedAtRaw\n : localUpdatedAtRaw\n ? new Date(localUpdatedAtRaw).getTime()\n : undefined;\n if (typeof localUpdatedAt !== 'number') return true;\n return remoteUpdatedAt > localUpdatedAt;\n })\n .map(([key]) => key);\n\n const cachedKeys = entries\n .filter(([key, remoteUpdatedAtValue]) => {\n const remoteUpdatedAt =\n typeof remoteUpdatedAtValue === 'object'\n ? (remoteUpdatedAtValue as any).updatedAt\n : remoteUpdatedAtValue;\n\n const local = (remoteDictionariesRecord as any)[key];\n const localUpdatedAtRaw = (local as any)?.updatedAt as\n | number\n | string\n | undefined;\n const localUpdatedAt =\n typeof localUpdatedAtRaw === 'number'\n ? localUpdatedAtRaw\n : localUpdatedAtRaw\n ? new Date(localUpdatedAtRaw).getTime()\n : undefined;\n return (\n typeof localUpdatedAt === 'number' &&\n typeof remoteUpdatedAt === 'number' &&\n localUpdatedAt >= remoteUpdatedAt\n );\n })\n .map(([key]) => key);\n\n // Check if dictionaries list is empty\n if (entries.length === 0) {\n appLogger('No dictionaries to fetch', {\n level: 'error',\n });\n return;\n }\n\n appLogger('Fetching dictionaries:');\n\n // Prepare dictionaries statuses\n const dictionariesStatuses: DictionariesStatus[] = [\n ...cachedKeys.map((dictionaryKey) => ({\n dictionaryKey,\n status: 'imported' as DictionaryStatus,\n })),\n ...keysToFetch.map((dictionaryKey) => ({\n dictionaryKey,\n status: 'pending' as const,\n })),\n ];\n\n // Initialize aggregated logger\n const logger = new PullLogger();\n logger.update(\n dictionariesStatuses.map<PullStatus>((s) => ({\n dictionaryKey: s.dictionaryKey,\n status: s.status,\n }))\n );\n\n const successfullyFetchedDictionaries: Dictionary[] = [];\n\n const processDictionary = async (\n statusObj: DictionariesStatus\n ): Promise<void> => {\n const isCached =\n statusObj.status === 'imported' || statusObj.status === 'up-to-date';\n\n if (!isCached) {\n statusObj.status = 'fetching';\n logger.update([\n { dictionaryKey: statusObj.dictionaryKey, status: 'fetching' },\n ]);\n }\n\n try {\n let sourceDictionary: Dictionary | undefined;\n\n if (isCached) {\n sourceDictionary = remoteDictionariesRecord[\n statusObj.dictionaryKey\n ] as Dictionary | undefined;\n }\n\n if (!sourceDictionary) {\n // Fetch the dictionary\n const getDictionaryResult =\n await intlayerAPI.dictionary.getDictionary(statusObj.dictionaryKey);\n\n sourceDictionary = getDictionaryResult.data as Dictionary | undefined;\n }\n\n if (!sourceDictionary) {\n throw new Error(\n `Dictionary ${statusObj.dictionaryKey} not found on remote`\n );\n }\n\n // Check if there is a local version of this dictionary that is hybrid\n const localDictionaries =\n unmergedDictionariesRecord[statusObj.dictionaryKey];\n const localAndRemoteDictionary = localDictionaries?.find(\n (d) => d.location === 'hybrid'\n );\n\n if (localAndRemoteDictionary) {\n // We want to preserve the local properties but use the remote content\n sourceDictionary = {\n ...sourceDictionary,\n location: 'hybrid',\n filePath: localAndRemoteDictionary.filePath,\n localId: localAndRemoteDictionary.localId,\n };\n }\n\n // Now, write the dictionary to local file\n const { status } = await writeContentDeclaration(\n sourceDictionary,\n config,\n options\n );\n\n statusObj.status = status;\n logger.update([{ dictionaryKey: statusObj.dictionaryKey, status }]);\n\n successfullyFetchedDictionaries.push(sourceDictionary);\n } catch (error) {\n statusObj.status = 'error';\n statusObj.error = error as Error;\n statusObj.errorMessage = `Error fetching dictionary ${statusObj.dictionaryKey}: ${error}`;\n logger.update([\n { dictionaryKey: statusObj.dictionaryKey, status: 'error' },\n ]);\n }\n };\n\n // Process dictionaries in parallel with concurrency limit\n await parallelize(dictionariesStatuses, processDictionary, 5);\n\n // Stop the logger and render final state\n logger.finish();\n\n // Per-dictionary summary\n const iconFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'fetched':\n case 'imported':\n case 'updated':\n case 'up-to-date':\n case 'reimported in JSON':\n case 'new content file':\n return '✔';\n case 'error':\n return '✖';\n default:\n return '⏲';\n }\n };\n\n const colorFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'fetched':\n case 'imported':\n case 'updated':\n case 'up-to-date':\n return ANSIColors.GREEN;\n case 'reimported in JSON':\n case 'new content file':\n return ANSIColors.YELLOW;\n case 'error':\n return ANSIColors.RED;\n default:\n return ANSIColors.BLUE;\n }\n };\n\n for (const s of dictionariesStatuses) {\n const icon = iconFor(s.status);\n const color = colorFor(s.status);\n appLogger(\n ` - ${s.dictionaryKey} ${ANSIColors.GREY}[${color}${icon} ${s.status}${ANSIColors.GREY}]${ANSIColors.RESET}`\n );\n }\n\n // Output any error messages\n for (const statusObj of dictionariesStatuses) {\n if (statusObj.errorMessage) {\n appLogger(statusObj.errorMessage, {\n level: 'error',\n });\n }\n }\n } catch (error) {\n appLogger(error, {\n level: 'error',\n });\n }\n};\n"],"mappings":"gqBAqCA,MAAa,EAAO,KAAO,IAAyC,CAClE,IAAM,EAAY,EAAa,GAAS,eAAe,SAAS,CAEhE,GAAI,CACF,IAAM,EAAS,EAAiB,GAAS,cAAc,CAKvD,GAJA,EAAiB,GAAS,cAAc,CAIpC,CAFe,MAAM,EAAa,EAAO,CAE5B,OAEjB,IAAM,EAAc,EAAoB,IAAA,GAAW,EAAO,CAEpD,EAA6B,EAAwB,EAAO,CAG5D,EACJ,MAAM,EAAY,WAAW,gCAAgC,CAE/D,GAAI,CAAC,EAAqC,KACxC,MAAU,MAAM,gCAAgC,CAGlD,IAAI,EACF,EAAqC,KAGnC,GAAS,eACX,EAAqC,OAAO,YAC1C,OAAO,QAAQ,EAAmC,CAAC,QAAQ,CAAC,KAC1D,EAAQ,cAAc,SAAS,EAAI,CACpC,CACF,EAIH,EAAqC,OAAO,YAC1C,OAAO,QAAQ,EAAmC,CAAC,QAAQ,CAAC,KAAS,CAEnE,IAAM,EADoB,EAA2B,KAE/B,IAAI,UACxB,EAAO,YAAY,UACnB,SAEF,OAAO,IAAa,UAAY,IAAa,UAC7C,CACH,CAGD,IAAM,EAAyB,EAC7B,EAAO,OAAO,QACd,0BACD,CACK,EAAkB,EAAO,OAAO,SAAW,GAAmB,CAC9D,EAAgD,EACpD,EACD,CACI,EAAgB,EAAuB,CACxC,EAAE,CAGA,EAAU,OAAO,QAAQ,EAAmC,CAC5D,EAAc,EACjB,QAAQ,CAAC,EAAK,KAA0B,CACvC,GAAI,CAAC,EAAsB,MAAO,GAElC,IAAM,EACJ,OAAO,GAAyB,SAC3B,EAA6B,UA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C,EAAO,CACd,EAAU,EAAO,CACf,MAAO,QACR,CAAC"}
1
+ {"version":3,"file":"pull.mjs","names":[],"sources":["../../src/pull.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n type DictionaryStatus,\n writeContentDeclaration,\n} from '@intlayer/chokidar/build';\nimport { logConfigDetails } from '@intlayer/chokidar/cli';\nimport { parallelize } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { getProjectRequire } from '@intlayer/config/utils';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport { PullLogger, type PullStatus } from './push/pullLog';\nimport { checkCMSAuth } from './utils/checkAccess';\n\ntype PullOptions = {\n dictionaries?: string[];\n newDictionariesPath?: string;\n configOptions?: GetConfigurationOptions;\n};\n\ntype DictionariesStatus = {\n dictionaryKey: string;\n status: DictionaryStatus | 'pending' | 'fetching' | 'error';\n error?: Error;\n errorMessage?: string;\n};\n\n/**\n * Fetch distant dictionaries and write them locally,\n * with progress indicators and concurrency control.\n */\nexport const pull = async (options?: PullOptions): Promise<void> => {\n const appLogger = getAppLogger(options?.configOptions?.override);\n\n try {\n const config = getConfiguration(options?.configOptions);\n logConfigDetails(options?.configOptions);\n\n const hasCMSAuth = await checkCMSAuth(config);\n\n if (!hasCMSAuth) return;\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, config);\n\n const unmergedDictionariesRecord = getUnmergedDictionaries(config);\n\n // Get remote update timestamps map\n const getDictionariesUpdateTimestampResult =\n await intlayerAPI.dictionary.getDictionariesUpdateTimestamp();\n\n if (!getDictionariesUpdateTimestampResult.data) {\n throw new Error('No distant dictionaries found');\n }\n\n let distantDictionariesUpdateTimeStamp: Record<string, any> =\n getDictionariesUpdateTimestampResult.data;\n\n // Optional filtering by requested dictionaries\n if (options?.dictionaries) {\n distantDictionariesUpdateTimeStamp = Object.fromEntries(\n Object.entries(distantDictionariesUpdateTimeStamp).filter(([key]) =>\n options.dictionaries?.includes(key)\n )\n );\n }\n\n // Filter by location\n distantDictionariesUpdateTimeStamp = Object.fromEntries(\n Object.entries(distantDictionariesUpdateTimeStamp).filter(([key]) => {\n const localDictionaries = unmergedDictionariesRecord[key];\n const location =\n localDictionaries?.[0]?.location ??\n config.dictionary?.location ??\n 'remote';\n\n return location === 'remote' || location === 'hybrid';\n })\n );\n\n // Load local cached remote dictionaries (if any)\n const remoteDictionariesPath = join(\n config.system.mainDir,\n 'remote_dictionaries.cjs'\n );\n const requireFunction = config.build?.require ?? getProjectRequire();\n const remoteDictionariesRecord: Record<string, any> = existsSync(\n remoteDictionariesPath\n )\n ? (requireFunction(remoteDictionariesPath) as any)\n : {};\n\n // Determine which keys need fetching by comparing updatedAt with local cache\n const entries = Object.entries(distantDictionariesUpdateTimeStamp);\n const keysToFetch = entries\n .filter(([key, remoteUpdatedAtValue]) => {\n if (!remoteUpdatedAtValue) return true;\n\n const remoteUpdatedAt =\n typeof remoteUpdatedAtValue === 'object'\n ? (remoteUpdatedAtValue as any).updatedAt\n : remoteUpdatedAtValue;\n\n const local = (remoteDictionariesRecord as any)[key];\n if (!local) return true;\n const localUpdatedAtRaw = (local as any)?.updatedAt as\n | number\n | string\n | undefined;\n const localUpdatedAt =\n typeof localUpdatedAtRaw === 'number'\n ? localUpdatedAtRaw\n : localUpdatedAtRaw\n ? new Date(localUpdatedAtRaw).getTime()\n : undefined;\n if (typeof localUpdatedAt !== 'number') return true;\n return remoteUpdatedAt > localUpdatedAt;\n })\n .map(([key]) => key);\n\n const cachedKeys = entries\n .filter(([key, remoteUpdatedAtValue]) => {\n const remoteUpdatedAt =\n typeof remoteUpdatedAtValue === 'object'\n ? (remoteUpdatedAtValue as any).updatedAt\n : remoteUpdatedAtValue;\n\n const local = (remoteDictionariesRecord as any)[key];\n const localUpdatedAtRaw = (local as any)?.updatedAt as\n | number\n | string\n | undefined;\n const localUpdatedAt =\n typeof localUpdatedAtRaw === 'number'\n ? localUpdatedAtRaw\n : localUpdatedAtRaw\n ? new Date(localUpdatedAtRaw).getTime()\n : undefined;\n return (\n typeof localUpdatedAt === 'number' &&\n typeof remoteUpdatedAt === 'number' &&\n localUpdatedAt >= remoteUpdatedAt\n );\n })\n .map(([key]) => key);\n\n // Check if dictionaries list is empty\n if (entries.length === 0) {\n appLogger('No dictionaries to fetch', {\n level: 'error',\n });\n return;\n }\n\n appLogger('Fetching dictionaries:');\n\n // Prepare dictionaries statuses\n const dictionariesStatuses: DictionariesStatus[] = [\n ...cachedKeys.map((dictionaryKey) => ({\n dictionaryKey,\n status: 'imported' as DictionaryStatus,\n })),\n ...keysToFetch.map((dictionaryKey) => ({\n dictionaryKey,\n status: 'pending' as const,\n })),\n ];\n\n // Initialize aggregated logger\n const logger = new PullLogger();\n logger.update(\n dictionariesStatuses.map<PullStatus>((s) => ({\n dictionaryKey: s.dictionaryKey,\n status: s.status,\n }))\n );\n\n const successfullyFetchedDictionaries: Dictionary[] = [];\n\n const processDictionary = async (\n statusObj: DictionariesStatus\n ): Promise<void> => {\n const isCached =\n statusObj.status === 'imported' || statusObj.status === 'up-to-date';\n\n if (!isCached) {\n statusObj.status = 'fetching';\n logger.update([\n { dictionaryKey: statusObj.dictionaryKey, status: 'fetching' },\n ]);\n }\n\n try {\n let sourceDictionary: Dictionary | undefined;\n\n if (isCached) {\n sourceDictionary = remoteDictionariesRecord[\n statusObj.dictionaryKey\n ] as Dictionary | undefined;\n }\n\n if (!sourceDictionary) {\n // Fetch the dictionary\n const getDictionaryResult =\n await intlayerAPI.dictionary.getDictionary(statusObj.dictionaryKey);\n\n sourceDictionary = getDictionaryResult.data as Dictionary | undefined;\n }\n\n if (!sourceDictionary) {\n throw new Error(\n `Dictionary ${statusObj.dictionaryKey} not found on remote`\n );\n }\n\n // Check if there is a local version of this dictionary that is hybrid\n const localDictionaries =\n unmergedDictionariesRecord[statusObj.dictionaryKey];\n const localAndRemoteDictionary = localDictionaries?.find(\n (d) => d.location === 'hybrid'\n );\n\n if (localAndRemoteDictionary) {\n // We want to preserve the local properties but use the remote content\n sourceDictionary = {\n ...sourceDictionary,\n location: 'hybrid',\n filePath: localAndRemoteDictionary.filePath,\n localId: localAndRemoteDictionary.localId,\n };\n }\n\n // Now, write the dictionary to local file\n const { status } = await writeContentDeclaration(\n sourceDictionary,\n config,\n options\n );\n\n statusObj.status = status;\n logger.update([{ dictionaryKey: statusObj.dictionaryKey, status }]);\n\n successfullyFetchedDictionaries.push(sourceDictionary);\n } catch (error) {\n statusObj.status = 'error';\n statusObj.error = error as Error;\n statusObj.errorMessage = `Error fetching dictionary ${statusObj.dictionaryKey}: ${error}`;\n logger.update([\n { dictionaryKey: statusObj.dictionaryKey, status: 'error' },\n ]);\n }\n };\n\n // Process dictionaries in parallel with concurrency limit\n await parallelize(dictionariesStatuses, processDictionary, 5);\n\n // Stop the logger and render final state\n logger.finish();\n\n // Per-dictionary summary\n const iconFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'fetched':\n case 'imported':\n case 'updated':\n case 'up-to-date':\n case 'reimported in JSON':\n case 'new content file':\n return '✔';\n case 'error':\n return '✖';\n default:\n return '⏲';\n }\n };\n\n const colorFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'fetched':\n case 'imported':\n case 'updated':\n case 'up-to-date':\n return ANSIColors.GREEN;\n case 'reimported in JSON':\n case 'new content file':\n return ANSIColors.YELLOW;\n case 'error':\n return ANSIColors.RED;\n default:\n return ANSIColors.BLUE;\n }\n };\n\n for (const s of dictionariesStatuses) {\n const icon = iconFor(s.status);\n const color = colorFor(s.status);\n appLogger(\n ` - ${s.dictionaryKey} ${ANSIColors.GREY}[${color}${icon} ${s.status}${ANSIColors.GREY}]${ANSIColors.RESET}`\n );\n }\n\n // Output any error messages\n for (const statusObj of dictionariesStatuses) {\n if (statusObj.errorMessage) {\n appLogger(statusObj.errorMessage, {\n level: 'error',\n });\n }\n }\n } catch (error) {\n appLogger(error, {\n level: 'error',\n });\n }\n};\n"],"mappings":"0rBAsCA,MAAa,EAAO,KAAO,IAAyC,CAClE,IAAM,EAAY,EAAa,GAAS,eAAe,SAAS,CAEhE,GAAI,CACF,IAAM,EAAS,EAAiB,GAAS,cAAc,CAKvD,GAJA,EAAiB,GAAS,cAAc,CAIpC,CAFe,MAAM,EAAa,EAAO,CAE5B,OAEjB,IAAM,EAAc,EAAoB,IAAA,GAAW,EAAO,CAEpD,EAA6B,EAAwB,EAAO,CAG5D,EACJ,MAAM,EAAY,WAAW,gCAAgC,CAE/D,GAAI,CAAC,EAAqC,KACxC,MAAU,MAAM,gCAAgC,CAGlD,IAAI,EACF,EAAqC,KAGnC,GAAS,eACX,EAAqC,OAAO,YAC1C,OAAO,QAAQ,EAAmC,CAAC,QAAQ,CAAC,KAC1D,EAAQ,cAAc,SAAS,EAAI,CACpC,CACF,EAIH,EAAqC,OAAO,YAC1C,OAAO,QAAQ,EAAmC,CAAC,QAAQ,CAAC,KAAS,CAEnE,IAAM,EADoB,EAA2B,KAE/B,IAAI,UACxB,EAAO,YAAY,UACnB,SAEF,OAAO,IAAa,UAAY,IAAa,UAC7C,CACH,CAGD,IAAM,EAAyB,EAC7B,EAAO,OAAO,QACd,0BACD,CACK,EAAkB,EAAO,OAAO,SAAW,GAAmB,CAC9D,EAAgD,EACpD,EACD,CACI,EAAgB,EAAuB,CACxC,EAAE,CAGA,EAAU,OAAO,QAAQ,EAAmC,CAC5D,EAAc,EACjB,QAAQ,CAAC,EAAK,KAA0B,CACvC,GAAI,CAAC,EAAsB,MAAO,GAElC,IAAM,EACJ,OAAO,GAAyB,SAC3B,EAA6B,UAC9B,EAEA,EAAS,EAAiC,GAChD,GAAI,CAAC,EAAO,MAAO,GACnB,IAAM,EAAqB,GAAe,UAIpC,EACJ,OAAO,GAAsB,S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@intlayer/config/logger";import{getConfiguration as r}from"@intlayer/config/node";var i=class{statuses=[];spinnerTimer=null;spinnerIndex=0;renderedLines=0;spinnerFrames=n;isFinished=!1;prefix;lastRenderedState=``;constructor(){this.prefix=r().log.prefix}update(e){if(!this.isFinished){for(let t of e){let e=this.statuses.findIndex(e=>e.dictionaryKey===t.dictionaryKey);e>=0?this.statuses[e]=t:this.statuses.push(t)}this.startSpinner(),this.render()}}finish(){this.isFinished=!0,this.stopSpinner(),this.render()}startSpinner(){this.spinnerTimer||this.isFinished||(this.spinnerTimer=setInterval(()=>{this.spinnerIndex=(this.spinnerIndex+1)%this.spinnerFrames.length,this.render()},100))}stopSpinner(){this.spinnerTimer&&=(clearInterval(this.spinnerTimer),null)}render(){let{total:n,done:r,success:i,errors:a}=this.computeProgress(),o=this.spinnerFrames[this.spinnerIndex],s=[],c=r===n,l=`dictionaries: ${r}/${n}`,u=[];i>0&&u.push(`ok: ${i}`),a>0&&u.push(t(`errors: ${a}`,e.RED));let d=u.length>0?` (${u.join(`, `)})`:``;c?s.push(`${this.prefix} ${t(`✔`,e.GREEN)} fetched ${l}${d}`):s.push(`${this.prefix} ${t(o,e.BLUE)} fetching ${l}${d}`);let f=s.join(`
1
+ import*as e from"@intlayer/config/colors";import{colorize as t,spinnerFrames as n}from"@intlayer/config/logger";import{getConfiguration as r}from"@intlayer/config/node";var i=class{statuses=[];spinnerTimer=null;spinnerIndex=0;renderedLines=0;spinnerFrames=n;isFinished=!1;prefix;lastRenderedState=``;constructor(){this.prefix=r().log.prefix}update(e){if(!this.isFinished){for(let t of e){let e=this.statuses.findIndex(e=>e.dictionaryKey===t.dictionaryKey);e>=0?this.statuses[e]=t:this.statuses.push(t)}this.startSpinner(),this.render()}}finish(){this.isFinished=!0,this.stopSpinner(),this.render()}startSpinner(){this.spinnerTimer||this.isFinished||(this.spinnerTimer=setInterval(()=>{this.spinnerIndex=(this.spinnerIndex+1)%this.spinnerFrames.length,this.render()},100))}stopSpinner(){this.spinnerTimer&&=(clearInterval(this.spinnerTimer),null)}render(){let{total:n,done:r,success:i,errors:a}=this.computeProgress(),o=this.spinnerFrames[this.spinnerIndex],s=[],c=r===n,l=`dictionaries: ${r}/${n}`,u=[];i>0&&u.push(`ok: ${i}`),a>0&&u.push(t(`errors: ${a}`,e.RED));let d=u.length>0?` (${u.join(`, `)})`:``;c?s.push(`${this.prefix} ${t(`✔`,e.GREEN)} fetched ${l}${d}`):s.push(`${this.prefix} ${t(o,e.BLUE)} fetching ${l}${d}`);let f=s.join(`
2
2
  `);if(f===this.lastRenderedState)return;this.lastRenderedState=f,this.renderedLines>0&&process.stdout.write(`\x1b[${this.renderedLines}F`);let p=Math.max(this.renderedLines,s.length);for(let e=0;e<p;e++){process.stdout.write(`\x1B[2K`);let t=s[e];t!==void 0&&process.stdout.write(t),process.stdout.write(`
3
3
  `)}this.renderedLines=s.length}computeProgress(){let e=new Set(this.statuses.map(e=>e.dictionaryKey)),t=new Set([`fetched`,`imported`,`updated`,`up-to-date`,`reimported in JSON`,`new content file`,`error`]),n=new Set([`fetched`,`imported`,`updated`,`up-to-date`,`reimported in JSON`,`new content file`]),r=this.statuses.filter(e=>t.has(e.status)).length,i=this.statuses.filter(e=>n.has(e.status)).length,a=this.statuses.filter(e=>e.status===`error`).length;return{total:e.size,done:r,success:i,errors:a}}};export{i as PullLogger};
4
4
  //# sourceMappingURL=pullLog.mjs.map