@company-six/qbosync 0.3.0 → 0.5.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.
- package/README.md +140 -5
- package/dist/client.d.ts +18 -0
- package/dist/client.js +36 -1
- package/dist/contract/answers.d.ts +5 -2
- package/dist/contract/bill.d.ts +271 -0
- package/dist/contract/bill.js +130 -0
- package/dist/contract/codes.d.ts +56 -0
- package/dist/contract/codes.js +65 -0
- package/dist/contract/index.d.ts +182 -2
- package/dist/contract/index.js +5 -2
- package/dist/contract/protocol.d.ts +2 -2
- package/dist/contract/protocol.js +2 -2
- package/dist/contract/statusReport.d.ts +2 -0
- package/package.json +2 -2
- package/sql/002_daily_report.sql +260 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { termsCode } from "./invoice.js";
|
|
3
|
+
import { address, cents, currency, customer, docNumber, envelope, isoDate, orderRef, references, sum, text } from "./common.js";
|
|
4
|
+
/**
|
|
5
|
+
* What a company owes its vendors: bills, and the vendor credits that reduce them. QBO Sync posts them as
|
|
6
|
+
* QuickBooks Bills and Vendor Credits. Paying a bill is a money movement, and apps send none.
|
|
7
|
+
*
|
|
8
|
+
* Built on QuickBooks' own bill, not on any one app's: a line is an ACCOUNT line (a cost on the account its
|
|
9
|
+
* `cost_code` maps to) or an ITEM line (a product bought, by `item_code`, with quantity and unit cost).
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* A cost code: the app's own word for what a line paid for (`freight`, `decoration`). Each company maps each
|
|
13
|
+
* app's codes once, in QBO Sync's Setup, to one of its QuickBooks accounts; a document with a code that is not
|
|
14
|
+
* mapped WAITS in QBO Sync until it is.
|
|
15
|
+
*/
|
|
16
|
+
export const costCode = z
|
|
17
|
+
.string()
|
|
18
|
+
.regex(/^[a-z][a-z0-9_]{0,39}$/, "must be lower-case letters, digits and _, starting with a letter, at most 40 characters (for example freight)");
|
|
19
|
+
/** One QuickBooks vendor per `ref` per company. Its name in QuickBooks is `company`, else `name`. */
|
|
20
|
+
export const vendor = z.strictObject({
|
|
21
|
+
ref: text,
|
|
22
|
+
name: text,
|
|
23
|
+
company: z.string().optional(),
|
|
24
|
+
email: z.string().optional(),
|
|
25
|
+
address: address.optional(),
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* One line of a bill or vendor credit: EITHER an account line (`cost_code`) OR an item line (`item_code`,
|
|
29
|
+
* `quantity`, `unit_cost_cents`). An item line's amount is quantity × unit cost rounded to whole cents; the unit
|
|
30
|
+
* cost may carry fractions of a cent (bought at $0.125 each). `customer` and `class_key` on a line take the place
|
|
31
|
+
* of the document's own for that line.
|
|
32
|
+
*/
|
|
33
|
+
export const billLine = z.strictObject({
|
|
34
|
+
description: text,
|
|
35
|
+
amount_cents: cents,
|
|
36
|
+
cost_code: costCode.optional(),
|
|
37
|
+
item_code: z.string().optional(),
|
|
38
|
+
quantity: z.number().positive("must be more than zero").optional(),
|
|
39
|
+
unit_cost_cents: z.number().min(0, "must not be negative").optional(),
|
|
40
|
+
customer: customer.optional(),
|
|
41
|
+
class_key: z.string().optional(),
|
|
42
|
+
});
|
|
43
|
+
/** The fields a bill and a vendor credit share. */
|
|
44
|
+
const vendorDocument = {
|
|
45
|
+
...envelope,
|
|
46
|
+
number: docNumber.optional(),
|
|
47
|
+
issue_date: isoDate,
|
|
48
|
+
currency,
|
|
49
|
+
vendor,
|
|
50
|
+
customer: customer.optional(),
|
|
51
|
+
order_ref: orderRef.optional(),
|
|
52
|
+
references: references.optional(),
|
|
53
|
+
class_key: z.string().optional(),
|
|
54
|
+
lines: z.array(billLine).min(1, "needs at least one line"),
|
|
55
|
+
total_cents: cents,
|
|
56
|
+
};
|
|
57
|
+
/** Quantity × unit cost, rounded to whole cents, as the line's amount must be. */
|
|
58
|
+
export function itemLineAmount(line) {
|
|
59
|
+
// The small nudge keeps 0.125 × 3 (0.37499999999999994) from rounding the wrong way.
|
|
60
|
+
return Math.round(line.quantity * line.unit_cost_cents + 1e-9);
|
|
61
|
+
}
|
|
62
|
+
/** The checks a bill and a vendor credit share: each line's kind and amount, and the total. */
|
|
63
|
+
function checkLines(doc, ctx) {
|
|
64
|
+
doc.lines.forEach((line, i) => {
|
|
65
|
+
const at = (field) => ["lines", i, field];
|
|
66
|
+
const hasCost = line.cost_code !== undefined;
|
|
67
|
+
const hasItem = line.item_code !== undefined && line.item_code.trim() !== "";
|
|
68
|
+
if (hasCost === hasItem) {
|
|
69
|
+
ctx.addIssue({ code: "custom", path: at("cost_code"), message: "a line needs either cost_code (an account line) or item_code (an item line), not both" });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (hasCost) {
|
|
73
|
+
for (const field of ["quantity", "unit_cost_cents"]) {
|
|
74
|
+
if (line[field] !== undefined)
|
|
75
|
+
ctx.addIssue({ code: "custom", path: at(field), message: "is only for an item line (item_code)" });
|
|
76
|
+
}
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (line.quantity === undefined)
|
|
80
|
+
ctx.addIssue({ code: "custom", path: at("quantity"), message: "is required on an item line" });
|
|
81
|
+
if (line.unit_cost_cents === undefined)
|
|
82
|
+
ctx.addIssue({ code: "custom", path: at("unit_cost_cents"), message: "is required on an item line" });
|
|
83
|
+
if (line.quantity !== undefined && line.unit_cost_cents !== undefined) {
|
|
84
|
+
const expected = itemLineAmount({ quantity: line.quantity, unit_cost_cents: line.unit_cost_cents });
|
|
85
|
+
if (expected !== line.amount_cents) {
|
|
86
|
+
ctx.addIssue({
|
|
87
|
+
code: "custom",
|
|
88
|
+
path: at("amount_cents"),
|
|
89
|
+
message: `must equal quantity × unit_cost_cents rounded to whole cents (${line.quantity} × ${line.unit_cost_cents} = ${expected})`,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
const expected = sum(doc.lines.map((l) => l.amount_cents));
|
|
95
|
+
if (doc.total_cents !== expected) {
|
|
96
|
+
ctx.addIssue({ code: "custom", path: ["total_cents"], message: `must equal the sum of the lines (${expected})` });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* What the company owes a vendor: posted as a Bill on Accounts Payable. `number` is the vendor's own bill
|
|
101
|
+
* number. `due_date` or `terms_code` (the same `net_<days>` as invoices) say when it is due; with terms,
|
|
102
|
+
* QuickBooks works the date out. `customer` (or a line's own) says whose sale the cost belongs to.
|
|
103
|
+
*
|
|
104
|
+
* A total of $0 is allowed: QuickBooks takes a $0 bill.
|
|
105
|
+
*
|
|
106
|
+
* Refused on its own: a line with both or neither of `cost_code` and `item_code`; an item line without its
|
|
107
|
+
* quantity or unit cost, or whose amount is not quantity × unit cost; a total that is not the sum of the lines.
|
|
108
|
+
* Whether the number is already used is checked when the document arrives.
|
|
109
|
+
*/
|
|
110
|
+
export const billSchema = z
|
|
111
|
+
.strictObject({
|
|
112
|
+
...vendorDocument,
|
|
113
|
+
type: z.literal("bill"),
|
|
114
|
+
due_date: isoDate.optional(),
|
|
115
|
+
terms_code: termsCode.optional(),
|
|
116
|
+
})
|
|
117
|
+
.superRefine(checkLines);
|
|
118
|
+
/**
|
|
119
|
+
* What a vendor gave back: posted as a Vendor Credit, which lowers what the company owes that vendor.
|
|
120
|
+
* `applies_to_bill_ref` names the bill it is against, when it is against one; the bill must be one this app sent,
|
|
121
|
+
* from the same vendor `ref`, and the credit posts after it. QuickBooks offers the credit when the company next
|
|
122
|
+
* pays that vendor; QBO Sync does not apply it.
|
|
123
|
+
*/
|
|
124
|
+
export const vendorCreditSchema = z
|
|
125
|
+
.strictObject({
|
|
126
|
+
...vendorDocument,
|
|
127
|
+
type: z.literal("vendor_credit"),
|
|
128
|
+
applies_to_bill_ref: text.optional(),
|
|
129
|
+
})
|
|
130
|
+
.superRefine(checkLines);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The codes an app uses, listed ahead of any document (0.5.0). Each company maps an app's codes in QBO Sync's
|
|
4
|
+
* Setup: item codes to QuickBooks products (Setup -> Products), cost codes to QuickBooks accounts (Setup -> Cost
|
|
5
|
+
* codes). Those steps learn a code when a document first carries it; a code listed here shows from day one, named
|
|
6
|
+
* by its label, so a company can finish its setup before the first document arrives.
|
|
7
|
+
*
|
|
8
|
+
* Listing changes nothing about posting, and is optional: an app with real catalogue SKUs lists nothing, and an app
|
|
9
|
+
* may still send a code it never listed. Each kind sent is the app's whole list of that kind: a code left out is
|
|
10
|
+
* removed, a kind not sent is left as it is.
|
|
11
|
+
*/
|
|
12
|
+
/** Longest item code QBO Sync keeps (Setup -> Products). */
|
|
13
|
+
export declare const MAX_ITEM_CODE_LENGTH = 200;
|
|
14
|
+
/** Most codes of one kind an app may list. */
|
|
15
|
+
export declare const MAX_DECLARED_CODES = 200;
|
|
16
|
+
/** An item code as invoice, credit memo and bill item lines send it: kept exactly, with nothing around it. */
|
|
17
|
+
export declare const declaredItemCode: z.ZodString;
|
|
18
|
+
export declare const declaredItemCodeSchema: z.ZodObject<{
|
|
19
|
+
/** Exactly as the app puts it on a line's `item_code`. */
|
|
20
|
+
code: z.ZodString;
|
|
21
|
+
/** What the code stands for, in the words the company's bookkeeper reads: "Shipping and freight". */
|
|
22
|
+
label: z.ZodString;
|
|
23
|
+
/** A longer note, when the label is not enough: "Every line added with + Shipping". */
|
|
24
|
+
description: z.ZodOptional<z.ZodString>;
|
|
25
|
+
}, z.core.$strict>;
|
|
26
|
+
export declare const declaredCostCodeSchema: z.ZodObject<{
|
|
27
|
+
/** Exactly as the app puts it on a bill line's `cost_code`. */
|
|
28
|
+
code: z.ZodString;
|
|
29
|
+
label: z.ZodString;
|
|
30
|
+
description: z.ZodOptional<z.ZodString>;
|
|
31
|
+
}, z.core.$strict>;
|
|
32
|
+
export type DeclaredItemCode = z.infer<typeof declaredItemCodeSchema>;
|
|
33
|
+
export type DeclaredCostCode = z.infer<typeof declaredCostCodeSchema>;
|
|
34
|
+
/** What `PUT /api/v1/codes` takes. At least one kind; each kind sent replaces the app's list of that kind. */
|
|
35
|
+
export declare const codesDeclarationSchema: z.ZodObject<{
|
|
36
|
+
item_codes: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
37
|
+
/** Exactly as the app puts it on a line's `item_code`. */
|
|
38
|
+
code: z.ZodString;
|
|
39
|
+
/** What the code stands for, in the words the company's bookkeeper reads: "Shipping and freight". */
|
|
40
|
+
label: z.ZodString;
|
|
41
|
+
/** A longer note, when the label is not enough: "Every line added with + Shipping". */
|
|
42
|
+
description: z.ZodOptional<z.ZodString>;
|
|
43
|
+
}, z.core.$strict>>>;
|
|
44
|
+
cost_codes: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
45
|
+
/** Exactly as the app puts it on a bill line's `cost_code`. */
|
|
46
|
+
code: z.ZodString;
|
|
47
|
+
label: z.ZodString;
|
|
48
|
+
description: z.ZodOptional<z.ZodString>;
|
|
49
|
+
}, z.core.$strict>>>;
|
|
50
|
+
}, z.core.$strict>;
|
|
51
|
+
export type CodesDeclaration = z.infer<typeof codesDeclarationSchema>;
|
|
52
|
+
/** What QBO Sync holds for the app: `GET /api/v1/codes`, and the answer to a `PUT`. */
|
|
53
|
+
export interface DeclaredCodes {
|
|
54
|
+
item_codes: DeclaredItemCode[];
|
|
55
|
+
cost_codes: DeclaredCostCode[];
|
|
56
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { costCode } from "./bill.js";
|
|
3
|
+
/**
|
|
4
|
+
* The codes an app uses, listed ahead of any document (0.5.0). Each company maps an app's codes in QBO Sync's
|
|
5
|
+
* Setup: item codes to QuickBooks products (Setup -> Products), cost codes to QuickBooks accounts (Setup -> Cost
|
|
6
|
+
* codes). Those steps learn a code when a document first carries it; a code listed here shows from day one, named
|
|
7
|
+
* by its label, so a company can finish its setup before the first document arrives.
|
|
8
|
+
*
|
|
9
|
+
* Listing changes nothing about posting, and is optional: an app with real catalogue SKUs lists nothing, and an app
|
|
10
|
+
* may still send a code it never listed. Each kind sent is the app's whole list of that kind: a code left out is
|
|
11
|
+
* removed, a kind not sent is left as it is.
|
|
12
|
+
*/
|
|
13
|
+
/** Longest item code QBO Sync keeps (Setup -> Products). */
|
|
14
|
+
export const MAX_ITEM_CODE_LENGTH = 200;
|
|
15
|
+
/** Most codes of one kind an app may list. */
|
|
16
|
+
export const MAX_DECLARED_CODES = 200;
|
|
17
|
+
const label = z
|
|
18
|
+
.string()
|
|
19
|
+
.trim()
|
|
20
|
+
.min(1, "must not be empty")
|
|
21
|
+
.max(80, "must be at most 80 characters");
|
|
22
|
+
const description = z.string().trim().min(1, "must not be empty when given").max(200, "must be at most 200 characters");
|
|
23
|
+
/** An item code as invoice, credit memo and bill item lines send it: kept exactly, with nothing around it. */
|
|
24
|
+
export const declaredItemCode = z
|
|
25
|
+
.string()
|
|
26
|
+
.min(1, "must not be empty")
|
|
27
|
+
.max(MAX_ITEM_CODE_LENGTH, `must be at most ${MAX_ITEM_CODE_LENGTH} characters`)
|
|
28
|
+
.refine((c) => c === c.trim(), "must have no spaces around it");
|
|
29
|
+
export const declaredItemCodeSchema = z.strictObject({
|
|
30
|
+
/** Exactly as the app puts it on a line's `item_code`. */
|
|
31
|
+
code: declaredItemCode,
|
|
32
|
+
/** What the code stands for, in the words the company's bookkeeper reads: "Shipping and freight". */
|
|
33
|
+
label,
|
|
34
|
+
/** A longer note, when the label is not enough: "Every line added with + Shipping". */
|
|
35
|
+
description: description.optional(),
|
|
36
|
+
});
|
|
37
|
+
export const declaredCostCodeSchema = z.strictObject({
|
|
38
|
+
/** Exactly as the app puts it on a bill line's `cost_code`. */
|
|
39
|
+
code: costCode,
|
|
40
|
+
label,
|
|
41
|
+
description: description.optional(),
|
|
42
|
+
});
|
|
43
|
+
function noRepeats(list, ctx, field) {
|
|
44
|
+
const seen = new Set();
|
|
45
|
+
list.forEach((entry, i) => {
|
|
46
|
+
if (seen.has(entry.code))
|
|
47
|
+
ctx.addIssue({ code: "custom", path: [field, i, "code"], message: `"${entry.code}" is listed twice` });
|
|
48
|
+
seen.add(entry.code);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/** What `PUT /api/v1/codes` takes. At least one kind; each kind sent replaces the app's list of that kind. */
|
|
52
|
+
export const codesDeclarationSchema = z
|
|
53
|
+
.strictObject({
|
|
54
|
+
item_codes: z.array(declaredItemCodeSchema).max(MAX_DECLARED_CODES, `at most ${MAX_DECLARED_CODES} codes`).optional(),
|
|
55
|
+
cost_codes: z.array(declaredCostCodeSchema).max(MAX_DECLARED_CODES, `at most ${MAX_DECLARED_CODES} codes`).optional(),
|
|
56
|
+
})
|
|
57
|
+
.superRefine((d, ctx) => {
|
|
58
|
+
if (d.item_codes === undefined && d.cost_codes === undefined) {
|
|
59
|
+
ctx.addIssue({ code: "custom", path: [], message: "send item_codes, cost_codes or both" });
|
|
60
|
+
}
|
|
61
|
+
if (d.item_codes)
|
|
62
|
+
noRepeats(d.item_codes, ctx, "item_codes");
|
|
63
|
+
if (d.cost_codes)
|
|
64
|
+
noRepeats(d.cost_codes, ctx, "cost_codes");
|
|
65
|
+
});
|
package/dist/contract/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { type BillDTO, type VendorCreditDTO } from "./bill.ts";
|
|
2
3
|
import { type CreditMemoDTO } from "./creditMemo.ts";
|
|
3
4
|
import { type InvoiceDTO } from "./invoice.ts";
|
|
4
5
|
/**
|
|
@@ -9,10 +10,12 @@ import { type InvoiceDTO } from "./invoice.ts";
|
|
|
9
10
|
export * from "./common.ts";
|
|
10
11
|
export * from "./invoice.ts";
|
|
11
12
|
export * from "./creditMemo.ts";
|
|
13
|
+
export * from "./bill.ts";
|
|
14
|
+
export * from "./codes.ts";
|
|
12
15
|
export * from "./statusReport.ts";
|
|
13
16
|
export * from "./protocol.ts";
|
|
14
17
|
export * from "./answers.ts";
|
|
15
|
-
/** An invoice or a credit
|
|
18
|
+
/** An invoice, a credit memo, a bill or a vendor credit: what an app may send. */
|
|
16
19
|
export declare const appDocumentSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
17
20
|
type: z.ZodLiteral<"invoice">;
|
|
18
21
|
number: z.ZodPipe<z.ZodString, z.ZodString>;
|
|
@@ -126,8 +129,185 @@ export declare const appDocumentSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
126
129
|
active: "active";
|
|
127
130
|
voided: "voided";
|
|
128
131
|
}>;
|
|
132
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
133
|
+
type: z.ZodLiteral<"bill">;
|
|
134
|
+
due_date: z.ZodOptional<z.ZodString>;
|
|
135
|
+
terms_code: z.ZodOptional<z.ZodString>;
|
|
136
|
+
number: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodString>>;
|
|
137
|
+
issue_date: z.ZodString;
|
|
138
|
+
currency: z.ZodString;
|
|
139
|
+
vendor: z.ZodObject<{
|
|
140
|
+
ref: z.ZodString;
|
|
141
|
+
name: z.ZodString;
|
|
142
|
+
company: z.ZodOptional<z.ZodString>;
|
|
143
|
+
email: z.ZodOptional<z.ZodString>;
|
|
144
|
+
address: z.ZodOptional<z.ZodObject<{
|
|
145
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
146
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
147
|
+
city: z.ZodOptional<z.ZodString>;
|
|
148
|
+
region: z.ZodOptional<z.ZodString>;
|
|
149
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
150
|
+
country: z.ZodOptional<z.ZodString>;
|
|
151
|
+
}, z.core.$strict>>;
|
|
152
|
+
}, z.core.$strict>;
|
|
153
|
+
customer: z.ZodOptional<z.ZodObject<{
|
|
154
|
+
ref: z.ZodString;
|
|
155
|
+
name: z.ZodString;
|
|
156
|
+
company: z.ZodOptional<z.ZodString>;
|
|
157
|
+
email: z.ZodOptional<z.ZodString>;
|
|
158
|
+
bill_to: z.ZodOptional<z.ZodObject<{
|
|
159
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
160
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
161
|
+
city: z.ZodOptional<z.ZodString>;
|
|
162
|
+
region: z.ZodOptional<z.ZodString>;
|
|
163
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
164
|
+
country: z.ZodOptional<z.ZodString>;
|
|
165
|
+
}, z.core.$strict>>;
|
|
166
|
+
ship_to: z.ZodOptional<z.ZodObject<{
|
|
167
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
168
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
169
|
+
city: z.ZodOptional<z.ZodString>;
|
|
170
|
+
region: z.ZodOptional<z.ZodString>;
|
|
171
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
172
|
+
country: z.ZodOptional<z.ZodString>;
|
|
173
|
+
}, z.core.$strict>>;
|
|
174
|
+
}, z.core.$strict>>;
|
|
175
|
+
order_ref: z.ZodOptional<z.ZodString>;
|
|
176
|
+
references: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
177
|
+
label: z.ZodString;
|
|
178
|
+
value: z.ZodString;
|
|
179
|
+
}, z.core.$strict>>>;
|
|
180
|
+
class_key: z.ZodOptional<z.ZodString>;
|
|
181
|
+
lines: z.ZodArray<z.ZodObject<{
|
|
182
|
+
description: z.ZodString;
|
|
183
|
+
amount_cents: z.ZodInt;
|
|
184
|
+
cost_code: z.ZodOptional<z.ZodString>;
|
|
185
|
+
item_code: z.ZodOptional<z.ZodString>;
|
|
186
|
+
quantity: z.ZodOptional<z.ZodNumber>;
|
|
187
|
+
unit_cost_cents: z.ZodOptional<z.ZodNumber>;
|
|
188
|
+
customer: z.ZodOptional<z.ZodObject<{
|
|
189
|
+
ref: z.ZodString;
|
|
190
|
+
name: z.ZodString;
|
|
191
|
+
company: z.ZodOptional<z.ZodString>;
|
|
192
|
+
email: z.ZodOptional<z.ZodString>;
|
|
193
|
+
bill_to: z.ZodOptional<z.ZodObject<{
|
|
194
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
195
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
196
|
+
city: z.ZodOptional<z.ZodString>;
|
|
197
|
+
region: z.ZodOptional<z.ZodString>;
|
|
198
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
199
|
+
country: z.ZodOptional<z.ZodString>;
|
|
200
|
+
}, z.core.$strict>>;
|
|
201
|
+
ship_to: z.ZodOptional<z.ZodObject<{
|
|
202
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
203
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
204
|
+
city: z.ZodOptional<z.ZodString>;
|
|
205
|
+
region: z.ZodOptional<z.ZodString>;
|
|
206
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
207
|
+
country: z.ZodOptional<z.ZodString>;
|
|
208
|
+
}, z.core.$strict>>;
|
|
209
|
+
}, z.core.$strict>>;
|
|
210
|
+
class_key: z.ZodOptional<z.ZodString>;
|
|
211
|
+
}, z.core.$strict>>;
|
|
212
|
+
total_cents: z.ZodInt;
|
|
213
|
+
schema_version: z.ZodLiteral<"1">;
|
|
214
|
+
source_ref: z.ZodString;
|
|
215
|
+
company_key: z.ZodString;
|
|
216
|
+
version: z.ZodInt;
|
|
217
|
+
status: z.ZodEnum<{
|
|
218
|
+
active: "active";
|
|
219
|
+
voided: "voided";
|
|
220
|
+
}>;
|
|
221
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
222
|
+
type: z.ZodLiteral<"vendor_credit">;
|
|
223
|
+
applies_to_bill_ref: z.ZodOptional<z.ZodString>;
|
|
224
|
+
number: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodString>>;
|
|
225
|
+
issue_date: z.ZodString;
|
|
226
|
+
currency: z.ZodString;
|
|
227
|
+
vendor: z.ZodObject<{
|
|
228
|
+
ref: z.ZodString;
|
|
229
|
+
name: z.ZodString;
|
|
230
|
+
company: z.ZodOptional<z.ZodString>;
|
|
231
|
+
email: z.ZodOptional<z.ZodString>;
|
|
232
|
+
address: z.ZodOptional<z.ZodObject<{
|
|
233
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
234
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
235
|
+
city: z.ZodOptional<z.ZodString>;
|
|
236
|
+
region: z.ZodOptional<z.ZodString>;
|
|
237
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
238
|
+
country: z.ZodOptional<z.ZodString>;
|
|
239
|
+
}, z.core.$strict>>;
|
|
240
|
+
}, z.core.$strict>;
|
|
241
|
+
customer: z.ZodOptional<z.ZodObject<{
|
|
242
|
+
ref: z.ZodString;
|
|
243
|
+
name: z.ZodString;
|
|
244
|
+
company: z.ZodOptional<z.ZodString>;
|
|
245
|
+
email: z.ZodOptional<z.ZodString>;
|
|
246
|
+
bill_to: z.ZodOptional<z.ZodObject<{
|
|
247
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
248
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
249
|
+
city: z.ZodOptional<z.ZodString>;
|
|
250
|
+
region: z.ZodOptional<z.ZodString>;
|
|
251
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
252
|
+
country: z.ZodOptional<z.ZodString>;
|
|
253
|
+
}, z.core.$strict>>;
|
|
254
|
+
ship_to: z.ZodOptional<z.ZodObject<{
|
|
255
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
256
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
257
|
+
city: z.ZodOptional<z.ZodString>;
|
|
258
|
+
region: z.ZodOptional<z.ZodString>;
|
|
259
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
260
|
+
country: z.ZodOptional<z.ZodString>;
|
|
261
|
+
}, z.core.$strict>>;
|
|
262
|
+
}, z.core.$strict>>;
|
|
263
|
+
order_ref: z.ZodOptional<z.ZodString>;
|
|
264
|
+
references: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
265
|
+
label: z.ZodString;
|
|
266
|
+
value: z.ZodString;
|
|
267
|
+
}, z.core.$strict>>>;
|
|
268
|
+
class_key: z.ZodOptional<z.ZodString>;
|
|
269
|
+
lines: z.ZodArray<z.ZodObject<{
|
|
270
|
+
description: z.ZodString;
|
|
271
|
+
amount_cents: z.ZodInt;
|
|
272
|
+
cost_code: z.ZodOptional<z.ZodString>;
|
|
273
|
+
item_code: z.ZodOptional<z.ZodString>;
|
|
274
|
+
quantity: z.ZodOptional<z.ZodNumber>;
|
|
275
|
+
unit_cost_cents: z.ZodOptional<z.ZodNumber>;
|
|
276
|
+
customer: z.ZodOptional<z.ZodObject<{
|
|
277
|
+
ref: z.ZodString;
|
|
278
|
+
name: z.ZodString;
|
|
279
|
+
company: z.ZodOptional<z.ZodString>;
|
|
280
|
+
email: z.ZodOptional<z.ZodString>;
|
|
281
|
+
bill_to: z.ZodOptional<z.ZodObject<{
|
|
282
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
283
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
284
|
+
city: z.ZodOptional<z.ZodString>;
|
|
285
|
+
region: z.ZodOptional<z.ZodString>;
|
|
286
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
287
|
+
country: z.ZodOptional<z.ZodString>;
|
|
288
|
+
}, z.core.$strict>>;
|
|
289
|
+
ship_to: z.ZodOptional<z.ZodObject<{
|
|
290
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
291
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
292
|
+
city: z.ZodOptional<z.ZodString>;
|
|
293
|
+
region: z.ZodOptional<z.ZodString>;
|
|
294
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
295
|
+
country: z.ZodOptional<z.ZodString>;
|
|
296
|
+
}, z.core.$strict>>;
|
|
297
|
+
}, z.core.$strict>>;
|
|
298
|
+
class_key: z.ZodOptional<z.ZodString>;
|
|
299
|
+
}, z.core.$strict>>;
|
|
300
|
+
total_cents: z.ZodInt;
|
|
301
|
+
schema_version: z.ZodLiteral<"1">;
|
|
302
|
+
source_ref: z.ZodString;
|
|
303
|
+
company_key: z.ZodString;
|
|
304
|
+
version: z.ZodInt;
|
|
305
|
+
status: z.ZodEnum<{
|
|
306
|
+
active: "active";
|
|
307
|
+
voided: "voided";
|
|
308
|
+
}>;
|
|
129
309
|
}, z.core.$strict>], "type">;
|
|
130
|
-
export type AppDocument = InvoiceDTO | CreditMemoDTO;
|
|
310
|
+
export type AppDocument = InvoiceDTO | CreditMemoDTO | BillDTO | VendorCreditDTO;
|
|
131
311
|
export type CheckedDocument = {
|
|
132
312
|
ok: true;
|
|
133
313
|
document: AppDocument;
|
package/dist/contract/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { billSchema, vendorCreditSchema } from "./bill.js";
|
|
2
3
|
import { creditMemoSchema } from "./creditMemo.js";
|
|
3
4
|
import { invoiceSchema } from "./invoice.js";
|
|
4
5
|
import { APP_DOCUMENT_TYPES } from "./protocol.js";
|
|
@@ -10,11 +11,13 @@ import { APP_DOCUMENT_TYPES } from "./protocol.js";
|
|
|
10
11
|
export * from "./common.js";
|
|
11
12
|
export * from "./invoice.js";
|
|
12
13
|
export * from "./creditMemo.js";
|
|
14
|
+
export * from "./bill.js";
|
|
15
|
+
export * from "./codes.js";
|
|
13
16
|
export * from "./statusReport.js";
|
|
14
17
|
export * from "./protocol.js";
|
|
15
18
|
export * from "./answers.js";
|
|
16
|
-
/** An invoice or a credit
|
|
17
|
-
export const appDocumentSchema = z.discriminatedUnion("type", [invoiceSchema, creditMemoSchema], {
|
|
19
|
+
/** An invoice, a credit memo, a bill or a vendor credit: what an app may send. */
|
|
20
|
+
export const appDocumentSchema = z.discriminatedUnion("type", [invoiceSchema, creditMemoSchema, billSchema, vendorCreditSchema], {
|
|
18
21
|
error: `type must be one of ${APP_DOCUMENT_TYPES.join(", ")}`,
|
|
19
22
|
});
|
|
20
23
|
/** One problem with a document as a readable line naming the field: `lines.0.amount_cents: must equal …`. */
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* against the code that enforces it, so these cannot drift from what QBO Sync does.
|
|
4
4
|
*/
|
|
5
5
|
/** Every document type there is. Apps send only `APP_DOCUMENT_TYPES`; status reports may name any of them. */
|
|
6
|
-
export declare const DOCUMENT_TYPES: readonly ["invoice", "credit_memo", "payment", "refund", "payout"];
|
|
6
|
+
export declare const DOCUMENT_TYPES: readonly ["invoice", "credit_memo", "bill", "vendor_credit", "payment", "refund", "payout"];
|
|
7
7
|
export type DocumentType = (typeof DOCUMENT_TYPES)[number];
|
|
8
8
|
/** What an app sends. Payments, refunds and payouts reach QBO Sync through its own connectors, never from an app. */
|
|
9
|
-
export declare const APP_DOCUMENT_TYPES: readonly ["invoice", "credit_memo"];
|
|
9
|
+
export declare const APP_DOCUMENT_TYPES: readonly ["invoice", "credit_memo", "bill", "vendor_credit"];
|
|
10
10
|
/** The most documents one request may carry. */
|
|
11
11
|
export declare const MAX_DOCUMENTS_PER_REQUEST = 100;
|
|
12
12
|
/** The most document refs one report request may name. */
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* against the code that enforces it, so these cannot drift from what QBO Sync does.
|
|
4
4
|
*/
|
|
5
5
|
/** Every document type there is. Apps send only `APP_DOCUMENT_TYPES`; status reports may name any of them. */
|
|
6
|
-
export const DOCUMENT_TYPES = ["invoice", "credit_memo", "payment", "refund", "payout"];
|
|
6
|
+
export const DOCUMENT_TYPES = ["invoice", "credit_memo", "bill", "vendor_credit", "payment", "refund", "payout"];
|
|
7
7
|
/** What an app sends. Payments, refunds and payouts reach QBO Sync through its own connectors, never from an app. */
|
|
8
|
-
export const APP_DOCUMENT_TYPES = ["invoice", "credit_memo"];
|
|
8
|
+
export const APP_DOCUMENT_TYPES = ["invoice", "credit_memo", "bill", "vendor_credit"];
|
|
9
9
|
/** The most documents one request may carry. */
|
|
10
10
|
export const MAX_DOCUMENTS_PER_REQUEST = 100;
|
|
11
11
|
/** The most document refs one report request may name. */
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@company-six/qbosync",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Connect an app to QBO Sync: send invoices
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Connect an app to QBO Sync: send invoices, credit memos, bills and vendor credits to QuickBooks, and hear back what happened to them.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": false,
|