@company-six/qbosync 0.3.1 → 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 +50 -3
- 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 -260
|
@@ -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,
|