@htilabs/platform-common-models 0.86.0 → 0.87.1
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/README.md +20 -0
- package/dist/{index-XWSYon40.d.cts → index-Bj-s0nZy.d.cts} +1 -1
- package/dist/{index-Bh1zO_Vu.d.ts → index-DvAypMJV.d.ts} +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/models/index.d.cts +2 -2
- package/dist/models/index.d.ts +2 -2
- package/dist/org-merge/index.cjs.map +1 -1
- package/dist/org-merge/index.js.map +1 -1
- package/dist/points-of-contact/index.cjs +222 -23
- package/dist/points-of-contact/index.cjs.map +1 -1
- package/dist/points-of-contact/index.d.cts +50 -5
- package/dist/points-of-contact/index.d.ts +50 -5
- package/dist/points-of-contact/index.js +219 -22
- package/dist/points-of-contact/index.js.map +1 -1
- package/dist/reader-BmhzOis-.d.ts +273 -0
- package/dist/reader-DfQtdw6n.d.cts +273 -0
- package/dist/schemas/index.d.cts +25 -25
- package/dist/schemas/index.d.ts +25 -25
- package/dist/seat-logs/index.cjs +815 -0
- package/dist/seat-logs/index.cjs.map +1 -0
- package/dist/seat-logs/index.d.cts +274 -0
- package/dist/seat-logs/index.d.ts +274 -0
- package/dist/seat-logs/index.js +742 -0
- package/dist/seat-logs/index.js.map +1 -0
- package/package.json +6 -1
- package/src/pointsOfContact/__tests__/seatContactLog.test.ts +170 -0
- package/src/pointsOfContact/readRules.ts +22 -4
- package/src/pointsOfContact/reader.ts +95 -1
- package/src/pointsOfContact/schemas.ts +4 -3
- package/src/seatLogs/__tests__/seatLogs.review.test.ts +222 -0
- package/src/seatLogs/__tests__/seatLogs.test.ts +335 -0
- package/src/seatLogs/index.ts +15 -0
- package/src/seatLogs/log.ts +700 -0
- package/src/seatLogs/personId.ts +100 -0
- package/src/seatLogs/personSlugWordlists.ts +40 -0
- package/src/seatLogs/reader.ts +143 -0
- package/src/seatLogs/schemas.ts +118 -0
- package/dist/{cvcEntry-D787utvP.d.cts → cvcEntry-BLeRivoF.d.cts} +8 -8
- package/dist/{cvcEntry-D787utvP.d.ts → cvcEntry-BLeRivoF.d.ts} +8 -8
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Person id: `per-<first>-<second>`, name-free (Person § "The id carries no
|
|
3
|
+
* name": "Display names carry identity; ids are stable and name-free").
|
|
4
|
+
*
|
|
5
|
+
* Canon: platform-prototype `src/screens.jsx` @ 398fb24 `mintPersonId`
|
|
6
|
+
* (L24354-L24363), drawing from the directory's `person_slug_wordlists`
|
|
7
|
+
* (`first`, `second`), which the records repo's directory generator
|
|
8
|
+
* (`tools/build_platform_directory.py`) emits.
|
|
9
|
+
*
|
|
10
|
+
* The wordlists default to the vendored copy of the records monolith's
|
|
11
|
+
* `PERSON_FIRST` / `PERSON_SECOND` (`./personSlugWordlists.ts`); a caller may
|
|
12
|
+
* still pass a directory build's `person_slug_wordlists` instead.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { PERSON_SLUG_WORDLISTS } from "./personSlugWordlists.js";
|
|
16
|
+
|
|
17
|
+
/** The directory build's slug wordlists. */
|
|
18
|
+
export interface PersonSlugWordlists {
|
|
19
|
+
first: readonly string[];
|
|
20
|
+
second: readonly string[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** `per-` then two lowercase words, optionally a numeric suffix (`-<n>`) when the pair pool was full. */
|
|
24
|
+
export const PERSON_ID_PATTERN = /^per-[a-z0-9]+-[a-z0-9]+(?:-\d+)?$/;
|
|
25
|
+
|
|
26
|
+
/** True for a string shaped like a Person id. */
|
|
27
|
+
export function isPersonId(v: unknown): v is string {
|
|
28
|
+
return typeof v === "string" && PERSON_ID_PATTERN.test(v);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A draw from `random` as an index into a list of `n`, clamped to `[0, n)`. */
|
|
32
|
+
function indexOf(r: number, n: number): number {
|
|
33
|
+
if (!Number.isFinite(r)) return 0;
|
|
34
|
+
return Math.min(n - 1, Math.max(0, Math.floor(r * n)));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Mint a Person id not in `taken`. `null` only when there are no wordlists
|
|
39
|
+
* (empty or `null`) — refuse rather than invent a shape.
|
|
40
|
+
*
|
|
41
|
+
* As the prototype (`mintPersonId`, screens.jsx L24352-L24363): up to 200
|
|
42
|
+
* random draws of `per-<first>-<second>`. If all 200 are taken, the whole
|
|
43
|
+
* two-word space is scanned in list order for a free pair. When every pair is
|
|
44
|
+
* taken (45 × 45 = 2,025 with the vendored lists), the records generator's
|
|
45
|
+
* full-pool rule applies (`generatePersonSlug`, records monolith: after its
|
|
46
|
+
* random tries fail it returns `<first>-<second>-<number 0-999>`): up to 200
|
|
47
|
+
* random `per-<first>-<second>-<0-999>`, then a deterministic scan over the
|
|
48
|
+
* pairs and suffixes 0, 1, 2, … until one is free, so a mint always ends.
|
|
49
|
+
*
|
|
50
|
+
* `taken` is a snapshot (every person id already held by a seat or a registry
|
|
51
|
+
* person; the caller supplies it), so two concurrent mints can return the
|
|
52
|
+
* same id: the store needs a UNIQUE index on the person id, and a caller
|
|
53
|
+
* retries the mint on a duplicate-key error. `random` must return `[0, 1)`;
|
|
54
|
+
* an out-of-range value is clamped. `wordlists` left `undefined` uses the
|
|
55
|
+
* vendored lists ({@link PERSON_SLUG_WORDLISTS}).
|
|
56
|
+
*/
|
|
57
|
+
export function mintPersonId(
|
|
58
|
+
wordlists: PersonSlugWordlists | null | undefined = PERSON_SLUG_WORDLISTS,
|
|
59
|
+
taken: Iterable<string | null | undefined> = [],
|
|
60
|
+
random: () => number = Math.random,
|
|
61
|
+
): string | null {
|
|
62
|
+
const F = wordlists?.first ?? [];
|
|
63
|
+
const S = wordlists?.second ?? [];
|
|
64
|
+
if (!F.length || !S.length) return null;
|
|
65
|
+
const used = new Set<string>();
|
|
66
|
+
for (const t of taken) if (t) used.add(t);
|
|
67
|
+
const pick = (list: readonly string[]) => list[indexOf(random(), list.length)];
|
|
68
|
+
for (let i = 0; i < 200; i++) {
|
|
69
|
+
const slug = "per-" + pick(F) + "-" + pick(S);
|
|
70
|
+
if (!used.has(slug)) return slug;
|
|
71
|
+
}
|
|
72
|
+
for (const f of F) {
|
|
73
|
+
for (const t of S) {
|
|
74
|
+
const slug = "per-" + f + "-" + t;
|
|
75
|
+
if (!used.has(slug)) return slug;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Every pair is taken: the records generator's numeric suffix.
|
|
79
|
+
for (let i = 0; i < 200; i++) {
|
|
80
|
+
const slug = "per-" + pick(F) + "-" + pick(S) + "-" + indexOf(random(), 1000);
|
|
81
|
+
if (!used.has(slug)) return slug;
|
|
82
|
+
}
|
|
83
|
+
// `used` is finite, so this ends.
|
|
84
|
+
for (let num = 0; ; num++) {
|
|
85
|
+
for (const f of F) {
|
|
86
|
+
for (const t of S) {
|
|
87
|
+
const slug = "per-" + f + "-" + t + "-" + num;
|
|
88
|
+
if (!used.has(slug)) return slug;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Mint a Person id from the vendored wordlists, not in `taken` (or `null`). */
|
|
95
|
+
export function mintNewPersonId(
|
|
96
|
+
taken: Iterable<string | null | undefined> = [],
|
|
97
|
+
random: () => number = Math.random,
|
|
98
|
+
): string | null {
|
|
99
|
+
return mintPersonId(PERSON_SLUG_WORDLISTS, taken, random);
|
|
100
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Person id wordlists, vendored.
|
|
3
|
+
*
|
|
4
|
+
* Source: the records repo (htilabstech/prototype) @ 1be43ed5, the monolith
|
|
5
|
+
* `HTI-LEADS-PAVE-Thread-prototype.html` consts `PERSON_FIRST` and
|
|
6
|
+
* `PERSON_SECOND`, copied unchanged. The same lists reach the Platform
|
|
7
|
+
* prototype as the directory build's `person_slug_wordlists`
|
|
8
|
+
* (records `tools/build_platform_directory.py` → platform-prototype
|
|
9
|
+
* `src/data.js` `HTI_DIRECTORY.person_slug_wordlists`; equal at 398fb24).
|
|
10
|
+
*
|
|
11
|
+
* Do not hand-edit. A word added or removed in the records monolith is
|
|
12
|
+
* re-copied here; an id already minted keeps its words either way (ids are
|
|
13
|
+
* never re-derived from these lists).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { PersonSlugWordlists } from "./personId.js";
|
|
17
|
+
|
|
18
|
+
/** `PERSON_FIRST` (45 words). */
|
|
19
|
+
export const PERSON_SLUG_FIRST: readonly string[] = Object.freeze([
|
|
20
|
+
"agate", "alabaster", "amber", "amethyst", "azure", "basalt", "beryl", "bronze", "carnelian",
|
|
21
|
+
"cedar", "chrome", "cinnabar", "citrine", "copper", "coral", "crystal", "ember", "feldspar",
|
|
22
|
+
"flint", "garnet", "granite", "graphite", "hematite", "indigo", "iron", "ivory", "jade",
|
|
23
|
+
"jasper", "lapis", "malachite", "marble", "obsidian", "onyx", "opal", "pearl", "pewter",
|
|
24
|
+
"pyrite", "quartz", "sable", "silver", "slate", "sterling", "tin", "topaz", "tungsten",
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
/** `PERSON_SECOND` (45 words). */
|
|
28
|
+
export const PERSON_SLUG_SECOND: readonly string[] = Object.freeze([
|
|
29
|
+
"augur", "beacon", "cairn", "cipher", "compass", "crest", "crown", "ember", "envoy", "flame",
|
|
30
|
+
"glyph", "harbor", "herald", "keep", "ledger", "lighthouse", "lyre", "mantle", "monolith",
|
|
31
|
+
"oracle", "pillar", "plume", "quill", "relic", "rune", "scribe", "scroll", "seal", "sentinel",
|
|
32
|
+
"sigil", "sojourner", "spire", "standard", "tablet", "talisman", "thread", "torch", "totem",
|
|
33
|
+
"tower", "verse", "vessel", "warden", "watch", "witness", "wreath",
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
/** The vendored wordlists, the default for `mintPersonId`. */
|
|
37
|
+
export const PERSON_SLUG_WORDLISTS: PersonSlugWordlists = Object.freeze({
|
|
38
|
+
first: PERSON_SLUG_FIRST,
|
|
39
|
+
second: PERSON_SLUG_SECOND,
|
|
40
|
+
});
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw-driver reads of the seat logs (no mongoose, no driver import), typed
|
|
3
|
+
* structurally like the points-of-contact reads: a `mongodb` `Db` or a
|
|
4
|
+
* mongoose connection's `.db` both fit. Ids are the string form, so no
|
|
5
|
+
* ObjectId is needed. A stored row that does not match the entry shape
|
|
6
|
+
* throws by default (an unreadable log never reads as empty); a read that
|
|
7
|
+
* must go on past one bad row passes `{ invalid: "skip" }`.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
SEAT_CONTACTS_COLLECTION,
|
|
12
|
+
SEAT_NAMES_COLLECTION,
|
|
13
|
+
SeatContactEntrySchema,
|
|
14
|
+
SeatNameEntrySchema,
|
|
15
|
+
type SeatContactEntry,
|
|
16
|
+
type SeatLogSubjectType,
|
|
17
|
+
type SeatNameEntry,
|
|
18
|
+
} from "./schemas.js";
|
|
19
|
+
|
|
20
|
+
/** The slice of a driver `Db` the reads use. */
|
|
21
|
+
export interface SeatLogDbLike {
|
|
22
|
+
collection(name: string): {
|
|
23
|
+
find(filter: Record<string, unknown>): { toArray(): Promise<unknown[]> };
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** A stored entry that does not match the contract. */
|
|
28
|
+
export class SeatLogShapeError extends Error {
|
|
29
|
+
constructor(readonly entryId: string | null, readonly issues: string[]) {
|
|
30
|
+
super(`seat-logs: stored entry ${entryId ?? "(no id)"} does not match the contract: ${issues.join("; ")}`);
|
|
31
|
+
this.name = "SeatLogShapeError";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function strip(r: unknown): Record<string, unknown> {
|
|
36
|
+
if (r === null || typeof r !== "object") return {};
|
|
37
|
+
const { _id: _ignored, ...rest } = r as Record<string, unknown>;
|
|
38
|
+
return rest;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type ParseResult<T> =
|
|
42
|
+
| { success: true; data: T }
|
|
43
|
+
| { success: false; error: { issues: { path: (string | number)[]; message: string }[] } };
|
|
44
|
+
|
|
45
|
+
function parseWith<T>(schema: { safeParse(v: unknown): ParseResult<T> }, raw: unknown): T {
|
|
46
|
+
const row = strip(raw);
|
|
47
|
+
const p = schema.safeParse(row);
|
|
48
|
+
if (p.success) return p.data;
|
|
49
|
+
throw new SeatLogShapeError(
|
|
50
|
+
typeof row.entry_id === "string" ? row.entry_id : null,
|
|
51
|
+
p.error.issues.map((i) => `${i.path.join(".") || "(row)"}: ${i.message}`),
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** How a read treats a stored row that does not match the entry shape. */
|
|
56
|
+
export interface SeatLogReadOptions {
|
|
57
|
+
/**
|
|
58
|
+
* `throw` (default): the read fails with {@link SeatLogShapeError} — for a
|
|
59
|
+
* write path, which must not act on a log it cannot fully read.
|
|
60
|
+
* `skip`: the row is left out of its subject's log and reported to
|
|
61
|
+
* `onInvalidRow`; the rest of the read goes on.
|
|
62
|
+
*/
|
|
63
|
+
invalid?: "throw" | "skip";
|
|
64
|
+
onInvalidRow?: (error: SeatLogShapeError) => void;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The id forms a subject id is matched in: as asked and lower-cased. A seat's
|
|
69
|
+
* log is stored under `String(users._id)` (24 lower-case hex); the base seat
|
|
70
|
+
* resolvers match `users._id` case-insensitively, so this does too.
|
|
71
|
+
*/
|
|
72
|
+
const idForms = (id: string) => [...new Set([id, id.toLowerCase()])];
|
|
73
|
+
|
|
74
|
+
const byEntryId = (a: { entry_id: string }, b: { entry_id: string }) =>
|
|
75
|
+
a.entry_id < b.entry_id ? -1 : a.entry_id > b.entry_id ? 1 : 0;
|
|
76
|
+
|
|
77
|
+
async function readLogs<T extends { subject_id: string; entry_id: string }>(
|
|
78
|
+
db: SeatLogDbLike,
|
|
79
|
+
collection: string,
|
|
80
|
+
subjectType: SeatLogSubjectType,
|
|
81
|
+
subjectIds: readonly string[],
|
|
82
|
+
parse: (raw: unknown) => T,
|
|
83
|
+
opts: SeatLogReadOptions,
|
|
84
|
+
): Promise<Map<string, T[]>> {
|
|
85
|
+
const ids = [...new Set(subjectIds.filter((s) => typeof s === "string" && s))];
|
|
86
|
+
const out = new Map<string, T[]>();
|
|
87
|
+
if (!ids.length) return out;
|
|
88
|
+
const askedByKey = new Map<string, string[]>();
|
|
89
|
+
for (const id of ids) {
|
|
90
|
+
const k = id.toLowerCase();
|
|
91
|
+
askedByKey.set(k, [...(askedByKey.get(k) ?? []), id]);
|
|
92
|
+
}
|
|
93
|
+
const raw = await db.collection(collection)
|
|
94
|
+
.find({ subject_type: subjectType, subject_id: { $in: ids.flatMap(idForms) } }).toArray();
|
|
95
|
+
for (const r of raw) {
|
|
96
|
+
let e: T;
|
|
97
|
+
try {
|
|
98
|
+
e = parse(r);
|
|
99
|
+
} catch (err) {
|
|
100
|
+
if (opts.invalid !== "skip" || !(err instanceof SeatLogShapeError)) throw err;
|
|
101
|
+
opts.onInvalidRow?.(err);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
for (const asked of askedByKey.get(e.subject_id.toLowerCase()) ?? []) {
|
|
105
|
+
const list = out.get(asked) ?? [];
|
|
106
|
+
list.push(e);
|
|
107
|
+
out.set(asked, list);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// The prototype store lists a subject's entries in entry_id order
|
|
111
|
+
// (objectStore.js `entries`: Object.keys(...).sort()); "the first live
|
|
112
|
+
// entry" fallbacks depend on it.
|
|
113
|
+
for (const list of out.values()) list.sort(byEntryId);
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Each subject's name entries (live and retired), in entry_id order, keyed by
|
|
119
|
+
* the subject id as asked (matched case-insensitively). Absent ids have no log.
|
|
120
|
+
*/
|
|
121
|
+
export function readSeatNameLogs(
|
|
122
|
+
db: SeatLogDbLike,
|
|
123
|
+
subjectIds: readonly string[],
|
|
124
|
+
subjectType: SeatLogSubjectType = "user",
|
|
125
|
+
opts: SeatLogReadOptions = {},
|
|
126
|
+
): Promise<Map<string, SeatNameEntry[]>> {
|
|
127
|
+
return readLogs(db, SEAT_NAMES_COLLECTION, subjectType, subjectIds,
|
|
128
|
+
(r) => parseWith<SeatNameEntry>(SeatNameEntrySchema, r), opts);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Each subject's contact entries (live and retired), in entry_id order, keyed
|
|
133
|
+
* by the subject id as asked (matched case-insensitively). Absent ids have no log.
|
|
134
|
+
*/
|
|
135
|
+
export function readSeatContactLogs(
|
|
136
|
+
db: SeatLogDbLike,
|
|
137
|
+
subjectIds: readonly string[],
|
|
138
|
+
subjectType: SeatLogSubjectType = "user",
|
|
139
|
+
opts: SeatLogReadOptions = {},
|
|
140
|
+
): Promise<Map<string, SeatContactEntry[]>> {
|
|
141
|
+
return readLogs(db, SEAT_CONTACTS_COLLECTION, subjectType, subjectIds,
|
|
142
|
+
(r) => parseWith<SeatContactEntry>(SeatContactEntrySchema, r), opts);
|
|
143
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A seat's NAME log and CONTACT log: the stored entry shapes.
|
|
3
|
+
*
|
|
4
|
+
* Canon: platform-prototype `src/screens.jsx` @ 398fb24 `SeatNamesLedger`
|
|
5
|
+
* (L25149-L25288) and `SeatMethodsLedger` (L24981-L25137), over the object
|
|
6
|
+
* store `src/objectStore.js` (`addEntry` / `act`, L660-L740) and the spine
|
|
7
|
+
* cascade `src/objectStructuresEngine.generated.js` (`HTI_OBJECT_SPINE`,
|
|
8
|
+
* L942-L1049).
|
|
9
|
+
*
|
|
10
|
+
* The record (Person Data Object, step 6c, Crysta 2026-10-11): "a seat's name
|
|
11
|
+
* and contact rails stay keyed by the seat". So an entry's subject is the seat
|
|
12
|
+
* (`subject_type: "user"`, `subject_id` = the platform-db `users._id`, string
|
|
13
|
+
* form). A registry person's name rides the same log with
|
|
14
|
+
* `subject_type: "person"` (Person decision B).
|
|
15
|
+
*
|
|
16
|
+
* Names, contact details and addresses are not fields of a Person; each is
|
|
17
|
+
* its own log that points at the subject, so every entry carries its own
|
|
18
|
+
* source and dates (Person § 3). An entry is never edited in place: a
|
|
19
|
+
* correction inserts a new entry and archives the old one (`period_end`), and
|
|
20
|
+
* a retired entry stays in the log with its dates.
|
|
21
|
+
*
|
|
22
|
+
* Field shapes are the prototype's as stored: open dates are the empty string
|
|
23
|
+
* `""` (not null), a closed entry carries `period_end` `YYYY-MM-DD`; the store
|
|
24
|
+
* stamps an `events[]` audit trail (`{ act, at, actor }`) and a phone's
|
|
25
|
+
* `digits` key.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { z } from "zod";
|
|
29
|
+
|
|
30
|
+
import { NameTypeKeys } from "../generated/cvc-enums.js";
|
|
31
|
+
|
|
32
|
+
/** Platform-db collection holding name entries (all subjects). */
|
|
33
|
+
export const SEAT_NAMES_COLLECTION = "seat_names";
|
|
34
|
+
/** Platform-db collection holding contact entries (all subjects). */
|
|
35
|
+
export const SEAT_CONTACTS_COLLECTION = "seat_contacts";
|
|
36
|
+
|
|
37
|
+
/** Whose log: a seat (`users._id`) or a registry person (`per-…` id). */
|
|
38
|
+
export const SEAT_LOG_SUBJECT_TYPES = ["user", "person"] as const;
|
|
39
|
+
export type SeatLogSubjectType = (typeof SEAT_LOG_SUBJECT_TYPES)[number];
|
|
40
|
+
|
|
41
|
+
/** The two contact types the seat ledger carries (prototype Email / Phone chips). */
|
|
42
|
+
export const SEAT_CONTACT_TYPES = ["email", "phone"] as const;
|
|
43
|
+
export type SeatContactType = (typeof SEAT_CONTACT_TYPES)[number];
|
|
44
|
+
|
|
45
|
+
/** CVC-1 `name_type` keys (the prototype stores `alias` / `legal`). */
|
|
46
|
+
export const SEAT_NAME_TYPES = Object.keys(NameTypeKeys) as [
|
|
47
|
+
keyof typeof NameTypeKeys,
|
|
48
|
+
...(keyof typeof NameTypeKeys)[],
|
|
49
|
+
];
|
|
50
|
+
export type SeatNameType = keyof typeof NameTypeKeys;
|
|
51
|
+
|
|
52
|
+
/** The name types the profile's add row offers, in its chip order. */
|
|
53
|
+
export const SEAT_NAME_ADD_TYPES = [
|
|
54
|
+
{ name_type: "alias", label: "Also known as" },
|
|
55
|
+
{ name_type: "legal", label: "Legal name" },
|
|
56
|
+
] as const satisfies readonly { name_type: SeatNameType; label: string }[];
|
|
57
|
+
|
|
58
|
+
/** One audit event the store stamps on an entry. */
|
|
59
|
+
export const SeatLogEventSchema = z.object({
|
|
60
|
+
/** `add`, `set_display`, `set_preferred`, `archive`, or `cascade` (a sibling's flag moved). */
|
|
61
|
+
act: z.string().min(1),
|
|
62
|
+
/** ISO instant. */
|
|
63
|
+
at: z.string().min(1),
|
|
64
|
+
/** The acting seat's id. */
|
|
65
|
+
actor: z.string(),
|
|
66
|
+
});
|
|
67
|
+
export type SeatLogEvent = z.infer<typeof SeatLogEventSchema>;
|
|
68
|
+
|
|
69
|
+
/** `""` (open) or a `YYYY-MM-DD` day. */
|
|
70
|
+
const DayOrEmpty = z.union([z.literal(""), z.string().regex(/^\d{4}-\d{2}-\d{2}$/)]);
|
|
71
|
+
|
|
72
|
+
const subjectShape = {
|
|
73
|
+
entry_id: z.string().min(1),
|
|
74
|
+
subject_id: z.string().min(1),
|
|
75
|
+
subject_type: z.enum(SEAT_LOG_SUBJECT_TYPES),
|
|
76
|
+
period_start: DayOrEmpty,
|
|
77
|
+
period_end: DayOrEmpty,
|
|
78
|
+
/** Where the entry came from (`admin_hub` on the profile). */
|
|
79
|
+
source: z.string(),
|
|
80
|
+
/** How it was captured (`direct_entry` on the profile). */
|
|
81
|
+
method: z.string(),
|
|
82
|
+
notes: z.string(),
|
|
83
|
+
events: z.array(SeatLogEventSchema).optional(),
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/** One name in a seat's (or registry person's) name log. */
|
|
87
|
+
export const SeatNameEntrySchema = z.object({
|
|
88
|
+
...subjectShape,
|
|
89
|
+
name_type: z.enum(SEAT_NAME_TYPES),
|
|
90
|
+
/** The name as written. */
|
|
91
|
+
raw: z.string().min(1),
|
|
92
|
+
/** The display name: one live entry per subject carries it. */
|
|
93
|
+
is_display: z.boolean(),
|
|
94
|
+
/** Set with the display mark on the profile (prototype acts both together). */
|
|
95
|
+
is_preferred: z.boolean(),
|
|
96
|
+
});
|
|
97
|
+
export type SeatNameEntry = z.infer<typeof SeatNameEntrySchema>;
|
|
98
|
+
|
|
99
|
+
/** One email or phone in a seat's contact log. */
|
|
100
|
+
export const SeatContactEntrySchema = z.object({
|
|
101
|
+
...subjectShape,
|
|
102
|
+
contact_type: z.enum(SEAT_CONTACT_TYPES),
|
|
103
|
+
/** Email trimmed; phone in the store's canonical display form ({@link canonSeatContactValue}). */
|
|
104
|
+
value: z.string().min(1),
|
|
105
|
+
use: z.string(),
|
|
106
|
+
/** The preferred entry of its type: one live entry per subject and type carries it. */
|
|
107
|
+
is_preferred: z.boolean(),
|
|
108
|
+
safety_status: z.string(),
|
|
109
|
+
/** Phone only: the identity key ({@link seatContactKey}), stamped by the store. */
|
|
110
|
+
digits: z.string().optional(),
|
|
111
|
+
});
|
|
112
|
+
export type SeatContactEntry = z.infer<typeof SeatContactEntrySchema>;
|
|
113
|
+
|
|
114
|
+
/** The subject an operation acts on. */
|
|
115
|
+
export interface SeatLogSubject {
|
|
116
|
+
subject_type: SeatLogSubjectType;
|
|
117
|
+
subject_id: string;
|
|
118
|
+
}
|
|
@@ -233,18 +233,18 @@ type SectionQuestionRef = InferRawDocType<typeof sectionQuestionRefSchema>;
|
|
|
233
233
|
declare const guidanceSchema: Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
234
234
|
_id: false;
|
|
235
235
|
}, {
|
|
236
|
-
type: "tip" | "warning" | "prompt";
|
|
237
236
|
text: string;
|
|
238
|
-
}, mongoose.Document<unknown, {}, {
|
|
239
237
|
type: "tip" | "warning" | "prompt";
|
|
238
|
+
}, mongoose.Document<unknown, {}, {
|
|
240
239
|
text: string;
|
|
240
|
+
type: "tip" | "warning" | "prompt";
|
|
241
241
|
}, {
|
|
242
242
|
id: string;
|
|
243
243
|
}, mongoose.MergeType<mongoose.DefaultSchemaOptions, {
|
|
244
244
|
_id: false;
|
|
245
245
|
}>> & Omit<{
|
|
246
|
-
type: "tip" | "warning" | "prompt";
|
|
247
246
|
text: string;
|
|
247
|
+
type: "tip" | "warning" | "prompt";
|
|
248
248
|
} & {
|
|
249
249
|
_id: mongoose.Types.ObjectId;
|
|
250
250
|
} & {
|
|
@@ -252,8 +252,8 @@ declare const guidanceSchema: Schema<any, mongoose.Model<any, any, any, any, any
|
|
|
252
252
|
}, "id"> & {
|
|
253
253
|
id: string;
|
|
254
254
|
}, unknown, {
|
|
255
|
-
type: "tip" | "warning" | "prompt";
|
|
256
255
|
text: string;
|
|
256
|
+
type: "tip" | "warning" | "prompt";
|
|
257
257
|
} & {
|
|
258
258
|
_id: mongoose.Types.ObjectId;
|
|
259
259
|
} & {
|
|
@@ -294,18 +294,18 @@ declare const sectionSchemaDefinition: {
|
|
|
294
294
|
type: Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
295
295
|
_id: false;
|
|
296
296
|
}, {
|
|
297
|
-
type: "tip" | "warning" | "prompt";
|
|
298
297
|
text: string;
|
|
299
|
-
}, mongoose.Document<unknown, {}, {
|
|
300
298
|
type: "tip" | "warning" | "prompt";
|
|
299
|
+
}, mongoose.Document<unknown, {}, {
|
|
301
300
|
text: string;
|
|
301
|
+
type: "tip" | "warning" | "prompt";
|
|
302
302
|
}, {
|
|
303
303
|
id: string;
|
|
304
304
|
}, mongoose.MergeType<mongoose.DefaultSchemaOptions, {
|
|
305
305
|
_id: false;
|
|
306
306
|
}>> & Omit<{
|
|
307
|
-
type: "tip" | "warning" | "prompt";
|
|
308
307
|
text: string;
|
|
308
|
+
type: "tip" | "warning" | "prompt";
|
|
309
309
|
} & {
|
|
310
310
|
_id: mongoose.Types.ObjectId;
|
|
311
311
|
} & {
|
|
@@ -313,8 +313,8 @@ declare const sectionSchemaDefinition: {
|
|
|
313
313
|
}, "id"> & {
|
|
314
314
|
id: string;
|
|
315
315
|
}, unknown, {
|
|
316
|
-
type: "tip" | "warning" | "prompt";
|
|
317
316
|
text: string;
|
|
317
|
+
type: "tip" | "warning" | "prompt";
|
|
318
318
|
} & {
|
|
319
319
|
_id: mongoose.Types.ObjectId;
|
|
320
320
|
} & {
|
|
@@ -233,18 +233,18 @@ type SectionQuestionRef = InferRawDocType<typeof sectionQuestionRefSchema>;
|
|
|
233
233
|
declare const guidanceSchema: Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
234
234
|
_id: false;
|
|
235
235
|
}, {
|
|
236
|
-
type: "tip" | "warning" | "prompt";
|
|
237
236
|
text: string;
|
|
238
|
-
}, mongoose.Document<unknown, {}, {
|
|
239
237
|
type: "tip" | "warning" | "prompt";
|
|
238
|
+
}, mongoose.Document<unknown, {}, {
|
|
240
239
|
text: string;
|
|
240
|
+
type: "tip" | "warning" | "prompt";
|
|
241
241
|
}, {
|
|
242
242
|
id: string;
|
|
243
243
|
}, mongoose.MergeType<mongoose.DefaultSchemaOptions, {
|
|
244
244
|
_id: false;
|
|
245
245
|
}>> & Omit<{
|
|
246
|
-
type: "tip" | "warning" | "prompt";
|
|
247
246
|
text: string;
|
|
247
|
+
type: "tip" | "warning" | "prompt";
|
|
248
248
|
} & {
|
|
249
249
|
_id: mongoose.Types.ObjectId;
|
|
250
250
|
} & {
|
|
@@ -252,8 +252,8 @@ declare const guidanceSchema: Schema<any, mongoose.Model<any, any, any, any, any
|
|
|
252
252
|
}, "id"> & {
|
|
253
253
|
id: string;
|
|
254
254
|
}, unknown, {
|
|
255
|
-
type: "tip" | "warning" | "prompt";
|
|
256
255
|
text: string;
|
|
256
|
+
type: "tip" | "warning" | "prompt";
|
|
257
257
|
} & {
|
|
258
258
|
_id: mongoose.Types.ObjectId;
|
|
259
259
|
} & {
|
|
@@ -294,18 +294,18 @@ declare const sectionSchemaDefinition: {
|
|
|
294
294
|
type: Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
295
295
|
_id: false;
|
|
296
296
|
}, {
|
|
297
|
-
type: "tip" | "warning" | "prompt";
|
|
298
297
|
text: string;
|
|
299
|
-
}, mongoose.Document<unknown, {}, {
|
|
300
298
|
type: "tip" | "warning" | "prompt";
|
|
299
|
+
}, mongoose.Document<unknown, {}, {
|
|
301
300
|
text: string;
|
|
301
|
+
type: "tip" | "warning" | "prompt";
|
|
302
302
|
}, {
|
|
303
303
|
id: string;
|
|
304
304
|
}, mongoose.MergeType<mongoose.DefaultSchemaOptions, {
|
|
305
305
|
_id: false;
|
|
306
306
|
}>> & Omit<{
|
|
307
|
-
type: "tip" | "warning" | "prompt";
|
|
308
307
|
text: string;
|
|
308
|
+
type: "tip" | "warning" | "prompt";
|
|
309
309
|
} & {
|
|
310
310
|
_id: mongoose.Types.ObjectId;
|
|
311
311
|
} & {
|
|
@@ -313,8 +313,8 @@ declare const sectionSchemaDefinition: {
|
|
|
313
313
|
}, "id"> & {
|
|
314
314
|
id: string;
|
|
315
315
|
}, unknown, {
|
|
316
|
-
type: "tip" | "warning" | "prompt";
|
|
317
316
|
text: string;
|
|
317
|
+
type: "tip" | "warning" | "prompt";
|
|
318
318
|
} & {
|
|
319
319
|
_id: mongoose.Types.ObjectId;
|
|
320
320
|
} & {
|