@panoptic-it-solutions/quickbooks-client 0.1.2 → 0.1.4

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/dist/index.d.mts CHANGED
@@ -120,6 +120,10 @@ interface Customer extends BaseEntity {
120
120
  ShipAddr?: Address;
121
121
  Balance?: number;
122
122
  Active?: boolean;
123
+ PaymentMethodRef?: {
124
+ value: string;
125
+ name?: string;
126
+ };
123
127
  }
124
128
  interface Address {
125
129
  Id?: string;
@@ -257,6 +261,12 @@ declare class QuickBooksClient {
257
261
  * Execute a query using QuickBooks Query Language
258
262
  */
259
263
  query<T>(sql: string): Promise<T[]>;
264
+ /**
265
+ * Execute a query with automatic pagination to fetch all results
266
+ * @param sql - Base SQL query (without STARTPOSITION/MAXRESULTS)
267
+ * @param pageSize - Number of results per page (default 1000, max 1000)
268
+ */
269
+ queryAll<T>(sql: string, pageSize?: number): Promise<T[]>;
260
270
  getInvoice(id: string): Promise<Invoice>;
261
271
  getInvoices(where?: string): Promise<Invoice[]>;
262
272
  createInvoice(invoice: Partial<Invoice>): Promise<Invoice>;
package/dist/index.d.ts CHANGED
@@ -120,6 +120,10 @@ interface Customer extends BaseEntity {
120
120
  ShipAddr?: Address;
121
121
  Balance?: number;
122
122
  Active?: boolean;
123
+ PaymentMethodRef?: {
124
+ value: string;
125
+ name?: string;
126
+ };
123
127
  }
124
128
  interface Address {
125
129
  Id?: string;
@@ -257,6 +261,12 @@ declare class QuickBooksClient {
257
261
  * Execute a query using QuickBooks Query Language
258
262
  */
259
263
  query<T>(sql: string): Promise<T[]>;
264
+ /**
265
+ * Execute a query with automatic pagination to fetch all results
266
+ * @param sql - Base SQL query (without STARTPOSITION/MAXRESULTS)
267
+ * @param pageSize - Number of results per page (default 1000, max 1000)
268
+ */
269
+ queryAll<T>(sql: string, pageSize?: number): Promise<T[]>;
260
270
  getInvoice(id: string): Promise<Invoice>;
261
271
  getInvoices(where?: string): Promise<Invoice[]>;
262
272
  createInvoice(invoice: Partial<Invoice>): Promise<Invoice>;
package/dist/index.js CHANGED
@@ -409,6 +409,50 @@ var QuickBooksClient = class {
409
409
  const entityKey = keys[0];
410
410
  return entityKey ? data.QueryResponse[entityKey] : [];
411
411
  }
412
+ /**
413
+ * Execute a query with automatic pagination to fetch all results
414
+ * @param sql - Base SQL query (without STARTPOSITION/MAXRESULTS)
415
+ * @param pageSize - Number of results per page (default 1000, max 1000)
416
+ */
417
+ async queryAll(sql, pageSize = 1e3) {
418
+ const allResults = [];
419
+ let startPosition = 1;
420
+ const maxResults = Math.min(pageSize, 1e3);
421
+ while (true) {
422
+ const paginatedSql = `${sql} STARTPOSITION ${startPosition} MAXRESULTS ${maxResults}`;
423
+ const tokens = await this.getValidTokens();
424
+ const env = this.config.environment || "production";
425
+ const baseUrl = API_BASE[env];
426
+ const url = `${baseUrl}/v3/company/${tokens.realm_id}/query`;
427
+ await this.checkRateLimit();
428
+ const fetchResponse = await fetch(url, {
429
+ method: "POST",
430
+ headers: {
431
+ Authorization: `Bearer ${tokens.access_token}`,
432
+ Accept: "application/json",
433
+ "Content-Type": "application/text"
434
+ },
435
+ body: paginatedSql
436
+ });
437
+ if (!fetchResponse.ok) {
438
+ const errorData = await fetchResponse.json().catch(() => ({}));
439
+ throw handleQuickBooksError({ status: fetchResponse.status, ...errorData });
440
+ }
441
+ const data = await fetchResponse.json();
442
+ const keys = Object.keys(data.QueryResponse).filter(
443
+ (k) => !["startPosition", "maxResults", "totalCount"].includes(k)
444
+ );
445
+ const entityKey = keys[0];
446
+ const pageResults = entityKey ? data.QueryResponse[entityKey] : [];
447
+ allResults.push(...pageResults);
448
+ this.log("debug", `Fetched page at position ${startPosition}, got ${pageResults.length} results (total: ${allResults.length})`);
449
+ if (pageResults.length < maxResults) {
450
+ break;
451
+ }
452
+ startPosition += maxResults;
453
+ }
454
+ return allResults;
455
+ }
412
456
  // ============================================
413
457
  // Invoice Methods
414
458
  // ============================================
package/dist/index.mjs CHANGED
@@ -373,6 +373,50 @@ var QuickBooksClient = class {
373
373
  const entityKey = keys[0];
374
374
  return entityKey ? data.QueryResponse[entityKey] : [];
375
375
  }
376
+ /**
377
+ * Execute a query with automatic pagination to fetch all results
378
+ * @param sql - Base SQL query (without STARTPOSITION/MAXRESULTS)
379
+ * @param pageSize - Number of results per page (default 1000, max 1000)
380
+ */
381
+ async queryAll(sql, pageSize = 1e3) {
382
+ const allResults = [];
383
+ let startPosition = 1;
384
+ const maxResults = Math.min(pageSize, 1e3);
385
+ while (true) {
386
+ const paginatedSql = `${sql} STARTPOSITION ${startPosition} MAXRESULTS ${maxResults}`;
387
+ const tokens = await this.getValidTokens();
388
+ const env = this.config.environment || "production";
389
+ const baseUrl = API_BASE[env];
390
+ const url = `${baseUrl}/v3/company/${tokens.realm_id}/query`;
391
+ await this.checkRateLimit();
392
+ const fetchResponse = await fetch(url, {
393
+ method: "POST",
394
+ headers: {
395
+ Authorization: `Bearer ${tokens.access_token}`,
396
+ Accept: "application/json",
397
+ "Content-Type": "application/text"
398
+ },
399
+ body: paginatedSql
400
+ });
401
+ if (!fetchResponse.ok) {
402
+ const errorData = await fetchResponse.json().catch(() => ({}));
403
+ throw handleQuickBooksError({ status: fetchResponse.status, ...errorData });
404
+ }
405
+ const data = await fetchResponse.json();
406
+ const keys = Object.keys(data.QueryResponse).filter(
407
+ (k) => !["startPosition", "maxResults", "totalCount"].includes(k)
408
+ );
409
+ const entityKey = keys[0];
410
+ const pageResults = entityKey ? data.QueryResponse[entityKey] : [];
411
+ allResults.push(...pageResults);
412
+ this.log("debug", `Fetched page at position ${startPosition}, got ${pageResults.length} results (total: ${allResults.length})`);
413
+ if (pageResults.length < maxResults) {
414
+ break;
415
+ }
416
+ startPosition += maxResults;
417
+ }
418
+ return allResults;
419
+ }
376
420
  // ============================================
377
421
  // Invoice Methods
378
422
  // ============================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panoptic-it-solutions/quickbooks-client",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "QuickBooks Online API client with OAuth 2.0, rate limiting, and typed entities",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",