@aglyn/plugins-crm 1.0.0-beta.221 → 1.0.0-beta.223
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/README.md +2 -1
- package/package.json +13 -13
- package/src/lib/components/activity-list.js +12 -5
- package/src/lib/components/activity-list.js.map +1 -1
- package/src/lib/components/companies-bulk-bar.d.ts +1 -4
- package/src/lib/components/companies-bulk-bar.js +7 -20
- package/src/lib/components/companies-bulk-bar.js.map +1 -1
- package/src/lib/components/companies-section.d.ts +3 -3
- package/src/lib/components/companies-section.js +149 -46
- package/src/lib/components/companies-section.js.map +1 -1
- package/src/lib/components/company-edit-drawer.js +281 -20
- package/src/lib/components/company-edit-drawer.js.map +1 -1
- package/src/lib/components/company-properties-card.js +99 -8
- package/src/lib/components/company-properties-card.js.map +1 -1
- package/src/lib/components/contact-detail-page.js +3 -1
- package/src/lib/components/contact-detail-page.js.map +1 -1
- package/src/lib/components/contact-merge-dialog.js +33 -10
- package/src/lib/components/contact-merge-dialog.js.map +1 -1
- package/src/lib/components/contact-properties-card.d.ts +0 -69
- package/src/lib/components/contact-properties-card.js +350 -60
- package/src/lib/components/contact-properties-card.js.map +1 -1
- package/src/lib/components/contact-reports-to-field.d.ts +46 -0
- package/src/lib/components/contact-reports-to-field.js +67 -0
- package/src/lib/components/contact-reports-to-field.js.map +1 -0
- package/src/lib/components/contacts-bulk-bar.d.ts +1 -8
- package/src/lib/components/contacts-bulk-bar.js +7 -19
- package/src/lib/components/contacts-bulk-bar.js.map +1 -1
- package/src/lib/components/contacts-section.js +46 -33
- package/src/lib/components/contacts-section.js.map +1 -1
- package/src/lib/components/crm-call-actions.d.ts +10 -0
- package/src/lib/components/crm-call-actions.js +26 -9
- package/src/lib/components/crm-call-actions.js.map +1 -1
- package/src/lib/components/crm-next-activity-column.js +1 -1
- package/src/lib/components/crm-next-activity-column.js.map +1 -1
- package/src/lib/components/crm-record-picker.d.ts +15 -0
- package/src/lib/components/crm-record-picker.js +16 -10
- package/src/lib/components/crm-record-picker.js.map +1 -1
- package/src/lib/components/crm-transfer-buttons.d.ts +54 -0
- package/src/lib/components/crm-transfer-buttons.js +167 -0
- package/src/lib/components/crm-transfer-buttons.js.map +1 -0
- package/src/lib/components/deal-contact-roles-card.d.ts +46 -0
- package/src/lib/components/deal-contact-roles-card.js +368 -0
- package/src/lib/components/deal-contact-roles-card.js.map +1 -0
- package/src/lib/components/deal-detail-page.d.ts +3 -2
- package/src/lib/components/deal-detail-page.js +25 -6
- package/src/lib/components/deal-detail-page.js.map +1 -1
- package/src/lib/components/deal-edit-drawer.d.ts +10 -0
- package/src/lib/components/deal-edit-drawer.js +219 -10
- package/src/lib/components/deal-edit-drawer.js.map +1 -1
- package/src/lib/components/deal-properties-card.d.ts +7 -0
- package/src/lib/components/deal-properties-card.js +34 -3
- package/src/lib/components/deal-properties-card.js.map +1 -1
- package/src/lib/components/deal-stage-card.d.ts +4 -0
- package/src/lib/components/deal-stage-card.js +10 -2
- package/src/lib/components/deal-stage-card.js.map +1 -1
- package/src/lib/components/deals-bulk-bar.d.ts +0 -3
- package/src/lib/components/deals-bulk-bar.js +7 -20
- package/src/lib/components/deals-bulk-bar.js.map +1 -1
- package/src/lib/components/deals-section.d.ts +3 -3
- package/src/lib/components/deals-section.js +123 -63
- package/src/lib/components/deals-section.js.map +1 -1
- package/src/lib/components/fields-section.js +31 -17
- package/src/lib/components/fields-section.js.map +1 -1
- package/src/lib/components/lead-convert-dialog.d.ts +4 -0
- package/src/lib/components/lead-convert-dialog.js +23 -1
- package/src/lib/components/lead-convert-dialog.js.map +1 -1
- package/src/lib/components/lead-detail-page.js +8 -2
- package/src/lib/components/lead-detail-page.js.map +1 -1
- package/src/lib/components/lead-profile-fields.d.ts +71 -0
- package/src/lib/components/lead-profile-fields.js +386 -0
- package/src/lib/components/lead-profile-fields.js.map +1 -0
- package/src/lib/components/lead-properties-card.d.ts +2 -1
- package/src/lib/components/lead-properties-card.js +85 -176
- package/src/lib/components/lead-properties-card.js.map +1 -1
- package/src/lib/components/lead-source-select.d.ts +4 -23
- package/src/lib/components/lead-source-select.js +9 -73
- package/src/lib/components/lead-source-select.js.map +1 -1
- package/src/lib/components/lead-status-chip.d.ts +9 -3
- package/src/lib/components/lead-status-chip.js +8 -4
- package/src/lib/components/lead-status-chip.js.map +1 -1
- package/src/lib/components/lead-status-options.d.ts +20 -0
- package/src/lib/components/lead-status-options.js +51 -0
- package/src/lib/components/lead-status-options.js.map +1 -0
- package/src/lib/components/lead-unqualify-dialog.d.ts +5 -0
- package/src/lib/components/lead-unqualify-dialog.js +50 -18
- package/src/lib/components/lead-unqualify-dialog.js.map +1 -1
- package/src/lib/components/leads-bulk-bar.d.ts +0 -3
- package/src/lib/components/leads-bulk-bar.js +29 -29
- package/src/lib/components/leads-bulk-bar.js.map +1 -1
- package/src/lib/components/leads-section.js +120 -68
- package/src/lib/components/leads-section.js.map +1 -1
- package/src/lib/components/linked-deals-card.d.ts +4 -0
- package/src/lib/components/linked-deals-card.js +47 -3
- package/src/lib/components/linked-deals-card.js.map +1 -1
- package/src/lib/components/log-activity-dialog.js +43 -3
- package/src/lib/components/log-activity-dialog.js.map +1 -1
- package/src/lib/components/new-contact-drawer.d.ts +8 -0
- package/src/lib/components/new-contact-drawer.js +108 -6
- package/src/lib/components/new-contact-drawer.js.map +1 -1
- package/src/lib/components/new-lead-drawer.d.ts +9 -2
- package/src/lib/components/new-lead-drawer.js +88 -121
- package/src/lib/components/new-lead-drawer.js.map +1 -1
- package/src/lib/components/picklist-select.d.ts +36 -0
- package/src/lib/components/picklist-select.js +114 -0
- package/src/lib/components/picklist-select.js.map +1 -0
- package/src/lib/components/picklist-values-card.d.ts +34 -0
- package/src/lib/components/{lead-source-values-card.js → picklist-values-card.js} +241 -58
- package/src/lib/components/picklist-values-card.js.map +1 -0
- package/src/lib/components/pipeline-stages-dialog.d.ts +7 -0
- package/src/lib/components/pipeline-stages-dialog.js +26 -4
- package/src/lib/components/pipeline-stages-dialog.js.map +1 -1
- package/src/lib/components/pipelines-dialog.js +15 -6
- package/src/lib/components/pipelines-dialog.js.map +1 -1
- package/src/lib/components/recent-activity-feed.js +20 -5
- package/src/lib/components/recent-activity-feed.js.map +1 -1
- package/src/lib/components/recipes-card.js +4 -2
- package/src/lib/components/recipes-card.js.map +1 -1
- package/src/lib/components/record-tasks-card.js +15 -8
- package/src/lib/components/record-tasks-card.js.map +1 -1
- package/src/lib/components/reports/forecast-card.d.ts +6 -0
- package/src/lib/components/reports/forecast-card.js +101 -3
- package/src/lib/components/reports/forecast-card.js.map +1 -1
- package/src/lib/components/reports/lead-funnel-card.d.ts +12 -0
- package/src/lib/components/reports/lead-funnel-card.js +9 -5
- package/src/lib/components/reports/lead-funnel-card.js.map +1 -1
- package/src/lib/components/reports/lead-source-card.d.ts +23 -0
- package/src/lib/components/reports/lead-source-card.js +318 -0
- package/src/lib/components/reports/lead-source-card.js.map +1 -0
- package/src/lib/components/reports/pipeline-card.js +2 -1
- package/src/lib/components/reports/pipeline-card.js.map +1 -1
- package/src/lib/components/reports/report-export.js +1 -1
- package/src/lib/components/reports/report-export.js.map +1 -1
- package/src/lib/components/reports-section.js +8 -0
- package/src/lib/components/reports-section.js.map +1 -1
- package/src/lib/components/sharing-rule-drawer.d.ts +5 -0
- package/src/lib/components/sharing-rule-drawer.js +108 -19
- package/src/lib/components/sharing-rule-drawer.js.map +1 -1
- package/src/lib/components/sharing-rules-card.js +11 -3
- package/src/lib/components/sharing-rules-card.js.map +1 -1
- package/src/lib/components/task-cells.d.ts +9 -1
- package/src/lib/components/task-cells.js +9 -4
- package/src/lib/components/task-cells.js.map +1 -1
- package/src/lib/components/task-edit-drawer.js +111 -43
- package/src/lib/components/task-edit-drawer.js.map +1 -1
- package/src/lib/components/tasks-bulk-bar.d.ts +0 -3
- package/src/lib/components/tasks-bulk-bar.js +7 -20
- package/src/lib/components/tasks-bulk-bar.js.map +1 -1
- package/src/lib/components/tasks-calendar.d.ts +3 -0
- package/src/lib/components/tasks-calendar.js +8 -1
- package/src/lib/components/tasks-calendar.js.map +1 -1
- package/src/lib/components/tasks-section.d.ts +3 -3
- package/src/lib/components/tasks-section.js +58 -43
- package/src/lib/components/tasks-section.js.map +1 -1
- package/src/lib/constants/api-routes.d.ts +2 -9
- package/src/lib/constants/api-routes.js +1 -7
- package/src/lib/constants/api-routes.js.map +1 -1
- package/src/lib/constants/bundle-common.d.ts +6 -0
- package/src/lib/constants/bundle-common.js +11 -0
- package/src/lib/constants/bundle-common.js.map +1 -1
- package/src/lib/constants/company-filters.d.ts +14 -0
- package/src/lib/constants/company-filters.js +51 -1
- package/src/lib/constants/company-filters.js.map +1 -1
- package/src/lib/constants/contact-filters.d.ts +2 -0
- package/src/lib/constants/contact-filters.js +18 -1
- package/src/lib/constants/contact-filters.js.map +1 -1
- package/src/lib/constants/deal-filters.d.ts +22 -1
- package/src/lib/constants/deal-filters.js +67 -4
- package/src/lib/constants/deal-filters.js.map +1 -1
- package/src/lib/declarations.console-server.d.ts +3 -0
- package/src/lib/declarations.console-server.js +35 -0
- package/src/lib/declarations.console-server.js.map +1 -1
- package/src/lib/declarations.d.ts +26 -0
- package/src/lib/declarations.js +35 -0
- package/src/lib/declarations.js.map +1 -0
- package/src/lib/declarations.server.d.ts +11 -0
- package/src/lib/declarations.server.js +97 -1
- package/src/lib/declarations.server.js.map +1 -1
- package/src/lib/hooks/use-company-picklists.d.ts +15 -0
- package/src/lib/hooks/use-company-picklists.js +55 -0
- package/src/lib/hooks/use-company-picklists.js.map +1 -0
- package/src/lib/hooks/use-crm-picklist.d.ts +25 -0
- package/src/lib/hooks/use-crm-picklist.js +53 -0
- package/src/lib/hooks/use-crm-picklist.js.map +1 -0
- package/src/lib/hooks/use-crm-record-names.d.ts +16 -0
- package/src/lib/hooks/use-crm-record-names.js +45 -19
- package/src/lib/hooks/use-crm-record-names.js.map +1 -1
- package/src/lib/hooks/use-crm-task-picklists.d.ts +11 -0
- package/src/lib/hooks/use-crm-task-picklists.js +45 -0
- package/src/lib/hooks/use-crm-task-picklists.js.map +1 -0
- package/src/lib/hooks/use-deals.d.ts +14 -0
- package/src/lib/hooks/use-deals.js +29 -0
- package/src/lib/hooks/use-deals.js.map +1 -1
- package/src/lib/hooks/use-lead-picklists.d.ts +14 -0
- package/src/lib/hooks/use-lead-picklists.js +46 -0
- package/src/lib/hooks/use-lead-picklists.js.map +1 -0
- package/src/lib/hooks/use-lead-source-picklist.d.ts +5 -19
- package/src/lib/hooks/use-lead-source-picklist.js +12 -22
- package/src/lib/hooks/use-lead-source-picklist.js.map +1 -1
- package/src/lib/hooks/use-lead-status-picklist.d.ts +9 -0
- package/src/lib/hooks/use-lead-status-picklist.js +40 -0
- package/src/lib/hooks/use-lead-status-picklist.js.map +1 -0
- package/src/lib/model/companies.d.ts +32 -3
- package/src/lib/model/companies.js +133 -16
- package/src/lib/model/companies.js.map +1 -1
- package/src/lib/model/contact-merge.d.ts +27 -3
- package/src/lib/model/contact-merge.js +81 -7
- package/src/lib/model/contact-merge.js.map +1 -1
- package/src/lib/model/contact-record.d.ts +17 -0
- package/src/lib/model/contact-record.js +17 -2
- package/src/lib/model/contact-record.js.map +1 -1
- package/src/lib/model/contact-update.d.ts +31 -2
- package/src/lib/model/contact-update.js +14 -0
- package/src/lib/model/contact-update.js.map +1 -1
- package/src/lib/model/crm-list-query.d.ts +5 -0
- package/src/lib/model/crm-list-query.js +8 -0
- package/src/lib/model/crm-list-query.js.map +1 -1
- package/src/lib/model/crm-next-activity.d.ts +107 -0
- package/src/lib/model/crm-next-activity.js +140 -0
- package/src/lib/model/crm-next-activity.js.map +1 -0
- package/src/lib/model/crm-recipes.d.ts +40 -0
- package/src/lib/model/crm-recipes.js +259 -0
- package/src/lib/model/crm-recipes.js.map +1 -0
- package/src/lib/model/crm-record-counts.d.ts +36 -0
- package/src/lib/model/crm-record-counts.js +54 -0
- package/src/lib/model/crm-record-counts.js.map +1 -0
- package/src/lib/model/crm-record-lists.d.ts +23 -0
- package/src/lib/model/crm-record-lists.js +161 -0
- package/src/lib/model/crm-record-lists.js.map +1 -0
- package/src/lib/model/crm-reports.d.ts +73 -3
- package/src/lib/model/crm-reports.js +120 -1
- package/src/lib/model/crm-reports.js.map +1 -1
- package/src/lib/model/crm-sharing.d.ts +21 -3
- package/src/lib/model/crm-sharing.js +27 -6
- package/src/lib/model/crm-sharing.js.map +1 -1
- package/src/lib/model/crm-task-reminders.d.ts +152 -0
- package/src/lib/model/crm-task-reminders.js +161 -0
- package/src/lib/model/crm-task-reminders.js.map +1 -0
- package/src/lib/model/deal-board-model.d.ts +8 -2
- package/src/lib/model/deal-board-model.js +15 -2
- package/src/lib/model/deal-board-model.js.map +1 -1
- package/src/lib/model/deal-contact-roles.d.ts +45 -0
- package/src/lib/model/deal-contact-roles.js +73 -0
- package/src/lib/model/deal-contact-roles.js.map +1 -0
- package/src/lib/model/deal-form-model.d.ts +56 -0
- package/src/lib/model/deal-form-model.js +79 -7
- package/src/lib/model/deal-form-model.js.map +1 -1
- package/src/lib/model/download-text-file.d.ts +23 -0
- package/src/lib/model/download-text-file.js +34 -0
- package/src/lib/model/download-text-file.js.map +1 -0
- package/src/lib/model/lead-filters.d.ts +36 -2
- package/src/lib/model/lead-filters.js +123 -2
- package/src/lib/model/lead-filters.js.map +1 -1
- package/src/lib/model/lead-source-direction.d.ts +38 -0
- package/src/lib/model/lead-source-direction.js +52 -0
- package/src/lib/model/lead-source-direction.js.map +1 -0
- package/src/lib/model/next-activity.d.ts +1 -1
- package/src/lib/model/next-activity.js.map +1 -1
- package/src/lib/model/picklist-values.d.ts +119 -0
- package/src/lib/model/picklist-values.js +256 -0
- package/src/lib/model/picklist-values.js.map +1 -0
- package/src/lib/model/record-facts-disclosed.d.ts +81 -0
- package/src/lib/model/record-facts-disclosed.js +281 -0
- package/src/lib/model/record-facts-disclosed.js.map +1 -0
- package/src/lib/model/record-facts.d.ts +215 -34
- package/src/lib/model/record-facts.js +307 -128
- package/src/lib/model/record-facts.js.map +1 -1
- package/src/lib/model/task-picklists.d.ts +52 -0
- package/src/lib/model/task-picklists.js +83 -0
- package/src/lib/model/task-picklists.js.map +1 -0
- package/src/lib/model/task-routes.d.ts +13 -0
- package/src/lib/model/task-routes.js +23 -4
- package/src/lib/model/task-routes.js.map +1 -1
- package/src/lib/plan-entitlements.js +6 -4
- package/src/lib/plan-entitlements.js.map +1 -1
- package/src/lib/plugin.js +17 -0
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/server/api-v1/contacts.js +220 -14
- package/src/lib/server/api-v1/contacts.js.map +1 -1
- package/src/lib/server/api-v1/crm-activities.js +14 -1
- package/src/lib/server/api-v1/crm-activities.js.map +1 -1
- package/src/lib/server/api-v1/crm-companies.js +123 -14
- package/src/lib/server/api-v1/crm-companies.js.map +1 -1
- package/src/lib/server/api-v1/crm-deals.js +291 -26
- package/src/lib/server/api-v1/crm-deals.js.map +1 -1
- package/src/lib/server/api-v1/crm-leads.js +144 -38
- package/src/lib/server/api-v1/crm-leads.js.map +1 -1
- package/src/lib/server/api-v1/crm-pipelines.d.ts +6 -0
- package/src/lib/server/api-v1/crm-pipelines.js +8 -2
- package/src/lib/server/api-v1/crm-pipelines.js.map +1 -1
- package/src/lib/server/api-v1/crm-tasks.js +78 -34
- package/src/lib/server/api-v1/crm-tasks.js.map +1 -1
- package/src/lib/server/api-v1/openapi.d.ts +0 -11
- package/src/lib/server/api-v1/openapi.js +171 -16
- package/src/lib/server/api-v1/openapi.js.map +1 -1
- package/src/lib/server/assign-contact-owner.d.ts +188 -0
- package/src/lib/server/assign-contact-owner.js +446 -0
- package/src/lib/server/assign-contact-owner.js.map +1 -0
- package/src/lib/server/associate-company-by-domain.d.ts +70 -0
- package/src/lib/server/associate-company-by-domain.js +153 -0
- package/src/lib/server/associate-company-by-domain.js.map +1 -0
- package/src/lib/server/automation-steps.d.ts +140 -0
- package/src/lib/server/automation-steps.js +669 -0
- package/src/lib/server/automation-steps.js.map +1 -0
- package/src/lib/server/capture-contact.d.ts +17 -0
- package/src/lib/server/capture-contact.js +95 -26
- package/src/lib/server/capture-contact.js.map +1 -1
- package/src/lib/server/capture-host-contact.d.ts +104 -0
- package/src/lib/server/capture-host-contact.js +151 -0
- package/src/lib/server/capture-host-contact.js.map +1 -0
- package/src/lib/server/company-children.d.ts +25 -0
- package/src/lib/server/company-children.js +42 -0
- package/src/lib/server/company-children.js.map +1 -0
- package/src/lib/server/company-delete.d.ts +18 -0
- package/src/lib/server/company-delete.js +44 -21
- package/src/lib/server/company-delete.js.map +1 -1
- package/src/lib/server/contact-email-history.js +21 -19
- package/src/lib/server/contact-email-history.js.map +1 -1
- package/src/lib/server/contact-remove.js +27 -2
- package/src/lib/server/contact-remove.js.map +1 -1
- package/src/lib/server/contact-reports-to.d.ts +61 -0
- package/src/lib/server/contact-reports-to.js +114 -0
- package/src/lib/server/contact-reports-to.js.map +1 -0
- package/src/lib/server/contact-update.d.ts +42 -1
- package/src/lib/server/contact-update.js +204 -23
- package/src/lib/server/contact-update.js.map +1 -1
- package/src/lib/server/convert-host-lead.d.ts +46 -1
- package/src/lib/server/convert-host-lead.js +173 -15
- package/src/lib/server/convert-host-lead.js.map +1 -1
- package/src/lib/server/convert-open-lead.js +12 -5
- package/src/lib/server/convert-open-lead.js.map +1 -1
- package/src/lib/server/crm-email-activity.d.ts +118 -0
- package/src/lib/server/crm-email-activity.js +148 -0
- package/src/lib/server/crm-email-activity.js.map +1 -0
- package/src/lib/server/crm-inbound-email.js +1 -1
- package/src/lib/server/crm-inbound-email.js.map +1 -1
- package/src/lib/server/crm-next-activity.d.ts +74 -0
- package/src/lib/server/crm-next-activity.js +194 -0
- package/src/lib/server/crm-next-activity.js.map +1 -0
- package/src/lib/server/crm-record-indexes.d.ts +45 -0
- package/src/lib/server/crm-record-indexes.js +78 -0
- package/src/lib/server/crm-record-indexes.js.map +1 -0
- package/src/lib/server/crm-sharing.d.ts +9 -1
- package/src/lib/server/crm-sharing.js +23 -3
- package/src/lib/server/crm-sharing.js.map +1 -1
- package/src/lib/server/deal-contact-roles.d.ts +27 -0
- package/src/lib/server/deal-contact-roles.js +89 -0
- package/src/lib/server/deal-contact-roles.js.map +1 -0
- package/src/lib/server/email-send.js +2 -1
- package/src/lib/server/email-send.js.map +1 -1
- package/src/lib/server/lead-convert.d.ts +5 -0
- package/src/lib/server/lead-convert.js +19 -3
- package/src/lib/server/lead-convert.js.map +1 -1
- package/src/lib/server/lead-create.d.ts +17 -2
- package/src/lib/server/lead-create.js +46 -14
- package/src/lib/server/lead-create.js.map +1 -1
- package/src/lib/server/lead-nurturing.d.ts +6 -0
- package/src/lib/server/lead-nurturing.js +57 -20
- package/src/lib/server/lead-nurturing.js.map +1 -1
- package/src/lib/server/lead-picklists.d.ts +35 -0
- package/src/lib/server/lead-picklists.js +52 -0
- package/src/lib/server/lead-picklists.js.map +1 -0
- package/src/lib/server/lead-source-picklist.d.ts +1 -13
- package/src/lib/server/lead-source-picklist.js +6 -33
- package/src/lib/server/lead-source-picklist.js.map +1 -1
- package/src/lib/server/merge-contacts.js +23 -5
- package/src/lib/server/merge-contacts.js.map +1 -1
- package/src/lib/server/next-activity-routes.js +2 -1
- package/src/lib/server/next-activity-routes.js.map +1 -1
- package/src/lib/server/person-eraser.d.ts +53 -0
- package/src/lib/server/person-eraser.js +149 -0
- package/src/lib/server/person-eraser.js.map +1 -0
- package/src/lib/server/person-records.d.ts +69 -0
- package/src/lib/server/person-records.js +317 -0
- package/src/lib/server/person-records.js.map +1 -0
- package/src/lib/server/person-refund.d.ts +97 -0
- package/src/lib/server/person-refund.js +221 -0
- package/src/lib/server/person-refund.js.map +1 -0
- package/src/lib/server/picklist-values.d.ts +21 -0
- package/src/lib/server/picklist-values.js +308 -0
- package/src/lib/server/picklist-values.js.map +1 -0
- package/src/lib/server/read-picklist.d.ts +44 -0
- package/src/lib/server/read-picklist.js +65 -0
- package/src/lib/server/read-picklist.js.map +1 -0
- package/src/lib/server/recipe-routes.js +22 -8
- package/src/lib/server/recipe-routes.js.map +1 -1
- package/src/lib/server/record-email-state.js +7 -1
- package/src/lib/server/record-email-state.js.map +1 -1
- package/src/lib/server/record-facts.d.ts +3 -0
- package/src/lib/server/record-facts.js +233 -31
- package/src/lib/server/record-facts.js.map +1 -1
- package/src/lib/server/record-origin.d.ts +27 -0
- package/src/lib/server/record-origin.js +104 -0
- package/src/lib/server/record-origin.js.map +1 -0
- package/src/lib/server/record-timeline.js +40 -3
- package/src/lib/server/record-timeline.js.map +1 -1
- package/src/lib/server/suite-gate.js +4 -3
- package/src/lib/server/suite-gate.js.map +1 -1
- package/src/lib/server/task-reminders-route.js +2 -1
- package/src/lib/server/task-reminders-route.js.map +1 -1
- package/src/lib/server/task-routes.js +33 -17
- package/src/lib/server/task-routes.js.map +1 -1
- package/src/lib/server-deal-stage.d.ts +5 -1
- package/src/lib/server-deal-stage.js +10 -5
- package/src/lib/server-deal-stage.js.map +1 -1
- package/src/lib/server.d.ts +8 -3
- package/src/lib/server.js +47 -43
- package/src/lib/server.js.map +1 -1
- package/src/lib/testing/memory-firestore.d.ts +55 -0
- package/src/lib/testing/memory-firestore.js +335 -0
- package/src/lib/testing/memory-firestore.js.map +1 -0
- package/src/lib/testing/stand-in-email-send-index.d.ts +25 -0
- package/src/lib/testing/stand-in-email-send-index.js +49 -0
- package/src/lib/testing/stand-in-email-send-index.js.map +1 -0
- package/src/lib/transfer/activities.d.ts +30 -0
- package/src/lib/transfer/activities.js +132 -0
- package/src/lib/transfer/activities.js.map +1 -0
- package/src/lib/transfer/aliases.d.ts +22 -0
- package/src/lib/transfer/aliases.js +1342 -0
- package/src/lib/transfer/aliases.js.map +1 -0
- package/src/lib/transfer/common.d.ts +222 -0
- package/src/lib/transfer/common.js +832 -0
- package/src/lib/transfer/common.js.map +1 -0
- package/src/lib/transfer/companies.d.ts +43 -0
- package/src/lib/transfer/companies.js +549 -0
- package/src/lib/transfer/companies.js.map +1 -0
- package/src/lib/transfer/contacts.d.ts +31 -0
- package/src/lib/transfer/contacts.js +727 -0
- package/src/lib/transfer/contacts.js.map +1 -0
- package/src/lib/transfer/deals.d.ts +66 -0
- package/src/lib/transfer/deals.js +698 -0
- package/src/lib/transfer/deals.js.map +1 -0
- package/src/lib/transfer/email-templates-package.d.ts +40 -0
- package/src/lib/transfer/email-templates-package.js +76 -0
- package/src/lib/transfer/email-templates-package.js.map +1 -0
- package/src/lib/transfer/email-templates-package.server.d.ts +32 -0
- package/src/lib/transfer/email-templates-package.server.js +176 -0
- package/src/lib/transfer/email-templates-package.server.js.map +1 -0
- package/src/lib/transfer/fields.d.ts +102 -0
- package/src/lib/transfer/fields.js +1755 -0
- package/src/lib/transfer/fields.js.map +1 -0
- package/src/lib/transfer/leads.d.ts +30 -0
- package/src/lib/transfer/leads.js +582 -0
- package/src/lib/transfer/leads.js.map +1 -0
- package/src/lib/transfer/pipelines.d.ts +21 -0
- package/src/lib/transfer/pipelines.js +172 -0
- package/src/lib/transfer/pipelines.js.map +1 -0
- package/src/lib/transfer/register.d.ts +47 -0
- package/src/lib/transfer/register.js +277 -0
- package/src/lib/transfer/register.js.map +1 -0
- package/src/lib/transfer/tasks.d.ts +30 -0
- package/src/lib/transfer/tasks.js +418 -0
- package/src/lib/transfer/tasks.js.map +1 -0
- package/src/lib/transfer/ui.d.ts +20 -0
- package/src/lib/transfer/ui.js +42 -0
- package/src/lib/transfer/ui.js.map +1 -0
- package/src/lib/components/company-import-drawer.d.ts +0 -42
- package/src/lib/components/company-import-drawer.js +0 -99
- package/src/lib/components/company-import-drawer.js.map +0 -1
- package/src/lib/components/contact-import-drawer.d.ts +0 -46
- package/src/lib/components/contact-import-drawer.js +0 -149
- package/src/lib/components/contact-import-drawer.js.map +0 -1
- package/src/lib/components/crm-export-all-button.d.ts +0 -39
- package/src/lib/components/crm-export-all-button.js +0 -98
- package/src/lib/components/crm-export-all-button.js.map +0 -1
- package/src/lib/components/csv-import-drawer.d.ts +0 -139
- package/src/lib/components/csv-import-drawer.js +0 -757
- package/src/lib/components/csv-import-drawer.js.map +0 -1
- package/src/lib/components/deal-import-drawer.d.ts +0 -24
- package/src/lib/components/deal-import-drawer.js +0 -83
- package/src/lib/components/deal-import-drawer.js.map +0 -1
- package/src/lib/components/lead-import-drawer.d.ts +0 -27
- package/src/lib/components/lead-import-drawer.js +0 -118
- package/src/lib/components/lead-import-drawer.js.map +0 -1
- package/src/lib/components/lead-source-values-card.d.ts +0 -27
- package/src/lib/components/lead-source-values-card.js.map +0 -1
- package/src/lib/components/task-import-drawer.d.ts +0 -24
- package/src/lib/components/task-import-drawer.js +0 -82
- package/src/lib/components/task-import-drawer.js.map +0 -1
- package/src/lib/model/companies-csv.d.ts +0 -36
- package/src/lib/model/companies-csv.js +0 -38
- package/src/lib/model/companies-csv.js.map +0 -1
- package/src/lib/model/contacts-csv.d.ts +0 -54
- package/src/lib/model/contacts-csv.js +0 -67
- package/src/lib/model/contacts-csv.js.map +0 -1
- package/src/lib/model/crm-company-import.d.ts +0 -154
- package/src/lib/model/crm-company-import.js +0 -331
- package/src/lib/model/crm-company-import.js.map +0 -1
- package/src/lib/model/crm-csv.d.ts +0 -239
- package/src/lib/model/crm-csv.js +0 -467
- package/src/lib/model/crm-csv.js.map +0 -1
- package/src/lib/model/crm-deal-import.d.ts +0 -112
- package/src/lib/model/crm-deal-import.js +0 -263
- package/src/lib/model/crm-deal-import.js.map +0 -1
- package/src/lib/model/crm-import.d.ts +0 -250
- package/src/lib/model/crm-import.js +0 -467
- package/src/lib/model/crm-import.js.map +0 -1
- package/src/lib/model/crm-lead-import.d.ts +0 -138
- package/src/lib/model/crm-lead-import.js +0 -446
- package/src/lib/model/crm-lead-import.js.map +0 -1
- package/src/lib/model/crm-task-import.d.ts +0 -94
- package/src/lib/model/crm-task-import.js +0 -275
- package/src/lib/model/crm-task-import.js.map +0 -1
- package/src/lib/model/deals-csv.d.ts +0 -32
- package/src/lib/model/deals-csv.js +0 -36
- package/src/lib/model/deals-csv.js.map +0 -1
- package/src/lib/model/import-column-shapes.d.ts +0 -36
- package/src/lib/model/import-column-shapes.js +0 -76
- package/src/lib/model/import-column-shapes.js.map +0 -1
- package/src/lib/model/lead-source-values.d.ts +0 -82
- package/src/lib/model/lead-source-values.js +0 -149
- package/src/lib/model/lead-source-values.js.map +0 -1
- package/src/lib/model/leads-csv.d.ts +0 -40
- package/src/lib/model/leads-csv.js +0 -40
- package/src/lib/model/leads-csv.js.map +0 -1
- package/src/lib/model/tasks-csv.d.ts +0 -28
- package/src/lib/model/tasks-csv.js +0 -28
- package/src/lib/model/tasks-csv.js.map +0 -1
- package/src/lib/server/companies-import.d.ts +0 -57
- package/src/lib/server/companies-import.js +0 -242
- package/src/lib/server/companies-import.js.map +0 -1
- package/src/lib/server/contacts-import.d.ts +0 -109
- package/src/lib/server/contacts-import.js +0 -393
- package/src/lib/server/contacts-import.js.map +0 -1
- package/src/lib/server/deals-import.d.ts +0 -76
- package/src/lib/server/deals-import.js +0 -248
- package/src/lib/server/deals-import.js.map +0 -1
- package/src/lib/server/export-route.d.ts +0 -60
- package/src/lib/server/export-route.js +0 -447
- package/src/lib/server/export-route.js.map +0 -1
- package/src/lib/server/import-context.d.ts +0 -87
- package/src/lib/server/import-context.js +0 -182
- package/src/lib/server/import-context.js.map +0 -1
- package/src/lib/server/lead-source-values.d.ts +0 -50
- package/src/lib/server/lead-source-values.js +0 -191
- package/src/lib/server/lead-source-values.js.map +0 -1
- package/src/lib/server/leads-import.d.ts +0 -84
- package/src/lib/server/leads-import.js +0 -367
- package/src/lib/server/leads-import.js.map +0 -1
- package/src/lib/server/tasks-import.d.ts +0 -54
- package/src/lib/server/tasks-import.js +0 -160
- package/src/lib/server/tasks-import.js.map +0 -1
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { type ContactSource, type CrmAssignmentTarget } from '@aglyn/aglyn/server';
|
|
18
|
+
/**
|
|
19
|
+
* WHO A NEW RECORD BELONGS TO — the one place an owner is decided on the
|
|
20
|
+
* server (AGL-2618).
|
|
21
|
+
*
|
|
22
|
+
* Two entry points over one transaction. `assignOwnerForCapture` is the
|
|
23
|
+
* capture door's pass: it runs the org's assignment rules in order, falls
|
|
24
|
+
* back to the capturing site's default owner, and touches only a record
|
|
25
|
+
* that has NO owner — a door that named one (the console's drawer, an
|
|
26
|
+
* import column, a conversion with a picked owner) has expressed a person's
|
|
27
|
+
* choice. `reassignContactOwner` is the automation's: an author who put
|
|
28
|
+
* "assign an owner" on a stage change means to reassign, and the step hands
|
|
29
|
+
* this either a member or the rotation.
|
|
30
|
+
*
|
|
31
|
+
* ## One transaction, because the pointer is shared
|
|
32
|
+
*
|
|
33
|
+
* The round-robin pool's pointer lives on the org document, and two
|
|
34
|
+
* captures landing together must take two different members. Firestore
|
|
35
|
+
* transactions serialize on what they read, so the org document, the
|
|
36
|
+
* contact and the roster documents are all read inside the transaction and
|
|
37
|
+
* the pointer is advanced in the same commit that writes the owner: a
|
|
38
|
+
* concurrent capture that read the same pointer retries and reads the moved
|
|
39
|
+
* one. The alternative — read the pointer, decide, then write — is exactly
|
|
40
|
+
* the read-then-write shape that lets two captures pick the same person.
|
|
41
|
+
*
|
|
42
|
+
* ## The roster is checked, once per member per attempt
|
|
43
|
+
*
|
|
44
|
+
* A rule may name a member who has since left, and a pool may hold one. A
|
|
45
|
+
* rule naming nobody on the roster is passed over rather than stopping the
|
|
46
|
+
* pass — the next rule may well assign — and a pool member who is gone is
|
|
47
|
+
* skipped for the next in the order. `orgs/{orgId}/members/{uid}` is keyed
|
|
48
|
+
* by uid, so the check is one document read per candidate, and only the
|
|
49
|
+
* roster is consulted: a project-level Auth lookup would admit people who
|
|
50
|
+
* are not on this organization at all (AGL-1122).
|
|
51
|
+
*
|
|
52
|
+
* ## The lead follows the contact
|
|
53
|
+
*
|
|
54
|
+
* The capture doors that file a lead (`addHostLead`: a form routed to leads,
|
|
55
|
+
* a sign-up, a booking) key it by `personKey(email)`, so the lead's document
|
|
56
|
+
* is addressable from the capture alone. When it exists it is given the same
|
|
57
|
+
* owner in the same transaction; two doors write the lead AFTER the contact
|
|
58
|
+
* they `void`ed, so for those sources the mirror is retried a few times over
|
|
59
|
+
* the next seconds, detached, and the person's Leads list shows the owner
|
|
60
|
+
* as soon as the lead is there.
|
|
61
|
+
*
|
|
62
|
+
* ## The owner is told, unless they chose themselves
|
|
63
|
+
*
|
|
64
|
+
* One console notification per assignment, for the record the recipient
|
|
65
|
+
* will open: the lead when the site holds one for this person, the contact
|
|
66
|
+
* otherwise. Not when the actor IS the new owner — a rep who converts a
|
|
67
|
+
* lead into their own contact has not been handed anything.
|
|
68
|
+
*
|
|
69
|
+
* ## Never rejects
|
|
70
|
+
*
|
|
71
|
+
* The capture has already succeeded and a form submission must not fail
|
|
72
|
+
* because the CRM could not decide who follows up; a failure is logged and
|
|
73
|
+
* answered as `none`, and the record is exactly as assignable by hand as it
|
|
74
|
+
* was before this existed. The automation executor turns a `none` into the
|
|
75
|
+
* step's recorded error.
|
|
76
|
+
*/
|
|
77
|
+
export interface OwnerAssignmentInput {
|
|
78
|
+
hostId: string;
|
|
79
|
+
/** `orgs/{orgId}/contacts/{contactId}` — the record the owner is written on. */
|
|
80
|
+
contactId: string;
|
|
81
|
+
/** The contact's address, which keys the lead and names the person in the notification. */
|
|
82
|
+
email: string;
|
|
83
|
+
/**
|
|
84
|
+
* The signed-in person making the assignment, when there is one. Never
|
|
85
|
+
* notified about their own choice; absent for a capture and an automation.
|
|
86
|
+
*/
|
|
87
|
+
actorUid?: string | null;
|
|
88
|
+
}
|
|
89
|
+
export interface CaptureAssignmentInput extends OwnerAssignmentInput {
|
|
90
|
+
source: ContactSource;
|
|
91
|
+
/** The form the capture came through, for a rule conditioned on it. */
|
|
92
|
+
formId?: string | null;
|
|
93
|
+
/** The tags the capture carried; the contact's own are read from the facet. */
|
|
94
|
+
tags?: readonly string[];
|
|
95
|
+
}
|
|
96
|
+
export interface ReassignmentInput extends OwnerAssignmentInput {
|
|
97
|
+
assign: CrmAssignmentTarget;
|
|
98
|
+
}
|
|
99
|
+
/** Why an assignment assigned nobody — the automation reports these verbatim. */
|
|
100
|
+
export type OwnerAssignmentRefusal = 'no-org' | 'no-contact' | 'no-lead' | 'no-rule' | 'empty-pool' | 'not-a-member' | 'failed';
|
|
101
|
+
/** What decided an assignment: a rule, the site default, the step's member, or the rotation. */
|
|
102
|
+
export type OwnerAssignedBy = 'rule' | 'default' | 'member' | 'roundRobin';
|
|
103
|
+
export type OwnerAssignment = {
|
|
104
|
+
outcome: 'assigned';
|
|
105
|
+
ownerUid: string;
|
|
106
|
+
by: OwnerAssignedBy;
|
|
107
|
+
/** The rule that decided it, when one did. */
|
|
108
|
+
ruleId?: string;
|
|
109
|
+
/** The lead document existed and now carries the owner too. */
|
|
110
|
+
leadMirrored: boolean;
|
|
111
|
+
/** A notification was fanned out to the new owner. */
|
|
112
|
+
notified: boolean;
|
|
113
|
+
}
|
|
114
|
+
/** The record already had this owner (a capture), or the same one was named again (a reassignment). */
|
|
115
|
+
| {
|
|
116
|
+
outcome: 'unchanged';
|
|
117
|
+
ownerUid: string;
|
|
118
|
+
} | {
|
|
119
|
+
outcome: 'none';
|
|
120
|
+
reason: OwnerAssignmentRefusal;
|
|
121
|
+
};
|
|
122
|
+
/** The words the run history and the log give each refusal. */
|
|
123
|
+
export declare const OWNER_ASSIGNMENT_REFUSALS: Record<OwnerAssignmentRefusal, string>;
|
|
124
|
+
/** The record an assignment notification opens. */
|
|
125
|
+
export type AssignedRecord = {
|
|
126
|
+
kind: 'contact';
|
|
127
|
+
id: string;
|
|
128
|
+
} | {
|
|
129
|
+
kind: 'lead';
|
|
130
|
+
id: string;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Tells a member a record is now theirs — one console notification, typed
|
|
134
|
+
* by the record it opens — unless the member handed it to themselves.
|
|
135
|
+
* Shared by the pass above and by the routes where a person picks the
|
|
136
|
+
* owner outright (a lead conversion naming a colleague), so every server
|
|
137
|
+
* path that writes `ownerUid` says so in the same words. Never throws;
|
|
138
|
+
* the fan-out swallows its own failures.
|
|
139
|
+
*/
|
|
140
|
+
export declare function notifyRecordAssigned(input: {
|
|
141
|
+
hostId: string;
|
|
142
|
+
orgId: string;
|
|
143
|
+
ownerUid: string;
|
|
144
|
+
actorUid?: string | null;
|
|
145
|
+
record: AssignedRecord;
|
|
146
|
+
/** How the person reads in the message: their name, else their address. */
|
|
147
|
+
who: string;
|
|
148
|
+
}): Promise<boolean>;
|
|
149
|
+
/**
|
|
150
|
+
* The capture door's pass: the org's rules in order, then the capturing
|
|
151
|
+
* site's default owner, on a record that has no owner yet. See the module
|
|
152
|
+
* comment for the whole of it.
|
|
153
|
+
*/
|
|
154
|
+
export declare function assignOwnerForCapture(input: CaptureAssignmentInput): Promise<OwnerAssignment>;
|
|
155
|
+
/**
|
|
156
|
+
* The deliberate assignment — the `assignContactOwner` step, and a person
|
|
157
|
+
* handing a record to somebody: a member by uid (verified on the roster) or
|
|
158
|
+
* the next in the round-robin pool, overwriting whoever held it. Naming the
|
|
159
|
+
* owner the record already has changes nothing and tells nobody.
|
|
160
|
+
*/
|
|
161
|
+
export declare function reassignContactOwner(input: ReassignmentInput): Promise<OwnerAssignment>;
|
|
162
|
+
/** The deliberate assignment of a LEAD the site holds and no contact has absorbed yet. */
|
|
163
|
+
export interface LeadReassignmentInput {
|
|
164
|
+
hostId: string;
|
|
165
|
+
/** `orgs/{orgId}/leads/{leadId}` — the person's key. */
|
|
166
|
+
leadId: string;
|
|
167
|
+
assign: CrmAssignmentTarget;
|
|
168
|
+
/** As {@link OwnerAssignmentInput.actorUid}: never told about their own choice. */
|
|
169
|
+
actorUid?: string | null;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* {@link reassignContactOwner} for a person who is still a LEAD (AGL-3458).
|
|
173
|
+
*
|
|
174
|
+
* A lead-routed form files a lead and no contact (AGL-3232), so an
|
|
175
|
+
* automation welcoming that person — "assign an owner, then book them a
|
|
176
|
+
* call" — has only the lead to act on. The owner is the lead's own
|
|
177
|
+
* `ownerUid`, the field the Leads list's Owner column and filter read and a
|
|
178
|
+
* conversion hands to the contact. Same transaction shape as a contact's:
|
|
179
|
+
* the org document, the lead and every roster candidate are read inside it,
|
|
180
|
+
* and the round-robin pointer moves in the commit that writes the owner, so
|
|
181
|
+
* a lead and a contact assigned at the same moment take two different
|
|
182
|
+
* members of the one rotation.
|
|
183
|
+
*
|
|
184
|
+
* Never rejects; a failure is logged and answered as `none`, which the
|
|
185
|
+
* automation records as the step's error.
|
|
186
|
+
*/
|
|
187
|
+
export declare function reassignLeadOwner(input: LeadReassignmentInput): Promise<OwnerAssignment>;
|
|
188
|
+
export default assignOwnerForCapture;
|
|
@@ -0,0 +1,446 @@
|
|
|
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
|
+
*/ import { assignmentRuleMatches, consentGroupForHost, contactFacetPath, CRM_ROUND_ROBIN_LAST_ASSIGNED_PATH, personKey, readContactFacet, readCrmAssignmentSettings, roundRobinOrder } from "@aglyn/aglyn/server";
|
|
18
|
+
import { firebaseAdmin, getHostDocAdmin, getOrgForHost, hostDisplayName, notifyUsers, restampCrmListFieldsAt } from "@aglyn/tenant-data-admin";
|
|
19
|
+
import { FieldValue } from "firebase-admin/firestore";
|
|
20
|
+
/** The words the run history and the log give each refusal. */ export const OWNER_ASSIGNMENT_REFUSALS = {
|
|
21
|
+
'no-org': 'this site has no organization',
|
|
22
|
+
'no-contact': 'the contact no longer exists',
|
|
23
|
+
'no-lead': 'the lead no longer exists',
|
|
24
|
+
'no-rule': 'no assignment rule matched and the site has no default owner',
|
|
25
|
+
'empty-pool': 'the round-robin pool has nobody on the roster in it',
|
|
26
|
+
'not-a-member': 'the owner named is not on the team',
|
|
27
|
+
failed: 'the owner could not be assigned'
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The doors whose lead lands after the contact they `void`ed — the ones the
|
|
31
|
+
* mirror is worth retrying for. An order, an import, a manual add and an
|
|
32
|
+
* API call file no lead, and a retry for them would be reads for nothing.
|
|
33
|
+
*/ const LEAD_FILING_SOURCES = new Set([
|
|
34
|
+
'form',
|
|
35
|
+
'member',
|
|
36
|
+
'booking'
|
|
37
|
+
]);
|
|
38
|
+
/** How long the detached lead mirror waits between its looks, in order. */ const LEAD_MIRROR_RETRY_MS = [
|
|
39
|
+
1000,
|
|
40
|
+
2000,
|
|
41
|
+
3000
|
|
42
|
+
];
|
|
43
|
+
/**
|
|
44
|
+
* The console path the owner's notification opens, in the `/{hostDocId}/rest`
|
|
45
|
+
* shape every host notification uses — the console rewrites it to
|
|
46
|
+
* `/{orgSlug}/hosts/{subdomain}/rest` when the link is followed, which is
|
|
47
|
+
* why `hostId` and `orgId` travel on the document. The same spelling the
|
|
48
|
+
* CRM's task notification uses; the hub's own route builder lives in the
|
|
49
|
+
* plugin, which this layer cannot import.
|
|
50
|
+
*/ function recordLink(hostId, record) {
|
|
51
|
+
const section = record.kind === 'contact' ? 'contacts' : 'leads';
|
|
52
|
+
return `/${hostId}/crm/${section}/${encodeURIComponent(record.id)}`;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Tells a member a record is now theirs — one console notification, typed
|
|
56
|
+
* by the record it opens — unless the member handed it to themselves.
|
|
57
|
+
* Shared by the pass above and by the routes where a person picks the
|
|
58
|
+
* owner outright (a lead conversion naming a colleague), so every server
|
|
59
|
+
* path that writes `ownerUid` says so in the same words. Never throws;
|
|
60
|
+
* the fan-out swallows its own failures.
|
|
61
|
+
*/ export async function notifyRecordAssigned(input) {
|
|
62
|
+
var _input_actorUid;
|
|
63
|
+
if (!input.ownerUid || input.ownerUid === ((_input_actorUid = input.actorUid) != null ? _input_actorUid : '')) return false;
|
|
64
|
+
const lead = input.record.kind === 'lead';
|
|
65
|
+
/*
|
|
66
|
+
* THE BODY SAYS WHAT HAPPENED, AND ON WHICH SITE (AGL-3432).
|
|
67
|
+
*
|
|
68
|
+
* It was the bare name, so a member who owns records on several sites read
|
|
69
|
+
* "Ada" in an email body and could not tell what Ada was or where. The
|
|
70
|
+
* site's name is one request-cached read of a document most callers have
|
|
71
|
+
* already paid for, taken only when somebody is actually notified; a read
|
|
72
|
+
* that fails drops the "on {site}" clause rather than the notification.
|
|
73
|
+
*/ let site = '';
|
|
74
|
+
try {
|
|
75
|
+
const host = await getHostDocAdmin(input.hostId);
|
|
76
|
+
if (host) site = ` on ${hostDisplayName(host, input.hostId)}`;
|
|
77
|
+
} catch (unused) {
|
|
78
|
+
// The clause goes, never the notification.
|
|
79
|
+
}
|
|
80
|
+
await notifyUsers([
|
|
81
|
+
input.ownerUid
|
|
82
|
+
], {
|
|
83
|
+
type: lead ? 'content.leadAssigned' : 'content.contactAssigned',
|
|
84
|
+
title: lead ? 'Lead assigned to you' : 'Contact assigned to you',
|
|
85
|
+
body: `${input.who} was assigned to you as a ${lead ? 'lead' : 'contact'}${site}.`,
|
|
86
|
+
link: recordLink(input.hostId, input.record),
|
|
87
|
+
orgId: input.orgId,
|
|
88
|
+
hostId: input.hostId
|
|
89
|
+
});
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The roster checks one assignment transaction makes: whether a uid is on the
|
|
94
|
+
* team, and who a target names — a member as named, or the next member of
|
|
95
|
+
* the round-robin pool who is still on the roster. One read per candidate
|
|
96
|
+
* per attempt; a retried transaction builds a fresh one and reads afresh, as
|
|
97
|
+
* it must.
|
|
98
|
+
*/ function rosterResolver(tx, membersRef, settings) {
|
|
99
|
+
const onRoster = new Map();
|
|
100
|
+
const isMember = (uid)=>{
|
|
101
|
+
let known = onRoster.get(uid);
|
|
102
|
+
if (!known) {
|
|
103
|
+
known = tx.get(membersRef.doc(uid)).then((snapshot)=>snapshot.exists);
|
|
104
|
+
onRoster.set(uid, known);
|
|
105
|
+
}
|
|
106
|
+
return known;
|
|
107
|
+
};
|
|
108
|
+
const fromPool = async ()=>{
|
|
109
|
+
for (const uid of roundRobinOrder(settings.pool.memberUids, settings.pool.lastAssignedUid)){
|
|
110
|
+
if (await isMember(uid)) return uid;
|
|
111
|
+
}
|
|
112
|
+
return null;
|
|
113
|
+
};
|
|
114
|
+
const resolveTarget = async (target)=>{
|
|
115
|
+
if ('roundRobin' in target) {
|
|
116
|
+
const uid = await fromPool();
|
|
117
|
+
return uid ? {
|
|
118
|
+
uid,
|
|
119
|
+
advancePointer: true
|
|
120
|
+
} : null;
|
|
121
|
+
}
|
|
122
|
+
return await isMember(target.memberUid) ? {
|
|
123
|
+
uid: target.memberUid,
|
|
124
|
+
advancePointer: false
|
|
125
|
+
} : null;
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
isMember,
|
|
129
|
+
resolveTarget
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
async function assignOwner(policy) {
|
|
133
|
+
const { input } = policy;
|
|
134
|
+
try {
|
|
135
|
+
const resolved = await getOrgForHost(input.hostId);
|
|
136
|
+
if (!resolved) return {
|
|
137
|
+
outcome: 'none',
|
|
138
|
+
reason: 'no-org'
|
|
139
|
+
};
|
|
140
|
+
const { orgId } = resolved;
|
|
141
|
+
const firestore = firebaseAdmin.app().firestore();
|
|
142
|
+
const orgRef = firestore.collection('orgs').doc(orgId);
|
|
143
|
+
const contactRef = orgRef.collection('contacts').doc(input.contactId);
|
|
144
|
+
const membersRef = orgRef.collection('members');
|
|
145
|
+
const leadKey = personKey(input.email);
|
|
146
|
+
// Beside the contact on the org, keyed by the same address (AGL-3275).
|
|
147
|
+
const leadRef = leadKey ? orgRef.collection('leads').doc(leadKey) : null;
|
|
148
|
+
let contactName = '';
|
|
149
|
+
const verdict = await firestore.runTransaction(async (tx)=>{
|
|
150
|
+
var _orgSnapshot_data, _contactSnapshot_data, _contact_name, _ref;
|
|
151
|
+
/*
|
|
152
|
+
* ALL READS BEFORE THE WRITE, which Firestore requires. The org
|
|
153
|
+
* document is read here rather than trusted from `getOrgForHost`,
|
|
154
|
+
* because the pointer it carries is the one thing a concurrent
|
|
155
|
+
* capture may have moved, and the rules and the pool are read from
|
|
156
|
+
* the same snapshot so the decision and the pointer agree.
|
|
157
|
+
*/ const [orgSnapshot, contactSnapshot, leadSnapshot] = await Promise.all([
|
|
158
|
+
tx.get(orgRef),
|
|
159
|
+
tx.get(contactRef),
|
|
160
|
+
leadRef ? tx.get(leadRef) : Promise.resolve(null)
|
|
161
|
+
]);
|
|
162
|
+
if (!contactSnapshot.exists) {
|
|
163
|
+
return {
|
|
164
|
+
outcome: 'none',
|
|
165
|
+
reason: 'no-contact'
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
const org = (_orgSnapshot_data = orgSnapshot.data()) != null ? _orgSnapshot_data : {};
|
|
169
|
+
const contact = (_contactSnapshot_data = contactSnapshot.data()) != null ? _contactSnapshot_data : {};
|
|
170
|
+
contactName = String((_contact_name = contact['name']) != null ? _contact_name : '');
|
|
171
|
+
const group = consentGroupForHost(org, input.hostId);
|
|
172
|
+
const facet = readContactFacet(contact, group.groupId);
|
|
173
|
+
const current = typeof facet.ownerUid === 'string' ? facet.ownerUid : '';
|
|
174
|
+
if (policy.kind === 'capture' && current) {
|
|
175
|
+
return {
|
|
176
|
+
outcome: 'unchanged',
|
|
177
|
+
ownerUid: current
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
const settings = readCrmAssignmentSettings(org);
|
|
181
|
+
const { isMember, resolveTarget } = rosterResolver(tx, membersRef, settings);
|
|
182
|
+
let decision = null;
|
|
183
|
+
let refusal = 'no-rule';
|
|
184
|
+
if (policy.kind === 'capture') {
|
|
185
|
+
var _policy_input_formId, _policy_input_tags, _facet_tags;
|
|
186
|
+
const capture = {
|
|
187
|
+
source: policy.input.source,
|
|
188
|
+
email: input.email,
|
|
189
|
+
formId: (_policy_input_formId = policy.input.formId) != null ? _policy_input_formId : null,
|
|
190
|
+
tags: [
|
|
191
|
+
...(_policy_input_tags = policy.input.tags) != null ? _policy_input_tags : [],
|
|
192
|
+
...(_facet_tags = facet.tags) != null ? _facet_tags : []
|
|
193
|
+
]
|
|
194
|
+
};
|
|
195
|
+
for (const rule of settings.rules){
|
|
196
|
+
if (!assignmentRuleMatches(rule.when, capture)) continue;
|
|
197
|
+
const hit = await resolveTarget(rule.assign);
|
|
198
|
+
if (hit) {
|
|
199
|
+
decision = _extends({}, hit, {
|
|
200
|
+
ownerUid: hit.uid,
|
|
201
|
+
by: 'rule',
|
|
202
|
+
ruleId: rule.id
|
|
203
|
+
});
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const fallback = settings.hostDefaultOwners[input.hostId];
|
|
208
|
+
if (!decision && fallback && await isMember(fallback)) {
|
|
209
|
+
decision = {
|
|
210
|
+
ownerUid: fallback,
|
|
211
|
+
by: 'default',
|
|
212
|
+
advancePointer: false
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
} else {
|
|
216
|
+
const { assign } = policy.input;
|
|
217
|
+
const hit = await resolveTarget(assign);
|
|
218
|
+
if (hit) {
|
|
219
|
+
decision = _extends({}, hit, {
|
|
220
|
+
ownerUid: hit.uid,
|
|
221
|
+
by: 'roundRobin' in assign ? 'roundRobin' : 'member'
|
|
222
|
+
});
|
|
223
|
+
} else {
|
|
224
|
+
refusal = 'roundRobin' in assign ? 'empty-pool' : 'not-a-member';
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (!decision) return {
|
|
228
|
+
outcome: 'none',
|
|
229
|
+
reason: refusal
|
|
230
|
+
};
|
|
231
|
+
if (decision.ownerUid === current) {
|
|
232
|
+
return {
|
|
233
|
+
outcome: 'unchanged',
|
|
234
|
+
ownerUid: current
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
tx.update(contactRef, {
|
|
238
|
+
[contactFacetPath(group.groupId, 'ownerUid')]: decision.ownerUid,
|
|
239
|
+
updatedAt: FieldValue.serverTimestamp()
|
|
240
|
+
});
|
|
241
|
+
if (decision.advancePointer) {
|
|
242
|
+
tx.update(orgRef, {
|
|
243
|
+
[CRM_ROUND_ROBIN_LAST_ASSIGNED_PATH]: decision.ownerUid
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
/*
|
|
247
|
+
* A lead somebody already assigned by hand keeps its owner on a
|
|
248
|
+
* capture — the contact was new, the lead may not have been — and
|
|
249
|
+
* follows the contact on a deliberate reassignment.
|
|
250
|
+
*/ const leadOwner = String((_ref = leadSnapshot == null ? void 0 : leadSnapshot.get('ownerUid')) != null ? _ref : '');
|
|
251
|
+
const leadMirrored = Boolean((leadSnapshot == null ? void 0 : leadSnapshot.exists) && (policy.kind === 'reassign' || !leadOwner));
|
|
252
|
+
if (leadMirrored && leadRef) {
|
|
253
|
+
tx.update(leadRef, {
|
|
254
|
+
ownerUid: decision.ownerUid,
|
|
255
|
+
updatedAt: FieldValue.serverTimestamp()
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
return _extends({
|
|
259
|
+
outcome: 'assigned',
|
|
260
|
+
ownerUid: decision.ownerUid,
|
|
261
|
+
by: decision.by
|
|
262
|
+
}, decision.ruleId ? {
|
|
263
|
+
ruleId: decision.ruleId
|
|
264
|
+
} : {}, {
|
|
265
|
+
leadMirrored,
|
|
266
|
+
notified: false
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
if (verdict.outcome !== 'assigned') return verdict;
|
|
270
|
+
// The owner is what the Contacts list filters by (AGL-3321).
|
|
271
|
+
await restampCrmListFieldsAt(contactRef, 'contacts');
|
|
272
|
+
if (!verdict.leadMirrored && leadRef && policy.kind === 'capture' && LEAD_FILING_SOURCES.has(policy.input.source)) {
|
|
273
|
+
void mirrorOwnerOntoLeadLater(leadRef, verdict.ownerUid);
|
|
274
|
+
}
|
|
275
|
+
const notified = await notifyRecordAssigned({
|
|
276
|
+
hostId: input.hostId,
|
|
277
|
+
orgId,
|
|
278
|
+
ownerUid: verdict.ownerUid,
|
|
279
|
+
actorUid: input.actorUid,
|
|
280
|
+
record: verdict.leadMirrored && leadKey ? {
|
|
281
|
+
kind: 'lead',
|
|
282
|
+
id: leadKey
|
|
283
|
+
} : {
|
|
284
|
+
kind: 'contact',
|
|
285
|
+
id: input.contactId
|
|
286
|
+
},
|
|
287
|
+
who: contactName || input.email
|
|
288
|
+
});
|
|
289
|
+
return _extends({}, verdict, {
|
|
290
|
+
notified
|
|
291
|
+
});
|
|
292
|
+
} catch (error) {
|
|
293
|
+
console.error('assignContactOwner failed', input.hostId, input.contactId, error);
|
|
294
|
+
return {
|
|
295
|
+
outcome: 'none',
|
|
296
|
+
reason: 'failed'
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* The detached second look for a lead that lands after the contact.
|
|
302
|
+
*
|
|
303
|
+
* Bounded, and only ever ADDS an owner: a lead that arrived with one (a
|
|
304
|
+
* person assigned it in the meantime) is left alone, and a lead that never
|
|
305
|
+
* arrives costs three reads over six seconds and nothing else. Detached
|
|
306
|
+
* because the capture must not hold `contactCreated` back for it — an
|
|
307
|
+
* automation welcoming the contact has nothing to do with the lead's owner
|
|
308
|
+
* column.
|
|
309
|
+
*/ async function mirrorOwnerOntoLeadLater(leadRef, ownerUid, delaysMs = LEAD_MIRROR_RETRY_MS) {
|
|
310
|
+
for (const delay of delaysMs){
|
|
311
|
+
await new Promise((resolve)=>setTimeout(resolve, delay));
|
|
312
|
+
try {
|
|
313
|
+
var _lead_get;
|
|
314
|
+
const lead = await leadRef.get();
|
|
315
|
+
if (!lead.exists) continue;
|
|
316
|
+
if (String((_lead_get = lead.get('ownerUid')) != null ? _lead_get : '')) return false;
|
|
317
|
+
await leadRef.update({
|
|
318
|
+
ownerUid,
|
|
319
|
+
updatedAt: FieldValue.serverTimestamp()
|
|
320
|
+
});
|
|
321
|
+
return true;
|
|
322
|
+
} catch (error) {
|
|
323
|
+
console.error('assignContactOwner lead mirror failed', leadRef.path, error);
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* The capture door's pass: the org's rules in order, then the capturing
|
|
331
|
+
* site's default owner, on a record that has no owner yet. See the module
|
|
332
|
+
* comment for the whole of it.
|
|
333
|
+
*/ export function assignOwnerForCapture(input) {
|
|
334
|
+
return assignOwner({
|
|
335
|
+
kind: 'capture',
|
|
336
|
+
input
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* The deliberate assignment — the `assignContactOwner` step, and a person
|
|
341
|
+
* handing a record to somebody: a member by uid (verified on the roster) or
|
|
342
|
+
* the next in the round-robin pool, overwriting whoever held it. Naming the
|
|
343
|
+
* owner the record already has changes nothing and tells nobody.
|
|
344
|
+
*/ export function reassignContactOwner(input) {
|
|
345
|
+
return assignOwner({
|
|
346
|
+
kind: 'reassign',
|
|
347
|
+
input
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* {@link reassignContactOwner} for a person who is still a LEAD (AGL-3458).
|
|
352
|
+
*
|
|
353
|
+
* A lead-routed form files a lead and no contact (AGL-3232), so an
|
|
354
|
+
* automation welcoming that person — "assign an owner, then book them a
|
|
355
|
+
* call" — has only the lead to act on. The owner is the lead's own
|
|
356
|
+
* `ownerUid`, the field the Leads list's Owner column and filter read and a
|
|
357
|
+
* conversion hands to the contact. Same transaction shape as a contact's:
|
|
358
|
+
* the org document, the lead and every roster candidate are read inside it,
|
|
359
|
+
* and the round-robin pointer moves in the commit that writes the owner, so
|
|
360
|
+
* a lead and a contact assigned at the same moment take two different
|
|
361
|
+
* members of the one rotation.
|
|
362
|
+
*
|
|
363
|
+
* Never rejects; a failure is logged and answered as `none`, which the
|
|
364
|
+
* automation records as the step's error.
|
|
365
|
+
*/ export async function reassignLeadOwner(input) {
|
|
366
|
+
try {
|
|
367
|
+
const resolved = await getOrgForHost(input.hostId);
|
|
368
|
+
if (!resolved) return {
|
|
369
|
+
outcome: 'none',
|
|
370
|
+
reason: 'no-org'
|
|
371
|
+
};
|
|
372
|
+
const { orgId } = resolved;
|
|
373
|
+
const firestore = firebaseAdmin.app().firestore();
|
|
374
|
+
const orgRef = firestore.collection('orgs').doc(orgId);
|
|
375
|
+
const leadRef = orgRef.collection('leads').doc(input.leadId);
|
|
376
|
+
const membersRef = orgRef.collection('members');
|
|
377
|
+
let who = '';
|
|
378
|
+
const verdict = await firestore.runTransaction(async (tx)=>{
|
|
379
|
+
var _leadSnapshot_data, _lead_name, _lead_email, _lead_ownerUid, _orgSnapshot_data;
|
|
380
|
+
const [orgSnapshot, leadSnapshot] = await Promise.all([
|
|
381
|
+
tx.get(orgRef),
|
|
382
|
+
tx.get(leadRef)
|
|
383
|
+
]);
|
|
384
|
+
if (!leadSnapshot.exists) return {
|
|
385
|
+
outcome: 'none',
|
|
386
|
+
reason: 'no-lead'
|
|
387
|
+
};
|
|
388
|
+
const lead = (_leadSnapshot_data = leadSnapshot.data()) != null ? _leadSnapshot_data : {};
|
|
389
|
+
who = String((_lead_name = lead['name']) != null ? _lead_name : '') || String((_lead_email = lead['email']) != null ? _lead_email : '');
|
|
390
|
+
const current = String((_lead_ownerUid = lead['ownerUid']) != null ? _lead_ownerUid : '');
|
|
391
|
+
const settings = readCrmAssignmentSettings((_orgSnapshot_data = orgSnapshot.data()) != null ? _orgSnapshot_data : {});
|
|
392
|
+
const { resolveTarget } = rosterResolver(tx, membersRef, settings);
|
|
393
|
+
const hit = await resolveTarget(input.assign);
|
|
394
|
+
if (!hit) {
|
|
395
|
+
return {
|
|
396
|
+
outcome: 'none',
|
|
397
|
+
reason: 'roundRobin' in input.assign ? 'empty-pool' : 'not-a-member'
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
if (hit.uid === current) return {
|
|
401
|
+
outcome: 'unchanged',
|
|
402
|
+
ownerUid: current
|
|
403
|
+
};
|
|
404
|
+
tx.update(leadRef, {
|
|
405
|
+
ownerUid: hit.uid,
|
|
406
|
+
updatedAt: FieldValue.serverTimestamp()
|
|
407
|
+
});
|
|
408
|
+
if (hit.advancePointer) {
|
|
409
|
+
tx.update(orgRef, {
|
|
410
|
+
[CRM_ROUND_ROBIN_LAST_ASSIGNED_PATH]: hit.uid
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
return {
|
|
414
|
+
outcome: 'assigned',
|
|
415
|
+
ownerUid: hit.uid,
|
|
416
|
+
by: 'roundRobin' in input.assign ? 'roundRobin' : 'member',
|
|
417
|
+
leadMirrored: false,
|
|
418
|
+
notified: false
|
|
419
|
+
};
|
|
420
|
+
});
|
|
421
|
+
if (verdict.outcome !== 'assigned') return verdict;
|
|
422
|
+
const notified = await notifyRecordAssigned({
|
|
423
|
+
hostId: input.hostId,
|
|
424
|
+
orgId,
|
|
425
|
+
ownerUid: verdict.ownerUid,
|
|
426
|
+
actorUid: input.actorUid,
|
|
427
|
+
record: {
|
|
428
|
+
kind: 'lead',
|
|
429
|
+
id: input.leadId
|
|
430
|
+
},
|
|
431
|
+
who
|
|
432
|
+
});
|
|
433
|
+
return _extends({}, verdict, {
|
|
434
|
+
notified
|
|
435
|
+
});
|
|
436
|
+
} catch (error) {
|
|
437
|
+
console.error('assignLeadOwner failed', input.hostId, input.leadId, error);
|
|
438
|
+
return {
|
|
439
|
+
outcome: 'none',
|
|
440
|
+
reason: 'failed'
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
export default assignOwnerForCapture;
|
|
445
|
+
|
|
446
|
+
//# sourceMappingURL=assign-contact-owner.js.map
|