@wirecat/cli-core 1.0.0-rc.0 → 1.0.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 +97 -0
- package/THIRD_PARTY_NOTICES +4 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/cli/account-rename.js +1 -1
- package/dist/cli/bot/api-input.d.ts +5 -0
- package/dist/cli/bot/api-input.js +6 -1
- package/dist/cli/bot/api.js +7 -1
- package/dist/cli/documents/words.d.ts +1 -1
- package/dist/cli/service-api.js +3 -1
- package/dist/crm/manifest/map.d.ts +5 -2
- package/dist/crm/manifest/map.js +14 -2
- package/dist/domain/organization-sectors.d.ts +10 -0
- package/dist/domain/organization-sectors.generated.d.ts +11 -0
- package/dist/domain/organization-sectors.generated.js +14 -0
- package/dist/domain/organization-sectors.js +9 -0
- package/dist/domain/person-kinds.d.ts +1 -1
- package/dist/entities/index.d.ts +1 -0
- package/dist/entities/knowledge-lists.d.ts +1 -0
- package/dist/entities/knowledge-lists.js +2 -0
- package/dist/errors/reasons.js +12 -3
- package/dist/mail/score.d.ts +2 -0
- package/dist/mail/score.js +9 -2
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/search-all-rank.d.ts +44 -0
- package/dist/services/search-all-rank.js +112 -0
- package/dist/services/search-all-tracker.d.ts +58 -0
- package/dist/services/search-all-tracker.js +155 -0
- package/dist/services/search-all.d.ts +1 -8
- package/dist/services/search-all.js +18 -199
- package/dist/services/tracker-meaning.js +1 -1
- package/dist/store/areas.d.ts +1 -0
- package/dist/store/index.d.ts +1 -0
- package/dist/store/people.d.ts +22 -1
- package/dist/store/people.js +15 -1
- package/dist/store/sqlite/domain-organizations.d.ts +33 -0
- package/dist/store/sqlite/domain-organizations.js +230 -0
- package/dist/store/sqlite/knowledge.d.ts +2 -9
- package/dist/store/sqlite/manifest.js +2 -0
- package/dist/store/sqlite/migrations.generated.js +21 -0
- package/dist/store/sqlite/organizations.d.ts +12 -1
- package/dist/store/sqlite/organizations.js +9 -1
- package/dist/store/sqlite/people-list.d.ts +6 -1
- package/dist/store/sqlite/people-list.js +66 -14
- package/dist/store/sqlite/person-match-scan.js +11 -1
- package/dist/store/sqlite/schema/sender-bots.d.ts +288 -0
- package/dist/store/sqlite/schema/sender-bots.js +22 -0
- package/dist/store/sqlite/schema.d.ts +1 -0
- package/dist/store/sqlite/schema.js +2 -0
- package/dist/store/sqlite/sender-bots.d.ts +43 -0
- package/dist/store/sqlite/sender-bots.js +189 -0
- package/dist/store/sqlite/sender-signals.d.ts +5 -2
- package/dist/store/sqlite/sender-signals.js +6 -6
- package/dist/store/sqlite/tracker.d.ts +11 -9
- package/dist/store/sqlite/tracker.js +27 -12
- package/dist/store/sqlite/work-tasks.js +2 -0
- package/dist/tracker/cli/index.d.ts +1 -1
- package/dist/tracker/cli/index.js +83 -24
- package/dist/tracker/sync.js +43 -20
- package/dist/tracker/writes.d.ts +28 -0
- package/dist/tracker/writes.js +141 -19
- package/package.json +3 -3
|
@@ -4,16 +4,14 @@ import { crmViewerOf } from "../crm/index.js";
|
|
|
4
4
|
import { hitFiles } from "../domain/attachments.js";
|
|
5
5
|
import { parseLocator } from "../domain/locator.js";
|
|
6
6
|
import { senderIsMe } from "../domain/models.js";
|
|
7
|
-
import {
|
|
8
|
-
import { trackerBodyOf, trackerTitleOf } from "../domain/tracker.js";
|
|
7
|
+
import { holdsKind, INTERNAL_NOTES, isDocumentAccountProvider } from "../domain/providers.js";
|
|
9
8
|
import { runEmbedders } from "../embeddings/embed.js";
|
|
10
9
|
import { chosenTextModel } from "../embeddings/models.js";
|
|
11
10
|
import { formatMeetingReference } from "../meetings/index.js";
|
|
12
11
|
import { entriesOfList, fitting, listedHolds } from "../search/account-list.js";
|
|
13
12
|
import { RRF_K } from "../search/fusion.js";
|
|
14
|
-
import { meaningWords } from "../search/lucene/meaning-parts.js";
|
|
15
13
|
import { plainQuery } from "../search/lucene/plain.js";
|
|
16
|
-
import { MESSAGE_PARSING
|
|
14
|
+
import { MESSAGE_PARSING } from "../search/lucene/types.js";
|
|
17
15
|
import { questionPeriod } from "../search/question-period.js";
|
|
18
16
|
import { planQuestion, questionLookup, questionText } from "../search/question-plan.js";
|
|
19
17
|
import { nearestCrmActivities } from "./crm-meaning.js";
|
|
@@ -24,9 +22,11 @@ import { nearEligible } from "./messages-discovery.js";
|
|
|
24
22
|
import { importAccounts, notesScopeOf, searchNotes } from "./notes-search.js";
|
|
25
23
|
import { BUSINESS_WORDS_ONLY, searchBusiness } from "./search-all-business.js";
|
|
26
24
|
import { meetingLane } from "./search-all-meetings.js";
|
|
25
|
+
import { contentWords, fusedLane, insidePeriodFirst, meaningWordsOf, oneList, PERIOD_DEPTH, titleWords, } from "./search-all-rank.js";
|
|
26
|
+
import { trackerLane } from "./search-all-tracker.js";
|
|
27
27
|
import { HARDER_CANDIDATES, reorderHarder } from "./search-harder.js";
|
|
28
28
|
import { listContextOf } from "./search-kind.js";
|
|
29
|
-
|
|
29
|
+
export { titleWords } from "./search-all-rank.js";
|
|
30
30
|
export const RESOURCES_SEARCHED = [
|
|
31
31
|
"messages",
|
|
32
32
|
"mail",
|
|
@@ -61,24 +61,6 @@ const filtersBeside = (text) => {
|
|
|
61
61
|
? planQuestion(text).scope
|
|
62
62
|
: undefined;
|
|
63
63
|
};
|
|
64
|
-
/**
|
|
65
|
-
* What a deal or a lead is found by: plain words or phrases, all of them, or any with OR. Anything else is refused,
|
|
66
|
-
* so `search all` skips deals with the reason instead of matching a field they do not have.
|
|
67
|
-
*/
|
|
68
|
-
export const titleWords = (text, refused = "deals and leads are found by the words of their title, company, contacts and activities only") => {
|
|
69
|
-
const { root } = parseLucene(text, SEARCH_QUERY);
|
|
70
|
-
const clauses = root.kind === "boolean" ? root.clauses : [{ node: root, occur: "must" }];
|
|
71
|
-
const words = clauses.map(({ node, occur }) => occur !== "must_not" &&
|
|
72
|
-
node.kind === "predicate" &&
|
|
73
|
-
(node.field === "text" || node.field === "title") &&
|
|
74
|
-
(node.operator === "term" || node.operator === "phrase")
|
|
75
|
-
? // A title holds "invoice", not the question mark of "invoice?".
|
|
76
|
-
node.value.replace(/\?+$/u, "") || node.value
|
|
77
|
-
: (() => {
|
|
78
|
-
throw new CliError("validation_error", refused);
|
|
79
|
-
})());
|
|
80
|
-
return { words, anyWord: clauses.length > 1 && clauses.every(({ occur }) => occur === "should") };
|
|
81
|
-
};
|
|
82
64
|
/** The single words of an all-words query, when it has two to eight of them; none for OR, fields or phrases. */
|
|
83
65
|
const strictWords = (text) => {
|
|
84
66
|
try {
|
|
@@ -140,75 +122,8 @@ const copyViewers = async (store) => {
|
|
|
140
122
|
}
|
|
141
123
|
return viewers;
|
|
142
124
|
};
|
|
143
|
-
const TRACKER_HIT_KINDS = { issue: "issue", project: "project", comment: "issue_comment" };
|
|
144
125
|
/** The accounts of every tracker the store holds copies of. */
|
|
145
126
|
export const trackerAccounts = async (store) => (await store.accounts.accounts()).filter(({ provider }) => holdsKind(provider, "tracker"));
|
|
146
|
-
/** An issue is titled as people say it, `ENG-12 Fix login`; anything else by its name or its first line. */
|
|
147
|
-
const trackerTitle = ({ kind, record }) => {
|
|
148
|
-
const title = trackerTitleOf(kind, record);
|
|
149
|
-
const key = kind === "issue" ? record.key : undefined;
|
|
150
|
-
return key ? `${key} ${title}` : title;
|
|
151
|
-
};
|
|
152
|
-
/**
|
|
153
|
-
* What the meaning half embeds: the words and phrases asked for, OR included, as notes take them. `title:` narrows to
|
|
154
|
-
* the title, which a hit by meaning cannot be held to, so such a query is searched by words only.
|
|
155
|
-
*/
|
|
156
|
-
const meaningWordsOf = (text) => {
|
|
157
|
-
try {
|
|
158
|
-
const { root } = parseLucene(text, SEARCH_QUERY);
|
|
159
|
-
const nodes = root.kind === "boolean" ? root.clauses.map(({ node }) => node) : [root];
|
|
160
|
-
if (!nodes.every((node) => node.kind === "predicate" && node.field === "text"))
|
|
161
|
-
return undefined;
|
|
162
|
-
return meaningWords(root) || undefined;
|
|
163
|
-
}
|
|
164
|
-
catch {
|
|
165
|
-
return undefined;
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
const trackerExcerpt = ({ kind, record }, query) => excerpt([trackerTitleOf(kind, record), trackerBodyOf(kind, record)].filter(Boolean).join("\n"), query);
|
|
169
|
-
/**
|
|
170
|
-
* One hit per tracker item, best first: the copies other sign-ins hold of one item (`items` maps a hit's ref to the
|
|
171
|
-
* item, for a provider whose ids name one item across its accounts) join the best-placed one, which names every account and takes the best cosine and every way any was found.
|
|
172
|
-
*/
|
|
173
|
-
const oneHitPerItem = (ordered, cosines, items) => {
|
|
174
|
-
const kept = new Map();
|
|
175
|
-
for (const hit of ordered) {
|
|
176
|
-
const key = items.get(hit.ref) ?? hit.ref;
|
|
177
|
-
const held = kept.get(key);
|
|
178
|
-
if (!held) {
|
|
179
|
-
kept.set(key, hit);
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
held.accounts = [...(held.accounts ?? [held.account]), hit.account];
|
|
183
|
-
held.foundBy = ["words", "meaning"].filter((by) => [held, hit].some(({ foundBy }) => foundBy.includes(by)));
|
|
184
|
-
const cosine = cosines.get(hit.ref);
|
|
185
|
-
if (cosine !== undefined && cosine > (cosines.get(held.ref) ?? Number.NEGATIVE_INFINITY))
|
|
186
|
-
cosines.set(held.ref, cosine);
|
|
187
|
-
}
|
|
188
|
-
return [...kept.values()];
|
|
189
|
-
};
|
|
190
|
-
/**
|
|
191
|
-
* One list for a lane found both ways, as notes and messages fuse theirs: each hit's rank in either list votes, a
|
|
192
|
-
* question's hit voting once; a hit found both ways keeps its words' text and is found by meaning too.
|
|
193
|
-
*/
|
|
194
|
-
const fusedLane = (byWords, byMeaning, discover, cosines) => {
|
|
195
|
-
const fused = new Map();
|
|
196
|
-
byWords.forEach((item, rank) => {
|
|
197
|
-
fused.set(item.ref, { item, score: 1 / (RRF_K + rank + 1) });
|
|
198
|
-
});
|
|
199
|
-
byMeaning.forEach(({ hit, score }, rank) => {
|
|
200
|
-
cosines.set(hit.ref, score);
|
|
201
|
-
const held = fused.get(hit.ref);
|
|
202
|
-
if (held && !held.item.foundBy.includes("meaning"))
|
|
203
|
-
held.item.foundBy = [...held.item.foundBy, "meaning"];
|
|
204
|
-
const vote = 1 / (RRF_K + rank + 1);
|
|
205
|
-
if (held && discover)
|
|
206
|
-
held.score = Math.max(held.score, vote);
|
|
207
|
-
else
|
|
208
|
-
fused.set(hit.ref, { item: held?.item ?? hit, score: (held?.score ?? 0) + vote });
|
|
209
|
-
});
|
|
210
|
-
return [...fused.values()].sort((a, b) => b.score - a.score).map(({ item }) => item);
|
|
211
|
-
};
|
|
212
127
|
/** The accounts of every CRM the store holds copies of. */
|
|
213
128
|
export const crmAccounts = async (store) => (await store.accounts.accounts()).filter(({ provider }) => holdsKind(provider, "crm"));
|
|
214
129
|
/**
|
|
@@ -429,7 +344,7 @@ export const searchAll = async (store, account, asked, messenger = {}, searchMes
|
|
|
429
344
|
accounts.push(...read.map(({ provider, account }) => ({ resource, provider, account })));
|
|
430
345
|
}
|
|
431
346
|
else if (resource === "crm") {
|
|
432
|
-
const { words, anyWord } = titleWords(request.text);
|
|
347
|
+
const { words, anyWord } = contentWords(titleWords(request.text), discover);
|
|
433
348
|
const chosen = scope?.crm;
|
|
434
349
|
// memo's, tg's and the MCP's search all pass no viewers: each copy's own rule decides, as a CRM CLI's does.
|
|
435
350
|
const viewers = request.crmViewers ?? (await copyViewers(store));
|
|
@@ -540,78 +455,25 @@ export const searchAll = async (store, account, asked, messenger = {}, searchMes
|
|
|
540
455
|
const read = scope?.tracker ?? (await trackerAccounts(store));
|
|
541
456
|
if (!read.length)
|
|
542
457
|
continue;
|
|
543
|
-
const
|
|
544
|
-
|
|
545
|
-
// that the folded list still fills the page.
|
|
546
|
-
const deep = Math.min(depth * read.length, 500);
|
|
547
|
-
const found = await store.tracker.find({
|
|
548
|
-
words,
|
|
549
|
-
anyWord: anyWord || discover,
|
|
550
|
-
...(request.exact ? { exact: true } : {}),
|
|
551
|
-
kinds: ["issue", "project", "comment"],
|
|
552
|
-
limit: deep,
|
|
458
|
+
const found = await trackerLane(store, {
|
|
459
|
+
text: request.text,
|
|
553
460
|
accounts: read,
|
|
461
|
+
depth,
|
|
462
|
+
discover,
|
|
463
|
+
cosines,
|
|
464
|
+
embedders,
|
|
465
|
+
...(request.exact ? { exact: true } : {}),
|
|
466
|
+
...(command === undefined ? {} : { command }),
|
|
467
|
+
...(request.env === undefined ? {} : { env: request.env }),
|
|
554
468
|
});
|
|
555
469
|
hasMore ||= found.hasMore;
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
const ref = `tracker:${at.provider}/${at.account}/${item.kind}/${item.record.externalId}`;
|
|
559
|
-
if (hasGlobalItemIds(at.provider))
|
|
560
|
-
items.set(ref, JSON.stringify([at.provider, item.kind, item.record.externalId]));
|
|
561
|
-
return {
|
|
562
|
-
kind: TRACKER_HIT_KINDS[item.kind],
|
|
563
|
-
// Two sign-ins see the same issue under the same id, so the account keeps their hits apart.
|
|
564
|
-
ref,
|
|
565
|
-
provider: at.provider,
|
|
566
|
-
account: at.account,
|
|
567
|
-
...(item.record.url ? { url: item.record.url } : {}),
|
|
568
|
-
title: trackerTitle(item),
|
|
569
|
-
timestamp: new Date(item.record.updatedAt ?? item.syncedAt).toISOString(),
|
|
570
|
-
text,
|
|
571
|
-
foundBy,
|
|
572
|
-
};
|
|
573
|
-
};
|
|
574
|
-
const byWords = found.items.map(({ account: at, item, excerpt: text }) => hitOf(at, item, text, ["words"]));
|
|
575
|
-
const plain = meaningWordsOf(discover ? questionText(request.text) : request.text);
|
|
576
|
-
let near;
|
|
577
|
-
let meaningSkipped;
|
|
578
|
-
if (request.exact)
|
|
579
|
-
meaningSkipped = "--exact searches words as written";
|
|
580
|
-
else if (plain === undefined)
|
|
581
|
-
meaningSkipped = "the query names a title, which meaning cannot follow";
|
|
582
|
-
else
|
|
583
|
-
try {
|
|
584
|
-
near = await nearestTracker(store, plain, {
|
|
585
|
-
limit: deep,
|
|
586
|
-
accounts: read,
|
|
587
|
-
embedders,
|
|
588
|
-
...(command === undefined ? {} : { command }),
|
|
589
|
-
...(request.env === undefined ? {} : { env: request.env }),
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
catch (error) {
|
|
593
|
-
if (!(error instanceof CliError && error.code === "not_found"))
|
|
594
|
-
throw error;
|
|
595
|
-
meaningSkipped = error.message;
|
|
596
|
-
}
|
|
597
|
-
tracker = {
|
|
598
|
-
by: near === undefined ? "words" : "words and meaning",
|
|
599
|
-
...(meaningSkipped === undefined ? {} : { meaningSkipped }),
|
|
600
|
-
};
|
|
601
|
-
if (near === undefined)
|
|
602
|
-
lists.push(oneHitPerItem(byWords, cosines, items));
|
|
603
|
-
else {
|
|
604
|
-
const byMeaning = near.map(({ account: at, item, score }) => ({
|
|
605
|
-
hit: hitOf(at, item, trackerExcerpt(item, request.text), ["meaning"]),
|
|
606
|
-
score,
|
|
607
|
-
}));
|
|
608
|
-
lists.push(oneHitPerItem(fusedLane(byWords, byMeaning, discover, cosines), cosines, items));
|
|
609
|
-
}
|
|
470
|
+
tracker = found.tracker;
|
|
471
|
+
lists.push(found.hits);
|
|
610
472
|
for (const { provider, account } of read)
|
|
611
473
|
accounts.push({ resource, provider, account });
|
|
612
474
|
}
|
|
613
475
|
else if (resource === "business") {
|
|
614
|
-
const { words, anyWord } = titleWords(request.text, BUSINESS_WORDS_ONLY);
|
|
476
|
+
const { words, anyWord } = contentWords(titleWords(request.text, BUSINESS_WORDS_ONLY), discover);
|
|
615
477
|
const found = await searchBusiness(store, {
|
|
616
478
|
words,
|
|
617
479
|
anyWord: anyWord || discover,
|
|
@@ -740,46 +602,3 @@ const withMeetingDocuments = async (store, lists, read) => {
|
|
|
740
602
|
];
|
|
741
603
|
}));
|
|
742
604
|
};
|
|
743
|
-
/** Passages of one meeting share its `ref`, the reference evidence cites; each is still a hit of its own. */
|
|
744
|
-
const hitKey = (item) => item.kind === "meeting" ? `${item.ref}\u0000${item.scope}\u0000${item.id}` : item.ref;
|
|
745
|
-
/**
|
|
746
|
-
* Every source's hits as one list: each source's best hit first, then every other hit by cosine, then by its rank in
|
|
747
|
-
* its source. Taking turns by rank (MEMO-37) gave each of two sources half of a ten-hit page however weak its hits;
|
|
748
|
-
* one model scores every source, so cosine compares across them. A hit only words found takes the cosine of
|
|
749
|
-
* the hit above it in its source: its source ranked it there, and with none it would follow every hit meaning found.
|
|
750
|
-
*/
|
|
751
|
-
const oneList = (lists, cosines) => {
|
|
752
|
-
const place = new Map();
|
|
753
|
-
for (const list of lists) {
|
|
754
|
-
let above = Number.NEGATIVE_INFINITY;
|
|
755
|
-
list.forEach((item, rank) => {
|
|
756
|
-
const key = hitKey(item);
|
|
757
|
-
above = cosines.get(item.ref) ?? above;
|
|
758
|
-
const held = place.get(key);
|
|
759
|
-
if (!held || rank < held.rank)
|
|
760
|
-
place.set(key, { item, rank, cosine: above });
|
|
761
|
-
});
|
|
762
|
-
}
|
|
763
|
-
const head = (rank) => Math.min(rank, 1);
|
|
764
|
-
return [...place.values()]
|
|
765
|
-
.sort((a, b) => head(a.rank) - head(b.rank) || b.cosine - a.cosine || a.rank - b.rank)
|
|
766
|
-
.map(({ item }) => item);
|
|
767
|
-
};
|
|
768
|
-
const PERIOD_DEPTH = 100;
|
|
769
|
-
const PERIOD_BOOST = 0.5;
|
|
770
|
-
/**
|
|
771
|
-
* A hit dated inside the question's period gains 0.5 over its place, 1 - rank/100: by rank, because only some hits have
|
|
772
|
-
* a cosine to compare. One scale for every page, so paging past the first 100 never reorders what came before.
|
|
773
|
-
*/
|
|
774
|
-
const insidePeriodFirst = (ordered, period) => {
|
|
775
|
-
if (!period)
|
|
776
|
-
return ordered;
|
|
777
|
-
const inside = ({ timestamp }) => {
|
|
778
|
-
const at = timestamp === null ? Number.NaN : Date.parse(timestamp);
|
|
779
|
-
return at >= period.from && at < period.to;
|
|
780
|
-
};
|
|
781
|
-
return ordered
|
|
782
|
-
.map((item, rank) => ({ item, score: 1 - rank / PERIOD_DEPTH + (inside(item) ? PERIOD_BOOST : 0) }))
|
|
783
|
-
.sort((a, b) => b.score - a.score)
|
|
784
|
-
.map(({ item }) => item);
|
|
785
|
-
};
|
|
@@ -20,7 +20,7 @@ export const embedTracker = async (store, options = {}) => {
|
|
|
20
20
|
export const nearestTracker = async (store, words, { limit, accounts, env, command, embedders, }) => {
|
|
21
21
|
const { model, directory, key } = localModel(await meaningModel(store, env), env, command);
|
|
22
22
|
if (!(await store.tracker.embedded(key, accounts)))
|
|
23
|
-
throw new CliError("not_found", `no issue, project or comment has vectors of ${model.id} yet, so only words were matched
|
|
23
|
+
throw new CliError("not_found", `no issue, project or comment has vectors of ${model.id} yet, so only words were matched`, { reason: "tracker.no-vectors", model: model.id });
|
|
24
24
|
const [vector] = await withLocal(model, directory, undefined, (embedder) => embedder.embed([words], "query"), embedders);
|
|
25
25
|
const floor = meaningFloor(key);
|
|
26
26
|
return (await store.tracker.nearest(key, vector, { limit, accounts })).filter(({ score }) => score > floor);
|
package/dist/store/areas.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export type { ProductFilter } from "./sqlite/products.js";
|
|
|
30
30
|
export { PROPOSAL_STATUSES, type ProposedAction } from "./sqlite/proposed-actions.js";
|
|
31
31
|
export type { MatchRun, RecordKey } from "./sqlite/records.js";
|
|
32
32
|
export type { RelationListItem } from "./sqlite/relation-list.js";
|
|
33
|
+
export type { SenderBot } from "./sqlite/sender-bots.js";
|
|
33
34
|
export type { SubscriptionFilter } from "./sqlite/subscriptions.js";
|
|
34
35
|
export { PROJECT_TASK_FIELDS, TASK_SORTS, type TaskSort } from "./sqlite/task-board.js";
|
|
35
36
|
export { TASK_RELATION_KINDS, type TaskRelationKind } from "./sqlite/task-relations.js";
|
package/dist/store/index.d.ts
CHANGED
|
@@ -104,6 +104,7 @@ export type { RelationRole, RelationRoles } from "./sqlite/relation-roles.js";
|
|
|
104
104
|
export type { RelationsStore, ReportedIssue, ReportedRelation, ReportedScope, ReportedSync, } from "./sqlite/reported-relations.js";
|
|
105
105
|
export type { AuthorInfo, Party, Reviewed, Written } from "./sqlite/reviewed.js";
|
|
106
106
|
export { fillSearchIndex, resetSearchIndex, type SearchIndexFill, type SearchIndexState, searchIndexState, } from "./sqlite/search-index.js";
|
|
107
|
+
export type { SenderBot } from "./sqlite/sender-bots.js";
|
|
107
108
|
export { REACHES, type Reach, type SenderSignal } from "./sqlite/sender-signals.js";
|
|
108
109
|
export type { ChallengeInput, SourceReviewDecision } from "./sqlite/source-review.js";
|
|
109
110
|
export type { PriceFilter, PriceInput, Subscription, SubscriptionDetail, SubscriptionFields, SubscriptionFilter, SubscriptionInput, SubscriptionPrice, SubscriptionsStore, SubscriptionUpdate, } from "./sqlite/subscriptions.js";
|
package/dist/store/people.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { type PersonPreparationRead } from "./sqlite/person-preparation.js";
|
|
|
15
15
|
import { type ShownBecause } from "./sqlite/person-ties.js";
|
|
16
16
|
import type { PrivateContact, PrivateContactNote } from "./sqlite/private-people.js";
|
|
17
17
|
import type { ProposedAction } from "./sqlite/proposed-actions.js";
|
|
18
|
+
import { type SenderBot } from "./sqlite/sender-bots.js";
|
|
18
19
|
import type { AccountKey, IdentityRef, LinkOptions, PersonFacts, PersonRecord, StoredAccount, UnlinkOptions } from "./types.js";
|
|
19
20
|
/** @experimental */
|
|
20
21
|
export interface AccountPeople {
|
|
@@ -206,8 +207,28 @@ export interface PeopleStore extends AccountPeople {
|
|
|
206
207
|
similar(name: string, options?: {
|
|
207
208
|
limit?: number;
|
|
208
209
|
}): Promise<SimilarPerson[]>;
|
|
209
|
-
/** Why each `person:<uid>` is shown by default, as `list` gives it; an empty list for one with no tie. */
|
|
210
|
+
/** Why each `person:<uid>` is shown by default, as `list` gives it; an empty list for one with no tie, or a bot. */
|
|
210
211
|
ties(people: readonly string[]): Promise<Record<string, ShownBecause[]>>;
|
|
212
|
+
/**
|
|
213
|
+
* The owner says a sender is a program: a person (`person:<uid>`) or one identity moves to a sender bot for its
|
|
214
|
+
* whole history, listed as `automated` under its person row's ref, and no rule moves it back. One identity of a person
|
|
215
|
+
* with others gets a person row of its own; `bot` (`sender-bot:<id>`) joins a stored bot instead. The owner's alone;
|
|
216
|
+
* refused for the owner's own person.
|
|
217
|
+
*/
|
|
218
|
+
moveToBot(subject: string | IdentityRef, by: Decider, options?: {
|
|
219
|
+
bot?: string;
|
|
220
|
+
name?: string;
|
|
221
|
+
reason?: string;
|
|
222
|
+
}): Promise<SenderBot>;
|
|
223
|
+
/**
|
|
224
|
+
* The owner says a sender is a person: a bot (`sender-bot:<id>` or its `person:<uid>`), or one identity of it, moves
|
|
225
|
+
* to a person for its whole history, and no rule makes it a bot again. Said of a person who is no bot, it keeps them
|
|
226
|
+
* a person. `person` joins that person instead. The owner's alone.
|
|
227
|
+
*/
|
|
228
|
+
moveToPerson(subject: string | IdentityRef, by: Decider, options?: {
|
|
229
|
+
person?: string;
|
|
230
|
+
reason?: string;
|
|
231
|
+
}): Promise<PersonRecord>;
|
|
211
232
|
}
|
|
212
233
|
export declare const accountPeopleOver: (context: StoreContext) => AccountPeople;
|
|
213
234
|
export declare const peopleStoreOver: (context: StoreContext, keyed: AccountPeople) => PeopleStore;
|
package/dist/store/people.js
CHANGED
|
@@ -13,10 +13,12 @@ import { erasePerson } from "./sqlite/person-erase.js";
|
|
|
13
13
|
import * as personLinks from "./sqlite/person-links.js";
|
|
14
14
|
import { linkPhones, PROPOSAL_SCORE, RULE, scanMatches } from "./sqlite/person-match-scan.js";
|
|
15
15
|
import * as personMerges from "./sqlite/person-merges.js";
|
|
16
|
+
import { ownerOnly } from "./sqlite/person-merges.js";
|
|
16
17
|
import { personPreparation } from "./sqlite/person-preparation.js";
|
|
17
18
|
import { personSeenInAccounts } from "./sqlite/person-scope.js";
|
|
18
19
|
import { shownReasons } from "./sqlite/person-ties.js";
|
|
19
20
|
import * as privatePeople from "./sqlite/private-people.js";
|
|
21
|
+
import { moveToBot, moveToPerson, senderBotsOf } from "./sqlite/sender-bots.js";
|
|
20
22
|
import { write } from "./sqlite/transaction.js";
|
|
21
23
|
export const accountPeopleOver = (context) => {
|
|
22
24
|
const { database } = context;
|
|
@@ -163,7 +165,19 @@ export const peopleStoreOver = (context, keyed) => {
|
|
|
163
165
|
similar: async (name, { limit = 8 } = {}) => similarPeople(database, name, limit),
|
|
164
166
|
ties: async (people) => {
|
|
165
167
|
const reasons = shownReasons(database);
|
|
166
|
-
|
|
168
|
+
const bots = senderBotsOf(database);
|
|
169
|
+
return Object.fromEntries(people.map((ref) => {
|
|
170
|
+
const id = Number(ref.replace(/^person:/, ""));
|
|
171
|
+
return [ref, bots.has(id) ? [] : (reasons.get(id) ?? [])];
|
|
172
|
+
}));
|
|
173
|
+
},
|
|
174
|
+
moveToBot: async (subject, by, options) => {
|
|
175
|
+
ownerOnly(by, "moves a sender to a bot");
|
|
176
|
+
return moveToBot(context, subject, options);
|
|
177
|
+
},
|
|
178
|
+
moveToPerson: async (subject, by, options) => {
|
|
179
|
+
ownerOnly(by, "moves a sender to a person");
|
|
180
|
+
return moveToPerson(context, subject, options);
|
|
167
181
|
},
|
|
168
182
|
};
|
|
169
183
|
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { CacheDatabase } from "../driver.js";
|
|
2
|
+
/**
|
|
3
|
+
* Newsletter hosts and mail services that send for many customers. Their domain names none of the senders, so it never
|
|
4
|
+
* makes an organization; the bounce and signing domains are here for mail whose `From` carries them.
|
|
5
|
+
*/
|
|
6
|
+
export declare const SENDING_PLATFORMS: ReadonlySet<string>;
|
|
7
|
+
/** How a rule's hold on an address is marked in `organization_identities.method`. */
|
|
8
|
+
export declare const BY_DOMAIN = "domain";
|
|
9
|
+
/** A rejected `proposed_actions` row of this kind keeps a rule from making an organization for its domain again. */
|
|
10
|
+
export declare const REFUSED_DOMAIN = "organization-domain";
|
|
11
|
+
/** The registrable domain whose organization an address joins; none for free, throwaway and platform mail. */
|
|
12
|
+
export declare const companyDomainOf: (address: string) => string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* A person as the kind pass leaves them: `holds` for a bot or a shared mailbox, whose addresses the organization owns;
|
|
15
|
+
* never for one the owner kept as a person.
|
|
16
|
+
*/
|
|
17
|
+
export interface Sorted {
|
|
18
|
+
id: number;
|
|
19
|
+
displayName: string | null;
|
|
20
|
+
holds: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Plan step 5: a bot or a shared mailbox at a company domain joins that domain's organization, made when none holds
|
|
24
|
+
* it; a human there becomes a `member-of` it, never merged. Free mail, throwaway mail and sending platforms make none.
|
|
25
|
+
* An organization holding a domain of the built-in Wikidata list gets its `metadata.sector`.
|
|
26
|
+
* The owner's word holds: a membership the owner removed and a domain whose organization the owner erased are not made
|
|
27
|
+
* again. The caller holds the write lock.
|
|
28
|
+
*/
|
|
29
|
+
export declare const groupByDomain: (database: CacheDatabase, people: readonly Sorted[], at: number) => void;
|
|
30
|
+
/** The owner erased an organization: no rule makes one for the company domains it held again. */
|
|
31
|
+
export declare const refuseDomainsOf: (database: CacheDatabase, organization: number, at: number) => void;
|
|
32
|
+
/** The owner moved these identities to a person: the holds a rule gave them go, so they read as a person's again. */
|
|
33
|
+
export declare const releaseDomainHolds: (database: CacheDatabase, identities: readonly number[]) => void;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { getDomainWithoutSuffix } from "tldts";
|
|
2
|
+
import { isReadable } from "../../domain/display-names.js";
|
|
3
|
+
import { SECTORS, sectorOfDomain } from "../../domain/organization-sectors.js";
|
|
4
|
+
import { isCompanyName } from "../../domain/person-kinds.js";
|
|
5
|
+
import { FREE_MAIL, isDisposableDomain, registrableOf } from "../../mail/score.js";
|
|
6
|
+
import { fold } from "../normalize.js";
|
|
7
|
+
import { actorOfOrigin } from "./actors.js";
|
|
8
|
+
import { linkKind } from "./link-kinds.js";
|
|
9
|
+
/**
|
|
10
|
+
* Newsletter hosts and mail services that send for many customers. Their domain names none of the senders, so it never
|
|
11
|
+
* makes an organization; the bounce and signing domains are here for mail whose `From` carries them.
|
|
12
|
+
*/
|
|
13
|
+
export const SENDING_PLATFORMS = new Set([
|
|
14
|
+
"substack.com",
|
|
15
|
+
"beehiiv.com",
|
|
16
|
+
"ghost.io",
|
|
17
|
+
"buttondown.email",
|
|
18
|
+
"buttondown.com",
|
|
19
|
+
"mailchimpapp.net",
|
|
20
|
+
"mcsv.net",
|
|
21
|
+
"mcdlv.net",
|
|
22
|
+
"rsgsv.net",
|
|
23
|
+
"list-manage.com",
|
|
24
|
+
"mandrillapp.com",
|
|
25
|
+
"sendgrid.net",
|
|
26
|
+
"amazonses.com",
|
|
27
|
+
"mailgun.org",
|
|
28
|
+
"mailgun.net",
|
|
29
|
+
"postmarkapp.com",
|
|
30
|
+
"mtasv.net",
|
|
31
|
+
"sparkpostmail.com",
|
|
32
|
+
"convertkit-mail.com",
|
|
33
|
+
"mlsend.com",
|
|
34
|
+
"sendinblue.com",
|
|
35
|
+
"brevosend.com",
|
|
36
|
+
]);
|
|
37
|
+
/** How a rule's hold on an address is marked in `organization_identities.method`. */
|
|
38
|
+
export const BY_DOMAIN = "domain";
|
|
39
|
+
/** A rejected `proposed_actions` row of this kind keeps a rule from making an organization for its domain again. */
|
|
40
|
+
export const REFUSED_DOMAIN = "organization-domain";
|
|
41
|
+
/** The registrable domain whose organization an address joins; none for free, throwaway and platform mail. */
|
|
42
|
+
export const companyDomainOf = (address) => {
|
|
43
|
+
if (!address.includes("@"))
|
|
44
|
+
return undefined;
|
|
45
|
+
const domain = registrableOf(address);
|
|
46
|
+
return domain.includes(".") && !FREE_MAIL.has(domain) && !SENDING_PLATFORMS.has(domain) && !isDisposableDomain(domain)
|
|
47
|
+
? domain
|
|
48
|
+
: undefined;
|
|
49
|
+
};
|
|
50
|
+
const nameFor = (shown, domain) => {
|
|
51
|
+
const label = getDomainWithoutSuffix(domain);
|
|
52
|
+
return shown !== null &&
|
|
53
|
+
isReadable(shown) &&
|
|
54
|
+
(isCompanyName(shown) || (label !== null && fold(shown).trim() === fold(label)))
|
|
55
|
+
? shown.trim()
|
|
56
|
+
: domain;
|
|
57
|
+
};
|
|
58
|
+
const mailOf = (database, people) => {
|
|
59
|
+
const found = new Map();
|
|
60
|
+
for (const row of database
|
|
61
|
+
.prepare("SELECT l.person_id AS person, i.id, lower(i.external_id) AS address FROM identity_links l " +
|
|
62
|
+
"JOIN identities i ON i.id = l.identity_id WHERE i.provider = 'email' " +
|
|
63
|
+
"AND l.person_id IN (SELECT value FROM json_each(?)) ORDER BY i.id")
|
|
64
|
+
.all(JSON.stringify(people))) {
|
|
65
|
+
const domain = companyDomainOf(String(row.address));
|
|
66
|
+
if (domain === undefined)
|
|
67
|
+
continue;
|
|
68
|
+
const person = Number(row.person);
|
|
69
|
+
found.set(person, [...(found.get(person) ?? []), { identity: Number(row.id), domain }]);
|
|
70
|
+
}
|
|
71
|
+
return found;
|
|
72
|
+
};
|
|
73
|
+
/** Every organization by the company domains of the addresses it holds, and which identities are held at all. */
|
|
74
|
+
const holdersOf = (database) => {
|
|
75
|
+
const byDomain = new Map();
|
|
76
|
+
const held = new Map();
|
|
77
|
+
for (const row of database
|
|
78
|
+
.prepare("SELECT oi.identity_id, oi.organization_id, lower(i.external_id) AS address FROM organization_identities oi " +
|
|
79
|
+
"JOIN organizations o ON o.id = oi.organization_id JOIN identities i ON i.id = oi.identity_id " +
|
|
80
|
+
"WHERE o.deleted_at IS NULL AND i.provider = 'email' ORDER BY oi.id")
|
|
81
|
+
.all()) {
|
|
82
|
+
const organization = Number(row.organization_id);
|
|
83
|
+
if (!held.has(Number(row.identity_id)))
|
|
84
|
+
held.set(Number(row.identity_id), organization);
|
|
85
|
+
const domain = companyDomainOf(String(row.address));
|
|
86
|
+
if (domain !== undefined)
|
|
87
|
+
byDomain.set(domain, (byDomain.get(domain) ?? new Set()).add(organization));
|
|
88
|
+
}
|
|
89
|
+
return { byDomain, held };
|
|
90
|
+
};
|
|
91
|
+
const refusedDomains = (database) => new Set(database
|
|
92
|
+
.prepare("SELECT json_extract(payload, '$.domain') AS domain FROM proposed_actions WHERE kind = ? AND status = 'rejected'")
|
|
93
|
+
.all(REFUSED_DOMAIN)
|
|
94
|
+
.map((row) => String(row.domain)));
|
|
95
|
+
/** Person → organization pairs the owner removed: a rule never links them again. */
|
|
96
|
+
const removedMemberships = (database) => new Set(database
|
|
97
|
+
.prepare("SELECT target_id, json_extract(payload, '$.to') AS target FROM proposed_actions WHERE kind = 'relationship' " +
|
|
98
|
+
"AND status = 'rejected' AND target_type = 'person' AND json_extract(payload, '$.kind') = 'member-of' " +
|
|
99
|
+
"AND json_extract(payload, '$.to') LIKE 'organization:%'")
|
|
100
|
+
.all()
|
|
101
|
+
.map((row) => `${row.target_id}>${row.target}`));
|
|
102
|
+
/** Humans the kind pass did not see who write from one of `domains`: a new organization takes them as members too. */
|
|
103
|
+
const othersAt = (database, domains, seen) => {
|
|
104
|
+
const found = new Map();
|
|
105
|
+
for (const row of database
|
|
106
|
+
.prepare("SELECT l.person_id AS person, i.id, lower(i.external_id) AS address FROM identity_links l " +
|
|
107
|
+
"JOIN identities i ON i.id = l.identity_id JOIN persons p ON p.id = l.person_id " +
|
|
108
|
+
"WHERE i.provider = 'email' AND p.owner = 0 AND p.kind IS NOT NULL AND p.kind NOT IN ('test', 'merged') " +
|
|
109
|
+
"AND NOT EXISTS (SELECT 1 FROM sender_bots b WHERE b.person_id = p.id) " +
|
|
110
|
+
"AND NOT EXISTS (SELECT 1 FROM organization_identities oi WHERE oi.identity_id = i.id) ORDER BY i.id")
|
|
111
|
+
.all()) {
|
|
112
|
+
const person = Number(row.person);
|
|
113
|
+
if (seen.has(person))
|
|
114
|
+
continue;
|
|
115
|
+
const domain = companyDomainOf(String(row.address));
|
|
116
|
+
if (domain === undefined || !domains.has(domain))
|
|
117
|
+
continue;
|
|
118
|
+
found.set(person, [...(found.get(person) ?? []), { identity: Number(row.id), domain }]);
|
|
119
|
+
}
|
|
120
|
+
return found;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Plan step 5: a bot or a shared mailbox at a company domain joins that domain's organization, made when none holds
|
|
124
|
+
* it; a human there becomes a `member-of` it, never merged. Free mail, throwaway mail and sending platforms make none.
|
|
125
|
+
* An organization holding a domain of the built-in Wikidata list gets its `metadata.sector`.
|
|
126
|
+
* The owner's word holds: a membership the owner removed and a domain whose organization the owner erased are not made
|
|
127
|
+
* again. The caller holds the write lock.
|
|
128
|
+
*/
|
|
129
|
+
export const groupByDomain = (database, people, at) => {
|
|
130
|
+
const mail = mailOf(database, people.map(({ id }) => id));
|
|
131
|
+
if (mail.size === 0)
|
|
132
|
+
return;
|
|
133
|
+
const { byDomain, held } = holdersOf(database);
|
|
134
|
+
const refused = refusedDomains(database);
|
|
135
|
+
const created = new Set();
|
|
136
|
+
const create = database.prepare("INSERT INTO organizations (kind, name, scope, created_at, updated_at) VALUES ('company', ?, 'personal', ?, ?) " +
|
|
137
|
+
"RETURNING id");
|
|
138
|
+
const hold = database.prepare("INSERT INTO organization_identities (identity_id, organization_id, method, author, created_at, updated_at) " +
|
|
139
|
+
`VALUES (?, ?, '${BY_DOMAIN}', 'rules', ?, ?) ON CONFLICT (identity_id, organization_id) DO NOTHING`);
|
|
140
|
+
const sends = database.prepare("UPDATE sender_bots SET organization_id = ?, updated_at = ? WHERE person_id = ? AND organization_id IS NULL");
|
|
141
|
+
const holder = (domain) => {
|
|
142
|
+
const found = byDomain.get(domain);
|
|
143
|
+
return found?.size === 1 ? [...found][0] : undefined;
|
|
144
|
+
};
|
|
145
|
+
for (const person of people) {
|
|
146
|
+
if (!person.holds)
|
|
147
|
+
continue;
|
|
148
|
+
for (const { identity, domain } of mail.get(person.id) ?? []) {
|
|
149
|
+
let organization = held.get(identity);
|
|
150
|
+
if (organization === undefined) {
|
|
151
|
+
if ((byDomain.get(domain)?.size ?? 0) > 1)
|
|
152
|
+
continue;
|
|
153
|
+
organization = holder(domain);
|
|
154
|
+
if (organization === undefined) {
|
|
155
|
+
if (refused.has(domain))
|
|
156
|
+
continue;
|
|
157
|
+
organization = Number(create.get(nameFor(person.displayName, domain), at, at)?.id);
|
|
158
|
+
byDomain.set(domain, new Set([organization]));
|
|
159
|
+
created.add(domain);
|
|
160
|
+
}
|
|
161
|
+
hold.run(identity, organization, at, at);
|
|
162
|
+
held.set(identity, organization);
|
|
163
|
+
}
|
|
164
|
+
sends.run(organization, at, person.id);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const removed = removedMemberships(database);
|
|
168
|
+
const member = database.prepare("INSERT INTO links (from_type, from_id, to_type, to_id, kind, source, confirmed, author, evidence, metadata, " +
|
|
169
|
+
`created_at, updated_at) SELECT 'person', ?, 'organization', ?, ${linkKind("member-of")}, 'owner', 1, 'rule', ?, ` +
|
|
170
|
+
`'{"derived":"mail-domain"}', ?, ? ` +
|
|
171
|
+
"WHERE NOT EXISTS (SELECT 1 FROM links WHERE from_type = 'person' AND from_id = ? AND to_type = 'organization' " +
|
|
172
|
+
`AND to_id = ? AND kind = ${linkKind("member-of")})`);
|
|
173
|
+
const join = (person, addresses) => {
|
|
174
|
+
for (const domain of new Set(addresses.map((one) => one.domain))) {
|
|
175
|
+
const organization = holder(domain);
|
|
176
|
+
if (organization === undefined || removed.has(`${person}>organization:${organization}`))
|
|
177
|
+
continue;
|
|
178
|
+
member.run(person, organization, `writes from ${domain}`, at, at, person, organization);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
const seen = new Set(people.map(({ id }) => id));
|
|
182
|
+
for (const person of people)
|
|
183
|
+
if (!person.holds)
|
|
184
|
+
join(person.id, mail.get(person.id) ?? []);
|
|
185
|
+
if (created.size > 0)
|
|
186
|
+
for (const [person, addresses] of othersAt(database, created, seen))
|
|
187
|
+
join(person, addresses);
|
|
188
|
+
setSectors(database, byDomain, at);
|
|
189
|
+
};
|
|
190
|
+
/** Each organization holding a company domain takes that domain's sector, the first in `SECTORS` order if several. */
|
|
191
|
+
const setSectors = (database, byDomain, at) => {
|
|
192
|
+
const found = new Map();
|
|
193
|
+
for (const [domain, organizations] of byDomain) {
|
|
194
|
+
const sector = sectorOfDomain(domain);
|
|
195
|
+
if (sector === undefined)
|
|
196
|
+
continue;
|
|
197
|
+
const rank = SECTORS.indexOf(sector);
|
|
198
|
+
for (const organization of organizations)
|
|
199
|
+
if (rank < (found.get(organization) ?? SECTORS.length))
|
|
200
|
+
found.set(organization, rank);
|
|
201
|
+
}
|
|
202
|
+
const set = database.prepare("UPDATE organizations SET metadata = json_set(coalesce(metadata, '{}'), '$.sector', ?), updated_at = ? " +
|
|
203
|
+
"WHERE id = ? AND deleted_at IS NULL AND json_extract(metadata, '$.sector') IS NOT ?");
|
|
204
|
+
for (const [organization, rank] of found)
|
|
205
|
+
set.run(SECTORS[rank] ?? null, at, organization, SECTORS[rank] ?? null);
|
|
206
|
+
};
|
|
207
|
+
/** The owner erased an organization: no rule makes one for the company domains it held again. */
|
|
208
|
+
export const refuseDomainsOf = (database, organization, at) => {
|
|
209
|
+
const domains = new Set(database
|
|
210
|
+
.prepare("SELECT lower(i.external_id) AS address FROM organization_identities oi JOIN identities i ON i.id = oi.identity_id " +
|
|
211
|
+
"WHERE oi.organization_id = ? AND i.provider = 'email'")
|
|
212
|
+
.all(organization)
|
|
213
|
+
.flatMap((row) => companyDomainOf(String(row.address)) ?? []));
|
|
214
|
+
if (domains.size === 0)
|
|
215
|
+
return;
|
|
216
|
+
const rule = actorOfOrigin(database, "rule");
|
|
217
|
+
const owner = database.prepare("SELECT id FROM persons WHERE owner = 1 ORDER BY id LIMIT 1").get();
|
|
218
|
+
const refuse = database.prepare("INSERT INTO proposed_actions (kind, payload, reason, status, proposed_by_type, proposed_by_id, decided_by_type, " +
|
|
219
|
+
"decided_by_id, decided_at, created_at, updated_at) VALUES (?, ?, ?, 'rejected', ?, ?, ?, ?, ?, ?, ?)");
|
|
220
|
+
const already = refusedDomains(database);
|
|
221
|
+
for (const domain of [...domains].filter((one) => !already.has(one)))
|
|
222
|
+
refuse.run(REFUSED_DOMAIN, JSON.stringify({ domain }), `the owner erased organization:${organization}`, rule.type, rule.id, owner === undefined ? null : "person", owner === undefined ? null : Number(owner.id), owner === undefined ? null : at, at, at);
|
|
223
|
+
};
|
|
224
|
+
/** The owner moved these identities to a person: the holds a rule gave them go, so they read as a person's again. */
|
|
225
|
+
export const releaseDomainHolds = (database, identities) => {
|
|
226
|
+
database
|
|
227
|
+
.prepare(`DELETE FROM organization_identities WHERE method = '${BY_DOMAIN}' AND author = 'rules' ` +
|
|
228
|
+
"AND identity_id IN (SELECT value FROM json_each(?))")
|
|
229
|
+
.run(JSON.stringify(identities));
|
|
230
|
+
};
|