Skip to content

Commit eb5892f

Browse files
committed
fix(oauth): look up provider terminal codes in a Map
1 parent c527438 commit eb5892f

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎apps/sim/lib/oauth/__tests__/terminal-errors.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('isTerminalRefreshError', () => {
5858
expect(isTerminalRefreshError('unauthorized_client', providerId)).toBe(true)
5959
})
6060

61-
it.each([undefined, 'microsoft', 'salesforce', 'google-email'])(
61+
it.each([undefined, 'microsoft', 'salesforce', 'google-email', 'constructor', '__proto__'])(
6262
'does not treat unauthorized_client as terminal for %s',
6363
(providerId) => {
6464
expect(isTerminalRefreshError('unauthorized_client', providerId)).toBe(false)

‎apps/sim/lib/oauth/terminal-errors.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ const TERMINAL_ERRORS = new Set<string>([
2323
* registration, and treating it as terminal would send every credential of the provider to
2424
* reauthorization over one configuration fault.
2525
*/
26-
const PROVIDER_TERMINAL_ERRORS: Readonly<Record<string, ReadonlySet<string>>> = {
27-
confluence: new Set(['unauthorized_client']),
28-
jira: new Set(['unauthorized_client']),
29-
}
26+
const PROVIDER_TERMINAL_ERRORS: ReadonlyMap<string, ReadonlySet<string>> = new Map([
27+
['confluence', new Set(['unauthorized_client'])],
28+
['jira', new Set(['unauthorized_client'])],
29+
])
3030

3131
const DEAD_CACHE_TTL_SEC = 60 * 60
3232

@@ -40,7 +40,7 @@ export function isTerminalRefreshError(
4040
): boolean {
4141
if (!code) return false
4242
if (TERMINAL_ERRORS.has(code)) return true
43-
return providerId !== undefined && (PROVIDER_TERMINAL_ERRORS[providerId]?.has(code) ?? false)
43+
return providerId !== undefined && (PROVIDER_TERMINAL_ERRORS.get(providerId)?.has(code) ?? false)
4444
}
4545

4646
export async function markCredentialDead(accountId: string, code: string): Promise<void> {

0 commit comments

Comments
 (0)