@aglyn/plugins-crm 1.0.0-beta.143
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.
- package/LICENSE +201 -0
- package/README.md +7 -0
- package/package.json +57 -0
- package/src/index.d.ts +21 -0
- package/src/index.js +29 -0
- package/src/index.js.map +1 -0
- package/src/lib/components/activity-list.d.ts +98 -0
- package/src/lib/components/activity-list.js +321 -0
- package/src/lib/components/activity-list.js.map +1 -0
- package/src/lib/components/activity-queries.d.ts +117 -0
- package/src/lib/components/activity-queries.js +198 -0
- package/src/lib/components/activity-queries.js.map +1 -0
- package/src/lib/components/add-to-list-button.d.ts +25 -0
- package/src/lib/components/add-to-list-button.js +64 -0
- package/src/lib/components/add-to-list-button.js.map +1 -0
- package/src/lib/components/add-to-list-dialog.d.ts +24 -0
- package/src/lib/components/add-to-list-dialog.js +327 -0
- package/src/lib/components/add-to-list-dialog.js.map +1 -0
- package/src/lib/components/assignment-rule-drawer.d.ts +43 -0
- package/src/lib/components/assignment-rule-drawer.js +293 -0
- package/src/lib/components/assignment-rule-drawer.js.map +1 -0
- package/src/lib/components/companies-bulk-bar.d.ts +29 -0
- package/src/lib/components/companies-bulk-bar.js +274 -0
- package/src/lib/components/companies-bulk-bar.js.map +1 -0
- package/src/lib/components/companies-section.d.ts +54 -0
- package/src/lib/components/companies-section.js +522 -0
- package/src/lib/components/companies-section.js.map +1 -0
- package/src/lib/components/company-contacts-card.d.ts +49 -0
- package/src/lib/components/company-contacts-card.js +435 -0
- package/src/lib/components/company-contacts-card.js.map +1 -0
- package/src/lib/components/company-deals-card.d.ts +20 -0
- package/src/lib/components/company-deals-card.js +38 -0
- package/src/lib/components/company-deals-card.js.map +1 -0
- package/src/lib/components/company-detail-page.d.ts +20 -0
- package/src/lib/components/company-detail-page.js +165 -0
- package/src/lib/components/company-detail-page.js.map +1 -0
- package/src/lib/components/company-edit-drawer.d.ts +65 -0
- package/src/lib/components/company-edit-drawer.js +433 -0
- package/src/lib/components/company-edit-drawer.js.map +1 -0
- package/src/lib/components/company-import-drawer.d.ts +42 -0
- package/src/lib/components/company-import-drawer.js +99 -0
- package/src/lib/components/company-import-drawer.js.map +1 -0
- package/src/lib/components/company-picker.d.ts +127 -0
- package/src/lib/components/company-picker.js +323 -0
- package/src/lib/components/company-picker.js.map +1 -0
- package/src/lib/components/company-properties-card.d.ts +47 -0
- package/src/lib/components/company-properties-card.js +289 -0
- package/src/lib/components/company-properties-card.js.map +1 -0
- package/src/lib/components/contact-address-fields.d.ts +29 -0
- package/src/lib/components/contact-address-fields.js +149 -0
- package/src/lib/components/contact-address-fields.js.map +1 -0
- package/src/lib/components/contact-associations-card.d.ts +72 -0
- package/src/lib/components/contact-associations-card.js +296 -0
- package/src/lib/components/contact-associations-card.js.map +1 -0
- package/src/lib/components/contact-custom-columns.d.ts +38 -0
- package/src/lib/components/contact-custom-columns.js +102 -0
- package/src/lib/components/contact-custom-columns.js.map +1 -0
- package/src/lib/components/contact-custom-fields-card.d.ts +39 -0
- package/src/lib/components/contact-custom-fields-card.js +204 -0
- package/src/lib/components/contact-custom-fields-card.js.map +1 -0
- package/src/lib/components/contact-deals-card.d.ts +20 -0
- package/src/lib/components/contact-deals-card.js +38 -0
- package/src/lib/components/contact-deals-card.js.map +1 -0
- package/src/lib/components/contact-detail-page.d.ts +46 -0
- package/src/lib/components/contact-detail-page.js +535 -0
- package/src/lib/components/contact-detail-page.js.map +1 -0
- package/src/lib/components/contact-duplicates-card.d.ts +42 -0
- package/src/lib/components/contact-duplicates-card.js +167 -0
- package/src/lib/components/contact-duplicates-card.js.map +1 -0
- package/src/lib/components/contact-field-drawer.d.ts +64 -0
- package/src/lib/components/contact-field-drawer.js +251 -0
- package/src/lib/components/contact-field-drawer.js.map +1 -0
- package/src/lib/components/contact-import-drawer.d.ts +46 -0
- package/src/lib/components/contact-import-drawer.js +149 -0
- package/src/lib/components/contact-import-drawer.js.map +1 -0
- package/src/lib/components/contact-known-by-card.d.ts +39 -0
- package/src/lib/components/contact-known-by-card.js +142 -0
- package/src/lib/components/contact-known-by-card.js.map +1 -0
- package/src/lib/components/contact-list-columns.d.ts +53 -0
- package/src/lib/components/contact-list-columns.js +288 -0
- package/src/lib/components/contact-list-columns.js.map +1 -0
- package/src/lib/components/contact-merge-dialog.d.ts +79 -0
- package/src/lib/components/contact-merge-dialog.js +405 -0
- package/src/lib/components/contact-merge-dialog.js.map +1 -0
- package/src/lib/components/contact-properties-card.d.ts +89 -0
- package/src/lib/components/contact-properties-card.js +492 -0
- package/src/lib/components/contact-properties-card.js.map +1 -0
- package/src/lib/components/contact-timeline-card.d.ts +68 -0
- package/src/lib/components/contact-timeline-card.js +435 -0
- package/src/lib/components/contact-timeline-card.js.map +1 -0
- package/src/lib/components/contacts-bulk-bar.d.ts +91 -0
- package/src/lib/components/contacts-bulk-bar.js +493 -0
- package/src/lib/components/contacts-bulk-bar.js.map +1 -0
- package/src/lib/components/contacts-section.d.ts +26 -0
- package/src/lib/components/contacts-section.js +1025 -0
- package/src/lib/components/contacts-section.js.map +1 -0
- package/src/lib/components/copy-capture-address-button.d.ts +33 -0
- package/src/lib/components/copy-capture-address-button.js +60 -0
- package/src/lib/components/copy-capture-address-button.js.map +1 -0
- package/src/lib/components/crm-attribution-zone.d.ts +38 -0
- package/src/lib/components/crm-attribution-zone.js +36 -0
- package/src/lib/components/crm-attribution-zone.js.map +1 -0
- package/src/lib/components/crm-booking-zone.d.ts +61 -0
- package/src/lib/components/crm-booking-zone.js +50 -0
- package/src/lib/components/crm-booking-zone.js.map +1 -0
- package/src/lib/components/crm-bulk-bar-frame.d.ts +47 -0
- package/src/lib/components/crm-bulk-bar-frame.js +137 -0
- package/src/lib/components/crm-bulk-bar-frame.js.map +1 -0
- package/src/lib/components/crm-call-actions.d.ts +65 -0
- package/src/lib/components/crm-call-actions.js +110 -0
- package/src/lib/components/crm-call-actions.js.map +1 -0
- package/src/lib/components/crm-column-menu.d.ts +21 -0
- package/src/lib/components/crm-column-menu.js +103 -0
- package/src/lib/components/crm-column-menu.js.map +1 -0
- package/src/lib/components/crm-console-page.d.ts +19 -0
- package/src/lib/components/crm-console-page.js +151 -0
- package/src/lib/components/crm-console-page.js.map +1 -0
- package/src/lib/components/crm-console-sections.d.ts +52 -0
- package/src/lib/components/crm-console-sections.js +83 -0
- package/src/lib/components/crm-console-sections.js.map +1 -0
- package/src/lib/components/crm-custom-field-control.d.ts +26 -0
- package/src/lib/components/crm-custom-field-control.js +131 -0
- package/src/lib/components/crm-custom-field-control.js.map +1 -0
- package/src/lib/components/crm-email-template-tools.d.ts +69 -0
- package/src/lib/components/crm-email-template-tools.js +240 -0
- package/src/lib/components/crm-email-template-tools.js.map +1 -0
- package/src/lib/components/crm-export-all-button.d.ts +39 -0
- package/src/lib/components/crm-export-all-button.js +98 -0
- package/src/lib/components/crm-export-all-button.js.map +1 -0
- package/src/lib/components/crm-filter-bar.d.ts +53 -0
- package/src/lib/components/crm-filter-bar.js +294 -0
- package/src/lib/components/crm-filter-bar.js.map +1 -0
- package/src/lib/components/crm-glance-card.d.ts +54 -0
- package/src/lib/components/crm-glance-card.js +219 -0
- package/src/lib/components/crm-glance-card.js.map +1 -0
- package/src/lib/components/crm-next-activity-column.d.ts +35 -0
- package/src/lib/components/crm-next-activity-column.js +100 -0
- package/src/lib/components/crm-next-activity-column.js.map +1 -0
- package/src/lib/components/crm-record-header.d.ts +97 -0
- package/src/lib/components/crm-record-header.js +160 -0
- package/src/lib/components/crm-record-header.js.map +1 -0
- package/src/lib/components/crm-record-insights-zone.d.ts +50 -0
- package/src/lib/components/crm-record-insights-zone.js +169 -0
- package/src/lib/components/crm-record-insights-zone.js.map +1 -0
- package/src/lib/components/crm-record-picker.d.ts +42 -0
- package/src/lib/components/crm-record-picker.js +104 -0
- package/src/lib/components/crm-record-picker.js.map +1 -0
- package/src/lib/components/crm-send-email-button.d.ts +39 -0
- package/src/lib/components/crm-send-email-button.js +81 -0
- package/src/lib/components/crm-send-email-button.js.map +1 -0
- package/src/lib/components/crm-send-email-dialog.d.ts +61 -0
- package/src/lib/components/crm-send-email-dialog.js +851 -0
- package/src/lib/components/crm-send-email-dialog.js.map +1 -0
- package/src/lib/components/crm-site-picker.d.ts +61 -0
- package/src/lib/components/crm-site-picker.js +99 -0
- package/src/lib/components/crm-site-picker.js.map +1 -0
- package/src/lib/components/crm-suite-lock.d.ts +29 -0
- package/src/lib/components/crm-suite-lock.js +114 -0
- package/src/lib/components/crm-suite-lock.js.map +1 -0
- package/src/lib/components/crm-tasks-due-card.d.ts +42 -0
- package/src/lib/components/crm-tasks-due-card.js +225 -0
- package/src/lib/components/crm-tasks-due-card.js.map +1 -0
- package/src/lib/components/crm-views-control.d.ts +65 -0
- package/src/lib/components/crm-views-control.js +518 -0
- package/src/lib/components/crm-views-control.js.map +1 -0
- package/src/lib/components/csv-import-drawer.d.ts +132 -0
- package/src/lib/components/csv-import-drawer.js +746 -0
- package/src/lib/components/csv-import-drawer.js.map +1 -0
- package/src/lib/components/deal-board.d.ts +70 -0
- package/src/lib/components/deal-board.js +478 -0
- package/src/lib/components/deal-board.js.map +1 -0
- package/src/lib/components/deal-detail-page.d.ts +18 -0
- package/src/lib/components/deal-detail-page.js +323 -0
- package/src/lib/components/deal-detail-page.js.map +1 -0
- package/src/lib/components/deal-edit-drawer.d.ts +59 -0
- package/src/lib/components/deal-edit-drawer.js +640 -0
- package/src/lib/components/deal-edit-drawer.js.map +1 -0
- package/src/lib/components/deal-import-drawer.d.ts +24 -0
- package/src/lib/components/deal-import-drawer.js +83 -0
- package/src/lib/components/deal-import-drawer.js.map +1 -0
- package/src/lib/components/deal-products-card.d.ts +48 -0
- package/src/lib/components/deal-products-card.js +614 -0
- package/src/lib/components/deal-products-card.js.map +1 -0
- package/src/lib/components/deal-properties-card.d.ts +29 -0
- package/src/lib/components/deal-properties-card.js +144 -0
- package/src/lib/components/deal-properties-card.js.map +1 -0
- package/src/lib/components/deal-stage-card.d.ts +24 -0
- package/src/lib/components/deal-stage-card.js +199 -0
- package/src/lib/components/deal-stage-card.js.map +1 -0
- package/src/lib/components/deals-bulk-bar.d.ts +31 -0
- package/src/lib/components/deals-bulk-bar.js +340 -0
- package/src/lib/components/deals-bulk-bar.js.map +1 -0
- package/src/lib/components/deals-section.d.ts +49 -0
- package/src/lib/components/deals-section.js +767 -0
- package/src/lib/components/deals-section.js.map +1 -0
- package/src/lib/components/email-capture-card.d.ts +42 -0
- package/src/lib/components/email-capture-card.js +134 -0
- package/src/lib/components/email-capture-card.js.map +1 -0
- package/src/lib/components/email-template-drawer.d.ts +33 -0
- package/src/lib/components/email-template-drawer.js +209 -0
- package/src/lib/components/email-template-drawer.js.map +1 -0
- package/src/lib/components/email-templates-card.d.ts +33 -0
- package/src/lib/components/email-templates-card.js +370 -0
- package/src/lib/components/email-templates-card.js.map +1 -0
- package/src/lib/components/erase-person-action.d.ts +92 -0
- package/src/lib/components/erase-person-action.js +261 -0
- package/src/lib/components/erase-person-action.js.map +1 -0
- package/src/lib/components/fields-section.d.ts +37 -0
- package/src/lib/components/fields-section.js +641 -0
- package/src/lib/components/fields-section.js.map +1 -0
- package/src/lib/components/form-contact-fields-card.d.ts +46 -0
- package/src/lib/components/form-contact-fields-card.js +253 -0
- package/src/lib/components/form-contact-fields-card.js.map +1 -0
- package/src/lib/components/insert-link-at-caret.d.ts +28 -0
- package/src/lib/components/insert-link-at-caret.js +37 -0
- package/src/lib/components/insert-link-at-caret.js.map +1 -0
- package/src/lib/components/lead-convert-dialog.d.ts +32 -0
- package/src/lib/components/lead-convert-dialog.js +493 -0
- package/src/lib/components/lead-convert-dialog.js.map +1 -0
- package/src/lib/components/lead-detail-page.d.ts +16 -0
- package/src/lib/components/lead-detail-page.js +163 -0
- package/src/lib/components/lead-detail-page.js.map +1 -0
- package/src/lib/components/lead-history-card.d.ts +32 -0
- package/src/lib/components/lead-history-card.js +165 -0
- package/src/lib/components/lead-history-card.js.map +1 -0
- package/src/lib/components/lead-import-drawer.d.ts +24 -0
- package/src/lib/components/lead-import-drawer.js +95 -0
- package/src/lib/components/lead-import-drawer.js.map +1 -0
- package/src/lib/components/lead-owner-select.d.ts +35 -0
- package/src/lib/components/lead-owner-select.js +91 -0
- package/src/lib/components/lead-owner-select.js.map +1 -0
- package/src/lib/components/lead-properties-card.d.ts +61 -0
- package/src/lib/components/lead-properties-card.js +395 -0
- package/src/lib/components/lead-properties-card.js.map +1 -0
- package/src/lib/components/lead-status-chip.d.ts +12 -0
- package/src/lib/components/lead-status-chip.js +43 -0
- package/src/lib/components/lead-status-chip.js.map +1 -0
- package/src/lib/components/lead-surfaces-note.d.ts +126 -0
- package/src/lib/components/lead-surfaces-note.js +262 -0
- package/src/lib/components/lead-surfaces-note.js.map +1 -0
- package/src/lib/components/lead-unqualify-dialog.d.ts +24 -0
- package/src/lib/components/lead-unqualify-dialog.js +125 -0
- package/src/lib/components/lead-unqualify-dialog.js.map +1 -0
- package/src/lib/components/leads-bulk-bar.d.ts +58 -0
- package/src/lib/components/leads-bulk-bar.js +307 -0
- package/src/lib/components/leads-bulk-bar.js.map +1 -0
- package/src/lib/components/leads-section.d.ts +23 -0
- package/src/lib/components/leads-section.js +664 -0
- package/src/lib/components/leads-section.js.map +1 -0
- package/src/lib/components/linked-deals-card.d.ts +32 -0
- package/src/lib/components/linked-deals-card.js +163 -0
- package/src/lib/components/linked-deals-card.js.map +1 -0
- package/src/lib/components/log-activity-dialog.d.ts +60 -0
- package/src/lib/components/log-activity-dialog.js +368 -0
- package/src/lib/components/log-activity-dialog.js.map +1 -0
- package/src/lib/components/lost-reason-dialog.d.ts +26 -0
- package/src/lib/components/lost-reason-dialog.js +95 -0
- package/src/lib/components/lost-reason-dialog.js.map +1 -0
- package/src/lib/components/new-contact-drawer.d.ts +78 -0
- package/src/lib/components/new-contact-drawer.js +343 -0
- package/src/lib/components/new-contact-drawer.js.map +1 -0
- package/src/lib/components/org-lead-surfaces-note.d.ts +57 -0
- package/src/lib/components/org-lead-surfaces-note.js +172 -0
- package/src/lib/components/org-lead-surfaces-note.js.map +1 -0
- package/src/lib/components/owner-avatar.d.ts +18 -0
- package/src/lib/components/owner-avatar.js +61 -0
- package/src/lib/components/owner-avatar.js.map +1 -0
- package/src/lib/components/pipeline-stages-dialog.d.ts +43 -0
- package/src/lib/components/pipeline-stages-dialog.js +339 -0
- package/src/lib/components/pipeline-stages-dialog.js.map +1 -0
- package/src/lib/components/pipelines-dialog.d.ts +55 -0
- package/src/lib/components/pipelines-dialog.js +517 -0
- package/src/lib/components/pipelines-dialog.js.map +1 -0
- package/src/lib/components/recent-activity-feed.d.ts +39 -0
- package/src/lib/components/recent-activity-feed.js +103 -0
- package/src/lib/components/recent-activity-feed.js.map +1 -0
- package/src/lib/components/recipes-card.d.ts +39 -0
- package/src/lib/components/recipes-card.js +485 -0
- package/src/lib/components/recipes-card.js.map +1 -0
- package/src/lib/components/record-activity-card.d.ts +26 -0
- package/src/lib/components/record-activity-card.js +121 -0
- package/src/lib/components/record-activity-card.js.map +1 -0
- package/src/lib/components/record-files-card.d.ts +67 -0
- package/src/lib/components/record-files-card.js +290 -0
- package/src/lib/components/record-files-card.js.map +1 -0
- package/src/lib/components/record-tasks-card.d.ts +32 -0
- package/src/lib/components/record-tasks-card.js +306 -0
- package/src/lib/components/record-tasks-card.js.map +1 -0
- package/src/lib/components/reports/activity-card.d.ts +57 -0
- package/src/lib/components/reports/activity-card.js +281 -0
- package/src/lib/components/reports/activity-card.js.map +1 -0
- package/src/lib/components/reports/closed-deals-card.d.ts +20 -0
- package/src/lib/components/reports/closed-deals-card.js +194 -0
- package/src/lib/components/reports/closed-deals-card.js.map +1 -0
- package/src/lib/components/reports/contacts-mix-card.d.ts +27 -0
- package/src/lib/components/reports/contacts-mix-card.js +161 -0
- package/src/lib/components/reports/contacts-mix-card.js.map +1 -0
- package/src/lib/components/reports/contacts-trend-card.d.ts +31 -0
- package/src/lib/components/reports/contacts-trend-card.js +144 -0
- package/src/lib/components/reports/contacts-trend-card.js.map +1 -0
- package/src/lib/components/reports/forecast-card.d.ts +22 -0
- package/src/lib/components/reports/forecast-card.js +251 -0
- package/src/lib/components/reports/forecast-card.js.map +1 -0
- package/src/lib/components/reports/lead-counts.d.ts +32 -0
- package/src/lib/components/reports/lead-counts.js +44 -0
- package/src/lib/components/reports/lead-counts.js.map +1 -0
- package/src/lib/components/reports/lead-funnel-card.d.ts +38 -0
- package/src/lib/components/reports/lead-funnel-card.js +375 -0
- package/src/lib/components/reports/lead-funnel-card.js.map +1 -0
- package/src/lib/components/reports/pipeline-card.d.ts +19 -0
- package/src/lib/components/reports/pipeline-card.js +338 -0
- package/src/lib/components/reports/pipeline-card.js.map +1 -0
- package/src/lib/components/reports/report-bar-chart.d.ts +39 -0
- package/src/lib/components/reports/report-bar-chart.js +133 -0
- package/src/lib/components/reports/report-bar-chart.js.map +1 -0
- package/src/lib/components/reports/report-breakdown.d.ts +32 -0
- package/src/lib/components/reports/report-breakdown.js +105 -0
- package/src/lib/components/reports/report-breakdown.js.map +1 -0
- package/src/lib/components/reports/report-export.d.ts +37 -0
- package/src/lib/components/reports/report-export.js +66 -0
- package/src/lib/components/reports/report-export.js.map +1 -0
- package/src/lib/components/reports/report-format.d.ts +36 -0
- package/src/lib/components/reports/report-format.js +43 -0
- package/src/lib/components/reports/report-format.js.map +1 -0
- package/src/lib/components/reports/report-scope.d.ts +81 -0
- package/src/lib/components/reports/report-scope.js +58 -0
- package/src/lib/components/reports/report-scope.js.map +1 -0
- package/src/lib/components/reports/report-stat-tile.d.ts +47 -0
- package/src/lib/components/reports/report-stat-tile.js +96 -0
- package/src/lib/components/reports/report-stat-tile.js.map +1 -0
- package/src/lib/components/reports/source-conversion-card.d.ts +28 -0
- package/src/lib/components/reports/source-conversion-card.js +205 -0
- package/src/lib/components/reports/source-conversion-card.js.map +1 -0
- package/src/lib/components/reports/tasks-card.d.ts +26 -0
- package/src/lib/components/reports/tasks-card.js +279 -0
- package/src/lib/components/reports/tasks-card.js.map +1 -0
- package/src/lib/components/reports/use-aggregate-read.d.ts +99 -0
- package/src/lib/components/reports/use-aggregate-read.js +195 -0
- package/src/lib/components/reports/use-aggregate-read.js.map +1 -0
- package/src/lib/components/reports/won-lost-by-owner-card.d.ts +30 -0
- package/src/lib/components/reports/won-lost-by-owner-card.js +168 -0
- package/src/lib/components/reports/won-lost-by-owner-card.js.map +1 -0
- package/src/lib/components/reports-section.d.ts +42 -0
- package/src/lib/components/reports-section.js +308 -0
- package/src/lib/components/reports-section.js.map +1 -0
- package/src/lib/components/sending-addresses-card.d.ts +49 -0
- package/src/lib/components/sending-addresses-card.js +262 -0
- package/src/lib/components/sending-addresses-card.js.map +1 -0
- package/src/lib/components/settings-section.d.ts +151 -0
- package/src/lib/components/settings-section.js +783 -0
- package/src/lib/components/settings-section.js.map +1 -0
- package/src/lib/components/task-cells.d.ts +51 -0
- package/src/lib/components/task-cells.js +139 -0
- package/src/lib/components/task-cells.js.map +1 -0
- package/src/lib/components/task-edit-drawer.d.ts +53 -0
- package/src/lib/components/task-edit-drawer.js +483 -0
- package/src/lib/components/task-edit-drawer.js.map +1 -0
- package/src/lib/components/task-import-drawer.d.ts +24 -0
- package/src/lib/components/task-import-drawer.js +82 -0
- package/src/lib/components/task-import-drawer.js.map +1 -0
- package/src/lib/components/task-snooze-menu.d.ts +65 -0
- package/src/lib/components/task-snooze-menu.js +207 -0
- package/src/lib/components/task-snooze-menu.js.map +1 -0
- package/src/lib/components/tasks-bulk-bar.d.ts +25 -0
- package/src/lib/components/tasks-bulk-bar.js +348 -0
- package/src/lib/components/tasks-bulk-bar.js.map +1 -0
- package/src/lib/components/tasks-calendar.d.ts +38 -0
- package/src/lib/components/tasks-calendar.js +228 -0
- package/src/lib/components/tasks-calendar.js.map +1 -0
- package/src/lib/components/tasks-section.d.ts +27 -0
- package/src/lib/components/tasks-section.js +579 -0
- package/src/lib/components/tasks-section.js.map +1 -0
- package/src/lib/components/use-contact-campaign-emails.d.ts +32 -0
- package/src/lib/components/use-contact-campaign-emails.js +83 -0
- package/src/lib/components/use-contact-campaign-emails.js.map +1 -0
- package/src/lib/components/use-crm-api.d.ts +44 -0
- package/src/lib/components/use-crm-api.js +84 -0
- package/src/lib/components/use-crm-api.js.map +1 -0
- package/src/lib/components/use-crm-inbound-address.d.ts +60 -0
- package/src/lib/components/use-crm-inbound-address.js +124 -0
- package/src/lib/components/use-crm-inbound-address.js.map +1 -0
- package/src/lib/components/use-emails-hub-path.d.ts +24 -0
- package/src/lib/components/use-emails-hub-path.js +59 -0
- package/src/lib/components/use-emails-hub-path.js.map +1 -0
- package/src/lib/components/use-member-email-aliases.d.ts +54 -0
- package/src/lib/components/use-member-email-aliases.js +186 -0
- package/src/lib/components/use-member-email-aliases.js.map +1 -0
- package/src/lib/components/use-org-members.d.ts +40 -0
- package/src/lib/components/use-org-members.js +100 -0
- package/src/lib/components/use-org-members.js.map +1 -0
- package/src/lib/constants/api-routes.d.ts +109 -0
- package/src/lib/constants/api-routes.js +74 -0
- package/src/lib/constants/api-routes.js.map +1 -0
- package/src/lib/constants/bundle-common.d.ts +14 -0
- package/src/lib/constants/bundle-common.js +14 -0
- package/src/lib/constants/bundle-common.js.map +1 -0
- package/src/lib/constants/company-filters.d.ts +18 -0
- package/src/lib/constants/company-filters.js +51 -0
- package/src/lib/constants/company-filters.js.map +1 -0
- package/src/lib/constants/contact-filters.d.ts +38 -0
- package/src/lib/constants/contact-filters.js +294 -0
- package/src/lib/constants/contact-filters.js.map +1 -0
- package/src/lib/hooks/use-contact-field-definitions.d.ts +48 -0
- package/src/lib/hooks/use-contact-field-definitions.js +72 -0
- package/src/lib/hooks/use-contact-field-definitions.js.map +1 -0
- package/src/lib/hooks/use-contact-update.d.ts +25 -0
- package/src/lib/hooks/use-contact-update.js +80 -0
- package/src/lib/hooks/use-contact-update.js.map +1 -0
- package/src/lib/hooks/use-crm-activity-logger.d.ts +73 -0
- package/src/lib/hooks/use-crm-activity-logger.js +101 -0
- package/src/lib/hooks/use-crm-activity-logger.js.map +1 -0
- package/src/lib/hooks/use-crm-bulk-apply.d.ts +52 -0
- package/src/lib/hooks/use-crm-bulk-apply.js +112 -0
- package/src/lib/hooks/use-crm-bulk-apply.js.map +1 -0
- package/src/lib/hooks/use-crm-default-view.d.ts +24 -0
- package/src/lib/hooks/use-crm-default-view.js +64 -0
- package/src/lib/hooks/use-crm-default-view.js.map +1 -0
- package/src/lib/hooks/use-crm-email-templates.d.ts +59 -0
- package/src/lib/hooks/use-crm-email-templates.js +103 -0
- package/src/lib/hooks/use-crm-email-templates.js.map +1 -0
- package/src/lib/hooks/use-crm-hub-path.d.ts +29 -0
- package/src/lib/hooks/use-crm-hub-path.js +41 -0
- package/src/lib/hooks/use-crm-hub-path.js.map +1 -0
- package/src/lib/hooks/use-crm-org-mount.d.ts +97 -0
- package/src/lib/hooks/use-crm-org-mount.js +215 -0
- package/src/lib/hooks/use-crm-org-mount.js.map +1 -0
- package/src/lib/hooks/use-crm-record-names.d.ts +52 -0
- package/src/lib/hooks/use-crm-record-names.js +126 -0
- package/src/lib/hooks/use-crm-record-names.js.map +1 -0
- package/src/lib/hooks/use-crm-records-quota.d.ts +68 -0
- package/src/lib/hooks/use-crm-records-quota.js +118 -0
- package/src/lib/hooks/use-crm-records-quota.js.map +1 -0
- package/src/lib/hooks/use-crm-saved-view.d.ts +96 -0
- package/src/lib/hooks/use-crm-saved-view.js +329 -0
- package/src/lib/hooks/use-crm-saved-view.js.map +1 -0
- package/src/lib/hooks/use-crm-scope.d.ts +117 -0
- package/src/lib/hooks/use-crm-scope.js +147 -0
- package/src/lib/hooks/use-crm-scope.js.map +1 -0
- package/src/lib/hooks/use-crm-tasks.d.ts +85 -0
- package/src/lib/hooks/use-crm-tasks.js +153 -0
- package/src/lib/hooks/use-crm-tasks.js.map +1 -0
- package/src/lib/hooks/use-crm-view-grid.d.ts +55 -0
- package/src/lib/hooks/use-crm-view-grid.js +170 -0
- package/src/lib/hooks/use-crm-view-grid.js.map +1 -0
- package/src/lib/hooks/use-crm-views.d.ts +42 -0
- package/src/lib/hooks/use-crm-views.js +84 -0
- package/src/lib/hooks/use-crm-views.js.map +1 -0
- package/src/lib/hooks/use-deal-stage-api.d.ts +69 -0
- package/src/lib/hooks/use-deal-stage-api.js +78 -0
- package/src/lib/hooks/use-deal-stage-api.js.map +1 -0
- package/src/lib/hooks/use-deals.d.ts +47 -0
- package/src/lib/hooks/use-deals.js +105 -0
- package/src/lib/hooks/use-deals.js.map +1 -0
- package/src/lib/hooks/use-org-leads.d.ts +53 -0
- package/src/lib/hooks/use-org-leads.js +114 -0
- package/src/lib/hooks/use-org-leads.js.map +1 -0
- package/src/lib/hooks/use-org-member-directory.d.ts +36 -0
- package/src/lib/hooks/use-org-member-directory.js +116 -0
- package/src/lib/hooks/use-org-member-directory.js.map +1 -0
- package/src/lib/hooks/use-org-member-options.d.ts +38 -0
- package/src/lib/hooks/use-org-member-options.js +131 -0
- package/src/lib/hooks/use-org-member-options.js.map +1 -0
- package/src/lib/hooks/use-pipeline.d.ts +71 -0
- package/src/lib/hooks/use-pipeline.js +159 -0
- package/src/lib/hooks/use-pipeline.js.map +1 -0
- package/src/lib/model/companies-bulk-writes.d.ts +40 -0
- package/src/lib/model/companies-bulk-writes.js +103 -0
- package/src/lib/model/companies-bulk-writes.js.map +1 -0
- package/src/lib/model/companies-csv.d.ts +36 -0
- package/src/lib/model/companies-csv.js +38 -0
- package/src/lib/model/companies-csv.js.map +1 -0
- package/src/lib/model/companies.d.ts +99 -0
- package/src/lib/model/companies.js +168 -0
- package/src/lib/model/companies.js.map +1 -0
- package/src/lib/model/company-delete-route.d.ts +43 -0
- package/src/lib/model/company-delete-route.js +31 -0
- package/src/lib/model/company-delete-route.js.map +1 -0
- package/src/lib/model/company-delete.d.ts +42 -0
- package/src/lib/model/company-delete.js +52 -0
- package/src/lib/model/company-delete.js.map +1 -0
- package/src/lib/model/contact-duplicates.d.ts +58 -0
- package/src/lib/model/contact-duplicates.js +67 -0
- package/src/lib/model/contact-duplicates.js.map +1 -0
- package/src/lib/model/contact-record.d.ts +113 -0
- package/src/lib/model/contact-record.js +70 -0
- package/src/lib/model/contact-record.js.map +1 -0
- package/src/lib/model/contact-update.d.ts +93 -0
- package/src/lib/model/contact-update.js +50 -0
- package/src/lib/model/contact-update.js.map +1 -0
- package/src/lib/model/contacts-bulk-writes.d.ts +173 -0
- package/src/lib/model/contacts-bulk-writes.js +196 -0
- package/src/lib/model/contacts-bulk-writes.js.map +1 -0
- package/src/lib/model/contacts-csv.d.ts +54 -0
- package/src/lib/model/contacts-csv.js +67 -0
- package/src/lib/model/contacts-csv.js.map +1 -0
- package/src/lib/model/contacts-list-seed.d.ts +51 -0
- package/src/lib/model/contacts-list-seed.js +63 -0
- package/src/lib/model/contacts-list-seed.js.map +1 -0
- package/src/lib/model/crm-activity-report.d.ts +27 -0
- package/src/lib/model/crm-activity-report.js +56 -0
- package/src/lib/model/crm-activity-report.js.map +1 -0
- package/src/lib/model/crm-api.d.ts +49 -0
- package/src/lib/model/crm-api.js +47 -0
- package/src/lib/model/crm-api.js.map +1 -0
- package/src/lib/model/crm-bulk-writes.d.ts +147 -0
- package/src/lib/model/crm-bulk-writes.js +207 -0
- package/src/lib/model/crm-bulk-writes.js.map +1 -0
- package/src/lib/model/crm-company-import.d.ts +154 -0
- package/src/lib/model/crm-company-import.js +331 -0
- package/src/lib/model/crm-company-import.js.map +1 -0
- package/src/lib/model/crm-custom-draft.d.ts +62 -0
- package/src/lib/model/crm-custom-draft.js +67 -0
- package/src/lib/model/crm-custom-draft.js.map +1 -0
- package/src/lib/model/crm-deal-import.d.ts +112 -0
- package/src/lib/model/crm-deal-import.js +263 -0
- package/src/lib/model/crm-deal-import.js.map +1 -0
- package/src/lib/model/crm-import.d.ts +244 -0
- package/src/lib/model/crm-import.js +466 -0
- package/src/lib/model/crm-import.js.map +1 -0
- package/src/lib/model/crm-lead-import.d.ts +105 -0
- package/src/lib/model/crm-lead-import.js +255 -0
- package/src/lib/model/crm-lead-import.js.map +1 -0
- package/src/lib/model/crm-record-routes.d.ts +21 -0
- package/src/lib/model/crm-record-routes.js +70 -0
- package/src/lib/model/crm-record-routes.js.map +1 -0
- package/src/lib/model/crm-routes.d.ts +101 -0
- package/src/lib/model/crm-routes.js +92 -0
- package/src/lib/model/crm-routes.js.map +1 -0
- package/src/lib/model/crm-task-import.d.ts +94 -0
- package/src/lib/model/crm-task-import.js +275 -0
- package/src/lib/model/crm-task-import.js.map +1 -0
- package/src/lib/model/crm-view-param.d.ts +43 -0
- package/src/lib/model/crm-view-param.js +49 -0
- package/src/lib/model/crm-view-param.js.map +1 -0
- package/src/lib/model/deal-board-model.d.ts +241 -0
- package/src/lib/model/deal-board-model.js +439 -0
- package/src/lib/model/deal-board-model.js.map +1 -0
- package/src/lib/model/deal-form-model.d.ts +114 -0
- package/src/lib/model/deal-form-model.js +218 -0
- package/src/lib/model/deal-form-model.js.map +1 -0
- package/src/lib/model/deals-csv.d.ts +32 -0
- package/src/lib/model/deals-csv.js +37 -0
- package/src/lib/model/deals-csv.js.map +1 -0
- package/src/lib/model/import-column-shapes.d.ts +36 -0
- package/src/lib/model/import-column-shapes.js +76 -0
- package/src/lib/model/import-column-shapes.js.map +1 -0
- package/src/lib/model/lead-company-suggestion.d.ts +61 -0
- package/src/lib/model/lead-company-suggestion.js +65 -0
- package/src/lib/model/lead-company-suggestion.js.map +1 -0
- package/src/lib/model/lead-filters.d.ts +29 -0
- package/src/lib/model/lead-filters.js +39 -0
- package/src/lib/model/lead-filters.js.map +1 -0
- package/src/lib/model/lead-surfaces.d.ts +58 -0
- package/src/lib/model/lead-surfaces.js +67 -0
- package/src/lib/model/lead-surfaces.js.map +1 -0
- package/src/lib/model/leads-csv.d.ts +40 -0
- package/src/lib/model/leads-csv.js +40 -0
- package/src/lib/model/leads-csv.js.map +1 -0
- package/src/lib/model/next-activity-api.d.ts +31 -0
- package/src/lib/model/next-activity-api.js +57 -0
- package/src/lib/model/next-activity-api.js.map +1 -0
- package/src/lib/model/next-activity.d.ts +64 -0
- package/src/lib/model/next-activity.js +47 -0
- package/src/lib/model/next-activity.js.map +1 -0
- package/src/lib/model/person-key-web.d.ts +43 -0
- package/src/lib/model/person-key-web.js +52 -0
- package/src/lib/model/person-key-web.js.map +1 -0
- package/src/lib/model/record-facts.d.ts +282 -0
- package/src/lib/model/record-facts.js +434 -0
- package/src/lib/model/record-facts.js.map +1 -0
- package/src/lib/model/task-api.d.ts +28 -0
- package/src/lib/model/task-api.js +57 -0
- package/src/lib/model/task-api.js.map +1 -0
- package/src/lib/model/task-calendar.d.ts +108 -0
- package/src/lib/model/task-calendar.js +139 -0
- package/src/lib/model/task-calendar.js.map +1 -0
- package/src/lib/model/task-routes.d.ts +177 -0
- package/src/lib/model/task-routes.js +197 -0
- package/src/lib/model/task-routes.js.map +1 -0
- package/src/lib/model/task-scope.d.ts +45 -0
- package/src/lib/model/task-scope.js +51 -0
- package/src/lib/model/task-scope.js.map +1 -0
- package/src/lib/model/task-views.d.ts +149 -0
- package/src/lib/model/task-views.js +286 -0
- package/src/lib/model/task-views.js.map +1 -0
- package/src/lib/model/tasks-csv.d.ts +28 -0
- package/src/lib/model/tasks-csv.js +28 -0
- package/src/lib/model/tasks-csv.js.map +1 -0
- package/src/lib/plugin.d.ts +32 -0
- package/src/lib/plugin.js +208 -0
- package/src/lib/plugin.js.map +1 -0
- package/src/lib/server/companies-import.d.ts +57 -0
- package/src/lib/server/companies-import.js +242 -0
- package/src/lib/server/companies-import.js.map +1 -0
- package/src/lib/server/company-delete.d.ts +59 -0
- package/src/lib/server/company-delete.js +146 -0
- package/src/lib/server/company-delete.js.map +1 -0
- package/src/lib/server/contact-email-history.d.ts +82 -0
- package/src/lib/server/contact-email-history.js +264 -0
- package/src/lib/server/contact-email-history.js.map +1 -0
- package/src/lib/server/contact-profile.d.ts +41 -0
- package/src/lib/server/contact-profile.js +45 -0
- package/src/lib/server/contact-profile.js.map +1 -0
- package/src/lib/server/contact-update.d.ts +92 -0
- package/src/lib/server/contact-update.js +512 -0
- package/src/lib/server/contact-update.js.map +1 -0
- package/src/lib/server/contacts-import.d.ts +73 -0
- package/src/lib/server/contacts-import.js +263 -0
- package/src/lib/server/contacts-import.js.map +1 -0
- package/src/lib/server/contacts-merge.d.ts +86 -0
- package/src/lib/server/contacts-merge.js +206 -0
- package/src/lib/server/contacts-merge.js.map +1 -0
- package/src/lib/server/deals-import.d.ts +76 -0
- package/src/lib/server/deals-import.js +246 -0
- package/src/lib/server/deals-import.js.map +1 -0
- package/src/lib/server/email-send.d.ts +119 -0
- package/src/lib/server/email-send.js +667 -0
- package/src/lib/server/email-send.js.map +1 -0
- package/src/lib/server/email-template-duplicate.d.ts +19 -0
- package/src/lib/server/email-template-duplicate.js +206 -0
- package/src/lib/server/email-template-duplicate.js.map +1 -0
- package/src/lib/server/erase-person.d.ts +108 -0
- package/src/lib/server/erase-person.js +309 -0
- package/src/lib/server/erase-person.js.map +1 -0
- package/src/lib/server/import-context.d.ts +85 -0
- package/src/lib/server/import-context.js +181 -0
- package/src/lib/server/import-context.js.map +1 -0
- package/src/lib/server/inbound-address.d.ts +61 -0
- package/src/lib/server/inbound-address.js +188 -0
- package/src/lib/server/inbound-address.js.map +1 -0
- package/src/lib/server/lead-convert.d.ts +78 -0
- package/src/lib/server/lead-convert.js +250 -0
- package/src/lib/server/lead-convert.js.map +1 -0
- package/src/lib/server/leads-import.d.ts +84 -0
- package/src/lib/server/leads-import.js +261 -0
- package/src/lib/server/leads-import.js.map +1 -0
- package/src/lib/server/next-activity-routes.d.ts +33 -0
- package/src/lib/server/next-activity-routes.js +110 -0
- package/src/lib/server/next-activity-routes.js.map +1 -0
- package/src/lib/server/org-activity.d.ts +61 -0
- package/src/lib/server/org-activity.js +120 -0
- package/src/lib/server/org-activity.js.map +1 -0
- package/src/lib/server/org-caller.d.ts +110 -0
- package/src/lib/server/org-caller.js +154 -0
- package/src/lib/server/org-caller.js.map +1 -0
- package/src/lib/server/recipe-routes.d.ts +75 -0
- package/src/lib/server/recipe-routes.js +442 -0
- package/src/lib/server/recipe-routes.js.map +1 -0
- package/src/lib/server/record-facts.d.ts +65 -0
- package/src/lib/server/record-facts.js +337 -0
- package/src/lib/server/record-facts.js.map +1 -0
- package/src/lib/server/record-timeline.d.ts +51 -0
- package/src/lib/server/record-timeline.js +215 -0
- package/src/lib/server/record-timeline.js.map +1 -0
- package/src/lib/server/suite-gate.d.ts +42 -0
- package/src/lib/server/suite-gate.js +87 -0
- package/src/lib/server/suite-gate.js.map +1 -0
- package/src/lib/server/task-routes.d.ts +132 -0
- package/src/lib/server/task-routes.js +699 -0
- package/src/lib/server/task-routes.js.map +1 -0
- package/src/lib/server/tasks-import.d.ts +54 -0
- package/src/lib/server/tasks-import.js +157 -0
- package/src/lib/server/tasks-import.js.map +1 -0
- package/src/lib/server-deal-stage.d.ts +88 -0
- package/src/lib/server-deal-stage.js +316 -0
- package/src/lib/server-deal-stage.js.map +1 -0
- package/src/lib/server.d.ts +149 -0
- package/src/lib/server.js +615 -0
- package/src/lib/server.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/server/task-routes.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 {\n type AglynOrgMember,\n consentGroupForHost,\n CRM_COLLECTIONS,\n type CrmTask,\n crmScopeTokens,\n crmTaskReminderAfterEdit,\n crmTaskReminderPending,\n isOrgWideMember,\n memberCanSee,\n type PluginApiHandler,\n type PluginApiRequest,\n type PluginApiResponse,\n} from '@aglyn/aglyn/server'\nimport {\n crmNextActivityLinksOf,\n firebaseAdmin,\n getOrgForHost,\n memberHasOrgPermission,\n notifyUsers,\n recomputeCrmNextTaskAt,\n resolveOrgMembership,\n} from '@aglyn/tenant-data-admin'\nimport { emitHostEvent } from '@aglyn/tenant-runtime'\nimport { FieldValue } from 'firebase-admin/firestore'\nimport {\n CRM_TASK_BATCH_MAX,\n type CrmTaskCompleteOutcome,\n type CrmTaskCompleteResponse,\n type CrmTaskFields,\n type CrmTaskSaveOutcome,\n type CrmTaskSaveResponse,\n type CrmTasksCompleteResponse,\n type CrmTasksSaveResponse,\n readCrmTaskFields,\n} from '../model/task-routes'\nimport { CRM_ORG_TASK_SCOPE } from '../model/task-scope'\nimport {\n authorizeOrgCaller,\n type CrmRouteScope,\n readCrmRouteScope,\n} from './org-caller'\nimport { crmSuiteRefusal } from './suite-gate'\n\n/**\n * The two things a task does that a browser must not do alone (AGL-2599).\n *\n * Every other task write is client-direct against the Firestore rules —\n * reopening, deleting, the list's own reads. These two are routes because\n * each has a side effect that lives outside the document:\n *\n * - SAVING a task assigned to somebody else NOTIFIES them, and a\n * notification is an Admin-SDK write into another person's inbox. Rather\n * than a client-direct write followed by a \"please notify\" call — two\n * operations that can disagree about whether the task exists — the route\n * persists the task itself and notifies from the same code path, so a\n * notification can never announce a task that failed to save. It also\n * stamps the scope, the provenance and the timestamps, which is one\n * creator computing `visibleTo` rather than two.\n *\n * - COMPLETING a task EMITS the `taskCompleted` host event, which is what a\n * workflow triggers on. A browser cannot run the workflow runner.\n *\n * Both authenticate the way the other console plugin routes do — the ID\n * token in the `Authorization` header — and then ask the same two questions\n * the rules ask of a `crmTasks` write: is this member allowed to write org\n * data (`owner`/`admin`/`editor`, and `data.manage` resolved through their\n * custom role), and can they reach THIS document's scope.\n *\n * ## The organization variant (AGL-2637)\n *\n * `{ orgId, … }` instead of a site: the org-level hub. The caller is\n * authorized by the ORG — an org-wide member holding `data.manage`, the\n * hub's own gate, never a site collaborator — and reaches every task the\n * org holds, so no scope check is made against the document. A NEW task\n * names the site it is filed from beside the org, or names none and is the\n * organization's own: `hostId: null`, the org scope token alone. Completing\n * emits on the task's OWN site, where its automations live; an\n * organization task has none and emits nothing, as an uncaptured deal's\n * stage change emits nothing.\n *\n * The org variant also takes a BATCH — `taskIds` to complete, `tasks` to\n * save — so the org hub's bulk bar makes one request per action rather\n * than one per task. Each task is answered on its own in `results`; the\n * request as a whole is refused only for what refuses every task alike.\n */\n\nexport type Refusal = {\n ok: false\n status: number\n body: { error: string; reason?: string; code?: string }\n}\n\n/** What the suite gate names when a task route refuses a plan without it. */\nconst TASKS_ACT = \"Working a record's tasks\"\n\nexport interface Writer {\n ok: true\n uid: string\n staff: boolean\n orgId: string\n org: Record<string, unknown>\n /** The member document under a site; `null` at the org level, where the reach is the org's. */\n member: Partial<AglynOrgMember> | null\n level: CrmRouteScope['level']\n}\n\nexport const refuse = (status: number, error: string): Refusal => ({\n ok: false,\n status,\n body: { error },\n})\n\nconst ORG_REFUSAL =\n 'Editing tasks at the organization level requires the \"Manage data\" ' +\n 'permission across the whole workspace.'\n\nexport interface CrmWriterOptions {\n /**\n * The act a plan without the CRM is refused for, named the way\n * `crmSuiteRefusalMessage` takes it. `null` for a route that asks the plan\n * itself, once it knows what the request writes, so the refusal can name\n * that act — a contact update names the first field it carries. Tasks\n * when unsaid.\n */\n suiteAct?: string | null\n}\n\n/**\n * Who is asking, and whether they may write this CRM at all.\n *\n * Under a site: the org resolved from the site and the rules' own role and\n * permission questions. At the organization level: the org the body names,\n * for an org-wide member with the permission. The scope question — may they\n * reach THIS task — is asked by the caller against the document, because on\n * a create the document does not exist yet and its scope is what the route\n * is about to stamp.\n */\nexport async function authorizeCrmWriter(\n req: PluginApiRequest,\n scope: CrmRouteScope,\n options: CrmWriterOptions = {},\n): Promise<Writer | Refusal> {\n const suiteAct = options.suiteAct === undefined ? TASKS_ACT : options.suiteAct\n if (scope.level === 'org') {\n const caller = await authorizeOrgCaller(req, scope.orgId, {\n needs: 'data.manage',\n refusal: ORG_REFUSAL,\n })\n if (caller.ok === false) return refuse(caller.status, caller.error)\n // The plan after the person (AGL-2787): see `suite-gate.ts`.\n const suite = suiteAct ? crmSuiteRefusal(caller.org, suiteAct) : null\n if (suite) return { ok: false, status: suite.status, body: suite.body }\n return {\n ok: true,\n uid: caller.uid,\n staff: caller.staff,\n orgId: caller.orgId,\n org: caller.org as Record<string, unknown>,\n member: null,\n level: 'org',\n }\n }\n\n const authorization = String(req.headers.authorization ?? '')\n const idToken = authorization.startsWith('Bearer ')\n ? authorization.slice('Bearer '.length)\n : undefined\n if (!idToken) return refuse(401, 'Unauthenticated')\n\n const decoded = await firebaseAdmin.app().auth().verifyIdToken(idToken)\n const staff = decoded['staff'] === true\n const resolved = await getOrgForHost(scope.hostId).catch(() => null)\n if (!resolved) {\n return refuse(404, 'This site has no organization, so it has no CRM.')\n }\n const { orgId, org } = resolved\n const membership = await resolveOrgMembership(decoded.uid, orgId).catch(\n () => null,\n )\n const member = (membership?.member ?? null) as Partial<AglynOrgMember> | null\n if (!staff) {\n const role = String(member?.role ?? '')\n /*\n * The rules' `canWriteOrgData()` restated: the role list is what an\n * unstamped permission map falls through to, and the permission is the\n * only half a custom role's revocation can reach. A route that checked\n * one and not the other would open a door the rules keep shut.\n */\n const writerRole = role === 'owner' || role === 'admin' || role === 'editor'\n const suspended =\n (member as { orgSuspended?: boolean } | null)?.orgSuspended === true\n if (!member || !writerRole || suspended) {\n return refuse(403, 'Your organization role does not allow editing the CRM.')\n }\n if (!(await memberHasOrgPermission(orgId, member, 'data.manage'))) {\n return refuse(\n 403,\n 'Your organization role does not allow editing the CRM.',\n )\n }\n }\n const suite = suiteAct ? crmSuiteRefusal(org, suiteAct) : null\n if (suite) return { ok: false, status: suite.status, body: suite.body }\n return {\n ok: true,\n uid: decoded.uid,\n staff,\n orgId,\n org: (org ?? {}) as Record<string, unknown>,\n member,\n level: 'site',\n }\n}\n\n/**\n * The rules' `canReadScoped()`, for a document the route has in hand. An\n * org-level writer was admitted as org-wide, and an org-wide member reads\n * every row.\n */\nexport const canReach = (writer: Writer, visibleTo: unknown): boolean =>\n writer.staff ||\n writer.level === 'org' ||\n isOrgWideMember(writer.member) ||\n memberCanSee(writer.member, visibleTo as string[] | undefined)\n\n/**\n * The records the task names carry `nextTaskAtMs` (AGL-2661), recomputed\n * after every write here. Its own catch: the task IS saved by now, and a\n * denormalized figure that could not move is logged and left for the\n * Fields section's recompute, not reported as a task that failed to save.\n */\nasync function settleNextActivity(\n orgId: string,\n links: readonly (Partial<CrmTaskFields> | Record<string, unknown> | null | undefined)[],\n): Promise<void> {\n try {\n await recomputeCrmNextTaskAt(\n firebaseAdmin.app().firestore(),\n orgId,\n links.map((link) => crmNextActivityLinksOf(link as Record<string, unknown>)),\n )\n } catch (error) {\n console.error('[crm] next activity could not be recomputed', orgId, error)\n }\n}\n\n/**\n * The console path the assignee's notification opens: the record the task\n * is for, in the hub, or the tasks list when it is for nobody in particular.\n *\n * In the `/{hostDocId}/rest` shape every host notification uses — the\n * console rewrites it to `/{orgSlug}/hosts/{subdomain}/rest` when the link\n * is followed, which is why `hostId` and `orgId` travel on the document. An\n * organization task has no site to open under, so its link is the `/org`\n * shape the console rewrites onto the organization's own hub.\n */\nfunction assignmentLink(hostId: string | null, fields: CrmTaskFields): string {\n const base = hostId ? `/${hostId}/crm` : '/org/crm'\n if (fields.contactId) return `${base}/contacts/${encodeURIComponent(fields.contactId)}`\n if (fields.dealId) return `${base}/deals/${encodeURIComponent(fields.dealId)}`\n if (fields.companyId) return `${base}/companies/${encodeURIComponent(fields.companyId)}`\n return `${base}/tasks`\n}\n\n/**\n * The editable fields as a Firestore write.\n *\n * The optional ids and the assignee are ABSENT on the document when unset,\n * never `null` — the record cards query `where('contactId', '==', id)` and\n * the \"My tasks\" view `where('assigneeUid', '==', uid)`, and neither is\n * helped by a null. So a create leaves an unset optional out, and an update\n * DELETES it: an assignee cleared in the drawer has to come off the\n * document, and an update that merely omitted the key would keep them.\n * `dueAtMs` is the one field written as `null` when unset, because every\n * view orders by it and a document missing the field drops out of an\n * `orderBy` entirely.\n */\nfunction storedFields(\n fields: CrmTaskFields,\n mode: 'create' | 'update',\n): Record<string, unknown> {\n const absent = mode === 'update' ? FieldValue.delete() : undefined\n const optional = (value: string | null) =>\n value ? { present: true, value } : { present: mode === 'update', value: absent }\n const out: Record<string, unknown> = {\n title: fields.title,\n kind: fields.kind,\n priority: fields.priority,\n dueAtMs: fields.dueAtMs,\n notes: fields.notes,\n }\n for (const [key, value] of [\n ['assigneeUid', fields.assigneeUid],\n ['contactId', fields.contactId],\n ['companyId', fields.companyId],\n ['dealId', fields.dealId],\n ] as const) {\n const slot = optional(value)\n if (slot.present) out[key] = slot.value\n }\n return out\n}\n\n/**\n * The reminder a save leaves (AGL-2659), as a Firestore write.\n *\n * `crmTaskReminderAfterEdit` decides which reminder the task ends up with;\n * this turns the decision into fields. Written as `null` when unset, like\n * `dueAtMs`, so the document says the reminder was decided. A reminder that\n * MOVED — to a new time, or to none — is a reminder not yet sent, so the\n * runner's mark comes off with it; one that stayed keeps its mark, which is\n * what stops a title correction from re-sending last week's reminder.\n */\nfunction reminderFields(\n fields: CrmTaskFields,\n existing: FirebaseFirestore.DocumentSnapshot | null,\n): Record<string, unknown> {\n const previous = existing\n ? {\n dueAtMs: (existing.get('dueAtMs') as number | null | undefined) ?? null,\n remindAtMs: (existing.get('remindAtMs') as number | null | undefined) ?? null,\n }\n : null\n const remindAtMs = crmTaskReminderAfterEdit({\n dueAtMs: fields.dueAtMs,\n remindAtMs: fields.remindAtMs,\n previous,\n })\n const out: Record<string, unknown> = { remindAtMs }\n if (previous && remindAtMs !== previous.remindAtMs) {\n out['reminderSentAtMs'] = FieldValue.delete()\n }\n return out\n}\n\nconst tasksCollection = (orgId: string) =>\n firebaseAdmin\n .app()\n .firestore()\n .collection('orgs')\n .doc(orgId)\n .collection(CRM_COLLECTIONS.tasks)\n\ntype TasksCollection = ReturnType<typeof tasksCollection>\n\n/**\n * Whether a uid names a member of the org, answered once per uid across a\n * batch: a bar reassigning forty tasks to one person asks the roster once.\n */\nfunction rosterOf(orgId: string) {\n const known = new Map<string, Promise<boolean>>()\n return (uid: string): Promise<boolean> => {\n let answer = known.get(uid)\n if (!answer) {\n answer = resolveOrgMembership(uid, orgId)\n .then((found) => Boolean(found?.member))\n .catch(() => false)\n known.set(uid, answer)\n }\n return answer\n }\n}\n\n/** Tell the assignee, when they are somebody new and somebody else. */\nasync function notifyAssignee(\n writer: Writer,\n fields: CrmTaskFields,\n previousAssignee: string | null,\n hostId: string | null,\n): Promise<boolean> {\n const assignee = fields.assigneeUid\n const notified = Boolean(\n assignee && assignee !== writer.uid && assignee !== previousAssignee,\n )\n if (!notified || !assignee) return false\n const due =\n typeof fields.dueAtMs === 'number'\n ? ` · due ${new Date(fields.dueAtMs).toLocaleString()}`\n : ''\n await notifyUsers([assignee], {\n type: 'content.taskAssigned',\n title: 'Task assigned to you',\n body: `${fields.title}${due}`,\n link: assignmentLink(hostId, fields),\n orgId: writer.orgId,\n ...(hostId ? { hostId } : {}),\n })\n return true\n}\n\n/**\n * Rewrite one existing task's editable fields, and tell a new assignee.\n *\n * `visibleTo` is not touched: the rules let only an org-wide member move a\n * record's scope, and this route is not the place that does it. `hostId`\n * and `createdByUid` are provenance and never rewritten. The notification\n * opens under the site the caller is on, or — at the organization level —\n * under the task's own site, and under the org hub for a task with none.\n */\nasync function updateTask(\n writer: Writer,\n scope: CrmRouteScope,\n tasks: TasksCollection,\n taskId: string,\n fields: CrmTaskFields,\n onRoster: (uid: string) => Promise<boolean>,\n): Promise<{ ok: true; notified: boolean } | Refusal> {\n if (fields.assigneeUid && !(await onRoster(fields.assigneeUid))) {\n return refuse(400, 'The assignee is not a member of this organization.')\n }\n const existing = await tasks.doc(taskId).get()\n if (!existing.exists) return refuse(404, 'That task no longer exists.')\n if (!canReach(writer, existing.get('visibleTo'))) {\n return refuse(403, 'That task is not visible to you.')\n }\n const previousAssignee = String(existing.get('assigneeUid') ?? '') || null\n const previousLinks = crmNextActivityLinksOf(existing.data() as Record<string, unknown>)\n await tasks.doc(taskId).update({\n ...storedFields(fields, 'update'),\n ...reminderFields(fields, existing),\n updatedAt: FieldValue.serverTimestamp(),\n })\n // Both sides: a task moved off one deal onto another leaves neither stale.\n await settleNextActivity(writer.orgId, [previousLinks, fields])\n const linkHostId =\n scope.level === 'site'\n ? scope.hostId\n : String(existing.get('hostId') ?? '').trim() || null\n const notified = await notifyAssignee(writer, fields, previousAssignee, linkHostId)\n return { ok: true, notified }\n}\n\n/**\n * Where a NEW task is filed from: the mounted site, or at the organization\n * level the site the body names — which has to be one of THIS org's, or an\n * org-wide member of one org could stamp a task with another org's site\n * token — or no site at all, the organization's own.\n */\nasync function resolveFiledFrom(\n writer: Writer,\n scope: CrmRouteScope,\n): Promise<{ ok: true; hostId: string | null } | Refusal> {\n if (scope.level === 'site') return { ok: true, hostId: scope.hostId }\n if (!scope.hostId) return { ok: true, hostId: null }\n const owner = await getOrgForHost(scope.hostId).catch(() => null)\n if (!owner || owner.orgId !== writer.orgId) {\n return refuse(400, 'That site is not one of this organization’s.')\n }\n return { ok: true, hostId: scope.hostId }\n}\n\n/**\n * Create one task, stamped with its scope and provenance.\n *\n * The scope every CRM creator stamps for a task filed from a site: the\n * whole org when the org has chosen that, and otherwise the sites this\n * site presents as one sender with — which, undeclared, is this site\n * alone. A scoped member creating a record they could not then see is\n * refused, which is the rules' `canCreateScoped()` said before the write\n * instead of after. An organization task — no site — carries\n * `CRM_ORG_TASK_SCOPE` and `hostId: null`.\n */\nasync function createTask(\n writer: Writer,\n scope: CrmRouteScope,\n tasks: TasksCollection,\n fields: CrmTaskFields,\n onRoster: (uid: string) => Promise<boolean>,\n): Promise<{ ok: true; taskId: string; notified: boolean } | Refusal> {\n if (fields.assigneeUid && !(await onRoster(fields.assigneeUid))) {\n return refuse(400, 'The assignee is not a member of this organization.')\n }\n const filed = await resolveFiledFrom(writer, scope)\n if (filed.ok === false) return filed\n const { hostId } = filed\n const visibleTo = hostId\n ? crmScopeTokens(writer.org, consentGroupForHost(writer.org, hostId))\n : [...CRM_ORG_TASK_SCOPE]\n if (!canReach(writer, visibleTo)) {\n return refuse(403, 'Your access to this organization does not reach this site.')\n }\n const ref = tasks.doc()\n await ref.set({\n ...storedFields(fields, 'create'),\n ...reminderFields(fields, null),\n status: 'open',\n completedAtMs: null,\n visibleTo,\n hostId,\n createdByUid: writer.uid,\n createdAt: FieldValue.serverTimestamp(),\n updatedAt: FieldValue.serverTimestamp(),\n })\n await settleNextActivity(writer.orgId, [fields])\n const notified = await notifyAssignee(writer, fields, null, hostId)\n return { ok: true, taskId: ref.id, notified }\n}\n\n/**\n * `POST crm/task-save` — create or update a task, and tell its assignee.\n *\n * Body: `{ hostId, taskId?, task: CrmTaskFields }` under a site;\n * `{ orgId, hostId?, taskId?, task }` at the organization level; or the\n * org-level batch `{ orgId, tasks: [{ taskId, task }] }`. Answers\n * `{ ok, taskId, notified }`, or `{ ok, results }` for the batch.\n *\n * The NOTIFICATION fires when the saved assignee is somebody other than the\n * person saving AND is not who the task was already assigned to. Assigning\n * a task to yourself is a note to self; re-saving a task's title does not\n * re-announce it to the person who already has it. The assignee must be a\n * member of the org — a uid nobody can find in the roster is refused rather\n * than written, because a notification to a stranger's inbox is the one\n * thing this route must never do.\n */\nexport const crmTaskSaveHandler: PluginApiHandler = async (req, res) => {\n if (req.method !== 'POST') {\n res.setHeader('Allow', 'POST')\n res.status(405).json({ error: 'Method not allowed' })\n return\n }\n const scope = readCrmRouteScope(req.body as Record<string, unknown>)\n if (!scope) {\n res.status(400).json({ error: 'Missing hostId' })\n return\n }\n if (Array.isArray(req.body?.tasks)) {\n await saveBatch(req, res, scope)\n return\n }\n const taskId = String(req.body?.taskId ?? '').trim()\n const read = readCrmTaskFields(req.body?.task)\n if (read.ok === false) {\n res.status(400).json({ error: read.error })\n return\n }\n const fields = read.fields\n\n try {\n const writer = await authorizeCrmWriter(req, scope)\n if (writer.ok === false) {\n res.status(writer.status).json(writer.body)\n return\n }\n const tasks = tasksCollection(writer.orgId)\n const onRoster = rosterOf(writer.orgId)\n let body: CrmTaskSaveResponse\n if (taskId) {\n const saved = await updateTask(writer, scope, tasks, taskId, fields, onRoster)\n if (saved.ok === false) {\n res.status(saved.status).json(saved.body)\n return\n }\n body = { ok: true, taskId, notified: saved.notified }\n } else {\n const saved = await createTask(writer, scope, tasks, fields, onRoster)\n if (saved.ok === false) {\n res.status(saved.status).json(saved.body)\n return\n }\n body = { ok: true, taskId: saved.taskId, notified: saved.notified }\n }\n res.status(200).json(body)\n } catch (error) {\n console.error('[crm] task-save failed', error)\n res.status(500).json({ error: 'The task could not be saved.' })\n }\n}\n\n/**\n * The batch: every entry read before any is written, so a body with one\n * unreadable entry is refused whole rather than half-applied; then each\n * task in order, each answered on its own.\n */\nasync function saveBatch(\n req: PluginApiRequest,\n res: PluginApiResponse,\n scope: CrmRouteScope,\n): Promise<void> {\n if (scope.level !== 'org') {\n res.status(400).json({\n error: 'A batch of tasks is saved at the organization level only.',\n })\n return\n }\n const entries = (req.body?.tasks as unknown[]).slice(0, CRM_TASK_BATCH_MAX + 1)\n if (!entries.length || entries.length > CRM_TASK_BATCH_MAX) {\n res.status(400).json({\n error: `Save between 1 and ${CRM_TASK_BATCH_MAX} tasks at a time.`,\n })\n return\n }\n const parsed: Array<{ taskId: string; fields: CrmTaskFields }> = []\n for (const entry of entries) {\n const raw = (entry ?? {}) as Record<string, unknown>\n const taskId = String(raw['taskId'] ?? '').trim()\n const read = readCrmTaskFields(raw['task'])\n if (!taskId || read.ok === false) {\n res.status(400).json({\n error: read.ok === false ? read.error : 'Every task in a batch names its taskId.',\n })\n return\n }\n parsed.push({ taskId, fields: read.fields })\n }\n\n try {\n const writer = await authorizeCrmWriter(req, scope)\n if (writer.ok === false) {\n res.status(writer.status).json(writer.body)\n return\n }\n const tasks = tasksCollection(writer.orgId)\n const onRoster = rosterOf(writer.orgId)\n const results: CrmTaskSaveOutcome[] = []\n for (const { taskId, fields } of parsed) {\n const saved = await updateTask(writer, scope, tasks, taskId, fields, onRoster)\n results.push(\n saved.ok === false\n ? { taskId, ok: false, error: saved.body.error }\n : { taskId, ok: true, notified: saved.notified },\n )\n }\n const body: CrmTasksSaveResponse = { ok: true, results }\n res.status(200).json(body)\n } catch (error) {\n console.error('[crm] task-save batch failed', error)\n res.status(500).json({ error: 'The tasks could not be saved.' })\n }\n}\n\n/**\n * Mark one task done and fire `taskCompleted` on the site whose automations\n * hear it: under a site, the site whose console ticked the box — workflows\n * belong to a site, and the person is on that site's console. At the\n * organization level there is no such console, so the event goes to the\n * task's OWN site, and an organization task, having none, fires nothing.\n * The task's own `hostId` rides in the payload as `taskHostId` either way,\n * for a workflow that cares about the difference.\n *\n * Idempotent on purpose: two people ticking the same box, or one person\n * double-clicking, completes a task once and fires its event once. The\n * second call reads the stored `completedAtMs` back and writes nothing.\n */\nasync function completeTask(\n writer: Writer,\n scope: CrmRouteScope,\n tasks: TasksCollection,\n taskId: string,\n): Promise<CrmTaskCompleteOutcome> {\n const ref = tasks.doc(taskId)\n const snapshot = await ref.get()\n if (!snapshot.exists) {\n return { taskId, ok: false, error: 'That task no longer exists.' }\n }\n const task = snapshot.data() as Partial<CrmTask>\n if (!canReach(writer, task.visibleTo)) {\n return { taskId, ok: false, error: 'That task is not visible to you.' }\n }\n if (task.status === 'done') {\n return {\n taskId,\n ok: true,\n completedAtMs: Number(task.completedAtMs ?? 0),\n alreadyDone: true,\n }\n }\n\n const completedAtMs = Date.now()\n await ref.update({\n status: 'done',\n completedAtMs,\n completedByUid: writer.uid,\n // A reminder still owed on a task that is done is owed to nobody\n // (AGL-2659); one already sent stays, as a fact about what happened.\n ...(crmTaskReminderPending(task) ? { remindAtMs: null } : {}),\n updatedAt: FieldValue.serverTimestamp(),\n })\n await settleNextActivity(writer.orgId, [task as Record<string, unknown>])\n\n const eventHostId =\n scope.level === 'site' ? scope.hostId : String(task.hostId ?? '').trim()\n if (eventHostId) {\n /*\n * The payload is what a workflow filter can read: every field a string,\n * number or boolean, and every optional one present as an empty string\n * rather than absent, so `contactId != \"\"` is a filter somebody can\n * write without knowing whether the key exists.\n */\n await emitHostEvent(eventHostId, 'taskCompleted', {\n taskId,\n title: String(task.title ?? ''),\n kind: String(task.kind ?? ''),\n priority: String(task.priority ?? ''),\n dueAtMs: typeof task.dueAtMs === 'number' ? task.dueAtMs : 0,\n completedAtMs,\n completedByUid: writer.uid,\n assigneeUid: String(task.assigneeUid ?? ''),\n createdByUid: String(task.createdByUid ?? ''),\n contactId: String(task.contactId ?? ''),\n companyId: String(task.companyId ?? ''),\n dealId: String(task.dealId ?? ''),\n taskHostId: String(task.hostId ?? ''),\n })\n }\n return { taskId, ok: true, completedAtMs }\n}\n\n/** A per-task outcome as the single-task route has always answered. */\nconst completeStatus = (outcome: Extract<CrmTaskCompleteOutcome, { ok: false }>) =>\n outcome.error === 'That task no longer exists.' ? 404 : 403\n\n/**\n * `POST crm/task-complete` — mark a task done and fire `taskCompleted`.\n *\n * Body: `{ hostId, taskId }` under a site, `{ orgId, taskId }` at the\n * organization level, or the org-level batch `{ orgId, taskIds }`. Answers\n * `{ ok, completedAtMs, alreadyDone? }`, or `{ ok, results }` for the batch.\n */\nexport const crmTaskCompleteHandler: PluginApiHandler = async (req, res) => {\n if (req.method !== 'POST') {\n res.setHeader('Allow', 'POST')\n res.status(405).json({ error: 'Method not allowed' })\n return\n }\n const scope = readCrmRouteScope(req.body as Record<string, unknown>)\n if (Array.isArray(req.body?.taskIds)) {\n await completeBatch(req, res, scope)\n return\n }\n const taskId = String(req.body?.taskId ?? '').trim()\n if (!scope || !taskId) {\n res.status(400).json({ error: 'Missing hostId or taskId' })\n return\n }\n\n try {\n const writer = await authorizeCrmWriter(req, scope)\n if (writer.ok === false) {\n res.status(writer.status).json(writer.body)\n return\n }\n const outcome = await completeTask(writer, scope, tasksCollection(writer.orgId), taskId)\n if (outcome.ok === false) {\n res.status(completeStatus(outcome)).json({ error: outcome.error })\n return\n }\n const body: CrmTaskCompleteResponse = {\n ok: true,\n completedAtMs: outcome.completedAtMs,\n ...(outcome.alreadyDone ? { alreadyDone: true } : {}),\n }\n res.status(200).json(body)\n } catch (error) {\n console.error('[crm] task-complete failed', error)\n res.status(500).json({ error: 'The task could not be completed.' })\n }\n}\n\n/**\n * The batch: the ids deduplicated and capped, then each task in order —\n * in order rather than at once, because each completion may run a site's\n * workflows, and two hundred runners started together is the burst the\n * per-task client call was written to avoid.\n */\nasync function completeBatch(\n req: PluginApiRequest,\n res: PluginApiResponse,\n scope: CrmRouteScope | null,\n): Promise<void> {\n if (!scope || scope.level !== 'org') {\n res.status(400).json({\n error: 'A batch of tasks is completed at the organization level only.',\n })\n return\n }\n const taskIds = [\n ...new Set(\n (req.body?.taskIds as unknown[]).map((id) => String(id ?? '').trim()).filter(Boolean),\n ),\n ]\n if (!taskIds.length || taskIds.length > CRM_TASK_BATCH_MAX) {\n res.status(400).json({\n error: `Complete between 1 and ${CRM_TASK_BATCH_MAX} tasks at a time.`,\n })\n return\n }\n\n try {\n const writer = await authorizeCrmWriter(req, scope)\n if (writer.ok === false) {\n res.status(writer.status).json(writer.body)\n return\n }\n const tasks = tasksCollection(writer.orgId)\n const results: CrmTaskCompleteOutcome[] = []\n for (const taskId of taskIds) {\n results.push(await completeTask(writer, scope, tasks, taskId))\n }\n const body: CrmTasksCompleteResponse = { ok: true, results }\n res.status(200).json(body)\n } catch (error) {\n console.error('[crm] task-complete batch failed', error)\n res.status(500).json({ error: 'The tasks could not be completed.' })\n }\n}\n"],"names":["consentGroupForHost","CRM_COLLECTIONS","crmScopeTokens","crmTaskReminderAfterEdit","crmTaskReminderPending","isOrgWideMember","memberCanSee","crmNextActivityLinksOf","firebaseAdmin","getOrgForHost","memberHasOrgPermission","notifyUsers","recomputeCrmNextTaskAt","resolveOrgMembership","emitHostEvent","FieldValue","CRM_TASK_BATCH_MAX","readCrmTaskFields","CRM_ORG_TASK_SCOPE","authorizeOrgCaller","readCrmRouteScope","crmSuiteRefusal","TASKS_ACT","refuse","status","error","ok","body","ORG_REFUSAL","authorizeCrmWriter","req","scope","options","suiteAct","undefined","level","caller","orgId","needs","refusal","suite","org","uid","staff","member","authorization","String","headers","idToken","startsWith","slice","length","decoded","app","auth","verifyIdToken","resolved","hostId","catch","membership","role","writerRole","suspended","orgSuspended","canReach","writer","visibleTo","settleNextActivity","links","firestore","map","link","console","assignmentLink","fields","base","contactId","encodeURIComponent","dealId","companyId","storedFields","mode","absent","delete","optional","value","present","out","title","kind","priority","dueAtMs","notes","key","assigneeUid","slot","reminderFields","existing","previous","get","remindAtMs","tasksCollection","collection","doc","tasks","rosterOf","known","Map","answer","then","found","Boolean","set","notifyAssignee","previousAssignee","assignee","notified","due","Date","toLocaleString","type","updateTask","taskId","onRoster","exists","previousLinks","data","update","updatedAt","serverTimestamp","linkHostId","trim","resolveFiledFrom","owner","createTask","filed","ref","completedAtMs","createdByUid","createdAt","id","crmTaskSaveHandler","res","method","setHeader","json","Array","isArray","saveBatch","read","task","saved","entries","parsed","entry","raw","push","results","completeTask","snapshot","Number","alreadyDone","now","completedByUid","eventHostId","taskHostId","completeStatus","outcome","crmTaskCompleteHandler","taskIds","completeBatch","Set","filter"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAEEA,mBAAmB,EACnBC,eAAe,EAEfC,cAAc,EACdC,wBAAwB,EACxBC,sBAAsB,EACtBC,eAAe,EACfC,YAAY,QAIP,sBAAqB;AAC5B,SACEC,sBAAsB,EACtBC,aAAa,EACbC,aAAa,EACbC,sBAAsB,EACtBC,WAAW,EACXC,sBAAsB,EACtBC,oBAAoB,QACf,2BAA0B;AACjC,SAASC,aAAa,QAAQ,wBAAuB;AACrD,SAASC,UAAU,QAAQ,2BAA0B;AACrD,SACEC,kBAAkB,EAQlBC,iBAAiB,QACZ,0BAAsB;AAC7B,SAASC,kBAAkB,QAAQ,yBAAqB;AACxD,SACEC,kBAAkB,EAElBC,iBAAiB,QACZ,kBAAc;AACrB,SAAS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C,OAAOvC,EAAE,KAAK,OAAO;YACvBoH,IAAItH,MAAM,CAACyC,OAAOzC,MAAM,EAAEyH,IAAI,CAAChF,OAAOtC,IAAI;YAC1C;QACF;QACA,MAAM6E,QAAQH,gBAAgBpC,OAAO5B,KAAK;QAC1C,MAAMwH,UAAoC,EAAE;QAC5C,KAAK,MAAMnC,UAAU+C,QAAS;YAC5BZ,QAAQD,IAAI,CAAC,MAAME,aAAa7F,QAAQlC,OAAOyE,OAAOkB;QACxD;QACA,MAAM/F,OAAiC;YAAED,IAAI;YAAMmI;QAAQ;QAC3Df,IAAItH,MAAM,CAAC,KAAKyH,IAAI,CAACtH;IACvB,EAAE,OAAOF,OAAO;QACd+C,QAAQ/C,KAAK,CAAC,oCAAoCA;QAClDqH,IAAItH,MAAM,CAAC,KAAKyH,IAAI,CAAC;YAAExH,OAAO;QAAoC;IACpE;AACF"}
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
/**
|
|
18
|
+
* `POST /api/crm/tasks-import` — one chunk of a tasks file, written
|
|
19
|
+
* (AGL-2662).
|
|
20
|
+
*
|
|
21
|
+
* The browser has already read the file and applied the operator's column
|
|
22
|
+
* mapping; what arrives here is up to {@link TASK_IMPORT_CHUNK_SIZE} raw
|
|
23
|
+
* rows in the vocabulary `crm-task-import.ts` defines. This route judges
|
|
24
|
+
* each one through the same normalizer, resolves the assignee against the
|
|
25
|
+
* org's roster, and writes the document in the shape the task-save route
|
|
26
|
+
* writes — the optional ids absent rather than null, `dueAtMs` null when
|
|
27
|
+
* unset so the ordered views keep the row.
|
|
28
|
+
*
|
|
29
|
+
* ## A stranger refuses the row
|
|
30
|
+
*
|
|
31
|
+
* The task-save route refuses an assignee who is not a member, because a
|
|
32
|
+
* notification to a stranger's inbox is the one thing it must never do.
|
|
33
|
+
* The import refuses the same way, per row, as `unknown-assignee`: the
|
|
34
|
+
* roster is read once for the request, and an address it does not hold
|
|
35
|
+
* sends the row back to the operator's skipped file. No notification is
|
|
36
|
+
* sent for an imported task, so nothing here reaches an inbox at all.
|
|
37
|
+
*
|
|
38
|
+
* ## Every task is the site's
|
|
39
|
+
*
|
|
40
|
+
* The shared drawer names a site even at the organization level, so an
|
|
41
|
+
* imported task carries that site's scope the way a task typed under it
|
|
42
|
+
* does. The organization's own tasks — no site — are filed one at a time
|
|
43
|
+
* from the organization hub, not from a file.
|
|
44
|
+
*
|
|
45
|
+
* Tasks are not CRM records for the band: no quota is asked.
|
|
46
|
+
*/
|
|
47
|
+
import { type PluginApiHandler } from '@aglyn/aglyn/server';
|
|
48
|
+
/**
|
|
49
|
+
* `POST crm/tasks-import` — `{ hostId, rows }` → a {@link TaskImportChunkResult}.
|
|
50
|
+
*
|
|
51
|
+
* The writes are batched: a task has no key to collide on and no count to
|
|
52
|
+
* keep honest between rows, so a chunk is one commit.
|
|
53
|
+
*/
|
|
54
|
+
export declare const crmTasksImportHandler: PluginApiHandler;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2026 Aglyn LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/ /**
|
|
18
|
+
* `POST /api/crm/tasks-import` — one chunk of a tasks file, written
|
|
19
|
+
* (AGL-2662).
|
|
20
|
+
*
|
|
21
|
+
* The browser has already read the file and applied the operator's column
|
|
22
|
+
* mapping; what arrives here is up to {@link TASK_IMPORT_CHUNK_SIZE} raw
|
|
23
|
+
* rows in the vocabulary `crm-task-import.ts` defines. This route judges
|
|
24
|
+
* each one through the same normalizer, resolves the assignee against the
|
|
25
|
+
* org's roster, and writes the document in the shape the task-save route
|
|
26
|
+
* writes — the optional ids absent rather than null, `dueAtMs` null when
|
|
27
|
+
* unset so the ordered views keep the row.
|
|
28
|
+
*
|
|
29
|
+
* ## A stranger refuses the row
|
|
30
|
+
*
|
|
31
|
+
* The task-save route refuses an assignee who is not a member, because a
|
|
32
|
+
* notification to a stranger's inbox is the one thing it must never do.
|
|
33
|
+
* The import refuses the same way, per row, as `unknown-assignee`: the
|
|
34
|
+
* roster is read once for the request, and an address it does not hold
|
|
35
|
+
* sends the row back to the operator's skipped file. No notification is
|
|
36
|
+
* sent for an imported task, so nothing here reaches an inbox at all.
|
|
37
|
+
*
|
|
38
|
+
* ## Every task is the site's
|
|
39
|
+
*
|
|
40
|
+
* The shared drawer names a site even at the organization level, so an
|
|
41
|
+
* imported task carries that site's scope the way a task typed under it
|
|
42
|
+
* does. The organization's own tasks — no site — are filed one at a time
|
|
43
|
+
* from the organization hub, not from a file.
|
|
44
|
+
*
|
|
45
|
+
* Tasks are not CRM records for the band: no quota is asked.
|
|
46
|
+
*/ import { CRM_COLLECTIONS } from "@aglyn/aglyn/server";
|
|
47
|
+
import { TASK_IMPORT_CHUNK_SIZE, TASK_IMPORT_MAX_BODY_BYTES, normalizeTaskImportRow } from "../model/crm-task-import.js";
|
|
48
|
+
import { firebaseAdmin } from "@aglyn/tenant-data-admin";
|
|
49
|
+
import { FieldValue } from "firebase-admin/firestore";
|
|
50
|
+
import { ownerDirectory, readImportRows, resolveImportContext } from "./import-context.js";
|
|
51
|
+
/**
|
|
52
|
+
* `POST crm/tasks-import` — `{ hostId, rows }` → a {@link TaskImportChunkResult}.
|
|
53
|
+
*
|
|
54
|
+
* The writes are batched: a task has no key to collide on and no count to
|
|
55
|
+
* keep honest between rows, so a chunk is one commit.
|
|
56
|
+
*/ export const crmTasksImportHandler = async (req, res)=>{
|
|
57
|
+
if (req.method !== 'POST') {
|
|
58
|
+
res.setHeader('Allow', 'POST');
|
|
59
|
+
return res.status(405).json({
|
|
60
|
+
error: 'Method not allowed'
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
const read = readImportRows(req, {
|
|
64
|
+
maxBodyBytes: TASK_IMPORT_MAX_BODY_BYTES,
|
|
65
|
+
chunkSize: TASK_IMPORT_CHUNK_SIZE
|
|
66
|
+
});
|
|
67
|
+
if ('error' in read) return res.status(read.status).json({
|
|
68
|
+
error: read.error
|
|
69
|
+
});
|
|
70
|
+
try {
|
|
71
|
+
const context = await resolveImportContext(req);
|
|
72
|
+
if (context.ok === false) return res.status(context.status).json(context.body);
|
|
73
|
+
const skipped = [];
|
|
74
|
+
const dropped = {};
|
|
75
|
+
const normalized = [];
|
|
76
|
+
read.rows.forEach((raw, index)=>{
|
|
77
|
+
const verdict = normalizeTaskImportRow(raw);
|
|
78
|
+
if (verdict.ok === false) {
|
|
79
|
+
skipped.push({
|
|
80
|
+
index,
|
|
81
|
+
title: verdict.input,
|
|
82
|
+
reason: verdict.reason
|
|
83
|
+
});
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
for (const entry of verdict.row.dropped){
|
|
87
|
+
var _dropped_entry_field;
|
|
88
|
+
dropped[entry.field] = ((_dropped_entry_field = dropped[entry.field]) != null ? _dropped_entry_field : 0) + 1;
|
|
89
|
+
}
|
|
90
|
+
normalized.push({
|
|
91
|
+
index,
|
|
92
|
+
row: verdict.row
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
// The roster reader keys on `ownerEmail`; a task's word for it is assignee.
|
|
96
|
+
const members = await ownerDirectory(context.orgId, normalized.map((entry)=>({
|
|
97
|
+
ownerEmail: entry.row.assigneeEmail
|
|
98
|
+
})));
|
|
99
|
+
const firestore = firebaseAdmin.app().firestore();
|
|
100
|
+
const tasks = firestore.collection('orgs').doc(context.orgId).collection(CRM_COLLECTIONS.tasks);
|
|
101
|
+
const batch = firestore.batch();
|
|
102
|
+
const nowMs = Date.now();
|
|
103
|
+
let created = 0;
|
|
104
|
+
for (const { index, row } of normalized){
|
|
105
|
+
var _row_notes;
|
|
106
|
+
let assigneeUid;
|
|
107
|
+
if (row.assigneeEmail) {
|
|
108
|
+
assigneeUid = members.get(row.assigneeEmail);
|
|
109
|
+
if (!assigneeUid) {
|
|
110
|
+
skipped.push({
|
|
111
|
+
index,
|
|
112
|
+
title: row.title,
|
|
113
|
+
reason: 'unknown-assignee'
|
|
114
|
+
});
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
batch.set(tasks.doc(), _extends({
|
|
119
|
+
title: row.title,
|
|
120
|
+
kind: row.kind,
|
|
121
|
+
priority: row.priority,
|
|
122
|
+
status: row.status,
|
|
123
|
+
dueAtMs: row.dueAtMs,
|
|
124
|
+
notes: (_row_notes = row.notes) != null ? _row_notes : '',
|
|
125
|
+
completedAtMs: row.status === 'done' ? nowMs : null
|
|
126
|
+
}, row.status === 'done' ? {
|
|
127
|
+
completedByUid: context.uid
|
|
128
|
+
} : {}, assigneeUid ? {
|
|
129
|
+
assigneeUid
|
|
130
|
+
} : {}, {
|
|
131
|
+
visibleTo: context.scopeTokens,
|
|
132
|
+
hostId: context.hostId,
|
|
133
|
+
createdByUid: context.uid,
|
|
134
|
+
createdAt: FieldValue.serverTimestamp(),
|
|
135
|
+
updatedAt: FieldValue.serverTimestamp()
|
|
136
|
+
}));
|
|
137
|
+
created += 1;
|
|
138
|
+
}
|
|
139
|
+
if (created) await batch.commit();
|
|
140
|
+
const result = {
|
|
141
|
+
received: read.rows.length,
|
|
142
|
+
created,
|
|
143
|
+
merged: 0,
|
|
144
|
+
skipped: skipped.sort((a, b)=>a.index - b.index),
|
|
145
|
+
dropped,
|
|
146
|
+
ownersUnresolved: []
|
|
147
|
+
};
|
|
148
|
+
return res.status(200).json(result);
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.error('crm/tasks-import failed', error);
|
|
151
|
+
return res.status(500).json({
|
|
152
|
+
error: 'The import could not continue.'
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
//# sourceMappingURL=tasks-import.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/server/tasks-import.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\n/**\n * `POST /api/crm/tasks-import` — one chunk of a tasks file, written\n * (AGL-2662).\n *\n * The browser has already read the file and applied the operator's column\n * mapping; what arrives here is up to {@link TASK_IMPORT_CHUNK_SIZE} raw\n * rows in the vocabulary `crm-task-import.ts` defines. This route judges\n * each one through the same normalizer, resolves the assignee against the\n * org's roster, and writes the document in the shape the task-save route\n * writes — the optional ids absent rather than null, `dueAtMs` null when\n * unset so the ordered views keep the row.\n *\n * ## A stranger refuses the row\n *\n * The task-save route refuses an assignee who is not a member, because a\n * notification to a stranger's inbox is the one thing it must never do.\n * The import refuses the same way, per row, as `unknown-assignee`: the\n * roster is read once for the request, and an address it does not hold\n * sends the row back to the operator's skipped file. No notification is\n * sent for an imported task, so nothing here reaches an inbox at all.\n *\n * ## Every task is the site's\n *\n * The shared drawer names a site even at the organization level, so an\n * imported task carries that site's scope the way a task typed under it\n * does. The organization's own tasks — no site — are filed one at a time\n * from the organization hub, not from a file.\n *\n * Tasks are not CRM records for the band: no quota is asked.\n */\n\nimport { CRM_COLLECTIONS, type PluginApiHandler } from '@aglyn/aglyn/server'\nimport {\n TASK_IMPORT_CHUNK_SIZE,\n TASK_IMPORT_MAX_BODY_BYTES,\n type TaskImportChunkResult,\n type TaskImportRawRow,\n type TaskImportRow,\n type TaskImportSkippedRow,\n normalizeTaskImportRow,\n} from '../model/crm-task-import'\nimport { firebaseAdmin } from '@aglyn/tenant-data-admin'\nimport { FieldValue } from 'firebase-admin/firestore'\nimport { ownerDirectory, readImportRows, resolveImportContext } from './import-context'\n\n/**\n * `POST crm/tasks-import` — `{ hostId, rows }` → a {@link TaskImportChunkResult}.\n *\n * The writes are batched: a task has no key to collide on and no count to\n * keep honest between rows, so a chunk is one commit.\n */\nexport const crmTasksImportHandler: PluginApiHandler = async (req, res) => {\n if (req.method !== 'POST') {\n res.setHeader('Allow', 'POST')\n return res.status(405).json({ error: 'Method not allowed' })\n }\n const read = readImportRows<TaskImportRawRow>(req, {\n maxBodyBytes: TASK_IMPORT_MAX_BODY_BYTES,\n chunkSize: TASK_IMPORT_CHUNK_SIZE,\n })\n if ('error' in read) return res.status(read.status).json({ error: read.error })\n try {\n const context = await resolveImportContext(req)\n if (context.ok === false) return res.status(context.status).json(context.body)\n\n const skipped: TaskImportSkippedRow[] = []\n const dropped: Record<string, number> = {}\n const normalized: { index: number; row: TaskImportRow }[] = []\n read.rows.forEach((raw, index) => {\n const verdict = normalizeTaskImportRow(raw)\n if (verdict.ok === false) {\n skipped.push({ index, title: verdict.input, reason: verdict.reason })\n return\n }\n for (const entry of verdict.row.dropped) {\n dropped[entry.field] = (dropped[entry.field] ?? 0) + 1\n }\n normalized.push({ index, row: verdict.row })\n })\n\n // The roster reader keys on `ownerEmail`; a task's word for it is assignee.\n const members = await ownerDirectory(\n context.orgId,\n normalized.map((entry) => ({ ownerEmail: entry.row.assigneeEmail })),\n )\n const firestore = firebaseAdmin.app().firestore()\n const tasks = firestore\n .collection('orgs')\n .doc(context.orgId)\n .collection(CRM_COLLECTIONS.tasks)\n const batch = firestore.batch()\n const nowMs = Date.now()\n let created = 0\n\n for (const { index, row } of normalized) {\n let assigneeUid: string | undefined\n if (row.assigneeEmail) {\n assigneeUid = members.get(row.assigneeEmail)\n if (!assigneeUid) {\n skipped.push({ index, title: row.title, reason: 'unknown-assignee' })\n continue\n }\n }\n batch.set(tasks.doc(), {\n title: row.title,\n kind: row.kind,\n priority: row.priority,\n status: row.status,\n dueAtMs: row.dueAtMs,\n notes: row.notes ?? '',\n completedAtMs: row.status === 'done' ? nowMs : null,\n ...(row.status === 'done' ? { completedByUid: context.uid } : {}),\n ...(assigneeUid ? { assigneeUid } : {}),\n visibleTo: context.scopeTokens,\n hostId: context.hostId,\n createdByUid: context.uid,\n createdAt: FieldValue.serverTimestamp(),\n updatedAt: FieldValue.serverTimestamp(),\n })\n created += 1\n }\n if (created) await batch.commit()\n\n const result: TaskImportChunkResult = {\n received: read.rows.length,\n created,\n merged: 0,\n skipped: skipped.sort((a, b) => a.index - b.index),\n dropped,\n ownersUnresolved: [],\n }\n return res.status(200).json(result)\n } catch (error) {\n console.error('crm/tasks-import failed', error)\n return res.status(500).json({ error: 'The import could not continue.' })\n }\n}\n"],"names":["CRM_COLLECTIONS","TASK_IMPORT_CHUNK_SIZE","TASK_IMPORT_MAX_BODY_BYTES","normalizeTaskImportRow","firebaseAdmin","FieldValue","ownerDirectory","readImportRows","resolveImportContext","crmTasksImportHandler","req","res","method","setHeader","status","json","error","read","maxBodyBytes","chunkSize","context","ok","body","skipped","dropped","normalized","rows","forEach","raw","index","verdict","push","title","input","reason","entry","row","field","members","orgId","map","ownerEmail","assigneeEmail","firestore","app","tasks","collection","doc","batch","nowMs","Date","now","created","assigneeUid","get","set","kind","priority","dueAtMs","notes","completedAtMs","completedByUid","uid","visibleTo","scopeTokens","hostId","createdByUid","createdAt","serverTimestamp","updatedAt","commit","result","received","length","merged","sort","a","b","ownersUnresolved","console"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BC,GAED,SAASA,eAAe,QAA+B,sBAAqB;AAC5E,SACEC,sBAAsB,EACtBC,0BAA0B,EAK1BC,sBAAsB,QACjB,8BAA0B;AACjC,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,2BAA0B;AACrD,SAASC,cAAc,EAAEC,cAAc,EAAEC,oBAAoB,QAAQ,sBAAkB;AAEvF;;;;;CAKC,GACD,OAAO,MAAMC,wBAA0C,OAAOC,KAAKC;IACjE,IAAID,IAAIE,MAAM,KAAK,QAAQ;QACzBD,IAAIE,SAAS,CAAC,SAAS;QACvB,OAAOF,IAAIG,MAAM,CAAC,KAAKC,IAAI,CAAC;YAAEC,OAAO;QAAqB;IAC5D;IACA,MAAMC,OAAOV,eAAiCG,KAAK;QACjDQ,cAAchB;QACdiB,WAAWlB;IACb;IACA,IAAI,WAAWgB,MAAM,OAAON,IAAIG,MAAM,CAACG,KAAKH,MAAM,EAAEC,IAAI,CAAC;QAAEC,OAAOC,KAAKD,KAAK;IAAC;IAC7E,IAAI;QACF,MAAMI,UAAU,MAAMZ,qBAAqBE;QAC3C,IAAIU,QAAQC,EAAE,KAAK,OAAO,OAAOV,IAAIG,MAAM,CAACM,QAAQN,MA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|
|
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
|
+
/**
|
|
18
|
+
* `POST /api/crm/deal-stage` — the one writer of a deal's stage (AGL-2598).
|
|
19
|
+
*
|
|
20
|
+
* ## Why a route, when the rules would let the browser do it
|
|
21
|
+
*
|
|
22
|
+
* A deal's title, amount and owner are edited client-direct against the
|
|
23
|
+
* Firestore rules, and nothing about a stage change needs a server to be
|
|
24
|
+
* SAFE. What it needs a server for is to be HEARD: a move between stages, a
|
|
25
|
+
* win and a loss are the three moments an automation wants — "when a deal is
|
|
26
|
+
* won, email the owner", "when one reaches negotiation, file a task" — and a
|
|
27
|
+
* workflow only fires on an event the tenant runtime emits. A stage written
|
|
28
|
+
* by the browser would be a fact nothing could react to. So every surface
|
|
29
|
+
* that moves a deal calls here, and this handler updates the document and
|
|
30
|
+
* then emits `dealStageChanged`, `dealWon` or `dealLost` with a flat payload
|
|
31
|
+
* a workflow filter can read.
|
|
32
|
+
*
|
|
33
|
+
* ## Who may call it
|
|
34
|
+
*
|
|
35
|
+
* Three gates, in the order the cheapest fails first:
|
|
36
|
+
*
|
|
37
|
+
* 1. A verified Firebase session — the console's `authorizedFetch` puts the
|
|
38
|
+
* id token on every call.
|
|
39
|
+
* 2. An admin or editor role ON THIS SITE, resolved by `hostRoleFor` from
|
|
40
|
+
* the org member document, which is the same projection the rules read.
|
|
41
|
+
* 3. The `data.manage` permission in the org — the key the whole CRM is
|
|
42
|
+
* gated on, resolved through the custom-role and per-member layers by
|
|
43
|
+
* `memberHasOrgPermission`, because a member document alone cannot say
|
|
44
|
+
* what a custom role took away.
|
|
45
|
+
*
|
|
46
|
+
* And then the deal has to be VISIBLE to the site: its `visibleTo` must
|
|
47
|
+
* intersect the scope tokens a contact captured on this site would carry.
|
|
48
|
+
* The Admin SDK evaluates no rules, so without this check an editor of one
|
|
49
|
+
* site in an agency could move another client's deals by id.
|
|
50
|
+
*
|
|
51
|
+
* ## The organization variant (AGL-2634)
|
|
52
|
+
*
|
|
53
|
+
* `{ orgId, dealId, … }` instead of a site: the org-level hub's board. The
|
|
54
|
+
* caller is authorized by the ORG — an org-wide member holding
|
|
55
|
+
* `data.manage`, the org hub's own gate — and no visibility check is made,
|
|
56
|
+
* because an org-wide member reads every row the org holds. The event
|
|
57
|
+
* still goes to the deal's own capturing site, which is where the
|
|
58
|
+
* automations that listen for it live; a deal no site captured has none to
|
|
59
|
+
* tell. And the act is logged in the org's feed, since there is no one
|
|
60
|
+
* site's feed it happened in.
|
|
61
|
+
*
|
|
62
|
+
* ## What it writes
|
|
63
|
+
*
|
|
64
|
+
* `stageId`, `status` (from the target stage's `kind`, never from the body),
|
|
65
|
+
* `stageChangedAtMs`, `closedAtMs` (set on a close, cleared on a reopen) and
|
|
66
|
+
* `lostReason` (kept on a loss, removed on anything else). A move to the
|
|
67
|
+
* stage the deal is already in writes nothing and emits nothing — an
|
|
68
|
+
* automation must not fire twice because a card was dropped where it was.
|
|
69
|
+
*
|
|
70
|
+
* ## A won deal makes its contact a customer (AGL-2641)
|
|
71
|
+
*
|
|
72
|
+
* A win is the same fact as a purchase — the business has decided this
|
|
73
|
+
* person bought — and an order already floors a contact's lifecycle stage
|
|
74
|
+
* at `customer` on capture. So the transition INTO `won` applies the same
|
|
75
|
+
* floor to the contact the deal names, in the same write path, behind no
|
|
76
|
+
* setting: `floorContactLifecycleStage` fills an empty stage or advances an
|
|
77
|
+
* earlier one inside the facet of the site the deal was made on, and never
|
|
78
|
+
* moves anybody back — a customer stays a customer, an evangelist an
|
|
79
|
+
* evangelist. When the stage did move, `contactStageChanged` is announced
|
|
80
|
+
* after `dealWon`, so an automation keyed on "became a customer" hears it,
|
|
81
|
+
* and the org's activity line says so. A failure to write the contact does
|
|
82
|
+
* not undo the win: the deal is already closed, and the response reports
|
|
83
|
+
* `customer: null` rather than a 500 for a stage change that did happen.
|
|
84
|
+
*/
|
|
85
|
+
import { type PluginApiHandler } from '@aglyn/aglyn/server';
|
|
86
|
+
/** The most a lost reason may carry — a sentence or two, not a post-mortem. */
|
|
87
|
+
export declare const LOST_REASON_MAX = 500;
|
|
88
|
+
export declare const crmDealStageHandler: PluginApiHandler;
|