@intlayer/cli 8.9.6 → 8.9.8

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 (207) hide show
  1. package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
  2. package/dist/cjs/auth/login.cjs +74 -76
  3. package/dist/cjs/auth/login.cjs.map +1 -1
  4. package/dist/cjs/auth/sessionToken.cjs +43 -0
  5. package/dist/cjs/auth/sessionToken.cjs.map +1 -0
  6. package/dist/cjs/build.cjs.map +1 -1
  7. package/dist/cjs/bundle.cjs.map +1 -1
  8. package/dist/cjs/ci.cjs.map +1 -1
  9. package/dist/cjs/cli.cjs.map +1 -1
  10. package/dist/cjs/config.cjs +1 -1
  11. package/dist/cjs/config.cjs.map +1 -1
  12. package/dist/cjs/editor.cjs.map +1 -1
  13. package/dist/cjs/extract.cjs.map +1 -1
  14. package/dist/cjs/fill/deepMergeContent.cjs.map +1 -1
  15. package/dist/cjs/fill/extractTranslatableContent.cjs.map +1 -1
  16. package/dist/cjs/fill/fill.cjs.map +1 -1
  17. package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -1
  18. package/dist/cjs/fill/formatFillData.cjs.map +1 -1
  19. package/dist/cjs/fill/getAvailableLocalesInDictionary.cjs.map +1 -1
  20. package/dist/cjs/fill/getFilterMissingContentPerLocale.cjs.map +1 -1
  21. package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -1
  22. package/dist/cjs/fill/translateDictionary.cjs +2 -2
  23. package/dist/cjs/fill/translateDictionary.cjs.map +1 -1
  24. package/dist/cjs/fill/writeFill.cjs.map +1 -1
  25. package/dist/cjs/getTargetDictionary.cjs.map +1 -1
  26. package/dist/cjs/init.cjs.map +1 -1
  27. package/dist/cjs/initMCP.cjs.map +1 -1
  28. package/dist/cjs/initSkills.cjs.map +1 -1
  29. package/dist/cjs/listContentDeclaration.cjs.map +1 -1
  30. package/dist/cjs/listProjects.cjs.map +1 -1
  31. package/dist/cjs/liveSync.cjs.map +1 -1
  32. package/dist/cjs/pull.cjs +3 -4
  33. package/dist/cjs/pull.cjs.map +1 -1
  34. package/dist/cjs/push/pullLog.cjs.map +1 -1
  35. package/dist/cjs/push/push.cjs +1 -2
  36. package/dist/cjs/push/push.cjs.map +1 -1
  37. package/dist/cjs/pushConfig.cjs +6 -4
  38. package/dist/cjs/pushConfig.cjs.map +1 -1
  39. package/dist/cjs/pushLog.cjs.map +1 -1
  40. package/dist/cjs/reviewDoc/reviewDoc.cjs.map +1 -1
  41. package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs.map +1 -1
  42. package/dist/cjs/searchDoc.cjs.map +1 -1
  43. package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
  44. package/dist/cjs/test/test.cjs.map +1 -1
  45. package/dist/cjs/translateDoc/translateDoc.cjs.map +1 -1
  46. package/dist/cjs/translateDoc/translateFile.cjs.map +1 -1
  47. package/dist/cjs/translateDoc/validation.cjs.map +1 -1
  48. package/dist/cjs/translation-alignment/alignBlocks.cjs.map +1 -1
  49. package/dist/cjs/translation-alignment/computeSimilarity.cjs.map +1 -1
  50. package/dist/cjs/translation-alignment/fingerprintBlock.cjs.map +1 -1
  51. package/dist/cjs/translation-alignment/mapChangedLinesToBlocks.cjs.map +1 -1
  52. package/dist/cjs/translation-alignment/normalizeBlock.cjs.map +1 -1
  53. package/dist/cjs/translation-alignment/pipeline.cjs.map +1 -1
  54. package/dist/cjs/translation-alignment/planActions.cjs.map +1 -1
  55. package/dist/cjs/translation-alignment/rebuildDocument.cjs.map +1 -1
  56. package/dist/cjs/translation-alignment/segmentDocument.cjs.map +1 -1
  57. package/dist/cjs/utils/calculateChunks.cjs.map +1 -1
  58. package/dist/cjs/utils/checkAccess.cjs +57 -30
  59. package/dist/cjs/utils/checkAccess.cjs.map +1 -1
  60. package/dist/cjs/utils/checkConfigConsistency.cjs.map +1 -1
  61. package/dist/cjs/utils/checkFileModifiedRange.cjs.map +1 -1
  62. package/dist/cjs/utils/checkLastUpdateTime.cjs.map +1 -1
  63. package/dist/cjs/utils/chunkInference.cjs +2 -2
  64. package/dist/cjs/utils/chunkInference.cjs.map +1 -1
  65. package/dist/cjs/utils/fixChunkStartEndChars.cjs.map +1 -1
  66. package/dist/cjs/utils/formatTimeDiff.cjs.map +1 -1
  67. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs.map +1 -1
  68. package/dist/cjs/utils/getOutputFilePath.cjs.map +1 -1
  69. package/dist/cjs/utils/getParentPackageJSON.cjs.map +1 -1
  70. package/dist/cjs/utils/listSpecialChars.cjs.map +1 -1
  71. package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -1
  72. package/dist/cjs/utils/openBrowser.cjs.map +1 -1
  73. package/dist/cjs/utils/reorderParagraphs.cjs.map +1 -1
  74. package/dist/cjs/utils/setupAI.cjs.map +1 -1
  75. package/dist/cjs/watch.cjs.map +1 -1
  76. package/dist/esm/IntlayerEventListener.mjs.map +1 -1
  77. package/dist/esm/auth/login.mjs +74 -76
  78. package/dist/esm/auth/login.mjs.map +1 -1
  79. package/dist/esm/auth/sessionToken.mjs +39 -0
  80. package/dist/esm/auth/sessionToken.mjs.map +1 -0
  81. package/dist/esm/build.mjs.map +1 -1
  82. package/dist/esm/bundle.mjs.map +1 -1
  83. package/dist/esm/ci.mjs.map +1 -1
  84. package/dist/esm/cli.mjs.map +1 -1
  85. package/dist/esm/config.mjs +2 -2
  86. package/dist/esm/config.mjs.map +1 -1
  87. package/dist/esm/editor.mjs.map +1 -1
  88. package/dist/esm/extract.mjs.map +1 -1
  89. package/dist/esm/fill/deepMergeContent.mjs.map +1 -1
  90. package/dist/esm/fill/extractTranslatableContent.mjs.map +1 -1
  91. package/dist/esm/fill/fill.mjs.map +1 -1
  92. package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -1
  93. package/dist/esm/fill/formatFillData.mjs.map +1 -1
  94. package/dist/esm/fill/getAvailableLocalesInDictionary.mjs.map +1 -1
  95. package/dist/esm/fill/getFilterMissingContentPerLocale.mjs.map +1 -1
  96. package/dist/esm/fill/listTranslationsTasks.mjs.map +1 -1
  97. package/dist/esm/fill/translateDictionary.mjs +2 -2
  98. package/dist/esm/fill/translateDictionary.mjs.map +1 -1
  99. package/dist/esm/fill/writeFill.mjs.map +1 -1
  100. package/dist/esm/getTargetDictionary.mjs.map +1 -1
  101. package/dist/esm/init.mjs.map +1 -1
  102. package/dist/esm/initMCP.mjs.map +1 -1
  103. package/dist/esm/initSkills.mjs.map +1 -1
  104. package/dist/esm/listContentDeclaration.mjs.map +1 -1
  105. package/dist/esm/listProjects.mjs.map +1 -1
  106. package/dist/esm/liveSync.mjs.map +1 -1
  107. package/dist/esm/pull.mjs +4 -5
  108. package/dist/esm/pull.mjs.map +1 -1
  109. package/dist/esm/push/pullLog.mjs.map +1 -1
  110. package/dist/esm/push/push.mjs +2 -3
  111. package/dist/esm/push/push.mjs.map +1 -1
  112. package/dist/esm/pushConfig.mjs +8 -6
  113. package/dist/esm/pushConfig.mjs.map +1 -1
  114. package/dist/esm/pushLog.mjs.map +1 -1
  115. package/dist/esm/reviewDoc/reviewDoc.mjs.map +1 -1
  116. package/dist/esm/reviewDoc/reviewDocBlockAware.mjs.map +1 -1
  117. package/dist/esm/searchDoc.mjs.map +1 -1
  118. package/dist/esm/test/listMissingTranslations.mjs.map +1 -1
  119. package/dist/esm/test/test.mjs.map +1 -1
  120. package/dist/esm/translateDoc/translateDoc.mjs.map +1 -1
  121. package/dist/esm/translateDoc/translateFile.mjs.map +1 -1
  122. package/dist/esm/translateDoc/validation.mjs.map +1 -1
  123. package/dist/esm/translation-alignment/alignBlocks.mjs.map +1 -1
  124. package/dist/esm/translation-alignment/computeSimilarity.mjs.map +1 -1
  125. package/dist/esm/translation-alignment/fingerprintBlock.mjs.map +1 -1
  126. package/dist/esm/translation-alignment/mapChangedLinesToBlocks.mjs.map +1 -1
  127. package/dist/esm/translation-alignment/normalizeBlock.mjs.map +1 -1
  128. package/dist/esm/translation-alignment/pipeline.mjs.map +1 -1
  129. package/dist/esm/translation-alignment/planActions.mjs.map +1 -1
  130. package/dist/esm/translation-alignment/rebuildDocument.mjs.map +1 -1
  131. package/dist/esm/translation-alignment/segmentDocument.mjs.map +1 -1
  132. package/dist/esm/utils/calculateChunks.mjs.map +1 -1
  133. package/dist/esm/utils/checkAccess.mjs +57 -31
  134. package/dist/esm/utils/checkAccess.mjs.map +1 -1
  135. package/dist/esm/utils/checkConfigConsistency.mjs.map +1 -1
  136. package/dist/esm/utils/checkFileModifiedRange.mjs.map +1 -1
  137. package/dist/esm/utils/checkLastUpdateTime.mjs.map +1 -1
  138. package/dist/esm/utils/chunkInference.mjs +2 -2
  139. package/dist/esm/utils/chunkInference.mjs.map +1 -1
  140. package/dist/esm/utils/fixChunkStartEndChars.mjs.map +1 -1
  141. package/dist/esm/utils/formatTimeDiff.mjs.map +1 -1
  142. package/dist/esm/utils/getIsFileUpdatedRecently.mjs.map +1 -1
  143. package/dist/esm/utils/getOutputFilePath.mjs.map +1 -1
  144. package/dist/esm/utils/getParentPackageJSON.mjs.map +1 -1
  145. package/dist/esm/utils/listSpecialChars.mjs.map +1 -1
  146. package/dist/esm/utils/mapChunksBetweenFiles.mjs.map +1 -1
  147. package/dist/esm/utils/openBrowser.mjs.map +1 -1
  148. package/dist/esm/utils/reorderParagraphs.mjs.map +1 -1
  149. package/dist/esm/utils/setupAI.mjs.map +1 -1
  150. package/dist/esm/watch.mjs.map +1 -1
  151. package/dist/types/IntlayerEventListener.d.ts.map +1 -1
  152. package/dist/types/auth/login.d.ts.map +1 -1
  153. package/dist/types/auth/sessionToken.d.ts +13 -0
  154. package/dist/types/auth/sessionToken.d.ts.map +1 -0
  155. package/dist/types/build.d.ts.map +1 -1
  156. package/dist/types/bundle.d.ts.map +1 -1
  157. package/dist/types/cli.d.ts.map +1 -1
  158. package/dist/types/config.d.ts.map +1 -1
  159. package/dist/types/editor.d.ts.map +1 -1
  160. package/dist/types/extract.d.ts.map +1 -1
  161. package/dist/types/fill/extractTranslatableContent.d.ts.map +1 -1
  162. package/dist/types/fill/fill.d.ts.map +1 -1
  163. package/dist/types/fill/formatFillData.d.ts.map +1 -1
  164. package/dist/types/fill/getAvailableLocalesInDictionary.d.ts.map +1 -1
  165. package/dist/types/fill/translateDictionary.d.ts +1 -2
  166. package/dist/types/fill/translateDictionary.d.ts.map +1 -1
  167. package/dist/types/index.d.ts +4 -4
  168. package/dist/types/init.d.ts.map +1 -1
  169. package/dist/types/initSkills.d.ts.map +1 -1
  170. package/dist/types/listContentDeclaration.d.ts.map +1 -1
  171. package/dist/types/listProjects.d.ts.map +1 -1
  172. package/dist/types/liveSync.d.ts.map +1 -1
  173. package/dist/types/pull.d.ts.map +1 -1
  174. package/dist/types/push/pullLog.d.ts.map +1 -1
  175. package/dist/types/push/push.d.ts.map +1 -1
  176. package/dist/types/pushConfig.d.ts.map +1 -1
  177. package/dist/types/pushLog.d.ts.map +1 -1
  178. package/dist/types/searchDoc.d.ts.map +1 -1
  179. package/dist/types/test/test.d.ts.map +1 -1
  180. package/dist/types/translateDoc/types.d.ts.map +1 -1
  181. package/dist/types/translateDoc/validation.d.ts.map +1 -1
  182. package/dist/types/translation-alignment/computeSimilarity.d.ts.map +1 -1
  183. package/dist/types/translation-alignment/normalizeBlock.d.ts.map +1 -1
  184. package/dist/types/translation-alignment/pipeline.d.ts.map +1 -1
  185. package/dist/types/translation-alignment/rebuildDocument.d.ts.map +1 -1
  186. package/dist/types/translation-alignment/segmentDocument.d.ts.map +1 -1
  187. package/dist/types/translation-alignment/types.d.ts.map +1 -1
  188. package/dist/types/utils/calculateChunks.d.ts.map +1 -1
  189. package/dist/types/utils/checkAccess.d.ts +3 -2
  190. package/dist/types/utils/checkAccess.d.ts.map +1 -1
  191. package/dist/types/utils/checkConfigConsistency.d.ts.map +1 -1
  192. package/dist/types/utils/checkFileModifiedRange.d.ts.map +1 -1
  193. package/dist/types/utils/checkLastUpdateTime.d.ts.map +1 -1
  194. package/dist/types/utils/chunkInference.d.ts.map +1 -1
  195. package/dist/types/utils/fixChunkStartEndChars.d.ts.map +1 -1
  196. package/dist/types/utils/formatTimeDiff.d.ts.map +1 -1
  197. package/dist/types/utils/getIsFileUpdatedRecently.d.ts.map +1 -1
  198. package/dist/types/utils/getOutputFilePath.d.ts.map +1 -1
  199. package/dist/types/utils/getParentPackageJSON.d.ts.map +1 -1
  200. package/dist/types/utils/listSpecialChars.d.ts.map +1 -1
  201. package/dist/types/utils/mapChunksBetweenFiles.d.ts.map +1 -1
  202. package/dist/types/utils/openBrowser.d.ts.map +1 -1
  203. package/dist/types/utils/reorderParagraphs.d.ts.map +1 -1
  204. package/dist/types/utils/setupAI.d.ts +1 -2
  205. package/dist/types/utils/setupAI.d.ts.map +1 -1
  206. package/dist/types/watch.d.ts.map +1 -1
  207. package/package.json +12 -12
