@endora-commerce/mod-organizations 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 (288) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +62 -0
  3. package/dist/admin/components/OrganizationSalesRepsTab.d.ts +27 -0
  4. package/dist/admin/components/OrganizationSalesRepsTab.d.ts.map +1 -0
  5. package/dist/admin/components/OrganizationSalesRepsTab.js +170 -0
  6. package/dist/admin/components/OrganizationSalesRepsTab.js.map +1 -0
  7. package/dist/admin/index.d.ts +30 -0
  8. package/dist/admin/index.d.ts.map +1 -0
  9. package/dist/admin/index.js +59 -0
  10. package/dist/admin/index.js.map +1 -0
  11. package/dist/admin/pages/OrganizationDetail.d.ts +9 -0
  12. package/dist/admin/pages/OrganizationDetail.d.ts.map +1 -0
  13. package/dist/admin/pages/OrganizationDetail.js +247 -0
  14. package/dist/admin/pages/OrganizationDetail.js.map +1 -0
  15. package/dist/admin/pages/OrganizationsList.d.ts +9 -0
  16. package/dist/admin/pages/OrganizationsList.d.ts.map +1 -0
  17. package/dist/admin/pages/OrganizationsList.js +73 -0
  18. package/dist/admin/pages/OrganizationsList.js.map +1 -0
  19. package/dist/admin/panels/ApplicablePriceListsPanel.d.ts +12 -0
  20. package/dist/admin/panels/ApplicablePriceListsPanel.d.ts.map +1 -0
  21. package/dist/admin/panels/ApplicablePriceListsPanel.js +49 -0
  22. package/dist/admin/panels/ApplicablePriceListsPanel.js.map +1 -0
  23. package/dist/admin/panels/FulfilmentStrategyPanel.d.ts +16 -0
  24. package/dist/admin/panels/FulfilmentStrategyPanel.d.ts.map +1 -0
  25. package/dist/admin/panels/FulfilmentStrategyPanel.js +29 -0
  26. package/dist/admin/panels/FulfilmentStrategyPanel.js.map +1 -0
  27. package/dist/admin/panels/HierarchyPanel.d.ts +15 -0
  28. package/dist/admin/panels/HierarchyPanel.d.ts.map +1 -0
  29. package/dist/admin/panels/HierarchyPanel.js +65 -0
  30. package/dist/admin/panels/HierarchyPanel.js.map +1 -0
  31. package/dist/admin/panels/ModerationActionsPanel.d.ts +28 -0
  32. package/dist/admin/panels/ModerationActionsPanel.d.ts.map +1 -0
  33. package/dist/admin/panels/ModerationActionsPanel.js +111 -0
  34. package/dist/admin/panels/ModerationActionsPanel.js.map +1 -0
  35. package/dist/admin/panels/RestrictionsPanel.d.ts +24 -0
  36. package/dist/admin/panels/RestrictionsPanel.d.ts.map +1 -0
  37. package/dist/admin/panels/RestrictionsPanel.js +121 -0
  38. package/dist/admin/panels/RestrictionsPanel.js.map +1 -0
  39. package/dist/admin/panels/VatValidationPanel.d.ts +28 -0
  40. package/dist/admin/panels/VatValidationPanel.d.ts.map +1 -0
  41. package/dist/admin/panels/VatValidationPanel.js +79 -0
  42. package/dist/admin/panels/VatValidationPanel.js.map +1 -0
  43. package/dist/backend/commands/move.command.d.ts +11 -0
  44. package/dist/backend/commands/move.command.d.ts.map +1 -0
  45. package/dist/backend/commands/move.command.js +11 -0
  46. package/dist/backend/commands/move.command.js.map +1 -0
  47. package/dist/backend/commands/set-cart-approval-policy.command.d.ts +31 -0
  48. package/dist/backend/commands/set-cart-approval-policy.command.d.ts.map +1 -0
  49. package/dist/backend/commands/set-cart-approval-policy.command.js +56 -0
  50. package/dist/backend/commands/set-cart-approval-policy.command.js.map +1 -0
  51. package/dist/backend/commands/set-credit-mode.command.d.ts +16 -0
  52. package/dist/backend/commands/set-credit-mode.command.d.ts.map +1 -0
  53. package/dist/backend/commands/set-credit-mode.command.js +25 -0
  54. package/dist/backend/commands/set-credit-mode.command.js.map +1 -0
  55. package/dist/backend/commands/set-parent.command.d.ts +26 -0
  56. package/dist/backend/commands/set-parent.command.d.ts.map +1 -0
  57. package/dist/backend/commands/set-parent.command.js +51 -0
  58. package/dist/backend/commands/set-parent.command.js.map +1 -0
  59. package/dist/backend/demo/reset.d.ts +20 -0
  60. package/dist/backend/demo/reset.d.ts.map +1 -0
  61. package/dist/backend/demo/reset.js +11 -0
  62. package/dist/backend/demo/reset.js.map +1 -0
  63. package/dist/backend/demo/rows.d.ts +44 -0
  64. package/dist/backend/demo/rows.d.ts.map +1 -0
  65. package/dist/backend/demo/rows.js +44 -0
  66. package/dist/backend/demo/rows.js.map +1 -0
  67. package/dist/backend/demo/seed.d.ts +20 -0
  68. package/dist/backend/demo/seed.d.ts.map +1 -0
  69. package/dist/backend/demo/seed.js +28 -0
  70. package/dist/backend/demo/seed.js.map +1 -0
  71. package/dist/backend/email-templates/invitation.d.ts +23 -0
  72. package/dist/backend/email-templates/invitation.d.ts.map +1 -0
  73. package/dist/backend/email-templates/invitation.js +35 -0
  74. package/dist/backend/email-templates/invitation.js.map +1 -0
  75. package/dist/backend/email-templates/transactional-defaults.d.ts +54 -0
  76. package/dist/backend/email-templates/transactional-defaults.d.ts.map +1 -0
  77. package/dist/backend/email-templates/transactional-defaults.js +242 -0
  78. package/dist/backend/email-templates/transactional-defaults.js.map +1 -0
  79. package/dist/backend/email-templates/verification.d.ts +14 -0
  80. package/dist/backend/email-templates/verification.d.ts.map +1 -0
  81. package/dist/backend/email-templates/verification.js +34 -0
  82. package/dist/backend/email-templates/verification.js.map +1 -0
  83. package/dist/backend/entities/email-verification-token.entity.d.ts +17 -0
  84. package/dist/backend/entities/email-verification-token.entity.d.ts.map +1 -0
  85. package/dist/backend/entities/email-verification-token.entity.js +60 -0
  86. package/dist/backend/entities/email-verification-token.entity.js.map +1 -0
  87. package/dist/backend/entities/organization-delivery-method-link.entity.d.ts +14 -0
  88. package/dist/backend/entities/organization-delivery-method-link.entity.d.ts.map +1 -0
  89. package/dist/backend/entities/organization-delivery-method-link.entity.js +41 -0
  90. package/dist/backend/entities/organization-delivery-method-link.entity.js.map +1 -0
  91. package/dist/backend/entities/organization-invitation.entity.d.ts +21 -0
  92. package/dist/backend/entities/organization-invitation.entity.d.ts.map +1 -0
  93. package/dist/backend/entities/organization-invitation.entity.js +85 -0
  94. package/dist/backend/entities/organization-invitation.entity.js.map +1 -0
  95. package/dist/backend/entities/organization-payment-method-link.entity.d.ts +14 -0
  96. package/dist/backend/entities/organization-payment-method-link.entity.d.ts.map +1 -0
  97. package/dist/backend/entities/organization-payment-method-link.entity.js +41 -0
  98. package/dist/backend/entities/organization-payment-method-link.entity.js.map +1 -0
  99. package/dist/backend/entities/organization-sales-rep-assignment.entity.d.ts +17 -0
  100. package/dist/backend/entities/organization-sales-rep-assignment.entity.d.ts.map +1 -0
  101. package/dist/backend/entities/organization-sales-rep-assignment.entity.js +56 -0
  102. package/dist/backend/entities/organization-sales-rep-assignment.entity.js.map +1 -0
  103. package/dist/backend/entities/organization-tax-id-validation.entity.d.ts +29 -0
  104. package/dist/backend/entities/organization-tax-id-validation.entity.d.ts.map +1 -0
  105. package/dist/backend/entities/organization-tax-id-validation.entity.js +78 -0
  106. package/dist/backend/entities/organization-tax-id-validation.entity.js.map +1 -0
  107. package/dist/backend/entities/organization-warehouse-link.entity.d.ts +15 -0
  108. package/dist/backend/entities/organization-warehouse-link.entity.d.ts.map +1 -0
  109. package/dist/backend/entities/organization-warehouse-link.entity.js +42 -0
  110. package/dist/backend/entities/organization-warehouse-link.entity.js.map +1 -0
  111. package/dist/backend/entities/organization.entity.d.ts +125 -0
  112. package/dist/backend/entities/organization.entity.d.ts.map +1 -0
  113. package/dist/backend/entities/organization.entity.js +282 -0
  114. package/dist/backend/entities/organization.entity.js.map +1 -0
  115. package/dist/backend/index.d.ts +250 -0
  116. package/dist/backend/index.d.ts.map +1 -0
  117. package/dist/backend/index.js +506 -0
  118. package/dist/backend/index.js.map +1 -0
  119. package/dist/backend/integrations/ministerstwo-finansow-client.d.ts +22 -0
  120. package/dist/backend/integrations/ministerstwo-finansow-client.d.ts.map +1 -0
  121. package/dist/backend/integrations/ministerstwo-finansow-client.js +172 -0
  122. package/dist/backend/integrations/ministerstwo-finansow-client.js.map +1 -0
  123. package/dist/backend/integrations/vies-client.d.ts +18 -0
  124. package/dist/backend/integrations/vies-client.d.ts.map +1 -0
  125. package/dist/backend/integrations/vies-client.js +133 -0
  126. package/dist/backend/integrations/vies-client.js.map +1 -0
  127. package/dist/backend/plugin.d.ts +126 -0
  128. package/dist/backend/plugin.d.ts.map +1 -0
  129. package/dist/backend/plugin.js +139 -0
  130. package/dist/backend/plugin.js.map +1 -0
  131. package/dist/backend/routes.admin.d.ts +66 -0
  132. package/dist/backend/routes.admin.d.ts.map +1 -0
  133. package/dist/backend/routes.admin.js +711 -0
  134. package/dist/backend/routes.admin.js.map +1 -0
  135. package/dist/backend/routes.customer.d.ts +33 -0
  136. package/dist/backend/routes.customer.d.ts.map +1 -0
  137. package/dist/backend/routes.customer.js +139 -0
  138. package/dist/backend/routes.customer.js.map +1 -0
  139. package/dist/backend/routes.members.d.ts +31 -0
  140. package/dist/backend/routes.members.d.ts.map +1 -0
  141. package/dist/backend/routes.members.js +109 -0
  142. package/dist/backend/routes.members.js.map +1 -0
  143. package/dist/backend/routes.public.d.ts +49 -0
  144. package/dist/backend/routes.public.d.ts.map +1 -0
  145. package/dist/backend/routes.public.js +220 -0
  146. package/dist/backend/routes.public.js.map +1 -0
  147. package/dist/backend/routes.sales-reps.d.ts +46 -0
  148. package/dist/backend/routes.sales-reps.d.ts.map +1 -0
  149. package/dist/backend/routes.sales-reps.js +114 -0
  150. package/dist/backend/routes.sales-reps.js.map +1 -0
  151. package/dist/backend/routes.storefront.d.ts +25 -0
  152. package/dist/backend/routes.storefront.d.ts.map +1 -0
  153. package/dist/backend/routes.storefront.js +65 -0
  154. package/dist/backend/routes.storefront.js.map +1 -0
  155. package/dist/backend/schemas/organization.d.ts +59 -0
  156. package/dist/backend/schemas/organization.d.ts.map +1 -0
  157. package/dist/backend/schemas/organization.js +55 -0
  158. package/dist/backend/schemas/organization.js.map +1 -0
  159. package/dist/backend/schemas/settings.d.ts +30 -0
  160. package/dist/backend/schemas/settings.d.ts.map +1 -0
  161. package/dist/backend/schemas/settings.js +35 -0
  162. package/dist/backend/schemas/settings.js.map +1 -0
  163. package/dist/backend/services/email-verification-service.d.ts +45 -0
  164. package/dist/backend/services/email-verification-service.d.ts.map +1 -0
  165. package/dist/backend/services/email-verification-service.js +95 -0
  166. package/dist/backend/services/email-verification-service.js.map +1 -0
  167. package/dist/backend/services/invitation-service.d.ts +85 -0
  168. package/dist/backend/services/invitation-service.d.ts.map +1 -0
  169. package/dist/backend/services/invitation-service.js +266 -0
  170. package/dist/backend/services/invitation-service.js.map +1 -0
  171. package/dist/backend/services/normalize-name.d.ts +14 -0
  172. package/dist/backend/services/normalize-name.d.ts.map +1 -0
  173. package/dist/backend/services/normalize-name.js +14 -0
  174. package/dist/backend/services/normalize-name.js.map +1 -0
  175. package/dist/backend/services/org-registration-notifier.d.ts +36 -0
  176. package/dist/backend/services/org-registration-notifier.d.ts.map +1 -0
  177. package/dist/backend/services/org-registration-notifier.js +109 -0
  178. package/dist/backend/services/org-registration-notifier.js.map +1 -0
  179. package/dist/backend/services/org-template-email.d.ts +18 -0
  180. package/dist/backend/services/org-template-email.d.ts.map +1 -0
  181. package/dist/backend/services/org-template-email.js +16 -0
  182. package/dist/backend/services/org-template-email.js.map +1 -0
  183. package/dist/backend/services/organization-context-service.d.ts +52 -0
  184. package/dist/backend/services/organization-context-service.d.ts.map +1 -0
  185. package/dist/backend/services/organization-context-service.js +70 -0
  186. package/dist/backend/services/organization-context-service.js.map +1 -0
  187. package/dist/backend/services/organization-country-reference.d.ts +11 -0
  188. package/dist/backend/services/organization-country-reference.d.ts.map +1 -0
  189. package/dist/backend/services/organization-country-reference.js +24 -0
  190. package/dist/backend/services/organization-country-reference.js.map +1 -0
  191. package/dist/backend/services/organization-details-port.d.ts +33 -0
  192. package/dist/backend/services/organization-details-port.d.ts.map +1 -0
  193. package/dist/backend/services/organization-details-port.js +95 -0
  194. package/dist/backend/services/organization-details-port.js.map +1 -0
  195. package/dist/backend/services/organization-effective-pricelists-service.d.ts +50 -0
  196. package/dist/backend/services/organization-effective-pricelists-service.d.ts.map +1 -0
  197. package/dist/backend/services/organization-effective-pricelists-service.js +68 -0
  198. package/dist/backend/services/organization-effective-pricelists-service.js.map +1 -0
  199. package/dist/backend/services/organization-inheritance-service.d.ts +73 -0
  200. package/dist/backend/services/organization-inheritance-service.d.ts.map +1 -0
  201. package/dist/backend/services/organization-inheritance-service.js +63 -0
  202. package/dist/backend/services/organization-inheritance-service.js.map +1 -0
  203. package/dist/backend/services/organization-moderation-service.d.ts +124 -0
  204. package/dist/backend/services/organization-moderation-service.d.ts.map +1 -0
  205. package/dist/backend/services/organization-moderation-service.js +337 -0
  206. package/dist/backend/services/organization-moderation-service.js.map +1 -0
  207. package/dist/backend/services/organization-restriction-service.d.ts +70 -0
  208. package/dist/backend/services/organization-restriction-service.d.ts.map +1 -0
  209. package/dist/backend/services/organization-restriction-service.js +210 -0
  210. package/dist/backend/services/organization-restriction-service.js.map +1 -0
  211. package/dist/backend/services/organization-tax-id-validation-service.d.ts +59 -0
  212. package/dist/backend/services/organization-tax-id-validation-service.d.ts.map +1 -0
  213. package/dist/backend/services/organization-tax-id-validation-service.js +115 -0
  214. package/dist/backend/services/organization-tax-id-validation-service.js.map +1 -0
  215. package/dist/backend/services/organization-tree-service.d.ts +102 -0
  216. package/dist/backend/services/organization-tree-service.d.ts.map +1 -0
  217. package/dist/backend/services/organization-tree-service.js +184 -0
  218. package/dist/backend/services/organization-tree-service.js.map +1 -0
  219. package/dist/backend/services/personal-organization-service.d.ts +130 -0
  220. package/dist/backend/services/personal-organization-service.d.ts.map +1 -0
  221. package/dist/backend/services/personal-organization-service.js +207 -0
  222. package/dist/backend/services/personal-organization-service.js.map +1 -0
  223. package/dist/backend/services/registration-service.d.ts +80 -0
  224. package/dist/backend/services/registration-service.d.ts.map +1 -0
  225. package/dist/backend/services/registration-service.js +126 -0
  226. package/dist/backend/services/registration-service.js.map +1 -0
  227. package/dist/backend/services/sales-rep-assignment-service.d.ts +89 -0
  228. package/dist/backend/services/sales-rep-assignment-service.d.ts.map +1 -0
  229. package/dist/backend/services/sales-rep-assignment-service.js +176 -0
  230. package/dist/backend/services/sales-rep-assignment-service.js.map +1 -0
  231. package/dist/backend/services/vat-validator-port.d.ts +20 -0
  232. package/dist/backend/services/vat-validator-port.d.ts.map +1 -0
  233. package/dist/backend/services/vat-validator-port.js +2 -0
  234. package/dist/backend/services/vat-validator-port.js.map +1 -0
  235. package/dist/manifest.d.ts +176 -0
  236. package/dist/manifest.d.ts.map +1 -0
  237. package/dist/manifest.js +503 -0
  238. package/dist/manifest.js.map +1 -0
  239. package/dist/migrations/20260424T205317_organizations_init.d.ts +13 -0
  240. package/dist/migrations/20260424T205317_organizations_init.d.ts.map +1 -0
  241. package/dist/migrations/20260424T205317_organizations_init.js +100 -0
  242. package/dist/migrations/20260424T205317_organizations_init.js.map +1 -0
  243. package/dist/migrations/20260425T051700_organizations_invitations_init.d.ts +13 -0
  244. package/dist/migrations/20260425T051700_organizations_invitations_init.d.ts.map +1 -0
  245. package/dist/migrations/20260425T051700_organizations_invitations_init.js +39 -0
  246. package/dist/migrations/20260425T051700_organizations_invitations_init.js.map +1 -0
  247. package/dist/migrations/20260611T140349_organizations_consolidation.d.ts +35 -0
  248. package/dist/migrations/20260611T140349_organizations_consolidation.d.ts.map +1 -0
  249. package/dist/migrations/20260611T140349_organizations_consolidation.js +180 -0
  250. package/dist/migrations/20260611T140349_organizations_consolidation.js.map +1 -0
  251. package/dist/migrations/20260611T140358_organizations_org_order_confirmation_emails.d.ts +10 -0
  252. package/dist/migrations/20260611T140358_organizations_org_order_confirmation_emails.d.ts.map +1 -0
  253. package/dist/migrations/20260611T140358_organizations_org_order_confirmation_emails.js +14 -0
  254. package/dist/migrations/20260611T140358_organizations_org_order_confirmation_emails.js.map +1 -0
  255. package/dist/migrations/20260611T140402_organizations_org_fulfilment_strategy.d.ts +14 -0
  256. package/dist/migrations/20260611T140402_organizations_org_fulfilment_strategy.d.ts.map +1 -0
  257. package/dist/migrations/20260611T140402_organizations_org_fulfilment_strategy.js +20 -0
  258. package/dist/migrations/20260611T140402_organizations_org_fulfilment_strategy.js.map +1 -0
  259. package/dist/migrations/20260717T151403_organizations_personal_organizations.d.ts +24 -0
  260. package/dist/migrations/20260717T151403_organizations_personal_organizations.d.ts.map +1 -0
  261. package/dist/migrations/20260717T151403_organizations_personal_organizations.js +63 -0
  262. package/dist/migrations/20260717T151403_organizations_personal_organizations.js.map +1 -0
  263. package/dist/migrations/20260718T200340_organizations_organization_custom_field_values.d.ts +12 -0
  264. package/dist/migrations/20260718T200340_organizations_organization_custom_field_values.d.ts.map +1 -0
  265. package/dist/migrations/20260718T200340_organizations_organization_custom_field_values.js +16 -0
  266. package/dist/migrations/20260718T200340_organizations_organization_custom_field_values.js.map +1 -0
  267. package/dist/migrations/20260720T044254_organizations_org_hierarchy.d.ts +23 -0
  268. package/dist/migrations/20260720T044254_organizations_org_hierarchy.d.ts.map +1 -0
  269. package/dist/migrations/20260720T044254_organizations_org_hierarchy.js +37 -0
  270. package/dist/migrations/20260720T044254_organizations_org_hierarchy.js.map +1 -0
  271. package/dist/migrations/20260912T094646_organizations_sales_channel_organizations.d.ts +27 -0
  272. package/dist/migrations/20260912T094646_organizations_sales_channel_organizations.d.ts.map +1 -0
  273. package/dist/migrations/20260912T094646_organizations_sales_channel_organizations.js +44 -0
  274. package/dist/migrations/20260912T094646_organizations_sales_channel_organizations.js.map +1 -0
  275. package/dist/migrations/index.d.ts +35 -0
  276. package/dist/migrations/index.d.ts.map +1 -0
  277. package/dist/migrations/index.js +45 -0
  278. package/dist/migrations/index.js.map +1 -0
  279. package/dist/ports/index.d.ts +53 -0
  280. package/dist/ports/index.d.ts.map +1 -0
  281. package/dist/ports/index.js +2 -0
  282. package/dist/ports/index.js.map +1 -0
  283. package/docs/organization-hierarchy.md +117 -0
  284. package/docs/organizations.md +312 -0
  285. package/i18n/en.json +17 -0
  286. package/i18n/pl.json +17 -0
  287. package/package.json +107 -0
  288. package/tailwind.css +14 -0
