Skip to content

Commit

Permalink
Fix a few crashes during QBO sync
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyxiao committed Oct 13, 2023
1 parent c4fbe91 commit 2be4e00
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
26 changes: 14 additions & 12 deletions integrations/integration-qbo/def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,13 @@ export const qboDef = {
}
for (const l of t.entity.Line) {
postings[l.Id] = {
accountExternalId: globalId(
t.realmId,
l.AccountBasedExpenseLineDetail.AccountRef.value,
),
// TODO: Handle non-accountBasedExpenseLineDetail
accountExternalId:
l.AccountBasedExpenseLineDetail &&
globalId(
t.realmId,
l.AccountBasedExpenseLineDetail.AccountRef.value,
),
amount: A(-1 * sign * l.Amount, t.entity.CurrencyRef.value),
memo: l.Description,
}
Expand Down Expand Up @@ -132,10 +135,10 @@ export const qboDef = {
}
for (const l of t.entity.Line) {
postings[l.Id] = {
accountExternalId: globalId(
t.realmId,
l.DepositLineDetail.AccountRef.value,
),
// Handle https://gist.github.com/tonyxiao/a9873b41c2df76f4f66c226933134a82
accountExternalId:
l.DepositLineDetail?.AccountRef &&
globalId(t.realmId, l.DepositLineDetail.AccountRef.value),
amount: A(-1 * l.Amount, t.entity.CurrencyRef.value),
memo: l.Description,
}
Expand Down Expand Up @@ -265,10 +268,9 @@ export const qboDef = {
// QBO uses a default accounts receivable account. but it does not appear possible to know
// exactly the id of the default account. therefore we wiill have to make do...
// https://c9.qbo.intuit.com/app/invoice?txnId=3968 for instance
accountExternalId: globalId(
t.realmId,
t.entity.DepositToAccountRef.value,
),
accountExternalId:
t.entity.DepositToAccountRef &&
globalId(t.realmId, t.entity.DepositToAccountRef.value),
},
remainder: {
accountType: 'asset/accounts_receivable',
Expand Down
12 changes: 6 additions & 6 deletions integrations/integration-qbo/qbo.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ declare namespace QBO {
Description: string
Amount: number
DetailType: string
AccountBasedExpenseLineDetail: AccountBasedExpenseLineDetail
AccountBasedExpenseLineDetail?: AccountBasedExpenseLineDetail
}

export interface AccountBasedExpenseLineDetail {
Expand All @@ -242,7 +242,7 @@ declare namespace QBO {
export interface Deposit extends _BaseEntity {
CurrencyRef: CurrencyRef
DepositToAccountRef: DepositToAccountRef
Line: Line[]
Line: DepositLine[]
PrivateNote: string
SyncToken: string
TotalAmt: number
Expand All @@ -256,17 +256,17 @@ declare namespace QBO {
value: string
}

export interface Line {
export interface DepositLine {
Amount: number
DepositLineDetail: DepositLineDetail
DepositLineDetail?: DepositLineDetail
Description: string
DetailType: string
Id: string
LineNum: number
}

export interface DepositLineDetail {
AccountRef: AccountRef
AccountRef?: AccountRef
Entity?: Entity
}

Expand Down Expand Up @@ -337,7 +337,7 @@ declare namespace QBO {
export interface Payment extends _BaseEntity {
CurrencyRef: CurrencyRef
CustomerRef: CustomerRef
DepositToAccountRef: {value: string}
DepositToAccountRef?: {value: string}
Line: PaymentLine[]
PrivateNote: string
ProcessPayment: boolean
Expand Down
2 changes: 1 addition & 1 deletion packages/cdk-core/oauth/NangoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export const zConnection = zConnectionShort.extend({
refresh_token: z.string().nullish(),
refresh_token_expires_in: z.number().nullish(),
token_type: z.string(), //'bearer',
scope: z.string(),
scope: z.string().optional(),
}),
}),
connection_config: z.record(z.unknown()),
Expand Down

0 comments on commit 2be4e00

Please sign in to comment.