@book.dev/sdk 3.7.0 → 3.9.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.
Files changed (53) hide show
  1. package/dist/ai.d.ts +12 -2
  2. package/dist/ai.js.map +1 -1
  3. package/dist/blockCatalogue.d.ts +560 -0
  4. package/dist/blockCatalogue.js +336 -0
  5. package/dist/blockCatalogue.js.map +1 -0
  6. package/dist/bookFolder.d.ts +9 -1
  7. package/dist/bookFolder.js +64 -2
  8. package/dist/bookFolder.js.map +1 -1
  9. package/dist/client.d.ts +22 -2
  10. package/dist/client.js +6 -2
  11. package/dist/client.js.map +1 -1
  12. package/dist/content.d.ts +40 -1
  13. package/dist/content.js +29 -7
  14. package/dist/content.js.map +1 -1
  15. package/dist/forwarding/forwardingClient.d.ts +68 -2
  16. package/dist/forwarding/forwardingClient.js +126 -12
  17. package/dist/forwarding/forwardingClient.js.map +1 -1
  18. package/dist/forwarding/index.d.ts +2 -1
  19. package/dist/forwarding/index.js +2 -1
  20. package/dist/forwarding/index.js.map +1 -1
  21. package/dist/forwarding/namespacedKeyStore.d.ts +52 -0
  22. package/dist/forwarding/namespacedKeyStore.js +99 -0
  23. package/dist/forwarding/namespacedKeyStore.js.map +1 -0
  24. package/dist/index.d.ts +10 -5
  25. package/dist/index.js +10 -5
  26. package/dist/index.js.map +1 -1
  27. package/dist/ledger.d.ts +29 -0
  28. package/dist/ledger.js +43 -0
  29. package/dist/ledger.js.map +1 -1
  30. package/dist/ledgerExportSection.d.ts +160 -0
  31. package/dist/ledgerExportSection.js +594 -0
  32. package/dist/ledgerExportSection.js.map +1 -0
  33. package/dist/orderKeys.d.ts +36 -0
  34. package/dist/orderKeys.js +88 -0
  35. package/dist/orderKeys.js.map +1 -0
  36. package/dist/plugins.d.ts +76 -4
  37. package/dist/plugins.js +95 -12
  38. package/dist/plugins.js.map +1 -1
  39. package/dist/provenance.d.ts +13 -0
  40. package/dist/registryClient.d.ts +227 -0
  41. package/dist/registryClient.js +397 -0
  42. package/dist/registryClient.js.map +1 -0
  43. package/dist/routes.d.ts +9 -0
  44. package/dist/routes.js +9 -0
  45. package/dist/routes.js.map +1 -1
  46. package/dist/suggestions.d.ts +12 -2
  47. package/dist/tableSnapshot.d.ts +233 -0
  48. package/dist/tableSnapshot.js +680 -0
  49. package/dist/tableSnapshot.js.map +1 -0
  50. package/dist/templates.d.ts +8 -0
  51. package/dist/templates.js +7 -2
  52. package/dist/templates.js.map +1 -1
  53. package/package.json +1 -1
