@wirecat/cli-core 0.605.0 → 0.607.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 +284 -1
- package/dist/calendar/index.d.ts +1 -0
- package/dist/calendar/index.js +1 -0
- package/dist/calendar/reads.js +5 -0
- package/dist/cli/app-mcp-command.d.ts +6 -2
- package/dist/cli/app-mcp-command.js +11 -2
- package/dist/cli/csv.d.ts +10 -0
- package/dist/cli/csv.js +22 -0
- package/dist/cli/early-refusal.d.ts +10 -0
- package/dist/cli/early-refusal.js +19 -0
- package/dist/cli/index.d.ts +4 -1
- package/dist/cli/index.js +4 -0
- package/dist/cli/profile-token.d.ts +29 -0
- package/dist/cli/profile-token.js +65 -0
- package/dist/cli/program.js +4 -2
- package/dist/cli/store-settings.js +38 -4
- package/dist/crm/cli/csv.d.ts +23 -0
- package/dist/crm/cli/csv.js +135 -0
- package/dist/crm/cli/index.d.ts +1 -1
- package/dist/crm/cli/index.js +36 -22
- package/dist/crm/cli/pipeline-view.d.ts +3 -0
- package/dist/crm/cli/pipeline-view.js +36 -0
- package/dist/crm/index.d.ts +2 -2
- package/dist/crm/index.js +1 -1
- package/dist/crm/source.d.ts +35 -5
- package/dist/crm/sync.d.ts +15 -7
- package/dist/crm/sync.js +169 -11
- package/dist/crm/writes.d.ts +6 -4
- package/dist/crm/writes.js +17 -13
- package/dist/documents.d.ts +2 -0
- package/dist/documents.js +2 -0
- package/dist/domain/business.d.ts +79 -0
- package/dist/domain/business.js +42 -0
- package/dist/domain/crm.d.ts +41 -2
- package/dist/domain/deals.d.ts +5 -2
- package/dist/domain/deals.js +5 -2
- package/dist/domain/finance.d.ts +2 -0
- package/dist/domain/finance.js +2 -2
- package/dist/domain/google-documents.d.ts +2 -0
- package/dist/domain/google-documents.js +3 -1
- package/dist/domain/money.d.ts +2 -0
- package/dist/domain/money.js +11 -3
- package/dist/domain/providers.d.ts +36 -1
- package/dist/domain/providers.js +69 -7
- package/dist/domain/record-fields.d.ts +42 -0
- package/dist/domain/record-fields.js +122 -0
- package/dist/domain/record-types.d.ts +489 -16
- package/dist/domain/record-types.js +374 -7
- package/dist/domain/records.d.ts +96 -5
- package/dist/domain/records.js +178 -32
- package/dist/domain/ref-summaries.js +5 -0
- package/dist/domain/references.d.ts +1 -1
- package/dist/domain/references.js +5 -0
- package/dist/domain/relations.d.ts +125 -0
- package/dist/domain/relations.js +107 -0
- package/dist/domain/vcard.d.ts +25 -0
- package/dist/domain/vcard.js +267 -0
- package/dist/entities/deal.d.ts +16 -2
- package/dist/entities/deal.js +5 -1
- package/dist/entities/index.d.ts +29 -13
- package/dist/entities/relationship.d.ts +8 -2
- package/dist/entities/relationship.js +8 -2
- package/dist/entities/task-results.d.ts +10 -10
- package/dist/errors/reasons.js +73 -2
- package/dist/fetch/addresses.d.ts +5 -0
- package/dist/fetch/addresses.js +76 -0
- package/dist/fetch/page.d.ts +64 -0
- package/dist/fetch/page.js +256 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +6 -3
- package/dist/mail/cli/review.js +20 -6
- package/dist/mail/index.d.ts +1 -1
- package/dist/mail/marks.d.ts +10 -5
- package/dist/mail/marks.js +16 -8
- package/dist/mail/review.d.ts +5 -0
- package/dist/meetings/calendar-text.d.ts +1 -1
- package/dist/meetings/calendar-text.js +4 -0
- package/dist/meetings/event-store.d.ts +2 -2
- package/dist/search/account-list.d.ts +4 -0
- package/dist/search/account-list.js +19 -8
- package/dist/search/query.js +2 -2
- package/dist/services/events-search.js +2 -2
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/ingest.d.ts +56 -8
- package/dist/services/ingest.js +95 -61
- package/dist/services/link-scorers/scan.js +2 -1
- package/dist/services/link-scorers/shared.js +2 -1
- package/dist/services/messages-search.js +3 -2
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/notes-search.js +1 -0
- package/dist/services/project-status/index.js +2 -1
- package/dist/services/proposals/kinds/contracts.d.ts +4 -0
- package/dist/services/proposals/kinds/contracts.js +9 -0
- package/dist/services/proposals/kinds/finance.d.ts +4 -0
- package/dist/services/proposals/kinds/finance.js +14 -35
- package/dist/services/proposals/kinds/orders.js +7 -30
- package/dist/services/proposals/kinds/shared.d.ts +27 -1
- package/dist/services/proposals/kinds/shared.js +34 -0
- package/dist/services/proposals/kinds/source-review.d.ts +4 -0
- package/dist/services/proposals/kinds/source-review.js +45 -0
- package/dist/services/proposals/kinds/subscriptions.d.ts +9 -0
- package/dist/services/proposals/kinds/subscriptions.js +24 -0
- package/dist/services/proposals/kinds/transactions.d.ts +4 -0
- package/dist/services/proposals/kinds/transactions.js +10 -0
- package/dist/services/proposals/registry.js +9 -0
- package/dist/services/search-all-meetings.js +2 -2
- package/dist/services/search-all.js +4 -3
- package/dist/services/search-kind.js +3 -3
- package/dist/services/stored-project-gathering.js +4 -3
- package/dist/store/decisions.js +5 -1
- package/dist/store/exports.d.ts +1 -0
- package/dist/store/exports.js +1 -0
- package/dist/store/index.d.ts +20 -4
- package/dist/store/index.js +4 -0
- package/dist/store/people.js +1 -1
- package/dist/store/project-transfer/request.d.ts +4 -1
- package/dist/store/project-transfer/schema.d.ts +9 -2
- package/dist/store/project-transfer/schema.js +4 -0
- package/dist/store/project-transfer/snapshot-model.d.ts +8 -2
- package/dist/store/source-review.d.ts +64 -0
- package/dist/store/source-review.js +7 -0
- package/dist/store/sqlite/accounts.d.ts +1 -1
- package/dist/store/sqlite/accounts.js +24 -1
- package/dist/store/sqlite/added-sources.d.ts +82 -0
- package/dist/store/sqlite/added-sources.js +237 -0
- package/dist/store/sqlite/business-contracts.d.ts +90 -0
- package/dist/store/sqlite/business-contracts.js +182 -0
- package/dist/store/sqlite/calendar-events.js +7 -3
- package/dist/store/sqlite/calendar-forget.js +3 -0
- package/dist/store/sqlite/calendar.d.ts +21 -1
- package/dist/store/sqlite/calendar.js +27 -7
- package/dist/store/sqlite/chat-rekey.js +7 -0
- package/dist/store/sqlite/chats.d.ts +3 -1
- package/dist/store/sqlite/chats.js +15 -1
- package/dist/store/sqlite/crm-rows.d.ts +44 -0
- package/dist/store/sqlite/crm-rows.js +195 -0
- package/dist/store/sqlite/crm-settings.d.ts +28 -0
- package/dist/store/sqlite/crm-settings.js +80 -0
- package/dist/store/sqlite/crm.d.ts +42 -11
- package/dist/store/sqlite/crm.js +402 -196
- package/dist/store/sqlite/deals.d.ts +4 -8
- package/dist/store/sqlite/deals.js +8 -5
- package/dist/store/sqlite/document-transfer/snapshot.js +2 -2
- package/dist/store/sqlite/emails.js +2 -0
- package/dist/store/sqlite/entity-types.d.ts +14 -9
- package/dist/store/sqlite/entity-types.js +4 -10
- package/dist/store/sqlite/evidence-signature.d.ts +114 -0
- package/dist/store/sqlite/evidence-signature.js +349 -0
- package/dist/store/sqlite/evidence-sources.d.ts +2 -1
- package/dist/store/sqlite/evidence-sources.js +7 -3
- package/dist/store/sqlite/facts.d.ts +7 -2
- package/dist/store/sqlite/facts.js +21 -5
- package/dist/store/sqlite/finance.d.ts +18 -105
- package/dist/store/sqlite/finance.js +100 -219
- package/dist/store/sqlite/involvement-queue.js +4 -3
- package/dist/store/sqlite/knowledge.d.ts +14 -4
- package/dist/store/sqlite/knowledge.js +108 -102
- package/dist/store/sqlite/labelled.d.ts +3 -0
- package/dist/store/sqlite/labelled.js +11 -0
- package/dist/store/sqlite/link-kinds.d.ts +4 -3
- package/dist/store/sqlite/link-kinds.js +6 -2
- package/dist/store/sqlite/manifest.js +7 -0
- package/dist/store/sqlite/memories.d.ts +24 -10
- package/dist/store/sqlite/memories.js +73 -19
- package/dist/store/sqlite/messages.js +2 -0
- package/dist/store/sqlite/migrations.generated.js +134 -0
- package/dist/store/sqlite/money-lines.d.ts +48 -0
- package/dist/store/sqlite/money-lines.js +76 -0
- package/dist/store/sqlite/money-transactions.d.ts +132 -0
- package/dist/store/sqlite/money-transactions.js +295 -0
- package/dist/store/sqlite/notes.d.ts +14 -4
- package/dist/store/sqlite/notes.js +43 -31
- package/dist/store/sqlite/orders.d.ts +36 -6
- package/dist/store/sqlite/orders.js +126 -46
- package/dist/store/sqlite/organizations.d.ts +8 -0
- package/dist/store/sqlite/organizations.js +14 -0
- package/dist/store/sqlite/payment-facts.js +1 -1
- package/dist/store/sqlite/person-preparation.d.ts +1 -1
- package/dist/store/sqlite/person-preparation.js +3 -2
- package/dist/store/sqlite/private-people.js +2 -0
- package/dist/store/sqlite/products.d.ts +78 -0
- package/dist/store/sqlite/products.js +131 -0
- package/dist/store/sqlite/project-transfer/records.js +39 -3
- package/dist/store/sqlite/project-transfer/snapshot.d.ts +4 -1
- package/dist/store/sqlite/project-transfer/snapshot.js +11 -3
- package/dist/store/sqlite/proposed-actions.d.ts +1 -1
- package/dist/store/sqlite/proposed-actions.js +24 -7
- package/dist/store/sqlite/providers.d.ts +0 -4
- package/dist/store/sqlite/providers.js +20 -2
- package/dist/store/sqlite/record-matching.d.ts +80 -0
- package/dist/store/sqlite/record-matching.js +264 -0
- package/dist/store/sqlite/record-projection.d.ts +89 -0
- package/dist/store/sqlite/record-projection.js +50 -0
- package/dist/store/sqlite/record-projectors-direct.d.ts +17 -0
- package/dist/store/sqlite/record-projectors-direct.js +125 -0
- package/dist/store/sqlite/record-projectors-money.d.ts +26 -0
- package/dist/store/sqlite/record-projectors-money.js +214 -0
- package/dist/store/sqlite/record-projectors-phone.d.ts +28 -0
- package/dist/store/sqlite/record-projectors-phone.js +212 -0
- package/dist/store/sqlite/record-projectors.d.ts +3 -44
- package/dist/store/sqlite/record-projectors.js +7 -67
- package/dist/store/sqlite/record-relations.d.ts +24 -0
- package/dist/store/sqlite/record-relations.js +92 -0
- package/dist/store/sqlite/record-remap.d.ts +12 -0
- package/dist/store/sqlite/record-remap.js +92 -0
- package/dist/store/sqlite/record-run.d.ts +71 -0
- package/dist/store/sqlite/record-run.js +179 -0
- package/dist/store/sqlite/record-settling.d.ts +9 -0
- package/dist/store/sqlite/record-settling.js +74 -0
- package/dist/store/sqlite/record-stamps.d.ts +13 -0
- package/dist/store/sqlite/record-stamps.js +30 -0
- package/dist/store/sqlite/record-writes.d.ts +43 -0
- package/dist/store/sqlite/record-writes.js +307 -0
- package/dist/store/sqlite/records.d.ts +52 -42
- package/dist/store/sqlite/records.js +123 -353
- package/dist/store/sqlite/ref-summaries.d.ts +6 -5
- package/dist/store/sqlite/ref-summaries.js +60 -8
- package/dist/store/sqlite/refunds.d.ts +31 -0
- package/dist/store/sqlite/refunds.js +112 -0
- package/dist/store/sqlite/relation-list.d.ts +43 -0
- package/dist/store/sqlite/relation-list.js +133 -0
- package/dist/store/sqlite/relation-proposals.d.ts +28 -6
- package/dist/store/sqlite/relation-proposals.js +134 -10
- package/dist/store/sqlite/relation-reads.d.ts +8 -0
- package/dist/store/sqlite/relation-reads.js +7 -0
- package/dist/store/sqlite/relation-roles.d.ts +26 -0
- package/dist/store/sqlite/relation-roles.js +91 -0
- package/dist/store/sqlite/reported-relations.d.ts +63 -0
- package/dist/store/sqlite/reported-relations.js +132 -0
- package/dist/store/sqlite/reviewed.d.ts +109 -0
- package/dist/store/sqlite/reviewed.js +173 -0
- package/dist/store/sqlite/schema/link-revisions.d.ts +136 -0
- package/dist/store/sqlite/schema/link-revisions.js +11 -0
- package/dist/store/sqlite/schema/links.d.ts +360 -0
- package/dist/store/sqlite/schema/links.js +32 -0
- package/dist/store/sqlite/schema.d.ts +2769 -306
- package/dist/store/sqlite/schema.js +258 -25
- package/dist/store/sqlite/source-review-marks.d.ts +54 -0
- package/dist/store/sqlite/source-review-marks.js +143 -0
- package/dist/store/sqlite/source-review.d.ts +54 -0
- package/dist/store/sqlite/source-review.js +221 -0
- package/dist/store/sqlite/stage-amounts.d.ts +14 -0
- package/dist/store/sqlite/stage-amounts.js +23 -0
- package/dist/store/sqlite/subscriptions.d.ts +135 -0
- package/dist/store/sqlite/subscriptions.js +294 -0
- package/dist/store/sqlite/text-input.d.ts +3 -0
- package/dist/store/sqlite/text-input.js +13 -0
- package/dist/store/sqlite/things.js +2 -9
- package/dist/store/sqlite/transaction.d.ts +15 -0
- package/dist/store/sqlite/transaction.js +57 -0
- package/dist/store/sqlite/wallets.d.ts +88 -0
- package/dist/store/sqlite/wallets.js +143 -0
- package/dist/store/store-errors.d.ts +1 -0
- package/dist/store/store-errors.js +45 -0
- package/dist/store/store.d.ts +19 -1
- package/dist/store/store.js +35 -6
- package/package.json +6 -3
- package/schemas/examples/records-business.jsonl +11 -0
- package/schemas/records-envelope.v1.schema.json +1160 -5
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { fold } from "../normalize.js";
|
|
3
|
+
import { forgetEvidenceToRow } from "./evidence-signature.js";
|
|
3
4
|
import { resolvePersonLinks } from "./person-resolution.js";
|
|
4
5
|
import { toIso } from "./values.js";
|
|
5
6
|
const required = ({ database }, key, personId) => {
|
|
@@ -81,6 +82,7 @@ export const editNote = (context, key, personId, id, text, revision) => {
|
|
|
81
82
|
};
|
|
82
83
|
export const removeNote = (context, key, personId, id) => {
|
|
83
84
|
note(context, key, personId, id);
|
|
85
|
+
forgetEvidenceToRow(context.database, { type: "note", id: Number(id) }, context.now());
|
|
84
86
|
context.database.prepare("DELETE FROM note_revisions WHERE note_id=?").run(id);
|
|
85
87
|
context.database.prepare("DELETE FROM notes WHERE id=?").run(id);
|
|
86
88
|
return { id, personId, removed: true };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type CatalogKind } from "../../domain/business.js";
|
|
2
|
+
import { type Author } from "./memories.js";
|
|
3
|
+
import type { StoreContext } from "./open.js";
|
|
4
|
+
import { type AuthorInfo, type Party } from "./reviewed.js";
|
|
5
|
+
export interface Product {
|
|
6
|
+
id: string;
|
|
7
|
+
ref: string;
|
|
8
|
+
/** One line, as a list prints it. */
|
|
9
|
+
title: string;
|
|
10
|
+
kind: CatalogKind;
|
|
11
|
+
name: string;
|
|
12
|
+
sku: string | null;
|
|
13
|
+
/** `null` for the owner's own item. */
|
|
14
|
+
supplier: Party | null;
|
|
15
|
+
unit: string | null;
|
|
16
|
+
/** Both `null` when it has no price. */
|
|
17
|
+
unitPrice: string | null;
|
|
18
|
+
currency: string | null;
|
|
19
|
+
description: string | null;
|
|
20
|
+
/** `YYYY-MM-DD`: no longer sold; its lines and subscriptions keep pointing at it. */
|
|
21
|
+
archivedDate: string | null;
|
|
22
|
+
author: AuthorInfo;
|
|
23
|
+
model: string | null;
|
|
24
|
+
source: string;
|
|
25
|
+
createdAt: string;
|
|
26
|
+
updatedAt: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ProductInput {
|
|
29
|
+
/** The owner and an agent write alike: a product feeds no total. */
|
|
30
|
+
by: Author;
|
|
31
|
+
/** `product` when left out. */
|
|
32
|
+
kind?: CatalogKind;
|
|
33
|
+
name: string;
|
|
34
|
+
sku?: string;
|
|
35
|
+
/** `person:` or `organization:`; the owner's own item when left out. */
|
|
36
|
+
supplier?: string;
|
|
37
|
+
unit?: string;
|
|
38
|
+
/** A decimal string in `currency`; give both or neither. */
|
|
39
|
+
unitPrice?: string;
|
|
40
|
+
currency?: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
/** Where an agent's row came from, such as `agent`; the owner's is always `owner`. */
|
|
43
|
+
source?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface ProductUpdate {
|
|
46
|
+
by: Author;
|
|
47
|
+
name?: string;
|
|
48
|
+
unit?: string | null;
|
|
49
|
+
/** Give both, or neither. A new price changes no line: each line holds its own copy; `null` for both drops it. */
|
|
50
|
+
unitPrice?: string | null;
|
|
51
|
+
currency?: string | null;
|
|
52
|
+
description?: string | null;
|
|
53
|
+
/** `YYYY-MM-DD` to stop selling it, `null` to sell it again. */
|
|
54
|
+
archivedDate?: string | null;
|
|
55
|
+
}
|
|
56
|
+
export interface ProductFilter {
|
|
57
|
+
kind?: CatalogKind;
|
|
58
|
+
supplier?: string;
|
|
59
|
+
/** `true` only archived ones, `false` only those still sold; both when left out. */
|
|
60
|
+
archived?: boolean;
|
|
61
|
+
/** Words of the name, in any letter case. */
|
|
62
|
+
name?: string;
|
|
63
|
+
/** 1–500, 100 by default; by name. */
|
|
64
|
+
limit?: number;
|
|
65
|
+
}
|
|
66
|
+
/** What the owner or a supplier sells, written directly by the owner or an agent. */
|
|
67
|
+
export interface ProductsStore {
|
|
68
|
+
add(input: ProductInput): Promise<Product>;
|
|
69
|
+
get(reference: string): Promise<Product>;
|
|
70
|
+
list(filter?: ProductFilter): Promise<Product[]>;
|
|
71
|
+
update(reference: string, input: ProductUpdate): Promise<Product>;
|
|
72
|
+
}
|
|
73
|
+
type ProductOperations = {
|
|
74
|
+
[K in keyof ProductsStore]: ProductsStore[K] extends (...args: infer A) => Promise<infer R> ? (...args: A) => R : never;
|
|
75
|
+
};
|
|
76
|
+
export declare const productOperationsOver: (context: StoreContext) => ProductOperations;
|
|
77
|
+
export declare const productsStoreOver: (context: StoreContext) => ProductsStore;
|
|
78
|
+
export {};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { CATALOG_KINDS, productLine } from "../../domain/business.js";
|
|
2
|
+
import { currencyOf, formatDecimal, minorUnits, scaleOf } from "../../domain/money.js";
|
|
3
|
+
import { fold } from "../normalize.js";
|
|
4
|
+
import { authorActor, authorOf } from "./memories.js";
|
|
5
|
+
import { requiredThing } from "./notes.js";
|
|
6
|
+
import { iso, isoDate, limitOf, oneOf, refuse, reviewedRowsOver, text, } from "./reviewed.js";
|
|
7
|
+
import { write } from "./transaction.js";
|
|
8
|
+
const PRODUCTS = "SELECT c.*, b.name AS author_name, b.kind AS author_kind FROM catalog_items c " +
|
|
9
|
+
"LEFT JOIN bots b ON c.author_type = 'bot' AND b.id = c.author_id";
|
|
10
|
+
export const productOperationsOver = (context) => {
|
|
11
|
+
const { database, now } = context;
|
|
12
|
+
const { partyOf, partyThing } = reviewedRowsOver(context);
|
|
13
|
+
const productOf = (row) => {
|
|
14
|
+
const currency = row.currency == null ? null : String(row.currency);
|
|
15
|
+
const units = row.unit_price == null || currency === null ? null : Number(row.unit_price);
|
|
16
|
+
const fields = {
|
|
17
|
+
name: String(row.name),
|
|
18
|
+
kind: row.kind,
|
|
19
|
+
unitPrice: units,
|
|
20
|
+
currency,
|
|
21
|
+
unit: row.unit == null ? null : String(row.unit),
|
|
22
|
+
archived: row.archived_date != null,
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
id: String(row.id),
|
|
26
|
+
ref: `product:${row.id}`,
|
|
27
|
+
title: productLine(fields),
|
|
28
|
+
kind: fields.kind,
|
|
29
|
+
name: fields.name,
|
|
30
|
+
sku: row.sku == null ? null : String(row.sku),
|
|
31
|
+
supplier: partyOf(row.supplier_type, row.supplier_id),
|
|
32
|
+
unit: fields.unit,
|
|
33
|
+
unitPrice: units === null || currency === null ? null : formatDecimal(units, scaleOf(currency)),
|
|
34
|
+
currency,
|
|
35
|
+
description: row.description == null ? null : String(row.description),
|
|
36
|
+
archivedDate: row.archived_date == null ? null : String(row.archived_date),
|
|
37
|
+
author: authorOf(row),
|
|
38
|
+
model: row.model == null ? null : String(row.model),
|
|
39
|
+
source: String(row.source),
|
|
40
|
+
createdAt: iso(row.created_at),
|
|
41
|
+
updatedAt: iso(row.updated_at),
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
const rowOf = (reference) => {
|
|
45
|
+
const thing = requiredThing(database, reference.includes(":") ? reference : `product:${reference}`, "the product");
|
|
46
|
+
if (thing.type !== "product")
|
|
47
|
+
return refuse(`${reference} is not a product`, "product.ref");
|
|
48
|
+
return database.prepare(`${PRODUCTS} WHERE c.id = ?`).get(thing.id);
|
|
49
|
+
};
|
|
50
|
+
const priceOf = (unitPrice, currency) => {
|
|
51
|
+
if ((unitPrice == null) !== (currency == null))
|
|
52
|
+
refuse("a product's price and currency come together", "product.field");
|
|
53
|
+
if (unitPrice == null || currency == null)
|
|
54
|
+
return { units: null, currency: null };
|
|
55
|
+
const code = currencyOf(currency);
|
|
56
|
+
return { units: minorUnits(unitPrice, code, "a product's price"), currency: code };
|
|
57
|
+
};
|
|
58
|
+
const skuTaken = (sku, supplier, except) => database
|
|
59
|
+
.prepare("SELECT id FROM catalog_items WHERE sku = ? AND deleted_at IS NULL AND supplier_type IS ? AND supplier_id IS ? " +
|
|
60
|
+
"AND id IS NOT ?")
|
|
61
|
+
.get(sku, supplier?.type ?? null, supplier?.id ?? null, except);
|
|
62
|
+
return {
|
|
63
|
+
add: (input) => {
|
|
64
|
+
const kind = input.kind === undefined ? "product" : oneOf(input.kind, CATALOG_KINDS, "a product's kind");
|
|
65
|
+
const name = text(input.name, "a product's name", 200) ?? refuse("a product needs a name", "product.field");
|
|
66
|
+
const sku = text(input.sku, "a product's code", 80);
|
|
67
|
+
const unit = text(input.unit, "a product's unit", 40);
|
|
68
|
+
const description = text(input.description, "a product's description", 2000);
|
|
69
|
+
const price = priceOf(input.unitPrice, input.currency);
|
|
70
|
+
const id = write(database, () => {
|
|
71
|
+
const supplier = partyThing(input.supplier, "the supplier");
|
|
72
|
+
if (sku !== null && skuTaken(sku, supplier, null))
|
|
73
|
+
refuse(`a product with the code ${sku} is already stored for that supplier`, "product.duplicate");
|
|
74
|
+
const { actor, model } = authorActor(context, input.by);
|
|
75
|
+
const source = input.by === "owner" ? "owner" : (text(input.source, "a source", 80) ?? "agent");
|
|
76
|
+
const at = now();
|
|
77
|
+
return Number(database
|
|
78
|
+
.prepare("INSERT INTO catalog_items (kind, name, name_folded, sku, supplier_type, supplier_id, unit, unit_price, " +
|
|
79
|
+
"currency, description, author_type, author_id, model, source, created_at, updated_at) " +
|
|
80
|
+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id")
|
|
81
|
+
.get(kind, name, fold(name), sku, supplier?.type ?? null, supplier?.id ?? null, unit, price.units, price.currency, description, actor.type, actor.id, model, source, at, at)?.id);
|
|
82
|
+
});
|
|
83
|
+
return productOf(rowOf(`product:${id}`));
|
|
84
|
+
},
|
|
85
|
+
get: (reference) => productOf(rowOf(reference)),
|
|
86
|
+
list: (filter = {}) => {
|
|
87
|
+
const kind = filter.kind === undefined ? null : oneOf(filter.kind, CATALOG_KINDS, "a kind");
|
|
88
|
+
const supplier = partyThing(filter.supplier, "the supplier");
|
|
89
|
+
const archived = filter.archived === undefined ? null : filter.archived ? 1 : 0;
|
|
90
|
+
const words = filter.name === undefined ? [] : fold(filter.name).split(/\s+/).filter(Boolean);
|
|
91
|
+
const limit = limitOf(filter.limit);
|
|
92
|
+
return database
|
|
93
|
+
.prepare(`${PRODUCTS} WHERE c.deleted_at IS NULL AND (? IS NULL OR c.kind = ?) ` +
|
|
94
|
+
"AND (? IS NULL OR (c.supplier_type = ? AND c.supplier_id = ?)) " +
|
|
95
|
+
"AND (? IS NULL OR (c.archived_date IS NOT NULL) = ?) ORDER BY c.name_folded, c.id")
|
|
96
|
+
.all(kind, kind, supplier?.type ?? null, supplier?.type ?? null, supplier?.id ?? null, archived, archived)
|
|
97
|
+
.filter((row) => words.every((word) => String(row.name_folded).includes(word)))
|
|
98
|
+
.slice(0, limit)
|
|
99
|
+
.map(productOf);
|
|
100
|
+
},
|
|
101
|
+
update: (reference, input) => {
|
|
102
|
+
const row = rowOf(reference);
|
|
103
|
+
if (row.deleted_at != null)
|
|
104
|
+
refuse(`product:${row.id} is deleted`, "product.ref");
|
|
105
|
+
authorActor(context, input.by);
|
|
106
|
+
const name = input.name === undefined ? String(row.name) : text(input.name, "a product's name", 200);
|
|
107
|
+
const unit = input.unit === undefined ? row.unit : text(input.unit, "a product's unit", 40);
|
|
108
|
+
const description = input.description === undefined ? row.description : text(input.description, "a product's description", 2000);
|
|
109
|
+
const price = input.unitPrice === undefined && input.currency === undefined
|
|
110
|
+
? { units: row.unit_price, currency: row.currency }
|
|
111
|
+
: priceOf(input.unitPrice, input.currency);
|
|
112
|
+
const archived = input.archivedDate === undefined ? row.archived_date : isoDate(input.archivedDate, "the day it stopped selling");
|
|
113
|
+
write(database, () => {
|
|
114
|
+
database
|
|
115
|
+
.prepare("UPDATE catalog_items SET name = ?, name_folded = ?, unit = ?, unit_price = ?, currency = ?, description = ?, " +
|
|
116
|
+
"archived_date = ?, updated_at = ? WHERE id = ?")
|
|
117
|
+
.run(name, fold(name), unit, price.units, price.currency, description, archived, now(), Number(row.id));
|
|
118
|
+
});
|
|
119
|
+
return productOf(rowOf(`product:${row.id}`));
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
export const productsStoreOver = (context) => {
|
|
124
|
+
const operations = productOperationsOver(context);
|
|
125
|
+
return {
|
|
126
|
+
add: async (input) => operations.add(input),
|
|
127
|
+
get: async (reference) => operations.get(reference),
|
|
128
|
+
list: async (filter) => operations.list(filter),
|
|
129
|
+
update: async (reference, input) => operations.update(reference, input),
|
|
130
|
+
};
|
|
131
|
+
};
|
|
@@ -1,7 +1,32 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { fold } from "../../normalize.js";
|
|
3
|
+
import { isEntityType } from "../entity-types.js";
|
|
4
|
+
import { evidenceMetadata, evidenceSignature } from "../evidence-signature.js";
|
|
3
5
|
import { nextId } from "../memories.js";
|
|
4
6
|
import { thingOf } from "../things.js";
|
|
7
|
+
const metadataOf = (database, link, to) => {
|
|
8
|
+
const provenance = link.provenance === null ? {} : { provenance: link.provenance };
|
|
9
|
+
if (link.kind === "evidence" && to)
|
|
10
|
+
return JSON.stringify({
|
|
11
|
+
...provenance,
|
|
12
|
+
...evidenceMetadata(evidenceSignature(database, to), link.updated_at, undefined),
|
|
13
|
+
});
|
|
14
|
+
if (link.kind === "evidence")
|
|
15
|
+
return JSON.stringify({ ...provenance, ...goneEvidence(link) });
|
|
16
|
+
return link.provenance === null ? null : JSON.stringify(provenance);
|
|
17
|
+
};
|
|
18
|
+
/** Evidence whose source was deleted for good travels with only its old reference, and stays gone. */
|
|
19
|
+
const goneEvidence = (link) => {
|
|
20
|
+
const kind = link.target_text?.split(":")[0] ?? "";
|
|
21
|
+
return {
|
|
22
|
+
v: 1,
|
|
23
|
+
sig: "gone",
|
|
24
|
+
rev: null,
|
|
25
|
+
cited_rev: null,
|
|
26
|
+
checked_at: link.updated_at,
|
|
27
|
+
gone: isEntityType(kind) ? kind : "source",
|
|
28
|
+
};
|
|
29
|
+
};
|
|
5
30
|
export const restoreAnnotationRecords = (database, projectId, snapshot, bindings) => {
|
|
6
31
|
const mappings = { ...bindings };
|
|
7
32
|
const resolve = (ref) => {
|
|
@@ -43,11 +68,22 @@ export const restoreAnnotationRecords = (database, projectId, snapshot, bindings
|
|
|
43
68
|
const from = resolve(link.from), to = resolve(link.to);
|
|
44
69
|
if (!from)
|
|
45
70
|
throw new CliError("validation_error", "project annotation link source is required");
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
.
|
|
71
|
+
// A relationship the store already holds under its unique key keeps that row: the snapshot maps onto it.
|
|
72
|
+
const made = database
|
|
73
|
+
.prepare("INSERT INTO links(from_type,from_id,to_type,to_id,kind,anchor,source,target_text,target_folded,role,evidence,metadata,confirmed,created_at,author,updated_at,starts_at,ends_at,deleted_at) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ON CONFLICT DO NOTHING RETURNING id")
|
|
74
|
+
.get(from.type, from.id, to?.type ?? null, to?.id ?? null, link.kind, link.anchor, link.origin, link.target_text, link.target_text === null || (link.kind === "evidence" && to === null) ? null : fold(link.target_text), link.role, link.evidence, metadataOf(database, link, to), Number(link.confirmed), link.created_at, link.author, link.updated_at, link.starts_at ?? null, link.ends_at ?? null, link.deleted_at ?? null);
|
|
75
|
+
const row = made ??
|
|
76
|
+
database
|
|
77
|
+
.prepare("SELECT id FROM links WHERE kind=? AND from_type=? AND from_id=? AND to_type IS ? AND to_id IS ? " +
|
|
78
|
+
"AND ifnull(anchor,'')=ifnull(?,'') AND ifnull(role,'')=ifnull(?,'') AND account_id IS NULL")
|
|
79
|
+
.get(link.kind, from.type, from.id, to?.type ?? null, to?.id ?? null, link.anchor, link.role);
|
|
49
80
|
if (!row)
|
|
50
81
|
throw new CliError("configuration_error", "project annotation link insertion failed");
|
|
82
|
+
// The owner confirmed it where the snapshot was taken: the row it maps onto says so too.
|
|
83
|
+
if (!made && link.confirmed)
|
|
84
|
+
database
|
|
85
|
+
.prepare("UPDATE links SET confirmed = 1, updated_at = max(updated_at, ?) WHERE id = ? AND confirmed = 0")
|
|
86
|
+
.run(link.updated_at, Number(row.id));
|
|
51
87
|
mappings[link.ref] = `link:${row.id}`;
|
|
52
88
|
}
|
|
53
89
|
return mappings;
|
|
@@ -23,7 +23,7 @@ export declare const projectAnnotationSnapshot: (database: CacheDatabase, projec
|
|
|
23
23
|
ref: string;
|
|
24
24
|
from: string;
|
|
25
25
|
to: string | null;
|
|
26
|
-
kind: "about" | "answered-by" | "assigned-to" | "attached" | "blocked-by" | "created-from" | "duplicate-of" | "evidence" | "follow-up-of" | "labelled" | "links-to" | "member-of" | "related-to";
|
|
26
|
+
kind: "about" | "answered-by" | "assigned-to" | "attached" | "blocked-by" | "created-from" | "customer-of" | "duplicate-of" | "evidence" | "follow-up-of" | "labelled" | "links-to" | "member-of" | "partner-of" | "related-to" | "reports-to";
|
|
27
27
|
origin: "file" | "message" | "owner" | "suggested";
|
|
28
28
|
anchor: string | null;
|
|
29
29
|
target_text: string | null;
|
|
@@ -34,6 +34,9 @@ export declare const projectAnnotationSnapshot: (database: CacheDatabase, projec
|
|
|
34
34
|
created_at: number;
|
|
35
35
|
updated_at: number;
|
|
36
36
|
author: string | null;
|
|
37
|
+
starts_at?: number | undefined;
|
|
38
|
+
ends_at?: number | undefined;
|
|
39
|
+
deleted_at?: number | undefined;
|
|
37
40
|
}[];
|
|
38
41
|
external: {
|
|
39
42
|
ref: string;
|
|
@@ -12,7 +12,9 @@ const flag = (value) => {
|
|
|
12
12
|
return unsupported();
|
|
13
13
|
return value === 1;
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
/** An evidence link's signature describes a row of this store, so it does not travel; the restore signs it anew. */
|
|
16
|
+
const SIGNATURE_KEYS = new Set(["v", "sig", "rev", "cited_rev", "quote", "checked_at", "gone"]);
|
|
17
|
+
const provenance = (raw, kind) => {
|
|
16
18
|
if (raw === null)
|
|
17
19
|
return null;
|
|
18
20
|
let value;
|
|
@@ -25,7 +27,7 @@ const provenance = (raw) => {
|
|
|
25
27
|
if (!value ||
|
|
26
28
|
typeof value !== "object" ||
|
|
27
29
|
Array.isArray(value) ||
|
|
28
|
-
Object.keys(value).some((key) => key !== "provenance"))
|
|
30
|
+
Object.keys(value).some((key) => key !== "provenance" && !(kind === "evidence" && SIGNATURE_KEYS.has(key))))
|
|
29
31
|
return unsupported();
|
|
30
32
|
const text = value.provenance;
|
|
31
33
|
if (text !== undefined && text !== null && typeof text !== "string")
|
|
@@ -107,6 +109,9 @@ export const projectAnnotationSnapshot = (database, projectId, budget) => read(d
|
|
|
107
109
|
"author",
|
|
108
110
|
"created_at",
|
|
109
111
|
"updated_at",
|
|
112
|
+
"starts_at",
|
|
113
|
+
"ends_at",
|
|
114
|
+
"deleted_at",
|
|
110
115
|
], [projectId, projectId, projectId, projectId]);
|
|
111
116
|
const projectRef = `project:${projectId}`;
|
|
112
117
|
const owned = new Set([projectRef, ...facts.map((row) => `fact:${row.id}`)]);
|
|
@@ -172,10 +177,13 @@ export const projectAnnotationSnapshot = (database, projectId, budget) => read(d
|
|
|
172
177
|
role: nullableText(row.role),
|
|
173
178
|
evidence: nullableText(row.evidence),
|
|
174
179
|
confirmed: flag(row.confirmed),
|
|
175
|
-
provenance: provenance(row.metadata),
|
|
180
|
+
provenance: provenance(row.metadata, row.kind),
|
|
176
181
|
created_at: row.created_at,
|
|
177
182
|
updated_at: row.updated_at,
|
|
178
183
|
author: nullableText(row.author),
|
|
184
|
+
...(row.starts_at == null ? {} : { starts_at: row.starts_at }),
|
|
185
|
+
...(row.ends_at == null ? {} : { ends_at: row.ends_at }),
|
|
186
|
+
...(row.deleted_at == null ? {} : { deleted_at: row.deleted_at }),
|
|
179
187
|
})),
|
|
180
188
|
};
|
|
181
189
|
const snapshot = decodeProjectAnnotationSnapshot(JSON.stringify({ ...data, external: sources.external(owned) }));
|
|
@@ -83,7 +83,7 @@ type ProposalOperations = Omit<{
|
|
|
83
83
|
/** Who proposed an action, for `mayDecide`. */
|
|
84
84
|
export declare const proposerOfAction: ({ proposedBy, payload }: ProposedAction) => Proposer;
|
|
85
85
|
export declare const proposalOperationsOver: (context: StoreContext) => ProposalOperations;
|
|
86
|
-
/** Refuses a
|
|
86
|
+
/** Refuses a dedicated kind on a generic action path: approving one as an action would skip its own checks. */
|
|
87
87
|
export declare const assertGenericAction: (kind: string) => void;
|
|
88
88
|
export declare const proposedActionsStoreOver: (context: StoreContext) => ProposedActionsStore;
|
|
89
89
|
export {};
|
|
@@ -3,6 +3,7 @@ import { MEETING_FINDINGS_KIND } from "../../meetings/index.js";
|
|
|
3
3
|
import { assertMayDecide, deciderAuthor } from "../decisions.js";
|
|
4
4
|
import { EVIDENCE_FINDINGS_KIND } from "../evidence-findings.js";
|
|
5
5
|
import { MAIL_FINDINGS_KIND } from "../mail-findings.js";
|
|
6
|
+
import { SOURCE_REVIEW_KIND } from "../source-review.js";
|
|
6
7
|
import { proposedBySql } from "./actors.js";
|
|
7
8
|
import { authorActor } from "./memories.js";
|
|
8
9
|
import { requiredThing } from "./notes.js";
|
|
@@ -164,17 +165,31 @@ export const proposalOperationsOver = (context) => {
|
|
|
164
165
|
},
|
|
165
166
|
};
|
|
166
167
|
};
|
|
167
|
-
|
|
168
|
+
const FINDINGS_COMMAND = "the dedicated findings command";
|
|
169
|
+
/** Stored kinds a generic action path never decides: each has its own review, which checks what it cites. */
|
|
168
170
|
const DEDICATED_REVIEW = {
|
|
169
|
-
[MEETING_FINDINGS_KIND]: {
|
|
170
|
-
|
|
171
|
-
|
|
171
|
+
[MEETING_FINDINGS_KIND]: {
|
|
172
|
+
what: "meeting findings",
|
|
173
|
+
reason: "meeting-findings.dedicated-review",
|
|
174
|
+
through: FINDINGS_COMMAND,
|
|
175
|
+
},
|
|
176
|
+
[EVIDENCE_FINDINGS_KIND]: {
|
|
177
|
+
what: "evidence findings",
|
|
178
|
+
reason: "evidence-findings.dedicated-review",
|
|
179
|
+
through: FINDINGS_COMMAND,
|
|
180
|
+
},
|
|
181
|
+
[MAIL_FINDINGS_KIND]: { what: "mail findings", reason: "mail-findings.dedicated-review", through: FINDINGS_COMMAND },
|
|
182
|
+
[SOURCE_REVIEW_KIND]: {
|
|
183
|
+
what: "a source review",
|
|
184
|
+
reason: "source-review.dedicated-review",
|
|
185
|
+
through: "the review of memories and facts, which signs their sources again",
|
|
186
|
+
},
|
|
172
187
|
};
|
|
173
|
-
/** Refuses a
|
|
188
|
+
/** Refuses a dedicated kind on a generic action path: approving one as an action would skip its own checks. */
|
|
174
189
|
export const assertGenericAction = (kind) => {
|
|
175
190
|
const dedicated = DEDICATED_REVIEW[kind];
|
|
176
191
|
if (dedicated)
|
|
177
|
-
throw new CliError("validation_error", `review ${dedicated.what} through
|
|
192
|
+
throw new CliError("validation_error", `review ${dedicated.what} through ${dedicated.through}`, {
|
|
178
193
|
reason: dedicated.reason,
|
|
179
194
|
});
|
|
180
195
|
};
|
|
@@ -189,7 +204,9 @@ export const proposedActionsStoreOver = (context) => {
|
|
|
189
204
|
propose: async (input) => {
|
|
190
205
|
const dedicated = DEDICATED_REVIEW[input.kind];
|
|
191
206
|
if (dedicated)
|
|
192
|
-
throw new CliError("validation_error", `stage ${dedicated.what} through
|
|
207
|
+
throw new CliError("validation_error", `stage ${dedicated.what} through ${dedicated.through}`, {
|
|
208
|
+
reason: dedicated.reason,
|
|
209
|
+
});
|
|
193
210
|
return operations.propose(input);
|
|
194
211
|
},
|
|
195
212
|
get: async (id) => operations.get(id),
|
|
@@ -5,8 +5,4 @@ export declare const PROVIDERS_SETTING = "providers";
|
|
|
5
5
|
export declare const storedProvidersOf: (database: CacheDatabase) => unknown[];
|
|
6
6
|
/** Called on every open: the module state follows the store the process opened last. */
|
|
7
7
|
export declare const loadProviders: (database: CacheDatabase) => void;
|
|
8
|
-
/**
|
|
9
|
-
* Writes `entry` over the stored one of its name and loads the result. Every run of every CLI calls it, so it
|
|
10
|
-
* writes only when the entry changed. Entries this build cannot read stay stored for the CLIs that can.
|
|
11
|
-
*/
|
|
12
8
|
export declare const registerProvider: (database: CacheDatabase, value: ProviderEntry, now: number) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addProvider, providerEntryOf, useStoredProviders } from "../../domain/providers.js";
|
|
1
|
+
import { addProvider, importedOf, kindsOfEntry, providerEntryOf, unitedKinds, useStoredProviders, } from "../../domain/providers.js";
|
|
2
2
|
import { write } from "./transaction.js";
|
|
3
3
|
export const PROVIDERS_SETTING = "providers";
|
|
4
4
|
/** The entries as stored, unchecked: a newer CLI may have written a kind this build does not know. */
|
|
@@ -23,10 +23,28 @@ const nameOf = (stored) => typeof stored === "object" && stored !== null ? store
|
|
|
23
23
|
* Writes `entry` over the stored one of its name and loads the result. Every run of every CLI calls it, so it
|
|
24
24
|
* writes only when the entry changed. Entries this build cannot read stay stored for the CLIs that can.
|
|
25
25
|
*/
|
|
26
|
+
/**
|
|
27
|
+
* The entry with what the stored one of its name held beyond it: another build's kinds are never dropped, and
|
|
28
|
+
* `imported` is kept as `importedOf` rules, so it can be neither stripped nor added later.
|
|
29
|
+
*/
|
|
30
|
+
const keptBeside = (entry, stored) => {
|
|
31
|
+
const found = stored.find((one) => nameOf(one) === entry.name);
|
|
32
|
+
let held;
|
|
33
|
+
try {
|
|
34
|
+
held = found === undefined ? undefined : providerEntryOf(found);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
held = undefined;
|
|
38
|
+
}
|
|
39
|
+
const imported = importedOf(entry, held);
|
|
40
|
+
const { imported: _given, ...rest } = entry;
|
|
41
|
+
const kinds = held && held.kind === entry.kind ? unitedKinds(kindsOfEntry(held), kindsOfEntry(entry)) : kindsOfEntry(entry);
|
|
42
|
+
return { ...rest, ...(kinds.length > 1 ? { kinds } : {}), ...(imported ? { imported: true } : {}) };
|
|
43
|
+
};
|
|
26
44
|
export const registerProvider = (database, value, now) => {
|
|
27
|
-
const entry = providerEntryOf(value);
|
|
28
45
|
write(database, () => {
|
|
29
46
|
const stored = storedProvidersOf(database);
|
|
47
|
+
const entry = keptBeside(providerEntryOf(value), stored);
|
|
30
48
|
const others = stored.filter((one) => nameOf(one) !== entry.name);
|
|
31
49
|
try {
|
|
32
50
|
useStoredProviders(others);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type IdentityType } from "../../domain/record-types.js";
|
|
2
|
+
import type { EnvelopeOptions, EnvelopeSource } from "../../domain/records.js";
|
|
3
|
+
import type { CacheDatabase } from "../driver.js";
|
|
4
|
+
import type { StoreContext } from "./open.js";
|
|
5
|
+
import { type Row } from "./record-projection.js";
|
|
6
|
+
/** The strong identifiers a person, organization or project record gives; a name is never one. */
|
|
7
|
+
export interface Identifiers {
|
|
8
|
+
/** Lower-cased, as every writer of an e-mail identity keeps them. */
|
|
9
|
+
emails: string[];
|
|
10
|
+
/** E.164. */
|
|
11
|
+
phones: string[];
|
|
12
|
+
/** The source's own contact identity, `<account>/contact/<external id>` under its provider, as CRM sync writes it. */
|
|
13
|
+
contact?: {
|
|
14
|
+
provider: string;
|
|
15
|
+
externalId: string;
|
|
16
|
+
};
|
|
17
|
+
/** An organization's, by the identity provider its scheme is kept under. */
|
|
18
|
+
organization: {
|
|
19
|
+
provider: string;
|
|
20
|
+
value: string;
|
|
21
|
+
}[];
|
|
22
|
+
/** A project's key, upper-cased. */
|
|
23
|
+
key?: string;
|
|
24
|
+
/** Values that look like an identifier but were not read as one, with why: a phone without `+` and no region. */
|
|
25
|
+
ignored: {
|
|
26
|
+
at: (string | number)[];
|
|
27
|
+
reason: "record.phone-region";
|
|
28
|
+
}[];
|
|
29
|
+
}
|
|
30
|
+
export type Match = {
|
|
31
|
+
outcome: "none";
|
|
32
|
+
} | {
|
|
33
|
+
outcome: "one";
|
|
34
|
+
id: number;
|
|
35
|
+
} | {
|
|
36
|
+
outcome: "ambiguous";
|
|
37
|
+
ids: number[];
|
|
38
|
+
reason: "record.ambiguous" | "record.separated";
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* A phone as E.164, `null` for a number written without `+` or `00` when the envelope names no `phone_region`, or
|
|
42
|
+
* nothing when it is no phone. Only the envelope says which country a national number is from: the store's
|
|
43
|
+
* `phone_countries` setting reads `4155550100` as Russian, so it never decides an identifier.
|
|
44
|
+
*/
|
|
45
|
+
export declare const e164Of: (phone: string, region: string | undefined) => string | null | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* A record's identifiers. What does not read as an e-mail, a phone or a `{scheme, value}` of a known scheme is no
|
|
48
|
+
* identifier and stays in the fields, as v1 kept it; a free-mail domain claimed as an organization's is refused.
|
|
49
|
+
*/
|
|
50
|
+
export declare const identifiersOf: (type: IdentityType, fields: Row, source: EnvelopeSource, externalId: string, options?: EnvelopeOptions) => Identifiers;
|
|
51
|
+
/**
|
|
52
|
+
* The entities the identifiers point at, each once. The one lookup an import matches by: the Memory workstream's
|
|
53
|
+
* shared matcher (D5) takes it over as it is, so it reads the store and nothing else.
|
|
54
|
+
*/
|
|
55
|
+
export declare const entitiesByIdentifiers: (database: CacheDatabase, type: IdentityType, ids: Identifiers) => number[];
|
|
56
|
+
/** Whether the owner separated `person` from an identity the record brings: linking would join what he told apart. */
|
|
57
|
+
export declare const separatedByOwner: (context: StoreContext, person: number, identities: number[]) => boolean;
|
|
58
|
+
/** What the identifiers say: no entity, exactly one, or several the owner has to choose between. */
|
|
59
|
+
export declare const matchOf: (context: StoreContext, type: IdentityType, ids: Identifiers) => Match;
|
|
60
|
+
/** The identity of `(provider, externalId)`, made when the store has none; never another person's. */
|
|
61
|
+
export declare const importedIdentity: ({ database, now }: StoreContext, identity: {
|
|
62
|
+
provider: string;
|
|
63
|
+
externalId: string;
|
|
64
|
+
name: string | null;
|
|
65
|
+
email?: string;
|
|
66
|
+
phone?: string;
|
|
67
|
+
}) => number;
|
|
68
|
+
/** Gives a person the record brought these identifiers; an identity another person already has stays theirs. */
|
|
69
|
+
export declare const linkToPerson: (context: StoreContext, person: number, identity: number, source: EnvelopeSource) => void;
|
|
70
|
+
/** Adds the record's identifiers to an entity the import made; never to one it linked by an identifier. */
|
|
71
|
+
export declare const addIdentifiers: (context: StoreContext, type: IdentityType, id: number, ids: Identifiers, name: string | null, source: EnvelopeSource) => void;
|
|
72
|
+
/** Makes the entity a record with no match stands for, marked by the caller as made by the import. */
|
|
73
|
+
export declare const createEntity: (context: StoreContext, type: IdentityType, fields: Row, ids: Identifiers, related: {
|
|
74
|
+
organization?: number | null;
|
|
75
|
+
}, source: EnvelopeSource, externalId: string) => number;
|
|
76
|
+
/**
|
|
77
|
+
* The name of an entity the import made follows the source, unless someone renamed it here: `before` is the name
|
|
78
|
+
* the source gave last time.
|
|
79
|
+
*/
|
|
80
|
+
export declare const renameMade: ({ database, now }: StoreContext, type: IdentityType, id: number, name: unknown, before: unknown) => void;
|