@rowbind/sdk 0.0.0-stage → 0.1.0-alpha.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 +537 -2
- package/dist/generated/catalog.d.ts +22 -0
- package/dist/generated/catalog.js +7 -0
- package/dist/generated/http.d.ts +1740 -0
- package/dist/generated/http.js +843 -0
- package/dist/generated/raw.d.ts +39 -0
- package/dist/generated/raw.js +14 -0
- package/dist/generated/validators.d.ts +1411 -0
- package/dist/generated/validators.js +993 -0
- package/dist/http-error.d.ts +5 -0
- package/dist/http-error.js +2 -0
- package/dist/http-request.d.ts +17 -0
- package/dist/http-request.js +73 -0
- package/dist/index.d.ts +622 -0
- package/dist/index.js +256 -0
- package/dist/inputs.d.ts +145 -0
- package/dist/inputs.js +46 -0
- package/dist/ledger.d.ts +98 -0
- package/dist/ledger.js +218 -0
- package/dist/raw-invoice-query.d.ts +2 -0
- package/dist/raw-invoice-query.js +10 -0
- package/dist/transport.d.ts +344 -0
- package/dist/transport.js +276 -0
- package/dist/wire.d.ts +16 -0
- package/dist/wire.js +8 -0
- package/examples/catalog-invoice.mts +30 -0
- package/examples/connection-health.mts +21 -0
- package/examples/department-quickbooks/example.mts +12 -0
- package/examples/department-quickbooks/tsconfig.json +4 -0
- package/examples/facturar.mts +34 -0
- package/examples/first-customer.mts +72 -0
- package/examples/invoice-balances.mts +60 -0
- package/examples/invoice-settlement.mts +86 -0
- package/examples/invoice-sync.mts +46 -0
- package/examples/invoice-traces.mts +65 -0
- package/examples/invoice.mts +27 -0
- package/examples/mixed-providers/example.mts +12 -0
- package/examples/mixed-providers/tsconfig.json +4 -0
- package/examples/native-query.mts +28 -0
- package/examples/native-quickstart.mts +46 -0
- package/examples/observed-payments.mts +29 -0
- package/examples/quickstart.mts +11 -0
- package/examples/reimbursement-batch.mts +36 -0
- package/examples/resume-invoice.mts +52 -0
- package/examples/tsconfig.editor.json +11 -0
- package/examples/webhook-receiver.mts +142 -0
- package/package.json +78 -4
package/dist/ledger.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { mkdirSync } from "node:fs";
|
|
3
|
+
import { dirname } from "node:path";
|
|
4
|
+
const qbd = "qbd-demo";
|
|
5
|
+
const netsuite = "ns-demo";
|
|
6
|
+
const subsidiaryId = "ns-sub-1";
|
|
7
|
+
const departmentId = "7";
|
|
8
|
+
export const fixture = {
|
|
9
|
+
quickbooksDesktop: {
|
|
10
|
+
connectionId: qbd,
|
|
11
|
+
invoiceOptions: undefined,
|
|
12
|
+
kitBuild: { inventoryAssemblyItemId: "qbd-kit", inventorySiteId: "qbd-main", transactionDate: "2026-11-28" },
|
|
13
|
+
},
|
|
14
|
+
netsuite: {
|
|
15
|
+
connectionId: netsuite,
|
|
16
|
+
invoiceOptions: { netsuite: { subsidiaryId } },
|
|
17
|
+
partialShipment: { orderId: "ns-so-1", orderLine: 10, locationId: "ns-main" },
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
export class LedgerError extends Error {
|
|
21
|
+
code;
|
|
22
|
+
constructor(code, message, requestId) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = "LedgerError";
|
|
25
|
+
this.code = code;
|
|
26
|
+
if (requestId !== undefined)
|
|
27
|
+
this.requestId = requestId;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function requireValue(condition, message, code = "invalid_input") {
|
|
31
|
+
if (!condition)
|
|
32
|
+
throw new LedgerError(code, message);
|
|
33
|
+
}
|
|
34
|
+
function checkConnection(connectionId, expected) {
|
|
35
|
+
requireValue(connectionId === qbd || connectionId === netsuite, "Unknown sandbox connection.", "connection_not_found");
|
|
36
|
+
requireValue(!expected || expected === connectionId, "The selected connection belongs to a different ERP.", "provider_mismatch");
|
|
37
|
+
}
|
|
38
|
+
function checkQuantity(quantity) {
|
|
39
|
+
requireValue(Number.isSafeInteger(quantity) && quantity > 0, "Quantity must be a positive whole number.");
|
|
40
|
+
}
|
|
41
|
+
// JSON object member order has no meaning. Array order (including invoice line order) does.
|
|
42
|
+
function canonicalJSON(value) {
|
|
43
|
+
return JSON.stringify(value, (_key, entry) => {
|
|
44
|
+
if (entry === null || typeof entry !== "object" || Array.isArray(entry))
|
|
45
|
+
return entry;
|
|
46
|
+
return Object.fromEntries(Object.entries(entry).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function dollars(cents) {
|
|
50
|
+
return `${cents / 100n}.${String(cents % 100n).padStart(2, "0")}`;
|
|
51
|
+
}
|
|
52
|
+
export class SandboxLedger {
|
|
53
|
+
db;
|
|
54
|
+
constructor(path) {
|
|
55
|
+
if (path !== ":memory:")
|
|
56
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
57
|
+
const sqlite = process.getBuiltinModule("node:sqlite");
|
|
58
|
+
if (!sqlite?.DatabaseSync)
|
|
59
|
+
throw new LedgerError("unsupported_runtime", "The offline SQLite sandbox needs Node 24 or later. For HTTP, configure ROWBIND_API_KEY.");
|
|
60
|
+
this.db = new sqlite.DatabaseSync(path);
|
|
61
|
+
try {
|
|
62
|
+
this.db.exec("PRAGMA busy_timeout = 5000; PRAGMA foreign_keys = ON");
|
|
63
|
+
this.transaction(() => this.db.exec(`
|
|
64
|
+
CREATE TABLE IF NOT EXISTS native_records (
|
|
65
|
+
id TEXT PRIMARY KEY, connection TEXT NOT NULL, document TEXT NOT NULL
|
|
66
|
+
);
|
|
67
|
+
CREATE TABLE IF NOT EXISTS operations (
|
|
68
|
+
id TEXT PRIMARY KEY, connection TEXT NOT NULL, key TEXT NOT NULL,
|
|
69
|
+
kind TEXT NOT NULL, payload TEXT NOT NULL,
|
|
70
|
+
native_id TEXT NOT NULL UNIQUE REFERENCES native_records(id), UNIQUE(connection, key)
|
|
71
|
+
);
|
|
72
|
+
CREATE TABLE IF NOT EXISTS inventory (
|
|
73
|
+
connection TEXT NOT NULL, site TEXT NOT NULL, item TEXT NOT NULL,
|
|
74
|
+
on_hand INTEGER NOT NULL CHECK(on_hand >= 0), PRIMARY KEY(connection, site, item)
|
|
75
|
+
);
|
|
76
|
+
CREATE TABLE IF NOT EXISTS order_lines (
|
|
77
|
+
connection TEXT NOT NULL, order_id TEXT NOT NULL, line INTEGER NOT NULL,
|
|
78
|
+
location TEXT NOT NULL, item TEXT NOT NULL, quantity INTEGER NOT NULL,
|
|
79
|
+
fulfilled INTEGER NOT NULL CHECK(fulfilled BETWEEN 0 AND quantity), PRIMARY KEY(connection, order_id, line)
|
|
80
|
+
);
|
|
81
|
+
INSERT OR IGNORE INTO inventory VALUES
|
|
82
|
+
('qbd-demo','qbd-main','qbd-kit',0), ('qbd-demo','qbd-main','qbd-a',12), ('qbd-demo','qbd-main','qbd-b',9),
|
|
83
|
+
('qbd-demo','qbd-secondary','qbd-kit',1), ('qbd-demo','qbd-secondary','qbd-a',8), ('qbd-demo','qbd-secondary','qbd-b',5),
|
|
84
|
+
('ns-demo','ns-main','ns-material',10), ('ns-demo','ns-main','ns-spare',8);
|
|
85
|
+
INSERT OR IGNORE INTO order_lines VALUES
|
|
86
|
+
('ns-demo','ns-so-1',10,'ns-main','ns-material',5,0), ('ns-demo','ns-so-1',30,'ns-main','ns-spare',4,0);
|
|
87
|
+
`));
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
this.db.close();
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
close() { this.db.close(); }
|
|
95
|
+
transaction(work) {
|
|
96
|
+
this.db.exec("BEGIN IMMEDIATE");
|
|
97
|
+
try {
|
|
98
|
+
const result = work();
|
|
99
|
+
this.db.exec("COMMIT");
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
this.db.exec("ROLLBACK");
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
write(connection, key, kind, payload, apply) {
|
|
108
|
+
requireValue(typeof key === "string" && key.trim().length > 0, "An idempotency key is required.");
|
|
109
|
+
const canonical = canonicalJSON(payload);
|
|
110
|
+
return this.transaction(() => {
|
|
111
|
+
const existing = this.db.prepare("SELECT id, kind, payload FROM operations WHERE connection = ? AND key = ?").get(connection, key);
|
|
112
|
+
if (existing) {
|
|
113
|
+
requireValue(existing.kind === kind && existing.payload === canonical, "The key already identifies a different operation on this connection.", "idempotency_conflict");
|
|
114
|
+
return { id: String(existing.id) };
|
|
115
|
+
}
|
|
116
|
+
const nativeId = `${connection === qbd ? "qbd" : "ns"}-${kind}-${randomUUID()}`;
|
|
117
|
+
const record = apply(nativeId);
|
|
118
|
+
const id = `op_${randomUUID()}`;
|
|
119
|
+
this.db.prepare("INSERT INTO native_records VALUES (?, ?, ?)").run(nativeId, connection, JSON.stringify(record));
|
|
120
|
+
this.db.prepare("INSERT INTO operations VALUES (?, ?, ?, ?, ?, ?)").run(id, connection, key, kind, canonical, nativeId);
|
|
121
|
+
return { id };
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
record(operationId) {
|
|
125
|
+
const row = this.db.prepare(`SELECT r.document FROM operations o JOIN native_records r
|
|
126
|
+
ON r.id = o.native_id AND r.connection = o.connection WHERE o.id = ?`).get(operationId);
|
|
127
|
+
requireValue(row, "Sandbox operation not found.", "record_not_found");
|
|
128
|
+
return JSON.parse(String(row.document));
|
|
129
|
+
}
|
|
130
|
+
createInvoice(connectionId, key, payload) {
|
|
131
|
+
checkConnection(connectionId);
|
|
132
|
+
return this.write(connectionId, key, "invoice", payload, id => {
|
|
133
|
+
requireValue(payload.currency === "USD" && payload.externalReference?.trim(), "The sandbox invoice requires USD and an external reference.");
|
|
134
|
+
requireValue(payload.customerRef?.externalId === "tienda-norte", "Customer reference has no mapping on this connection.", "mapping_not_found");
|
|
135
|
+
const nsOptions = payload.providerOptions?.netsuite;
|
|
136
|
+
if (connectionId === netsuite) {
|
|
137
|
+
requireValue(nsOptions?.subsidiaryId === subsidiaryId, "A valid subsidiary is required for this NetSuite connection.", "mapping_not_found");
|
|
138
|
+
requireValue(nsOptions.departmentId === undefined || nsOptions.departmentId === departmentId, "Unknown invoice department in the sandbox subsidiary.", "mapping_not_found");
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
requireValue(nsOptions === undefined, "NetSuite options require a NetSuite connection.", "provider_mismatch");
|
|
142
|
+
}
|
|
143
|
+
requireValue(Array.isArray(payload.lines) && payload.lines.length > 0, "An invoice must have at least one line.");
|
|
144
|
+
const prefix = connectionId === qbd ? "qbd" : "ns";
|
|
145
|
+
let cents = 0n;
|
|
146
|
+
const lines = payload.lines.map(({ itemRef, quantity, unitPrice }) => {
|
|
147
|
+
const externalId = itemRef?.externalId;
|
|
148
|
+
requireValue(externalId === "mano-de-obra" || externalId === "material", "Item reference has no mapping on this connection.", "mapping_not_found");
|
|
149
|
+
checkQuantity(quantity);
|
|
150
|
+
requireValue(typeof unitPrice === "string" && /^\d+\.\d{2}$/.test(unitPrice), "Unit price must be a nonnegative USD string with two decimal places.");
|
|
151
|
+
cents += BigInt(unitPrice.replace(".", "")) * BigInt(quantity);
|
|
152
|
+
return { itemId: prefix + (externalId === "mano-de-obra" ? "-labor" : "-material"), quantity, unitPrice };
|
|
153
|
+
});
|
|
154
|
+
const total = dollars(cents);
|
|
155
|
+
return { kind: "invoice", id, connectionId, customerId: prefix + "-customer-norte", externalReference: payload.externalReference,
|
|
156
|
+
currency: "USD", lines, total, balanceDue: total, ...(connectionId === netsuite ? { subsidiaryId } : {}),
|
|
157
|
+
...(nsOptions?.departmentId && { departmentId: nsOptions.departmentId }) };
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
sites(connectionId) {
|
|
161
|
+
checkConnection(connectionId, qbd);
|
|
162
|
+
return [{ id: "qbd-main", name: "Main warehouse" }, { id: "qbd-secondary", name: "Secondary warehouse" }];
|
|
163
|
+
}
|
|
164
|
+
stock(connectionId, siteId) {
|
|
165
|
+
checkConnection(connectionId);
|
|
166
|
+
const rows = this.db.prepare("SELECT item, on_hand FROM inventory WHERE connection = ? AND site = ? ORDER BY item").all(connectionId, siteId);
|
|
167
|
+
requireValue(rows.length, "Unknown site on the selected connection.", "record_not_found");
|
|
168
|
+
return rows.map(row => ({ itemId: String(row.item), quantityOnHand: Number(row.on_hand) }));
|
|
169
|
+
}
|
|
170
|
+
consume(connection, site, item, quantity) {
|
|
171
|
+
const updated = this.db.prepare(`UPDATE inventory SET on_hand = on_hand - ?
|
|
172
|
+
WHERE connection = ? AND site = ? AND item = ? AND on_hand >= ?`).run(quantity, connection, site, item, quantity);
|
|
173
|
+
requireValue(updated.changes === 1, "Insufficient inventory at the selected site.", "insufficient_stock");
|
|
174
|
+
}
|
|
175
|
+
build(connectionId, key, payload) {
|
|
176
|
+
checkConnection(connectionId, qbd);
|
|
177
|
+
return this.write(connectionId, key, "build", payload, id => {
|
|
178
|
+
const { inventoryAssemblyItemId, inventorySiteId, transactionDate, quantityToBuild, markPendingIfRequired } = payload;
|
|
179
|
+
requireValue(inventoryAssemblyItemId === "qbd-kit", "Unknown assembly in this company file.", "mapping_not_found");
|
|
180
|
+
requireValue(this.sites(connectionId).some(site => site.id === inventorySiteId), "Unknown inventory site in this company file.", "record_not_found");
|
|
181
|
+
checkQuantity(quantityToBuild);
|
|
182
|
+
const date = new Date(transactionDate + "T00:00:00Z");
|
|
183
|
+
requireValue(/^\d{4}-\d{2}-\d{2}$/.test(transactionDate) && Number.isFinite(date.getTime()) && date.toISOString().startsWith(transactionDate), "A valid YYYY-MM-DD transaction date is required.");
|
|
184
|
+
requireValue(markPendingIfRequired === false, "The sandbox supports completed builds only.");
|
|
185
|
+
this.consume(connectionId, inventorySiteId, "qbd-a", 2 * quantityToBuild);
|
|
186
|
+
this.consume(connectionId, inventorySiteId, "qbd-b", quantityToBuild);
|
|
187
|
+
this.db.prepare("UPDATE inventory SET on_hand = on_hand + ? WHERE connection = ? AND site = ? AND item = ?").run(quantityToBuild, connectionId, inventorySiteId, inventoryAssemblyItemId);
|
|
188
|
+
return { kind: "build", id, connectionId, inventoryAssemblyItemId, inventorySiteId, transactionDate, quantityToBuild, isPending: false };
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
order(connectionId, id) {
|
|
192
|
+
checkConnection(connectionId, netsuite);
|
|
193
|
+
const rows = this.db.prepare(`SELECT line, location, quantity, fulfilled FROM order_lines
|
|
194
|
+
WHERE connection = ? AND order_id = ? ORDER BY line`).all(connectionId, id);
|
|
195
|
+
requireValue(rows.length, "Sales order not found on the selected connection.", "record_not_found");
|
|
196
|
+
return { id, lines: rows.map(row => ({ orderLine: Number(row.line), locationId: String(row.location),
|
|
197
|
+
quantity: Number(row.quantity), quantityFulfilled: Number(row.fulfilled) })) };
|
|
198
|
+
}
|
|
199
|
+
fulfill(connectionId, key, payload) {
|
|
200
|
+
checkConnection(connectionId, netsuite);
|
|
201
|
+
return this.write(connectionId, key, "fulfillment", payload, id => {
|
|
202
|
+
const { salesOrderId, lines } = payload;
|
|
203
|
+
requireValue(Array.isArray(lines) && lines.length > 0, "A fulfillment requires at least one line.");
|
|
204
|
+
const seen = new Set();
|
|
205
|
+
for (const { orderLine, locationId, quantity } of lines) {
|
|
206
|
+
checkQuantity(quantity);
|
|
207
|
+
requireValue(!seen.has(orderLine), "Each sales-order line can appear only once per fulfillment.");
|
|
208
|
+
seen.add(orderLine);
|
|
209
|
+
const line = this.db.prepare("SELECT location, item, quantity, fulfilled FROM order_lines WHERE connection = ? AND order_id = ? AND line = ?").get(connectionId, salesOrderId, orderLine);
|
|
210
|
+
requireValue(line && line.location === locationId, "Unknown order line or location on the selected sales order.", "record_not_found");
|
|
211
|
+
requireValue(quantity <= Number(line.quantity) - Number(line.fulfilled), "Quantity exceeds the remaining units on this order line.", "quantity_exceeds_remaining");
|
|
212
|
+
this.consume(connectionId, locationId, String(line.item), quantity);
|
|
213
|
+
this.db.prepare("UPDATE order_lines SET fulfilled = fulfilled + ? WHERE connection = ? AND order_id = ? AND line = ?").run(quantity, connectionId, salesOrderId, orderLine);
|
|
214
|
+
}
|
|
215
|
+
return { kind: "fulfillment", id, connectionId, salesOrderId, lines: [...lines] };
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// The sandbox and pilot accept this subset of both protocols. A matched ID is
|
|
2
|
+
// the only part of the request that can be used to address the upstream book.
|
|
3
|
+
export function rawInvoiceLookupId(request) {
|
|
4
|
+
if (request.provider === "quickbooksDesktop") {
|
|
5
|
+
return /^<InvoiceQueryRq>[ \t\r\n]*<TxnID>([A-Za-z0-9_-]{1,128})<\/TxnID>[ \t\r\n]*<\/InvoiceQueryRq>$/.exec(request.qbxml.trim())?.[1] ?? null;
|
|
6
|
+
}
|
|
7
|
+
if (request.method !== "GET")
|
|
8
|
+
return null;
|
|
9
|
+
return /^\/services\/rest\/record\/v1\/invoice\/([A-Za-z0-9_-]{1,128})$/.exec(request.path)?.[1] ?? null;
|
|
10
|
+
}
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import * as http from "./generated/http.js";
|
|
3
|
+
import type { ResponseMetadata, RowbindFetch } from "./http-request.js";
|
|
4
|
+
import { type invoiceSchema } from "./inputs.js";
|
|
5
|
+
import { LedgerError } from "./ledger.js";
|
|
6
|
+
export type WireConnection = http.Connection;
|
|
7
|
+
export type PilotOperation = http.Operation;
|
|
8
|
+
type NativeResult<P extends http.RawReadResult["provider"]> = Extract<http.RawReadResult, {
|
|
9
|
+
provider: P;
|
|
10
|
+
}> & ResponseMetadata;
|
|
11
|
+
export type InvoiceTraceLookup = Pick<http.ListInvoiceTracesParams, "connectionId" | "after"> & ({
|
|
12
|
+
requestId: string;
|
|
13
|
+
reference?: never;
|
|
14
|
+
operationId?: never;
|
|
15
|
+
} | {
|
|
16
|
+
reference: string;
|
|
17
|
+
requestId?: never;
|
|
18
|
+
operationId?: never;
|
|
19
|
+
} | {
|
|
20
|
+
operationId: string;
|
|
21
|
+
requestId?: never;
|
|
22
|
+
reference?: never;
|
|
23
|
+
});
|
|
24
|
+
export declare class OperationWaitError extends LedgerError {
|
|
25
|
+
readonly operationId: string;
|
|
26
|
+
readonly diagnosis?: http.InvoiceRecoveryEntry | undefined;
|
|
27
|
+
constructor(code: "verification_pending" | "transport_unavailable" | "core_storage_unavailable", message: string, operationId: string, diagnosis?: http.InvoiceRecoveryEntry | undefined, requestId?: string);
|
|
28
|
+
}
|
|
29
|
+
export declare class PilotTransport {
|
|
30
|
+
private readonly fetch?;
|
|
31
|
+
private readonly base;
|
|
32
|
+
private readonly key;
|
|
33
|
+
constructor(url: string, key: string, fetch?: RowbindFetch | undefined);
|
|
34
|
+
private options;
|
|
35
|
+
createCompany(input: http.CompanyRequest): Promise<{
|
|
36
|
+
id: string;
|
|
37
|
+
externalId: string;
|
|
38
|
+
name: string;
|
|
39
|
+
}>;
|
|
40
|
+
createConnectSession(input: http.ConnectSessionRequest): Promise<{
|
|
41
|
+
id: string;
|
|
42
|
+
companyId: string;
|
|
43
|
+
provider: "quickbooksDesktop" | "netsuite";
|
|
44
|
+
expiresAt: string;
|
|
45
|
+
status: "pending";
|
|
46
|
+
url: string;
|
|
47
|
+
}>;
|
|
48
|
+
connectSession(id: string): Promise<{
|
|
49
|
+
id: string;
|
|
50
|
+
companyId: string;
|
|
51
|
+
provider: "quickbooksDesktop" | "netsuite";
|
|
52
|
+
expiresAt: string;
|
|
53
|
+
status: "pending" | "connected" | "expired";
|
|
54
|
+
connectionId?: string;
|
|
55
|
+
}>;
|
|
56
|
+
readRaw(id: string, input: Extract<http.RawReadRequest, {
|
|
57
|
+
provider: "quickbooksDesktop";
|
|
58
|
+
}>): Promise<NativeResult<"quickbooksDesktop">>;
|
|
59
|
+
readRaw(id: string, input: Extract<http.RawReadRequest, {
|
|
60
|
+
provider: "netsuite";
|
|
61
|
+
}>): Promise<NativeResult<"netsuite">>;
|
|
62
|
+
queryRaw(id: string, input: Extract<http.RawQueryRequest, {
|
|
63
|
+
provider: "quickbooksDesktop";
|
|
64
|
+
}>): Promise<Extract<http.RawQueryResult, {
|
|
65
|
+
provider: "quickbooksDesktop";
|
|
66
|
+
}> & ResponseMetadata>;
|
|
67
|
+
queryRaw(id: string, input: Extract<http.RawQueryRequest, {
|
|
68
|
+
provider: "netsuite";
|
|
69
|
+
}>): Promise<Extract<http.RawQueryResult, {
|
|
70
|
+
provider: "netsuite";
|
|
71
|
+
}> & ResponseMetadata>;
|
|
72
|
+
createReceivedPayment(body: http.ReceivedPaymentRequest, key: string): Promise<{
|
|
73
|
+
id: string;
|
|
74
|
+
}>;
|
|
75
|
+
createCreditMemo(body: http.CreditMemoRequest, key: string): Promise<{
|
|
76
|
+
id: string;
|
|
77
|
+
}>;
|
|
78
|
+
applyCreditMemo(id: string, body: http.CreditApplicationRequest, key: string): Promise<{
|
|
79
|
+
id: string;
|
|
80
|
+
}>;
|
|
81
|
+
createBatch(body: http.BatchRequest, idempotencyKey: string): Promise<{
|
|
82
|
+
id: string;
|
|
83
|
+
}>;
|
|
84
|
+
batch(id: string): Promise<{
|
|
85
|
+
id: string;
|
|
86
|
+
connectionId: string;
|
|
87
|
+
status: "pending" | "verified";
|
|
88
|
+
rows: {
|
|
89
|
+
key: string;
|
|
90
|
+
kind: "vendor_bill" | "bill_payment";
|
|
91
|
+
status: "pending" | "verified" | "blocked";
|
|
92
|
+
amount: string;
|
|
93
|
+
dependsOn: string[];
|
|
94
|
+
nativeId?: string;
|
|
95
|
+
balanceDue?: string;
|
|
96
|
+
diagnosis?: {
|
|
97
|
+
code: "queued" | "awaiting_bills" | "dispatch_claimed" | "source_offline" | "wrong_book" | "book_diverged" | "source_record_missing" | "source_record_mismatch" | "bills_changed" | "storage_error" | "internal_error" | "record_verified";
|
|
98
|
+
certainty: "unknown" | "verified" | "not_sent";
|
|
99
|
+
nextAction: "dispatch_once" | "wait_for_bills" | "verify_original_book" | "restore_connection" | "open_authorized_book" | "reconcile_book" | "review_mismatch" | "review_bills" | "resume_operation" | "none";
|
|
100
|
+
owner: "none" | "rowbind" | "erp_admin" | "saas";
|
|
101
|
+
requiredEvidence: "none" | "verified_dependencies" | "authorized_book" | "consistent_book" | "open_bills" | "native_bill" | "native_payment_and_applications";
|
|
102
|
+
blockingRowKeys: string[];
|
|
103
|
+
observedAt: string | null;
|
|
104
|
+
};
|
|
105
|
+
history?: {
|
|
106
|
+
code: "queued" | "awaiting_bills" | "dispatch_claimed" | "source_offline" | "wrong_book" | "book_diverged" | "source_record_missing" | "source_record_mismatch" | "bills_changed" | "storage_error" | "internal_error" | "record_verified";
|
|
107
|
+
certainty: "unknown" | "verified" | "not_sent";
|
|
108
|
+
nextAction: "dispatch_once" | "wait_for_bills" | "verify_original_book" | "restore_connection" | "open_authorized_book" | "reconcile_book" | "review_mismatch" | "review_bills" | "resume_operation" | "none";
|
|
109
|
+
owner: "none" | "rowbind" | "erp_admin" | "saas";
|
|
110
|
+
requiredEvidence: "none" | "verified_dependencies" | "authorized_book" | "consistent_book" | "open_bills" | "native_bill" | "native_payment_and_applications";
|
|
111
|
+
blockingRowKeys: string[];
|
|
112
|
+
observedAt: string | null;
|
|
113
|
+
}[];
|
|
114
|
+
}[];
|
|
115
|
+
}>;
|
|
116
|
+
searchCatalog(id: string, kind: http.CatalogKind, params: http.SearchCatalogParams): Promise<{
|
|
117
|
+
records: {
|
|
118
|
+
nativeId: string;
|
|
119
|
+
displayName: string;
|
|
120
|
+
sku?: string;
|
|
121
|
+
}[];
|
|
122
|
+
nextCursor: string | null;
|
|
123
|
+
}>;
|
|
124
|
+
linkCatalog(id: string, kind: http.CatalogKind, input: http.CatalogLinkRequest): Promise<{
|
|
125
|
+
kind: "customer" | "item";
|
|
126
|
+
externalId: string;
|
|
127
|
+
nativeId: string;
|
|
128
|
+
}>;
|
|
129
|
+
enableInvoiceSync(connectionId: string): Promise<{
|
|
130
|
+
connectionId: string;
|
|
131
|
+
resource: "invoices";
|
|
132
|
+
status: "initializing" | "syncing" | "current" | "unavailable";
|
|
133
|
+
coveredThrough: string | null;
|
|
134
|
+
lastAttemptAt: string | null;
|
|
135
|
+
lastFailure?: "source_offline" | "wrong_book" | "book_diverged" | "storage_error" | "permission_denied" | "source_history_gap" | null;
|
|
136
|
+
}>;
|
|
137
|
+
retrieveInvoiceSync(connectionId: string): Promise<{
|
|
138
|
+
connectionId: string;
|
|
139
|
+
resource: "invoices";
|
|
140
|
+
status: "initializing" | "syncing" | "current" | "unavailable";
|
|
141
|
+
coveredThrough: string | null;
|
|
142
|
+
lastAttemptAt: string | null;
|
|
143
|
+
lastFailure?: "source_offline" | "wrong_book" | "book_diverged" | "storage_error" | "permission_denied" | "source_history_gap" | null;
|
|
144
|
+
}>;
|
|
145
|
+
listSyncedInvoices(connectionId: string, params?: http.ListSyncedInvoicesParams): Promise<{
|
|
146
|
+
connectionId: string;
|
|
147
|
+
snapshotRevision: number;
|
|
148
|
+
coveredThrough: string;
|
|
149
|
+
invoices: {
|
|
150
|
+
invoiceId: string;
|
|
151
|
+
revision: number;
|
|
152
|
+
currency: string;
|
|
153
|
+
balanceDue: string;
|
|
154
|
+
status?: "voided";
|
|
155
|
+
details?: {
|
|
156
|
+
customerId?: string;
|
|
157
|
+
externalReference?: string;
|
|
158
|
+
invoiceNumber?: string;
|
|
159
|
+
issueDate?: string;
|
|
160
|
+
dueDate?: string;
|
|
161
|
+
total?: string;
|
|
162
|
+
subsidiaryId?: string;
|
|
163
|
+
departmentId?: string;
|
|
164
|
+
lines?: {
|
|
165
|
+
itemId: string;
|
|
166
|
+
quantity: number;
|
|
167
|
+
unitPrice: string;
|
|
168
|
+
description?: string;
|
|
169
|
+
}[];
|
|
170
|
+
};
|
|
171
|
+
}[];
|
|
172
|
+
nextCursor: string | null;
|
|
173
|
+
}>;
|
|
174
|
+
enableReceivedPaymentSync(connectionId: string): Promise<{
|
|
175
|
+
connectionId: string;
|
|
176
|
+
resource: "received_payments";
|
|
177
|
+
status: "initializing" | "syncing" | "current" | "unavailable";
|
|
178
|
+
coveredThrough: string | null;
|
|
179
|
+
lastAttemptAt: string | null;
|
|
180
|
+
lastFailure: "source_offline" | "wrong_book" | "book_diverged" | "storage_error" | "page_lost" | null;
|
|
181
|
+
}>;
|
|
182
|
+
retrieveReceivedPaymentSync(connectionId: string): Promise<{
|
|
183
|
+
connectionId: string;
|
|
184
|
+
resource: "received_payments";
|
|
185
|
+
status: "initializing" | "syncing" | "current" | "unavailable";
|
|
186
|
+
coveredThrough: string | null;
|
|
187
|
+
lastAttemptAt: string | null;
|
|
188
|
+
lastFailure: "source_offline" | "wrong_book" | "book_diverged" | "storage_error" | "page_lost" | null;
|
|
189
|
+
}>;
|
|
190
|
+
listObservedPayments(connectionId: string, params?: http.ListObservedPaymentsParams): Promise<{
|
|
191
|
+
observations: {
|
|
192
|
+
id: string;
|
|
193
|
+
connectionId: string;
|
|
194
|
+
provider: "quickbooksDesktop" | "netsuite";
|
|
195
|
+
paymentId: string;
|
|
196
|
+
invoiceId: string;
|
|
197
|
+
amount: string;
|
|
198
|
+
currency: "USD";
|
|
199
|
+
balanceDue: string;
|
|
200
|
+
modifiedAt: string;
|
|
201
|
+
observedAt: string;
|
|
202
|
+
status: "pending_match" | "matched";
|
|
203
|
+
externalInvoiceId: string | null;
|
|
204
|
+
}[];
|
|
205
|
+
nextCursor: string | null;
|
|
206
|
+
}>;
|
|
207
|
+
matchObservedPayment(id: string, input: http.MatchObservedPaymentRequest): Promise<{
|
|
208
|
+
id: string;
|
|
209
|
+
connectionId: string;
|
|
210
|
+
provider: "quickbooksDesktop" | "netsuite";
|
|
211
|
+
paymentId: string;
|
|
212
|
+
invoiceId: string;
|
|
213
|
+
amount: string;
|
|
214
|
+
currency: "USD";
|
|
215
|
+
balanceDue: string;
|
|
216
|
+
modifiedAt: string;
|
|
217
|
+
observedAt: string;
|
|
218
|
+
status: "pending_match" | "matched";
|
|
219
|
+
externalInvoiceId: string | null;
|
|
220
|
+
}>;
|
|
221
|
+
createWebhookEndpoint(body: http.WebhookEndpointRequest): Promise<{
|
|
222
|
+
id: string;
|
|
223
|
+
destination: string;
|
|
224
|
+
eventType: "operation.verified" | "invoice.created" | "invoice.updated" | "invoice.voided" | "invoice.deleted" | "payment.matched";
|
|
225
|
+
}>;
|
|
226
|
+
webhookDeliveries(id: string): Promise<{
|
|
227
|
+
deliveries: ({
|
|
228
|
+
eventId: string;
|
|
229
|
+
operationId: string;
|
|
230
|
+
status: "pending" | "delivered" | "dead_letter";
|
|
231
|
+
attempts: number;
|
|
232
|
+
lastHttpStatus: number | null;
|
|
233
|
+
} | {
|
|
234
|
+
eventId: string;
|
|
235
|
+
eventType: "invoice.created";
|
|
236
|
+
connectionId: string;
|
|
237
|
+
invoiceId: string;
|
|
238
|
+
revision: number;
|
|
239
|
+
status: "pending" | "delivered" | "dead_letter";
|
|
240
|
+
attempts: number;
|
|
241
|
+
lastHttpStatus: number | null;
|
|
242
|
+
} | {
|
|
243
|
+
eventId: string;
|
|
244
|
+
eventType: "invoice.updated";
|
|
245
|
+
connectionId: string;
|
|
246
|
+
invoiceId: string;
|
|
247
|
+
revision: number;
|
|
248
|
+
status: "pending" | "delivered" | "dead_letter";
|
|
249
|
+
attempts: number;
|
|
250
|
+
lastHttpStatus: number | null;
|
|
251
|
+
} | {
|
|
252
|
+
eventId: string;
|
|
253
|
+
eventType: "invoice.voided";
|
|
254
|
+
connectionId: string;
|
|
255
|
+
invoiceId: string;
|
|
256
|
+
revision: number;
|
|
257
|
+
status: "pending" | "delivered" | "dead_letter";
|
|
258
|
+
attempts: number;
|
|
259
|
+
lastHttpStatus: number | null;
|
|
260
|
+
} | {
|
|
261
|
+
eventId: string;
|
|
262
|
+
eventType: "invoice.deleted";
|
|
263
|
+
connectionId: string;
|
|
264
|
+
invoiceId: string;
|
|
265
|
+
revision: number;
|
|
266
|
+
status: "pending" | "delivered" | "dead_letter";
|
|
267
|
+
attempts: number;
|
|
268
|
+
lastHttpStatus: number | null;
|
|
269
|
+
} | {
|
|
270
|
+
eventId: string;
|
|
271
|
+
eventType: "payment.matched";
|
|
272
|
+
connectionId: string;
|
|
273
|
+
invoiceId: string;
|
|
274
|
+
paymentId: string;
|
|
275
|
+
observationId: string;
|
|
276
|
+
status: "pending" | "delivered" | "dead_letter";
|
|
277
|
+
attempts: number;
|
|
278
|
+
lastHttpStatus: number | null;
|
|
279
|
+
})[];
|
|
280
|
+
}>;
|
|
281
|
+
replayWebhookDelivery(id: string, eventId: string): Promise<{
|
|
282
|
+
eventId: string;
|
|
283
|
+
}>;
|
|
284
|
+
connections(): Promise<({
|
|
285
|
+
id: string;
|
|
286
|
+
provider: "quickbooksDesktop";
|
|
287
|
+
} | {
|
|
288
|
+
id: string;
|
|
289
|
+
provider: "netsuite";
|
|
290
|
+
subsidiaryId: string;
|
|
291
|
+
})[]>;
|
|
292
|
+
connection(id: string): Promise<{
|
|
293
|
+
id: string;
|
|
294
|
+
provider: "quickbooksDesktop";
|
|
295
|
+
} | {
|
|
296
|
+
id: string;
|
|
297
|
+
provider: "netsuite";
|
|
298
|
+
subsidiaryId: string;
|
|
299
|
+
}>;
|
|
300
|
+
connectionHealth(id: string): Promise<{
|
|
301
|
+
connectionId: string;
|
|
302
|
+
provider: "quickbooksDesktop" | "netsuite";
|
|
303
|
+
authorization: "authorized" | "unrecorded";
|
|
304
|
+
authorizedAt: string | null;
|
|
305
|
+
status: "verified" | "wrong_book" | "book_diverged" | "unchecked" | "offline" | "permission_denied";
|
|
306
|
+
checkedAt: string | null;
|
|
307
|
+
lastVerifiedAt: string | null;
|
|
308
|
+
capability: "invoices:read";
|
|
309
|
+
nextAction: "restore_connection" | "open_authorized_book" | "reconcile_book" | "none" | "run_check" | "restore_permissions" | "authorize_connection";
|
|
310
|
+
divergence?: {
|
|
311
|
+
kind: "invoice_receipt";
|
|
312
|
+
operationId: string;
|
|
313
|
+
} | {
|
|
314
|
+
kind: "invoice_checkpoint" | "payment_checkpoint";
|
|
315
|
+
revision: number;
|
|
316
|
+
};
|
|
317
|
+
}>;
|
|
318
|
+
checkConnectionHealth(id: string): Promise<{
|
|
319
|
+
connectionId: string;
|
|
320
|
+
provider: "quickbooksDesktop" | "netsuite";
|
|
321
|
+
authorization: "authorized" | "unrecorded";
|
|
322
|
+
authorizedAt: string | null;
|
|
323
|
+
status: "verified" | "wrong_book" | "book_diverged" | "unchecked" | "offline" | "permission_denied";
|
|
324
|
+
checkedAt: string | null;
|
|
325
|
+
lastVerifiedAt: string | null;
|
|
326
|
+
capability: "invoices:read";
|
|
327
|
+
nextAction: "restore_connection" | "open_authorized_book" | "reconcile_book" | "none" | "run_check" | "restore_permissions" | "authorize_connection";
|
|
328
|
+
divergence?: {
|
|
329
|
+
kind: "invoice_receipt";
|
|
330
|
+
operationId: string;
|
|
331
|
+
} | {
|
|
332
|
+
kind: "invoice_checkpoint" | "payment_checkpoint";
|
|
333
|
+
revision: number;
|
|
334
|
+
};
|
|
335
|
+
}>;
|
|
336
|
+
create(body: Omit<z.output<typeof invoiceSchema>, "idempotencyKey">, idempotencyKey: string, responseMetadata?: ResponseMetadata): Promise<{
|
|
337
|
+
id: string;
|
|
338
|
+
}>;
|
|
339
|
+
invoiceTraces(lookup: InvoiceTraceLookup): Promise<http.InvoiceTracePage>;
|
|
340
|
+
invoiceRecovery(id: string, params?: http.RetrieveInvoiceRecoveryParams): Promise<http.InvoiceRecoveryPage>;
|
|
341
|
+
operation(id: string, deadline?: number): Promise<PilotOperation>;
|
|
342
|
+
wait(id: string, timeoutMs: number): Promise<http.ReceivedPaymentRecord | http.CreditMemoRecord | http.CreditApplicationRecord | http.InvoiceRecord>;
|
|
343
|
+
}
|
|
344
|
+
export {};
|