@@ -0,0 +1,160 @@
1
+ /**
2
+ * LX-2: the machine-readable **ledger section** an owner-initiated site export
3
+ * embeds alongside its pages/databases, and the read-authorized capture that
4
+ * builds it.
5
+ *
6
+ * ## Payload shape (the island's `ledger` key)
7
+ * Ledger records live OUTSIDE the document (four managed databases behind a
8
+ * restricted host page), so the export crawl never discovers them. When the
9
+ * export set shows ledger blocks and the exporter opted in, the site island
10
+ * carries a {@link LedgerExportSection}:
11
+ *
12
+ * - `settings` — raw settings rows by key, the SAME keys the whole-space
13
+ * backup's {@link LedgerBackupSection} uses: `ledgerDb` (the seeded ids,
14
+ * reconstructed in the stored `LedgerIds` shape) and `ledgerPeriods` (the
15
+ * `LedgerPeriod[]` array, verbatim). `ledgerEntrySeq` is NOT carried — it
16
+ * has no client read surface; an importer can re-derive it from the highest
17
+ * entry number (LX-4's concern).
18
+ * - `library` — the ledger's own records in {@link LibrarySnapshot} shape
19
+ * (exactly how they travel in a backup bundle): the restricted root host
20
+ * page, the four child host pages, the four managed {@link StoredDatabase}s
21
+ * (full schema), and every row page.
22
+ * - `auditHead` — the newest audit event's `seq` + its chain hash
23
+ * ({@link ledgerAuditEventHash}): a cheap tamper-evidence ANCHOR. The full
24
+ * audit stream is deliberately NOT exported (a document export is not a
25
+ * backup; the stream can dwarf the books). Holding the anchor, a verifier
26
+ * with live access can prove the exported head is (or was) the real chain
27
+ * head; offline chain verification needs a real backup (LGR-15).
28
+ *
29
+ * ## Authorization (no escalation through export)
30
+ * Every read below goes through the exporting principal's OWN {@link DataClient}
31
+ * read paths — the same routes/guards that gate the ledger UI. A principal who
32
+ * cannot read the ledger sees `ledgerInfo() → {exists:false}` (the server's
33
+ * existence-hiding body) or 404s on the restricted pages; either way the
34
+ * capture returns `null` and the export simply carries no ledger section (the
35
+ * blocks render as placeholders, LX-1). Fail-closed: ANY partial read failure
36
+ * drops the whole section rather than embedding an incomplete book.
37
+ */
38
+ import type { DataClient } from './client';
39
+ import type { LibrarySnapshot } from './bookFolder';
40
+ import { type LedgerAccountStatus, type LedgerAccountType, type LedgerClearedState, type LedgerPeriod, type LedgerReconciliationStatus, type LedgerTransactionState } from './ledger';
41
+ /** The ledger records embedded in a site export's source island (LX-2). */
42
+ export interface LedgerExportSection {
43
+ /** Raw settings rows by key: `ledgerDb` (seeded ids) and `ledgerPeriods`
44
+ * (`LedgerPeriod[]`, present only when periods exist). Same keys as the
45
+ * backup bundle's `LedgerBackupSection.settings` (LGR-15). */
46
+ settings: Record<string, unknown>;
47
+ /** The ledger's own pages + databases, {@link LibrarySnapshot} shape: root
48
+ * host page, four child host pages, four managed databases, every row page. */
49
+ library: LibrarySnapshot;
50
+ /** Tamper-evidence anchor: the newest audit event's `seq` and chain hash.
51
+ * `null` when the audit stream is empty. The full stream is not exported. */
52
+ auditHead: {
53
+ seq: number;
54
+ hash: string;
55
+ } | null;
56
+ }
57
+ /**
58
+ * Capture the {@link LedgerExportSection} through the exporting principal's own
59
+ * read paths, or `null` when there is nothing to include: no seeded ledger,
60
+ * a principal who cannot read it, or any partial read failure (fail-closed —
61
+ * never embed half a book).
62
+ */
63
+ export declare function gatherLedgerExportSection(client: DataClient): Promise<LedgerExportSection | null>;
64
+ /** One account as the section records it (source ids kept for mapping). */
65
+ export interface LedgerSectionAccount {
66
+ id: string;
67
+ name: string;
68
+ type: LedgerAccountType;
69
+ status: LedgerAccountStatus;
70
+ currency: string;
71
+ evidenceRequired: boolean;
72
+ }
73
+ /** One posting as the section records it. */
74
+ export interface LedgerSectionPosting {
75
+ id: string;
76
+ accountId: string;
77
+ amountMinor: number;
78
+ cleared: LedgerClearedState;
79
+ reconciliationId: string | null;
80
+ memo: string | null;
81
+ }
82
+ /** One journal entry as the section records it. */
83
+ export interface LedgerSectionTransaction {
84
+ id: string;
85
+ date: string;
86
+ description: string;
87
+ state: LedgerTransactionState;
88
+ reverses: string | null;
89
+ entryNo: number | null;
90
+ kind: 'closing' | null;
91
+ /** Evidence manifest items recorded on the entry. An HTML export carries no
92
+ * evidence BYTES, so a restore drops these (counted, surfaced, never silent). */
93
+ evidenceCount: number;
94
+ postings: LedgerSectionPosting[];
95
+ createdAt: string;
96
+ }
97
+ /** One statement reconciliation as the section records it. */
98
+ export interface LedgerSectionReconciliation {
99
+ id: string;
100
+ accountId: string;
101
+ statementDate: string;
102
+ statementBalanceMinor: number;
103
+ status: LedgerReconciliationStatus;
104
+ createdAt: string;
105
+ }
106
+ /** The typed book a valid section parses to — the replay plan's input. */
107
+ export interface LedgerSectionBook {
108
+ accounts: LedgerSectionAccount[];
109
+ /** Sorted for replay: posted/void entries by entry number, drafts last. */
110
+ transactions: LedgerSectionTransaction[];
111
+ reconciliations: LedgerSectionReconciliation[];
112
+ /** Period records verbatim from `settings.ledgerPeriods` ([] when absent). */
113
+ periods: LedgerPeriod[];
114
+ auditHead: LedgerExportSection['auditHead'];
115
+ /** Total evidence manifest items the section records (not restorable from HTML). */
116
+ evidenceDropped: number;
117
+ }
118
+ export type LedgerSectionParseResult = {
119
+ ok: true;
120
+ book: LedgerSectionBook;
121
+ } | {
122
+ ok: false;
123
+ reason: string;
124
+ };
125
+ /** What a section restore reports back (see the server's `restoreExportSection`). */
126
+ export interface LedgerSectionRestoreResult {
127
+ restored: {
128
+ accounts: number;
129
+ transactions: number;
130
+ postings: number;
131
+ reconciliations: number;
132
+ periods: number;
133
+ };
134
+ /** Evidence manifest items that could not be restored — an HTML export
135
+ * carries no evidence bytes; recover them from a backup bundle (LGR-15). */
136
+ evidenceDropped: number;
137
+ /** Finished reconciliations whose exact freeze could not be reproduced
138
+ * (exotic reopen histories) and were replayed as ABANDONED instead —
139
+ * workflow metadata only; the postings and report numbers are unaffected. */
140
+ reconciliationsDowngraded: number;
141
+ }
142
+ /**
143
+ * Parse + deep-validate a {@link LedgerExportSection} into a replayable
144
+ * {@link LedgerSectionBook}, or refuse with a reason. Refusals are TOTAL —
145
+ * a section is either a coherent book or it is not restored at all (never a
146
+ * partial parse the writer then trips over halfway).
147
+ *
148
+ * Validated here (beyond the island reader's shape check):
149
+ * - the `ledgerDb` ids resolve to four DISTINCT databases the section carries;
150
+ * - every row page belongs to one of the four (host pages are pass-through);
151
+ * - enums, dates, and amounts are valid; posted/void entries balance to zero
152
+ * with ≥2 postings; postings reference known accounts/transactions;
153
+ * - the reversal graph is coherent: every `void` entry has exactly one
154
+ * reversal, every reversal negates its original leg-for-leg;
155
+ * - reconciliation invariants: `reconciled` ⇔ frozen by a FINISHED
156
+ * reconciliation on the same account, at most one OPEN per account;
157
+ * - period records are well-formed, closing entries are referenced by
158
+ * exactly one period, and closed ranges do not overlap.
159
+ */
160
+ export declare function parseLedgerExportSection(section: LedgerExportSection): LedgerSectionParseResult;