DeepSeek V4 Pro · Heavy
oauth-credential-sync-and-app-integration-enhancements-cal-com
cal.com · TypeScript · M · 100–299 lines · 6 files
The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Opus 5.5.
- Gold bugs found
- 8 of 19
- Comments published
- 10
- Comments matching a bug
- 8
- Comments not matching
- 2
- Cost of this PR
- $1.480
Published comments (10)
Unconditional Salesforce token refresh on every calendar operation — This adds a network round-trip and database write to every calendar operation, even when the existing token remains valid. Check the token expiry before calling `getClient` unconditionally from the constructor.
Non-atomic credential check-then-act allows duplicate concurrent writes — Two concurrent webhook calls can both pass the `findFirst` check and create duplicate credentials, or one fails on a unique-constraint violation. Use `prisma.credential.upsert` keyed on a unique `(userId, appId)` constraint instead.
Return parsed JSON with data instead of raw fetch Response — Callers read `.data` or `.expiresIn` off the returned object, but a raw Fetch `Response` exposes neither, so token refresh throws or stores `NaN` expiry. Return `{ data: await response.json() }` to match the axios-shaped result. **Also found in:** - `packages/app-store/googlecalendar/lib/CalendarService.ts:94-96`
Google Calendar refresh stores Zod SafeParse wrapper as credential key — Storing the Zod wrapper means later schema parsing in `googleAuth` sees `{ success, data }` instead of the token fields and rejects the credential. Extract `.data` from `parseRefreshTokenResponse` before passing it to `prisma.credential.update`.
Refreshed Salesforce token not used by returned connection — The connection still uses the stale `credentialKey.access_token` and `credentialKey.instance_url`, so the refresh has no effect on the request in progress. Update those fields from `accessTokenParsed.data` before constructing the connection. **Also found in:** - `packages/app-store/salesforce/lib/CalendarService.ts:90-99`
Duplicate computed keys cause token schema to strip expiry fields — Both computed keys evaluate to `"[object Object]"`, so the second overwrites the first and no expiry field is ever retained; unknown-key stripping also drops `expires_in` and `expiry_date`. Replace them with `z.record(z.number())` or an explicit expiry field.
Zod schema uses fixed computed keys instead of record — The computed keys are fixed object properties, not a record, so the schema validates neither arbitrary numeric expiry fields nor extra unknown keys. Use `z.record(z.string(), z.number())` and explicit unknown-key handling to match the documented behavior.
Placeholder refresh_token overwrites real refresh token — When `refresh_token` is absent, this assigns the literal string `"refresh_token"`, which callers like office365calendar later spread back into credentials and persist. Preserve the original refresh token instead of substituting a placeholder. **Also found in:** - `packages/app-store/_utils/oauth/parseRefreshTokenResponse.ts:5-11`
Webhook secret comparison is not constant-time — Use `crypto.timingSafeEqual` on equal-length buffers, rejecting immediately when lengths differ.
refreshOAuthTokens gets credential ID where user ID is expected — The sync endpoint receives `credential.id` as `calcomUserId` instead of `credential.userId`, which the other callers send. Pass `credential.userId` to `refreshOAuthTokens`.