@wirecat/cli-core 0.618.0 → 0.619.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/CHANGELOG.md +339 -1
- package/README.md +1 -1
- package/THIRD_PARTY_NOTICES +3 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/background/deliver.d.ts +5 -2
- package/dist/background/deliver.js +30 -12
- package/dist/background/report/render.d.ts +3 -1
- package/dist/background/report/render.js +3 -1
- package/dist/calendar/cli/answers.d.ts +1 -0
- package/dist/calendar/cli/answers.js +6 -1
- package/dist/calendar/cli/index.js +2 -14
- package/dist/calendar/cli/people-link.d.ts +3 -0
- package/dist/calendar/cli/people-link.js +23 -0
- package/dist/calendar/index.d.ts +1 -1
- package/dist/calendar/index.js +1 -1
- package/dist/calendar/mcp/index.d.ts +12 -12
- package/dist/cli/base-stages-command.d.ts +22 -0
- package/dist/cli/base-stages-command.js +174 -0
- package/dist/cli/command-runs.d.ts +2 -0
- package/dist/cli/command-runs.js +3 -1
- package/dist/cli/config-command.js +6 -1
- package/dist/cli/context.js +1 -0
- package/dist/cli/group-lock.d.ts +42 -0
- package/dist/cli/group-lock.js +130 -0
- package/dist/cli/index.d.ts +7 -2
- package/dist/cli/index.js +7 -2
- package/dist/cli/messenger/backfill-command.js +27 -15
- package/dist/cli/messenger/contacts-command.js +10 -3
- package/dist/cli/messenger/context.js +1 -0
- package/dist/cli/messenger/doctor-command.js +3 -1
- package/dist/cli/messenger/models-command.js +1 -1
- package/dist/cli/messenger/store-maintenance-command.d.ts +22 -2
- package/dist/cli/messenger/store-maintenance-command.js +9 -4
- package/dist/cli/model-catalogue-command.d.ts +3 -1
- package/dist/cli/model-catalogue-command.js +46 -2
- package/dist/cli/profile.d.ts +8 -0
- package/dist/cli/profile.js +25 -0
- package/dist/cli/program.js +2 -0
- package/dist/cli/runs/search-query.d.ts +1 -1
- package/dist/cli/runs/search-query.js +4 -0
- package/dist/cli/runs/search.d.ts +5 -1
- package/dist/cli/runs/search.js +12 -1
- package/dist/cli/search-left-out.d.ts +6 -1
- package/dist/cli/search-left-out.js +9 -4
- package/dist/cli/settings.d.ts +8 -0
- package/dist/cli/settings.js +17 -2
- package/dist/cli/shared-command-exports.d.ts +16 -0
- package/dist/cli/store-recover.d.ts +3 -3
- package/dist/cli/store-recover.js +26 -26
- package/dist/cli/store-settings.d.ts +2 -0
- package/dist/cli/store-settings.js +37 -9
- package/dist/crm/cli/index.js +38 -6
- package/dist/crm/group-hint.d.ts +8 -0
- package/dist/crm/group-hint.js +13 -0
- package/dist/crm/source.d.ts +12 -1
- package/dist/crm/sync.d.ts +31 -2
- package/dist/crm/sync.js +110 -3
- package/dist/crm/testing/acme-scenario.d.ts +40 -0
- package/dist/crm/testing/acme-scenario.js +170 -0
- package/dist/crm/testing/index.d.ts +1 -0
- package/dist/crm/testing/index.js +1 -0
- package/dist/crm/testing/source-contract.js +12 -0
- package/dist/crm/testing/source.d.ts +2 -0
- package/dist/crm/testing/source.js +1 -0
- package/dist/domain/addresses.d.ts +13 -0
- package/dist/domain/addresses.js +63 -0
- package/dist/domain/categories.d.ts +3 -0
- package/dist/domain/categories.js +2 -0
- package/dist/domain/crm.d.ts +23 -0
- package/dist/domain/crm.js +7 -0
- package/dist/domain/mentions.d.ts +2 -12
- package/dist/domain/mentions.js +2 -19
- package/dist/domain/orders.d.ts +8 -1
- package/dist/domain/orders.js +6 -2
- package/dist/domain/phones.d.ts +26 -0
- package/dist/domain/phones.js +48 -0
- package/dist/domain/record-types.d.ts +1 -1
- package/dist/domain/record-types.js +1 -0
- package/dist/domain/records.d.ts +5 -0
- package/dist/domain/ref-summaries.d.ts +39 -0
- package/dist/domain/ref-summaries.js +51 -3
- package/dist/domain/relations.d.ts +12 -2
- package/dist/domain/relations.js +14 -3
- package/dist/domain/vcard.d.ts +2 -2
- package/dist/domain/vcard.js +4 -10
- package/dist/embeddings/models.d.ts +11 -3
- package/dist/embeddings/models.js +28 -4
- package/dist/entities/business-context.d.ts +149 -0
- package/dist/entities/business-context.js +192 -0
- package/dist/entities/contact-activity.d.ts +2 -0
- package/dist/entities/contact-activity.js +7 -1
- package/dist/entities/contact-context.d.ts +157 -0
- package/dist/entities/contact-context.js +2 -0
- package/dist/entities/deal.d.ts +10 -0
- package/dist/entities/deal.js +2 -0
- package/dist/entities/index.d.ts +23 -3
- package/dist/entities/index.js +5 -0
- package/dist/entities/mention.d.ts +4 -3
- package/dist/entities/mention.js +2 -1
- package/dist/entities/message-transfer.d.ts +4 -2
- package/dist/entities/message-transfer.js +2 -2
- package/dist/entities/model.d.ts +2 -2
- package/dist/entities/model.js +1 -1
- package/dist/entities/relationship.d.ts +4 -0
- package/dist/entities/relationship.js +4 -0
- package/dist/errors/reasons.js +37 -4
- package/dist/fetch/page.js +2 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/meetings/context-store.d.ts +2 -0
- package/dist/meetings/findings-rules.d.ts +4 -0
- package/dist/meetings/findings-rules.js +5 -2
- package/dist/meetings/result-items.d.ts +1 -0
- package/dist/meetings/result-items.js +1 -0
- package/dist/models/index.js +22 -5
- package/dist/runs/events.d.ts +11 -1
- package/dist/runs/events.js +3 -1
- package/dist/runs/log-attributes.js +4 -0
- package/dist/runs/log-events.js +2 -0
- package/dist/runs/recording.d.ts +3 -0
- package/dist/runs/recording.js +36 -12
- package/dist/runs/run.d.ts +12 -3
- package/dist/runs/run.js +32 -13
- package/dist/search/account-list.d.ts +6 -0
- package/dist/search/account-list.js +9 -3
- package/dist/search/groups.d.ts +68 -0
- package/dist/search/groups.js +172 -0
- package/dist/services/account-groups.d.ts +28 -0
- package/dist/services/account-groups.js +89 -0
- package/dist/services/archive.d.ts +7 -1
- package/dist/services/archive.js +19 -3
- package/dist/services/business-context.d.ts +113 -0
- package/dist/services/business-context.js +156 -0
- package/dist/services/communications.d.ts +50 -0
- package/dist/services/communications.js +140 -0
- package/dist/services/deal-context.d.ts +90 -0
- package/dist/services/deal-context.js +131 -0
- package/dist/services/deps.d.ts +2 -0
- package/dist/services/enrichment.d.ts +7 -2
- package/dist/services/enrichment.js +46 -5
- package/dist/services/events-search.js +2 -1
- package/dist/services/group-guard.d.ts +28 -0
- package/dist/services/group-guard.js +131 -0
- package/dist/services/index.d.ts +15 -2
- package/dist/services/index.js +9 -2
- package/dist/services/ingest.d.ts +12 -0
- package/dist/services/ingest.js +4 -0
- package/dist/services/meaning-model.d.ts +7 -0
- package/dist/services/meaning-model.js +20 -0
- package/dist/services/meeting-context.d.ts +6 -1
- package/dist/services/meeting-context.js +12 -5
- package/dist/services/message-resolution.js +2 -3
- package/dist/services/messages-meaning.js +4 -5
- package/dist/services/messages-search.d.ts +5 -1
- package/dist/services/messages-search.js +1 -1
- package/dist/services/model-downloads.d.ts +1 -1
- package/dist/services/model-downloads.js +6 -4
- package/dist/services/money-context.d.ts +73 -0
- package/dist/services/money-context.js +77 -0
- package/dist/services/notes-search.d.ts +4 -1
- package/dist/services/notes-search.js +19 -7
- package/dist/services/organization-context.d.ts +80 -0
- package/dist/services/organization-context.js +154 -0
- package/dist/services/people.d.ts +22 -6
- package/dist/services/people.js +38 -8
- package/dist/services/person-business.d.ts +43 -0
- package/dist/services/person-business.js +67 -0
- package/dist/services/person-context.d.ts +9 -1
- package/dist/services/person-context.js +5 -3
- package/dist/services/proposals/kinds/identity-link.d.ts +4 -0
- package/dist/services/proposals/kinds/identity-link.js +48 -0
- package/dist/services/proposals/kinds/orders.js +1 -1
- package/dist/services/proposals/registry.js +2 -0
- package/dist/services/search-kind.d.ts +12 -5
- package/dist/services/search-kind.js +49 -10
- package/dist/services/text-model-choice.js +1 -1
- package/dist/store/accounts.d.ts +18 -0
- package/dist/store/accounts.js +18 -3
- package/dist/store/damage.d.ts +43 -10
- package/dist/store/damage.js +119 -36
- package/dist/store/decisions.js +3 -1
- package/dist/store/evidence-findings.d.ts +14 -0
- package/dist/store/evidence-findings.js +2 -0
- package/dist/store/exports.d.ts +2 -1
- package/dist/store/identity-links.d.ts +92 -0
- package/dist/store/identity-links.js +6 -0
- package/dist/store/index.d.ts +11 -5
- package/dist/store/index.js +5 -2
- package/dist/store/journal.d.ts +10 -0
- package/dist/store/journal.js +33 -0
- package/dist/store/marks.d.ts +19 -1
- package/dist/store/marks.js +23 -1
- package/dist/store/people.d.ts +22 -0
- package/dist/store/people.js +15 -1
- package/dist/store/sqlite/accounts.js +2 -0
- package/dist/store/sqlite/base-stages.d.ts +122 -0
- package/dist/store/sqlite/base-stages.js +443 -0
- package/dist/store/sqlite/base-suggest.d.ts +13 -0
- package/dist/store/sqlite/base-suggest.js +62 -0
- package/dist/store/sqlite/business-contracts.js +10 -1
- package/dist/store/sqlite/crm-settings.d.ts +12 -2
- package/dist/store/sqlite/crm-settings.js +56 -13
- package/dist/store/sqlite/crm.d.ts +13 -1
- package/dist/store/sqlite/crm.js +20 -4
- package/dist/store/sqlite/deals.d.ts +33 -0
- package/dist/store/sqlite/deals.js +42 -4
- package/dist/store/sqlite/decision-requests.js +7 -3
- package/dist/store/sqlite/email-index.js +8 -4
- package/dist/store/sqlite/evidence-findings.js +29 -5
- package/dist/store/sqlite/findings-core.js +4 -2
- package/dist/store/sqlite/identity-link-rows.d.ts +50 -0
- package/dist/store/sqlite/identity-link-rows.js +146 -0
- package/dist/store/sqlite/identity-proposals.d.ts +53 -0
- package/dist/store/sqlite/identity-proposals.js +234 -0
- package/dist/store/sqlite/knowledge.js +2 -2
- package/dist/store/sqlite/link-kinds.d.ts +1 -0
- package/dist/store/sqlite/link-kinds.js +1 -0
- package/dist/store/sqlite/link-row.d.ts +6 -0
- package/dist/store/sqlite/link-row.js +35 -0
- package/dist/store/sqlite/link-source.d.ts +10 -0
- package/dist/store/sqlite/link-source.js +16 -0
- package/dist/store/sqlite/manifest.js +1 -0
- package/dist/store/sqlite/meeting-context-links.js +9 -6
- package/dist/store/sqlite/memories.js +9 -7
- package/dist/store/sqlite/mentions.d.ts +4 -1
- package/dist/store/sqlite/mentions.js +14 -9
- package/dist/store/sqlite/migrations.generated.js +8 -0
- package/dist/store/sqlite/notes.d.ts +1 -2
- package/dist/store/sqlite/notes.js +4 -29
- package/dist/store/sqlite/open-store.js +3 -0
- package/dist/store/sqlite/open.js +11 -2
- package/dist/store/sqlite/orders.d.ts +2 -0
- package/dist/store/sqlite/orders.js +9 -3
- package/dist/store/sqlite/organization-categories.d.ts +18 -0
- package/dist/store/sqlite/organization-categories.js +34 -0
- package/dist/store/sqlite/organizations.d.ts +5 -1
- package/dist/store/sqlite/organizations.js +14 -4
- package/dist/store/sqlite/person-links.d.ts +19 -4
- package/dist/store/sqlite/person-links.js +49 -11
- package/dist/store/sqlite/person-match-scan.d.ts +13 -0
- package/dist/store/sqlite/person-match-scan.js +251 -0
- package/dist/store/sqlite/person-matcher.d.ts +16 -0
- package/dist/store/sqlite/person-matcher.js +32 -0
- package/dist/store/sqlite/proposed-actions.js +6 -0
- package/dist/store/sqlite/record-matching.d.ts +2 -8
- package/dist/store/sqlite/record-matching.js +8 -40
- package/dist/store/sqlite/record-projectors-phone.js +2 -1
- package/dist/store/sqlite/record-relationships.d.ts +52 -0
- package/dist/store/sqlite/record-relationships.js +243 -0
- package/dist/store/sqlite/record-run.d.ts +5 -0
- package/dist/store/sqlite/record-run.js +62 -2
- package/dist/store/sqlite/record-writes.d.ts +1 -1
- package/dist/store/sqlite/record-writes.js +4 -2
- package/dist/store/sqlite/records.js +27 -2
- package/dist/store/sqlite/ref-accounts.d.ts +13 -0
- package/dist/store/sqlite/ref-accounts.js +117 -0
- package/dist/store/sqlite/ref-summaries.js +5 -1
- package/dist/store/sqlite/relation-list.d.ts +4 -1
- package/dist/store/sqlite/relation-list.js +18 -2
- package/dist/store/sqlite/relation-proposals.d.ts +6 -0
- package/dist/store/sqlite/relation-proposals.js +3 -0
- package/dist/store/sqlite/relation-roles.js +12 -6
- package/dist/store/sqlite/reported-relations.d.ts +11 -1
- package/dist/store/sqlite/reported-relations.js +59 -18
- package/dist/store/sqlite/schema.d.ts +32 -0
- package/dist/store/sqlite/schema.js +3 -0
- package/dist/store/sqlite/transaction.js +11 -1
- package/dist/store/store.d.ts +3 -0
- package/dist/store/store.js +5 -0
- package/dist/store/write-events.d.ts +18 -0
- package/dist/store/write-events.js +88 -0
- package/package.json +3 -3
- package/parity.json +11 -4
- package/schemas/records-envelope.v1.schema.json +3 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { CRM_OPENS } from "../../domain/providers.js";
|
|
2
|
+
import { syncCrm } from "../index.js";
|
|
3
|
+
import { fakeCrmSource } from "./source.js";
|
|
4
|
+
/** The CRM portal of the owner's own company, Northstar Consulting. */
|
|
5
|
+
export const ACME_PORTAL = { provider: "example-crm", account: "northstar.example" };
|
|
6
|
+
export const ACME_TELEGRAM = { provider: "telegram", account: "100" };
|
|
7
|
+
export const ACME_MAIL = { provider: "email", account: "owner@northstar.example" };
|
|
8
|
+
export const ACME_CALENDAR = { provider: "google-calendar", account: "owner@northstar.example" };
|
|
9
|
+
const DAY = 86_400_000;
|
|
10
|
+
/** The deal opens on this day; every message, mail and meeting falls within its first month. */
|
|
11
|
+
export const ACME_OPENED = Date.UTC(2026, 9, 1);
|
|
12
|
+
export const ACME_NOW = Date.UTC(2026, 10, 1);
|
|
13
|
+
const USERS = [
|
|
14
|
+
{ externalId: "u1", name: "Emma", email: "emma@northstar.example", position: "Sales owner", departments: ["10"] },
|
|
15
|
+
];
|
|
16
|
+
/**
|
|
17
|
+
* Plan §8's scenario, synthetic: Northstar Consulting is the owner's own company and its CRM portal, Acme Ltd its
|
|
18
|
+
* customer. Alice and Bob are Acme's CRM contacts; Emma is a portal user, Northstar's sales owner and the deal's owner.
|
|
19
|
+
* The deal "Acme renewal" has Alice as contact (CRM), Bob as decision-maker (the owner's) and project Atlas (the
|
|
20
|
+
* owner's, on the CRM copy). The owner has a Telegram dialog with Alice, a mail with Bob, a Zoom meeting with all three, an invoice to
|
|
21
|
+
* Acme with no payment and an open follow-up task. Everything is written through the store's and the CRM sync's own
|
|
22
|
+
* calls; the store is the caller's, and no real account is touched.
|
|
23
|
+
*/
|
|
24
|
+
export const acmeScenario = async (store) => {
|
|
25
|
+
await store.accounts.registerProvider({ name: ACME_PORTAL.provider, kind: "crm", aliases: [], opens: CRM_OPENS });
|
|
26
|
+
const crm = fakeCrmSource({ traits: { removedInChanges: true } });
|
|
27
|
+
crm.put("organization", { externalId: "c1", name: "Acme Ltd" });
|
|
28
|
+
crm.put("organization", { externalId: "my1", name: "Northstar Consulting", own: true });
|
|
29
|
+
crm.put("person", {
|
|
30
|
+
externalId: "7",
|
|
31
|
+
name: "Alice",
|
|
32
|
+
email: "alice@acme.example",
|
|
33
|
+
position: "Procurement manager",
|
|
34
|
+
organizations: [{ externalId: "c1", primary: true }],
|
|
35
|
+
});
|
|
36
|
+
crm.put("person", { externalId: "8", name: "Bob", email: "bob@acme.example", organizations: [{ externalId: "c1" }] });
|
|
37
|
+
crm.put("deal", {
|
|
38
|
+
externalId: "d1",
|
|
39
|
+
title: "Acme renewal",
|
|
40
|
+
pipeline: "deal-1",
|
|
41
|
+
stage: "new",
|
|
42
|
+
organization: "c1",
|
|
43
|
+
people: [{ externalId: "7", role: "contact", primary: true }],
|
|
44
|
+
assignee: "u1",
|
|
45
|
+
createdAt: ACME_OPENED,
|
|
46
|
+
});
|
|
47
|
+
const source = Object.assign(crm, { users: async () => USERS });
|
|
48
|
+
const sync = () => syncCrm(source, store, ACME_PORTAL, { rescan: true, now: ACME_NOW });
|
|
49
|
+
await sync();
|
|
50
|
+
const personOf = async (email) => `person:${(await store.people.personOf({ provider: "email", id: email }))?.uid}`;
|
|
51
|
+
const [alice, bob, emma] = await Promise.all(["alice@acme.example", "bob@acme.example", "emma@northstar.example"].map(personOf));
|
|
52
|
+
const organizations = await store.knowledge.organizations();
|
|
53
|
+
const named = (name) => organizations.find((one) => one.name === name)?.ref;
|
|
54
|
+
const acme = named("Acme Ltd");
|
|
55
|
+
const own = named("Northstar Consulting");
|
|
56
|
+
const deal = (await store.crm.refOf(ACME_PORTAL, "deal", "d1"));
|
|
57
|
+
const owner = `person:${(await store.people.owner())?.uid}`;
|
|
58
|
+
const relate = (from, to, kind, role) => store.knowledge.relate(null, { from, to, kind, ...(role ? { role } : {}), by: "owner" });
|
|
59
|
+
await relate(acme, own, "customer-of");
|
|
60
|
+
await relate(owner, own, "member-of", "founder");
|
|
61
|
+
await relate(deal, bob, "related-to", "decision-maker");
|
|
62
|
+
const project = (await store.knowledge.addProject({ name: "Atlas", organization: acme })).ref;
|
|
63
|
+
await store.deals.setProject(deal, { project, by: "owner" });
|
|
64
|
+
const invoice = (await store.finance.addInvoice({
|
|
65
|
+
by: "owner",
|
|
66
|
+
direction: "receivable",
|
|
67
|
+
counterparty: acme,
|
|
68
|
+
currency: "EUR",
|
|
69
|
+
issueDate: "2026-10-10",
|
|
70
|
+
project,
|
|
71
|
+
lines: [{ description: "Atlas renewal", amount: "1200.00" }],
|
|
72
|
+
})).ref;
|
|
73
|
+
const task = (await store.tasks.create({ project, title: "Follow up on the Acme renewal", type: "chore" }, "owner"))
|
|
74
|
+
.ref;
|
|
75
|
+
await store.accounts.saveAccount(ACME_TELEGRAM, { name: null });
|
|
76
|
+
await store.chats.saveChats(ACME_TELEGRAM, [
|
|
77
|
+
{
|
|
78
|
+
id: "201",
|
|
79
|
+
title: "Alice",
|
|
80
|
+
kind: "dialog",
|
|
81
|
+
unreadCount: 0,
|
|
82
|
+
lastMessageAt: new Date(ACME_OPENED + 3 * DAY).toISOString(),
|
|
83
|
+
participantsCount: null,
|
|
84
|
+
},
|
|
85
|
+
]);
|
|
86
|
+
await store.people.savePeople(ACME_TELEGRAM, [{ id: "201", name: "Alice" }]);
|
|
87
|
+
await store.messages.saveMessages(ACME_TELEGRAM, "201", [
|
|
88
|
+
{
|
|
89
|
+
id: "1",
|
|
90
|
+
chatId: "201",
|
|
91
|
+
senderId: "201",
|
|
92
|
+
senderName: "Alice",
|
|
93
|
+
timestamp: new Date(ACME_OPENED + 3 * DAY).toISOString(),
|
|
94
|
+
editedAt: null,
|
|
95
|
+
text: "Can we renew Atlas before December?",
|
|
96
|
+
outgoing: false,
|
|
97
|
+
attachments: [],
|
|
98
|
+
replyTo: null,
|
|
99
|
+
forwardedFrom: null,
|
|
100
|
+
reactions: null,
|
|
101
|
+
},
|
|
102
|
+
], { via: "acme-scenario" });
|
|
103
|
+
await store.roster.saveMembers(ACME_TELEGRAM, "201", ["201", "100"]);
|
|
104
|
+
await store.people.linkIdentities({ provider: "email", id: "alice@acme.example" }, { provider: "telegram", id: "201" }, { method: "manual", by: "owner" });
|
|
105
|
+
const mail = await store.accounts.saveAccount(ACME_MAIL, { name: null });
|
|
106
|
+
await store.mail.saveThread({
|
|
107
|
+
accountId: mail,
|
|
108
|
+
externalId: "renewal-terms",
|
|
109
|
+
now: ACME_NOW,
|
|
110
|
+
emails: [
|
|
111
|
+
{
|
|
112
|
+
externalId: "<terms@acme.example>",
|
|
113
|
+
subject: "Renewal terms",
|
|
114
|
+
from: { address: "bob@acme.example", name: "Bob" },
|
|
115
|
+
to: [{ address: ACME_MAIL.account, name: null }],
|
|
116
|
+
sentAt: ACME_OPENED + 5 * DAY,
|
|
117
|
+
receivedAt: ACME_OPENED + 5 * DAY,
|
|
118
|
+
bodyText: "Here are our terms for the renewal.",
|
|
119
|
+
outgoing: false,
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
});
|
|
123
|
+
await store.people.savePeople(ACME_MAIL, [{ id: "bob@acme.example", name: "Bob" }]);
|
|
124
|
+
const calendarAccount = await store.accounts.saveAccount(ACME_CALENDAR, { name: null });
|
|
125
|
+
const [calendar] = await store.calendar.saveCalendars(calendarAccount, [
|
|
126
|
+
{
|
|
127
|
+
externalId: "primary",
|
|
128
|
+
title: "Work",
|
|
129
|
+
timezone: "UTC",
|
|
130
|
+
accessRole: "owner",
|
|
131
|
+
primary: true,
|
|
132
|
+
syncByDefault: true,
|
|
133
|
+
},
|
|
134
|
+
], ACME_NOW);
|
|
135
|
+
await store.calendar.saveEntries(calendar?.id, [
|
|
136
|
+
{
|
|
137
|
+
externalId: "renewal-call",
|
|
138
|
+
kind: "single",
|
|
139
|
+
status: "confirmed",
|
|
140
|
+
title: "Acme renewal call (Zoom)",
|
|
141
|
+
location: "https://zoom.example/j/1",
|
|
142
|
+
startsAt: ACME_OPENED + 7 * DAY,
|
|
143
|
+
endsAt: ACME_OPENED + 7 * DAY + 3_600_000,
|
|
144
|
+
participants: [
|
|
145
|
+
{ email: "alice@acme.example", name: "Alice" },
|
|
146
|
+
{ email: "bob@acme.example", name: "Bob" },
|
|
147
|
+
{ email: "emma@northstar.example", name: "Emma" },
|
|
148
|
+
],
|
|
149
|
+
},
|
|
150
|
+
], ACME_NOW);
|
|
151
|
+
const [event] = await store.calendar.events({ limit: 1 });
|
|
152
|
+
return {
|
|
153
|
+
store,
|
|
154
|
+
crm,
|
|
155
|
+
sync,
|
|
156
|
+
refs: {
|
|
157
|
+
owner,
|
|
158
|
+
own,
|
|
159
|
+
acme,
|
|
160
|
+
alice: alice,
|
|
161
|
+
bob: bob,
|
|
162
|
+
emma: emma,
|
|
163
|
+
deal,
|
|
164
|
+
project,
|
|
165
|
+
invoice,
|
|
166
|
+
task,
|
|
167
|
+
event: `event:${event?.id}`,
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { ACME_CALENDAR, ACME_MAIL, ACME_NOW, ACME_OPENED, ACME_PORTAL, ACME_TELEGRAM, type AcmeScenario, acmeScenario, } from "./acme-scenario.js";
|
|
1
2
|
export { exampleDeal, exampleLead, exampleOrganization, examplePerson, FAKE_CRM_ALIASES, type FakeCrmSource, type FakeCrmSourceOptions, type FakeCrmWrite, fakeCrmSource, LEAD_PIPELINE, SALES_PIPELINE, SOURCE_FIELD, } from "./source.js";
|
|
2
3
|
export { type CrmSourceFixture, crmSourceContract } from "./source-contract.js";
|
|
3
4
|
export { CRM_TRAIT_COMBINATIONS, type CrmSyncFixture, crmSyncContract } from "./sync-contract.js";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { ACME_CALENDAR, ACME_MAIL, ACME_NOW, ACME_OPENED, ACME_PORTAL, ACME_TELEGRAM, acmeScenario, } from "./acme-scenario.js";
|
|
1
2
|
export { exampleDeal, exampleLead, exampleOrganization, examplePerson, FAKE_CRM_ALIASES, fakeCrmSource, LEAD_PIPELINE, SALES_PIPELINE, SOURCE_FIELD, } from "./source.js";
|
|
2
3
|
export { crmSourceContract } from "./source-contract.js";
|
|
3
4
|
export { CRM_TRAIT_COMBINATIONS, crmSyncContract } from "./sync-contract.js";
|
|
@@ -28,6 +28,18 @@ const listAll = async (source, kind, cursor) => {
|
|
|
28
28
|
/** What every CRM adapter answers, whatever the CRM: run each case in the adapter's tests. */
|
|
29
29
|
export const crmSourceContract = (make) => {
|
|
30
30
|
const cases = [
|
|
31
|
+
{
|
|
32
|
+
name: "self: a source that names its own user gives it as a user id, and every deal and lead an assignee",
|
|
33
|
+
async run() {
|
|
34
|
+
const { source } = await make();
|
|
35
|
+
if (!source.self)
|
|
36
|
+
return;
|
|
37
|
+
assert.match(String(await source.self()), /^\d{1,20}$/, "self() answers a numeric user id");
|
|
38
|
+
for (const kind of DEAL_KINDS.filter((one) => source.traits.kinds.includes(one)))
|
|
39
|
+
for (const item of (await listAll(source, kind, null)).items)
|
|
40
|
+
assert.ok(item.assignee, `${kind} ${item.externalId} has an assignee: mine would keep it as nobody's`);
|
|
41
|
+
},
|
|
42
|
+
},
|
|
31
43
|
{
|
|
32
44
|
name: "pipelines: unique ids in each kind, stages with a known outcome and unique ids",
|
|
33
45
|
async run() {
|
|
@@ -8,6 +8,8 @@ export interface FakeCrmSourceOptions {
|
|
|
8
8
|
pageSize?: number;
|
|
9
9
|
/** What the write side takes: every verb on both kinds, not idempotent, when absent. */
|
|
10
10
|
capabilities?: Partial<CrmWriteCapabilities>;
|
|
11
|
+
/** The sign-in's own user, as `self()` answers it; absent, the fake names none and is copied whole. */
|
|
12
|
+
self?: string;
|
|
11
13
|
}
|
|
12
14
|
/** One write the fake CRM was sent, in order. */
|
|
13
15
|
export interface FakeCrmWrite {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** One reading of an email address everywhere a person is matched by one: a local part, an `@` and a dotted domain. */
|
|
2
|
+
export declare const EMAIL_ADDRESS: RegExp;
|
|
3
|
+
/** Whether a lower-cased, trimmed value is an email address. */
|
|
4
|
+
export declare const isEmailAddress: (value: string) => boolean;
|
|
5
|
+
/** Local parts that name a mailbox, not a person; the no-reply family names no one at all. */
|
|
6
|
+
export declare const ROLE_ADDRESS_WORDS: {
|
|
7
|
+
readonly noReply: readonly ["noreply", "no-reply", "donotreply", "do-not-reply", "mailer-daemon", "bounce", "bounces"];
|
|
8
|
+
readonly shared: readonly ["info", "hello", "hi", "contact", "contacts", "support", "help", "helpdesk", "service", "sales", "office", "admin", "team", "billing", "accounts", "accounting", "invoices", "finance", "hr", "jobs", "careers", "press", "media", "marketing", "partners", "legal", "privacy", "security", "abuse", "postmaster", "webmaster", "mail", "inbox", "enquiries", "inquiries", "booking", "reservations", "orders", "feedback", "newsletter", "notifications", "alerts"];
|
|
9
|
+
};
|
|
10
|
+
/** Whether the whole local part, `+tag` and `.`/`-`/`_` aside, is a role word: `info@`, `Hello+news@`, `no_reply@`. */
|
|
11
|
+
export declare const isRoleAddress: (address: string) => boolean;
|
|
12
|
+
/** Whether the address is a no-reply one, which belongs to no person. */
|
|
13
|
+
export declare const isNoReplyAddress: (address: string) => boolean;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** One reading of an email address everywhere a person is matched by one: a local part, an `@` and a dotted domain. */
|
|
2
|
+
export const EMAIL_ADDRESS = /^[^\s@]+@[^\s@]+\.[^\s@]+$/u;
|
|
3
|
+
/** Whether a lower-cased, trimmed value is an email address. */
|
|
4
|
+
export const isEmailAddress = (value) => EMAIL_ADDRESS.test(value);
|
|
5
|
+
/** Local parts that name a mailbox, not a person; the no-reply family names no one at all. */
|
|
6
|
+
export const ROLE_ADDRESS_WORDS = {
|
|
7
|
+
noReply: ["noreply", "no-reply", "donotreply", "do-not-reply", "mailer-daemon", "bounce", "bounces"],
|
|
8
|
+
shared: [
|
|
9
|
+
"info",
|
|
10
|
+
"hello",
|
|
11
|
+
"hi",
|
|
12
|
+
"contact",
|
|
13
|
+
"contacts",
|
|
14
|
+
"support",
|
|
15
|
+
"help",
|
|
16
|
+
"helpdesk",
|
|
17
|
+
"service",
|
|
18
|
+
"sales",
|
|
19
|
+
"office",
|
|
20
|
+
"admin",
|
|
21
|
+
"team",
|
|
22
|
+
"billing",
|
|
23
|
+
"accounts",
|
|
24
|
+
"accounting",
|
|
25
|
+
"invoices",
|
|
26
|
+
"finance",
|
|
27
|
+
"hr",
|
|
28
|
+
"jobs",
|
|
29
|
+
"careers",
|
|
30
|
+
"press",
|
|
31
|
+
"media",
|
|
32
|
+
"marketing",
|
|
33
|
+
"partners",
|
|
34
|
+
"legal",
|
|
35
|
+
"privacy",
|
|
36
|
+
"security",
|
|
37
|
+
"abuse",
|
|
38
|
+
"postmaster",
|
|
39
|
+
"webmaster",
|
|
40
|
+
"mail",
|
|
41
|
+
"inbox",
|
|
42
|
+
"enquiries",
|
|
43
|
+
"inquiries",
|
|
44
|
+
"booking",
|
|
45
|
+
"reservations",
|
|
46
|
+
"orders",
|
|
47
|
+
"feedback",
|
|
48
|
+
"newsletter",
|
|
49
|
+
"notifications",
|
|
50
|
+
"alerts",
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
const bare = (word) => word.replace(/[.\-_]/gu, "");
|
|
54
|
+
const NO_REPLY = new Set(ROLE_ADDRESS_WORDS.noReply.map(bare));
|
|
55
|
+
const ROLE = new Set([...ROLE_ADDRESS_WORDS.shared, ...ROLE_ADDRESS_WORDS.noReply].map(bare));
|
|
56
|
+
const localWord = (address) => {
|
|
57
|
+
const local = address.trim().toLowerCase().split("@")[0] ?? "";
|
|
58
|
+
return bare(local.split("+")[0] ?? "");
|
|
59
|
+
};
|
|
60
|
+
/** Whether the whole local part, `+tag` and `.`/`-`/`_` aside, is a role word: `info@`, `Hello+news@`, `no_reply@`. */
|
|
61
|
+
export const isRoleAddress = (address) => ROLE.has(localWord(address));
|
|
62
|
+
/** Whether the address is a no-reply one, which belongs to no person. */
|
|
63
|
+
export const isNoReplyAddress = (address) => NO_REPLY.has(localWord(address));
|
package/dist/domain/crm.d.ts
CHANGED
|
@@ -145,4 +145,27 @@ export interface CrmRecords {
|
|
|
145
145
|
person: CrmPerson;
|
|
146
146
|
organization: CrmOrganization;
|
|
147
147
|
}
|
|
148
|
+
/** The account's scope settings: `also` are the users whose deals the owner counts as nobody's. */
|
|
149
|
+
export type CrmScopeSetting = {
|
|
150
|
+
mode: "all";
|
|
151
|
+
} | {
|
|
152
|
+
mode: "mine";
|
|
153
|
+
also: readonly string[];
|
|
154
|
+
explicit: boolean;
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Which deals and leads a sync copies: all, or those with no assignee or assigned to the sign-in's own user (`self`)
|
|
158
|
+
* or to one of `also`. Contacts and companies are always copied whole. Ids are normalised (`normalCrmUserId`).
|
|
159
|
+
*/
|
|
160
|
+
export type CrmScope = {
|
|
161
|
+
mode: "all";
|
|
162
|
+
} | {
|
|
163
|
+
mode: "mine";
|
|
164
|
+
self: string;
|
|
165
|
+
also: readonly string[];
|
|
166
|
+
};
|
|
167
|
+
/** A CRM's user id as `unassigned` takes it: digits, as every CRM core syncs numbers its users. */
|
|
168
|
+
export declare const isCrmUserId: (id: string) => boolean;
|
|
169
|
+
/** One spelling per user id, so `015`, ` 15` and `15` are one user wherever they come from. */
|
|
170
|
+
export declare const normalCrmUserId: (id: string) => string;
|
|
148
171
|
export declare const isItemKind: (kind: CrmKind) => kind is DealKind;
|
package/dist/domain/crm.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
/** What a CRM holds that the store copies: its deals and leads, and the contacts and companies on them. */
|
|
2
2
|
export const CRM_KINDS = ["organization", "person", "deal", "lead"];
|
|
3
|
+
/** A CRM's user id as `unassigned` takes it: digits, as every CRM core syncs numbers its users. */
|
|
4
|
+
export const isCrmUserId = (id) => /^\d{1,20}$/.test(id);
|
|
5
|
+
/** One spelling per user id, so `015`, ` 15` and `15` are one user wherever they come from. */
|
|
6
|
+
export const normalCrmUserId = (id) => {
|
|
7
|
+
const text = id.trim();
|
|
8
|
+
return /^\d+$/.test(text) ? text.replace(/^0+(?=\d)/, "") : text;
|
|
9
|
+
};
|
|
3
10
|
export const isItemKind = (kind) => kind === "deal" || kind === "lead";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PhoneOptions } from "./phones.js";
|
|
1
2
|
export declare const MENTION_KINDS: readonly ["phone", "email", "url", "document", "person-name", "place"];
|
|
2
3
|
export type MentionKind = (typeof MENTION_KINDS)[number];
|
|
3
4
|
/** Who decides, and for a name whether every undecided place of it in the same chat follows. */
|
|
@@ -29,10 +30,7 @@ export interface FoundMention {
|
|
|
29
30
|
}
|
|
30
31
|
/** The site a host belongs to, from the public suffix list: `docs.google.com` → `google.com`. */
|
|
31
32
|
export declare const siteOf: (host: string) => string;
|
|
32
|
-
export
|
|
33
|
-
/** Where a number written without `+` is read, first match first: the store's `phone_countries`. */
|
|
34
|
-
phoneCountries?: readonly string[];
|
|
35
|
-
}
|
|
33
|
+
export { type PhoneOptions, typedPhone } from "./phones.js";
|
|
36
34
|
/** Every phone, e-mail address, link, Google document and address in the text, in the order they are written. */
|
|
37
35
|
export declare const findMentions: (text: string, { phoneCountries }?: PhoneOptions) => FoundMention[];
|
|
38
36
|
/**
|
|
@@ -47,11 +45,3 @@ export declare const oneTrackedLinkPerSite: <T extends {
|
|
|
47
45
|
export declare const trackedOrigin: (value: string) => string | undefined;
|
|
48
46
|
/** A value as a person types it, in the form mentions store: `8 900 000-00-01` → `+79000000001`. */
|
|
49
47
|
export declare const normalizedValue: (typed: string, options?: PhoneOptions) => string;
|
|
50
|
-
/**
|
|
51
|
-
* A number typed into a search, read as if a phone word stood before it, and the national number every stored
|
|
52
|
-
* spelling of it ends with — at least 8 digits, so a short tail does not match unrelated numbers.
|
|
53
|
-
*/
|
|
54
|
-
export declare const typedPhone: (typed: string, { phoneCountries }?: PhoneOptions) => {
|
|
55
|
-
value: string;
|
|
56
|
-
national: string | null;
|
|
57
|
-
} | undefined;
|
package/dist/domain/mentions.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { domainToUnicode } from "node:url";
|
|
3
3
|
import psl from "psl";
|
|
4
4
|
import { googleDocumentId, trimUrl } from "./google-documents.js";
|
|
5
|
-
import { DEFAULT_PHONE_COUNTRIES, nationalPhone } from "./phones.js";
|
|
5
|
+
import { DEFAULT_PHONE_COUNTRIES, nationalPhone, typedPhone } from "./phones.js";
|
|
6
6
|
import { findPlaces } from "./places.js";
|
|
7
7
|
export const MENTION_KINDS = ["phone", "email", "url", "document", "person-name", "place"];
|
|
8
8
|
/** Bumped when a kind's rule changes, so `mentions rebuild` can redo that kind alone. */
|
|
@@ -121,6 +121,7 @@ const DATE = /^\d{1,2}[./-]\d{1,2}[./-]\d{2,4}$|^\d{4}[./-]\d{1,2}[./-]\d{1,2}$/
|
|
|
121
121
|
const IP = /^\d{1,3}(?:\.\d{1,3}){3}$/;
|
|
122
122
|
const RUSSIAN_GROUPS = /\d{3}[ \u00a0\-–]\d{2}[ \u00a0\-–]\d{2}$/;
|
|
123
123
|
const SPANISH_GROUPS = /^[6-9]\d{2}[ \u00a0\-–]\d{3}[ \u00a0\-–]\d{3}$/;
|
|
124
|
+
export { typedPhone } from "./phones.js";
|
|
124
125
|
/**
|
|
125
126
|
* Looks like a phone, not a checked one: a wrong guess costs one `dismissed`, a miss a search that finds nothing.
|
|
126
127
|
* `+` or `00` makes it international. Without them the number is read in the store's countries: grouped or after
|
|
@@ -213,21 +214,3 @@ const exactlyOne = (text, options) => {
|
|
|
213
214
|
const [one] = findMentions(text, options);
|
|
214
215
|
return one && one.start === 0 && one.end === text.length ? one.value : undefined;
|
|
215
216
|
};
|
|
216
|
-
/**
|
|
217
|
-
* A number typed into a search, read as if a phone word stood before it, and the national number every stored
|
|
218
|
-
* spelling of it ends with — at least 8 digits, so a short tail does not match unrelated numbers.
|
|
219
|
-
*/
|
|
220
|
-
export const typedPhone = (typed, { phoneCountries = DEFAULT_PHONE_COUNTRIES } = {}) => {
|
|
221
|
-
const text = typed.trim();
|
|
222
|
-
if (!/^\+?[\d\s().\-–]+$/.test(text))
|
|
223
|
-
return undefined;
|
|
224
|
-
const digits = text.replace(/\(0\)/, "").replace(/\D/g, "").replace(/^00/, "");
|
|
225
|
-
if (digits.length < 7 || digits.length > 15)
|
|
226
|
-
return undefined;
|
|
227
|
-
const national = nationalPhone(digits, phoneCountries, { anyType: true });
|
|
228
|
-
const tail = national?.national ?? digits.replace(/^0+/, "");
|
|
229
|
-
return {
|
|
230
|
-
value: text.startsWith("+") || /^00/.test(text) ? `+${digits}` : (national?.value ?? digits),
|
|
231
|
-
national: tail.length >= 8 ? tail : null,
|
|
232
|
-
};
|
|
233
|
-
};
|
package/dist/domain/orders.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { OrderDirection } from "./business.js";
|
|
1
2
|
import type { FinanceReview } from "./finance.js";
|
|
2
3
|
export declare const ORDER_STATUSES: readonly ["placed", "shipped", "delivered", "cancelled", "returned"];
|
|
3
4
|
/** Why it was ordered: for the owner himself, for his business, for a client, or anything else. */
|
|
@@ -8,12 +9,18 @@ export interface OrderTitleFields {
|
|
|
8
9
|
id: number;
|
|
9
10
|
number: string | null;
|
|
10
11
|
supplierName: string;
|
|
12
|
+
direction: OrderDirection;
|
|
13
|
+
/** A sale's title names its customer; the supplier is then the owner. */
|
|
14
|
+
customerName: string | null;
|
|
11
15
|
total: number | null;
|
|
12
16
|
currency: string | null;
|
|
13
17
|
status: OrderStatus;
|
|
14
18
|
review: FinanceReview;
|
|
15
19
|
}
|
|
16
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* "12345 · Ozon, 2 499.00 RUB (shipped)", or for a sale "O-55 · to ООО Пример, …": a ref summary's title, which
|
|
22
|
+
* `refLabel` prefixes.
|
|
23
|
+
*/
|
|
17
24
|
export declare const orderLine: (order: OrderTitleFields) => string;
|
|
18
25
|
/** "Order 12345 · Ozon, 2 499.00 RUB (shipped)". */
|
|
19
26
|
export declare const orderTitle: (order: OrderTitleFields) => string;
|
package/dist/domain/orders.js
CHANGED
|
@@ -2,11 +2,15 @@ import { moneyLabel } from "./money.js";
|
|
|
2
2
|
export const ORDER_STATUSES = ["placed", "shipped", "delivered", "cancelled", "returned"];
|
|
3
3
|
/** Why it was ordered: for the owner himself, for his business, for a client, or anything else. */
|
|
4
4
|
export const ORDER_PURPOSES = ["personal", "business", "client", "other"];
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* "12345 · Ozon, 2 499.00 RUB (shipped)", or for a sale "O-55 · to ООО Пример, …": a ref summary's title, which
|
|
7
|
+
* `refLabel` prefixes.
|
|
8
|
+
*/
|
|
6
9
|
export const orderLine = (order) => {
|
|
10
|
+
const party = order.direction === "sale" && order.customerName !== null ? `to ${order.customerName}` : order.supplierName;
|
|
7
11
|
const money = order.total === null || order.currency === null ? "" : `, ${moneyLabel(order.total, order.currency)}`;
|
|
8
12
|
const notes = [order.status, order.review === "confirmed" ? null : order.review].filter(Boolean).join(", ");
|
|
9
|
-
return `${order.number ?? `#${order.id}`} · ${
|
|
13
|
+
return `${order.number ?? `#${order.id}`} · ${party}${money} (${notes})`;
|
|
10
14
|
};
|
|
11
15
|
/** "Order 12345 · Ozon, 2 499.00 RUB (shipped)". */
|
|
12
16
|
export const orderTitle = (order) => `Order ${orderLine(order)}`;
|
package/dist/domain/phones.d.ts
CHANGED
|
@@ -20,3 +20,29 @@ export interface NationalPhone {
|
|
|
20
20
|
export declare const nationalPhone: (digits: string, countries: readonly string[], { anyType }: {
|
|
21
21
|
anyType: boolean;
|
|
22
22
|
}) => NationalPhone | undefined;
|
|
23
|
+
export interface PhoneOptions {
|
|
24
|
+
/** Where a number written without `+` is read, first match first: the store's `phone_countries`. */
|
|
25
|
+
phoneCountries?: readonly string[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A number typed into a search, read as if a phone word stood before it, and the national number every stored
|
|
29
|
+
* spelling of it ends with — at least 8 digits, so a short tail does not match unrelated numbers.
|
|
30
|
+
*/
|
|
31
|
+
export declare const typedPhone: (typed: string, { phoneCountries }?: PhoneOptions) => {
|
|
32
|
+
value: string;
|
|
33
|
+
national: string | null;
|
|
34
|
+
} | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* A phone as a source typed it, as E.164: `null` for a number written without `+` or `00` when no region is given,
|
|
37
|
+
* nothing when it is no phone. Only the source says which country a national number is from: the store's
|
|
38
|
+
* `phone_countries` setting reads `4155550100` as Russian, so it never decides an identifier.
|
|
39
|
+
*/
|
|
40
|
+
export declare const e164Of: (phone: string, region: string | undefined) => string | null | undefined;
|
|
41
|
+
/** The messengers that keep a contact's number as bare international digits, the `+` left off. */
|
|
42
|
+
export declare const BARE_INTERNATIONAL_PROVIDERS: readonly string[];
|
|
43
|
+
/**
|
|
44
|
+
* The E.164 number a stored phone column stands for. A number written with `+` or `00` is read however it is spaced;
|
|
45
|
+
* a `phone` identity keeps it whole. Bare digits are international only from a messenger that stores them so; from a
|
|
46
|
+
* CRM or a card they are a national number, whose country nothing names, so they match nothing.
|
|
47
|
+
*/
|
|
48
|
+
export declare const storedPhone: (raw: string, provider: string) => string | undefined;
|
package/dist/domain/phones.js
CHANGED
|
@@ -50,3 +50,51 @@ export const nationalPhone = (digits, countries, { anyType }) => {
|
|
|
50
50
|
}
|
|
51
51
|
return undefined;
|
|
52
52
|
};
|
|
53
|
+
/**
|
|
54
|
+
* A number typed into a search, read as if a phone word stood before it, and the national number every stored
|
|
55
|
+
* spelling of it ends with — at least 8 digits, so a short tail does not match unrelated numbers.
|
|
56
|
+
*/
|
|
57
|
+
export const typedPhone = (typed, { phoneCountries = DEFAULT_PHONE_COUNTRIES } = {}) => {
|
|
58
|
+
const text = typed.trim();
|
|
59
|
+
if (!/^\+?[\d\s().\-–]+$/.test(text))
|
|
60
|
+
return undefined;
|
|
61
|
+
const digits = text.replace(/\(0\)/, "").replace(/\D/g, "").replace(/^00/, "");
|
|
62
|
+
if (digits.length < 7 || digits.length > 15)
|
|
63
|
+
return undefined;
|
|
64
|
+
const national = nationalPhone(digits, phoneCountries, { anyType: true });
|
|
65
|
+
const tail = national?.national ?? digits.replace(/^0+/, "");
|
|
66
|
+
return {
|
|
67
|
+
value: text.startsWith("+") || /^00/.test(text) ? `+${digits}` : (national?.value ?? digits),
|
|
68
|
+
national: tail.length >= 8 ? tail : null,
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* A phone as a source typed it, as E.164: `null` for a number written without `+` or `00` when no region is given,
|
|
73
|
+
* nothing when it is no phone. Only the source says which country a national number is from: the store's
|
|
74
|
+
* `phone_countries` setting reads `4155550100` as Russian, so it never decides an identifier.
|
|
75
|
+
*/
|
|
76
|
+
export const e164Of = (phone, region) => {
|
|
77
|
+
if (/^\s*(\+|00)/.test(phone))
|
|
78
|
+
return typedPhone(phone)?.value;
|
|
79
|
+
if (typedPhone(phone) === undefined)
|
|
80
|
+
return undefined;
|
|
81
|
+
if (region === undefined)
|
|
82
|
+
return null;
|
|
83
|
+
const digits = phone.replace(/\(0\)/, "").replace(/\D/g, "");
|
|
84
|
+
return nationalPhone(digits, [region], { anyType: true })?.value;
|
|
85
|
+
};
|
|
86
|
+
/** The messengers that keep a contact's number as bare international digits, the `+` left off. */
|
|
87
|
+
export const BARE_INTERNATIONAL_PROVIDERS = ["telegram", "max", "whatsapp"];
|
|
88
|
+
/**
|
|
89
|
+
* The E.164 number a stored phone column stands for. A number written with `+` or `00` is read however it is spaced;
|
|
90
|
+
* a `phone` identity keeps it whole. Bare digits are international only from a messenger that stores them so; from a
|
|
91
|
+
* CRM or a card they are a national number, whose country nothing names, so they match nothing.
|
|
92
|
+
*/
|
|
93
|
+
export const storedPhone = (raw, provider) => {
|
|
94
|
+
if (/^\s*(\+|00)/.test(raw))
|
|
95
|
+
return typedPhone(raw)?.value;
|
|
96
|
+
if (!BARE_INTERNATIONAL_PROVIDERS.includes(provider))
|
|
97
|
+
return undefined;
|
|
98
|
+
const found = /^([1-9]\d{6,14})$/.exec(raw.trim());
|
|
99
|
+
return found ? `+${found[1]}` : undefined;
|
|
100
|
+
};
|
|
@@ -10,7 +10,7 @@ export interface RecordRoleSpec {
|
|
|
10
10
|
amount?: boolean;
|
|
11
11
|
/** A business relationship between entities, by its kind: the relation may carry `as`, the part the target plays. */
|
|
12
12
|
relationship?: RelationKind;
|
|
13
|
-
/**
|
|
13
|
+
/** Never read to make the entity, so it never makes a record wait. */
|
|
14
14
|
kept?: boolean;
|
|
15
15
|
/**
|
|
16
16
|
* A role v1 already had: `fields.<role>` may name a store ref instead of a relation, and its target type is not
|
|
@@ -95,6 +95,7 @@ export const RECORD_TYPES = {
|
|
|
95
95
|
name: kept("The person's name"),
|
|
96
96
|
email: kept("E-mail addresses, one or a list: an exact one links the record to the one person who has it"),
|
|
97
97
|
phone: kept("Phone numbers, one or a list: an exact one, read to E.164, links like an e-mail"),
|
|
98
|
+
position: kept("The job title, kept beside each member-of as its position: never the role"),
|
|
98
99
|
}),
|
|
99
100
|
roles: { "member-of": { targets: ORGANIZATION, relationship: "member-of", kept: true } },
|
|
100
101
|
},
|
package/dist/domain/records.d.ts
CHANGED
|
@@ -53,6 +53,11 @@ export interface IngestError {
|
|
|
53
53
|
code: string;
|
|
54
54
|
message: string;
|
|
55
55
|
key?: string;
|
|
56
|
+
/** The record an entry is about when it is not in this envelope: one of an earlier batch. */
|
|
57
|
+
record?: {
|
|
58
|
+
type: string;
|
|
59
|
+
externalId: string;
|
|
60
|
+
};
|
|
56
61
|
}
|
|
57
62
|
/** The v1 envelope as JSON Schema (Draft 2020-12); `schemas/records-envelope.v1.schema.json` is this, written out. */
|
|
58
63
|
export declare const RECORDS_ENVELOPE_SCHEMA: {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Profiles } from "../search/account-list.js";
|
|
2
|
+
import type { AccountKey } from "../store/types.js";
|
|
1
3
|
import type { RefKindName } from "./references.js";
|
|
2
4
|
export type RefState = "available" | "deleted" | "unavailable";
|
|
3
5
|
/** A message or chat of the `email` provider is mail, so it reads as `email` and `email_thread`. */
|
|
@@ -27,6 +29,22 @@ export interface RefsStore {
|
|
|
27
29
|
summaries(refs: readonly string[], options?: {
|
|
28
30
|
excerpt?: boolean;
|
|
29
31
|
}): Promise<Map<string, RefSummary>>;
|
|
32
|
+
/**
|
|
33
|
+
* The accounts the referenced thing belongs to: `[]` when no account brought it (the owner made it), `undefined`
|
|
34
|
+
* when the store holds nothing for the reference or it is not one.
|
|
35
|
+
*/
|
|
36
|
+
accounts(ref: string): Promise<{
|
|
37
|
+
provider: string;
|
|
38
|
+
account: string;
|
|
39
|
+
}[] | undefined>;
|
|
40
|
+
/**
|
|
41
|
+
* Each part the thing belongs to, all of which a group must hold: a proposed action (`action:<id>`) is its own
|
|
42
|
+
* account and its target's; a suggested link (`link:<id>`) its two ends; anything else one part, as `accounts`.
|
|
43
|
+
*/
|
|
44
|
+
ends(ref: string): Promise<{
|
|
45
|
+
provider: string;
|
|
46
|
+
account: string;
|
|
47
|
+
}[][] | undefined>;
|
|
30
48
|
}
|
|
31
49
|
/** The caller's answer to "which profile opens this": one signed in, or the choices and why there is not one. */
|
|
32
50
|
export type ProfilesFor = (provider: string, account: string | null) => {
|
|
@@ -42,6 +60,27 @@ export interface RefOpen {
|
|
|
42
60
|
why: string | null;
|
|
43
61
|
}
|
|
44
62
|
export declare const PROFILE_PLACEHOLDER = "<profile>";
|
|
63
|
+
export declare const profilesOn: (profiles: Profiles, app: string, key: AccountKey) => string[];
|
|
64
|
+
/** From the store's record, so it answers for any CLI that registered its provider, not only the messengers. */
|
|
65
|
+
export declare const storedProfilesFor: (profiles: Profiles) => ProfilesFor;
|
|
66
|
+
/**
|
|
67
|
+
* Which CLI changes a CRM copy on its server, and as which profile; `profile` is `null` unless exactly one fits.
|
|
68
|
+
* `account` is the row's: the write refuses a row of any other account than its profile's live one.
|
|
69
|
+
*/
|
|
70
|
+
export interface WritesWith {
|
|
71
|
+
tool: string | null;
|
|
72
|
+
account: AccountKey;
|
|
73
|
+
profile: string | null;
|
|
74
|
+
profiles: string[];
|
|
75
|
+
why: string | null;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* `null` for the owner's own row: memo itself writes it. `allowed` is the caller's profile or group lock: a profile it
|
|
79
|
+
* forbids is never named, and the one profile it leaves is the answer.
|
|
80
|
+
*/
|
|
81
|
+
export declare const writesWithOf: (account: AccountKey | null, profilesFor: ProfilesFor, { allowed }?: {
|
|
82
|
+
allowed?: (tool: string, profile: string) => boolean;
|
|
83
|
+
}) => WritesWith | null;
|
|
45
84
|
/** A title from someone else's text, as one line: a newline in it would break every row it is printed in. */
|
|
46
85
|
export declare const oneLine: (text: string) => string;
|
|
47
86
|
/**
|