arcli 2.0.0 → 2.2.0

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 (511) hide show
  1. package/CHANGELOG.md +106 -1
  2. package/README.md +21 -14
  3. package/dist/cli/arca-runtime.js +41 -0
  4. package/dist/cli/commands/billing-family.command.js +36 -9
  5. package/dist/cli/commands/billing-shortcuts.command.js +8 -2
  6. package/dist/cli/commands/billing.command.batch.js +28 -12
  7. package/dist/cli/commands/billing.command.interactive-preview.js +12 -13
  8. package/dist/cli/commands/billing.command.options.js +83 -39
  9. package/dist/cli/commands/billing.command.output.js +3 -3
  10. package/dist/cli/commands/billing.command.parser.js +44 -30
  11. package/dist/cli/commands/billing.command.pdf.js +9 -6
  12. package/dist/cli/commands/billing.command.shared.js +86 -49
  13. package/dist/cli/commands/billing.command.shortcuts.js +3 -4
  14. package/dist/cli/commands/completion.command.js +140 -0
  15. package/dist/cli/commands/config.command.js +44 -45
  16. package/dist/cli/commands/cuit-argument.js +10 -0
  17. package/dist/cli/commands/examples.command.js +0 -1
  18. package/dist/cli/commands/export-shortcut.command.js +19 -0
  19. package/dist/cli/commands/export.command.js +106 -0
  20. package/dist/cli/commands/export.command.options.js +140 -0
  21. package/dist/cli/commands/export.command.parser.js +84 -0
  22. package/dist/cli/commands/export.command.pdf.js +61 -0
  23. package/dist/cli/commands/fce-obligation.command.js +8 -16
  24. package/dist/cli/commands/interactive.command.js +9 -8
  25. package/dist/cli/commands/padron.command.js +46 -0
  26. package/dist/cli/commands/parameters.command.js +13 -13
  27. package/dist/cli/commands/pdf.command.js +17 -31
  28. package/dist/cli/commands/storybook.command.js +4 -4
  29. package/dist/cli/commands/vouchers.command.js +14 -14
  30. package/dist/cli/error-output.js +89 -11
  31. package/dist/cli/global-options.js +55 -0
  32. package/dist/cli/help-argv.js +0 -1
  33. package/dist/cli/help.js +243 -391
  34. package/dist/cli/ignored-global-options.js +32 -0
  35. package/dist/cli/index.js +12 -14
  36. package/dist/cli/interactive/advanced-options.js +13 -14
  37. package/dist/cli/interactive/config.flow.js +59 -20
  38. package/dist/cli/interactive/export.flow.js +263 -0
  39. package/dist/cli/interactive/history.flow.js +2 -3
  40. package/dist/cli/interactive/interactive-mode.js +63 -33
  41. package/dist/cli/interactive/invoice-picker.js +7 -7
  42. package/dist/cli/interactive/invoice.flow.js +35 -13
  43. package/dist/cli/interactive/note.flow.js +16 -16
  44. package/dist/cli/interactive/pdf.flow.js +9 -7
  45. package/dist/cli/interactive/prompts.js +0 -1
  46. package/dist/cli/interactive/receiver-padron.js +52 -0
  47. package/dist/cli/interactive/repeat.flow.js +10 -11
  48. package/dist/cli/interactive/session.js +13 -8
  49. package/dist/cli/interactive/status.flow.js +0 -1
  50. package/dist/cli/interactive/update.flow.js +0 -1
  51. package/dist/cli/interactive/validators.js +7 -6
  52. package/dist/cli/option-parsers.js +14 -4
  53. package/dist/cli/program.js +14 -5
  54. package/dist/cli/skipped-options.js +14 -0
  55. package/dist/cli/spinner.js +0 -1
  56. package/dist/cli/types.js +0 -1
  57. package/dist/cli/version.js +1 -2
  58. package/dist/index.js +0 -1
  59. package/dist/lib/dates/arca-date.js +3 -4
  60. package/dist/lib/errors/app-error.js +2 -2
  61. package/dist/lib/files/read-json-file.js +2 -3
  62. package/dist/lib/files/restrict-to-owner.js +0 -1
  63. package/dist/lib/files/write-new-file.js +29 -0
  64. package/dist/lib/identity/cuit.js +26 -0
  65. package/dist/lib/identity/format-cuit.js +1 -2
  66. package/dist/lib/links.js +2 -1
  67. package/dist/lib/numbers/argentine-amount.js +3 -4
  68. package/dist/lib/numbers/strict-integer.js +0 -1
  69. package/dist/lib/paths/mask-path.js +0 -1
  70. package/dist/lib/security/certificate.js +10 -8
  71. package/dist/lib/security/pem.js +2 -3
  72. package/dist/modules/billing/billing-response.js +16 -5
  73. package/dist/modules/billing/billing.amounts.js +3 -4
  74. package/dist/modules/billing/billing.associated-period.js +7 -8
  75. package/dist/modules/billing/billing.associated-vouchers.js +5 -6
  76. package/dist/modules/billing/billing.batch.js +12 -5
  77. package/dist/modules/billing/billing.constants.js +0 -1
  78. package/dist/modules/billing/billing.currency.js +4 -5
  79. package/dist/modules/billing/billing.date-range.js +27 -11
  80. package/dist/modules/billing/billing.display.js +14 -8
  81. package/dist/modules/billing/billing.errors.js +2 -3
  82. package/dist/modules/billing/billing.fce.js +3 -4
  83. package/dist/modules/billing/billing.iva-receptor.js +2 -3
  84. package/dist/modules/billing/billing.json-format.js +0 -1
  85. package/dist/modules/billing/billing.json-input.js +278 -0
  86. package/dist/modules/billing/billing.labels.js +1 -2
  87. package/dist/modules/billing/billing.mappers.js +0 -1
  88. package/dist/modules/billing/billing.padron.js +59 -0
  89. package/dist/modules/billing/billing.presenter.js +0 -1
  90. package/dist/modules/billing/billing.schemas.js +20 -6
  91. package/dist/modules/billing/billing.serialize.js +11 -15
  92. package/dist/modules/billing/billing.service.js +25 -4
  93. package/dist/modules/billing/billing.text.js +4 -13
  94. package/dist/modules/billing/billing.types.internal.js +0 -1
  95. package/dist/modules/billing/billing.types.js +0 -1
  96. package/dist/modules/billing/billing.validation.js +13 -11
  97. package/dist/modules/billing/voucher-kind-map.js +15 -16
  98. package/dist/modules/completion/completion.js +53 -0
  99. package/dist/modules/completion/completion.presenter.js +35 -0
  100. package/dist/modules/completion/installer.js +92 -0
  101. package/dist/modules/completion/shell-scripts.js +46 -0
  102. package/dist/modules/config/certificate-expiry.js +90 -0
  103. package/dist/modules/config/config-doctor.js +42 -28
  104. package/dist/modules/config/config-value-parser.js +32 -17
  105. package/dist/modules/config/config.export-credentials.js +23 -0
  106. package/dist/modules/config/config.presenter.js +28 -6
  107. package/dist/modules/config/config.schemas.js +27 -12
  108. package/dist/modules/config/config.sections.js +31 -11
  109. package/dist/modules/config/config.service.js +38 -9
  110. package/dist/modules/examples/examples.js +72 -37
  111. package/dist/modules/export/export.items.js +149 -0
  112. package/dist/modules/export/export.json-input.js +91 -0
  113. package/dist/modules/export/export.mappers.js +293 -0
  114. package/dist/modules/export/export.presenter.js +2 -0
  115. package/dist/modules/export/export.response.js +86 -0
  116. package/dist/modules/export/export.serialize.js +70 -0
  117. package/dist/modules/export/export.service.js +146 -0
  118. package/dist/modules/export/export.text.js +177 -0
  119. package/dist/modules/export/export.types.js +36 -0
  120. package/dist/modules/fce/fce-obligation.js +3 -4
  121. package/dist/modules/fce/fce-obligation.presenter.js +2 -3
  122. package/dist/modules/interactive/amount-input.js +0 -1
  123. package/dist/modules/interactive/choices.js +10 -2
  124. package/dist/modules/interactive/config-fields.js +17 -3
  125. package/dist/modules/interactive/equivalent-command.js +6 -3
  126. package/dist/modules/interactive/export-equivalent-command.js +40 -0
  127. package/dist/modules/interactive/invoice-copy.js +1 -2
  128. package/dist/modules/interactive/periods.js +0 -1
  129. package/dist/modules/interactive/wizard.js +0 -1
  130. package/dist/modules/padron/padron.js +23 -0
  131. package/dist/modules/padron/padron.presenter.js +48 -0
  132. package/dist/modules/parameters/health.js +0 -1
  133. package/dist/modules/parameters/parameters.js +2 -3
  134. package/dist/modules/parameters/parameters.presenter.js +14 -12
  135. package/dist/modules/parameters/status.js +0 -1
  136. package/dist/modules/pdf/pdf-data.mapper.js +94 -3
  137. package/dist/modules/pdf/pdf-decision.js +0 -1
  138. package/dist/modules/pdf/pdf-file-name.js +0 -1
  139. package/dist/modules/pdf/pdf-issuer.js +3 -3
  140. package/dist/modules/pdf/pdf-legends.js +35 -0
  141. package/dist/modules/pdf/pdf.errors.js +0 -1
  142. package/dist/modules/pdf/pdf.types.js +0 -1
  143. package/dist/modules/storybook/showcase-theme.js +0 -1
  144. package/dist/modules/storybook/showcase.js +35 -23
  145. package/dist/modules/update-check/changelog.js +0 -1
  146. package/dist/modules/update-check/update-check.presenter.js +6 -7
  147. package/dist/modules/update-check/update-check.service.js +0 -1
  148. package/dist/modules/vouchers/voucher-history.js +0 -1
  149. package/dist/modules/vouchers/voucher-history.presenter.js +3 -4
  150. package/dist/services/arca/arca-billing.gateway.js +18 -4
  151. package/dist/services/arca/arca-client.factory.js +27 -1
  152. package/dist/services/arca/arca-context.resolver.js +17 -7
  153. package/dist/services/arca/arca-export.gateway.js +146 -0
  154. package/dist/services/arca/arca-fce-obligation.gateway.js +2 -3
  155. package/dist/services/arca/arca-padron.gateway.js +103 -0
  156. package/dist/services/arca/arca-parameters.gateway.js +2 -3
  157. package/dist/services/arca/arca-voucher-history.gateway.js +2 -3
  158. package/dist/services/arca/last-voucher.js +26 -0
  159. package/dist/services/clipboard/clipboard.js +0 -1
  160. package/dist/services/pdf/escape-html.js +0 -1
  161. package/dist/services/pdf/pdf-browser.js +0 -1
  162. package/dist/services/pdf/pdf-exporter.js +26 -11
  163. package/dist/services/pdf/pdf-plugin.js +41 -14
  164. package/dist/ui/components/certificateBanner.js +8 -0
  165. package/dist/ui/components/contentPanel.js +0 -1
  166. package/dist/ui/components/errorPanel.js +0 -1
  167. package/dist/ui/components/index.js +1 -1
  168. package/dist/ui/components/keyValuePanel.js +0 -1
  169. package/dist/ui/components/noticePanel.js +0 -1
  170. package/dist/ui/components/rawPanel.js +0 -1
  171. package/dist/ui/components/sectionHeading.js +0 -1
  172. package/dist/ui/components/statusBar.js +0 -1
  173. package/dist/ui/components/statusPanel.js +0 -1
  174. package/dist/ui/components/testingBanner.js +0 -1
  175. package/dist/ui/index.js +0 -1
  176. package/dist/ui/presenters/billing.presenter.js +0 -1
  177. package/dist/ui/presenters/config.presenter.js +1 -2
  178. package/dist/ui/presenters/errors.presenter.js +14 -12
  179. package/dist/ui/presenters/errors.zod-presenter.js +13 -35
  180. package/dist/ui/presenters/export.presenter.js +1 -0
  181. package/dist/ui/presenters/index.js +1 -1
  182. package/dist/ui/presenters/pdf.presenter.js +1 -2
  183. package/dist/ui/presenters/showcase.presenter.js +0 -1
  184. package/dist/ui/primitives/index.js +0 -1
  185. package/dist/ui/primitives/renderDivider.js +0 -1
  186. package/dist/ui/primitives/renderFooter.js +0 -1
  187. package/dist/ui/primitives/renderJson.js +0 -1
  188. package/dist/ui/primitives/renderKeyValue.js +0 -1
  189. package/dist/ui/primitives/renderLogo.js +0 -1
  190. package/dist/ui/primitives/renderObject.js +0 -1
  191. package/dist/ui/primitives/renderPanel.js +0 -1
  192. package/dist/ui/primitives/renderSubtitle.js +0 -1
  193. package/dist/ui/primitives/renderTable.js +0 -1
  194. package/dist/ui/primitives/terminalWidth.js +0 -1
  195. package/dist/ui/primitives/text.js +0 -1
  196. package/dist/ui/stream/index.js +0 -1
  197. package/dist/ui/stream/terminal-stream.js +13 -2
  198. package/dist/ui/theme/index.js +0 -1
  199. package/dist/ui/theme/theme.js +0 -1
  200. package/llms.txt +122 -45
  201. package/package.json +1 -2
  202. package/dist/cli/commands/billing-family.command.d.ts +0 -2
  203. package/dist/cli/commands/billing-family.command.js.map +0 -1
  204. package/dist/cli/commands/billing-shortcuts.command.d.ts +0 -2
  205. package/dist/cli/commands/billing-shortcuts.command.js.map +0 -1
  206. package/dist/cli/commands/billing.command.batch.d.ts +0 -22
  207. package/dist/cli/commands/billing.command.batch.js.map +0 -1
  208. package/dist/cli/commands/billing.command.interactive-preview.d.ts +0 -18
  209. package/dist/cli/commands/billing.command.interactive-preview.js.map +0 -1
  210. package/dist/cli/commands/billing.command.options.d.ts +0 -2
  211. package/dist/cli/commands/billing.command.options.js.map +0 -1
  212. package/dist/cli/commands/billing.command.output.d.ts +0 -14
  213. package/dist/cli/commands/billing.command.output.js.map +0 -1
  214. package/dist/cli/commands/billing.command.parser.d.ts +0 -28
  215. package/dist/cli/commands/billing.command.parser.js.map +0 -1
  216. package/dist/cli/commands/billing.command.pdf.d.ts +0 -24
  217. package/dist/cli/commands/billing.command.pdf.js.map +0 -1
  218. package/dist/cli/commands/billing.command.shared.d.ts +0 -7
  219. package/dist/cli/commands/billing.command.shared.js.map +0 -1
  220. package/dist/cli/commands/billing.command.shortcuts.d.ts +0 -7
  221. package/dist/cli/commands/billing.command.shortcuts.js.map +0 -1
  222. package/dist/cli/commands/config.command.d.ts +0 -7
  223. package/dist/cli/commands/config.command.js.map +0 -1
  224. package/dist/cli/commands/examples.command.d.ts +0 -2
  225. package/dist/cli/commands/examples.command.js.map +0 -1
  226. package/dist/cli/commands/fce-obligation.command.d.ts +0 -2
  227. package/dist/cli/commands/fce-obligation.command.js.map +0 -1
  228. package/dist/cli/commands/interactive.command.d.ts +0 -3
  229. package/dist/cli/commands/interactive.command.js.map +0 -1
  230. package/dist/cli/commands/parameters.command.d.ts +0 -2
  231. package/dist/cli/commands/parameters.command.js.map +0 -1
  232. package/dist/cli/commands/pdf.command.d.ts +0 -2
  233. package/dist/cli/commands/pdf.command.js.map +0 -1
  234. package/dist/cli/commands/storybook.command.d.ts +0 -2
  235. package/dist/cli/commands/storybook.command.js.map +0 -1
  236. package/dist/cli/commands/vouchers.command.d.ts +0 -2
  237. package/dist/cli/commands/vouchers.command.js.map +0 -1
  238. package/dist/cli/error-output.d.ts +0 -7
  239. package/dist/cli/error-output.js.map +0 -1
  240. package/dist/cli/help-argv.d.ts +0 -5
  241. package/dist/cli/help-argv.js.map +0 -1
  242. package/dist/cli/help.d.ts +0 -12
  243. package/dist/cli/help.js.map +0 -1
  244. package/dist/cli/index.d.ts +0 -2
  245. package/dist/cli/index.js.map +0 -1
  246. package/dist/cli/interactive/advanced-options.d.ts +0 -21
  247. package/dist/cli/interactive/advanced-options.js.map +0 -1
  248. package/dist/cli/interactive/config.flow.d.ts +0 -5
  249. package/dist/cli/interactive/config.flow.js.map +0 -1
  250. package/dist/cli/interactive/history.flow.d.ts +0 -6
  251. package/dist/cli/interactive/history.flow.js.map +0 -1
  252. package/dist/cli/interactive/interactive-mode.d.ts +0 -3
  253. package/dist/cli/interactive/interactive-mode.js.map +0 -1
  254. package/dist/cli/interactive/invoice-picker.d.ts +0 -25
  255. package/dist/cli/interactive/invoice-picker.js.map +0 -1
  256. package/dist/cli/interactive/invoice.flow.d.ts +0 -20
  257. package/dist/cli/interactive/invoice.flow.js.map +0 -1
  258. package/dist/cli/interactive/note.flow.d.ts +0 -32
  259. package/dist/cli/interactive/note.flow.js.map +0 -1
  260. package/dist/cli/interactive/pdf.flow.d.ts +0 -5
  261. package/dist/cli/interactive/pdf.flow.js.map +0 -1
  262. package/dist/cli/interactive/prompts.d.ts +0 -57
  263. package/dist/cli/interactive/prompts.js.map +0 -1
  264. package/dist/cli/interactive/repeat.flow.d.ts +0 -13
  265. package/dist/cli/interactive/repeat.flow.js.map +0 -1
  266. package/dist/cli/interactive/session.d.ts +0 -22
  267. package/dist/cli/interactive/session.js.map +0 -1
  268. package/dist/cli/interactive/status.flow.d.ts +0 -3
  269. package/dist/cli/interactive/status.flow.js.map +0 -1
  270. package/dist/cli/interactive/update.flow.d.ts +0 -6
  271. package/dist/cli/interactive/update.flow.js.map +0 -1
  272. package/dist/cli/interactive/validators.d.ts +0 -9
  273. package/dist/cli/interactive/validators.js.map +0 -1
  274. package/dist/cli/option-parsers.d.ts +0 -6
  275. package/dist/cli/option-parsers.js.map +0 -1
  276. package/dist/cli/program.d.ts +0 -2
  277. package/dist/cli/program.js.map +0 -1
  278. package/dist/cli/spinner.d.ts +0 -8
  279. package/dist/cli/spinner.js.map +0 -1
  280. package/dist/cli/types.d.ts +0 -6
  281. package/dist/cli/types.js.map +0 -1
  282. package/dist/cli/version.d.ts +0 -1
  283. package/dist/cli/version.js.map +0 -1
  284. package/dist/index.d.ts +0 -1
  285. package/dist/index.js.map +0 -1
  286. package/dist/lib/dates/arca-date.d.ts +0 -19
  287. package/dist/lib/dates/arca-date.js.map +0 -1
  288. package/dist/lib/errors/app-error.d.ts +0 -17
  289. package/dist/lib/errors/app-error.js.map +0 -1
  290. package/dist/lib/files/read-json-file.d.ts +0 -1
  291. package/dist/lib/files/read-json-file.js.map +0 -1
  292. package/dist/lib/files/restrict-to-owner.d.ts +0 -7
  293. package/dist/lib/files/restrict-to-owner.js.map +0 -1
  294. package/dist/lib/identity/format-cuit.d.ts +0 -2
  295. package/dist/lib/identity/format-cuit.js.map +0 -1
  296. package/dist/lib/links.d.ts +0 -2
  297. package/dist/lib/links.js.map +0 -1
  298. package/dist/lib/numbers/argentine-amount.d.ts +0 -23
  299. package/dist/lib/numbers/argentine-amount.js.map +0 -1
  300. package/dist/lib/numbers/strict-integer.d.ts +0 -4
  301. package/dist/lib/numbers/strict-integer.js.map +0 -1
  302. package/dist/lib/paths/mask-path.d.ts +0 -1
  303. package/dist/lib/paths/mask-path.js.map +0 -1
  304. package/dist/lib/security/certificate.d.ts +0 -7
  305. package/dist/lib/security/certificate.js.map +0 -1
  306. package/dist/lib/security/pem.d.ts +0 -5
  307. package/dist/lib/security/pem.js.map +0 -1
  308. package/dist/modules/billing/billing-response.d.ts +0 -4
  309. package/dist/modules/billing/billing-response.js.map +0 -1
  310. package/dist/modules/billing/billing.amounts.d.ts +0 -21
  311. package/dist/modules/billing/billing.amounts.js.map +0 -1
  312. package/dist/modules/billing/billing.associated-period.d.ts +0 -8
  313. package/dist/modules/billing/billing.associated-period.js.map +0 -1
  314. package/dist/modules/billing/billing.associated-vouchers.d.ts +0 -12
  315. package/dist/modules/billing/billing.associated-vouchers.js.map +0 -1
  316. package/dist/modules/billing/billing.batch.d.ts +0 -23
  317. package/dist/modules/billing/billing.batch.js.map +0 -1
  318. package/dist/modules/billing/billing.constants.d.ts +0 -2
  319. package/dist/modules/billing/billing.constants.js.map +0 -1
  320. package/dist/modules/billing/billing.currency.d.ts +0 -18
  321. package/dist/modules/billing/billing.currency.js.map +0 -1
  322. package/dist/modules/billing/billing.date-range.d.ts +0 -9
  323. package/dist/modules/billing/billing.date-range.js.map +0 -1
  324. package/dist/modules/billing/billing.display.d.ts +0 -13
  325. package/dist/modules/billing/billing.display.js.map +0 -1
  326. package/dist/modules/billing/billing.errors.d.ts +0 -12
  327. package/dist/modules/billing/billing.errors.js.map +0 -1
  328. package/dist/modules/billing/billing.fce.d.ts +0 -21
  329. package/dist/modules/billing/billing.fce.js.map +0 -1
  330. package/dist/modules/billing/billing.iva-receptor.d.ts +0 -8
  331. package/dist/modules/billing/billing.iva-receptor.js.map +0 -1
  332. package/dist/modules/billing/billing.json-format.d.ts +0 -6
  333. package/dist/modules/billing/billing.json-format.js.map +0 -1
  334. package/dist/modules/billing/billing.labels.d.ts +0 -9
  335. package/dist/modules/billing/billing.labels.js.map +0 -1
  336. package/dist/modules/billing/billing.mappers.d.ts +0 -8
  337. package/dist/modules/billing/billing.mappers.js.map +0 -1
  338. package/dist/modules/billing/billing.presenter.d.ts +0 -7
  339. package/dist/modules/billing/billing.presenter.js.map +0 -1
  340. package/dist/modules/billing/billing.schemas.d.ts +0 -142
  341. package/dist/modules/billing/billing.schemas.js.map +0 -1
  342. package/dist/modules/billing/billing.serialize.d.ts +0 -8
  343. package/dist/modules/billing/billing.serialize.js.map +0 -1
  344. package/dist/modules/billing/billing.service.d.ts +0 -27
  345. package/dist/modules/billing/billing.service.js.map +0 -1
  346. package/dist/modules/billing/billing.text.d.ts +0 -8
  347. package/dist/modules/billing/billing.text.js.map +0 -1
  348. package/dist/modules/billing/billing.types.d.ts +0 -13
  349. package/dist/modules/billing/billing.types.internal.d.ts +0 -30
  350. package/dist/modules/billing/billing.types.internal.js.map +0 -1
  351. package/dist/modules/billing/billing.types.js.map +0 -1
  352. package/dist/modules/billing/billing.validation.d.ts +0 -7
  353. package/dist/modules/billing/billing.validation.js.map +0 -1
  354. package/dist/modules/billing/voucher-kind-map.d.ts +0 -9
  355. package/dist/modules/billing/voucher-kind-map.js.map +0 -1
  356. package/dist/modules/config/config-doctor.d.ts +0 -15
  357. package/dist/modules/config/config-doctor.js.map +0 -1
  358. package/dist/modules/config/config-value-parser.d.ts +0 -2
  359. package/dist/modules/config/config-value-parser.js.map +0 -1
  360. package/dist/modules/config/config.presenter.d.ts +0 -15
  361. package/dist/modules/config/config.presenter.js.map +0 -1
  362. package/dist/modules/config/config.schemas.d.ts +0 -154
  363. package/dist/modules/config/config.schemas.js.map +0 -1
  364. package/dist/modules/config/config.sections.d.ts +0 -14
  365. package/dist/modules/config/config.sections.js.map +0 -1
  366. package/dist/modules/config/config.service.d.ts +0 -35
  367. package/dist/modules/config/config.service.js.map +0 -1
  368. package/dist/modules/examples/examples.d.ts +0 -1
  369. package/dist/modules/examples/examples.js.map +0 -1
  370. package/dist/modules/fce/fce-obligation.d.ts +0 -20
  371. package/dist/modules/fce/fce-obligation.js.map +0 -1
  372. package/dist/modules/fce/fce-obligation.presenter.d.ts +0 -9
  373. package/dist/modules/fce/fce-obligation.presenter.js.map +0 -1
  374. package/dist/modules/interactive/amount-input.d.ts +0 -4
  375. package/dist/modules/interactive/amount-input.js.map +0 -1
  376. package/dist/modules/interactive/choices.d.ts +0 -13
  377. package/dist/modules/interactive/choices.js.map +0 -1
  378. package/dist/modules/interactive/config-fields.d.ts +0 -20
  379. package/dist/modules/interactive/config-fields.js.map +0 -1
  380. package/dist/modules/interactive/equivalent-command.d.ts +0 -8
  381. package/dist/modules/interactive/equivalent-command.js.map +0 -1
  382. package/dist/modules/interactive/invoice-copy.d.ts +0 -19
  383. package/dist/modules/interactive/invoice-copy.js.map +0 -1
  384. package/dist/modules/interactive/periods.d.ts +0 -7
  385. package/dist/modules/interactive/periods.js.map +0 -1
  386. package/dist/modules/interactive/wizard.d.ts +0 -16
  387. package/dist/modules/interactive/wizard.js.map +0 -1
  388. package/dist/modules/parameters/health.d.ts +0 -17
  389. package/dist/modules/parameters/health.js.map +0 -1
  390. package/dist/modules/parameters/parameters.d.ts +0 -50
  391. package/dist/modules/parameters/parameters.js.map +0 -1
  392. package/dist/modules/parameters/parameters.presenter.d.ts +0 -12
  393. package/dist/modules/parameters/parameters.presenter.js.map +0 -1
  394. package/dist/modules/parameters/status.d.ts +0 -31
  395. package/dist/modules/parameters/status.js.map +0 -1
  396. package/dist/modules/pdf/pdf-data.mapper.d.ts +0 -4
  397. package/dist/modules/pdf/pdf-data.mapper.js.map +0 -1
  398. package/dist/modules/pdf/pdf-decision.d.ts +0 -14
  399. package/dist/modules/pdf/pdf-decision.js.map +0 -1
  400. package/dist/modules/pdf/pdf-file-name.d.ts +0 -3
  401. package/dist/modules/pdf/pdf-file-name.js.map +0 -1
  402. package/dist/modules/pdf/pdf-issuer.d.ts +0 -8
  403. package/dist/modules/pdf/pdf-issuer.js.map +0 -1
  404. package/dist/modules/pdf/pdf.errors.d.ts +0 -9
  405. package/dist/modules/pdf/pdf.errors.js.map +0 -1
  406. package/dist/modules/pdf/pdf.types.d.ts +0 -91
  407. package/dist/modules/pdf/pdf.types.js.map +0 -1
  408. package/dist/modules/storybook/showcase-theme.d.ts +0 -7
  409. package/dist/modules/storybook/showcase-theme.js.map +0 -1
  410. package/dist/modules/storybook/showcase.d.ts +0 -2
  411. package/dist/modules/storybook/showcase.js.map +0 -1
  412. package/dist/modules/update-check/changelog.d.ts +0 -23
  413. package/dist/modules/update-check/changelog.js.map +0 -1
  414. package/dist/modules/update-check/update-check.presenter.d.ts +0 -6
  415. package/dist/modules/update-check/update-check.presenter.js.map +0 -1
  416. package/dist/modules/update-check/update-check.service.d.ts +0 -11
  417. package/dist/modules/update-check/update-check.service.js.map +0 -1
  418. package/dist/modules/vouchers/voucher-history.d.ts +0 -39
  419. package/dist/modules/vouchers/voucher-history.js.map +0 -1
  420. package/dist/modules/vouchers/voucher-history.presenter.d.ts +0 -29
  421. package/dist/modules/vouchers/voucher-history.presenter.js.map +0 -1
  422. package/dist/services/arca/arca-billing.gateway.d.ts +0 -10
  423. package/dist/services/arca/arca-billing.gateway.js.map +0 -1
  424. package/dist/services/arca/arca-client.factory.d.ts +0 -5
  425. package/dist/services/arca/arca-client.factory.js.map +0 -1
  426. package/dist/services/arca/arca-context.resolver.d.ts +0 -44
  427. package/dist/services/arca/arca-context.resolver.js.map +0 -1
  428. package/dist/services/arca/arca-fce-obligation.gateway.d.ts +0 -7
  429. package/dist/services/arca/arca-fce-obligation.gateway.js.map +0 -1
  430. package/dist/services/arca/arca-parameters.gateway.d.ts +0 -10
  431. package/dist/services/arca/arca-parameters.gateway.js.map +0 -1
  432. package/dist/services/arca/arca-voucher-history.gateway.d.ts +0 -8
  433. package/dist/services/arca/arca-voucher-history.gateway.js.map +0 -1
  434. package/dist/services/clipboard/clipboard.d.ts +0 -2
  435. package/dist/services/clipboard/clipboard.js.map +0 -1
  436. package/dist/services/pdf/escape-html.d.ts +0 -6
  437. package/dist/services/pdf/escape-html.js.map +0 -1
  438. package/dist/services/pdf/pdf-browser.d.ts +0 -5
  439. package/dist/services/pdf/pdf-browser.js.map +0 -1
  440. package/dist/services/pdf/pdf-exporter.d.ts +0 -19
  441. package/dist/services/pdf/pdf-exporter.js.map +0 -1
  442. package/dist/services/pdf/pdf-plugin.d.ts +0 -50
  443. package/dist/services/pdf/pdf-plugin.js.map +0 -1
  444. package/dist/ui/components/contentPanel.d.ts +0 -5
  445. package/dist/ui/components/contentPanel.js.map +0 -1
  446. package/dist/ui/components/errorPanel.d.ts +0 -1
  447. package/dist/ui/components/errorPanel.js.map +0 -1
  448. package/dist/ui/components/index.d.ts +0 -9
  449. package/dist/ui/components/index.js.map +0 -1
  450. package/dist/ui/components/keyValuePanel.d.ts +0 -3
  451. package/dist/ui/components/keyValuePanel.js.map +0 -1
  452. package/dist/ui/components/noticePanel.d.ts +0 -3
  453. package/dist/ui/components/noticePanel.js.map +0 -1
  454. package/dist/ui/components/rawPanel.d.ts +0 -1
  455. package/dist/ui/components/rawPanel.js.map +0 -1
  456. package/dist/ui/components/sectionHeading.d.ts +0 -3
  457. package/dist/ui/components/sectionHeading.js.map +0 -1
  458. package/dist/ui/components/statusBar.d.ts +0 -19
  459. package/dist/ui/components/statusBar.js.map +0 -1
  460. package/dist/ui/components/statusPanel.d.ts +0 -3
  461. package/dist/ui/components/statusPanel.js.map +0 -1
  462. package/dist/ui/components/testingBanner.d.ts +0 -2
  463. package/dist/ui/components/testingBanner.js.map +0 -1
  464. package/dist/ui/index.d.ts +0 -5
  465. package/dist/ui/index.js.map +0 -1
  466. package/dist/ui/presenters/billing.presenter.d.ts +0 -2
  467. package/dist/ui/presenters/billing.presenter.js.map +0 -1
  468. package/dist/ui/presenters/config.presenter.d.ts +0 -1
  469. package/dist/ui/presenters/config.presenter.js.map +0 -1
  470. package/dist/ui/presenters/errors.presenter.d.ts +0 -1
  471. package/dist/ui/presenters/errors.presenter.js.map +0 -1
  472. package/dist/ui/presenters/errors.zod-presenter.d.ts +0 -4
  473. package/dist/ui/presenters/errors.zod-presenter.js.map +0 -1
  474. package/dist/ui/presenters/index.d.ts +0 -6
  475. package/dist/ui/presenters/index.js.map +0 -1
  476. package/dist/ui/presenters/pdf.presenter.d.ts +0 -13
  477. package/dist/ui/presenters/pdf.presenter.js.map +0 -1
  478. package/dist/ui/presenters/showcase.presenter.d.ts +0 -1
  479. package/dist/ui/presenters/showcase.presenter.js.map +0 -1
  480. package/dist/ui/primitives/index.d.ts +0 -10
  481. package/dist/ui/primitives/index.js.map +0 -1
  482. package/dist/ui/primitives/renderDivider.d.ts +0 -5
  483. package/dist/ui/primitives/renderDivider.js.map +0 -1
  484. package/dist/ui/primitives/renderFooter.d.ts +0 -7
  485. package/dist/ui/primitives/renderFooter.js.map +0 -1
  486. package/dist/ui/primitives/renderJson.d.ts +0 -3
  487. package/dist/ui/primitives/renderJson.js.map +0 -1
  488. package/dist/ui/primitives/renderKeyValue.d.ts +0 -14
  489. package/dist/ui/primitives/renderKeyValue.js.map +0 -1
  490. package/dist/ui/primitives/renderLogo.d.ts +0 -3
  491. package/dist/ui/primitives/renderLogo.js.map +0 -1
  492. package/dist/ui/primitives/renderObject.d.ts +0 -1
  493. package/dist/ui/primitives/renderObject.js.map +0 -1
  494. package/dist/ui/primitives/renderPanel.d.ts +0 -27
  495. package/dist/ui/primitives/renderPanel.js.map +0 -1
  496. package/dist/ui/primitives/renderSubtitle.d.ts +0 -7
  497. package/dist/ui/primitives/renderSubtitle.js.map +0 -1
  498. package/dist/ui/primitives/renderTable.d.ts +0 -6
  499. package/dist/ui/primitives/renderTable.js.map +0 -1
  500. package/dist/ui/primitives/terminalWidth.d.ts +0 -4
  501. package/dist/ui/primitives/terminalWidth.js.map +0 -1
  502. package/dist/ui/primitives/text.d.ts +0 -28
  503. package/dist/ui/primitives/text.js.map +0 -1
  504. package/dist/ui/stream/index.d.ts +0 -1
  505. package/dist/ui/stream/index.js.map +0 -1
  506. package/dist/ui/stream/terminal-stream.d.ts +0 -16
  507. package/dist/ui/stream/terminal-stream.js.map +0 -1
  508. package/dist/ui/theme/index.d.ts +0 -1
  509. package/dist/ui/theme/index.js.map +0 -1
  510. package/dist/ui/theme/theme.d.ts +0 -68
  511. package/dist/ui/theme/theme.js.map +0 -1
