@company-six/qbosync 0.11.0 → 0.12.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 CHANGED
@@ -140,6 +140,16 @@ Apps send invoices, credit memos, bills and vendor credits. Payments, refunds an
140
140
 
141
141
  **Other ids of the same order (0.11.0).** When an order's payment comes from somewhere that knows the order by another id, list that id in `extra_order_refs`, in `order_ref`'s `"<system>:<id>"` form. A Faire order your app received as a Shopify order is the case: `order_ref: "shopify:5551234567"`, `extra_order_refs: ["faire:bo_kt2semdnvy"]` (Faire's own order id, lower case, as its API gives it). A payment or refund QBO Sync reads matches the invoice or credit memo by any of them, as by `order_ref`. At most 10, no repeats, none the same as `order_ref`; the contract refuses anything else. Two orders' invoices may list the same id (two shop orders made from one marketplace order): that payment then pays all of them, oldest first. A QBO Sync older than 0.11.0's contract refuses the field, so update the SDK only once QBO Sync has it.
142
142
 
143
+ **The sale a document belongs to (0.12.0).** `sale_group` says which sale a document is part of: `sale_group: { ref: "myapp:project:2207" }`. Documents your app sends for one company that name the same `ref` belong together (a sale is matched within one app and one company, never across apps): the sale's invoices, and the bills and vendor credits that are its costs. That is what lets a company record a bill's cost with its sale, when it pays for an order weeks before it invoices the customer. `ref` is whatever id your app has for the whole sale (a project, a sales order), in `order_ref`'s `"<system>:<id>"` form; it is compared whole and exactly, so send the same text on every document of the sale.
144
+
145
+ - **It is optional, on every document.** One without it is accepted and handled exactly as before; send it only if your app knows which sale a document belongs to.
146
+ - **It is not `order_ref`.** `order_ref` is how a payment finds its invoice; `sale_group` is how a bill finds its sale's invoice. A document may carry both, either or neither, with the same id or different ones, and neither is used in the other's place.
147
+ - **Send it on invoices, bills and vendor credits.** A credit memo may carry it, but nothing reads it there: a credit memo keeps applying to its invoice as before.
148
+ - **It is an object** so later versions can add facts about the sale beside `ref`. Today `ref` is its only key and any other is refused. It carries no instructions: what a company does with a sale's costs is its own setting in QBO Sync.
149
+ - **What QBO Sync does with it is each company's own setting.** With no setting, the field is stored and nothing else changes. A company may choose to keep a bill's cost aside (in a Costs in progress account) until the sale's first invoice is in QuickBooks, and then move it to cost; for that, the bill and the invoice must carry the same `ref`. A QBO Sync that does not know the field yet refuses a document that carries it, so start sending it only once QBO Sync has been updated.
150
+ - **A document already sent keeps what it was first sent with.** Sending it again at the same `version` with `sale_group` added is a changed document and is refused (`version_conflict`), and a document already in QuickBooks takes no new version. So start with sales whose documents are all still to be sent, and do not name a sale on a bill when that sale's invoice was sent without it: the bill would find no invoice of its sale, and a company that keeps that cost aside keeps it aside until an invoice that names the sale reaches QuickBooks.
151
+ - **`ref` is at most 200 characters** (0.12.1); a longer one is refused.
152
+
143
153
  ### Bills and vendor credits (0.5.0)
144
154
 
145
155
  A bill is what the company owes a vendor; a vendor credit is what a vendor gave back. QBO Sync posts them as QuickBooks Bills and Vendor Credits.
@@ -166,6 +176,7 @@ const bill: BillDTO = {
166
176
 
167
177
  - A line is an **account line** (`cost_code`: your word for what was paid for) or an **item line** (`item_code`, `quantity`, `unit_cost_cents`: a product bought, by SKU). Each company maps your cost codes to its accounts once, in QBO Sync's Setup; a bill whose code is not mapped waits, and its status report says so. An item line posts on the product the company chose for its `item_code` in Setup → Products (the same choice your invoices use), else the QuickBooks product with that SKU; a bill never creates a product, so with neither it fails, or waits until the company chooses one if it has set your app to never create products.
168
178
  - `customer` (on the bill, or on one line) puts the cost on that customer for job costing; it is not billed to them again.
179
+ - `sale_group` (optional, 0.12.0) names the sale the cost belongs to, with the same `ref` as on that sale's invoice (see "The sale a document belongs to" above).
169
180
  - A vendor credit has the same fields, no terms, and may name its bill with `applies_to_bill_ref`. QuickBooks offers the credit when the company next pays that vendor.
170
181
  - `number` is unique per vendor among your bills. When QuickBooks already holds a bill from that vendor with that number, the bill waits for a person in QBO Sync to link it or post it anyway.
171
182
  - Like an invoice, a bill is kept as first received. Once it is in QuickBooks, correct it with a vendor credit; one QuickBooks refused, or a person rolled back, goes again as its next version (see "Correcting one that failed or was rolled back" above).
@@ -56,7 +56,6 @@ export declare const ATTACHMENTS_PATH = "/api/v1/attachments";
56
56
  * a name of its own.
57
57
  */
58
58
  export declare const attachmentUploadSchema: z.ZodObject<{
59
- /** The company as the app's documents name it. */
60
59
  company_key: z.ZodString;
61
60
  content_type: z.ZodString;
62
61
  size_bytes: z.ZodInt;
@@ -124,6 +124,9 @@ export declare const billSchema: z.ZodObject<{
124
124
  }, z.core.$strict>>;
125
125
  }, z.core.$strict>>;
126
126
  order_ref: z.ZodOptional<z.ZodString>;
127
+ sale_group: z.ZodOptional<z.ZodObject<{
128
+ ref: z.ZodString;
129
+ }, z.core.$strict>>;
127
130
  references: z.ZodOptional<z.ZodArray<z.ZodObject<{
128
131
  label: z.ZodString;
129
132
  value: z.ZodString;
@@ -225,6 +228,9 @@ export declare const vendorCreditSchema: z.ZodObject<{
225
228
  }, z.core.$strict>>;
226
229
  }, z.core.$strict>>;
227
230
  order_ref: z.ZodOptional<z.ZodString>;
231
+ sale_group: z.ZodOptional<z.ZodObject<{
232
+ ref: z.ZodString;
233
+ }, z.core.$strict>>;
228
234
  references: z.ZodOptional<z.ZodArray<z.ZodObject<{
229
235
  label: z.ZodString;
230
236
  value: z.ZodString;
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { termsCode } from "./invoice.js";
3
- import { address, cents, currency, customer, docNumber, envelope, isoDate, orderRef, references, sum, text } from "./common.js";
3
+ import { address, cents, currency, customer, docNumber, envelope, isoDate, orderRef, references, saleGroup, sum, text } from "./common.js";
4
4
  /**
5
5
  * What a company owes its vendors: bills, and the vendor credits that reduce them. QBO Sync posts them as
6
6
  * QuickBooks Bills and Vendor Credits. Paying a bill is a money movement, and apps send none.
@@ -49,6 +49,8 @@ const vendorDocument = {
49
49
  vendor,
50
50
  customer: customer.optional(),
51
51
  order_ref: orderRef.optional(),
52
+ /** The sale this cost belongs to (0.12.0, `saleGroup` in `common.ts`): the same `ref` as on the sale's invoice. */
53
+ sale_group: saleGroup.optional(),
52
54
  references: references.optional(),
53
55
  class_key: z.string().optional(),
54
56
  lines: z.array(billLine).min(1, "needs at least one line"),
@@ -19,15 +19,11 @@ export declare const MAX_DECLARED_CODES = 200;
19
19
  /** An item code as invoice, credit memo and bill item lines send it: kept exactly, with nothing around it. */
20
20
  export declare const declaredItemCode: z.ZodString;
21
21
  export declare const declaredItemCodeSchema: z.ZodObject<{
22
- /** Exactly as the app puts it on a line's `item_code`. */
23
22
  code: z.ZodString;
24
- /** What the code stands for, in the words the company's bookkeeper reads: "Shipping and freight". */
25
23
  label: z.ZodString;
26
- /** A longer note, when the label is not enough: "Every line added with + Shipping". */
27
24
  description: z.ZodOptional<z.ZodString>;
28
25
  }, z.core.$strict>;
29
26
  export declare const declaredCostCodeSchema: z.ZodObject<{
30
- /** Exactly as the app puts it on a bill line's `cost_code`. */
31
27
  code: z.ZodString;
32
28
  label: z.ZodString;
33
29
  description: z.ZodOptional<z.ZodString>;
@@ -36,21 +32,13 @@ export type DeclaredItemCode = z.infer<typeof declaredItemCodeSchema>;
36
32
  export type DeclaredCostCode = z.infer<typeof declaredCostCodeSchema>;
37
33
  /** What `PUT /api/v1/codes` takes. At least one kind; each kind sent replaces that company's list of that kind. */
38
34
  export declare const codesDeclarationSchema: z.ZodObject<{
39
- /**
40
- * The company the lists are for, as the app's documents name it. Needed when the app sends for several
41
- * companies; with one, it may be left out (0.6.0).
42
- */
43
35
  company_key: z.ZodOptional<z.ZodString>;
44
36
  item_codes: z.ZodOptional<z.ZodArray<z.ZodObject<{
45
- /** Exactly as the app puts it on a line's `item_code`. */
46
37
  code: z.ZodString;
47
- /** What the code stands for, in the words the company's bookkeeper reads: "Shipping and freight". */
48
38
  label: z.ZodString;
49
- /** A longer note, when the label is not enough: "Every line added with + Shipping". */
50
39
  description: z.ZodOptional<z.ZodString>;
51
40
  }, z.core.$strict>>>;
52
41
  cost_codes: z.ZodOptional<z.ZodArray<z.ZodObject<{
53
- /** Exactly as the app puts it on a bill line's `cost_code`. */
54
42
  code: z.ZodString;
55
43
  label: z.ZodString;
56
44
  description: z.ZodOptional<z.ZodString>;
@@ -27,11 +27,51 @@ export declare const text: z.ZodString;
27
27
  export declare const isoDate: z.ZodString;
28
28
  /** An ISO 4217 currency code, upper case: "USD". */
29
29
  export declare const currency: z.ZodString;
30
+ /** `sale_group.ref` is at most this many characters (0.12.1). */
31
+ export declare const MAX_SALE_GROUP_REF = 200;
30
32
  /**
31
33
  * `order_ref`: "<system>:<id>", e.g. "shopify:5551234567". Two apps' order ids can
32
34
  * collide; the system prefix is what keeps them apart, so it is required.
33
35
  */
34
36
  export declare const orderRef: z.ZodString;
37
+ /**
38
+ * `sale_group` (0.12.0): the sale this document belongs to. OPTIONAL on every document: one without it is
39
+ * accepted and handled exactly as before.
40
+ *
41
+ * Documents one app sends for one company that name the same `ref` belong to the same sale (never across apps): the sale's invoices, and the bills
42
+ * and vendor credits that are its costs. That is what lets a bill's cost be recorded with its sale, for a company
43
+ * that pays for an order weeks before it invoices the customer.
44
+ *
45
+ * `ref` is whatever id your app has for the whole sale (a project, a sales order), in `order_ref`'s form,
46
+ * "<system>:<id>": "myapp:project:2207". It is compared whole and exactly, so send the same text on every
47
+ * document of the sale.
48
+ *
49
+ * How it differs from `order_ref`: `order_ref` is how a PAYMENT finds its invoice; `sale_group` is how a BILL
50
+ * finds its sale's invoice. They are independent. A document may carry both, either or neither, they may hold the
51
+ * same id or different ones, and neither is used in the other's place: a document with no `sale_group` belongs to
52
+ * no sale group, whatever its `order_ref` says.
53
+ *
54
+ * An object, not a plain string, so that later versions can add facts about the sale beside `ref`. It carries no
55
+ * instructions: what a company does with a sale's costs is that company's own setting in QBO Sync. Any other key
56
+ * is refused today.
57
+ *
58
+ * Meant for invoices, bills and vendor credits. A credit memo may carry it, but nothing reads it there: a credit
59
+ * memo keeps applying to its invoice as before.
60
+ *
61
+ * What QBO Sync does with a sale's documents is each company's own setting. With no setting, the field is stored
62
+ * and nothing else changes. A company may choose to keep a bill's cost aside until the sale's invoice is in
63
+ * QuickBooks; for that, the bill and the invoice must carry the same `ref`.
64
+ *
65
+ * A document already sent keeps what it was first sent with: the same version sent again with `sale_group` added
66
+ * is a changed document and is refused, and a document already in QuickBooks takes no new version. So name sales
67
+ * on documents still to be sent, and never on a bill whose sale's invoice was sent without it.
68
+ *
69
+ * `ref` is at most `MAX_SALE_GROUP_REF` characters (0.12.1): QBO Sync indexes it.
70
+ */
71
+ export declare const saleGroup: z.ZodObject<{
72
+ ref: z.ZodString;
73
+ }, z.core.$strict>;
74
+ export type SaleGroup = z.infer<typeof saleGroup>;
35
75
  /** At most this many `extra_order_refs` on one document. */
36
76
  export declare const MAX_EXTRA_ORDER_REFS = 10;
37
77
  /**
@@ -31,13 +31,55 @@ export const isoDate = z.string().refine((s) => {
31
31
  }, "must be a date as YYYY-MM-DD");
32
32
  /** An ISO 4217 currency code, upper case: "USD". */
33
33
  export const currency = z.string().regex(/^[A-Z]{3}$/, "must be a three-letter currency code such as USD");
34
+ /** The form `order_ref` and `sale_group.ref` share: a lower-case system name, a colon, an id with no spaces. */
35
+ const SYSTEM_AND_ID = /^[a-z][a-z0-9_-]*:\S+$/;
36
+ /** `sale_group.ref` is at most this many characters (0.12.1). */
37
+ export const MAX_SALE_GROUP_REF = 200;
34
38
  /**
35
39
  * `order_ref`: "<system>:<id>", e.g. "shopify:5551234567". Two apps' order ids can
36
40
  * collide; the system prefix is what keeps them apart, so it is required.
37
41
  */
38
- export const orderRef = z
39
- .string()
40
- .regex(/^[a-z][a-z0-9_-]*:\S+$/, 'must be "<system>:<id>", e.g. "shopify:5551234567"');
42
+ export const orderRef = z.string().regex(SYSTEM_AND_ID, 'must be "<system>:<id>", e.g. "shopify:5551234567"');
43
+ /**
44
+ * `sale_group` (0.12.0): the sale this document belongs to. OPTIONAL on every document: one without it is
45
+ * accepted and handled exactly as before.
46
+ *
47
+ * Documents one app sends for one company that name the same `ref` belong to the same sale (never across apps): the sale's invoices, and the bills
48
+ * and vendor credits that are its costs. That is what lets a bill's cost be recorded with its sale, for a company
49
+ * that pays for an order weeks before it invoices the customer.
50
+ *
51
+ * `ref` is whatever id your app has for the whole sale (a project, a sales order), in `order_ref`'s form,
52
+ * "<system>:<id>": "myapp:project:2207". It is compared whole and exactly, so send the same text on every
53
+ * document of the sale.
54
+ *
55
+ * How it differs from `order_ref`: `order_ref` is how a PAYMENT finds its invoice; `sale_group` is how a BILL
56
+ * finds its sale's invoice. They are independent. A document may carry both, either or neither, they may hold the
57
+ * same id or different ones, and neither is used in the other's place: a document with no `sale_group` belongs to
58
+ * no sale group, whatever its `order_ref` says.
59
+ *
60
+ * An object, not a plain string, so that later versions can add facts about the sale beside `ref`. It carries no
61
+ * instructions: what a company does with a sale's costs is that company's own setting in QBO Sync. Any other key
62
+ * is refused today.
63
+ *
64
+ * Meant for invoices, bills and vendor credits. A credit memo may carry it, but nothing reads it there: a credit
65
+ * memo keeps applying to its invoice as before.
66
+ *
67
+ * What QBO Sync does with a sale's documents is each company's own setting. With no setting, the field is stored
68
+ * and nothing else changes. A company may choose to keep a bill's cost aside until the sale's invoice is in
69
+ * QuickBooks; for that, the bill and the invoice must carry the same `ref`.
70
+ *
71
+ * A document already sent keeps what it was first sent with: the same version sent again with `sale_group` added
72
+ * is a changed document and is refused, and a document already in QuickBooks takes no new version. So name sales
73
+ * on documents still to be sent, and never on a bill whose sale's invoice was sent without it.
74
+ *
75
+ * `ref` is at most `MAX_SALE_GROUP_REF` characters (0.12.1): QBO Sync indexes it.
76
+ */
77
+ export const saleGroup = z.strictObject({
78
+ ref: z
79
+ .string()
80
+ .max(MAX_SALE_GROUP_REF, `must be at most ${MAX_SALE_GROUP_REF} characters`)
81
+ .regex(SYSTEM_AND_ID, 'must be "<system>:<id>", e.g. "myapp:project:2207"'),
82
+ });
41
83
  /** At most this many `extra_order_refs` on one document. */
42
84
  export const MAX_EXTRA_ORDER_REFS = 10;
43
85
  /**
@@ -27,6 +27,9 @@ export declare const creditMemoSchema: z.ZodObject<{
27
27
  applies_to_invoice_ref: z.ZodString;
28
28
  order_ref: z.ZodOptional<z.ZodString>;
29
29
  extra_order_refs: z.ZodOptional<z.ZodArray<z.ZodString>>;
30
+ sale_group: z.ZodOptional<z.ZodObject<{
31
+ ref: z.ZodString;
32
+ }, z.core.$strict>>;
30
33
  references: z.ZodOptional<z.ZodArray<z.ZodObject<{
31
34
  label: z.ZodString;
32
35
  value: z.ZodString;
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { cents, currency, customer, docNumber, envelope, extraOrderRefIssues, extraOrderRefs, isoDate, lineAmountMatches, orderRef, positiveCents, references, sum, text, } from "./common.js";
2
+ import { cents, currency, customer, docNumber, envelope, extraOrderRefIssues, extraOrderRefs, isoDate, lineAmountMatches, orderRef, positiveCents, references, saleGroup, sum, text, } from "./common.js";
3
3
  /** A credit memo line: reverses an invoice line (`applies_to_line_ref`), or is a money-only credit. */
4
4
  export const creditMemoLine = z.strictObject({
5
5
  applies_to_line_ref: z.string().optional(),
@@ -30,6 +30,8 @@ export const creditMemoSchema = z
30
30
  applies_to_invoice_ref: text,
31
31
  order_ref: orderRef.optional(),
32
32
  extra_order_refs: extraOrderRefs.optional(),
33
+ /** May be sent (0.12.0, `saleGroup` in `common.ts`), but nothing reads it on a credit memo: it applies to its invoice as before. */
34
+ sale_group: saleGroup.optional(),
33
35
  references: references.optional(),
34
36
  class_key: z.string().optional(),
35
37
  customer,
@@ -27,6 +27,9 @@ export declare const appDocumentSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
27
27
  currency: z.ZodString;
28
28
  order_ref: z.ZodOptional<z.ZodString>;
29
29
  extra_order_refs: z.ZodOptional<z.ZodArray<z.ZodString>>;
30
+ sale_group: z.ZodOptional<z.ZodObject<{
31
+ ref: z.ZodString;
32
+ }, z.core.$strict>>;
30
33
  references: z.ZodOptional<z.ZodArray<z.ZodObject<{
31
34
  label: z.ZodString;
32
35
  value: z.ZodString;
@@ -93,6 +96,9 @@ export declare const appDocumentSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
93
96
  applies_to_invoice_ref: z.ZodString;
94
97
  order_ref: z.ZodOptional<z.ZodString>;
95
98
  extra_order_refs: z.ZodOptional<z.ZodArray<z.ZodString>>;
99
+ sale_group: z.ZodOptional<z.ZodObject<{
100
+ ref: z.ZodString;
101
+ }, z.core.$strict>>;
96
102
  references: z.ZodOptional<z.ZodArray<z.ZodObject<{
97
103
  label: z.ZodString;
98
104
  value: z.ZodString;
@@ -189,6 +195,9 @@ export declare const appDocumentSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
189
195
  }, z.core.$strict>>;
190
196
  }, z.core.$strict>>;
191
197
  order_ref: z.ZodOptional<z.ZodString>;
198
+ sale_group: z.ZodOptional<z.ZodObject<{
199
+ ref: z.ZodString;
200
+ }, z.core.$strict>>;
192
201
  references: z.ZodOptional<z.ZodArray<z.ZodObject<{
193
202
  label: z.ZodString;
194
203
  value: z.ZodString;
@@ -283,6 +292,9 @@ export declare const appDocumentSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
283
292
  }, z.core.$strict>>;
284
293
  }, z.core.$strict>>;
285
294
  order_ref: z.ZodOptional<z.ZodString>;
295
+ sale_group: z.ZodOptional<z.ZodObject<{
296
+ ref: z.ZodString;
297
+ }, z.core.$strict>>;
286
298
  references: z.ZodOptional<z.ZodArray<z.ZodObject<{
287
299
  label: z.ZodString;
288
300
  value: z.ZodString;
@@ -32,6 +32,9 @@ export declare const invoiceSchema: z.ZodObject<{
32
32
  currency: z.ZodString;
33
33
  order_ref: z.ZodOptional<z.ZodString>;
34
34
  extra_order_refs: z.ZodOptional<z.ZodArray<z.ZodString>>;
35
+ sale_group: z.ZodOptional<z.ZodObject<{
36
+ ref: z.ZodString;
37
+ }, z.core.$strict>>;
35
38
  references: z.ZodOptional<z.ZodArray<z.ZodObject<{
36
39
  label: z.ZodString;
37
40
  value: z.ZodString;
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { cents, currency, customer, docNumber, envelope, extraOrderRefIssues, extraOrderRefs, fee, isoDate, lineAmountMatches, orderRef, references, sum, text, } from "./common.js";
2
+ import { cents, currency, customer, docNumber, envelope, extraOrderRefIssues, extraOrderRefs, fee, isoDate, lineAmountMatches, orderRef, references, saleGroup, sum, text, } from "./common.js";
3
3
  /** One invoice line. `line_ref` is stable (say, the shop's line item id); credit memos point at it. */
4
4
  export const invoiceLine = z.strictObject({
5
5
  line_ref: text,
@@ -37,6 +37,8 @@ export const invoiceSchema = z
37
37
  currency,
38
38
  order_ref: orderRef.optional(),
39
39
  extra_order_refs: extraOrderRefs.optional(),
40
+ /** The sale this invoice belongs to (0.12.0, `saleGroup` in `common.ts`): bills that name the same sale are its costs. */
41
+ sale_group: saleGroup.optional(),
40
42
  references: references.optional(),
41
43
  class_key: z.string().optional(),
42
44
  customer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@company-six/qbosync",
3
- "version": "0.11.0",
3
+ "version": "0.12.1",
4
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",