@opencxh/domain 1.241.0 → 1.243.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.
@@ -1,3 +1,4 @@
1
+ import { PostalAddress } from '../organization/types';
1
2
  import { OwnerScope } from '../scope/types';
2
3
  /** Where a company row came from. `local` is a row somebody created by hand. */
3
4
  export interface CompanySource {
@@ -39,6 +40,11 @@ export interface Company {
39
40
  externalIds: string[];
40
41
  ownerScope: OwnerScope;
41
42
  source: CompanySource;
43
+ /**
44
+ * Where the company sits. Needed by anything that puts this company on paper — a quote's
45
+ * recipient block is the first, and the issue gate refuses a document with a hole in it.
46
+ */
47
+ address?: PostalAddress;
42
48
  /** Raw, human-readable phone/website as entered, for display. */
43
49
  phone?: string;
44
50
  website?: string;
@@ -33,7 +33,7 @@ export type DocumentSlots = Record<string, readonly DocumentBlock[]>;
33
33
  * text lives.
34
34
  *
35
35
  * Every text-bearing field is walked, not just `text` — a token in a table cell or a letterhead
36
- * value is the ordinary case for an invoice, and missing one would leave `{factuur.nummer}`
36
+ * value is the ordinary case for an invoice, and missing one would leave `{invoice.number}`
37
37
  * printed on a document that went out the door.
38
38
  */
39
39
  export declare function fillDocument(blocks: readonly DocumentBlock[], context: TemplateContext, conditions?: Record<string, TemplateCondition>, slots?: DocumentSlots): FillDocumentResult;
@@ -59,7 +59,7 @@ export interface DocumentTemplate {
59
59
  * app that decides it.
60
60
  */
61
61
  export interface TemplateCondition {
62
- /** A path into the same context the tokens read: `klant.incasso`. */
62
+ /** A path into the same context the tokens read: `customer.direct_debit`. */
63
63
  key: string;
64
64
  /** Show when the value equals this. */
65
65
  equals?: unknown;
@@ -1,12 +1,18 @@
1
1
  import { OrganizationHouseStyle } from '../document-template/types';
2
2
  import { OrganizationProfile } from './profile';
3
- export interface OrganizationAddress {
3
+ /**
4
+ * A postal address. One shape wherever one appears — the organisation's own and a customer's.
5
+ *
6
+ * A quote prints both, and two types that differ only by name is how the two sides drift apart.
7
+ */
8
+ export interface PostalAddress {
4
9
  street?: string;
5
10
  houseNumber?: string;
6
11
  postalCode?: string;
7
12
  city?: string;
8
13
  country?: string;
9
14
  }
15
+ export type OrganizationAddress = PostalAddress;
10
16
  export interface OrganizationBilling {
11
17
  companyName?: string;
12
18
  /** BTW / VAT number */
@@ -0,0 +1,72 @@
1
+ import { DocumentBlock } from '../../platform/document-blocks';
2
+ import { DocumentSlots, TemplateContext } from '../document-template/tokens';
3
+ import { TaxRate } from '../money/tax';
4
+ import { PostalAddress } from '../organization/types';
5
+ import { Transaction } from './types';
6
+ /**
7
+ * The seam between a transaction and the paper it is printed on.
8
+ *
9
+ * Two functions and no renderer. The block order lives in a `DocumentTemplate` row, not in code:
10
+ * the moment it is hardcoded here, the template layer is decoration and every house-style change
11
+ * is a deploy. What a template *cannot* express is the line table and the totals — a token
12
+ * replaces text, it cannot build a table out of an array — so those arrive as slots.
13
+ *
14
+ * The consequence for a second consumer (a work order, a timesheet) is that it costs one context,
15
+ * one slot function and one seeded template row. No renderer, no screen, no export.
16
+ */
17
+ /** What a template author addresses. */
18
+ export interface TransactionContextSources {
19
+ companyName?: string;
20
+ /** The customer's postal address, for the recipient block. */
21
+ companyAddress?: PostalAddress;
22
+ contactName?: string;
23
+ organizationName?: string;
24
+ /** Who the recipient reads; drives which template row is picked. */
25
+ locale?: string;
26
+ }
27
+ /**
28
+ * The tokens: `{customer.name}`, `{quote.number}`, `{totals.gross}`.
29
+ *
30
+ * English, like every other identifier in this repo. A token is a **path into data**, not a
31
+ * sentence — the Dutch on a quote is the text a template author writes around it.
32
+ *
33
+ * **The cost price and the margin are not in here, and that is load-bearing.** A template author
34
+ * writes `{regel.bedrag}` by hand; if a cost ever landed in this object, `{regel.inkoop}` on a
35
+ * quote would be one typo away from the customer. The shield on the way out of the server
36
+ * (`transactionView`) is the second lock; this one is the first.
37
+ */
38
+ export declare function transactionContext(transaction: Transaction, sources?: TransactionContextSources): TemplateContext;
39
+ /**
40
+ * The blocks a template cannot write itself: the line table and the totals.
41
+ *
42
+ * Keyed by the `block_id` the template author puts on an empty placeholder — `lines` and `totals`.
43
+ * That pairing is a **convention**, not a contract: an author cannot invent a third slot and
44
+ * expect sales to fill it, because the consumer decides what it hands over.
45
+ *
46
+ * Amounts arrive already formatted. The blocks layer never computes; that is the whole reason a
47
+ * totals row carries a string.
48
+ */
49
+ export declare function transactionSlots(transaction: Transaction, rates?: readonly TaxRate[], labels?: SlotLabels): DocumentSlots;
50
+ export interface SlotLabels {
51
+ description: string;
52
+ quantity: string;
53
+ unitPrice: string;
54
+ net: string;
55
+ tax: string;
56
+ gross: string;
57
+ }
58
+ export declare const DUTCH_SLOT_LABELS: SlotLabels;
59
+ /**
60
+ * The default quote template, as a **seed** — not a renderer.
61
+ *
62
+ * Note the split inside it: the token **paths** are English because they address data, the
63
+ * **text** around them is Dutch because a customer reads it.
64
+ *
65
+ * The distinction is the whole point of the template layer: this array is written into a
66
+ * `DocumentTemplate` row the first time an organisation needs one, and from then on the row is
67
+ * the truth. An administrator moves the terms above the lines and that sticks; nobody deploys.
68
+ *
69
+ * The two empty placeholders are the slots {@link transactionSlots} fills. Their `block_id` is
70
+ * the whole contract.
71
+ */
72
+ export declare const DEFAULT_QUOTE_TEMPLATE_BLOCKS: DocumentBlock[];
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,5 @@
1
1
  export * from './convert';
2
+ export * from './document';
2
3
  export * from './keys';
3
4
  export * from './kinds';
4
5
  export * from './types';