@endora-commerce/mod-invoices 0.0.0-stage → 0.100.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 (235) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -2
  3. package/dist/admin/components/InvoiceSectionTabs.d.ts +22 -0
  4. package/dist/admin/components/InvoiceSectionTabs.d.ts.map +1 -0
  5. package/dist/admin/components/InvoiceSectionTabs.js +34 -0
  6. package/dist/admin/components/InvoiceSectionTabs.js.map +1 -0
  7. package/dist/admin/index.d.ts +34 -0
  8. package/dist/admin/index.d.ts.map +1 -0
  9. package/dist/admin/index.js +69 -0
  10. package/dist/admin/index.js.map +1 -0
  11. package/dist/admin/pages/InvoiceDetail.d.ts +10 -0
  12. package/dist/admin/pages/InvoiceDetail.d.ts.map +1 -0
  13. package/dist/admin/pages/InvoiceDetail.js +111 -0
  14. package/dist/admin/pages/InvoiceDetail.js.map +1 -0
  15. package/dist/admin/pages/InvoiceTemplateEditor.d.ts +11 -0
  16. package/dist/admin/pages/InvoiceTemplateEditor.d.ts.map +1 -0
  17. package/dist/admin/pages/InvoiceTemplateEditor.js +188 -0
  18. package/dist/admin/pages/InvoiceTemplateEditor.js.map +1 -0
  19. package/dist/admin/pages/InvoiceTemplatesPage.d.ts +10 -0
  20. package/dist/admin/pages/InvoiceTemplatesPage.d.ts.map +1 -0
  21. package/dist/admin/pages/InvoiceTemplatesPage.js +60 -0
  22. package/dist/admin/pages/InvoiceTemplatesPage.js.map +1 -0
  23. package/dist/admin/pages/InvoicesList.d.ts +9 -0
  24. package/dist/admin/pages/InvoicesList.d.ts.map +1 -0
  25. package/dist/admin/pages/InvoicesList.js +116 -0
  26. package/dist/admin/pages/InvoicesList.js.map +1 -0
  27. package/dist/admin/templates/described-blocks.d.ts +67 -0
  28. package/dist/admin/templates/described-blocks.d.ts.map +1 -0
  29. package/dist/admin/templates/described-blocks.js +83 -0
  30. package/dist/admin/templates/described-blocks.js.map +1 -0
  31. package/dist/admin/templates/invoice-builder-plugin.d.ts +4 -0
  32. package/dist/admin/templates/invoice-builder-plugin.d.ts.map +1 -0
  33. package/dist/admin/templates/invoice-builder-plugin.js +12 -0
  34. package/dist/admin/templates/invoice-builder-plugin.js.map +1 -0
  35. package/dist/admin/templates/invoice-puck-config.d.ts +37 -0
  36. package/dist/admin/templates/invoice-puck-config.d.ts.map +1 -0
  37. package/dist/admin/templates/invoice-puck-config.js +733 -0
  38. package/dist/admin/templates/invoice-puck-config.js.map +1 -0
  39. package/dist/backend/email-templates/invoice-issued.default.d.ts +10 -0
  40. package/dist/backend/email-templates/invoice-issued.default.d.ts.map +1 -0
  41. package/dist/backend/email-templates/invoice-issued.default.js +45 -0
  42. package/dist/backend/email-templates/invoice-issued.default.js.map +1 -0
  43. package/dist/backend/entities/invoice-external-attachment.entity.d.ts +20 -0
  44. package/dist/backend/entities/invoice-external-attachment.entity.d.ts.map +1 -0
  45. package/dist/backend/entities/invoice-external-attachment.entity.js +77 -0
  46. package/dist/backend/entities/invoice-external-attachment.entity.js.map +1 -0
  47. package/dist/backend/entities/invoice-line.entity.d.ts +20 -0
  48. package/dist/backend/entities/invoice-line.entity.d.ts.map +1 -0
  49. package/dist/backend/entities/invoice-line.entity.js +82 -0
  50. package/dist/backend/entities/invoice-line.entity.js.map +1 -0
  51. package/dist/backend/entities/invoice-number-counter.entity.d.ts +18 -0
  52. package/dist/backend/entities/invoice-number-counter.entity.d.ts.map +1 -0
  53. package/dist/backend/entities/invoice-number-counter.entity.js +63 -0
  54. package/dist/backend/entities/invoice-number-counter.entity.js.map +1 -0
  55. package/dist/backend/entities/invoice-template.entity.d.ts +22 -0
  56. package/dist/backend/entities/invoice-template.entity.d.ts.map +1 -0
  57. package/dist/backend/entities/invoice-template.entity.js +84 -0
  58. package/dist/backend/entities/invoice-template.entity.js.map +1 -0
  59. package/dist/backend/entities/invoice.entity.d.ts +64 -0
  60. package/dist/backend/entities/invoice.entity.d.ts.map +1 -0
  61. package/dist/backend/entities/invoice.entity.js +202 -0
  62. package/dist/backend/entities/invoice.entity.js.map +1 -0
  63. package/dist/backend/index.d.ts +111 -0
  64. package/dist/backend/index.d.ts.map +1 -0
  65. package/dist/backend/index.js +291 -0
  66. package/dist/backend/index.js.map +1 -0
  67. package/dist/backend/pdf-components/descriptor.d.ts +29 -0
  68. package/dist/backend/pdf-components/descriptor.d.ts.map +1 -0
  69. package/dist/backend/pdf-components/descriptor.js +227 -0
  70. package/dist/backend/pdf-components/descriptor.js.map +1 -0
  71. package/dist/backend/pdf-components/embed-logo-images.d.ts +35 -0
  72. package/dist/backend/pdf-components/embed-logo-images.d.ts.map +1 -0
  73. package/dist/backend/pdf-components/embed-logo-images.js +101 -0
  74. package/dist/backend/pdf-components/embed-logo-images.js.map +1 -0
  75. package/dist/backend/pdf-components/sample.d.ts +4 -0
  76. package/dist/backend/pdf-components/sample.d.ts.map +1 -0
  77. package/dist/backend/pdf-components/sample.js +75 -0
  78. package/dist/backend/pdf-components/sample.js.map +1 -0
  79. package/dist/backend/pdf-components/sections.d.ts +34 -0
  80. package/dist/backend/pdf-components/sections.d.ts.map +1 -0
  81. package/dist/backend/pdf-components/sections.js +445 -0
  82. package/dist/backend/pdf-components/sections.js.map +1 -0
  83. package/dist/backend/pdf-components/tree-mapper.d.ts +37 -0
  84. package/dist/backend/pdf-components/tree-mapper.d.ts.map +1 -0
  85. package/dist/backend/pdf-components/tree-mapper.js +76 -0
  86. package/dist/backend/pdf-components/tree-mapper.js.map +1 -0
  87. package/dist/backend/plugin.d.ts +124 -0
  88. package/dist/backend/plugin.d.ts.map +1 -0
  89. package/dist/backend/plugin.js +87 -0
  90. package/dist/backend/plugin.js.map +1 -0
  91. package/dist/backend/routes.admin.d.ts +41 -0
  92. package/dist/backend/routes.admin.d.ts.map +1 -0
  93. package/dist/backend/routes.admin.js +219 -0
  94. package/dist/backend/routes.admin.js.map +1 -0
  95. package/dist/backend/routes.customer.d.ts +33 -0
  96. package/dist/backend/routes.customer.d.ts.map +1 -0
  97. package/dist/backend/routes.customer.js +124 -0
  98. package/dist/backend/routes.customer.js.map +1 -0
  99. package/dist/backend/seeds/generic-invoice-template.d.ts +18 -0
  100. package/dist/backend/seeds/generic-invoice-template.d.ts.map +1 -0
  101. package/dist/backend/seeds/generic-invoice-template.js +174 -0
  102. package/dist/backend/seeds/generic-invoice-template.js.map +1 -0
  103. package/dist/backend/services/amount-to-words.d.ts +20 -0
  104. package/dist/backend/services/amount-to-words.d.ts.map +1 -0
  105. package/dist/backend/services/amount-to-words.js +232 -0
  106. package/dist/backend/services/amount-to-words.js.map +1 -0
  107. package/dist/backend/services/auto-issue-reactor.d.ts +53 -0
  108. package/dist/backend/services/auto-issue-reactor.d.ts.map +1 -0
  109. package/dist/backend/services/auto-issue-reactor.js +122 -0
  110. package/dist/backend/services/auto-issue-reactor.js.map +1 -0
  111. package/dist/backend/services/corrective-invoice.d.ts +38 -0
  112. package/dist/backend/services/corrective-invoice.d.ts.map +1 -0
  113. package/dist/backend/services/corrective-invoice.js +257 -0
  114. package/dist/backend/services/corrective-invoice.js.map +1 -0
  115. package/dist/backend/services/cross-module-context.d.ts +82 -0
  116. package/dist/backend/services/cross-module-context.d.ts.map +1 -0
  117. package/dist/backend/services/cross-module-context.js +93 -0
  118. package/dist/backend/services/cross-module-context.js.map +1 -0
  119. package/dist/backend/services/duplicate-number-refusal.d.ts +33 -0
  120. package/dist/backend/services/duplicate-number-refusal.d.ts.map +1 -0
  121. package/dist/backend/services/duplicate-number-refusal.js +92 -0
  122. package/dist/backend/services/duplicate-number-refusal.js.map +1 -0
  123. package/dist/backend/services/erp-sale-document-write-port.d.ts +37 -0
  124. package/dist/backend/services/erp-sale-document-write-port.d.ts.map +1 -0
  125. package/dist/backend/services/erp-sale-document-write-port.js +192 -0
  126. package/dist/backend/services/erp-sale-document-write-port.js.map +1 -0
  127. package/dist/backend/services/invoice-attachment-fetch-registry.d.ts +75 -0
  128. package/dist/backend/services/invoice-attachment-fetch-registry.d.ts.map +1 -0
  129. package/dist/backend/services/invoice-attachment-fetch-registry.js +81 -0
  130. package/dist/backend/services/invoice-attachment-fetch-registry.js.map +1 -0
  131. package/dist/backend/services/invoice-copy-host.service.d.ts +9 -0
  132. package/dist/backend/services/invoice-copy-host.service.d.ts.map +1 -0
  133. package/dist/backend/services/invoice-copy-host.service.js +52 -0
  134. package/dist/backend/services/invoice-copy-host.service.js.map +1 -0
  135. package/dist/backend/services/invoice-email-dispatch.d.ts +89 -0
  136. package/dist/backend/services/invoice-email-dispatch.d.ts.map +1 -0
  137. package/dist/backend/services/invoice-email-dispatch.js +138 -0
  138. package/dist/backend/services/invoice-email-dispatch.js.map +1 -0
  139. package/dist/backend/services/invoice-line-builder.d.ts +29 -0
  140. package/dist/backend/services/invoice-line-builder.d.ts.map +1 -0
  141. package/dist/backend/services/invoice-line-builder.js +46 -0
  142. package/dist/backend/services/invoice-line-builder.js.map +1 -0
  143. package/dist/backend/services/invoice-number-collisions.d.ts +17 -0
  144. package/dist/backend/services/invoice-number-collisions.d.ts.map +1 -0
  145. package/dist/backend/services/invoice-number-collisions.js +154 -0
  146. package/dist/backend/services/invoice-number-collisions.js.map +1 -0
  147. package/dist/backend/services/invoice-number-generator.d.ts +96 -0
  148. package/dist/backend/services/invoice-number-generator.d.ts.map +1 -0
  149. package/dist/backend/services/invoice-number-generator.js +157 -0
  150. package/dist/backend/services/invoice-number-generator.js.map +1 -0
  151. package/dist/backend/services/invoice-pdf-block-registry.d.ts +65 -0
  152. package/dist/backend/services/invoice-pdf-block-registry.d.ts.map +1 -0
  153. package/dist/backend/services/invoice-pdf-block-registry.js +94 -0
  154. package/dist/backend/services/invoice-pdf-block-registry.js.map +1 -0
  155. package/dist/backend/services/invoice-pdf-renderer.d.ts +57 -0
  156. package/dist/backend/services/invoice-pdf-renderer.d.ts.map +1 -0
  157. package/dist/backend/services/invoice-pdf-renderer.js +158 -0
  158. package/dist/backend/services/invoice-pdf-renderer.js.map +1 -0
  159. package/dist/backend/services/invoice-pdf.d.ts +24 -0
  160. package/dist/backend/services/invoice-pdf.d.ts.map +1 -0
  161. package/dist/backend/services/invoice-pdf.js +52 -0
  162. package/dist/backend/services/invoice-pdf.js.map +1 -0
  163. package/dist/backend/services/invoice-placement-apply-port.d.ts +29 -0
  164. package/dist/backend/services/invoice-placement-apply-port.d.ts.map +1 -0
  165. package/dist/backend/services/invoice-placement-apply-port.js +40 -0
  166. package/dist/backend/services/invoice-placement-apply-port.js.map +1 -0
  167. package/dist/backend/services/invoice-read-port.d.ts +44 -0
  168. package/dist/backend/services/invoice-read-port.d.ts.map +1 -0
  169. package/dist/backend/services/invoice-read-port.js +95 -0
  170. package/dist/backend/services/invoice-read-port.js.map +1 -0
  171. package/dist/backend/services/invoice-service.d.ts +94 -0
  172. package/dist/backend/services/invoice-service.d.ts.map +1 -0
  173. package/dist/backend/services/invoice-service.js +374 -0
  174. package/dist/backend/services/invoice-service.js.map +1 -0
  175. package/dist/backend/services/invoice-template-service.d.ts +43 -0
  176. package/dist/backend/services/invoice-template-service.d.ts.map +1 -0
  177. package/dist/backend/services/invoice-template-service.js +147 -0
  178. package/dist/backend/services/invoice-template-service.js.map +1 -0
  179. package/dist/backend/services/numbering-configuration.d.ts +76 -0
  180. package/dist/backend/services/numbering-configuration.d.ts.map +1 -0
  181. package/dist/backend/services/numbering-configuration.js +176 -0
  182. package/dist/backend/services/numbering-configuration.js.map +1 -0
  183. package/dist/backend/services/numbering-write-validator.d.ts +22 -0
  184. package/dist/backend/services/numbering-write-validator.d.ts.map +1 -0
  185. package/dist/backend/services/numbering-write-validator.js +82 -0
  186. package/dist/backend/services/numbering-write-validator.js.map +1 -0
  187. package/dist/backend/services/seller-settings.d.ts +24 -0
  188. package/dist/backend/services/seller-settings.d.ts.map +1 -0
  189. package/dist/backend/services/seller-settings.js +38 -0
  190. package/dist/backend/services/seller-settings.js.map +1 -0
  191. package/dist/backend/services/vendor-number-hold.d.ts +10 -0
  192. package/dist/backend/services/vendor-number-hold.d.ts.map +1 -0
  193. package/dist/backend/services/vendor-number-hold.js +14 -0
  194. package/dist/backend/services/vendor-number-hold.js.map +1 -0
  195. package/dist/manifest.d.ts +203 -0
  196. package/dist/manifest.d.ts.map +1 -0
  197. package/dist/manifest.js +390 -0
  198. package/dist/manifest.js.map +1 -0
  199. package/dist/migrations/20260629T125121_invoices_module.d.ts +17 -0
  200. package/dist/migrations/20260629T125121_invoices_module.d.ts.map +1 -0
  201. package/dist/migrations/20260629T125121_invoices_module.js +117 -0
  202. package/dist/migrations/20260629T125121_invoices_module.js.map +1 -0
  203. package/dist/migrations/20260801T111000_invoices_generic_template_reseed.d.ts +6 -0
  204. package/dist/migrations/20260801T111000_invoices_generic_template_reseed.d.ts.map +1 -0
  205. package/dist/migrations/20260801T111000_invoices_generic_template_reseed.js +25 -0
  206. package/dist/migrations/20260801T111000_invoices_generic_template_reseed.js.map +1 -0
  207. package/dist/migrations/20260817T201110_invoices_correction_idempotency_key.d.ts +20 -0
  208. package/dist/migrations/20260817T201110_invoices_correction_idempotency_key.d.ts.map +1 -0
  209. package/dist/migrations/20260817T201110_invoices_correction_idempotency_key.js +33 -0
  210. package/dist/migrations/20260817T201110_invoices_correction_idempotency_key.js.map +1 -0
  211. package/dist/migrations/20260903T101756_invoices_namespace_block_names.d.ts +6 -0
  212. package/dist/migrations/20260903T101756_invoices_namespace_block_names.d.ts.map +1 -0
  213. package/dist/migrations/20260903T101756_invoices_namespace_block_names.js +56 -0
  214. package/dist/migrations/20260903T101756_invoices_namespace_block_names.js.map +1 -0
  215. package/dist/migrations/20260914T133603_invoices_erp_imported_sale_documents.d.ts +12 -0
  216. package/dist/migrations/20260914T133603_invoices_erp_imported_sale_documents.d.ts.map +1 -0
  217. package/dist/migrations/20260914T133603_invoices_erp_imported_sale_documents.js +87 -0
  218. package/dist/migrations/20260914T133603_invoices_erp_imported_sale_documents.js.map +1 -0
  219. package/dist/migrations/20260926T230239_invoices_import_identity.d.ts +33 -0
  220. package/dist/migrations/20260926T230239_invoices_import_identity.d.ts.map +1 -0
  221. package/dist/migrations/20260926T230239_invoices_import_identity.js +83 -0
  222. package/dist/migrations/20260926T230239_invoices_import_identity.js.map +1 -0
  223. package/dist/migrations/index.d.ts +32 -0
  224. package/dist/migrations/index.d.ts.map +1 -0
  225. package/dist/migrations/index.js +39 -0
  226. package/dist/migrations/index.js.map +1 -0
  227. package/dist/ports/index.d.ts +93 -0
  228. package/dist/ports/index.d.ts.map +1 -0
  229. package/dist/ports/index.js +2 -0
  230. package/dist/ports/index.js.map +1 -0
  231. package/docs/invoices.md +113 -0
  232. package/i18n/en.json +45 -0
  233. package/i18n/pl.json +45 -0
  234. package/package.json +119 -3
  235. package/tailwind.css +14 -0
