@endora-commerce/contracts 0.109.0 → 0.111.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 (385) hide show
  1. package/dist/accept-language.d.ts +31 -0
  2. package/dist/accept-language.js +64 -0
  3. package/dist/actor.d.ts +16 -0
  4. package/dist/addresses.d.ts +35 -0
  5. package/dist/addresses.js +8 -1
  6. package/dist/admin-actions.d.ts +2 -0
  7. package/dist/admin-actions.js +18 -0
  8. package/dist/admin-contributions.d.ts +99 -12
  9. package/dist/admin-contributions.js +36 -10
  10. package/dist/admin-roles.d.ts +17 -2
  11. package/dist/admin-users.d.ts +9 -0
  12. package/dist/admin.d.ts +114 -4
  13. package/dist/admin.js +98 -3
  14. package/dist/api-keys.d.ts +22 -0
  15. package/dist/api-keys.js +4 -0
  16. package/dist/assets-library.d.ts +45 -0
  17. package/dist/assets-library.js +20 -3
  18. package/dist/audit-logs.d.ts +12 -0
  19. package/dist/audit-logs.js +12 -0
  20. package/dist/auth.d.ts +9 -0
  21. package/dist/auth.js +9 -0
  22. package/dist/blog.d.ts +382 -22
  23. package/dist/blog.js +199 -17
  24. package/dist/carts.d.ts +423 -36
  25. package/dist/carts.js +150 -12
  26. package/dist/catalog.d.ts +379 -208
  27. package/dist/catalog.js +241 -163
  28. package/dist/cms-brand.d.ts +14 -14
  29. package/dist/cms.d.ts +71 -16
  30. package/dist/cms.js +15 -0
  31. package/dist/command-hooks.d.ts +301 -0
  32. package/dist/command-hooks.js +248 -0
  33. package/dist/common.d.ts +23 -6
  34. package/dist/common.js +25 -2
  35. package/dist/comparisons.d.ts +21 -14
  36. package/dist/comparisons.js +2 -1
  37. package/dist/credit-limits.d.ts +22 -0
  38. package/dist/credit-limits.js +35 -0
  39. package/dist/crm.d.ts +134 -78
  40. package/dist/crm.js +21 -5
  41. package/dist/custom-fields.d.ts +417 -49
  42. package/dist/custom-fields.js +142 -1
  43. package/dist/customer-accounts.d.ts +324 -22
  44. package/dist/customer-accounts.js +43 -0
  45. package/dist/customer-notifications.d.ts +143 -0
  46. package/dist/customer-notifications.js +41 -0
  47. package/dist/customers.d.ts +92 -73
  48. package/dist/customers.js +98 -10
  49. package/dist/dictionary.d.ts +53 -0
  50. package/dist/dictionary.js +25 -0
  51. package/dist/document-templates.d.ts +12 -12
  52. package/dist/email.d.ts +34 -0
  53. package/dist/email.js +6 -0
  54. package/dist/errors.d.ts +431 -3
  55. package/dist/errors.js +523 -3
  56. package/dist/forms-logic.d.ts +79 -0
  57. package/dist/forms-logic.fixtures.d.ts +52 -0
  58. package/dist/forms-logic.fixtures.js +610 -0
  59. package/dist/forms-logic.js +699 -0
  60. package/dist/forms.d.ts +9833 -0
  61. package/dist/forms.js +827 -0
  62. package/dist/i18n.d.ts +34 -0
  63. package/dist/i18n.js +15 -0
  64. package/dist/import-export.d.ts +180 -0
  65. package/dist/import-export.js +60 -0
  66. package/dist/index.d.ts +16 -1
  67. package/dist/index.js +30 -1
  68. package/dist/inventory.d.ts +9 -9
  69. package/dist/invoice-ledger.d.ts +13 -13
  70. package/dist/invoices.d.ts +126 -0
  71. package/dist/invoices.js +53 -0
  72. package/dist/line-bounds.d.ts +53 -0
  73. package/dist/line-bounds.js +65 -0
  74. package/dist/megamenu.d.ts +27 -27
  75. package/dist/mfa.d.ts +210 -4
  76. package/dist/mfa.js +136 -0
  77. package/dist/modules.d.ts +56 -8
  78. package/dist/modules.js +128 -3
  79. package/dist/money-decimal.d.ts +54 -0
  80. package/dist/money-decimal.js +95 -0
  81. package/dist/newsletter.d.ts +4 -4
  82. package/dist/orders.d.ts +246 -12
  83. package/dist/orders.js +140 -7
  84. package/dist/organization-hooks.d.ts +99 -0
  85. package/dist/organization-hooks.js +22 -0
  86. package/dist/organization-registry-lookup.d.ts +362 -0
  87. package/dist/organization-registry-lookup.js +196 -0
  88. package/dist/organization-roles.d.ts +341 -0
  89. package/dist/organization-roles.js +218 -0
  90. package/dist/organizations.d.ts +1074 -103
  91. package/dist/organizations.js +293 -28
  92. package/dist/page-builder-props.d.ts +56 -56
  93. package/dist/pim-connector.d.ts +7 -3
  94. package/dist/pim-connector.js +6 -2
  95. package/dist/pim-field-path.d.ts +5 -1
  96. package/dist/pim-field-path.js +37 -81
  97. package/dist/pim-locale-mapping.d.ts +131 -0
  98. package/dist/pim-locale-mapping.js +193 -0
  99. package/dist/price-books.d.ts +215 -63
  100. package/dist/price-books.js +47 -2
  101. package/dist/price-lists.d.ts +13 -10
  102. package/dist/product-feeds.d.ts +249 -100
  103. package/dist/product-feeds.js +46 -2
  104. package/dist/product-scope-model.d.ts +161 -0
  105. package/dist/product-scope-model.js +161 -0
  106. package/dist/product-scope-overrides.d.ts +0 -103
  107. package/dist/product-scope-overrides.js +0 -54
  108. package/dist/product-scoped-values.d.ts +2610 -0
  109. package/dist/product-scoped-values.js +425 -0
  110. package/dist/product-scopes.d.ts +199 -64
  111. package/dist/product-scopes.js +120 -23
  112. package/dist/product-tax-rates.d.ts +38 -0
  113. package/dist/product-tax-rates.js +45 -0
  114. package/dist/product-url-keys.d.ts +51 -45
  115. package/dist/product-url-keys.js +73 -39
  116. package/dist/product-value-resolver.d.ts +37 -60
  117. package/dist/product-value-resolver.js +36 -96
  118. package/dist/projects.d.ts +76 -28
  119. package/dist/projects.js +53 -9
  120. package/dist/promotions.d.ts +163 -11
  121. package/dist/promotions.js +23 -1
  122. package/dist/pwa.d.ts +41 -2
  123. package/dist/quick-order.d.ts +159 -9
  124. package/dist/quick-order.js +79 -4
  125. package/dist/quote-requests.d.ts +231 -17
  126. package/dist/quote-requests.js +111 -9
  127. package/dist/record-references.d.ts +15 -15
  128. package/dist/record-references.js +2 -3
  129. package/dist/record-rich-text.js +2 -1
  130. package/dist/returns.d.ts +214 -52
  131. package/dist/returns.js +143 -28
  132. package/dist/sales-channels.d.ts +34 -3
  133. package/dist/sales-channels.js +16 -1
  134. package/dist/saved-list-views.d.ts +28 -0
  135. package/dist/saved-list-views.js +14 -1
  136. package/dist/schema-extensions.d.ts +36 -0
  137. package/dist/schema-extensions.js +29 -0
  138. package/dist/scoped-write-encoding.d.ts +100 -0
  139. package/dist/scoped-write-encoding.js +135 -0
  140. package/dist/search.d.ts +18 -16
  141. package/dist/seo.d.ts +83 -30
  142. package/dist/seo.js +8 -1
  143. package/dist/settings.d.ts +173 -2
  144. package/dist/settings.js +53 -2
  145. package/dist/shopping-lists.d.ts +63 -4
  146. package/dist/shopping-lists.js +57 -3
  147. package/dist/storefront-cache-tags.d.ts +22 -0
  148. package/dist/storefront-cache-tags.js +12 -0
  149. package/dist/storefront-value-overrides.d.ts +18 -56
  150. package/dist/storefront-value-overrides.js +11 -86
  151. package/dist/tasks.d.ts +27 -27
  152. package/dist/taxes.d.ts +27 -0
  153. package/dist/taxes.js +4 -0
  154. package/dist/transactional-emails.d.ts +48 -22
  155. package/dist/webhooks.d.ts +75 -0
  156. package/dist/webhooks.js +24 -0
  157. package/package.json +5 -3
  158. package/dist/actor.d.ts.map +0 -1
  159. package/dist/actor.js.map +0 -1
  160. package/dist/addresses.d.ts.map +0 -1
  161. package/dist/addresses.js.map +0 -1
  162. package/dist/admin-actions.d.ts.map +0 -1
  163. package/dist/admin-actions.js.map +0 -1
  164. package/dist/admin-contributions.d.ts.map +0 -1
  165. package/dist/admin-contributions.js.map +0 -1
  166. package/dist/admin-feedback.d.ts.map +0 -1
  167. package/dist/admin-feedback.js.map +0 -1
  168. package/dist/admin-i18n.d.ts.map +0 -1
  169. package/dist/admin-i18n.js.map +0 -1
  170. package/dist/admin-name.d.ts.map +0 -1
  171. package/dist/admin-name.js.map +0 -1
  172. package/dist/admin-notifications.d.ts.map +0 -1
  173. package/dist/admin-notifications.js.map +0 -1
  174. package/dist/admin-preferences.d.ts.map +0 -1
  175. package/dist/admin-preferences.js.map +0 -1
  176. package/dist/admin-roles.d.ts.map +0 -1
  177. package/dist/admin-roles.js.map +0 -1
  178. package/dist/admin-search.d.ts.map +0 -1
  179. package/dist/admin-search.js.map +0 -1
  180. package/dist/admin-users.d.ts.map +0 -1
  181. package/dist/admin-users.js.map +0 -1
  182. package/dist/admin.d.ts.map +0 -1
  183. package/dist/admin.js.map +0 -1
  184. package/dist/analytics.d.ts.map +0 -1
  185. package/dist/analytics.js.map +0 -1
  186. package/dist/api-keys.d.ts.map +0 -1
  187. package/dist/api-keys.js.map +0 -1
  188. package/dist/assets-library.d.ts.map +0 -1
  189. package/dist/assets-library.js.map +0 -1
  190. package/dist/audit-logs.d.ts.map +0 -1
  191. package/dist/audit-logs.js.map +0 -1
  192. package/dist/auth.d.ts.map +0 -1
  193. package/dist/auth.js.map +0 -1
  194. package/dist/blog.d.ts.map +0 -1
  195. package/dist/blog.js.map +0 -1
  196. package/dist/capabilities.d.ts.map +0 -1
  197. package/dist/capabilities.js.map +0 -1
  198. package/dist/carts.d.ts.map +0 -1
  199. package/dist/carts.js.map +0 -1
  200. package/dist/catalog.d.ts.map +0 -1
  201. package/dist/catalog.js.map +0 -1
  202. package/dist/cms-brand.d.ts.map +0 -1
  203. package/dist/cms-brand.js.map +0 -1
  204. package/dist/cms-contact-form.d.ts.map +0 -1
  205. package/dist/cms-contact-form.js.map +0 -1
  206. package/dist/cms.d.ts.map +0 -1
  207. package/dist/cms.js.map +0 -1
  208. package/dist/common.d.ts.map +0 -1
  209. package/dist/common.js.map +0 -1
  210. package/dist/comparisons.d.ts.map +0 -1
  211. package/dist/comparisons.js.map +0 -1
  212. package/dist/credentials.d.ts.map +0 -1
  213. package/dist/credentials.js.map +0 -1
  214. package/dist/credit-limits.d.ts.map +0 -1
  215. package/dist/credit-limits.js.map +0 -1
  216. package/dist/crm-rich-text.d.ts.map +0 -1
  217. package/dist/crm-rich-text.js.map +0 -1
  218. package/dist/crm.d.ts.map +0 -1
  219. package/dist/crm.js.map +0 -1
  220. package/dist/currencies.d.ts.map +0 -1
  221. package/dist/currencies.js.map +0 -1
  222. package/dist/custom-fields.d.ts.map +0 -1
  223. package/dist/custom-fields.js.map +0 -1
  224. package/dist/customer-accounts.d.ts.map +0 -1
  225. package/dist/customer-accounts.js.map +0 -1
  226. package/dist/customers.d.ts.map +0 -1
  227. package/dist/customers.js.map +0 -1
  228. package/dist/dictionary.d.ts.map +0 -1
  229. package/dist/dictionary.js.map +0 -1
  230. package/dist/document-templates.d.ts.map +0 -1
  231. package/dist/document-templates.js.map +0 -1
  232. package/dist/document-values.d.ts.map +0 -1
  233. package/dist/document-values.js.map +0 -1
  234. package/dist/email-address.d.ts.map +0 -1
  235. package/dist/email-address.js.map +0 -1
  236. package/dist/email.d.ts.map +0 -1
  237. package/dist/email.js.map +0 -1
  238. package/dist/envelopes.d.ts.map +0 -1
  239. package/dist/envelopes.js.map +0 -1
  240. package/dist/environment-inputs.d.ts.map +0 -1
  241. package/dist/environment-inputs.js.map +0 -1
  242. package/dist/erp-connector.d.ts.map +0 -1
  243. package/dist/erp-connector.js.map +0 -1
  244. package/dist/errors.d.ts.map +0 -1
  245. package/dist/errors.js.map +0 -1
  246. package/dist/google-analytics.d.ts.map +0 -1
  247. package/dist/google-analytics.js.map +0 -1
  248. package/dist/google-tag-manager.d.ts.map +0 -1
  249. package/dist/google-tag-manager.js.map +0 -1
  250. package/dist/i18n.d.ts.map +0 -1
  251. package/dist/i18n.js.map +0 -1
  252. package/dist/import-export.d.ts.map +0 -1
  253. package/dist/import-export.js.map +0 -1
  254. package/dist/index.d.ts.map +0 -1
  255. package/dist/index.js.map +0 -1
  256. package/dist/inventory.d.ts.map +0 -1
  257. package/dist/inventory.js.map +0 -1
  258. package/dist/invoice-ledger.d.ts.map +0 -1
  259. package/dist/invoice-ledger.js.map +0 -1
  260. package/dist/invoices.d.ts.map +0 -1
  261. package/dist/invoices.js.map +0 -1
  262. package/dist/kernel.d.ts.map +0 -1
  263. package/dist/kernel.js.map +0 -1
  264. package/dist/languages.d.ts.map +0 -1
  265. package/dist/languages.js.map +0 -1
  266. package/dist/line-groups.d.ts.map +0 -1
  267. package/dist/line-groups.js.map +0 -1
  268. package/dist/linkedin-ads.d.ts.map +0 -1
  269. package/dist/linkedin-ads.js.map +0 -1
  270. package/dist/localized-name.d.ts.map +0 -1
  271. package/dist/localized-name.js.map +0 -1
  272. package/dist/megamenu.d.ts.map +0 -1
  273. package/dist/megamenu.js.map +0 -1
  274. package/dist/meta-ads.d.ts.map +0 -1
  275. package/dist/meta-ads.js.map +0 -1
  276. package/dist/mfa.d.ts.map +0 -1
  277. package/dist/mfa.js.map +0 -1
  278. package/dist/modules.d.ts.map +0 -1
  279. package/dist/modules.js.map +0 -1
  280. package/dist/money-decimal.d.ts.map +0 -1
  281. package/dist/money-decimal.js.map +0 -1
  282. package/dist/money-input.d.ts.map +0 -1
  283. package/dist/money-input.js.map +0 -1
  284. package/dist/newsletter.d.ts.map +0 -1
  285. package/dist/newsletter.js.map +0 -1
  286. package/dist/order-minimums.d.ts.map +0 -1
  287. package/dist/order-minimums.js.map +0 -1
  288. package/dist/orders.d.ts.map +0 -1
  289. package/dist/orders.js.map +0 -1
  290. package/dist/organizations.d.ts.map +0 -1
  291. package/dist/organizations.js.map +0 -1
  292. package/dist/page-builder-props.d.ts.map +0 -1
  293. package/dist/page-builder-props.js.map +0 -1
  294. package/dist/page-builder-values.d.ts.map +0 -1
  295. package/dist/page-builder-values.js.map +0 -1
  296. package/dist/pagination.d.ts.map +0 -1
  297. package/dist/pagination.js.map +0 -1
  298. package/dist/payment-methods.d.ts.map +0 -1
  299. package/dist/payment-methods.js.map +0 -1
  300. package/dist/payment-return-url.d.ts.map +0 -1
  301. package/dist/payment-return-url.js.map +0 -1
  302. package/dist/payments.d.ts.map +0 -1
  303. package/dist/payments.js.map +0 -1
  304. package/dist/pim-connector.d.ts.map +0 -1
  305. package/dist/pim-connector.js.map +0 -1
  306. package/dist/pim-field-path.d.ts.map +0 -1
  307. package/dist/pim-field-path.js.map +0 -1
  308. package/dist/platform-info.d.ts.map +0 -1
  309. package/dist/platform-info.js.map +0 -1
  310. package/dist/platform-language.d.ts.map +0 -1
  311. package/dist/platform-language.js.map +0 -1
  312. package/dist/price-book-decimal.d.ts.map +0 -1
  313. package/dist/price-book-decimal.js.map +0 -1
  314. package/dist/price-books.d.ts.map +0 -1
  315. package/dist/price-books.js.map +0 -1
  316. package/dist/price-lists.d.ts.map +0 -1
  317. package/dist/price-lists.js.map +0 -1
  318. package/dist/product-feeds.d.ts.map +0 -1
  319. package/dist/product-feeds.js.map +0 -1
  320. package/dist/product-scope-overrides.d.ts.map +0 -1
  321. package/dist/product-scope-overrides.js.map +0 -1
  322. package/dist/product-scopes.d.ts.map +0 -1
  323. package/dist/product-scopes.js.map +0 -1
  324. package/dist/product-summary-text.d.ts.map +0 -1
  325. package/dist/product-summary-text.js.map +0 -1
  326. package/dist/product-url-keys.d.ts.map +0 -1
  327. package/dist/product-url-keys.js.map +0 -1
  328. package/dist/product-value-resolver.d.ts.map +0 -1
  329. package/dist/product-value-resolver.js.map +0 -1
  330. package/dist/projects.d.ts.map +0 -1
  331. package/dist/projects.js.map +0 -1
  332. package/dist/promotions.d.ts.map +0 -1
  333. package/dist/promotions.js.map +0 -1
  334. package/dist/prompt-actions.d.ts.map +0 -1
  335. package/dist/prompt-actions.js.map +0 -1
  336. package/dist/pwa.d.ts.map +0 -1
  337. package/dist/pwa.js.map +0 -1
  338. package/dist/quick-order.d.ts.map +0 -1
  339. package/dist/quick-order.js.map +0 -1
  340. package/dist/quote-requests.d.ts.map +0 -1
  341. package/dist/quote-requests.js.map +0 -1
  342. package/dist/record-references.d.ts.map +0 -1
  343. package/dist/record-references.js.map +0 -1
  344. package/dist/record-rich-text.d.ts.map +0 -1
  345. package/dist/record-rich-text.js.map +0 -1
  346. package/dist/returns.d.ts.map +0 -1
  347. package/dist/returns.js.map +0 -1
  348. package/dist/sales-channels.d.ts.map +0 -1
  349. package/dist/sales-channels.js.map +0 -1
  350. package/dist/saved-list-views.d.ts.map +0 -1
  351. package/dist/saved-list-views.js.map +0 -1
  352. package/dist/scope-notice.d.ts.map +0 -1
  353. package/dist/scope-notice.js.map +0 -1
  354. package/dist/scoped-translations.d.ts +0 -48
  355. package/dist/scoped-translations.d.ts.map +0 -1
  356. package/dist/scoped-translations.js +0 -78
  357. package/dist/scoped-translations.js.map +0 -1
  358. package/dist/search.d.ts.map +0 -1
  359. package/dist/search.js.map +0 -1
  360. package/dist/seo.d.ts.map +0 -1
  361. package/dist/seo.js.map +0 -1
  362. package/dist/settings.d.ts.map +0 -1
  363. package/dist/settings.js.map +0 -1
  364. package/dist/shipments.d.ts.map +0 -1
  365. package/dist/shipments.js.map +0 -1
  366. package/dist/shipping-methods.d.ts.map +0 -1
  367. package/dist/shipping-methods.js.map +0 -1
  368. package/dist/shopping-lists.d.ts.map +0 -1
  369. package/dist/shopping-lists.js.map +0 -1
  370. package/dist/storefront-cache-tags.d.ts.map +0 -1
  371. package/dist/storefront-cache-tags.js.map +0 -1
  372. package/dist/storefront-language-path.d.ts.map +0 -1
  373. package/dist/storefront-language-path.js.map +0 -1
  374. package/dist/storefront-value-overrides.d.ts.map +0 -1
  375. package/dist/storefront-value-overrides.js.map +0 -1
  376. package/dist/tasks.d.ts.map +0 -1
  377. package/dist/tasks.js.map +0 -1
  378. package/dist/taxes.d.ts.map +0 -1
  379. package/dist/taxes.js.map +0 -1
  380. package/dist/text-normalization.d.ts.map +0 -1
  381. package/dist/text-normalization.js.map +0 -1
  382. package/dist/transactional-emails.d.ts.map +0 -1
  383. package/dist/transactional-emails.js.map +0 -1
  384. package/dist/webhooks.d.ts.map +0 -1
  385. package/dist/webhooks.js.map +0 -1
