@aglyn/plugins-crm 1.0.0-beta.244 → 1.0.0-beta.247
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/package.json +14 -14
- package/src/lib/components/contact-custom-columns.d.ts +15 -6
- package/src/lib/components/contact-custom-columns.js +27 -7
- package/src/lib/components/contact-custom-columns.js.map +1 -1
- package/src/lib/components/contact-field-drawer.d.ts +2 -0
- package/src/lib/components/contact-field-drawer.js +29 -15
- package/src/lib/components/contact-field-drawer.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-custom-field-control.d.ts +4 -2
- package/src/lib/components/crm-custom-field-control.js +53 -1
- package/src/lib/components/crm-custom-field-control.js.map +1 -1
- package/src/lib/components/fields-section.js +4 -2
- package/src/lib/components/fields-section.js.map +1 -1
- package/src/lib/components/form-contact-fields-card.js +2 -0
- package/src/lib/components/form-contact-fields-card.js.map +1 -1
- package/src/lib/constants/contact-filters.d.ts +7 -0
- package/src/lib/constants/contact-filters.js +8 -1
- package/src/lib/constants/contact-filters.js.map +1 -1
- package/src/lib/declarations.console-server.d.ts +7 -0
- package/src/lib/declarations.console-server.js +39 -0
- package/src/lib/declarations.console-server.js.map +1 -1
- package/src/lib/model/crm-picklist-setup-content.d.ts +121 -0
- package/src/lib/model/crm-picklist-setup-content.js +262 -0
- package/src/lib/model/crm-picklist-setup-content.js.map +1 -0
- package/src/lib/model/crm-record-routes.js +18 -0
- package/src/lib/model/crm-record-routes.js.map +1 -1
- package/src/lib/model/crm-setup-content.d.ts +199 -0
- package/src/lib/model/crm-setup-content.js +427 -0
- package/src/lib/model/crm-setup-content.js.map +1 -0
- package/src/lib/server/crm-setup-ai-capabilities.d.ts +68 -0
- package/src/lib/server/crm-setup-ai-capabilities.js +290 -0
- package/src/lib/server/crm-setup-ai-capabilities.js.map +1 -0
- package/src/lib/server/crm-setup-writers.server.d.ts +120 -0
- package/src/lib/server/crm-setup-writers.server.js +492 -0
- package/src/lib/server/crm-setup-writers.server.js.map +1 -0
- package/src/lib/server/picklist-regroup.d.ts +30 -0
- package/src/lib/server/picklist-regroup.js +61 -0
- package/src/lib/server/picklist-regroup.js.map +1 -0
- package/src/lib/server/picklist-values.d.ts +2 -14
- package/src/lib/server/picklist-values.js +3 -40
- package/src/lib/server/picklist-values.js.map +1 -1
- package/src/lib/transfer/common.d.ts +4 -2
- package/src/lib/transfer/common.js +14 -3
- package/src/lib/transfer/common.js.map +1 -1
- package/src/lib/transfer/fields.js +10 -1
- package/src/lib/transfer/fields.js.map +1 -1
- package/src/lib/transfer/pipelines.js +4 -2
- package/src/lib/transfer/pipelines.js.map +1 -1
|
@@ -0,0 +1,290 @@
|
|
|
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
|
+
*/ import { CONTACT_FIELD_TYPES } from "@aglyn/aglyn/app-utils/contact-custom-fields";
|
|
17
|
+
import { CRM_FIELD_OBJECTS } from "@aglyn/aglyn/app-utils/crm";
|
|
18
|
+
import { registerPluginAiCapability } from "@aglyn/aglyn/plugin-manager/plugin-ai-capabilities";
|
|
19
|
+
import { BUNDLE_ID } from "../constants/bundle-common.js";
|
|
20
|
+
import { CRM_FIELD_LABEL_MAX_LENGTH, CRM_FIELD_OPTION_MAX_LENGTH, CRM_FIELD_OPTIONS_MAX, CRM_FIELD_SETUP_RESOURCE, CRM_PIPELINE_SETUP_RESOURCE, CRM_SETUP_OPEN_STAGES_MAX, CRM_SETUP_STAGE_NAME_MAX } from "../model/crm-setup-content.js";
|
|
21
|
+
import { CRM_PICKLIST_VALUES_LISTS, CRM_PICKLIST_VALUES_SETUP_MAX, CRM_PICKLIST_VALUES_SETUP_RESOURCE } from "../model/crm-picklist-setup-content.js";
|
|
22
|
+
import { PIPELINE_NAME_MAX } from "../model/deal-board-model.js";
|
|
23
|
+
/**
|
|
24
|
+
* WHAT AN AI BUILD CAN SET UP IN THE CRM (AGL-3746): a deal pipeline with its
|
|
25
|
+
* stages, and a custom field on a contact, company, deal or lead.
|
|
26
|
+
*
|
|
27
|
+
* The capabilities the AI plugin's build planner offers for "set up a sales
|
|
28
|
+
* pipeline for my agency: Discovery, Proposal, Negotiation, Won/Lost" or
|
|
29
|
+
* "add a Budget field to deals". Each item is written by this plugin's
|
|
30
|
+
* `crm-pipeline` or `crm-field` writer, so every rule is the writer's and the
|
|
31
|
+
* console's: the `crm` plan feature, an owner, admin or editor with
|
|
32
|
+
* `data.manage`, the scope, `stagesProblem`, the field types and the org's
|
|
33
|
+
* 100-field ceiling. Both are saved live, as the console saves them (`live`):
|
|
34
|
+
* neither has a draft state. Matched by name, so asking again changes
|
|
35
|
+
* nothing twice.
|
|
36
|
+
*
|
|
37
|
+
* The arguments are flat, as the contract requires, and are the setup's own
|
|
38
|
+
* fields; the planner fills them, so no model runs (`estimateCredits` 0). No
|
|
39
|
+
* page block shows either, so neither changes what a visitor sees.
|
|
40
|
+
*
|
|
41
|
+
* A Salesforce "opportunity" is a deal here and an "account" a company; the
|
|
42
|
+
* descriptions say so, since a request may use either word.
|
|
43
|
+
*/ /** The operations' names in a build plan. */ export const CRM_PIPELINE_AI_OP = 'crm-pipeline';
|
|
44
|
+
export const CRM_FIELD_AI_OP = 'crm-field';
|
|
45
|
+
export const CRM_PICKLIST_VALUES_AI_OP = 'crm-picklist-values';
|
|
46
|
+
/** How many of each one build may set up. */ export const CRM_PIPELINE_AI_MAX_PER_PLAN = 3;
|
|
47
|
+
export const CRM_FIELD_AI_MAX_PER_PLAN = 12;
|
|
48
|
+
export const CRM_PICKLIST_VALUES_AI_MAX_PER_PLAN = 12;
|
|
49
|
+
/** The CRM is included from Starter (`crm`); Free has none of it. */ const CRM_FEATURE = 'crm';
|
|
50
|
+
function pick(args, keys) {
|
|
51
|
+
return Object.fromEntries(keys.filter((key)=>args[key] !== undefined && args[key] !== '').map((key)=>[
|
|
52
|
+
key,
|
|
53
|
+
args[key]
|
|
54
|
+
]));
|
|
55
|
+
}
|
|
56
|
+
/** The pipeline writer's content for an item: its arguments, as they are. Pure. */ export function crmPipelineSetupContentFromArgs(args) {
|
|
57
|
+
return pick(args, [
|
|
58
|
+
'name',
|
|
59
|
+
'renameFrom',
|
|
60
|
+
'stages',
|
|
61
|
+
'wonStage',
|
|
62
|
+
'lostStage',
|
|
63
|
+
'makeDefault'
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
/** The field writer's content for an item: its arguments, as they are. Pure. */ export function crmFieldSetupContentFromArgs(args) {
|
|
67
|
+
return pick(args, [
|
|
68
|
+
'object',
|
|
69
|
+
'label',
|
|
70
|
+
'type',
|
|
71
|
+
'options',
|
|
72
|
+
'currency',
|
|
73
|
+
'required'
|
|
74
|
+
]);
|
|
75
|
+
}
|
|
76
|
+
export const crmPipelineAiCapability = {
|
|
77
|
+
op: CRM_PIPELINE_AI_OP,
|
|
78
|
+
noun: 'sales pipeline',
|
|
79
|
+
where: 'CRM → Deals → Pipelines',
|
|
80
|
+
intents: [
|
|
81
|
+
'CRM deal pipelines and their stages — "set up a sales pipeline: Discovery, Proposal, Negotiation, Won/Lost", rename a pipeline, add or reorder stages, set a stage’s win probability, make a pipeline the default; a Salesforce opportunity pipeline is a deal pipeline'
|
|
82
|
+
],
|
|
83
|
+
argsSchema: {
|
|
84
|
+
type: 'object',
|
|
85
|
+
properties: {
|
|
86
|
+
name: {
|
|
87
|
+
type: 'string',
|
|
88
|
+
description: 'The pipeline’s name, e.g. "Agency sales". An existing pipeline of this name (any case) is updated rather than duplicated; give "renameFrom" to rename one.',
|
|
89
|
+
maxLength: PIPELINE_NAME_MAX
|
|
90
|
+
},
|
|
91
|
+
renameFrom: {
|
|
92
|
+
type: 'string',
|
|
93
|
+
description: 'Only to rename: the current name of the pipeline that becomes "name".',
|
|
94
|
+
maxLength: PIPELINE_NAME_MAX
|
|
95
|
+
},
|
|
96
|
+
stages: {
|
|
97
|
+
type: 'array',
|
|
98
|
+
description: 'The OPEN stages a deal moves through, in order, each a name with an optional win probability in parentheses, e.g. "Discovery (20%)". Never Won or Lost: every pipeline already has one of each (name them in wonStage and lostStage). Leave out to keep the stages as they are (a new pipeline then gets the standard set). Stages already in the pipeline and not listed are kept.',
|
|
99
|
+
items: {
|
|
100
|
+
type: 'string',
|
|
101
|
+
maxLength: CRM_SETUP_STAGE_NAME_MAX + 8
|
|
102
|
+
},
|
|
103
|
+
maxItems: CRM_SETUP_OPEN_STAGES_MAX
|
|
104
|
+
},
|
|
105
|
+
wonStage: {
|
|
106
|
+
type: 'string',
|
|
107
|
+
description: 'What the closing Won stage is called, where the request names it, e.g. "Won". Leave out to keep "Closed Won".',
|
|
108
|
+
maxLength: CRM_SETUP_STAGE_NAME_MAX
|
|
109
|
+
},
|
|
110
|
+
lostStage: {
|
|
111
|
+
type: 'string',
|
|
112
|
+
description: 'What the closing Lost stage is called, where the request names it, e.g. "Lost". Leave out to keep "Closed Lost".',
|
|
113
|
+
maxLength: CRM_SETUP_STAGE_NAME_MAX
|
|
114
|
+
},
|
|
115
|
+
makeDefault: {
|
|
116
|
+
type: 'boolean',
|
|
117
|
+
description: 'true only when the request says new deals should land in this pipeline (its main or default pipeline).'
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
required: [
|
|
121
|
+
'name'
|
|
122
|
+
],
|
|
123
|
+
additionalProperties: false
|
|
124
|
+
},
|
|
125
|
+
maxPerPlan: CRM_PIPELINE_AI_MAX_PER_PLAN,
|
|
126
|
+
freeAllowed: false,
|
|
127
|
+
feature: CRM_FEATURE,
|
|
128
|
+
draftResource: CRM_PIPELINE_SETUP_RESOURCE,
|
|
129
|
+
live: true,
|
|
130
|
+
// Written without a model: the planner already filled the arguments.
|
|
131
|
+
estimateCredits: ()=>0,
|
|
132
|
+
degrade: 'omit',
|
|
133
|
+
draftContent: (item)=>crmPipelineSetupContentFromArgs(item.args)
|
|
134
|
+
};
|
|
135
|
+
export const crmFieldAiCapability = {
|
|
136
|
+
op: CRM_FIELD_AI_OP,
|
|
137
|
+
noun: 'CRM custom field',
|
|
138
|
+
where: 'CRM → Fields',
|
|
139
|
+
intents: [
|
|
140
|
+
'CRM custom fields on contacts, companies (accounts), deals (opportunities) or leads — "add a Budget field to opportunities", "a Choice field for Industry on companies"; types text, number, date, choice, checkbox, link and currency (an amount of money: budget, deal size, revenue)'
|
|
141
|
+
],
|
|
142
|
+
argsSchema: {
|
|
143
|
+
type: 'object',
|
|
144
|
+
properties: {
|
|
145
|
+
object: {
|
|
146
|
+
type: 'string',
|
|
147
|
+
description: 'The record it describes: contact; company (an account); deal (an opportunity); lead.',
|
|
148
|
+
enum: CRM_FIELD_OBJECTS
|
|
149
|
+
},
|
|
150
|
+
label: {
|
|
151
|
+
type: 'string',
|
|
152
|
+
description: 'The field’s name as people read it, e.g. "Budget". A field of this name on the same record (any case) is left as it is rather than duplicated.',
|
|
153
|
+
maxLength: CRM_FIELD_LABEL_MAX_LENGTH
|
|
154
|
+
},
|
|
155
|
+
type: {
|
|
156
|
+
type: 'string',
|
|
157
|
+
description: 'What it holds: text; number (a count or a percentage); currency (an amount of money — a budget, a price, revenue — with "currency"); date; select (a Choice from listed options); checkbox (yes or no); url (a link).',
|
|
158
|
+
enum: CONTACT_FIELD_TYPES
|
|
159
|
+
},
|
|
160
|
+
options: {
|
|
161
|
+
type: 'array',
|
|
162
|
+
description: 'For select only: the choices, in order. A select field that exists gains the ones it lacks.',
|
|
163
|
+
items: {
|
|
164
|
+
type: 'string',
|
|
165
|
+
maxLength: CRM_FIELD_OPTION_MAX_LENGTH
|
|
166
|
+
},
|
|
167
|
+
maxItems: CRM_FIELD_OPTIONS_MAX
|
|
168
|
+
},
|
|
169
|
+
currency: {
|
|
170
|
+
type: 'string',
|
|
171
|
+
description: 'For currency only: the ISO 4217 code its amounts are in, e.g. "EUR", when the request names one. Leave out for US dollars.',
|
|
172
|
+
maxLength: 3
|
|
173
|
+
},
|
|
174
|
+
required: {
|
|
175
|
+
type: 'boolean',
|
|
176
|
+
description: 'true only when the request says the field must always be filled in.'
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
required: [
|
|
180
|
+
'object',
|
|
181
|
+
'label',
|
|
182
|
+
'type'
|
|
183
|
+
],
|
|
184
|
+
additionalProperties: false
|
|
185
|
+
},
|
|
186
|
+
maxPerPlan: CRM_FIELD_AI_MAX_PER_PLAN,
|
|
187
|
+
freeAllowed: false,
|
|
188
|
+
feature: CRM_FEATURE,
|
|
189
|
+
draftResource: CRM_FIELD_SETUP_RESOURCE,
|
|
190
|
+
live: true,
|
|
191
|
+
estimateCredits: ()=>0,
|
|
192
|
+
degrade: 'omit',
|
|
193
|
+
draftContent: (item)=>crmFieldSetupContentFromArgs(item.args)
|
|
194
|
+
};
|
|
195
|
+
/** The picklist values writer's content for an item: its arguments, as they are. Pure. */ export function crmPicklistValuesSetupContentFromArgs(args) {
|
|
196
|
+
return pick(args, [
|
|
197
|
+
'list',
|
|
198
|
+
'object',
|
|
199
|
+
'field',
|
|
200
|
+
'values',
|
|
201
|
+
'meaning',
|
|
202
|
+
'group'
|
|
203
|
+
]);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* VALUES ADDED TO A CRM PICKLIST (AGL-3756): "add Nurturing as a lead
|
|
207
|
+
* status", "add Trade show and Podcast as lead sources", "add Renewal as a
|
|
208
|
+
* deal type", "add Enterprise to the Tier choices on companies". Written by
|
|
209
|
+
* the `crm-picklist-values` writer, so the rules are the Fields page's: only
|
|
210
|
+
* adds, matched without capitals, never removes, renames, reorders or
|
|
211
|
+
* reactivates. Live, as the console's Add value is; 0 credits.
|
|
212
|
+
*/ export const crmPicklistValuesAiCapability = {
|
|
213
|
+
op: CRM_PICKLIST_VALUES_AI_OP,
|
|
214
|
+
noun: 'CRM picklist values',
|
|
215
|
+
where: 'CRM → Fields',
|
|
216
|
+
intents: [
|
|
217
|
+
'add values to a CRM picklist — a lead status ("Contacted", meaning Working), a lead source (Inbound or Outbound), a deal (opportunity) type or contact role, a company (account) type, industry, rating or ownership, a salutation, a task status, priority, type or subject — or add choices to a custom Choice field; only adds, never removes or renames'
|
|
218
|
+
],
|
|
219
|
+
argsSchema: {
|
|
220
|
+
type: 'object',
|
|
221
|
+
properties: {
|
|
222
|
+
list: {
|
|
223
|
+
type: 'string',
|
|
224
|
+
description: 'Which list: leadStatus, leadSource, opportunityType (a deal’s Type), opportunityContactRole, accountType (a company’s Type), industry, rating, ownership, salutation, taskStatus, taskPriority, taskType, taskSubject; or custom for a custom Choice field (then give object and field).',
|
|
225
|
+
enum: CRM_PICKLIST_VALUES_LISTS
|
|
226
|
+
},
|
|
227
|
+
object: {
|
|
228
|
+
type: 'string',
|
|
229
|
+
description: 'For custom only: the record the Choice field is on — contact; company; deal; lead.',
|
|
230
|
+
enum: CRM_FIELD_OBJECTS
|
|
231
|
+
},
|
|
232
|
+
field: {
|
|
233
|
+
type: 'string',
|
|
234
|
+
description: 'For custom only: the Choice field’s name, e.g. "Tier".',
|
|
235
|
+
maxLength: 80
|
|
236
|
+
},
|
|
237
|
+
values: {
|
|
238
|
+
type: 'array',
|
|
239
|
+
description: 'The values to add, in order, e.g. ["Trade show", "Podcast"]. A value the list already has (any capitals) is left as it is. Never values to remove or rename.',
|
|
240
|
+
items: {
|
|
241
|
+
type: 'string',
|
|
242
|
+
maxLength: 120
|
|
243
|
+
},
|
|
244
|
+
maxItems: CRM_PICKLIST_VALUES_SETUP_MAX
|
|
245
|
+
},
|
|
246
|
+
meaning: {
|
|
247
|
+
type: 'string',
|
|
248
|
+
description: 'Required for leadStatus, taskStatus, taskPriority and taskType: what every value in this item means. leadStatus: new, nurturing, working or unqualified (never qualified); taskStatus: open or done; taskPriority: low, normal or high; taskType: call, email, meeting or todo. Split values of different meanings into separate items.',
|
|
249
|
+
maxLength: 40
|
|
250
|
+
},
|
|
251
|
+
group: {
|
|
252
|
+
type: 'string',
|
|
253
|
+
description: 'For leadSource only: inbound (the lead came to them) or outbound (they went to the lead), when the request says or it is plain.',
|
|
254
|
+
enum: [
|
|
255
|
+
'inbound',
|
|
256
|
+
'outbound'
|
|
257
|
+
]
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
required: [
|
|
261
|
+
'list',
|
|
262
|
+
'values'
|
|
263
|
+
],
|
|
264
|
+
additionalProperties: false
|
|
265
|
+
},
|
|
266
|
+
maxPerPlan: CRM_PICKLIST_VALUES_AI_MAX_PER_PLAN,
|
|
267
|
+
freeAllowed: false,
|
|
268
|
+
feature: CRM_FEATURE,
|
|
269
|
+
draftResource: CRM_PICKLIST_VALUES_SETUP_RESOURCE,
|
|
270
|
+
live: true,
|
|
271
|
+
estimateCredits: ()=>0,
|
|
272
|
+
degrade: 'omit',
|
|
273
|
+
draftContent: (item)=>crmPicklistValuesSetupContentFromArgs(item.args)
|
|
274
|
+
};
|
|
275
|
+
/**
|
|
276
|
+
* Registers both capabilities; the console-server declarations call it beside
|
|
277
|
+
* the writers, since only the console runs AI jobs (AGL-3026). Idempotent.
|
|
278
|
+
*/ export function registerCrmSetupAiCapabilities() {
|
|
279
|
+
registerPluginAiCapability(crmPipelineAiCapability, {
|
|
280
|
+
pluginId: BUNDLE_ID
|
|
281
|
+
});
|
|
282
|
+
registerPluginAiCapability(crmFieldAiCapability, {
|
|
283
|
+
pluginId: BUNDLE_ID
|
|
284
|
+
});
|
|
285
|
+
registerPluginAiCapability(crmPicklistValuesAiCapability, {
|
|
286
|
+
pluginId: BUNDLE_ID
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
//# sourceMappingURL=crm-setup-ai-capabilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/server/crm-setup-ai-capabilities.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 { CONTACT_FIELD_TYPES } from '@aglyn/aglyn/app-utils/contact-custom-fields'\nimport { CRM_FIELD_OBJECTS } from '@aglyn/aglyn/app-utils/crm'\nimport {\n registerPluginAiCapability,\n type PluginAiCapability,\n type PluginAiCapabilityArgs,\n} from '@aglyn/aglyn/plugin-manager/plugin-ai-capabilities'\nimport { BUNDLE_ID } from '../constants/bundle-common'\nimport {\n CRM_FIELD_LABEL_MAX_LENGTH,\n CRM_FIELD_OPTION_MAX_LENGTH,\n CRM_FIELD_OPTIONS_MAX,\n CRM_FIELD_SETUP_RESOURCE,\n CRM_PIPELINE_SETUP_RESOURCE,\n CRM_SETUP_OPEN_STAGES_MAX,\n CRM_SETUP_STAGE_NAME_MAX,\n} from '../model/crm-setup-content'\nimport {\n CRM_PICKLIST_VALUES_LISTS,\n CRM_PICKLIST_VALUES_SETUP_MAX,\n CRM_PICKLIST_VALUES_SETUP_RESOURCE,\n} from '../model/crm-picklist-setup-content'\nimport { PIPELINE_NAME_MAX } from '../model/deal-board-model'\n\n/**\n * WHAT AN AI BUILD CAN SET UP IN THE CRM (AGL-3746): a deal pipeline with its\n * stages, and a custom field on a contact, company, deal or lead.\n *\n * The capabilities the AI plugin's build planner offers for \"set up a sales\n * pipeline for my agency: Discovery, Proposal, Negotiation, Won/Lost\" or\n * \"add a Budget field to deals\". Each item is written by this plugin's\n * `crm-pipeline` or `crm-field` writer, so every rule is the writer's and the\n * console's: the `crm` plan feature, an owner, admin or editor with\n * `data.manage`, the scope, `stagesProblem`, the field types and the org's\n * 100-field ceiling. Both are saved live, as the console saves them (`live`):\n * neither has a draft state. Matched by name, so asking again changes\n * nothing twice.\n *\n * The arguments are flat, as the contract requires, and are the setup's own\n * fields; the planner fills them, so no model runs (`estimateCredits` 0). No\n * page block shows either, so neither changes what a visitor sees.\n *\n * A Salesforce \"opportunity\" is a deal here and an \"account\" a company; the\n * descriptions say so, since a request may use either word.\n */\n\n/** The operations' names in a build plan. */\nexport const CRM_PIPELINE_AI_OP = 'crm-pipeline'\nexport const CRM_FIELD_AI_OP = 'crm-field'\nexport const CRM_PICKLIST_VALUES_AI_OP = 'crm-picklist-values'\n\n/** How many of each one build may set up. */\nexport const CRM_PIPELINE_AI_MAX_PER_PLAN = 3\nexport const CRM_FIELD_AI_MAX_PER_PLAN = 12\nexport const CRM_PICKLIST_VALUES_AI_MAX_PER_PLAN = 12\n\n/** The CRM is included from Starter (`crm`); Free has none of it. */\nconst CRM_FEATURE = 'crm'\n\nfunction pick(args: PluginAiCapabilityArgs, keys: readonly string[]): Record<string, unknown> {\n return Object.fromEntries(keys.filter((key) => args[key] !== undefined && args[key] !== '').map((key) => [key, args[key]]))\n}\n\n/** The pipeline writer's content for an item: its arguments, as they are. Pure. */\nexport function crmPipelineSetupContentFromArgs(args: PluginAiCapabilityArgs): Readonly<Record<string, unknown>> {\n return pick(args, ['name', 'renameFrom', 'stages', 'wonStage', 'lostStage', 'makeDefault'])\n}\n\n/** The field writer's content for an item: its arguments, as they are. Pure. */\nexport function crmFieldSetupContentFromArgs(args: PluginAiCapabilityArgs): Readonly<Record<string, unknown>> {\n return pick(args, ['object', 'label', 'type', 'options', 'currency', 'required'])\n}\n\nexport const crmPipelineAiCapability: PluginAiCapability = {\n op: CRM_PIPELINE_AI_OP,\n noun: 'sales pipeline',\n where: 'CRM → Deals → Pipelines',\n intents: [\n 'CRM deal pipelines and their stages — \"set up a sales pipeline: Discovery, Proposal, Negotiation, Won/Lost\", rename a pipeline, add or reorder stages, set a stage’s win probability, make a pipeline the default; a Salesforce opportunity pipeline is a deal pipeline',\n ],\n argsSchema: {\n type: 'object',\n properties: {\n name: {\n type: 'string',\n description:\n 'The pipeline’s name, e.g. \"Agency sales\". An existing pipeline of this name (any case) is updated rather than duplicated; give \"renameFrom\" to rename one.',\n maxLength: PIPELINE_NAME_MAX,\n },\n renameFrom: {\n type: 'string',\n description: 'Only to rename: the current name of the pipeline that becomes \"name\".',\n maxLength: PIPELINE_NAME_MAX,\n },\n stages: {\n type: 'array',\n description:\n 'The OPEN stages a deal moves through, in order, each a name with an optional win probability in parentheses, e.g. \"Discovery (20%)\". Never Won or Lost: every pipeline already has one of each (name them in wonStage and lostStage). Leave out to keep the stages as they are (a new pipeline then gets the standard set). Stages already in the pipeline and not listed are kept.',\n items: { type: 'string', maxLength: CRM_SETUP_STAGE_NAME_MAX + 8 },\n maxItems: CRM_SETUP_OPEN_STAGES_MAX,\n },\n wonStage: {\n type: 'string',\n description: 'What the closing Won stage is called, where the request names it, e.g. \"Won\". Leave out to keep \"Closed Won\".',\n maxLength: CRM_SETUP_STAGE_NAME_MAX,\n },\n lostStage: {\n type: 'string',\n description: 'What the closing Lost stage is called, where the request names it, e.g. \"Lost\". Leave out to keep \"Closed Lost\".',\n maxLength: CRM_SETUP_STAGE_NAME_MAX,\n },\n makeDefault: {\n type: 'boolean',\n description: 'true only when the request says new deals should land in this pipeline (its main or default pipeline).',\n },\n },\n required: ['name'],\n additionalProperties: false,\n },\n maxPerPlan: CRM_PIPELINE_AI_MAX_PER_PLAN,\n freeAllowed: false,\n feature: CRM_FEATURE,\n draftResource: CRM_PIPELINE_SETUP_RESOURCE,\n live: true,\n // Written without a model: the planner already filled the arguments.\n estimateCredits: () => 0,\n degrade: 'omit',\n draftContent: (item) => crmPipelineSetupContentFromArgs(item.args),\n}\n\nexport const crmFieldAiCapability: PluginAiCapability = {\n op: CRM_FIELD_AI_OP,\n noun: 'CRM custom field',\n where: 'CRM → Fields',\n intents: [\n 'CRM custom fields on contacts, companies (accounts), deals (opportunities) or leads — \"add a Budget field to opportunities\", \"a Choice field for Industry on companies\"; types text, number, date, choice, checkbox, link and currency (an amount of money: budget, deal size, revenue)',\n ],\n argsSchema: {\n type: 'object',\n properties: {\n object: {\n type: 'string',\n description: 'The record it describes: contact; company (an account); deal (an opportunity); lead.',\n enum: CRM_FIELD_OBJECTS,\n },\n label: {\n type: 'string',\n description:\n 'The field’s name as people read it, e.g. \"Budget\". A field of this name on the same record (any case) is left as it is rather than duplicated.',\n maxLength: CRM_FIELD_LABEL_MAX_LENGTH,\n },\n type: {\n type: 'string',\n description:\n 'What it holds: text; number (a count or a percentage); currency (an amount of money — a budget, a price, revenue — with \"currency\"); date; select (a Choice from listed options); checkbox (yes or no); url (a link).',\n enum: CONTACT_FIELD_TYPES,\n },\n options: {\n type: 'array',\n description: 'For select only: the choices, in order. A select field that exists gains the ones it lacks.',\n items: { type: 'string', maxLength: CRM_FIELD_OPTION_MAX_LENGTH },\n maxItems: CRM_FIELD_OPTIONS_MAX,\n },\n currency: {\n type: 'string',\n description:\n 'For currency only: the ISO 4217 code its amounts are in, e.g. \"EUR\", when the request names one. Leave out for US dollars.',\n maxLength: 3,\n },\n required: {\n type: 'boolean',\n description: 'true only when the request says the field must always be filled in.',\n },\n },\n required: ['object', 'label', 'type'],\n additionalProperties: false,\n },\n maxPerPlan: CRM_FIELD_AI_MAX_PER_PLAN,\n freeAllowed: false,\n feature: CRM_FEATURE,\n draftResource: CRM_FIELD_SETUP_RESOURCE,\n live: true,\n estimateCredits: () => 0,\n degrade: 'omit',\n draftContent: (item) => crmFieldSetupContentFromArgs(item.args),\n}\n\n/** The picklist values writer's content for an item: its arguments, as they are. Pure. */\nexport function crmPicklistValuesSetupContentFromArgs(args: PluginAiCapabilityArgs): Readonly<Record<string, unknown>> {\n return pick(args, ['list', 'object', 'field', 'values', 'meaning', 'group'])\n}\n\n/**\n * VALUES ADDED TO A CRM PICKLIST (AGL-3756): \"add Nurturing as a lead\n * status\", \"add Trade show and Podcast as lead sources\", \"add Renewal as a\n * deal type\", \"add Enterprise to the Tier choices on companies\". Written by\n * the `crm-picklist-values` writer, so the rules are the Fields page's: only\n * adds, matched without capitals, never removes, renames, reorders or\n * reactivates. Live, as the console's Add value is; 0 credits.\n */\nexport const crmPicklistValuesAiCapability: PluginAiCapability = {\n op: CRM_PICKLIST_VALUES_AI_OP,\n noun: 'CRM picklist values',\n where: 'CRM → Fields',\n intents: [\n 'add values to a CRM picklist — a lead status (\"Contacted\", meaning Working), a lead source (Inbound or Outbound), a deal (opportunity) type or contact role, a company (account) type, industry, rating or ownership, a salutation, a task status, priority, type or subject — or add choices to a custom Choice field; only adds, never removes or renames',\n ],\n argsSchema: {\n type: 'object',\n properties: {\n list: {\n type: 'string',\n description:\n 'Which list: leadStatus, leadSource, opportunityType (a deal’s Type), opportunityContactRole, accountType (a company’s Type), industry, rating, ownership, salutation, taskStatus, taskPriority, taskType, taskSubject; or custom for a custom Choice field (then give object and field).',\n enum: CRM_PICKLIST_VALUES_LISTS,\n },\n object: {\n type: 'string',\n description: 'For custom only: the record the Choice field is on — contact; company; deal; lead.',\n enum: CRM_FIELD_OBJECTS,\n },\n field: {\n type: 'string',\n description: 'For custom only: the Choice field’s name, e.g. \"Tier\".',\n maxLength: 80,\n },\n values: {\n type: 'array',\n description:\n 'The values to add, in order, e.g. [\"Trade show\", \"Podcast\"]. A value the list already has (any capitals) is left as it is. Never values to remove or rename.',\n items: { type: 'string', maxLength: 120 },\n maxItems: CRM_PICKLIST_VALUES_SETUP_MAX,\n },\n meaning: {\n type: 'string',\n description:\n 'Required for leadStatus, taskStatus, taskPriority and taskType: what every value in this item means. leadStatus: new, nurturing, working or unqualified (never qualified); taskStatus: open or done; taskPriority: low, normal or high; taskType: call, email, meeting or todo. Split values of different meanings into separate items.',\n maxLength: 40,\n },\n group: {\n type: 'string',\n description: 'For leadSource only: inbound (the lead came to them) or outbound (they went to the lead), when the request says or it is plain.',\n enum: ['inbound', 'outbound'],\n },\n },\n required: ['list', 'values'],\n additionalProperties: false,\n },\n maxPerPlan: CRM_PICKLIST_VALUES_AI_MAX_PER_PLAN,\n freeAllowed: false,\n feature: CRM_FEATURE,\n draftResource: CRM_PICKLIST_VALUES_SETUP_RESOURCE,\n live: true,\n estimateCredits: () => 0,\n degrade: 'omit',\n draftContent: (item) => crmPicklistValuesSetupContentFromArgs(item.args),\n}\n\n/**\n * Registers both capabilities; the console-server declarations call it beside\n * the writers, since only the console runs AI jobs (AGL-3026). Idempotent.\n */\nexport function registerCrmSetupAiCapabilities(): void {\n registerPluginAiCapability(crmPipelineAiCapability, { pluginId: BUNDLE_ID })\n registerPluginAiCapability(crmFieldAiCapability, { pluginId: BUNDLE_ID })\n registerPluginAiCapability(crmPicklistValuesAiCapability, { pluginId: BUNDLE_ID })\n}\n"],"names":["CONTACT_FIELD_TYPES","CRM_FIELD_OBJECTS","registerPluginAiCapability","BUNDLE_ID","CRM_FIELD_LABEL_MAX_LENGTH","CRM_FIELD_OPTION_MAX_LENGTH","CRM_FIELD_OPTIONS_MAX","CRM_FIELD_SETUP_RESOURCE","CRM_PIPELINE_SETUP_RESOURCE","CRM_SETUP_OPEN_STAGES_MAX","CRM_SETUP_STAGE_NAME_MAX","CRM_PICKLIST_VALUES_LISTS","CRM_PICKLIST_VALUES_SETUP_MAX","CRM_PICKLIST_VALUES_SETUP_RESOURCE","PIPELINE_NAME_MAX","CRM_PIPELINE_AI_OP","CRM_FIELD_AI_OP","CRM_PICKLIST_VALUES_AI_OP","CRM_PIPELINE_AI_MAX_PER_PLAN","CRM_FIELD_AI_MAX_PER_PLAN","CRM_PICKLIST_VALUES_AI_MAX_PER_PLAN","CRM_FEATURE","pick","args","keys","Object","fromEntries","filter","key","undefined","map","crmPipelineSetupContentFromArgs","crmFieldSetupContentFromArgs","crmPipelineAiCapability","op","noun","where","intents","argsSchema","type","properties","name","description","maxLength","renameFrom","stages","items","maxItems","wonStage","lostStage","makeDefault","required","additionalProperties","maxPerPlan","freeAllowed","feature","draftResource","live","estimateCredits","degrade","draftContent","item","crmFieldAiCapability","object","enum","label","options","currency","crmPicklistValuesSetupContentFromArgs","crmPicklistValuesAiCapability","list","field","values","meaning","group","registerCrmSetupAiCapabilities","pluginId"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,mBAAmB,QAAQ,+CAA8C;AAClF,SAASC,iBAAiB,QAAQ,6BAA4B;AAC9D,SACEC,0BAA0B,QAGrB,qDAAoD;AAC3D,SAASC,SAAS,QAAQ,gCAA4B;AACtD,SACEC,0BAA0B,EAC1BC,2BAA2B,EAC3BC,qBAAqB,EACrBC,wBAAwB,EACxBC,2BAA2B,EAC3BC,yBAAyB,EACzBC,wBAAwB,QACnB,gCAA4B;AACnC,SACEC,yBAAyB,EACzBC,6BAA6B,EAC7BC,kCAAkC,QAC7B,yCAAqC;AAC5C,SAASC,iBAAiB,QAAQ,+BAA2B;AAE7D;;;;;;;;;;;;;;;;;;;;CAoBC,GAED,2CAA2C,GAC3C,OAAO,MAAMC,qBAAqB,eAAc;AAChD,OAAO,MAAMC,kBAAkB,YAAW;AAC1C,OAAO,MAAMC,4BAA4B,sBAAqB;AAE9D,2CAA2C,GAC3C,OAAO,MAAMC,+BAA+B,EAAC;AAC7C,OAAO,MAAMC,4BAA4B,GAAE;AAC3C,OAAO,MAAMC,sCAAsC,GAAE;AAErD,mEAAmE,GACnE,MAAMC,cAAc;AAEpB,SAASC,KAAKC,IAA4B,EAAEC,IAAuB;IACjE,OAAOC,OAAOC,WAAW,CAACF,KAAKG,MAAM,CAAC,CAACC,MAAQL,IAAI,CAACK,IAAI,KAAKC,aAAaN,IAAI,CAACK,IAAI,KAAK,IAAIE,GAAG,CAAC,CAACF,MAAQ;YAACA;YAAKL,IAAI,CAACK,IAAI;SAAC;AAC3H;AAEA,iFAAiF,GACjF,OAAO,SAASG,gCAAgCR,IAA4B;IAC1E,OAAOD,KAAKC,MAAM;QAAC;QAAQ;QAAc;QAAU;QAAY;QAAa;KAAc;AAC5F;AAEA,8EAA8E,GAC9E,OAAO,SAASS,6BAA6BT,IAA4B;IACvE,OAAOD,KAAKC,MAAM;QAAC;QAAU;QAAS;QAAQ;QAAW;QAAY;KAAW;AAClF;AAEA,OAAO,MAAMU,0BAA8C;IACzDC,IAAInB;IACJoB,MAAM;IACNC,OAAO;IACPC,SAAS;QACP;KACD;IACDC,YAAY;QACVC,MAAM;QACNC,YAAY;YACVC,MAAM;gBACJF,MAAM;gBACNG,aACE;gBACFC,WAAW7B;YACb;YACA8B,YAAY;gBACVL,MAAM;gBACNG,aAAa;gBACbC,WAAW7B;YACb;YACA+B,QAAQ;gBACNN,MAAM;gBACNG,aACE;gBACFI,OAAO;oBAAEP,MAAM;oBAAUI,WAAWjC,2BAA2B;gBAAE;gBACjEqC,UAAUtC;YACZ;YACAuC,UAAU;gBACRT,MAAM;gBACNG,aAAa;gBACbC,WAAWjC;YACb;YACAuC,WAAW;gBACTV,MAAM;gBACNG,aAAa;gBACbC,WAAWjC;YACb;YACAwC,aAAa;gBACXX,MAAM;gBACNG,aAAa;YACf;QACF;QACAS,UAAU;YAAC;SAAO;QAClBC,sBAAsB;IACxB;IACAC,YAAYnC;IACZoC,aAAa;IACbC,SAASlC;IACTmC,eAAehD;IACfiD,MAAM;IACN,qEAAqE;IACrEC,iBAAiB,IAAM;IACvBC,SAAS;IACTC,cAAc,CAACC,OAAS9B,gCAAgC8B,KAAKtC,IAAI;AACnE,EAAC;AAED,OAAO,MAAMuC,uBAA2C;IACtD5B,IAAIlB;IACJmB,MAAM;IACNC,OAAO;IACPC,SAAS;QACP;KACD;IACDC,YAAY;QACVC,MAAM;QACNC,YAAY;YACVuB,QAAQ;gBACNxB,MAAM;gBACNG,aAAa;gBACbsB,MAAM/D;YACR;YACAgE,OAAO;gBACL1B,MAAM;gBACNG,aACE;gBACFC,WAAWvC;YACb;YACAmC,MAAM;gBACJA,MAAM;gBACNG,aACE;gBACFsB,MAAMhE;YACR;YACAkE,SAAS;gBACP3B,MAAM;gBACNG,aAAa;gBACbI,OAAO;oBAAEP,MAAM;oBAAUI,WAAWtC;gBAA4B;gBAChE0C,UAAUzC;YACZ;YACA6D,UAAU;gBACR5B,MAAM;gBACNG,aACE;gBACFC,WAAW;YACb;YACAQ,UAAU;gBACRZ,MAAM;gBACNG,aAAa;YACf;QACF;QACAS,UAAU;YAAC;YAAU;YAAS;SAAO;QACrCC,sBAAsB;IACxB;IACAC,YAAYlC;IACZmC,aAAa;IACbC,SAASlC;IACTmC,eAAejD;IACfkD,MAAM;IACNC,iBAAiB,IAAM;IACvBC,SAAS;IACTC,cAAc,CAACC,OAAS7B,6BAA6B6B,KAAKtC,IAAI;AAChE,EAAC;AAED,wFAAwF,GACxF,OAAO,SAAS6C,sCAAsC7C,IAA4B;IAChF,OAAOD,KAAKC,MAAM;QAAC;QAAQ;QAAU;QAAS;QAAU;QAAW;KAAQ;AAC7E;AAEA;;;;;;;CAOC,GACD,OAAO,MAAM8C,gCAAoD;IAC/DnC,IAAIjB;IACJkB,MAAM;IACNC,OAAO;IACPC,SAAS;QACP;KACD;IACDC,YAAY;QACVC,MAAM;QACNC,YAAY;YACV8B,MAAM;gBACJ/B,MAAM;gBACNG,aACE;gBACFsB,MAAMrD;YACR;YACAoD,QAAQ;gBACNxB,MAAM;gBACNG,aAAa;gBACbsB,MAAM/D;YACR;YACAsE,OAAO;gBACLhC,MAAM;gBACNG,aAAa;gBACbC,WAAW;YACb;YACA6B,QAAQ;gBACNjC,MAAM;gBACNG,aACE;gBACFI,OAAO;oBAAEP,MAAM;oBAAUI,WAAW;gBAAI;gBACxCI,UAAUnC;YACZ;YACA6D,SAAS;gBACPlC,MAAM;gBACNG,aACE;gBACFC,WAAW;YACb;YACA+B,OAAO;gBACLnC,MAAM;gBACNG,aAAa;gBACbsB,MAAM;oBAAC;oBAAW;iBAAW;YAC/B;QACF;QACAb,UAAU;YAAC;YAAQ;SAAS;QAC5BC,sBAAsB;IACxB;IACAC,YAAYjC;IACZkC,aAAa;IACbC,SAASlC;IACTmC,eAAe3C;IACf4C,MAAM;IACNC,iBAAiB,IAAM;IACvBC,SAAS;IACTC,cAAc,CAACC,OAASO,sCAAsCP,KAAKtC,IAAI;AACzE,EAAC;AAED;;;CAGC,GACD,OAAO,SAASoD;IACdzE,2BAA2B+B,yBAAyB;QAAE2C,UAAUzE;IAAU;IAC1ED,2BAA2B4D,sBAAsB;QAAEc,UAAUzE;IAAU;IACvED,2BAA2BmE,+BAA+B;QAAEO,UAAUzE;IAAU;AAClF"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { type CrmPicklist, type CrmPicklistId, type CrmPicklistObject, type CrmPicklistTarget } from '@aglyn/aglyn/app-utils/crm';
|
|
18
|
+
import type { PluginResourceDraftWriter } from '@aglyn/aglyn/plugin-manager/plugin-resource-drafts';
|
|
19
|
+
import { type CrmFieldDefinitionDoc } from '../model/crm-setup-content';
|
|
20
|
+
import type { PipelineDoc } from '../model/deal-board-model';
|
|
21
|
+
/**
|
|
22
|
+
* THE CRM'S SETUP WRITERS (AGL-3746): a deal pipeline and a custom field,
|
|
23
|
+
* saved for another plugin — Aglyn AI's build — under the CRM's rules.
|
|
24
|
+
*
|
|
25
|
+
* Registered on the core's resource-drafts seam as `crm-pipeline` and
|
|
26
|
+
* `crm-field`. Neither is a draft: a pipeline and a field have no draft
|
|
27
|
+
* state, and the console saves both live, so these do too, and their AI
|
|
28
|
+
* capabilities say so (`live`). What they write is exactly what the
|
|
29
|
+
* console's Pipelines dialog and Fields section write
|
|
30
|
+
* (`model/crm-setup-content.ts`), and they admit exactly whom the Firestore
|
|
31
|
+
* rules admit for those writes, since the Admin SDK passes the rules by:
|
|
32
|
+
*
|
|
33
|
+
* - THE SITE is the org's, and THE PLAN carries the CRM (`crm`, Starter and
|
|
34
|
+
* up — `orgCarriesCrmSuite`), refused in the suite gate's words;
|
|
35
|
+
* - THE MEMBER is an owner, admin or editor (`canWriteOrgData`) whose org
|
|
36
|
+
* access is not suspended, holding `data.manage`, the key the whole CRM
|
|
37
|
+
* is gated on;
|
|
38
|
+
* - THE SCOPE is one the member can create in (`canCreateScoped`): a
|
|
39
|
+
* pipeline is stamped as the board's seed stamps it from this site
|
|
40
|
+
* (`crmScopeTokens`), a field org-wide, which only an org-wide member
|
|
41
|
+
* reaches.
|
|
42
|
+
*
|
|
43
|
+
* Idempotent: the job's attempt key is a new pipeline's or field's id, and
|
|
44
|
+
* an existing pipeline, stage or field is matched by name (see the model),
|
|
45
|
+
* so asking again changes nothing.
|
|
46
|
+
*/
|
|
47
|
+
type Firestore = FirebaseFirestore.Firestore;
|
|
48
|
+
/** The refusals, in the console's and the routes' words. */
|
|
49
|
+
export declare const CRM_SETUP_ROLE_REFUSAL = "Editing the CRM requires the editor role";
|
|
50
|
+
export declare const CRM_SETUP_PERMISSION_REFUSAL = "Your organization role does not allow editing organization data";
|
|
51
|
+
export declare const CRM_SETUP_SCOPE_REFUSAL = "Your access to this organization does not reach that site";
|
|
52
|
+
export declare const CRM_SETUP_FIELD_SCOPE_REFUSAL = "Custom fields are organization-wide, and your access reaches only some sites";
|
|
53
|
+
export declare const CRM_SETUP_PICKLIST_SCOPE_REFUSAL = "Picklists are organization-wide, and your access reaches only some sites";
|
|
54
|
+
/** Who the member is in the org, as the writers ask. */
|
|
55
|
+
export interface CrmSetupMember {
|
|
56
|
+
role: string;
|
|
57
|
+
canManageData: boolean;
|
|
58
|
+
/** The membership itself, for its reach and whether it is suspended. */
|
|
59
|
+
member: Readonly<Record<string, unknown>>;
|
|
60
|
+
}
|
|
61
|
+
/** The reads and writes the writers make, over the Admin SDK unless a spec hands in its own. */
|
|
62
|
+
export interface CrmSetupStore {
|
|
63
|
+
/** The pipelines readable under these scope tokens. */
|
|
64
|
+
pipelines(orgId: string, readTokens: readonly string[]): Promise<PipelineDoc[]>;
|
|
65
|
+
pipeline(orgId: string, id: string): Promise<PipelineDoc | null>;
|
|
66
|
+
/** One batch: the new or changed pipeline, and the default flag off the others. */
|
|
67
|
+
savePipeline(orgId: string, write: {
|
|
68
|
+
id: string;
|
|
69
|
+
create?: Record<string, unknown>;
|
|
70
|
+
update?: Record<string, unknown>;
|
|
71
|
+
defaultsOff: string[];
|
|
72
|
+
}, now: Date): Promise<void>;
|
|
73
|
+
/** Every definition the org holds, retired ones included, to the ceiling and one past it. */
|
|
74
|
+
fields(orgId: string): Promise<CrmFieldDefinitionDoc[]>;
|
|
75
|
+
field(orgId: string, id: string): Promise<CrmFieldDefinitionDoc | null>;
|
|
76
|
+
createField(orgId: string, id: string, document: Record<string, unknown>): Promise<void>;
|
|
77
|
+
setFieldOptions(orgId: string, id: string, options: string[], now: Date): Promise<void>;
|
|
78
|
+
/** A picklist's stored document, or `null` for an org that never stored one (AGL-3756). */
|
|
79
|
+
picklist(orgId: string, id: CrmPicklistId): Promise<Readonly<Record<string, unknown>> | null>;
|
|
80
|
+
/**
|
|
81
|
+
* Read a picklist and write it back in one transaction, as the console's
|
|
82
|
+
* route does, so a person editing the list at the same moment is not
|
|
83
|
+
* overwritten. `change` answers the list to write, or `null` for none.
|
|
84
|
+
*/
|
|
85
|
+
changePicklist<T>(orgId: string, id: CrmPicklistId, change: (stored: Readonly<Record<string, unknown>> | null) => {
|
|
86
|
+
write: CrmPicklist | null;
|
|
87
|
+
result: T;
|
|
88
|
+
}, stamp: {
|
|
89
|
+
hostId: string;
|
|
90
|
+
}): Promise<T>;
|
|
91
|
+
/** A value's group onto every record of `object` holding `label` (a lead's `leadSourceDirection`). */
|
|
92
|
+
regroup(orgId: string, object: CrmPicklistObject, target: CrmPicklistTarget, label: string, group: string | null): Promise<number>;
|
|
93
|
+
}
|
|
94
|
+
export interface CrmSetupWriterDeps {
|
|
95
|
+
store?: CrmSetupStore;
|
|
96
|
+
/** The org a site belongs to; the platform's lookup otherwise. */
|
|
97
|
+
orgIdForHost?: (hostId: string) => Promise<string | null>;
|
|
98
|
+
/** The member, or `null` when they are not one; the platform's otherwise. */
|
|
99
|
+
member?: (uid: string, orgId: string) => Promise<CrmSetupMember | null>;
|
|
100
|
+
}
|
|
101
|
+
/** The CRM's collections over the Admin SDK. */
|
|
102
|
+
export declare function adminCrmSetupStore(firestore?: () => Firestore): CrmSetupStore;
|
|
103
|
+
/** The `crm-pipeline` writer: creates or brings a pipeline to the ask. */
|
|
104
|
+
export declare function createCrmPipelineSetupWriter(deps?: CrmSetupWriterDeps): PluginResourceDraftWriter;
|
|
105
|
+
/** The `crm-field` writer: creates a custom field, or finds the one asked for. */
|
|
106
|
+
export declare function createCrmFieldSetupWriter(deps?: CrmSetupWriterDeps): PluginResourceDraftWriter;
|
|
107
|
+
export declare const crmPipelineSetupWriter: PluginResourceDraftWriter;
|
|
108
|
+
export declare const crmFieldSetupWriter: PluginResourceDraftWriter;
|
|
109
|
+
/**
|
|
110
|
+
* The `crm-picklist-values` writer: adds values to a standard CRM picklist
|
|
111
|
+
* or a custom Choice field's choices, never removing, renaming, reordering
|
|
112
|
+
* or reactivating one. Gated as the Fields page is — the `crm` feature, an
|
|
113
|
+
* owner, admin or editor with `data.manage` — and org-wide, as every
|
|
114
|
+
* picklist and field document is. A lead source added where records
|
|
115
|
+
* already hold its label files them under its group (`leadSourceDirection`),
|
|
116
|
+
* as the console's route does (AGL-3577).
|
|
117
|
+
*/
|
|
118
|
+
export declare function createCrmPicklistValuesSetupWriter(deps?: CrmSetupWriterDeps): PluginResourceDraftWriter;
|
|
119
|
+
export declare const crmPicklistValuesSetupWriter: PluginResourceDraftWriter;
|
|
120
|
+
export {};
|