@aglyn/plugins-crm 1.0.0-beta.217 → 1.0.0-beta.219
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 -13
- package/src/index.d.ts +1 -0
- package/src/index.js.map +1 -1
- package/src/lib/components/companies-bulk-bar.js +12 -4
- package/src/lib/components/companies-bulk-bar.js.map +1 -1
- package/src/lib/components/company-detail-page.js +11 -0
- package/src/lib/components/company-detail-page.js.map +1 -1
- package/src/lib/components/company-edit-drawer.js +12 -2
- package/src/lib/components/company-edit-drawer.js.map +1 -1
- package/src/lib/components/company-import-drawer.d.ts +1 -1
- package/src/lib/components/company-picker.js +10 -3
- package/src/lib/components/company-picker.js.map +1 -1
- package/src/lib/components/contact-detail-page.d.ts +4 -4
- package/src/lib/components/contact-detail-page.js +50 -53
- package/src/lib/components/contact-detail-page.js.map +1 -1
- package/src/lib/components/contact-list-columns.d.ts +3 -0
- package/src/lib/components/contact-list-columns.js +21 -5
- package/src/lib/components/contact-list-columns.js.map +1 -1
- package/src/lib/components/contact-merge-dialog.js +2 -1
- package/src/lib/components/contact-merge-dialog.js.map +1 -1
- package/src/lib/components/contact-timeline-card.js +4 -3
- package/src/lib/components/contact-timeline-card.js.map +1 -1
- package/src/lib/components/contacts-bulk-bar.d.ts +3 -3
- package/src/lib/components/contacts-bulk-bar.js +24 -51
- package/src/lib/components/contacts-bulk-bar.js.map +1 -1
- package/src/lib/components/contacts-section.js +9 -3
- package/src/lib/components/contacts-section.js.map +1 -1
- package/src/lib/components/crm-export-all-button.d.ts +1 -1
- package/src/lib/components/crm-export-all-button.js.map +1 -1
- package/src/lib/components/crm-send-email-dialog.js +9 -6
- package/src/lib/components/crm-send-email-dialog.js.map +1 -1
- package/src/lib/components/csv-import-drawer.js +2 -2
- package/src/lib/components/csv-import-drawer.js.map +1 -1
- package/src/lib/components/deal-detail-page.js +18 -2
- package/src/lib/components/deal-detail-page.js.map +1 -1
- package/src/lib/components/deal-edit-drawer.js +10 -0
- package/src/lib/components/deal-edit-drawer.js.map +1 -1
- package/src/lib/components/deals-bulk-bar.js +13 -5
- package/src/lib/components/deals-bulk-bar.js.map +1 -1
- package/src/lib/components/lead-campaigns-card.js +6 -0
- package/src/lib/components/lead-campaigns-card.js.map +1 -1
- package/src/lib/components/lead-detail-page.js +25 -5
- package/src/lib/components/lead-detail-page.js.map +1 -1
- package/src/lib/components/lead-properties-card.js +6 -0
- package/src/lib/components/lead-properties-card.js.map +1 -1
- package/src/lib/components/lead-surfaces-note.js +4 -5
- package/src/lib/components/lead-surfaces-note.js.map +1 -1
- package/src/lib/components/lead-unqualify-dialog.js +6 -0
- package/src/lib/components/lead-unqualify-dialog.js.map +1 -1
- package/src/lib/components/leads-bulk-bar.js +28 -3
- package/src/lib/components/leads-bulk-bar.js.map +1 -1
- package/src/lib/components/leads-section.js +36 -7
- package/src/lib/components/leads-section.js.map +1 -1
- package/src/lib/components/org-lead-surfaces-note.js +6 -2
- package/src/lib/components/org-lead-surfaces-note.js.map +1 -1
- package/src/lib/components/recipes-card.js +9 -4
- package/src/lib/components/recipes-card.js.map +1 -1
- package/src/lib/components/record-sharing-card.d.ts +57 -0
- package/src/lib/components/record-sharing-card.js +244 -0
- package/src/lib/components/record-sharing-card.js.map +1 -0
- package/src/lib/components/settings-section.js +7 -0
- package/src/lib/components/settings-section.js.map +1 -1
- package/src/lib/components/share-records-dialog.d.ts +28 -0
- package/src/lib/components/share-records-dialog.js +184 -0
- package/src/lib/components/share-records-dialog.js.map +1 -0
- package/src/lib/components/sharing-rule-drawer.d.ts +37 -0
- package/src/lib/components/sharing-rule-drawer.js +374 -0
- package/src/lib/components/sharing-rule-drawer.js.map +1 -0
- package/src/lib/components/sharing-rules-card.d.ts +24 -0
- package/src/lib/components/sharing-rules-card.js +287 -0
- package/src/lib/components/sharing-rules-card.js.map +1 -0
- package/src/lib/components/use-crm-api.d.ts +1 -1
- package/src/lib/components/use-crm-api.js.map +1 -1
- package/src/lib/components/use-site-route-context.d.ts +25 -0
- package/src/lib/components/use-site-route-context.js +58 -0
- package/src/lib/components/use-site-route-context.js.map +1 -0
- package/src/lib/constants/api-routes.d.ts +31 -0
- package/src/lib/constants/api-routes.js +27 -1
- package/src/lib/constants/api-routes.js.map +1 -1
- package/src/lib/declarations.console-server.d.ts +37 -0
- package/src/lib/declarations.console-server.js +103 -0
- package/src/lib/declarations.console-server.js.map +1 -0
- package/src/lib/declarations.server.d.ts +6 -0
- package/src/lib/declarations.server.js +33 -0
- package/src/lib/declarations.server.js.map +1 -1
- package/src/lib/hooks/use-contact-remove.d.ts +35 -0
- package/src/lib/hooks/use-contact-remove.js +77 -0
- package/src/lib/hooks/use-contact-remove.js.map +1 -0
- package/src/lib/hooks/use-crm-sharing.d.ts +30 -0
- package/src/lib/hooks/use-crm-sharing.js +109 -0
- package/src/lib/hooks/use-crm-sharing.js.map +1 -0
- package/src/lib/model/companies-csv.d.ts +1 -1
- package/src/lib/model/companies-csv.js +2 -2
- package/src/lib/model/companies-csv.js.map +1 -1
- package/src/lib/model/contact-holder.d.ts +68 -0
- package/src/lib/model/contact-holder.js +129 -0
- package/src/lib/model/contact-holder.js.map +1 -0
- package/src/lib/model/contact-interaction-links.d.ts +46 -0
- package/src/lib/model/contact-interaction-links.js +65 -0
- package/src/lib/model/contact-interaction-links.js.map +1 -0
- package/src/lib/model/contact-merge.d.ts +136 -0
- package/src/lib/model/contact-merge.js +412 -0
- package/src/lib/model/contact-merge.js.map +1 -0
- package/src/lib/model/contact-record.d.ts +7 -1
- package/src/lib/model/contact-record.js +6 -5
- package/src/lib/model/contact-record.js.map +1 -1
- package/src/lib/model/contact-remove.d.ts +48 -0
- package/src/lib/model/contact-remove.js +22 -0
- package/src/lib/model/contact-remove.js.map +1 -0
- package/src/lib/model/contacts-bulk-writes.d.ts +2 -71
- package/src/lib/model/contacts-bulk-writes.js +2 -82
- package/src/lib/model/contacts-bulk-writes.js.map +1 -1
- package/src/lib/model/contacts-csv.d.ts +2 -2
- package/src/lib/model/contacts-csv.js +2 -2
- package/src/lib/model/contacts-csv.js.map +1 -1
- package/src/lib/model/crm-csv.d.ts +239 -0
- package/src/lib/model/crm-csv.js +467 -0
- package/src/lib/model/crm-csv.js.map +1 -0
- package/src/lib/model/crm-digest.d.ts +185 -0
- package/src/lib/model/crm-digest.js +272 -0
- package/src/lib/model/crm-digest.js.map +1 -0
- package/src/lib/model/crm-import.d.ts +7 -1
- package/src/lib/model/crm-import.js +2 -1
- package/src/lib/model/crm-import.js.map +1 -1
- package/src/lib/model/crm-record-routes.d.ts +5 -0
- package/src/lib/model/crm-record-routes.js +7 -0
- package/src/lib/model/crm-record-routes.js.map +1 -1
- package/src/lib/model/crm-routes.d.ts +6 -5
- package/src/lib/model/crm-routes.js +7 -7
- package/src/lib/model/crm-routes.js.map +1 -1
- package/src/lib/model/crm-search-sources.d.ts +15 -0
- package/src/lib/model/crm-search-sources.js +162 -0
- package/src/lib/model/crm-search-sources.js.map +1 -0
- package/src/lib/model/crm-sharing-api.d.ts +32 -0
- package/src/lib/model/crm-sharing-api.js +59 -0
- package/src/lib/model/crm-sharing-api.js.map +1 -0
- package/src/lib/model/crm-sharing.d.ts +333 -0
- package/src/lib/model/crm-sharing.js +603 -0
- package/src/lib/model/crm-sharing.js.map +1 -0
- package/src/lib/model/deals-csv.d.ts +1 -1
- package/src/lib/model/deals-csv.js +4 -5
- package/src/lib/model/deals-csv.js.map +1 -1
- package/src/lib/model/lead-filters.d.ts +1 -1
- package/src/lib/model/leads-csv.d.ts +1 -1
- package/src/lib/model/leads-csv.js +1 -1
- package/src/lib/model/leads-csv.js.map +1 -1
- package/src/lib/model/tasks-csv.d.ts +1 -1
- package/src/lib/model/tasks-csv.js +1 -1
- package/src/lib/model/tasks-csv.js.map +1 -1
- package/src/lib/plan-entitlements.d.ts +75 -0
- package/src/lib/plan-entitlements.js +56 -0
- package/src/lib/plan-entitlements.js.map +1 -0
- package/src/lib/plugin.js +3 -0
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/server/api-v1/contacts-merge.d.ts +20 -0
- package/src/lib/server/api-v1/contacts-merge.js +120 -0
- package/src/lib/server/api-v1/contacts-merge.js.map +1 -0
- package/src/lib/server/api-v1/contacts.d.ts +18 -0
- package/src/lib/server/api-v1/contacts.js +1076 -0
- package/src/lib/server/api-v1/contacts.js.map +1 -0
- package/src/lib/server/api-v1/crm-activities.d.ts +18 -0
- package/src/lib/server/api-v1/crm-activities.js +269 -0
- package/src/lib/server/api-v1/crm-activities.js.map +1 -0
- package/src/lib/server/api-v1/crm-companies.d.ts +18 -0
- package/src/lib/server/api-v1/crm-companies.js +391 -0
- package/src/lib/server/api-v1/crm-companies.js.map +1 -0
- package/src/lib/server/api-v1/crm-deals.d.ts +18 -0
- package/src/lib/server/api-v1/crm-deals.js +631 -0
- package/src/lib/server/api-v1/crm-deals.js.map +1 -0
- package/src/lib/server/api-v1/crm-email-templates.d.ts +18 -0
- package/src/lib/server/api-v1/crm-email-templates.js +336 -0
- package/src/lib/server/api-v1/crm-email-templates.js.map +1 -0
- package/src/lib/server/api-v1/crm-leads.d.ts +18 -0
- package/src/lib/server/api-v1/crm-leads.js +832 -0
- package/src/lib/server/api-v1/crm-leads.js.map +1 -0
- package/src/lib/server/api-v1/crm-pipelines.d.ts +76 -0
- package/src/lib/server/api-v1/crm-pipelines.js +146 -0
- package/src/lib/server/api-v1/crm-pipelines.js.map +1 -0
- package/src/lib/server/api-v1/crm-shared.d.ts +271 -0
- package/src/lib/server/api-v1/crm-shared.js +436 -0
- package/src/lib/server/api-v1/crm-shared.js.map +1 -0
- package/src/lib/server/api-v1/crm-tasks.d.ts +18 -0
- package/src/lib/server/api-v1/crm-tasks.js +398 -0
- package/src/lib/server/api-v1/crm-tasks.js.map +1 -0
- package/src/lib/server/api-v1/openapi.d.ts +29 -0
- package/src/lib/server/api-v1/openapi.js +985 -0
- package/src/lib/server/api-v1/openapi.js.map +1 -0
- package/src/lib/server/api-v1/usage.d.ts +26 -0
- package/src/lib/server/api-v1/usage.js +73 -0
- package/src/lib/server/api-v1/usage.js.map +1 -0
- package/src/lib/server/consent-group-participant.js +1 -1
- package/src/lib/server/consent-group-participant.js.map +1 -1
- package/src/lib/server/contact-lifecycle-floor.d.ts +89 -0
- package/src/lib/server/contact-lifecycle-floor.js +91 -0
- package/src/lib/server/contact-lifecycle-floor.js.map +1 -0
- package/src/lib/server/contact-remove.d.ts +75 -0
- package/src/lib/server/contact-remove.js +244 -0
- package/src/lib/server/contact-remove.js.map +1 -0
- package/src/lib/server/contact-update.js +2 -1
- package/src/lib/server/contact-update.js.map +1 -1
- package/src/lib/server/contacts-import.d.ts +47 -11
- package/src/lib/server/contacts-import.js +171 -71
- package/src/lib/server/contacts-import.js.map +1 -1
- package/src/lib/server/contacts-merge.d.ts +1 -1
- package/src/lib/server/contacts-merge.js +3 -2
- package/src/lib/server/contacts-merge.js.map +1 -1
- package/src/lib/server/convert-host-lead.d.ts +189 -0
- package/src/lib/server/convert-host-lead.js +518 -0
- package/src/lib/server/convert-host-lead.js.map +1 -0
- package/src/lib/server/crm-sharing.d.ts +108 -0
- package/src/lib/server/crm-sharing.js +790 -0
- package/src/lib/server/crm-sharing.js.map +1 -0
- package/src/lib/server/daily-digest-route.d.ts +107 -0
- package/src/lib/server/daily-digest-route.js +588 -0
- package/src/lib/server/daily-digest-route.js.map +1 -0
- package/src/lib/server/export-route.d.ts +60 -0
- package/src/lib/server/export-route.js +447 -0
- package/src/lib/server/export-route.js.map +1 -0
- package/src/lib/server/inbound-route.d.ts +74 -0
- package/src/lib/server/inbound-route.js +257 -0
- package/src/lib/server/inbound-route.js.map +1 -0
- package/src/lib/server/lead-convert.d.ts +1 -1
- package/src/lib/server/lead-convert.js +2 -2
- package/src/lib/server/lead-convert.js.map +1 -1
- package/src/lib/server/merge-contacts.d.ts +55 -0
- package/src/lib/server/merge-contacts.js +274 -0
- package/src/lib/server/merge-contacts.js.map +1 -0
- package/src/lib/server/pipeline-record-index.d.ts +36 -0
- package/src/lib/server/pipeline-record-index.js +87 -0
- package/src/lib/server/pipeline-record-index.js.map +1 -0
- package/src/lib/server/record-facts.js +2 -1
- package/src/lib/server/record-facts.js.map +1 -1
- package/src/lib/server/task-reminders-route.d.ts +82 -0
- package/src/lib/server/task-reminders-route.js +497 -0
- package/src/lib/server/task-reminders-route.js.map +1 -0
- package/src/lib/server-deal-stage.js +2 -1
- package/src/lib/server-deal-stage.js.map +1 -1
- package/src/lib/server.d.ts +5 -2
- package/src/lib/server.js +47 -2
- package/src/lib/server.js.map +1 -1
- package/src/lib/testing/stand-in-site-record-routes.d.ts +26 -0
- package/src/lib/testing/stand-in-site-record-routes.js +55 -0
- package/src/lib/testing/stand-in-site-record-routes.js.map +1 -0
- package/src/lib/usage-axes.d.ts +35 -0
- package/src/lib/usage-axes.js +68 -0
- package/src/lib/usage-axes.js.map +1 -0
- package/src/lib/components/use-emails-hub-path.d.ts +0 -24
- package/src/lib/components/use-emails-hub-path.js +0 -59
- package/src/lib/components/use-emails-hub-path.js.map +0 -1
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* CRM SHARING FOR MULTI-BRAND ORGS (AGL-3336).
|
|
19
|
+
*
|
|
20
|
+
* An org manager shares a lead, a contact, a company or a deal with other
|
|
21
|
+
* sites — by hand, from the record or a list's bulk bar, or by a SHARING
|
|
22
|
+
* RULE that applies to every record it matches, now and later. The model is
|
|
23
|
+
* Salesforce's three layers:
|
|
24
|
+
*
|
|
25
|
+
* 1. the org-wide default — the consent-group scope a record is captured
|
|
26
|
+
* with (`consentGroupScope`), untouched by anything here;
|
|
27
|
+
* 2. sharing rules — `crm.sharingRules` on the org document;
|
|
28
|
+
* 3. manual shares — per record, per target.
|
|
29
|
+
*
|
|
30
|
+
* ## One field is enforced, so one field is widened
|
|
31
|
+
*
|
|
32
|
+
* Both enforcement layers read `visibleTo`: the rules with `hasAny`, every
|
|
33
|
+
* list with `array-contains-any`. A share therefore ADDS its tokens to
|
|
34
|
+
* `visibleTo`, which is what puts the record on the target site's lists as a
|
|
35
|
+
* real query — no second field, no second index, no loaded-window match.
|
|
36
|
+
* `'org'` is the token for "all sites", and it covers a site created later
|
|
37
|
+
* with nothing to recompute, because every site's read set carries it.
|
|
38
|
+
*
|
|
39
|
+
* ## …and the sources stay distinguishable
|
|
40
|
+
*
|
|
41
|
+
* The record keeps its grants under `sharing` (`SCOPE_GRANTS_FIELD` in
|
|
42
|
+
* core): one grant per rule and one per hand-shared target, and `added`,
|
|
43
|
+
* the tokens the grants put on `visibleTo` that were not there already.
|
|
44
|
+
* The record's own scope — its HELD tokens — is `visibleTo` without
|
|
45
|
+
* `added`, so taking a grant away removes only what grants alone
|
|
46
|
+
* contributed, and never a consent-group token. A token a site later
|
|
47
|
+
* captures the person on is held from then on: the capturing sites
|
|
48
|
+
* (`hostId`, `capturedByHostIds`) are never counted as added.
|
|
49
|
+
*
|
|
50
|
+
* ## Visibility is not consent, and not write access
|
|
51
|
+
*
|
|
52
|
+
* Nothing here reads or writes a consent entry. A site a record is shared
|
|
53
|
+
* with sees it; it holds no basis to market to the person, and the
|
|
54
|
+
* audience paths read `heldByHost`, not `visibleTo`. Write access is its
|
|
55
|
+
* own field, `writeTo`, present only on a shared record: the held tokens
|
|
56
|
+
* and the tokens of grants whose access is `edit`. The Firestore rules and
|
|
57
|
+
* the CRM's routes check it; a read-only grant is the default.
|
|
58
|
+
*/
|
|
59
|
+
import type { ScopeToken } from '@aglyn/aglyn';
|
|
60
|
+
/** The four record types a share or a rule applies to, by their collection. */
|
|
61
|
+
export declare const CRM_SHARING_OBJECTS: readonly ["leads", "contacts", "companies", "deals"];
|
|
62
|
+
export type CrmSharingObject = (typeof CRM_SHARING_OBJECTS)[number];
|
|
63
|
+
export declare function isCrmSharingObject(value: unknown): value is CrmSharingObject;
|
|
64
|
+
/** How each object reads in a sentence. */
|
|
65
|
+
export declare const CRM_SHARING_OBJECT_LABELS: Readonly<Record<CrmSharingObject, {
|
|
66
|
+
one: string;
|
|
67
|
+
many: string;
|
|
68
|
+
}>>;
|
|
69
|
+
/** What a target site may do with a shared record. Read-only unless a grant says edit. */
|
|
70
|
+
export type CrmShareAccess = 'read' | 'edit';
|
|
71
|
+
export declare function isCrmShareAccess(value: unknown): value is CrmShareAccess;
|
|
72
|
+
/** Where a grant came from. */
|
|
73
|
+
export type CrmShareSource = 'manual' | 'rule';
|
|
74
|
+
/** One grant on one record. */
|
|
75
|
+
export interface CrmShareGrant {
|
|
76
|
+
source: CrmShareSource;
|
|
77
|
+
/** The sites it shares with: `['org']` for all sites, else host tokens. */
|
|
78
|
+
tokens: ScopeToken[];
|
|
79
|
+
access: CrmShareAccess;
|
|
80
|
+
/** The rule behind a `rule` grant. */
|
|
81
|
+
ruleId?: string;
|
|
82
|
+
/** Who shared it by hand, as they were named at the time. */
|
|
83
|
+
byUid?: string;
|
|
84
|
+
byName?: string;
|
|
85
|
+
/** When the grant was made. */
|
|
86
|
+
atMs: number;
|
|
87
|
+
}
|
|
88
|
+
/** `sharing` on a record — see the module note. */
|
|
89
|
+
export interface CrmRecordSharing {
|
|
90
|
+
/** Keyed by {@link manualGrantKey} or {@link ruleGrantKey}. */
|
|
91
|
+
grants: Record<string, CrmShareGrant>;
|
|
92
|
+
/** Every token any grant names — the record's shares, however held. */
|
|
93
|
+
tokens: ScopeToken[];
|
|
94
|
+
/** The tokens the grants ADDED to `visibleTo` — see `heldScopeTokens`. */
|
|
95
|
+
added: ScopeToken[];
|
|
96
|
+
/** The rules holding a grant here, so a rule's removal can find its records. */
|
|
97
|
+
ruleIds: string[];
|
|
98
|
+
/**
|
|
99
|
+
* The held tokens of a record shared with all sites, and nothing
|
|
100
|
+
* otherwise. `array-contains` on it answers "is this record shared with
|
|
101
|
+
* everyone AND held by site X" — the one question `added` alone cannot,
|
|
102
|
+
* since a query takes a single array clause.
|
|
103
|
+
*/
|
|
104
|
+
orgWideHeldBy: ScopeToken[];
|
|
105
|
+
}
|
|
106
|
+
/** The record field its grants live under — the core's name for it. */
|
|
107
|
+
export declare const CRM_SHARING_FIELD = "sharing";
|
|
108
|
+
/** The record field naming who may WRITE it, present only while it is shared. */
|
|
109
|
+
export declare const CRM_WRITE_SCOPE_FIELD = "writeTo";
|
|
110
|
+
/** The array field a rule's removal queries. */
|
|
111
|
+
export declare const CRM_SHARING_RULE_IDS_PATH = "sharing.ruleIds";
|
|
112
|
+
/** A hand share is one grant per target, so each is unshared on its own. */
|
|
113
|
+
export declare function manualGrantKey(token: string): string;
|
|
114
|
+
export declare function ruleGrantKey(ruleId: string): string;
|
|
115
|
+
/** A record's grants, cleaned; `{}` for a record never shared. */
|
|
116
|
+
export declare function readRecordGrants(record: Readonly<Record<string, unknown>> | null | undefined): Record<string, CrmShareGrant>;
|
|
117
|
+
/**
|
|
118
|
+
* The sites that captured or created the record. Their tokens are HELD,
|
|
119
|
+
* whatever `added` says: a person shared to site B and later captured on B
|
|
120
|
+
* is B's own from then on, and unsharing must not hide them from B.
|
|
121
|
+
*/
|
|
122
|
+
export declare function recordHolderHostIds(record: Readonly<Record<string, unknown>>): string[];
|
|
123
|
+
/**
|
|
124
|
+
* The record's own scope: `visibleTo` less what grants added, its capturing
|
|
125
|
+
* sites kept — the core's `heldScopeTokens`, as scope tokens.
|
|
126
|
+
*/
|
|
127
|
+
export declare function recordHeldScope(record: Readonly<Record<string, unknown>>): ScopeToken[];
|
|
128
|
+
export interface CrmSharingPlan {
|
|
129
|
+
visibleTo: ScopeToken[];
|
|
130
|
+
/** `null` removes the field: an unshared record writes by `visibleTo`. */
|
|
131
|
+
writeTo: ScopeToken[] | null;
|
|
132
|
+
/** `null` removes the field. */
|
|
133
|
+
sharing: CrmRecordSharing | null;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The fields a record carries under `grants`.
|
|
137
|
+
*
|
|
138
|
+
* A grant naming a token the record already holds adds nothing, and a
|
|
139
|
+
* record held org-wide adds nothing at all — every site sees it already, so
|
|
140
|
+
* a share there would only make a later unshare look like it hid something.
|
|
141
|
+
* The token order is the held scope first and the additions after it, so an
|
|
142
|
+
* unchanged record plans the `visibleTo` it has.
|
|
143
|
+
*/
|
|
144
|
+
export declare function planRecordSharing(record: Readonly<Record<string, unknown>>, grants: Readonly<Record<string, CrmShareGrant>>): CrmSharingPlan;
|
|
145
|
+
/** Whether writing `plan` would change what the record stores. */
|
|
146
|
+
export declare function sharingPlanChanges(record: Readonly<Record<string, unknown>>, plan: CrmSharingPlan): boolean;
|
|
147
|
+
/** The org document path the rules are stored under. */
|
|
148
|
+
export declare const CRM_SHARING_RULES_PATH = "crm.sharingRules";
|
|
149
|
+
/** A workspace keeps at most this many. */
|
|
150
|
+
export declare const CRM_SHARING_RULES_MAX = 20;
|
|
151
|
+
/** At most this many values per criterion. */
|
|
152
|
+
export declare const CRM_SHARING_CRITERION_MAX = 20;
|
|
153
|
+
/**
|
|
154
|
+
* Which records a rule matches, beyond the object and the capturing site.
|
|
155
|
+
* AND across the keys, OR within one; an absent or empty key matches
|
|
156
|
+
* everything.
|
|
157
|
+
*/
|
|
158
|
+
export interface CrmSharingCriteria {
|
|
159
|
+
/** A lead's or a contact's lead source, by label. */
|
|
160
|
+
leadSources?: string[];
|
|
161
|
+
/** Any of these tags (lead, contact, company). */
|
|
162
|
+
tags?: string[];
|
|
163
|
+
/** Filed under any of these campaigns (lead, contact). */
|
|
164
|
+
campaignIds?: string[];
|
|
165
|
+
/** A lead's status, a contact's lifecycle stage, or a deal's stage id. */
|
|
166
|
+
stages?: string[];
|
|
167
|
+
/** Owned by any of these members. */
|
|
168
|
+
ownerUids?: string[];
|
|
169
|
+
}
|
|
170
|
+
export declare const CRM_SHARING_CRITERIA_KEYS: readonly ["leadSources", "tags", "campaignIds", "stages", "ownerUids"];
|
|
171
|
+
/** Which criteria an object's records can answer. */
|
|
172
|
+
export declare const CRM_SHARING_CRITERIA_FOR: Readonly<Record<CrmSharingObject, readonly (keyof CrmSharingCriteria)[]>>;
|
|
173
|
+
/** Where a rule's recompute stands. */
|
|
174
|
+
export interface CrmSharingRuleRun {
|
|
175
|
+
status: 'running' | 'done' | 'failed';
|
|
176
|
+
/** What the run does: apply the rule everywhere, or take it away. */
|
|
177
|
+
mode: 'apply' | 'remove';
|
|
178
|
+
/** Records examined. */
|
|
179
|
+
processed: number;
|
|
180
|
+
/** Records whose sharing changed. */
|
|
181
|
+
changed: number;
|
|
182
|
+
/** The last record id an `apply` run examined, to continue after. */
|
|
183
|
+
cursor?: string | null;
|
|
184
|
+
startedAtMs: number;
|
|
185
|
+
finishedAtMs?: number;
|
|
186
|
+
error?: string;
|
|
187
|
+
}
|
|
188
|
+
export interface CrmSharingRule {
|
|
189
|
+
id: string;
|
|
190
|
+
name: string;
|
|
191
|
+
object: CrmSharingObject;
|
|
192
|
+
/** Off keeps the rule and takes away what it granted. */
|
|
193
|
+
enabled: boolean;
|
|
194
|
+
/** Records captured or created on any of these sites; empty is every site. */
|
|
195
|
+
sourceHostIds: string[];
|
|
196
|
+
criteria: CrmSharingCriteria;
|
|
197
|
+
/** `['org']` for all sites, including sites added later; else host tokens. */
|
|
198
|
+
targets: ScopeToken[];
|
|
199
|
+
access: CrmShareAccess;
|
|
200
|
+
/** Being deleted: its grants are being removed, and it matches nothing. */
|
|
201
|
+
deleting?: boolean;
|
|
202
|
+
createdByUid?: string;
|
|
203
|
+
createdAtMs: number;
|
|
204
|
+
updatedAtMs: number;
|
|
205
|
+
run?: CrmSharingRuleRun;
|
|
206
|
+
}
|
|
207
|
+
/** One rule as stored, cleaned, or null when it cannot be applied. */
|
|
208
|
+
export declare function readCrmSharingRule(raw: unknown): CrmSharingRule | null;
|
|
209
|
+
/** The org's sharing rules, in their stored order. */
|
|
210
|
+
export declare function readCrmSharingRules(org: Readonly<Record<string, unknown>> | null | undefined): CrmSharingRule[];
|
|
211
|
+
/** The rules that grant anything now: enabled, and not being deleted. */
|
|
212
|
+
export declare function activeSharingRules(rules: readonly CrmSharingRule[], object?: CrmSharingObject): CrmSharingRule[];
|
|
213
|
+
/**
|
|
214
|
+
* A share's targets, cleaned for storage: `['org']` when all sites are
|
|
215
|
+
* named, else the host tokens, capped. `null` when nothing is left.
|
|
216
|
+
*/
|
|
217
|
+
export declare function normalizeShareTargets(tokens: readonly string[]): ScopeToken[] | null;
|
|
218
|
+
/** Targets from a request: `'all'`, or a list of host ids. */
|
|
219
|
+
export declare function shareTargetsFrom(input: unknown): ScopeToken[] | null;
|
|
220
|
+
export interface CrmSharingFacts {
|
|
221
|
+
hostIds: string[];
|
|
222
|
+
leadSources: string[];
|
|
223
|
+
tags: string[];
|
|
224
|
+
campaignIds: string[];
|
|
225
|
+
stages: string[];
|
|
226
|
+
ownerUids: string[];
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* The facts a rule's criteria are matched against. A contact keeps each
|
|
230
|
+
* holder's working fields in its own facet, so a contact answers with the
|
|
231
|
+
* union of its facets: a rule about "contacts tagged vip" matches a person
|
|
232
|
+
* any holder tagged.
|
|
233
|
+
*/
|
|
234
|
+
export declare function crmSharingFacts(object: CrmSharingObject, record: Readonly<Record<string, unknown>>): CrmSharingFacts;
|
|
235
|
+
/** Whether a rule shares this record. */
|
|
236
|
+
export declare function crmSharingRuleMatches(rule: CrmSharingRule, object: CrmSharingObject, record: Readonly<Record<string, unknown>>): boolean;
|
|
237
|
+
/**
|
|
238
|
+
* The grants a record should carry: its hand shares as they are, and one
|
|
239
|
+
* grant per active rule that matches it now. A rule grant already present
|
|
240
|
+
* keeps its date, so re-evaluating an unchanged record writes nothing.
|
|
241
|
+
*
|
|
242
|
+
* A rule grant whose rule is not among `rules` is dropped — the caller
|
|
243
|
+
* passes every active rule of the org, so a rule absent from them has been
|
|
244
|
+
* switched off or deleted.
|
|
245
|
+
*/
|
|
246
|
+
export declare function evaluateRecordGrants(object: CrmSharingObject, record: Readonly<Record<string, unknown>>, rules: readonly CrmSharingRule[], atMs: number): Record<string, CrmShareGrant>;
|
|
247
|
+
/** The hand shares after sharing with `targets`, by `by`. */
|
|
248
|
+
export declare function withManualShares(grants: Readonly<Record<string, CrmShareGrant>>, targets: readonly ScopeToken[], access: CrmShareAccess, by: {
|
|
249
|
+
uid: string;
|
|
250
|
+
name?: string | null;
|
|
251
|
+
}, atMs: number): Record<string, CrmShareGrant>;
|
|
252
|
+
/** The hand shares after unsharing `targets`. Rule grants are the rule's to take away. */
|
|
253
|
+
export declare function withoutManualShares(grants: Readonly<Record<string, CrmShareGrant>>, targets: readonly string[]): Record<string, CrmShareGrant>;
|
|
254
|
+
/**
|
|
255
|
+
* Whether a caller holding `tokens` may write the record: `writeTo` on a
|
|
256
|
+
* shared record, else `visibleTo` — the Firestore rules' own predicate.
|
|
257
|
+
*/
|
|
258
|
+
export declare function crmRecordWritableBy(record: Readonly<Record<string, unknown>>, tokens: readonly string[]): boolean;
|
|
259
|
+
/** How a record reached a site that sees it only through a share. */
|
|
260
|
+
export interface CrmShareChip {
|
|
261
|
+
source: CrmShareSource;
|
|
262
|
+
access: CrmShareAccess;
|
|
263
|
+
/** The member who shared it by hand. */
|
|
264
|
+
byName?: string;
|
|
265
|
+
/** The rule that shared it. */
|
|
266
|
+
ruleId?: string;
|
|
267
|
+
/** Shared with every site. */
|
|
268
|
+
allSites: boolean;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Why a site seeing this record sees it, when the answer is a share — or
|
|
272
|
+
* `null` when the site holds it (or cannot see it at all). `hostIds` are
|
|
273
|
+
* the viewing group's sites; at the organization level there is none.
|
|
274
|
+
*/
|
|
275
|
+
export declare function crmShareChipFor(record: Readonly<Record<string, unknown>> | null | undefined, hostIds: readonly string[]): CrmShareChip | null;
|
|
276
|
+
/** The chip's words: "Shared by Dana", "Shared by rule Brand A leads". */
|
|
277
|
+
export declare function crmShareChipLabel(chip: CrmShareChip, rules?: readonly Pick<CrmSharingRule, 'id' | 'name'>[]): string;
|
|
278
|
+
/** One line of a record's Sharing card. */
|
|
279
|
+
export type CrmSharingLine = {
|
|
280
|
+
kind: 'held';
|
|
281
|
+
hostIds: string[];
|
|
282
|
+
allSites: boolean;
|
|
283
|
+
} | {
|
|
284
|
+
kind: 'manual';
|
|
285
|
+
key: string;
|
|
286
|
+
token: ScopeToken;
|
|
287
|
+
access: CrmShareAccess;
|
|
288
|
+
byName?: string;
|
|
289
|
+
atMs: number;
|
|
290
|
+
} | {
|
|
291
|
+
kind: 'rule';
|
|
292
|
+
key: string;
|
|
293
|
+
ruleId: string;
|
|
294
|
+
tokens: ScopeToken[];
|
|
295
|
+
access: CrmShareAccess;
|
|
296
|
+
atMs: number;
|
|
297
|
+
};
|
|
298
|
+
/**
|
|
299
|
+
* Where a record is visible and why: the sites that hold it (its consent
|
|
300
|
+
* group or its creating site), then one line per hand share, then one per
|
|
301
|
+
* rule. The held line is never unsharable; a hand share is, in one click.
|
|
302
|
+
*/
|
|
303
|
+
export declare function describeRecordSharing(record: Readonly<Record<string, unknown>> | null | undefined): CrmSharingLine[];
|
|
304
|
+
/** "All sites", a site's name, or "N sites". */
|
|
305
|
+
export declare function describeShareTargets(tokens: readonly string[], siteName: (hostId: string) => string): string;
|
|
306
|
+
/** A rule as one sentence of its "which records" half. */
|
|
307
|
+
export declare function describeSharingRuleScope(rule: Pick<CrmSharingRule, 'object' | 'sourceHostIds' | 'criteria'>, siteName: (hostId: string) => string, labels?: {
|
|
308
|
+
owner?: (uid: string) => string;
|
|
309
|
+
stage?: (id: string) => string;
|
|
310
|
+
}): string;
|
|
311
|
+
/** `POST /api/crm/sharing` — every sharing act, by `action`. */
|
|
312
|
+
export declare const CRM_SHARING_ROUTE: "crm/sharing";
|
|
313
|
+
export declare const crmSharingRouteUrl: () => string;
|
|
314
|
+
/** Records one share or unshare may name. */
|
|
315
|
+
export declare const CRM_SHARING_IDS_MAX = 200;
|
|
316
|
+
export type CrmSharingAction = 'sites' | 'share' | 'unshare' | 'evaluate' | 'rule-save' | 'rule-delete' | 'rule-continue';
|
|
317
|
+
export interface CrmSharingSite {
|
|
318
|
+
id: string;
|
|
319
|
+
name: string;
|
|
320
|
+
}
|
|
321
|
+
export interface CrmSharingResponse {
|
|
322
|
+
ok: true;
|
|
323
|
+
/** `sites`: the org's sites, by name. */
|
|
324
|
+
sites?: CrmSharingSite[];
|
|
325
|
+
/** `share`/`unshare`/`evaluate`: records whose sharing changed. */
|
|
326
|
+
changed?: number;
|
|
327
|
+
/** Records named that could not be found. */
|
|
328
|
+
missing?: number;
|
|
329
|
+
/** The rule a rule action saved or ran. */
|
|
330
|
+
rule?: CrmSharingRule | null;
|
|
331
|
+
/** Whether a rule run has more to do (`rule-continue` again). */
|
|
332
|
+
more?: boolean;
|
|
333
|
+
}
|