Skip to content

Commit cb7ce86

Browse files
aadamgoughAdam Gough
andauthored
fix(msverify): changed consent for microsoft (#1057)
* changed consent * changed excel error message and default sheets * changed variable res for excel --------- Co-authored-by: Adam Gough <[email protected]>
1 parent 5caef3a commit cb7ce86

File tree

4 files changed

+88
-55
lines changed

4 files changed

+88
-55
lines changed

apps/sim/lib/auth.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,6 @@ export const auth = betterAuth({
456456
responseType: 'code',
457457
accessType: 'offline',
458458
authentication: 'basic',
459-
prompt: 'consent',
460459
pkce: true,
461460
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/microsoft-teams`,
462461
},
@@ -472,7 +471,6 @@ export const auth = betterAuth({
472471
responseType: 'code',
473472
accessType: 'offline',
474473
authentication: 'basic',
475-
prompt: 'consent',
476474
pkce: true,
477475
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/microsoft-excel`,
478476
},
@@ -495,7 +493,6 @@ export const auth = betterAuth({
495493
responseType: 'code',
496494
accessType: 'offline',
497495
authentication: 'basic',
498-
prompt: 'consent',
499496
pkce: true,
500497
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/microsoft-planner`,
501498
},
@@ -520,7 +517,6 @@ export const auth = betterAuth({
520517
responseType: 'code',
521518
accessType: 'offline',
522519
authentication: 'basic',
523-
prompt: 'consent',
524520
pkce: true,
525521
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/outlook`,
526522
},
@@ -536,7 +532,6 @@ export const auth = betterAuth({
536532
responseType: 'code',
537533
accessType: 'offline',
538534
authentication: 'basic',
539-
prompt: 'consent',
540535
pkce: true,
541536
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/onedrive`,
542537
},
@@ -559,7 +554,6 @@ export const auth = betterAuth({
559554
responseType: 'code',
560555
accessType: 'offline',
561556
authentication: 'basic',
562-
prompt: 'consent',
563557
pkce: true,
564558
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/sharepoint`,
565559
},

apps/sim/tools/microsoft_excel/read.ts

Lines changed: 74 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ export const readTool: ToolConfig<MicrosoftExcelToolParams, MicrosoftExcelReadRe
4545
}
4646

4747
if (!params.range) {
48-
return `https://graph.microsoft.com/v1.0/me/drive/items/${spreadsheetId}/workbook/worksheets('Sheet1')/range(address='A1:Z1000')`
48+
// When no range is provided, first fetch the first worksheet name (to avoid hardcoding "Sheet1")
49+
// We'll read its default range after in transformResponse
50+
return `https://graph.microsoft.com/v1.0/me/drive/items/${spreadsheetId}/workbook/worksheets?$select=name&$orderby=position&$top=1`
4951
}
5052

5153
const rangeInput = params.range.trim()
@@ -72,7 +74,65 @@ export const readTool: ToolConfig<MicrosoftExcelToolParams, MicrosoftExcelReadRe
7274
},
7375
},
7476

75-
transformResponse: async (response: Response) => {
77+
transformResponse: async (response: Response, params?: MicrosoftExcelToolParams) => {
78+
const defaultAddress = 'A1:Z1000' // Match Google Sheets default logic
79+
80+
// If we came from the worksheets listing (no range provided), resolve first sheet name then fetch range
81+
if (response.url.includes('/workbook/worksheets?')) {
82+
const listData = await response.json()
83+
const firstSheetName: string | undefined = listData?.value?.[0]?.name
84+
85+
if (!firstSheetName) {
86+
throw new Error('No worksheets found in the Excel workbook')
87+
}
88+
89+
const spreadsheetIdFromUrl = response.url.split('/drive/items/')[1]?.split('/')[0] || ''
90+
const accessToken = params?.accessToken
91+
if (!accessToken) {
92+
throw new Error('Access token is required to read Excel range')
93+
}
94+
95+
const rangeUrl = `https://graph.microsoft.com/v1.0/me/drive/items/${encodeURIComponent(
96+
spreadsheetIdFromUrl
97+
)}/workbook/worksheets('${encodeURIComponent(firstSheetName)}')/range(address='${defaultAddress}')`
98+
99+
const rangeResp = await fetch(rangeUrl, {
100+
headers: { Authorization: `Bearer ${accessToken}` },
101+
})
102+
103+
if (!rangeResp.ok) {
104+
// Normalize Microsoft Graph sheet/range errors to a friendly message
105+
throw new Error(
106+
'Invalid range provided or worksheet not found. Provide a range like "Sheet1!A1:B2"'
107+
)
108+
}
109+
110+
const data = await rangeResp.json()
111+
112+
const metadata = {
113+
spreadsheetId: spreadsheetIdFromUrl,
114+
properties: {},
115+
spreadsheetUrl: `https://graph.microsoft.com/v1.0/me/drive/items/${spreadsheetIdFromUrl}`,
116+
}
117+
118+
const result: MicrosoftExcelReadResponse = {
119+
success: true,
120+
output: {
121+
data: {
122+
range: data.range || `${firstSheetName}!${defaultAddress}`,
123+
values: data.values || [],
124+
},
125+
metadata: {
126+
spreadsheetId: metadata.spreadsheetId,
127+
spreadsheetUrl: metadata.spreadsheetUrl,
128+
},
129+
},
130+
}
131+
132+
return result
133+
}
134+
135+
// Normal path: caller supplied a range; just return the parsed result
76136
const data = await response.json()
77137

78138
const urlParts = response.url.split('/drive/items/')
@@ -102,27 +162,20 @@ export const readTool: ToolConfig<MicrosoftExcelToolParams, MicrosoftExcelReadRe
102162
},
103163

104164
outputs: {
105-
success: { type: 'boolean', description: 'Operation success status' },
106-
output: {
165+
data: {
107166
type: 'object',
108-
description: 'Excel spreadsheet data and metadata',
167+
description: 'Range data from the spreadsheet',
109168
properties: {
110-
data: {
111-
type: 'object',
112-
description: 'Range data from the spreadsheet',
113-
properties: {
114-
range: { type: 'string', description: 'The range that was read' },
115-
values: { type: 'array', description: 'Array of rows containing cell values' },
116-
},
117-
},
118-
metadata: {
119-
type: 'object',
120-
description: 'Spreadsheet metadata',
121-
properties: {
122-
spreadsheetId: { type: 'string', description: 'The ID of the spreadsheet' },
123-
spreadsheetUrl: { type: 'string', description: 'URL to access the spreadsheet' },
124-
},
125-
},
169+
range: { type: 'string', description: 'The range that was read' },
170+
values: { type: 'array', description: 'Array of rows containing cell values' },
171+
},
172+
},
173+
metadata: {
174+
type: 'object',
175+
description: 'Spreadsheet metadata',
176+
properties: {
177+
spreadsheetId: { type: 'string', description: 'The ID of the spreadsheet' },
178+
spreadsheetUrl: { type: 'string', description: 'URL to access the spreadsheet' },
126179
},
127180
},
128181
},

apps/sim/tools/microsoft_excel/table_add.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,14 @@ export const tableAddTool: ToolConfig<
128128
},
129129

130130
outputs: {
131-
success: { type: 'boolean', description: 'Operation success status' },
132-
output: {
131+
index: { type: 'number', description: 'Index of the first row that was added' },
132+
values: { type: 'array', description: 'Array of rows that were added to the table' },
133+
metadata: {
133134
type: 'object',
134-
description: 'Table add operation results and metadata',
135+
description: 'Spreadsheet metadata',
135136
properties: {
136-
index: { type: 'number', description: 'Index of the first row that was added' },
137-
values: { type: 'array', description: 'Array of rows that were added to the table' },
138-
metadata: {
139-
type: 'object',
140-
description: 'Spreadsheet metadata',
141-
properties: {
142-
spreadsheetId: { type: 'string', description: 'The ID of the spreadsheet' },
143-
spreadsheetUrl: { type: 'string', description: 'URL to access the spreadsheet' },
144-
},
145-
},
137+
spreadsheetId: { type: 'string', description: 'The ID of the spreadsheet' },
138+
spreadsheetUrl: { type: 'string', description: 'URL to access the spreadsheet' },
146139
},
147140
},
148141
},

apps/sim/tools/microsoft_excel/write.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -161,23 +161,16 @@ export const writeTool: ToolConfig<MicrosoftExcelToolParams, MicrosoftExcelWrite
161161
},
162162

163163
outputs: {
164-
success: { type: 'boolean', description: 'Operation success status' },
165-
output: {
164+
updatedRange: { type: 'string', description: 'The range that was updated' },
165+
updatedRows: { type: 'number', description: 'Number of rows that were updated' },
166+
updatedColumns: { type: 'number', description: 'Number of columns that were updated' },
167+
updatedCells: { type: 'number', description: 'Number of cells that were updated' },
168+
metadata: {
166169
type: 'object',
167-
description: 'Write operation results and metadata',
170+
description: 'Spreadsheet metadata',
168171
properties: {
169-
updatedRange: { type: 'string', description: 'The range that was updated' },
170-
updatedRows: { type: 'number', description: 'Number of rows that were updated' },
171-
updatedColumns: { type: 'number', description: 'Number of columns that were updated' },
172-
updatedCells: { type: 'number', description: 'Number of cells that were updated' },
173-
metadata: {
174-
type: 'object',
175-
description: 'Spreadsheet metadata',
176-
properties: {
177-
spreadsheetId: { type: 'string', description: 'The ID of the spreadsheet' },
178-
spreadsheetUrl: { type: 'string', description: 'URL to access the spreadsheet' },
179-
},
180-
},
172+
spreadsheetId: { type: 'string', description: 'The ID of the spreadsheet' },
173+
spreadsheetUrl: { type: 'string', description: 'URL to access the spreadsheet' },
181174
},
182175
},
183176
},

0 commit comments

Comments
 (0)