@aglyn/plugins-crm 1.30.0 → 1.32.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/activity-list.js +31 -9
- package/src/lib/components/activity-list.js.map +1 -1
- package/src/lib/components/activity-recording.d.ts +74 -0
- package/src/lib/components/activity-recording.js +608 -0
- package/src/lib/components/activity-recording.js.map +1 -0
- package/src/lib/components/log-activity-dialog.js +38 -3
- package/src/lib/components/log-activity-dialog.js.map +1 -1
- package/src/lib/model/crm-search-sources.js +2 -1
- package/src/lib/model/crm-search-sources.js.map +1 -1
- package/src/lib/server/api-v1/crm-activities.js +119 -14
- package/src/lib/server/api-v1/crm-activities.js.map +1 -1
- package/src/lib/server/api-v1/openapi.js +50 -2
- package/src/lib/server/api-v1/openapi.js.map +1 -1
- package/src/lib/server/person-eraser.d.ts +30 -0
- package/src/lib/server/person-eraser.js +88 -1
- package/src/lib/server/person-eraser.js.map +1 -1
- package/src/lib/server/record-timeline.js +11 -1
- package/src/lib/server/record-timeline.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../libs/plugins/crm/src/lib/server/api-v1/openapi.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n type ApiV1ResourceDescription,\n booleanField,\n integerField,\n isoField,\n nullableField,\n objectKindField,\n openObjectField,\n postalAddressField,\n queryParam,\n requiredQueryParam,\n RECORD_STAMPS,\n stringField,\n stringListField,\n UPDATED_AFTER_PARAM,\n} from '@aglyn/tenant-data-admin/server/api-v1-description'\n\n/**\n * The CRM's resources as the customer API's OpenAPI document describes them\n * (AGL-2733), keyed by the resource each describes — what the console's\n * builder turns into their paths, tags and schemas, and the MCP tools derive\n * from.\n *\n * Transcribed from the response examples in `apps/docs/api/resources/*.md`,\n * the customer-facing contract, as the platform's own resources are; each\n * write body lists its handler's own writable set. `api-v1-openapi.spec.ts`\n * holds the document to every endpoint the documentation promises.\n */\n/** How a company picklist field reads in the description (AGL-3514). */\nfunction companyPicklistNote(label: string, plural: string): string {\n return (\n `${label}: one of the organization's active ${plural} (CRM › Fields › Companies), matched ` +\n 'without regard to case. Any other value is refused with a 400 naming the values allowed; ' +\n 'the value a company already holds is kept even after it is deactivated.'\n )\n}\n\n\n/**\n * The site a lead belongs to (AGL-4225). A lead is a site's record and its id\n * is unique only within the site, so the handler refuses every lead request\n * without one — and until this was declared, a client reading the document\n * could not know to send it.\n */\nconst LEAD_SITE_PARAM = requiredQueryParam(\n 'siteId',\n 'Required. The site the lead belongs to — the `id` of a site from `listSites`.',\n)\n\nexport const CRM_API_V1_DESCRIPTIONS: Readonly<Record<string, ApiV1ResourceDescription>> = {\n contacts: {\n tag: 'Contacts',\n docsPage: 'contacts',\n description: 'People, organization-wide. Part of the CRM, which is included from Starter.',\n schemaName: 'Contact',\n required: ['id', 'object', 'email'],\n writable: [\n 'email', 'name', 'tags', 'notes', 'marketingConsent', 'consentSiteId', 'consentGroupId', 'custom',\n 'phone', 'jobTitle', 'companyId', 'address', 'ownerUid', 'lifecycleStage', 'mediaIds',\n 'leadSource',\n // Salesforce's standard contact fields (AGL-3515).\n 'salutation', 'firstName', 'lastName', 'department', 'mobilePhone', 'homePhone', 'otherPhone',\n 'fax', 'birthdate', 'assistantName', 'assistantPhone', 'reportsToContactId', 'otherAddress', 'doNotCall',\n ],\n writeOnly: {\n consentSiteId: stringField('The site this write is made on behalf of: where the person opted in, and whose profile the profile fields land on.'),\n consentGroupId: stringField('With `marketingConsent: true`: the consent group the person was shown when they opted in. The opt-in then covers every site of that group; without it, or when the site is no longer in that group, it covers `consentSiteId` alone.'),\n custom: openObjectField('Contact custom fields, keyed by field key.'),\n mediaIds: stringListField('Media library files attached by the named site, by id, at most 20. An empty array clears them.'),\n },\n writeNote: 'A create needs an `email`, a `name`, a `phone`, a `mobilePhone`, or a `firstName` or `lastName`. `email` is accepted on create only — a `PATCH` that names it is a `400`, because a contact is identified by its email.',\n fields: {\n id: stringField('Contact id.'),\n object: objectKindField('contact'),\n email: nullableField(\n stringField('Primary email, unique per organization, or `null` for a contact with no address yet.'),\n ),\n name: stringField('Display name.'),\n tags: stringListField('Free-form tags.'),\n notes: stringField('Free-form notes.'),\n marketingConsent: booleanField('Whether the contact accepted marketing email.'),\n consentSites: stringListField('Site ids the consent was given on.'),\n sources: stringListField('Where this contact came from.'),\n phone: stringField('Telephone number.'),\n jobTitle: stringField('Job title.'),\n companyId: nullableField(stringField('Primary company.')),\n address: postalAddressField(),\n ownerUid: nullableField(stringField('Owning user. Checked on the page, not the query.')),\n lifecycleStage: nullableField(stringField('CRM lifecycle stage.')),\n leadSource: nullableField(stringField('Lead source: one of the organization’s Lead source values (CRM › Fields › Leads), stored on the named site’s profile. A value the list does not hold is a `400` naming the values it allows.')),\n // Salesforce's standard contact fields (AGL-3515).\n salutation: nullableField(stringField(\"One of the organization's salutation values (Mr., Ms., Mrs., Dr., Prof. and its own).\")),\n firstName: nullableField(stringField('First name. With `lastName`, it makes the name the named site shows.')),\n lastName: nullableField(stringField('Last name.')),\n department: nullableField(stringField('Department.')),\n mobilePhone: nullableField(stringField('Mobile phone, E.164.')),\n homePhone: nullableField(stringField('Home phone, E.164.')),\n otherPhone: nullableField(stringField('Other phone, E.164.')),\n fax: nullableField(stringField('Fax, E.164.')),\n birthdate: nullableField(stringField('Birthdate, `YYYY-MM-DD`, never in the future.')),\n assistantName: nullableField(stringField(\"Assistant's name.\")),\n assistantPhone: nullableField(stringField(\"Assistant's phone, E.164.\")),\n reportsToContactId: nullableField(stringField('The contact this person reports to. Never the contact itself, and never one that already reports to it.')),\n otherAddress: nullableField(postalAddressField()),\n doNotCall: booleanField('The person asked not to be phoned.'),\n companyIds: stringListField('Every company this contact belongs to.'),\n alternateEmails: stringListField('Other addresses that resolve to this contact.'),\n ...RECORD_STAMPS,\n },\n ops: [\n {\n path: '/v1/contacts', method: 'get', operationId: 'listContacts', summary: 'List contacts', list: true, returns: 'Contact', entitlement: 'crm',\n description: 'Lists the workspace’s contacts: one record per person, with email, name, phone, tags and per-site profile. Filter by exact `email` to find one person.',\n filters: [\n queryParam('email', 'The contact with this email address. Letter case is ignored; an address that cannot be read is refused.'),\n queryParam('tag', 'Contacts with this tag.'),\n queryParam('lifecycleStage', 'Contacts at this lifecycle stage.'),\n queryParam('ownerUid', 'Contacts owned by this workspace member.'),\n ],\n },\n // openWorld: after saving, the address’s mail domain is looked up (DNS) to flag addresses that would bounce.\n { path: '/v1/contacts', method: 'post', operationId: 'createContact', summary: 'Add a contact', accepts: 'ContactWrite', returns: 'Contact', entitlement: 'crm', creates: true, description: 'Adds a person to the workspace’s contacts. An email address is a contact’s identity: one that already belongs to a contact is refused, naming the existing contact’s id. Returns the new contact.', openWorld: true },\n { path: '/v1/contacts/{contactId}', method: 'get', operationId: 'getContact', summary: 'Get a contact', description: 'Returns one contact. Needs `contactId` from List contacts.', returns: 'Contact', entitlement: 'crm', pathParams: [{ name: 'contactId', description: 'Contact id.' }] },\n { path: '/v1/contacts/{contactId}', method: 'patch', operationId: 'updateContact', summary: 'Update a contact', description: 'Changes a contact’s details; fields not sent stay as they are. The email address cannot be changed. Needs `contactId` from List contacts. Returns the updated contact.', accepts: 'ContactWrite', returns: 'Contact', entitlement: 'crm', pathParams: [{ name: 'contactId', description: 'Contact id.' }] },\n { path: '/v1/contacts/{contactId}', method: 'delete', operationId: 'deleteContact', summary: 'Delete a contact', description: 'Removes a person from the workspace’s contacts, with the tags, notes, timeline and consent the workspace’s sites hold for them. Permanent. Needs `contactId` from List contacts.', returns: 'Deleted', entitlement: 'crm', pathParams: [{ name: 'contactId', description: 'Contact id.' }] },\n { path: '/v1/contacts/{contactId}/merge', method: 'post', operationId: 'mergeContact', summary: 'Merge two contacts', description: 'Folds one contact into another: the contact in `contactId` survives and keeps its email, and the contact named in `sourceContactId` is merged into it and deleted. Permanent. Returns the surviving contact.', accepts: 'ContactMerge', returns: 'Contact', entitlement: 'crm', destructive: true, pathParams: [{ name: 'contactId', description: 'The contact that survives.' }], idempotent: true },\n ],\n components: {\n ContactMerge: {\n type: 'object',\n required: ['sourceContactId'],\n description:\n 'Merge another contact into this one. The source is removed. Any other ' +\n 'member is a `400`.',\n properties: {\n sourceContactId: {\n type: 'string',\n description:\n 'The contact to merge FROM. It does not survive, and it must not be ' +\n 'the contact in the path.',\n },\n },\n additionalProperties: false,\n },\n },\n },\n companies: {\n tag: 'Companies',\n docsPage: 'companies',\n description: 'Organizations in the CRM.',\n schemaName: 'Company',\n required: ['id', 'object', 'name'],\n writable: [\n 'name', 'domain', 'website', 'phone', 'address', 'industry', 'ownerUid', 'notes', 'custom', 'mediaIds', 'consentSiteId',\n // Salesforce's Account fields (AGL-3514).\n 'type', 'rating', 'ownership', 'accountSource', 'annualRevenueCents', 'currency', 'numberOfEmployees', 'fax',\n 'accountNumber', 'site', 'tickerSymbol', 'sicCode', 'shippingAddress', 'parentCompanyId',\n ],\n writeOnly: {\n mediaIds: stringListField('Media library files attached to this company, by id, at most 20. An empty array clears them.'),\n consentSiteId: stringField('The site the company is created on behalf of.'),\n },\n writeNote: 'A create needs `name` and `consentSiteId`; a `PATCH` that names `consentSiteId` is a `400`.',\n fields: {\n id: stringField('Company id.'),\n object: objectKindField('company'),\n name: stringField('Company name.'),\n domain: nullableField(stringField('Primary domain. Unique per organization.')),\n website: nullableField(stringField('Website URL.')),\n phone: nullableField(stringField('Telephone number.')),\n address: { ...postalAddressField(), description: 'Billing address. Members are optional and free-form.' },\n industry: nullableField(stringField(companyPicklistNote('Industry', 'industries'))),\n // Salesforce's Account fields (AGL-3514).\n type: nullableField(stringField(companyPicklistNote('Account type', 'types'))),\n rating: nullableField(stringField(companyPicklistNote('Rating', 'ratings'))),\n ownership: nullableField(stringField(companyPicklistNote('Ownership', 'ownership values'))),\n accountSource: nullableField(\n stringField(\n \"Where the account came from: one of the organization's active lead source values \" +\n '(CRM › Fields › Leads), matched without regard to case. Any other value is refused ' +\n 'with a 400 naming the values allowed; the value a company already holds is kept.',\n ),\n ),\n annualRevenueCents: nullableField(integerField('Annual revenue in the minor unit of `currency`, 0 or more.')),\n currency: stringField('Lowercase ISO 4217 code of the annual revenue. `usd` when unset.'),\n numberOfEmployees: nullableField(integerField('Number of employees, 0 to 99,999,999.')),\n fax: nullableField(stringField('E.164 fax number.')),\n accountNumber: nullableField(stringField('Account number, at most 40 characters.')),\n site: nullableField(stringField('Which of the company’s locations this record is, at most 80 characters.')),\n tickerSymbol: nullableField(stringField('Stock ticker symbol, at most 20 characters.')),\n sicCode: nullableField(stringField('Standard Industrial Classification code, at most 20 characters.')),\n shippingAddress: { ...postalAddressField(), description: 'Shipping address. Members are optional and free-form.' },\n parentCompanyId: nullableField(\n stringField('The company this one sits under. Never itself or a company below it; deleting the parent clears it.'),\n ),\n ownerUid: nullableField(stringField('Owning user.')),\n notes: nullableField(stringField('Free-form notes.')),\n custom: openObjectField('Customer-defined fields.'),\n nextTaskAt: nullableField(isoField('When the next open task on this company is due.')),\n siteId: nullableField(stringField('Site the record originated on.')),\n ...RECORD_STAMPS,\n },\n ops: [\n { path: '/v1/companies', method: 'get', operationId: 'listCompanies', summary: 'List companies', description: 'Lists the companies in the workspace’s CRM. Filter by exact `domain` to find one.', list: true, returns: 'Company', entitlement: 'crm', filters: [UPDATED_AFTER_PARAM, queryParam('domain', 'Exact match.'), queryParam('ownerUid', 'Owning user.')] },\n { path: '/v1/companies', method: 'post', operationId: 'createCompany', summary: 'Add a company', accepts: 'CompanyWrite', returns: 'Company', entitlement: 'crm', creates: true, description: 'Adds a company to the CRM. Needs a `name`. A company whose domain is already in the CRM is refused, naming the existing id. Returns the new company.', bodyRequires: ['name'] },\n { path: '/v1/companies/{companyId}', method: 'get', operationId: 'getCompany', summary: 'Get a company', description: 'Returns one company. Needs `companyId` from List companies.', returns: 'Company', entitlement: 'crm', pathParams: [{ name: 'companyId', description: 'Company id.' }] },\n { path: '/v1/companies/{companyId}', method: 'patch', operationId: 'updateCompany', summary: 'Update a company', description: 'Changes a company’s details; fields not sent stay as they are. Needs `companyId` from List companies. Returns the updated company.', accepts: 'CompanyWrite', returns: 'Company', entitlement: 'crm', pathParams: [{ name: 'companyId', description: 'Company id.' }] },\n { path: '/v1/companies/{companyId}', method: 'delete', operationId: 'deleteCompany', summary: 'Delete a company', description: 'Deletes a company permanently. Needs `companyId` from List companies.', returns: 'Deleted', entitlement: 'crm', pathParams: [{ name: 'companyId', description: 'Company id.' }] },\n ],\n },\n pipelines: {\n tag: 'Pipelines',\n docsPage: 'pipelines',\n description: 'Deal pipelines and their stages. Read-only over the API.',\n schemaName: 'Pipeline',\n required: ['id', 'object', 'name', 'stages'],\n fields: {\n id: stringField('Pipeline id.'),\n object: objectKindField('pipeline'),\n name: stringField('Pipeline name.'),\n isDefault: booleanField('Whether new deals land here when none is named.'),\n archived: booleanField('Whether the pipeline is archived.'),\n archivedAt: nullableField(isoField('When it was archived.')),\n stages: {\n type: 'array',\n description: 'Ordered stages. A deal’s `stageId` names one of these.',\n items: {\n type: 'object',\n properties: {\n id: { type: 'string' },\n name: { type: 'string' },\n order: { type: 'integer' },\n probability: { type: 'integer', description: 'Chance of closing from this stage, 0–100.' },\n kind: { type: 'string', enum: ['open', 'won', 'lost'] },\n forecastCategory: {\n type: 'string',\n enum: ['omitted', 'pipeline', 'bestCase', 'commit', 'closed'],\n description: 'The forecast category a deal takes on landing in this stage.',\n },\n },\n additionalProperties: true,\n },\n },\n siteId: nullableField(stringField('Site the pipeline belongs to, when scoped.')),\n ...RECORD_STAMPS,\n },\n ops: [\n { path: '/v1/pipelines', method: 'get', operationId: 'listPipelines', summary: 'List deal pipelines', description: 'Lists the workspace’s sales pipelines and their stages. A stage’s id is the `stageId` a deal takes.', list: true, returns: 'Pipeline', entitlement: 'crm', filters: [UPDATED_AFTER_PARAM] },\n { path: '/v1/pipelines/{pipelineId}', method: 'get', operationId: 'getPipeline', summary: 'Get a deal pipeline', description: 'Returns one pipeline and its stages. Needs `pipelineId` from List deal pipelines.', returns: 'Pipeline', entitlement: 'crm', pathParams: [{ name: 'pipelineId', description: 'Pipeline id.' }] },\n ],\n },\n deals: {\n tag: 'Deals',\n docsPage: 'deals',\n description: 'Opportunities moving through a pipeline.',\n schemaName: 'Deal',\n required: ['id', 'object', 'title', 'pipelineId', 'stageId'],\n writable: ['title', 'pipelineId', 'stageId', 'status', 'amountCents', 'currency', 'lineItems', 'expectedCloseAt', 'ownerUid', 'contactId', 'companyId', 'lostReason', 'notes', 'custom', 'mediaIds', 'consentSiteId', 'type', 'leadSource', 'nextStep', 'probability', 'forecastCategory', 'campaignId', 'contactRoles'],\n writeOnly: {\n mediaIds: stringListField('Media library files attached to this deal, by id, at most 20. An empty array clears them.'),\n consentSiteId: stringField('The site the deal is created on behalf of.'),\n },\n writeNote:\n '`pipelineId` and `consentSiteId` are accepted on create only; a `PATCH` that names either is a `400`. ' +\n '`type` and `leadSource` must be active values of the organization’s lists (a deal keeps the value it holds). ' +\n 'A stage move sets `forecastCategory` from the new stage and clears `probability`, unless the same body sets them. ' +\n '`contactRoles` replaces the whole list: each contact once, at most 50, at most one `primary`, each `role` an active value of the organization’s contact roles. ' +\n 'The Primary is `contactId`: a body sending both must agree, and `contactId` alone makes that contact Primary.',\n fields: {\n id: stringField('Deal id.'),\n object: objectKindField('deal'),\n title: stringField('Deal title.'),\n pipelineId: stringField('Pipeline the deal sits in.'),\n stageId: stringField('Stage within that pipeline.'),\n status: stringField('`open`, `won` or `lost`.'),\n amountCents: integerField('Value in the smallest unit of `currency`.'),\n currency: stringField('ISO 4217 code.'),\n lineItems: { type: 'array', description: 'Line items, when the deal carries them.', items: { type: 'object', additionalProperties: true } },\n expectedCloseAt: nullableField(isoField('Forecast close date.')),\n closedAt: nullableField(isoField('When it was actually closed.')),\n stageChangedAt: nullableField(isoField('When the stage last moved.')),\n ownerUid: nullableField(stringField('Owning user.')),\n contactId: nullableField(stringField('Associated contact — the Primary of `contactRoles`.')),\n contactRoles: {\n type: 'array',\n description:\n 'Every contact on the deal and the part each plays (Salesforce’s Opportunity Contact Roles). At most one is `primary`, and it is `contactId`.',\n items: {\n type: 'object',\n required: ['contactId', 'primary'],\n properties: {\n contactId: stringField('The contact.'),\n role: nullableField(stringField('One of the organization’s contact roles (Decision Maker, Evaluator, …), or `null` for none.')),\n primary: booleanField('Whether this is the deal’s Primary contact.'),\n },\n },\n },\n companyId: nullableField(stringField('Associated company.')),\n lostReason: nullableField(stringField('Why it was lost.')),\n notes: nullableField(stringField('Free-form notes.')),\n type: nullableField(stringField('Type — one of the organization’s deal types (New Business, Existing Business, …).')),\n leadSource: nullableField(stringField('Lead source — one of the organization’s lead sources.')),\n nextStep: nullableField(stringField('What happens next. At most 255 characters.')),\n probability: nullableField(integerField('This deal’s own chance of closing, 0–100; `null` uses its stage’s. A stage move clears it.')),\n forecastCategory: nullableField(stringField('`omitted`, `pipeline`, `bestCase`, `commit` or `closed`. Every stage move sets it from the new stage.')),\n campaignId: nullableField(stringField('The campaign the deal is attributed to.')),\n custom: openObjectField('Customer-defined fields.'),\n nextTaskAt: nullableField(isoField('When the next open task on this deal is due.')),\n siteId: nullableField(stringField('Site the record originated on.')),\n ...RECORD_STAMPS,\n },\n ops: [\n { path: '/v1/deals', method: 'get', operationId: 'listDeals', summary: 'List deals', description: 'Lists the workspace’s deals with their pipeline, stage, amount and status. Filter by pipeline, stage, status or owner.', list: true, returns: 'Deal', entitlement: 'crm', filters: [UPDATED_AFTER_PARAM, queryParam('pipelineId', 'Pipeline.'), queryParam('stageId', 'Stage.'), queryParam('status', 'Deal status.'), queryParam('ownerUid', 'Owning user.'), queryParam('type', 'Type, exactly as stored.'), queryParam('leadSource', 'Lead source, exactly as stored.'), queryParam('forecastCategory', 'Forecast category.'), queryParam('campaignId', 'Campaign.')] },\n { path: '/v1/deals', method: 'post', operationId: 'createDeal', summary: 'Add a deal', description: 'Opens a deal. Needs a `title`; `pipelineId` and `stageId` come from List deal pipelines. Returns the new deal.', accepts: 'DealWrite', returns: 'Deal', entitlement: 'crm', creates: true, bodyRequires: ['title'] },\n { path: '/v1/deals/{dealId}', method: 'get', operationId: 'getDeal', summary: 'Get a deal', description: 'Returns one deal. Needs `dealId` from List deals.', returns: 'Deal', entitlement: 'crm', pathParams: [{ name: 'dealId', description: 'Deal id.' }] },\n { path: '/v1/deals/{dealId}', method: 'patch', operationId: 'updateDeal', summary: 'Update a deal', description: 'Changes a deal, including moving it to another stage or marking it won or lost; fields not sent stay as they are. Needs `dealId` from List deals. Returns the updated deal.', accepts: 'DealWrite', returns: 'Deal', entitlement: 'crm', pathParams: [{ name: 'dealId', description: 'Deal id.' }] },\n { path: '/v1/deals/{dealId}', method: 'delete', operationId: 'deleteDeal', summary: 'Delete a deal', description: 'Deletes a deal permanently. Needs `dealId` from List deals.', returns: 'Deleted', entitlement: 'crm', pathParams: [{ name: 'dealId', description: 'Deal id.' }] },\n ],\n },\n tasks: {\n tag: 'Tasks',\n docsPage: 'tasks',\n description: 'Follow-ups attached to CRM records.',\n schemaName: 'Task',\n required: ['id', 'object', 'title'],\n writable: ['title', 'notes', 'kind', 'priority', 'status', 'dueAt', 'remindAt', 'assigneeUid', 'contactId', 'companyId', 'dealId', 'consentSiteId'],\n writeOnly: {\n consentSiteId: stringField('The site the task is created on behalf of.'),\n },\n writeNote: 'A create needs `title` and `consentSiteId`; a `PATCH` that names `consentSiteId` is a `400`.',\n fields: {\n id: stringField('Task id.'),\n object: objectKindField('task'),\n title: stringField('Task title.'),\n notes: nullableField(stringField('Free-form notes.')),\n kind: stringField('Task type as its meaning: `call`, `email`, `meeting` or `todo`. A write takes the meaning or a label of the Type picklist.'),\n typeLabel: stringField('The organization’s Type picklist label, e.g. `Call`. Read-only; set through `kind`.'),\n priority: stringField('`low`, `normal` or `high`. A write takes the meaning or a label of the Priority picklist.'),\n priorityLabel: stringField('The organization’s Priority picklist label, e.g. `High`. Read-only; set through `priority`.'),\n status: stringField('`open` or `done`. A write takes the meaning or a label of the Status picklist, e.g. `In Progress`.'),\n statusLabel: stringField('The organization’s Status picklist label, e.g. `Not Started`. Read-only; set through `status`.'),\n dueAt: nullableField(isoField('When the task is due.')),\n remindAt: nullableField(isoField('When a reminder is scheduled.')),\n reminderSentAt: nullableField(isoField('When the reminder was sent.')),\n completedAt: nullableField(isoField('When it was completed.')),\n assigneeUid: nullableField(stringField('Assigned user.')),\n contactId: nullableField(stringField('Associated contact.')),\n companyId: nullableField(stringField('Associated company.')),\n dealId: nullableField(stringField('Associated deal.')),\n siteId: nullableField(stringField('Site the record originated on.')),\n ...RECORD_STAMPS,\n },\n ops: [\n { path: '/v1/tasks', method: 'get', operationId: 'listTasks', summary: 'List tasks', description: 'Lists the workspace’s CRM tasks. Filter by status, assignee, contact or deal.', list: true, returns: 'Task', entitlement: 'crm', filters: [UPDATED_AFTER_PARAM, queryParam('status', 'Task status.'), queryParam('assigneeUid', 'Assigned user.'), queryParam('contactId', 'Associated contact.'), queryParam('dealId', 'Associated deal.')] },\n { path: '/v1/tasks', method: 'post', operationId: 'createTask', summary: 'Add a task', description: 'Creates a task, such as a follow-up, with a `title` and optionally a due date, a reminder and the contact, company or deal it is about. Returns the new task.', accepts: 'TaskWrite', returns: 'Task', entitlement: 'crm', creates: true, bodyRequires: ['title'] },\n { path: '/v1/tasks/{taskId}', method: 'get', operationId: 'getTask', summary: 'Get a task', description: 'Returns one task. Needs `taskId` from List tasks.', returns: 'Task', entitlement: 'crm', pathParams: [{ name: 'taskId', description: 'Task id.' }] },\n { path: '/v1/tasks/{taskId}', method: 'patch', operationId: 'updateTask', summary: 'Update a task', description: 'Changes a task, including marking it done; fields not sent stay as they are. Needs `taskId` from List tasks. Returns the updated task.', accepts: 'TaskWrite', returns: 'Task', entitlement: 'crm', pathParams: [{ name: 'taskId', description: 'Task id.' }] },\n { path: '/v1/tasks/{taskId}', method: 'delete', operationId: 'deleteTask', summary: 'Delete a task', description: 'Deletes a task permanently. Needs `taskId` from List tasks.', returns: 'Deleted', entitlement: 'crm', pathParams: [{ name: 'taskId', description: 'Task id.' }] },\n ],\n },\n activities: {\n tag: 'Activities',\n docsPage: 'activities',\n description: 'Logged interactions. Append-only: no PATCH.',\n schemaName: 'Activity',\n required: ['id', 'object', 'kind', 'at'],\n writable: ['kind', 'body', 'at', 'byUid', 'contactId', 'companyId', 'dealId', 'outcome', 'durationMinutes', 'direction', 'consentSiteId'],\n writeOnly: {\n consentSiteId: stringField('The site the activity is logged on behalf of.'),\n },\n writeRequired: ['body', 'consentSiteId'],\n fields: {\n id: stringField('Activity id.'),\n object: objectKindField('activity'),\n kind: stringField('What happened, e.g. `call`, `email`, `note`.'),\n body: stringField('Free-form body.'),\n at: isoField('When the interaction happened — not when it was logged.'),\n byUid: nullableField(stringField('User who logged it.')),\n contactId: nullableField(stringField('Associated contact.')),\n companyId: nullableField(stringField('Associated company. When none is sent, the company of the deal, else of the contact.')),\n dealId: nullableField(stringField('Associated deal.')),\n outcome: nullableField(stringField('Outcome label.')),\n durationMinutes: nullableField(integerField('Duration, for calls and meetings.')),\n direction: nullableField(stringField('Which way it went: `inbound`, `outbound` or `internal` for a call, `inbound` or `outbound` for an email.')),\n siteId: nullableField(stringField('Site the record originated on.')),\n ...RECORD_STAMPS,\n },\n ops: [\n { path: '/v1/activities', method: 'get', operationId: 'listActivities', summary: 'List activities', description: 'Lists the calls, emails, meetings and notes logged in the CRM. Filter by kind, contact or deal.', list: true, returns: 'Activity', entitlement: 'crm', filters: [UPDATED_AFTER_PARAM, queryParam('kind', 'Activity kind.'), queryParam('contactId', 'Associated contact.'), queryParam('dealId', 'Associated deal.')] },\n { path: '/v1/activities', method: 'post', operationId: 'createActivity', summary: 'Log an activity', description: 'Records a call, email, meeting or note against a contact, company or deal. Needs the activity’s text in `body`. Returns the logged activity. Logging an email records it; it does not send one.', accepts: 'ActivityWrite', returns: 'Activity', entitlement: 'crm', creates: true },\n { path: '/v1/activities/{activityId}', method: 'get', operationId: 'getActivity', summary: 'Get an activity', description: 'Returns one logged activity. Needs `activityId` from List activities.', returns: 'Activity', entitlement: 'crm', pathParams: [{ name: 'activityId', description: 'Activity id.' }] },\n { path: '/v1/activities/{activityId}', method: 'delete', operationId: 'deleteActivity', summary: 'Delete an activity', description: 'Deletes a logged activity permanently. Needs `activityId` from List activities.', returns: 'Deleted', entitlement: 'crm', pathParams: [{ name: 'activityId', description: 'Activity id.' }] },\n ],\n },\n leads: {\n tag: 'Leads',\n docsPage: 'leads',\n description: 'Unqualified interest, before it becomes a contact. A lead is a record of its own: the person and their company as text, until converting makes the contact and the company.',\n schemaName: 'Lead',\n required: ['id', 'object', 'siteId'],\n writable: [\n 'siteId', 'email', 'name', 'status', 'ownerUid', 'ownerEmail', 'notes', 'unqualifiedReason', 'company', 'jobTitle', 'phone', 'website', 'address', 'tags', 'leadSource',\n // Salesforce's standard lead fields (AGL-3513).\n 'salutation', 'firstName', 'lastName', 'mobilePhone', 'fax', 'doNotCall', 'industry', 'rating', 'annualRevenueCents', 'currency', 'numberOfEmployees',\n ],\n writeNote: '`email` and `name` are taken on a create only; a `PATCH` cannot change the address, which is the lead’s identity within its site. While `firstName` or `lastName` is set, `name` is their composition, \"First Last\", and follows them.',\n writeRequired: ['email'],\n writeOnly: {\n siteId: stringField('The site the lead belongs to, instead of the `siteId` query parameter.'),\n status: stringField('One of the organization’s active lead status values by its label (CRM › Fields › Leads), or a meaning — `new`, `nurturing`, `working` or `unqualified` (`nurturing` and `unqualified` on a `PATCH` only). Stored as the meaning and the label together. A lead becomes `qualified` by being converted.'),\n ownerEmail: stringField('A member’s address, resolved against the organization’s roster. Not with `ownerUid` in the same request.'),\n },\n fields: {\n id: stringField('Lead id.'),\n object: objectKindField('lead'),\n siteId: stringField('Site the lead arrived on.'),\n email: nullableField(stringField('Email — the lead’s identity within its site.')),\n name: nullableField(stringField('Name, when supplied.')),\n status: stringField('What the lead status means: `new`, `nurturing`, `working`, `qualified` or `unqualified`. What every filter and automation reads.'),\n statusLabel: stringField('The organization’s label for the lead status value the lead holds — one of `status`’s meaning. Read-only; set it through `status`.'),\n ownerUid: nullableField(stringField('Owning user.')),\n notes: nullableField(stringField('Free-form notes.')),\n unqualifiedReason: nullableField(stringField('Why the lead was disqualified.')),\n company: nullableField(stringField('The company’s name, as text. Converting the lead is what links or creates the company record.')),\n jobTitle: nullableField(stringField('Job title.')),\n phone: nullableField(stringField('E.164 phone number.')),\n website: nullableField(stringField('An http(s) URL.')),\n address: nullableField(postalAddressField()),\n tags: stringListField('Lower-cased tags.'),\n leadSource: nullableField(\n stringField(\n \"Where the lead came from: one of the organization's active lead source values \" +\n '(CRM › Fields › Leads), matched without regard to case. Any other value is refused ' +\n 'with a 400 naming the values allowed; the value a lead already holds is kept even ' +\n \"after it is deactivated. A create that names none starts from the list's default.\",\n ),\n ),\n // Salesforce's standard lead fields (AGL-3513).\n salutation: nullableField(stringField('Salutation: one of the organization’s active Salutation values (CRM › Fields › Contacts), matched without regard to case. Any other value is a `400` naming the values allowed; the value a lead already holds is kept.')),\n firstName: nullableField(stringField('First name, at most 59 characters. While it or `lastName` is set, `name` is \"First Last\".')),\n lastName: nullableField(stringField('Last name, at most 59 characters.')),\n mobilePhone: nullableField(stringField('E.164 mobile phone number.')),\n fax: nullableField(stringField('E.164 fax number.')),\n doNotCall: booleanField('The person asked not to be phoned. A hint on every call control, never a block. `false` clears it.'),\n industry: nullableField(stringField('Industry: one of the organization’s active Industry values (CRM › Fields › Companies) — the list companies keep, so converting carries it. Any other value is a `400` naming the values allowed; the value a lead already holds is kept.')),\n rating: nullableField(stringField('Rating: one of the organization’s active Rating values (CRM › Fields › Companies). Any other value is a `400` naming the values allowed.')),\n annualRevenueCents: nullableField(integerField('Annual revenue in the minor unit of `currency`, 0 or more.')),\n currency: stringField('Lowercase ISO 4217 code of the annual revenue. `usd` when unset.'),\n numberOfEmployees: nullableField(integerField('Number of employees, 0 to 99,999,999.')),\n sources: stringListField('The surfaces that captured the lead: `signup`, `booking`, `form:{formId}`, `import`, `manual`, `api`.'),\n submissionCount: integerField('How many form submissions this lead has made.'),\n firstSeen: isoField('First interaction.'),\n lastSeen: isoField('Most recent interaction.'),\n marketingConsent: booleanField('Whether marketing consent was given.'),\n marketingConsentAt: nullableField(isoField('When consent was given.')),\n convertedContactId: nullableField(stringField('Contact created by conversion.')),\n convertedAt: nullableField(isoField('When it was converted.')),\n companyId: nullableField(stringField('Company created or matched by conversion.')),\n dealId: nullableField(stringField('Deal created by conversion.')),\n ...RECORD_STAMPS,\n },\n ops: [\n { path: '/v1/leads', method: 'get', operationId: 'listLeads', summary: 'List a site’s leads', description: 'Lists the leads one site has captured, not yet converted into contacts. Needs `siteId` from List sites. Filter by status or owner.', list: true, returns: 'Lead', entitlement: 'crm', filters: [UPDATED_AFTER_PARAM, LEAD_SITE_PARAM, queryParam('status', 'Lead status.'), queryParam('ownerUid', 'Owning user.')] },\n // openWorld: after saving, the address’s mail domain is looked up (DNS) to flag addresses that would bounce.\n // destructive: adding an address the site already holds updates that lead, so it can overwrite what was there.\n { path: '/v1/leads', method: 'post', operationId: 'createLead', summary: 'Add a lead to a site', accepts: 'LeadWrite', returns: 'Lead', entitlement: 'crm', creates: true, description: 'Adds a lead to one site. Needs `siteId` from List sites and the lead’s `email`. One email is one lead per site: adding an address the site already holds updates that lead. No contact is created until the lead is converted. Returns the lead.', idempotent: true, openWorld: true, destructive: true, bodyRequires: ['siteId', 'email'] },\n { path: '/v1/leads/{leadId}', method: 'get', operationId: 'getLead', summary: 'Get a lead', description: 'Returns one lead. Needs `siteId` from List sites and `leadId` from List a site’s leads.', returns: 'Lead', entitlement: 'crm', pathParams: [{ name: 'leadId', description: 'Lead id.' }], filters: [LEAD_SITE_PARAM] },\n { path: '/v1/leads/{leadId}', method: 'patch', operationId: 'updateLead', summary: 'Update a lead', description: 'Changes a lead, including its status; fields not sent stay as they are. Needs `siteId` from List sites and `leadId` from List a site’s leads. Returns the updated lead.', accepts: 'LeadWrite', returns: 'Lead', entitlement: 'crm', pathParams: [{ name: 'leadId', description: 'Lead id.' }], filters: [LEAD_SITE_PARAM] },\n // openWorld: the contact it creates has its mail domain looked up (DNS) to flag addresses that would bounce.\n { path: '/v1/leads/{leadId}/convert', method: 'post', operationId: 'convertLead', summary: 'Convert a lead into a contact', accepts: 'LeadConvertRequest', bodyOptional: true, returns: 'LeadConversion', entitlement: 'crm', description: 'Turns a lead into a contact, joining an existing contact with the same email, and can also link or create a company and open a deal. Needs `siteId` from List sites and `leadId` from List a site’s leads. Converting a lead again returns the same ids.', pathParams: [{ name: 'leadId', description: 'Lead id.' }], idempotent: true, openWorld: true, filters: [LEAD_SITE_PARAM] },\n ],\n components: {\n LeadConvertRequest: {\n type: 'object',\n description:\n 'Optional. What else the conversion does besides creating the contact. ' +\n 'Leave it out to convert the lead into a contact alone.',\n properties: {\n company: {\n type: ['object', 'null'],\n description:\n 'A company for the contact: `{ \"link\": \"<companyId>\" }` to link one from List companies, ' +\n '`{ \"create\": { \"name\": \"…\", \"domain\": \"…\" } }` to add one (an existing company with that ' +\n 'name or domain is reused), or null for none.',\n },\n deal: {\n type: ['object', 'null'],\n description:\n 'A deal to open in the default pipeline: `{ \"title\": \"…\", \"amountCents\": 12500, \"currency\": ' +\n '\"usd\", \"stageId\": \"…\", \"type\": \"…\" }`. `title` is required; the rest is optional. Null for none.',\n },\n ownerUid: { type: 'string', description: 'Workspace member who owns the contact and the deal. Defaults to the lead’s owner.' },\n ownerEmail: { type: 'string', description: 'The owner by email address, instead of `ownerUid`.' },\n },\n additionalProperties: false,\n },\n LeadConversion: {\n type: 'object',\n description:\n 'What the conversion produced: the contact, and the company and deal ' +\n 'when it made or linked them. Converting the same lead again returns ' +\n 'the same ids.',\n properties: {\n object: { type: 'string', const: 'lead_conversion' },\n contactId: { type: 'string' },\n companyId: { type: ['string', 'null'] },\n dealId: { type: ['string', 'null'] },\n },\n additionalProperties: true,\n },\n },\n },\n 'email-templates': {\n tag: 'Email templates',\n docsPage: 'email-templates',\n description: 'Reusable email bodies.',\n schemaName: 'EmailTemplate',\n required: ['id', 'object', 'name'],\n writable: ['name', 'kind', 'visibility', 'ownerUid', 'subject', 'body', 'consentSiteId'],\n writeOnly: {\n consentSiteId: stringField('The site the template is created on behalf of.'),\n },\n writeNote: 'A create needs `name`, `body` and `consentSiteId`; a `PATCH` that names `consentSiteId` is a `400`.',\n fields: {\n id: stringField('Template id.'),\n object: objectKindField('email_template'),\n name: stringField('Template name.'),\n kind: stringField('Template kind.'),\n visibility: stringField('`org` or `private`.'),\n ownerUid: nullableField(stringField('Owner, for a private template.')),\n subject: stringField('Subject line.'),\n body: stringField('Body. May contain merge tokens.'),\n siteId: nullableField(stringField('Site the template belongs to, when scoped.')),\n ...RECORD_STAMPS,\n },\n ops: [\n { path: '/v1/email-templates', method: 'get', operationId: 'listEmailTemplates', summary: 'List email templates', description: 'Lists the workspace’s saved email templates with their name, subject and kind.', list: true, returns: 'EmailTemplate', entitlement: 'crm', filters: [UPDATED_AFTER_PARAM, queryParam('kind', 'Template kind.'), queryParam('visibility', 'Visibility.')] },\n { path: '/v1/email-templates', method: 'post', operationId: 'createEmailTemplate', summary: 'Add an email template', description: 'Saves a reusable email with a `name`, a subject and the message in `body`. Saving a template sends nothing. Returns the new template.', accepts: 'EmailTemplateWrite', returns: 'EmailTemplate', entitlement: 'crm', creates: true, bodyRequires: ['name', 'body'] },\n { path: '/v1/email-templates/{templateId}', method: 'get', operationId: 'getEmailTemplate', summary: 'Get an email template', description: 'Returns one email template. Needs `templateId` from List email templates.', returns: 'EmailTemplate', entitlement: 'crm', pathParams: [{ name: 'templateId', description: 'Template id.' }] },\n { path: '/v1/email-templates/{templateId}', method: 'patch', operationId: 'updateEmailTemplate', summary: 'Update an email template', description: 'Changes a template; fields not sent stay as they are. Needs `templateId` from List email templates. Returns the updated template.', accepts: 'EmailTemplateWrite', returns: 'EmailTemplate', entitlement: 'crm', pathParams: [{ name: 'templateId', description: 'Template id.' }] },\n { path: '/v1/email-templates/{templateId}', method: 'delete', operationId: 'deleteEmailTemplate', summary: 'Delete an email template', description: 'Deletes a template permanently. Needs `templateId` from List email templates.', returns: 'Deleted', entitlement: 'crm', pathParams: [{ name: 'templateId', description: 'Template id.' }] },\n ],\n },\n}\n"],"names":["booleanField","integerField","isoField","nullableField","objectKindField","openObjectField","postalAddressField","queryParam","requiredQueryParam","RECORD_STAMPS","stringField","stringListField","UPDATED_AFTER_PARAM","companyPicklistNote","label","plural","LEAD_SITE_PARAM","CRM_API_V1_DESCRIPTIONS","contacts","tag","docsPage","description","schemaName","required","writable","writeOnly","consentSiteId","consentGroupId","custom","mediaIds","writeNote","fields","id","object","email","name","tags","notes","marketingConsent","consentSites","sources","phone","jobTitle","companyId","address","ownerUid","lifecycleStage","leadSource","salutation","firstName","lastName","department","mobilePhone","homePhone","otherPhone","fax","birthdate","assistantName","assistantPhone","reportsToContactId","otherAddress","doNotCall","companyIds","alternateEmails","ops","path","method","operationId","summary","list","returns","entitlement","filters","accepts","creates","openWorld","pathParams","destructive","idempotent","components","ContactMerge","type","properties","sourceContactId","additionalProperties","companies","domain","website","industry","rating","ownership","accountSource","annualRevenueCents","currency","numberOfEmployees","accountNumber","site","tickerSymbol","sicCode","shippingAddress","parentCompanyId","nextTaskAt","siteId","bodyRequires","pipelines","isDefault","archived","archivedAt","stages","items","order","probability","kind","enum","forecastCategory","deals","title","pipelineId","stageId","status","amountCents","lineItems","expectedCloseAt","closedAt","stageChangedAt","contactId","contactRoles","role","primary","lostReason","nextStep","campaignId","tasks","typeLabel","priority","priorityLabel","statusLabel","dueAt","remindAt","reminderSentAt","completedAt","assigneeUid","dealId","activities","writeRequired","body","at","byUid","outcome","durationMinutes","direction","leads","ownerEmail","unqualifiedReason","company","submissionCount","firstSeen","lastSeen","marketingConsentAt","convertedContactId","convertedAt","bodyOptional","LeadConvertRequest","deal","LeadConversion","const","visibility","subject"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAEEA,YAAY,EACZC,YAAY,EACZC,QAAQ,EACRC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,kBAAkB,EAClBC,UAAU,EACVC,kBAAkB,EAClBC,aAAa,EACbC,WAAW,EACXC,eAAe,EACfC,mBAAmB,QACd,qDAAoD;AAE3D;;;;;;;;;;CAUC,GACD,sEAAsE,GACtE,SAASC,oBAAoBC,KAAa,EAAEC,MAAc;IACxD,OACE,GAAGD,MAAM,mCAAmC,EAAEC,OAAO,qCAAqC,CAAC,GAC3F,8FACA;AAEJ;AAGA;;;;;CAKC,GACD,MAAMC,kBAAkBR,mBACtB,UACA;AAGF,OAAO,MAAMS,0BAA8E;IACzFC,UAAU;QACRC,KAAK;QACLC,UAAU;QACVC,aAAa;QACbC,YAAY;QACZC,UAAU;YAAC;YAAM;YAAU;SAAQ;QACnCC,UAAU;YACR;YAAS;YAAQ;YAAQ;YAAS;YAAoB;YAAiB;YAAkB;YACzF;YAAS;YAAY;YAAa;YAAW;YAAY;YAAkB;YAC3E;YACA,mDAAmD;YACnD;YAAc;YAAa;YAAY;YAAc;YAAe;YAAa;YACjF;YAAO;YAAa;YAAiB;YAAkB;YAAsB;YAAgB;SAC9F;QACDC,WAAW;YACTC,eAAehB,YAAY;YAC3BiB,gBAAgBjB,YAAY;YAC5BkB,QAAQvB,gBAAgB;YACxBwB,UAAUlB,gBAAgB;QAC5B;QACAmB,WAAW;QACXC,QAAQ;YACNC,IAAItB,YAAY;YAChBuB,QAAQ7B,gBAAgB;YACxB8B,OAAO/B,cACLO,YAAY;YAEdyB,MAAMzB,YAAY;YAClB0B,MAAMzB,gBAAgB;YACtB0B,OAAO3B,YAAY;YACnB4B,kBAAk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AAE;YAAC;YACxU;gBAAE4C,MAAM;gBAAoCC,QAAQ;gBAASC,aAAa;gBAAuBC,SAAS;gBAA4B/C,aAAa;gBAAqIoD,SAAS;gBAAsBH,SAAS;gBAAiBC,aAAa;gBAAOK,YAAY;oBAAC;wBAAEzC,MAAM;wBAAcd,aAAa;oBAAe;iBAAE;YAAC;YACva;gBAAE4C,MAAM;gBAAoCC,QAAQ;gBAAUC,aAAa;gBAAuBC,SAAS;gBAA4B/C,aAAa;gBAAiFiD,SAAS;gBAAWC,aAAa;gBAAOK,YAAY;oBAAC;wBAAEzC,MAAM;wBAAcd,aAAa;oBAAe;iBAAE;YAAC;SAChV;IACH;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/plugins/crm/src/lib/server/api-v1/openapi.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n type ApiV1ResourceDescription,\n booleanField,\n integerField,\n isoField,\n nullableField,\n objectKindField,\n openObjectField,\n postalAddressField,\n queryParam,\n requiredQueryParam,\n RECORD_STAMPS,\n stringField,\n stringListField,\n UPDATED_AFTER_PARAM,\n} from '@aglyn/tenant-data-admin/server/api-v1-description'\n\n/**\n * The CRM's resources as the customer API's OpenAPI document describes them\n * (AGL-2733), keyed by the resource each describes — what the console's\n * builder turns into their paths, tags and schemas, and the MCP tools derive\n * from.\n *\n * Transcribed from the response examples in `apps/docs/api/resources/*.md`,\n * the customer-facing contract, as the platform's own resources are; each\n * write body lists its handler's own writable set. `api-v1-openapi.spec.ts`\n * holds the document to every endpoint the documentation promises.\n */\n/** How a company picklist field reads in the description (AGL-3514). */\nfunction companyPicklistNote(label: string, plural: string): string {\n return (\n `${label}: one of the organization's active ${plural} (CRM › Fields › Companies), matched ` +\n 'without regard to case. Any other value is refused with a 400 naming the values allowed; ' +\n 'the value a company already holds is kept even after it is deactivated.'\n )\n}\n\n\n/**\n * The site a lead belongs to (AGL-4225). A lead is a site's record and its id\n * is unique only within the site, so the handler refuses every lead request\n * without one — and until this was declared, a client reading the document\n * could not know to send it.\n */\nconst LEAD_SITE_PARAM = requiredQueryParam(\n 'siteId',\n 'Required. The site the lead belongs to — the `id` of a site from `listSites`.',\n)\n\nexport const CRM_API_V1_DESCRIPTIONS: Readonly<Record<string, ApiV1ResourceDescription>> = {\n contacts: {\n tag: 'Contacts',\n docsPage: 'contacts',\n description: 'People, organization-wide. Part of the CRM, which is included from Starter.',\n schemaName: 'Contact',\n required: ['id', 'object', 'email'],\n writable: [\n 'email', 'name', 'tags', 'notes', 'marketingConsent', 'consentSiteId', 'consentGroupId', 'custom',\n 'phone', 'jobTitle', 'companyId', 'address', 'ownerUid', 'lifecycleStage', 'mediaIds',\n 'leadSource',\n // Salesforce's standard contact fields (AGL-3515).\n 'salutation', 'firstName', 'lastName', 'department', 'mobilePhone', 'homePhone', 'otherPhone',\n 'fax', 'birthdate', 'assistantName', 'assistantPhone', 'reportsToContactId', 'otherAddress', 'doNotCall',\n ],\n writeOnly: {\n consentSiteId: stringField('The site this write is made on behalf of: where the person opted in, and whose profile the profile fields land on.'),\n consentGroupId: stringField('With `marketingConsent: true`: the consent group the person was shown when they opted in. The opt-in then covers every site of that group; without it, or when the site is no longer in that group, it covers `consentSiteId` alone.'),\n custom: openObjectField('Contact custom fields, keyed by field key.'),\n mediaIds: stringListField('Media library files attached by the named site, by id, at most 20. An empty array clears them.'),\n },\n writeNote: 'A create needs an `email`, a `name`, a `phone`, a `mobilePhone`, or a `firstName` or `lastName`. `email` is accepted on create only — a `PATCH` that names it is a `400`, because a contact is identified by its email.',\n fields: {\n id: stringField('Contact id.'),\n object: objectKindField('contact'),\n email: nullableField(\n stringField('Primary email, unique per organization, or `null` for a contact with no address yet.'),\n ),\n name: stringField('Display name.'),\n tags: stringListField('Free-form tags.'),\n notes: stringField('Free-form notes.'),\n marketingConsent: booleanField('Whether the contact accepted marketing email.'),\n consentSites: stringListField('Site ids the consent was given on.'),\n sources: stringListField('Where this contact came from.'),\n phone: stringField('Telephone number.'),\n jobTitle: stringField('Job title.'),\n companyId: nullableField(stringField('Primary company.')),\n address: postalAddressField(),\n ownerUid: nullableField(stringField('Owning user. Checked on the page, not the query.')),\n lifecycleStage: nullableField(stringField('CRM lifecycle stage.')),\n leadSource: nullableField(stringField('Lead source: one of the organization’s Lead source values (CRM › Fields › Leads), stored on the named site’s profile. A value the list does not hold is a `400` naming the values it allows.')),\n // Salesforce's standard contact fields (AGL-3515).\n salutation: nullableField(stringField(\"One of the organization's salutation values (Mr., Ms., Mrs., Dr., Prof. and its own).\")),\n firstName: nullableField(stringField('First name. With `lastName`, it makes the name the named site shows.')),\n lastName: nullableField(stringField('Last name.')),\n department: nullableField(stringField('Department.')),\n mobilePhone: nullableField(stringField('Mobile phone, E.164.')),\n homePhone: nullableField(stringField('Home phone, E.164.')),\n otherPhone: nullableField(stringField('Other phone, E.164.')),\n fax: nullableField(stringField('Fax, E.164.')),\n birthdate: nullableField(stringField('Birthdate, `YYYY-MM-DD`, never in the future.')),\n assistantName: nullableField(stringField(\"Assistant's name.\")),\n assistantPhone: nullableField(stringField(\"Assistant's phone, E.164.\")),\n reportsToContactId: nullableField(stringField('The contact this person reports to. Never the contact itself, and never one that already reports to it.')),\n otherAddress: nullableField(postalAddressField()),\n doNotCall: booleanField('The person asked not to be phoned.'),\n companyIds: stringListField('Every company this contact belongs to.'),\n alternateEmails: stringListField('Other addresses that resolve to this contact.'),\n ...RECORD_STAMPS,\n },\n ops: [\n {\n path: '/v1/contacts', method: 'get', operationId: 'listContacts', summary: 'List contacts', list: true, returns: 'Contact', entitlement: 'crm',\n description: 'Lists the workspace’s contacts: one record per person, with email, name, phone, tags and per-site profile. Filter by exact `email` to find one person.',\n filters: [\n queryParam('email', 'The contact with this email address. Letter case is ignored; an address that cannot be read is refused.'),\n queryParam('tag', 'Contacts with this tag.'),\n queryParam('lifecycleStage', 'Contacts at this lifecycle stage.'),\n queryParam('ownerUid', 'Contacts owned by this workspace member.'),\n ],\n },\n // openWorld: after saving, the address’s mail domain is looked up (DNS) to flag addresses that would bounce.\n { path: '/v1/contacts', method: 'post', operationId: 'createContact', summary: 'Add a contact', accepts: 'ContactWrite', returns: 'Contact', entitlement: 'crm', creates: true, description: 'Adds a person to the workspace’s contacts. An email address is a contact’s identity: one that already belongs to a contact is refused, naming the existing contact’s id. Returns the new contact.', openWorld: true },\n { path: '/v1/contacts/{contactId}', method: 'get', operationId: 'getContact', summary: 'Get a contact', description: 'Returns one contact. Needs `contactId` from List contacts.', returns: 'Contact', entitlement: 'crm', pathParams: [{ name: 'contactId', description: 'Contact id.' }] },\n { path: '/v1/contacts/{contactId}', method: 'patch', operationId: 'updateContact', summary: 'Update a contact', description: 'Changes a contact’s details; fields not sent stay as they are. The email address cannot be changed. Needs `contactId` from List contacts. Returns the updated contact.', accepts: 'ContactWrite', returns: 'Contact', entitlement: 'crm', pathParams: [{ name: 'contactId', description: 'Contact id.' }] },\n { path: '/v1/contacts/{contactId}', method: 'delete', operationId: 'deleteContact', summary: 'Delete a contact', description: 'Removes a person from the workspace’s contacts, with the tags, notes, timeline and consent the workspace’s sites hold for them. Permanent. Needs `contactId` from List contacts.', returns: 'Deleted', entitlement: 'crm', pathParams: [{ name: 'contactId', description: 'Contact id.' }] },\n { path: '/v1/contacts/{contactId}/merge', method: 'post', operationId: 'mergeContact', summary: 'Merge two contacts', description: 'Folds one contact into another: the contact in `contactId` survives and keeps its email, and the contact named in `sourceContactId` is merged into it and deleted. Permanent. Returns the surviving contact.', accepts: 'ContactMerge', returns: 'Contact', entitlement: 'crm', destructive: true, pathParams: [{ name: 'contactId', description: 'The contact that survives.' }], idempotent: true },\n ],\n components: {\n ContactMerge: {\n type: 'object',\n required: ['sourceContactId'],\n description:\n 'Merge another contact into this one. The source is removed. Any other ' +\n 'member is a `400`.',\n properties: {\n sourceContactId: {\n type: 'string',\n description:\n 'The contact to merge FROM. It does not survive, and it must not be ' +\n 'the contact in the path.',\n },\n },\n additionalProperties: false,\n },\n },\n },\n companies: {\n tag: 'Companies',\n docsPage: 'companies',\n description: 'Organizations in the CRM.',\n schemaName: 'Company',\n required: ['id', 'object', 'name'],\n writable: [\n 'name', 'domain', 'website', 'phone', 'address', 'industry', 'ownerUid', 'notes', 'custom', 'mediaIds', 'consentSiteId',\n // Salesforce's Account fields (AGL-3514).\n 'type', 'rating', 'ownership', 'accountSource', 'annualRevenueCents', 'currency', 'numberOfEmployees', 'fax',\n 'accountNumber', 'site', 'tickerSymbol', 'sicCode', 'shippingAddress', 'parentCompanyId',\n ],\n writeOnly: {\n mediaIds: stringListField('Media library files attached to this company, by id, at most 20. An empty array clears them.'),\n consentSiteId: stringField('The site the company is created on behalf of.'),\n },\n writeNote: 'A create needs `name` and `consentSiteId`; a `PATCH` that names `consentSiteId` is a `400`.',\n fields: {\n id: stringField('Company id.'),\n object: objectKindField('company'),\n name: stringField('Company name.'),\n domain: nullableField(stringField('Primary domain. Unique per organization.')),\n website: nullableField(stringField('Website URL.')),\n phone: nullableField(stringField('Telephone number.')),\n address: { ...postalAddressField(), description: 'Billing address. Members are optional and free-form.' },\n industry: nullableField(stringField(companyPicklistNote('Industry', 'industries'))),\n // Salesforce's Account fields (AGL-3514).\n type: nullableField(stringField(companyPicklistNote('Account type', 'types'))),\n rating: nullableField(stringField(companyPicklistNote('Rating', 'ratings'))),\n ownership: nullableField(stringField(companyPicklistNote('Ownership', 'ownership values'))),\n accountSource: nullableField(\n stringField(\n \"Where the account came from: one of the organization's active lead source values \" +\n '(CRM › Fields › Leads), matched without regard to case. Any other value is refused ' +\n 'with a 400 naming the values allowed; the value a company already holds is kept.',\n ),\n ),\n annualRevenueCents: nullableField(integerField('Annual revenue in the minor unit of `currency`, 0 or more.')),\n currency: stringField('Lowercase ISO 4217 code of the annual revenue. `usd` when unset.'),\n numberOfEmployees: nullableField(integerField('Number of employees, 0 to 99,999,999.')),\n fax: nullableField(stringField('E.164 fax number.')),\n accountNumber: nullableField(stringField('Account number, at most 40 characters.')),\n site: nullableField(stringField('Which of the company’s locations this record is, at most 80 characters.')),\n tickerSymbol: nullableField(stringField('Stock ticker symbol, at most 20 characters.')),\n sicCode: nullableField(stringField('Standard Industrial Classification code, at most 20 characters.')),\n shippingAddress: { ...postalAddressField(), description: 'Shipping address. Members are optional and free-form.' },\n parentCompanyId: nullableField(\n stringField('The company this one sits under. Never itself or a company below it; deleting the parent clears it.'),\n ),\n ownerUid: nullableField(stringField('Owning user.')),\n notes: nullableField(stringField('Free-form notes.')),\n custom: openObjectField('Customer-defined fields.'),\n nextTaskAt: nullableField(isoField('When the next open task on this company is due.')),\n siteId: nullableField(stringField('Site the record originated on.')),\n ...RECORD_STAMPS,\n },\n ops: [\n { path: '/v1/companies', method: 'get', operationId: 'listCompanies', summary: 'List companies', description: 'Lists the companies in the workspace’s CRM. Filter by exact `domain` to find one.', list: true, returns: 'Company', entitlement: 'crm', filters: [UPDATED_AFTER_PARAM, queryParam('domain', 'Exact match.'), queryParam('ownerUid', 'Owning user.')] },\n { path: '/v1/companies', method: 'post', operationId: 'createCompany', summary: 'Add a company', accepts: 'CompanyWrite', returns: 'Company', entitlement: 'crm', creates: true, description: 'Adds a company to the CRM. Needs a `name`. A company whose domain is already in the CRM is refused, naming the existing id. Returns the new company.', bodyRequires: ['name'] },\n { path: '/v1/companies/{companyId}', method: 'get', operationId: 'getCompany', summary: 'Get a company', description: 'Returns one company. Needs `companyId` from List companies.', returns: 'Company', entitlement: 'crm', pathParams: [{ name: 'companyId', description: 'Company id.' }] },\n { path: '/v1/companies/{companyId}', method: 'patch', operationId: 'updateCompany', summary: 'Update a company', description: 'Changes a company’s details; fields not sent stay as they are. Needs `companyId` from List companies. Returns the updated company.', accepts: 'CompanyWrite', returns: 'Company', entitlement: 'crm', pathParams: [{ name: 'companyId', description: 'Company id.' }] },\n { path: '/v1/companies/{companyId}', method: 'delete', operationId: 'deleteCompany', summary: 'Delete a company', description: 'Deletes a company permanently. Needs `companyId` from List companies.', returns: 'Deleted', entitlement: 'crm', pathParams: [{ name: 'companyId', description: 'Company id.' }] },\n ],\n },\n pipelines: {\n tag: 'Pipelines',\n docsPage: 'pipelines',\n description: 'Deal pipelines and their stages. Read-only over the API.',\n schemaName: 'Pipeline',\n required: ['id', 'object', 'name', 'stages'],\n fields: {\n id: stringField('Pipeline id.'),\n object: objectKindField('pipeline'),\n name: stringField('Pipeline name.'),\n isDefault: booleanField('Whether new deals land here when none is named.'),\n archived: booleanField('Whether the pipeline is archived.'),\n archivedAt: nullableField(isoField('When it was archived.')),\n stages: {\n type: 'array',\n description: 'Ordered stages. A deal’s `stageId` names one of these.',\n items: {\n type: 'object',\n properties: {\n id: { type: 'string' },\n name: { type: 'string' },\n order: { type: 'integer' },\n probability: { type: 'integer', description: 'Chance of closing from this stage, 0–100.' },\n kind: { type: 'string', enum: ['open', 'won', 'lost'] },\n forecastCategory: {\n type: 'string',\n enum: ['omitted', 'pipeline', 'bestCase', 'commit', 'closed'],\n description: 'The forecast category a deal takes on landing in this stage.',\n },\n },\n additionalProperties: true,\n },\n },\n siteId: nullableField(stringField('Site the pipeline belongs to, when scoped.')),\n ...RECORD_STAMPS,\n },\n ops: [\n { path: '/v1/pipelines', method: 'get', operationId: 'listPipelines', summary: 'List deal pipelines', description: 'Lists the workspace’s sales pipelines and their stages. A stage’s id is the `stageId` a deal takes.', list: true, returns: 'Pipeline', entitlement: 'crm', filters: [UPDATED_AFTER_PARAM] },\n { path: '/v1/pipelines/{pipelineId}', method: 'get', operationId: 'getPipeline', summary: 'Get a deal pipeline', description: 'Returns one pipeline and its stages. Needs `pipelineId` from List deal pipelines.', returns: 'Pipeline', entitlement: 'crm', pathParams: [{ name: 'pipelineId', description: 'Pipeline id.' }] },\n ],\n },\n deals: {\n tag: 'Deals',\n docsPage: 'deals',\n description: 'Opportunities moving through a pipeline.',\n schemaName: 'Deal',\n required: ['id', 'object', 'title', 'pipelineId', 'stageId'],\n writable: ['title', 'pipelineId', 'stageId', 'status', 'amountCents', 'currency', 'lineItems', 'expectedCloseAt', 'ownerUid', 'contactId', 'companyId', 'lostReason', 'notes', 'custom', 'mediaIds', 'consentSiteId', 'type', 'leadSource', 'nextStep', 'probability', 'forecastCategory', 'campaignId', 'contactRoles'],\n writeOnly: {\n mediaIds: stringListField('Media library files attached to this deal, by id, at most 20. An empty array clears them.'),\n consentSiteId: stringField('The site the deal is created on behalf of.'),\n },\n writeNote:\n '`pipelineId` and `consentSiteId` are accepted on create only; a `PATCH` that names either is a `400`. ' +\n '`type` and `leadSource` must be active values of the organization’s lists (a deal keeps the value it holds). ' +\n 'A stage move sets `forecastCategory` from the new stage and clears `probability`, unless the same body sets them. ' +\n '`contactRoles` replaces the whole list: each contact once, at most 50, at most one `primary`, each `role` an active value of the organization’s contact roles. ' +\n 'The Primary is `contactId`: a body sending both must agree, and `contactId` alone makes that contact Primary.',\n fields: {\n id: stringField('Deal id.'),\n object: objectKindField('deal'),\n title: stringField('Deal title.'),\n pipelineId: stringField('Pipeline the deal sits in.'),\n stageId: stringField('Stage within that pipeline.'),\n status: stringField('`open`, `won` or `lost`.'),\n amountCents: integerField('Value in the smallest unit of `currency`.'),\n currency: stringField('ISO 4217 code.'),\n lineItems: { type: 'array', description: 'Line items, when the deal carries them.', items: { type: 'object', additionalProperties: true } },\n expectedCloseAt: nullableField(isoField('Forecast close date.')),\n closedAt: nullableField(isoField('When it was actually closed.')),\n stageChangedAt: nullableField(isoField('When the stage last moved.')),\n ownerUid: nullableField(stringField('Owning user.')),\n contactId: nullableField(stringField('Associated contact — the Primary of `contactRoles`.')),\n contactRoles: {\n type: 'array',\n description:\n 'Every contact on the deal and the part each plays (Salesforce’s Opportunity Contact Roles). At most one is `primary`, and it is `contactId`.',\n items: {\n type: 'object',\n required: ['contactId', 'primary'],\n properties: {\n contactId: stringField('The contact.'),\n role: nullableField(stringField('One of the organization’s contact roles (Decision Maker, Evaluator, …), or `null` for none.')),\n primary: booleanField('Whether this is the deal’s Primary contact.'),\n },\n },\n },\n companyId: nullableField(stringField('Associated company.')),\n lostReason: nullableField(stringField('Why it was lost.')),\n notes: nullableField(stringField('Free-form notes.')),\n type: nullableField(stringField('Type — one of the organization’s deal types (New Business, Existing Business, …).')),\n leadSource: nullableField(stringField('Lead source — one of the organization’s lead sources.')),\n nextStep: nullableField(stringField('What happens next. At most 255 characters.')),\n probability: nullableField(integerField('This deal’s own chance of closing, 0–100; `null` uses its stage’s. A stage move clears it.')),\n forecastCategory: nullableField(stringField('`omitted`, `pipeline`, `bestCase`, `commit` or `closed`. Every stage move sets it from the new stage.')),\n campaignId: nullableField(stringField('The campaign the deal is attributed to.')),\n custom: openObjectField('Customer-defined fields.'),\n nextTaskAt: nullableField(isoField('When the next open task on this deal is due.')),\n siteId: nullableField(stringField('Site the record originated on.')),\n ...RECORD_STAMPS,\n },\n ops: [\n { path: '/v1/deals', method: 'get', operationId: 'listDeals', summary: 'List deals', description: 'Lists the workspace’s deals with their pipeline, stage, amount and status. Filter by pipeline, stage, status or owner.', list: true, returns: 'Deal', entitlement: 'crm', filters: [UPDATED_AFTER_PARAM, queryParam('pipelineId', 'Pipeline.'), queryParam('stageId', 'Stage.'), queryParam('status', 'Deal status.'), queryParam('ownerUid', 'Owning user.'), queryParam('type', 'Type, exactly as stored.'), queryParam('leadSource', 'Lead source, exactly as stored.'), queryParam('forecastCategory', 'Forecast category.'), queryParam('campaignId', 'Campaign.')] },\n { path: '/v1/deals', method: 'post', operationId: 'createDeal', summary: 'Add a deal', description: 'Opens a deal. Needs a `title`; `pipelineId` and `stageId` come from List deal pipelines. Returns the new deal.', accepts: 'DealWrite', returns: 'Deal', entitlement: 'crm', creates: true, bodyRequires: ['title'] },\n { path: '/v1/deals/{dealId}', method: 'get', operationId: 'getDeal', summary: 'Get a deal', description: 'Returns one deal. Needs `dealId` from List deals.', returns: 'Deal', entitlement: 'crm', pathParams: [{ name: 'dealId', description: 'Deal id.' }] },\n { path: '/v1/deals/{dealId}', method: 'patch', operationId: 'updateDeal', summary: 'Update a deal', description: 'Changes a deal, including moving it to another stage or marking it won or lost; fields not sent stay as they are. Needs `dealId` from List deals. Returns the updated deal.', accepts: 'DealWrite', returns: 'Deal', entitlement: 'crm', pathParams: [{ name: 'dealId', description: 'Deal id.' }] },\n { path: '/v1/deals/{dealId}', method: 'delete', operationId: 'deleteDeal', summary: 'Delete a deal', description: 'Deletes a deal permanently. Needs `dealId` from List deals.', returns: 'Deleted', entitlement: 'crm', pathParams: [{ name: 'dealId', description: 'Deal id.' }] },\n ],\n },\n tasks: {\n tag: 'Tasks',\n docsPage: 'tasks',\n description: 'Follow-ups attached to CRM records.',\n schemaName: 'Task',\n required: ['id', 'object', 'title'],\n writable: ['title', 'notes', 'kind', 'priority', 'status', 'dueAt', 'remindAt', 'assigneeUid', 'contactId', 'companyId', 'dealId', 'consentSiteId'],\n writeOnly: {\n consentSiteId: stringField('The site the task is created on behalf of.'),\n },\n writeNote: 'A create needs `title` and `consentSiteId`; a `PATCH` that names `consentSiteId` is a `400`.',\n fields: {\n id: stringField('Task id.'),\n object: objectKindField('task'),\n title: stringField('Task title.'),\n notes: nullableField(stringField('Free-form notes.')),\n kind: stringField('Task type as its meaning: `call`, `email`, `meeting` or `todo`. A write takes the meaning or a label of the Type picklist.'),\n typeLabel: stringField('The organization’s Type picklist label, e.g. `Call`. Read-only; set through `kind`.'),\n priority: stringField('`low`, `normal` or `high`. A write takes the meaning or a label of the Priority picklist.'),\n priorityLabel: stringField('The organization’s Priority picklist label, e.g. `High`. Read-only; set through `priority`.'),\n status: stringField('`open` or `done`. A write takes the meaning or a label of the Status picklist, e.g. `In Progress`.'),\n statusLabel: stringField('The organization’s Status picklist label, e.g. `Not Started`. Read-only; set through `status`.'),\n dueAt: nullableField(isoField('When the task is due.')),\n remindAt: nullableField(isoField('When a reminder is scheduled.')),\n reminderSentAt: nullableField(isoField('When the reminder was sent.')),\n completedAt: nullableField(isoField('When it was completed.')),\n assigneeUid: nullableField(stringField('Assigned user.')),\n contactId: nullableField(stringField('Associated contact.')),\n companyId: nullableField(stringField('Associated company.')),\n dealId: nullableField(stringField('Associated deal.')),\n siteId: nullableField(stringField('Site the record originated on.')),\n ...RECORD_STAMPS,\n },\n ops: [\n { path: '/v1/tasks', method: 'get', operationId: 'listTasks', summary: 'List tasks', description: 'Lists the workspace’s CRM tasks. Filter by status, assignee, contact or deal.', list: true, returns: 'Task', entitlement: 'crm', filters: [UPDATED_AFTER_PARAM, queryParam('status', 'Task status.'), queryParam('assigneeUid', 'Assigned user.'), queryParam('contactId', 'Associated contact.'), queryParam('dealId', 'Associated deal.')] },\n { path: '/v1/tasks', method: 'post', operationId: 'createTask', summary: 'Add a task', description: 'Creates a task, such as a follow-up, with a `title` and optionally a due date, a reminder and the contact, company or deal it is about. Returns the new task.', accepts: 'TaskWrite', returns: 'Task', entitlement: 'crm', creates: true, bodyRequires: ['title'] },\n { path: '/v1/tasks/{taskId}', method: 'get', operationId: 'getTask', summary: 'Get a task', description: 'Returns one task. Needs `taskId` from List tasks.', returns: 'Task', entitlement: 'crm', pathParams: [{ name: 'taskId', description: 'Task id.' }] },\n { path: '/v1/tasks/{taskId}', method: 'patch', operationId: 'updateTask', summary: 'Update a task', description: 'Changes a task, including marking it done; fields not sent stay as they are. Needs `taskId` from List tasks. Returns the updated task.', accepts: 'TaskWrite', returns: 'Task', entitlement: 'crm', pathParams: [{ name: 'taskId', description: 'Task id.' }] },\n { path: '/v1/tasks/{taskId}', method: 'delete', operationId: 'deleteTask', summary: 'Delete a task', description: 'Deletes a task permanently. Needs `taskId` from List tasks.', returns: 'Deleted', entitlement: 'crm', pathParams: [{ name: 'taskId', description: 'Task id.' }] },\n ],\n },\n activities: {\n tag: 'Activities',\n docsPage: 'activities',\n description: 'Logged interactions. Append-only, except that a call or a meeting takes its recording and transcript afterwards (PATCH).',\n schemaName: 'Activity',\n required: ['id', 'object', 'kind', 'at'],\n writable: ['kind', 'body', 'at', 'byUid', 'contactId', 'companyId', 'dealId', 'outcome', 'durationMinutes', 'direction', 'mediaIds', 'transcript', 'consentSiteId'],\n writeOnly: {\n consentSiteId: stringField('The site the activity is logged on behalf of.'),\n },\n writeRequired: ['body', 'consentSiteId'],\n fields: {\n id: stringField('Activity id.'),\n object: objectKindField('activity'),\n kind: stringField('What happened, e.g. `call`, `email`, `note`.'),\n body: stringField('Free-form body.'),\n at: isoField('When the interaction happened — not when it was logged.'),\n byUid: nullableField(stringField('User who logged it.')),\n contactId: nullableField(stringField('Associated contact.')),\n companyId: nullableField(stringField('Associated company. When none is sent, the company of the deal, else of the contact.')),\n dealId: nullableField(stringField('Associated deal.')),\n outcome: nullableField(stringField('Outcome label.')),\n durationMinutes: nullableField(integerField('Duration, for calls and meetings.')),\n direction: nullableField(stringField('Which way it went: `inbound`, `outbound` or `internal` for a call, `inbound` or `outbound` for an email.')),\n mediaIds: stringListField('A call’s or a meeting’s recordings: media library files by id, at most 5. Upload the audio first with Upload a file to the media library (`private: true`, `purpose: \"callRecording\"`).'),\n transcript: nullableField(stringField('What was said, as text, for a call or a meeting; at most 200,000 characters. Searchable with the body.')),\n siteId: nullableField(stringField('Site the record originated on.')),\n ...RECORD_STAMPS,\n },\n ops: [\n { path: '/v1/activities', method: 'get', operationId: 'listActivities', summary: 'List activities', description: 'Lists the calls, emails, meetings and notes logged in the CRM. Filter by kind, contact or deal.', list: true, returns: 'Activity', entitlement: 'crm', filters: [UPDATED_AFTER_PARAM, queryParam('kind', 'Activity kind.'), queryParam('contactId', 'Associated contact.'), queryParam('dealId', 'Associated deal.')] },\n { path: '/v1/activities', method: 'post', operationId: 'createActivity', summary: 'Log an activity', description: 'Records a call, email, meeting or note against a contact, company or deal. Needs the activity’s text in `body`. Returns the logged activity. Logging an email records it; it does not send one.', accepts: 'ActivityWrite', returns: 'Activity', entitlement: 'crm', creates: true },\n { path: '/v1/activities/{activityId}', method: 'get', operationId: 'getActivity', summary: 'Get an activity', description: 'Returns one logged activity. Needs `activityId` from List activities.', returns: 'Activity', entitlement: 'crm', pathParams: [{ name: 'activityId', description: 'Activity id.' }] },\n { path: '/v1/activities/{activityId}', method: 'patch', operationId: 'updateActivity', summary: 'Attach a recording or transcript to an activity', description: 'Attaches a call’s or a meeting’s recording (`mediaIds`) and its `transcript` after it was logged; nothing else about the activity changes, and `null` or `[]` removes them. Needs `activityId` from List activities. Upload the audio first with Upload a file to the media library. Returns the activity.', accepts: 'ActivityRecordingWrite', returns: 'Activity', entitlement: 'crm', pathParams: [{ name: 'activityId', description: 'Activity id.' }] },\n { path: '/v1/activities/{activityId}', method: 'delete', operationId: 'deleteActivity', summary: 'Delete an activity', description: 'Deletes a logged activity permanently. Needs `activityId` from List activities.', returns: 'Deleted', entitlement: 'crm', pathParams: [{ name: 'activityId', description: 'Activity id.' }] },\n ],\n components: {\n ActivityRecordingWrite: {\n type: 'object',\n description:\n 'What a call or a meeting takes after it was logged. Any other member is a `400`.',\n properties: {\n mediaIds: {\n type: ['array', 'null'],\n items: { type: 'string' },\n maxItems: 5,\n description: 'Media library files by id, at most 5. `null` or `[]` removes them.',\n },\n transcript: {\n type: ['string', 'null'],\n maxLength: 200000,\n description: 'What was said, as text. `null` or an empty string removes it.',\n },\n },\n additionalProperties: false,\n },\n },\n },\n leads: {\n tag: 'Leads',\n docsPage: 'leads',\n description: 'Unqualified interest, before it becomes a contact. A lead is a record of its own: the person and their company as text, until converting makes the contact and the company.',\n schemaName: 'Lead',\n required: ['id', 'object', 'siteId'],\n writable: [\n 'siteId', 'email', 'name', 'status', 'ownerUid', 'ownerEmail', 'notes', 'unqualifiedReason', 'company', 'jobTitle', 'phone', 'website', 'address', 'tags', 'leadSource',\n // Salesforce's standard lead fields (AGL-3513).\n 'salutation', 'firstName', 'lastName', 'mobilePhone', 'fax', 'doNotCall', 'industry', 'rating', 'annualRevenueCents', 'currency', 'numberOfEmployees',\n ],\n writeNote: '`email` and `name` are taken on a create only; a `PATCH` cannot change the address, which is the lead’s identity within its site. While `firstName` or `lastName` is set, `name` is their composition, \"First Last\", and follows them.',\n writeRequired: ['email'],\n writeOnly: {\n siteId: stringField('The site the lead belongs to, instead of the `siteId` query parameter.'),\n status: stringField('One of the organization’s active lead status values by its label (CRM › Fields › Leads), or a meaning — `new`, `nurturing`, `working` or `unqualified` (`nurturing` and `unqualified` on a `PATCH` only). Stored as the meaning and the label together. A lead becomes `qualified` by being converted.'),\n ownerEmail: stringField('A member’s address, resolved against the organization’s roster. Not with `ownerUid` in the same request.'),\n },\n fields: {\n id: stringField('Lead id.'),\n object: objectKindField('lead'),\n siteId: stringField('Site the lead arrived on.'),\n email: nullableField(stringField('Email — the lead’s identity within its site.')),\n name: nullableField(stringField('Name, when supplied.')),\n status: stringField('What the lead status means: `new`, `nurturing`, `working`, `qualified` or `unqualified`. What every filter and automation reads.'),\n statusLabel: stringField('The organization’s label for the lead status value the lead holds — one of `status`’s meaning. Read-only; set it through `status`.'),\n ownerUid: nullableField(stringField('Owning user.')),\n notes: nullableField(stringField('Free-form notes.')),\n unqualifiedReason: nullableField(stringField('Why the lead was disqualified.')),\n company: nullableField(stringField('The company’s name, as text. Converting the lead is what links or creates the company record.')),\n jobTitle: nullableField(stringField('Job title.')),\n phone: nullableField(stringField('E.164 phone number.')),\n website: nullableField(stringField('An http(s) URL.')),\n address: nullableField(postalAddressField()),\n tags: stringListField('Lower-cased tags.'),\n leadSource: nullableField(\n stringField(\n \"Where the lead came from: one of the organization's active lead source values \" +\n '(CRM › Fields › Leads), matched without regard to case. Any other value is refused ' +\n 'with a 400 naming the values allowed; the value a lead already holds is kept even ' +\n \"after it is deactivated. A create that names none starts from the list's default.\",\n ),\n ),\n // Salesforce's standard lead fields (AGL-3513).\n salutation: nullableField(stringField('Salutation: one of the organization’s active Salutation values (CRM › Fields › Contacts), matched without regard to case. Any other value is a `400` naming the values allowed; the value a lead already holds is kept.')),\n firstName: nullableField(stringField('First name, at most 59 characters. While it or `lastName` is set, `name` is \"First Last\".')),\n lastName: nullableField(stringField('Last name, at most 59 characters.')),\n mobilePhone: nullableField(stringField('E.164 mobile phone number.')),\n fax: nullableField(stringField('E.164 fax number.')),\n doNotCall: booleanField('The person asked not to be phoned. A hint on every call control, never a block. `false` clears it.'),\n industry: nullableField(stringField('Industry: one of the organization’s active Industry values (CRM › Fields › Companies) — the list companies keep, so converting carries it. Any other value is a `400` naming the values allowed; the value a lead already holds is kept.')),\n rating: nullableField(stringField('Rating: one of the organization’s active Rating values (CRM › Fields › Companies). Any other value is a `400` naming the values allowed.')),\n annualRevenueCents: nullableField(integerField('Annual revenue in the minor unit of `currency`, 0 or more.')),\n currency: stringField('Lowercase ISO 4217 code of the annual revenue. `usd` when unset.'),\n numberOfEmployees: nullableField(integerField('Number of employees, 0 to 99,999,999.')),\n sources: stringListField('The surfaces that captured the lead: `signup`, `booking`, `form:{formId}`, `import`, `manual`, `api`.'),\n submissionCount: integerField('How many form submissions this lead has made.'),\n firstSeen: isoField('First interaction.'),\n lastSeen: isoField('Most recent interaction.'),\n marketingConsent: booleanField('Whether marketing consent was given.'),\n marketingConsentAt: nullableField(isoField('When consent was given.')),\n convertedContactId: nullableField(stringField('Contact created by conversion.')),\n convertedAt: nullableField(isoField('When it was converted.')),\n companyId: nullableField(stringField('Company created or matched by conversion.')),\n dealId: nullableField(stringField('Deal created by conversion.')),\n ...RECORD_STAMPS,\n },\n ops: [\n { path: '/v1/leads', method: 'get', operationId: 'listLeads', summary: 'List a site’s leads', description: 'Lists the leads one site has captured, not yet converted into contacts. Needs `siteId` from List sites. Filter by status or owner.', list: true, returns: 'Lead', entitlement: 'crm', filters: [UPDATED_AFTER_PARAM, LEAD_SITE_PARAM, queryParam('status', 'Lead status.'), queryParam('ownerUid', 'Owning user.')] },\n // openWorld: after saving, the address’s mail domain is looked up (DNS) to flag addresses that would bounce.\n // destructive: adding an address the site already holds updates that lead, so it can overwrite what was there.\n { path: '/v1/leads', method: 'post', operationId: 'createLead', summary: 'Add a lead to a site', accepts: 'LeadWrite', returns: 'Lead', entitlement: 'crm', creates: true, description: 'Adds a lead to one site. Needs `siteId` from List sites and the lead’s `email`. One email is one lead per site: adding an address the site already holds updates that lead. No contact is created until the lead is converted. Returns the lead.', idempotent: true, openWorld: true, destructive: true, bodyRequires: ['siteId', 'email'] },\n { path: '/v1/leads/{leadId}', method: 'get', operationId: 'getLead', summary: 'Get a lead', description: 'Returns one lead. Needs `siteId` from List sites and `leadId` from List a site’s leads.', returns: 'Lead', entitlement: 'crm', pathParams: [{ name: 'leadId', description: 'Lead id.' }], filters: [LEAD_SITE_PARAM] },\n { path: '/v1/leads/{leadId}', method: 'patch', operationId: 'updateLead', summary: 'Update a lead', description: 'Changes a lead, including its status; fields not sent stay as they are. Needs `siteId` from List sites and `leadId` from List a site’s leads. Returns the updated lead.', accepts: 'LeadWrite', returns: 'Lead', entitlement: 'crm', pathParams: [{ name: 'leadId', description: 'Lead id.' }], filters: [LEAD_SITE_PARAM] },\n // openWorld: the contact it creates has its mail domain looked up (DNS) to flag addresses that would bounce.\n { path: '/v1/leads/{leadId}/convert', method: 'post', operationId: 'convertLead', summary: 'Convert a lead into a contact', accepts: 'LeadConvertRequest', bodyOptional: true, returns: 'LeadConversion', entitlement: 'crm', description: 'Turns a lead into a contact, joining an existing contact with the same email, and can also link or create a company and open a deal. Needs `siteId` from List sites and `leadId` from List a site’s leads. Converting a lead again returns the same ids.', pathParams: [{ name: 'leadId', description: 'Lead id.' }], idempotent: true, openWorld: true, filters: [LEAD_SITE_PARAM] },\n ],\n components: {\n LeadConvertRequest: {\n type: 'object',\n description:\n 'Optional. What else the conversion does besides creating the contact. ' +\n 'Leave it out to convert the lead into a contact alone.',\n properties: {\n company: {\n type: ['object', 'null'],\n description:\n 'A company for the contact: `{ \"link\": \"<companyId>\" }` to link one from List companies, ' +\n '`{ \"create\": { \"name\": \"…\", \"domain\": \"…\" } }` to add one (an existing company with that ' +\n 'name or domain is reused), or null for none.',\n },\n deal: {\n type: ['object', 'null'],\n description:\n 'A deal to open in the default pipeline: `{ \"title\": \"…\", \"amountCents\": 12500, \"currency\": ' +\n '\"usd\", \"stageId\": \"…\", \"type\": \"…\" }`. `title` is required; the rest is optional. Null for none.',\n },\n ownerUid: { type: 'string', description: 'Workspace member who owns the contact and the deal. Defaults to the lead’s owner.' },\n ownerEmail: { type: 'string', description: 'The owner by email address, instead of `ownerUid`.' },\n },\n additionalProperties: false,\n },\n LeadConversion: {\n type: 'object',\n description:\n 'What the conversion produced: the contact, and the company and deal ' +\n 'when it made or linked them. Converting the same lead again returns ' +\n 'the same ids.',\n properties: {\n object: { type: 'string', const: 'lead_conversion' },\n contactId: { type: 'string' },\n companyId: { type: ['string', 'null'] },\n dealId: { type: ['string', 'null'] },\n },\n additionalProperties: true,\n },\n },\n },\n 'email-templates': {\n tag: 'Email templates',\n docsPage: 'email-templates',\n description: 'Reusable email bodies.',\n schemaName: 'EmailTemplate',\n required: ['id', 'object', 'name'],\n writable: ['name', 'kind', 'visibility', 'ownerUid', 'subject', 'body', 'consentSiteId'],\n writeOnly: {\n consentSiteId: stringField('The site the template is created on behalf of.'),\n },\n writeNote: 'A create needs `name`, `body` and `consentSiteId`; a `PATCH` that names `consentSiteId` is a `400`.',\n fields: {\n id: stringField('Template id.'),\n object: objectKindField('email_template'),\n name: stringField('Template name.'),\n kind: stringField('Template kind.'),\n visibility: stringField('`org` or `private`.'),\n ownerUid: nullableField(stringField('Owner, for a private template.')),\n subject: stringField('Subject line.'),\n body: stringField('Body. May contain merge tokens.'),\n siteId: nullableField(stringField('Site the template belongs to, when scoped.')),\n ...RECORD_STAMPS,\n },\n ops: [\n { path: '/v1/email-templates', method: 'get', operationId: 'listEmailTemplates', summary: 'List email templates', description: 'Lists the workspace’s saved email templates with their name, subject and kind.', list: true, returns: 'EmailTemplate', entitlement: 'crm', filters: [UPDATED_AFTER_PARAM, queryParam('kind', 'Template kind.'), queryParam('visibility', 'Visibility.')] },\n { path: '/v1/email-templates', method: 'post', operationId: 'createEmailTemplate', summary: 'Add an email template', description: 'Saves a reusable email with a `name`, a subject and the message in `body`. Saving a template sends nothing. Returns the new template.', accepts: 'EmailTemplateWrite', returns: 'EmailTemplate', entitlement: 'crm', creates: true, bodyRequires: ['name', 'body'] },\n { path: '/v1/email-templates/{templateId}', method: 'get', operationId: 'getEmailTemplate', summary: 'Get an email template', description: 'Returns one email template. Needs `templateId` from List email templates.', returns: 'EmailTemplate', entitlement: 'crm', pathParams: [{ name: 'templateId', description: 'Template id.' }] },\n { path: '/v1/email-templates/{templateId}', method: 'patch', operationId: 'updateEmailTemplate', summary: 'Update an email template', description: 'Changes a template; fields not sent stay as they are. Needs `templateId` from List email templates. Returns the updated template.', accepts: 'EmailTemplateWrite', returns: 'EmailTemplate', entitlement: 'crm', pathParams: [{ name: 'templateId', description: 'Template id.' }] },\n { path: '/v1/email-templates/{templateId}', method: 'delete', operationId: 'deleteEmailTemplate', summary: 'Delete an email template', description: 'Deletes a template permanently. Needs `templateId` from List email templates.', returns: 'Deleted', entitlement: 'crm', pathParams: [{ name: 'templateId', description: 'Template id.' }] },\n ],\n },\n}\n"],"names":["booleanField","integerField","isoField","nullableField","objectKindField","openObjectField","postalAddressField","queryParam","requiredQueryParam","RECORD_STAMPS","stringField","stringListField","UPDATED_AFTER_PARAM","companyPicklistNote","label","plural","LEAD_SITE_PARAM","CRM_API_V1_DESCRIPTIONS","contacts","tag","docsPage","description","schemaName","required","writable","writeOnly","consentSiteId","consentGroupId","custom","mediaIds","writeNote","fields","id","object","email","name","tags","notes","marketingConsent","consentSites","sources","phone","jobTitle","companyId","address","ownerUid","lifecycleStage","leadSource","salutation","firstName","lastName","department","mobilePhone","homePhone","otherPhone","fax","birthdate","assistantName","assistantPhone","reportsToContactId","otherAddress","doNotCall","companyIds","alternateEmails","ops","path","method","operationId","summary","list","returns","entitlement","filters","accepts","creates","openWorld","pathParams","destructive","idempotent","components","ContactMerge","type","properties","sourceContactId","additionalProperties","companies","domain","website","industry","rating","ownership","accountSource","annualRevenueCents","currency","numberOfEmployees","accountNumber","site","tickerSymbol","sicCode","shippingAddress","parentCompanyId","nextTaskAt","siteId","bodyRequires","pipelines","isDefault","archived","archivedAt","stages","items","order","probability","kind","enum","forecastCategory","deals","title","pipelineId","stageId","status","amountCents","lineItems","expectedCloseAt","closedAt","stageChangedAt","contactId","contactRoles","role","primary","lostReason","nextStep","campaignId","tasks","typeLabel","priority","priorityLabel","statusLabel","dueAt","remindAt","reminderSentAt","completedAt","assigneeUid","dealId","activities","writeRequired","body","at","byUid","outcome","durationMinutes","direction","transcript","ActivityRecordingWrite","maxItems","maxLength","leads","ownerEmail","unqualifiedReason","company","submissionCount","firstSeen","lastSeen","marketingConsentAt","convertedContactId","convertedAt","bodyOptional","LeadConvertRequest","deal","LeadConversion","const","visibility","subject"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAEEA,YAAY,EACZC,YAAY,EACZC,QAAQ,EACRC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,kBAAkB,EAClBC,UAAU,EACVC,kBAAkB,EAClBC,aAAa,EACbC,WAAW,EACXC,eAAe,EACfC,mBAAmB,QACd,qDAAoD;AAE3D;;;;;;;;;;CAUC,GACD,sEAAsE,GACtE,SAASC,oBAAoBC,KAAa,EAAEC,MAAc;IACxD,OACE,GAAGD,MAAM,mCAAmC,EAAEC,OAAO,qCAAqC,CAAC,GAC3F,8FACA;AAEJ;AAGA;;;;;CAKC,GACD,MAAMC,kBAAkBR,mBACtB,UACA;AAGF,OAAO,MAAMS,0BAA8E;IACzFC,UAAU;QACRC,KAAK;QACLC,UAAU;QACVC,aAAa;QACbC,YAAY;QACZC,UAAU;YAAC;YAAM;YAAU;SAAQ;QACnCC,UAAU;YACR;YAAS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BC,aAAa;gBAAOK,YAAY;oBAAC;wBAAEzC,MAAM;wBAAcd,aAAa;oBAAe;iBAAE;YAAC;YACva;gBAAE4C,MAAM;gBAAoCC,QAAQ;gBAAUC,aAAa;gBAAuBC,SAAS;gBAA4B/C,aAAa;gBAAiFiD,SAAS;gBAAWC,aAAa;gBAAOK,YAAY;oBAAC;wBAAEzC,MAAM;wBAAcd,aAAa;oBAAe;iBAAE;YAAC;SAChV;IACH;AACF,EAAC"}
|
|
@@ -44,9 +44,39 @@ import type { PluginPersonRecordsEraser } from '@aglyn/aglyn/plugin-manager/plug
|
|
|
44
44
|
* and the lead rows and writes nothing.
|
|
45
45
|
*/
|
|
46
46
|
type Firestore = FirebaseFirestore.Firestore;
|
|
47
|
+
/** The part of a Storage bucket the eraser uses: deleting an object by path. */
|
|
48
|
+
export interface CrmEraserBucket {
|
|
49
|
+
file(path: string): {
|
|
50
|
+
delete(): Promise<unknown>;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
47
53
|
export interface CrmPersonEraserDeps {
|
|
48
54
|
firestore(): Firestore;
|
|
55
|
+
/** The media bucket, where a call recording's bytes are. */
|
|
56
|
+
bucket?(): CrmEraserBucket;
|
|
49
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Whether a media document is a CALL RECORDING: uploaded from a CRM activity
|
|
60
|
+
* with the call-recording confirmation, as against a brochure or a logo that
|
|
61
|
+
* happens to be attached to a record too and belongs to the business. The
|
|
62
|
+
* upload routes mark it `mediaPurpose: 'callRecording'`.
|
|
63
|
+
*/
|
|
64
|
+
export declare function isCallRecordingMedia(data: Record<string, unknown> | undefined): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* The call recordings filed on a person's activities, destroyed with them:
|
|
67
|
+
* the bytes (and anything derived from them), the media document, and the
|
|
68
|
+
* library's counter. A recording is the person's voice, so it is personal
|
|
69
|
+
* data in a way the sentence about the call is — and unlike a media delete in
|
|
70
|
+
* the library, nothing is kept for a restore. Only files uploaded as call
|
|
71
|
+
* recordings are touched; any other file a record names is the business's
|
|
72
|
+
* and stays. Returns how many were destroyed.
|
|
73
|
+
*/
|
|
74
|
+
export declare function eraseCallRecordings(input: {
|
|
75
|
+
db: Firestore;
|
|
76
|
+
orgRef: FirebaseFirestore.DocumentReference;
|
|
77
|
+
activities: readonly FirebaseFirestore.QueryDocumentSnapshot[];
|
|
78
|
+
bucket: CrmEraserBucket | null;
|
|
79
|
+
}): Promise<number>;
|
|
50
80
|
export declare function createCrmPersonEraser(deps: CrmPersonEraserDeps): PluginPersonRecordsEraser;
|
|
51
81
|
/** The records eraser over the platform's own Firestore, as the declarations register it. */
|
|
52
82
|
export declare function crmPersonEraser(): PluginPersonRecordsEraser;
|
|
@@ -15,12 +15,83 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/ import { CRM_COLLECTIONS } from "@aglyn/aglyn/app-utils/crm";
|
|
18
|
+
import { FieldValue } from "firebase-admin/firestore";
|
|
18
19
|
import { runPluginEventHandlers } from "@aglyn/aglyn/plugin-manager/plugin-events";
|
|
19
20
|
import { companyContactsCountFields } from "@aglyn/tenant-data-admin/server/contact-company-link";
|
|
20
21
|
import { deleteWhereEquals } from "@aglyn/tenant-data-admin/server/paged-sweeps";
|
|
21
22
|
import { firebaseAdmin } from "@aglyn/tenant-data-admin/server/firebase-admin";
|
|
23
|
+
import { mediaStoragePathInScope } from "@aglyn/tenant-data-admin/server/media-storage-path";
|
|
24
|
+
import { mediaDerivedObjectPaths } from "@aglyn/tenant-data-admin/server/media-variants";
|
|
22
25
|
import { contactFacetHolders, repointContactReportsTo } from "./contact-reports-to.js";
|
|
23
26
|
import { sweepDealContactRoles } from "./deal-contact-roles.js";
|
|
27
|
+
/**
|
|
28
|
+
* Whether a media document is a CALL RECORDING: uploaded from a CRM activity
|
|
29
|
+
* with the call-recording confirmation, as against a brochure or a logo that
|
|
30
|
+
* happens to be attached to a record too and belongs to the business. The
|
|
31
|
+
* upload routes mark it `mediaPurpose: 'callRecording'`.
|
|
32
|
+
*/ export function isCallRecordingMedia(data) {
|
|
33
|
+
if ((data == null ? void 0 : data['mediaPurpose']) === 'callRecording') return true;
|
|
34
|
+
const confirmation = data == null ? void 0 : data['rightsConfirmation'];
|
|
35
|
+
return (confirmation == null ? void 0 : confirmation['purpose']) === 'callRecording';
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The call recordings filed on a person's activities, destroyed with them:
|
|
39
|
+
* the bytes (and anything derived from them), the media document, and the
|
|
40
|
+
* library's counter. A recording is the person's voice, so it is personal
|
|
41
|
+
* data in a way the sentence about the call is — and unlike a media delete in
|
|
42
|
+
* the library, nothing is kept for a restore. Only files uploaded as call
|
|
43
|
+
* recordings are touched; any other file a record names is the business's
|
|
44
|
+
* and stays. Returns how many were destroyed.
|
|
45
|
+
*/ export async function eraseCallRecordings(input) {
|
|
46
|
+
const { orgRef, activities, bucket } = input;
|
|
47
|
+
const ids = new Set();
|
|
48
|
+
for (const activity of activities){
|
|
49
|
+
const named = activity.get('mediaIds');
|
|
50
|
+
if (!Array.isArray(named)) continue;
|
|
51
|
+
for (const id of named)if (typeof id === 'string' && id) ids.add(id);
|
|
52
|
+
}
|
|
53
|
+
let erased = 0;
|
|
54
|
+
const base = `orgs/${orgRef.id}`;
|
|
55
|
+
for (const mediaId of ids){
|
|
56
|
+
try {
|
|
57
|
+
var _snapshot_data, _data_sizeBytes;
|
|
58
|
+
const mediaRef = orgRef.collection('media').doc(mediaId);
|
|
59
|
+
const snapshot = await mediaRef.get();
|
|
60
|
+
if (!snapshot.exists) continue;
|
|
61
|
+
const data = (_snapshot_data = snapshot.data()) != null ? _snapshot_data : {};
|
|
62
|
+
if (!isCallRecordingMedia(data)) continue;
|
|
63
|
+
const objectPath = mediaStoragePathInScope({
|
|
64
|
+
storagePath: data['storagePath'],
|
|
65
|
+
base,
|
|
66
|
+
mediaId
|
|
67
|
+
});
|
|
68
|
+
if (bucket) {
|
|
69
|
+
for (const path of [
|
|
70
|
+
objectPath,
|
|
71
|
+
...mediaDerivedObjectPaths(objectPath, data)
|
|
72
|
+
]){
|
|
73
|
+
await bucket.file(path).delete().catch(()=>undefined);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const sizeBytes = Number((_data_sizeBytes = data['sizeBytes']) != null ? _data_sizeBytes : 0) || 0;
|
|
77
|
+
// The document and the counter in one commit, so the library's total
|
|
78
|
+
// never counts a file that is gone.
|
|
79
|
+
const batch = input.db.batch();
|
|
80
|
+
batch.delete(mediaRef);
|
|
81
|
+
batch.set(orgRef.collection('counters').doc('media'), {
|
|
82
|
+
bytes: FieldValue.increment(-sizeBytes),
|
|
83
|
+
count: FieldValue.increment(-1)
|
|
84
|
+
}, {
|
|
85
|
+
merge: true
|
|
86
|
+
});
|
|
87
|
+
await batch.commit();
|
|
88
|
+
erased += 1;
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.error(`${LABEL}: call recording could not be erased`, error);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return erased;
|
|
94
|
+
}
|
|
24
95
|
/** The label every log line of this eraser carries — never the address. */ const LABEL = 'crm person eraser';
|
|
25
96
|
async function contactsOf(firestore, target) {
|
|
26
97
|
const contacts = firestore.collection('orgs').doc(target.orgId).collection('contacts');
|
|
@@ -39,6 +110,7 @@ export function createCrmPersonEraser(deps) {
|
|
|
39
110
|
deals: 0,
|
|
40
111
|
tasks: 0,
|
|
41
112
|
activities: 0,
|
|
113
|
+
recordings: 0,
|
|
42
114
|
leads: 0
|
|
43
115
|
};
|
|
44
116
|
const wanted = new Set(request.contactIds);
|
|
@@ -73,6 +145,20 @@ export function createCrmPersonEraser(deps) {
|
|
|
73
145
|
// Off every deal: its contact role, and its Primary with `contactId` (AGL-3521).
|
|
74
146
|
report.deals += await sweepDealContactRoles(db, orgRef.collection(CRM_COLLECTIONS.deals), contactId, null, LABEL);
|
|
75
147
|
report.tasks += await deleteWhereEquals(db, orgRef.collection(CRM_COLLECTIONS.tasks), 'contactId', contactId, LABEL);
|
|
148
|
+
// The recordings BEFORE the activities that name them: once the
|
|
149
|
+
// activities are gone, nothing says which files were this person's.
|
|
150
|
+
try {
|
|
151
|
+
var _ref;
|
|
152
|
+
const filed = await orgRef.collection(CRM_COLLECTIONS.activities).where('contactId', '==', contactId).get();
|
|
153
|
+
report.recordings += await eraseCallRecordings({
|
|
154
|
+
db,
|
|
155
|
+
orgRef,
|
|
156
|
+
activities: filed.docs,
|
|
157
|
+
bucket: (_ref = deps.bucket == null ? void 0 : deps.bucket.call(deps)) != null ? _ref : null
|
|
158
|
+
});
|
|
159
|
+
} catch (error) {
|
|
160
|
+
console.error(`${LABEL}: call recordings could not be read`, error);
|
|
161
|
+
}
|
|
76
162
|
report.activities += await deleteWhereEquals(db, orgRef.collection(CRM_COLLECTIONS.activities), 'contactId', contactId, LABEL);
|
|
77
163
|
// A pointer at an erased person is a trace of them: cleared in every
|
|
78
164
|
// holder's facet that could hold one — the holders of this contact.
|
|
@@ -142,7 +228,8 @@ export function createCrmPersonEraser(deps) {
|
|
|
142
228
|
}
|
|
143
229
|
/** The records eraser over the platform's own Firestore, as the declarations register it. */ export function crmPersonEraser() {
|
|
144
230
|
return createCrmPersonEraser({
|
|
145
|
-
firestore: ()=>firebaseAdmin.app().firestore()
|
|
231
|
+
firestore: ()=>firebaseAdmin.app().firestore(),
|
|
232
|
+
bucket: ()=>firebaseAdmin.app().storage().bucket(process.env['NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET'])
|
|
146
233
|
});
|
|
147
234
|
}
|
|
148
235
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/server/person-eraser.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 { CRM_COLLECTIONS } from '@aglyn/aglyn/app-utils/crm'\nimport { runPluginEventHandlers } from '@aglyn/aglyn/plugin-manager/plugin-events'\nimport type {\n PluginPersonErasureReport,\n PluginPersonErasureRequest,\n PluginPersonErasureTarget,\n PluginPersonRecordsEraser,\n} from '@aglyn/aglyn/plugin-manager/plugin-person-erasure'\nimport { companyContactsCountFields } from '@aglyn/tenant-data-admin/server/contact-company-link'\nimport { deleteWhereEquals } from '@aglyn/tenant-data-admin/server/paged-sweeps'\nimport { firebaseAdmin } from '@aglyn/tenant-data-admin/server/firebase-admin'\nimport { contactFacetHolders, repointContactReportsTo } from './contact-reports-to'\nimport { sweepDealContactRoles } from './deal-contact-roles'\n\n/**\n * THE CRM'S SHARE OF A PERSON ERASURE (AGL-2623, AGL-3080): the records\n * eraser of the plugin that keeps people.\n *\n * `locate` names the person's contacts — every contact document whose address\n * is theirs — before anything is erased, so every other plugin can find what\n * it keeps by them. `erase` runs after every other eraser:\n *\n * 1. each contact and its satellites — each linked company's contact count\n * moved down once, deals unlinked (a deal is the team's own pipeline\n * record and stays; the person leaves its contact roles, AGL-3521), tasks and activities deleted, every other contact's\n * reports-to that named the person cleared (AGL-3515) — then the contact\n * document itself, WHOLE. Not the CRM's delete, which is a detach that\n * leaves the row for the other holders: every site's facet, every consent\n * entry and every attribution goes with it, and with the facets every\n * profile field — the birthdate, the phones, the other address, the\n * assistant — that Salesforce's standard fields put there;\n * 2. the person's lead: the organization's row (AGL-3275), and every legacy\n * per-site row still standing on a site of this workspace — and no other\n * workspace's;\n * 3. once those rows are gone, `host.records.removed` names them, so a plugin\n * keeping a figure over leads — a form counting the people it filed —\n * drops by this person and by nothing else (AGL-3330).\n *\n * Each step is best-effort against the others: a failure is logged and counted\n * as zero, and the report says what happened. A DRY RUN counts the contacts\n * and the lead rows and writes nothing.\n */\n\ntype Firestore = FirebaseFirestore.Firestore\n\nexport interface CrmPersonEraserDeps {\n firestore(): Firestore\n}\n\n/** The label every log line of this eraser carries — never the address. */\nconst LABEL = 'crm person eraser'\n\nasync function contactsOf(\n firestore: Firestore,\n target: PluginPersonErasureTarget,\n): Promise<FirebaseFirestore.QueryDocumentSnapshot[]> {\n const contacts = firestore.collection('orgs').doc(target.orgId).collection('contacts')\n return (await contacts.where('email', '==', target.email).get()).docs\n}\n\nexport function createCrmPersonEraser(deps: CrmPersonEraserDeps): PluginPersonRecordsEraser {\n async function locate(target: PluginPersonErasureTarget): Promise<readonly string[]> {\n return (await contactsOf(deps.firestore(), target)).map((contact) => String(contact.id))\n }\n\n async function erase(request: PluginPersonErasureRequest): Promise<PluginPersonErasureReport> {\n const db = deps.firestore()\n const orgRef = db.collection('orgs').doc(request.orgId)\n const report = {\n contacts: 0,\n companyLinks: 0,\n deals: 0,\n tasks: 0,\n activities: 0,\n leads: 0,\n }\n const wanted = new Set(request.contactIds)\n // The contacts `locate` named, read again: a dry run counts them, and a\n // contact deleted since is simply not there to erase.\n const contacts = (await contactsOf(db, request)).filter((contact) => wanted.has(contact.id))\n const hostIds = (await db.collection('hosts').where('orgId', '==', request.orgId).get()).docs.map(\n (doc) => String(doc.id),\n )\n\n if (request.dryRun) {\n let leads = (await orgRef.collection('leads').doc(request.key).get()).exists ? 1 : 0\n for (const hostId of hostIds) {\n const lead = await db.collection('hosts').doc(hostId).collection('leads').doc(request.key).get()\n if (lead.exists) leads += 1\n }\n return { ...report, contacts: contacts.length, leads }\n }\n\n for (const contact of contacts) {\n const contactId = String(contact.id)\n const companyIds: unknown = contact.get('companyIds')\n const linked = Array.isArray(companyIds)\n ? companyIds.filter((id): id is string => typeof id === 'string' && !!id)\n : []\n for (const companyId of new Set(linked)) {\n try {\n await orgRef\n .collection(CRM_COLLECTIONS.companies)\n .doc(companyId)\n .update(companyContactsCountFields(-1))\n report.companyLinks += 1\n } catch (error) {\n console.error(`${LABEL}: company count could not move for ${companyId}`, error)\n }\n }\n // Off every deal: its contact role, and its Primary with `contactId` (AGL-3521).\n report.deals += await sweepDealContactRoles(\n db,\n orgRef.collection(CRM_COLLECTIONS.deals),\n contactId,\n null,\n LABEL,\n )\n report.tasks += await deleteWhereEquals(db, orgRef.collection(CRM_COLLECTIONS.tasks), 'contactId', contactId, LABEL)\n report.activities += await deleteWhereEquals(\n db,\n orgRef.collection(CRM_COLLECTIONS.activities),\n 'contactId',\n contactId,\n LABEL,\n )\n // A pointer at an erased person is a trace of them: cleared in every\n // holder's facet that could hold one — the holders of this contact.\n await repointContactReportsTo(\n db,\n orgRef.collection('contacts'),\n contactFacetHolders(contact.data() ?? {}),\n contactId,\n null,\n LABEL,\n )\n try {\n await contact.ref.delete()\n report.contacts += 1\n } catch (error) {\n console.error(`${LABEL}: contact delete failed for ${contactId}`, error)\n }\n }\n\n /*\n * THE ORG ROW, ONCE (AGL-3275) — and then every legacy row still standing.\n * A lead is one document for the whole org now, but until every site is\n * folded a person can still be held at `hosts/{hostId}/leads`, and an\n * erasure that deleted only the org row would leave that copy behind. So\n * both are swept, and `leads` is what was actually destroyed rather than\n * how many places were looked at.\n */\n const erasedLeads: Array<{ id: string; data: Record<string, unknown> }> = []\n try {\n const orgLead = orgRef.collection('leads').doc(request.key)\n const snapshot = await orgLead.get()\n if (snapshot.exists) {\n erasedLeads.push({ id: request.key, data: snapshot.data() ?? {} })\n await orgLead.delete()\n report.leads += 1\n }\n } catch (error) {\n console.error(`${LABEL}: org lead delete failed`, error)\n }\n for (const hostId of hostIds) {\n try {\n const lead = db.collection('hosts').doc(hostId).collection('leads').doc(request.key)\n const snapshot = await lead.get()\n if (snapshot.exists) {\n erasedLeads.push({ id: request.key, data: snapshot.data() ?? {} })\n await lead.delete()\n report.leads += 1\n }\n } catch (error) {\n console.error(`${LABEL}: legacy lead delete failed for ${hostId}`, error)\n }\n }\n if (erasedLeads.length) {\n // Isolated per plugin by the seam, and never the erasure's failure.\n await runPluginEventHandlers('host.records.removed', {\n orgId: request.orgId,\n hostIds,\n collection: 'leads',\n records: erasedLeads,\n }).catch((error) => console.error(`${LABEL}: records-removed event failed`, error))\n }\n return report\n }\n\n return { locate, erase }\n}\n\n/** The records eraser over the platform's own Firestore, as the declarations register it. */\nexport function crmPersonEraser(): PluginPersonRecordsEraser {\n return createCrmPersonEraser({ firestore: () => firebaseAdmin.app().firestore() })\n}\n"],"names":["CRM_COLLECTIONS","runPluginEventHandlers","companyContactsCountFields","deleteWhereEquals","firebaseAdmin","contactFacetHolders","repointContactReportsTo","sweepDealContactRoles","LABEL","contactsOf","firestore","target","contacts","collection","doc","orgId","where","email","get","docs","createCrmPersonEraser","deps","locate","map","contact","String","id","erase","request","db","orgRef","report","companyLinks","deals","tasks","activities","leads","wanted","Set","contactIds","filter","has","hostIds","dryRun","key","exists","hostId","lead","length","contactId","companyIds","linked","Array","isArray","companyId","companies","update","error","console","data","ref","delete","erasedLeads","orgLead","snapshot","push","records","catch","crmPersonEraser","app"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,eAAe,QAAQ,6BAA4B;AAC5D,SAASC,sBAAsB,QAAQ,4CAA2C;AAOlF,SAASC,0BAA0B,QAAQ,uDAAsD;AACjG,SAASC,iBAAiB,QAAQ,+CAA8C;AAChF,SAASC,aAAa,QAAQ,iDAAgD;AAC9E,SAASC,mBAAmB,EAAEC,uBAAuB,QAAQ,0BAAsB;AACnF,SAASC,qBAAqB,QAAQ,0BAAsB;AAqC5D,yEAAyE,GACzE,MAAMC,QAAQ;AAEd,eAAeC,WACbC,SAAoB,EACpBC,MAAiC;IAEjC,MAAMC,WAAWF,UAAUG,UAAU,CAAC,QAAQC,GAAG,CAACH,OAAOI,KAAK,EAAEF,UAAU,CAAC;IAC3E,OAAO,AAAC,CAAA,MAAMD,SAASI,KAAK,CAAC,SAAS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AAoE;YACpE,MAAM/C,uBAAuB,wBAAwB;gBACnDc,OAAOa,QAAQb,KAAK;gBACpB2B;gBACA7B,YAAY;gBACZqD,SAASJ;YACX,GAAGK,KAAK,CAAC,CAACV,QAAUC,QAAQD,KAAK,CAAC,GAAGjD,MAAM,8BAA8B,CAAC,EAAEiD;QAC9E;QACA,OAAO1B;IACT;IAEA,OAAO;QAAET;QAAQK;IAAM;AACzB;AAEA,2FAA2F,GAC3F,OAAO,SAASyC;IACd,OAAOhD,sBAAsB;QAAEV,WAAW,IAAMN,cAAciE,GAAG,GAAG3D,SAAS;IAAG;AAClF"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/server/person-eraser.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 { CRM_COLLECTIONS } from '@aglyn/aglyn/app-utils/crm'\nimport { FieldValue } from 'firebase-admin/firestore'\nimport { runPluginEventHandlers } from '@aglyn/aglyn/plugin-manager/plugin-events'\nimport type {\n PluginPersonErasureReport,\n PluginPersonErasureRequest,\n PluginPersonErasureTarget,\n PluginPersonRecordsEraser,\n} from '@aglyn/aglyn/plugin-manager/plugin-person-erasure'\nimport { companyContactsCountFields } from '@aglyn/tenant-data-admin/server/contact-company-link'\nimport { deleteWhereEquals } from '@aglyn/tenant-data-admin/server/paged-sweeps'\nimport { firebaseAdmin } from '@aglyn/tenant-data-admin/server/firebase-admin'\nimport { mediaStoragePathInScope } from '@aglyn/tenant-data-admin/server/media-storage-path'\nimport { mediaDerivedObjectPaths } from '@aglyn/tenant-data-admin/server/media-variants'\nimport { contactFacetHolders, repointContactReportsTo } from './contact-reports-to'\nimport { sweepDealContactRoles } from './deal-contact-roles'\n\n/**\n * THE CRM'S SHARE OF A PERSON ERASURE (AGL-2623, AGL-3080): the records\n * eraser of the plugin that keeps people.\n *\n * `locate` names the person's contacts — every contact document whose address\n * is theirs — before anything is erased, so every other plugin can find what\n * it keeps by them. `erase` runs after every other eraser:\n *\n * 1. each contact and its satellites — each linked company's contact count\n * moved down once, deals unlinked (a deal is the team's own pipeline\n * record and stays; the person leaves its contact roles, AGL-3521), tasks and activities deleted, every other contact's\n * reports-to that named the person cleared (AGL-3515) — then the contact\n * document itself, WHOLE. Not the CRM's delete, which is a detach that\n * leaves the row for the other holders: every site's facet, every consent\n * entry and every attribution goes with it, and with the facets every\n * profile field — the birthdate, the phones, the other address, the\n * assistant — that Salesforce's standard fields put there;\n * 2. the person's lead: the organization's row (AGL-3275), and every legacy\n * per-site row still standing on a site of this workspace — and no other\n * workspace's;\n * 3. once those rows are gone, `host.records.removed` names them, so a plugin\n * keeping a figure over leads — a form counting the people it filed —\n * drops by this person and by nothing else (AGL-3330).\n *\n * Each step is best-effort against the others: a failure is logged and counted\n * as zero, and the report says what happened. A DRY RUN counts the contacts\n * and the lead rows and writes nothing.\n */\n\ntype Firestore = FirebaseFirestore.Firestore\n\n/** The part of a Storage bucket the eraser uses: deleting an object by path. */\nexport interface CrmEraserBucket {\n file(path: string): { delete(): Promise<unknown> }\n}\n\nexport interface CrmPersonEraserDeps {\n firestore(): Firestore\n /** The media bucket, where a call recording's bytes are. */\n bucket?(): CrmEraserBucket\n}\n\n/**\n * Whether a media document is a CALL RECORDING: uploaded from a CRM activity\n * with the call-recording confirmation, as against a brochure or a logo that\n * happens to be attached to a record too and belongs to the business. The\n * upload routes mark it `mediaPurpose: 'callRecording'`.\n */\nexport function isCallRecordingMedia(data: Record<string, unknown> | undefined): boolean {\n if (data?.['mediaPurpose'] === 'callRecording') return true\n const confirmation = data?.['rightsConfirmation'] as Record<string, unknown> | undefined\n return confirmation?.['purpose'] === 'callRecording'\n}\n\n/**\n * The call recordings filed on a person's activities, destroyed with them:\n * the bytes (and anything derived from them), the media document, and the\n * library's counter. A recording is the person's voice, so it is personal\n * data in a way the sentence about the call is — and unlike a media delete in\n * the library, nothing is kept for a restore. Only files uploaded as call\n * recordings are touched; any other file a record names is the business's\n * and stays. Returns how many were destroyed.\n */\nexport async function eraseCallRecordings(input: {\n db: Firestore\n orgRef: FirebaseFirestore.DocumentReference\n activities: readonly FirebaseFirestore.QueryDocumentSnapshot[]\n bucket: CrmEraserBucket | null\n}): Promise<number> {\n const { orgRef, activities, bucket } = input\n const ids = new Set<string>()\n for (const activity of activities) {\n const named: unknown = activity.get('mediaIds')\n if (!Array.isArray(named)) continue\n for (const id of named) if (typeof id === 'string' && id) ids.add(id)\n }\n let erased = 0\n const base = `orgs/${orgRef.id}`\n for (const mediaId of ids) {\n try {\n const mediaRef = orgRef.collection('media').doc(mediaId)\n const snapshot = await mediaRef.get()\n if (!snapshot.exists) continue\n const data = (snapshot.data() ?? {}) as Record<string, unknown>\n if (!isCallRecordingMedia(data)) continue\n const objectPath = mediaStoragePathInScope({\n storagePath: data['storagePath'],\n base,\n mediaId,\n })\n if (bucket) {\n for (const path of [objectPath, ...mediaDerivedObjectPaths(objectPath, data)]) {\n await bucket.file(path).delete().catch(() => undefined)\n }\n }\n const sizeBytes = Number(data['sizeBytes'] ?? 0) || 0\n // The document and the counter in one commit, so the library's total\n // never counts a file that is gone.\n const batch = input.db.batch()\n batch.delete(mediaRef)\n batch.set(\n orgRef.collection('counters').doc('media'),\n {\n bytes: FieldValue.increment(-sizeBytes),\n count: FieldValue.increment(-1),\n },\n { merge: true },\n )\n await batch.commit()\n erased += 1\n } catch (error) {\n console.error(`${LABEL}: call recording could not be erased`, error)\n }\n }\n return erased\n}\n\n/** The label every log line of this eraser carries — never the address. */\nconst LABEL = 'crm person eraser'\n\nasync function contactsOf(\n firestore: Firestore,\n target: PluginPersonErasureTarget,\n): Promise<FirebaseFirestore.QueryDocumentSnapshot[]> {\n const contacts = firestore.collection('orgs').doc(target.orgId).collection('contacts')\n return (await contacts.where('email', '==', target.email).get()).docs\n}\n\nexport function createCrmPersonEraser(deps: CrmPersonEraserDeps): PluginPersonRecordsEraser {\n async function locate(target: PluginPersonErasureTarget): Promise<readonly string[]> {\n return (await contactsOf(deps.firestore(), target)).map((contact) => String(contact.id))\n }\n\n async function erase(request: PluginPersonErasureRequest): Promise<PluginPersonErasureReport> {\n const db = deps.firestore()\n const orgRef = db.collection('orgs').doc(request.orgId)\n const report = {\n contacts: 0,\n companyLinks: 0,\n deals: 0,\n tasks: 0,\n activities: 0,\n recordings: 0,\n leads: 0,\n }\n const wanted = new Set(request.contactIds)\n // The contacts `locate` named, read again: a dry run counts them, and a\n // contact deleted since is simply not there to erase.\n const contacts = (await contactsOf(db, request)).filter((contact) => wanted.has(contact.id))\n const hostIds = (await db.collection('hosts').where('orgId', '==', request.orgId).get()).docs.map(\n (doc) => String(doc.id),\n )\n\n if (request.dryRun) {\n let leads = (await orgRef.collection('leads').doc(request.key).get()).exists ? 1 : 0\n for (const hostId of hostIds) {\n const lead = await db.collection('hosts').doc(hostId).collection('leads').doc(request.key).get()\n if (lead.exists) leads += 1\n }\n return { ...report, contacts: contacts.length, leads }\n }\n\n for (const contact of contacts) {\n const contactId = String(contact.id)\n const companyIds: unknown = contact.get('companyIds')\n const linked = Array.isArray(companyIds)\n ? companyIds.filter((id): id is string => typeof id === 'string' && !!id)\n : []\n for (const companyId of new Set(linked)) {\n try {\n await orgRef\n .collection(CRM_COLLECTIONS.companies)\n .doc(companyId)\n .update(companyContactsCountFields(-1))\n report.companyLinks += 1\n } catch (error) {\n console.error(`${LABEL}: company count could not move for ${companyId}`, error)\n }\n }\n // Off every deal: its contact role, and its Primary with `contactId` (AGL-3521).\n report.deals += await sweepDealContactRoles(\n db,\n orgRef.collection(CRM_COLLECTIONS.deals),\n contactId,\n null,\n LABEL,\n )\n report.tasks += await deleteWhereEquals(db, orgRef.collection(CRM_COLLECTIONS.tasks), 'contactId', contactId, LABEL)\n // The recordings BEFORE the activities that name them: once the\n // activities are gone, nothing says which files were this person's.\n try {\n const filed = await orgRef\n .collection(CRM_COLLECTIONS.activities)\n .where('contactId', '==', contactId)\n .get()\n report.recordings += await eraseCallRecordings({\n db,\n orgRef,\n activities: filed.docs,\n bucket: deps.bucket?.() ?? null,\n })\n } catch (error) {\n console.error(`${LABEL}: call recordings could not be read`, error)\n }\n report.activities += await deleteWhereEquals(\n db,\n orgRef.collection(CRM_COLLECTIONS.activities),\n 'contactId',\n contactId,\n LABEL,\n )\n // A pointer at an erased person is a trace of them: cleared in every\n // holder's facet that could hold one — the holders of this contact.\n await repointContactReportsTo(\n db,\n orgRef.collection('contacts'),\n contactFacetHolders(contact.data() ?? {}),\n contactId,\n null,\n LABEL,\n )\n try {\n await contact.ref.delete()\n report.contacts += 1\n } catch (error) {\n console.error(`${LABEL}: contact delete failed for ${contactId}`, error)\n }\n }\n\n /*\n * THE ORG ROW, ONCE (AGL-3275) — and then every legacy row still standing.\n * A lead is one document for the whole org now, but until every site is\n * folded a person can still be held at `hosts/{hostId}/leads`, and an\n * erasure that deleted only the org row would leave that copy behind. So\n * both are swept, and `leads` is what was actually destroyed rather than\n * how many places were looked at.\n */\n const erasedLeads: Array<{ id: string; data: Record<string, unknown> }> = []\n try {\n const orgLead = orgRef.collection('leads').doc(request.key)\n const snapshot = await orgLead.get()\n if (snapshot.exists) {\n erasedLeads.push({ id: request.key, data: snapshot.data() ?? {} })\n await orgLead.delete()\n report.leads += 1\n }\n } catch (error) {\n console.error(`${LABEL}: org lead delete failed`, error)\n }\n for (const hostId of hostIds) {\n try {\n const lead = db.collection('hosts').doc(hostId).collection('leads').doc(request.key)\n const snapshot = await lead.get()\n if (snapshot.exists) {\n erasedLeads.push({ id: request.key, data: snapshot.data() ?? {} })\n await lead.delete()\n report.leads += 1\n }\n } catch (error) {\n console.error(`${LABEL}: legacy lead delete failed for ${hostId}`, error)\n }\n }\n if (erasedLeads.length) {\n // Isolated per plugin by the seam, and never the erasure's failure.\n await runPluginEventHandlers('host.records.removed', {\n orgId: request.orgId,\n hostIds,\n collection: 'leads',\n records: erasedLeads,\n }).catch((error) => console.error(`${LABEL}: records-removed event failed`, error))\n }\n return report\n }\n\n return { locate, erase }\n}\n\n/** The records eraser over the platform's own Firestore, as the declarations register it. */\nexport function crmPersonEraser(): PluginPersonRecordsEraser {\n return createCrmPersonEraser({\n firestore: () => firebaseAdmin.app().firestore(),\n bucket: () =>\n firebaseAdmin.app().storage().bucket(process.env['NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET']),\n })\n}\n"],"names":["CRM_COLLECTIONS","FieldValue","runPluginEventHandlers","companyContactsCountFields","deleteWhereEquals","firebaseAdmin","mediaStoragePathInScope","mediaDerivedObjectPaths","contactFacetHolders","repointContactReportsTo","sweepDealContactRoles","isCallRecordingMedia","data","confirmation","eraseCallRecordings","input","orgRef","activities","bucket","ids","Set","activity","named","get","Array","isArray","id","add","erased","base","mediaId","snapshot","mediaRef","collection","doc","exists","objectPath","storagePath","path","file","delete","catch","undefined","sizeBytes","Number","batch","db","set","bytes","increment","count","merge","commit","error","console","LABEL","contactsOf","firestore","target","contacts","orgId","where","email","docs","createCrmPersonEraser","deps","locate","map","contact","String","erase","request","report","companyLinks","deals","tasks","recordings","leads","wanted","contactIds","filter","has","hostIds","dryRun","key","hostId","lead","length","contactId","companyIds","linked","companyId","companies","update","filed","ref","erasedLeads","orgLead","push","records","crmPersonEraser","app","storage","process","env"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,eAAe,QAAQ,6BAA4B;AAC5D,SAASC,UAAU,QAAQ,2BAA0B;AACrD,SAASC,sBAAsB,QAAQ,4CAA2C;AAOlF,SAASC,0BAA0B,QAAQ,uDAAsD;AACjG,SAASC,iBAAiB,QAAQ,+CAA8C;AAChF,SAASC,aAAa,QAAQ,iDAAgD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