Skip to content

Commit 425616e

Browse files
committed
fix(quickbooks): address PR review (stable account ID, where sanitization, send body, query description)
1 parent aa81b4e commit 425616e

14 files changed

Lines changed: 81 additions & 21 deletions

File tree

apps/docs/content/docs/en/tools/quickbooks.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ List vendors from QuickBooks Online
615615

616616
### `quickbooks_query`
617617

618-
Run a QuickBooks Online query (SQL-like syntax, e.g.,
618+
Run a QuickBooks Online query using SQL-like syntax (example: SELECT * FROM Item WHERE Active = true)
619619

620620
#### Input
621621

apps/sim/app/(landing)/integrations/data/integrations.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10390,7 +10390,7 @@
1039010390
},
1039110391
{
1039210392
"name": "Run Query",
10393-
"description": "Run a QuickBooks Online query (SQL-like syntax, e.g., "
10393+
"description": "Run a QuickBooks Online query using SQL-like syntax (example: SELECT * FROM Item WHERE Active = true)"
1039410394
}
1039510395
],
1039610396
"operationCount": 22,

apps/sim/lib/auth/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,7 @@ export const auth = betterAuth({
18121812
return null
18131813
}
18141814
return {
1815-
id: `quickbooks-${realmId}-${generateId()}`,
1815+
id: `quickbooks-${realmId}`,
18161816
name: `QuickBooks Company ${realmId}`,
18171817
email: `quickbooks-${realmId}@quickbooks.local`,
18181818
emailVerified: true,

apps/sim/tools/quickbooks/list_accounts.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { createLogger } from '@sim/logger'
22
import type { QuickBooksAccountListResponse, QuickBooksListParams } from '@/tools/quickbooks/types'
33
import { ACCOUNT_OUTPUT } from '@/tools/quickbooks/types'
4-
import { buildCompanyUrl, quickbooksAuthHeaders } from '@/tools/quickbooks/utils'
4+
import {
5+
buildCompanyUrl,
6+
quickbooksAuthHeaders,
7+
sanitizeWhereClause,
8+
} from '@/tools/quickbooks/utils'
59
import type { ToolConfig } from '@/tools/types'
610

711
const logger = createLogger('QuickBooksListAccounts')
@@ -54,7 +58,8 @@ export const quickbooksListAccountsTool: ToolConfig<
5458
url: (params) => {
5559
const max = Math.min(Math.max(Number(params.maxResults) || 100, 1), 1000)
5660
const start = Math.max(Number(params.startPosition) || 1, 1)
57-
const whereClause = params.where ? ` WHERE ${params.where}` : ''
61+
const safeWhere = sanitizeWhereClause(params.where)
62+
const whereClause = safeWhere ? ` WHERE ${safeWhere}` : ''
5863
const sql = `SELECT * FROM Account${whereClause} STARTPOSITION ${start} MAXRESULTS ${max}`
5964
const url = buildCompanyUrl(params.realmId, '/query')
6065
return `${url}?query=${encodeURIComponent(sql)}&minorversion=73`

apps/sim/tools/quickbooks/list_bills.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { createLogger } from '@sim/logger'
22
import type { QuickBooksBillListResponse, QuickBooksListParams } from '@/tools/quickbooks/types'
33
import { BILL_OUTPUT } from '@/tools/quickbooks/types'
4-
import { buildCompanyUrl, quickbooksAuthHeaders } from '@/tools/quickbooks/utils'
4+
import {
5+
buildCompanyUrl,
6+
quickbooksAuthHeaders,
7+
sanitizeWhereClause,
8+
} from '@/tools/quickbooks/utils'
59
import type { ToolConfig } from '@/tools/types'
610

711
const logger = createLogger('QuickBooksListBills')
@@ -52,7 +56,8 @@ export const quickbooksListBillsTool: ToolConfig<QuickBooksListParams, QuickBook
5256
url: (params) => {
5357
const max = Math.min(Math.max(Number(params.maxResults) || 100, 1), 1000)
5458
const start = Math.max(Number(params.startPosition) || 1, 1)
55-
const whereClause = params.where ? ` WHERE ${params.where}` : ''
59+
const safeWhere = sanitizeWhereClause(params.where)
60+
const whereClause = safeWhere ? ` WHERE ${safeWhere}` : ''
5661
const sql = `SELECT * FROM Bill${whereClause} STARTPOSITION ${start} MAXRESULTS ${max}`
5762
const url = buildCompanyUrl(params.realmId, '/query')
5863
return `${url}?query=${encodeURIComponent(sql)}&minorversion=73`

apps/sim/tools/quickbooks/list_customers.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { createLogger } from '@sim/logger'
22
import type { QuickBooksCustomerListResponse, QuickBooksListParams } from '@/tools/quickbooks/types'
33
import { CUSTOMER_OUTPUT } from '@/tools/quickbooks/types'
4-
import { buildCompanyUrl, quickbooksAuthHeaders } from '@/tools/quickbooks/utils'
4+
import {
5+
buildCompanyUrl,
6+
quickbooksAuthHeaders,
7+
sanitizeWhereClause,
8+
} from '@/tools/quickbooks/utils'
59
import type { ToolConfig } from '@/tools/types'
610

711
const logger = createLogger('QuickBooksListCustomers')
@@ -54,7 +58,8 @@ export const quickbooksListCustomersTool: ToolConfig<
5458
url: (params) => {
5559
const max = Math.min(Math.max(Number(params.maxResults) || 100, 1), 1000)
5660
const start = Math.max(Number(params.startPosition) || 1, 1)
57-
const whereClause = params.where ? ` WHERE ${params.where}` : ''
61+
const safeWhere = sanitizeWhereClause(params.where)
62+
const whereClause = safeWhere ? ` WHERE ${safeWhere}` : ''
5863
const sql = `SELECT * FROM Customer${whereClause} STARTPOSITION ${start} MAXRESULTS ${max}`
5964
const url = buildCompanyUrl(params.realmId, '/query')
6065
return `${url}?query=${encodeURIComponent(sql)}&minorversion=73`

apps/sim/tools/quickbooks/list_estimates.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { createLogger } from '@sim/logger'
22
import type { QuickBooksEstimateListResponse, QuickBooksListParams } from '@/tools/quickbooks/types'
33
import { ESTIMATE_OUTPUT } from '@/tools/quickbooks/types'
4-
import { buildCompanyUrl, quickbooksAuthHeaders } from '@/tools/quickbooks/utils'
4+
import {
5+
buildCompanyUrl,
6+
quickbooksAuthHeaders,
7+
sanitizeWhereClause,
8+
} from '@/tools/quickbooks/utils'
59
import type { ToolConfig } from '@/tools/types'
610

711
const logger = createLogger('QuickBooksListEstimates')
@@ -54,7 +58,8 @@ export const quickbooksListEstimatesTool: ToolConfig<
5458
url: (params) => {
5559
const max = Math.min(Math.max(Number(params.maxResults) || 100, 1), 1000)
5660
const start = Math.max(Number(params.startPosition) || 1, 1)
57-
const whereClause = params.where ? ` WHERE ${params.where}` : ''
61+
const safeWhere = sanitizeWhereClause(params.where)
62+
const whereClause = safeWhere ? ` WHERE ${safeWhere}` : ''
5863
const sql = `SELECT * FROM Estimate${whereClause} STARTPOSITION ${start} MAXRESULTS ${max}`
5964
const url = buildCompanyUrl(params.realmId, '/query')
6065
return `${url}?query=${encodeURIComponent(sql)}&minorversion=73`

apps/sim/tools/quickbooks/list_invoices.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { createLogger } from '@sim/logger'
22
import type { QuickBooksInvoiceListResponse, QuickBooksListParams } from '@/tools/quickbooks/types'
33
import { INVOICE_OUTPUT } from '@/tools/quickbooks/types'
4-
import { buildCompanyUrl, quickbooksAuthHeaders } from '@/tools/quickbooks/utils'
4+
import {
5+
buildCompanyUrl,
6+
quickbooksAuthHeaders,
7+
sanitizeWhereClause,
8+
} from '@/tools/quickbooks/utils'
59
import type { ToolConfig } from '@/tools/types'
610

711
const logger = createLogger('QuickBooksListInvoices')
@@ -54,7 +58,8 @@ export const quickbooksListInvoicesTool: ToolConfig<
5458
url: (params) => {
5559
const max = Math.min(Math.max(Number(params.maxResults) || 100, 1), 1000)
5660
const start = Math.max(Number(params.startPosition) || 1, 1)
57-
const whereClause = params.where ? ` WHERE ${params.where}` : ''
61+
const safeWhere = sanitizeWhereClause(params.where)
62+
const whereClause = safeWhere ? ` WHERE ${safeWhere}` : ''
5863
const sql = `SELECT * FROM Invoice${whereClause} STARTPOSITION ${start} MAXRESULTS ${max}`
5964
const url = buildCompanyUrl(params.realmId, '/query')
6065
return `${url}?query=${encodeURIComponent(sql)}&minorversion=73`

apps/sim/tools/quickbooks/list_items.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { createLogger } from '@sim/logger'
22
import type { QuickBooksItemListResponse, QuickBooksListParams } from '@/tools/quickbooks/types'
33
import { ITEM_OUTPUT } from '@/tools/quickbooks/types'
4-
import { buildCompanyUrl, quickbooksAuthHeaders } from '@/tools/quickbooks/utils'
4+
import {
5+
buildCompanyUrl,
6+
quickbooksAuthHeaders,
7+
sanitizeWhereClause,
8+
} from '@/tools/quickbooks/utils'
59
import type { ToolConfig } from '@/tools/types'
610

711
const logger = createLogger('QuickBooksListItems')
@@ -52,7 +56,8 @@ export const quickbooksListItemsTool: ToolConfig<QuickBooksListParams, QuickBook
5256
url: (params) => {
5357
const max = Math.min(Math.max(Number(params.maxResults) || 100, 1), 1000)
5458
const start = Math.max(Number(params.startPosition) || 1, 1)
55-
const whereClause = params.where ? ` WHERE ${params.where}` : ''
59+
const safeWhere = sanitizeWhereClause(params.where)
60+
const whereClause = safeWhere ? ` WHERE ${safeWhere}` : ''
5661
const sql = `SELECT * FROM Item${whereClause} STARTPOSITION ${start} MAXRESULTS ${max}`
5762
const url = buildCompanyUrl(params.realmId, '/query')
5863
return `${url}?query=${encodeURIComponent(sql)}&minorversion=73`

apps/sim/tools/quickbooks/list_payments.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { createLogger } from '@sim/logger'
22
import type { QuickBooksListParams, QuickBooksPaymentListResponse } from '@/tools/quickbooks/types'
33
import { PAYMENT_OUTPUT } from '@/tools/quickbooks/types'
4-
import { buildCompanyUrl, quickbooksAuthHeaders } from '@/tools/quickbooks/utils'
4+
import {
5+
buildCompanyUrl,
6+
quickbooksAuthHeaders,
7+
sanitizeWhereClause,
8+
} from '@/tools/quickbooks/utils'
59
import type { ToolConfig } from '@/tools/types'
610

711
const logger = createLogger('QuickBooksListPayments')
@@ -54,7 +58,8 @@ export const quickbooksListPaymentsTool: ToolConfig<
5458
url: (params) => {
5559
const max = Math.min(Math.max(Number(params.maxResults) || 100, 1), 1000)
5660
const start = Math.max(Number(params.startPosition) || 1, 1)
57-
const whereClause = params.where ? ` WHERE ${params.where}` : ''
61+
const safeWhere = sanitizeWhereClause(params.where)
62+
const whereClause = safeWhere ? ` WHERE ${safeWhere}` : ''
5863
const sql = `SELECT * FROM Payment${whereClause} STARTPOSITION ${start} MAXRESULTS ${max}`
5964
const url = buildCompanyUrl(params.realmId, '/query')
6065
return `${url}?query=${encodeURIComponent(sql)}&minorversion=73`

0 commit comments

Comments
 (0)