@panoptic-it-solutions/quickbooks-client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +194 -0
- package/dist/index.d.mts +366 -0
- package/dist/index.d.ts +366 -0
- package/dist/index.js +594 -0
- package/dist/index.mjs +557 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# @panoptic-it-solutions/quickbooks-client
|
|
2
|
+
|
|
3
|
+
QuickBooks Online API client with OAuth 2.0, rate limiting, and typed entities.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @panoptic-it-solutions/quickbooks-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { QuickBooksClient, generateAuthUrl, exchangeCodeForTokens, generateState } from '@panoptic-it-solutions/quickbooks-client';
|
|
15
|
+
import type { TokenStore, QuickBooksTokens } from '@panoptic-it-solutions/quickbooks-client';
|
|
16
|
+
|
|
17
|
+
// 1. Implement TokenStore for your storage backend
|
|
18
|
+
const tokenStore: TokenStore = {
|
|
19
|
+
async getTokens() {
|
|
20
|
+
// Return stored tokens or null
|
|
21
|
+
return db.getQuickBooksTokens();
|
|
22
|
+
},
|
|
23
|
+
async storeTokens(tokens) {
|
|
24
|
+
// Store tokens
|
|
25
|
+
await db.saveQuickBooksTokens(tokens);
|
|
26
|
+
},
|
|
27
|
+
async clearTokens() {
|
|
28
|
+
// Clear tokens
|
|
29
|
+
await db.deleteQuickBooksTokens();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// 2. Create the client
|
|
34
|
+
const client = new QuickBooksClient({
|
|
35
|
+
clientId: process.env.QB_CLIENT_ID,
|
|
36
|
+
clientSecret: process.env.QB_CLIENT_SECRET,
|
|
37
|
+
redirectUri: process.env.QB_REDIRECT_URI,
|
|
38
|
+
environment: 'production', // or 'sandbox'
|
|
39
|
+
tokenStore,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// 3. Use the client
|
|
43
|
+
const invoices = await client.getInvoices();
|
|
44
|
+
const customers = await client.getCustomers('Active = true');
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## OAuth Flow
|
|
48
|
+
|
|
49
|
+
### Generate Authorization URL
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { generateAuthUrl, generateState } from '@panoptic/quickbooks-client';
|
|
53
|
+
|
|
54
|
+
const state = generateState(); // Store this for CSRF validation
|
|
55
|
+
const authUrl = generateAuthUrl({
|
|
56
|
+
clientId: process.env.QB_CLIENT_ID,
|
|
57
|
+
clientSecret: process.env.QB_CLIENT_SECRET,
|
|
58
|
+
redirectUri: process.env.QB_REDIRECT_URI,
|
|
59
|
+
}, state);
|
|
60
|
+
|
|
61
|
+
// Redirect user to authUrl
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Handle OAuth Callback
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { exchangeCodeForTokens } from '@panoptic/quickbooks-client';
|
|
68
|
+
|
|
69
|
+
// In your callback handler:
|
|
70
|
+
const tokens = await exchangeCodeForTokens(
|
|
71
|
+
{
|
|
72
|
+
clientId: process.env.QB_CLIENT_ID,
|
|
73
|
+
clientSecret: process.env.QB_CLIENT_SECRET,
|
|
74
|
+
redirectUri: process.env.QB_REDIRECT_URI,
|
|
75
|
+
},
|
|
76
|
+
code, // from URL params
|
|
77
|
+
realmId // from URL params
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// Store tokens using your TokenStore
|
|
81
|
+
await tokenStore.storeTokens(tokens);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## API Methods
|
|
85
|
+
|
|
86
|
+
### Invoices
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
const invoices = await client.getInvoices();
|
|
90
|
+
const invoice = await client.getInvoice('123');
|
|
91
|
+
const newInvoice = await client.createInvoice({
|
|
92
|
+
CustomerRef: { value: '1' },
|
|
93
|
+
Line: [{ Amount: 100, DetailType: 'SalesItemLineDetail' }]
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Customers
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
const customers = await client.getCustomers();
|
|
101
|
+
const customer = await client.getCustomer('123');
|
|
102
|
+
const newCustomer = await client.createCustomer({
|
|
103
|
+
DisplayName: 'Acme Corp'
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Payments
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
const payments = await client.getPayments();
|
|
111
|
+
const payment = await client.createPayment({
|
|
112
|
+
CustomerRef: { value: '1' },
|
|
113
|
+
TotalAmt: 100
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Bills & Vendors
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
const bills = await client.getBills();
|
|
121
|
+
const vendors = await client.getVendors();
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Raw Query
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
const results = await client.query<Invoice>(
|
|
128
|
+
"SELECT * FROM Invoice WHERE Balance > '0'"
|
|
129
|
+
);
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Features
|
|
133
|
+
|
|
134
|
+
- **No external OAuth dependencies** - Pure fetch-based OAuth 2.0 implementation
|
|
135
|
+
- **Automatic token refresh** - Tokens are refreshed automatically when expired
|
|
136
|
+
- **Rate limiting** - Built-in 500 req/min rate limiter with exponential backoff
|
|
137
|
+
- **Typed entities** - Full TypeScript support for Invoice, Customer, Payment, etc.
|
|
138
|
+
- **Pluggable token storage** - Implement `TokenStore` interface for any backend
|
|
139
|
+
|
|
140
|
+
## TokenStore Interface
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
interface TokenStore {
|
|
144
|
+
getTokens(): Promise<QuickBooksTokens | null>;
|
|
145
|
+
storeTokens(tokens: QuickBooksTokens): Promise<void>;
|
|
146
|
+
clearTokens(): Promise<void>;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
interface QuickBooksTokens {
|
|
150
|
+
access_token: string;
|
|
151
|
+
refresh_token: string;
|
|
152
|
+
realm_id: string;
|
|
153
|
+
expires_at: number;
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Error Handling
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import { QuickBooksError, QB_ERROR_CODES } from '@panoptic-it-solutions/quickbooks-client';
|
|
161
|
+
|
|
162
|
+
try {
|
|
163
|
+
await client.getInvoices();
|
|
164
|
+
} catch (error) {
|
|
165
|
+
if (error instanceof QuickBooksError) {
|
|
166
|
+
switch (error.code) {
|
|
167
|
+
case QB_ERROR_CODES.TOKEN_EXPIRED:
|
|
168
|
+
// Handle expired token
|
|
169
|
+
break;
|
|
170
|
+
case QB_ERROR_CODES.RATE_LIMIT:
|
|
171
|
+
// Handle rate limiting
|
|
172
|
+
break;
|
|
173
|
+
case QB_ERROR_CODES.UNAUTHORIZED:
|
|
174
|
+
// Handle auth error
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Configuration
|
|
182
|
+
|
|
183
|
+
| Option | Required | Default | Description |
|
|
184
|
+
|--------|----------|---------|-------------|
|
|
185
|
+
| `clientId` | Yes | - | OAuth client ID from Intuit |
|
|
186
|
+
| `clientSecret` | Yes | - | OAuth client secret |
|
|
187
|
+
| `redirectUri` | Yes | - | OAuth callback URL |
|
|
188
|
+
| `environment` | No | `production` | `sandbox` or `production` |
|
|
189
|
+
| `tokenStore` | Yes | - | Token storage implementation |
|
|
190
|
+
| `onLog` | No | - | Logging callback |
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QuickBooks Client Types
|
|
3
|
+
*/
|
|
4
|
+
/** OAuth token data */
|
|
5
|
+
interface QuickBooksTokens {
|
|
6
|
+
access_token: string;
|
|
7
|
+
refresh_token: string;
|
|
8
|
+
realm_id: string;
|
|
9
|
+
expires_at: number;
|
|
10
|
+
token_type?: string;
|
|
11
|
+
}
|
|
12
|
+
/** Configuration for the QuickBooks client */
|
|
13
|
+
interface QuickBooksConfig {
|
|
14
|
+
clientId: string;
|
|
15
|
+
clientSecret: string;
|
|
16
|
+
redirectUri: string;
|
|
17
|
+
environment?: "sandbox" | "production";
|
|
18
|
+
scopes?: string[];
|
|
19
|
+
}
|
|
20
|
+
/** Options for initializing the client */
|
|
21
|
+
interface QuickBooksClientOptions extends QuickBooksConfig {
|
|
22
|
+
tokenStore: TokenStore;
|
|
23
|
+
/** Optional logging hook */
|
|
24
|
+
onLog?: (level: "debug" | "info" | "warn" | "error", message: string, data?: unknown) => void;
|
|
25
|
+
}
|
|
26
|
+
/** Token storage interface - implement this for your storage backend */
|
|
27
|
+
interface TokenStore {
|
|
28
|
+
/** Get stored tokens */
|
|
29
|
+
getTokens(): Promise<QuickBooksTokens | null>;
|
|
30
|
+
/** Store tokens */
|
|
31
|
+
storeTokens(tokens: QuickBooksTokens): Promise<void>;
|
|
32
|
+
/** Clear stored tokens */
|
|
33
|
+
clearTokens(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
/** OAuth token response from Intuit */
|
|
36
|
+
interface OAuthTokenResponse {
|
|
37
|
+
access_token: string;
|
|
38
|
+
refresh_token: string;
|
|
39
|
+
token_type: string;
|
|
40
|
+
expires_in: number;
|
|
41
|
+
x_refresh_token_expires_in: number;
|
|
42
|
+
}
|
|
43
|
+
/** QuickBooks API error response */
|
|
44
|
+
interface QuickBooksApiError {
|
|
45
|
+
Fault?: {
|
|
46
|
+
Error?: Array<{
|
|
47
|
+
Message?: string;
|
|
48
|
+
Detail?: string;
|
|
49
|
+
code?: string;
|
|
50
|
+
}>;
|
|
51
|
+
type?: string;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Query response wrapper */
|
|
55
|
+
interface QueryResponse<T> {
|
|
56
|
+
QueryResponse: Record<string, T[] | number | undefined> & {
|
|
57
|
+
startPosition?: number;
|
|
58
|
+
maxResults?: number;
|
|
59
|
+
totalCount?: number;
|
|
60
|
+
};
|
|
61
|
+
time?: string;
|
|
62
|
+
}
|
|
63
|
+
/** Base entity with common fields */
|
|
64
|
+
interface BaseEntity {
|
|
65
|
+
Id?: string;
|
|
66
|
+
SyncToken?: string;
|
|
67
|
+
MetaData?: {
|
|
68
|
+
CreateTime?: string;
|
|
69
|
+
LastUpdatedTime?: string;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** Invoice entity */
|
|
73
|
+
interface Invoice extends BaseEntity {
|
|
74
|
+
DocNumber?: string;
|
|
75
|
+
TxnDate?: string;
|
|
76
|
+
DueDate?: string;
|
|
77
|
+
TotalAmt?: number;
|
|
78
|
+
Balance?: number;
|
|
79
|
+
CustomerRef?: {
|
|
80
|
+
value: string;
|
|
81
|
+
name?: string;
|
|
82
|
+
};
|
|
83
|
+
Line?: InvoiceLine[];
|
|
84
|
+
BillEmail?: {
|
|
85
|
+
Address?: string;
|
|
86
|
+
};
|
|
87
|
+
CurrencyRef?: {
|
|
88
|
+
value: string;
|
|
89
|
+
name?: string;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
interface InvoiceLine {
|
|
93
|
+
Id?: string;
|
|
94
|
+
LineNum?: number;
|
|
95
|
+
Description?: string;
|
|
96
|
+
Amount?: number;
|
|
97
|
+
DetailType?: string;
|
|
98
|
+
SalesItemLineDetail?: {
|
|
99
|
+
ItemRef?: {
|
|
100
|
+
value: string;
|
|
101
|
+
name?: string;
|
|
102
|
+
};
|
|
103
|
+
Qty?: number;
|
|
104
|
+
UnitPrice?: number;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** Customer entity */
|
|
108
|
+
interface Customer extends BaseEntity {
|
|
109
|
+
DisplayName?: string;
|
|
110
|
+
CompanyName?: string;
|
|
111
|
+
GivenName?: string;
|
|
112
|
+
FamilyName?: string;
|
|
113
|
+
PrimaryEmailAddr?: {
|
|
114
|
+
Address?: string;
|
|
115
|
+
};
|
|
116
|
+
PrimaryPhone?: {
|
|
117
|
+
FreeFormNumber?: string;
|
|
118
|
+
};
|
|
119
|
+
BillAddr?: Address;
|
|
120
|
+
ShipAddr?: Address;
|
|
121
|
+
Balance?: number;
|
|
122
|
+
Active?: boolean;
|
|
123
|
+
}
|
|
124
|
+
interface Address {
|
|
125
|
+
Id?: string;
|
|
126
|
+
Line1?: string;
|
|
127
|
+
Line2?: string;
|
|
128
|
+
City?: string;
|
|
129
|
+
CountrySubDivisionCode?: string;
|
|
130
|
+
PostalCode?: string;
|
|
131
|
+
Country?: string;
|
|
132
|
+
}
|
|
133
|
+
/** Payment entity */
|
|
134
|
+
interface Payment extends BaseEntity {
|
|
135
|
+
TxnDate?: string;
|
|
136
|
+
TotalAmt?: number;
|
|
137
|
+
CustomerRef?: {
|
|
138
|
+
value: string;
|
|
139
|
+
name?: string;
|
|
140
|
+
};
|
|
141
|
+
DepositToAccountRef?: {
|
|
142
|
+
value: string;
|
|
143
|
+
name?: string;
|
|
144
|
+
};
|
|
145
|
+
PaymentMethodRef?: {
|
|
146
|
+
value: string;
|
|
147
|
+
name?: string;
|
|
148
|
+
};
|
|
149
|
+
Line?: PaymentLine[];
|
|
150
|
+
}
|
|
151
|
+
interface PaymentLine {
|
|
152
|
+
Amount?: number;
|
|
153
|
+
LinkedTxn?: Array<{
|
|
154
|
+
TxnId: string;
|
|
155
|
+
TxnType: string;
|
|
156
|
+
}>;
|
|
157
|
+
}
|
|
158
|
+
/** Account entity */
|
|
159
|
+
interface Account extends BaseEntity {
|
|
160
|
+
Name?: string;
|
|
161
|
+
AccountType?: string;
|
|
162
|
+
AccountSubType?: string;
|
|
163
|
+
CurrentBalance?: number;
|
|
164
|
+
Active?: boolean;
|
|
165
|
+
Classification?: string;
|
|
166
|
+
FullyQualifiedName?: string;
|
|
167
|
+
}
|
|
168
|
+
/** Vendor entity */
|
|
169
|
+
interface Vendor extends BaseEntity {
|
|
170
|
+
DisplayName?: string;
|
|
171
|
+
CompanyName?: string;
|
|
172
|
+
GivenName?: string;
|
|
173
|
+
FamilyName?: string;
|
|
174
|
+
PrimaryEmailAddr?: {
|
|
175
|
+
Address?: string;
|
|
176
|
+
};
|
|
177
|
+
PrimaryPhone?: {
|
|
178
|
+
FreeFormNumber?: string;
|
|
179
|
+
};
|
|
180
|
+
BillAddr?: Address;
|
|
181
|
+
Balance?: number;
|
|
182
|
+
Active?: boolean;
|
|
183
|
+
}
|
|
184
|
+
/** Bill entity */
|
|
185
|
+
interface Bill extends BaseEntity {
|
|
186
|
+
DocNumber?: string;
|
|
187
|
+
TxnDate?: string;
|
|
188
|
+
DueDate?: string;
|
|
189
|
+
TotalAmt?: number;
|
|
190
|
+
Balance?: number;
|
|
191
|
+
VendorRef?: {
|
|
192
|
+
value: string;
|
|
193
|
+
name?: string;
|
|
194
|
+
};
|
|
195
|
+
Line?: BillLine[];
|
|
196
|
+
}
|
|
197
|
+
interface BillLine {
|
|
198
|
+
Id?: string;
|
|
199
|
+
LineNum?: number;
|
|
200
|
+
Description?: string;
|
|
201
|
+
Amount?: number;
|
|
202
|
+
DetailType?: string;
|
|
203
|
+
AccountBasedExpenseLineDetail?: {
|
|
204
|
+
AccountRef?: {
|
|
205
|
+
value: string;
|
|
206
|
+
name?: string;
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/** Item entity */
|
|
211
|
+
interface Item extends BaseEntity {
|
|
212
|
+
Name?: string;
|
|
213
|
+
Description?: string;
|
|
214
|
+
Active?: boolean;
|
|
215
|
+
FullyQualifiedName?: string;
|
|
216
|
+
Type?: "Inventory" | "Service" | "NonInventory";
|
|
217
|
+
UnitPrice?: number;
|
|
218
|
+
PurchaseCost?: number;
|
|
219
|
+
QtyOnHand?: number;
|
|
220
|
+
IncomeAccountRef?: {
|
|
221
|
+
value: string;
|
|
222
|
+
name?: string;
|
|
223
|
+
};
|
|
224
|
+
ExpenseAccountRef?: {
|
|
225
|
+
value: string;
|
|
226
|
+
name?: string;
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* QuickBooks Online API Client
|
|
232
|
+
*
|
|
233
|
+
* Main client class with rate limiting, auto token refresh, and typed API methods
|
|
234
|
+
*/
|
|
235
|
+
|
|
236
|
+
declare class QuickBooksClient {
|
|
237
|
+
private config;
|
|
238
|
+
private tokenStore;
|
|
239
|
+
private requestTimestamps;
|
|
240
|
+
private onLog;
|
|
241
|
+
constructor(options: QuickBooksClientOptions);
|
|
242
|
+
private validateConfig;
|
|
243
|
+
private log;
|
|
244
|
+
/**
|
|
245
|
+
* Rate limiting - ensures we don't exceed 500 requests/minute
|
|
246
|
+
*/
|
|
247
|
+
private checkRateLimit;
|
|
248
|
+
/**
|
|
249
|
+
* Get current tokens, refreshing if necessary
|
|
250
|
+
*/
|
|
251
|
+
private getValidTokens;
|
|
252
|
+
/**
|
|
253
|
+
* Make an authenticated API request with retry logic
|
|
254
|
+
*/
|
|
255
|
+
private request;
|
|
256
|
+
/**
|
|
257
|
+
* Execute a query using QuickBooks Query Language
|
|
258
|
+
*/
|
|
259
|
+
query<T>(sql: string): Promise<T[]>;
|
|
260
|
+
getInvoice(id: string): Promise<Invoice>;
|
|
261
|
+
getInvoices(where?: string): Promise<Invoice[]>;
|
|
262
|
+
createInvoice(invoice: Partial<Invoice>): Promise<Invoice>;
|
|
263
|
+
updateInvoice(invoice: Invoice): Promise<Invoice>;
|
|
264
|
+
deleteInvoice(id: string, syncToken: string): Promise<void>;
|
|
265
|
+
getCustomer(id: string): Promise<Customer>;
|
|
266
|
+
getCustomers(where?: string): Promise<Customer[]>;
|
|
267
|
+
createCustomer(customer: Partial<Customer>): Promise<Customer>;
|
|
268
|
+
updateCustomer(customer: Customer): Promise<Customer>;
|
|
269
|
+
getPayment(id: string): Promise<Payment>;
|
|
270
|
+
getPayments(where?: string): Promise<Payment[]>;
|
|
271
|
+
createPayment(payment: Partial<Payment>): Promise<Payment>;
|
|
272
|
+
getAccount(id: string): Promise<Account>;
|
|
273
|
+
getAccounts(where?: string): Promise<Account[]>;
|
|
274
|
+
getVendor(id: string): Promise<Vendor>;
|
|
275
|
+
getVendors(where?: string): Promise<Vendor[]>;
|
|
276
|
+
createVendor(vendor: Partial<Vendor>): Promise<Vendor>;
|
|
277
|
+
updateVendor(vendor: Vendor): Promise<Vendor>;
|
|
278
|
+
getBill(id: string): Promise<Bill>;
|
|
279
|
+
getBills(where?: string): Promise<Bill[]>;
|
|
280
|
+
createBill(bill: Partial<Bill>): Promise<Bill>;
|
|
281
|
+
updateBill(bill: Bill): Promise<Bill>;
|
|
282
|
+
getItem(id: string): Promise<Item>;
|
|
283
|
+
getItems(where?: string): Promise<Item[]>;
|
|
284
|
+
createItem(item: Partial<Item>): Promise<Item>;
|
|
285
|
+
updateItem(item: Item): Promise<Item>;
|
|
286
|
+
/**
|
|
287
|
+
* Get company info
|
|
288
|
+
*/
|
|
289
|
+
getCompanyInfo(): Promise<unknown>;
|
|
290
|
+
/**
|
|
291
|
+
* Check if connected to QuickBooks
|
|
292
|
+
*/
|
|
293
|
+
isConnected(): Promise<boolean>;
|
|
294
|
+
/**
|
|
295
|
+
* Check connection status with details
|
|
296
|
+
*/
|
|
297
|
+
getConnectionStatus(): Promise<{
|
|
298
|
+
isConnected: boolean;
|
|
299
|
+
needsRefresh: boolean;
|
|
300
|
+
realmId?: string;
|
|
301
|
+
expiresAt?: number;
|
|
302
|
+
}>;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* OAuth 2.0 implementation for QuickBooks Online
|
|
307
|
+
*
|
|
308
|
+
* Replaces intuit-oauth with native fetch implementation
|
|
309
|
+
*/
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Generate the authorization URL for OAuth flow
|
|
313
|
+
*/
|
|
314
|
+
declare function generateAuthUrl(config: QuickBooksConfig, state: string): string;
|
|
315
|
+
/**
|
|
316
|
+
* Exchange authorization code for tokens
|
|
317
|
+
*/
|
|
318
|
+
declare function exchangeCodeForTokens(config: QuickBooksConfig, code: string, realmId: string): Promise<QuickBooksTokens>;
|
|
319
|
+
/**
|
|
320
|
+
* Refresh access token using refresh token
|
|
321
|
+
*/
|
|
322
|
+
declare function refreshTokens(config: QuickBooksConfig, refreshToken: string, realmId: string): Promise<QuickBooksTokens>;
|
|
323
|
+
/**
|
|
324
|
+
* Revoke tokens (disconnect from QuickBooks)
|
|
325
|
+
*/
|
|
326
|
+
declare function revokeTokens(config: QuickBooksConfig, token: string): Promise<void>;
|
|
327
|
+
/**
|
|
328
|
+
* Calculate token expiry timestamp from expires_in value
|
|
329
|
+
*/
|
|
330
|
+
declare function calculateTokenExpiry(expiresIn: number): number;
|
|
331
|
+
/**
|
|
332
|
+
* Check if token is expired or will expire soon (within 5 minutes)
|
|
333
|
+
*/
|
|
334
|
+
declare function isTokenExpired(expiresAt: number, bufferSeconds?: number): boolean;
|
|
335
|
+
/**
|
|
336
|
+
* Generate a random state parameter for CSRF protection
|
|
337
|
+
*/
|
|
338
|
+
declare function generateState(): string;
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* QuickBooks Error Handling
|
|
342
|
+
*/
|
|
343
|
+
/** Error codes for QuickBooks API errors */
|
|
344
|
+
declare const QB_ERROR_CODES: {
|
|
345
|
+
readonly TOKEN_EXPIRED: "QB_TOKEN_EXPIRED";
|
|
346
|
+
readonly REFRESH_FAILED: "QB_REFRESH_FAILED";
|
|
347
|
+
readonly UNAUTHORIZED: "QB_UNAUTHORIZED";
|
|
348
|
+
readonly INVALID_REALM: "QB_INVALID_REALM";
|
|
349
|
+
readonly API_ERROR: "QB_API_ERROR";
|
|
350
|
+
readonly RATE_LIMIT: "QB_RATE_LIMIT";
|
|
351
|
+
readonly NETWORK_ERROR: "QB_NETWORK_ERROR";
|
|
352
|
+
readonly INVALID_CONFIG: "QB_INVALID_CONFIG";
|
|
353
|
+
readonly TOKEN_STORE_ERROR: "QB_TOKEN_STORE_ERROR";
|
|
354
|
+
};
|
|
355
|
+
type QuickBooksErrorCode = (typeof QB_ERROR_CODES)[keyof typeof QB_ERROR_CODES];
|
|
356
|
+
/** Custom error class for QuickBooks-related errors */
|
|
357
|
+
declare class QuickBooksError extends Error {
|
|
358
|
+
code: QuickBooksErrorCode;
|
|
359
|
+
status?: number | undefined;
|
|
360
|
+
details?: unknown | undefined;
|
|
361
|
+
constructor(message: string, code: QuickBooksErrorCode, status?: number | undefined, details?: unknown | undefined);
|
|
362
|
+
}
|
|
363
|
+
/** Handle and normalize errors from QuickBooks API */
|
|
364
|
+
declare function handleQuickBooksError(error: unknown): QuickBooksError;
|
|
365
|
+
|
|
366
|
+
export { type Account, type Address, type BaseEntity, type Bill, type BillLine, type Customer, type Invoice, type InvoiceLine, type Item, type OAuthTokenResponse, type Payment, type PaymentLine, QB_ERROR_CODES, type QueryResponse, type QuickBooksApiError, QuickBooksClient, type QuickBooksClientOptions, type QuickBooksConfig, QuickBooksError, type QuickBooksErrorCode, type QuickBooksTokens, type TokenStore, type Vendor, calculateTokenExpiry, exchangeCodeForTokens, generateAuthUrl, generateState, handleQuickBooksError, isTokenExpired, refreshTokens, revokeTokens };
|