@substrat-run/engine-invoicing 0.1.0 → 0.1.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 +65 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# @substrat-run/engine-invoicing
|
|
2
|
+
|
|
3
|
+
Invoicing engine for [Substrat](https://github.com/substrat-run/substrat) —
|
|
4
|
+
accumulates **invoice bases** (Swedish: *fakturaunderlag*) from billable events and
|
|
5
|
+
makes them **immutable once exported**.
|
|
6
|
+
|
|
7
|
+
It produces the *basis* for an invoice: per-customer collections of billable lines
|
|
8
|
+
with frozen prices and provenance, ready to hand to whatever actually issues invoices
|
|
9
|
+
(typically an accounting connector). It is **not** a ledger, not accounts receivable,
|
|
10
|
+
not payment tracking.
|
|
11
|
+
|
|
12
|
+
**Full documentation: https://substrat.ahlstrand.es/engines/invoicing**
|
|
13
|
+
|
|
14
|
+
## Snapshot, not join
|
|
15
|
+
|
|
16
|
+
The engine consumes `workorder.completed` with **zero imports** from the work-order
|
|
17
|
+
engine — star topology. The consumer parses its own Zod view of the event payload,
|
|
18
|
+
finds or creates the open underlag for that customer, and copies the billable lines
|
|
19
|
+
with provenance (`source_type`, `source_id`):
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
events: {
|
|
23
|
+
consumes: [{ type: 'workorder.completed', schemaVersion: 1 }],
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Prices are frozen from the payload at the moment the work order completed. If the
|
|
28
|
+
vertical's price list changes tomorrow, yesterday's underlag doesn't. Consumers are
|
|
29
|
+
delivered at-least-once; find-or-create plus the kernel's delivery journal keep the
|
|
30
|
+
handler idempotent.
|
|
31
|
+
|
|
32
|
+
## The immutability invariant
|
|
33
|
+
|
|
34
|
+
An underlag is `open` or `exported`:
|
|
35
|
+
|
|
36
|
+
- While **open**, consumed events append lines.
|
|
37
|
+
- **`invoicing/export`** flips it to `exported` — from then on it is immutable.
|
|
38
|
+
Nothing appends, nothing edits, exporting again throws.
|
|
39
|
+
- Billable work arriving *after* export opens a **new** underlag. History is never
|
|
40
|
+
rewritten; late facts become new facts.
|
|
41
|
+
|
|
42
|
+
`invoicing.underlag-exported` is the natural hook for an accounting connector that
|
|
43
|
+
turns the frozen basis into a real invoice.
|
|
44
|
+
|
|
45
|
+
## Operations
|
|
46
|
+
|
|
47
|
+
| Operation | Permission | Does |
|
|
48
|
+
|---|---|---|
|
|
49
|
+
| `invoicing/list` | `invoicing:read` | list underlag, each with computed total |
|
|
50
|
+
| `invoicing/get` | `invoicing:read` | one underlag with all lines and total |
|
|
51
|
+
| `invoicing/export` | `invoicing:export` | flip to `exported` — the point of no return |
|
|
52
|
+
|
|
53
|
+
Totals use exact decimal arithmetic from
|
|
54
|
+
[`@substrat-run/contracts`](https://npmjs.com/package/@substrat-run/contracts), never floats.
|
|
55
|
+
|
|
56
|
+
## Related packages
|
|
57
|
+
|
|
58
|
+
- [`@substrat-run/kernel`](https://npmjs.com/package/@substrat-run/kernel) — the
|
|
59
|
+
scope-host contract these operations run on
|
|
60
|
+
- [`@substrat-run/engine-workorder`](https://npmjs.com/package/@substrat-run/engine-workorder) —
|
|
61
|
+
the producer of the billable events this engine consumes
|
|
62
|
+
|
|
63
|
+
## Status
|
|
64
|
+
|
|
65
|
+
Pre-release (0.x): surfaces change without notice until the first vertical ships.
|
package/dist/index.d.ts
CHANGED
|
@@ -35,6 +35,12 @@ export declare const invoicingManifest: {
|
|
|
35
35
|
entityType: string;
|
|
36
36
|
parentType: string;
|
|
37
37
|
}[] | undefined;
|
|
38
|
+
guards?: {
|
|
39
|
+
before: string;
|
|
40
|
+
predicate: string;
|
|
41
|
+
config: Record<string, unknown>;
|
|
42
|
+
}[] | undefined;
|
|
43
|
+
withdraws?: string[] | undefined;
|
|
38
44
|
api?: string | undefined;
|
|
39
45
|
searchables?: {
|
|
40
46
|
entityType: string;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,OAAO,EAIL,KAAK,kBAAkB,EAGxB,MAAM,sBAAsB,CAAC;AAS9B,eAAO,MAAM,cAAc;;;CAG1B,CAAC;AAEF,eAAO,MAAM,iBAAiB
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,OAAO,EAIL,KAAK,kBAAkB,EAGxB,MAAM,sBAAsB,CAAC;AAS9B,eAAO,MAAM,cAAc;;;CAG1B,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAkPyb,CAAC;;;;;WAAyJ,CAAC;;;;gBAAkI,CAAC;;mBAAkE,CAAC;;;;eAAsG,CAAC;;;;;sBAAuK,CAAC;;;;;;CA3NrkC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;GA6B/B,CAAC;AAuBF,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;CACpB;AAkID,eAAO,MAAM,eAAe,EAAE,kBAW7B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@substrat-run/engine-invoicing",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Substrat engine: fakturaunderlag — consumes billable events, snapshots lines with provenance, immutable once exported",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"repository": {
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"zod": "^3.25.0",
|
|
29
|
-
"@substrat-run/
|
|
30
|
-
"@substrat-run/
|
|
29
|
+
"@substrat-run/contracts": "^0.2.0",
|
|
30
|
+
"@substrat-run/kernel": "^0.2.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"typescript": "^5.6.0"
|