Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
"cmd:rename-qb-accounts": "tsx src/cmd/renameQbAccount/index.ts"
},
"dependencies": {
"@assembly-js/node-sdk": "^3.19.1",
"@sentry/nextjs": "^9.13.0",
"@supabase/supabase-js": "^2.49.4",
"@trigger.dev/sdk": "4.3.0",
"bottleneck": "^2.19.5",
"copilot-design-system": "^2.0.10",
"copilot-node-sdk": "^3.11.1",
"dayjs": "^1.11.13",
"deep-equal": "^2.2.3",
"drizzle-orm": "^0.42.0",
Expand Down Expand Up @@ -88,4 +88,4 @@
"yarn prettier:fix"
]
}
}
}
2 changes: 2 additions & 0 deletions src/app/api/quickbooks/webhook/webhook.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { AuthService } from '@/app/api/quickbooks/auth/auth.service'
import { WebhookService } from '@/app/api/quickbooks/webhook/webhook.service'
import { NextRequest, NextResponse } from 'next/server'

export const maxDuration = 300 // 5 minutes

export async function captureWebhookEvent(req: NextRequest) {
console.info('\n\n####### Webhook triggered #######')
const user = await authenticate(req)
Expand Down
3 changes: 3 additions & 0 deletions src/app/api/quickbooks/webhook/webhook.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { ProductService } from '@/app/api/quickbooks/product/product.service'
import { SettingService } from '@/app/api/quickbooks/setting/setting.service'
import { SyncLogService } from '@/app/api/quickbooks/syncLog/syncLog.service'
import { AccountErrorCodes } from '@/constant/intuitErrorCode'

Check warning on line 11 in src/app/api/quickbooks/webhook/webhook.service.ts

View workflow job for this annotation

GitHub Actions / Run linters

'AccountErrorCodes' is defined but never used. Allowed unused vars must match /^_/u
import { QBSyncLog } from '@/db/schema/qbSyncLogs'
import {
InvoiceCreatedResponseSchema,
Expand All @@ -20,11 +20,12 @@
WebhookEventResponseSchema,
WebhookEventResponseType,
} from '@/type/dto/webhook.dto'
import { refreshTokenExpireMessage, validateAccessToken } from '@/utils/auth'

Check warning on line 23 in src/app/api/quickbooks/webhook/webhook.service.ts

View workflow job for this annotation

GitHub Actions / Run linters

'refreshTokenExpireMessage' is defined but never used. Allowed unused vars must match /^_/u
import { CopilotAPI } from '@/utils/copilotAPI'
import { ErrorMessageAndCode, getMessageAndCodeFromError } from '@/utils/error'
import { IntuitAPITokensType } from '@/utils/intuitAPI'
import CustomLogger from '@/utils/logger'
import { sleep } from '@/utils/sleep'
import {
getDeletedAtForAuthAccountCategoryLog,
getCategory,
Expand Down Expand Up @@ -377,6 +378,8 @@
payload: unknown,
qbTokenInfo: IntuitAPITokensType,
) {
await sleep(1000) // Payment succeed event can sometimes trigger before invoice created.

console.info('###### PAYMENT SUCCEEDED ######')
const parsedPaymentSucceed =
PaymentSucceededResponseSchema.safeParse(payload)
Expand Down
8 changes: 4 additions & 4 deletions src/utils/copilotAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import {
WorkspaceResponseSchema,
} from '@/type/common'
import Bottleneck from 'bottleneck'
import type { CopilotAPI as SDK } from 'copilot-node-sdk'
import { copilotApi } from 'copilot-node-sdk'
import type { AssemblyAPI as SDK } from '@assembly-js/node-sdk'
import { assemblyApi } from '@assembly-js/node-sdk'
import { z } from 'zod'
import { API_DOMAIN } from '@/constant/domains'
import httpStatus from 'http-status'
Expand All @@ -55,7 +55,7 @@ export class CopilotAPI {
copilot: SDK

constructor(private token: string) {
this.copilot = copilotApi({ apiKey, token })
this.copilot = assemblyApi({ apiKey, token })
}

private async manualFetch(
Expand Down Expand Up @@ -270,7 +270,7 @@ export class CopilotAPI {
async _getCustomFields(): Promise<CustomFieldResponse> {
console.info('CopilotAPI#getCustomFields | token =', this.token)
return CustomFieldResponseSchema.parse(
await this.copilot.listCustomFields(),
await this.copilot.listCustomFields({}),
)
}

Expand Down
2 changes: 2 additions & 0 deletions src/utils/sleep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const sleep = (ms: number) =>
new Promise((resolve) => setTimeout(resolve, ms))
22 changes: 11 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ __metadata:
languageName: node
linkType: hard

"@assembly-js/node-sdk@npm:^3.19.1":
version: 3.19.1
resolution: "@assembly-js/node-sdk@npm:3.19.1"
dependencies:
isomorphic-fetch: "npm:^3.0.0"
next: "npm:^14.0.2"
checksum: 10c0/8385b54c6426f7867db8c308c96f5e535aeab59ff1150fc96809d080a1004792920d0390e8a7d26775e5480a8a10f2b7f7db1d29c1e42267a9a03e12e8418785
languageName: node
linkType: hard

"@babel/code-frame@npm:^7.0.0, @babel/code-frame@npm:^7.27.1":
version: 7.27.1
resolution: "@babel/code-frame@npm:7.27.1"
Expand Down Expand Up @@ -5200,16 +5210,6 @@ __metadata:
languageName: node
linkType: hard

"copilot-node-sdk@npm:^3.11.1":
version: 3.11.1
resolution: "copilot-node-sdk@npm:3.11.1"
dependencies:
isomorphic-fetch: "npm:^3.0.0"
next: "npm:^14.0.2"
checksum: 10c0/f98ef7fa04ab4e49dacc0732a227e234a90a63d9d7a3e510a1c383ce4f6ca23e6a393f981e36ea68c0b2e6cb316a7c5fc97e47ce53a8bc20bbaa2afa383bf537
languageName: node
linkType: hard

"copy-anything@npm:^4":
version: 4.0.5
resolution: "copy-anything@npm:4.0.5"
Expand Down Expand Up @@ -5313,6 +5313,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "custom-app-base@workspace:."
dependencies:
"@assembly-js/node-sdk": "npm:^3.19.1"
"@eslint/eslintrc": "npm:^3.3.1"
"@eslint/js": "npm:^9.24.0"
"@ngrok/ngrok": "npm:^1.4.1"
Expand All @@ -5331,7 +5332,6 @@ __metadata:
autoprefixer: "npm:^10.4.0"
bottleneck: "npm:^2.19.5"
copilot-design-system: "npm:^2.0.10"
copilot-node-sdk: "npm:^3.11.1"
dayjs: "npm:^1.11.13"
deep-equal: "npm:^2.2.3"
dotenv: "npm:^16.4.5"
Expand Down
Loading