@wirecat/wirecat 0.0.0-stage → 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/LICENSE +204 -0
- package/README.md +400 -2
- package/THIRD_PARTY_NOTICES +2 -0
- package/contracts/wirecat.json +4612 -0
- package/dist/actions/actions.js +269 -0
- package/dist/actions/command.js +102 -0
- package/dist/agents/command.js +17 -0
- package/dist/agents/log.js +23 -0
- package/dist/answer.js +100 -0
- package/dist/answers/command.js +128 -0
- package/dist/app.js +15 -0
- package/dist/author.js +109 -0
- package/dist/bin/wcat-wirecat.js +40 -0
- package/dist/bots/command.js +175 -0
- package/dist/bundle/auto-YETGUQ2J.js +43 -0
- package/dist/bundle/chunk-3ME37WWB.js +31 -0
- package/dist/bundle/chunk-4WI3FO7T.js +395 -0
- package/dist/bundle/chunk-7O7XM37N.js +2 -0
- package/dist/bundle/chunk-DWQQRBQV.js +51 -0
- package/dist/bundle/chunk-FOWR5KJS.js +72 -0
- package/dist/bundle/chunk-GGRL6DTE.js +120 -0
- package/dist/bundle/chunk-KNFSW562.js +312 -0
- package/dist/bundle/chunk-KPJVVFQF.js +416 -0
- package/dist/bundle/chunk-WMPDRWVF.js +222 -0
- package/dist/bundle/chunk-X5OK73GU.js +807 -0
- package/dist/bundle/chunk-ZC4PRE6C.js +38 -0
- package/dist/bundle/entry-S4DSYEAY.js +64 -0
- package/dist/bundle/failure-FALOD7QW.js +19 -0
- package/dist/bundle/from-memo-XVOLSUOM.js +314 -0
- package/dist/bundle/program-XSZSINBU.js +14994 -0
- package/dist/bundle/server-GQ4NZUDL.js +303 -0
- package/dist/bundle/update-2EH5KHTV.js +22 -0
- package/dist/bundle/wcat-wirecat.js +83 -0
- package/dist/config-command.js +39 -0
- package/dist/config-issues.js +15 -0
- package/dist/config.js +187 -0
- package/dist/context/command.js +162 -0
- package/dist/context/context.js +197 -0
- package/dist/contract-overrides/commands.js +81 -0
- package/dist/contract-overrides/mcp.js +241 -0
- package/dist/contract-overrides/meetings.js +344 -0
- package/dist/contract-overrides/search.js +508 -0
- package/dist/contract-overrides/skill.js +85 -0
- package/dist/contract-overrides.js +7 -0
- package/dist/digest/backfill.js +175 -0
- package/dist/digest/brief.js +189 -0
- package/dist/digest/catch-up-record.js +30 -0
- package/dist/digest/catch-up.js +86 -0
- package/dist/digest/command.js +110 -0
- package/dist/digest/digest-commands.js +327 -0
- package/dist/digest/digest.js +560 -0
- package/dist/digest/digests.js +213 -0
- package/dist/digest/history.js +202 -0
- package/dist/digest/input.js +30 -0
- package/dist/digest/known.js +28 -0
- package/dist/digest/sources.js +155 -0
- package/dist/digest/sync-health.js +158 -0
- package/dist/digest/task-proposals.js +67 -0
- package/dist/digest/tasks.js +145 -0
- package/dist/digest/text.js +49 -0
- package/dist/discovery/command.js +107 -0
- package/dist/doctor/command.js +167 -0
- package/dist/documents/command.js +107 -0
- package/dist/domain-lists/command.js +13 -0
- package/dist/events/command.js +35 -0
- package/dist/events/events.js +196 -0
- package/dist/examples.js +609 -0
- package/dist/facts/command.js +100 -0
- package/dist/facts/fact.js +54 -0
- package/dist/facts/facts.js +15 -0
- package/dist/failure.js +58 -0
- package/dist/finance/command.js +121 -0
- package/dist/finance/contracts-command.js +109 -0
- package/dist/finance/deal-text.js +34 -0
- package/dist/finance/deals-command.js +346 -0
- package/dist/finance/finance.js +129 -0
- package/dist/finance/lines-command.js +70 -0
- package/dist/finance/orders-command.js +94 -0
- package/dist/finance/products-command.js +98 -0
- package/dist/finance/subscriptions-command.js +152 -0
- package/dist/finance/transactions-command.js +136 -0
- package/dist/finance/wallets-command.js +105 -0
- package/dist/finance/written.js +36 -0
- package/dist/findings/command.js +102 -0
- package/dist/findings-input.js +23 -0
- package/dist/identity.js +20 -0
- package/dist/install/postinstall.js +47 -0
- package/dist/json-fields.js +48 -0
- package/dist/knowledge/business-text.js +19 -0
- package/dist/knowledge/command.js +435 -0
- package/dist/knowledge/document-context.js +33 -0
- package/dist/knowledge/key-documents.js +120 -0
- package/dist/knowledge/list-queries.js +20 -0
- package/dist/knowledge/meeting-projects-command.js +61 -0
- package/dist/knowledge/messenger-sync.js +253 -0
- package/dist/knowledge/money-text.js +16 -0
- package/dist/knowledge/notes-about.js +81 -0
- package/dist/knowledge/organization-delete-command.js +44 -0
- package/dist/knowledge/organization-text.js +27 -0
- package/dist/knowledge/project-actions-command.js +130 -0
- package/dist/knowledge/project-actions.js +104 -0
- package/dist/knowledge/project-activity-command.js +70 -0
- package/dist/knowledge/project-context.js +101 -0
- package/dist/knowledge/project-findings.js +41 -0
- package/dist/knowledge/project-gather-command.js +100 -0
- package/dist/knowledge/project-status-command.js +129 -0
- package/dist/knowledge/project-transfer-command.js +58 -0
- package/dist/knowledge/project-transfer.js +107 -0
- package/dist/knowledge/relationships-scan.js +116 -0
- package/dist/knowledge/relationships.js +115 -0
- package/dist/knowledge/roles-command.js +67 -0
- package/dist/mail/command.js +20 -0
- package/dist/mail/findings-command.js +143 -0
- package/dist/mail/findings-duplicates.js +159 -0
- package/dist/mail/messages-command.js +77 -0
- package/dist/mail/review-command.js +59 -0
- package/dist/mail/subscriptions-command.js +84 -0
- package/dist/mcp/catalogue.js +159 -0
- package/dist/mcp/command.js +125 -0
- package/dist/mcp/granted.js +18 -0
- package/dist/mcp/permissions.js +61 -0
- package/dist/mcp/server.js +128 -0
- package/dist/meetings/command.js +31 -0
- package/dist/meetings/list-command.js +59 -0
- package/dist/meetings/preparation-command.js +42 -0
- package/dist/meetings/preparation-text.js +44 -0
- package/dist/meetings/preparation.js +50 -0
- package/dist/meetings/read.js +32 -0
- package/dist/memories/command.js +105 -0
- package/dist/memories/memories.js +17 -0
- package/dist/memories/memory.js +89 -0
- package/dist/memories/sources.js +111 -0
- package/dist/mentions/command.js +91 -0
- package/dist/migrate/check.js +48 -0
- package/dist/migrate/from-memo.js +345 -0
- package/dist/migrate/skill.js +35 -0
- package/dist/models/command.js +19 -0
- package/dist/options.js +35 -0
- package/dist/output.js +17 -0
- package/dist/page.js +14 -0
- package/dist/people/command.js +144 -0
- package/dist/people/delete-command.js +53 -0
- package/dist/people/doubts-command.js +81 -0
- package/dist/people/identities-command.js +188 -0
- package/dist/people/identity.js +42 -0
- package/dist/people/owner.js +14 -0
- package/dist/people/proposal-rows.js +70 -0
- package/dist/people/proposals-command.js +248 -0
- package/dist/people/review-context.js +108 -0
- package/dist/people/subject.js +19 -0
- package/dist/program.js +875 -0
- package/dist/read-only.js +51 -0
- package/dist/reasons.js +368 -0
- package/dist/records/import.js +135 -0
- package/dist/records/input.js +210 -0
- package/dist/records/mapping.js +80 -0
- package/dist/records/record-commands.js +125 -0
- package/dist/records/sources.js +73 -0
- package/dist/refs.js +28 -0
- package/dist/review/command.js +171 -0
- package/dist/review/kinds.js +44 -0
- package/dist/review/review.js +299 -0
- package/dist/review/status.js +93 -0
- package/dist/rows.js +219 -0
- package/dist/run/auto.js +237 -0
- package/dist/run/entry.js +62 -0
- package/dist/run/files.js +51 -0
- package/dist/run/import.js +253 -0
- package/dist/run/lock.js +20 -0
- package/dist/save-help.js +3 -0
- package/dist/schedule/command.js +58 -0
- package/dist/schedule/mail-triage-input.js +152 -0
- package/dist/schedule/task-triage-input.js +152 -0
- package/dist/search/answers.js +176 -0
- package/dist/search/command.js +257 -0
- package/dist/search/denied.js +9 -0
- package/dist/search/embed.js +126 -0
- package/dist/search/hits.js +4 -0
- package/dist/search/lane-gates.js +76 -0
- package/dist/search/notes-text.js +18 -0
- package/dist/search/people.js +88 -0
- package/dist/search/search.js +306 -0
- package/dist/show/command.js +179 -0
- package/dist/store/crm-viewer.js +102 -0
- package/dist/store/group.js +112 -0
- package/dist/store/groups-command.js +136 -0
- package/dist/store/guard.js +94 -0
- package/dist/store/held.js +21 -0
- package/dist/store/info-command.js +37 -0
- package/dist/store/scope.js +53 -0
- package/dist/store/source-list.js +222 -0
- package/dist/store/source-target.js +28 -0
- package/dist/tags/command.js +176 -0
- package/dist/tasks/command.js +174 -0
- package/dist/tasks/context.js +74 -0
- package/dist/tasks/list.js +199 -0
- package/dist/tasks/proposal-duplicates.js +70 -0
- package/dist/tasks/relations-command.js +28 -0
- package/dist/tasks/shared.js +105 -0
- package/dist/tasks/tasks.js +197 -0
- package/dist/templates/command.js +18 -0
- package/dist/terminal.js +23 -0
- package/dist/update.js +35 -0
- package/dist/version.js +2 -0
- package/dist/vocabulary/command.js +103 -0
- package/dist/vocabulary/inspect.js +23 -0
- package/dist/vocabulary/inspection.js +18 -0
- package/dist/vocabulary/list.js +18 -0
- package/dist/vocabulary/project.js +19 -0
- package/dist/wcat.js +3 -0
- package/install/postinstall.mjs +9 -0
- package/package.json +89 -4
- package/scenarios/decision-trail.md +21 -0
- package/scenarios/person-brief.md +35 -0
- package/scenarios/prepare-meeting.md +17 -0
- package/scenarios/project-state.md +26 -0
- package/scenarios/set-up.md +18 -0
- package/scenarios/start-the-day.md +19 -0
- package/skills/mail-triage/SKILL.md +208 -0
- package/skills/morning-digest/SKILL.md +147 -0
- package/skills/task-triage/SKILL.md +79 -0
- package/skills/wcat/SKILL.md +65 -0
- package/skills/wcat/topics/mail.md +32 -0
- package/skills/wcat/topics/mcp.md +22 -0
- package/skills/wcat/topics/meetings.md +37 -0
- package/skills/wcat/topics/money.md +52 -0
- package/skills/wcat/topics/projects.md +54 -0
- package/skills/wcat/topics/proposals.md +113 -0
- package/skills/wcat/topics/search.md +85 -0
- package/skills/wcat/topics/vocabulary.md +8 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { crmViewerOf, kindIn, } from "@wirecat/cli-core";
|
|
3
|
+
const shortened = new WeakMap();
|
|
4
|
+
/** Why an answer read from this store shows less of a CRM copy than its rule gives, one line per copy. */
|
|
5
|
+
export const crmNotes = (store) => [...(shortened.get(store) ?? [])];
|
|
6
|
+
/**
|
|
7
|
+
* What wcat may show of one CRM copy (SEC-197): what the user its sync signed in as reads, as cli-core's `search all`
|
|
8
|
+
* reads another account's copy. A copy that limits its users and names none shows nothing; an account that is no CRM,
|
|
9
|
+
* as an ERP's import, shows whole. A note on why it shows less is kept for the answer (`crmNotes`).
|
|
10
|
+
*/
|
|
11
|
+
export const crmViewing = async (store, key) => {
|
|
12
|
+
if (kindIn(key.provider) !== "crm")
|
|
13
|
+
return { viewer: undefined };
|
|
14
|
+
const viewing = await crmViewerOf(store, key, (await store.crm.ownUser(key)) ?? null);
|
|
15
|
+
if (viewing.note) {
|
|
16
|
+
const notes = shortened.get(store) ?? new Set();
|
|
17
|
+
notes.add(`${key.provider}:${key.account}: ${viewing.note}`);
|
|
18
|
+
shortened.set(store, notes);
|
|
19
|
+
}
|
|
20
|
+
return viewing;
|
|
21
|
+
};
|
|
22
|
+
/** The CRM accounts the store holds. */
|
|
23
|
+
const crmAccounts = async (store) => (await store.accounts.accounts()).filter((key) => kindIn(key.provider) === "crm");
|
|
24
|
+
/** Every CRM copy's rule, as cli-core's contexts take it (`viewing`). */
|
|
25
|
+
export const crmViewingAll = async (store) => Promise.all((await crmAccounts(store)).map((key) => crmViewing(store, key)));
|
|
26
|
+
/** The viewer of every limited CRM copy, as `listRelations` takes them. */
|
|
27
|
+
export const crmViewersAll = async (store) => crmViewers(store, await crmAccounts(store));
|
|
28
|
+
/** The viewer of every limited copy among `keys`. */
|
|
29
|
+
export const crmViewers = async (store, keys) => (await Promise.all(keys.map(async (key) => (await crmViewing(store, key)).viewer))).filter((one) => one !== undefined);
|
|
30
|
+
/**
|
|
31
|
+
* Whether wcat may show a deal or lead: the owner's own always, a copy's by cli-core's `seenBy` rule, which
|
|
32
|
+
* `@wirecat/cli-core` declares but does not export at run time.
|
|
33
|
+
*/
|
|
34
|
+
const crmSees = (store) => {
|
|
35
|
+
const known = new Map();
|
|
36
|
+
return async (row) => {
|
|
37
|
+
if (row.account === null)
|
|
38
|
+
return true;
|
|
39
|
+
const id = `${row.account.provider}:${row.account.account}`;
|
|
40
|
+
if (!known.has(id))
|
|
41
|
+
known.set(id, crmViewing(store, row.account).then(({ viewer }) => viewer));
|
|
42
|
+
const viewer = await known.get(id);
|
|
43
|
+
return viewer === undefined || (viewer.assignee !== null && row.assignee === viewer.assignee);
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
/** The rows of `rows` wcat may show. */
|
|
47
|
+
export const seenRows = async (store, rows) => {
|
|
48
|
+
const sees = crmSees(store);
|
|
49
|
+
const kept = await Promise.all(rows.map(sees));
|
|
50
|
+
return rows.filter((_, at) => kept[at]);
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* A page of `most` rows wcat may show, read on past the rows it hides so a page is short only at the end. cli-core's
|
|
54
|
+
* `DealFilter.viewer` cannot do it in SQL here: it hides every row not assigned to the viewer, the owner's own and
|
|
55
|
+
* other accounts' too, and wcat lists them together.
|
|
56
|
+
*/
|
|
57
|
+
export const seenPage = async (store, most, read) => {
|
|
58
|
+
const sees = crmSees(store);
|
|
59
|
+
const kept = [];
|
|
60
|
+
let offset = 0;
|
|
61
|
+
let more = true;
|
|
62
|
+
while (more && kept.length <= most) {
|
|
63
|
+
const page = await read(most + 1, offset);
|
|
64
|
+
for (const row of page.items)
|
|
65
|
+
if (await sees(row))
|
|
66
|
+
kept.push(row);
|
|
67
|
+
offset += page.items.length;
|
|
68
|
+
more = page.hasMore && page.items.length > 0;
|
|
69
|
+
}
|
|
70
|
+
return { items: kept.slice(0, most), hasMore: kept.length > most || more };
|
|
71
|
+
};
|
|
72
|
+
/** A deal or lead by its ref; one in a copy wcat may not show is not found, as cli-core's `show` answers it. */
|
|
73
|
+
export const readableDeal = async (store, ref) => {
|
|
74
|
+
const found = await store.deals.get(ref);
|
|
75
|
+
if (!(await crmSees(store)(found))) {
|
|
76
|
+
const why = crmNotes(store);
|
|
77
|
+
throw new CliError("not_found", `${ref} is not a copy this store's CRM sign-in may read${why.length ? `: ${why.join("; ")}` : ""}`, { reason: "deal.not-readable" });
|
|
78
|
+
}
|
|
79
|
+
return found;
|
|
80
|
+
};
|
|
81
|
+
/** A pipeline's funnel, counting in a CRM copy only the rows wcat may show. */
|
|
82
|
+
export const readablePipeline = async (store, ref, options = {}) => {
|
|
83
|
+
const report = await store.deals.pipeline(ref, options);
|
|
84
|
+
if (report.account === null)
|
|
85
|
+
return report;
|
|
86
|
+
const { viewer } = await crmViewing(store, report.account);
|
|
87
|
+
return viewer === undefined ? report : store.deals.pipeline(report.ref, { ...options, viewer });
|
|
88
|
+
};
|
|
89
|
+
/** Pipelines with each limited copy's stage counts read again as its viewer sees them. */
|
|
90
|
+
export const readablePipelines = async (store, pipelines, kind) => {
|
|
91
|
+
const accounts = new Map(pipelines.flatMap(({ account }) => (account ? [[`${account.provider}:${account.account}`, account]] : [])));
|
|
92
|
+
const seen = new Map();
|
|
93
|
+
for (const account of accounts.values()) {
|
|
94
|
+
const { viewer } = await crmViewing(store, account);
|
|
95
|
+
if (viewer === undefined)
|
|
96
|
+
continue;
|
|
97
|
+
for (const one of await store.deals.pipelines({ ...(kind === undefined ? {} : { kind }), account, viewer }))
|
|
98
|
+
seen.set(one.ref, one);
|
|
99
|
+
}
|
|
100
|
+
return pipelines.map((one) => seen.get(one.ref) ?? one);
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=crm-viewer.js.map
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { entriesOfList, inGroupOf, keyOf, kindIn, listContextOf, refuseOutsideGroup, runGroup, scopeToGroup, } from "@wirecat/cli-core";
|
|
2
|
+
import { withStore } from "../answer.js";
|
|
3
|
+
import { APP } from "../app.js";
|
|
4
|
+
/**
|
|
5
|
+
* The account wcat's reads run as: its own notes. It names no stored account, so the list reader never adds it to
|
|
6
|
+
* `held` as a new one.
|
|
7
|
+
*/
|
|
8
|
+
export const WCAT_ACCOUNT = { provider: "notes", account: "internal" };
|
|
9
|
+
/** Who runs, as cli-core's source lists see it: wcat, so `group:` and profiles resolve as every app saved them. */
|
|
10
|
+
export const memoListContext = async (store, env) => {
|
|
11
|
+
const held = await store.accounts.storedAccounts();
|
|
12
|
+
// listContextOf adds the running account when the store has no row for it; wcat's own notes are no account.
|
|
13
|
+
const context = await listContextOf(store, WCAT_ACCOUNT, APP, held, env);
|
|
14
|
+
return {
|
|
15
|
+
...context,
|
|
16
|
+
held: context.held.filter((one) => one.id !== 0 || keyOf(one) !== keyOf(WCAT_ACCOUNT)),
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/** The group this run reads (WC-ACCT-13): the first word, `WCAT_GROUP` or the lock `WCAT_GROUP_LOCK`. */
|
|
20
|
+
export const groupOf = (env, word) => runGroup(APP, env, word);
|
|
21
|
+
const scopeIn = (run, context) => {
|
|
22
|
+
// Refuses an unknown or empty group the same way a `--source` would.
|
|
23
|
+
scopeToGroup(run, {}, context);
|
|
24
|
+
const accounts = entriesOfList(`group:${run.name}`, context).flatMap((entry) => entry.accounts.map(({ provider, account }) => ({ provider, account })));
|
|
25
|
+
return { run, accounts, has: inGroupOf(context, run.name) };
|
|
26
|
+
};
|
|
27
|
+
export const groupScopeOf = async (store, env) => {
|
|
28
|
+
const run = groupOf(env);
|
|
29
|
+
return run === undefined ? undefined : scopeIn(run, await memoListContext(store, env));
|
|
30
|
+
};
|
|
31
|
+
/** The owner's own invoices, payments and contracts, as cli-core's business lane names them. */
|
|
32
|
+
const OWN_BUSINESS = { provider: "business", account: "internal" };
|
|
33
|
+
/**
|
|
34
|
+
* The group's accounts of each kind `search all` reads. The owner's own notes (`wcat notes add`) and business data
|
|
35
|
+
* belong to no account, so every group reads them; an import's business data is its account's, in a group only when
|
|
36
|
+
* the group holds that account (WC-ACCT-13). `imports` are the accounts whose imports made business data.
|
|
37
|
+
*/
|
|
38
|
+
export const accountsByKind = (scope, imports = []) => {
|
|
39
|
+
const kinds = {
|
|
40
|
+
messages: [],
|
|
41
|
+
mail: [],
|
|
42
|
+
notes: [WCAT_ACCOUNT],
|
|
43
|
+
events: [],
|
|
44
|
+
crm: [],
|
|
45
|
+
business: [OWN_BUSINESS, ...imports.filter(scope.has)],
|
|
46
|
+
meetings: [],
|
|
47
|
+
tracker: [],
|
|
48
|
+
};
|
|
49
|
+
for (const key of scope.accounts) {
|
|
50
|
+
const kind = kindIn(key.provider);
|
|
51
|
+
if (kind === "documents")
|
|
52
|
+
kinds.notes.push(key);
|
|
53
|
+
else if (kind !== undefined && kind in kinds)
|
|
54
|
+
kinds[kind].push(key);
|
|
55
|
+
}
|
|
56
|
+
return kinds;
|
|
57
|
+
};
|
|
58
|
+
/** Every stored account, or only the group's when the run is in one. */
|
|
59
|
+
export const scopedAccounts = async (store, env) => {
|
|
60
|
+
const all = await store.accounts.accounts();
|
|
61
|
+
const scope = await groupScopeOf(store, env);
|
|
62
|
+
return scope === undefined ? all : all.filter(scope.has);
|
|
63
|
+
};
|
|
64
|
+
/** Keeps only the group's accounts; every one when the run is in no group. */
|
|
65
|
+
export const inGroup = async (store, env, keys) => {
|
|
66
|
+
const scope = await groupScopeOf(store, env);
|
|
67
|
+
return scope === undefined ? [...keys] : keys.filter(scope.has);
|
|
68
|
+
};
|
|
69
|
+
/** Whether a thing belongs to the run's group as cli-core's lock judges a reference: no account means the owner's. */
|
|
70
|
+
const refInGroup = async (store, scope, ref) => {
|
|
71
|
+
const accounts = await store.refs.accounts(ref);
|
|
72
|
+
return !accounts?.length || accounts.some(scope.has);
|
|
73
|
+
};
|
|
74
|
+
/** The items of a list that belong to the run's group; every one when the run is in no group. */
|
|
75
|
+
export const keepInGroup = async (store, env, items, refOf) => {
|
|
76
|
+
const scope = await groupScopeOf(store, env);
|
|
77
|
+
if (scope === undefined)
|
|
78
|
+
return [...items];
|
|
79
|
+
const kept = [];
|
|
80
|
+
for (const item of items)
|
|
81
|
+
if (await refInGroup(store, scope, refOf(item)))
|
|
82
|
+
kept.push(item);
|
|
83
|
+
return kept;
|
|
84
|
+
};
|
|
85
|
+
const optionValue = (command, name) => {
|
|
86
|
+
const value = command.getOptionValue(name);
|
|
87
|
+
return typeof value === "string" ? value : undefined;
|
|
88
|
+
};
|
|
89
|
+
const declares = (command, name) => command.options.some((option) => option.attributeName() === name);
|
|
90
|
+
/**
|
|
91
|
+
* Before every action: under WCAT_GROUP_LOCK cli-core refuses a command not marked `groupAware` and any reference
|
|
92
|
+
* whose thing is outside the group (WC-ACCT-13). In a group, no `--source` becomes `group:<name>`, a given one is
|
|
93
|
+
* narrowed to the group, and an outside `--account` is refused. `word` is the first word `liftGroup` lifted.
|
|
94
|
+
*/
|
|
95
|
+
export const scopeRunsToGroup = (program, env, word) => {
|
|
96
|
+
program.hook("preAction", async (_root, command) => {
|
|
97
|
+
const run = groupOf(env, word);
|
|
98
|
+
if (run === undefined)
|
|
99
|
+
return;
|
|
100
|
+
await withStore(env, async (store) => {
|
|
101
|
+
await refuseOutsideGroup(command, { app: APP, env, store });
|
|
102
|
+
const context = await memoListContext(store, env);
|
|
103
|
+
const source = declares(command, "source") ? optionValue(command, "source") : undefined;
|
|
104
|
+
const account = declares(command, "account") ? optionValue(command, "account") : undefined;
|
|
105
|
+
const scoped = scopeToGroup(run, { ...(source === undefined ? {} : { source }), ...(account === undefined ? {} : { account }) }, context);
|
|
106
|
+
// `--all` and `--source` are each other's opposite; under a group, `--all` reads the group's accounts itself.
|
|
107
|
+
if (declares(command, "source") && scoped.source !== undefined && command.getOptionValue("all") !== true)
|
|
108
|
+
command.setOptionValue("source", scoped.source);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=group.js.map
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
3
|
+
import { addGroupMember, commandWords, deleteAccountGroup, grantsAuthority, LOCAL_READ, LOCAL_WRITE, listAccountGroups, moveGroupMember, queryTerms, removeGroupMember, renameAccountGroup, setAccountScope, setChatScope, withQuery, } from "@wirecat/cli-core";
|
|
4
|
+
import { answers, itemAnswer, listAnswer, withStore } from "../answer.js";
|
|
5
|
+
import { APP } from "../app.js";
|
|
6
|
+
import { WCAT_ACCOUNT } from "./group.js";
|
|
7
|
+
/** With --chat, `account` takes the chat's own scope off, so it follows its account again. */
|
|
8
|
+
const scopeOption = (scope, chat) => {
|
|
9
|
+
if (scope === "personal" || scope === "work")
|
|
10
|
+
return scope;
|
|
11
|
+
if (scope === "account" && chat !== undefined)
|
|
12
|
+
return null;
|
|
13
|
+
throw new CliError("validation_error", chat === undefined
|
|
14
|
+
? `--scope ${scope}: personal or work`
|
|
15
|
+
: `--scope ${scope}: personal, work, or account to let the chat follow its account`, { reason: "input.invalid", param: "scope" });
|
|
16
|
+
};
|
|
17
|
+
const MEMBER_HELP = "one account, as --source names it: telegram:102, tg:work, email:me@work.example, bitrix24:<portal>";
|
|
18
|
+
/** wcat's own entity: one group and its accounts. */
|
|
19
|
+
const GROUPS_QUERY = { entity: "account_group", backend: "native", fields: [] };
|
|
20
|
+
const at = (store, env) => ({ store, account: WCAT_ACCOUNT, app: APP, env });
|
|
21
|
+
export const membershipText = ({ groups, duplicates, suggested, unresolved }) => [
|
|
22
|
+
...Object.entries(groups).flatMap(([name, members]) => [
|
|
23
|
+
`${name}${members.length ? "" : " (empty)"}`,
|
|
24
|
+
...members.map((member) => [
|
|
25
|
+
` ${member.provider}:${member.account}`,
|
|
26
|
+
member.profiles.length ? member.profiles.join(", ") : "",
|
|
27
|
+
member.reason === "setting" ? "" : member.reason,
|
|
28
|
+
member.also_in.length ? `also in ${member.also_in.join(", ")}` : "",
|
|
29
|
+
]
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
.join(" ")),
|
|
32
|
+
]),
|
|
33
|
+
...duplicates.map(({ member, groups: names }) => `duplicate: ${member} is in ${names.join(", ")}`),
|
|
34
|
+
...suggested.map(({ group, member, because }) => `suggested: ${member} for ${group} — ${because}`),
|
|
35
|
+
...unresolved.map((entry) => `unresolved: ${entry} names no account`),
|
|
36
|
+
].join("\n");
|
|
37
|
+
/**
|
|
38
|
+
* `wcat groups …`: which accounts each group holds (WC-ACCT-13), and the owner's edits of that. cli-core computes the
|
|
39
|
+
* membership and makes each change in one write; wcat names its own command words as words no group may take.
|
|
40
|
+
*/
|
|
41
|
+
export const groupsCommand = (program, streams, env) => {
|
|
42
|
+
const { print } = answers(program, streams, env);
|
|
43
|
+
const groups = program.command("groups").description("account groups: wcat <group> … reads only the group's accounts");
|
|
44
|
+
/** Every answer, a read's or an edit's, is the groups as `groups list` gives them: one row per group. */
|
|
45
|
+
const show = async (command, json, work) => {
|
|
46
|
+
const membership = await withStore(env, work);
|
|
47
|
+
const { groups: named, duplicates, suggested, unresolved } = membership;
|
|
48
|
+
const items = Object.entries(named).map(([group, members]) => ({
|
|
49
|
+
group,
|
|
50
|
+
members,
|
|
51
|
+
duplicates: duplicates.filter(({ groups: names }) => names.includes(group)),
|
|
52
|
+
suggested: suggested.filter((one) => one.group === group),
|
|
53
|
+
}));
|
|
54
|
+
print(json, listAnswer(command, {
|
|
55
|
+
items,
|
|
56
|
+
limit: Math.max(1, items.length),
|
|
57
|
+
has_more: false,
|
|
58
|
+
missing: unresolved.map((entry) => ({
|
|
59
|
+
field: entry,
|
|
60
|
+
why: "a saved group entry that names no account",
|
|
61
|
+
})),
|
|
62
|
+
}), membershipText(membership));
|
|
63
|
+
};
|
|
64
|
+
const reserved = () => commandWords(program);
|
|
65
|
+
withQuery(annotate(groups.command("list"), { effects: LOCAL_READ, output: { entity: "account_group" } }), GROUPS_QUERY)
|
|
66
|
+
.description("every saved group, then all, with its accounts, each with its profiles in every app and the other groups that " +
|
|
67
|
+
"hold it too; duplicates and profile-name suggestions last")
|
|
68
|
+
.summary("the saved groups, then all, with accounts, profiles and duplicates")
|
|
69
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")
|
|
70
|
+
.action(async (words, options) => {
|
|
71
|
+
queryTerms(words, GROUPS_QUERY, "groups list");
|
|
72
|
+
await show("groups list", options.json, (store) => listAccountGroups(at(store, env)));
|
|
73
|
+
});
|
|
74
|
+
grantsAuthority(annotate(groups.command("add"), { effects: LOCAL_WRITE, output: { entity: "account_group" } }))
|
|
75
|
+
.description("put an account in a group, which is made when it does not exist; it may stay in others too")
|
|
76
|
+
.summary("put an account in a group")
|
|
77
|
+
.argument("<group>", "the group: letters, digits, - and _, not a wcat command word")
|
|
78
|
+
.argument("<source>", MEMBER_HELP)
|
|
79
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")
|
|
80
|
+
.action((group, member, options) => show("groups add", options.json, (store) => addGroupMember(at(store, env), { group, member, reserved: reserved() })));
|
|
81
|
+
grantsAuthority(annotate(groups.command("remove"), { effects: LOCAL_WRITE, output: { entity: "account_group" } }))
|
|
82
|
+
.description("take an account out of a group; the account and its data stay, and `all` still reads it")
|
|
83
|
+
.summary("take an account out of a group")
|
|
84
|
+
.argument("<group>", "the group")
|
|
85
|
+
.argument("<source>", MEMBER_HELP)
|
|
86
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")
|
|
87
|
+
.action((group, member, options) => show("groups remove", options.json, (store) => removeGroupMember(at(store, env), { group, member })));
|
|
88
|
+
// The words, not --from/--to: the shared vocabulary gives --to to a message's recipient.
|
|
89
|
+
grantsAuthority(annotate(groups.command("move"), { effects: LOCAL_WRITE, output: { entity: "account_group" } }))
|
|
90
|
+
.description("move an account from one group to another in one write; the other group is made when it is new")
|
|
91
|
+
.summary("move an account between groups")
|
|
92
|
+
.argument("<source>", MEMBER_HELP)
|
|
93
|
+
.argument("<from>", "the group it leaves")
|
|
94
|
+
.argument("<to>", "the group it joins")
|
|
95
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")
|
|
96
|
+
.action((member, from, to, options) => show("groups move", options.json, (store) => moveGroupMember(at(store, env), { member, from, to, reserved: reserved() })));
|
|
97
|
+
grantsAuthority(annotate(groups.command("rename"), { effects: LOCAL_WRITE, output: { entity: "account_group" } }))
|
|
98
|
+
.description("give a group another name, with its members; a run, lock or agent that still names the old one is refused " +
|
|
99
|
+
"with the groups there are")
|
|
100
|
+
.summary("rename a group")
|
|
101
|
+
.argument("<group>", "the group")
|
|
102
|
+
.argument("<name>", "its new name: letters, digits, - and _, not a wcat command word")
|
|
103
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")
|
|
104
|
+
.action((from, to, options) => show("groups rename", options.json, (store) => renameAccountGroup(at(store, env), { from, to, reserved: reserved() })));
|
|
105
|
+
grantsAuthority(annotate(groups.command("delete"), { effects: LOCAL_WRITE, output: { entity: "account_group" } }))
|
|
106
|
+
.description("delete a group and its memberships; its accounts and their data stay, in their other groups and in `all`")
|
|
107
|
+
.summary("delete a group")
|
|
108
|
+
.argument("<group>", "the group")
|
|
109
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")
|
|
110
|
+
.action((group, options) => show("groups delete", options.json, (store) => deleteAccountGroup(at(store, env), group)));
|
|
111
|
+
// Moving an account to work lets work views and agents of a work group read it: the owner's word, never an agent's.
|
|
112
|
+
grantsAuthority(annotate(groups.command("update"), {
|
|
113
|
+
effects: LOCAL_WRITE,
|
|
114
|
+
mcp: false,
|
|
115
|
+
output: { entity: "account_scope" },
|
|
116
|
+
}))
|
|
117
|
+
.description("set an account's scope, personal or work, which decides whether work views and meeting preparation read it; " +
|
|
118
|
+
"with --chat, pin one chat of it to a scope, or let it follow its account again")
|
|
119
|
+
.summary("set an account's or one chat's scope, personal or work")
|
|
120
|
+
.argument("<source>", MEMBER_HELP)
|
|
121
|
+
.requiredOption("--scope <scope>", "personal or work; with --chat also account, which takes the chat's own off")
|
|
122
|
+
.option("--chat <chat>", "one chat of the account, by its id there")
|
|
123
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")
|
|
124
|
+
.action(async (member, options) => {
|
|
125
|
+
const scope = scopeOption(options.scope, options.chat);
|
|
126
|
+
if (options.chat === undefined) {
|
|
127
|
+
const account = await withStore(env, (store) => setAccountScope(at(store, env), { member, scope: scope }));
|
|
128
|
+
print(options.json, itemAnswer(account), `${account.provider}:${account.account} is ${account.scope}`);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const chat = await withStore(env, (store) => setChatScope(at(store, env), { member, chat: options.chat, scope }));
|
|
132
|
+
print(options.json, itemAnswer(chat), `chat ${chat.chat} of ${chat.provider}:${chat.account} is ${chat.scope}` +
|
|
133
|
+
(chat.own === null ? ", as its account" : ", its own"));
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
//# sourceMappingURL=groups-command.js.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { groupGuardOf, lockedRegistry, proposalRegistry } from "@wirecat/cli-core";
|
|
3
|
+
import { APP } from "../app.js";
|
|
4
|
+
import { reviewRegistry } from "../review/kinds.js";
|
|
5
|
+
import { groupScopeOf } from "./group.js";
|
|
6
|
+
/** cli-core's guard for a run under WCAT_GROUP_LOCK; `undefined` when the run is not locked (WC-ACCT-13). */
|
|
7
|
+
export const guardOf = (store, env) => groupGuardOf(store, APP, env);
|
|
8
|
+
/** The review list a run decides through: under the lock a proposal outside the group is not listed nor decided. */
|
|
9
|
+
export const reviewOf = async (store, env) => {
|
|
10
|
+
const guard = await guardOf(store, env);
|
|
11
|
+
return guard === undefined ? reviewRegistry(store) : lockedRegistry(reviewRegistry(store), guard);
|
|
12
|
+
};
|
|
13
|
+
/** The proposals a run decides through, not only the review's: under the lock the same limits hold. */
|
|
14
|
+
export const proposalsOf = async (store, env) => {
|
|
15
|
+
const guard = await guardOf(store, env);
|
|
16
|
+
return guard === undefined ? proposalRegistry(store) : lockedRegistry(proposalRegistry(store), guard);
|
|
17
|
+
};
|
|
18
|
+
/** An answer with every outside reference taken out of its `evidence`, and how many, under the lock. */
|
|
19
|
+
export const stripped = async (store, env, value) => {
|
|
20
|
+
const guard = await guardOf(store, env);
|
|
21
|
+
if (guard === undefined)
|
|
22
|
+
return value;
|
|
23
|
+
const { value: kept, out_of_scope } = await guard.strip(value);
|
|
24
|
+
if (out_of_scope === 0 || kept === null || typeof kept !== "object" || Array.isArray(kept))
|
|
25
|
+
return kept;
|
|
26
|
+
// A list answer is an envelope with no room for a field of its own: what it left out goes in `missing`.
|
|
27
|
+
if ("items" in kept) {
|
|
28
|
+
const missing = kept.missing ?? [];
|
|
29
|
+
const why = `${out_of_scope} evidence references outside group ${guard.group} left out`;
|
|
30
|
+
return { ...kept, missing: [...missing, { field: "out_of_scope", why }] };
|
|
31
|
+
}
|
|
32
|
+
return { ...kept, out_of_scope };
|
|
33
|
+
};
|
|
34
|
+
/** The sources read back for a memory or a fact, under the lock only the group's, and how many were left out. */
|
|
35
|
+
export const sourcesIn = async (store, env, sources) => {
|
|
36
|
+
const guard = await guardOf(store, env);
|
|
37
|
+
if (guard === undefined)
|
|
38
|
+
return { sources: [...sources] };
|
|
39
|
+
const kept = [];
|
|
40
|
+
for (const one of sources)
|
|
41
|
+
if (one.ref === null || (await guard.visible(one.ref)))
|
|
42
|
+
kept.push(one);
|
|
43
|
+
return { sources: kept, ...(kept.length < sources.length ? { out_of_scope: sources.length - kept.length } : {}) };
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Under the lock, a context's `notRead` would name every account kept out, which tells the agent they exist: those
|
|
47
|
+
* become one line with their count. Sources that are no account of the store (`notes`, `events`) stay as they are.
|
|
48
|
+
*/
|
|
49
|
+
export const lockedCoverage = async (store, env, value) => {
|
|
50
|
+
const guard = await guardOf(store, env);
|
|
51
|
+
const scope = guard === undefined ? undefined : await groupScopeOf(store, env);
|
|
52
|
+
if (guard === undefined || scope === undefined)
|
|
53
|
+
return value;
|
|
54
|
+
const held = new Set((await store.accounts.storedAccounts()).map(({ provider, account }) => `${provider}:${account}`));
|
|
55
|
+
const outside = (source) => held.has(source) && !scope.accounts.some((key) => `${key.provider}:${key.account}` === source);
|
|
56
|
+
const walk = (node) => {
|
|
57
|
+
if (Array.isArray(node))
|
|
58
|
+
return node.map(walk);
|
|
59
|
+
if (node === null || typeof node !== "object")
|
|
60
|
+
return node;
|
|
61
|
+
return Object.fromEntries(Object.entries(node).map(([key, inner]) => {
|
|
62
|
+
if (key !== "notRead" || !Array.isArray(inner))
|
|
63
|
+
return [key, walk(inner)];
|
|
64
|
+
const rows = inner;
|
|
65
|
+
const away = rows.filter((one) => outside(one.source)).length;
|
|
66
|
+
const kept = rows.filter((one) => !outside(one.source));
|
|
67
|
+
return [
|
|
68
|
+
key,
|
|
69
|
+
away ? [...kept, { source: "other accounts", reason: `${away} outside group ${guard.group}` }] : kept,
|
|
70
|
+
];
|
|
71
|
+
}));
|
|
72
|
+
};
|
|
73
|
+
return walk(value);
|
|
74
|
+
};
|
|
75
|
+
/** Refuses a proposed action outside the locked group, as cli-core's lock refuses a reference. */
|
|
76
|
+
export const refuseOutsideAction = async (store, env, id) => {
|
|
77
|
+
const guard = await guardOf(store, env);
|
|
78
|
+
if (guard !== undefined && !(await guard.visible(`action:${id}`)))
|
|
79
|
+
throw new CliError("permission_error", `this process is locked to group ${guard.group} — action ${id} is outside it`, {
|
|
80
|
+
reason: "group.outside",
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
/** The actions of a list a locked run may see. */
|
|
84
|
+
export const actionsIn = async (store, env, actions) => {
|
|
85
|
+
const guard = await guardOf(store, env);
|
|
86
|
+
if (guard === undefined)
|
|
87
|
+
return [...actions];
|
|
88
|
+
const kept = [];
|
|
89
|
+
for (const one of actions)
|
|
90
|
+
if (await guard.visible(`action:${one.id}`))
|
|
91
|
+
kept.push(one);
|
|
92
|
+
return kept;
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=guard.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A live message, or a live email of the mail tables, by the ids its locator holds. Mail an import before 0.8.0
|
|
3
|
+
* saved as messages is a message.
|
|
4
|
+
*/
|
|
5
|
+
export const heldMessage = async (store, key, id, chatId) => {
|
|
6
|
+
if (key.provider === "email") {
|
|
7
|
+
const account = await store.accounts.storedAccount(key).catch(() => undefined);
|
|
8
|
+
const email = account ? await store.mail.email(account.id, id) : null;
|
|
9
|
+
if (email)
|
|
10
|
+
return email.deletedAt === null
|
|
11
|
+
? {
|
|
12
|
+
text: [email.subject, email.bodyText].filter(Boolean).join("\n\n"),
|
|
13
|
+
senderId: email.fromAddress,
|
|
14
|
+
senderName: email.fromName,
|
|
15
|
+
timestamp: new Date(email.sentAt ?? email.receivedAt ?? email.createdAt).toISOString(),
|
|
16
|
+
}
|
|
17
|
+
: undefined;
|
|
18
|
+
}
|
|
19
|
+
return store.messages.message(key, id, { chatId });
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=held.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
2
|
+
import { itemOf, LOCAL_READ, LOCAL_WRITE, recoveryNotes, snakeKeys, storeInfo, storeRecoveryCheck, storeRecoveryRun, } from "@wirecat/cli-core";
|
|
3
|
+
import { answers } from "../answer.js";
|
|
4
|
+
import { VERSION } from "../version.js";
|
|
5
|
+
export const storeCommand = (program, streams, env) => {
|
|
6
|
+
const { print } = answers(program, streams, env);
|
|
7
|
+
const store = annotate(program.command("store"), { effects: LOCAL_READ }).description("the shared local store every WireCat tool reads");
|
|
8
|
+
annotate(store.command("info"), { effects: LOCAL_READ, output: { entity: "store_info" } })
|
|
9
|
+
.summary("the shared store's format and size, and whether wcat can read it")
|
|
10
|
+
.description("the store file: where it is, its size, its schema against the one wcat speaks, which tools used it and how many rows it holds; changes nothing")
|
|
11
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")
|
|
12
|
+
.action(async (options) => print(options.json, itemOf(await storeInfo(env))));
|
|
13
|
+
const recover = annotate(store.command("recover"), { effects: LOCAL_READ })
|
|
14
|
+
.summary("what is damaged in the store and how to recover it")
|
|
15
|
+
.description("check every page and search index of the store, say what is damaged, what it means and the commands that recover it; changes nothing")
|
|
16
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")
|
|
17
|
+
.action(async (options) => {
|
|
18
|
+
const answer = await storeRecoveryCheck(env, "wcat");
|
|
19
|
+
print(options.json, itemOf(snakeKeys(answer)), recoveryNotes(answer).join("\n"));
|
|
20
|
+
});
|
|
21
|
+
annotate(recover.command("run"), { effects: LOCAL_WRITE })
|
|
22
|
+
.summary("rebuild a damaged store from every row it can read")
|
|
23
|
+
.description("copy every readable row into a new file with the sqlite3 program, rebuild the search indexes, mentions and vector index, " +
|
|
24
|
+
"check it, and put it in place of the store; the damaged file is kept beside it. Refuses while a WireCat timer or process has the store")
|
|
25
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")
|
|
26
|
+
.action(async (_options, command) => {
|
|
27
|
+
const answer = await storeRecoveryRun(env, {
|
|
28
|
+
command: "wcat",
|
|
29
|
+
version: VERSION,
|
|
30
|
+
note: (text) => streams.diagnostic(text),
|
|
31
|
+
});
|
|
32
|
+
// `recover` has its own --json, and commander gives it the flag even when it follows `run`.
|
|
33
|
+
const { json } = command.optsWithGlobals();
|
|
34
|
+
print(json, itemOf(snakeKeys(answer)), recoveryNotes(answer).join("\n"));
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=info-command.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { parseLocator } from "@wirecat/cli-core";
|
|
3
|
+
import { scopedAccounts } from "./group.js";
|
|
4
|
+
import { oneAccountOf, writeAccountOf } from "./source-list.js";
|
|
5
|
+
const choices = (keys) => keys.length ? `; choose one of ${keys.map(({ provider, account }) => `${provider}:${account}`).join(", ")}` : "";
|
|
6
|
+
export const selectAccount = async (store, env, scope) => {
|
|
7
|
+
const held = await scopedAccounts(store, env);
|
|
8
|
+
if (!scope.provider)
|
|
9
|
+
throw new CliError("validation_error", `give --account <provider>:<account>${choices(held)}`);
|
|
10
|
+
const matches = held.filter((key) => key.provider === scope.provider && (scope.account === undefined || key.account === scope.account));
|
|
11
|
+
if (matches.length !== 1)
|
|
12
|
+
throw new CliError(matches.length ? "validation_error" : "not_found", matches.length
|
|
13
|
+
? `several accounts match; give one${choices(matches)}`
|
|
14
|
+
: `the store holds no ${scope.provider} account matching this selection${choices(held)}`);
|
|
15
|
+
return matches[0];
|
|
16
|
+
};
|
|
17
|
+
/** The `meeting:<account id>/<meeting id>` reference for a meeting the selected account holds. */
|
|
18
|
+
export const meetingReference = async (store, env, id, scope) => {
|
|
19
|
+
if (!/^\d+$/.test(id))
|
|
20
|
+
throw new CliError("validation_error", "--meeting takes the meeting's id in the store");
|
|
21
|
+
const account = await store.accounts.storedAccount(await selectAccount(store, env, scope));
|
|
22
|
+
const found = await store.meetings.meeting(Number(id));
|
|
23
|
+
if (found === null || found.meeting.accountId !== account.id)
|
|
24
|
+
throw new CliError("not_found", `the ${account.provider} account ${account.account} holds no meeting ${id}`);
|
|
25
|
+
return `meeting:${account.id}/${found.meeting.id}`;
|
|
26
|
+
};
|
|
27
|
+
export const selectTarget = async (store, env, input) => {
|
|
28
|
+
const choices = ["message", "chat", "contact", "person", "task", "organization", "project", "meeting"];
|
|
29
|
+
const selected = choices.filter((name) => input[name] !== undefined);
|
|
30
|
+
if (selected.length !== 1)
|
|
31
|
+
throw new CliError("validation_error", "select exactly one of --message, --chat, --contact, --person, --task, --organization, --project or --meeting");
|
|
32
|
+
const type = selected[0];
|
|
33
|
+
if (type === "message") {
|
|
34
|
+
const locator = input.message;
|
|
35
|
+
let parsed;
|
|
36
|
+
try {
|
|
37
|
+
parsed = parseLocator(locator);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
throw new CliError("validation_error", "give a valid msg: source locator");
|
|
41
|
+
}
|
|
42
|
+
if ((input.provider && parsed.provider !== input.provider) || (input.account && parsed.account !== input.account))
|
|
43
|
+
throw new CliError("validation_error", "locator and selected account disagree");
|
|
44
|
+
return { key: { provider: parsed.provider, account: parsed.account }, target: { type, locator } };
|
|
45
|
+
}
|
|
46
|
+
return { key: await selectAccount(store, env, input), target: { type, id: input[type] } };
|
|
47
|
+
};
|
|
48
|
+
/** A write's `--account` as the scope the helpers above take, resolved only when given: a locator may name it. */
|
|
49
|
+
export const scopeOf = async (store, env, options, warn) => {
|
|
50
|
+
const value = writeAccountOf(options, warn);
|
|
51
|
+
return value === undefined ? {} : oneAccountOf(store, env, value, "--account");
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=scope.js.map
|