@@ -0,0 +1,117 @@
1
+ import { Migration } from '@mikro-orm/migrations';
2
+ /**
3
+ * Feature 047 — Invoices module.
4
+ *
5
+ * Extends the existing `invoices` table (created in 004_commerce_init) with the
6
+ * fields needed for real VAT invoices, and adds the supporting tables:
7
+ * - `invoice_lines` — immutable per-line snapshots
8
+ * - `invoice_number_counters` — per (channel, kind, year) gap-free sequence
9
+ * - `invoice_templates` — WYSIWYG (Puck) PDF layouts (global + per-channel)
10
+ *
11
+ * No email-log table — invoice emails reuse the `transactional_emails` module.
12
+ */
13
+ export class Migration20260629T125121InvoicesModule extends Migration {
14
+ async up() {
15
+ // --- Extend invoices ---------------------------------------------------
16
+ this.addSql(`alter table "invoices" add column "sales_channel_id" uuid null;`);
17
+ this.addSql(`alter table "invoices" add column "sale_date" date null;`);
18
+ this.addSql(`alter table "invoices" add column "payment_due_date" date null;`);
19
+ this.addSql(`alter table "invoices" add column "payment_method" varchar(64) null;`);
20
+ this.addSql(`alter table "invoices" add column "net_total" numeric(14,2) null;`);
21
+ this.addSql(`alter table "invoices" add column "tax_total" numeric(14,2) null;`);
22
+ this.addSql(`alter table "invoices" add column "paid_total" numeric(14,2) not null default 0;`);
23
+ this.addSql(`alter table "invoices" add column "original_invoice_id" uuid null;`);
24
+ this.addSql(`alter table "invoices" add column "template_id" uuid null;`);
25
+ this.addSql(`alter table "invoices" add column "seller_snapshot" jsonb null;`);
26
+ this.addSql(`alter table "invoices" add column "buyer_snapshot" jsonb null;`);
27
+ this.addSql(`alter table "invoices" add column "ksef_reference_number" varchar(128) null;`);
28
+ this.addSql(`alter table "invoices" add column "ksef_processed_at" timestamptz null;`);
29
+ this.addSql(`alter table "invoices" add column "issued_by" varchar(128) null;`);
30
+ this.addSql(`create index "invoices_sales_channel_id_index" on "invoices" ("sales_channel_id");`);
31
+ this.addSql(`create index "invoices_kind_index" on "invoices" ("kind");`);
32
+ // At most one invoice + one proforma per order; many corrections allowed.
33
+ this.addSql(`create unique index "invoices_order_kind_uq" on "invoices" ("order_id", "kind") where "kind" <> 'correction';`);
34
+ // --- invoice_lines -----------------------------------------------------
35
+ this.addSql(`
36
+ create table "invoice_lines" (
37
+ "id" uuid not null,
38
+ "invoice_id" uuid not null,
39
+ "ordinal" int not null,
40
+ "name" varchar(512) not null,
41
+ "unit" varchar(32) not null,
42
+ "quantity" numeric(12,3) not null,
43
+ "unit_net_price" numeric(14,4) not null,
44
+ "tax_rate" numeric(5,4) not null,
45
+ "net_value" numeric(14,2) not null,
46
+ "gross_value" numeric(14,2) not null,
47
+ "order_item_id" uuid null,
48
+ constraint "invoice_lines_pkey" primary key ("id")
49
+ );
50
+ `);
51
+ this.addSql(`create index "invoice_lines_invoice_idx" on "invoice_lines" ("invoice_id");`);
52
+ this.addSql(`create index "invoice_lines_invoice_ordinal_idx" on "invoice_lines" ("invoice_id", "ordinal");`);
53
+ // --- invoice_number_counters ------------------------------------------
54
+ this.addSql(`
55
+ create table "invoice_number_counters" (
56
+ "id" uuid not null,
57
+ "sales_channel_id" uuid not null,
58
+ "kind" varchar(16) not null,
59
+ "period_year" int not null,
60
+ "current_value" int not null default 0,
61
+ "created_at" timestamptz not null,
62
+ "updated_at" timestamptz not null,
63
+ constraint "invoice_number_counters_pkey" primary key ("id")
64
+ );
65
+ `);
66
+ this.addSql(`alter table "invoice_number_counters" add constraint "invoice_number_counters_scope_uq" unique ("sales_channel_id", "kind", "period_year");`);
67
+ // --- invoice_templates -------------------------------------------------
68
+ this.addSql(`
69
+ create table "invoice_templates" (
70
+ "id" uuid not null,
71
+ "code" varchar(180) not null,
72
+ "name" varchar(200) not null,
73
+ "sales_channel_id" uuid null,
74
+ "content" jsonb not null,
75
+ "languages" jsonb not null,
76
+ "active" boolean not null default true,
77
+ "is_system" boolean not null default false,
78
+ "version" int not null default 1,
79
+ "created_at" timestamptz not null,
80
+ "updated_at" timestamptz not null,
81
+ constraint "invoice_templates_pkey" primary key ("id")
82
+ );
83
+ `);
84
+ this.addSql(`create index "invoice_templates_code_idx" on "invoice_templates" ("code");`);
85
+ this.addSql(`create index "invoice_templates_sales_channel_idx" on "invoice_templates" ("sales_channel_id");`);
86
+ // One active template per channel (global = the all-zero coalesce key).
87
+ this.addSql(`create unique index "invoice_templates_active_scope_uq" on "invoice_templates" ` +
88
+ `(coalesce("sales_channel_id", '00000000-0000-0000-0000-000000000000')) where "active";`);
89
+ }
90
+ async down() {
91
+ this.addSql(`drop table if exists "invoice_templates";`);
92
+ this.addSql(`drop table if exists "invoice_number_counters";`);
93
+ this.addSql(`drop table if exists "invoice_lines";`);
94
+ this.addSql(`drop index if exists "invoices_order_kind_uq";`);
95
+ this.addSql(`drop index if exists "invoices_kind_index";`);
96
+ this.addSql(`drop index if exists "invoices_sales_channel_id_index";`);
97
+ for (const col of [
98
+ 'issued_by',
99
+ 'ksef_processed_at',
100
+ 'ksef_reference_number',
101
+ 'buyer_snapshot',
102
+ 'seller_snapshot',
103
+ 'template_id',
104
+ 'original_invoice_id',
105
+ 'paid_total',
106
+ 'tax_total',
107
+ 'net_total',
108
+ 'payment_method',
109
+ 'payment_due_date',
110
+ 'sale_date',
111
+ 'sales_channel_id',
112
+ ]) {
113
+ this.addSql(`alter table "invoices" drop column if exists "${col}";`);
114
+ }
115
+ }
116
+ }
117
+ //# sourceMappingURL=20260629T125121_invoices_module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20260629T125121_invoices_module.js","sourceRoot":"","sources":["../../src/migrations/20260629T125121_invoices_module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD;;;;;;;;;;GAUG;AACH,MAAM,OAAO,sCAAuC,SAAQ,SAAS;IAC1D,KAAK,CAAC,EAAE;QACf,0EAA0E;QAC1E,IAAI,CAAC,MAAM,CAAC,iEAAiE,CAAC,CAAC;QAC/E,IAAI,CAAC,MAAM,CAAC,0DAA0D,CAAC,CAAC;QACxE,IAAI,CAAC,MAAM,CAAC,iEAAiE,CAAC,CAAC;QAC/E,IAAI,CAAC,MAAM,CAAC,sEAAsE,CAAC,CAAC;QACpF,IAAI,CAAC,MAAM,CAAC,mEAAmE,CAAC,CAAC;QACjF,IAAI,CAAC,MAAM,CAAC,mEAAmE,CAAC,CAAC;QACjF,IAAI,CAAC,MAAM,CAAC,kFAAkF,CAAC,CAAC;QAChG,IAAI,CAAC,MAAM,CAAC,oEAAoE,CAAC,CAAC;QAClF,IAAI,CAAC,MAAM,CAAC,4DAA4D,CAAC,CAAC;QAC1E,IAAI,CAAC,MAAM,CAAC,iEAAiE,CAAC,CAAC;QAC/E,IAAI,CAAC,MAAM,CAAC,gEAAgE,CAAC,CAAC;QAC9E,IAAI,CAAC,MAAM,CAAC,8EAA8E,CAAC,CAAC;QAC5F,IAAI,CAAC,MAAM,CAAC,yEAAyE,CAAC,CAAC;QACvF,IAAI,CAAC,MAAM,CAAC,kEAAkE,CAAC,CAAC;QAChF,IAAI,CAAC,MAAM,CAAC,oFAAoF,CAAC,CAAC;QAClG,IAAI,CAAC,MAAM,CAAC,4DAA4D,CAAC,CAAC;QAC1E,0EAA0E;QAC1E,IAAI,CAAC,MAAM,CACT,+GAA+G,CAChH,CAAC;QAEF,0EAA0E;QAC1E,IAAI,CAAC,MAAM,CAAC;;;;;;;;;;;;;;;KAeX,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,6EAA6E,CAAC,CAAC;QAC3F,IAAI,CAAC,MAAM,CACT,gGAAgG,CACjG,CAAC;QAEF,yEAAyE;QACzE,IAAI,CAAC,MAAM,CAAC;;;;;;;;;;;KAWX,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CACT,6IAA6I,CAC9I,CAAC;QAEF,0EAA0E;QAC1E,IAAI,CAAC,MAAM,CAAC;;;;;;;;;;;;;;;KAeX,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,4EAA4E,CAAC,CAAC;QAC1F,IAAI,CAAC,MAAM,CACT,iGAAiG,CAClG,CAAC;QACF,wEAAwE;QACxE,IAAI,CAAC,MAAM,CACT,iFAAiF;YAC/E,wFAAwF,CAC3F,CAAC;IACJ,CAAC;IAEQ,KAAK,CAAC,IAAI;QACjB,IAAI,CAAC,MAAM,CAAC,2CAA2C,CAAC,CAAC;QACzD,IAAI,CAAC,MAAM,CAAC,iDAAiD,CAAC,CAAC;QAC/D,IAAI,CAAC,MAAM,CAAC,uCAAuC,CAAC,CAAC;QACrD,IAAI,CAAC,MAAM,CAAC,gDAAgD,CAAC,CAAC;QAC9D,IAAI,CAAC,MAAM,CAAC,6CAA6C,CAAC,CAAC;QAC3D,IAAI,CAAC,MAAM,CAAC,yDAAyD,CAAC,CAAC;QACvE,KAAK,MAAM,GAAG,IAAI;YAChB,WAAW;YACX,mBAAmB;YACnB,uBAAuB;YACvB,gBAAgB;YAChB,iBAAiB;YACjB,aAAa;YACb,qBAAqB;YACrB,YAAY;YACZ,WAAW;YACX,WAAW;YACX,gBAAgB;YAChB,kBAAkB;YAClB,WAAW;YACX,kBAAkB;SACnB,EAAE,CAAC;YACF,IAAI,CAAC,MAAM,CAAC,iDAAiD,GAAG,IAAI,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ import { Migration } from '@mikro-orm/migrations';
2
+ export declare class Migration20260801T111000InvoicesGenericTemplateReseed extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
6
+ //# sourceMappingURL=20260801T111000_invoices_generic_template_reseed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20260801T111000_invoices_generic_template_reseed.d.ts","sourceRoot":"","sources":["../../src/migrations/20260801T111000_invoices_generic_template_reseed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAelD,qBAAa,qDAAsD,SAAQ,SAAS;IACnE,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IAanB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAGrC"}
@@ -0,0 +1,25 @@
1
+ import { Migration } from '@mikro-orm/migrations';
2
+ import { GENERIC_INVOICE_TEMPLATE_CODE, GENERIC_INVOICE_TEMPLATE_CONTENT, GENERIC_INVOICE_TEMPLATE_LANGUAGES, } from '../backend/seeds/generic-invoice-template.js';
3
+ /**
4
+ * Reseed the system `generic` invoice template with the current Puck tree
5
+ * (full defaultProps for sidebar radios/selects + English sample footer).
6
+ */
7
+ function jsonbLiteral(value) {
8
+ return JSON.stringify(value).replace(/'/g, "''");
9
+ }
10
+ export class Migration20260801T111000InvoicesGenericTemplateReseed extends Migration {
11
+ async up() {
12
+ const contentJson = jsonbLiteral(GENERIC_INVOICE_TEMPLATE_CONTENT);
13
+ const languagesJson = jsonbLiteral(GENERIC_INVOICE_TEMPLATE_LANGUAGES);
14
+ this.addSql(`update "invoice_templates" ` +
15
+ `set "content" = '${contentJson}'::jsonb, ` +
16
+ `"languages" = '${languagesJson}'::jsonb, ` +
17
+ `"version" = "version" + 1, ` +
18
+ `"updated_at" = now() ` +
19
+ `where "code" = '${GENERIC_INVOICE_TEMPLATE_CODE}' and "is_system" = true;`);
20
+ }
21
+ async down() {
22
+ // Prior tree cannot be restored; leave the reseeded content in place.
23
+ }
24
+ }
25
+ //# sourceMappingURL=20260801T111000_invoices_generic_template_reseed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20260801T111000_invoices_generic_template_reseed.js","sourceRoot":"","sources":["../../src/migrations/20260801T111000_invoices_generic_template_reseed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EACL,6BAA6B,EAC7B,gCAAgC,EAChC,kCAAkC,GACnC,MAAM,8CAA8C,CAAC;AAEtD;;;GAGG;AACH,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,OAAO,qDAAsD,SAAQ,SAAS;IACzE,KAAK,CAAC,EAAE;QACf,MAAM,WAAW,GAAG,YAAY,CAAC,gCAAgC,CAAC,CAAC;QACnE,MAAM,aAAa,GAAG,YAAY,CAAC,kCAAkC,CAAC,CAAC;QACvE,IAAI,CAAC,MAAM,CACT,6BAA6B;YAC3B,oBAAoB,WAAW,YAAY;YAC3C,kBAAkB,aAAa,YAAY;YAC3C,6BAA6B;YAC7B,uBAAuB;YACvB,mBAAmB,6BAA6B,2BAA2B,CAC9E,CAAC;IACJ,CAAC;IAEQ,KAAK,CAAC,IAAI;QACjB,sEAAsE;IACxE,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ import { Migration } from '@mikro-orm/migrations';
2
+ /**
3
+ * `invoices.correction_idempotency_key` — one correction per return case (D-91).
4
+ *
5
+ * The settlement ordering law attempts every external effect before it writes
6
+ * any state, so a refusal from a later step leaves a retryable case and the
7
+ * retry asks `invoices` for the same correction again. The key is the return
8
+ * case id: a second partial return against the same order is a different case
9
+ * and still gets its own document.
10
+ *
11
+ * Nullable, because every correction issued before this migration has no key
12
+ * and manual corrections have none either. The unique index is therefore
13
+ * partial — `where "correction_idempotency_key" is not null` — so the absence
14
+ * is not a value two rows can collide on.
15
+ */
16
+ export declare class Migration20260817T201110InvoicesCorrectionIdempotencyKey extends Migration {
17
+ up(): Promise<void>;
18
+ down(): Promise<void>;
19
+ }
20
+ //# sourceMappingURL=20260817T201110_invoices_correction_idempotency_key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20260817T201110_invoices_correction_idempotency_key.d.ts","sourceRoot":"","sources":["../../src/migrations/20260817T201110_invoices_correction_idempotency_key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD;;;;;;;;;;;;;GAaG;AACH,qBAAa,wDAAyD,SAAQ,SAAS;IACtE,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IAYnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAIrC"}
@@ -0,0 +1,33 @@
1
+ import { Migration } from '@mikro-orm/migrations';
2
+ /**
3
+ * `invoices.correction_idempotency_key` — one correction per return case (D-91).
4
+ *
5
+ * The settlement ordering law attempts every external effect before it writes
6
+ * any state, so a refusal from a later step leaves a retryable case and the
7
+ * retry asks `invoices` for the same correction again. The key is the return
8
+ * case id: a second partial return against the same order is a different case
9
+ * and still gets its own document.
10
+ *
11
+ * Nullable, because every correction issued before this migration has no key
12
+ * and manual corrections have none either. The unique index is therefore
13
+ * partial — `where "correction_idempotency_key" is not null` — so the absence
14
+ * is not a value two rows can collide on.
15
+ */
16
+ export class Migration20260817T201110InvoicesCorrectionIdempotencyKey extends Migration {
17
+ async up() {
18
+ this.addSql(`
19
+ alter table "invoices"
20
+ add column "correction_idempotency_key" varchar(64) null;
21
+ `);
22
+ this.addSql(`
23
+ create unique index "invoices_correction_idempotency_key_unique"
24
+ on "invoices" ("correction_idempotency_key")
25
+ where "correction_idempotency_key" is not null;
26
+ `);
27
+ }
28
+ async down() {
29
+ this.addSql(`drop index if exists "invoices_correction_idempotency_key_unique";`);
30
+ this.addSql(`alter table "invoices" drop column if exists "correction_idempotency_key";`);
31
+ }
32
+ }
33
+ //# sourceMappingURL=20260817T201110_invoices_correction_idempotency_key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20260817T201110_invoices_correction_idempotency_key.js","sourceRoot":"","sources":["../../src/migrations/20260817T201110_invoices_correction_idempotency_key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,wDAAyD,SAAQ,SAAS;IAC5E,KAAK,CAAC,EAAE;QACf,IAAI,CAAC,MAAM,CAAC;;;KAGX,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC;;;;KAIX,CAAC,CAAC;IACL,CAAC;IAEQ,KAAK,CAAC,IAAI;QACjB,IAAI,CAAC,MAAM,CAAC,oEAAoE,CAAC,CAAC;QAClF,IAAI,CAAC,MAAM,CAAC,4EAA4E,CAAC,CAAC;IAC5F,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ import { Migration } from '@mikro-orm/migrations';
2
+ export declare class Migration20260903T101756InvoicesNamespaceBlockNames extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
6
+ //# sourceMappingURL=20260903T101756_invoices_namespace_block_names.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20260903T101756_invoices_namespace_block_names.d.ts","sourceRoot":"","sources":["../../src/migrations/20260903T101756_invoices_namespace_block_names.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAmDlD,qBAAa,mDAAoD,SAAQ,SAAS;IACjE,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IAMnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAKrC"}
@@ -0,0 +1,56 @@
1
+ import { Migration } from '@mikro-orm/migrations';
2
+ import { FROZEN_BLOCK_RENAMES, FROZEN_BLOCK_RENAMES_INVERSE, applyRenameFunctionSql, createRenameFunctionSql, dropRenameFunctionSql, } from '@endora-commerce/page-builder-core/migration';
3
+ /**
4
+ * Namespace the Page Builder block names stored in `invoices`'s 1 `jsonb` column
5
+ * — feature 096, T408 (`contracts/block-name-migration.md`).
6
+ *
7
+ * **The rewrite is structural, never textual.** Twelve of the 74 renamed names
8
+ * are ordinary English words that occur throughout shop content — `Row`,
9
+ * `Text`, `Image`, `Map`, `Button` among them — so a text substitution over the
10
+ * column would corrupt a `RawHtml` block's markup and every `alt` attribute in
11
+ * the shop. `pg_temp.rename_block_names_invoices` descends the document and replaces the value of a
12
+ * `type` property in a **node** position and nothing else; the walk is
13
+ * generated from `FROZEN_BLOCK_RENAMES` by
14
+ * `@endora-commerce/page-builder-core/migration`, so five migrations share one
15
+ * definition of what a node is.
16
+ *
17
+ * **This migration belongs to `invoices` because `invoices` owns these tables**,
18
+ * not because it owns the new names (`contracts/block-name-migration.md` §2).
19
+ * Some of the names it writes belong to other modules; that creates no
20
+ * obligation on them and **no new manifest `dependencies` edge**, because a
21
+ * block name is a string value inside a JSONB document — not a foreign key and
22
+ * not a table identifier.
23
+ *
24
+ * **It cannot fail on its input.** A name the map does not hold is left
25
+ * byte-identical: an already-namespaced one and an unrecognised one alike,
26
+ * because the map's domain is bare and its codomain is dotted, so the two sets
27
+ * are disjoint. That is also what makes a second run rewrite nothing — FR-013
28
+ * is a property of the map rather than an outcome a branch has to remember to
29
+ * produce, and no dot test appears in this SQL.
30
+ *
31
+ * `down()` applies the inverse over the identical walk and is **exact for the
32
+ * frozen set**. It is partial by construction: a name with no pre-migration
33
+ * form — a block authored after the upgrade, a third party's `acme.Banner` —
34
+ * has nothing to return to and is left alone. That is correct, and it is why
35
+ * the operator pre-flight (§6) is a backup rather than a `down()`.
36
+ */
37
+ /**
38
+ * Named per module: the five rename migrations may run on one pooled session,
39
+ * and a second `create function` over the same name fails. Each drops its own
40
+ * when it is done, and a rollback removes it with everything else — `pg_temp`
41
+ * DDL is transactional.
42
+ */
43
+ const FN = 'rename_block_names_invoices';
44
+ export class Migration20260903T101756InvoicesNamespaceBlockNames extends Migration {
45
+ async up() {
46
+ this.addSql(createRenameFunctionSql(FN, FROZEN_BLOCK_RENAMES));
47
+ this.addSql(applyRenameFunctionSql(FN, 'invoice_templates', 'content'));
48
+ this.addSql(dropRenameFunctionSql(FN));
49
+ }
50
+ async down() {
51
+ this.addSql(createRenameFunctionSql(FN, FROZEN_BLOCK_RENAMES_INVERSE));
52
+ this.addSql(applyRenameFunctionSql(FN, 'invoice_templates', 'content'));
53
+ this.addSql(dropRenameFunctionSql(FN));
54
+ }
55
+ }
56
+ //# sourceMappingURL=20260903T101756_invoices_namespace_block_names.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20260903T101756_invoices_namespace_block_names.js","sourceRoot":"","sources":["../../src/migrations/20260903T101756_invoices_namespace_block_names.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EACL,oBAAoB,EACpB,4BAA4B,EAC5B,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,8CAA8C,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH;;;;;GAKG;AACH,MAAM,EAAE,GAAG,6BAA6B,CAAC;AAEzC,MAAM,OAAO,mDAAoD,SAAQ,SAAS;IACvE,KAAK,CAAC,EAAE;QACf,IAAI,CAAC,MAAM,CAAC,uBAAuB,CAAC,EAAE,EAAE,oBAAoB,CAAC,CAAC,CAAC;QAC/D,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,EAAE,EAAE,mBAAmB,EAAE,SAAS,CAAC,CAAC,CAAC;QACxE,IAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC,EAAE,CAAC,CAAC,CAAC;IACzC,CAAC;IAEQ,KAAK,CAAC,IAAI;QACjB,IAAI,CAAC,MAAM,CAAC,uBAAuB,CAAC,EAAE,EAAE,4BAA4B,CAAC,CAAC,CAAC;QACvE,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,EAAE,EAAE,mBAAmB,EAAE,SAAS,CAAC,CAAC,CAAC;QACxE,IAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC,EAAE,CAAC,CAAC,CAAC;IACzC,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ import { Migration } from '@mikro-orm/migrations';
2
+ /**
3
+ * Feature 119, Phase 14a — ERP-imported sale documents (FR-087/FR-088).
4
+ *
5
+ * Extends `invoices` with origin/organization/external-ref columns and adds
6
+ * `invoice_external_attachments` for lazy-fetched XL attachment metadata.
7
+ */
8
+ export declare class Migration20260914T133603InvoicesErpImportedSaleDocuments extends Migration {
9
+ up(): Promise<void>;
10
+ down(): Promise<void>;
11
+ }
12
+ //# sourceMappingURL=20260914T133603_invoices_erp_imported_sale_documents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20260914T133603_invoices_erp_imported_sale_documents.d.ts","sourceRoot":"","sources":["../../src/migrations/20260914T133603_invoices_erp_imported_sale_documents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD;;;;;GAKG;AACH,qBAAa,wDAAyD,SAAQ,SAAS;IACtE,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IA6EnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAerC"}
@@ -0,0 +1,87 @@
1
+ import { Migration } from '@mikro-orm/migrations';
2
+ /**
3
+ * Feature 119, Phase 14a — ERP-imported sale documents (FR-087/FR-088).
4
+ *
5
+ * Extends `invoices` with origin/organization/external-ref columns and adds
6
+ * `invoice_external_attachments` for lazy-fetched XL attachment metadata.
7
+ */
8
+ export class Migration20260914T133603InvoicesErpImportedSaleDocuments extends Migration {
9
+ async up() {
10
+ this.addSql(`alter table "invoices" alter column "order_id" drop not null;`);
11
+ this.addSql(`alter table "invoices" add column "origin" varchar(16) not null default 'platform';`);
12
+ this.addSql(`alter table "invoices" add column "organization_id" uuid null;`);
13
+ this.addSql(`alter table "invoices" add column "external_document_ref" jsonb null;`);
14
+ this.addSql(`create index "invoices_origin_index" on "invoices" ("origin");`);
15
+ this.addSql(`create index "invoices_organization_id_index" on "invoices" ("organization_id");`);
16
+ this.addSql(`
17
+ alter table "invoices"
18
+ add constraint "invoices_organization_id_foreign"
19
+ foreign key ("organization_id") references "organizations" ("id")
20
+ on update cascade on delete restrict;
21
+ `);
22
+ this.addSql(`
23
+ alter table "invoices"
24
+ add constraint "invoices_origin_platform_order_chk"
25
+ check (origin <> 'platform' or "order_id" is not null);
26
+ `);
27
+ this.addSql(`
28
+ alter table "invoices"
29
+ add constraint "invoices_origin_erp_import_org_chk"
30
+ check (
31
+ origin <> 'erp_import'
32
+ or ("organization_id" is not null and "external_document_ref" is not null)
33
+ );
34
+ `);
35
+ this.addSql(`
36
+ create unique index "invoices_external_xl_sale_document_uq"
37
+ on "invoices" ((external_document_ref->>'xlSaleDocumentId'))
38
+ where origin = 'erp_import';
39
+ `);
40
+ this.addSql(`
41
+ create table "invoice_external_attachments" (
42
+ "id" uuid not null,
43
+ "invoice_id" uuid not null,
44
+ "xl_attachment_id" varchar(128) not null,
45
+ "file_name" varchar(256) not null,
46
+ "content_type" varchar(128) null,
47
+ "asset_id" uuid null,
48
+ "downloaded_at" timestamptz null,
49
+ "created_at" timestamptz not null,
50
+ "updated_at" timestamptz not null,
51
+ constraint "invoice_external_attachments_pkey" primary key ("id")
52
+ );
53
+ `);
54
+ this.addSql(`create index "invoice_external_attachments_invoice_idx" on "invoice_external_attachments" ("invoice_id");`);
55
+ this.addSql(`
56
+ alter table "invoice_external_attachments"
57
+ add constraint "invoice_external_attachments_invoice_id_foreign"
58
+ foreign key ("invoice_id") references "invoices" ("id")
59
+ on update cascade on delete cascade;
60
+ `);
61
+ this.addSql(`
62
+ alter table "invoice_external_attachments"
63
+ add constraint "invoice_external_attachments_asset_id_foreign"
64
+ foreign key ("asset_id") references "assets" ("id")
65
+ on update cascade on delete set null;
66
+ `);
67
+ this.addSql(`
68
+ alter table "invoice_external_attachments"
69
+ add constraint "invoice_external_attachments_invoice_xl_uq"
70
+ unique ("invoice_id", "xl_attachment_id");
71
+ `);
72
+ }
73
+ async down() {
74
+ this.addSql(`drop table if exists "invoice_external_attachments" cascade;`);
75
+ this.addSql(`drop index if exists "invoices_external_xl_sale_document_uq";`);
76
+ this.addSql(`alter table "invoices" drop constraint if exists "invoices_origin_erp_import_org_chk";`);
77
+ this.addSql(`alter table "invoices" drop constraint if exists "invoices_origin_platform_order_chk";`);
78
+ this.addSql(`alter table "invoices" drop constraint if exists "invoices_organization_id_foreign";`);
79
+ this.addSql(`drop index if exists "invoices_organization_id_index";`);
80
+ this.addSql(`drop index if exists "invoices_origin_index";`);
81
+ this.addSql(`alter table "invoices" drop column if exists "external_document_ref";`);
82
+ this.addSql(`alter table "invoices" drop column if exists "organization_id";`);
83
+ this.addSql(`alter table "invoices" drop column if exists "origin";`);
84
+ this.addSql(`alter table "invoices" alter column "order_id" set not null;`);
85
+ }
86
+ }
87
+ //# sourceMappingURL=20260914T133603_invoices_erp_imported_sale_documents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20260914T133603_invoices_erp_imported_sale_documents.js","sourceRoot":"","sources":["../../src/migrations/20260914T133603_invoices_erp_imported_sale_documents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD;;;;;GAKG;AACH,MAAM,OAAO,wDAAyD,SAAQ,SAAS;IAC5E,KAAK,CAAC,EAAE;QACf,IAAI,CAAC,MAAM,CAAC,+DAA+D,CAAC,CAAC;QAE7E,IAAI,CAAC,MAAM,CACT,qFAAqF,CACtF,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,gEAAgE,CAAC,CAAC;QAC9E,IAAI,CAAC,MAAM,CAAC,uEAAuE,CAAC,CAAC;QAErF,IAAI,CAAC,MAAM,CAAC,gEAAgE,CAAC,CAAC;QAC9E,IAAI,CAAC,MAAM,CACT,kFAAkF,CACnF,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC;;;;;KAKX,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC;;;;KAIX,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC;;;;;;;KAOX,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC;;;;KAIX,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC;;;;;;;;;;;;;KAaX,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CACT,2GAA2G,CAC5G,CAAC;QACF,IAAI,CAAC,MAAM,CAAC;;;;;KAKX,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC;;;;;KAKX,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC;;;;KAIX,CAAC,CAAC;IACL,CAAC;IAEQ,KAAK,CAAC,IAAI;QACjB,IAAI,CAAC,MAAM,CAAC,8DAA8D,CAAC,CAAC;QAE5E,IAAI,CAAC,MAAM,CAAC,+DAA+D,CAAC,CAAC;QAC7E,IAAI,CAAC,MAAM,CAAC,wFAAwF,CAAC,CAAC;QACtG,IAAI,CAAC,MAAM,CAAC,wFAAwF,CAAC,CAAC;QACtG,IAAI,CAAC,MAAM,CAAC,sFAAsF,CAAC,CAAC;QACpG,IAAI,CAAC,MAAM,CAAC,wDAAwD,CAAC,CAAC;QACtE,IAAI,CAAC,MAAM,CAAC,+CAA+C,CAAC,CAAC;QAC7D,IAAI,CAAC,MAAM,CAAC,uEAAuE,CAAC,CAAC;QACrF,IAAI,CAAC,MAAM,CAAC,iEAAiE,CAAC,CAAC;QAC/E,IAAI,CAAC,MAAM,CAAC,wDAAwD,CAAC,CAAC;QAEtE,IAAI,CAAC,MAAM,CAAC,8DAA8D,CAAC,CAAC;IAC9E,CAAC;CACF"}
@@ -0,0 +1,33 @@
1
+ import { Migration } from '@mikro-orm/migrations';
2
+ /**
3
+ * Feature 134, T135 — an imported invoice is identified by its source system
4
+ * and its id there (`specs/134-paid-module-extraction/research.md` D21 §3).
5
+ *
6
+ * Until now an `erp_import` row was unique on
7
+ * `external_document_ref->>'xlSaleDocumentId'` alone, a key named after the one
8
+ * connector that wrote it. A second source system's ids come from an unrelated
9
+ * id space, so the same string from another system would have reached — and
10
+ * overwritten — the first system's document. This migration:
11
+ *
12
+ * 1. drops the id-only unique index;
13
+ * 2. renames the persisted JSONB keys `xlSaleDocumentId` → `externalId` and
14
+ * `xlDocumentNumber` → `externalNumber` (an absent number stays absent);
15
+ * 3. renames `invoice_external_attachments.xl_attachment_id` →
16
+ * `external_attachment_id`, and its unique constraint with it;
17
+ * 4. adds `invoices_erp_import_identity_chk`, so a missing key cannot fall
18
+ * through the unique index as a NULL;
19
+ * 5. creates `invoices_external_document_uq` on the pair.
20
+ *
21
+ * Every row written before this migration carries `system = 'comarch_xl'`,
22
+ * so a set unique on the id alone is unique on the pair and step 5 cannot fail
23
+ * on existing data.
24
+ *
25
+ * `down()` reverses each step, and it is valid **only while a single source
26
+ * system has written**. Once two systems share an id, recreating the id-only
27
+ * index fails, and it should: that index would merge two documents.
28
+ */
29
+ export declare class Migration20260926T230239InvoicesImportIdentity extends Migration {
30
+ up(): Promise<void>;
31
+ down(): Promise<void>;
32
+ }
33
+ //# sourceMappingURL=20260926T230239_invoices_import_identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20260926T230239_invoices_import_identity.d.ts","sourceRoot":"","sources":["../../src/migrations/20260926T230239_invoices_import_identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,8CAA+C,SAAQ,SAAS;IAC5D,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IAwCnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CA8BrC"}
@@ -0,0 +1,83 @@
1
+ import { Migration } from '@mikro-orm/migrations';
2
+ /**
3
+ * Feature 134, T135 — an imported invoice is identified by its source system
4
+ * and its id there (`specs/134-paid-module-extraction/research.md` D21 §3).
5
+ *
6
+ * Until now an `erp_import` row was unique on
7
+ * `external_document_ref->>'xlSaleDocumentId'` alone, a key named after the one
8
+ * connector that wrote it. A second source system's ids come from an unrelated
9
+ * id space, so the same string from another system would have reached — and
10
+ * overwritten — the first system's document. This migration:
11
+ *
12
+ * 1. drops the id-only unique index;
13
+ * 2. renames the persisted JSONB keys `xlSaleDocumentId` → `externalId` and
14
+ * `xlDocumentNumber` → `externalNumber` (an absent number stays absent);
15
+ * 3. renames `invoice_external_attachments.xl_attachment_id` →
16
+ * `external_attachment_id`, and its unique constraint with it;
17
+ * 4. adds `invoices_erp_import_identity_chk`, so a missing key cannot fall
18
+ * through the unique index as a NULL;
19
+ * 5. creates `invoices_external_document_uq` on the pair.
20
+ *
21
+ * Every row written before this migration carries `system = 'comarch_xl'`,
22
+ * so a set unique on the id alone is unique on the pair and step 5 cannot fail
23
+ * on existing data.
24
+ *
25
+ * `down()` reverses each step, and it is valid **only while a single source
26
+ * system has written**. Once two systems share an id, recreating the id-only
27
+ * index fails, and it should: that index would merge two documents.
28
+ */
29
+ export class Migration20260926T230239InvoicesImportIdentity extends Migration {
30
+ async up() {
31
+ this.addSql(`drop index if exists "invoices_external_xl_sale_document_uq";`);
32
+ this.addSql(`
33
+ update "invoices"
34
+ set "external_document_ref" =
35
+ ("external_document_ref" - 'xlSaleDocumentId' - 'xlDocumentNumber')
36
+ || jsonb_strip_nulls(jsonb_build_object(
37
+ 'externalId', "external_document_ref"->'xlSaleDocumentId',
38
+ 'externalNumber', "external_document_ref"->'xlDocumentNumber'
39
+ ))
40
+ where "external_document_ref"->'xlSaleDocumentId' is not null;
41
+ `);
42
+ this.addSql(`alter table "invoice_external_attachments" rename column "xl_attachment_id" to "external_attachment_id";`);
43
+ this.addSql(`alter table "invoice_external_attachments" rename constraint "invoice_external_attachments_invoice_xl_uq" to "invoice_external_attachments_invoice_external_uq";`);
44
+ this.addSql(`
45
+ alter table "invoices"
46
+ add constraint "invoices_erp_import_identity_chk"
47
+ check (
48
+ origin <> 'erp_import'
49
+ or (
50
+ coalesce("external_document_ref"->>'system', '') <> ''
51
+ and coalesce("external_document_ref"->>'externalId', '') <> ''
52
+ )
53
+ );
54
+ `);
55
+ this.addSql(`
56
+ create unique index "invoices_external_document_uq"
57
+ on "invoices" ((external_document_ref->>'system'), (external_document_ref->>'externalId'))
58
+ where origin = 'erp_import';
59
+ `);
60
+ }
61
+ async down() {
62
+ this.addSql(`drop index if exists "invoices_external_document_uq";`);
63
+ this.addSql(`alter table "invoices" drop constraint if exists "invoices_erp_import_identity_chk";`);
64
+ this.addSql(`alter table "invoice_external_attachments" rename constraint "invoice_external_attachments_invoice_external_uq" to "invoice_external_attachments_invoice_xl_uq";`);
65
+ this.addSql(`alter table "invoice_external_attachments" rename column "external_attachment_id" to "xl_attachment_id";`);
66
+ this.addSql(`
67
+ update "invoices"
68
+ set "external_document_ref" =
69
+ ("external_document_ref" - 'externalId' - 'externalNumber')
70
+ || jsonb_strip_nulls(jsonb_build_object(
71
+ 'xlSaleDocumentId', "external_document_ref"->'externalId',
72
+ 'xlDocumentNumber', "external_document_ref"->'externalNumber'
73
+ ))
74
+ where "external_document_ref"->'externalId' is not null;
75
+ `);
76
+ this.addSql(`
77
+ create unique index "invoices_external_xl_sale_document_uq"
78
+ on "invoices" ((external_document_ref->>'xlSaleDocumentId'))
79
+ where origin = 'erp_import';
80
+ `);
81
+ }
82
+ }
83
+ //# sourceMappingURL=20260926T230239_invoices_import_identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20260926T230239_invoices_import_identity.js","sourceRoot":"","sources":["../../src/migrations/20260926T230239_invoices_import_identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,8CAA+C,SAAQ,SAAS;IAClE,KAAK,CAAC,EAAE;QACf,IAAI,CAAC,MAAM,CAAC,+DAA+D,CAAC,CAAC;QAE7E,IAAI,CAAC,MAAM,CAAC;;;;;;;;;KASX,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CACT,0GAA0G,CAC3G,CAAC;QACF,IAAI,CAAC,MAAM,CACT,kKAAkK,CACnK,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC;;;;;;;;;;KAUX,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC;;;;KAIX,CAAC,CAAC;IACL,CAAC;IAEQ,KAAK,CAAC,IAAI;QACjB,IAAI,CAAC,MAAM,CAAC,uDAAuD,CAAC,CAAC;QACrE,IAAI,CAAC,MAAM,CACT,sFAAsF,CACvF,CAAC;QAEF,IAAI,CAAC,MAAM,CACT,kKAAkK,CACnK,CAAC;QACF,IAAI,CAAC,MAAM,CACT,0GAA0G,CAC3G,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC;;;;;;;;;KASX,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC;;;;KAIX,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The `./migrations` subpath — every migration class this module owns, as one
3
+ * ordered `migrations` array.
4
+ *
5
+ * The array is what the platform reads when this module is **installed**:
6
+ * `src/packages/package-runtime.ts` takes `exported['migrations']` and refuses
7
+ * the package outright when it is absent (D-168).
8
+ *
9
+ * Listed in ascending timestamp, which is the order of this module's own
10
+ * migrations and of nothing else (feature 081): a manifest `dependencies` array
11
+ * is the only thing ordering this block against another module's.
12
+ *
13
+ * The **named** exports stay beside the array, and the asymmetry with
14
+ * `./backend` — which publishes an array and no named class (D-168) — is
15
+ * deliberate. `db/migrations-registry.generated.ts` imports each class by name
16
+ * from this specifier, and a migration class name is contract in a way an entity
17
+ * class name is not: `mikro_orm_migrations` persists it, so it is a string every
18
+ * already-migrated database holds.
19
+ *
20
+ * A class that is in neither the array nor the barrel is a migration that does
21
+ * not run: `migration:pending` reports nothing pending and the first symptom is
22
+ * a query against a table nobody created.
23
+ */
24
+ import { Migration20260629T125121InvoicesModule } from './20260629T125121_invoices_module.js';
25
+ import { Migration20260801T111000InvoicesGenericTemplateReseed } from './20260801T111000_invoices_generic_template_reseed.js';
26
+ import { Migration20260817T201110InvoicesCorrectionIdempotencyKey } from './20260817T201110_invoices_correction_idempotency_key.js';
27
+ import { Migration20260903T101756InvoicesNamespaceBlockNames } from './20260903T101756_invoices_namespace_block_names.js';
28
+ import { Migration20260914T133603InvoicesErpImportedSaleDocuments } from './20260914T133603_invoices_erp_imported_sale_documents.js';
29
+ import { Migration20260926T230239InvoicesImportIdentity } from './20260926T230239_invoices_import_identity.js';
30
+ export declare const migrations: (typeof Migration20260629T125121InvoicesModule)[];
31
+ export { Migration20260629T125121InvoicesModule, Migration20260801T111000InvoicesGenericTemplateReseed, Migration20260817T201110InvoicesCorrectionIdempotencyKey, Migration20260903T101756InvoicesNamespaceBlockNames, Migration20260914T133603InvoicesErpImportedSaleDocuments, Migration20260926T230239InvoicesImportIdentity, };
32
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,sCAAsC,EAAE,MAAM,sCAAsC,CAAC;AAC9F,OAAO,EAAE,qDAAqD,EAAE,MAAM,uDAAuD,CAAC;AAC9H,OAAO,EAAE,wDAAwD,EAAE,MAAM,0DAA0D,CAAC;AACpI,OAAO,EAAE,mDAAmD,EAAE,MAAM,qDAAqD,CAAC;AAC1H,OAAO,EAAE,wDAAwD,EAAE,MAAM,2DAA2D,CAAC;AACrI,OAAO,EAAE,8CAA8C,EAAE,MAAM,+CAA+C,CAAC;AAE/G,eAAO,MAAM,UAAU,mDAOtB,CAAC;AAEF,OAAO,EACL,sCAAsC,EACtC,qDAAqD,EACrD,wDAAwD,EACxD,mDAAmD,EACnD,wDAAwD,EACxD,8CAA8C,GAC/C,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The `./migrations` subpath — every migration class this module owns, as one
3
+ * ordered `migrations` array.
4
+ *
5
+ * The array is what the platform reads when this module is **installed**:
6
+ * `src/packages/package-runtime.ts` takes `exported['migrations']` and refuses
7
+ * the package outright when it is absent (D-168).
8
+ *
9
+ * Listed in ascending timestamp, which is the order of this module's own
10
+ * migrations and of nothing else (feature 081): a manifest `dependencies` array
11
+ * is the only thing ordering this block against another module's.
12
+ *
13
+ * The **named** exports stay beside the array, and the asymmetry with
14
+ * `./backend` — which publishes an array and no named class (D-168) — is
15
+ * deliberate. `db/migrations-registry.generated.ts` imports each class by name
16
+ * from this specifier, and a migration class name is contract in a way an entity
17
+ * class name is not: `mikro_orm_migrations` persists it, so it is a string every
18
+ * already-migrated database holds.
19
+ *
20
+ * A class that is in neither the array nor the barrel is a migration that does
21
+ * not run: `migration:pending` reports nothing pending and the first symptom is
22
+ * a query against a table nobody created.
23
+ */
24
+ import { Migration20260629T125121InvoicesModule } from './20260629T125121_invoices_module.js';
25
+ import { Migration20260801T111000InvoicesGenericTemplateReseed } from './20260801T111000_invoices_generic_template_reseed.js';
26
+ import { Migration20260817T201110InvoicesCorrectionIdempotencyKey } from './20260817T201110_invoices_correction_idempotency_key.js';
27
+ import { Migration20260903T101756InvoicesNamespaceBlockNames } from './20260903T101756_invoices_namespace_block_names.js';
28
+ import { Migration20260914T133603InvoicesErpImportedSaleDocuments } from './20260914T133603_invoices_erp_imported_sale_documents.js';
29
+ import { Migration20260926T230239InvoicesImportIdentity } from './20260926T230239_invoices_import_identity.js';
30
+ export const migrations = [
31
+ Migration20260629T125121InvoicesModule,
32
+ Migration20260801T111000InvoicesGenericTemplateReseed,
33
+ Migration20260817T201110InvoicesCorrectionIdempotencyKey,
34
+ Migration20260903T101756InvoicesNamespaceBlockNames,
35
+ Migration20260914T133603InvoicesErpImportedSaleDocuments,
36
+ Migration20260926T230239InvoicesImportIdentity,
37
+ ];
38
+ export { Migration20260629T125121InvoicesModule, Migration20260801T111000InvoicesGenericTemplateReseed, Migration20260817T201110InvoicesCorrectionIdempotencyKey, Migration20260903T101756InvoicesNamespaceBlockNames, Migration20260914T133603InvoicesErpImportedSaleDocuments, Migration20260926T230239InvoicesImportIdentity, };
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,sCAAsC,EAAE,MAAM,sCAAsC,CAAC;AAC9F,OAAO,EAAE,qDAAqD,EAAE,MAAM,uDAAuD,CAAC;AAC9H,OAAO,EAAE,wDAAwD,EAAE,MAAM,0DAA0D,CAAC;AACpI,OAAO,EAAE,mDAAmD,EAAE,MAAM,qDAAqD,CAAC;AAC1H,OAAO,EAAE,wDAAwD,EAAE,MAAM,2DAA2D,CAAC;AACrI,OAAO,EAAE,8CAA8C,EAAE,MAAM,+CAA+C,CAAC;AAE/G,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,sCAAsC;IACtC,qDAAqD;IACrD,wDAAwD;IACxD,mDAAmD;IACnD,wDAAwD;IACxD,8CAA8C;CAC/C,CAAC;AAEF,OAAO,EACL,sCAAsC,EACtC,qDAAqD,EACrD,wDAAwD,EACxD,mDAAmD,EACnD,wDAAwD,EACxD,8CAA8C,GAC/C,CAAC"}