@happyvertical/accounting 0.101.1 → 0.101.3
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 +19 -3
- package/dist/chunks/{invoice-request-C_z10JiX.js → invoice-request-CnemKZt9.js} +40 -2
- package/dist/chunks/invoice-request-CnemKZt9.js.map +1 -0
- package/dist/chunks/{quickbooks-DxvEmXav.js → quickbooks-jX3_uKoz.js} +3 -4
- package/dist/chunks/{quickbooks-DxvEmXav.js.map → quickbooks-jX3_uKoz.js.map} +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/providers/quickbooks/invoice-request.d.ts.map +1 -1
- package/dist/providers/quickbooks/line-amount.d.ts +3 -0
- package/dist/providers/quickbooks/line-amount.d.ts.map +1 -0
- package/dist/types.d.ts +5 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/chunks/OAuthClient-x9rUYj0b.js +0 -18264
- package/dist/chunks/OAuthClient-x9rUYj0b.js.map +0 -1
- package/dist/chunks/invoice-request-C_z10JiX.js.map +0 -1
- package/dist/chunks/rolldown-runtime-D1cXj70v.js +0 -46
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"invoice-request-C_z10JiX.js","names":[],"sources":["../../src/providers/quickbooks/invoice-request.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport type { InvoiceInput, QuickBooksInvoiceRequest } from '../../types.js';\n\n/** Prepare once, persist before sending, and reuse unchanged. Performs no I/O. */\nexport function prepareQuickBooksInvoiceRequest(\n invoice: InvoiceInput,\n identity: Omit<QuickBooksInvoiceRequest, 'payloadHash'>,\n): QuickBooksInvoiceRequest {\n if (invoice.externalId)\n throw new Error('QuickBooks request identity is only for invoice creation');\n const payload = JSON.stringify(mapInvoiceToQBO(invoice));\n const request = { ...identity, payloadHash: hash(payload) };\n validateQuickBooksInvoiceRequest(\n request,\n identity.realmId,\n identity.environment,\n payload,\n );\n return Object.freeze(request);\n}\n\nfunction hash(payload: string): string {\n return createHash('sha256').update(payload).digest('hex');\n}\n\nexport function validateQuickBooksInvoiceRequest(\n request: QuickBooksInvoiceRequest,\n realmId: string,\n environment: 'sandbox' | 'production',\n payload: string | undefined,\n): void {\n // A deliberately conservative URL-safe subset of Intuit's 50-character limit.\n if (\n !request ||\n typeof request.requestId !== 'string' ||\n !/^[A-Za-z0-9._-]{1,50}$/.test(request.requestId)\n ) {\n throw new Error(\n 'QuickBooks requestId must contain 1–50 URL-safe letters, digits, dots, underscores or hyphens',\n );\n }\n if (\n !request.realmId ||\n request.realmId !== realmId ||\n !['sandbox', 'production'].includes(request.environment) ||\n request.environment !== environment\n ) {\n throw new Error('QuickBooks invoice request realm/environment mismatch');\n }\n if (!payload || request.payloadHash !== hash(payload)) {\n throw new Error(\n 'QuickBooks invoice request payload mismatch; reconcile the original request',\n );\n }\n const parsed = JSON.parse(payload);\n if (parsed.Id !== undefined || parsed.SyncToken !== undefined) {\n throw new Error('QuickBooks request identity is only for invoice creation');\n }\n}\n\nfunction formatLocalDate(date: Date): string {\n const year = date.getFullYear();\n const month = String(date.getMonth() + 1).padStart(2, '0');\n const day = String(date.getDate()).padStart(2, '0');\n return `${year}-${month}-${day}`;\n}\n\nexport function mapInvoiceToQBO(invoice: InvoiceInput) {\n if (invoice.collectionMethod === 'charge_automatically') {\n // QuickBooks cannot charge a stored payment method for an invoice.\n throw new Error(\n 'QuickBooks does not support charge_automatically invoice collection',\n );\n }\n if (invoice.automaticTax)\n throw new Error(\n 'QuickBooks does not support automaticTax invoice calculation',\n );\n if (\n invoice.quickbooksMapping &&\n !['TaxExcluded', 'NotApplicable'].includes(\n invoice.quickbooksMapping.globalTaxCalculation,\n )\n )\n throw new Error(\n 'QuickBooks globalTaxCalculation must be TaxExcluded or NotApplicable',\n );\n const finite = (value: number, label: string) => {\n if (!Number.isFinite(value) || value < 0)\n throw new Error(\n `QuickBooks ${label} must be a finite non-negative amount`,\n );\n return value;\n };\n const reference = (value: string | undefined, label: string) => {\n if (!value || value.trim() !== value || value.length > 255)\n throw new Error(\n `QuickBooks ${label} must be a non-empty realm reference`,\n );\n return { value };\n };\n finite(invoice.subtotal, 'subtotal');\n finite(invoice.taxAmount, 'tax amount');\n finite(invoice.totalAmount, 'total amount');\n if (invoice.lineItems.length === 0)\n throw new Error('QuickBooks invoices require at least one sales line');\n const close = (a: number, b: number) =>\n Number.isFinite(a) &&\n Number.isFinite(b) &&\n Math.abs(a - b) <=\n Number.EPSILON * Math.max(1, Math.abs(a), Math.abs(b)) * 8;\n const lines = invoice.lineItems.map((item, idx) => {\n if (item.discount !== undefined && item.discount !== 0)\n throw new Error(\n 'QuickBooks line discounts are not supported; record an explicit supported sales line instead',\n );\n if (item.taxRate !== undefined && item.taxRate !== 0)\n throw new Error(\n 'QuickBooks numeric taxRate is not supported; use a realm taxCodeRef',\n );\n if (item.taxCode !== undefined)\n throw new Error(\n 'QuickBooks generic taxCode is not a realm tax reference; use quickbooksMapping.taxCodeRef',\n );\n finite(item.quantity, `line ${idx + 1} quantity`);\n finite(item.unitPrice, `line ${idx + 1} unit price`);\n const amount = finite(\n item.amount ?? item.quantity * item.unitPrice,\n `line ${idx + 1} amount`,\n );\n if (!close(amount, item.quantity * item.unitPrice))\n throw new Error(\n `QuickBooks line ${idx + 1} amount must equal quantity times unit price`,\n );\n return {\n LineNum: idx + 1,\n Description: item.description,\n Amount: amount,\n DetailType: 'SalesItemLineDetail' as const,\n SalesItemLineDetail: {\n Qty: item.quantity,\n UnitPrice: item.unitPrice,\n ItemRef: item.quickbooksMapping\n ? reference(item.quickbooksMapping.itemRef, `line ${idx + 1} itemRef`)\n : undefined,\n TaxCodeRef: item.quickbooksMapping\n ? reference(\n item.quickbooksMapping.taxCodeRef,\n `line ${idx + 1} taxCodeRef`,\n )\n : undefined,\n },\n };\n });\n // Compensated summation limits accumulated binary floating-point error\n // without assuming a currency-specific number of decimal places.\n let mappedSubtotal = 0;\n let compensation = 0;\n for (const line of lines) {\n const adjusted = line.Amount - compensation;\n const next = mappedSubtotal + adjusted;\n compensation = next - mappedSubtotal - adjusted;\n mappedSubtotal = next;\n }\n if (!close(mappedSubtotal, invoice.subtotal))\n throw new Error('QuickBooks line amounts must equal the invoice subtotal');\n if (!close(invoice.subtotal + invoice.taxAmount, invoice.totalAmount))\n throw new Error(\n 'QuickBooks subtotal plus tax must equal the invoice total',\n );\n const hasLineMapping = invoice.lineItems.some(\n (item) => item.quickbooksMapping,\n );\n if ((invoice.taxAmount > 0 || hasLineMapping) && !invoice.quickbooksMapping)\n throw new Error(\n 'QuickBooks mapped or nonzero-tax invoices require explicit globalTaxCalculation',\n );\n if (\n invoice.quickbooksMapping &&\n invoice.lineItems.some((item) => !item.quickbooksMapping)\n )\n throw new Error(\n 'QuickBooks mapped invoices require itemRef and taxCodeRef on every line',\n );\n if (\n invoice.taxAmount > 0 &&\n invoice.quickbooksMapping?.globalTaxCalculation === 'NotApplicable'\n )\n throw new Error(\n 'QuickBooks nonzero tax cannot use NotApplicable global tax calculation',\n );\n return {\n CustomerRef: { value: invoice.customerExternalId || invoice.customerId },\n DocNumber: invoice.invoiceNumber,\n TxnDate: formatLocalDate(invoice.issueDate),\n DueDate: formatLocalDate(invoice.dueDate),\n Line: lines,\n GlobalTaxCalculation: invoice.quickbooksMapping?.globalTaxCalculation,\n TxnTaxDetail: invoice.quickbooksMapping\n ? { TotalTax: invoice.taxAmount }\n : undefined,\n CurrencyRef: invoice.currency ? { value: invoice.currency } : undefined,\n CustomerMemo: invoice.memo ? { value: invoice.memo } : undefined,\n };\n}\n"],"mappings":";;;AAIA,SAAgB,gCACd,SACA,UAC0B;CAC1B,IAAI,QAAQ,YACV,MAAM,IAAI,MAAM,0DAA0D;CAC5E,MAAM,UAAU,KAAK,UAAU,gBAAgB,OAAO,CAAC;CACvD,MAAM,UAAU;EAAE,GAAG;EAAU,aAAa,KAAK,OAAO;CAAE;CAC1D,iCACE,SACA,SAAS,SACT,SAAS,aACT,OACF;C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ACF"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __esmMin = (fn, res, err) => () => {
|
|
9
|
-
if (err) throw err[0];
|
|
10
|
-
try {
|
|
11
|
-
return fn && (res = fn(fn = 0)), res;
|
|
12
|
-
} catch (e) {
|
|
13
|
-
throw err = [e], e;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
17
|
-
var __exportAll = (all, no_symbols) => {
|
|
18
|
-
let target = {};
|
|
19
|
-
for (var name in all) __defProp(target, name, {
|
|
20
|
-
get: all[name],
|
|
21
|
-
enumerable: true
|
|
22
|
-
});
|
|
23
|
-
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
24
|
-
return target;
|
|
25
|
-
};
|
|
26
|
-
var __copyProps = (to, from, except, desc) => {
|
|
27
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
28
|
-
key = keys[i];
|
|
29
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
30
|
-
get: ((k) => from[k]).bind(null, key),
|
|
31
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
return to;
|
|
35
|
-
};
|
|
36
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
37
|
-
value: mod,
|
|
38
|
-
enumerable: true
|
|
39
|
-
}) : target, mod));
|
|
40
|
-
var __toCommonJS = (mod) => __hasOwnProp.call(mod, "module.exports") ? mod["module.exports"] : __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
42
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
43
|
-
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
44
|
-
});
|
|
45
|
-
//#endregion
|
|
46
|
-
export { __toCommonJS as a, __require as i, __esmMin as n, __toESM as o, __exportAll as r, __commonJSMin as t };
|