@aglyn/plugins-crm 1.18.0 → 1.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +14 -14
- package/src/lib/components/log-activity-dialog.d.ts +2 -0
- package/src/lib/components/log-activity-dialog.js +11 -2
- package/src/lib/components/log-activity-dialog.js.map +1 -1
- package/src/lib/components/record-sharing-card.js +8 -7
- package/src/lib/components/record-sharing-card.js.map +1 -1
- package/src/lib/components/settings-section.d.ts +10 -3
- package/src/lib/components/settings-section.js +286 -35
- package/src/lib/components/settings-section.js.map +1 -1
- package/src/lib/components/share-records-dialog.d.ts +17 -3
- package/src/lib/components/share-records-dialog.js +59 -45
- package/src/lib/components/share-records-dialog.js.map +1 -1
- package/src/lib/components/sharing-rule-drawer.d.ts +13 -3
- package/src/lib/components/sharing-rule-drawer.js +51 -40
- package/src/lib/components/sharing-rule-drawer.js.map +1 -1
- package/src/lib/components/sharing-rules-card.js +2 -1
- package/src/lib/components/sharing-rules-card.js.map +1 -1
- package/src/lib/declarations.server.js +10 -1
- package/src/lib/declarations.server.js.map +1 -1
- package/src/lib/hooks/use-campaign-filing-log.js +10 -2
- package/src/lib/hooks/use-campaign-filing-log.js.map +1 -1
- package/src/lib/hooks/use-crm-sharing.d.ts +8 -0
- package/src/lib/hooks/use-crm-sharing.js +20 -0
- package/src/lib/hooks/use-crm-sharing.js.map +1 -1
- package/src/lib/model/crm-sharing-api.d.ts +5 -2
- package/src/lib/model/crm-sharing-api.js +3 -0
- package/src/lib/model/crm-sharing-api.js.map +1 -1
- package/src/lib/model/crm-sharing.d.ts +153 -5
- package/src/lib/model/crm-sharing.js +243 -20
- package/src/lib/model/crm-sharing.js.map +1 -1
- package/src/lib/model/lead-filters.d.ts +1 -1
- package/src/lib/server/add-contact-by-hand.js +11 -4
- package/src/lib/server/add-contact-by-hand.js.map +1 -1
- package/src/lib/server/api-v1/crm-activities.js +2 -2
- package/src/lib/server/api-v1/crm-activities.js.map +1 -1
- package/src/lib/server/api-v1/crm-companies.js +2 -2
- package/src/lib/server/api-v1/crm-companies.js.map +1 -1
- package/src/lib/server/api-v1/crm-deals.js +2 -2
- package/src/lib/server/api-v1/crm-deals.js.map +1 -1
- package/src/lib/server/api-v1/crm-shared.d.ts +16 -0
- package/src/lib/server/api-v1/crm-shared.js +12 -1
- package/src/lib/server/api-v1/crm-shared.js.map +1 -1
- package/src/lib/server/api-v1/crm-tasks.js +2 -2
- package/src/lib/server/api-v1/crm-tasks.js.map +1 -1
- package/src/lib/server/associate-company-by-domain.d.ts +1 -1
- package/src/lib/server/associate-company-by-domain.js +4 -4
- package/src/lib/server/associate-company-by-domain.js.map +1 -1
- package/src/lib/server/automation-steps.js +24 -12
- package/src/lib/server/automation-steps.js.map +1 -1
- package/src/lib/server/campaign-filing-activity.js +7 -3
- package/src/lib/server/campaign-filing-activity.js.map +1 -1
- package/src/lib/server/convert-host-lead.js +13 -4
- package/src/lib/server/convert-host-lead.js.map +1 -1
- package/src/lib/server/crm-default-sharing.d.ts +86 -0
- package/src/lib/server/crm-default-sharing.js +409 -0
- package/src/lib/server/crm-default-sharing.js.map +1 -0
- package/src/lib/server/crm-inbound-email.js +2 -2
- package/src/lib/server/crm-inbound-email.js.map +1 -1
- package/src/lib/server/crm-sharing-runs.d.ts +71 -0
- package/src/lib/server/crm-sharing-runs.js +221 -0
- package/src/lib/server/crm-sharing-runs.js.map +1 -0
- package/src/lib/server/crm-sharing.d.ts +24 -1
- package/src/lib/server/crm-sharing.js +183 -31
- package/src/lib/server/crm-sharing.js.map +1 -1
- package/src/lib/server/email-send.js +5 -2
- package/src/lib/server/email-send.js.map +1 -1
- package/src/lib/server/record-timeline.d.ts +2 -1
- package/src/lib/server/record-timeline.js +11 -6
- package/src/lib/server/record-timeline.js.map +1 -1
- package/src/lib/server/task-routes.js +10 -6
- package/src/lib/server/task-routes.js.map +1 -1
- package/src/lib/server.js +23 -1
- package/src/lib/server.js.map +1 -1
- package/src/lib/transfer/common.d.ts +5 -1
- package/src/lib/transfer/common.js +8 -5
- package/src/lib/transfer/common.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/plugins/crm/src/lib/declarations.server.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// The contract from its own module, not the plugin-manager barrel: boot needs\n// the registry and nothing else, and the barrel reaches the client contexts.\nimport { registerPluginConsentGroupParticipant } from '@aglyn/aglyn/plugin-manager/plugin-consent-group-change'\nimport {\n registerPluginContactCaptureWriter,\n type PluginContactCaptureWriter,\n} from '@aglyn/aglyn/plugin-manager/plugin-contact-capture'\nimport { registerPluginLeadConversionListener } from '@aglyn/aglyn/plugin-manager/plugin-lead-conversion'\nimport { registerPluginPersonMatcher } from '@aglyn/aglyn/plugin-manager/plugin-person-matches'\nimport {\n registerPluginPersonRecords,\n type PluginPersonRecords,\n} from '@aglyn/aglyn/plugin-manager/plugin-person-records'\nimport {\n registerPluginRecordIndex,\n type PluginRecordIndex,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-index'\nimport { registerPluginRecordEmailStateWriter } from '@aglyn/aglyn/plugin-manager/plugin-record-email-state'\nimport { registerPluginRecordOriginWriter } from '@aglyn/aglyn/plugin-manager/plugin-record-origin'\nimport {\n registerPluginRecordTimelineWriter,\n type PluginRecordTimelineWriter,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-timeline'\nimport { registerPluginRecordWrittenListener } from '@aglyn/aglyn/plugin-manager/plugin-record-written'\nimport { registerPluginScopeSharingPatch } from '@aglyn/aglyn/plugin-manager/plugin-scope-sharing'\nimport { registerServerStepExecutor } from '@aglyn/aglyn/plugin-manager/plugin-server-steps'\nimport { registerPluginUsageMeter } from '@aglyn/aglyn/plugin-manager/plugin-usage-meters'\nimport { BUNDLE_ID, CRM_RECORDS_METER_ID, CRM_STEP_TYPES } from './constants/bundle-common'\nimport { summarizeConsentGroupChange } from './model/consent-group-summary'\n\n/**\n * The CRM as the plugin that keeps people.\n *\n * Light by construction, the way the workflows listener is: the capture\n * itself is imported when the first one arrives, not when the process\n * starts, so a process that never captures anybody pays for this object and\n * nothing else. That matters because this registers in EVERY server process,\n * including ones that will never touch the CRM.\n */\nexport const crmContactCaptureWriter: PluginContactCaptureWriter = {\n async capture(request) {\n const { captureContactForCrm } = await import('./server/capture-contact')\n return await captureContactForCrm(request)\n },\n}\n\n/**\n * The CRM as the plugin other plugins ask for people (AGL-3080), deferred\n * like the capture: `server/person-records.ts` and the Admin SDK it brings\n * load with the first question, not when the process starts.\n */\nexport const crmPersonRecordsService: PluginPersonRecords = {\n async find(request) {\n const { crmPersonRecords } = await import('./server/person-records')\n return crmPersonRecords.find(request)\n },\n async read(request) {\n const { crmPersonRecords } = await import('./server/person-records')\n return crmPersonRecords.read(request)\n },\n async fileUnder(request) {\n const { crmPersonRecords } = await import('./server/person-records')\n return crmPersonRecords.fileUnder(request)\n },\n async recordRefund(request) {\n const { crmPersonRecords } = await import('./server/person-records')\n return crmPersonRecords.recordRefund(request)\n },\n async peopleInView(request) {\n const { crmPersonRecords } = await import('./server/person-records')\n return crmPersonRecords.peopleInView(request)\n },\n async wroteIn(request) {\n const { crmPersonRecords } = await import('./server/person-records')\n return crmPersonRecords.wroteIn(request)\n },\n async search(request) {\n const { crmPersonRecords } = await import('./server/person-records')\n return crmPersonRecords.search(request)\n },\n // The walk a connector copies a site's people out by (AGL-3639).\n async changedSince(request) {\n const { crmPersonRecords } = await import('./server/person-records')\n return crmPersonRecords.changedSince(request)\n },\n}\n\n/**\n * The `pipeline` record index, its reads loaded with the first one — see\n * `server/pipeline-record-index.ts` for what it answers.\n */\nexport const crmPipelineRecordIndex: PluginRecordIndex = {\n async list(request) {\n const { pipelineRecordIndex } = await import('./server/pipeline-record-index')\n return pipelineRecordIndex.list(request)\n },\n async get(request) {\n const { pipelineRecordIndex } = await import('./server/pipeline-record-index')\n return pipelineRecordIndex.get(request)\n },\n}\n\n/** One of `server/crm-record-indexes.ts`'s indexes, its reads loaded with the first one. */\nfunction lazyCrmRecordIndex(kind: 'company' | 'messageTemplate'): PluginRecordIndex {\n return {\n async list(request) {\n const { crmRecordIndexes } = await import('./server/crm-record-indexes')\n return crmRecordIndexes()[kind].list(request)\n },\n async get(request) {\n const { crmRecordIndexes } = await import('./server/crm-record-indexes')\n return crmRecordIndexes()[kind].get(request)\n },\n }\n}\n\n/** The companies a person works for, as another plugin reads them (AGL-3080). */\nexport const crmCompanyRecordIndex = lazyCrmRecordIndex('company')\n\n/** The email templates and snippets reps write, as another plugin reads them (AGL-3080). */\nexport const crmMessageTemplateRecordIndex = lazyCrmRecordIndex('messageTemplate')\n\n/**\n * The CRM's writer on the record-timeline seam (AGL-2981), deferred: the\n * writer and the Admin SDK it brings load with the first entry filed.\n */\nexport const crmRecordTimelineWriter: PluginRecordTimelineWriter = {\n async logActivity(request) {\n const { createCrmRecordTimelineWriter, defaultCrmRecordTimelineDeps } =\n await import('./server/record-timeline')\n return createCrmRecordTimelineWriter(defaultCrmRecordTimelineDeps()).logActivity(request)\n },\n async createTask(request) {\n const { createCrmRecordTimelineWriter, defaultCrmRecordTimelineDeps } =\n await import('./server/record-timeline')\n return createCrmRecordTimelineWriter(defaultCrmRecordTimelineDeps()).createTask(request)\n },\n async recordEmailDelivery(request) {\n const { createCrmRecordTimelineWriter, defaultCrmRecordTimelineDeps } =\n await import('./server/record-timeline')\n return createCrmRecordTimelineWriter(defaultCrmRecordTimelineDeps()).recordEmailDelivery!(request)\n },\n // A delivery event for a message the CRM tagged (AGL-2615, AGL-3080).\n async recordTaggedDelivery(request) {\n const { createCrmRecordTimelineWriter, defaultCrmRecordTimelineDeps } =\n await import('./server/record-timeline')\n return createCrmRecordTimelineWriter(defaultCrmRecordTimelineDeps()).recordTaggedDelivery!(request)\n },\n // An automation's email to the person its event is about, filed on that\n // person's timeline with its delivery state (AGL-2615, AGL-3080).\n async prepareEmail(request) {\n const { prepareCrmRecordEmail } = await import('./server/automation-steps')\n return prepareCrmRecordEmail(request)\n },\n}\n\n/**\n * The plugin's SERVER declarations: what the server must know at boot, before\n * any door of the CRM has been called.\n *\n * ## Why a declaration and not a `tenantApi` registration\n *\n * The doors that meet a person mostly never load this plugin. A form\n * submission is a core route; an order and a booking are captured inside\n * STRIPE WEBHOOKS. None of them has a reason to load the CRM, and a registry\n * filled by a surface that did not load answers `null` — which\n * `capturePluginContact` defines as \"this workspace has no record system\", a\n * sentence that would be false and silent. Orders would stop creating\n * contacts with nothing red anywhere, which is the AGL-3025 shape.\n *\n * Running from both apps' generated server-declarations manifest at boot is\n * what makes the answer true in every process. It is also called from the\n * plugin's own API register functions, so a process whose boot did not run it\n * still registers the writer the first time a CRM door loads. Registering\n * twice replaces in place.\n *\n * ⚠️ The registry holds ONE writer: a workspace keeps one set of people. A\n * second plugin's is refused naming both, and the incumbent keeps serving.\n */\nexport function registerCrmServerDeclarations(): void {\n registerPluginContactCaptureWriter(crmContactCaptureWriter, {\n pluginId: BUNDLE_ID,\n })\n // The other half of keeping people (AGL-3080): another plugin that holds\n // an address, or a record the CRM handed it, asks here for the person —\n // a flow email's consent read, a refund, an automation filing somebody\n // under a campaign — and never opens the CRM's collections itself.\n registerPluginPersonRecords(crmPersonRecordsService, { pluginId: BUNDLE_ID })\n // A record's scoped list fields follow its sites, so the sweep that keeps\n // \"all sites except\" current restamps them in the same write (AGL-4047).\n // Deferred like the capture.\n registerPluginScopeSharingPatch(\n ['contacts', 'leads', 'companies', 'deals', 'crmTasks'],\n async (collection, next) => {\n const { crmScopeSharingPatch } = await import('./server/scope-sharing-patch')\n return crmScopeSharingPatch(collection, next)\n },\n { pluginId: BUNDLE_ID },\n )\n // The CRM's own share of a lead conversion (AGL-3254): the lead's\n // campaigns go onto the contact's facet. Through the seam every door\n // that converts a lead reaches, and deferred like the capture: the\n // module that writes is loaded when the first conversion arrives, and\n // it brings the Admin SDK with it — this file defers the plugin's OWN\n // module only. A library imported statically across the plugin cannot\n // also be lazy-loaded here: `enforce-module-boundaries` refuses every\n // static import of a library the project lazy-loads anywhere.\n registerPluginLeadConversionListener(\n async (request) => {\n const { carryLeadCampaignsOnConversion } =\n await import('./server/lead-campaign-carry')\n return carryLeadCampaignsOnConversion(request)\n },\n { pluginId: BUNDLE_ID },\n )\n // \"Did this workspace already know this person?\" (AGL-3289), asked by the\n // staff console's acquisition card. Deferred like the rest: the reads load\n // when a staff member first opens a card, not when the process starts.\n registerPluginPersonMatcher(\n async (request) => {\n const { matchCrmPeople } = await import('./server/person-matches')\n return matchCrmPeople(request)\n },\n { pluginId: BUNDLE_ID },\n )\n // The CRM's share of a consent group change (AGL-3320): a contact's\n // per-site refusal carried across a separation, and the records keyed by a\n // group re-homed after the flip. Registered whether or not a workspace has\n // the CRM switched on, because the contacts — and the refusals on them —\n // outlive the switch. Deferred like the rest; the summary is plain words\n // and answers synchronously.\n // The record email-state writer (AGL-3245), here as well as in the console\n // API so the tenant's doors reach it too: a form submission's capture is\n // checked for deliverability after its response (AGL-3328), and the \"Would\n // bounce\" that check finds is written through this seam. Deferred like the\n // rest; the console's own registration replaces this one with the same\n // writer, loaded eagerly.\n registerPluginRecordEmailStateWriter(\n {\n async stamp(request) {\n const { createCrmRecordEmailStateWriter, defaultCrmRecordEmailStateDeps } =\n await import('./server/record-email-state')\n return createCrmRecordEmailStateWriter(defaultCrmRecordEmailStateDeps()).stamp(request)\n },\n // A send's first opens and clicks, stamped on the contacts they name\n // (AGL-2616) — the campaign webhook's courtesy, deferred like the rest.\n async engaged(request) {\n const { createCrmRecordEmailStateWriter, defaultCrmRecordEmailStateDeps } =\n await import('./server/record-email-state')\n return createCrmRecordEmailStateWriter(defaultCrmRecordEmailStateDeps()).engaged!(request)\n },\n // A delivered campaign's leads, moved to Nurturing (AGL-3446).\n async reached(request) {\n const { createCrmRecordEmailStateWriter, defaultCrmRecordEmailStateDeps } =\n await import('./server/record-email-state')\n return createCrmRecordEmailStateWriter(defaultCrmRecordEmailStateDeps()).reached!(request)\n },\n // A lead that wrote back, moved to Working (AGL-3080).\n async replied(request) {\n const { createCrmRecordEmailStateWriter, defaultCrmRecordEmailStateDeps } =\n await import('./server/record-email-state')\n return createCrmRecordEmailStateWriter(defaultCrmRecordEmailStateDeps()).replied!(request)\n },\n },\n { pluginId: BUNDLE_ID },\n )\n // The record timeline writer (AGL-2981), here as well as in the API\n // surfaces so a door in either app reaches it: a booking confirmed on the\n // tenant, or by the payment webhook, files its meeting and follow-up\n // through it (AGL-2660). Deferred like the rest; an API registration\n // replaces this one with the same writer, loaded eagerly.\n registerPluginRecordTimelineWriter(crmRecordTimelineWriter, { pluginId: BUNDLE_ID })\n // Where a person came from (AGL-3519): a door the CRM does not run — the\n // platform's account sign-up, a sequence enrolling someone — names its\n // origin, and the CRM stamps the built-in Lead source on a record holding\n // none. Deferred like the rest.\n registerPluginRecordOriginWriter(\n {\n async stamp(request) {\n const { crmRecordOriginWriter } = await import('./server/record-origin')\n return crmRecordOriginWriter.stamp(request)\n },\n },\n { pluginId: BUNDLE_ID },\n )\n // Sharing rules (AGL-3336), re-evaluated after every server write of a\n // lead, a contact, a company or a deal: the core tells its record-written\n // listeners from the list-field restamp every such writer ends with, in\n // both apps — a form's capture on the tenant, an edit in the console.\n // Deferred like the rest: an org with no rules pays one cached read.\n registerPluginRecordWrittenListener(\n async (event) => {\n const { crmSharingRecordWritten } = await import('./server/crm-sharing')\n await crmSharingRecordWritten(event)\n },\n { pluginId: BUNDLE_ID, key: 'sharing' },\n )\n // The organization's pipelines and their stages, as another plugin reads\n // them (AGL-3080): an automation the AI drafts names the stage a deal\n // moves to. Deferred like the rest: the reads load with the first one.\n registerPluginRecordIndex('pipeline', crmPipelineRecordIndex, { pluginId: BUNDLE_ID })\n // The company a person works for, and the templates reps write, as a sales\n // sequence reads them (AGL-3080). Deferred like the rest.\n registerPluginRecordIndex('company', crmCompanyRecordIndex, { pluginId: BUNDLE_ID })\n registerPluginRecordIndex('messageTemplate', crmMessageTemplateRecordIndex, { pluginId: BUNDLE_ID })\n // The automation steps that write the CRM (AGL-2605, AGL-3080), run for the\n // workflows engine through the server-step seam and declared under\n // `serverSteps`. Deferred like the rest: the writes load with the first step.\n registerServerStepExecutor(\n CRM_STEP_TYPES,\n async (request) => (await import('./server/automation-steps')).runCrmAutomationStep(request),\n { pluginId: BUNDLE_ID },\n )\n registerPluginConsentGroupParticipant(\n {\n async preview(request) {\n const { consentGroupParticipant } = await import('./server/consent-group-participant')\n return consentGroupParticipant.preview(request)\n },\n async run(request) {\n const { consentGroupParticipant } = await import('./server/consent-group-participant')\n return consentGroupParticipant.run(request)\n },\n summarize: summarizeConsentGroupChange,\n },\n { pluginId: BUNDLE_ID },\n )\n // The records band in the monthly usage sweep, a core cron that never\n // loads a CRM door; declared in `usageAxes` so the sweep refuses to bill a\n // month without it. Deferred like the rest: the counts load with the\n // first sweep.\n registerPluginUsageMeter({\n pluginId: BUNDLE_ID,\n id: CRM_RECORDS_METER_ID,\n measure: async (context) => {\n const { measureCrmRecords } = await import('./server/crm-records-meter')\n return measureCrmRecords(context)\n },\n })\n}\n\n"],"names":["registerPluginConsentGroupParticipant","registerPluginContactCaptureWriter","registerPluginLeadConversionListener","registerPluginPersonMatcher","registerPluginPersonRecords","registerPluginRecordIndex","registerPluginRecordEmailStateWriter","registerPluginRecordOriginWriter","registerPluginRecordTimelineWriter","registerPluginRecordWrittenListener","registerPluginScopeSharingPatch","registerServerStepExecutor","registerPluginUsageMeter","BUNDLE_ID","CRM_RECORDS_METER_ID","CRM_STEP_TYPES","summarizeConsentGroupChange","crmContactCaptureWriter","capture","request","captureContactForCrm","crmPersonRecordsService","find","crmPersonRecords","read","fileUnder","recordRefund","peopleInView","wroteIn","search","changedSince","crmPipelineRecordIndex","list","pipelineRecordIndex","get","lazyCrmRecordIndex","kind","crmRecordIndexes","crmCompanyRecordIndex","crmMessageTemplateRecordIndex","crmRecordTimelineWriter","logActivity","createCrmRecordTimelineWriter","defaultCrmRecordTimelineDeps","createTask","recordEmailDelivery","recordTaggedDelivery","prepareEmail","prepareCrmRecordEmail","registerCrmServerDeclarations","pluginId","collection","next","crmScopeSharingPatch","carryLeadCampaignsOnConversion","matchCrmPeople","stamp","createCrmRecordEmailStateWriter","defaultCrmRecordEmailStateDeps","engaged","reached","replied","crmRecordOriginWriter","event","crmSharingRecordWritten","key","runCrmAutomationStep","preview","consentGroupParticipant","run","summarize","id","measure","context","measureCrmRecords"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,8EAA8E;AAC9E,6EAA6E;AAC7E,SAASA,qCAAqC,QAAQ,0DAAyD;AAC/G,SACEC,kCAAkC,QAE7B,qDAAoD;AAC3D,SAASC,oCAAoC,QAAQ,qDAAoD;AACzG,SAASC,2BAA2B,QAAQ,oDAAmD;AAC/F,SACEC,2BAA2B,QAEtB,oDAAmD;AAC1D,SACEC,yBAAyB,QAEpB,kDAAiD;AACxD,SAASC,oCAAoC,QAAQ,wDAAuD;AAC5G,SAASC,gCAAgC,QAAQ,mDAAkD;AACnG,SACEC,kCAAkC,QAE7B,qDAAoD;AAC3D,SAASC,mCAAmC,QAAQ,oDAAmD;AACvG,SAASC,+BAA+B,QAAQ,mDAAkD;AAClG,SAASC,0BAA0B,QAAQ,kDAAiD;AAC5F,SAASC,wBAAwB,QAAQ,kDAAiD;AAC1F,SAASC,SAAS,EAAEC,oBAAoB,EAAEC,cAAc,QAAQ,+BAA2B;AAC3F,SAASC,2BAA2B,QAAQ,mCAA+B;AAE3E;;;;;;;;CAQC,GACD,OAAO,MAAMC,0BAAsD;IACjE,MAAMC,SAAQC,OAAO;QACnB,MA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ations.server.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// The contract from its own module, not the plugin-manager barrel: boot needs\n// the registry and nothing else, and the barrel reaches the client contexts.\nimport { registerPluginConsentGroupParticipant } from '@aglyn/aglyn/plugin-manager/plugin-consent-group-change'\nimport {\n registerPluginContactCaptureWriter,\n type PluginContactCaptureWriter,\n} from '@aglyn/aglyn/plugin-manager/plugin-contact-capture'\nimport { registerPluginLeadConversionListener } from '@aglyn/aglyn/plugin-manager/plugin-lead-conversion'\nimport { registerPluginPersonMatcher } from '@aglyn/aglyn/plugin-manager/plugin-person-matches'\nimport {\n registerPluginPersonRecords,\n type PluginPersonRecords,\n} from '@aglyn/aglyn/plugin-manager/plugin-person-records'\nimport {\n registerPluginRecordIndex,\n type PluginRecordIndex,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-index'\nimport { registerPluginRecordEmailStateWriter } from '@aglyn/aglyn/plugin-manager/plugin-record-email-state'\nimport { registerPluginRecordOriginWriter } from '@aglyn/aglyn/plugin-manager/plugin-record-origin'\nimport {\n registerPluginRecordTimelineWriter,\n type PluginRecordTimelineWriter,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-timeline'\nimport { registerPluginRecordWrittenListener } from '@aglyn/aglyn/plugin-manager/plugin-record-written'\nimport {\n registerPluginScopeSharingPatch,\n registerPluginScopeSharingSiteChange,\n} from '@aglyn/aglyn/plugin-manager/plugin-scope-sharing'\nimport { registerServerStepExecutor } from '@aglyn/aglyn/plugin-manager/plugin-server-steps'\nimport { registerPluginUsageMeter } from '@aglyn/aglyn/plugin-manager/plugin-usage-meters'\nimport { BUNDLE_ID, CRM_RECORDS_METER_ID, CRM_STEP_TYPES } from './constants/bundle-common'\nimport { summarizeConsentGroupChange } from './model/consent-group-summary'\n\n/**\n * The CRM as the plugin that keeps people.\n *\n * Light by construction, the way the workflows listener is: the capture\n * itself is imported when the first one arrives, not when the process\n * starts, so a process that never captures anybody pays for this object and\n * nothing else. That matters because this registers in EVERY server process,\n * including ones that will never touch the CRM.\n */\nexport const crmContactCaptureWriter: PluginContactCaptureWriter = {\n async capture(request) {\n const { captureContactForCrm } = await import('./server/capture-contact')\n return await captureContactForCrm(request)\n },\n}\n\n/**\n * The CRM as the plugin other plugins ask for people (AGL-3080), deferred\n * like the capture: `server/person-records.ts` and the Admin SDK it brings\n * load with the first question, not when the process starts.\n */\nexport const crmPersonRecordsService: PluginPersonRecords = {\n async find(request) {\n const { crmPersonRecords } = await import('./server/person-records')\n return crmPersonRecords.find(request)\n },\n async read(request) {\n const { crmPersonRecords } = await import('./server/person-records')\n return crmPersonRecords.read(request)\n },\n async fileUnder(request) {\n const { crmPersonRecords } = await import('./server/person-records')\n return crmPersonRecords.fileUnder(request)\n },\n async recordRefund(request) {\n const { crmPersonRecords } = await import('./server/person-records')\n return crmPersonRecords.recordRefund(request)\n },\n async peopleInView(request) {\n const { crmPersonRecords } = await import('./server/person-records')\n return crmPersonRecords.peopleInView(request)\n },\n async wroteIn(request) {\n const { crmPersonRecords } = await import('./server/person-records')\n return crmPersonRecords.wroteIn(request)\n },\n async search(request) {\n const { crmPersonRecords } = await import('./server/person-records')\n return crmPersonRecords.search(request)\n },\n // The walk a connector copies a site's people out by (AGL-3639).\n async changedSince(request) {\n const { crmPersonRecords } = await import('./server/person-records')\n return crmPersonRecords.changedSince(request)\n },\n}\n\n/**\n * The `pipeline` record index, its reads loaded with the first one — see\n * `server/pipeline-record-index.ts` for what it answers.\n */\nexport const crmPipelineRecordIndex: PluginRecordIndex = {\n async list(request) {\n const { pipelineRecordIndex } = await import('./server/pipeline-record-index')\n return pipelineRecordIndex.list(request)\n },\n async get(request) {\n const { pipelineRecordIndex } = await import('./server/pipeline-record-index')\n return pipelineRecordIndex.get(request)\n },\n}\n\n/** One of `server/crm-record-indexes.ts`'s indexes, its reads loaded with the first one. */\nfunction lazyCrmRecordIndex(kind: 'company' | 'messageTemplate'): PluginRecordIndex {\n return {\n async list(request) {\n const { crmRecordIndexes } = await import('./server/crm-record-indexes')\n return crmRecordIndexes()[kind].list(request)\n },\n async get(request) {\n const { crmRecordIndexes } = await import('./server/crm-record-indexes')\n return crmRecordIndexes()[kind].get(request)\n },\n }\n}\n\n/** The companies a person works for, as another plugin reads them (AGL-3080). */\nexport const crmCompanyRecordIndex = lazyCrmRecordIndex('company')\n\n/** The email templates and snippets reps write, as another plugin reads them (AGL-3080). */\nexport const crmMessageTemplateRecordIndex = lazyCrmRecordIndex('messageTemplate')\n\n/**\n * The CRM's writer on the record-timeline seam (AGL-2981), deferred: the\n * writer and the Admin SDK it brings load with the first entry filed.\n */\nexport const crmRecordTimelineWriter: PluginRecordTimelineWriter = {\n async logActivity(request) {\n const { createCrmRecordTimelineWriter, defaultCrmRecordTimelineDeps } =\n await import('./server/record-timeline')\n return createCrmRecordTimelineWriter(defaultCrmRecordTimelineDeps()).logActivity(request)\n },\n async createTask(request) {\n const { createCrmRecordTimelineWriter, defaultCrmRecordTimelineDeps } =\n await import('./server/record-timeline')\n return createCrmRecordTimelineWriter(defaultCrmRecordTimelineDeps()).createTask(request)\n },\n async recordEmailDelivery(request) {\n const { createCrmRecordTimelineWriter, defaultCrmRecordTimelineDeps } =\n await import('./server/record-timeline')\n return createCrmRecordTimelineWriter(defaultCrmRecordTimelineDeps()).recordEmailDelivery!(request)\n },\n // A delivery event for a message the CRM tagged (AGL-2615, AGL-3080).\n async recordTaggedDelivery(request) {\n const { createCrmRecordTimelineWriter, defaultCrmRecordTimelineDeps } =\n await import('./server/record-timeline')\n return createCrmRecordTimelineWriter(defaultCrmRecordTimelineDeps()).recordTaggedDelivery!(request)\n },\n // An automation's email to the person its event is about, filed on that\n // person's timeline with its delivery state (AGL-2615, AGL-3080).\n async prepareEmail(request) {\n const { prepareCrmRecordEmail } = await import('./server/automation-steps')\n return prepareCrmRecordEmail(request)\n },\n}\n\n/**\n * The plugin's SERVER declarations: what the server must know at boot, before\n * any door of the CRM has been called.\n *\n * ## Why a declaration and not a `tenantApi` registration\n *\n * The doors that meet a person mostly never load this plugin. A form\n * submission is a core route; an order and a booking are captured inside\n * STRIPE WEBHOOKS. None of them has a reason to load the CRM, and a registry\n * filled by a surface that did not load answers `null` — which\n * `capturePluginContact` defines as \"this workspace has no record system\", a\n * sentence that would be false and silent. Orders would stop creating\n * contacts with nothing red anywhere, which is the AGL-3025 shape.\n *\n * Running from both apps' generated server-declarations manifest at boot is\n * what makes the answer true in every process. It is also called from the\n * plugin's own API register functions, so a process whose boot did not run it\n * still registers the writer the first time a CRM door loads. Registering\n * twice replaces in place.\n *\n * ⚠️ The registry holds ONE writer: a workspace keeps one set of people. A\n * second plugin's is refused naming both, and the incumbent keeps serving.\n */\nexport function registerCrmServerDeclarations(): void {\n registerPluginContactCaptureWriter(crmContactCaptureWriter, {\n pluginId: BUNDLE_ID,\n })\n // The other half of keeping people (AGL-3080): another plugin that holds\n // an address, or a record the CRM handed it, asks here for the person —\n // a flow email's consent read, a refund, an automation filing somebody\n // under a campaign — and never opens the CRM's collections itself.\n registerPluginPersonRecords(crmPersonRecordsService, { pluginId: BUNDLE_ID })\n // A record's scoped list fields follow its sites, so the sweep that keeps\n // \"all sites except\" current restamps them in the same write (AGL-4047).\n // Deferred like the capture.\n registerPluginScopeSharingPatch(\n ['contacts', 'leads', 'companies', 'deals', 'crmTasks'],\n async (collection, next) => {\n const { crmScopeSharingPatch } = await import('./server/scope-sharing-patch')\n return crmScopeSharingPatch(collection, next)\n },\n { pluginId: BUNDLE_ID },\n )\n // Its grants shared with all sites except some sit inside a record's\n // `sharing`, which the sweep does not walk, so a change to the workspace's\n // sites brings them level here (AGL-4047). Deferred like the patch.\n registerPluginScopeSharingSiteChange(\n async (input) => {\n const { crmSharingAfterSiteChange } = await import('./server/crm-sharing-runs')\n await crmSharingAfterSiteChange(input)\n },\n { pluginId: BUNDLE_ID },\n )\n // The CRM's own share of a lead conversion (AGL-3254): the lead's\n // campaigns go onto the contact's facet. Through the seam every door\n // that converts a lead reaches, and deferred like the capture: the\n // module that writes is loaded when the first conversion arrives, and\n // it brings the Admin SDK with it — this file defers the plugin's OWN\n // module only. A library imported statically across the plugin cannot\n // also be lazy-loaded here: `enforce-module-boundaries` refuses every\n // static import of a library the project lazy-loads anywhere.\n registerPluginLeadConversionListener(\n async (request) => {\n const { carryLeadCampaignsOnConversion } =\n await import('./server/lead-campaign-carry')\n return carryLeadCampaignsOnConversion(request)\n },\n { pluginId: BUNDLE_ID },\n )\n // \"Did this workspace already know this person?\" (AGL-3289), asked by the\n // staff console's acquisition card. Deferred like the rest: the reads load\n // when a staff member first opens a card, not when the process starts.\n registerPluginPersonMatcher(\n async (request) => {\n const { matchCrmPeople } = await import('./server/person-matches')\n return matchCrmPeople(request)\n },\n { pluginId: BUNDLE_ID },\n )\n // The CRM's share of a consent group change (AGL-3320): a contact's\n // per-site refusal carried across a separation, and the records keyed by a\n // group re-homed after the flip. Registered whether or not a workspace has\n // the CRM switched on, because the contacts — and the refusals on them —\n // outlive the switch. Deferred like the rest; the summary is plain words\n // and answers synchronously.\n // The record email-state writer (AGL-3245), here as well as in the console\n // API so the tenant's doors reach it too: a form submission's capture is\n // checked for deliverability after its response (AGL-3328), and the \"Would\n // bounce\" that check finds is written through this seam. Deferred like the\n // rest; the console's own registration replaces this one with the same\n // writer, loaded eagerly.\n registerPluginRecordEmailStateWriter(\n {\n async stamp(request) {\n const { createCrmRecordEmailStateWriter, defaultCrmRecordEmailStateDeps } =\n await import('./server/record-email-state')\n return createCrmRecordEmailStateWriter(defaultCrmRecordEmailStateDeps()).stamp(request)\n },\n // A send's first opens and clicks, stamped on the contacts they name\n // (AGL-2616) — the campaign webhook's courtesy, deferred like the rest.\n async engaged(request) {\n const { createCrmRecordEmailStateWriter, defaultCrmRecordEmailStateDeps } =\n await import('./server/record-email-state')\n return createCrmRecordEmailStateWriter(defaultCrmRecordEmailStateDeps()).engaged!(request)\n },\n // A delivered campaign's leads, moved to Nurturing (AGL-3446).\n async reached(request) {\n const { createCrmRecordEmailStateWriter, defaultCrmRecordEmailStateDeps } =\n await import('./server/record-email-state')\n return createCrmRecordEmailStateWriter(defaultCrmRecordEmailStateDeps()).reached!(request)\n },\n // A lead that wrote back, moved to Working (AGL-3080).\n async replied(request) {\n const { createCrmRecordEmailStateWriter, defaultCrmRecordEmailStateDeps } =\n await import('./server/record-email-state')\n return createCrmRecordEmailStateWriter(defaultCrmRecordEmailStateDeps()).replied!(request)\n },\n },\n { pluginId: BUNDLE_ID },\n )\n // The record timeline writer (AGL-2981), here as well as in the API\n // surfaces so a door in either app reaches it: a booking confirmed on the\n // tenant, or by the payment webhook, files its meeting and follow-up\n // through it (AGL-2660). Deferred like the rest; an API registration\n // replaces this one with the same writer, loaded eagerly.\n registerPluginRecordTimelineWriter(crmRecordTimelineWriter, { pluginId: BUNDLE_ID })\n // Where a person came from (AGL-3519): a door the CRM does not run — the\n // platform's account sign-up, a sequence enrolling someone — names its\n // origin, and the CRM stamps the built-in Lead source on a record holding\n // none. Deferred like the rest.\n registerPluginRecordOriginWriter(\n {\n async stamp(request) {\n const { crmRecordOriginWriter } = await import('./server/record-origin')\n return crmRecordOriginWriter.stamp(request)\n },\n },\n { pluginId: BUNDLE_ID },\n )\n // Sharing rules (AGL-3336), re-evaluated after every server write of a\n // lead, a contact, a company or a deal: the core tells its record-written\n // listeners from the list-field restamp every such writer ends with, in\n // both apps — a form's capture on the tenant, an edit in the console.\n // Deferred like the rest: an org with no rules pays one cached read.\n registerPluginRecordWrittenListener(\n async (event) => {\n const { crmSharingRecordWritten } = await import('./server/crm-sharing')\n await crmSharingRecordWritten(event)\n },\n { pluginId: BUNDLE_ID, key: 'sharing' },\n )\n // The organization's pipelines and their stages, as another plugin reads\n // them (AGL-3080): an automation the AI drafts names the stage a deal\n // moves to. Deferred like the rest: the reads load with the first one.\n registerPluginRecordIndex('pipeline', crmPipelineRecordIndex, { pluginId: BUNDLE_ID })\n // The company a person works for, and the templates reps write, as a sales\n // sequence reads them (AGL-3080). Deferred like the rest.\n registerPluginRecordIndex('company', crmCompanyRecordIndex, { pluginId: BUNDLE_ID })\n registerPluginRecordIndex('messageTemplate', crmMessageTemplateRecordIndex, { pluginId: BUNDLE_ID })\n // The automation steps that write the CRM (AGL-2605, AGL-3080), run for the\n // workflows engine through the server-step seam and declared under\n // `serverSteps`. Deferred like the rest: the writes load with the first step.\n registerServerStepExecutor(\n CRM_STEP_TYPES,\n async (request) => (await import('./server/automation-steps')).runCrmAutomationStep(request),\n { pluginId: BUNDLE_ID },\n )\n registerPluginConsentGroupParticipant(\n {\n async preview(request) {\n const { consentGroupParticipant } = await import('./server/consent-group-participant')\n return consentGroupParticipant.preview(request)\n },\n async run(request) {\n const { consentGroupParticipant } = await import('./server/consent-group-participant')\n return consentGroupParticipant.run(request)\n },\n summarize: summarizeConsentGroupChange,\n },\n { pluginId: BUNDLE_ID },\n )\n // The records band in the monthly usage sweep, a core cron that never\n // loads a CRM door; declared in `usageAxes` so the sweep refuses to bill a\n // month without it. Deferred like the rest: the counts load with the\n // first sweep.\n registerPluginUsageMeter({\n pluginId: BUNDLE_ID,\n id: CRM_RECORDS_METER_ID,\n measure: async (context) => {\n const { measureCrmRecords } = await import('./server/crm-records-meter')\n return measureCrmRecords(context)\n },\n })\n}\n\n"],"names":["registerPluginConsentGroupParticipant","registerPluginContactCaptureWriter","registerPluginLeadConversionListener","registerPluginPersonMatcher","registerPluginPersonRecords","registerPluginRecordIndex","registerPluginRecordEmailStateWriter","registerPluginRecordOriginWriter","registerPluginRecordTimelineWriter","registerPluginRecordWrittenListener","registerPluginScopeSharingPatch","registerPluginScopeSharingSiteChange","registerServerStepExecutor","registerPluginUsageMeter","BUNDLE_ID","CRM_RECORDS_METER_ID","CRM_STEP_TYPES","summarizeConsentGroupChange","crmContactCaptureWriter","capture","request","captureContactForCrm","crmPersonRecordsService","find","crmPersonRecords","read","fileUnder","recordRefund","peopleInView","wroteIn","search","changedSince","crmPipelineRecordIndex","list","pipelineRecordIndex","get","lazyCrmRecordIndex","kind","crmRecordIndexes","crmCompanyRecordIndex","crmMessageTemplateRecordIndex","crmRecordTimelineWriter","logActivity","createCrmRecordTimelineWriter","defaultCrmRecordTimelineDeps","createTask","recordEmailDelivery","recordTaggedDelivery","prepareEmail","prepareCrmRecordEmail","registerCrmServerDeclarations","pluginId","collection","next","crmScopeSharingPatch","input","crmSharingAfterSiteChange","carryLeadCampaignsOnConversion","matchCrmPeople","stamp","createCrmRecordEmailStateWriter","defaultCrmRecordEmailStateDeps","engaged","reached","replied","crmRecordOriginWriter","event","crmSharingRecordWritten","key","runCrmAutomationStep","preview","consentGroupParticipant","run","summarize","id","measure","context","measureCrmRecords"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,8EAA8E;AAC9E,6EAA6E;AAC7E,SAASA,qCAAqC,QAAQ,0DAAyD;AAC/G,SACEC,kCAAkC,QAE7B,qDAAoD;AAC3D,SAASC,oCAAoC,QAAQ,qDAAoD;AACzG,SAASC,2BAA2B,QAAQ,oDAAmD;AAC/F,SACEC,2BAA2B,QAEtB,oDAAmD;AAC1D,SACEC,yBAAyB,QAEpB,kDAAiD;AACxD,SAASC,oCAAoC,QAAQ,wDAAuD;AAC5G,SAASC,gCAAgC,QAAQ,mDAAkD;AACnG,SACEC,kCAAkC,QAE7B,qDAAoD;AAC3D,SAASC,mCAAmC,QAAQ,oDAAmD;AACvG,SACEC,+BAA+B,EAC/BC,oCAAoC,QAC/B,mDAAkD;AACzD,SAASC,0BAA0B,QAAQ,kDAAiD;AAC5F,SAASC,wBAAwB,QAAQ,kDAAiD;AAC1F,SAASC,SAAS,EAA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GAAG,CAACpD;QACrC;QACAqD,WAAWxD;IACb,GACA;QAAEkC,UAAUrC;IAAU;IAExB,sEAAsE;IACtE,2EAA2E;IAC3E,qEAAqE;IACrE,eAAe;IACfD,yBAAyB;QACvBsC,UAAUrC;QACV4D,IAAI3D;QACJ4D,SAAS,OAAOC;YACd,MAAM,EAAEC,iBAAiB,EAAE,GAAG,MAAM,MAAM,CAAC;YAC3C,OAAOA,kBAAkBD;QAC3B;IACF;AACF"}
|
|
@@ -22,6 +22,7 @@ import { useCallback } from "react";
|
|
|
22
22
|
import { buildCampaignFilingActivity } from "../model/campaign-filing-activity.js";
|
|
23
23
|
import { resolveCrmActivityCompany } from "../model/crm-activity-link.js";
|
|
24
24
|
import { crmActivityClientReads } from "./crm-activity-client-reads.js";
|
|
25
|
+
import { useCrmDefaultMarkFollowUp } from "./use-crm-sharing.js";
|
|
25
26
|
/**
|
|
26
27
|
* FILES A MEMBER'S FILING ON THE RECORD'S TIMELINE (AGL-3274), from the
|
|
27
28
|
* console.
|
|
@@ -48,6 +49,7 @@ import { crmActivityClientReads } from "./crm-activity-client-reads.js";
|
|
|
48
49
|
const { data: user } = useUser();
|
|
49
50
|
const authorName = useUserName();
|
|
50
51
|
const uid = user == null ? void 0 : user.uid;
|
|
52
|
+
const markUnderDefault = useCrmDefaultMarkFollowUp(hostId, orgId, org);
|
|
51
53
|
return useCallback(async (link, change, recordHostId)=>{
|
|
52
54
|
var _change_filed, _change_removed;
|
|
53
55
|
const siteHostId = hostId || recordHostId || null;
|
|
@@ -70,10 +72,12 @@ import { crmActivityClientReads } from "./crm-activity-client-reads.js";
|
|
|
70
72
|
}, crmActivityClientReads(firestore, orgId));
|
|
71
73
|
const atMs = Date.now();
|
|
72
74
|
const activities = collection(firestore, 'orgs', orgId, CRM_COLLECTIONS.activities);
|
|
75
|
+
const written = [];
|
|
73
76
|
for (const entry of entries){
|
|
74
77
|
try {
|
|
75
78
|
// Named by the platform's own id, as every console resource is.
|
|
76
|
-
|
|
79
|
+
const id = createResourceUid();
|
|
80
|
+
await setDoc(doc(activities, id), _extends({}, buildCampaignFilingActivity({
|
|
77
81
|
action: entry.action,
|
|
78
82
|
campaign: entry.campaign,
|
|
79
83
|
link: stamped,
|
|
@@ -86,17 +90,21 @@ import { crmActivityClientReads } from "./crm-activity-client-reads.js";
|
|
|
86
90
|
createdAt: new Date(),
|
|
87
91
|
updatedAt: new Date()
|
|
88
92
|
}));
|
|
93
|
+
written.push(id);
|
|
89
94
|
} catch (error) {
|
|
90
95
|
console.error('[crm] the filing could not be written on the timeline', error);
|
|
91
96
|
}
|
|
92
97
|
}
|
|
98
|
+
// Under "All sites except…", the marker a site added later joins by (AGL-4047).
|
|
99
|
+
if (written.length) markUnderDefault(written);
|
|
93
100
|
}, [
|
|
94
101
|
firestore,
|
|
95
102
|
orgId,
|
|
96
103
|
hostId,
|
|
97
104
|
org,
|
|
98
105
|
uid,
|
|
99
|
-
authorName
|
|
106
|
+
authorName,
|
|
107
|
+
markUnderDefault
|
|
100
108
|
]);
|
|
101
109
|
}
|
|
102
110
|
export default useCampaignFilingLog;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/hooks/use-campaign-filing-log.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'use client'\n\nimport {\n CRM_COLLECTIONS,\n consentGroupForHost,\n createResourceUid,\n crmScopeTokens,\n type CrmActivityLink,\n} from '@aglyn/aglyn'\nimport { useFirestore, useUser, useUserName } from '@aglyn/tenant-feature-instance'\nimport { collection, doc, setDoc } from 'firebase/firestore'\nimport { useCallback } from 'react'\nimport {\n buildCampaignFilingActivity,\n type CampaignFilingRef,\n} from '../model/campaign-filing-activity'\nimport { resolveCrmActivityCompany } from '../model/crm-activity-link'\nimport { crmActivityClientReads } from './crm-activity-client-reads'\n\n/** What one surface's save changed, by campaign, with the names it showed. */\nexport interface CampaignFilingChange {\n filed?: readonly CampaignFilingRef[]\n removed?: readonly CampaignFilingRef[]\n}\n\n/**\n * FILES A MEMBER'S FILING ON THE RECORD'S TIMELINE (AGL-3274), from the\n * console.\n *\n * The lead's Campaigns card and the Leads list's bulk bar write the\n * membership client-direct — a one-field update the rules already admit —\n * so the entry that records it is written the same way, into the org's\n * activity collection the log dialog writes, with the scope a record made\n * on this site carries (`crmScopeTokens`), the signed-in member as author,\n * and the CRM's own id as the filing plugin. The entry rolls up to the\n * record's company (AGL-4123) like any other.\n *\n * The site an entry carries is the hook's, or — for a surface that files\n * leads from several sites at once, the organization-level bulk bar — the\n * one a call names for its record. With neither there is no scope to stamp,\n * and nothing is written.\n *\n * Bookkeeping beside the act: the membership has landed by the time this\n * runs, so a write that fails is logged and the filing stands — the card\n * shows the campaigns from the document, not from the timeline.\n */\nexport function useCampaignFilingLog(input: {\n orgId: string | null | undefined\n /** The site the entry carries as provenance: the lead's, or the contact's viewing site. */\n hostId: string | null | undefined\n org: Record<string, unknown> | null | undefined\n}) {\n const { orgId, hostId, org } = input\n const firestore = useFirestore()\n const { data: user } = useUser()\n const authorName = useUserName()\n const uid = user?.uid\n\n return useCallback(\n async (\n link: CrmActivityLink,\n change: CampaignFilingChange,\n recordHostId?: string | null,\n ): Promise<void> => {\n const siteHostId = hostId || recordHostId || null\n if (!orgId || !siteHostId || !uid) return\n const entries = [\n ...(change.filed ?? []).map((campaign) => ({ action: 'filed' as const, campaign })),\n ...(change.removed ?? []).map((campaign) => ({ action: 'removed' as const, campaign })),\n ]\n if (!entries.length) return\n const group = consentGroupForHost(org, siteHostId)\n const visibleTo = crmScopeTokens(org, group)\n const stamped = await resolveCrmActivityCompany(\n link,\n { groupId: group.groupId },\n crmActivityClientReads(firestore, orgId),\n )\n const atMs = Date.now()\n const activities = collection(firestore, 'orgs', orgId, CRM_COLLECTIONS.activities)\n for (const entry of entries) {\n try {\n // Named by the platform's own id, as every console resource is.\n await setDoc(doc(activities,
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/hooks/use-campaign-filing-log.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'use client'\n\nimport {\n CRM_COLLECTIONS,\n consentGroupForHost,\n createResourceUid,\n crmScopeTokens,\n type CrmActivityLink,\n} from '@aglyn/aglyn'\nimport { useFirestore, useUser, useUserName } from '@aglyn/tenant-feature-instance'\nimport { collection, doc, setDoc } from 'firebase/firestore'\nimport { useCallback } from 'react'\nimport {\n buildCampaignFilingActivity,\n type CampaignFilingRef,\n} from '../model/campaign-filing-activity'\nimport { resolveCrmActivityCompany } from '../model/crm-activity-link'\nimport { crmActivityClientReads } from './crm-activity-client-reads'\nimport { useCrmDefaultMarkFollowUp } from './use-crm-sharing'\n\n/** What one surface's save changed, by campaign, with the names it showed. */\nexport interface CampaignFilingChange {\n filed?: readonly CampaignFilingRef[]\n removed?: readonly CampaignFilingRef[]\n}\n\n/**\n * FILES A MEMBER'S FILING ON THE RECORD'S TIMELINE (AGL-3274), from the\n * console.\n *\n * The lead's Campaigns card and the Leads list's bulk bar write the\n * membership client-direct — a one-field update the rules already admit —\n * so the entry that records it is written the same way, into the org's\n * activity collection the log dialog writes, with the scope a record made\n * on this site carries (`crmScopeTokens`), the signed-in member as author,\n * and the CRM's own id as the filing plugin. The entry rolls up to the\n * record's company (AGL-4123) like any other.\n *\n * The site an entry carries is the hook's, or — for a surface that files\n * leads from several sites at once, the organization-level bulk bar — the\n * one a call names for its record. With neither there is no scope to stamp,\n * and nothing is written.\n *\n * Bookkeeping beside the act: the membership has landed by the time this\n * runs, so a write that fails is logged and the filing stands — the card\n * shows the campaigns from the document, not from the timeline.\n */\nexport function useCampaignFilingLog(input: {\n orgId: string | null | undefined\n /** The site the entry carries as provenance: the lead's, or the contact's viewing site. */\n hostId: string | null | undefined\n org: Record<string, unknown> | null | undefined\n}) {\n const { orgId, hostId, org } = input\n const firestore = useFirestore()\n const { data: user } = useUser()\n const authorName = useUserName()\n const uid = user?.uid\n const markUnderDefault = useCrmDefaultMarkFollowUp(hostId, orgId, org)\n\n return useCallback(\n async (\n link: CrmActivityLink,\n change: CampaignFilingChange,\n recordHostId?: string | null,\n ): Promise<void> => {\n const siteHostId = hostId || recordHostId || null\n if (!orgId || !siteHostId || !uid) return\n const entries = [\n ...(change.filed ?? []).map((campaign) => ({ action: 'filed' as const, campaign })),\n ...(change.removed ?? []).map((campaign) => ({ action: 'removed' as const, campaign })),\n ]\n if (!entries.length) return\n const group = consentGroupForHost(org, siteHostId)\n const visibleTo = crmScopeTokens(org, group)\n const stamped = await resolveCrmActivityCompany(\n link,\n { groupId: group.groupId },\n crmActivityClientReads(firestore, orgId),\n )\n const atMs = Date.now()\n const activities = collection(firestore, 'orgs', orgId, CRM_COLLECTIONS.activities)\n const written: string[] = []\n for (const entry of entries) {\n try {\n // Named by the platform's own id, as every console resource is.\n const id = createResourceUid()\n await setDoc(doc(activities, id), {\n ...buildCampaignFilingActivity({\n action: entry.action,\n campaign: entry.campaign,\n link: stamped,\n hostId: siteHostId,\n visibleTo,\n atMs,\n byUid: uid,\n byName: authorName || null,\n }),\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n written.push(id)\n } catch (error) {\n console.error('[crm] the filing could not be written on the timeline', error)\n }\n }\n // Under \"All sites except…\", the marker a site added later joins by (AGL-4047).\n if (written.length) markUnderDefault(written)\n },\n [firestore, orgId, hostId, org, uid, authorName, markUnderDefault],\n )\n}\n\nexport default useCampaignFilingLog\n"],"names":["CRM_COLLECTIONS","consentGroupForHost","createResourceUid","crmScopeTokens","useFirestore","useUser","useUserName","collection","doc","setDoc","useCallback","buildCampaignFilingActivity","resolveCrmActivityCompany","crmActivityClientReads","useCrmDefaultMarkFollowUp","useCampaignFilingLog","input","orgId","hostId","org","firestore","data","user","authorName","uid","markUnderDefault","link","change","recordHostId","siteHostId","entries","filed","map","campaign","action","removed","length","group","visibleTo","stamped","groupId","atMs","Date","now","activities","written","entry","id","byUid","byName","createdAt","updatedAt","push","error","console"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAEA,SACEA,eAAe,EACfC,mBAAmB,EACnBC,iBAAiB,EACjBC,cAAc,QAET,eAAc;AACrB,SAASC,YAAY,EAAEC,OAAO,EAAEC,WAAW,QAAQ,iCAAgC;AACnF,SAASC,UAAU,EAAEC,GAAG,EAAEC,MAAM,QAAQ,qBAAoB;AAC5D,SAASC,WAAW,QAAQ,QAAO;AACnC,SACEC,2BAA2B,QAEtB,uCAAmC;AAC1C,SAASC,yBAAyB,QAAQ,gCAA4B;AACtE,SAASC,sBAAsB,QAAQ,iCAA6B;AACpE,SAASC,yBAAyB,QAAQ,uBAAmB;AAQ7D;;;;;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,SAASC,qBAAqBC,KAKpC;IACC,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAEC,GAAG,EAAE,GAAGH;IAC/B,MAAMI,YAAYhB;IAClB,MAAM,EAAEiB,MAAMC,IAAI,EAAE,GAAGjB;IACvB,MAAMkB,aAAajB;IACnB,MAAMkB,MAAMF,wBAAAA,KAAME,GAAG;IACrB,MAAMC,mBAAmBX,0BAA0BI,QAAQD,OAAOE;IAElE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AQT,MAAM,EAAEX,iBAAiBoB;IACvC,GACA;QAACzB;QAAWH;QAAOC;QAAQC;QAAKK;QAAKD;QAAYE;KAAiB;AAEtE;AAEA,eAAeV,qBAAoB"}
|
|
@@ -28,3 +28,11 @@ export declare function useCrmSharingRules(org: CrmOrgDoc): import("../model/crm
|
|
|
28
28
|
* save has landed whether or not a rule then shares the record.
|
|
29
29
|
*/
|
|
30
30
|
export declare function useCrmSharingFollowUp(hostId: string | null | undefined, orgId: string | null | undefined): (object: CrmSharingObject, ids: readonly string[]) => void;
|
|
31
|
+
/**
|
|
32
|
+
* The follow-up a browser's own logged activity owes the CRM default "All
|
|
33
|
+
* sites except…" (AGL-4047): the rules refuse the marker from a client, so
|
|
34
|
+
* the server writes it when the activity's sites are exactly the default's,
|
|
35
|
+
* and a site added later then sees it. Only an org with that default asks;
|
|
36
|
+
* fire-and-forget like the sharing follow-up.
|
|
37
|
+
*/
|
|
38
|
+
export declare function useCrmDefaultMarkFollowUp(hostId: string | null | undefined, orgId: string | null | undefined, org: CrmOrgDoc): (ids: readonly string[]) => void;
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/ 'use client';
|
|
17
|
+
import { crmDefaultSharingOf } from "@aglyn/aglyn";
|
|
17
18
|
import { useUser } from "@aglyn/tenant-feature-instance";
|
|
18
19
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
19
20
|
import { readCrmSharingRules } from "../model/crm-sharing.js";
|
|
@@ -105,5 +106,24 @@ import { useCrmOrgMount } from "./use-crm-org-mount.js";
|
|
|
105
106
|
orgId
|
|
106
107
|
]);
|
|
107
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* The follow-up a browser's own logged activity owes the CRM default "All
|
|
111
|
+
* sites except…" (AGL-4047): the rules refuse the marker from a client, so
|
|
112
|
+
* the server writes it when the activity's sites are exactly the default's,
|
|
113
|
+
* and a site added later then sees it. Only an org with that default asks;
|
|
114
|
+
* fire-and-forget like the sharing follow-up.
|
|
115
|
+
*/ export function useCrmDefaultMarkFollowUp(hostId, orgId, org) {
|
|
116
|
+
const { data: user } = useUser();
|
|
117
|
+
const asks = crmDefaultSharingOf(org != null ? org : null) === 'allExcept';
|
|
118
|
+
return useCallback((ids)=>{
|
|
119
|
+
if (!asks) return;
|
|
120
|
+
void followUpCrmSharing(user, crmTaskCallScope(hostId, orgId), 'crmActivities', ids);
|
|
121
|
+
}, [
|
|
122
|
+
asks,
|
|
123
|
+
user,
|
|
124
|
+
hostId,
|
|
125
|
+
orgId
|
|
126
|
+
]);
|
|
127
|
+
}
|
|
108
128
|
|
|
109
129
|
//# sourceMappingURL=use-crm-sharing.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/hooks/use-crm-sharing.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'use client'\n\nimport { useUser } from '@aglyn/tenant-feature-instance'\nimport { useCallback, useEffect, useMemo, useState } from 'react'\nimport { type CrmSharingObject, type CrmSharingSite, readCrmSharingRules } from '../model/crm-sharing'\nimport { callCrmSharing, followUpCrmSharing } from '../model/crm-sharing-api'\nimport { crmTaskCallScope } from '../model/task-routes'\nimport { useCrmOrgMount } from './use-crm-org-mount'\nimport type { CrmOrgDoc } from './use-crm-scope'\n\nexport interface CrmSharingSites {\n sites: CrmSharingSite[]\n ready: boolean\n /** How a site reads: its name, or a neutral phrase for one this reader cannot name. */\n siteName: (hostId: string) => string\n}\n\n/**\n * The org's sites, for a sharing surface (AGL-3336).\n *\n * At the organization level the hub already holds them (`useCrmOrgMount`).\n * Under a site a member cannot list the org's other sites, so a MANAGER's\n * surface asks `crm/sharing` for them — the one reader a share is offered\n * to — and every other reader names them as \"another site\".\n */\nexport function useCrmSharingSites(input: {\n hostId: string | null\n orgId: string | null\n enabled: boolean\n}): CrmSharingSites {\n const { hostId, orgId, enabled } = input\n const mount = useCrmOrgMount()\n const { data: user } = useUser()\n const [fetched, setFetched] = useState<{ key: string; sites: CrmSharingSite[] } | null>(null)\n const scope = crmTaskCallScope(hostId, orgId)\n const key = scope ? JSON.stringify(scope) : ''\n const fromMount = mount && !hostId\n useEffect(() => {\n if (fromMount || !enabled || !scope || !user) return\n let cancelled = false\n callCrmSharing(user, scope, 'sites')\n .then((answer) => {\n if (!cancelled) setFetched({ key, sites: answer.sites ?? [] })\n })\n .catch(() => {\n if (!cancelled) setFetched({ key, sites: [] })\n })\n return () => {\n cancelled = true\n }\n // `scope` is keyed by `key`; the object itself is rebuilt every render.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [fromMount, enabled, key, user])\n const sites = useMemo<CrmSharingSite[]>(\n () =>\n fromMount\n ? mount.hosts.map((host) => ({ id: host.id, name: host.name }))\n : fetched?.key === key\n ? fetched.sites\n : [],\n [fromMount, mount, fetched, key],\n )\n const ready = fromMount ? mount.hostsReady : fetched?.key === key || !enabled\n const siteName = useCallback(\n (id: string) => sites.find((site) => site.id === id)?.name ?? (id === hostId ? 'This site' : 'another site'),\n [sites, hostId],\n )\n return { sites, ready, siteName }\n}\n\n/** The org's sharing rules, off the org document the shell already passed. */\nexport function useCrmSharingRules(org: CrmOrgDoc) {\n return useMemo(\n () => readCrmSharingRules((org ?? null) as Record<string, unknown> | null),\n [org],\n )\n}\n\n\n/**\n * The follow-up a CLIENT-DIRECT write to a lead, a company or a deal owes\n * the org's sharing rules (AGL-3336): a server write is followed by the\n * core's record-written seam, a browser's by this. Fire-and-forget — the\n * save has landed whether or not a rule then shares the record.\n */\nexport function useCrmSharingFollowUp(\n hostId: string | null | undefined,\n orgId: string | null | undefined,\n): (object: CrmSharingObject, ids: readonly string[]) => void {\n const { data: user } = useUser()\n return useCallback(\n (object: CrmSharingObject, ids: readonly string[]) => {\n void followUpCrmSharing(user, crmTaskCallScope(hostId, orgId), object, ids)\n },\n [user, hostId, orgId],\n )\n}\n"],"names":["useUser","useCallback","useEffect","useMemo","useState","readCrmSharingRules","callCrmSharing","followUpCrmSharing","crmTaskCallScope","useCrmOrgMount","useCrmSharingSites","input","hostId","orgId","enabled","mount","data","user","fetched","setFetched","scope","key","JSON","stringify","fromMount","cancelled","then","answer","sites","catch","hosts","map","host","id","name","ready","hostsReady","siteName","find","site","useCrmSharingRules","org","useCrmSharingFollowUp","object","ids"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;AAEA,SAASA,OAAO,QAAQ,iCAAgC;AACxD,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACjE,SAAqDC,mBAAmB,QAAQ,0BAAsB;AACtG,SAASC,cAAc,EAAEC,kBAAkB,QAAQ,8BAA0B;AAC7E,SAASC,gBAAgB,QAAQ,0BAAsB;AACvD,SAASC,cAAc,QAAQ,yBAAqB;AAUpD;;;;;;;CAOC,GACD,OAAO,SAASC,mBAAmBC,KAIlC;IACC,MAAM,EAAEC,MAAM,EAAEC,KAAK,EAAEC,OAAO,EAAE,GAAGH;IACnC,MAAMI,QAAQN;IACd,MAAM,EAAEO,MAAMC,IAAI,EAAE,GAAGjB;IACvB,MAAM,CAACkB,SAASC,WAAW,GAAGf,SAA0D;IACxF,MAAMgB,QAAQZ,iBAAiBI,QAAQC;IACvC,MAAMQ,MAAMD,QAAQE,KAAKC,SAAS,CAACH,SAAS;IAC5C,MAAMI,YAAYT,SAAS,CAACH;IAC5BV,UAAU;QACR,IAAIsB,aAAa,CAACV,WAAW,CAACM,SAAS,CAACH,MAAM;QAC9C,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IACvB,OAAOC,YACL,CAAC0C,QAA0BC;QACzB,KAAKrC,mBAAmBU,MAAMT,iBAAiBI,QAAQC,QAAQ8B,QAAQC;IACzE,GACA;QAAC3B;QAAML;QAAQC;KAAM;AAEzB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/hooks/use-crm-sharing.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'use client'\n\nimport { crmDefaultSharingOf } from '@aglyn/aglyn'\nimport { useUser } from '@aglyn/tenant-feature-instance'\nimport { useCallback, useEffect, useMemo, useState } from 'react'\nimport { type CrmSharingObject, type CrmSharingSite, readCrmSharingRules } from '../model/crm-sharing'\nimport { callCrmSharing, followUpCrmSharing } from '../model/crm-sharing-api'\nimport { crmTaskCallScope } from '../model/task-routes'\nimport { useCrmOrgMount } from './use-crm-org-mount'\nimport type { CrmOrgDoc } from './use-crm-scope'\n\nexport interface CrmSharingSites {\n sites: CrmSharingSite[]\n ready: boolean\n /** How a site reads: its name, or a neutral phrase for one this reader cannot name. */\n siteName: (hostId: string) => string\n}\n\n/**\n * The org's sites, for a sharing surface (AGL-3336).\n *\n * At the organization level the hub already holds them (`useCrmOrgMount`).\n * Under a site a member cannot list the org's other sites, so a MANAGER's\n * surface asks `crm/sharing` for them — the one reader a share is offered\n * to — and every other reader names them as \"another site\".\n */\nexport function useCrmSharingSites(input: {\n hostId: string | null\n orgId: string | null\n enabled: boolean\n}): CrmSharingSites {\n const { hostId, orgId, enabled } = input\n const mount = useCrmOrgMount()\n const { data: user } = useUser()\n const [fetched, setFetched] = useState<{ key: string; sites: CrmSharingSite[] } | null>(null)\n const scope = crmTaskCallScope(hostId, orgId)\n const key = scope ? JSON.stringify(scope) : ''\n const fromMount = mount && !hostId\n useEffect(() => {\n if (fromMount || !enabled || !scope || !user) return\n let cancelled = false\n callCrmSharing(user, scope, 'sites')\n .then((answer) => {\n if (!cancelled) setFetched({ key, sites: answer.sites ?? [] })\n })\n .catch(() => {\n if (!cancelled) setFetched({ key, sites: [] })\n })\n return () => {\n cancelled = true\n }\n // `scope` is keyed by `key`; the object itself is rebuilt every render.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [fromMount, enabled, key, user])\n const sites = useMemo<CrmSharingSite[]>(\n () =>\n fromMount\n ? mount.hosts.map((host) => ({ id: host.id, name: host.name }))\n : fetched?.key === key\n ? fetched.sites\n : [],\n [fromMount, mount, fetched, key],\n )\n const ready = fromMount ? mount.hostsReady : fetched?.key === key || !enabled\n const siteName = useCallback(\n (id: string) => sites.find((site) => site.id === id)?.name ?? (id === hostId ? 'This site' : 'another site'),\n [sites, hostId],\n )\n return { sites, ready, siteName }\n}\n\n/** The org's sharing rules, off the org document the shell already passed. */\nexport function useCrmSharingRules(org: CrmOrgDoc) {\n return useMemo(\n () => readCrmSharingRules((org ?? null) as Record<string, unknown> | null),\n [org],\n )\n}\n\n\n/**\n * The follow-up a CLIENT-DIRECT write to a lead, a company or a deal owes\n * the org's sharing rules (AGL-3336): a server write is followed by the\n * core's record-written seam, a browser's by this. Fire-and-forget — the\n * save has landed whether or not a rule then shares the record.\n */\nexport function useCrmSharingFollowUp(\n hostId: string | null | undefined,\n orgId: string | null | undefined,\n): (object: CrmSharingObject, ids: readonly string[]) => void {\n const { data: user } = useUser()\n return useCallback(\n (object: CrmSharingObject, ids: readonly string[]) => {\n void followUpCrmSharing(user, crmTaskCallScope(hostId, orgId), object, ids)\n },\n [user, hostId, orgId],\n )\n}\n\n/**\n * The follow-up a browser's own logged activity owes the CRM default \"All\n * sites except…\" (AGL-4047): the rules refuse the marker from a client, so\n * the server writes it when the activity's sites are exactly the default's,\n * and a site added later then sees it. Only an org with that default asks;\n * fire-and-forget like the sharing follow-up.\n */\nexport function useCrmDefaultMarkFollowUp(\n hostId: string | null | undefined,\n orgId: string | null | undefined,\n org: CrmOrgDoc,\n): (ids: readonly string[]) => void {\n const { data: user } = useUser()\n const asks = crmDefaultSharingOf((org ?? null) as Record<string, unknown> | null) === 'allExcept'\n return useCallback(\n (ids: readonly string[]) => {\n if (!asks) return\n void followUpCrmSharing(user, crmTaskCallScope(hostId, orgId), 'crmActivities', ids)\n },\n [asks, user, hostId, orgId],\n )\n}\n"],"names":["crmDefaultSharingOf","useUser","useCallback","useEffect","useMemo","useState","readCrmSharingRules","callCrmSharing","followUpCrmSharing","crmTaskCallScope","useCrmOrgMount","useCrmSharingSites","input","hostId","orgId","enabled","mount","data","user","fetched","setFetched","scope","key","JSON","stringify","fromMount","cancelled","then","answer","sites","catch","hosts","map","host","id","name","ready","hostsReady","siteName","find","site","useCrmSharingRules","org","useCrmSharingFollowUp","object","ids","useCrmDefaultMarkFollowUp","asks"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;AAEA,SAASA,mBAAmB,QAAQ,eAAc;AAClD,SAASC,OAAO,QAAQ,iCAAgC;AACxD,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACjE,SAAqDC,mBAAmB,QAAQ,0BAAsB;AACtG,SAASC,cAAc,EAAEC,kBAAkB,QAAQ,8BAA0B;AAC7E,SAASC,gBAAgB,QAAQ,0BAAsB;AACvD,SAASC,cAAc,QAAQ,yBAAqB;AAUpD;;;;;;;CAOC,GACD,OAAO,SAASC,mBAAmBC,KAIlC;IACC,MAAM,EAAEC,MAAM,EAAEC,KAAK,EAAEC,OAAO,EAAE,GAAGH;IACnC,MAAMI,QAAQN;IACd,MAAM,EAAEO,MAAMC,IAAI,EAAE,GAAGjB;IACvB,MAAM,CAACkB,S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,4EAA4E,GAC5E,OAAO,SAASG,mBAAmBC,GAAc;IAC/C,OAAOtC,QACL,IAAME,oBAAqBoC,cAAAA,MAAO,OAClC;QAACA;KAAI;AAET;AAGA;;;;;CAKC,GACD,OAAO,SAASC,sBACd9B,MAAiC,EACjCC,KAAgC;IAEhC,MAAM,EAAEG,MAAMC,IAAI,EAAE,GAAGjB;IACvB,OAAOC,YACL,CAAC0C,QAA0BC;QACzB,KAAKrC,mBAAmBU,MAAMT,iBAAiBI,QAAQC,QAAQ8B,QAAQC;IACzE,GACA;QAAC3B;QAAML;QAAQC;KAAM;AAEzB;AAEA;;;;;;CAMC,GACD,OAAO,SAASgC,0BACdjC,MAAiC,EACjCC,KAAgC,EAChC4B,GAAc;IAEd,MAAM,EAAEzB,MAAMC,IAAI,EAAE,GAAGjB;IACvB,MAAM8C,OAAO/C,oBAAqB0C,cAAAA,MAAO,UAA6C;IACtF,OAAOxC,YACL,CAAC2C;QACC,IAAI,CAACE,MAAM;QACX,KAAKvC,mBAAmBU,MAAMT,iBAAiBI,QAAQC,QAAQ,iBAAiB+B;IAClF,GACA;QAACE;QAAM7B;QAAML;QAAQC;KAAM;AAE/B"}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
import { type MaybeTokenSource } from '@aglyn/shared-util-http/authorized-token';
|
|
18
|
-
import { type CrmSharingAction, type CrmSharingObject, type CrmSharingResponse } from './crm-sharing';
|
|
18
|
+
import { type CrmDefaultMarkOnlyCollection, type CrmSharingAction, type CrmSharingObject, type CrmSharingResponse } from './crm-sharing';
|
|
19
19
|
import type { CrmTaskRouteScope } from './task-routes';
|
|
20
20
|
/**
|
|
21
21
|
* One call to `crm/sharing` (AGL-3336). Answers the route's body, or throws
|
|
@@ -28,5 +28,8 @@ export declare function callCrmSharing(user: MaybeTokenSource, scope: CrmTaskRou
|
|
|
28
28
|
* record-written seam, and a browser that wrote the record itself asks for
|
|
29
29
|
* the same re-evaluation here. Never throws, and never holds the save — the
|
|
30
30
|
* record is written whether or not a rule then shares it.
|
|
31
|
+
*
|
|
32
|
+
* A logged activity, which no rule applies to, asks the same way for only
|
|
33
|
+
* the CRM default's "All sites except…" marker (AGL-4047).
|
|
31
34
|
*/
|
|
32
|
-
export declare function followUpCrmSharing(user: MaybeTokenSource, scope: CrmTaskRouteScope | null, object: CrmSharingObject, ids: readonly string[]): Promise<void>;
|
|
35
|
+
export declare function followUpCrmSharing(user: MaybeTokenSource, scope: CrmTaskRouteScope | null, object: CrmSharingObject | CrmDefaultMarkOnlyCollection, ids: readonly string[]): Promise<void>;
|
|
@@ -41,6 +41,9 @@ import { CRM_SHARING_IDS_MAX, crmSharingRouteUrl } from "./crm-sharing.js";
|
|
|
41
41
|
* record-written seam, and a browser that wrote the record itself asks for
|
|
42
42
|
* the same re-evaluation here. Never throws, and never holds the save — the
|
|
43
43
|
* record is written whether or not a rule then shares it.
|
|
44
|
+
*
|
|
45
|
+
* A logged activity, which no rule applies to, asks the same way for only
|
|
46
|
+
* the CRM default's "All sites except…" marker (AGL-4047).
|
|
44
47
|
*/ export async function followUpCrmSharing(user, scope, object, ids) {
|
|
45
48
|
const unique = [
|
|
46
49
|
...new Set(ids.filter(Boolean))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/model/crm-sharing-api.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 authorizedFetch,\n type MaybeTokenSource,\n} from '@aglyn/shared-util-http/authorized-token'\nimport {\n CRM_SHARING_IDS_MAX,\n type CrmSharingAction,\n type CrmSharingObject,\n type CrmSharingResponse,\n crmSharingRouteUrl,\n} from './crm-sharing'\nimport type { CrmTaskRouteScope } from './task-routes'\n\n/**\n * One call to `crm/sharing` (AGL-3336). Answers the route's body, or throws\n * with the route's own sentence so a snackbar can say it.\n */\nexport async function callCrmSharing(\n user: MaybeTokenSource,\n scope: CrmTaskRouteScope,\n action: CrmSharingAction,\n body: Record<string, unknown> = {},\n): Promise<CrmSharingResponse> {\n const response = await authorizedFetch(user, crmSharingRouteUrl(), {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ ...scope, ...body, action }),\n })\n const answer = (await response.json().catch(() => ({}))) as Partial<CrmSharingResponse> & {\n error?: string\n }\n if (!response.ok || answer.ok !== true) {\n throw new Error(answer.error || 'The sharing could not be saved.')\n }\n return answer as CrmSharingResponse\n}\n\n/**\n * What a CLIENT-DIRECT write to a lead, a company or a deal owes the org's\n * sharing rules: the server writers are followed by the core's\n * record-written seam, and a browser that wrote the record itself asks for\n * the same re-evaluation here. Never throws, and never holds the save — the\n * record is written whether or not a rule then shares it.\n */\nexport async function followUpCrmSharing(\n user: MaybeTokenSource,\n scope: CrmTaskRouteScope | null,\n object: CrmSharingObject,\n ids: readonly string[],\n): Promise<void> {\n const unique = [...new Set(ids.filter(Boolean))].slice(0, CRM_SHARING_IDS_MAX)\n if (!scope || !unique.length) return\n try {\n await callCrmSharing(user, scope, 'evaluate', { object, ids: unique })\n } catch (error) {\n console.warn('[crm] sharing rules were not re-evaluated', error)\n }\n}\n"],"names":["authorizedFetch","CRM_SHARING_IDS_MAX","crmSharingRouteUrl","callCrmSharing","user","scope","action","body","response","method","headers","JSON","stringify","answer","json","catch","ok","Error","error","followUpCrmSharing","object","ids","unique","Set","filter","Boolean","slice","length","console","warn"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,eAAe,QAEV,2CAA0C;AACjD,SACEC,mBAAmB,
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/model/crm-sharing-api.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 authorizedFetch,\n type MaybeTokenSource,\n} from '@aglyn/shared-util-http/authorized-token'\nimport {\n CRM_SHARING_IDS_MAX,\n type CrmDefaultMarkOnlyCollection,\n type CrmSharingAction,\n type CrmSharingObject,\n type CrmSharingResponse,\n crmSharingRouteUrl,\n} from './crm-sharing'\nimport type { CrmTaskRouteScope } from './task-routes'\n\n/**\n * One call to `crm/sharing` (AGL-3336). Answers the route's body, or throws\n * with the route's own sentence so a snackbar can say it.\n */\nexport async function callCrmSharing(\n user: MaybeTokenSource,\n scope: CrmTaskRouteScope,\n action: CrmSharingAction,\n body: Record<string, unknown> = {},\n): Promise<CrmSharingResponse> {\n const response = await authorizedFetch(user, crmSharingRouteUrl(), {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ ...scope, ...body, action }),\n })\n const answer = (await response.json().catch(() => ({}))) as Partial<CrmSharingResponse> & {\n error?: string\n }\n if (!response.ok || answer.ok !== true) {\n throw new Error(answer.error || 'The sharing could not be saved.')\n }\n return answer as CrmSharingResponse\n}\n\n/**\n * What a CLIENT-DIRECT write to a lead, a company or a deal owes the org's\n * sharing rules: the server writers are followed by the core's\n * record-written seam, and a browser that wrote the record itself asks for\n * the same re-evaluation here. Never throws, and never holds the save — the\n * record is written whether or not a rule then shares it.\n *\n * A logged activity, which no rule applies to, asks the same way for only\n * the CRM default's \"All sites except…\" marker (AGL-4047).\n */\nexport async function followUpCrmSharing(\n user: MaybeTokenSource,\n scope: CrmTaskRouteScope | null,\n object: CrmSharingObject | CrmDefaultMarkOnlyCollection,\n ids: readonly string[],\n): Promise<void> {\n const unique = [...new Set(ids.filter(Boolean))].slice(0, CRM_SHARING_IDS_MAX)\n if (!scope || !unique.length) return\n try {\n await callCrmSharing(user, scope, 'evaluate', { object, ids: unique })\n } catch (error) {\n console.warn('[crm] sharing rules were not re-evaluated', error)\n }\n}\n"],"names":["authorizedFetch","CRM_SHARING_IDS_MAX","crmSharingRouteUrl","callCrmSharing","user","scope","action","body","response","method","headers","JSON","stringify","answer","json","catch","ok","Error","error","followUpCrmSharing","object","ids","unique","Set","filter","Boolean","slice","length","console","warn"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,eAAe,QAEV,2CAA0C;AACjD,SACEC,mBAAmB,EAKnBC,kBAAkB,QACb,mBAAe;AAGtB;;;CAGC,GACD,OAAO,eAAeC,eACpBC,IAAsB,EACtBC,KAAwB,EACxBC,MAAwB,EACxBC,OAAgC,CAAC,CAAC;IAElC,MAAMC,WAAW,MAAMR,gBAAgBI,MAAMF,sBAAsB;QACjEO,QAAQ;QACRC,SAAS;YAAE,gBAAgB;QAAmB;QAC9CH,MAAMI,KAAKC,SAAS,CAAC,aAAKP,OAAUE;YAAMD;;IAC5C;IACA,MAAMO,SAAU,MAAML,SAASM,IAAI,GAAGC,KAAK,CAAC,IAAO,CAAA,CAAC,CAAA;IAGpD,IAAI,CAACP,SAASQ,EAAE,IAAIH,OAAOG,EAAE,KAAK,MAAM;QACtC,MAAM,IAAIC,MAAMJ,OAAOK,KAAK,IAAI;IAClC;IACA,OAAOL;AACT;AAEA;;;;;;;;;CASC,GACD,OAAO,eAAeM,mBACpBf,IAAsB,EACtBC,KAA+B,EAC/Be,MAAuD,EACvDC,GAAsB;IAEtB,MAAMC,SAAS;WAAI,IAAIC,IAAIF,IAAIG,MAAM,CAACC;KAAU,CAACC,KAAK,CAAC,GAAGzB;IAC1D,IAAI,CAACI,SAAS,CAACiB,OAAOK,MAAM,EAAE;IAC9B,IAAI;QACF,MAAMxB,eAAeC,MAAMC,OAAO,YAAY;YAAEe;YAAQC,KAAKC;QAAO;IACtE,EAAE,OAAOJ,OAAO;QACdU,QAAQC,IAAI,CAAC,6CAA6CX;IAC5D;AACF"}
|
|
@@ -55,8 +55,23 @@
|
|
|
55
55
|
* own field, `writeTo`, present only on a shared record: the held tokens
|
|
56
56
|
* and the tokens of grants whose access is `edit`. The Firestore rules and
|
|
57
57
|
* the CRM's routes check it; a read-only grant is the default.
|
|
58
|
+
*
|
|
59
|
+
* ## All sites except some (AGL-4047)
|
|
60
|
+
*
|
|
61
|
+
* A grant or a rule can share with every site but the ones it leaves out:
|
|
62
|
+
* `except` beside `tokens` (a rule's `targets`). Readers still enforce one
|
|
63
|
+
* flat list, so the grant's `tokens` are the sites it reaches, worked out
|
|
64
|
+
* from the workspace's sites every time the record's sharing is recomputed,
|
|
65
|
+
* and a site added later joins on the next recompute, which the workspace's
|
|
66
|
+
* own site change starts (`server/crm-sharing-runs.ts`). `planRecordSharing`
|
|
67
|
+
* reads `tokens` as it always has, so `visibleTo`, `added` and `writeTo` come
|
|
68
|
+
* out the same way. A site left out that captured the person still holds
|
|
69
|
+
* them: held tokens are never a grant's to take away. One grant reaches at
|
|
70
|
+
* most {@link CRM_SHARING_MAX_INCLUDED} sites, since a record's search fields
|
|
71
|
+
* grow by site; past that it keeps the sites it has and stops widening.
|
|
58
72
|
*/
|
|
59
73
|
import type { ScopeToken } from '@aglyn/aglyn';
|
|
74
|
+
import { type ScopeSharingChoice } from '@aglyn/aglyn/app-utils/scope-tokens';
|
|
60
75
|
import type { CrmPicklist } from '@aglyn/aglyn/app-utils/crm';
|
|
61
76
|
/** The four record types a share or a rule applies to, by their collection. */
|
|
62
77
|
export declare const CRM_SHARING_OBJECTS: readonly ["leads", "contacts", "companies", "deals"];
|
|
@@ -75,8 +90,17 @@ export type CrmShareSource = 'manual' | 'rule';
|
|
|
75
90
|
/** One grant on one record. */
|
|
76
91
|
export interface CrmShareGrant {
|
|
77
92
|
source: CrmShareSource;
|
|
78
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* The sites it shares with: `['org']` for all sites, else host tokens. For
|
|
95
|
+
* a grant with `except`, the sites it reached when last worked out.
|
|
96
|
+
*/
|
|
79
97
|
tokens: ScopeToken[];
|
|
98
|
+
/**
|
|
99
|
+
* Present on a grant shared with all sites except some (AGL-4047): the
|
|
100
|
+
* sites it leaves out, as host tokens. `tokens` follows the workspace's
|
|
101
|
+
* sites, so a site added later joins.
|
|
102
|
+
*/
|
|
103
|
+
except?: ScopeToken[];
|
|
80
104
|
access: CrmShareAccess;
|
|
81
105
|
/** The rule behind a `rule` grant. */
|
|
82
106
|
ruleId?: string;
|
|
@@ -103,6 +127,12 @@ export interface CrmRecordSharing {
|
|
|
103
127
|
* since a query takes a single array clause.
|
|
104
128
|
*/
|
|
105
129
|
orgWideHeldBy: ScopeToken[];
|
|
130
|
+
/**
|
|
131
|
+
* `true` while any grant shares with all sites except some (AGL-4047), so
|
|
132
|
+
* a change to the workspace's sites can find the records to bring level
|
|
133
|
+
* ({@link CRM_SHARING_EXCEPT_PATH}). Absent otherwise.
|
|
134
|
+
*/
|
|
135
|
+
hasExcept?: true;
|
|
106
136
|
}
|
|
107
137
|
/** The record field its grants live under — the core's name for it. */
|
|
108
138
|
export declare const CRM_SHARING_FIELD = "sharing";
|
|
@@ -110,6 +140,16 @@ export declare const CRM_SHARING_FIELD = "sharing";
|
|
|
110
140
|
export declare const CRM_WRITE_SCOPE_FIELD = "writeTo";
|
|
111
141
|
/** The array field a rule's removal queries. */
|
|
112
142
|
export declare const CRM_SHARING_RULE_IDS_PATH = "sharing.ruleIds";
|
|
143
|
+
/** The field a site change queries for records with an all-except grant (AGL-4047). */
|
|
144
|
+
export declare const CRM_SHARING_EXCEPT_PATH = "sharing.hasExcept";
|
|
145
|
+
/**
|
|
146
|
+
* The most sites one all-except grant reaches (AGL-4047). A record's scoped
|
|
147
|
+
* search fields grow by site (`scopedSearchTokens`), so past this the grant
|
|
148
|
+
* keeps the sites it has and stops widening, and a new share is refused.
|
|
149
|
+
*/
|
|
150
|
+
export declare const CRM_SHARING_MAX_INCLUDED = 30;
|
|
151
|
+
/** The key of a record's one hand share with all sites except some. */
|
|
152
|
+
export declare const MANUAL_EXCEPT_GRANT_KEY = "manual_except";
|
|
113
153
|
/** A hand share is one grant per target, so each is unshared on its own. */
|
|
114
154
|
export declare function manualGrantKey(token: string): string;
|
|
115
155
|
export declare function ruleGrantKey(ruleId: string): string;
|
|
@@ -202,8 +242,17 @@ export interface CrmSharingRule {
|
|
|
202
242
|
/** Records captured or created on any of these sites; empty is every site. */
|
|
203
243
|
sourceHostIds: string[];
|
|
204
244
|
criteria: CrmSharingCriteria;
|
|
205
|
-
/**
|
|
245
|
+
/**
|
|
246
|
+
* `['org']` for all sites, including sites added later; else host tokens.
|
|
247
|
+
* For a rule with `except`, the sites it reached when it was saved.
|
|
248
|
+
*/
|
|
206
249
|
targets: ScopeToken[];
|
|
250
|
+
/**
|
|
251
|
+
* Present on a rule that shares with all sites except some (AGL-4047): the
|
|
252
|
+
* sites it leaves out, as host tokens. Its grants follow the workspace's
|
|
253
|
+
* sites, so a site added later joins.
|
|
254
|
+
*/
|
|
255
|
+
except?: ScopeToken[];
|
|
207
256
|
access: CrmShareAccess;
|
|
208
257
|
/** Being deleted: its grants are being removed, and it matches nothing. */
|
|
209
258
|
deleting?: boolean;
|
|
@@ -225,6 +274,28 @@ export declare function activeSharingRules(rules: readonly CrmSharingRule[], obj
|
|
|
225
274
|
export declare function normalizeShareTargets(tokens: readonly string[]): ScopeToken[] | null;
|
|
226
275
|
/** Targets from a request: `'all'`, or a list of host ids. */
|
|
227
276
|
export declare function shareTargetsFrom(input: unknown): ScopeToken[] | null;
|
|
277
|
+
/**
|
|
278
|
+
* All sites except some, from a request (AGL-4047):
|
|
279
|
+
* `{ mode: 'allExcept', exceptHostIds }`, or null when the input is not that
|
|
280
|
+
* choice. Whether the sites are the workspace's, and what the choice reaches,
|
|
281
|
+
* is `sharingFromChoice`'s to answer against the workspace's sites.
|
|
282
|
+
*/
|
|
283
|
+
export declare function shareExceptChoiceFrom(input: unknown): Extract<ScopeSharingChoice, {
|
|
284
|
+
mode: 'allExcept';
|
|
285
|
+
}> | null;
|
|
286
|
+
/**
|
|
287
|
+
* The sites `orgs/{orgId}.hosts` names: the list the sweep keeps every
|
|
288
|
+
* all-except document level with (`orgHostIdsFromDoc`), read the same way
|
|
289
|
+
* here so the CRM's grants and the sweep never disagree about a site.
|
|
290
|
+
*/
|
|
291
|
+
export declare function crmOrgHostIds(org: Readonly<Record<string, unknown>> | null | undefined): string[];
|
|
292
|
+
/**
|
|
293
|
+
* The sites an all-except grant reaches (AGL-4047): the workspace's sites
|
|
294
|
+
* less the ones it leaves out, sorted. `orgHostIds` unknown keeps what the
|
|
295
|
+
* grant reached last. Past {@link CRM_SHARING_MAX_INCLUDED} it stops
|
|
296
|
+
* widening: it keeps the sites it reached that are still the workspace's.
|
|
297
|
+
*/
|
|
298
|
+
export declare function sitesAllExcept(except: readonly string[], orgHostIds: readonly string[] | null | undefined, previous: readonly string[]): ScopeToken[];
|
|
228
299
|
export interface CrmSharingFacts {
|
|
229
300
|
hostIds: string[];
|
|
230
301
|
leadSources: string[];
|
|
@@ -247,6 +318,12 @@ export declare function crmSharingFacts(object: CrmSharingObject, record: Readon
|
|
|
247
318
|
*/
|
|
248
319
|
export interface CrmSharingContext {
|
|
249
320
|
leadSources?: CrmPicklist;
|
|
321
|
+
/**
|
|
322
|
+
* The workspace's sites (`orgs/{orgId}.hosts`), which an all-except grant
|
|
323
|
+
* reaches less the ones it leaves out (AGL-4047). Absent, such a grant keeps
|
|
324
|
+
* the sites it reached last.
|
|
325
|
+
*/
|
|
326
|
+
orgHostIds?: readonly string[];
|
|
250
327
|
}
|
|
251
328
|
/** Whether any active rule for `object` asks a lead source direction — whether the list must be read. */
|
|
252
329
|
export declare function sharingRulesAskLeadSourceDirection(rules: readonly CrmSharingRule[], object: CrmSharingObject): boolean;
|
|
@@ -262,11 +339,31 @@ export declare function crmSharingRuleMatches(rule: CrmSharingRule, object: CrmS
|
|
|
262
339
|
* switched off or deleted.
|
|
263
340
|
*/
|
|
264
341
|
export declare function evaluateRecordGrants(object: CrmSharingObject, record: Readonly<Record<string, unknown>>, rules: readonly CrmSharingRule[], atMs: number, context?: CrmSharingContext): Record<string, CrmShareGrant>;
|
|
342
|
+
/**
|
|
343
|
+
* Whether working out this record's sharing needs the workspace's sites: a
|
|
344
|
+
* grant on it, or an active rule for its kind, leaves sites out (AGL-4047).
|
|
345
|
+
* Everything else plans from the record and the rules alone.
|
|
346
|
+
*/
|
|
347
|
+
export declare function sharingAsksOrgSites(object: CrmSharingObject, record: Readonly<Record<string, unknown>>, rules: readonly CrmSharingRule[]): boolean;
|
|
265
348
|
/** The hand shares after sharing with `targets`, by `by`. */
|
|
266
349
|
export declare function withManualShares(grants: Readonly<Record<string, CrmShareGrant>>, targets: readonly ScopeToken[], access: CrmShareAccess, by: {
|
|
267
350
|
uid: string;
|
|
268
351
|
name?: string | null;
|
|
269
352
|
}, atMs: number): Record<string, CrmShareGrant>;
|
|
353
|
+
/**
|
|
354
|
+
* The hand shares after sharing with all sites except some (AGL-4047): one
|
|
355
|
+
* grant, {@link MANUAL_EXCEPT_GRANT_KEY}, replacing any earlier one. `tokens`
|
|
356
|
+
* are the sites it reaches today.
|
|
357
|
+
*/
|
|
358
|
+
export declare function withManualExceptShare(grants: Readonly<Record<string, CrmShareGrant>>, share: {
|
|
359
|
+
tokens: readonly ScopeToken[];
|
|
360
|
+
except: readonly ScopeToken[];
|
|
361
|
+
}, access: CrmShareAccess, by: {
|
|
362
|
+
uid: string;
|
|
363
|
+
name?: string | null;
|
|
364
|
+
}, atMs: number): Record<string, CrmShareGrant>;
|
|
365
|
+
/** The hand shares after taking away the share with all sites except some. */
|
|
366
|
+
export declare function withoutManualExceptShare(grants: Readonly<Record<string, CrmShareGrant>>): Record<string, CrmShareGrant>;
|
|
270
367
|
/** The hand shares after unsharing `targets`. Rule grants are the rule's to take away. */
|
|
271
368
|
export declare function withoutManualShares(grants: Readonly<Record<string, CrmShareGrant>>, targets: readonly string[]): Record<string, CrmShareGrant>;
|
|
272
369
|
/**
|
|
@@ -305,11 +402,22 @@ export type CrmSharingLine = {
|
|
|
305
402
|
access: CrmShareAccess;
|
|
306
403
|
byName?: string;
|
|
307
404
|
atMs: number;
|
|
405
|
+
} | {
|
|
406
|
+
/** A hand share with all sites except some (AGL-4047). */
|
|
407
|
+
kind: 'manualExcept';
|
|
408
|
+
key: string;
|
|
409
|
+
tokens: ScopeToken[];
|
|
410
|
+
except: ScopeToken[];
|
|
411
|
+
access: CrmShareAccess;
|
|
412
|
+
byName?: string;
|
|
413
|
+
atMs: number;
|
|
308
414
|
} | {
|
|
309
415
|
kind: 'rule';
|
|
310
416
|
key: string;
|
|
311
417
|
ruleId: string;
|
|
312
418
|
tokens: ScopeToken[];
|
|
419
|
+
/** The sites a rule shares with all but (AGL-4047). */
|
|
420
|
+
except?: ScopeToken[];
|
|
313
421
|
access: CrmShareAccess;
|
|
314
422
|
atMs: number;
|
|
315
423
|
};
|
|
@@ -319,8 +427,12 @@ export type CrmSharingLine = {
|
|
|
319
427
|
* rule. The held line is never unsharable; a hand share is, in one click.
|
|
320
428
|
*/
|
|
321
429
|
export declare function describeRecordSharing(record: Readonly<Record<string, unknown>> | null | undefined): CrmSharingLine[];
|
|
322
|
-
/**
|
|
323
|
-
|
|
430
|
+
/**
|
|
431
|
+
* "All sites", a site's name, or "N sites"; for a share with all sites except
|
|
432
|
+
* some (AGL-4047), "All sites except Blog", "All sites except Blog and Shop"
|
|
433
|
+
* or "All sites except 3 sites".
|
|
434
|
+
*/
|
|
435
|
+
export declare function describeShareTargets(tokens: readonly string[], siteName: (hostId: string) => string, except?: readonly string[] | null): string;
|
|
324
436
|
/** A rule as one sentence of its "which records" half. */
|
|
325
437
|
export declare function describeSharingRuleScope(rule: Pick<CrmSharingRule, 'object' | 'sourceHostIds' | 'criteria'>, siteName: (hostId: string) => string, labels?: {
|
|
326
438
|
owner?: (uid: string) => string;
|
|
@@ -331,7 +443,7 @@ export declare const CRM_SHARING_ROUTE: "crm/sharing";
|
|
|
331
443
|
export declare const crmSharingRouteUrl: () => string;
|
|
332
444
|
/** Records one share or unshare may name. */
|
|
333
445
|
export declare const CRM_SHARING_IDS_MAX = 200;
|
|
334
|
-
export type CrmSharingAction = 'sites' | 'share' | 'unshare' | 'evaluate' | 'rule-save' | 'rule-delete' | 'rule-continue';
|
|
446
|
+
export type CrmSharingAction = 'sites' | 'share' | 'unshare' | 'evaluate' | 'rule-save' | 'rule-delete' | 'rule-continue' | 'default-apply' | 'default-apply-continue';
|
|
335
447
|
export interface CrmSharingSite {
|
|
336
448
|
id: string;
|
|
337
449
|
name: string;
|
|
@@ -348,4 +460,40 @@ export interface CrmSharingResponse {
|
|
|
348
460
|
rule?: CrmSharingRule | null;
|
|
349
461
|
/** Whether a rule run has more to do (`rule-continue` again). */
|
|
350
462
|
more?: boolean;
|
|
463
|
+
/** `default-apply`: where the "Apply to existing records" run stands. */
|
|
464
|
+
applyRun?: CrmDefaultApplyRun | null;
|
|
465
|
+
}
|
|
466
|
+
/** The collections the run walks, in order: the cursor names a place in this list. */
|
|
467
|
+
export declare const CRM_DEFAULT_APPLY_COLLECTIONS: readonly ["contacts", "leads", "companies", "deals", "crmTasks", "crmActivities"];
|
|
468
|
+
export type CrmDefaultApplyCollection = (typeof CRM_DEFAULT_APPLY_COLLECTIONS)[number];
|
|
469
|
+
export declare function isCrmDefaultApplyCollection(value: unknown): value is CrmDefaultApplyCollection;
|
|
470
|
+
/**
|
|
471
|
+
* What a browser writes itself that no sharing rule applies to, yet the CRM
|
|
472
|
+
* default "All sites except…" stamps: a logged activity. Its `evaluate`
|
|
473
|
+
* follow-up only marks it, when its sites are exactly the default's, so a
|
|
474
|
+
* site added later sees it (AGL-4047).
|
|
475
|
+
*/
|
|
476
|
+
export declare const CRM_DEFAULT_MARK_ONLY_COLLECTIONS: readonly ["crmActivities"];
|
|
477
|
+
export type CrmDefaultMarkOnlyCollection = (typeof CRM_DEFAULT_MARK_ONLY_COLLECTIONS)[number];
|
|
478
|
+
export declare function isCrmDefaultMarkOnlyCollection(value: unknown): value is CrmDefaultMarkOnlyCollection;
|
|
479
|
+
/** Where the run's progress is mirrored on the org document, for the settings card. */
|
|
480
|
+
export declare const CRM_DEFAULT_APPLY_RUN_PATH = "crm.defaultApplyRun";
|
|
481
|
+
export interface CrmDefaultApplyRun {
|
|
482
|
+
status: 'running' | 'done' | 'failed';
|
|
483
|
+
/** Records read. */
|
|
484
|
+
processed: number;
|
|
485
|
+
/** Records whose sites moved. */
|
|
486
|
+
changed: number;
|
|
487
|
+
/** Records it would take past the site limit, left as they were. */
|
|
488
|
+
capped: number;
|
|
489
|
+
/** Where it carries on from. */
|
|
490
|
+
cursor: {
|
|
491
|
+
collection: CrmDefaultApplyCollection;
|
|
492
|
+
afterId: string | null;
|
|
493
|
+
} | null;
|
|
494
|
+
startedAtMs: number;
|
|
495
|
+
finishedAtMs?: number;
|
|
496
|
+
error?: string;
|
|
351
497
|
}
|
|
498
|
+
/** The run as the org document mirrors it, cleaned; null when none was ever started. */
|
|
499
|
+
export declare function readCrmDefaultApplyRun(org: Readonly<Record<string, unknown>> | null | undefined): CrmDefaultApplyRun | null;
|