@@ -0,0 +1,293 @@
1
+ import { formatArcaDateAsArgentineDate, formatDateAsArcaDate, parseArgentineDateInputAsArcaDate, } from '../../lib/dates/arca-date.js';
2
+ import { AppError, InputValidationError } from '../../lib/errors/app-error.js';
3
+ import { resolveBillingCurrencyCode } from '../billing/billing.mappers.js';
4
+ import { DEFAULT_EXPORT_CURRENCY_CODE, DEFAULT_EXPORT_LANGUAGE, DEFAULT_EXPORT_TYPE, EXPORT_TYPE_VALUES, EXPORT_TYPES, EXPORT_TYPES_WITHOUT_PERMITS, EXPORT_VOUCHER_KIND, MAX_EXPORT_VOUCHER_NUMBER, } from './export.types.js';
5
+ /** Codigo de pais de Argentina en la tabla DST_pais: no es un destino de exportacion. */
6
+ export const ARGENTINA_COUNTRY_CODE = 200;
7
+ /** Forma de pago por defecto: WSFEX la exige y casi todas las exportaciones se cobran por transferencia internacional. */
8
+ export const DEFAULT_EXPORT_PAYMENT_TERMS = 'Transferencia Internacional';
9
+ /** ARCA no acepta cotizaciones en pesos distintas de 1. */
10
+ const LOCAL_EXCHANGE_RATE = 1;
11
+ function requireText(value, description, flag) {
12
+ const trimmed = value?.trim();
13
+ if (!trimmed) {
14
+ throw new InputValidationError(`Falta ${description}. Usá ${flag}.`);
15
+ }
16
+ return trimmed;
17
+ }
18
+ function roundAmount(value) {
19
+ return Math.round(value * 100) / 100;
20
+ }
21
+ /** La fecha del comprobante, en formato ARCA: por defecto hoy en Argentina. */
22
+ export function resolveExportVoucherDate(value, now = new Date()) {
23
+ return value?.trim() ? parseArgentineDateInputAsArcaDate(value) : formatDateAsArcaDate(now);
24
+ }
25
+ /**
26
+ * Acepta `ARS`, `USD` o los codigos de ARCA (`PES`, `DOL`). Sin `--moneda` la exportacion va en dolares; la moneda
27
+ * de la config es la de los comprobantes locales. Sin `--cotizacion-moneda` se usa la de aduana que publica ARCA
28
+ * (WSFEX no acepta `Moneda_ctz` en 0): la clave `cotizacion` de la config no aplica, porque una cotizacion guardada
29
+ * queda vieja en dias (REV-35).
30
+ */
31
+ export function resolveExportCurrency(input) {
32
+ const requested = input.currencyCode?.trim() || DEFAULT_EXPORT_CURRENCY_CODE;
33
+ const currencyCode = resolveBillingCurrencyCode(requested);
34
+ const displayCode = requested.toUpperCase();
35
+ if (currencyCode === 'PES') {
36
+ if (input.sameCurrency) {
37
+ throw new InputValidationError('--misma-moneda solo aplica a comprobantes en moneda extranjera.');
38
+ }
39
+ if (typeof input.exchangeRate === 'number' && input.exchangeRate !== LOCAL_EXCHANGE_RATE) {
40
+ throw new InputValidationError('En pesos la cotización tiene que ser 1. Quitá --cotizacion-moneda o usá --cm 1.');
41
+ }
42
+ return {
43
+ fields: { CanMisMonExt: 'N', Moneda_ctz: LOCAL_EXCHANGE_RATE, Moneda_Id: currencyCode },
44
+ needsQuotation: false,
45
+ };
46
+ }
47
+ const rate = input.exchangeRate;
48
+ if (rate !== undefined && rate <= LOCAL_EXCHANGE_RATE) {
49
+ throw new InputValidationError(`La cotización de ${displayCode} tiene que ser mayor a 1.`);
50
+ }
51
+ return {
52
+ fields: {
53
+ CanMisMonExt: input.sameCurrency ? 'S' : 'N',
54
+ Moneda_ctz: rate ?? 0,
55
+ Moneda_Id: currencyCode,
56
+ },
57
+ needsQuotation: rate === undefined,
58
+ };
59
+ }
60
+ /**
61
+ * La cotizacion de aduana de la fecha del comprobante. WSFEX devuelve por moneda la ultima publicada, asi que el
62
+ * dia en curso —que todavia no tiene— o un fin de semana traen la anterior. Sin fila para la moneda no hay
63
+ * cotizacion que usar: es error, salvo que el usuario la informe con `--cotizacion-moneda`.
64
+ */
65
+ export function resolveExportQuotation(currencyCode, quotations, voucherDate) {
66
+ const code = currencyCode.trim().toUpperCase();
67
+ const quotation = quotations.find((entry) => entry.code.trim().toUpperCase() === code);
68
+ if (quotation) {
69
+ return quotation;
70
+ }
71
+ const available = quotations.map((entry) => entry.code).join(', ');
72
+ throw new AppError(`ARCA no informó la cotización de ${code} para el ${formatArcaDateAsArgentineDate(voucherDate)}.${available ? ` Las monedas con cotización son ${available}.` : ''} Informá la cotización con --cotizacion-moneda.`, { code: 'ARCA_QUOTATION_ERROR' });
73
+ }
74
+ /**
75
+ * WSFEX exige una `Actividad` (error 2100) y solo acepta los codigos de su propia tabla, que no es la del padron y
76
+ * es mas chica (error 2105 al emitir). Cada emisor tiene la suya, asi que no hay default: sale de `--actividad` o de
77
+ * `exportacion.actividad`. Los nombres de la tabla llegan con la codificacion rota, por eso los mensajes solo dan codigos.
78
+ */
79
+ export function resolveExportActivity(value, activities = []) {
80
+ if (!Number.isInteger(value) || value < 1) {
81
+ throw new InputValidationError('La actividad tiene que ser un número entero positivo. Usá --actividad.');
82
+ }
83
+ if (activities.length === 0 || activities.some((activity) => activity.id === value)) {
84
+ return value;
85
+ }
86
+ const prefix = String(value).slice(0, 3);
87
+ const family = activities.filter((activity) => String(activity.id).startsWith(prefix)).slice(0, 5);
88
+ const candidates = family.length > 0 ? ` Las que empiezan con ${prefix} son ${family.map((activity) => activity.id).join(', ')}.` : '';
89
+ throw new InputValidationError(`La actividad ${value} no está en la tabla de actividades de WSFEX y ARCA la rechaza (error 2105).${candidates} Indicá la que corresponda con --actividad.`);
90
+ }
91
+ export function resolveExportType(value) {
92
+ if (value === undefined) {
93
+ return DEFAULT_EXPORT_TYPE;
94
+ }
95
+ if (!EXPORT_TYPE_VALUES.includes(value)) {
96
+ throw new InputValidationError('--tipo-expo tiene que ser 1 (exportación definitiva de bienes), 2 (servicios) o 4 (otros).');
97
+ }
98
+ return value;
99
+ }
100
+ export function resolveExportLanguage(value, languages) {
101
+ if (value === undefined) {
102
+ return DEFAULT_EXPORT_LANGUAGE;
103
+ }
104
+ if (languages.length > 0 && !languages.some((language) => language.id === value)) {
105
+ throw new InputValidationError(`El idioma ${value} no existe en la tabla de ARCA.`);
106
+ }
107
+ return value;
108
+ }
109
+ /**
110
+ * El pais se puede escribir por codigo (`203`) o por nombre (`Brasil`). Se valida contra la tabla de ARCA y
111
+ * se rechaza Argentina: WSFEX es solo para exportaciones.
112
+ */
113
+ export function resolveExportDestinationCountry(value, countries) {
114
+ const trimmed = requireText(value, 'el país de destino', '--pais-destino');
115
+ const numeric = /^\d+$/.test(trimmed) ? Number(trimmed) : undefined;
116
+ const country = numeric
117
+ ? countries.find((entry) => entry.code === numeric)
118
+ : countries.find((entry) => entry.name.trim().toLowerCase() === trimmed.toLowerCase());
119
+ if (!country) {
120
+ throw new InputValidationError(`El país de destino "${trimmed}" no existe en la tabla de ARCA. Usá el código o el nombre que informa ARCA.`);
121
+ }
122
+ if (country.code === ARGENTINA_COUNTRY_CODE) {
123
+ throw new InputValidationError('Argentina no es un destino de exportación: usá `arcli factura a` o `arcli factura b`.');
124
+ }
125
+ return country;
126
+ }
127
+ /**
128
+ * DST_CUIT repite cada pais tres veces, con el tipo de entidad pegado al nombre: "BRASIL - Persona Jurídica".
129
+ * DST_pais trae solo "BRASIL", asi que el sufijo no sirve para comparar ni para mostrar el pais.
130
+ */
131
+ const COUNTRY_CUIT_ENTITY_SUFFIX = /\s*-\s*(?:persona\s+f[ií]sica|persona\s+jur[ií]dica|otro\s+tipo\s+de\s+entidad)\s*$/i;
132
+ /** Cuando el pais tiene las tres filas, gana la de persona juridica: el cliente de una exportacion suele ser una empresa. */
133
+ const COUNTRY_CUIT_ENTITY_PREFERENCE = [
134
+ /\bpersona\s+jur[ií]dica\s*$/i,
135
+ /\botro\s+tipo\s+de\s+entidad\s*$/i,
136
+ /\bpersona\s+f[ií]sica\s*$/i,
137
+ ];
138
+ /** Para comparar nombres de las dos tablas: sin tipo de entidad, sin acentos, sin mayusculas y con un solo espacio. */
139
+ function normalizeCountryName(value) {
140
+ return value
141
+ .normalize('NFD')
142
+ .replace(/[\u0300-\u036f]/g, '')
143
+ .replace(/\s+/g, ' ')
144
+ .trim()
145
+ .toLowerCase();
146
+ }
147
+ function countryNameWithoutEntity(value) {
148
+ return value.replace(COUNTRY_CUIT_ENTITY_SUFFIX, '').trim();
149
+ }
150
+ function pickCountryCuit(entries) {
151
+ for (const preference of COUNTRY_CUIT_ENTITY_PREFERENCE) {
152
+ const preferred = entries.find((entry) => preference.test(entry.countryName));
153
+ if (preferred) {
154
+ return preferred;
155
+ }
156
+ }
157
+ return entries[0];
158
+ }
159
+ /**
160
+ * WSFEX pide el CUIT del pais del cliente. Se resuelve con la tabla DST_CUIT, que nombra cada pais con el tipo de
161
+ * entidad ("ESTADOS UNIDOS - Persona Jurídica"), mientras que la tabla de destinos dice solo "ESTADOS UNIDOS": por
162
+ * eso se compara sin el sufijo. Si el CUIT viene por flag se valida contra la tabla, salvo para los paises cuyo
163
+ * nombre no coincide entre las dos tablas ("CHINA" y "CHINA REP.POPULAR"), donde solo se acepta que exista.
164
+ */
165
+ export function resolveExportClientCountryCuit(options) {
166
+ const destination = normalizeCountryName(options.country.name);
167
+ const forDestination = options.countries.filter((entry) => normalizeCountryName(countryNameWithoutEntity(entry.countryName)) === destination);
168
+ if (options.cuit === undefined) {
169
+ const resolved = pickCountryCuit(forDestination);
170
+ if (!resolved) {
171
+ throw new InputValidationError(`La tabla de ARCA no tiene CUIT para "${options.country.name}". Indicalo con --cuit-pais.`);
172
+ }
173
+ return resolved.cuit;
174
+ }
175
+ const match = options.countries.find((entry) => entry.cuit === options.cuit);
176
+ if (!match) {
177
+ throw new InputValidationError(`El CUIT de país ${options.cuit} no existe en la tabla de ARCA.`);
178
+ }
179
+ const expected = pickCountryCuit(forDestination);
180
+ if (expected && normalizeCountryName(countryNameWithoutEntity(match.countryName)) !== destination) {
181
+ throw new InputValidationError(`El CUIT de país ${options.cuit} corresponde a "${countryNameWithoutEntity(match.countryName)}" y el destino es "${options.country.name}". Para "${options.country.name}" la tabla de ARCA trae ${expected.cuit}.`);
182
+ }
183
+ return options.cuit;
184
+ }
185
+ /** `--incoterm` se compara contra la tabla de ARCA, sin importar mayusculas. */
186
+ export function resolveExportIncoterm(value, incoterms) {
187
+ const trimmed = value?.trim();
188
+ if (!trimmed) {
189
+ return undefined;
190
+ }
191
+ const incoterm = incoterms.find((entry) => entry.code.trim().toUpperCase() === trimmed.toUpperCase());
192
+ if (!incoterm) {
193
+ throw new InputValidationError(`El incoterm "${trimmed}" no existe en la tabla de ARCA. Consultá los válidos con arcli parametros.`);
194
+ }
195
+ return incoterm;
196
+ }
197
+ export function resolveExportPointOfSale(value, config) {
198
+ const pointOfSale = value ?? config.puntoVentaPorDefecto;
199
+ if (pointOfSale === undefined) {
200
+ throw new InputValidationError('Falta el punto de venta. Usá --punto-venta o configurá puntoVentaPorDefecto.');
201
+ }
202
+ if (!Number.isInteger(pointOfSale) || pointOfSale < 1) {
203
+ throw new InputValidationError('El punto de venta tiene que ser un número entero positivo.');
204
+ }
205
+ return pointOfSale;
206
+ }
207
+ /** Numero del comprobante o de la solicitud: el indicado por el usuario o el que sigue al ultimo de ARCA. */
208
+ export function resolveExportNumber(options) {
209
+ if (options.provided !== undefined) {
210
+ if (!Number.isInteger(options.provided) || options.provided < 1) {
211
+ throw new InputValidationError(`${options.label} tiene que ser un número entero positivo.`);
212
+ }
213
+ return options.provided;
214
+ }
215
+ const next = (Number.isFinite(options.last) ? options.last : 0) + 1;
216
+ if (next > MAX_EXPORT_VOUCHER_NUMBER) {
217
+ throw new InputValidationError(`${options.label} supera el máximo de ARCA (${MAX_EXPORT_VOUCHER_NUMBER}).`);
218
+ }
219
+ return next;
220
+ }
221
+ /** En los tipos 2 (servicios) y 4 (otros) ARCA exige `Permiso_existente` vacio, no `N` (error 1550). */
222
+ function requiresEmptyPermitsExisting(exportType) {
223
+ return EXPORT_TYPES_WITHOUT_PERMITS.includes(exportType);
224
+ }
225
+ /**
226
+ * Con `Permiso_existente = N` ARCA rechaza el campo `Permisos` (error 1720), y en los tipos 2 y 4 pide el campo
227
+ * vacio y no admite permisos (error 1550): sin permisos no se manda.
228
+ */
229
+ function resolvePermits(input, destinationCountry, exportType) {
230
+ const permits = (input.permits ?? []).map((permit) => permit.trim()).filter(Boolean);
231
+ if (permits.length === 0) {
232
+ if (input.permitsExisting) {
233
+ throw new InputValidationError('--permiso-existente pide al menos un permiso de embarque. Usá --permiso.');
234
+ }
235
+ return undefined;
236
+ }
237
+ if (requiresEmptyPermitsExisting(exportType)) {
238
+ throw new InputValidationError(`El tipo de exportación ${exportType} (${EXPORT_TYPES[exportType]}) no lleva permisos de embarque: ARCA exige Permiso_existente vacío (error 1550). Quitá --permiso.`);
239
+ }
240
+ if (!input.permitsExisting) {
241
+ throw new InputValidationError('Los permisos de embarque van con --permiso-existente: ARCA necesita saber que el permiso ya existe.');
242
+ }
243
+ return { Permiso: [...new Set(permits)].map((id) => ({ Dst_merc: destinationCountry, Id_permiso: id })) };
244
+ }
245
+ /**
246
+ * Arma el `Cmp` de `FEXAuthorize` con los datos ya resueltos contra las tablas de ARCA.
247
+ *
248
+ * Los bloques vacios no van: `Permisos` sin permisos (error 1720), `Cmps_asoc` y `Opcionales` sin filas (error 1820
249
+ * el primero). `Actividades`, en cambio, siempre lleva una `Actividad` (error 2100).
250
+ */
251
+ export function buildExportPayload(input, resolution) {
252
+ const clientName = requireText(input.clientName, 'el nombre del cliente', '--cliente');
253
+ const clientAddress = requireText(input.clientAddress, 'el domicilio del cliente', '--domicilio-cliente');
254
+ if (typeof input.amount !== 'number' || !(input.amount > 0)) {
255
+ throw new InputValidationError('Falta el importe total o no es válido. Usá --monto.');
256
+ }
257
+ const permits = resolvePermits(input, resolution.destinationCountry.code, resolution.exportType);
258
+ /** En servicios y otros ARCA pide el campo vacio; en el resto, `N` sin permisos y `S` con permisos. */
259
+ const permitsExisting = requiresEmptyPermitsExisting(resolution.exportType)
260
+ ? ''
261
+ : input.permitsExisting
262
+ ? 'S'
263
+ : 'N';
264
+ return {
265
+ // Actividades va siempre con una: con el bloque vacio ARCA contesta 2100.
266
+ Actividades: { Actividad: [{ Id: resolution.activity }] },
267
+ CanMisMonExt: resolution.currency.CanMisMonExt,
268
+ Cbte_nro: resolution.voucherNumber,
269
+ Cbte_Tipo: EXPORT_VOUCHER_KIND.arcaType,
270
+ Cliente: clientName,
271
+ Cuit_pais_cliente: resolution.clientCountryCuit,
272
+ Domicilio_cliente: clientAddress,
273
+ Dst_cmp: resolution.destinationCountry.code,
274
+ Fecha_cbte: resolution.voucherDate,
275
+ Fecha_pago: resolution.paymentDate,
276
+ Forma_pago: input.paymentTerms?.trim() || DEFAULT_EXPORT_PAYMENT_TERMS,
277
+ Id: resolution.requestId,
278
+ Id_impositivo: input.clientTaxId?.trim() ?? '',
279
+ Idioma_cbte: resolution.languageId,
280
+ Imp_total: roundAmount(input.amount),
281
+ Incoterms: resolution.incoterm?.code ?? '',
282
+ Incoterms_Ds: input.incotermDescription?.trim() || resolution.incoterm?.name || '',
283
+ Items: { Item: [...resolution.items] },
284
+ Moneda_ctz: resolution.currency.Moneda_ctz,
285
+ Moneda_Id: resolution.currency.Moneda_Id,
286
+ Obs: input.observations?.trim() ?? '',
287
+ Obs_comerciales: input.commercialObservations?.trim() ?? '',
288
+ Permiso_existente: permitsExisting,
289
+ ...(permits ? { Permisos: permits } : {}),
290
+ Punto_vta: resolution.pointOfSale,
291
+ Tipo_expo: resolution.exportType,
292
+ };
293
+ }
@@ -0,0 +1,2 @@
1
+ export { formatExportResultAsJson } from './export.serialize.js';
2
+ export { formatExportResultAsText } from './export.text.js';
@@ -0,0 +1,86 @@
1
+ const POINT_OF_SALE_HINT = 'Revisá los puntos de venta habilitados para WSFEX con `arcli parametros puntos-venta`.';
2
+ function normalizeArcaDate(value) {
3
+ const digits = (value ?? '').replace(/\D/g, '').slice(0, 8);
4
+ return /^\d{8}$/.test(digits) ? digits : null;
5
+ }
6
+ /**
7
+ * WSFEX informa los errores en `FEXErr` y los avisos en `FEXEvents`, con el codigo en 0 cuando no hay nada que
8
+ * decir: en la autorizacion exitosa manda `ErrCode: 0` con `ErrMsg: "OK"`, que no es un error.
9
+ */
10
+ function toEntry(code, message) {
11
+ if (!code) {
12
+ return [];
13
+ }
14
+ return [{ code, message: message?.trim() || 'ARCA no informó el detalle.' }];
15
+ }
16
+ function buildSuggestions(options) {
17
+ const suggestions = new Set();
18
+ if (/punto de venta/i.test(options.messages)) {
19
+ suggestions.add(POINT_OF_SALE_HINT);
20
+ }
21
+ if (/permiso/i.test(options.messages)) {
22
+ suggestions.add('Revisá los permisos de embarque: van con --permiso y --permiso-existente.');
23
+ }
24
+ if (/cuit.*(pais|país)/i.test(options.messages)) {
25
+ suggestions.add('Revisá el CUIT del país del cliente (`--cuit-pais`) y el país de destino.');
26
+ }
27
+ if (/moneda|cotizaci[oó]n/i.test(options.messages)) {
28
+ suggestions.add('Revisá la moneda y la cotización (`--moneda`, `--cotizacion-moneda`).');
29
+ }
30
+ if (/incoterm/i.test(options.messages)) {
31
+ suggestions.add('Revisá el incoterm (`--incoterm`) contra la tabla de ARCA.');
32
+ }
33
+ if (/actividad/i.test(options.messages)) {
34
+ suggestions.add('La actividad tiene que estar vinculada al emisor y activa para WSFEX: revisá las actividades habilitadas en ARCA o indicá otra con --actividad.');
35
+ }
36
+ if (/correlativ/i.test(options.messages)) {
37
+ suggestions.add('Revisá el número del comprobante (--numero): tiene que ser el siguiente al último E emitido en ese punto de venta.');
38
+ }
39
+ if (options.status !== 'aprobado' && suggestions.size === 0) {
40
+ suggestions.add('Revisá observaciones y errores de ARCA antes de volver a emitir.');
41
+ }
42
+ return [...suggestions];
43
+ }
44
+ export function createDryRunExportResponse() {
45
+ return {
46
+ cae: null,
47
+ caeVencimiento: null,
48
+ errors: [],
49
+ events: [],
50
+ observacion: null,
51
+ observaciones: [],
52
+ raw: null,
53
+ resultado: null,
54
+ status: 'observado',
55
+ suggestions: [],
56
+ };
57
+ }
58
+ /** WSFEX informa el rechazo en `Resultado` y los errores duros en `FEXErr`, sin lanzar excepcion. */
59
+ export function mapExportResponse(output) {
60
+ const result = output.FEXAuthorizeResult;
61
+ const authorization = result?.FEXResultAuth;
62
+ const errors = toEntry(result?.FEXErr?.ErrCode, result?.FEXErr?.ErrMsg);
63
+ const events = toEntry(result?.FEXEvents?.EventCode, result?.FEXEvents?.EventMsg);
64
+ const motivo = authorization?.Motivos_Obs?.trim();
65
+ const observaciones = motivo ? [motivo] : [];
66
+ const resultado = authorization?.Resultado?.trim() || null;
67
+ const cae = authorization?.Cae?.trim() || null;
68
+ const status = resultado === 'R' || errors.length > 0
69
+ ? 'rechazado'
70
+ : resultado === 'A' && observaciones.length === 0
71
+ ? 'aprobado'
72
+ : 'observado';
73
+ const messages = [...observaciones, ...errors.map((error) => error.message)].join(' | ');
74
+ return {
75
+ cae,
76
+ caeVencimiento: normalizeArcaDate(authorization?.Fch_venc_Cae),
77
+ errors,
78
+ events,
79
+ observacion: observaciones.join(' | ') || null,
80
+ observaciones,
81
+ raw: output,
82
+ resultado,
83
+ status,
84
+ suggestions: buildSuggestions({ messages, status }),
85
+ };
86
+ }
@@ -0,0 +1,70 @@
1
+ // Aditivo: la clave `pdf` solo aparece si se intento generar el PDF.
2
+ function formatPdfOutcome(result) {
3
+ if (!result.pdf) {
4
+ return {};
5
+ }
6
+ if ('path' in result.pdf) {
7
+ return { pdf: { ruta: result.pdf.path } };
8
+ }
9
+ const { code, message, suggestion } = result.pdf.error;
10
+ return { pdf: { error: { codigo: code, mensaje: message, sugerencia: suggestion ?? null } } };
11
+ }
12
+ function formatRawResponse(result) {
13
+ return result.response.raw ?? { mensaje: 'Sin emisión real. Usá --emitir para obtener una respuesta de ARCA.' };
14
+ }
15
+ /** Lo que WSFEX tiene y wsfe no: destino, incoterm, permisos e items reales. */
16
+ function formatExportBlock(result) {
17
+ const { payload, display } = result;
18
+ return {
19
+ actividad: payload.Actividades.Actividad.map((activity) => activity.Id),
20
+ cliente: payload.Cliente,
21
+ cuitPaisCliente: payload.Cuit_pais_cliente,
22
+ destino: { codigo: payload.Dst_cmp, nombre: display.countryName ?? null },
23
+ domicilioCliente: payload.Domicilio_cliente,
24
+ formaPago: payload.Forma_pago,
25
+ idImpositivo: payload.Id_impositivo || null,
26
+ idioma: payload.Idioma_cbte,
27
+ incoterm: payload.Incoterms || null,
28
+ incotermDescripcion: payload.Incoterms_Ds || null,
29
+ items: payload.Items.Item.map((item) => ({
30
+ cantidad: item.Pro_qty,
31
+ codigo: item.Pro_codigo || null,
32
+ descripcion: item.Pro_ds,
33
+ precioUnitario: item.Pro_precio_uni,
34
+ total: item.Pro_total_item,
35
+ unidad: display.unitNames[item.Pro_umed] ?? null,
36
+ unidadCodigo: item.Pro_umed,
37
+ })),
38
+ mismaMoneda: payload.CanMisMonExt === 'S',
39
+ permisos: payload.Permisos?.Permiso ?? [],
40
+ tipoExpo: payload.Tipo_expo,
41
+ };
42
+ }
43
+ export function serializeExportResult(result, options = {}) {
44
+ const summary = {
45
+ atajo: result.voucherKind.shortcut,
46
+ avisos: result.warnings ?? [],
47
+ cae: result.response.cae,
48
+ caeVencimiento: result.response.caeVencimiento,
49
+ comprobante: result.voucherKind.displayName,
50
+ errores: result.response.errors,
51
+ estado: result.response.status,
52
+ eventos: result.response.events,
53
+ exportacion: formatExportBlock(result),
54
+ observaciones: result.response.observaciones,
55
+ observacion: result.response.observacion,
56
+ ...formatPdfOutcome(result),
57
+ previsualizacion: result.dryRun,
58
+ resultado: result.response.resultado,
59
+ solicitud: result.payload,
60
+ sugerencias: result.response.suggestions,
61
+ tipoArca: result.voucherKind.arcaType,
62
+ };
63
+ return options.raw ? { ...summary, respuesta: formatRawResponse(result) } : summary;
64
+ }
65
+ export function formatExportResultAsJson(result, options = {}) {
66
+ return JSON.stringify(serializeExportResult(result, options), null, 2);
67
+ }
68
+ export function formatRawExportResponse(result) {
69
+ return formatRawResponse(result);
70
+ }
@@ -0,0 +1,146 @@
1
+ import { formatArcaDateAsArgentineDate, formatDateAsArcaDate, parseArgentineDateInputAsArcaDate, } from '../../lib/dates/arca-date.js';
2
+ import { InputValidationError } from '../../lib/errors/app-error.js';
3
+ import { assertExportItemsTotal, buildExportItems, DEFAULT_EXPORT_ITEM_DESCRIPTION } from './export.items.js';
4
+ import { buildExportPayload, resolveExportActivity, resolveExportClientCountryCuit, resolveExportCurrency, resolveExportDestinationCountry, resolveExportIncoterm, resolveExportLanguage, resolveExportNumber, resolveExportPointOfSale, resolveExportQuotation, resolveExportType, resolveExportVoucherDate, } from './export.mappers.js';
5
+ import { createDryRunExportResponse, mapExportResponse } from './export.response.js';
6
+ import { EXPORT_VOUCHER_KIND, } from './export.types.js';
7
+ /** Se valida antes de tocar la red: un flag que falta no tiene por que autenticar en WSAA. */
8
+ function assertRequiredFields(input, activity) {
9
+ if (typeof input.amount !== 'number' || !(input.amount > 0)) {
10
+ throw new InputValidationError('Falta el importe total o no es válido. Usá --monto.');
11
+ }
12
+ if (!input.clientName?.trim()) {
13
+ throw new InputValidationError('Falta el nombre del cliente. Usá --cliente.');
14
+ }
15
+ if (!input.clientAddress?.trim()) {
16
+ throw new InputValidationError('Falta el domicilio del cliente. Usá --domicilio-cliente.');
17
+ }
18
+ if (!input.destinationCountry?.trim()) {
19
+ throw new InputValidationError('Falta el país de destino. Usá --pais-destino.');
20
+ }
21
+ // WSFEX numera por punto de venta y tipo, pero @arcasdk/core no deja consultar el ultimo (FEXGetLast_CMP lleva
22
+ // Pto_venta y Cbte_Tipo dentro de Auth y el SDK pisa ese bloque). Hasta que se arregle, el numero lo indica el usuario.
23
+ if (input.voucherNumber === undefined) {
24
+ throw new InputValidationError('Falta el número del comprobante. Usá --numero: arcli todavía no puede consultar en WSFEX el último emitido. Si es la primera Factura E de este punto de venta, es 1; si no, el siguiente al último que emitiste.');
25
+ }
26
+ if (activity === undefined) {
27
+ throw new InputValidationError('Falta la actividad de exportación. Usá --actividad o guardala con "arcli config establecer exportacion.actividad <código>": es el código de la tabla de actividades de WSFEX, por ejemplo 620100.');
28
+ }
29
+ assertExportItemsTotal(input.items, input.amount);
30
+ }
31
+ /** WSFEX no acepta comprobantes con fecha futura. Las fechas pasadas si son validas. */
32
+ function assertNotFuture(voucherDate, now) {
33
+ const today = formatDateAsArcaDate(now);
34
+ if (voucherDate > today) {
35
+ throw new InputValidationError(`La fecha del comprobante (${voucherDate.slice(6, 8)}/${voucherDate.slice(4, 6)}/${voucherDate.slice(0, 4)}) no puede ser futura.`);
36
+ }
37
+ }
38
+ export class ExportService {
39
+ /**
40
+ * Resuelve todo lo que pide WSFEX antes de emitir: tablas de paises, incoterms, idiomas y unidades,
41
+ * numeracion y cotizacion. Son llamadas de lectura: no emiten nada.
42
+ */
43
+ async resolve(input, gateway, runtime, now = new Date()) {
44
+ const config = runtime.config;
45
+ const activityCode = input.activity ?? config.exportacion?.actividad;
46
+ assertRequiredFields(input, activityCode);
47
+ const exportType = resolveExportType(input.exportType);
48
+ const voucherDate = resolveExportVoucherDate(input.voucherDate, now);
49
+ const paymentDate = input.paymentDate?.trim() ? parseArgentineDateInputAsArcaDate(input.paymentDate) : voucherDate;
50
+ assertNotFuture(voucherDate, now);
51
+ const countryList = await gateway.getDestinationCountries();
52
+ const destinationCountry = resolveExportDestinationCountry(input.destinationCountry, countryList);
53
+ const countryCuits = await gateway.getDestinationCountryCuits();
54
+ const clientCountryCuit = resolveExportClientCountryCuit({
55
+ country: destinationCountry,
56
+ countries: countryCuits,
57
+ cuit: input.clientCountryCuit,
58
+ });
59
+ const units = await gateway.getUnits();
60
+ const items = buildExportItems(input.items, input.amount, units, input.description?.trim() || DEFAULT_EXPORT_ITEM_DESCRIPTION);
61
+ const incoterm = resolveExportIncoterm(input.incoterm, input.incoterm?.trim() ? await gateway.getIncoterms() : []);
62
+ // Se consulta siempre: la vista previa muestra el nombre del idioma, tambien el de por defecto.
63
+ const languages = await gateway.getLanguages();
64
+ const languageId = resolveExportLanguage(input.language, languages);
65
+ const currency = resolveExportCurrency(input);
66
+ const quotation = currency.needsQuotation
67
+ ? resolveExportQuotation(currency.fields.Moneda_Id, await gateway.getQuotations(voucherDate), voucherDate)
68
+ : undefined;
69
+ const exchangeRate = quotation?.rate ?? currency.fields.Moneda_ctz;
70
+ const pointOfSale = resolveExportPointOfSale(input.pointOfSale, config);
71
+ const voucherNumber = resolveExportNumber({
72
+ label: 'El número del comprobante',
73
+ last: 0,
74
+ provided: input.voucherNumber,
75
+ });
76
+ const requestId = resolveExportNumber({
77
+ label: 'El ID de la solicitud',
78
+ last: input.requestId === undefined ? await gateway.getLastRequestId() : 0,
79
+ provided: input.requestId,
80
+ });
81
+ const activity = resolveExportActivity(activityCode, await gateway.getActivities());
82
+ const payload = buildExportPayload(input, {
83
+ activity,
84
+ clientCountryCuit,
85
+ currency: {
86
+ ...currency.fields,
87
+ Moneda_Id: quotation?.code ?? currency.fields.Moneda_Id,
88
+ Moneda_ctz: exchangeRate,
89
+ },
90
+ destinationCountry,
91
+ exportType,
92
+ incoterm,
93
+ items: items.items,
94
+ languageId,
95
+ paymentDate,
96
+ pointOfSale,
97
+ requestId,
98
+ voucherDate,
99
+ voucherNumber,
100
+ });
101
+ const currencyCode = payload.Moneda_Id.trim().toUpperCase();
102
+ const display = {
103
+ countryCuitName: countryCuits.find((entry) => entry.cuit === clientCountryCuit)?.countryName,
104
+ countryName: destinationCountry.name,
105
+ currencyName: (await gateway.getCurrencies()).find((entry) => entry.code.trim().toUpperCase() === currencyCode)
106
+ ?.name,
107
+ incotermName: incoterm?.name,
108
+ languageName: languages.find((language) => language.id === languageId)?.name,
109
+ unitNames: Object.fromEntries(units.map((unit) => [unit.id, unit.name])),
110
+ };
111
+ // La cotizacion de aduana del dia se publica mas tarde: se emite con la ultima disponible, avisando de que dia es.
112
+ const warnings = [
113
+ ...(quotation?.date && quotation.date !== voucherDate
114
+ ? [
115
+ `ARCA no publicó la cotización de ${quotation.code} del ${formatArcaDateAsArgentineDate(voucherDate)}: se usa la del ${formatArcaDateAsArgentineDate(quotation.date)} (${quotation.rate}). Para usar otra, --cotizacion-moneda.`,
116
+ ]
117
+ : []),
118
+ ];
119
+ return { display, payload, warnings };
120
+ }
121
+ /** Vista previa: el payload resuelto, sin llamar a `authorize`. */
122
+ preview(resolved, runtime, warnings) {
123
+ return {
124
+ display: resolved.display,
125
+ dryRun: true,
126
+ environment: runtime.environment,
127
+ payload: resolved.payload,
128
+ response: createDryRunExportResponse(),
129
+ voucherKind: EXPORT_VOUCHER_KIND,
130
+ warnings,
131
+ };
132
+ }
133
+ /** La llamada que emite. Un error aca puede haber dejado el comprobante autorizado en ARCA. */
134
+ async execute(options) {
135
+ const raw = await options.gateway.authorize(options.resolved.payload);
136
+ return {
137
+ display: options.resolved.display,
138
+ dryRun: false,
139
+ environment: options.runtime.environment,
140
+ payload: options.resolved.payload,
141
+ response: mapExportResponse(raw),
142
+ voucherKind: EXPORT_VOUCHER_KIND,
143
+ warnings: options.warnings,
144
+ };
145
+ }
146
+ }