Skip to content

Commit 28e9cc7

Browse files
committed
fix(bigquery): add auth provider, fix docsLink and insertedRows count
1 parent a24b8a5 commit 28e9cc7

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

apps/sim/blocks/blocks/google_bigquery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const GoogleBigQueryBlock: BlockConfig = {
88
description: 'Query, list, and insert data in Google BigQuery',
99
longDescription:
1010
'Connect to Google BigQuery to run SQL queries, list datasets and tables, get table metadata, and insert rows.',
11-
docsLink: 'https://docs.sim.ai/tools/google-bigquery',
11+
docsLink: 'https://docs.sim.ai/tools/google_bigquery',
1212
category: 'tools',
1313
bgColor: '#E0E0E0',
1414
icon: GoogleBigQueryIcon,

apps/sim/lib/auth/auth.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ export const auth = betterAuth({
484484
'google-docs',
485485
'google-sheets',
486486
'google-forms',
487+
'google-bigquery',
487488
'google-vault',
488489
'google-groups',
489490
'vertex-ai',
@@ -1068,6 +1069,46 @@ export const auth = betterAuth({
10681069
}
10691070
},
10701071
},
1072+
{
1073+
providerId: 'google-bigquery',
1074+
clientId: env.GOOGLE_CLIENT_ID as string,
1075+
clientSecret: env.GOOGLE_CLIENT_SECRET as string,
1076+
discoveryUrl: 'https://accounts.google.com/.well-known/openid-configuration',
1077+
accessType: 'offline',
1078+
scopes: [
1079+
'https://www.googleapis.com/auth/userinfo.email',
1080+
'https://www.googleapis.com/auth/userinfo.profile',
1081+
'https://www.googleapis.com/auth/bigquery',
1082+
],
1083+
prompt: 'consent',
1084+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/google-bigquery`,
1085+
getUserInfo: async (tokens) => {
1086+
try {
1087+
const response = await fetch('https://openidconnect.googleapis.com/v1/userinfo', {
1088+
headers: { Authorization: `Bearer ${tokens.accessToken}` },
1089+
})
1090+
if (!response.ok) {
1091+
logger.error('Failed to fetch Google user info', { status: response.status })
1092+
throw new Error(`Failed to fetch Google user info: ${response.statusText}`)
1093+
}
1094+
const profile = await response.json()
1095+
const now = new Date()
1096+
return {
1097+
id: `${profile.sub}-${crypto.randomUUID()}`,
1098+
name: profile.name || 'Google User',
1099+
email: profile.email,
1100+
image: profile.picture || undefined,
1101+
emailVerified: profile.email_verified || false,
1102+
createdAt: now,
1103+
updatedAt: now,
1104+
}
1105+
} catch (error) {
1106+
logger.error('Error in Google getUserInfo', { error })
1107+
throw error
1108+
}
1109+
},
1110+
},
1111+
10711112
{
10721113
providerId: 'google-vault',
10731114
clientId: env.GOOGLE_CLIENT_ID as string,

apps/sim/tools/google_bigquery/insert_rows.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,22 @@ export const insertRowsTool: ToolConfig<
113113
const parsed = typeof params.rows === 'string' ? JSON.parse(params.rows) : params.rows
114114
totalRows = Array.isArray(parsed) ? parsed.length : 0
115115
}
116-
const failedIndexes = new Set(insertErrors.map((e: { index: number }) => e.index))
116+
117+
// When insertErrors is empty, all rows succeeded.
118+
// When insertErrors is present and skipInvalidRows is false (default),
119+
// the entire batch is rejected — no rows are inserted.
120+
let insertedRows = 0
121+
if (insertErrors.length === 0) {
122+
insertedRows = totalRows
123+
} else if (params?.skipInvalidRows) {
124+
const failedIndexes = new Set(insertErrors.map((e: { index: number }) => e.index))
125+
insertedRows = totalRows - failedIndexes.size
126+
}
117127

118128
return {
119129
success: true,
120130
output: {
121-
insertedRows: totalRows - failedIndexes.size,
131+
insertedRows,
122132
errors,
123133
},
124134
}

0 commit comments

Comments
 (0)