@rowbind/sdk 0.1.0-alpha.1 → 0.1.0-canary.130
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 +101 -1
- package/dist/generated/http.d.ts +380 -2
- package/dist/generated/http.js +195 -2
- package/dist/generated/validators.d.ts +413 -3
- package/dist/generated/validators.js +355 -2
- package/dist/http-request.js +2 -1
- package/dist/index.d.ts +58 -2
- package/dist/index.js +35 -1
- package/dist/invoice-custom-fields.d.ts +42 -0
- package/dist/invoice-custom-fields.js +105 -0
- package/dist/transport.d.ts +11 -1
- package/dist/transport.js +132 -1
- package/dist/wire.d.ts +1 -1
- package/dist/wire.js +1 -1
- package/package.json +60 -78
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { LedgerError } from "./ledger.js";
|
|
3
|
+
function field(schema, id, type, parseValue) {
|
|
4
|
+
const definition = schema.fields.find(entry => entry.id === id);
|
|
5
|
+
if (definition?.type !== type) {
|
|
6
|
+
throw new LedgerError("invalid_input", `Field ${id} is not ${type} in this invoice schema.`);
|
|
7
|
+
}
|
|
8
|
+
const { connectionId, provider, revision: schemaRevision } = schema;
|
|
9
|
+
const { writable, nullable, maxLength } = definition;
|
|
10
|
+
function parse(value, code) {
|
|
11
|
+
const parsed = parseValue(value);
|
|
12
|
+
if (parsed === undefined || (type === "text" && typeof parsed === "string" && maxLength !== undefined && [...parsed].length > maxLength)) {
|
|
13
|
+
throw new LedgerError(code, `Field ${id} requires a valid ${type} value from this schema.`);
|
|
14
|
+
}
|
|
15
|
+
return parsed;
|
|
16
|
+
}
|
|
17
|
+
function write(value) {
|
|
18
|
+
if (!writable)
|
|
19
|
+
throw new LedgerError("invalid_input", `Field ${id} is read-only.`);
|
|
20
|
+
return { connectionId, provider, schemaRevision, fieldId: id, value };
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
id,
|
|
24
|
+
get(snapshot) {
|
|
25
|
+
if (snapshot.connectionId !== connectionId || snapshot.provider !== provider || snapshot.schemaRevision !== schemaRevision) {
|
|
26
|
+
throw new LedgerError("custom_field_schema_mismatch", "Discover and regenerate the custom fields for this connection and schema revision.");
|
|
27
|
+
}
|
|
28
|
+
if (!Object.hasOwn(snapshot.values, id))
|
|
29
|
+
return undefined;
|
|
30
|
+
const value = snapshot.values[id];
|
|
31
|
+
if (value === null && nullable)
|
|
32
|
+
return null;
|
|
33
|
+
return parse(value, "invalid_response");
|
|
34
|
+
},
|
|
35
|
+
set: value => write(parse(value, "invalid_input")),
|
|
36
|
+
clear() {
|
|
37
|
+
if (!nullable)
|
|
38
|
+
throw new LedgerError("invalid_input", `Field ${id} cannot be cleared.`);
|
|
39
|
+
return write(null);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const decimalPattern = /^-?(?:0|[1-9]\d*)(?:\.\d+)?$/;
|
|
44
|
+
const isoDate = z.iso.date();
|
|
45
|
+
const fieldFactories = {
|
|
46
|
+
text: (schema, id) => field(schema, id, "text", value => typeof value === "string" ? value : undefined),
|
|
47
|
+
boolean: (schema, id) => field(schema, id, "boolean", value => typeof value === "boolean" ? value : undefined),
|
|
48
|
+
decimal: (schema, id) => field(schema, id, "decimal", value => typeof value === "string" && value.length <= 64 && decimalPattern.test(value) ? value : undefined),
|
|
49
|
+
date: (schema, id) => field(schema, id, "date", value => typeof value === "string" && isoDate.safeParse(value).success ? value : undefined),
|
|
50
|
+
select(schema, id, options) {
|
|
51
|
+
const nativeOptions = schema.fields.find(entry => entry.id === id)?.options?.map(option => option.id) ?? [];
|
|
52
|
+
if (nativeOptions.length !== options.length || new Set(options).size !== options.length ||
|
|
53
|
+
options.some(value => !nativeOptions.some(native => value === native))) {
|
|
54
|
+
throw new LedgerError("custom_field_schema_mismatch", `Field ${id} has different select options in the discovered schema.`);
|
|
55
|
+
}
|
|
56
|
+
const knownOptions = [...options];
|
|
57
|
+
return field(schema, id, "select", value => knownOptions.find(option => option === value));
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
/** Construct typed handles from a discovered schema, without using unvalidated field names. */
|
|
61
|
+
export const invoiceCustomField = {
|
|
62
|
+
...fieldFactories,
|
|
63
|
+
readOnly({ id, get }) { return { id, get }; },
|
|
64
|
+
withoutClear({ id, get, set }) { return { id, get, set }; },
|
|
65
|
+
};
|
|
66
|
+
/** Render a TypeScript module. Review and save the result in your application, then import its fields. */
|
|
67
|
+
export function generateInvoiceCustomFields(schema) {
|
|
68
|
+
const definitions = schema.fields.map(definition => {
|
|
69
|
+
if (!Object.hasOwn(fieldFactories, definition.type))
|
|
70
|
+
throw new LedgerError("invalid_input", "Discover a supported invoice field schema before generating types.");
|
|
71
|
+
const id = JSON.stringify(definition.id);
|
|
72
|
+
const options = definition.type === "select" ? `, ${JSON.stringify(definition.options?.map(option => option.id) ?? [])}` : "";
|
|
73
|
+
const handle = `invoiceCustomField.${definition.type}(schema, ${id}${options})`;
|
|
74
|
+
const accessor = !definition.writable ? `invoiceCustomField.readOnly(${handle})` :
|
|
75
|
+
!definition.nullable ? `invoiceCustomField.withoutClear(${handle})` : handle;
|
|
76
|
+
return ` [${id}]: ${accessor},`;
|
|
77
|
+
});
|
|
78
|
+
return [
|
|
79
|
+
"// Generated by Rowbind from the discovered invoice fields. Regenerate after schema changes.",
|
|
80
|
+
'import { invoiceCustomField, type InvoiceCustomFieldSchema } from "@rowbind/sdk"',
|
|
81
|
+
"",
|
|
82
|
+
`export const schema: InvoiceCustomFieldSchema = ${JSON.stringify(schema, null, 2)}`,
|
|
83
|
+
"export const fields = {",
|
|
84
|
+
...definitions,
|
|
85
|
+
"}",
|
|
86
|
+
"",
|
|
87
|
+
].join("\n");
|
|
88
|
+
}
|
|
89
|
+
export function stageInvoiceCustomFields(connectionId, invoiceId, current, assignments) {
|
|
90
|
+
if (current.connectionId !== connectionId || current.invoiceId !== invoiceId) {
|
|
91
|
+
throw new LedgerError("invalid_input", "Use the current custom field values from this invoice and connection.");
|
|
92
|
+
}
|
|
93
|
+
const values = new Map();
|
|
94
|
+
for (const assignment of assignments) {
|
|
95
|
+
if (assignment.connectionId !== connectionId || assignment.provider !== current.provider || assignment.schemaRevision !== current.schemaRevision) {
|
|
96
|
+
throw new LedgerError("custom_field_schema_mismatch", "Use assignments from the current invoice schema for this connection.");
|
|
97
|
+
}
|
|
98
|
+
if (values.has(assignment.fieldId))
|
|
99
|
+
throw new LedgerError("invalid_input", `Set field ${assignment.fieldId} at most once.`);
|
|
100
|
+
values.set(assignment.fieldId, assignment.value);
|
|
101
|
+
}
|
|
102
|
+
if (!values.size)
|
|
103
|
+
throw new LedgerError("invalid_input", "Set or clear at least one invoice custom field.");
|
|
104
|
+
return { schemaRevision: current.schemaRevision, revision: current.revision, values: Object.fromEntries(values) };
|
|
105
|
+
}
|
package/dist/transport.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
import * as http from "./generated/http.js";
|
|
3
3
|
import type { ResponseMetadata, RowbindFetch } from "./http-request.js";
|
|
4
4
|
import { type invoiceSchema } from "./inputs.js";
|
|
@@ -69,6 +69,11 @@ export declare class PilotTransport {
|
|
|
69
69
|
}>): Promise<Extract<http.RawQueryResult, {
|
|
70
70
|
provider: "netsuite";
|
|
71
71
|
}> & ResponseMetadata>;
|
|
72
|
+
admitRawWrite(id: string, input: http.AdmitRawWriteBody, idempotencyKey: string): Promise<http.RawWriteAdmission>;
|
|
73
|
+
retrieveRawWrite(id: string, operationId: string): Promise<http.RawWriteOperation>;
|
|
74
|
+
retrieveQuickBooksVendor(id: string, listId: string): Promise<http.QuickBooksVendor>;
|
|
75
|
+
retrieveQuickBooksInvoice(id: string, txnId: string): Promise<http.QuickBooksInvoiceDetails>;
|
|
76
|
+
getQuickBooksTrialBalance(id: string, options: http.GetQuickBooksTrialBalanceParams): Promise<http.QuickBooksTrialBalance>;
|
|
72
77
|
createReceivedPayment(body: http.ReceivedPaymentRequest, key: string): Promise<{
|
|
73
78
|
id: string;
|
|
74
79
|
}>;
|
|
@@ -142,6 +147,11 @@ export declare class PilotTransport {
|
|
|
142
147
|
lastAttemptAt: string | null;
|
|
143
148
|
lastFailure?: "source_offline" | "wrong_book" | "book_diverged" | "storage_error" | "permission_denied" | "source_history_gap" | null;
|
|
144
149
|
}>;
|
|
150
|
+
retrieveInvoice(connectionId: string, nativeId: string): Promise<http.RetrievedInvoice>;
|
|
151
|
+
discoverInvoiceCustomFields(connectionId: string): Promise<http.InvoiceCustomFieldSchema>;
|
|
152
|
+
readInvoiceCustomFields(connectionId: string, nativeId: string): Promise<http.InvoiceCustomFieldValues>;
|
|
153
|
+
updateInvoiceCustomFields(connectionId: string, nativeId: string, input: http.InvoiceCustomFieldUpdate, idempotencyKey: string, provider?: http.InvoiceCustomFieldValues["provider"]): Promise<http.InvoiceCustomFieldValues>;
|
|
154
|
+
listInventoryLevels(connectionId: string, filters: http.ListInventoryLevelsParams): Promise<http.InventoryLevels>;
|
|
145
155
|
listSyncedInvoices(connectionId: string, params?: http.ListSyncedInvoicesParams): Promise<{
|
|
146
156
|
connectionId: string;
|
|
147
157
|
snapshotRevision: number;
|
package/dist/transport.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
2
|
+
import { z } from "zod";
|
|
2
3
|
import * as http from "./generated/http.js";
|
|
3
|
-
import { ApplyCreditMemoResponse, CreateCreditMemoResponse, CreateReceivedPaymentResponse, SearchCatalogParams, SearchCatalogQueryParams, SearchCatalogResponse, LinkCatalogParams, LinkCatalogBody, LinkCatalogResponse, CreateBatchResponse, CreateCompanyResponse, CreateConnectSessionResponse, CreateInvoiceResponse, CreateWebhookEndpointResponse, ListConnectionsResponse, ListWebhookDeliveriesResponse, ReplayWebhookDeliveryResponse, EnableReceivedPaymentSyncParams, EnableReceivedPaymentSyncResponse, RetrieveReceivedPaymentSyncParams, RetrieveReceivedPaymentSyncResponse, ListObservedPaymentsParams, ListObservedPaymentsQueryParams, ListObservedPaymentsResponse, MatchObservedPaymentParams, MatchObservedPaymentBody, MatchObservedPaymentResponse, RetrieveConnectionHealthParams, RetrieveConnectionHealthResponse, CheckConnectionHealthParams, CheckConnectionHealthResponse, ReadRawBody, ReadRawParams, ReadRawResponse, ListInvoiceTracesQueryParams, ListInvoiceTracesResponse, ListSyncedInvoicesParams, ListSyncedInvoicesQueryParams, ListSyncedInvoicesResponse, RetrieveInvoiceRecoveryParams, RetrieveInvoiceRecoveryQueryParams, RetrieveInvoiceRecoveryResponse, RetrieveBatchResponse, RetrieveConnectionResponse, RetrieveInvoiceSyncResponse, RetrieveConnectSessionResponse, RetrieveOperationResponse, } from "./generated/validators.js";
|
|
4
|
+
import { ApplyCreditMemoResponse, CreateCreditMemoResponse, CreateReceivedPaymentResponse, SearchCatalogParams, SearchCatalogQueryParams, SearchCatalogResponse, LinkCatalogParams, LinkCatalogBody, LinkCatalogResponse, CreateBatchResponse, CreateCompanyResponse, CreateConnectSessionResponse, CreateInvoiceResponse, CreateWebhookEndpointResponse, ListConnectionsResponse, ListWebhookDeliveriesResponse, ReplayWebhookDeliveryResponse, EnableReceivedPaymentSyncParams, EnableReceivedPaymentSyncResponse, RetrieveReceivedPaymentSyncParams, RetrieveReceivedPaymentSyncResponse, ListObservedPaymentsParams, ListObservedPaymentsQueryParams, ListObservedPaymentsResponse, MatchObservedPaymentParams, MatchObservedPaymentBody, MatchObservedPaymentResponse, RetrieveConnectionHealthParams, RetrieveConnectionHealthResponse, CheckConnectionHealthParams, CheckConnectionHealthResponse, ReadRawBody, ReadRawParams, ReadRawResponse, AdmitRawWriteBody, AdmitRawWriteParams, AdmitRawWriteResponse, RetrieveRawWriteParams, RetrieveRawWriteResponse, RetrieveQuickBooksVendorParams, RetrieveQuickBooksVendorResponse, RetrieveQuickBooksInvoiceParams, RetrieveQuickBooksInvoiceResponse, GetQuickBooksTrialBalanceParams, GetQuickBooksTrialBalanceQueryParams, GetQuickBooksTrialBalanceResponse, ListInvoiceTracesQueryParams, ListInvoiceTracesResponse, ListInventoryLevelsParams, ListInventoryLevelsQueryParams, ListInventoryLevelsResponse, ListSyncedInvoicesParams, ListSyncedInvoicesQueryParams, ListSyncedInvoicesResponse, RetrieveInvoiceParams, RetrieveInvoiceResponse, RetrieveInvoiceRecoveryParams, RetrieveInvoiceRecoveryQueryParams, RetrieveInvoiceRecoveryResponse, DiscoverInvoiceCustomFieldsParams, DiscoverInvoiceCustomFieldsResponse, ReadInvoiceCustomFieldsParams, ReadInvoiceCustomFieldsResponse, UpdateInvoiceCustomFieldsParams, UpdateInvoiceCustomFieldsBody, UpdateInvoiceCustomFieldsResponse, RetrieveBatchResponse, RetrieveConnectionResponse, RetrieveInvoiceSyncResponse, RetrieveConnectSessionResponse, RetrieveOperationResponse, } from "./generated/validators.js";
|
|
4
5
|
import { QueryRawBody, QueryRawParams, QueryRawResponse } from "./wire.js";
|
|
5
6
|
import { parseInput } from "./inputs.js";
|
|
6
7
|
import { LedgerError } from "./ledger.js";
|
|
8
|
+
const customFieldIdempotencyKey = z.string().min(1).max(255).regex(/\S/);
|
|
7
9
|
export class OperationWaitError extends LedgerError {
|
|
8
10
|
operationId;
|
|
9
11
|
diagnosis;
|
|
@@ -82,6 +84,68 @@ export class PilotTransport {
|
|
|
82
84
|
}
|
|
83
85
|
return { ...result.data, ...responseMetadata };
|
|
84
86
|
}
|
|
87
|
+
async admitRawWrite(id, input, idempotencyKey) {
|
|
88
|
+
parseInput(AdmitRawWriteParams, { id });
|
|
89
|
+
const body = parseInput(AdmitRawWriteBody, input);
|
|
90
|
+
const key = parseInput(customFieldIdempotencyKey.regex(/^[ -~]+$/), idempotencyKey);
|
|
91
|
+
if (!body.qbxml.trim())
|
|
92
|
+
throw new LedgerError("invalid_input", "Provide a qbXML write fragment.");
|
|
93
|
+
const responseMetadata = {};
|
|
94
|
+
const result = AdmitRawWriteResponse.safeParse(await http.admitRawWrite(id, body, { "Idempotency-Key": key }, {
|
|
95
|
+
...this.options(), responseMetadata,
|
|
96
|
+
}));
|
|
97
|
+
if (!result.success)
|
|
98
|
+
throw new LedgerError("invalid_response", "Rowbind did not return a raw write operation ID.", responseMetadata.requestId);
|
|
99
|
+
return result.data;
|
|
100
|
+
}
|
|
101
|
+
async retrieveRawWrite(id, operationId) {
|
|
102
|
+
parseInput(RetrieveRawWriteParams, { id, operationId });
|
|
103
|
+
const responseMetadata = {};
|
|
104
|
+
const response = await http.retrieveRawWrite(id, operationId, { ...this.options(), responseMetadata });
|
|
105
|
+
const result = RetrieveRawWriteResponse.safeParse(response);
|
|
106
|
+
if (!result.success || result.data.id !== operationId || (result.data.status !== "verified" && "record" in response)) {
|
|
107
|
+
throw new LedgerError("invalid_response", "Rowbind did not return a valid result for the requested raw write.", responseMetadata.requestId);
|
|
108
|
+
}
|
|
109
|
+
return result.data;
|
|
110
|
+
}
|
|
111
|
+
async retrieveQuickBooksVendor(id, listId) {
|
|
112
|
+
parseInput(RetrieveQuickBooksVendorParams, { id, listId });
|
|
113
|
+
const responseMetadata = {};
|
|
114
|
+
const result = RetrieveQuickBooksVendorResponse.safeParse(await http.retrieveQuickBooksVendor(id, listId, {
|
|
115
|
+
...this.options(), responseMetadata, preserveServiceErrors: ["source_offline", "upstream_unavailable"],
|
|
116
|
+
}));
|
|
117
|
+
if (!result.success || result.data.listId !== listId) {
|
|
118
|
+
throw new LedgerError("invalid_response", "Rowbind did not return the requested QuickBooks vendor.", responseMetadata.requestId);
|
|
119
|
+
}
|
|
120
|
+
return result.data;
|
|
121
|
+
}
|
|
122
|
+
async retrieveQuickBooksInvoice(id, txnId) {
|
|
123
|
+
parseInput(RetrieveQuickBooksInvoiceParams, { id, txnId });
|
|
124
|
+
const responseMetadata = {};
|
|
125
|
+
const result = RetrieveQuickBooksInvoiceResponse.safeParse(await http.retrieveQuickBooksInvoice(id, txnId, {
|
|
126
|
+
...this.options(), responseMetadata, preserveServiceErrors: ["source_offline", "upstream_unavailable"],
|
|
127
|
+
}));
|
|
128
|
+
if (!result.success || result.data.txnId !== txnId) {
|
|
129
|
+
throw new LedgerError("invalid_response", "Rowbind did not return the requested QuickBooks invoice.", responseMetadata.requestId);
|
|
130
|
+
}
|
|
131
|
+
return result.data;
|
|
132
|
+
}
|
|
133
|
+
async getQuickBooksTrialBalance(id, options) {
|
|
134
|
+
parseInput(GetQuickBooksTrialBalanceParams, { id });
|
|
135
|
+
const query = parseInput(GetQuickBooksTrialBalanceQueryParams, options);
|
|
136
|
+
if ((query.from === undefined) !== (query.to === undefined) ||
|
|
137
|
+
(query.from !== undefined && query.to !== undefined && query.from > query.to)) {
|
|
138
|
+
throw new LedgerError("invalid_input", "Provide both trial balance dates in chronological order, or omit both.");
|
|
139
|
+
}
|
|
140
|
+
const responseMetadata = {};
|
|
141
|
+
const result = GetQuickBooksTrialBalanceResponse.safeParse(await http.getQuickBooksTrialBalance(id, query, {
|
|
142
|
+
...this.options(), responseMetadata, preserveServiceErrors: ["source_offline", "upstream_unavailable"],
|
|
143
|
+
}));
|
|
144
|
+
if (!result.success) {
|
|
145
|
+
throw new LedgerError("invalid_response", "Rowbind did not return a valid QuickBooks trial balance.", responseMetadata.requestId);
|
|
146
|
+
}
|
|
147
|
+
return result.data;
|
|
148
|
+
}
|
|
85
149
|
async createReceivedPayment(body, key) {
|
|
86
150
|
return CreateReceivedPaymentResponse.parse(await http.createReceivedPayment(body, { "Idempotency-Key": key }, this.options()));
|
|
87
151
|
}
|
|
@@ -123,6 +187,73 @@ export class PilotTransport {
|
|
|
123
187
|
const result = await http.retrieveInvoiceSync(connectionId, this.options());
|
|
124
188
|
return forConnection(RetrieveInvoiceSyncResponse.parse(result), connectionId);
|
|
125
189
|
}
|
|
190
|
+
async retrieveInvoice(connectionId, nativeId) {
|
|
191
|
+
parseInput(RetrieveInvoiceParams, { id: connectionId, nativeId });
|
|
192
|
+
const responseMetadata = {};
|
|
193
|
+
const result = RetrieveInvoiceResponse.safeParse(await http.retrieveInvoice(connectionId, nativeId, {
|
|
194
|
+
...this.options(), responseMetadata, preserveServiceErrors: ["source_offline", "upstream_unavailable"],
|
|
195
|
+
}));
|
|
196
|
+
if (!result.success || result.data.connectionId !== connectionId || result.data.id !== nativeId) {
|
|
197
|
+
throw new LedgerError("invalid_response", "Rowbind did not return the requested native invoice in this connection.", responseMetadata.requestId);
|
|
198
|
+
}
|
|
199
|
+
return result.data;
|
|
200
|
+
}
|
|
201
|
+
async discoverInvoiceCustomFields(connectionId) {
|
|
202
|
+
parseInput(DiscoverInvoiceCustomFieldsParams, { id: connectionId });
|
|
203
|
+
const responseMetadata = {};
|
|
204
|
+
const result = DiscoverInvoiceCustomFieldsResponse.safeParse(await http.discoverInvoiceCustomFields(connectionId, {
|
|
205
|
+
...this.options(), responseMetadata, preserveServiceErrors: ["source_offline", "upstream_unavailable"],
|
|
206
|
+
}));
|
|
207
|
+
if (!result.success || result.data.connectionId !== connectionId ||
|
|
208
|
+
new Set(result.data.fields.map(field => field.id)).size !== result.data.fields.length || result.data.fields.some(field => field.type === "select" && (!field.options || new Set(field.options.map(option => option.id)).size !== field.options.length))) {
|
|
209
|
+
throw new LedgerError("invalid_response", "Rowbind returned an invalid invoice custom field schema.", responseMetadata.requestId);
|
|
210
|
+
}
|
|
211
|
+
return result.data;
|
|
212
|
+
}
|
|
213
|
+
async readInvoiceCustomFields(connectionId, nativeId) {
|
|
214
|
+
parseInput(ReadInvoiceCustomFieldsParams, { id: connectionId, nativeId });
|
|
215
|
+
const responseMetadata = {};
|
|
216
|
+
const result = ReadInvoiceCustomFieldsResponse.safeParse(await http.readInvoiceCustomFields(connectionId, nativeId, {
|
|
217
|
+
...this.options(), responseMetadata, preserveServiceErrors: ["source_offline", "upstream_unavailable"],
|
|
218
|
+
}));
|
|
219
|
+
if (!result.success || result.data.connectionId !== connectionId || result.data.invoiceId !== nativeId) {
|
|
220
|
+
throw new LedgerError("invalid_response", "Rowbind returned invalid custom fields for the requested invoice.", responseMetadata.requestId);
|
|
221
|
+
}
|
|
222
|
+
return result.data;
|
|
223
|
+
}
|
|
224
|
+
async updateInvoiceCustomFields(connectionId, nativeId, input, idempotencyKey, provider) {
|
|
225
|
+
parseInput(UpdateInvoiceCustomFieldsParams, { id: connectionId, nativeId });
|
|
226
|
+
const body = parseInput(UpdateInvoiceCustomFieldsBody, input);
|
|
227
|
+
const key = parseInput(customFieldIdempotencyKey, idempotencyKey);
|
|
228
|
+
if (!Object.keys(body.values).length)
|
|
229
|
+
throw new LedgerError("invalid_input", "Set or clear at least one invoice custom field.");
|
|
230
|
+
const responseMetadata = {};
|
|
231
|
+
const result = UpdateInvoiceCustomFieldsResponse.safeParse(await http.updateInvoiceCustomFields(connectionId, nativeId, body, { "Idempotency-Key": key }, { ...this.options(), responseMetadata, preserveServiceErrors: ["source_offline", "upstream_unavailable"] }));
|
|
232
|
+
if (!result.success || result.data.connectionId !== connectionId || result.data.invoiceId !== nativeId ||
|
|
233
|
+
result.data.schemaRevision !== body.schemaRevision || (provider !== undefined && result.data.provider !== provider) ||
|
|
234
|
+
Object.entries(body.values).some(([id, value]) => result.data.values[id] !== value)) {
|
|
235
|
+
throw new LedgerError("invalid_response", "Rowbind did not confirm the requested custom field values.", responseMetadata.requestId);
|
|
236
|
+
}
|
|
237
|
+
return result.data;
|
|
238
|
+
}
|
|
239
|
+
async listInventoryLevels(connectionId, filters) {
|
|
240
|
+
parseInput(ListInventoryLevelsParams, { id: connectionId });
|
|
241
|
+
const query = parseInput(ListInventoryLevelsQueryParams, filters);
|
|
242
|
+
const responseMetadata = {};
|
|
243
|
+
const result = ListInventoryLevelsResponse.safeParse(await http.listInventoryLevels(connectionId, query, {
|
|
244
|
+
...this.options(), responseMetadata, preserveServiceErrors: ["source_offline", "upstream_unavailable"],
|
|
245
|
+
}));
|
|
246
|
+
if (!result.success || result.data.connectionId !== connectionId || result.data.itemId !== query.itemId) {
|
|
247
|
+
throw new LedgerError("invalid_response", "Rowbind did not return stock for the requested item and book.", responseMetadata.requestId);
|
|
248
|
+
}
|
|
249
|
+
const stock = result.data;
|
|
250
|
+
const sites = new Set(stock.granularity === "site" ? stock.levels.map(level => level.siteId) : []);
|
|
251
|
+
if ((stock.granularity === "site" && sites.size !== stock.levels.length) ||
|
|
252
|
+
(query.siteId && (sites.size !== 1 || !sites.has(query.siteId)))) {
|
|
253
|
+
throw new LedgerError("invalid_response", "Rowbind did not return the requested unique stock positions.", responseMetadata.requestId);
|
|
254
|
+
}
|
|
255
|
+
return stock;
|
|
256
|
+
}
|
|
126
257
|
async listSyncedInvoices(connectionId, params = {}) {
|
|
127
258
|
parseInput(ListSyncedInvoicesParams, { id: connectionId });
|
|
128
259
|
const query = parseInput(ListSyncedInvoicesQueryParams, params);
|
package/dist/wire.d.ts
CHANGED
|
@@ -11,6 +11,6 @@ export declare const QueryRawBody: import("zod").ZodUnion<readonly [import("zod"
|
|
|
11
11
|
limit: import("zod").ZodExactOptional<import("zod").ZodInt>;
|
|
12
12
|
offset: import("zod").ZodExactOptional<import("zod").ZodInt>;
|
|
13
13
|
}, import("zod/v4/core").$strict>]>;
|
|
14
|
-
export { SearchCatalogParams, SearchCatalogQueryParams, SearchCatalogResponse, LinkCatalogParams, LinkCatalogBody, LinkCatalogResponse, QueryRawParams, QueryRawResponse, ReadRawBody, ReadRawParams, ReadRawResponse, EnableInvoiceSyncParams, EnableInvoiceSyncResponse, RetrieveInvoiceSyncParams, RetrieveInvoiceSyncResponse, EnableReceivedPaymentSyncParams, EnableReceivedPaymentSyncResponse, RetrieveReceivedPaymentSyncParams, RetrieveReceivedPaymentSyncResponse, ListSyncedInvoicesParams, ListSyncedInvoicesQueryParams, ListSyncedInvoicesResponse, ListObservedPaymentsParams, ListObservedPaymentsQueryParams, ListObservedPaymentsResponse, MatchObservedPaymentParams, MatchObservedPaymentBody, MatchObservedPaymentResponse, CreateReceivedPaymentBody, CreateReceivedPaymentResponse, CreateCreditMemoBody, CreateCreditMemoResponse, ApplyCreditMemoBody, ApplyCreditMemoParams, ApplyCreditMemoResponse, CreateBatchBody, CreateBatchResponse, RetrieveBatchParams, RetrieveBatchResponse, CreateWebhookEndpointBody, CreateWebhookEndpointResponse, ListWebhookDeliveriesParams, ListWebhookDeliveriesResponse, ReplayWebhookDeliveryParams, ReplayWebhookDeliveryResponse, CreateCompanyBody, CreateCompanyResponse, CreateConnectSessionBody, CreateConnectSessionResponse, RetrieveConnectSessionParams, RetrieveConnectSessionResponse, ListConnectionsResponse, RetrieveConnectionHealthParams, RetrieveConnectionHealthResponse, CheckConnectionHealthParams, CheckConnectionHealthResponse, RetrieveConnectionParams, RetrieveConnectionResponse, CreateInvoiceBody, CreateInvoiceResponse, ListInvoiceTracesQueryParams, ListInvoiceTracesResponse, RetrieveInvoiceRecoveryParams, RetrieveInvoiceRecoveryQueryParams, RetrieveInvoiceRecoveryResponse, RetrieveOperationParams, RetrieveOperationResponse, } from "./generated/validators.js";
|
|
14
|
+
export { SearchCatalogParams, SearchCatalogQueryParams, SearchCatalogResponse, LinkCatalogParams, LinkCatalogBody, LinkCatalogResponse, ListInventoryLevelsParams, ListInventoryLevelsQueryParams, ListInventoryLevelsResponse, QueryRawParams, QueryRawResponse, ReadRawBody, ReadRawParams, ReadRawResponse, AdmitRawWriteBody, AdmitRawWriteParams, AdmitRawWriteResponse, RetrieveRawWriteParams, RetrieveRawWriteResponse, RetrieveQuickBooksVendorParams, RetrieveQuickBooksVendorResponse, RetrieveQuickBooksInvoiceParams, RetrieveQuickBooksInvoiceResponse, GetQuickBooksTrialBalanceParams, GetQuickBooksTrialBalanceQueryParams, GetQuickBooksTrialBalanceResponse, EnableInvoiceSyncParams, EnableInvoiceSyncResponse, RetrieveInvoiceSyncParams, RetrieveInvoiceSyncResponse, EnableReceivedPaymentSyncParams, EnableReceivedPaymentSyncResponse, RetrieveReceivedPaymentSyncParams, RetrieveReceivedPaymentSyncResponse, ListSyncedInvoicesParams, ListSyncedInvoicesQueryParams, ListSyncedInvoicesResponse, ListObservedPaymentsParams, ListObservedPaymentsQueryParams, ListObservedPaymentsResponse, MatchObservedPaymentParams, MatchObservedPaymentBody, MatchObservedPaymentResponse, CreateReceivedPaymentBody, CreateReceivedPaymentResponse, CreateCreditMemoBody, CreateCreditMemoResponse, ApplyCreditMemoBody, ApplyCreditMemoParams, ApplyCreditMemoResponse, CreateBatchBody, CreateBatchResponse, RetrieveBatchParams, RetrieveBatchResponse, CreateWebhookEndpointBody, CreateWebhookEndpointResponse, ListWebhookDeliveriesParams, ListWebhookDeliveriesResponse, ReplayWebhookDeliveryParams, ReplayWebhookDeliveryResponse, CreateCompanyBody, CreateCompanyResponse, CreateConnectSessionBody, CreateConnectSessionResponse, RetrieveConnectSessionParams, RetrieveConnectSessionResponse, ListConnectionsResponse, RetrieveConnectionHealthParams, RetrieveConnectionHealthResponse, CheckConnectionHealthParams, CheckConnectionHealthResponse, RetrieveConnectionParams, RetrieveConnectionResponse, CreateInvoiceBody, CreateInvoiceResponse, RetrieveInvoiceParams, RetrieveInvoiceResponse, DiscoverInvoiceCustomFieldsParams, DiscoverInvoiceCustomFieldsResponse, ReadInvoiceCustomFieldsParams, ReadInvoiceCustomFieldsResponse, UpdateInvoiceCustomFieldsParams, UpdateInvoiceCustomFieldsBody, UpdateInvoiceCustomFieldsResponse, ListInvoiceTracesQueryParams, ListInvoiceTracesResponse, RetrieveInvoiceRecoveryParams, RetrieveInvoiceRecoveryQueryParams, RetrieveInvoiceRecoveryResponse, RetrieveOperationParams, RetrieveOperationResponse, } from "./generated/validators.js";
|
|
15
15
|
export { rawInvoiceLookupId } from "./raw-invoice-query.js";
|
|
16
16
|
export { httpError } from "./http-error.js";
|
package/dist/wire.js
CHANGED
|
@@ -3,6 +3,6 @@ import { QueryRawBody as generatedQueryRawBody } from "./generated/validators.js
|
|
|
3
3
|
// OpenAPI describes the page size and offset bounds separately. SuiteTalk also
|
|
4
4
|
// requires every offset to fall on a page boundary.
|
|
5
5
|
export const QueryRawBody = generatedQueryRawBody.refine(input => input.provider !== "netsuite" || (input.offset ?? 0) % (input.limit ?? 10) === 0, { path: ["offset"], message: "Provide an offset divisible by the page limit." });
|
|
6
|
-
export { SearchCatalogParams, SearchCatalogQueryParams, SearchCatalogResponse, LinkCatalogParams, LinkCatalogBody, LinkCatalogResponse, QueryRawParams, QueryRawResponse, ReadRawBody, ReadRawParams, ReadRawResponse, EnableInvoiceSyncParams, EnableInvoiceSyncResponse, RetrieveInvoiceSyncParams, RetrieveInvoiceSyncResponse, EnableReceivedPaymentSyncParams, EnableReceivedPaymentSyncResponse, RetrieveReceivedPaymentSyncParams, RetrieveReceivedPaymentSyncResponse, ListSyncedInvoicesParams, ListSyncedInvoicesQueryParams, ListSyncedInvoicesResponse, ListObservedPaymentsParams, ListObservedPaymentsQueryParams, ListObservedPaymentsResponse, MatchObservedPaymentParams, MatchObservedPaymentBody, MatchObservedPaymentResponse, CreateReceivedPaymentBody, CreateReceivedPaymentResponse, CreateCreditMemoBody, CreateCreditMemoResponse, ApplyCreditMemoBody, ApplyCreditMemoParams, ApplyCreditMemoResponse, CreateBatchBody, CreateBatchResponse, RetrieveBatchParams, RetrieveBatchResponse, CreateWebhookEndpointBody, CreateWebhookEndpointResponse, ListWebhookDeliveriesParams, ListWebhookDeliveriesResponse, ReplayWebhookDeliveryParams, ReplayWebhookDeliveryResponse, CreateCompanyBody, CreateCompanyResponse, CreateConnectSessionBody, CreateConnectSessionResponse, RetrieveConnectSessionParams, RetrieveConnectSessionResponse, ListConnectionsResponse, RetrieveConnectionHealthParams, RetrieveConnectionHealthResponse, CheckConnectionHealthParams, CheckConnectionHealthResponse, RetrieveConnectionParams, RetrieveConnectionResponse, CreateInvoiceBody, CreateInvoiceResponse, ListInvoiceTracesQueryParams, ListInvoiceTracesResponse, RetrieveInvoiceRecoveryParams, RetrieveInvoiceRecoveryQueryParams, RetrieveInvoiceRecoveryResponse, RetrieveOperationParams, RetrieveOperationResponse, } from "./generated/validators.js";
|
|
6
|
+
export { SearchCatalogParams, SearchCatalogQueryParams, SearchCatalogResponse, LinkCatalogParams, LinkCatalogBody, LinkCatalogResponse, ListInventoryLevelsParams, ListInventoryLevelsQueryParams, ListInventoryLevelsResponse, QueryRawParams, QueryRawResponse, ReadRawBody, ReadRawParams, ReadRawResponse, AdmitRawWriteBody, AdmitRawWriteParams, AdmitRawWriteResponse, RetrieveRawWriteParams, RetrieveRawWriteResponse, RetrieveQuickBooksVendorParams, RetrieveQuickBooksVendorResponse, RetrieveQuickBooksInvoiceParams, RetrieveQuickBooksInvoiceResponse, GetQuickBooksTrialBalanceParams, GetQuickBooksTrialBalanceQueryParams, GetQuickBooksTrialBalanceResponse, EnableInvoiceSyncParams, EnableInvoiceSyncResponse, RetrieveInvoiceSyncParams, RetrieveInvoiceSyncResponse, EnableReceivedPaymentSyncParams, EnableReceivedPaymentSyncResponse, RetrieveReceivedPaymentSyncParams, RetrieveReceivedPaymentSyncResponse, ListSyncedInvoicesParams, ListSyncedInvoicesQueryParams, ListSyncedInvoicesResponse, ListObservedPaymentsParams, ListObservedPaymentsQueryParams, ListObservedPaymentsResponse, MatchObservedPaymentParams, MatchObservedPaymentBody, MatchObservedPaymentResponse, CreateReceivedPaymentBody, CreateReceivedPaymentResponse, CreateCreditMemoBody, CreateCreditMemoResponse, ApplyCreditMemoBody, ApplyCreditMemoParams, ApplyCreditMemoResponse, CreateBatchBody, CreateBatchResponse, RetrieveBatchParams, RetrieveBatchResponse, CreateWebhookEndpointBody, CreateWebhookEndpointResponse, ListWebhookDeliveriesParams, ListWebhookDeliveriesResponse, ReplayWebhookDeliveryParams, ReplayWebhookDeliveryResponse, CreateCompanyBody, CreateCompanyResponse, CreateConnectSessionBody, CreateConnectSessionResponse, RetrieveConnectSessionParams, RetrieveConnectSessionResponse, ListConnectionsResponse, RetrieveConnectionHealthParams, RetrieveConnectionHealthResponse, CheckConnectionHealthParams, CheckConnectionHealthResponse, RetrieveConnectionParams, RetrieveConnectionResponse, CreateInvoiceBody, CreateInvoiceResponse, RetrieveInvoiceParams, RetrieveInvoiceResponse, DiscoverInvoiceCustomFieldsParams, DiscoverInvoiceCustomFieldsResponse, ReadInvoiceCustomFieldsParams, ReadInvoiceCustomFieldsResponse, UpdateInvoiceCustomFieldsParams, UpdateInvoiceCustomFieldsBody, UpdateInvoiceCustomFieldsResponse, ListInvoiceTracesQueryParams, ListInvoiceTracesResponse, RetrieveInvoiceRecoveryParams, RetrieveInvoiceRecoveryQueryParams, RetrieveInvoiceRecoveryResponse, RetrieveOperationParams, RetrieveOperationResponse, } from "./generated/validators.js";
|
|
7
7
|
export { rawInvoiceLookupId } from "./raw-invoice-query.js";
|
|
8
8
|
export { httpError } from "./http-error.js";
|
package/package.json
CHANGED
|
@@ -1,80 +1,62 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"e2e:preflight": "node --env-file-if-exists=.env.pilot pilot/preflight.mts",
|
|
63
|
-
"pree2e:live": "bun run build",
|
|
64
|
-
"e2e:payables:fixture": "node --test test/payables-acceptance.test.mts test/quickbooks-payables.test.mts test/netsuite-payables-acceptance.test.mts test/netsuite-payables.test.mts",
|
|
65
|
-
"e2e:payables": "node --env-file-if-exists=.env.pilot pilot/payables.mts",
|
|
66
|
-
"e2e:live": "node --env-file-if-exists=.env.client pilot/acceptance.mts",
|
|
67
|
-
"e2e:mock": "bun run build && node --test test/pilot-transport.test.mts test/pilot-service.test.mts test/netsuite-pilot.test.mts test/quickbooks-pilot.test.mts test/pilot-acceptance.test.mts",
|
|
68
|
-
"preeditor:department": "bun run build",
|
|
69
|
-
"editor:department": "tsc -p examples/department-quickbooks --pretty false"
|
|
70
|
-
},
|
|
71
|
-
"dependencies": {
|
|
72
|
-
"zod": "4.6.7"
|
|
73
|
-
},
|
|
74
|
-
"devDependencies": {
|
|
75
|
-
"@rowbind/api-contract": "0.0.0",
|
|
76
|
-
"@types/node": "24.19.4",
|
|
77
|
-
"orval": "8.50.0",
|
|
78
|
-
"typescript": "5.9.3"
|
|
79
|
-
}
|
|
2
|
+
"name": "@rowbind/sdk",
|
|
3
|
+
"version": "0.1.0-canary.130",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Rowbind SDK for the local sandbox and the QuickBooks Desktop and NetSuite invoice pilot",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/betegon/rowbind.git"
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=24"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./wire": {
|
|
22
|
+
"types": "./dist/wire.d.ts",
|
|
23
|
+
"import": "./dist/wire.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": ["dist", "README.md", "examples/first-customer.mts", "examples/connection-health.mts", "examples/facturar.mts", "examples/catalog-invoice.mts", "examples/invoice.mts", "examples/quickstart.mts", "examples/native-quickstart.mts", "examples/native-query.mts", "examples/tsconfig.editor.json", "examples/mixed-providers", "examples/department-quickbooks", "examples/resume-invoice.mts", "examples/invoice-traces.mts", "examples/reimbursement-batch.mts", "examples/invoice-sync.mts", "examples/invoice-balances.mts", "examples/observed-payments.mts", "examples/invoice-settlement.mts", "examples/webhook-receiver.mts"],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -p tsconfig.build.json",
|
|
29
|
+
"prepack": "bun run build",
|
|
30
|
+
"prequickstart": "bun run build",
|
|
31
|
+
"quickstart": "node examples/quickstart.mts",
|
|
32
|
+
"preinvoice": "bun run build",
|
|
33
|
+
"invoice": "node --env-file-if-exists=.env.client examples/invoice.mts",
|
|
34
|
+
"prepilot": "bun run build",
|
|
35
|
+
"pilot": "node --env-file-if-exists=.env.pilot pilot/start.mts",
|
|
36
|
+
"preeditor:error": "bun run build",
|
|
37
|
+
"editor:error": "tsc -p examples/mixed-providers --pretty false",
|
|
38
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
39
|
+
"test": "node --test test/*.test.mts",
|
|
40
|
+
"test:bun-tarball": "node scripts/test-bun-tarball.mjs",
|
|
41
|
+
"generate:http": "node scripts/generate-http.mjs",
|
|
42
|
+
"check:generated": "node scripts/generate-http.mjs --check",
|
|
43
|
+
"pree2e:preflight": "bun run build",
|
|
44
|
+
"e2e:preflight": "node --env-file-if-exists=.env.pilot pilot/preflight.mts",
|
|
45
|
+
"pree2e:live": "bun run build",
|
|
46
|
+
"e2e:payables:fixture": "node --test test/payables-acceptance.test.mts test/quickbooks-payables.test.mts test/netsuite-payables-acceptance.test.mts test/netsuite-payables.test.mts",
|
|
47
|
+
"e2e:payables": "node --env-file-if-exists=.env.pilot pilot/payables.mts",
|
|
48
|
+
"e2e:live": "node --env-file-if-exists=.env.client pilot/acceptance.mts",
|
|
49
|
+
"e2e:mock": "bun run build && node --test test/pilot-transport.test.mts test/pilot-service.test.mts test/netsuite-pilot.test.mts test/quickbooks-pilot.test.mts test/pilot-acceptance.test.mts",
|
|
50
|
+
"preeditor:department": "bun run build",
|
|
51
|
+
"editor:department": "tsc -p examples/department-quickbooks --pretty false"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"zod": "4.6.7"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@rowbind/api-contract": "0.0.0",
|
|
58
|
+
"@types/node": "24.19.4",
|
|
59
|
+
"orval": "8.50.0",
|
|
60
|
+
"typescript": "5.9.3"
|
|
61
|
+
}
|
|
80
62
|
}
|