@@ -0,0 +1,282 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { BeforeCreate, BeforeUpdate, Entity, Index, OptionalProps, PrimaryKey, Property, Unique, } from '@mikro-orm/core';
11
+ import { GlobalEntity } from '@endora-commerce/platform/tenancy';
12
+ import { randomUUID } from 'crypto';
13
+ import { normalizeOrganizationName } from '../services/normalize-name.js';
14
+ /**
15
+ * Organization — the buyer-side legal entity. Owns Customer Accounts,
16
+ * Addresses, and (via FKs that land with later US) Quote Requests, Orders,
17
+ * and Credit Limits.
18
+ *
19
+ * `taxId` is globally unique in the installation (Polish NIP by default; the
20
+ * exact format is spec-validated at the Zod boundary).
21
+ *
22
+ * Status lifecycle (feature 026):
23
+ * pending_verification -> active (moderation approve, or auto-approve)
24
+ * pending_verification -> rejected (moderation reject; terminal)
25
+ * active -> blocked (operator-driven; reversible)
26
+ * blocked -> active (unblock)
27
+ *
28
+ * Legacy `suspended` is migrated to `blocked` by migration 047 and is no
29
+ * longer a valid runtime value.
30
+ *
31
+ * `version` is the optimistic-lock token used by every moderation /
32
+ * restriction / VAT-fill write — see OrganizationModerationService for the
33
+ * conflict handling.
34
+ *
35
+ * `nameSearch` is a denormalized lowercased + diacritic-stripped copy of
36
+ * `name`, kept in sync by the BeforeCreate / BeforeUpdate hooks below. It
37
+ * backs the admin OrganizationPicker's diacritic-insensitive typeahead
38
+ * without needing pg_trgm/unaccent extensions.
39
+ */
40
+ let Organization = class Organization {
41
+ [OptionalProps];
42
+ id = randomUUID();
43
+ name;
44
+ legalName;
45
+ taxId;
46
+ status = 'pending_verification';
47
+ vatStatus = 'vat_payer';
48
+ /**
49
+ * Feature 051 — `true` for a single-member Personal Organization backing a B2C
50
+ * (individual) customer; `false` for a company organization. Personal orgs are
51
+ * auto-provisioned, created `active`, and excluded from B2B admin surfaces.
52
+ */
53
+ isPersonal = false;
54
+ /**
55
+ * Optional pricing bucket. Feeds the feature 011 Application Rule
56
+ * evaluator's `customerGroup` criterion — a Sale or Base list with a
57
+ * `customerGroup ∈ {…}` rule applies to every Organization carrying
58
+ * that `customerGroupId`.
59
+ */
60
+ customerGroupId;
61
+ /** JSONB snapshot of { street, city, postalCode, country }. */
62
+ registeredAddress;
63
+ /**
64
+ * Feature 038 (US4) — additional email addresses that also receive an order
65
+ * confirmation for every order placed by a Customer of this Organization.
66
+ * Read by the orders module through OrganizationConfirmationEmailsPort.
67
+ */
68
+ orderConfirmationEmails = [];
69
+ // ── feature 026: moderation + VAT validation tracking ───────────────────
70
+ vatValidatedAt;
71
+ vatValidationProvider;
72
+ vatValidationOutcome;
73
+ blockedReason;
74
+ blockedAt;
75
+ rejectedReason;
76
+ rejectedAt;
77
+ approvedAt;
78
+ approvedByAdminUserId;
79
+ /**
80
+ * Per-Organization policy flag (feature 027 US4). When `true`, ordinary
81
+ * Customer members of this Organization must submit their cart for
82
+ * approval by an Organization Administrator before checkout. Carts
83
+ * created by an Organization Administrator are exempt from the gate
84
+ * (self-approval exemption — see research.md §R11 for feature 027).
85
+ */
86
+ requiresCartApproval = false;
87
+ /**
88
+ * Organization-level override of the warehouse-picking (fulfilment) strategy
89
+ * applied when reserving stock at order placement (precedence: Product →
90
+ * Organization → Sales Channel setting → platform default). `null` ⇒ inherit.
91
+ * Mirrors the per-product columns on `Product`. When `defined_order`,
92
+ * `fulfilmentStrategyWarehouseOrder` carries the ordered warehouse-id walk.
93
+ */
94
+ fulfilmentStrategy;
95
+ fulfilmentStrategyWarehouseOrder;
96
+ // ── feature 056: organization hierarchy ────────────────────────────────
97
+ /**
98
+ * Nullable self-referential parent (`parent_id`). NULL ⇒ this org is a root.
99
+ * The FK (`REFERENCES organizations(id) ON DELETE RESTRICT`) is enforced at
100
+ * the DB level (migration 097); writes go through the tree Commands only, so
101
+ * `path` and cycle/depth invariants stay consistent.
102
+ */
103
+ parentId;
104
+ /**
105
+ * Materialized ancestor-chain path `'/<rootId>/…/<thisId>/'`. Backfilled to
106
+ * `'/<id>/'` (a root) for every pre-feature org. A `text_pattern_ops` prefix
107
+ * index backs single-query subtree (`path LIKE :selfPath || '%'`) traversal.
108
+ */
109
+ path = '';
110
+ /**
111
+ * Per-org platform-admin override of the credit-inheritance mode. NULL ⇒ use
112
+ * the Settings global default. Set only through the `organization.set_credit_mode`
113
+ * Command (platform-admin gated).
114
+ */
115
+ creditInheritanceMode;
116
+ /**
117
+ * Lowercased + diacritic-stripped copy of `name`. Kept in sync by the
118
+ * BeforeCreate / BeforeUpdate hooks; never read or written by callers
119
+ * directly.
120
+ */
121
+ nameSearch = '';
122
+ /** Optimistic-lock token (auto-incremented by MikroORM on every update). */
123
+ version;
124
+ createdAt = new Date();
125
+ updatedAt = new Date();
126
+ // Feature 055 — Custom Fields Layer value bag (inherits host tenant scope).
127
+ customFieldValues = {};
128
+ deletedAt;
129
+ // ── lifecycle hooks ────────────────────────────────────────────────────
130
+ syncNameSearch(_args) {
131
+ this.nameSearch = normalizeOrganizationName(this.name);
132
+ }
133
+ };
134
+ __decorate([
135
+ PrimaryKey({ type: 'uuid' }),
136
+ __metadata("design:type", String)
137
+ ], Organization.prototype, "id", void 0);
138
+ __decorate([
139
+ Property({ type: 'string', length: 255 }),
140
+ Index(),
141
+ __metadata("design:type", String)
142
+ ], Organization.prototype, "name", void 0);
143
+ __decorate([
144
+ Property({ type: 'string', length: 255, nullable: true }),
145
+ __metadata("design:type", Object)
146
+ ], Organization.prototype, "legalName", void 0);
147
+ __decorate([
148
+ Property({ type: 'string', length: 32 }),
149
+ Unique(),
150
+ __metadata("design:type", String)
151
+ ], Organization.prototype, "taxId", void 0);
152
+ __decorate([
153
+ Property({ type: 'string', length: 32 }),
154
+ Index(),
155
+ __metadata("design:type", String)
156
+ ], Organization.prototype, "status", void 0);
157
+ __decorate([
158
+ Property({ type: 'string', length: 16 }),
159
+ __metadata("design:type", String)
160
+ ], Organization.prototype, "vatStatus", void 0);
161
+ __decorate([
162
+ Property({ type: 'boolean' }),
163
+ Index(),
164
+ __metadata("design:type", Boolean)
165
+ ], Organization.prototype, "isPersonal", void 0);
166
+ __decorate([
167
+ Property({ type: 'uuid', nullable: true }),
168
+ Index(),
169
+ __metadata("design:type", Object)
170
+ ], Organization.prototype, "customerGroupId", void 0);
171
+ __decorate([
172
+ Property({ type: 'json' }),
173
+ __metadata("design:type", Object)
174
+ ], Organization.prototype, "registeredAddress", void 0);
175
+ __decorate([
176
+ Property({ type: 'json' }),
177
+ __metadata("design:type", Array)
178
+ ], Organization.prototype, "orderConfirmationEmails", void 0);
179
+ __decorate([
180
+ Property({ type: 'datetime', nullable: true }),
181
+ __metadata("design:type", Object)
182
+ ], Organization.prototype, "vatValidatedAt", void 0);
183
+ __decorate([
184
+ Property({ type: 'string', length: 32, nullable: true }),
185
+ __metadata("design:type", Object)
186
+ ], Organization.prototype, "vatValidationProvider", void 0);
187
+ __decorate([
188
+ Property({ type: 'string', length: 16, nullable: true }),
189
+ __metadata("design:type", Object)
190
+ ], Organization.prototype, "vatValidationOutcome", void 0);
191
+ __decorate([
192
+ Property({ type: 'text', nullable: true }),
193
+ __metadata("design:type", Object)
194
+ ], Organization.prototype, "blockedReason", void 0);
195
+ __decorate([
196
+ Property({ type: 'datetime', nullable: true }),
197
+ __metadata("design:type", Object)
198
+ ], Organization.prototype, "blockedAt", void 0);
199
+ __decorate([
200
+ Property({ type: 'text', nullable: true }),
201
+ __metadata("design:type", Object)
202
+ ], Organization.prototype, "rejectedReason", void 0);
203
+ __decorate([
204
+ Property({ type: 'datetime', nullable: true }),
205
+ __metadata("design:type", Object)
206
+ ], Organization.prototype, "rejectedAt", void 0);
207
+ __decorate([
208
+ Property({ type: 'datetime', nullable: true }),
209
+ __metadata("design:type", Object)
210
+ ], Organization.prototype, "approvedAt", void 0);
211
+ __decorate([
212
+ Property({ type: 'uuid', nullable: true }),
213
+ __metadata("design:type", Object)
214
+ ], Organization.prototype, "approvedByAdminUserId", void 0);
215
+ __decorate([
216
+ Property({ type: 'boolean' }),
217
+ __metadata("design:type", Boolean)
218
+ ], Organization.prototype, "requiresCartApproval", void 0);
219
+ __decorate([
220
+ Property({ type: 'string', length: 32, nullable: true }),
221
+ __metadata("design:type", Object)
222
+ ], Organization.prototype, "fulfilmentStrategy", void 0);
223
+ __decorate([
224
+ Property({ type: 'json', nullable: true }),
225
+ __metadata("design:type", Object)
226
+ ], Organization.prototype, "fulfilmentStrategyWarehouseOrder", void 0);
227
+ __decorate([
228
+ Property({ type: 'uuid', nullable: true }),
229
+ Index(),
230
+ __metadata("design:type", Object)
231
+ ], Organization.prototype, "parentId", void 0);
232
+ __decorate([
233
+ Property({ type: 'text' }),
234
+ __metadata("design:type", String)
235
+ ], Organization.prototype, "path", void 0);
236
+ __decorate([
237
+ Property({ type: 'string', length: 20, nullable: true }),
238
+ __metadata("design:type", Object)
239
+ ], Organization.prototype, "creditInheritanceMode", void 0);
240
+ __decorate([
241
+ Property({ type: 'string', length: 255 }),
242
+ __metadata("design:type", String)
243
+ ], Organization.prototype, "nameSearch", void 0);
244
+ __decorate([
245
+ Property({ type: 'integer', version: true }),
246
+ __metadata("design:type", Number)
247
+ ], Organization.prototype, "version", void 0);
248
+ __decorate([
249
+ Property({ type: 'datetime', onCreate: () => new Date() }),
250
+ __metadata("design:type", Date)
251
+ ], Organization.prototype, "createdAt", void 0);
252
+ __decorate([
253
+ Property({ type: 'datetime', onUpdate: () => new Date() }),
254
+ __metadata("design:type", Date)
255
+ ], Organization.prototype, "updatedAt", void 0);
256
+ __decorate([
257
+ Property({ type: 'json' }),
258
+ __metadata("design:type", Object)
259
+ ], Organization.prototype, "customFieldValues", void 0);
260
+ __decorate([
261
+ Property({ type: 'datetime', nullable: true }),
262
+ __metadata("design:type", Object)
263
+ ], Organization.prototype, "deletedAt", void 0);
264
+ __decorate([
265
+ BeforeCreate(),
266
+ BeforeUpdate(),
267
+ __metadata("design:type", Function),
268
+ __metadata("design:paramtypes", [Object]),
269
+ __metadata("design:returntype", void 0)
270
+ ], Organization.prototype, "syncNameSearch", null);
271
+ Organization = __decorate([
272
+ GlobalEntity(),
273
+ Entity({ tableName: 'organizations' })
274
+ ], Organization);
275
+ export { Organization };
276
+ export const ORGANIZATION_STATUSES = [
277
+ 'pending_verification',
278
+ 'active',
279
+ 'blocked',
280
+ 'rejected',
281
+ ];
282
+ //# sourceMappingURL=organization.entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"organization.entity.js","sourceRoot":"","sources":["../../../src/backend/entities/organization.entity.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,MAAM,EACN,KAAK,EACL,aAAa,EACb,UAAU,EACV,QAAQ,EACR,MAAM,GAEP,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGI,IAAM,YAAY,GAAlB,MAAM,YAAY;IACvB,CAAC,aAAa,CAAC,CA4BD;IAGd,EAAE,GAAW,UAAU,EAAE,CAAC;IAI1B,IAAI,CAAU;IAGd,SAAS,CAAiB;IAI1B,KAAK,CAAU;IAIf,MAAM,GAAuB,sBAAsB,CAAC;IAGpD,SAAS,GAAkD,WAAW,CAAC;IAEvE;;;;OAIG;IAGH,UAAU,GAAY,KAAK,CAAC;IAE5B;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EAAE,CAAC;8BAChD,IAAI;+CAAc;AAG7B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;8BAChD,IAAI;+CAAc;AAI7B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;uDACqB;AAGhD;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;+CACvB;AAMxB;IAFC,YAAY,EAAE;IACd,YAAY,EAAE;;;;kDAGd;AA7MU,YAAY;IAFxB,YAAY,EAAE;IACd,MAAM,CAAC,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC;GAC1B,YAAY,CA8MxB;;AAQD,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,sBAAsB;IACtB,QAAQ;IACR,SAAS;IACT,UAAU;CACF,CAAC"}
@@ -0,0 +1,250 @@
1
+ import type { EntityManager } from '@mikro-orm/postgresql';
2
+ import type { ChannelMemberEntityType } from '@endora-commerce/contracts';
3
+ import type { AddressServicePort, AdminNotificationRecordPort, CustomFieldValuePort, CustomerAccountMemberWritePort, CustomerAccountReadPort, CustomerAuthPort, CustomerPasswordResetPort, CustomerRolePort, DictionaryValidator, EmailDefaultsRegistryPort, EmailMailerPort, PriceListReadPort, TemplateEmailPort, TransactionalEmailSender, VatValidator } from '@endora-commerce/contracts';
4
+ import type { AuditPort } from '@endora-commerce/platform/kernel';
5
+ import type { CommandBus } from '@endora-commerce/platform/commands';
6
+ import type { EventBus } from '@endora-commerce/platform/events';
7
+ import type { ModuleContext } from '@endora-commerce/platform/kernel';
8
+ import type { OrganizationReadPort } from '@endora-commerce/platform/kernel';
9
+ import type { RequireAdminAnyFactory, RequireAdminFactory } from '@endora-commerce/platform/kernel';
10
+ import type { SalesChannelResolutionPort } from '@endora-commerce/platform/kernel';
11
+ import type { SettingsReadPort } from '@endora-commerce/platform/kernel';
12
+ import { OrganizationRestrictionService } from './services/organization-restriction-service.js';
13
+ import { OrganizationTreeService } from './services/organization-tree-service.js';
14
+ import { OrganizationInheritanceService } from './services/organization-inheritance-service.js';
15
+ import { OrganizationModerationService } from './services/organization-moderation-service.js';
16
+ import { type SalesRepAssignmentPort } from './services/sales-rep-assignment-service.js';
17
+ import { OrgRegistrationNotifier } from './services/org-registration-notifier.js';
18
+ import { Organization } from './entities/organization.entity.js';
19
+ import { organizationsModule, type OrganizationsModuleOptions } from './plugin.js';
20
+ import { EmailVerificationToken } from './entities/email-verification-token.entity.js';
21
+ import { OrganizationDeliveryMethodLink } from './entities/organization-delivery-method-link.entity.js';
22
+ import { OrganizationInvitation } from './entities/organization-invitation.entity.js';
23
+ import { OrganizationPaymentMethodLink } from './entities/organization-payment-method-link.entity.js';
24
+ import { OrganizationSalesRepAssignment } from './entities/organization-sales-rep-assignment.entity.js';
25
+ import { OrganizationTaxIdValidation } from './entities/organization-tax-id-validation.entity.js';
26
+ import { OrganizationWarehouseLink } from './entities/organization-warehouse-link.entity.js';
27
+ /**
28
+ * `organizations` — the tenancy root, and seven container names claimed by a
29
+ * table that nobody was registering (feature 072, wave 4, T138).
30
+ *
31
+ * This module owns more root-built machinery than any other converted so far:
32
+ * eight services, two EventBus subscriptions, and the four closures that turn a
33
+ * request actor into a per-Organization allow-list. Converting it drains all
34
+ * seven `HOST_REGISTERED_PORTS` entries declared `'organizations'`.
35
+ *
36
+ * **The allow-lists are the interesting part.** `buildOrgAllowListResolver` in
37
+ * each root fused two unrelated reads into one closure: *actor → organization
38
+ * id* (composition-shaped — production reads `request.actor`, the harness
39
+ * `request.testActor`) and *organization id → allowed ids* (this module's
40
+ * domain knowledge). Fused, it could only be a root contribution, which is why
41
+ * `payment_methods`, `delivery_methods` and `inventory` each declared a
42
+ * contribution point for it. Split, neither half is a contribution point: the
43
+ * first is `customerOrganizationIdResolver`, which the **platform** registers
44
+ * once in `composeApp` — a deployment input the roots each wrote out until
45
+ * `specs/117-instance-bring-up/` Phase 6, where it turned out that no
46
+ * composition other than those two had it at all — the second is
47
+ * {@link OrganizationRestrictionService.allowedIdsFor} behind a gated port, and
48
+ * each consumer composes the two itself.
49
+ *
50
+ * That split is forced, not stylistic. A module may not write a name another
51
+ * module owns — `ctx.di.register` claims every key and the kernel throws
52
+ * `DuplicateRegistrationError` on the second writer — so "`organizations`
53
+ * contributes to `payment_methods`' contribution point" was never available.
54
+ * Contribution points are a root↔module seam because a root sits outside the
55
+ * manifest graph and has no `dependencies` array that could record the edge; a
56
+ * module↔module edge always can be expressed as the dependent resolving the
57
+ * provider's port, and therefore must be.
58
+ *
59
+ * **The degrade moved with it.** The old closure wrapped the read in a bare
60
+ * `catch` that returned "no restriction". Around a *port* call that also
61
+ * swallows `ModuleDisabledError`, turning a fail-closed gate into a fail-open
62
+ * restriction check — on the one path whose whole job is to restrict. The
63
+ * "organization unknown or soft-deleted ⇒ unrestricted" policy now lives in
64
+ * `allowedIdsFor`'s return type, where it belongs, and no consumer needs a
65
+ * `catch` at all.
66
+ *
67
+ * **Two EventBus subscriptions stop being ungated.** Both roots called
68
+ * `eventBus.on('organization.registered.v1', …)` directly, so the admin
69
+ * notification and the moderation reactor fired even with the module switched
70
+ * off — the defect `shipments` and `payments` produced in wave 2. They are
71
+ * `ctx.subscribe` now (Constitution XVII item 2).
72
+ *
73
+ * **`dictionaryValidator` is passed for the first time.** `RegistrationService`
74
+ * has always taken one and `validateCountry` returns early without it; neither
75
+ * root ever passed one, so organization registration accepted any country
76
+ * string, including a code an operator had deactivated. Third instance of that
77
+ * exact shape after `sales_channels` and `inventory`.
78
+ *
79
+ * This module is **non-deactivatable**, and `customer_accounts` and
80
+ * `credit_limits` both declare it as a dependency. Where it sits in the
81
+ * composer's emitted order buys nothing on top of that: since D-45 there is one
82
+ * registration pass and registration resolves nothing, so the manifest edge is
83
+ * what the lifecycle, the migration order and an operator's switch all read.
84
+ *
85
+ * **The sales-rep scope came home in T143a cluster 6, and the two roots did not
86
+ * agree on it.** Production built `SalesRepAssignmentService` *with* the
87
+ * feature-056 subtree deps — the org tree and the `organizations:rollup`
88
+ * capability check — so a rep holding the capability saw the subtree of each
89
+ * assignment. The harness built the same class with neither, and its
90
+ * orders/RFQ scope resolver did not use even that: it ran its own raw SQL over
91
+ * `organization_sales_rep_assignments`. So the roll-up rule was exercised by no
92
+ * test through either path, and a flat list is what every test asserted
93
+ * against. `organizationSalesRepScopePort` is one implementation for both
94
+ * compositions, and it is `quote_requests`' `salesRepSubtree` wiring spelled
95
+ * once instead of a fourth time.
96
+ */
97
+ /** What `organizations` resolves from the container, and the names it owns. */
98
+ /**
99
+ * `OrganizationTaxProfilePort` was declared here and is
100
+ * `@endora-commerce/contracts`' since `specs/110-instance-repository/` T118.
101
+ * That is a correction rather than a relocation: it is a `providePort` name, so
102
+ * its type argument is a contract type and never the provider's own file
103
+ * (composition checklist item 3), and every consumer of the port had to name
104
+ * this package to spell the type it resolves.
105
+ *
106
+ * It is deliberately **not** re-exported from here. A transitional
107
+ * `export type { … }` was written and withdrawn: the barrel then re-exports a
108
+ * name whose source is another package, and
109
+ * `test/unit/packages/module-package-entity-surface.test.ts` refuses that as
110
+ * `unresolvable-reexport` — whether the barrel carries an entity class by name
111
+ * becomes *unknown* rather than false, which is the direction D-168 may not be
112
+ * wrong in. Two spellings for one type was the wrong shape anyway.
113
+ */
114
+ export interface OrganizationsCradle {
115
+ /**
116
+ * Feature 120 (FR-015) — the platform's channel-bridge registry, resolved by
117
+ * **container name** rather than imported. The shape is the narrow one this
118
+ * module needs, which is what `ctx.cradle<C>()` asks an author to declare;
119
+ * the registry itself is the kernel's and is published on no barrel.
120
+ */
121
+ readonly salesChannelBridgeRegistry: {
122
+ register(bridge: {
123
+ entityType: ChannelMemberEntityType;
124
+ table: string;
125
+ entityIdColumn: string;
126
+ }): void;
127
+ };
128
+ readonly emFactory: () => EntityManager;
129
+ readonly eventBus: EventBus;
130
+ readonly commandBus: CommandBus;
131
+ readonly auditLogService: AuditPort;
132
+ readonly settingsReadPort: SettingsReadPort;
133
+ readonly salesChannelResolutionPort: SalesChannelResolutionPort;
134
+ readonly requireAdmin: RequireAdminFactory;
135
+ readonly requireAdminAny: RequireAdminAnyFactory;
136
+ readonly requireCustomer: OrganizationsModuleOptions['requireCustomer'];
137
+ readonly customerContextResolver: OrganizationsModuleOptions['resolveCustomerContext'];
138
+ readonly customerAuthPort: CustomerAuthPort;
139
+ readonly passwordResetService: CustomerPasswordResetPort;
140
+ readonly customerRolePort: CustomerRolePort;
141
+ /**
142
+ * The two halves of `customer_accounts`' published surface this module runs
143
+ * its member lifecycle over (feature 075, Phase C). Every route file and
144
+ * three services named that module's entity before the cut.
145
+ */
146
+ readonly customerAccountReadPort: CustomerAccountReadPort;
147
+ readonly customerAccountMemberWritePort: CustomerAccountMemberWritePort;
148
+ readonly addressService: AddressServicePort;
149
+ readonly customFieldValueService: CustomFieldValuePort;
150
+ readonly dictionaryValidator: DictionaryValidator;
151
+ readonly emailMailer: EmailMailerPort;
152
+ readonly adminNotificationRecordPort: AdminNotificationRecordPort;
153
+ /** `price_lists`' own answer to "which lists are active" (feature 075, Phase C). */
154
+ readonly priceListReadPort: PriceListReadPort;
155
+ /**
156
+ * `transactional_emails`' own accessors since T120. The sender is late-bound
157
+ * — that module publishes it at route registration — and the template adapter
158
+ * is the one this module used to build for itself from a helper it owned.
159
+ */
160
+ readonly transactionalEmailSenderAccessor: () => TransactionalEmailSender | undefined;
161
+ readonly templateEmailPort: TemplateEmailPort;
162
+ readonly emailDefaultsPort: EmailDefaultsRegistryPort;
163
+ /**
164
+ * Deployment inputs. The storefront origin an invitation link points at is an
165
+ * environment fact; the probe is a harness fact — a route that hands back the
166
+ * last verification token must never exist in production.
167
+ */
168
+ readonly storefrontBaseUrl: string;
169
+ readonly organizationsExposeTestProbe: boolean;
170
+ /**
171
+ * Contribution point: what else a login must do. `carts` merges the anonymous
172
+ * cart, `comparisons` adopts the anonymous comparison. Points *outward* from
173
+ * this module to two that depend on it, so it cannot be a port; defaulted to
174
+ * doing nothing, which is a coherent login.
175
+ */
176
+ readonly organizationsLoginHook: NonNullable<OrganizationsModuleOptions['onLogin']>;
177
+ /**
178
+ * Contribution point: the VAT-ID clients. Production contributes nothing and
179
+ * this module talks to VIES and Ministerstwo Finansów; the harness scripts
180
+ * both, because no test may open that socket.
181
+ */
182
+ /**
183
+ * The two tax-ID adapters. **Both required**, unlike the service's own
184
+ * optional constructor fields: this module always registers a default pair
185
+ * and every composition that overrides them overrides both, so an optional
186
+ * type here would only be a way for `vatValidatorPort` to hand out
187
+ * `undefined` for a state no composition can produce (feature 076, D-86).
188
+ */
189
+ readonly organizationsTaxIdClients: {
190
+ readonly vies: VatValidator;
191
+ readonly mfPl: VatValidator;
192
+ };
193
+ readonly organizationReadPort: OrganizationReadPort;
194
+ readonly organizationRestrictionPort: OrganizationRestrictionService;
195
+ readonly organizationTreeService: OrganizationTreeService;
196
+ /** Owned by `admin_roles`: whether this rep holds the roll-up capability. */
197
+ readonly permissionService: {
198
+ hasPermission(adminUserId: string, permission: string): Promise<boolean>;
199
+ };
200
+ /**
201
+ * Which organizations a sales-rep admin may see, subtree-expanded when the
202
+ * rep holds `organizations:rollup` (feature 056 / T143a).
203
+ */
204
+ readonly organizationSalesRepScopePort: SalesRepAssignmentPort;
205
+ readonly organizationInheritancePort: OrganizationInheritanceService;
206
+ readonly organizationModerationService: OrganizationModerationService;
207
+ readonly organizationRegistrationNotifier: OrgRegistrationNotifier;
208
+ readonly organizations: ReturnType<typeof organizationsModule>;
209
+ }
210
+ export declare function registerModule(ctx: ModuleContext): void;
211
+ /**
212
+ * The module's persisted entity classes, on the `./backend` subpath, as one
213
+ * array and **no named class export** (D-168).
214
+ *
215
+ * This is the shape the platform reads when the package is *installed*: the
216
+ * boot-time loader (`src/packages/package-runtime.ts`, `exported['entities']`)
217
+ * and the static declaration reader (`scripts/lib/package-declarations.ts`),
218
+ * which is the third source of `check:module-boundary`'s `table->owner` map and
219
+ * the package pass of `check-entity-tenant-classification`. A missing array is
220
+ * answered with `[]` — zero entities registered, no error anywhere.
221
+ *
222
+ * The order is the one `db/entities-registry.generated.ts` declared before this
223
+ * module became a package, so the registered set is the same list in the same
224
+ * sequence.
225
+ */
226
+ export declare const entities: (typeof Organization | typeof OrganizationPaymentMethodLink | typeof OrganizationDeliveryMethodLink | typeof OrganizationWarehouseLink | typeof EmailVerificationToken | typeof OrganizationTaxIdValidation | typeof OrganizationSalesRepAssignment | typeof OrganizationInvitation)[];
227
+ /**
228
+ * Published for the composition root, which contributes these shapes and must
229
+ * name their types. It reached the source files by relative path until
230
+ * 2026-08-26, which is `TS6059` under `backend/tsconfig.build.json`'s
231
+ * `rootDir` — even for an `import type`, because a type-only import still
232
+ * joins the program. Nothing in `backend/src` may name a package's source, so
233
+ * the type has to arrive through the published subpath.
234
+ */
235
+ export type { OrganizationTreeService } from './services/organization-tree-service.js';
236
+ /**
237
+ * The sales-channel membership bridge this module owns (feature 120, FR-015).
238
+ *
239
+ * Exported as well as registered because the owning module is the only honest
240
+ * source for it: a caller that composes no platform — the bare-database test
241
+ * harness, which constructs the kernel's membership service directly — declares
242
+ * these from here rather than from a list of nine it keeps itself, which is
243
+ * exactly the total map this feature deleted.
244
+ */
245
+ export declare const salesChannelBridges: ReadonlyArray<{
246
+ readonly entityType: ChannelMemberEntityType;
247
+ readonly table: string;
248
+ readonly entityIdColumn: string;
249
+ }>;
250
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/backend/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,KAAK,EACV,kBAAkB,EAClB,2BAA2B,EAG3B,oBAAoB,EACpB,8BAA8B,EAC9B,uBAAuB,EACvB,gBAAgB,EACh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