@fleetless/contracts 7.0.0-next.1 → 7.1.0-next.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.
@@ -0,0 +1,113 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "type": "object",
4
+ "properties": {
5
+ "available": {
6
+ "type": "boolean",
7
+ "description": "Whether this cloud can list Lexware documents at all for this org — `false` when this cloud has no Lexware configured, its Lexware account failed the account check, or the org has no Lexware contact."
8
+ },
9
+ "complete": {
10
+ "type": "boolean",
11
+ "description": "`false` when a document of an unsupported type or status was skipped rather than listed, counted in `unsupported_count`."
12
+ },
13
+ "unsupported_count": {
14
+ "type": "integer",
15
+ "minimum": 0,
16
+ "maximum": 9007199254740991,
17
+ "description": "How many documents of an unsupported type or status were skipped; `complete` is `false` whenever this is above zero."
18
+ },
19
+ "documents": {
20
+ "type": "array",
21
+ "items": {
22
+ "type": "object",
23
+ "properties": {
24
+ "id": {
25
+ "type": "string",
26
+ "format": "uuid",
27
+ "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$",
28
+ "description": "The Lexware voucher id. Opaque; read the document or its file by this id, never a locally invented one."
29
+ },
30
+ "kind": {
31
+ "type": "string",
32
+ "enum": [
33
+ "invoice",
34
+ "credit_note",
35
+ "down_payment_invoice",
36
+ "bookkeeping_invoice",
37
+ "bookkeeping_credit_note"
38
+ ],
39
+ "description": "The document's kind."
40
+ },
41
+ "status": {
42
+ "type": "string",
43
+ "enum": [
44
+ "open",
45
+ "overdue",
46
+ "paid",
47
+ "paidoff",
48
+ "voided",
49
+ "transferred",
50
+ "sepadebit"
51
+ ],
52
+ "description": "The document's own status."
53
+ },
54
+ "number": {
55
+ "anyOf": [
56
+ {
57
+ "type": "string"
58
+ },
59
+ {
60
+ "type": "null"
61
+ }
62
+ ],
63
+ "description": "The Lexware voucher number, for display only — never a key to read by. `null` for a voucher Lexware has not numbered."
64
+ },
65
+ "document_date": {
66
+ "type": "string",
67
+ "format": "date-time",
68
+ "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$",
69
+ "description": "The date printed on the document."
70
+ },
71
+ "currency": {
72
+ "type": "string",
73
+ "const": "EUR",
74
+ "description": "Every Lexware voucher this reads is EUR; nothing here reads a foreign-currency voucher."
75
+ },
76
+ "gross_cents": {
77
+ "type": "integer",
78
+ "minimum": -9007199254740991,
79
+ "maximum": 9007199254740991,
80
+ "description": "The gross amount, in integer cents, signed by `kind` and never by the sign Lexware itself reports: `credit_note` and `bookkeeping_credit_note` are zero or negative, every other kind is zero or positive."
81
+ },
82
+ "file": {
83
+ "type": "string",
84
+ "enum": [
85
+ "available",
86
+ "unavailable"
87
+ ],
88
+ "description": "Whether Lexware holds a file for this document at all."
89
+ }
90
+ },
91
+ "required": [
92
+ "id",
93
+ "kind",
94
+ "status",
95
+ "number",
96
+ "document_date",
97
+ "currency",
98
+ "gross_cents",
99
+ "file"
100
+ ],
101
+ "additionalProperties": false
102
+ },
103
+ "description": "Every supported document this org has, complete or not — never a truncated page."
104
+ }
105
+ },
106
+ "required": [
107
+ "available",
108
+ "complete",
109
+ "unsupported_count",
110
+ "documents"
111
+ ],
112
+ "additionalProperties": false
113
+ }
@@ -0,0 +1,83 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "type": "object",
4
+ "properties": {
5
+ "id": {
6
+ "type": "string",
7
+ "format": "uuid",
8
+ "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$",
9
+ "description": "The Lexware voucher id. Opaque; read the document or its file by this id, never a locally invented one."
10
+ },
11
+ "kind": {
12
+ "type": "string",
13
+ "enum": [
14
+ "invoice",
15
+ "credit_note",
16
+ "down_payment_invoice",
17
+ "bookkeeping_invoice",
18
+ "bookkeeping_credit_note"
19
+ ],
20
+ "description": "The document's kind."
21
+ },
22
+ "status": {
23
+ "type": "string",
24
+ "enum": [
25
+ "open",
26
+ "overdue",
27
+ "paid",
28
+ "paidoff",
29
+ "voided",
30
+ "transferred",
31
+ "sepadebit"
32
+ ],
33
+ "description": "The document's own status."
34
+ },
35
+ "number": {
36
+ "anyOf": [
37
+ {
38
+ "type": "string"
39
+ },
40
+ {
41
+ "type": "null"
42
+ }
43
+ ],
44
+ "description": "The Lexware voucher number, for display only — never a key to read by. `null` for a voucher Lexware has not numbered."
45
+ },
46
+ "document_date": {
47
+ "type": "string",
48
+ "format": "date-time",
49
+ "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$",
50
+ "description": "The date printed on the document."
51
+ },
52
+ "currency": {
53
+ "type": "string",
54
+ "const": "EUR",
55
+ "description": "Every Lexware voucher this reads is EUR; nothing here reads a foreign-currency voucher."
56
+ },
57
+ "gross_cents": {
58
+ "type": "integer",
59
+ "minimum": -9007199254740991,
60
+ "maximum": 9007199254740991,
61
+ "description": "The gross amount, in integer cents, signed by `kind` and never by the sign Lexware itself reports: `credit_note` and `bookkeeping_credit_note` are zero or negative, every other kind is zero or positive."
62
+ },
63
+ "file": {
64
+ "type": "string",
65
+ "enum": [
66
+ "available",
67
+ "unavailable"
68
+ ],
69
+ "description": "Whether Lexware holds a file for this document at all."
70
+ }
71
+ },
72
+ "required": [
73
+ "id",
74
+ "kind",
75
+ "status",
76
+ "number",
77
+ "document_date",
78
+ "currency",
79
+ "gross_cents",
80
+ "file"
81
+ ],
82
+ "additionalProperties": false
83
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "type": "object",
4
+ "properties": {
5
+ "reason": {
6
+ "type": "string",
7
+ "enum": [
8
+ "provider_unavailable",
9
+ "rate_limited",
10
+ "list_limit_exceeded",
11
+ "list_changed",
12
+ "unsupported_document",
13
+ "profile_mismatch"
14
+ ],
15
+ "description": "Why Cloud refused rather than answering with a partial or unchecked document: `provider_unavailable` (Lexware did not answer or answered with an error), `rate_limited` (Lexware throttled the request; nothing was read), `list_limit_exceeded` (Lexware reports more than 10,000 documents for the org), `list_changed` (the document list changed while it was being paged, so no consistent list exists), `unsupported_document` (the detail or the file only: Lexware answered with an e-invoice profile or a file this cloud cannot present as the document), `profile_mismatch` (the Lexware account this cloud is configured with failed its account check, so every Lexware read stays closed)."
16
+ }
17
+ },
18
+ "required": [
19
+ "reason"
20
+ ],
21
+ "additionalProperties": false
22
+ }
package/dist/billing.d.ts CHANGED
@@ -1144,6 +1144,173 @@ export declare const billingView: z.ZodObject<{
1144
1144
  }, z.core.$strip>>;