@@ -1 +1 @@
1
- {"version":3,"file":"checkFileModifiedRange.cjs","names":["checkLastUpdateTime","formatTimeDiff"],"sources":["../../../src/utils/checkFileModifiedRange.ts"],"sourcesContent":["import { checkLastUpdateTime } from './checkLastUpdateTime';\nimport { formatTimeDiff } from './formatTimeDiff';\n\ntype GetTimeRangeResult = {\n relativeTime: Date;\n absoluteTime: Date;\n};\n\n/**\n * Threshold that helps us differentiate between a numeric *timestamp* (ms from epoch)\n * and a numeric *duration* (ms ago).\n * 50 years expressed in milliseconds is far greater than any reasonable\n * \"relative\" duration we expect the helper to receive (e.g. a couple of years).\n */\nconst TIMESTAMP_THRESHOLD_MS = 50 * 365 * 24 * 60 * 60 * 1000; // 50 years\n\n/**\n * Normalises the input date representation into a pair:\n * 1. `relativeTime` – a Date instance whose epoch-time equals the duration\n * between `now` and the absolute date.\n * 2. `absoluteTime` – the concrete point in time represented as a Date.\n *\n * Rules for interpreting the input:\n * • Date => treated as an absolute time.\n * • string => parsed via the Date constructor => absolute time.\n * • number:\n * – if the value is larger than the TIMESTAMP_THRESHOLD_MS we assume it\n * is a unix timestamp (absolute time).\n * – otherwise we treat it as a *relative* duration expressed in\n * milliseconds.\n */\nconst normaliseInputDate = (\n date: Date | number | string,\n now: Date = new Date()\n): GetTimeRangeResult => {\n // Case 1: Already a Date instance\n if (date instanceof Date) {\n return {\n absoluteTime: date,\n relativeTime: new Date(now.getTime() - date.getTime()),\n };\n }\n\n // Case 2: Numeric value – decide between timestamp vs relative ms.\n if (typeof date === 'number') {\n if (date > TIMESTAMP_THRESHOLD_MS) {\n // Treat as *unix timestamp* (absolute)\n const absoluteTime = new Date(date);\n return {\n absoluteTime,\n relativeTime: new Date(now.getTime() - absoluteTime.getTime()),\n };\n }\n\n // Treat as a *relative* duration (milliseconds in the past)\n const relativeMs = date;\n return {\n // Relative duration expressed as a Date object starting at the epoch\n relativeTime: new Date(relativeMs),\n // The concrete date obtained by subtracting the duration from *now*\n absoluteTime: new Date(now.getTime() - relativeMs),\n };\n }\n\n // Case 3: String representation – let Date parse it.\n if (typeof date === 'string') {\n const absoluteTime = new Date(date);\n if (Number.isNaN(absoluteTime.getTime())) {\n throw new Error(`Invalid date string provided: ${date}`);\n }\n\n return {\n absoluteTime,\n relativeTime: new Date(now.getTime() - absoluteTime.getTime()),\n };\n }\n\n throw new Error(`Unsupported date format: ${date}`);\n};\n\ntype CheckFileModifiedRangeResult = {\n isSkipped: boolean;\n message: string;\n};\n\ntype CheckFileModifiedRangeOptions = {\n skipIfModifiedBefore?: Date | number | string;\n skipIfModifiedAfter?: Date | number | string;\n};\n\nexport const checkFileModifiedRange = (\n filePath: string,\n options: CheckFileModifiedRangeOptions\n): CheckFileModifiedRangeResult => {\n const fileLastUpdateTime = checkLastUpdateTime(filePath);\n const { skipIfModifiedBefore, skipIfModifiedAfter } = options;\n\n // Normalise the provided thresholds to concrete dates.\n const now = new Date();\n const minDate = skipIfModifiedBefore\n ? normaliseInputDate(skipIfModifiedBefore, now).absoluteTime\n : undefined;\n const maxDate = skipIfModifiedAfter\n ? normaliseInputDate(skipIfModifiedAfter, now).absoluteTime\n : undefined;\n\n // Determine if the file should be skipped.\n let shouldSkip = false;\n\n if (minDate instanceof Date && maxDate instanceof Date) {\n // Skip when the modification time falls *within* the range [minDate, maxDate]\n shouldSkip = fileLastUpdateTime >= minDate && fileLastUpdateTime <= maxDate;\n } else if (minDate instanceof Date) {\n // Only lower bound – skip when the file was modified *after* minDate\n shouldSkip = fileLastUpdateTime >= minDate;\n } else if (maxDate) {\n // Only upper bound – skip when the file was modified *after* maxDate\n shouldSkip = fileLastUpdateTime >= maxDate;\n }\n\n if (shouldSkip) {\n // For the sake of the message we compute the relative time to *now* using\n // whichever bound was responsible for the skip logic.\n const referenceDate = (\n minDate && maxDate\n ? // When both bounds are present, the *range* caused the skip so we use\n // the distance between the two bounds as the relative duration.\n new Date(Math.abs(maxDate.getTime() - minDate.getTime()))\n : (minDate ?? maxDate)\n )!;\n\n const relativeTime = new Date(now.getTime() - referenceDate.getTime());\n\n return {\n isSkipped: true,\n message: `Skipping file because it has been modified within the last ${formatTimeDiff(relativeTime)} - ${filePath}`,\n };\n }\n\n return {\n isSkipped: false,\n message: `File ${filePath} can be processed - ${filePath}`,\n };\n};\n"],"mappings":";;;;;;;;;;;AAcA,MAAM,yBAAyB,KAAK,MAAM,KAAK,KAAK,KAAK;;;;;;;;;;;;;;;;AAiBzD,MAAM,sBACJ,MACA,sBAAY,IAAI,MAAM,KACC;CAEvB,IAAI,gBAAgB,MAClB,OAAO;EACL,cAAc;EACd,cAAc,IAAI,KAAK,IAAI,SAAS,GAAG,KAAK,SAAS,CAAC;EACvD;CAIH,IAAI,OAAO,SAAS,UAAU;EAC5B,IAAI,OAAO,wBAAwB;GAEjC,MAAM,eAAe,IAAI,KAAK,KAAK;GACnC,OAAO;IACL;IACA,cAAc,IAAI,KAAK,IAAI,SAAS,GAAG,aAAa,SAAS,CAAC;IAC/D;;EAIH,MAAM,aAAa;EACnB,OAAO;GAEL,cAAc,IAAI,KAAK,WAAW;GAElC,cAAc,IAAI,KAAK,IAAI,SAAS,GAAG,WAAW;GACnD;;CAIH,IAAI,OAAO,SAAS,UAAU;EAC5B,MAAM,eAAe,IAAI,KAAK,KAAK;EACnC,IAAI,OAAO,MAAM,aAAa,SAAS,CAAC,EACtC,MAAM,IAAI,MAAM,iCAAiC,OAAO;EAG1D,OAAO;GACL;GACA,cAAc,IAAI,KAAK,IAAI,SAAS,GAAG,aAAa,SAAS,CAAC;GAC/D;;CAGH,MAAM,IAAI,MAAM,4BAA4B,OAAO;;AAarD,MAAa,0BACX,UACA,YACiC;CACjC,MAAM,qBAAqBA,sDAAoB,SAAS;CACxD,MAAM,EAAE,sBAAsB,wBAAwB;CAGtD,MAAM,sBAAM,IAAI,MAAM;CACtB,MAAM,UAAU,uBACZ,mBAAmB,sBAAsB,IAAI,CAAC,eAC9C;CACJ,MAAM,UAAU,sBACZ,mBAAmB,qBAAqB,IAAI,CAAC,eAC7C;CAGJ,IAAI,aAAa;CAEjB,IAAI,mBAAmB,QAAQ,mBAAmB,MAEhD,aAAa,sBAAsB,WAAW,sBAAsB;MAC/D,IAAI,mBAAmB,MAE5B,aAAa,sBAAsB;MAC9B,IAAI,SAET,aAAa,sBAAsB;CAGrC,IAAI,YAAY;EAGd,MAAM,gBACJ,WAAW,UAGP,IAAI,KAAK,KAAK,IAAI,QAAQ,SAAS,GAAG,QAAQ,SAAS,CAAC,CAAC,GACxD,WAAW;EAKlB,OAAO;GACL,WAAW;GACX,SAAS,8DAA8DC,4CAAe,IAJ/D,KAAK,IAAI,SAAS,GAAG,cAAc,SAAS,CAI+B,CAAC,CAAC,KAAK;GAC1G;;CAGH,OAAO;EACL,WAAW;EACX,SAAS,QAAQ,SAAS,sBAAsB;EACjD"}
1
+ {"version":3,"file":"checkFileModifiedRange.cjs","names":["checkLastUpdateTime","formatTimeDiff"],"sources":["../../../src/utils/checkFileModifiedRange.ts"],"sourcesContent":["import { checkLastUpdateTime } from './checkLastUpdateTime';\nimport { formatTimeDiff } from './formatTimeDiff';\n\ntype GetTimeRangeResult = {\n relativeTime: Date;\n absoluteTime: Date;\n};\n\n/**\n * Threshold that helps us differentiate between a numeric *timestamp* (ms from epoch)\n * and a numeric *duration* (ms ago).\n * 50 years expressed in milliseconds is far greater than any reasonable\n * \"relative\" duration we expect the helper to receive (e.g. a couple of years).\n */\nconst TIMESTAMP_THRESHOLD_MS = 50 * 365 * 24 * 60 * 60 * 1000; // 50 years\n\n/**\n * Normalises the input date representation into a pair:\n * 1. `relativeTime` – a Date instance whose epoch-time equals the duration\n * between `now` and the absolute date.\n * 2. `absoluteTime` – the concrete point in time represented as a Date.\n *\n * Rules for interpreting the input:\n * • Date => treated as an absolute time.\n * • string => parsed via the Date constructor => absolute time.\n * • number:\n * – if the value is larger than the TIMESTAMP_THRESHOLD_MS we assume it\n * is a unix timestamp (absolute time).\n * – otherwise we treat it as a *relative* duration expressed in\n * milliseconds.\n */\nconst normaliseInputDate = (\n date: Date | number | string,\n now: Date = new Date()\n): GetTimeRangeResult => {\n // Case 1: Already a Date instance\n if (date instanceof Date) {\n return {\n absoluteTime: date,\n relativeTime: new Date(now.getTime() - date.getTime()),\n };\n }\n\n // Case 2: Numeric value – decide between timestamp vs relative ms.\n if (typeof date === 'number') {\n if (date > TIMESTAMP_THRESHOLD_MS) {\n // Treat as *unix timestamp* (absolute)\n const absoluteTime = new Date(date);\n return {\n absoluteTime,\n relativeTime: new Date(now.getTime() - absoluteTime.getTime()),\n };\n }\n\n // Treat as a *relative* duration (milliseconds in the past)\n const relativeMs = date;\n return {\n // Relative duration expressed as a Date object starting at the epoch\n relativeTime: new Date(relativeMs),\n // The concrete date obtained by subtracting the duration from *now*\n absoluteTime: new Date(now.getTime() - relativeMs),\n };\n }\n\n // Case 3: String representation – let Date parse it.\n if (typeof date === 'string') {\n const absoluteTime = new Date(date);\n if (Number.isNaN(absoluteTime.getTime())) {\n throw new Error(`Invalid date string provided: ${date}`);\n }\n\n return {\n absoluteTime,\n relativeTime: new Date(now.getTime() - absoluteTime.getTime()),\n };\n }\n\n throw new Error(`Unsupported date format: ${date}`);\n};\n\ntype CheckFileModifiedRangeResult = {\n isSkipped: boolean;\n message: string;\n};\n\ntype CheckFileModifiedRangeOptions = {\n skipIfModifiedBefore?: Date | number | string;\n skipIfModifiedAfter?: Date | number | string;\n};\n\nexport const checkFileModifiedRange = (\n filePath: string,\n options: CheckFileModifiedRangeOptions\n): CheckFileModifiedRangeResult => {\n const fileLastUpdateTime = checkLastUpdateTime(filePath);\n const { skipIfModifiedBefore, skipIfModifiedAfter } = options;\n\n // Normalise the provided thresholds to concrete dates.\n const now = new Date();\n const minDate = skipIfModifiedBefore\n ? normaliseInputDate(skipIfModifiedBefore, now).absoluteTime\n : undefined;\n const maxDate = skipIfModifiedAfter\n ? normaliseInputDate(skipIfModifiedAfter, now).absoluteTime\n : undefined;\n\n // Determine if the file should be skipped.\n let shouldSkip = false;\n\n if (minDate instanceof Date && maxDate instanceof Date) {\n // Skip when the modification time falls *within* the range [minDate, maxDate]\n shouldSkip = fileLastUpdateTime >= minDate && fileLastUpdateTime <= maxDate;\n } else if (minDate instanceof Date) {\n // Only lower bound – skip when the file was modified *after* minDate\n shouldSkip = fileLastUpdateTime >= minDate;\n } else if (maxDate) {\n // Only upper bound – skip when the file was modified *after* maxDate\n shouldSkip = fileLastUpdateTime >= maxDate;\n }\n\n if (shouldSkip) {\n // For the sake of the message we compute the relative time to *now* using\n // whichever bound was responsible for the skip logic.\n const referenceDate = (\n minDate && maxDate\n ? // When both bounds are present, the *range* caused the skip so we use\n // the distance between the two bounds as the relative duration.\n new Date(Math.abs(maxDate.getTime() - minDate.getTime()))\n : (minDate ?? maxDate)\n )!;\n\n const relativeTime = new Date(now.getTime() - referenceDate.getTime());\n\n return {\n isSkipped: true,\n message: `Skipping file because it has been modified within the last ${formatTimeDiff(relativeTime)} - ${filePath}`,\n };\n }\n\n return {\n isSkipped: false,\n message: `File ${filePath} can be processed - ${filePath}`,\n };\n};\n"],"mappings":";;;;;;;;;;;AAcA,MAAM,yBAAyB,KAAK,MAAM,KAAK,KAAK,KAAK;;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,WAAW,UAGP,IAAI,KAAK,KAAK,IAAI,QAAQ,QAAQ,IAAI,QAAQ,QAAQ,CAAC,CAAC,IACvD,WAAW;EAKlB,OAAO;GACL,WAAW;GACX,SAAS,8DAA8DC,4CAAe,IAJ/D,KAAK,IAAI,QAAQ,IAAI,cAAc,QAAQ,CAI+B,CAAC,EAAE,KAAK;EAC3G;CACF;CAEA,OAAO;EACL,WAAW;EACX,SAAS,QAAQ,SAAS,sBAAsB;CAClD;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"checkLastUpdateTime.cjs","names":[],"sources":["../../../src/utils/checkLastUpdateTime.ts"],"sourcesContent":["import { statSync } from 'node:fs';\n\n/**\n * Returns the last modification date of a file.\n *\n * @param filePath - Absolute or relative path to the file to inspect.\n * @returns Date instance representing the file's last modified time (mtime).\n * @throws Will propagate any error thrown by fs.statSync (e.g., file not found).\n */\nexport const checkLastUpdateTime = (filePath: string): Date => {\n const stats = statSync(filePath);\n return new Date(stats.mtime);\n};\n"],"mappings":";;;;;;;;;;;;AASA,MAAa,uBAAuB,aAA2B;CAC7D,MAAM,8BAAiB,SAAS;CAChC,OAAO,IAAI,KAAK,MAAM,MAAM"}
1
+ {"version":3,"file":"checkLastUpdateTime.cjs","names":[],"sources":["../../../src/utils/checkLastUpdateTime.ts"],"sourcesContent":["import { statSync } from 'node:fs';\n\n/**\n * Returns the last modification date of a file.\n *\n * @param filePath - Absolute or relative path to the file to inspect.\n * @returns Date instance representing the file's last modified time (mtime).\n * @throws Will propagate any error thrown by fs.statSync (e.g., file not found).\n */\nexport const checkLastUpdateTime = (filePath: string): Date => {\n const stats = statSync(filePath);\n return new Date(stats.mtime);\n};\n"],"mappings":";;;;;;;;;;;;AASA,MAAa,uBAAuB,aAA2B;CAC7D,MAAM,8BAAiB,QAAQ;CAC/B,OAAO,IAAI,KAAK,MAAM,KAAK;AAC7B"}
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- let _intlayer_api = require("@intlayer/api");
3
+ const require_utils_checkAccess = require('./checkAccess.cjs');
4
4
  let _intlayer_config_utils = require("@intlayer/config/utils");
5
5
 
6
6
  //#region src/utils/chunkInference.ts
@@ -25,7 +25,7 @@ const chunkInference = async (system, messages, aiOptions, configuration, aiClie
25
25
  };
26
26
  return;
27
27
  }
