@aglyn/plugins-crm 1.0.0-beta.218 → 1.0.0-beta.220

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 (346) hide show
  1. package/README.md +2 -0
  2. package/package.json +14 -14
  3. package/src/index.d.ts +1 -0
  4. package/src/index.js.map +1 -1
  5. package/src/lib/components/companies-bulk-bar.js +12 -4
  6. package/src/lib/components/companies-bulk-bar.js.map +1 -1
  7. package/src/lib/components/company-detail-page.js +11 -0
  8. package/src/lib/components/company-detail-page.js.map +1 -1
  9. package/src/lib/components/company-edit-drawer.js +12 -2
  10. package/src/lib/components/company-edit-drawer.js.map +1 -1
  11. package/src/lib/components/company-import-drawer.d.ts +1 -1
  12. package/src/lib/components/company-picker.js +10 -3
  13. package/src/lib/components/company-picker.js.map +1 -1
  14. package/src/lib/components/contact-associations-card.js +4 -3
  15. package/src/lib/components/contact-associations-card.js.map +1 -1
  16. package/src/lib/components/contact-detail-page.d.ts +4 -4
  17. package/src/lib/components/contact-detail-page.js +50 -53
  18. package/src/lib/components/contact-detail-page.js.map +1 -1
  19. package/src/lib/components/contact-list-columns.d.ts +3 -0
  20. package/src/lib/components/contact-list-columns.js +21 -5
  21. package/src/lib/components/contact-list-columns.js.map +1 -1
  22. package/src/lib/components/contact-merge-dialog.js +2 -1
  23. package/src/lib/components/contact-merge-dialog.js.map +1 -1
  24. package/src/lib/components/contact-timeline-card.js +4 -3
  25. package/src/lib/components/contact-timeline-card.js.map +1 -1
  26. package/src/lib/components/contacts-bulk-bar.d.ts +3 -3
  27. package/src/lib/components/contacts-bulk-bar.js +24 -51
  28. package/src/lib/components/contacts-bulk-bar.js.map +1 -1
  29. package/src/lib/components/contacts-section.js +9 -3
  30. package/src/lib/components/contacts-section.js.map +1 -1
  31. package/src/lib/components/crm-booking-zone.d.ts +8 -2
  32. package/src/lib/components/crm-booking-zone.js.map +1 -1
  33. package/src/lib/components/crm-export-all-button.d.ts +1 -1
  34. package/src/lib/components/crm-export-all-button.js.map +1 -1
  35. package/src/lib/components/crm-glance-card.js +2 -1
  36. package/src/lib/components/crm-glance-card.js.map +1 -1
  37. package/src/lib/components/crm-send-email-dialog.js +9 -6
  38. package/src/lib/components/crm-send-email-dialog.js.map +1 -1
  39. package/src/lib/components/csv-import-drawer.js +2 -2
  40. package/src/lib/components/csv-import-drawer.js.map +1 -1
  41. package/src/lib/components/deal-detail-page.js +18 -2
  42. package/src/lib/components/deal-detail-page.js.map +1 -1
  43. package/src/lib/components/deal-edit-drawer.js +10 -0
  44. package/src/lib/components/deal-edit-drawer.js.map +1 -1
  45. package/src/lib/components/deal-products-card.js +27 -16
  46. package/src/lib/components/deal-products-card.js.map +1 -1
  47. package/src/lib/components/deals-bulk-bar.js +13 -5
  48. package/src/lib/components/deals-bulk-bar.js.map +1 -1
  49. package/src/lib/components/lead-campaigns-card.d.ts +4 -4
  50. package/src/lib/components/lead-campaigns-card.js +15 -8
  51. package/src/lib/components/lead-campaigns-card.js.map +1 -1
  52. package/src/lib/components/lead-detail-page.js +25 -5
  53. package/src/lib/components/lead-detail-page.js.map +1 -1
  54. package/src/lib/components/lead-properties-card.js +10 -0
  55. package/src/lib/components/lead-properties-card.js.map +1 -1
  56. package/src/lib/components/lead-status-chip.js +3 -1
  57. package/src/lib/components/lead-status-chip.js.map +1 -1
  58. package/src/lib/components/lead-surfaces-note.js +4 -5
  59. package/src/lib/components/lead-surfaces-note.js.map +1 -1
  60. package/src/lib/components/lead-unqualify-dialog.js +6 -0
  61. package/src/lib/components/lead-unqualify-dialog.js.map +1 -1
  62. package/src/lib/components/leads-bulk-bar.js +34 -11
  63. package/src/lib/components/leads-bulk-bar.js.map +1 -1
  64. package/src/lib/components/leads-section.js +41 -8
  65. package/src/lib/components/leads-section.js.map +1 -1
  66. package/src/lib/components/new-lead-drawer.js +5 -4
  67. package/src/lib/components/new-lead-drawer.js.map +1 -1
  68. package/src/lib/components/org-lead-surfaces-note.js +6 -2
  69. package/src/lib/components/org-lead-surfaces-note.js.map +1 -1
  70. package/src/lib/components/recipes-card.js +9 -4
  71. package/src/lib/components/recipes-card.js.map +1 -1
  72. package/src/lib/components/record-sharing-card.d.ts +57 -0
  73. package/src/lib/components/record-sharing-card.js +244 -0
  74. package/src/lib/components/record-sharing-card.js.map +1 -0
  75. package/src/lib/components/reports/activity-card.js +4 -3
  76. package/src/lib/components/reports/activity-card.js.map +1 -1
  77. package/src/lib/components/reports/closed-deals-card.js +4 -3
  78. package/src/lib/components/reports/closed-deals-card.js.map +1 -1
  79. package/src/lib/components/reports/contacts-mix-card.js +3 -2
  80. package/src/lib/components/reports/contacts-mix-card.js.map +1 -1
  81. package/src/lib/components/reports/contacts-trend-card.js +2 -1
  82. package/src/lib/components/reports/contacts-trend-card.js.map +1 -1
  83. package/src/lib/components/reports/forecast-card.js +3 -2
  84. package/src/lib/components/reports/forecast-card.js.map +1 -1
  85. package/src/lib/components/reports/lead-funnel-card.js +8 -6
  86. package/src/lib/components/reports/lead-funnel-card.js.map +1 -1
  87. package/src/lib/components/reports/pipeline-card.js +4 -3
  88. package/src/lib/components/reports/pipeline-card.js.map +1 -1
  89. package/src/lib/components/reports/report-format.d.ts +1 -1
  90. package/src/lib/components/reports/report-format.js.map +1 -1
  91. package/src/lib/components/reports/report-scope.d.ts +1 -1
  92. package/src/lib/components/reports/report-scope.js.map +1 -1
  93. package/src/lib/components/reports/source-conversion-card.js +2 -1
  94. package/src/lib/components/reports/source-conversion-card.js.map +1 -1
  95. package/src/lib/components/reports/tasks-card.js +2 -1
  96. package/src/lib/components/reports/tasks-card.js.map +1 -1
  97. package/src/lib/components/reports/won-lost-by-owner-card.js +3 -2
  98. package/src/lib/components/reports/won-lost-by-owner-card.js.map +1 -1
  99. package/src/lib/components/reports-section.js +4 -4
  100. package/src/lib/components/reports-section.js.map +1 -1
  101. package/src/lib/components/settings-section.js +7 -0
  102. package/src/lib/components/settings-section.js.map +1 -1
  103. package/src/lib/components/share-records-dialog.d.ts +28 -0
  104. package/src/lib/components/share-records-dialog.js +184 -0
  105. package/src/lib/components/share-records-dialog.js.map +1 -0
  106. package/src/lib/components/sharing-rule-drawer.d.ts +37 -0
  107. package/src/lib/components/sharing-rule-drawer.js +374 -0
  108. package/src/lib/components/sharing-rule-drawer.js.map +1 -0
  109. package/src/lib/components/sharing-rules-card.d.ts +24 -0
  110. package/src/lib/components/sharing-rules-card.js +287 -0
  111. package/src/lib/components/sharing-rules-card.js.map +1 -0
  112. package/src/lib/components/use-crm-api.d.ts +1 -1
  113. package/src/lib/components/use-crm-api.js.map +1 -1
  114. package/src/lib/components/use-site-route-context.d.ts +25 -0
  115. package/src/lib/components/use-site-route-context.js +58 -0
  116. package/src/lib/components/use-site-route-context.js.map +1 -0
  117. package/src/lib/constants/api-routes.d.ts +31 -0
  118. package/src/lib/constants/api-routes.js +27 -1
  119. package/src/lib/constants/api-routes.js.map +1 -1
  120. package/src/lib/constants/bundle-common.d.ts +2 -0
  121. package/src/lib/constants/bundle-common.js +1 -0
  122. package/src/lib/constants/bundle-common.js.map +1 -1
  123. package/src/lib/declarations.console-server.d.ts +41 -0
  124. package/src/lib/declarations.console-server.js +115 -0
  125. package/src/lib/declarations.console-server.js.map +1 -0
  126. package/src/lib/declarations.server.d.ts +12 -0
  127. package/src/lib/declarations.server.js +84 -1
  128. package/src/lib/declarations.server.js.map +1 -1
  129. package/src/lib/hooks/use-contact-remove.d.ts +35 -0
  130. package/src/lib/hooks/use-contact-remove.js +77 -0
  131. package/src/lib/hooks/use-contact-remove.js.map +1 -0
  132. package/src/lib/hooks/use-crm-campaigns.d.ts +2 -2
  133. package/src/lib/hooks/use-crm-campaigns.js +3 -3
  134. package/src/lib/hooks/use-crm-campaigns.js.map +1 -1
  135. package/src/lib/hooks/use-crm-sharing.d.ts +30 -0
  136. package/src/lib/hooks/use-crm-sharing.js +109 -0
  137. package/src/lib/hooks/use-crm-sharing.js.map +1 -0
  138. package/src/lib/model/campaign-filing-activity.d.ts +1 -1
  139. package/src/lib/model/campaign-filing-activity.js +1 -1
  140. package/src/lib/model/campaign-filing-activity.js.map +1 -1
  141. package/src/lib/model/companies-csv.d.ts +1 -1
  142. package/src/lib/model/companies-csv.js +2 -2
  143. package/src/lib/model/companies-csv.js.map +1 -1
  144. package/src/lib/model/contact-holder.d.ts +68 -0
  145. package/src/lib/model/contact-holder.js +129 -0
  146. package/src/lib/model/contact-holder.js.map +1 -0
  147. package/src/lib/model/contact-interaction-links.d.ts +46 -0
  148. package/src/lib/model/contact-interaction-links.js +65 -0
  149. package/src/lib/model/contact-interaction-links.js.map +1 -0
  150. package/src/lib/model/contact-merge.d.ts +136 -0
  151. package/src/lib/model/contact-merge.js +412 -0
  152. package/src/lib/model/contact-merge.js.map +1 -0
  153. package/src/lib/model/contact-record.d.ts +7 -1
  154. package/src/lib/model/contact-record.js +7 -6
  155. package/src/lib/model/contact-record.js.map +1 -1
  156. package/src/lib/model/contact-remove.d.ts +48 -0
  157. package/src/lib/model/contact-remove.js +22 -0
  158. package/src/lib/model/contact-remove.js.map +1 -0
  159. package/src/lib/model/contacts-bulk-writes.d.ts +2 -71
  160. package/src/lib/model/contacts-bulk-writes.js +2 -82
  161. package/src/lib/model/contacts-bulk-writes.js.map +1 -1
  162. package/src/lib/model/contacts-csv.d.ts +2 -2
  163. package/src/lib/model/contacts-csv.js +2 -2
  164. package/src/lib/model/contacts-csv.js.map +1 -1
  165. package/src/lib/model/crm-csv.d.ts +239 -0
  166. package/src/lib/model/crm-csv.js +467 -0
  167. package/src/lib/model/crm-csv.js.map +1 -0
  168. package/src/lib/model/crm-digest.d.ts +227 -0
  169. package/src/lib/model/crm-digest.js +336 -0
  170. package/src/lib/model/crm-digest.js.map +1 -0
  171. package/src/lib/model/crm-import.d.ts +7 -1
  172. package/src/lib/model/crm-import.js +2 -1
  173. package/src/lib/model/crm-import.js.map +1 -1
  174. package/src/lib/model/crm-inbound.d.ts +162 -0
  175. package/src/lib/model/crm-inbound.js +208 -0
  176. package/src/lib/model/crm-inbound.js.map +1 -0
  177. package/src/lib/model/crm-lead-import.d.ts +1 -1
  178. package/src/lib/model/crm-lead-import.js +4 -4
  179. package/src/lib/model/crm-lead-import.js.map +1 -1
  180. package/src/lib/model/crm-record-routes.d.ts +5 -0
  181. package/src/lib/model/crm-record-routes.js +7 -0
  182. package/src/lib/model/crm-record-routes.js.map +1 -1
  183. package/src/lib/model/crm-reports.d.ts +467 -0
  184. package/src/lib/model/crm-reports.js +667 -0
  185. package/src/lib/model/crm-reports.js.map +1 -0
  186. package/src/lib/model/crm-routes.d.ts +6 -5
  187. package/src/lib/model/crm-routes.js +7 -7
  188. package/src/lib/model/crm-routes.js.map +1 -1
  189. package/src/lib/model/crm-search-sources.d.ts +15 -0
  190. package/src/lib/model/crm-search-sources.js +162 -0
  191. package/src/lib/model/crm-search-sources.js.map +1 -0
  192. package/src/lib/model/crm-sharing-api.d.ts +32 -0
  193. package/src/lib/model/crm-sharing-api.js +59 -0
  194. package/src/lib/model/crm-sharing-api.js.map +1 -0
  195. package/src/lib/model/crm-sharing.d.ts +333 -0
  196. package/src/lib/model/crm-sharing.js +603 -0
  197. package/src/lib/model/crm-sharing.js.map +1 -0
  198. package/src/lib/model/deals-csv.d.ts +1 -1
  199. package/src/lib/model/deals-csv.js +4 -5
  200. package/src/lib/model/deals-csv.js.map +1 -1
  201. package/src/lib/model/lead-filters.d.ts +5 -4
  202. package/src/lib/model/lead-filters.js +7 -5
  203. package/src/lib/model/lead-filters.js.map +1 -1
  204. package/src/lib/model/leads-csv.d.ts +1 -1
  205. package/src/lib/model/leads-csv.js +1 -1
  206. package/src/lib/model/leads-csv.js.map +1 -1
  207. package/src/lib/model/tasks-csv.d.ts +1 -1
  208. package/src/lib/model/tasks-csv.js +1 -1
  209. package/src/lib/model/tasks-csv.js.map +1 -1
  210. package/src/lib/plan-entitlements.d.ts +75 -0
  211. package/src/lib/plan-entitlements.js +56 -0
  212. package/src/lib/plan-entitlements.js.map +1 -0
  213. package/src/lib/plugin.js +39 -0
  214. package/src/lib/plugin.js.map +1 -1
  215. package/src/lib/server/api-v1/contacts-merge.d.ts +20 -0
  216. package/src/lib/server/api-v1/contacts-merge.js +120 -0
  217. package/src/lib/server/api-v1/contacts-merge.js.map +1 -0
  218. package/src/lib/server/api-v1/contacts.d.ts +18 -0
  219. package/src/lib/server/api-v1/contacts.js +1076 -0
  220. package/src/lib/server/api-v1/contacts.js.map +1 -0
  221. package/src/lib/server/api-v1/crm-activities.d.ts +18 -0
  222. package/src/lib/server/api-v1/crm-activities.js +269 -0
  223. package/src/lib/server/api-v1/crm-activities.js.map +1 -0
  224. package/src/lib/server/api-v1/crm-companies.d.ts +18 -0
  225. package/src/lib/server/api-v1/crm-companies.js +391 -0
  226. package/src/lib/server/api-v1/crm-companies.js.map +1 -0
  227. package/src/lib/server/api-v1/crm-deals.d.ts +18 -0
  228. package/src/lib/server/api-v1/crm-deals.js +631 -0
  229. package/src/lib/server/api-v1/crm-deals.js.map +1 -0
  230. package/src/lib/server/api-v1/crm-email-templates.d.ts +18 -0
  231. package/src/lib/server/api-v1/crm-email-templates.js +336 -0
  232. package/src/lib/server/api-v1/crm-email-templates.js.map +1 -0
  233. package/src/lib/server/api-v1/crm-leads.d.ts +18 -0
  234. package/src/lib/server/api-v1/crm-leads.js +833 -0
  235. package/src/lib/server/api-v1/crm-leads.js.map +1 -0
  236. package/src/lib/server/api-v1/crm-pipelines.d.ts +76 -0
  237. package/src/lib/server/api-v1/crm-pipelines.js +146 -0
  238. package/src/lib/server/api-v1/crm-pipelines.js.map +1 -0
  239. package/src/lib/server/api-v1/crm-shared.d.ts +271 -0
  240. package/src/lib/server/api-v1/crm-shared.js +436 -0
  241. package/src/lib/server/api-v1/crm-shared.js.map +1 -0
  242. package/src/lib/server/api-v1/crm-tasks.d.ts +18 -0
  243. package/src/lib/server/api-v1/crm-tasks.js +398 -0
  244. package/src/lib/server/api-v1/crm-tasks.js.map +1 -0
  245. package/src/lib/server/api-v1/openapi.d.ts +29 -0
  246. package/src/lib/server/api-v1/openapi.js +985 -0
  247. package/src/lib/server/api-v1/openapi.js.map +1 -0
  248. package/src/lib/server/api-v1/usage.d.ts +26 -0
  249. package/src/lib/server/api-v1/usage.js +73 -0
  250. package/src/lib/server/api-v1/usage.js.map +1 -0
  251. package/src/lib/server/campaign-filing-activity.d.ts +1 -1
  252. package/src/lib/server/campaign-filing-activity.js +7 -11
  253. package/src/lib/server/campaign-filing-activity.js.map +1 -1
  254. package/src/lib/server/capture-contact.js +15 -4
  255. package/src/lib/server/capture-contact.js.map +1 -1
  256. package/src/lib/server/consent-group-participant.js +1 -1
  257. package/src/lib/server/consent-group-participant.js.map +1 -1
  258. package/src/lib/server/contact-email-engagement.d.ts +33 -0
  259. package/src/lib/server/contact-email-engagement.js +146 -0
  260. package/src/lib/server/contact-email-engagement.js.map +1 -0
  261. package/src/lib/server/contact-lifecycle-floor.d.ts +89 -0
  262. package/src/lib/server/contact-lifecycle-floor.js +91 -0
  263. package/src/lib/server/contact-lifecycle-floor.js.map +1 -0
  264. package/src/lib/server/contact-remove.d.ts +75 -0
  265. package/src/lib/server/contact-remove.js +244 -0
  266. package/src/lib/server/contact-remove.js.map +1 -0
  267. package/src/lib/server/contact-update.js +4 -3
  268. package/src/lib/server/contact-update.js.map +1 -1
  269. package/src/lib/server/contacts-import.d.ts +47 -11
  270. package/src/lib/server/contacts-import.js +171 -71
  271. package/src/lib/server/contacts-import.js.map +1 -1
  272. package/src/lib/server/contacts-merge.d.ts +1 -1
  273. package/src/lib/server/contacts-merge.js +3 -2
  274. package/src/lib/server/contacts-merge.js.map +1 -1
  275. package/src/lib/server/container-detach.d.ts +31 -0
  276. package/src/lib/server/container-detach.js +115 -0
  277. package/src/lib/server/container-detach.js.map +1 -0
  278. package/src/lib/server/convert-host-lead.d.ts +189 -0
  279. package/src/lib/server/convert-host-lead.js +518 -0
  280. package/src/lib/server/convert-host-lead.js.map +1 -0
  281. package/src/lib/server/crm-inbound-email.d.ts +162 -0
  282. package/src/lib/server/crm-inbound-email.js +259 -0
  283. package/src/lib/server/crm-inbound-email.js.map +1 -0
  284. package/src/lib/server/crm-records-meter.d.ts +50 -0
  285. package/src/lib/server/crm-records-meter.js +126 -0
  286. package/src/lib/server/crm-records-meter.js.map +1 -0
  287. package/src/lib/server/crm-sharing.d.ts +108 -0
  288. package/src/lib/server/crm-sharing.js +790 -0
  289. package/src/lib/server/crm-sharing.js.map +1 -0
  290. package/src/lib/server/daily-digest-route.d.ts +101 -0
  291. package/src/lib/server/daily-digest-route.js +578 -0
  292. package/src/lib/server/daily-digest-route.js.map +1 -0
  293. package/src/lib/server/export-route.d.ts +60 -0
  294. package/src/lib/server/export-route.js +447 -0
  295. package/src/lib/server/export-route.js.map +1 -0
  296. package/src/lib/server/inbound-address.js +5 -3
  297. package/src/lib/server/inbound-address.js.map +1 -1
  298. package/src/lib/server/inbound-route.d.ts +74 -0
  299. package/src/lib/server/inbound-route.js +260 -0
  300. package/src/lib/server/inbound-route.js.map +1 -0
  301. package/src/lib/server/lead-campaign-carry.js +3 -3
  302. package/src/lib/server/lead-campaign-carry.js.map +1 -1
  303. package/src/lib/server/lead-convert.d.ts +1 -1
  304. package/src/lib/server/lead-convert.js +2 -2
  305. package/src/lib/server/lead-convert.js.map +1 -1
  306. package/src/lib/server/lead-create.d.ts +1 -1
  307. package/src/lib/server/lead-create.js +10 -15
  308. package/src/lib/server/lead-create.js.map +1 -1
  309. package/src/lib/server/lead-nurturing.d.ts +23 -0
  310. package/src/lib/server/lead-nurturing.js +82 -0
  311. package/src/lib/server/lead-nurturing.js.map +1 -0
  312. package/src/lib/server/leads-import.js +7 -7
  313. package/src/lib/server/leads-import.js.map +1 -1
  314. package/src/lib/server/merge-contacts.d.ts +55 -0
  315. package/src/lib/server/merge-contacts.js +274 -0
  316. package/src/lib/server/merge-contacts.js.map +1 -0
  317. package/src/lib/server/pipeline-record-index.d.ts +36 -0
  318. package/src/lib/server/pipeline-record-index.js +87 -0
  319. package/src/lib/server/pipeline-record-index.js.map +1 -0
  320. package/src/lib/server/record-email-state.js +23 -0
  321. package/src/lib/server/record-email-state.js.map +1 -1
  322. package/src/lib/server/record-facts.js +2 -1
  323. package/src/lib/server/record-facts.js.map +1 -1
  324. package/src/lib/server/record-timeline.d.ts +12 -0
  325. package/src/lib/server/record-timeline.js +127 -15
  326. package/src/lib/server/record-timeline.js.map +1 -1
  327. package/src/lib/server/task-reminders-route.d.ts +82 -0
  328. package/src/lib/server/task-reminders-route.js +499 -0
  329. package/src/lib/server/task-reminders-route.js.map +1 -0
  330. package/src/lib/server/task-routes.d.ts +2 -0
  331. package/src/lib/server/task-routes.js +22 -3
  332. package/src/lib/server/task-routes.js.map +1 -1
  333. package/src/lib/server-deal-stage.js +2 -1
  334. package/src/lib/server-deal-stage.js.map +1 -1
  335. package/src/lib/server.d.ts +5 -2
  336. package/src/lib/server.js +47 -2
  337. package/src/lib/server.js.map +1 -1
  338. package/src/lib/testing/stand-in-site-record-routes.d.ts +26 -0
  339. package/src/lib/testing/stand-in-site-record-routes.js +55 -0
  340. package/src/lib/testing/stand-in-site-record-routes.js.map +1 -0
  341. package/src/lib/usage-axes.d.ts +35 -0
  342. package/src/lib/usage-axes.js +75 -0
  343. package/src/lib/usage-axes.js.map +1 -0
  344. package/src/lib/components/use-emails-hub-path.d.ts +0 -24
  345. package/src/lib/components/use-emails-hub-path.js +0 -59
  346. package/src/lib/components/use-emails-hub-path.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/server/crm-records-meter.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { checkCrmRecordsQuota } from '@aglyn/aglyn/app-utils/plan-entitlements'\nimport type {\n PluginUsageMeterContext,\n PluginUsageMeterReading,\n} from '@aglyn/aglyn/plugin-manager/plugin-usage-meters'\nimport { firebaseAdmin } from '@aglyn/tenant-data-admin'\n\n/**\n * The CRM's month in the usage sweep: the records band (AGL-890, widened in\n * AGL-2611) — contacts, companies and deals, counted together across the\n * workspace and measured against the ONE band `contactsPerHost` names.\n *\n * ## A stock, read at the end of the month it bills (AGL-2399)\n *\n * Records are a LEVEL, not a total: the count read now describes now. The\n * closed-month sweep runs after the month is over, so it bills the last\n * reading taken INSIDE the month — the period-end stamp each in-progress\n * sweep writes — and falls back to measuring only when no such reading\n * exists. The in-progress sweep stamps its own reading as the period-end one,\n * and a closed sweep never stamps, so every re-run of a closed month reads\n * the same input and bills the same amount.\n *\n * The records trio is resolved as a unit, so `contactsCount + companiesCount\n * + dealsCount === crmRecordsCount` on every row. A closed month with a\n * contacts reading but no records reading was measured on contacts alone,\n * before the band was widened, and bills the other two as nothing — the\n * permissive direction, and the only one the period-end rule permits. The\n * persisted names still say \"contacts\" because every reader of the rollup\n * keys on them; the quantity behind them is the records band.\n *\n * ## Withheld while the CRM is dark (AGL-1604)\n *\n * `release_crm` gates the console CRM. Records still accrue while it is off —\n * capture and `GET /v1/contacts` keep running — and nobody may be charged for\n * what they cannot reach, so the overage is withheld rather than billed, and\n * recorded as withheld so the month is legible. The COUNT is written always:\n * it is an entitlement input, and only the figure that reaches the invoice\n * moves with the flag.\n */\nexport async function measureCrmRecords(\n context: PluginUsageMeterContext,\n): Promise<PluginUsageMeterReading> {\n const orgRef = firebaseAdmin.app().firestore().collection('orgs').doc(context.orgId)\n // Three aggregate counts, one per collection the band counts. Tasks and\n // activities are not counted, deliberately.\n const [contactsSnap, companiesSnap, dealsSnap] = await Promise.all([\n orgRef.collection('contacts').count().get(),\n orgRef.collection('companies').count().get(),\n orgRef.collection('deals').count().get(),\n ])\n const contactsCountAtSweep = Number(contactsSnap.data().count ?? 0)\n const companiesCountAtSweep = Number(companiesSnap.data().count ?? 0)\n const dealsCountAtSweep = Number(dealsSnap.data().count ?? 0)\n // The band's own figure: the three summed, measured at the same instant, so\n // the total and its parts describe one moment.\n const crmRecordsCountAtSweep =\n contactsCountAtSweep + companiesCountAtSweep + dealsCountAtSweep\n\n /**\n * A reading an earlier sweep stamped, or `null` when there is none to\n * trust. A missing field, a NaN or a negative falls back to measuring and\n * never bills as zero: billing zero on a malformed field would forfeit the\n * overage silently and look exactly like a customer inside the band.\n */\n const stamped = (field: string): number | null => {\n const value = Number(context.previous[field])\n return Number.isFinite(value) && value >= 0 ? value : null\n }\n const contactsAtPeriodEnd = stamped('contactsCountAtPeriodEnd')\n const crmRecordsAtPeriodEnd = stamped('crmRecordsCountAtPeriodEnd')\n const companiesAtPeriodEnd = stamped('companiesCountAtPeriodEnd')\n const dealsAtPeriodEnd = stamped('dealsCountAtPeriodEnd')\n\n const { closed } = context\n const contactsCount =\n closed && contactsAtPeriodEnd !== null ? contactsAtPeriodEnd : contactsCountAtSweep\n const [crmRecordsCount, companiesCount, dealsCount] =\n closed && crmRecordsAtPeriodEnd !== null\n ? [crmRecordsAtPeriodEnd, companiesAtPeriodEnd ?? 0, dealsAtPeriodEnd ?? 0]\n : closed && contactsAtPeriodEnd !== null\n ? [contactsAtPeriodEnd, 0, 0]\n : [crmRecordsCountAtSweep, companiesCountAtSweep, dealsCountAtSweep]\n\n // The band's verdict on the SUM, unchanged by the flag — the count and the\n // quota are what entitlement resolution reads, and only the figure that\n // reaches the invoice moves.\n const quota = checkCrmRecordsQuota(context.org as never, crmRecordsCount)\n const billed = context.releaseFlagOn('release_crm')\n const overageUsd = billed ? quota.overageMonthlyUsd : 0\n\n return {\n fields: {\n contactsCount,\n crmRecordsCount,\n companiesCount,\n dealsCount,\n // What this run measured, beside the billed basis: the difference is\n // how much a month moved by being measured inside it.\n contactsCountAtSweep,\n crmRecordsCountAtSweep,\n contactsOverageUsd: overageUsd,\n contactsOverageBilled: billed,\n contactsOverageWithheldUsd: billed ? 0 : quota.overageMonthlyUsd,\n },\n // Stamped together, so a closed sweep reads the total and its parts back\n // as one unit taken on one day.\n periodEndFields: {\n contactsCountAtPeriodEnd: contactsCountAtSweep,\n crmRecordsCountAtPeriodEnd: crmRecordsCountAtSweep,\n companiesCountAtPeriodEnd: companiesCountAtSweep,\n dealsCountAtPeriodEnd: dealsCountAtSweep,\n },\n billedUsd: overageUsd,\n periodEndBasis:\n closed && (contactsAtPeriodEnd !== null || crmRecordsAtPeriodEnd !== null),\n }\n}\n"],"names":["checkCrmRecordsQuota","firebaseAdmin","measureCrmRecords","context","contactsSnap","companiesSnap","dealsSnap","orgRef","app","firestore","collection","doc","orgId","Promise","all","count","get","contactsCountAtSweep","Number","data","companiesCountAtSweep","dealsCountAtSweep","crmRecordsCountAtSweep","stamped","field","value","previous","isFinite","contactsAtPeriodEnd","crmRecordsAtPeriodEnd","companiesAtPeriodEnd","dealsAtPeriodEnd","closed","contactsCount","crmRecordsCount","companiesCount","dealsCount","quota","org","billed","releaseFlagOn","overageUsd","overageMonthlyUsd","fields","contactsOverageUsd","contactsOverageBilled","contactsOverageWithheldUsd","periodEndFields","contactsCountAtPeriodEnd","crmRecordsCountAtPeriodEnd","companiesCountAtPeriodEnd","dealsCountAtPeriodEnd","billedUsd","periodEndBasis"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,oBAAoB,QAAQ,2CAA0C;AAK/E,SAASC,aAAa,QAAQ,2BAA0B;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BC,GACD,OAAO,eAAeC,kBACpBC,OAAgC;QAUIC,0BACCC,2BACJC;IAVjC,MAAMC,SAASN,cAAcO,GAAG,GAAGC,SAAS,GAAGC,UAAU,CAAC,QAAQC,GAAG,CAACR,QAAQS,KAAK;IACnF,wEAAwE;IACxE,4CAA4C;IAC5C,MAAM,CAACR,cAAcC,eAAeC,UAAU,GAAG,MAAMO,QAAQC,GAAG,CAAC;QACjEP,OAAOG,UAAU,CAAC,YAAYK,KAAK,GAAGC,GAAG;QACzCT,OAAOG,UAAU,CAAC,aAAaK,KAAK,GAAGC,GAAG;QAC1CT,OAAOG,UAAU,CAAC,SAASK,KAAK,GAAGC,GAAG;KACvC;IACD,MAAMC,uBAAuBC,QAAOd,2BAAAA,aAAae,IAAI,GAAGJ,KAAK,YAAzBX,2BAA6B;IACjE,MAAMgB,wBAAwBF,QAAOb,4BAAAA,cAAcc,IAAI,GAAGJ,KAAK,YAA1BV,4BAA8B;IACnE,MAAMgB,oBAAoBH,QAAOZ,wBAAAA,UAAUa,IAAI,GAAGJ,KAAK,YAAtBT,wBAA0B;IAC3D,4EAA4E;IAC5E,+CAA+C;IAC/C,MAAMgB,yBACJL,uBAAuBG,wBAAwBC;IAEjD;;;;;GAKC,GACD,MAAME,UAAU,CAACC;QACf,MAAMC,QAAQP,OAAOf,QAAQuB,QAAQ,CAACF,MAAM;QAC5C,OAAON,OAAOS,QAAQ,CAACF,UAAUA,SAAS,IAAIA,QAAQ;IACxD;IACA,MAAMG,sBAAsBL,QAAQ;IACpC,MAAMM,wBAAwBN,QAAQ;IACtC,MAAMO,uBAAuBP,QAAQ;IACrC,MAAMQ,mBAAmBR,QAAQ;IAEjC,MAAM,EAAES,MAAM,EAAE,GAAG7B;IACnB,MAAM8B,gBACJD,UAAUJ,wBAAwB,OAAOA,sBAAsBX;IACjE,MAAM,CAACiB,iBAAiBC,gBAAgBC,WAAW,GACjDJ,UAAUH,0BAA0B,OAChC;QAACA;QAAuBC,+BAAAA,uBAAwB;QAAGC,2BAAAA,mBAAoB;KAAE,GACzEC,UAAUJ,wBAAwB,OAChC;QAACA;QAAqB;QAAG;KAAE,GAC3B;QAACN;QAAwBF;QAAuBC;KAAkB;IAE1E,2EAA2E;IAC3E,wEAAwE;IACxE,6BAA6B;IAC7B,MAAMgB,QAAQrC,qBAAqBG,QAAQmC,GAAG,EAAWJ;IACzD,MAAMK,SAASpC,QAAQqC,aAAa,CAAC;IACrC,MAAMC,aAAaF,SAASF,MAAMK,iBAAiB,GAAG;IAEtD,OAAO;QACLC,QAAQ;YACNV;YACAC;YACAC;YACAC;YACA,qEAAqE;YACrE,sDAAsD;YACtDnB;YACAK;YACAsB,oBAAoBH;YACpBI,uBAAuBN;YACvBO,4BAA4BP,SAAS,IAAIF,MAAMK,iBAAiB;QAClE;QACA,yEAAyE;QACzE,gCAAgC;QAChCK,iBAAiB;YACfC,0BAA0B/B;YAC1BgC,4BAA4B3B;YAC5B4B,2BAA2B9B;YAC3B+B,uBAAuB9B;QACzB;QACA+B,WAAWX;QACXY,gBACErB,UAAWJ,CAAAA,wBAAwB,QAAQC,0BAA0B,IAAG;IAC5E;AACF"}
@@ -0,0 +1,108 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import type { PluginApiHandler } from '@aglyn/aglyn/server';
18
+ import { type CrmShareGrant, type CrmSharingObject, type CrmSharingRule, type CrmSharingSite } from '../model/crm-sharing';
19
+ type Firestore = FirebaseFirestore.Firestore;
20
+ /** Test seam, and what a rule write calls so its own process reads it fresh. */
21
+ export declare function forgetCrmSharingRules(orgId?: string): void;
22
+ export declare function crmSharingRulesOf(firestore: Firestore, orgId: string, options?: {
23
+ fresh?: boolean;
24
+ nowMs?: number;
25
+ }): Promise<{
26
+ rules: CrmSharingRule[];
27
+ fresh: boolean;
28
+ }>;
29
+ export interface RecomputeRecordSharingInput {
30
+ firestore: Firestore;
31
+ orgId: string;
32
+ object: CrmSharingObject;
33
+ id: string;
34
+ /** Every rule the org has, in any state. */
35
+ rules: readonly CrmSharingRule[];
36
+ /** Whether `rules` was read just now; a stale list is re-read before it takes a grant away. */
37
+ fresh: boolean;
38
+ /** The hand shares' change, for a share or an unshare. */
39
+ manual?: (grants: Record<string, CrmShareGrant>) => Record<string, CrmShareGrant>;
40
+ atMs: number;
41
+ }
42
+ export type RecomputeOutcome = 'changed' | 'unchanged' | 'missing';
43
+ export declare function recomputeRecordSharing(input: RecomputeRecordSharingInput): Promise<RecomputeOutcome>;
44
+ /**
45
+ * Re-evaluates the org's rules for these records — the one thing a write
46
+ * anywhere owes the sharing. An org with no active rule for the object
47
+ * costs one cached read and nothing else; grants of a rule switched off
48
+ * are taken away by that rule's own removal pass, not here.
49
+ */
50
+ export declare function evaluateCrmSharing(firestore: Firestore, orgId: string, object: CrmSharingObject, ids: readonly string[]): Promise<{
51
+ changed: number;
52
+ missing: number;
53
+ }>;
54
+ /**
55
+ * The core's record-written seam (AGL-3336): every server writer of a lead,
56
+ * a contact, a company or a deal restamps it, and the restamp tells this.
57
+ * Never throws — the write it is told about already landed.
58
+ */
59
+ export declare function crmSharingRecordWritten(event: {
60
+ path: string;
61
+ collection: string;
62
+ }): Promise<void>;
63
+ export declare function crmSharingSites(firestore: Firestore, orgId: string): Promise<CrmSharingSite[]>;
64
+ /**
65
+ * The rule a request describes, judged: an object, a name, sites that are
66
+ * the org's own, targets that are the org's own or all sites. `null` with
67
+ * the reason when it cannot be saved.
68
+ */
69
+ export declare function ruleFromRequest(raw: unknown, context: {
70
+ hostIds: readonly string[];
71
+ existing: CrmSharingRule | null;
72
+ uid: string;
73
+ nowMs: number;
74
+ }): {
75
+ rule: CrmSharingRule;
76
+ error: null;
77
+ } | {
78
+ rule: null;
79
+ error: string;
80
+ };
81
+ /**
82
+ * One budgeted pass of a rule's run, with the progress written on the rule
83
+ * after every page so a reopened settings page shows where it stands and
84
+ * `rule-continue` picks up from the cursor.
85
+ *
86
+ * `apply` walks the object's whole collection by document id — a rule
87
+ * matches on fields no index narrows to (a facet's tags, a site that
88
+ * captured the person) — and writes only the records whose sharing moves.
89
+ * `remove` asks for exactly the records the rule holds a grant on
90
+ * (`sharing.ruleIds`), each of which the recompute then takes it off; a
91
+ * page that makes no progress fails the run rather than looping.
92
+ */
93
+ export declare function advanceSharingRuleRun(firestore: Firestore, orgId: string, ruleId: string, deadlineMs: number): Promise<{
94
+ rule: CrmSharingRule | null;
95
+ more: boolean;
96
+ }>;
97
+ /**
98
+ * `POST /api/crm/sharing` — `{ action, hostId | orgId, … }`.
99
+ *
100
+ * Every action but `evaluate` is an org manager's: an OWNER or ADMIN of the
101
+ * whole workspace (`authorizeOrgCaller(…, 'manage-org')`), under a site's
102
+ * hub or the org's. `evaluate` is what a client-direct write owes the rules
103
+ * and is open to whoever may write the CRM. The plan gate is the CRM's own
104
+ * (`crmSuiteRefusal`): sharing is only meaningful across several sites, and
105
+ * the number of sites a workspace may have is already the plan's.
106
+ */
107
+ export declare const crmSharingHandler: PluginApiHandler;
108
+ export {};