1145
1145
  }, z.core.$strip>;
1146
1146
  export type BillingView = z.infer<typeof billingView>;
1147
+ /**
1148
+ * A document's kind, narrowed from Lexware's own `voucherType`: `invoice` ←
1149
+ * `invoice`, `credit_note` ← `creditnote`, `down_payment_invoice` ←
1150
+ * `downpaymentinvoice`, `bookkeeping_invoice` ← `salesinvoice`,
1151
+ * `bookkeeping_credit_note` ← `salescreditnote`.
1152
+ */
1153
+ export declare const billingDocumentKind: z.ZodEnum<{
1154
+ invoice: "invoice";
1155
+ credit_note: "credit_note";
1156
+ down_payment_invoice: "down_payment_invoice";
1157
+ bookkeeping_invoice: "bookkeeping_invoice";
1158
+ bookkeeping_credit_note: "bookkeeping_credit_note";
1159
+ }>;
1160
+ export type BillingDocumentKind = z.infer<typeof billingDocumentKind>;
1161
+ /** A document's own status, read from the Lexware voucher as it stands today. */
1162
+ export declare const billingDocumentStatus: z.ZodEnum<{
1163
+ paid: "paid";
1164
+ open: "open";
1165
+ overdue: "overdue";
1166
+ paidoff: "paidoff";
1167
+ voided: "voided";
1168
+ transferred: "transferred";
1169
+ sepadebit: "sepadebit";
1170
+ }>;
1171
+ export type BillingDocumentStatus = z.infer<typeof billingDocumentStatus>;
1172
+ /**
1173
+ * The electronic-invoice profile of an `invoice`, `down_payment_invoice` or
1174
+ * `credit_note`: `NONE` is a plain PDF and never an e-invoice; `EN16931`
1175
+ * (ZUGFeRD) is a PDF with an embedded XML, and that PDF is itself the
1176
+ * e-invoice; `XRechnung` is an XML that is the e-invoice, with a PDF that is
1177
+ * only a preview. `null` on a bookkeeping voucher — it has no profile at all.
1178
+ */
1179
+ export declare const billingDocumentProfile: z.ZodEnum<{
1180
+ NONE: "NONE";
1181
+ EN16931: "EN16931";
1182
+ XRechnung: "XRechnung";
1183
+ }>;
1184
+ export type BillingDocumentProfile = z.infer<typeof billingDocumentProfile>;
1185
+ /** A file format a document's bytes may be read in. */
1186
+ export declare const billingDocumentFormat: z.ZodEnum<{
1187
+ pdf: "pdf";
1188
+ xml: "xml";
1189
+ }>;
1190
+ export type BillingDocumentFormat = z.infer<typeof billingDocumentFormat>;
1191
+ /** One Lexware document, as `GET /api/billing/documents` lists it. */
1192
+ export declare const billingDocument: z.ZodObject<{
1193
+ id: z.ZodUUID;
1194
+ kind: z.ZodEnum<{
1195
+ invoice: "invoice";
1196
+ credit_note: "credit_note";
1197
+ down_payment_invoice: "down_payment_invoice";
1198
+ bookkeeping_invoice: "bookkeeping_invoice";
1199
+ bookkeeping_credit_note: "bookkeeping_credit_note";
1200
+ }>;
1201
+ status: z.ZodEnum<{
1202
+ paid: "paid";
1203
+ open: "open";
1204
+ overdue: "overdue";
1205
+ paidoff: "paidoff";
1206
+ voided: "voided";
1207
+ transferred: "transferred";
1208
+ sepadebit: "sepadebit";
1209
+ }>;
1210
+ number: z.ZodNullable<z.ZodString>;
1211
+ document_date: z.ZodISODateTime;
1212
+ currency: z.ZodLiteral<"EUR">;
1213
+ gross_cents: z.ZodNumber;
1214
+ file: z.ZodEnum<{
1215
+ unavailable: "unavailable";
1216
+ available: "available";
1217
+ }>;
1218
+ }, z.core.$strict>;
1219
+ export type BillingDocument = z.infer<typeof billingDocument>;
1220
+ /** `GET /api/billing/documents`'s answer. */
1221
+ export declare const billingDocumentList: z.ZodObject<{
1222
+ available: z.ZodBoolean;
1223
+ complete: z.ZodBoolean;
1224
+ unsupported_count: z.ZodNumber;
1225
+ documents: z.ZodArray<z.ZodObject<{
1226
+ id: z.ZodUUID;
1227
+ kind: z.ZodEnum<{
1228
+ invoice: "invoice";
1229
+ credit_note: "credit_note";
1230
+ down_payment_invoice: "down_payment_invoice";
1231
+ bookkeeping_invoice: "bookkeeping_invoice";
1232
+ bookkeeping_credit_note: "bookkeeping_credit_note";
1233
+ }>;
1234
+ status: z.ZodEnum<{
1235
+ paid: "paid";
1236
+ open: "open";
1237
+ overdue: "overdue";
1238
+ paidoff: "paidoff";
1239
+ voided: "voided";
1240
+ transferred: "transferred";
1241
+ sepadebit: "sepadebit";
1242
+ }>;
1243
+ number: z.ZodNullable<z.ZodString>;
1244
+ document_date: z.ZodISODateTime;
1245
+ currency: z.ZodLiteral<"EUR">;
1246
+ gross_cents: z.ZodNumber;
1247
+ file: z.ZodEnum<{
1248
+ unavailable: "unavailable";
1249
+ available: "available";
1250
+ }>;
1251
+ }, z.core.$strict>>;
1252
+ }, z.core.$strict>;
1253
+ export type BillingDocumentList = z.infer<typeof billingDocumentList>;
1254
+ /** Which role a file plays for a document: the e-invoice itself, a preview rendered alongside it, or the plain document. */
1255
+ export declare const billingDocumentFileRole: z.ZodEnum<{
1256
+ e_invoice: "e_invoice";
1257
+ preview: "preview";
1258
+ document: "document";
1259
+ }>;
1260
+ export type BillingDocumentFileRole = z.infer<typeof billingDocumentFileRole>;
1261
+ /** `GET /api/billing/documents/:id`'s answer: `billingDocument` plus the e-invoice profile and the files this document offers. */
1262
+ export declare const billingDocumentDetail: z.ZodObject<{
1263
+ id: z.ZodUUID;
1264
+ kind: z.ZodEnum<{
1265
+ invoice: "invoice";
1266
+ credit_note: "credit_note";
1267
+ down_payment_invoice: "down_payment_invoice";
1268
+ bookkeeping_invoice: "bookkeeping_invoice";
1269
+ bookkeeping_credit_note: "bookkeeping_credit_note";
1270
+ }>;
1271
+ status: z.ZodEnum<{
1272
+ paid: "paid";
1273
+ open: "open";
1274
+ overdue: "overdue";
1275
+ paidoff: "paidoff";
1276
+ voided: "voided";
1277
+ transferred: "transferred";
1278
+ sepadebit: "sepadebit";
1279
+ }>;
1280
+ number: z.ZodNullable<z.ZodString>;
1281
+ document_date: z.ZodISODateTime;
1282
+ currency: z.ZodLiteral<"EUR">;
1283
+ gross_cents: z.ZodNumber;
1284
+ file: z.ZodEnum<{
1285
+ unavailable: "unavailable";
1286
+ available: "available";
1287
+ }>;
1288
+ electronic_document_profile: z.ZodNullable<z.ZodEnum<{
1289
+ NONE: "NONE";
1290
+ EN16931: "EN16931";
1291
+ XRechnung: "XRechnung";
1292
+ }>>;
1293
+ formats: z.ZodArray<z.ZodObject<{
1294
+ format: z.ZodEnum<{
1295
+ pdf: "pdf";
1296
+ xml: "xml";
1297
+ }>;
1298
+ role: z.ZodEnum<{
1299
+ e_invoice: "e_invoice";
1300
+ preview: "preview";
1301
+ document: "document";
1302
+ }>;
1303
+ }, z.core.$strict>>;
1304
+ }, z.core.$strict>;
1305
+ export type BillingDocumentDetail = z.infer<typeof billingDocumentDetail>;
1306
+ /** `GET /api/billing/documents/:id/file`'s query: which format to read the file in. */
1307
+ export declare const billingDocumentFileQuery: z.ZodObject<{
1308
+ format: z.ZodDefault<z.ZodEnum<{
1309
+ pdf: "pdf";
1310
+ xml: "xml";
1311
+ }>>;
1312
+ }, z.core.$strict>;
1313
+ export type BillingDocumentFileQuery = z.infer<typeof billingDocumentFileQuery>;
1147
1314
  export declare const billingChangeResponse: z.ZodUnion<readonly [z.ZodObject<{
1148
1315
  billing: z.ZodObject<{
1149
1316
  available: z.ZodBoolean;
package/dist/billing.js CHANGED
@@ -562,6 +562,116 @@ export const billingView = z.object({
562
562
  }),
563
563
  invoices: z.array(billingInvoice).meta({ description: 'Newest first, at most 24.' }),
564
564
  });
565
+ /*
566
+ * ---------------------------------------------------------------------------
567
+ * Billing documents: a read-only view of the Lexware vouchers issued to
568
+ * the org's company (2026-10-19, fleetless/fleetless#544).
569
+ *
570
+ * `GET /api/billing/documents`, `GET /api/billing/documents/:id` and
571
+ * `GET /api/billing/documents/:id/file` in `src/routes.ts`. Cloud resolves
572
+ * the org's own Lexware contact itself; the contact is never supplied by the
573
+ * caller. Only finalized vouchers of the five kinds below ever appear — a
574
+ * draft, a quotation, an order confirmation, a delivery note or a purchase
575
+ * voucher never does, and a voided one still does.
576
+ * ---------------------------------------------------------------------------
577
+ */
578
+ /**
579
+ * A document's kind, narrowed from Lexware's own `voucherType`: `invoice` ←
580
+ * `invoice`, `credit_note` ← `creditnote`, `down_payment_invoice` ←
581
+ * `downpaymentinvoice`, `bookkeeping_invoice` ← `salesinvoice`,
582
+ * `bookkeeping_credit_note` ← `salescreditnote`.
583
+ */
584
+ export const billingDocumentKind = z.enum(['invoice', 'credit_note', 'down_payment_invoice', 'bookkeeping_invoice', 'bookkeeping_credit_note']);
585
+ /** A document's own status, read from the Lexware voucher as it stands today. */
586
+ export const billingDocumentStatus = z.enum(['open', 'overdue', 'paid', 'paidoff', 'voided', 'transferred', 'sepadebit']);
587
+ /**
588
+ * The electronic-invoice profile of an `invoice`, `down_payment_invoice` or
589
+ * `credit_note`: `NONE` is a plain PDF and never an e-invoice; `EN16931`
590
+ * (ZUGFeRD) is a PDF with an embedded XML, and that PDF is itself the
591
+ * e-invoice; `XRechnung` is an XML that is the e-invoice, with a PDF that is
592
+ * only a preview. `null` on a bookkeeping voucher — it has no profile at all.
593
+ */
594
+ export const billingDocumentProfile = z.enum(['NONE', 'EN16931', 'XRechnung']);
595
+ /** A file format a document's bytes may be read in. */
596
+ export const billingDocumentFormat = z.enum(['pdf', 'xml']);
597
+ /**
598
+ * The fields shared by `billingDocument` and `billingDocumentDetail`, kept
599
+ * unrefined so `billingDocumentDetail` can `.extend()` it without depending
600
+ * on whether a `.superRefine()` survives an `.extend()` call. The sign rule
601
+ * below (`refuseWrongGrossSign`) is therefore applied separately to each of
602
+ * the two exports, sharing the one function rather than the one schema.
603
+ */
604
+ const billingDocumentBase = z.object({
605
+ id: z.uuid().meta({ description: 'The Lexware voucher id. Opaque; read the document or its file by this id, never a locally invented one.' }),
606
+ kind: billingDocumentKind.meta({ description: "The document's kind." }),
607
+ status: billingDocumentStatus.meta({ description: "The document's own status." }),
608
+ number: z.string().nullable().meta({ description: "The Lexware voucher number, for display only — never a key to read by. `null` for a voucher Lexware has not numbered." }),
609
+ document_date: z.iso.datetime({ offset: true }).meta({ description: 'The date printed on the document.' }),
610
+ currency: z.literal('EUR').meta({ description: 'Every Lexware voucher this reads is EUR; nothing here reads a foreign-currency voucher.' }),
611
+ gross_cents: z.number().int().meta({
612
+ description: 'The gross amount, in integer cents, signed by `kind` and never by the sign Lexware itself reports: `credit_note` and ' +
613
+ '`bookkeeping_credit_note` are zero or negative, every other kind is zero or positive.',
614
+ }),
615
+ file: z.enum(['available', 'unavailable']).meta({ description: 'Whether Lexware holds a file for this document at all.' }),
616
+ });
617
+ /** Refused on a sign that disagrees with `kind`, regardless of what Lexware itself reported. */
618
+ function refuseWrongGrossSign(doc, ctx) {
619
+ const isCredit = doc.kind === 'credit_note' || doc.kind === 'bookkeeping_credit_note';
620
+ if (isCredit && doc.gross_cents > 0) {
621
+ ctx.addIssue({ code: 'custom', path: ['gross_cents'], message: 'A credit note is zero or negative.' });
622
+ }
623
+ if (!isCredit && doc.gross_cents < 0) {
624
+ ctx.addIssue({ code: 'custom', path: ['gross_cents'], message: 'Only a credit note is negative.' });
625
+ }
626
+ }
627
+ /** One Lexware document, as `GET /api/billing/documents` lists it. */
628
+ export const billingDocument = billingDocumentBase.strict().superRefine(refuseWrongGrossSign);
629
+ /** `GET /api/billing/documents`'s answer. */
630
+ export const billingDocumentList = z.object({
631
+ available: z.boolean().meta({ description: 'Whether this cloud can list Lexware documents at all for this org — `false` when this cloud has no Lexware configured, its Lexware account failed the account check, or the org has no Lexware contact.' }),
632
+ complete: z.boolean().meta({ description: '`false` when a document of an unsupported type or status was skipped rather than listed, counted in `unsupported_count`.' }),
633
+ unsupported_count: z.number().int().nonnegative().meta({ description: 'How many documents of an unsupported type or status were skipped; `complete` is `false` whenever this is above zero.' }),
634
+ documents: z.array(billingDocument).meta({ description: 'Every supported document this org has, complete or not — never a truncated page.' }),
635
+ }).strict().superRefine((list, ctx) => {
636
+ if (!list.available && (list.documents.length > 0 || !list.complete || list.unsupported_count > 0)) {
637
+ ctx.addIssue({ code: 'custom', path: ['available'], message: 'available: false carries no documents, is complete and has no unsupported document.' });
638
+ }
639
+ });
640
+ /** Which role a file plays for a document: the e-invoice itself, a preview rendered alongside it, or the plain document. */
641
+ export const billingDocumentFileRole = z.enum(['e_invoice', 'preview', 'document']);
642
+ const billingDocumentFormatEntry = z.object({ format: billingDocumentFormat, role: billingDocumentFileRole }).strict();
643
+ function sameFormats(a, b) {
644
+ return a.length === b.length && a.every((entry, i) => entry.format === b[i].format && entry.role === b[i].role);
645
+ }
646
+ /** Refused on any `formats` that disagrees with `electronic_document_profile` (or, for `null`, with `file`). */
647
+ function refuseWrongFormats(doc, ctx) {
648
+ const expected = doc.electronic_document_profile === 'NONE' ? [{ format: 'pdf', role: 'document' }]
649
+ : doc.electronic_document_profile === 'EN16931' ? [{ format: 'pdf', role: 'e_invoice' }]
650
+ : doc.electronic_document_profile === 'XRechnung' ? [{ format: 'xml', role: 'e_invoice' }, { format: 'pdf', role: 'preview' }]
651
+ : doc.file === 'available' ? [{ format: 'pdf', role: 'document' }] : [];
652
+ if (!sameFormats(doc.formats, expected)) {
653
+ ctx.addIssue({ code: 'custom', path: ['formats'], message: 'formats must match electronic_document_profile (or, for a bookkeeping voucher, file) exactly.' });
654
+ }
655
+ }
656
+ /** `GET /api/billing/documents/:id`'s answer: `billingDocument` plus the e-invoice profile and the files this document offers. */
657
+ export const billingDocumentDetail = billingDocumentBase
658
+ .extend({
659
+ electronic_document_profile: billingDocumentProfile.nullable().meta({ description: 'The e-invoice profile, or `null` for a bookkeeping voucher — it has none.' }),
660
+ formats: z.array(billingDocumentFormatEntry).meta({
661
+ description: '`NONE`: `[{ format: "pdf", role: "document" }]`. `EN16931`: `[{ format: "pdf", role: "e_invoice" }]`. `XRechnung`: ' +
662
+ '`[{ format: "xml", role: "e_invoice" }, { format: "pdf", role: "preview" }]`. `null` profile: `[{ format: "pdf", role: "document" }]` ' +
663
+ 'when `file` is `available`, otherwise `[]`.',
664
+ }),
665
+ })
666
+ .strict()
667
+ .superRefine((doc, ctx) => {
668
+ refuseWrongGrossSign(doc, ctx);
669
+ refuseWrongFormats(doc, ctx);
670
+ });
671
+ /** `GET /api/billing/documents/:id/file`'s query: which format to read the file in. */
672
+ export const billingDocumentFileQuery = z.object({
673
+ format: billingDocumentFormat.default('pdf').meta({ description: 'The file format to read. `xml` answers `404` unless the document is `XRechnung`.' }),
674
+ }).strict();
565
675
  /** `POST /api/billing/change`'s answer: the billing view afterwards, and what was charged right now, if anything. */
566
676
  const acceptedBillingChange = z.object({
567
677
  billing: billingView.meta({ description: 'The billing view after the change.' }),
package/dist/errors.d.ts CHANGED
@@ -237,10 +237,26 @@ export declare const paymentProviderUnavailableDetails: z.ZodObject<{
237
237
  status: z.ZodNullable<z.ZodNumber>;
238
238
  }, z.core.$strip>;
239
239
  export type PaymentProviderUnavailableDetails = z.infer<typeof paymentProviderUnavailableDetails>;
240
+ /**
241
+ * The `details` of a `billing_documents_unavailable` refusal (2026-10-19,
242
+ * fleetless/fleetless#544): which of the six reasons Cloud could not
243
+ * produce a complete, trustworthy answer from Lexware for.
244
+ */
245
+ export declare const billingDocumentsUnavailableDetails: z.ZodObject<{
246
+ reason: z.ZodEnum<{
247
+ provider_unavailable: "provider_unavailable";
248
+ rate_limited: "rate_limited";
249
+ list_limit_exceeded: "list_limit_exceeded";
250
+ list_changed: "list_changed";
251
+ unsupported_document: "unsupported_document";
252
+ profile_mismatch: "profile_mismatch";
253
+ }>;
254
+ }, z.core.$strict>;
255
+ export type BillingDocumentsUnavailableDetails = z.infer<typeof billingDocumentsUnavailableDetails>;
240
256
  /**
241
257
  * The codes in use today. The wire deliberately allows any string — this
242
258
  * list is the shared vocabulary, not a closed set, so a new refusal never
243
259
  * needs a contracts release before it can be reported honestly.
244
260
  */
245
- export declare const ERROR_CODES: readonly ["not_found", "validation_error", "bad_request", "unknown_datapoint", "invalid_token", "protocol_mismatch", "bridge_too_old", "invalid_frame", "duplicate_slug", "reserved_slug", "unknown_slug", "unknown_field_path", "unknown_type", "unknown_topic", "invalid_rate", "invalid_range", "config_conflict", "no_data", "robot_offline", "bridge_timeout", "unauthorized", "forbidden", "invalid_credentials", "token_expired", "token_revoked", "email_taken", "identifier_taken", "weak_password", "account_blocked", "busy", "parameter_invalid", "cancel_rejected", "job_lost", "job_unknown_to_bridge", "action_server_lost", "action_failed", "goal_rejected", "goal_send_failed", "result_failed", "goal_uncontrollable", "bridge_disconnected", "config_changed", "publisher_busy", "unknown_command", "not_subscribable", "camera_offline", "no_snapshot_yet", "live_unavailable", "wrong_kind", "not_recorded", "not_aggregatable", "quota_exceeded", "credential_in_use", "goal_timeout", "robot_in_use", "robot_deletion_partial", "job_queue_full", "invalid_uuid", "rate_limited", "tier_required", "token_spent", "service_timeout", "asset_missing", "dynamic_registration_disabled", "client_limit_reached", "idp_unavailable", "mcp_disabled", "tool_not_available", "capability_required", "last_owner", "role_name_taken", "role_in_use", "last_role", "target_state_conflict", "signup_closed", "draft_not_a_document", "internal_error", "not_cancellable", "unsupported_media_type", "wrong_browser", "invalid_yaml", "unstorable_yaml", "registration_closed", "domain_not_allowed", "email_unverified", "origin_not_allowed", "template_invalid", "provider_disabled", "provider_misconfigured", "invalid_redirect_uri", "interaction_expired", "invalid_code", "method_not_allowed", "plan_limit", "plan_required", "org_locked", "file_too_large", "billing_unavailable", "payment_provider_unavailable", "history_migrating"];
261
+ export declare const ERROR_CODES: readonly ["not_found", "validation_error", "bad_request", "unknown_datapoint", "invalid_token", "protocol_mismatch", "bridge_too_old", "invalid_frame", "duplicate_slug", "reserved_slug", "unknown_slug", "unknown_field_path", "unknown_type", "unknown_topic", "invalid_rate", "invalid_range", "config_conflict", "no_data", "robot_offline", "bridge_timeout", "unauthorized", "forbidden", "invalid_credentials", "token_expired", "token_revoked", "email_taken", "identifier_taken", "weak_password", "account_blocked", "busy", "parameter_invalid", "cancel_rejected", "job_lost", "job_unknown_to_bridge", "action_server_lost", "action_failed", "goal_rejected", "goal_send_failed", "result_failed", "goal_uncontrollable", "bridge_disconnected", "config_changed", "publisher_busy", "unknown_command", "not_subscribable", "camera_offline", "no_snapshot_yet", "live_unavailable", "wrong_kind", "not_recorded", "not_aggregatable", "quota_exceeded", "credential_in_use", "goal_timeout", "robot_in_use", "robot_deletion_partial", "job_queue_full", "invalid_uuid", "rate_limited", "tier_required", "token_spent", "service_timeout", "asset_missing", "dynamic_registration_disabled", "client_limit_reached", "idp_unavailable", "mcp_disabled", "tool_not_available", "capability_required", "last_owner", "role_name_taken", "role_in_use", "last_role", "target_state_conflict", "signup_closed", "draft_not_a_document", "internal_error", "not_cancellable", "unsupported_media_type", "wrong_browser", "invalid_yaml", "unstorable_yaml", "registration_closed", "domain_not_allowed", "email_unverified", "origin_not_allowed", "template_invalid", "provider_disabled", "provider_misconfigured", "invalid_redirect_uri", "interaction_expired", "invalid_code", "method_not_allowed", "plan_limit", "plan_required", "org_locked", "file_too_large", "billing_unavailable", "payment_provider_unavailable", "history_migrating", "billing_documents_unavailable"];
246
262
  export type ErrorCode = (typeof ERROR_CODES)[number];
package/dist/errors.js CHANGED
@@ -165,6 +165,21 @@ export const paymentProviderUnavailableDetails = z.object({
165
165
  provider: z.literal('mollie').meta({ description: 'The payment provider. Always `mollie` today.' }),
166
166
  status: z.number().int().nullable().meta({ description: "Mollie's own HTTP status, or `null` when the request timed out instead of answering." }),
167
167
  });
168
+ /**
169
+ * The `details` of a `billing_documents_unavailable` refusal (2026-10-19,
170
+ * fleetless/fleetless#544): which of the six reasons Cloud could not
171
+ * produce a complete, trustworthy answer from Lexware for.
172
+ */
173
+ export const billingDocumentsUnavailableDetails = z.object({
174
+ reason: z.enum(['provider_unavailable', 'rate_limited', 'list_limit_exceeded', 'list_changed', 'unsupported_document', 'profile_mismatch']).meta({
175
+ description: 'Why Cloud refused rather than answering with a partial or unchecked document: `provider_unavailable` (Lexware did not answer ' +
176
+ 'or answered with an error), `rate_limited` (Lexware throttled the request; nothing was read), `list_limit_exceeded` (Lexware ' +
177
+ 'reports more than 10,000 documents for the org), `list_changed` (the document list changed while it was being paged, so no ' +
178
+ 'consistent list exists), `unsupported_document` (the detail or the file only: Lexware answered with an e-invoice profile or a ' +
179
+ 'file this cloud cannot present as the document), `profile_mismatch` (the Lexware account this cloud is configured with failed ' +
180
+ 'its account check, so every Lexware read stays closed).',
181
+ }),
182
+ }).strict();
168
183
  /**
169
184
  * The codes in use today. The wire deliberately allows any string — this
170
185
  * list is the shared vocabulary, not a closed set, so a new refusal never
@@ -1069,4 +1084,21 @@ export const ERROR_CODES = [
1069
1084
  * finished. Retry later; nothing in the request needs to change.
1070
1085
  */
1071
1086
  'history_migrating',
1087
+ // 2026-10-19 — Lexware billing documents (fleetless/fleetless#544).
1088
+ /**
1089
+ * `503` from `GET /api/billing/documents`, `GET /api/billing/documents/:id`
1090
+ * and `GET /api/billing/documents/:id/file`: Cloud could not produce a
1091
+ * complete, checked answer from Lexware, so it answers this instead of a
1092
+ * partial list or an unchecked document. `details` is
1093
+ * `billingDocumentsUnavailableDetails`, naming the reason. Never a partial
1094
+ * list: a page nobody can tell apart from the whole list is worse than no
1095
+ * answer at all. Retrying may work for `provider_unavailable`,
1096
+ * `rate_limited` and `list_changed`.
1097
+ *
1098
+ * `502` instead, with reason `unsupported_document`, from the detail and the
1099
+ * file route when Lexware answers with an e-invoice profile or a file this
1100
+ * cloud cannot present as the document (an unknown profile, an HTML error
1101
+ * page, bytes that are not a PDF or an XML). Nothing is streamed then.
1102
+ */
1103
+ 'billing_documents_unavailable',
1072
1104
  ];
package/dist/index.d.ts CHANGED
@@ -47,8 +47,8 @@ export { auditActor, auditEvent, auditQuery, auditListResponse, AUDIT_CSV_COLUMN
47
47
  export type { AuditActor, AuditEvent, AuditQuery, AuditListResponse } from './audit.js';
48
48
  export { alertRowCondition, alertSeverity, alertState, datapointAlertRow, alertListResponse, orgFiringAlertsResponse, orgAlertsQuery, datapointDisplay, putDatapointDisplayRequest, } from './alerts.js';
49
49
  export type { AlertRowCondition, AlertSeverity, AlertState, DatapointAlertRow, AlertListResponse, OrgFiringAlertsResponse, OrgAlertsQuery, DatapointDisplay, PutDatapointDisplayRequest, } from './alerts.js';
50
- export { apiError, parameterViolation, parameterInvalidDetails, cancelRejectedDetails, invalidCodeDetails, ERROR_CODES, planLimitDetails, assetPlanLimitDetails, planRequiredDetails, orgLockedDetails, fileTooLargeDetails, paymentProviderUnavailableDetails, } from './errors.js';
51
- export type { ApiError, ParameterViolation, ParameterInvalidDetails, CancelRejectedDetails, InvalidCodeDetails, ErrorCode, PlanLimitDetails, AssetPlanLimitDetails, PlanRequiredDetails, OrgLockedDetails, FileTooLargeDetails, PaymentProviderUnavailableDetails, } from './errors.js';
50
+ export { apiError, parameterViolation, parameterInvalidDetails, cancelRejectedDetails, invalidCodeDetails, ERROR_CODES, planLimitDetails, assetPlanLimitDetails, planRequiredDetails, orgLockedDetails, fileTooLargeDetails, paymentProviderUnavailableDetails, billingDocumentsUnavailableDetails, } from './errors.js';
51
+ export type { ApiError, ParameterViolation, ParameterInvalidDetails, CancelRejectedDetails, InvalidCodeDetails, ErrorCode, PlanLimitDetails, AssetPlanLimitDetails, PlanRequiredDetails, OrgLockedDetails, FileTooLargeDetails, PaymentProviderUnavailableDetails, BillingDocumentsUnavailableDetails, } from './errors.js';
52
52
  export { oauthErrorCode, oauthError, oauthRedirectResponse, oauthCodeTokenRequest, oauthRefreshTokenRequest, oauthTokenRequest, oauthTokenResponse, redirectUri, codeChallengeMethod, oauthAuthorizeQuery, dynamicClientRegistrationRequest, MCP_DCR_MAX_REDIRECT_URIS, dynamicClientRegistrationResponse, authorizationServerMetadata, protectedResourceMetadata, } from './oauth.js';
53
53
  export type { OauthErrorCode, OauthError, OauthRedirectResponse, OauthCodeTokenRequest, OauthRefreshTokenRequest, OauthTokenRequest, OauthTokenResponse, RedirectUri, OauthAuthorizeQuery, DynamicClientRegistrationRequest, DynamicClientRegistrationResponse, AuthorizationServerMetadata, ProtectedResourceMetadata, } from './oauth.js';
54
54
  export { ROUTES, ROUTE_SECTIONS, IN_HANDLER_ROUTES, developerSignInRoutes } from './routes.js';
@@ -57,7 +57,7 @@ export { planId, PLAN_ORDER, planLimitKey, planLimits, planFeature, planFeatures
57
57
  export type { PlanId, PlanLimitKey, PlanLimits, PlanFeature, PlanFeatures, PlanPrices, PlanSupport, PlanCatalogueEntry, AddonKey, AddonCatalogueEntry, } from './plans.js';
58
58
  export { planCurrency, orgAddons, orgPlanUsage, planChangeKeep, planChangeReason, pendingPlanChange, orgLock, orgPlan, planChangeRequest, planOverrides, adminPlanChangeRequest, } from './plans.js';
59
59
  export type { PlanCurrency, OrgAddons, OrgPlanUsage, PlanChangeKeep, PlanChangeReason, PendingPlanChange, OrgLock, OrgPlan, PlanChangeRequest, PlanOverrides, AdminPlanChangeRequest, } from './plans.js';
60
- export { countryCode, EU_COUNTRIES, SELLER_COUNTRY, DE_VAT_RATE_PERCENT, isEuCountry, currencyForCountry, payerKind, billingCycle, vatTreatment, payerRefusalRule, vatFor, viesCountry, normalizeVatId, periodNetCents, prorateCents, vatCents, chargeAmounts, DAY_MS, periodDays, remainingDays, changeNetCents, checkoutQuote, BILLING_RETRY_DAYS, BILLING_LOCK_DAY, billingAddress, billingDetails, checkoutRequest, checkoutResponse, checkoutStatus, vatIdStatus, vatIdCheckRequest, vatIdCheckResponse, billingChangeRequest, billingCancelRequest, billingDetailsUpdate, paymentMethodKind, paymentMethodChangeRequest, billingAccountStatus, paymentMethod, invoiceStatus, billingInvoice, billingAccount, billingView, billingChangeResponse, } from './billing.js';
61
- export type { PayerKind, BillingCycle, VatTreatment, PayerRefusalRule, VatDecision, ChargeAmounts, BillingState, QuoteLine, CheckoutQuote, BillingAddress, BillingDetails, CheckoutRequest, CheckoutResponse, CheckoutStatus, VatIdStatus, VatIdCheckRequest, VatIdCheckResponse, BillingChangeRequest, BillingCancelRequest, BillingDetailsUpdate, PaymentMethodKind, PaymentMethodChangeRequest, BillingAccountStatus, PaymentMethod, InvoiceStatus, BillingInvoice, BillingAccount, BillingView, BillingChangeResponse, } from './billing.js';
60
+ export { countryCode, EU_COUNTRIES, SELLER_COUNTRY, DE_VAT_RATE_PERCENT, isEuCountry, currencyForCountry, payerKind, billingCycle, vatTreatment, payerRefusalRule, vatFor, viesCountry, normalizeVatId, periodNetCents, prorateCents, vatCents, chargeAmounts, DAY_MS, periodDays, remainingDays, changeNetCents, checkoutQuote, BILLING_RETRY_DAYS, BILLING_LOCK_DAY, billingAddress, billingDetails, checkoutRequest, checkoutResponse, checkoutStatus, vatIdStatus, vatIdCheckRequest, vatIdCheckResponse, billingChangeRequest, billingCancelRequest, billingDetailsUpdate, paymentMethodKind, paymentMethodChangeRequest, billingAccountStatus, paymentMethod, invoiceStatus, billingInvoice, billingAccount, billingView, billingChangeResponse, billingDocumentKind, billingDocumentStatus, billingDocumentProfile, billingDocumentFormat, billingDocument, billingDocumentList, billingDocumentFileRole, billingDocumentDetail, billingDocumentFileQuery, } from './billing.js';
61
+ export type { PayerKind, BillingCycle, VatTreatment, PayerRefusalRule, VatDecision, ChargeAmounts, BillingState, QuoteLine, CheckoutQuote, BillingAddress, BillingDetails, CheckoutRequest, CheckoutResponse, CheckoutStatus, VatIdStatus, VatIdCheckRequest, VatIdCheckResponse, BillingChangeRequest, BillingCancelRequest, BillingDetailsUpdate, PaymentMethodKind, PaymentMethodChangeRequest, BillingAccountStatus, PaymentMethod, InvoiceStatus, BillingInvoice, BillingAccount, BillingView, BillingChangeResponse, BillingDocumentKind, BillingDocumentStatus, BillingDocumentProfile, BillingDocumentFormat, BillingDocument, BillingDocumentList, BillingDocumentFileRole, BillingDocumentDetail, BillingDocumentFileQuery, } from './billing.js';
62
62
  export { purchaseBillingDetails, purchaseOperationKey, purchaseOperation, purchaseQuote, purchaseHoldReason, purchaseRefusalRule, purchaseIntent, purchaseIntentLookupQuery, purchaseIntentConfirmRequest, purchaseConflictDetails, invoicePayRequest, purchaseIntentResponse, vatDecision, viesPendingReason, } from './billing.js';
63
63
  export type { PurchaseBillingDetails, PurchaseOperation, PurchaseQuote, PurchaseIntent, PurchaseIntentLookupQuery, PurchaseIntentConfirmRequest, PurchaseConflictDetails, InvoicePayRequest, PurchaseIntentResponse, ViesVerdict, ViesPendingReason, } from './billing.js';
package/dist/index.js CHANGED
@@ -58,7 +58,9 @@ planLimitDetails, assetPlanLimitDetails, planRequiredDetails, orgLockedDetails,
58
58
  // 2026-10-03 — the per-file asset limit (#136).
59
59
  fileTooLargeDetails,
60
60
  // 2026-10-04 — billing through Mollie (#104).
61
- paymentProviderUnavailableDetails, } from './errors.js';
61
+ paymentProviderUnavailableDetails,
62
+ // 2026-10-19 — Lexware billing documents (fleetless/fleetless#544).
63
+ billingDocumentsUnavailableDetails, } from './errors.js';
62
64
  export { oauthErrorCode, oauthError, oauthRedirectResponse, oauthCodeTokenRequest, oauthRefreshTokenRequest, oauthTokenRequest, oauthTokenResponse, redirectUri, codeChallengeMethod, oauthAuthorizeQuery, dynamicClientRegistrationRequest, MCP_DCR_MAX_REDIRECT_URIS, dynamicClientRegistrationResponse, authorizationServerMetadata, protectedResourceMetadata, } from './oauth.js';
63
65
  export { ROUTES, ROUTE_SECTIONS, IN_HANDLER_ROUTES, developerSignInRoutes } from './routes.js';
64
66
  // 2026-10-02 — plans (#103). The catalogue (I-1) only: `PLANS` and `ADDONS`
@@ -70,5 +72,7 @@ export { planId, PLAN_ORDER, planLimitKey, planLimits, planFeature, planFeatures
70
72
  // admin request (I-2).
71
73
  export { planCurrency, orgAddons, orgPlanUsage, planChangeKeep, planChangeReason, pendingPlanChange, orgLock, orgPlan, planChangeRequest, planOverrides, adminPlanChangeRequest, } from './plans.js';
72
74
  // 2026-10-04 — billing through Mollie (#104).
73
- export { countryCode, EU_COUNTRIES, SELLER_COUNTRY, DE_VAT_RATE_PERCENT, isEuCountry, currencyForCountry, payerKind, billingCycle, vatTreatment, payerRefusalRule, vatFor, viesCountry, normalizeVatId, periodNetCents, prorateCents, vatCents, chargeAmounts, DAY_MS, periodDays, remainingDays, changeNetCents, checkoutQuote, BILLING_RETRY_DAYS, BILLING_LOCK_DAY, billingAddress, billingDetails, checkoutRequest, checkoutResponse, checkoutStatus, vatIdStatus, vatIdCheckRequest, vatIdCheckResponse, billingChangeRequest, billingCancelRequest, billingDetailsUpdate, paymentMethodKind, paymentMethodChangeRequest, billingAccountStatus, paymentMethod, invoiceStatus, billingInvoice, billingAccount, billingView, billingChangeResponse, } from './billing.js';
75
+ export { countryCode, EU_COUNTRIES, SELLER_COUNTRY, DE_VAT_RATE_PERCENT, isEuCountry, currencyForCountry, payerKind, billingCycle, vatTreatment, payerRefusalRule, vatFor, viesCountry, normalizeVatId, periodNetCents, prorateCents, vatCents, chargeAmounts, DAY_MS, periodDays, remainingDays, changeNetCents, checkoutQuote, BILLING_RETRY_DAYS, BILLING_LOCK_DAY, billingAddress, billingDetails, checkoutRequest, checkoutResponse, checkoutStatus, vatIdStatus, vatIdCheckRequest, vatIdCheckResponse, billingChangeRequest, billingCancelRequest, billingDetailsUpdate, paymentMethodKind, paymentMethodChangeRequest, billingAccountStatus, paymentMethod, invoiceStatus, billingInvoice, billingAccount, billingView, billingChangeResponse,
76
+ // 2026-10-19 — Lexware billing documents (fleetless/fleetless#544).
77
+ billingDocumentKind, billingDocumentStatus, billingDocumentProfile, billingDocumentFormat, billingDocument, billingDocumentList, billingDocumentFileRole, billingDocumentDetail, billingDocumentFileQuery, } from './billing.js';
74
78
  export { purchaseBillingDetails, purchaseOperationKey, purchaseOperation, purchaseQuote, purchaseHoldReason, purchaseRefusalRule, purchaseIntent, purchaseIntentLookupQuery, purchaseIntentConfirmRequest, purchaseConflictDetails, invoicePayRequest, purchaseIntentResponse, vatDecision, viesPendingReason, } from './billing.js';