28
- const response = await (0, _intlayer_api.getIntlayerAPIProxy)(void 0, configuration).ai.customQuery({
28
+ const response = await (await require_utils_checkAccess.getAuthenticatedAPI(configuration)).ai.customQuery({
29
29
  aiOptions,
30
30
  messages
31
31
  });
@@ -1 +1 @@
1
- {"version":3,"file":"chunkInference.cjs","names":[],"sources":["../../../src/utils/chunkInference.ts"],"sourcesContent":["import type {\n AIConfig,\n AIOptions,\n Messages,\n SystemMessage,\n} from '@intlayer/ai';\nimport { getIntlayerAPIProxy } from '@intlayer/api';\nimport { retryManager } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { AIClient } from './setupAI';\n\ntype ChunkInferenceResult = {\n fileContent: string;\n tokenUsed: number;\n};\n\n/**\n * Translates a single chunk via the OpenAI API.\n * Includes retry logic if the call fails.\n */\nexport const chunkInference = async (\n system: SystemMessage,\n messages: Messages,\n aiOptions?: AIOptions,\n configuration?: IntlayerConfig,\n aiClient?: AIClient,\n aiConfig?: AIConfig\n): Promise<ChunkInferenceResult> => {\n let lastResult: ChunkInferenceResult;\n\n await retryManager(async () => {\n if (aiClient && aiConfig) {\n const response = await aiClient.customQuery({\n aiConfig,\n system,\n messages,\n });\n\n if (!response) {\n throw new Error('No response from AI API');\n }\n\n const { fileContent, tokenUsed } = response;\n\n lastResult = {\n fileContent: processContent(fileContent),\n tokenUsed,\n };\n\n return;\n }\n\n const api = getIntlayerAPIProxy(undefined, configuration);\n\n const response = await api.ai.customQuery({\n aiOptions,\n messages,\n });\n\n if (!response.data) {\n throw new Error('No response from AI API');\n }\n\n const { fileContent, tokenUsed } = response.data;\n\n lastResult = {\n fileContent: processContent(fileContent),\n tokenUsed,\n };\n })();\n\n return lastResult!;\n};\n\nconst processContent = (content: string) => {\n return content\n .replaceAll('///chunksStart///', '')\n .replaceAll('///chunkStart///', '')\n .replaceAll('///chunksEnd///', '')\n .replaceAll('///chunkEnd///', '')\n .replaceAll('///chunksStart///', '')\n .replaceAll('chunkStart///', '')\n .replaceAll('chunksEnd///', '')\n .replaceAll('chunkEnd///', '')\n .replaceAll('///chunksStart', '')\n .replaceAll('///chunkStart', '')\n .replaceAll('///chunksEnd', '')\n .replaceAll('///chunkEnd', '')\n .replaceAll('chunksStart', '')\n .replaceAll('chunkStart', '')\n .replaceAll('chunksEnd', '')\n .replaceAll('chunkEnd', '');\n};\n"],"mappings":";;;;;;;;;;AAoBA,MAAa,iBAAiB,OAC5B,QACA,UACA,WACA,eACA,UACA,aACkC;CAClC,IAAI;CAEJ,+CAAmB,YAAY;EAC7B,IAAI,YAAY,UAAU;GACxB,MAAM,WAAW,MAAM,SAAS,YAAY;IAC1C;IACA;IACA;IACD,CAAC;GAEF,IAAI,CAAC,UACH,MAAM,IAAI,MAAM,0BAA0B;GAG5C,MAAM,EAAE,aAAa,cAAc;GAEnC,aAAa;IACX,aAAa,eAAe,YAAY;IACxC;IACD;GAED;;EAKF,MAAM,WAAW,6CAFe,QAAW,cAEjB,CAAC,GAAG,YAAY;GACxC;GACA;GACD,CAAC;EAEF,IAAI,CAAC,SAAS,MACZ,MAAM,IAAI,MAAM,0BAA0B;EAG5C,MAAM,EAAE,aAAa,cAAc,SAAS;EAE5C,aAAa;GACX,aAAa,eAAe,YAAY;GACxC;GACD;GACD,EAAE;CAEJ,OAAO;;AAGT,MAAM,kBAAkB,YAAoB;CAC1C,OAAO,QACJ,WAAW,qBAAqB,GAAG,CACnC,WAAW,oBAAoB,GAAG,CAClC,WAAW,mBAAmB,GAAG,CACjC,WAAW,kBAAkB,GAAG,CAChC,WAAW,qBAAqB,GAAG,CACnC,WAAW,iBAAiB,GAAG,CAC/B,WAAW,gBAAgB,GAAG,CAC9B,WAAW,eAAe,GAAG,CAC7B,WAAW,kBAAkB,GAAG,CAChC,WAAW,iBAAiB,GAAG,CAC/B,WAAW,gBAAgB,GAAG,CAC9B,WAAW,eAAe,GAAG,CAC7B,WAAW,eAAe,GAAG,CAC7B,WAAW,cAAc,GAAG,CAC5B,WAAW,aAAa,GAAG,CAC3B,WAAW,YAAY,GAAG"}
1
+ {"version":3,"file":"chunkInference.cjs","names":["getAuthenticatedAPI"],"sources":["../../../src/utils/chunkInference.ts"],"sourcesContent":["import type {\n AIConfig,\n AIOptions,\n Messages,\n SystemMessage,\n} from '@intlayer/ai';\nimport { retryManager } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { getAuthenticatedAPI } from './checkAccess';\nimport type { AIClient } from './setupAI';\n\ntype ChunkInferenceResult = {\n fileContent: string;\n tokenUsed: number;\n};\n\n/**\n * Translates a single chunk via the OpenAI API.\n * Includes retry logic if the call fails.\n */\nexport const chunkInference = async (\n system: SystemMessage,\n messages: Messages,\n aiOptions?: AIOptions,\n configuration?: IntlayerConfig,\n aiClient?: AIClient,\n aiConfig?: AIConfig\n): Promise<ChunkInferenceResult> => {\n let lastResult: ChunkInferenceResult;\n\n await retryManager(async () => {\n if (aiClient && aiConfig) {\n const response = await aiClient.customQuery({\n aiConfig,\n system,\n messages,\n });\n\n if (!response) {\n throw new Error('No response from AI API');\n }\n\n const { fileContent, tokenUsed } = response;\n\n lastResult = {\n fileContent: processContent(fileContent),\n tokenUsed,\n };\n\n return;\n }\n\n const api = await getAuthenticatedAPI(configuration);\n\n const response = await api.ai.customQuery({\n aiOptions,\n messages,\n });\n\n if (!response.data) {\n throw new Error('No response from AI API');\n }\n\n const { fileContent, tokenUsed } = response.data;\n\n lastResult = {\n fileContent: processContent(fileContent),\n tokenUsed,\n };\n })();\n\n return lastResult!;\n};\n\nconst processContent = (content: string) => {\n return content\n .replaceAll('///chunksStart///', '')\n .replaceAll('///chunkStart///', '')\n .replaceAll('///chunksEnd///', '')\n .replaceAll('///chunkEnd///', '')\n .replaceAll('///chunksStart///', '')\n .replaceAll('chunkStart///', '')\n .replaceAll('chunksEnd///', '')\n .replaceAll('chunkEnd///', '')\n .replaceAll('///chunksStart', '')\n .replaceAll('///chunkStart', '')\n .replaceAll('///chunksEnd', '')\n .replaceAll('///chunkEnd', '')\n .replaceAll('chunksStart', '')\n .replaceAll('chunkStart', '')\n .replaceAll('chunksEnd', '')\n .replaceAll('chunkEnd', '');\n};\n"],"mappings":";;;;;;;;;;AAoBA,MAAa,iBAAiB,OAC5B,QACA,UACA,WACA,eACA,UACA,aACkC;CAClC,IAAI;CAEJ,+CAAmB,YAAY;EAC7B,IAAI,YAAY,UAAU;GACxB,MAAM,WAAW,MAAM,SAAS,YAAY;IAC1C;IACA;IACA;GACF,CAAC;GAED,IAAI,CAAC,UACH,MAAM,IAAI,MAAM,yBAAyB;GAG3C,MAAM,EAAE,aAAa,cAAc;GAEnC,aAAa;IACX,aAAa,eAAe,WAAW;IACvC;GACF;GAEA;EACF;EAIA,MAAM,WAAW,OAAM,MAFLA,8CAAoB,aAAa,GAExB,GAAG,YAAY;GACxC;GACA;EACF,CAAC;EAED,IAAI,CAAC,SAAS,MACZ,MAAM,IAAI,MAAM,yBAAyB;EAG3C,MAAM,EAAE,aAAa,cAAc,SAAS;EAE5C,aAAa;GACX,aAAa,eAAe,WAAW;GACvC;EACF;CACF,CAAC,EAAE;CAEH,OAAO;AACT;AAEA,MAAM,kBAAkB,YAAoB;CAC1C,OAAO,QACJ,WAAW,qBAAqB,EAAE,EAClC,WAAW,oBAAoB,EAAE,EACjC,WAAW,mBAAmB,EAAE,EAChC,WAAW,kBAAkB,EAAE,EAC/B,WAAW,qBAAqB,EAAE,EAClC,WAAW,iBAAiB,EAAE,EAC9B,WAAW,gBAAgB,EAAE,EAC7B,WAAW,eAAe,EAAE,EAC5B,WAAW,kBAAkB,EAAE,EAC/B,WAAW,iBAAiB,EAAE,EAC9B,WAAW,gBAAgB,EAAE,EAC7B,WAAW,eAAe,EAAE,EAC5B,WAAW,eAAe,EAAE,EAC5B,WAAW,cAAc,EAAE,EAC3B,WAAW,aAAa,EAAE,EAC1B,WAAW,YAAY,EAAE;AAC9B"}
@@ -1 +1 @@
1
- {"version":3,"file":"fixChunkStartEndChars.cjs","names":[],"sources":["../../../src/utils/fixChunkStartEndChars.ts"],"sourcesContent":["const CHAR_TO_CHECK_FORMATTING = ['```', '\\n\\n', '\\n', '---', '{{', '}}'];\n\n// Escape a string for use in RegExp\nconst escapeForRegExp = (str: string) =>\n str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&').replace(/\\n/g, '\\\\n');\n\n// Build once the regex that matches any combination of the formatting chars appearing\n// sequentially at the beginning or at the end of a string.\nconst FORMATTING_REGEX_SOURCE = `(?:${CHAR_TO_CHECK_FORMATTING.map(escapeForRegExp).join('|')})+`;\nconst LEADING_FORMATTING_REGEX = new RegExp(`^${FORMATTING_REGEX_SOURCE}`);\nconst TRAILING_FORMATTING_REGEX = new RegExp(`${FORMATTING_REGEX_SOURCE}$`);\n\nexport const fixChunkStartEndChars = (\n reviewedChunkResult: string,\n baseChunkContext: string\n) => {\n let result = reviewedChunkResult;\n\n const baseLeading =\n baseChunkContext.match(LEADING_FORMATTING_REGEX)?.[0] ?? '';\n const baseTrailing =\n baseChunkContext.match(TRAILING_FORMATTING_REGEX)?.[0] ?? '';\n\n const resultLeading = result.match(LEADING_FORMATTING_REGEX)?.[0] ?? '';\n const resultTrailing = result.match(TRAILING_FORMATTING_REGEX)?.[0] ?? '';\n\n // Fix leading formatting\n if (baseLeading !== resultLeading) {\n // Remove current leading formatting found in result and prepend the correct one\n result = baseLeading + result.slice(resultLeading.length);\n }\n\n // Fix trailing formatting\n if (baseTrailing !== resultTrailing) {\n // Remove current trailing formatting found in result and append the correct one\n result =\n result.slice(0, result.length - resultTrailing.length) + baseTrailing;\n }\n\n return result;\n};\n"],"mappings":";;;AAAA,MAAM,2BAA2B;CAAC;CAAO;CAAQ;CAAM;CAAO;CAAM;CAAK;AAGzE,MAAM,mBAAmB,QACvB,IAAI,QAAQ,uBAAuB,OAAO,CAAC,QAAQ,OAAO,MAAM;AAIlE,MAAM,0BAA0B,MAAM,yBAAyB,IAAI,gBAAgB,CAAC,KAAK,IAAI,CAAC;AAC9F,MAAM,2BAA2B,IAAI,OAAO,IAAI,0BAA0B;AAC1E,MAAM,4BAA4B,IAAI,OAAO,GAAG,wBAAwB,GAAG;AAE3E,MAAa,yBACX,qBACA,qBACG;CACH,IAAI,SAAS;CAEb,MAAM,cACJ,iBAAiB,MAAM,yBAAyB,GAAG,MAAM;CAC3D,MAAM,eACJ,iBAAiB,MAAM,0BAA0B,GAAG,MAAM;CAE5D,MAAM,gBAAgB,OAAO,MAAM,yBAAyB,GAAG,MAAM;CACrE,MAAM,iBAAiB,OAAO,MAAM,0BAA0B,GAAG,MAAM;CAGvE,IAAI,gBAAgB,eAElB,SAAS,cAAc,OAAO,MAAM,cAAc,OAAO;CAI3D,IAAI,iBAAiB,gBAEnB,SACE,OAAO,MAAM,GAAG,OAAO,SAAS,eAAe,OAAO,GAAG;CAG7D,OAAO"}
1
+ {"version":3,"file":"fixChunkStartEndChars.cjs","names":[],"sources":["../../../src/utils/fixChunkStartEndChars.ts"],"sourcesContent":["const CHAR_TO_CHECK_FORMATTING = ['```', '\\n\\n', '\\n', '---', '{{', '}}'];\n\n// Escape a string for use in RegExp\nconst escapeForRegExp = (str: string) =>\n str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&').replace(/\\n/g, '\\\\n');\n\n// Build once the regex that matches any combination of the formatting chars appearing\n// sequentially at the beginning or at the end of a string.\nconst FORMATTING_REGEX_SOURCE = `(?:${CHAR_TO_CHECK_FORMATTING.map(escapeForRegExp).join('|')})+`;\nconst LEADING_FORMATTING_REGEX = new RegExp(`^${FORMATTING_REGEX_SOURCE}`);\nconst TRAILING_FORMATTING_REGEX = new RegExp(`${FORMATTING_REGEX_SOURCE}$`);\n\nexport const fixChunkStartEndChars = (\n reviewedChunkResult: string,\n baseChunkContext: string\n) => {\n let result = reviewedChunkResult;\n\n const baseLeading =\n baseChunkContext.match(LEADING_FORMATTING_REGEX)?.[0] ?? '';\n const baseTrailing =\n baseChunkContext.match(TRAILING_FORMATTING_REGEX)?.[0] ?? '';\n\n const resultLeading = result.match(LEADING_FORMATTING_REGEX)?.[0] ?? '';\n const resultTrailing = result.match(TRAILING_FORMATTING_REGEX)?.[0] ?? '';\n\n // Fix leading formatting\n if (baseLeading !== resultLeading) {\n // Remove current leading formatting found in result and prepend the correct one\n result = baseLeading + result.slice(resultLeading.length);\n }\n\n // Fix trailing formatting\n if (baseTrailing !== resultTrailing) {\n // Remove current trailing formatting found in result and append the correct one\n result =\n result.slice(0, result.length - resultTrailing.length) + baseTrailing;\n }\n\n return result;\n};\n"],"mappings":";;;AAAA,MAAM,2BAA2B;CAAC;CAAO;CAAQ;CAAM;CAAO;CAAM;AAAI;AAGxE,MAAM,mBAAmB,QACvB,IAAI,QAAQ,uBAAuB,MAAM,EAAE,QAAQ,OAAO,KAAK;AAIjE,MAAM,0BAA0B,MAAM,yBAAyB,IAAI,eAAe,EAAE,KAAK,GAAG,EAAE;AAC9F,MAAM,2BAA2B,IAAI,OAAO,IAAI,yBAAyB;AACzE,MAAM,4BAA4B,IAAI,OAAO,GAAG,wBAAwB,EAAE;AAE1E,MAAa,yBACX,qBACA,qBACG;CACH,IAAI,SAAS;CAEb,MAAM,cACJ,iBAAiB,MAAM,wBAAwB,IAAI,MAAM;CAC3D,MAAM,eACJ,iBAAiB,MAAM,yBAAyB,IAAI,MAAM;CAE5D,MAAM,gBAAgB,OAAO,MAAM,wBAAwB,IAAI,MAAM;CACrE,MAAM,iBAAiB,OAAO,MAAM,yBAAyB,IAAI,MAAM;CAGvE,IAAI,gBAAgB,eAElB,SAAS,cAAc,OAAO,MAAM,cAAc,MAAM;CAI1D,IAAI,iBAAiB,gBAEnB,SACE,OAAO,MAAM,GAAG,OAAO,SAAS,eAAe,MAAM,IAAI;CAG7D,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"formatTimeDiff.cjs","names":[],"sources":["../../../src/utils/formatTimeDiff.ts"],"sourcesContent":["export const formatTimeDiff = (realtiveTime: Date): string => {\n const diff = realtiveTime.getTime();\n\n const MS_IN_SECOND = 1000;\n const MS_IN_MINUTE = 60 * MS_IN_SECOND;\n const MS_IN_HOUR = 60 * MS_IN_MINUTE;\n const MS_IN_DAY = 24 * MS_IN_HOUR;\n\n const days = Math.floor(diff / MS_IN_DAY);\n const hours = Math.floor((diff % MS_IN_DAY) / MS_IN_HOUR);\n const minutes = Math.floor((diff % MS_IN_HOUR) / MS_IN_MINUTE);\n const seconds = Math.floor((diff % MS_IN_MINUTE) / MS_IN_SECOND);\n\n if (days > 0) {\n return `${days}d ${hours}h ${minutes}m ${seconds}s`;\n }\n if (hours > 0) {\n return `${hours}h ${minutes}m ${seconds}s`;\n }\n\n return `${minutes}m ${seconds}s`;\n};\n"],"mappings":";;;AAAA,MAAa,kBAAkB,iBAA+B;CAC5D,MAAM,OAAO,aAAa,SAAS;CAEnC,MAAM,eAAe;CACrB,MAAM,eAAe,KAAK;CAC1B,MAAM,aAAa,KAAK;CACxB,MAAM,YAAY,KAAK;CAEvB,MAAM,OAAO,KAAK,MAAM,OAAO,UAAU;CACzC,MAAM,QAAQ,KAAK,MAAO,OAAO,YAAa,WAAW;CACzD,MAAM,UAAU,KAAK,MAAO,OAAO,aAAc,aAAa;CAC9D,MAAM,UAAU,KAAK,MAAO,OAAO,eAAgB,aAAa;CAEhE,IAAI,OAAO,GACT,OAAO,GAAG,KAAK,IAAI,MAAM,IAAI,QAAQ,IAAI,QAAQ;CAEnD,IAAI,QAAQ,GACV,OAAO,GAAG,MAAM,IAAI,QAAQ,IAAI,QAAQ;CAG1C,OAAO,GAAG,QAAQ,IAAI,QAAQ"}
1
+ {"version":3,"file":"formatTimeDiff.cjs","names":[],"sources":["../../../src/utils/formatTimeDiff.ts"],"sourcesContent":["export const formatTimeDiff = (realtiveTime: Date): string => {\n const diff = realtiveTime.getTime();\n\n const MS_IN_SECOND = 1000;\n const MS_IN_MINUTE = 60 * MS_IN_SECOND;\n const MS_IN_HOUR = 60 * MS_IN_MINUTE;\n const MS_IN_DAY = 24 * MS_IN_HOUR;\n\n const days = Math.floor(diff / MS_IN_DAY);\n const hours = Math.floor((diff % MS_IN_DAY) / MS_IN_HOUR);\n const minutes = Math.floor((diff % MS_IN_HOUR) / MS_IN_MINUTE);\n const seconds = Math.floor((diff % MS_IN_MINUTE) / MS_IN_SECOND);\n\n if (days > 0) {\n return `${days}d ${hours}h ${minutes}m ${seconds}s`;\n }\n if (hours > 0) {\n return `${hours}h ${minutes}m ${seconds}s`;\n }\n\n return `${minutes}m ${seconds}s`;\n};\n"],"mappings":";;;AAAA,MAAa,kBAAkB,iBAA+B;CAC5D,MAAM,OAAO,aAAa,QAAQ;CAElC,MAAM,eAAe;CACrB,MAAM,eAAe,KAAK;CAC1B,MAAM,aAAa,KAAK;CACxB,MAAM,YAAY,KAAK;CAEvB,MAAM,OAAO,KAAK,MAAM,OAAO,SAAS;CACxC,MAAM,QAAQ,KAAK,MAAO,OAAO,YAAa,UAAU;CACxD,MAAM,UAAU,KAAK,MAAO,OAAO,aAAc,YAAY;CAC7D,MAAM,UAAU,KAAK,MAAO,OAAO,eAAgB,YAAY;CAE/D,IAAI,OAAO,GACT,OAAO,GAAG,KAAK,IAAI,MAAM,IAAI,QAAQ,IAAI,QAAQ;CAEnD,IAAI,QAAQ,GACV,OAAO,GAAG,MAAM,IAAI,QAAQ,IAAI,QAAQ;CAG1C,OAAO,GAAG,QAAQ,IAAI,QAAQ;AAChC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getIsFileUpdatedRecently.cjs","names":[],"sources":["../../../src/utils/getIsFileUpdatedRecently.ts"],"sourcesContent":["import { statSync } from 'node:fs';\n\nconst SKIP_RANGE_OF_LAST_UPDATE_TIME: number = 0; //2 * 60 * 60 * 1000; // 2 hours\n\n/**\n * Check if file was updated recently, to skip re-translation\n */\nexport const getIsFileUpdatedRecently = (localeFilePath: string): boolean => {\n const stats = statSync(localeFilePath);\n const lastModified = new Date(stats.mtime);\n const threshold = new Date(Date.now() - SKIP_RANGE_OF_LAST_UPDATE_TIME);\n\n return lastModified > threshold;\n};\n"],"mappings":";;;;;AAEA,MAAM,iCAAyC;;;;AAK/C,MAAa,4BAA4B,mBAAoC;CAC3E,MAAM,8BAAiB,eAAe;CAItC,OAAO,IAHkB,KAAK,MAAM,MAGjB,GAAG,IAFA,KAAK,KAAK,KAAK,GAAG,+BAET"}
1
+ {"version":3,"file":"getIsFileUpdatedRecently.cjs","names":[],"sources":["../../../src/utils/getIsFileUpdatedRecently.ts"],"sourcesContent":["import { statSync } from 'node:fs';\n\nconst SKIP_RANGE_OF_LAST_UPDATE_TIME: number = 0; //2 * 60 * 60 * 1000; // 2 hours\n\n/**\n * Check if file was updated recently, to skip re-translation\n */\nexport const getIsFileUpdatedRecently = (localeFilePath: string): boolean => {\n const stats = statSync(localeFilePath);\n const lastModified = new Date(stats.mtime);\n const threshold = new Date(Date.now() - SKIP_RANGE_OF_LAST_UPDATE_TIME);\n\n return lastModified > threshold;\n};\n"],"mappings":";;;;;AAEA,MAAM,iCAAyC;;;;AAK/C,MAAa,4BAA4B,mBAAoC;CAC3E,MAAM,8BAAiB,cAAc;CAIrC,OAAO,IAHkB,KAAK,MAAM,KAGlB,IAAI,IAFA,KAAK,KAAK,IAAI,IAAI,8BAEV;AAChC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getOutputFilePath.cjs","names":[],"sources":["../../../src/utils/getOutputFilePath.ts"],"sourcesContent":["import { resolveRelativePath } from '@intlayer/chokidar/utils';\nimport { parseStringPattern } from '@intlayer/config/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { Fill } from '@intlayer/types/dictionary';\nimport type {\n FilePathPattern,\n FilePathPatternContext,\n} from '@intlayer/types/filePathPattern';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n * Get the output file path by replacing the base locale with the target locale\n *\n * This function handles two types of replacements:\n * 1. Actual locale values (e.g., `/en/` → `/fr/`)\n * 2. Template placeholders (e.g., `{{baseLocale}}` → `{{locale}}`, `{{baseLocaleName}}` → `{{localeName}}`)\n *\n * Replacement patterns:\n * - `/baseLocale/` → `/locale/`\n * - `\\baseLocale\\` → `\\locale\\`\n * - `_baseLocale.` → `_locale.`\n * - `baseLocale_` → `locale_`\n * - `.baseLocaleName.` → `.localeName.`\n * - `{{baseLocale}}` → `{{locale}}`\n * - `{{baseLocaleName}}` → `{{localeName}}`\n *\n * If no patterns match, appends `.locale` to the file extension.\n *\n * @param filePath - The input file path\n * @param locale - The target locale\n * @param baseLocale - The base locale to replace\n * @returns The output file path with locale replacements\n */\nexport const getOutputFilePath = (\n filePath: string,\n locale: LocalesValues,\n baseLocale: LocalesValues\n): string => {\n if (!filePath || !locale || !baseLocale) {\n throw new Error('filePath, locale, and baseLocale are required');\n }\n\n let outputFilePath = filePath;\n\n // Define replacement patterns with global flag to replace all occurrences\n const replacements = [\n // Template placeholders (processed first)\n {\n pattern: /\\{\\{baseLocale\\}\\}/g,\n replacement: '{{locale}}',\n },\n {\n pattern: /\\{\\{baseLocaleName\\}\\}/g,\n replacement: '{{localeName}}',\n },\n\n // Path separators (most specific first)\n {\n // Unix path separators\n pattern: new RegExp(`/${baseLocale}/`, 'g'),\n replacement: `/${locale}/`,\n },\n {\n // Windows path separators\n pattern: new RegExp(`\\\\\\\\${baseLocale}\\\\\\\\`, 'g'),\n replacement: `\\\\${locale}\\\\`,\n },\n\n // File naming patterns\n {\n // file_en.md → file_fr.md\n pattern: new RegExp(`_${baseLocale}\\\\.`, 'g'),\n replacement: `_${locale}.`,\n },\n {\n // /file_en.md → /file_fr.md\n pattern: new RegExp(`/${baseLocale}_`, 'g'),\n replacement: `/${locale}_`,\n },\n {\n // Start of filename pattern en_guide.md → fr_guide.md (or after path separator)\n pattern: new RegExp(`(^|[\\\\/])${baseLocale}_`, 'g'),\n replacement: `$1${locale}_`,\n },\n {\n // Dot delimited pattern guide.en.md → guide.fr.md\n pattern: new RegExp(`\\\\.${baseLocale}\\\\.`, 'g'),\n replacement: `.${locale}.`,\n },\n ];\n\n // Apply all replacements\n for (const { pattern, replacement } of replacements) {\n outputFilePath = outputFilePath.replace(pattern, replacement);\n }\n\n // If no changes were made, append locale as extension\n if (outputFilePath === filePath) {\n const lastDotIndex = filePath.lastIndexOf('.');\n if (lastDotIndex > 0) {\n // Insert locale before the file extension\n return `${filePath.slice(0, lastDotIndex)}.${locale}${filePath.slice(lastDotIndex)}`;\n } else {\n // No extension found, just append\n return `${filePath}.${locale}`;\n }\n }\n\n return outputFilePath;\n};\n\n/**\n * Get the effective FilePathPattern for a given locale from a Fill/CompilerOutput value.\n *\n * - If Fill is an object, returns the pattern for that locale (or `false` if disabled/missing).\n * - If Fill is a string/function, returns it as-is (applies to all locales).\n * - If Fill is `false`, returns `false` (disabled for all locales).\n * - If Fill is `true` or a locale entry is `true`, returns `undefined` (use default).\n */\nexport const getPatternForLocale = (\n output: Fill,\n locale: Locale\n): FilePathPattern | false | undefined => {\n if (output === false) return false;\n if (output === true) return undefined;\n if (typeof output === 'string' || typeof output === 'function')\n return output as FilePathPattern;\n if (typeof output === 'object' && output !== null) {\n const entry = (output as Record<string, boolean | FilePathPattern>)[locale];\n if (entry === undefined || entry === false) return false;\n if (entry === true) return undefined;\n return entry as FilePathPattern;\n }\n return false;\n};\n\n/**\n * Resolve a Fill/CompilerOutput pattern to an absolute file path for a given locale.\n * Returns `false` if the locale is disabled or no pattern is configured.\n */\nexport const resolveOutputPattern = async (\n output: Fill,\n locale: Locale,\n context: FilePathPatternContext,\n sourceFilePath: string,\n baseDir: string\n): Promise<string | false> => {\n const pattern = getPatternForLocale(output, locale);\n if (pattern === false || pattern === undefined) return false;\n\n const rawPath =\n typeof pattern === 'function'\n ? await pattern(context)\n : parseStringPattern(pattern, context);\n\n return resolveRelativePath(rawPath, sourceFilePath, baseDir);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,qBACX,UACA,QACA,eACW;CACX,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,YAC3B,MAAM,IAAI,MAAM,gDAAgD;CAGlE,IAAI,iBAAiB;CAGrB,MAAM,eAAe;EAEnB;GACE,SAAS;GACT,aAAa;GACd;EACD;GACE,SAAS;GACT,aAAa;GACd;EAGD;GAEE,SAAS,IAAI,OAAO,IAAI,WAAW,IAAI,IAAI;GAC3C,aAAa,IAAI,OAAO;GACzB;EACD;GAEE,SAAS,IAAI,OAAO,OAAO,WAAW,OAAO,IAAI;GACjD,aAAa,KAAK,OAAO;GAC1B;EAGD;GAEE,SAAS,IAAI,OAAO,IAAI,WAAW,MAAM,IAAI;GAC7C,aAAa,IAAI,OAAO;GACzB;EACD;GAEE,SAAS,IAAI,OAAO,IAAI,WAAW,IAAI,IAAI;GAC3C,aAAa,IAAI,OAAO;GACzB;EACD;GAEE,SAAS,IAAI,OAAO,YAAY,WAAW,IAAI,IAAI;GACnD,aAAa,KAAK,OAAO;GAC1B;EACD;GAEE,SAAS,IAAI,OAAO,MAAM,WAAW,MAAM,IAAI;GAC/C,aAAa,IAAI,OAAO;GACzB;EACF;CAGD,KAAK,MAAM,EAAE,SAAS,iBAAiB,cACrC,iBAAiB,eAAe,QAAQ,SAAS,YAAY;CAI/D,IAAI,mBAAmB,UAAU;EAC/B,MAAM,eAAe,SAAS,YAAY,IAAI;EAC9C,IAAI,eAAe,GAEjB,OAAO,GAAG,SAAS,MAAM,GAAG,aAAa,CAAC,GAAG,SAAS,SAAS,MAAM,aAAa;OAGlF,OAAO,GAAG,SAAS,GAAG;;CAI1B,OAAO;;;;;;;;;;AAWT,MAAa,uBACX,QACA,WACwC;CACxC,IAAI,WAAW,OAAO,OAAO;CAC7B,IAAI,WAAW,MAAM,OAAO;CAC5B,IAAI,OAAO,WAAW,YAAY,OAAO,WAAW,YAClD,OAAO;CACT,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM;EACjD,MAAM,QAAS,OAAqD;EACpE,IAAI,UAAU,UAAa,UAAU,OAAO,OAAO;EACnD,IAAI,UAAU,MAAM,OAAO;EAC3B,OAAO;;CAET,OAAO;;;;;;AAOT,MAAa,uBAAuB,OAClC,QACA,QACA,SACA,gBACA,YAC4B;CAC5B,MAAM,UAAU,oBAAoB,QAAQ,OAAO;CACnD,IAAI,YAAY,SAAS,YAAY,QAAW,OAAO;CAOvD,yDAJE,OAAO,YAAY,aACf,MAAM,QAAQ,QAAQ,kDACH,SAAS,QAAQ,EAEN,gBAAgB,QAAQ"}
1
+ {"version":3,"file":"getOutputFilePath.cjs","names":[],"sources":["../../../src/utils/getOutputFilePath.ts"],"sourcesContent":["import { resolveRelativePath } from '@intlayer/chokidar/utils';\nimport { parseStringPattern } from '@intlayer/config/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { Fill } from '@intlayer/types/dictionary';\nimport type {\n FilePathPattern,\n FilePathPatternContext,\n} from '@intlayer/types/filePathPattern';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n * Get the output file path by replacing the base locale with the target locale\n *\n * This function handles two types of replacements:\n * 1. Actual locale values (e.g., `/en/` → `/fr/`)\n * 2. Template placeholders (e.g., `{{baseLocale}}` → `{{locale}}`, `{{baseLocaleName}}` → `{{localeName}}`)\n *\n * Replacement patterns:\n * - `/baseLocale/` → `/locale/`\n * - `\\baseLocale\\` → `\\locale\\`\n * - `_baseLocale.` → `_locale.`\n * - `baseLocale_` → `locale_`\n * - `.baseLocaleName.` → `.localeName.`\n * - `{{baseLocale}}` → `{{locale}}`\n * - `{{baseLocaleName}}` → `{{localeName}}`\n *\n * If no patterns match, appends `.locale` to the file extension.\n *\n * @param filePath - The input file path\n * @param locale - The target locale\n * @param baseLocale - The base locale to replace\n * @returns The output file path with locale replacements\n */\nexport const getOutputFilePath = (\n filePath: string,\n locale: LocalesValues,\n baseLocale: LocalesValues\n): string => {\n if (!filePath || !locale || !baseLocale) {\n throw new Error('filePath, locale, and baseLocale are required');\n }\n\n let outputFilePath = filePath;\n\n // Define replacement patterns with global flag to replace all occurrences\n const replacements = [\n // Template placeholders (processed first)\n {\n pattern: /\\{\\{baseLocale\\}\\}/g,\n replacement: '{{locale}}',\n },\n {\n pattern: /\\{\\{baseLocaleName\\}\\}/g,\n replacement: '{{localeName}}',\n },\n\n // Path separators (most specific first)\n {\n // Unix path separators\n pattern: new RegExp(`/${baseLocale}/`, 'g'),\n replacement: `/${locale}/`,\n },\n {\n // Windows path separators\n pattern: new RegExp(`\\\\\\\\${baseLocale}\\\\\\\\`, 'g'),\n replacement: `\\\\${locale}\\\\`,\n },\n\n // File naming patterns\n {\n // file_en.md → file_fr.md\n pattern: new RegExp(`_${baseLocale}\\\\.`, 'g'),\n replacement: `_${locale}.`,\n },\n {\n // /file_en.md → /file_fr.md\n pattern: new RegExp(`/${baseLocale}_`, 'g'),\n replacement: `/${locale}_`,\n },\n {\n // Start of filename pattern en_guide.md → fr_guide.md (or after path separator)\n pattern: new RegExp(`(^|[\\\\/])${baseLocale}_`, 'g'),\n replacement: `$1${locale}_`,\n },\n {\n // Dot delimited pattern guide.en.md → guide.fr.md\n pattern: new RegExp(`\\\\.${baseLocale}\\\\.`, 'g'),\n replacement: `.${locale}.`,\n },\n ];\n\n // Apply all replacements\n for (const { pattern, replacement } of replacements) {\n outputFilePath = outputFilePath.replace(pattern, replacement);\n }\n\n // If no changes were made, append locale as extension\n if (outputFilePath === filePath) {\n const lastDotIndex = filePath.lastIndexOf('.');\n if (lastDotIndex > 0) {\n // Insert locale before the file extension\n return `${filePath.slice(0, lastDotIndex)}.${locale}${filePath.slice(lastDotIndex)}`;\n } else {\n // No extension found, just append\n return `${filePath}.${locale}`;\n }\n }\n\n return outputFilePath;\n};\n\n/**\n * Get the effective FilePathPattern for a given locale from a Fill/CompilerOutput value.\n *\n * - If Fill is an object, returns the pattern for that locale (or `false` if disabled/missing).\n * - If Fill is a string/function, returns it as-is (applies to all locales).\n * - If Fill is `false`, returns `false` (disabled for all locales).\n * - If Fill is `true` or a locale entry is `true`, returns `undefined` (use default).\n */\nexport const getPatternForLocale = (\n output: Fill,\n locale: Locale\n): FilePathPattern | false | undefined => {\n if (output === false) return false;\n if (output === true) return undefined;\n if (typeof output === 'string' || typeof output === 'function')\n return output as FilePathPattern;\n if (typeof output === 'object' && output !== null) {\n const entry = (output as Record<string, boolean | FilePathPattern>)[locale];\n if (entry === undefined || entry === false) return false;\n if (entry === true) return undefined;\n return entry as FilePathPattern;\n }\n return false;\n};\n\n/**\n * Resolve a Fill/CompilerOutput pattern to an absolute file path for a given locale.\n * Returns `false` if the locale is disabled or no pattern is configured.\n */\nexport const resolveOutputPattern = async (\n output: Fill,\n locale: Locale,\n context: FilePathPatternContext,\n sourceFilePath: string,\n baseDir: string\n): Promise<string | false> => {\n const pattern = getPatternForLocale(output, locale);\n if (pattern === false || pattern === undefined) return false;\n\n const rawPath =\n typeof pattern === 'function'\n ? await pattern(context)\n : parseStringPattern(pattern, context);\n\n return resolveRelativePath(rawPath, sourceFilePath, baseDir);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,qBACX,UACA,QACA,eACW;CACX,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,YAC3B,MAAM,IAAI,MAAM,+CAA+C;CAGjE,IAAI,iBAAiB;CAGrB,MAAM,eAAe;EAEnB;GACE,SAAS;GACT,aAAa;EACf;EACA;GACE,SAAS;GACT,aAAa;EACf;EAGA;GAEE,SAAS,IAAI,OAAO,IAAI,WAAW,IAAI,GAAG;GAC1C,aAAa,IAAI,OAAO;EAC1B;EACA;GAEE,SAAS,IAAI,OAAO,OAAO,WAAW,OAAO,GAAG;GAChD,aAAa,KAAK,OAAO;EAC3B;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version":3,"file":"getParentPackageJSON.cjs","names":[],"sources":["../../../src/utils/getParentPackageJSON.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\n\ntype PackageJSON = {\n name?: string;\n version?: string;\n private: boolean;\n description?: string;\n homepage?: string;\n bugs: {\n url?: string;\n };\n repository: {\n type?: string;\n url?: string;\n };\n license?: string;\n author: {\n name?: string;\n url?: string;\n };\n contributors?: {\n name?: string;\n email?: string;\n url?: string;\n }[];\n type?: string;\n scripts: Record<string, string>;\n devDependencies: Record<string, string>;\n packageManager?: string;\n engines: Record<string, string>;\n};\n\nexport const getParentPackageJSON = (startDir: string): PackageJSON => {\n let currentDir = startDir;\n\n while (currentDir !== dirname(currentDir)) {\n // Stop when we reach the root\n const packageJsonPath = resolve(currentDir, 'package.json');\n\n if (existsSync(packageJsonPath)) {\n return JSON.parse(readFileSync(packageJsonPath, 'utf8'));\n }\n\n // Move up one directory level\n currentDir = dirname(currentDir);\n }\n\n // Check the root directory as well\n const rootPackageJsonPath = resolve(currentDir, 'package.json');\n if (existsSync(rootPackageJsonPath)) {\n return JSON.parse(readFileSync(rootPackageJsonPath, 'utf8'));\n }\n\n // If no package.json is found in any parent directory\n throw new Error(\n `No package.json found in any parent directory of ${startDir}`\n );\n};\n"],"mappings":";;;;;;AAiCA,MAAa,wBAAwB,aAAkC;CACrE,IAAI,aAAa;CAEjB,OAAO,sCAAuB,WAAW,EAAE;EAEzC,MAAM,yCAA0B,YAAY,eAAe;EAE3D,4BAAe,gBAAgB,EAC7B,OAAO,KAAK,gCAAmB,iBAAiB,OAAO,CAAC;EAI1D,oCAAqB,WAAW;;CAIlC,MAAM,6CAA8B,YAAY,eAAe;CAC/D,4BAAe,oBAAoB,EACjC,OAAO,KAAK,gCAAmB,qBAAqB,OAAO,CAAC;CAI9D,MAAM,IAAI,MACR,oDAAoD,WACrD"}
1
+ {"version":3,"file":"getParentPackageJSON.cjs","names":[],"sources":["../../../src/utils/getParentPackageJSON.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\n\ntype PackageJSON = {\n name?: string;\n version?: string;\n private: boolean;\n description?: string;\n homepage?: string;\n bugs: {\n url?: string;\n };\n repository: {\n type?: string;\n url?: string;\n };\n license?: string;\n author: {\n name?: string;\n url?: string;\n };\n contributors?: {\n name?: string;\n email?: string;\n url?: string;\n }[];\n type?: string;\n scripts: Record<string, string>;\n devDependencies: Record<string, string>;\n packageManager?: string;\n engines: Record<string, string>;\n};\n\nexport const getParentPackageJSON = (startDir: string): PackageJSON => {\n let currentDir = startDir;\n\n while (currentDir !== dirname(currentDir)) {\n // Stop when we reach the root\n const packageJsonPath = resolve(currentDir, 'package.json');\n\n if (existsSync(packageJsonPath)) {\n return JSON.parse(readFileSync(packageJsonPath, 'utf8'));\n }\n\n // Move up one directory level\n currentDir = dirname(currentDir);\n }\n\n // Check the root directory as well\n const rootPackageJsonPath = resolve(currentDir, 'package.json');\n if (existsSync(rootPackageJsonPath)) {\n return JSON.parse(readFileSync(rootPackageJsonPath, 'utf8'));\n }\n\n // If no package.json is found in any parent directory\n throw new Error(\n `No package.json found in any parent directory of ${startDir}`\n );\n};\n"],"mappings":";;;;;;AAiCA,MAAa,wBAAwB,aAAkC;CACrE,IAAI,aAAa;CAEjB,OAAO,sCAAuB,UAAU,GAAG;EAEzC,MAAM,yCAA0B,YAAY,cAAc;EAE1D,4BAAe,eAAe,GAC5B,OAAO,KAAK,gCAAmB,iBAAiB,MAAM,CAAC;EAIzD,oCAAqB,UAAU;CACjC;CAGA,MAAM,6CAA8B,YAAY,cAAc;CAC9D,4BAAe,mBAAmB,GAChC,OAAO,KAAK,gCAAmB,qBAAqB,MAAM,CAAC;CAI7D,MAAM,IAAI,MACR,oDAAoD,UACtD;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"listSpecialChars.cjs","names":[],"sources":["../../../src/utils/listSpecialChars.ts"],"sourcesContent":["type ListCharResult = {\n char: string;\n /** First line index contained in this chunk (0-based) */\n lineStart: number;\n /** Start character index in the original text (0-based, inclusive)*/\n charStart: number;\n}[];\n\nconst SPECIAL_CHARS = [\n ' ',\n '\\\\',\n '|',\n '(',\n ')',\n '{',\n '}',\n '[',\n ']',\n '<',\n '>',\n '\"',\n '=',\n '+',\n '*',\n '&',\n '#',\n '%',\n '$',\n '!',\n '?',\n ':',\n ';',\n '~',\n];\n\nexport const listSpecialChars = (text: string): ListCharResult => {\n const results: ListCharResult = [];\n\n let lineIndex = 0;\n\n for (let i = 0; i < text.length; i++) {\n const currentChar = text[i];\n\n // Handle newline characters (\"\\n\"): treat them as a \"\\\\\" special char\n if (currentChar === '\\n') {\n results.push({\n char: '\\\\',\n lineStart: lineIndex,\n charStart: i,\n });\n\n // Move to the next line after recording the special char\n lineIndex++;\n continue;\n }\n\n // Check if the current character is one of the special characters\n if (SPECIAL_CHARS.includes(currentChar)) {\n results.push({\n char: currentChar,\n lineStart: lineIndex,\n charStart: i,\n });\n }\n }\n\n return results;\n};\n"],"mappings":";;;AAQA,MAAM,gBAAgB;CACpB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAa,oBAAoB,SAAiC;CAChE,MAAM,UAA0B,EAAE;CAElC,IAAI,YAAY;CAEhB,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,MAAM,cAAc,KAAK;EAGzB,IAAI,gBAAgB,MAAM;GACxB,QAAQ,KAAK;IACX,MAAM;IACN,WAAW;IACX,WAAW;IACZ,CAAC;GAGF;GACA;;EAIF,IAAI,cAAc,SAAS,YAAY,EACrC,QAAQ,KAAK;GACX,MAAM;GACN,WAAW;GACX,WAAW;GACZ,CAAC;;CAIN,OAAO"}
1
+ {"version":3,"file":"listSpecialChars.cjs","names":[],"sources":["../../../src/utils/listSpecialChars.ts"],"sourcesContent":["type ListCharResult = {\n char: string;\n /** First line index contained in this chunk (0-based) */\n lineStart: number;\n /** Start character index in the original text (0-based, inclusive)*/\n charStart: number;\n}[];\n\nconst SPECIAL_CHARS = [\n ' ',\n '\\\\',\n '|',\n '(',\n ')',\n '{',\n '}',\n '[',\n ']',\n '<',\n '>',\n '\"',\n '=',\n '+',\n '*',\n '&',\n '#',\n '%',\n '$',\n '!',\n '?',\n ':',\n ';',\n '~',\n];\n\nexport const listSpecialChars = (text: string): ListCharResult => {\n const results: ListCharResult = [];\n\n let lineIndex = 0;\n\n for (let i = 0; i < text.length; i++) {\n const currentChar = text[i];\n\n // Handle newline characters (\"\\n\"): treat them as a \"\\\\\" special char\n if (currentChar === '\\n') {\n results.push({\n char: '\\\\',\n lineStart: lineIndex,\n charStart: i,\n });\n\n // Move to the next line after recording the special char\n lineIndex++;\n continue;\n }\n\n // Check if the current character is one of the special characters\n if (SPECIAL_CHARS.includes(currentChar)) {\n results.push({\n char: currentChar,\n lineStart: lineIndex,\n charStart: i,\n });\n }\n }\n\n return results;\n};\n"],"mappings":";;;AAQA,MAAM,gBAAgB;CACpB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,oBAAoB,SAAiC;CAChE,MAAM,UAA0B,CAAC;CAEjC,IAAI,YAAY;CAEhB,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,MAAM,cAAc,KAAK;EAGzB,IAAI,gBAAgB,MAAM;GACxB,QAAQ,KAAK;IACX,MAAM;IACN,WAAW;IACX,WAAW;GACb,CAAC;GAGD;GACA;EACF;EAGA,IAAI,cAAc,SAAS,WAAW,GACpC,QAAQ,KAAK;GACX,MAAM;GACN,WAAW;GACX,WAAW;EACb,CAAC;CAEL;CAEA,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"mapChunksBetweenFiles.cjs","names":["chunkText"],"sources":["../../../src/utils/mapChunksBetweenFiles.ts"],"sourcesContent":["import { splitTextByLines } from '@intlayer/chokidar/utils';\nimport { type ChunkLineResult, chunkText } from './calculateChunks';\n\nexport interface ChunkMapping {\n baseChunk: ChunkLineResult;\n updatedChunk: ChunkLineResult | null; // null if the chunk was deleted\n hasChanges: boolean;\n}\n\n/**\n * Maps chunks from base file to corresponding chunks in updated file,\n * handling insertions, deletions, and modifications properly.\n */\nexport const mapChunksBetweenFiles = (\n baseFileContent: string,\n updatedFileContent: string,\n maxCharsPerChunk: number = 800,\n changedLines?: number[]\n): ChunkMapping[] => {\n const baseChunks = chunkText(baseFileContent, maxCharsPerChunk, 0);\n const baseLines = splitTextByLines(baseFileContent);\n const updatedLines = splitTextByLines(updatedFileContent);\n\n // Create a simple line mapping using LCS (Longest Common Subsequence) approach\n const lineMapping = createLineMapping(baseLines, updatedLines);\n\n return baseChunks.map((baseChunk): ChunkMapping => {\n // Map the base chunk's line range to the updated file\n const mappedRange = mapLineRange(\n baseChunk.lineStart,\n baseChunk.lineLength,\n lineMapping\n );\n\n if (!mappedRange) {\n // This chunk was completely deleted\n return {\n baseChunk,\n updatedChunk: null,\n hasChanges: true,\n };\n }\n\n // Create the corresponding chunk in the updated file\n const updatedChunk: ChunkLineResult = {\n lineStart: mappedRange.start,\n lineLength: mappedRange.length,\n charStart: 0, // Will be calculated when needed\n charLength: 0, // Will be calculated when needed\n content: extractLinesFromRange(\n updatedLines,\n mappedRange.start,\n mappedRange.length\n ),\n };\n\n // Calculate character positions\n updatedChunk.charStart = getCharStartForLine(\n updatedFileContent,\n updatedChunk.lineStart\n );\n updatedChunk.charLength = updatedChunk.content.length;\n\n // Determine if this chunk has changes\n const hasChanges = determineIfChunkHasChanges(\n baseChunk,\n updatedChunk,\n changedLines\n );\n\n return {\n baseChunk,\n updatedChunk,\n hasChanges,\n };\n });\n};\n\n/**\n * Creates a mapping between line numbers in base file and updated file\n * Returns a map where key = base line number, value = updated line number (or null if deleted)\n */\nconst createLineMapping = (\n baseLines: string[],\n updatedLines: string[]\n): Map<number, number | null> => {\n const mapping = new Map<number, number | null>();\n\n // Use a simple diff algorithm (similar to Myers algorithm but simplified)\n const dp: number[][] = Array(baseLines.length + 1)\n .fill(null)\n .map(() => Array(updatedLines.length + 1).fill(0));\n\n // Fill the DP table\n for (let i = 1; i <= baseLines.length; i++) {\n for (let j = 1; j <= updatedLines.length; j++) {\n if (baseLines[i - 1] === updatedLines[j - 1]) {\n dp[i][j] = dp[i - 1][j - 1] + 1;\n } else {\n dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);\n }\n }\n }\n\n // Backtrack to create the mapping\n let i = baseLines.length;\n let j = updatedLines.length;\n\n while (i > 0 || j > 0) {\n if (i > 0 && j > 0 && baseLines[i - 1] === updatedLines[j - 1]) {\n // Lines match\n mapping.set(i - 1, j - 1);\n i--;\n j--;\n } else if (i > 0 && (j === 0 || dp[i - 1][j] >= dp[i][j - 1])) {\n // Line was deleted from base\n mapping.set(i - 1, null);\n i--;\n } else {\n // Line was added to updated (no mapping needed for base)\n j--;\n }\n }\n\n return mapping;\n};\n\n/**\n * Maps a line range from base file to updated file using the line mapping\n */\nconst mapLineRange = (\n baseStart: number,\n baseLength: number,\n lineMapping: Map<number, number | null>\n): { start: number; length: number } | null => {\n const mappedLines: number[] = [];\n\n for (let i = baseStart; i < baseStart + baseLength; i++) {\n const mappedLine = lineMapping.get(i);\n if (mappedLine !== null && mappedLine !== undefined) {\n mappedLines.push(mappedLine);\n }\n }\n\n if (mappedLines.length === 0) {\n return null; // All lines were deleted\n }\n\n // Find the continuous range in the mapped lines\n mappedLines.sort((a, b) => a - b);\n const start = mappedLines[0];\n const end = mappedLines[mappedLines.length - 1];\n\n return {\n start,\n length: end - start + 1,\n };\n};\n\n/**\n * Extracts lines from a range in the lines array\n */\nconst extractLinesFromRange = (\n lines: string[],\n start: number,\n length: number\n): string => {\n const endIndex = Math.min(start + length, lines.length);\n return lines.slice(start, endIndex).join('');\n};\n\n/**\n * Gets the character position where a line starts in the text\n */\nconst getCharStartForLine = (text: string, lineNumber: number): number => {\n const lines = splitTextByLines(text);\n let charStart = 0;\n\n for (let i = 0; i < Math.min(lineNumber, lines.length); i++) {\n charStart += lines[i].length;\n }\n\n return charStart;\n};\n\n/**\n * Determines if a chunk has changes based on git changed lines or content comparison\n */\nconst determineIfChunkHasChanges = (\n baseChunk: ChunkLineResult,\n updatedChunk: ChunkLineResult,\n changedLines?: number[]\n): boolean => {\n // If we have git changed lines, use them for precise detection\n if (changedLines && changedLines.length > 0) {\n return changedLines.some(\n (line) =>\n line >= updatedChunk.lineStart &&\n line < updatedChunk.lineStart + updatedChunk.lineLength\n );\n }\n\n // Fallback to content comparison\n return baseChunk.content !== updatedChunk.content;\n};\n"],"mappings":";;;;;;;;;;AAaA,MAAa,yBACX,iBACA,oBACA,mBAA2B,KAC3B,iBACmB;CACnB,MAAM,aAAaA,wCAAU,iBAAiB,kBAAkB,EAAE;CAClE,MAAM,2DAA6B,gBAAgB;CACnD,MAAM,8DAAgC,mBAAmB;CAGzD,MAAM,cAAc,kBAAkB,WAAW,aAAa;CAE9D,OAAO,WAAW,KAAK,cAA4B;EAEjD,MAAM,cAAc,aAClB,UAAU,WACV,UAAU,YACV,YACD;EAED,IAAI,CAAC,aAEH,OAAO;GACL;GACA,cAAc;GACd,YAAY;GACb;EAIH,MAAM,eAAgC;GACpC,WAAW,YAAY;GACvB,YAAY,YAAY;GACxB,WAAW;GACX,YAAY;GACZ,SAAS,sBACP,cACA,YAAY,OACZ,YAAY,OACb;GACF;EAGD,aAAa,YAAY,oBACvB,oBACA,aAAa,UACd;EACD,aAAa,aAAa,aAAa,QAAQ;EAS/C,OAAO;GACL;GACA;GACA,YATiB,2BACjB,WACA,cACA,aAMU;GACX;GACD;;;;;;AAOJ,MAAM,qBACJ,WACA,iBAC+B;CAC/B,MAAM,0BAAU,IAAI,KAA4B;CAGhD,MAAM,KAAiB,MAAM,UAAU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,OAAO,SAAS,CAAC,KAAK,GAAG;;;;;AAM9C,MAAM,uBAAuB,MAAc,eAA+B;CACxE,MAAM,uDAAyB,KAAK;CACpC,IAAI,YAAY;CAEhB,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,IAAI,YAAY,MAAM,OAAO,EAAE,KACtD,aAAa,MAAM,GAAG;CAGxB,OAAO;;;;;AAMT,MAAM,8BACJ,WACA,cACA,iBACY;CAEZ,IAAI,gBAAgB,aAAa,SAAS,GACxC,OAAO,aAAa,MACjB,SACC,QAAQ,aAAa,aACrB,OAAO,aAAa,YAAY,aAAa,WAChD;CAIH,OAAO,UAAU,YAAY,aAAa"}
1
+ {"version":3,"file":"mapChunksBetweenFiles.cjs","names":["chunkText"],"sources":["../../../src/utils/mapChunksBetweenFiles.ts"],"sourcesContent":["import { splitTextByLines } from '@intlayer/chokidar/utils';\nimport { type ChunkLineResult, chunkText } from './calculateChunks';\n\nexport interface ChunkMapping {\n baseChunk: ChunkLineResult;\n updatedChunk: ChunkLineResult | null; // null if the chunk was deleted\n hasChanges: boolean;\n}\n\n/**\n * Maps chunks from base file to corresponding chunks in updated file,\n * handling insertions, deletions, and modifications properly.\n */\nexport const mapChunksBetweenFiles = (\n baseFileContent: string,\n updatedFileContent: string,\n maxCharsPerChunk: number = 800,\n changedLines?: number[]\n): ChunkMapping[] => {\n const baseChunks = chunkText(baseFileContent, maxCharsPerChunk, 0);\n const baseLines = splitTextByLines(baseFileContent);\n const updatedLines = splitTextByLines(updatedFileContent);\n\n // Create a simple line mapping using LCS (Longest Common Subsequence) approach\n const lineMapping = createLineMapping(baseLines, updatedLines);\n\n return baseChunks.map((baseChunk): ChunkMapping => {\n // Map the base chunk's line range to the updated file\n const mappedRange = mapLineRange(\n baseChunk.lineStart,\n baseChunk.lineLength,\n lineMapping\n );\n\n if (!mappedRange) {\n // This chunk was completely deleted\n return {\n baseChunk,\n updatedChunk: null,\n hasChanges: true,\n };\n }\n\n // Create the corresponding chunk in the updated file\n const updatedChunk: ChunkLineResult = {\n lineStart: mappedRange.start,\n lineLength: mappedRange.length,\n charStart: 0, // Will be calculated when needed\n charLength: 0, // Will be calculated when needed\n content: extractLinesFromRange(\n updatedLines,\n mappedRange.start,\n mappedRange.length\n ),\n };\n\n // Calculate character positions\n updatedChunk.charStart = getCharStartForLine(\n updatedFileContent,\n updatedChunk.lineStart\n );\n updatedChunk.charLength = updatedChunk.content.length;\n\n // Determine if this chunk has changes\n const hasChanges = determineIfChunkHasChanges(\n baseChunk,\n updatedChunk,\n changedLines\n );\n\n return {\n baseChunk,\n updatedChunk,\n hasChanges,\n };\n });\n};\n\n/**\n * Creates a mapping between line numbers in base file and updated file\n * Returns a map where key = base line number, value = updated line number (or null if deleted)\n */\nconst createLineMapping = (\n baseLines: string[],\n updatedLines: string[]\n): Map<number, number | null> => {\n const mapping = new Map<number, number | null>();\n\n // Use a simple diff algorithm (similar to Myers algorithm but simplified)\n const dp: number[][] = Array(baseLines.length + 1)\n .fill(null)\n .map(() => Array(updatedLines.length + 1).fill(0));\n\n // Fill the DP table\n for (let i = 1; i <= baseLines.length; i++) {\n for (let j = 1; j <= updatedLines.length; j++) {\n if (baseLines[i - 1] === updatedLines[j - 1]) {\n dp[i][j] = dp[i - 1][j - 1] + 1;\n } else {\n dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);\n }\n }\n }\n\n // Backtrack to create the mapping\n let i = baseLines.length;\n let j = updatedLines.length;\n\n while (i > 0 || j > 0) {\n if (i > 0 && j > 0 && baseLines[i - 1] === updatedLines[j - 1]) {\n // Lines match\n mapping.set(i - 1, j - 1);\n i--;\n j--;\n } else if (i > 0 && (j === 0 || dp[i - 1][j] >= dp[i][j - 1])) {\n // Line was deleted from base\n mapping.set(i - 1, null);\n i--;\n } else {\n // Line was added to updated (no mapping needed for base)\n j--;\n }\n }\n\n return mapping;\n};\n\n/**\n * Maps a line range from base file to updated file using the line mapping\n */\nconst mapLineRange = (\n baseStart: number,\n baseLength: number,\n lineMapping: Map<number, number | null>\n): { start: number; length: number } | null => {\n const mappedLines: number[] = [];\n\n for (let i = baseStart; i < baseStart + baseLength; i++) {\n const mappedLine = lineMapping.get(i);\n if (mappedLine !== null && mappedLine !== undefined) {\n mappedLines.push(mappedLine);\n }\n }\n\n if (mappedLines.length === 0) {\n return null; // All lines were deleted\n }\n\n // Find the continuous range in the mapped lines\n mappedLines.sort((a, b) => a - b);\n const start = mappedLines[0];\n const end = mappedLines[mappedLines.length - 1];\n\n return {\n start,\n length: end - start + 1,\n };\n};\n\n/**\n * Extracts lines from a range in the lines array\n */\nconst extractLinesFromRange = (\n lines: string[],\n start: number,\n length: number\n): string => {\n const endIndex = Math.min(start + length, lines.length);\n return lines.slice(start, endIndex).join('');\n};\n\n/**\n * Gets the character position where a line starts in the text\n */\nconst getCharStartForLine = (text: string, lineNumber: number): number => {\n const lines = splitTextByLines(text);\n let charStart = 0;\n\n for (let i = 0; i < Math.min(lineNumber, lines.length); i++) {\n charStart += lines[i].length;\n }\n\n return charStart;\n};\n\n/**\n * Determines if a chunk has changes based on git changed lines or content comparison\n */\nconst determineIfChunkHasChanges = (\n baseChunk: ChunkLineResult,\n updatedChunk: ChunkLineResult,\n changedLines?: number[]\n): boolean => {\n // If we have git changed lines, use them for precise detection\n if (changedLines && changedLines.length > 0) {\n return changedLines.some(\n (line) =>\n line >= updatedChunk.lineStart &&\n line < updatedChunk.lineStart + updatedChunk.lineLength\n );\n }\n\n // Fallback to content comparison\n return baseChunk.content !== updatedChunk.content;\n};\n"],"mappings":";;;;;;;;;;AAaA,MAAa,yBACX,iBACA,oBACA,mBAA2B,KAC3B,iBACmB;CACnB,MAAM,aAAaA,wCAAU,iBAAiB,kBAAkB,CAAC;CACjE,MAAM,2DAA6B,eAAe;CAClD,MAAM,8DAAgC,kBAAkB;CAGxD,MAAM,cAAc,kBAAkB,WAAW,YAAY;CAE7D,OAAO,WAAW,KAAK,cAA4B;EAEjD,MAAM,cAAc,aAClB,UAAU,WACV,UAAU,YAC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CAC7C,MAAM,cAAwB,CAAC;CAE/B,KAAK,IAAI,IAAI,WAAW,IAAI,YAAY,YAAY,KAAK;EACvD,MAAM,aAAa,YAAY,IAAI,CAAC;EACpC,IAAI,eAAe,QAAQ,eAAe,QACxC,YAAY,KAAK,UAAU;CAE/B;CAEA,IAAI,YAAY,WAAW,GACzB,OAAO;CAIT,YAAY,MAAM,GAAG,MAAM,IAAI,CAAC;CAChC,MAAM,QAAQ,YAAY;CAG1B,OAAO;EACL;EACA,QAJU,YAAY,YAAY,SAAS,KAI7B,QAAQ;CACxB;AACF;;;;AAKA,MAAM,yBACJ,OACA,OACA,WACW;CACX,MAAM,WAAW,KAAK,IAAI,QAAQ,QAAQ,MAAM,MAAM;CACtD,OAAO,MAAM,MAAM,OAAO,QAAQ,EAAE,KAAK,EAAE;AAC7C;;;;AAKA,MAAM,uBAAuB,MAAc,eAA+B;CACxE,MAAM,uDAAyB,IAAI;CACnC,IAAI,YAAY;CAEhB,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,IAAI,YAAY,MAAM,MAAM,GAAG,KACtD,aAAa,MAAM,GAAG;CAGxB,OAAO;AACT;;;;AAKA,MAAM,8BACJ,WACA,cACA,iBACY;CAEZ,IAAI,gBAAgB,aAAa,SAAS,GACxC,OAAO,aAAa,MACjB,SACC,QAAQ,aAAa,aACrB,OAAO,aAAa,YAAY,aAAa,UACjD;CAIF,OAAO,UAAU,YAAY,aAAa;AAC5C"}
@@ -1 +1 @@
1
- {"version":3,"file":"openBrowser.cjs","names":[],"sources":["../../../src/utils/openBrowser.ts"],"sourcesContent":["import { exec } from 'node:child_process';\nimport { platform } from 'node:os';\n\nexport const openBrowser = (url: string) => {\n const osPlatform = platform();\n let command = '';\n\n if (osPlatform === 'darwin') {\n command = `open \"${url}\"`;\n } else if (osPlatform === 'win32') {\n command = `start \"${url}\"`;\n } else {\n command = `xdg-open \"${url}\"`;\n }\n\n exec(command, (error) => {\n if (error) {\n console.error(`Failed to open browser: ${error.message}`);\n }\n });\n};\n"],"mappings":";;;;;;AAGA,MAAa,eAAe,QAAgB;CAC1C,MAAM,oCAAuB;CAC7B,IAAI,UAAU;CAEd,IAAI,eAAe,UACjB,UAAU,SAAS,IAAI;MAClB,IAAI,eAAe,SACxB,UAAU,UAAU,IAAI;MAExB,UAAU,aAAa,IAAI;CAG7B,6BAAK,UAAU,UAAU;EACvB,IAAI,OACF,QAAQ,MAAM,2BAA2B,MAAM,UAAU;GAE3D"}
1
+ {"version":3,"file":"openBrowser.cjs","names":[],"sources":["../../../src/utils/openBrowser.ts"],"sourcesContent":["import { exec } from 'node:child_process';\nimport { platform } from 'node:os';\n\nexport const openBrowser = (url: string) => {\n const osPlatform = platform();\n let command = '';\n\n if (osPlatform === 'darwin') {\n command = `open \"${url}\"`;\n } else if (osPlatform === 'win32') {\n command = `start \"${url}\"`;\n } else {\n command = `xdg-open \"${url}\"`;\n }\n\n exec(command, (error) => {\n if (error) {\n console.error(`Failed to open browser: ${error.message}`);\n }\n });\n};\n"],"mappings":";;;;;;AAGA,MAAa,eAAe,QAAgB;CAC1C,MAAM,mCAAsB;CAC5B,IAAI,UAAU;CAEd,IAAI,eAAe,UACjB,UAAU,SAAS,IAAI;MAClB,IAAI,eAAe,SACxB,UAAU,UAAU,IAAI;MAExB,UAAU,aAAa,IAAI;CAG7B,6BAAK,UAAU,UAAU;EACvB,IAAI,OACF,QAAQ,MAAM,2BAA2B,MAAM,SAAS;CAE5D,CAAC;AACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"reorderParagraphs.cjs","names":["listSpecialChars"],"sources":["../../../src/utils/reorderParagraphs.ts"],"sourcesContent":["import { listSpecialChars } from './listSpecialChars';\n\n/**\n * Split a text into paragraphs.\n *\n * We consider a paragraph boundary to be a block of at least two consecutive\n * new-lines that is immediately followed by a non-white-space character. This\n * way, internal blank lines that are part of the same paragraph (e.g. a list\n * item that purposely contains a visual break) are preserved while true\n * paragraph breaks – the ones generated when calling `arr.join(\"\\n\\n\")` in\n * the tests – are still detected.\n */\nconst splitByParagraph = (text: string): string[] => {\n const paragraphs: string[] = [];\n\n // Capture the delimiter so that we can inspect how many new-lines it\n // contains. We know that the test strings only use LF, so we keep the\n // regex simple here.\n const tokens = text.split(/(\\n{2,})/);\n\n for (let i = 0; i < tokens.length; i++) {\n const token = tokens[i];\n\n // Even-indexed tokens are the actual paragraph contents.\n if (i % 2 === 0) {\n if (token) paragraphs.push(token);\n continue;\n }\n\n // Odd-indexed tokens are the delimiters (>= two consecutive new-lines).\n // The first and last pairs represent the natural separators that are\n // added when paragraphs are later joined with \"\\n\\n\". Any additional\n // pairs in between correspond to *explicit* blank paragraphs that were\n // present in the original text and must therefore be preserved.\n const pairsOfNewlines = Math.floor(token.length / 2);\n const blankParagraphs = Math.max(0, pairsOfNewlines - 2);\n\n for (let j = 0; j < blankParagraphs; j++) {\n paragraphs.push('\\n\\n');\n }\n }\n\n return paragraphs;\n};\n\n/**\n * Determine whether two paragraphs match – either exactly, or by sharing the\n * same \"special-character signature\".\n */\nconst paragraphMatches = (\n paragraph: string,\n baseParagraph: string,\n paragraphSignature: ReturnType<typeof listSpecialChars>,\n baseSignature: ReturnType<typeof listSpecialChars>\n): boolean => {\n if (paragraph === baseParagraph) return true;\n // fallback to special-character signature comparison\n if (paragraphSignature.length !== baseSignature.length) return false;\n\n for (let i = 0; i < paragraphSignature.length; i++) {\n if (paragraphSignature[i].char !== baseSignature[i].char) {\n return false;\n }\n }\n return true;\n};\n\n/**\n * Re-order `textToReorder` so that its paragraphs follow the ordering found in\n * `baseFileContent`, while preserving any extra paragraphs (those not present\n * in the base file) in a position that is intuitive for a human reader: right\n * after the closest preceding paragraph coming from the base file.\n */\nexport const reorderParagraphs = (\n textToReorder: string,\n baseFileContent: string\n): string => {\n // 1. Split both texts into paragraphs and pre-compute their signatures.\n const baseFileParagraphs = splitByParagraph(baseFileContent);\n const textToReorderParagraphs = splitByParagraph(textToReorder);\n\n const baseSignatures = baseFileParagraphs.map((p) => listSpecialChars(p));\n const textSignatures = textToReorderParagraphs.map((p) =>\n listSpecialChars(p)\n );\n\n // 2. For every paragraph in the text to reorder, find the *first* base\n // paragraph it matches. We only allow each base paragraph to be matched\n // once. Any further identical paragraphs will be treated as \"extra\" and\n // will be positioned later on, next to their closest neighbour.\n const firstMatchIndexForBase: number[] = Array(\n baseFileParagraphs.length\n ).fill(-1);\n const paragraphMatchedBaseIdx: (number | null)[] = Array(\n textToReorderParagraphs.length\n ).fill(null);\n\n for (let i = 0; i < textToReorderParagraphs.length; i++) {\n const paragraph = textToReorderParagraphs[i];\n const sig = textSignatures[i];\n\n // exact match pass first for performance\n let foundIdx = baseFileParagraphs.findIndex(\n (baseParagraph, idx) =>\n firstMatchIndexForBase[idx] === -1 && paragraph === baseParagraph\n );\n\n if (foundIdx === -1) {\n // fallback to the signature comparison\n foundIdx = baseFileParagraphs.findIndex(\n (baseParagraph, idx) =>\n firstMatchIndexForBase[idx] === -1 &&\n paragraphMatches(paragraph, baseParagraph, sig, baseSignatures[idx])\n );\n }\n\n if (foundIdx !== -1) {\n firstMatchIndexForBase[foundIdx] = i;\n paragraphMatchedBaseIdx[i] = foundIdx;\n }\n }\n\n // 3. For the paragraphs that *didn't* get matched to a base paragraph, we\n // record the highest-numbered base paragraph that was matched *before* it\n // in the original text. The extra paragraph will later be placed right\n // after that paragraph in the final ordering.\n const insertAfterBaseIdx: number[] = Array(\n textToReorderParagraphs.length\n ).fill(-1);\n let maxBaseIdxEncountered = -1;\n\n for (let i = 0; i < textToReorderParagraphs.length; i++) {\n const matchedBase = paragraphMatchedBaseIdx[i];\n\n if (matchedBase !== null) {\n if (matchedBase > maxBaseIdxEncountered) {\n maxBaseIdxEncountered = matchedBase;\n }\n } else {\n insertAfterBaseIdx[i] = maxBaseIdxEncountered;\n }\n }\n\n // 4. Build the final, reordered list of paragraphs.\n const result: string[] = [];\n\n // Helper: quickly retrieve all indices of paragraphs that should be inserted\n // after a given base index, while keeping their original order.\n const extraParagraphsBuckets: Record<number, number[]> = {};\n insertAfterBaseIdx.forEach((afterIdx, paragraphIdx) => {\n if (afterIdx === -1) return; // will be handled later (if any)\n extraParagraphsBuckets[afterIdx] = extraParagraphsBuckets[afterIdx] || [];\n extraParagraphsBuckets[afterIdx].push(paragraphIdx);\n });\n\n for (let bIdx = 0; bIdx < baseFileParagraphs.length; bIdx++) {\n const matchedParagraphIdx = firstMatchIndexForBase[bIdx];\n\n if (matchedParagraphIdx !== -1) {\n result.push(textToReorderParagraphs[matchedParagraphIdx]);\n }\n\n if (extraParagraphsBuckets[bIdx]) {\n extraParagraphsBuckets[bIdx].forEach((pIdx) => {\n result.push(textToReorderParagraphs[pIdx]);\n });\n }\n }\n\n // Finally, if there were extra paragraphs appearing *before* any matched\n // base paragraph (insertAfterBaseIdx === -1), we prepend them to the output\n // in their original order.\n const leadingExtras: string[] = [];\n insertAfterBaseIdx.forEach((afterIdx, pIdx) => {\n if (afterIdx === -1 && paragraphMatchedBaseIdx[pIdx] === null) {\n leadingExtras.push(textToReorderParagraphs[pIdx]);\n }\n });\n\n return [...leadingExtras, ...result].join('\\n\\n');\n};\n"],"mappings":";;;;;;;;;;;;;;AAYA,MAAM,oBAAoB,SAA2B;CACnD,MAAM,aAAuB,EAAE;CAK/B,MAAM,SAAS,KAAK,MAAM,WAAW;CAErC,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;EACtC,MAAM,QAAQ,OAAO;EAGrB,IAAI,IAAI,MAAM,GAAG;GACf,IAAI,OAAO,WAAW,KAAK,MAAM;GACjC;;EAQF,MAAM,kBAAkB,KAAK,MAAM,MAAM,SAAS,EAAE;EACpD,MAAM,kBAAkB,KAAK,IAAI,GAAG,kBAAkB,EAAE;EAExD,KAAK,IAAI,IAAI,GAAG,IAAI,iBAAiB,KACnC,WAAW,KAAK,OAAO;;CAI3B,OAAO;;;;;;AAOT,MAAM,oBACJ,WACA,eACA,oBACA,kBACY;CACZ,IAAI,cAAc,eAAe,OAAO;CAExC,IAAI,m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Aa,IAAI;EACrB,uBAAuB,YAAY,uBAAuB,aAAa,EAAE;EACzE,uBAAuB,UAAU,KAAK,aAAa;GACnD;CAEF,KAAK,IAAI,OAAO,GAAG,OAAO,mBAAmB,QAAQ,QAAQ;EAC3D,MAAM,sBAAsB,uBAAuB;EAEnD,IAAI,wBAAwB,IAC1B,OAAO,KAAK,wBAAwB,qBAAqB;EAG3D,IAAI,uBAAuB,OACzB,uBAAuB,MAAM,SAAS,SAAS;GAC7C,OAAO,KAAK,wBAAwB,MAAM;IAC1C;;CAON,MAAM,gBAA0B,EAAE;CAClC,mBAAmB,SAAS,UAAU,SAAS;EAC7C,IAAI,aAAa,MAAM,wBAAwB,UAAU,MACvD,cAAc,KAAK,wBAAwB,MAAM;GAEnD;CAEF,OAAO,CAAC,GAAG,eAAe,GAAG,OAAO,CAAC,KAAK,OAAO"}
1
+ {"version":3,"file":"reorderParagraphs.cjs","names":["listSpecialChars"],"sources":["../../../src/utils/reorderParagraphs.ts"],"sourcesContent":["import { listSpecialChars } from './listSpecialChars';\n\n/**\n * Split a text into paragraphs.\n *\n * We consider a paragraph boundary to be a block of at least two consecutive\n * new-lines that is immediately followed by a non-white-space character. This\n * way, internal blank lines that are part of the same paragraph (e.g. a list\n * item that purposely contains a visual break) are preserved while true\n * paragraph breaks – the ones generated when calling `arr.join(\"\\n\\n\")` in\n * the tests – are still detected.\n */\nconst splitByParagraph = (text: string): string[] => {\n const paragraphs: string[] = [];\n\n // Capture the delimiter so that we can inspect how many new-lines it\n // contains. We know that the test strings only use LF, so we keep the\n // regex simple here.\n const tokens = text.split(/(\\n{2,})/);\n\n for (let i = 0; i < tokens.length; i++) {\n const token = tokens[i];\n\n // Even-indexed tokens are the actual paragraph contents.\n if (i % 2 === 0) {\n if (token) paragraphs.push(token);\n continue;\n }\n\n // Odd-indexed tokens are the delimiters (>= two consecutive new-lines).\n // The first and last pairs represent the natural separators that are\n // added when paragraphs are later joined with \"\\n\\n\". Any additional\n // pairs in between correspond to *explicit* blank paragraphs that were\n // present in the original text and must therefore be preserved.\n const pairsOfNewlines = Math.floor(token.length / 2);\n const blankParagraphs = Math.max(0, pairsOfNewlines - 2);\n\n for (let j = 0; j < blankParagraphs; j++) {\n paragraphs.push('\\n\\n');\n }\n }\n\n return paragraphs;\n};\n\n/**\n * Determine whether two paragraphs match – either exactly, or by sharing the\n * same \"special-character signature\".\n */\nconst paragraphMatches = (\n paragraph: string,\n baseParagraph: string,\n paragraphSignature: ReturnType<typeof listSpecialChars>,\n baseSignature: ReturnType<typeof listSpecialChars>\n): boolean => {\n if (paragraph === baseParagraph) return true;\n // fallback to special-character signature comparison\n if (paragraphSignature.length !== baseSignature.length) return false;\n\n for (let i = 0; i < paragraphSignature.length; i++) {\n if (paragraphSignature[i].char !== baseSignature[i].char) {\n return false;\n }\n }\n return true;\n};\n\n/**\n * Re-order `textToReorder` so that its paragraphs follow the ordering found in\n * `baseFileContent`, while preserving any extra paragraphs (those not present\n * in the base file) in a position that is intuitive for a human reader: right\n * after the closest preceding paragraph coming from the base file.\n */\nexport const reorderParagraphs = (\n textToReorder: string,\n baseFileContent: string\n): string => {\n // 1. Split both texts into paragraphs and pre-compute their signatures.\n const baseFileParagraphs = splitByParagraph(baseFileContent);\n const textToReorderParagraphs = splitByParagraph(textToReorder);\n\n const baseSignatures = baseFileParagraphs.map((p) => listSpecialChars(p));\n const textSignatures = textToReorderParagraphs.map((p) =>\n listSpecialChars(p)\n );\n\n // 2. For every paragraph in the text to reorder, find the *first* base\n // paragraph it matches. We only allow each base paragraph to be matched\n // once. Any further identical paragraphs will be treated as \"extra\" and\n // will be positioned later on, next to their closest neighbour.\n const firstMatchIndexForBase: number[] = Array(\n baseFileParagraphs.length\n ).fill(-1);\n const paragraphMatchedBaseIdx: (number | null)[] = Array(\n textToReorderParagraphs.length\n ).fill(null);\n\n for (let i = 0; i < textToReorderParagraphs.length; i++) {\n const paragraph = textToReorderParagraphs[i];\n const sig = textSignatures[i];\n\n // exact match pass first for performance\n let foundIdx = baseFileParagraphs.findIndex(\n (baseParagraph, idx) =>\n firstMatchIndexForBase[idx] === -1 && paragraph === baseParagraph\n );\n\n if (foundIdx === -1) {\n // fallback to the signature comparison\n foundIdx = baseFileParagraphs.findIndex(\n (baseParagraph, idx) =>\n firstMatchIndexForBase[idx] === -1 &&\n paragraphMatches(paragraph, baseParagraph, sig, baseSignatures[idx])\n );\n }\n\n if (foundIdx !== -1) {\n firstMatchIndexForBase[foundIdx] = i;\n paragraphMatchedBaseIdx[i] = foundIdx;\n }\n }\n\n // 3. For the paragraphs that *didn't* get matched to a base paragraph, we\n // record the highest-numbered base paragraph that was matched *before* it\n // in the original text. The extra paragraph will later be placed right\n // after that paragraph in the final ordering.\n const insertAfterBaseIdx: number[] = Array(\n textToReorderParagraphs.length\n ).fill(-1);\n let maxBaseIdxEncountered = -1;\n\n for (let i = 0; i < textToReorderParagraphs.length; i++) {\n const matchedBase = paragraphMatchedBaseIdx[i];\n\n if (matchedBase !== null) {\n if (matchedBase > maxBaseIdxEncountered) {\n maxBaseIdxEncountered = matchedBase;\n }\n } else {\n insertAfterBaseIdx[i] = maxBaseIdxEncountered;\n }\n }\n\n // 4. Build the final, reordered list of paragraphs.\n const result: string[] = [];\n\n // Helper: quickly retrieve all indices of paragraphs that should be inserted\n // after a given base index, while keeping their original order.\n const extraParagraphsBuckets: Record<number, number[]> = {};\n insertAfterBaseIdx.forEach((afterIdx, paragraphIdx) => {\n if (afterIdx === -1) return; // will be handled later (if any)\n extraParagraphsBuckets[afterIdx] = extraParagraphsBuckets[afterIdx] || [];\n extraParagraphsBuckets[afterIdx].push(paragraphIdx);\n });\n\n for (let bIdx = 0; bIdx < baseFileParagraphs.length; bIdx++) {\n const matchedParagraphIdx = firstMatchIndexForBase[bIdx];\n\n if (matchedParagraphIdx !== -1) {\n result.push(textToReorderParagraphs[matchedParagraphIdx]);\n }\n\n if (extraParagraphsBuckets[bIdx]) {\n extraParagraphsBuckets[bIdx].forEach((pIdx) => {\n result.push(textToReorderParagraphs[pIdx]);\n });\n }\n }\n\n // Finally, if there were extra paragraphs appearing *before* any matched\n // base paragraph (insertAfterBaseIdx === -1), we prepend them to the output\n // in their original order.\n const leadingExtras: string[] = [];\n insertAfterBaseIdx.forEach((afterIdx, pIdx) => {\n if (afterIdx === -1 && paragraphMatchedBaseIdx[pIdx] === null) {\n leadingExtras.push(textToReorderParagraphs[pIdx]);\n }\n });\n\n return [...leadingExtras, ...result].join('\\n\\n');\n};\n"],"mappings":";;;;;;;;;;;;;;AAYA,MAAM,oBAAoB,SAA2B;CACnD,MAAM,aAAuB,CAAC;CAK9B,MAAM,SAAS,KAAK,MAAM,UAAU;CAEpC,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;EACtC,MAAM,QAAQ,OAAO;EAGrB,IAAI,IAAI,MAAM,GAAG;GACf,IAAI,OAAO,WAAW,KAAK,KAAK;GAChC;EACF;EAOA,MAAM,kBAAkB,KAAK,MAAM,MAAM,SAAS,CAAC;EACnD,MAAM,kBAAkB,KAAK,IAAI,GAAG,kBAAkB,CAAC;EAEvD,KAAK,IAAI,IAAI,GAAG,IAAI,iBAAiB,KACnC,WAAW,KAAK,MAAM;CAE1B;CAEA,OAAO;AACT;;;;;AAMA,MAAM,oBACJ,WACA,eACA,oBACA,kBACY;CACZ,IAAI,cAAc,eAAe,OAAO;CAExC,IAAI,mBAAmB,WAAW,cAAc,QAAQ,OAAO;CAE/D,KAAK,IAAI,IAAI,GAAG,IAAI,mBAAmB,QAAQ,KAC7C,IAAI,mBAAmB,GAAG,SAAS,cAAc,GAAG,MAClD,OAAO;CAGX,OAAO;AACT;;;;;;;AAQA,MAAa,qBACX,eACA,oBACW;CAEX,MAAM,qBAAqB,iBAAiB,eAAe;CAC3D,MAAM,0BAA0B,iBAAiB,aAAa;CAE9D,MAAM,iBAAiB,mBAAmB,KAAK,MAAMA,gDAAiB,CAAC,CAAC;CACxE,MAAM,iBAAiB,wBAAwB,KAAK,MAClDA,gDAA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MAAM,gBAA0B,CAAC;CACjC,mBAAmB,SAAS,UAAU,SAAS;EAC7C,IAAI,aAAa,MAAM,wBAAwB,UAAU,MACvD,cAAc,KAAK,wBAAwB,KAAK;CAEpD,CAAC;CAED,OAAO,CAAC,GAAG,eAAe,GAAG,MAAM,EAAE,KAAK,MAAM;AAClD"}
@@ -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 * 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 projectOptions: configuration.ai as 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":";;;;;;;;AAgBA,WAAW,sBAAsB;AAEjC,MAAM,eAAe,WAAsB,cAA6B;CACtE,UAAU;wCACC,aAAaA,wBAAW,UAAU;wCAClC,WAAW,YAAY,aAAaA,wBAAW,KAAK;wCACpD,YAAYA,wBAAW,UAAU;wCACjC,WAAW,SAAS,aAAaA,wBAAW,KAAK;wCACjD,cAAcA,wBAAW,UAAU;wCACnC,WAAW,SAAS,MAAM,aAAaA,wBAAW,KAAK;EACjE,CAAC;;;;;;;AAQJ,MAAa,UAAU,OACrB,eACA,cACuC;CACvC,MAAM,sDAAyB,cAAc;CAQ7C,IALE,WAAW,UACX,WAAW,aAAa,YACxB,cAAc,IAAI,UAClB,cAAc,IAAI,aAAa,UAElB;EAEb,IAAI;EAEJ,IAAI;GACF,WAAW,MAAM,OAAO;UAClB;GAEN,UACE;0CACW,2CAA2CA,wBAAW,KAAK;0CAC3D,gBAAgBA,wBAAW,WAAW;0CAE7C,iFACAA,wBAAW,KACZ;IACF,EACD,EACE,OAAO,QACR,CACF;GAGD,MAAM,cAAc,MAAMC,wCAAc,eAAe,UAAU;GACjE,YAAY,aAAa,EAAE,EAAE,UAAU;GACvC,OAAO;IACL,YAAY;IACZ;IACD;;EAIH,UAAU,uCACC,gBAAgBD,wBAAW,WAAW,wCACtC,+BAA+BA,wBAAW,UAAU,CAC9D,CAAC;EAEF,MAAM,WAAW,MAAM,SAAS,YAAY;GAC1C,aAAa;GACb,gBAAgB,cAAc;GAC9B,YAAY,CAAC,SAAS;GACvB,CAAC;EAEF,YAAY,aAAa,EAAE,EAAE,UAAU;EAEvC,OAAO;GACL;GACA;GACA,YAAY;GACZ,aAAa;GACd;;CAIH,MAAM,cAAc,MAAMC,wCAAc,eAAe,UAAU;CACjE,YAAY,aAAa,EAAE,EAAE,UAAU;CAEvC,OAAO;EACL,YAAY;EACZ;EACD"}
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 projectOptions: configuration.ai as 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":";;;;;;;;AAgBA,WAAW,sBAAsB;AAEjC,MAAM,eAAe,WAAsB,cAA6B;CACtE,UAAU;wCACC,aAAaA,wBAAW,SAAS;wCACjC,WAAW,YAAY,aAAaA,wBAAW,IAAI;wCACnD,YAAYA,wBAAW,SAAS;wCAChC,WAAW,SAAS,aAAaA,wBAAW,IAAI;wCAChD,cAAcA,wBAAW,SAAS;wCAClC,WAAW,SAAS,MAAM,aAAaA,wBAAW,IAAI;CACjE,CAAC;AACH;;;;;;AAOA,MAAa,UAAU,OACrB,eACA,cACuC;CACvC,MAAM,sDAAyB,aAAa;CAQ5C,IALE,WAAW,UACX,WAAW,aAAa,YACxB,cAAc,IAAI,UAClB,cAAc,IAAI,aAAa,UAElB;EAEb,IAAI;EAEJ,IAAI;GACF,WAAW,MAAM,OAAO;EAC1B,QAAQ;GAEN,UACE;0CACW,2CAA2CA,wBAAW,IAAI;0CAC1D,gBAAgBA,wBAAW,UAAU;0CAE5C,iFACAA,wBAAW,IACb;GACF,GACA,EACE,OAAO,OACT,CACF;GAGA,MAAM,cAAc,MAAMC,wCAAc,eAAe,SAAS;GAChE,YAAY,aAAa,CAAC,GAAG,SAAS;GACtC,OAAO;IACL,YAAY;IACZ;GACF;EACF;EAGA,UAAU,uCACC,gBAAgBD,wBAAW,UAAU,yCACrC,+BAA+BA,wBAAW,SAAS,CAC9D,CAAC;EAED,MAAM,WAAW,MAAM,SAAS,YAAY;GAC1C,aAAa;GACb,gBAAgB,cAAc;GAC9B,YAAY,CAAC,QAAQ;EACvB,CAAC;EAED,YAAY,aAAa,CAAC,GAAG,SAAS;EAEtC,OAAO;GACL;GACA;GACA,YAAY;GACZ,aAAa;EACf;CACF;CAGA,MAAM,cAAc,MAAMC,wCAAc,eAAe,SAAS;CAChE,YAAY,aAAa,CAAC,GAAG,SAAS;CAEtC,OAAO;EACL,YAAY;EACZ;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"watch.cjs","names":[],"sources":["../../src/watch.ts"],"sourcesContent":["import { logConfigDetails } from '@intlayer/chokidar/cli';\nimport { runParallel } from '@intlayer/chokidar/utils';\nimport { watch } from '@intlayer/chokidar/watcher';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\n\ntype WatchOptions = {\n skipPrepare?: boolean;\n with?: string | string[];\n configOptions?: GetConfigurationOptions;\n};\n\n/**\n * Get locales dictionaries .content.{json|ts|tsx|js|jsx|mjs|cjs} and build the JSON dictionaries in the .intlayer directory.\n * Watch mode available to get the change in the .content.{json|ts|tsx|js|jsx|mjs|cjs}\n */\nexport const watchContentDeclaration = async (options?: WatchOptions) => {\n const config = getConfiguration(options?.configOptions);\n logConfigDetails(options?.configOptions);\n\n const appLogger = getAppLogger(config);\n\n // Store references to the child process\n let parallelProcess: ReturnType<typeof runParallel> | undefined;\n\n if (options?.with) {\n parallelProcess = runParallel(options.with);\n // Handle the promise to avoid unhandled rejection\n parallelProcess.result.catch(() => {\n // Parallel process failed or was terminated\n process.exit(1);\n });\n }\n\n // Capture the watcher instance\n const watcher = await watch({\n persistent: true,\n skipPrepare: options?.skipPrepare ?? false,\n });\n\n // Define a Graceful Shutdown function\n let isShuttingDown = false;\n const handleShutdown = async () => {\n // Prevent multiple calls\n if (isShuttingDown) return;\n isShuttingDown = true;\n\n appLogger('Stopping Intlayer watcher...');\n\n try {\n // Kill the parallel process (e.g., Next.js) before closing the watcher\n if (parallelProcess) {\n parallelProcess.kill();\n }\n\n // Close the file watcher to stop \"esbuild service not running\" errors\n await watcher.close();\n } catch (error) {\n console.error('Error during shutdown:', error);\n } finally {\n process.exit(0);\n }\n };\n\n // Attach Signal Listeners\n process.on('SIGINT', handleShutdown);\n process.on('SIGTERM', handleShutdown);\n};\n"],"mappings":";;;;;;;;;;;;;AAmBA,MAAa,0BAA0B,OAAO,YAA2B;CACvE,MAAM,qDAA0B,SAAS,cAAc;CACvD,6CAAiB,SAAS,cAAc;CAExC,MAAM,sDAAyB,OAAO;CAGtC,IAAI;CAEJ,IAAI,SAAS,MAAM;EACjB,4DAA8B,QAAQ,KAAK;EAE3C,gBAAgB,OAAO,YAAY;GAEjC,QAAQ,KAAK,EAAE;IACf;;CAIJ,MAAM,UAAU,4CAAY;EAC1B,YAAY;EACZ,aAAa,SAAS,eAAe;EACtC,CAAC;CAGF,IAAI,iBAAiB;CACrB,MAAM,iBAAiB,YAAY;EAEjC,IAAI,gBAAgB;EACpB,iBAAiB;EAEjB,UAAU,+BAA+B;EAEzC,IAAI;GAEF,IAAI,iBACF,gBAAgB,MAAM;GAIxB,MAAM,QAAQ,OAAO;WACd,OAAO;GACd,QAAQ,MAAM,0BAA0B,MAAM;YACtC;GACR,QAAQ,KAAK,EAAE;;;CAKnB,QAAQ,GAAG,UAAU,eAAe;CACpC,QAAQ,GAAG,WAAW,eAAe"}
1
+ {"version":3,"file":"watch.cjs","names":[],"sources":["../../src/watch.ts"],"sourcesContent":["import { logConfigDetails } from '@intlayer/chokidar/cli';\nimport { runParallel } from '@intlayer/chokidar/utils';\nimport { watch } from '@intlayer/chokidar/watcher';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\n\ntype WatchOptions = {\n skipPrepare?: boolean;\n with?: string | string[];\n configOptions?: GetConfigurationOptions;\n};\n\n/**\n * Get locales dictionaries .content.{json|ts|tsx|js|jsx|mjs|cjs} and build the JSON dictionaries in the .intlayer directory.\n * Watch mode available to get the change in the .content.{json|ts|tsx|js|jsx|mjs|cjs}\n */\nexport const watchContentDeclaration = async (options?: WatchOptions) => {\n const config = getConfiguration(options?.configOptions);\n logConfigDetails(options?.configOptions);\n\n const appLogger = getAppLogger(config);\n\n // Store references to the child process\n let parallelProcess: ReturnType<typeof runParallel> | undefined;\n\n if (options?.with) {\n parallelProcess = runParallel(options.with);\n // Handle the promise to avoid unhandled rejection\n parallelProcess.result.catch(() => {\n // Parallel process failed or was terminated\n process.exit(1);\n });\n }\n\n // Capture the watcher instance\n const watcher = await watch({\n persistent: true,\n skipPrepare: options?.skipPrepare ?? false,\n });\n\n // Define a Graceful Shutdown function\n let isShuttingDown = false;\n const handleShutdown = async () => {\n // Prevent multiple calls\n if (isShuttingDown) return;\n isShuttingDown = true;\n\n appLogger('Stopping Intlayer watcher...');\n\n try {\n // Kill the parallel process (e.g., Next.js) before closing the watcher\n if (parallelProcess) {\n parallelProcess.kill();\n }\n\n // Close the file watcher to stop \"esbuild service not running\" errors\n await watcher.close();\n } catch (error) {\n console.error('Error during shutdown:', error);\n } finally {\n process.exit(0);\n }\n };\n\n // Attach Signal Listeners\n process.on('SIGINT', handleShutdown);\n process.on('SIGTERM', handleShutdown);\n};\n"],"mappings":";;;;;;;;;;;;;AAmBA,MAAa,0BAA0B,OAAO,YAA2B;CACvE,MAAM,qDAA0B,SAAS,aAAa;CACtD,6CAAiB,SAAS,aAAa;CAEvC,MAAM,sDAAyB,MAAM;CAGrC,IAAI;CAEJ,IAAI,SAAS,MAAM;EACjB,4DAA8B,QAAQ,IAAI;EAE1C,gBAAgB,OAAO,YAAY;GAEjC,QAAQ,KAAK,CAAC;EAChB,CAAC;CACH;CAGA,MAAM,UAAU,4CAAY;EAC1B,YAAY;EACZ,aAAa,SAAS,eAAe;CACvC,CAAC;CAGD,IAAI,iBAAiB;CACrB,MAAM,iBAAiB,YAAY;EAEjC,IAAI,gBAAgB;EACpB,iBAAiB;EAEjB,UAAU,8BAA8B;EAExC,IAAI;GAEF,IAAI,iBACF,gBAAgB,KAAK;GAIvB,MAAM,QAAQ,MAAM;EACtB,SAAS,OAAO;GACd,QAAQ,MAAM,0BAA0B,KAAK;EAC/C,UAAU;GACR,QAAQ,KAAK,CAAC;EAChB;CACF;CAGA,QAAQ,GAAG,UAAU,cAAc;CACnC,QAAQ,GAAG,WAAW,cAAc;AACtC"}
@@ -1 +1 @@
1
- {"version":3,"file":"IntlayerEventListener.mjs","names":[],"sources":["../../src/IntlayerEventListener.ts"],"sourcesContent":["import { getIntlayerAPIProxy } from '@intlayer/api';\n// @ts-ignore: @intlayer/backend is not built yet\nimport type { DictionaryAPI, MessageEventData } from '@intlayer/backend';\nimport { default as configuration } from '@intlayer/config/built';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { EventSource } from 'eventsource';\n\nexport type IntlayerMessageEvent = MessageEvent;\n\n/**\n * IntlayerEventListener class to listen for dictionary changes via SSE (Server-Sent Events).\n *\n * Usage example:\n *\n * import { buildIntlayerDictionary } from './transpiler/declaration_file_to_dictionary/intlayer_dictionary';\n * import { IntlayerEventListener } from '@intlayer/api';\n *\n * export const checkDictionaryChanges = async () => {\n * // Instantiate the listener\n * const eventListener = new IntlayerEventListener();\n *\n * // Set up your callbacks\n * eventListener.onDictionaryChange = async (dictionary) => {\n * await buildIntlayerDictionary(dictionary);\n * };\n *\n * // Initialize the listener\n * await eventListener.initialize();\n *\n * // Optionally, clean up later when you’re done\n * // eventListener.cleanup();\n * };\n */\nexport class IntlayerEventListener {\n private appLogger = getAppLogger(configuration);\n\n private eventSource: EventSource | null = null;\n private reconnectAttempts = 0;\n private maxReconnectAttempts = 5;\n private reconnectDelay = 1000; // Start with 1 second\n private isManuallyDisconnected = false;\n private reconnectTimeout: NodeJS.Timeout | null = null;\n\n /**\n * Callback triggered when a Dictionary is ADDED.\n */\n public onDictionaryAdded?: (dictionary: DictionaryAPI) => any;\n\n /**\n * Callback triggered when a Dictionary is UPDATED.\n */\n public onDictionaryChange?: (dictionary: DictionaryAPI) => any;\n\n /**\n * Callback triggered when a Dictionary is DELETED.\n */\n public onDictionaryDeleted?: (dictionary: DictionaryAPI) => any;\n\n /**\n * Callback triggered when connection is established or re-established.\n */\n public onConnectionOpen?: () => any;\n\n /**\n * Callback triggered when connection encounters an error.\n */\n public onConnectionError?: (error: Event) => any;\n\n constructor(private intlayerConfig: IntlayerConfig = configuration) {\n this.appLogger = getAppLogger(this.intlayerConfig);\n }\n\n /**\n * Initializes the EventSource connection using the given intlayerConfig\n * (or the default config if none was provided).\n */\n public async initialize(): Promise<void> {\n this.isManuallyDisconnected = false;\n await this.connect();\n }\n\n /**\n * Establishes the EventSource connection with automatic reconnection support.\n */\n private async connect(): Promise<void> {\n try {\n const backendURL = this.intlayerConfig.editor.backendURL;\n\n // Retrieve the access token via proxy\n const accessToken = await getIntlayerAPIProxy(\n undefined,\n this.intlayerConfig\n ).oAuth.getOAuth2AccessToken();\n\n if (!accessToken) {\n throw new Error('Failed to retrieve access token');\n }\n\n const API_ROUTE = `${backendURL}/api/event-listener`;\n\n // Close existing connection if any\n if (this.eventSource) {\n this.eventSource.close();\n }\n\n this.eventSource = new EventSource(API_ROUTE, {\n fetch: (input, init) =>\n fetch(input, {\n ...init,\n headers: {\n ...(init?.headers ?? {}),\n Authorization: `Bearer ${accessToken.data?.accessToken}`,\n },\n }),\n });\n\n this.eventSource.onopen = () => {\n this.reconnectAttempts = 0;\n this.reconnectDelay = 1000; // Reset delay\n this.onConnectionOpen?.();\n };\n\n this.eventSource.onmessage = (event) => this.handleMessage(event);\n this.eventSource.onerror = (event) => this.handleError(event);\n } catch (_error) {\n this.appLogger('Failed to establish EventSource connection:', {\n level: 'error',\n });\n this.scheduleReconnect();\n }\n }\n\n /**\n * Cleans up (closes) the EventSource connection.\n */\n public cleanup(): void {\n this.isManuallyDisconnected = true;\n\n if (this.reconnectTimeout) {\n clearTimeout(this.reconnectTimeout);\n this.reconnectTimeout = null;\n }\n\n if (this.eventSource) {\n this.eventSource.close();\n this.eventSource = null;\n }\n }\n\n /**\n * Schedules a reconnection attempt with exponential backoff.\n */\n private scheduleReconnect(): void {\n if (\n this.isManuallyDisconnected ||\n this.reconnectAttempts >= this.maxReconnectAttempts\n ) {\n if (this.reconnectAttempts >= this.maxReconnectAttempts) {\n this.appLogger(\n [\n `Max reconnection attempts (${this.maxReconnectAttempts}) reached. Giving up.`,\n ],\n {\n level: 'error',\n }\n );\n }\n return;\n }\n\n this.reconnectAttempts++;\n const delay = this.reconnectDelay * 2 ** (this.reconnectAttempts - 1); // Exponential backoff\n\n this.appLogger(\n `Scheduling reconnection attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts} in ${delay}ms`\n );\n\n this.reconnectTimeout = setTimeout(async () => {\n if (!this.isManuallyDisconnected) {\n await this.connect();\n }\n }, delay);\n }\n\n /**\n * Handles incoming SSE messages, parses the event data,\n * and invokes the appropriate callback.\n */\n private async handleMessage(event: IntlayerMessageEvent): Promise<void> {\n try {\n const { data } = event;\n\n const dataJSON: MessageEventData[] = JSON.parse(data);\n\n for (const dataEl of dataJSON) {\n switch (dataEl.object) {\n case 'DICTIONARY':\n switch (dataEl.status) {\n case 'ADDED':\n await this.onDictionaryAdded?.(dataEl.data);\n break;\n case 'UPDATED':\n await this.onDictionaryChange?.(dataEl.data);\n break;\n case 'DELETED':\n await this.onDictionaryDeleted?.(dataEl.data);\n break;\n default:\n this.appLogger(\n ['Unhandled dictionary status:', dataEl.status],\n {\n level: 'error',\n }\n );\n break;\n }\n break;\n default:\n this.appLogger(['Unknown object type:', dataEl.object], {\n level: 'error',\n });\n break;\n }\n }\n } catch (error) {\n this.appLogger(['Error processing dictionary update:', error], {\n level: 'error',\n });\n }\n }\n\n /**\n * Handles any SSE errors and attempts reconnection if appropriate.\n */\n private handleError(event: Event): void {\n const errorEvent = event as any;\n\n // Log detailed error information\n this.appLogger(\n [\n 'EventSource error:',\n {\n type: errorEvent.type,\n message: errorEvent.message,\n code: errorEvent.code,\n readyState: this.eventSource?.readyState,\n url: this.eventSource?.url,\n },\n ],\n {\n level: 'error',\n }\n );\n\n // Notify error callback\n this.onConnectionError?.(event);\n\n // Check if this is a connection close error\n const isConnectionClosed =\n errorEvent.type === 'error' &&\n (errorEvent.message?.includes('terminated') ||\n errorEvent.message?.includes('closed') ||\n this.eventSource?.readyState === EventSource.CLOSED);\n\n if (isConnectionClosed && !this.isManuallyDisconnected) {\n this.appLogger(\n 'Connection was terminated by server, attempting to reconnect...'\n );\n this.scheduleReconnect();\n } else {\n // For other types of errors, close the connection\n this.cleanup();\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,wBAAb,MAAmC;CAmCb;CAlCpB,AAAQ,YAAY,aAAa,cAAc;CAE/C,AAAQ,cAAkC;CAC1C,AAAQ,oBAAoB;CAC5B,AAAQ,uBAAuB;CAC/B,AAAQ,iBAAiB;CACzB,AAAQ,yBAAyB;CACjC,AAAQ,mBAA0C;;;;CAKlD,AAAO;;;;CAKP,AAAO;;;;CAKP,AAAO;;;;CAKP,AAAO;;;;CAKP,AAAO;CAEP,YAAY,AAAQ,iBAAiC,eAAe;EAAhD;EAClB,KAAK,YAAY,aAAa,KAAK,eAAe;;;;;;CAOpD,MAAa,aAA4B;EACvC,KAAK,yBAAyB;EAC9B,MAAM,KAAK,SAAS;;;;;CAMtB,MAAc,UAAyB;EACrC,IAAI;GACF,MAAM,aAAa,KAAK,eAAe,OAAO;GAG9C,MAAM,cAAc,MAAM,oBACxB,QACA,KAAK,eACN,CAAC,MAAM,sBAAsB;GAE9B,IAAI,CAAC,aACH,MAAM,IAAI,MAAM,kCAAkC;GAGpD,MAAM,YAAY,GAAG,WAAW;GAGhC,IAAI,KAAK,aACP,KAAK,YAAY,OAAO;GAG1B,KAAK,cAAc,IAAI,YAAY,WAAW,EAC5C,QAAQ,OAAO,SACb,MAAM,OAAO;IACX,GAAG;IACH,SAAS;KACP,GAAI,MAAM,WAAW,EAAE;KACvB,eAAe,UAAU,YAAY,MAAM;KAC5C;IACF,CAAC,EACL,CAAC;GAEF,KAAK,YAAY,eAAe;IAC9B,KAAK,oBAAoB;IACzB,KAAK,i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O,EAC/C,EACE,OAAO,SACR,CACF;OACD;;KAEJ;IACF;KACE,KAAK,UAAU,CAAC,wBAAwB,OAAO,OAAO,EAAE,EACtD,OAAO,SACR,CAAC;KACF;;WAGC,OAAO;GACd,KAAK,UAAU,CAAC,uCAAuC,MAAM,EAAE,EAC7D,OAAO,SACR,CAAC;;;;;;CAON,AAAQ,YAAY,OAAoB;EACtC,MAAM,aAAa;EAGnB,KAAK,UACH,CACE,sBACA;GACE,MAAM,WAAW;GACjB,SAAS,WAAW;GACpB,MAAM,WAAW;GACjB,YAAY,KAAK,aAAa;GAC9B,KAAK,KAAK,aAAa;GACxB,CACF,EACD,EACE,OAAO,SACR,CACF;EAGD,KAAK,oBAAoB,MAAM;EAS/B,IALE,WAAW,SAAS,YACnB,WAAW,SAAS,SAAS,aAAa,IACzC,WAAW,SAAS,SAAS,SAAS,IACtC,KAAK,aAAa,eAAe,YAAY,WAEvB,CAAC,KAAK,wBAAwB;GACtD,KAAK,UACH,kEACD;GACD,KAAK,mBAAmB;SAGxB,KAAK,SAAS"}
1
+ {"version":3,"file":"IntlayerEventListener.mjs","names":[],"sources":["../../src/IntlayerEventListener.ts"],"sourcesContent":["import { getIntlayerAPIProxy } from '@intlayer/api';\n// @ts-ignore: @intlayer/backend is not built yet\nimport type { DictionaryAPI, MessageEventData } from '@intlayer/backend';\nimport { default as configuration } from '@intlayer/config/built';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { EventSource } from 'eventsource';\n\nexport type IntlayerMessageEvent = MessageEvent;\n\n/**\n * IntlayerEventListener class to listen for dictionary changes via SSE (Server-Sent Events).\n *\n * Usage example:\n *\n * import { buildIntlayerDictionary } from './transpiler/declaration_file_to_dictionary/intlayer_dictionary';\n * import { IntlayerEventListener } from '@intlayer/api';\n *\n * export const checkDictionaryChanges = async () => {\n * // Instantiate the listener\n * const eventListener = new IntlayerEventListener();\n *\n * // Set up your callbacks\n * eventListener.onDictionaryChange = async (dictionary) => {\n * await buildIntlayerDictionary(dictionary);\n * };\n *\n * // Initialize the listener\n * await eventListener.initialize();\n *\n * // Optionally, clean up later when you’re done\n * // eventListener.cleanup();\n * };\n */\nexport class IntlayerEventListener {\n private appLogger = getAppLogger(configuration);\n\n private eventSource: EventSource | null = null;\n private reconnectAttempts = 0;\n private maxReconnectAttempts = 5;\n private reconnectDelay = 1000; // Start with 1 second\n private isManuallyDisconnected = false;\n private reconnectTimeout: NodeJS.Timeout | null = null;\n\n /**\n * Callback triggered when a Dictionary is ADDED.\n */\n public onDictionaryAdded?: (dictionary: DictionaryAPI) => any;\n\n /**\n * Callback triggered when a Dictionary is UPDATED.\n */\n public onDictionaryChange?: (dictionary: DictionaryAPI) => any;\n\n /**\n * Callback triggered when a Dictionary is DELETED.\n */\n public onDictionaryDeleted?: (dictionary: DictionaryAPI) => any;\n\n /**\n * Callback triggered when connection is established or re-established.\n */\n public onConnectionOpen?: () => any;\n\n /**\n * Callback triggered when connection encounters an error.\n */\n public onConnectionError?: (error: Event) => any;\n\n constructor(private intlayerConfig: IntlayerConfig = configuration) {\n this.appLogger = getAppLogger(this.intlayerConfig);\n }\n\n /**\n * Initializes the EventSource connection using the given intlayerConfig\n * (or the default config if none was provided).\n */\n public async initialize(): Promise<void> {\n this.isManuallyDisconnected = false;\n await this.connect();\n }\n\n /**\n * Establishes the EventSource connection with automatic reconnection support.\n */\n private async connect(): Promise<void> {\n try {\n const backendURL = this.intlayerConfig.editor.backendURL;\n\n // Retrieve the access token via proxy\n const accessToken = await getIntlayerAPIProxy(\n undefined,\n this.intlayerConfig\n ).oAuth.getOAuth2AccessToken();\n\n if (!accessToken) {\n throw new Error('Failed to retrieve access token');\n }\n\n const API_ROUTE = `${backendURL}/api/event-listener`;\n\n // Close existing connection if any\n if (this.eventSource) {\n this.eventSource.close();\n }\n\n this.eventSource = new EventSource(API_ROUTE, {\n fetch: (input, init) =>\n fetch(input, {\n ...init,\n headers: {\n ...(init?.headers ?? {}),\n Authorization: `Bearer ${accessToken.data?.accessToken}`,\n },\n }),\n });\n\n this.eventSource.onopen = () => {\n this.reconnectAttempts = 0;\n this.reconnectDelay = 1000; // Reset delay\n this.onConnectionOpen?.();\n };\n\n this.eventSource.onmessage = (event) => this.handleMessage(event);\n this.eventSource.onerror = (event) => this.handleError(event);\n } catch (_error) {\n this.appLogger('Failed to establish EventSource connection:', {\n level: 'error',\n });\n this.scheduleReconnect();\n }\n }\n\n /**\n * Cleans up (closes) the EventSource connection.\n */\n public cleanup(): void {\n this.isManuallyDisconnected = true;\n\n if (this.reconnectTimeout) {\n clearTimeout(this.reconnectTimeout);\n this.reconnectTimeout = null;\n }\n\n if (this.eventSource) {\n this.eventSource.close();\n this.eventSource = null;\n }\n }\n\n /**\n * Schedules a reconnection attempt with exponential backoff.\n */\n private scheduleReconnect(): void {\n if (\n this.isManuallyDisconnected ||\n this.reconnectAttempts >= this.maxReconnectAttempts\n ) {\n if (this.reconnectAttempts >= this.maxReconnectAttempts) {\n this.appLogger(\n [\n `Max reconnection attempts (${this.maxReconnectAttempts}) reached. Giving up.`,\n ],\n {\n level: 'error',\n }\n );\n }\n return;\n }\n\n this.reconnectAttempts++;\n const delay = this.reconnectDelay * 2 ** (this.reconnectAttempts - 1); // Exponential backoff\n\n this.appLogger(\n `Scheduling reconnection attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts} in ${delay}ms`\n );\n\n this.reconnectTimeout = setTimeout(async () => {\n if (!this.isManuallyDisconnected) {\n await this.connect();\n }\n }, delay);\n }\n\n /**\n * Handles incoming SSE messages, parses the event data,\n * and invokes the appropriate callback.\n */\n private async handleMessage(event: IntlayerMessageEvent): Promise<void> {\n try {\n const { data } = event;\n\n const dataJSON: MessageEventData[] = JSON.parse(data);\n\n for (const dataEl of dataJSON) {\n switch (dataEl.object) {\n case 'DICTIONARY':\n switch (dataEl.status) {\n case 'ADDED':\n await this.onDictionaryAdded?.(dataEl.data);\n break;\n case 'UPDATED':\n await this.onDictionaryChange?.(dataEl.data);\n break;\n case 'DELETED':\n await this.onDictionaryDeleted?.(dataEl.data);\n break;\n default:\n this.appLogger(\n ['Unhandled dictionary status:', dataEl.status],\n {\n level: 'error',\n }\n );\n break;\n }\n break;\n default:\n this.appLogger(['Unknown object type:', dataEl.object], {\n level: 'error',\n });\n break;\n }\n }\n } catch (error) {\n this.appLogger(['Error processing dictionary update:', error], {\n level: 'error',\n });\n }\n }\n\n /**\n * Handles any SSE errors and attempts reconnection if appropriate.\n */\n private handleError(event: Event): void {\n const errorEvent = event as any;\n\n // Log detailed error information\n this.appLogger(\n [\n 'EventSource error:',\n {\n type: errorEvent.type,\n message: errorEvent.message,\n code: errorEvent.code,\n readyState: this.eventSource?.readyState,\n url: this.eventSource?.url,\n },\n ],\n {\n level: 'error',\n }\n );\n\n // Notify error callback\n this.onConnectionError?.(event);\n\n // Check if this is a connection close error\n const isConnectionClosed =\n errorEvent.type === 'error' &&\n (errorEvent.message?.includes('terminated') ||\n errorEvent.message?.includes('closed') ||\n this.eventSource?.readyState === EventSource.CLOSED);\n\n if (isConnectionClosed && !this.isManuallyDisconnected) {\n this.appLogger(\n 'Connection was terminated by server, attempting to reconnect...'\n );\n this.scheduleReconnect();\n } else {\n // For other types of errors, close the connection\n this.cleanup();\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,wBAAb,MAAmC;CAmCb;CAlCpB,AAAQ,YAAY,aAAa,aAAa;CAE9C,AAAQ,cAAkC;CAC1C,AAAQ,oBAAoB;CAC5B,AAAQ,uBAAuB;CAC/B,AAAQ,iBAAiB;CACzB,AAAQ,yBAAyB;CACjC,AAAQ,mBAA0C;;;;CAKlD,AAAO;;;;CAKP,AAAO;;;;CAKP,AAAO;;;;CAKP,AAAO;;;;CAKP,AAAO;CAEP,YAAY,AAAQ,iBAAiC,eAAe;EAAhD;EAClB,KAAK,YAAY,aAAa,KAAK,cAAc;CACnD;;;;;CAMA,MAAa,aAA4B;EACv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ACH,iEACF;GACA,KAAK,kBAAkB;EACzB,OAEE,KAAK,QAAQ;CAEjB;AACF"}
@@ -1,4 +1,5 @@
1
1
  import { openBrowser } from "../utils/openBrowser.mjs";
2
+ import { writeCliSessionToken } from "./sessionToken.mjs";
2
3
  import { logConfigDetails } from "@intlayer/chokidar/cli";
3
4
  import * as ANSIColors from "@intlayer/config/colors";
4
5
  import { colorize, colorizePath, getAppLogger } from "@intlayer/config/logger";
@@ -7,13 +8,65 @@ import http from "node:http";
7
8
  import { URL } from "node:url";
8
9
 
9
10
  //#region src/auth/login.ts
11
+ const buildSuccessHtml = (message) => `
12
+ <!DOCTYPE html>
13
+ <html lang="en" data-theme="dark">
14
+ <head>
15
+ <meta charset="UTF-8">
16
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
17
+ <title>Intlayer CLI Login</title>
18
+ <style>
19
+ :root {
20
+ --color-background: rgba(23, 23, 23);
21
+ --color-card: rgba(39, 39, 39);
22
+ --color-text: rgba(255, 245, 237);
23
+ --color-neutral: rgba(93, 93, 93);
24
+ --font-sans: "Inter", -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
25
+ }
26
+ * { box-sizing: border-box; }
27
+ body {
28
+ font-family: var(--font-sans);
29
+ display: flex;
30
+ align-items: center;
31
+ justify-content: center;
32
+ min-height: 100vh;
33
+ margin: 0;
34
+ padding: 1rem;
35
+ background-color: var(--color-background);
36
+ color: var(--color-text);
37
+ }
38
+ .container {
39
+ text-align: center;
40
+ padding: 2rem;
41
+ border-radius: 1rem;
42
+ background-color: var(--color-card);
43
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
44
+ max-width: 400px;
45
+ width: 100%;
46
+ }
47
+ h1 { margin: 0 0 1rem 0; font-size: 1.5rem; font-weight: 700; color: var(--color-text); }
48
+ p { color: var(--color-neutral); font-size: 0.8rem; margin: 0 0 1.5rem 0; line-height: 1.5; }
49
+ </style>
50
+ </head>
51
+ <body>
52
+ <div class="container">
53
+ <h1>Login Successful</h1>
54
+ <p>${message}</p>
55
+ </div>
56
+ <script>
57
+ window.close();
58
+ setTimeout(() => { window.close(); }, 1000);
59
+ <\/script>
60
+ </body>
61
+ </html>
62
+ `;
10
63
  const login = async (options) => {
11
64
  const configuration = getConfiguration(options.configOptions);
12
65
  logConfigDetails(options?.configOptions);
13
66
  const logger = getAppLogger(configuration);
14
67
  const cmsUrl = options.cmsUrl ?? configuration.editor.cmsURL;
15
68
  return new Promise((resolve) => {
16
- const server = http.createServer((req, res) => {
69
+ const server = http.createServer(async (req, res) => {
17
70
  const url = new URL(req.url ?? "", `http://${req.headers.host}`);
18
71
  res.setHeader("Access-Control-Allow-Origin", "*");
19
72
  res.setHeader("Access-Control-Allow-Methods", "GET, OPTIONS");
@@ -24,8 +77,24 @@ const login = async (options) => {
24
77
  return;
25
78
  }
26
79
  if (url.pathname === "/callback") {
80
+ const sessionToken = url.searchParams.get("sessionToken");
81
+ const sessionExpiresAt = url.searchParams.get("expiresAt");
27
82
  const clientId = url.searchParams.get("clientId");
28
83
  const clientSecret = url.searchParams.get("clientSecret");
84
+ if (sessionToken && sessionExpiresAt) {
85
+ logger("");
86
+ logger(`Log in successful. ${colorize("2h", ANSIColors.BLUE)} session token received.`);
87
+ logger("");
88
+ logger(colorize(`Token expires at: ${new Date(sessionExpiresAt).toLocaleString()}`, ANSIColors.GREY));
89
+ await writeCliSessionToken(configuration, sessionToken, new Date(sessionExpiresAt));
90
+ res.writeHead(200, { "Content-Type": "text/html" });
91
+ res.end(buildSuccessHtml("Your 2h session token has been stored. You can now close this tab and return to your terminal."));
92
+ server.close(() => {
93
+ resolve();
94
+ process.exit(0);
95
+ });
96
+ return;
97
+ }
29
98
  if (clientId && clientSecret) {
30
99
  logger("");
31
100
  logger("Log in successful. Client ID and Client Secret received.");
@@ -56,80 +125,7 @@ const login = async (options) => {
56
125
  });
57
126
  logger(colorize("--------------------------------", ANSIColors.GREY_DARK));
58
127
  res.writeHead(200, { "Content-Type": "text/html" });
59
- res.end(`
60
- <!DOCTYPE html>
61
- <html lang="en" data-theme="dark">
62
- <head>
63
- <meta charset="UTF-8">
64
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
65
- <title>Intlayer CLI Login</title>
66
- <style>
67
- :root {
68
- --color-background: rgba(23, 23, 23);
69
- --color-card: rgba(39, 39, 39);
70
- --color-text: rgba(255, 245, 237);
71
- --color-neutral: rgba(93, 93, 93);
72
- --font-sans: "Inter", -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
73
- }
74
-
75
- * {
76
- box-sizing: border-box;
77
- }
78
-
79
- body {
80
- font-family: var(--font-sans);
81
- display: flex;
82
- align-items: center;
83
- justify-content: center;
84
- min-height: 100vh;
85
- margin: 0;
86
- padding: 1rem;
87
- background-color: var(--color-background);
88
- color: var(--color-text);
89
- }
90
-
91
- .container {
92
- text-align: center;
93
- padding: 2rem;
94
- border-radius: 1rem;
95
- background-color: var(--color-card);
96
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
97
- max-width: 400px;
98
- width: 100%;
99
- }
100
-
101
- h1 {
102
- margin: 0 0 1rem 0;
103
- font-size: 1.5rem;
104
- font-weight: 700;
105
- color: var(--color-text);
106
- }
107
-
108
- p {
109
- color: var(--color-neutral);
110
- font-size: 0.8rem;
111
- margin: 0 0 1.5rem 0;
112
- line-height: 1.5;
113
- }
114
- </style>
115
- </head>
116
- <body>
117
- <div class="container">
118
- <h1>Login Successful</h1>
119
- <p>You have successfully logged in to Intlayer CLI. You can now close this tab and return to your terminal.</p>
120
- </div>
121
- <script>
122
- // Attempt to close the window
123
- window.close();
124
-
125
- // Fallback: if window.close() doesn't work, show a message
126
- setTimeout(() => {
127
- window.close();
128
- }, 1000);
129
- <\/script>
130
- </body>
131
- </html>
132
- `);
128
+ res.end(buildSuccessHtml("You have successfully logged in to Intlayer CLI. You can now close this tab and return to your terminal."));
133
129
  server.close(() => {
134
130
  resolve();
135
131
  process.exit(0);
@@ -147,7 +143,9 @@ const login = async (options) => {
147
143
  const address = server.address();
148
144
  const port = typeof address === "object" && address ? address.port : 0;
149
145
  const state = Math.random().toString(36).substring(7);
150
- const loginUrl = `${cmsUrl ?? process.env.INTLAYER_SITE_URL ?? "http://localhost:3000"}/auth/cli-login?port=${port}&state=${state}`;
146
+ const websiteUrl = cmsUrl ?? process.env.INTLAYER_SITE_URL ?? "http://localhost:3000";
147
+ const backendUrl = configuration.editor.backendURL ?? "";
148
+ const loginUrl = `${websiteUrl}/auth/cli-login?port=${port}&state=${state}&backendUrl=${encodeURIComponent(backendUrl)}`;
151
149
  logger("Opening browser for login...");
152
150
  logger(`If browser does not open, visit: ${colorizePath(loginUrl)}`);
153
151
  openBrowser(loginUrl);