@@ -0,0 +1,341 @@
1
+ import { z } from 'zod';
2
+ import type { Actor } from './actor.js';
3
+ /**
4
+ * Organization roles and organization permissions — the buyer's side of
5
+ * "who may do what" (`specs/170-organization-roles/`).
6
+ *
7
+ * An Organization holds two predefined roles — *Administrator* (every present
8
+ * permission, immutable) and *Member* (editable) — and up to fifty custom ones.
9
+ * Each member holds exactly one. A role is a set of **organization permission**
10
+ * codes (`<module>.<action>`), declared by the module whose buyer action each
11
+ * gates in its manifest's `organizationPermissions` field (`./modules.ts`).
12
+ * The operator vocabulary (`<area>:<action>`, `/admin-roles`) is a different
13
+ * one and the two never meet (FR-020, research R-2).
14
+ *
15
+ * Normative: `specs/170-organization-roles/contracts/organization-permission-port.md`
16
+ * and `contracts/storefront-api.md` §2. They replaced the legacy two-value role
17
+ * enum, removed with its columns by the feature's legacy-removal package
18
+ * (research R-23).
19
+ */
20
+ export declare const organizationRoleKindSchema: z.ZodEnum<{
21
+ custom: "custom";
22
+ administrator: "administrator";
23
+ member: "member";
24
+ }>;
25
+ export type OrganizationRoleKind = z.infer<typeof organizationRoleKindSchema>;
26
+ /**
27
+ * The role as every response shows it (FR-008, FR-056, FR-073). `name` is the
28
+ * translated label for `administrator` / `member` in the response language and
29
+ * the stored name for `custom`.
30
+ */
31
+ export declare const organizationRoleRefSchema: z.ZodObject<{
32
+ id: z.ZodString;
33
+ name: z.ZodString;
34
+ kind: z.ZodEnum<{
35
+ custom: "custom";
36
+ administrator: "administrator";
37
+ member: "member";
38
+ }>;
39
+ }, z.core.$strict>;
40
+ export type OrganizationRoleRef = z.infer<typeof organizationRoleRefSchema>;
41
+ /**
42
+ * One role on the role-management screens, storefront and Admin UI alike
43
+ * (`contracts/storefront-api.md` §2). `permissions` are the stored grants of
44
+ * **present** codes only — a grant of a switched-off module's code is kept
45
+ * server-side and never round-trips through the editor (FR-025); for the
46
+ * administrator it is every present code. `pendingInvitationCount` counts
47
+ * invitations neither accepted, revoked nor expired (FR-010a).
48
+ */
49
+ export declare const organizationRoleViewSchema: z.ZodObject<{
50
+ id: z.ZodString;
51
+ kind: z.ZodEnum<{
52
+ custom: "custom";
53
+ administrator: "administrator";
54
+ member: "member";
55
+ }>;
56
+ name: z.ZodString;
57
+ description: z.ZodNullable<z.ZodString>;
58
+ permissions: z.ZodArray<z.ZodString>;
59
+ memberCount: z.ZodNumber;
60
+ pendingInvitationCount: z.ZodNumber;
61
+ version: z.ZodNumber;
62
+ updatedAt: z.ZodString;
63
+ }, z.core.$strip>;
64
+ export type OrganizationRoleView = z.infer<typeof organizationRoleViewSchema>;
65
+ export declare const organizationRoleListResponseSchema: z.ZodObject<{
66
+ data: z.ZodArray<z.ZodObject<{
67
+ id: z.ZodString;
68
+ kind: z.ZodEnum<{
69
+ custom: "custom";
70
+ administrator: "administrator";
71
+ member: "member";
72
+ }>;
73
+ name: z.ZodString;
74
+ description: z.ZodNullable<z.ZodString>;
75
+ permissions: z.ZodArray<z.ZodString>;
76
+ memberCount: z.ZodNumber;
77
+ pendingInvitationCount: z.ZodNumber;
78
+ version: z.ZodNumber;
79
+ updatedAt: z.ZodString;
80
+ }, z.core.$strip>>;
81
+ }, z.core.$strip>;
82
+ export type OrganizationRoleListResponse = z.infer<typeof organizationRoleListResponseSchema>;
83
+ export declare const organizationRoleResponseSchema: z.ZodObject<{
84
+ data: z.ZodObject<{
85
+ id: z.ZodString;
86
+ kind: z.ZodEnum<{
87
+ custom: "custom";
88
+ administrator: "administrator";
89
+ member: "member";
90
+ }>;
91
+ name: z.ZodString;
92
+ description: z.ZodNullable<z.ZodString>;
93
+ permissions: z.ZodArray<z.ZodString>;
94
+ memberCount: z.ZodNumber;
95
+ pendingInvitationCount: z.ZodNumber;
96
+ version: z.ZodNumber;
97
+ updatedAt: z.ZodString;
98
+ }, z.core.$strip>;
99
+ }, z.core.$strip>;
100
+ export type OrganizationRoleResponse = z.infer<typeof organizationRoleResponseSchema>;
101
+ /** One grantable code, translated in the request language (R-31). */
102
+ export declare const organizationPermissionCatalogueEntrySchema: z.ZodObject<{
103
+ code: z.ZodString;
104
+ label: z.ZodString;
105
+ description: z.ZodString;
106
+ memberDefault: z.ZodBoolean;
107
+ }, z.core.$strip>;
108
+ export type OrganizationPermissionCatalogueEntry = z.infer<typeof organizationPermissionCatalogueEntrySchema>;
109
+ /** `GET …/permission-catalogue` — present codes only, grouped by declaring module. */
110
+ export declare const organizationPermissionCatalogueResponseSchema: z.ZodObject<{
111
+ data: z.ZodObject<{
112
+ groups: z.ZodArray<z.ZodObject<{
113
+ moduleId: z.ZodString;
114
+ moduleLabel: z.ZodString;
115
+ permissions: z.ZodArray<z.ZodObject<{
116
+ code: z.ZodString;
117
+ label: z.ZodString;
118
+ description: z.ZodString;
119
+ memberDefault: z.ZodBoolean;
120
+ }, z.core.$strip>>;
121
+ }, z.core.$strip>>;
122
+ }, z.core.$strip>;
123
+ }, z.core.$strip>;
124
+ export type OrganizationPermissionCatalogueResponse = z.infer<typeof organizationPermissionCatalogueResponseSchema>;
125
+ /** `GET /api/v1/organizations/mine/role` — the member's own role (FR-058). */
126
+ export declare const organizationOwnRoleResponseSchema: z.ZodObject<{
127
+ data: z.ZodObject<{
128
+ role: z.ZodObject<{
129
+ id: z.ZodString;
130
+ name: z.ZodString;
131
+ kind: z.ZodEnum<{
132
+ custom: "custom";
133
+ administrator: "administrator";
134
+ member: "member";
135
+ }>;
136
+ }, z.core.$strict>;
137
+ permissions: z.ZodArray<z.ZodObject<{
138
+ code: z.ZodString;
139
+ label: z.ZodString;
140
+ description: z.ZodString;
141
+ }, z.core.$strip>>;
142
+ }, z.core.$strip>;
143
+ }, z.core.$strip>;
144
+ export type OrganizationOwnRoleResponse = z.infer<typeof organizationOwnRoleResponseSchema>;
145
+ /** `DELETE …/roles/:id` — what moved to the replacement role (FR-024). */
146
+ export declare const deleteOrganizationRoleResponseSchema: z.ZodObject<{
147
+ data: z.ZodObject<{
148
+ reassignedMembers: z.ZodNumber;
149
+ reassignedInvitations: z.ZodNumber;
150
+ }, z.core.$strip>;
151
+ }, z.core.$strip>;
152
+ export type DeleteOrganizationRoleResponse = z.infer<typeof deleteOrganizationRoleResponseSchema>;
153
+ /** `POST …/roles` — a custom role. */
154
+ export declare const createOrganizationRoleRequestSchema: z.ZodObject<{
155
+ name: z.ZodString;
156
+ description: z.ZodOptional<z.ZodString>;
157
+ permissions: z.ZodArray<z.ZodString>;
158
+ }, z.core.$strict>;
159
+ export type CreateOrganizationRoleRequest = z.infer<typeof createOrganizationRoleRequestSchema>;
160
+ /**
161
+ * `PATCH …/roles/:id`. `expectedVersion` is the version the editor read
162
+ * (`ORGANIZATION_ROLE_STALE` on mismatch, R-29); `name` and `description` are
163
+ * refused for the *Member* role by the Command, not by the schema.
164
+ */
165
+ export declare const updateOrganizationRoleRequestSchema: z.ZodObject<{
166
+ expectedVersion: z.ZodNumber;
167
+ name: z.ZodOptional<z.ZodString>;
168
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
169
+ permissions: z.ZodOptional<z.ZodArray<z.ZodString>>;
170
+ }, z.core.$strict>;
171
+ export type UpdateOrganizationRoleRequest = z.infer<typeof updateOrganizationRoleRequestSchema>;
172
+ /** `DELETE …/roles/:id`. A held role needs a replacement (FR-024). */
173
+ export declare const deleteOrganizationRoleRequestSchema: z.ZodObject<{
174
+ expectedVersion: z.ZodNumber;
175
+ replacementRoleId: z.ZodOptional<z.ZodString>;
176
+ }, z.core.$strict>;
177
+ export type DeleteOrganizationRoleRequest = z.infer<typeof deleteOrganizationRoleRequestSchema>;
178
+ /**
179
+ * `PATCH /api/v1/organizations/mine/members/:id/role` — replaces the legacy
180
+ * `changeMemberRoleRequestSchema` (`{ role }`).
181
+ */
182
+ export declare const assignMemberRoleRequestSchema: z.ZodObject<{
183
+ roleId: z.ZodString;
184
+ }, z.core.$strict>;
185
+ export type AssignMemberRoleRequest = z.infer<typeof assignMemberRoleRequestSchema>;
186
+ /**
187
+ * Inviting a member, on the storefront and in the Admin UI
188
+ * (`POST …/mine/invitations`, `POST /api/v1/admin/organizations/:id/members/invite`)
189
+ * — replaces the legacy `inviteMemberRequestSchema` (`{ email, role? }`). An
190
+ * absent `roleId` is the Organization's *Member* role, resolved server-side.
191
+ */
192
+ export declare const inviteMemberToRoleRequestSchema: z.ZodObject<{
193
+ email: z.ZodString;
194
+ roleId: z.ZodOptional<z.ZodString>;
195
+ }, z.core.$strict>;
196
+ export type InviteMemberToRoleRequest = z.infer<typeof inviteMemberToRoleRequestSchema>;
197
+ /**
198
+ * Platform admin — `POST /api/v1/admin/organizations/:id/members` (direct
199
+ * create). Replaces the legacy `adminDirectMemberRequestSchema`'s `role?`.
200
+ */
201
+ export declare const adminDirectMemberToRoleRequestSchema: z.ZodObject<{
202
+ email: z.ZodString;
203
+ firstName: z.ZodString;
204
+ lastName: z.ZodString;
205
+ password: z.ZodString;
206
+ roleId: z.ZodOptional<z.ZodString>;
207
+ customFieldValues: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
208
+ }, z.core.$strict>;
209
+ export type AdminDirectMemberToRoleRequest = z.infer<typeof adminDirectMemberToRoleRequestSchema>;
210
+ /**
211
+ * Platform admin — `PATCH /api/v1/admin/organizations/:id/members/:customerAccountId/role`.
212
+ * Replaces the legacy `adminPatchMemberRoleRequestSchema` (`{ role, expectedUpdatedAt? }`).
213
+ */
214
+ export declare const adminAssignMemberRoleRequestSchema: z.ZodObject<{
215
+ roleId: z.ZodString;
216
+ expectedUpdatedAt: z.ZodOptional<z.ZodString>;
217
+ }, z.core.$strict>;
218
+ export type AdminAssignMemberRoleRequest = z.infer<typeof adminAssignMemberRoleRequestSchema>;
219
+ /** Who is being judged. `organizationRoleId` is the actor's when known (R-15). */
220
+ export interface OrganizationPermissionSubject {
221
+ readonly customerAccountId: string;
222
+ readonly organizationId: string;
223
+ readonly organizationRoleId?: string | null;
224
+ }
225
+ export interface OrganizationEffectivePermissions {
226
+ readonly role: {
227
+ readonly id: string;
228
+ readonly kind: OrganizationRoleKind;
229
+ };
230
+ /** Sorted; present codes only (FR-007). */
231
+ readonly permissions: readonly string[];
232
+ }
233
+ /**
234
+ * Container name: `organizationPermissionPort`. Owner: `organizations`.
235
+ *
236
+ * Reached with `lazyPort<OrganizationPermissionPort>(ctx, 'organizationPermissionPort')`
237
+ * and never captured into a singleton. A subject whose role cannot be found in
238
+ * its Organization fails **closed**: `can` and `isAdministrator` answer `false`,
239
+ * `effective` an empty set. A code outside the vocabulary is a programming
240
+ * error: `can` answers `false`, `assert` throws `500 INTERNAL` (the permission
241
+ * inventory refuses such a call statically as well).
242
+ */
243
+ export interface OrganizationPermissionPort {
244
+ can(subject: OrganizationPermissionSubject, code: string): Promise<boolean>;
245
+ /**
246
+ * Throws `403 ORGANIZATION_PERMISSION_REQUIRED` with
247
+ * `details: { permission, permissionLabel }`. `language` selects the label.
248
+ */
249
+ assert(subject: OrganizationPermissionSubject, code: string, options?: {
250
+ language?: string;
251
+ }): Promise<void>;
252
+ isAdministrator(subject: OrganizationPermissionSubject): Promise<boolean>;
253
+ effective(subject: OrganizationPermissionSubject): Promise<OrganizationEffectivePermissions>;
254
+ /** Role ids of `organizationId` whose effective set holds `code` — administrator included. */
255
+ rolesHolding(organizationId: string, code: string): Promise<readonly string[]>;
256
+ }
257
+ /** Container name: `organizationRoleReadPort`. Owner: `organizations`. */
258
+ export interface OrganizationRoleReadPort {
259
+ /**
260
+ * The id of the Organization's predefined role of `kind`, read through the
261
+ * role cache from **committed** rows. A caller that has just created the
262
+ * Organization in its own open transaction takes the id from the provisioning
263
+ * answer instead (research R-34).
264
+ */
265
+ predefinedRoleId(organizationId: string, kind: 'administrator' | 'member'): Promise<string>;
266
+ /**
267
+ * The role `roleId` **of `organizationId`**, or `null` when that Organization
268
+ * has no such role — another Organization's role id included (FR-005). Read
269
+ * through the role cache from committed rows, like {@link predefinedRoleId}.
270
+ * `name` is `null` for the two predefined roles, whose label is translated
271
+ * (FR-003). Added for `customer_account.change_role` (WP-02b), which assigns a
272
+ * role the caller named and must refuse one it cannot see.
273
+ */
274
+ findRole(organizationId: string, roleId: string): Promise<OrganizationRoleSummary | null>;
275
+ /**
276
+ * The role `roleId` **of `organizationId`** as every response names it
277
+ * (FR-008, FR-056): a predefined role's label translated into `language`
278
+ * (English when absent or unsupported), a custom role's own name verbatim;
279
+ * `null` when that Organization has no such role (FR-005). Read through the
280
+ * role cache like {@link findRole}. Added for the session views and the
281
+ * operator's impersonation answer (WP-03), which other modules serve.
282
+ */
283
+ roleRef(organizationId: string, roleId: string, language?: string): Promise<OrganizationRoleRef | null>;
284
+ }
285
+ /** A role as {@link OrganizationRoleReadPort.findRole} answers it. */
286
+ export interface OrganizationRoleSummary {
287
+ readonly id: string;
288
+ readonly kind: OrganizationRoleKind;
289
+ /** The custom role's name; `null` for `administrator` and `member`. */
290
+ readonly name: string | null;
291
+ }
292
+ /**
293
+ * The refusal {@link organizationPermissionPreHandler} raises for a request
294
+ * that carries no customer: `401 UNAUTHORIZED`, the answer `requireCustomer`
295
+ * gives.
296
+ *
297
+ * It is a class of this package rather than the platform's `HttpError`
298
+ * because the guard is a plain function here and this package depends on
299
+ * nothing but `zod` — it cannot construct the platform's error. The platform's
300
+ * error envelope renders it exactly as it renders `requireCustomer`'s refusal.
301
+ * The guard is declared **after** `requireCustomer`, so in a correctly
302
+ * declared route this is a second line and never the first.
303
+ */
304
+ export declare class CustomerSessionRequiredError extends Error {
305
+ readonly statusCode = 401;
306
+ readonly code: "UNAUTHORIZED";
307
+ constructor();
308
+ }
309
+ /** What {@link organizationPermissionPreHandler} reads off a request. */
310
+ export interface OrganizationPermissionGuardRequest {
311
+ readonly actor: Actor;
312
+ /** The platform's `request.responseLanguage()`, when the error envelope installed it. */
313
+ readonly responseLanguage?: () => Promise<string>;
314
+ }
315
+ export interface OrganizationPermissionGuardOptions {
316
+ /**
317
+ * `'refuse'` (the default): a non-customer actor is refused with
318
+ * {@link CustomerSessionRequiredError}. `'pass'`: a non-customer actor — an
319
+ * anonymous visitor with a guest basket — passes **unjudged** to the route's
320
+ * own handling. Only for routes that admit a guest today (owner ruling PR-4,
321
+ * research R-35); every other guard stays fail-closed.
322
+ */
323
+ readonly guests?: 'refuse' | 'pass';
324
+ }
325
+ /**
326
+ * The route guard every gating module declares (research R-20, R-35):
327
+ *
328
+ * ```ts
329
+ * preHandler: [requireCustomer, organizationPermissionPreHandler(() => permissions, 'carts.create')]
330
+ * ```
331
+ *
332
+ * A plain function — no Fastify import — so it lives beside the port it calls.
333
+ * `getPort` is a thunk resolved on **every** request, never at registration:
334
+ * a captured port is the third fail-open shape of `module-composition.md` item
335
+ * 4a. A customer actor — impersonation included — is judged by `assert` with
336
+ * the subject built from the actor and the response language; the port's
337
+ * refusal propagates unchanged. Composite actions are two guards, never a
338
+ * combined code; the refusal names the first missing one.
339
+ */
340
+ export declare function organizationPermissionPreHandler(getPort: () => OrganizationPermissionPort, code: string, options?: OrganizationPermissionGuardOptions): (request: OrganizationPermissionGuardRequest) => Promise<void>;
341
+ //# sourceMappingURL=organization-roles.d.ts.map
@@ -0,0 +1,218 @@
1
+ import { z } from 'zod';
2
+ import { isoDateTimeSchema, uuidSchema } from './common.js';
3
+ import { ERROR_CODES } from './errors.js';
4
+ import { customFieldValuesSchema } from './custom-fields.js';
5
+ /**
6
+ * Organization roles and organization permissions — the buyer's side of
7
+ * "who may do what" (`specs/170-organization-roles/`).
8
+ *
9
+ * An Organization holds two predefined roles — *Administrator* (every present
10
+ * permission, immutable) and *Member* (editable) — and up to fifty custom ones.
11
+ * Each member holds exactly one. A role is a set of **organization permission**
12
+ * codes (`<module>.<action>`), declared by the module whose buyer action each
13
+ * gates in its manifest's `organizationPermissions` field (`./modules.ts`).
14
+ * The operator vocabulary (`<area>:<action>`, `/admin-roles`) is a different
15
+ * one and the two never meet (FR-020, research R-2).
16
+ *
17
+ * Normative: `specs/170-organization-roles/contracts/organization-permission-port.md`
18
+ * and `contracts/storefront-api.md` §2. They replaced the legacy two-value role
19
+ * enum, removed with its columns by the feature's legacy-removal package
20
+ * (research R-23).
21
+ */
22
+ // --- Kinds and references ----------------------------------------------------
23
+ export const organizationRoleKindSchema = z.enum(['administrator', 'member', 'custom']);
24
+ /**
25
+ * The role as every response shows it (FR-008, FR-056, FR-073). `name` is the
26
+ * translated label for `administrator` / `member` in the response language and
27
+ * the stored name for `custom`.
28
+ */
29
+ export const organizationRoleRefSchema = z
30
+ .object({ id: uuidSchema, name: z.string(), kind: organizationRoleKindSchema })
31
+ .strict();
32
+ /**
33
+ * One role on the role-management screens, storefront and Admin UI alike
34
+ * (`contracts/storefront-api.md` §2). `permissions` are the stored grants of
35
+ * **present** codes only — a grant of a switched-off module's code is kept
36
+ * server-side and never round-trips through the editor (FR-025); for the
37
+ * administrator it is every present code. `pendingInvitationCount` counts
38
+ * invitations neither accepted, revoked nor expired (FR-010a).
39
+ */
40
+ export const organizationRoleViewSchema = z.object({
41
+ id: uuidSchema,
42
+ kind: organizationRoleKindSchema,
43
+ name: z.string(),
44
+ description: z.string().nullable(),
45
+ permissions: z.array(z.string()),
46
+ memberCount: z.number().int().min(0),
47
+ pendingInvitationCount: z.number().int().min(0),
48
+ version: z.number().int().min(1),
49
+ updatedAt: isoDateTimeSchema,
50
+ });
51
+ export const organizationRoleListResponseSchema = z.object({ data: z.array(organizationRoleViewSchema) });
52
+ export const organizationRoleResponseSchema = z.object({ data: organizationRoleViewSchema });
53
+ /** One grantable code, translated in the request language (R-31). */
54
+ export const organizationPermissionCatalogueEntrySchema = z.object({
55
+ code: z.string(),
56
+ label: z.string(),
57
+ description: z.string(),
58
+ memberDefault: z.boolean(),
59
+ });
60
+ /** `GET …/permission-catalogue` — present codes only, grouped by declaring module. */
61
+ export const organizationPermissionCatalogueResponseSchema = z.object({
62
+ data: z.object({
63
+ groups: z.array(z.object({
64
+ moduleId: z.string(),
65
+ moduleLabel: z.string(),
66
+ permissions: z.array(organizationPermissionCatalogueEntrySchema),
67
+ })),
68
+ }),
69
+ });
70
+ /** `GET /api/v1/organizations/mine/role` — the member's own role (FR-058). */
71
+ export const organizationOwnRoleResponseSchema = z.object({
72
+ data: z.object({
73
+ role: organizationRoleRefSchema,
74
+ permissions: z.array(z.object({ code: z.string(), label: z.string(), description: z.string() })),
75
+ }),
76
+ });
77
+ /** `DELETE …/roles/:id` — what moved to the replacement role (FR-024). */
78
+ export const deleteOrganizationRoleResponseSchema = z.object({
79
+ data: z.object({
80
+ reassignedMembers: z.number().int().min(0),
81
+ reassignedInvitations: z.number().int().min(0),
82
+ }),
83
+ });
84
+ // --- Requests -----------------------------------------------------------------
85
+ //
86
+ // Every request schema here is `.strict()`, and that is load-bearing (FR-073,
87
+ // research R-24): Zod's default `.object` strips an unknown key silently, so a
88
+ // client still sending the legacy `role` would be answered as though it had
89
+ // asked for the default role. Strict refuses it with `400 VALIDATION_FAILED`
90
+ // naming the key.
91
+ const roleNameSchema = z.string().trim().min(1).max(80);
92
+ const roleDescriptionSchema = z.string().trim().max(500);
93
+ const permissionCodesSchema = z.array(z.string().min(1));
94
+ /** `POST …/roles` — a custom role. */
95
+ export const createOrganizationRoleRequestSchema = z
96
+ .object({
97
+ name: roleNameSchema,
98
+ description: roleDescriptionSchema.optional(),
99
+ permissions: permissionCodesSchema,
100
+ })
101
+ .strict();
102
+ /**
103
+ * `PATCH …/roles/:id`. `expectedVersion` is the version the editor read
104
+ * (`ORGANIZATION_ROLE_STALE` on mismatch, R-29); `name` and `description` are
105
+ * refused for the *Member* role by the Command, not by the schema.
106
+ */
107
+ export const updateOrganizationRoleRequestSchema = z
108
+ .object({
109
+ expectedVersion: z.number().int().min(1),
110
+ name: roleNameSchema.optional(),
111
+ description: roleDescriptionSchema.nullable().optional(),
112
+ permissions: permissionCodesSchema.optional(),
113
+ })
114
+ .strict();
115
+ /** `DELETE …/roles/:id`. A held role needs a replacement (FR-024). */
116
+ export const deleteOrganizationRoleRequestSchema = z
117
+ .object({
118
+ expectedVersion: z.number().int().min(1),
119
+ replacementRoleId: uuidSchema.optional(),
120
+ })
121
+ .strict();
122
+ /**
123
+ * `PATCH /api/v1/organizations/mine/members/:id/role` — replaces the legacy
124
+ * `changeMemberRoleRequestSchema` (`{ role }`).
125
+ */
126
+ export const assignMemberRoleRequestSchema = z.object({ roleId: uuidSchema }).strict();
127
+ /**
128
+ * Inviting a member, on the storefront and in the Admin UI
129
+ * (`POST …/mine/invitations`, `POST /api/v1/admin/organizations/:id/members/invite`)
130
+ * — replaces the legacy `inviteMemberRequestSchema` (`{ email, role? }`). An
131
+ * absent `roleId` is the Organization's *Member* role, resolved server-side.
132
+ */
133
+ export const inviteMemberToRoleRequestSchema = z
134
+ .object({ email: z.string().email(), roleId: uuidSchema.optional() })
135
+ .strict();
136
+ /**
137
+ * Platform admin — `POST /api/v1/admin/organizations/:id/members` (direct
138
+ * create). Replaces the legacy `adminDirectMemberRequestSchema`'s `role?`.
139
+ */
140
+ export const adminDirectMemberToRoleRequestSchema = z
141
+ .object({
142
+ email: z.string().email(),
143
+ firstName: z.string().min(1).max(120),
144
+ lastName: z.string().min(1).max(120),
145
+ password: z.string().min(12).max(256),
146
+ roleId: uuidSchema.optional(),
147
+ /**
148
+ * Feature 175 (FR-018) — the new account's custom-field values (entity
149
+ * type `customer`), validated with the administrator's rules before the
150
+ * account is created.
151
+ */
152
+ customFieldValues: customFieldValuesSchema.optional(),
153
+ })
154
+ .strict();
155
+ /**
156
+ * Platform admin — `PATCH /api/v1/admin/organizations/:id/members/:customerAccountId/role`.
157
+ * Replaces the legacy `adminPatchMemberRoleRequestSchema` (`{ role, expectedUpdatedAt? }`).
158
+ */
159
+ export const adminAssignMemberRoleRequestSchema = z
160
+ .object({ roleId: uuidSchema, expectedUpdatedAt: z.string().optional() })
161
+ .strict();
162
+ // --- The route guard -------------------------------------------------------------
163
+ /**
164
+ * The refusal {@link organizationPermissionPreHandler} raises for a request
165
+ * that carries no customer: `401 UNAUTHORIZED`, the answer `requireCustomer`
166
+ * gives.
167
+ *
168
+ * It is a class of this package rather than the platform's `HttpError`
169
+ * because the guard is a plain function here and this package depends on
170
+ * nothing but `zod` — it cannot construct the platform's error. The platform's
171
+ * error envelope renders it exactly as it renders `requireCustomer`'s refusal.
172
+ * The guard is declared **after** `requireCustomer`, so in a correctly
173
+ * declared route this is a second line and never the first.
174
+ */
175
+ export class CustomerSessionRequiredError extends Error {
176
+ statusCode = 401;
177
+ code = ERROR_CODES.UNAUTHORIZED;
178
+ constructor() {
179
+ super('Customer session required.');
180
+ this.name = 'CustomerSessionRequiredError';
181
+ }
182
+ }
183
+ /**
184
+ * The route guard every gating module declares (research R-20, R-35):
185
+ *
186
+ * ```ts
187
+ * preHandler: [requireCustomer, organizationPermissionPreHandler(() => permissions, 'carts.create')]
188
+ * ```
189
+ *
190
+ * A plain function — no Fastify import — so it lives beside the port it calls.
191
+ * `getPort` is a thunk resolved on **every** request, never at registration:
192
+ * a captured port is the third fail-open shape of `module-composition.md` item
193
+ * 4a. A customer actor — impersonation included — is judged by `assert` with
194
+ * the subject built from the actor and the response language; the port's
195
+ * refusal propagates unchanged. Composite actions are two guards, never a
196
+ * combined code; the refusal names the first missing one.
197
+ */
198
+ export function organizationPermissionPreHandler(getPort, code, options = {}) {
199
+ const guests = options.guests ?? 'refuse';
200
+ return async (request) => {
201
+ const actor = request.actor;
202
+ if (actor.kind !== 'customer') {
203
+ if (guests === 'pass')
204
+ return;
205
+ throw new CustomerSessionRequiredError();
206
+ }
207
+ const subject = {
208
+ customerAccountId: actor.customerAccountId,
209
+ // `''` is what the auth hook stamps when no resolver is wired; the port
210
+ // finds no role in it and fails closed.
211
+ organizationId: actor.organizationId ?? '',
212
+ organizationRoleId: actor.organizationRoleId ?? null,
213
+ };
214
+ const language = request.responseLanguage ? await request.responseLanguage() : undefined;
215
+ await getPort().assert(subject, code, language === undefined ? {} : { language });
216
+ };
217
+ }
218
+ //# sourceMappingURL=organization-roles.js.map