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 <adamgough@Mac.attlocal.net>
This commit is contained in:
Adam Gough
2025-08-20 19:54:51 -07:00
committed by GitHub
parent 5caef3a37d
commit cb7ce8659b
4 changed files with 88 additions and 55 deletions

View File

@@ -456,7 +456,6 @@ export const auth = betterAuth({
responseType: 'code',
accessType: 'offline',
authentication: 'basic',
prompt: 'consent',
pkce: true,
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/microsoft-teams`,
},
@@ -472,7 +471,6 @@ export const auth = betterAuth({
responseType: 'code',
accessType: 'offline',
authentication: 'basic',
prompt: 'consent',
pkce: true,
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/microsoft-excel`,
},
@@ -495,7 +493,6 @@ export const auth = betterAuth({
responseType: 'code',
accessType: 'offline',
authentication: 'basic',
prompt: 'consent',
pkce: true,
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/microsoft-planner`,
},
@@ -520,7 +517,6 @@ export const auth = betterAuth({
responseType: 'code',
accessType: 'offline',
authentication: 'basic',
prompt: 'consent',
pkce: true,
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/outlook`,
},
@@ -536,7 +532,6 @@ export const auth = betterAuth({
responseType: 'code',
accessType: 'offline',
authentication: 'basic',
prompt: 'consent',
pkce: true,
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/onedrive`,
},
@@ -559,7 +554,6 @@ export const auth = betterAuth({
responseType: 'code',
accessType: 'offline',
authentication: 'basic',
prompt: 'consent',
pkce: true,
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/sharepoint`,
},

View File

@@ -45,7 +45,9 @@ export const readTool: ToolConfig<MicrosoftExcelToolParams, MicrosoftExcelReadRe
}
if (!params.range) {
return `https://graph.microsoft.com/v1.0/me/drive/items/${spreadsheetId}/workbook/worksheets('Sheet1')/range(address='A1:Z1000')`
// When no range is provided, first fetch the first worksheet name (to avoid hardcoding "Sheet1")
// We'll read its default range after in transformResponse
return `https://graph.microsoft.com/v1.0/me/drive/items/${spreadsheetId}/workbook/worksheets?$select=name&$orderby=position&$top=1`
}
const rangeInput = params.range.trim()
@@ -72,7 +74,65 @@ export const readTool: ToolConfig<MicrosoftExcelToolParams, MicrosoftExcelReadRe
},
},
transformResponse: async (response: Response) => {
transformResponse: async (response: Response, params?: MicrosoftExcelToolParams) => {
const defaultAddress = 'A1:Z1000' // Match Google Sheets default logic
// If we came from the worksheets listing (no range provided), resolve first sheet name then fetch range
if (response.url.includes('/workbook/worksheets?')) {
const listData = await response.json()
const firstSheetName: string | undefined = listData?.value?.[0]?.name
if (!firstSheetName) {
throw new Error('No worksheets found in the Excel workbook')
}
const spreadsheetIdFromUrl = response.url.split('/drive/items/')[1]?.split('/')[0] || ''
const accessToken = params?.accessToken
if (!accessToken) {
throw new Error('Access token is required to read Excel range')
}
const rangeUrl = `https://graph.microsoft.com/v1.0/me/drive/items/${encodeURIComponent(
spreadsheetIdFromUrl
)}/workbook/worksheets('${encodeURIComponent(firstSheetName)}')/range(address='${defaultAddress}')`
const rangeResp = await fetch(rangeUrl, {
headers: { Authorization: `Bearer ${accessToken}` },
})
if (!rangeResp.ok) {
// Normalize Microsoft Graph sheet/range errors to a friendly message
throw new Error(
'Invalid range provided or worksheet not found. Provide a range like "Sheet1!A1:B2"'
)
}
const data = await rangeResp.json()
const metadata = {
spreadsheetId: spreadsheetIdFromUrl,
properties: {},
spreadsheetUrl: `https://graph.microsoft.com/v1.0/me/drive/items/${spreadsheetIdFromUrl}`,
}
const result: MicrosoftExcelReadResponse = {
success: true,
output: {
data: {
range: data.range || `${firstSheetName}!${defaultAddress}`,
values: data.values || [],
},
metadata: {
spreadsheetId: metadata.spreadsheetId,
spreadsheetUrl: metadata.spreadsheetUrl,
},
},
}
return result
}
// Normal path: caller supplied a range; just return the parsed result
const data = await response.json()
const urlParts = response.url.split('/drive/items/')
@@ -102,27 +162,20 @@ export const readTool: ToolConfig<MicrosoftExcelToolParams, MicrosoftExcelReadRe
},
outputs: {
success: { type: 'boolean', description: 'Operation success status' },
output: {
data: {
type: 'object',
description: 'Excel spreadsheet data and metadata',
description: 'Range data from the spreadsheet',
properties: {
data: {
type: 'object',
description: 'Range data from the spreadsheet',
properties: {
range: { type: 'string', description: 'The range that was read' },
values: { type: 'array', description: 'Array of rows containing cell values' },
},
},
metadata: {
type: 'object',
description: 'Spreadsheet metadata',
properties: {
spreadsheetId: { type: 'string', description: 'The ID of the spreadsheet' },
spreadsheetUrl: { type: 'string', description: 'URL to access the spreadsheet' },
},
},
range: { type: 'string', description: 'The range that was read' },
values: { type: 'array', description: 'Array of rows containing cell values' },
},
},
metadata: {
type: 'object',
description: 'Spreadsheet metadata',
properties: {
spreadsheetId: { type: 'string', description: 'The ID of the spreadsheet' },
spreadsheetUrl: { type: 'string', description: 'URL to access the spreadsheet' },
},
},
},

View File

@@ -128,21 +128,14 @@ export const tableAddTool: ToolConfig<
},
outputs: {
success: { type: 'boolean', description: 'Operation success status' },
output: {
index: { type: 'number', description: 'Index of the first row that was added' },
values: { type: 'array', description: 'Array of rows that were added to the table' },
metadata: {
type: 'object',
description: 'Table add operation results and metadata',
description: 'Spreadsheet metadata',
properties: {
index: { type: 'number', description: 'Index of the first row that was added' },
values: { type: 'array', description: 'Array of rows that were added to the table' },
metadata: {
type: 'object',
description: 'Spreadsheet metadata',
properties: {
spreadsheetId: { type: 'string', description: 'The ID of the spreadsheet' },
spreadsheetUrl: { type: 'string', description: 'URL to access the spreadsheet' },
},
},
spreadsheetId: { type: 'string', description: 'The ID of the spreadsheet' },
spreadsheetUrl: { type: 'string', description: 'URL to access the spreadsheet' },
},
},
},

View File

@@ -161,23 +161,16 @@ export const writeTool: ToolConfig<MicrosoftExcelToolParams, MicrosoftExcelWrite
},
outputs: {
success: { type: 'boolean', description: 'Operation success status' },
output: {
updatedRange: { type: 'string', description: 'The range that was updated' },
updatedRows: { type: 'number', description: 'Number of rows that were updated' },
updatedColumns: { type: 'number', description: 'Number of columns that were updated' },
updatedCells: { type: 'number', description: 'Number of cells that were updated' },
metadata: {
type: 'object',
description: 'Write operation results and metadata',
description: 'Spreadsheet metadata',
properties: {
updatedRange: { type: 'string', description: 'The range that was updated' },
updatedRows: { type: 'number', description: 'Number of rows that were updated' },
updatedColumns: { type: 'number', description: 'Number of columns that were updated' },
updatedCells: { type: 'number', description: 'Number of cells that were updated' },
metadata: {
type: 'object',
description: 'Spreadsheet metadata',
properties: {
spreadsheetId: { type: 'string', description: 'The ID of the spreadsheet' },
spreadsheetUrl: { type: 'string', description: 'URL to access the spreadsheet' },
},
},
spreadsheetId: { type: 'string', description: 'The ID of the spreadsheet' },
spreadsheetUrl: { type: 'string', description: 'URL to access the spreadsheet' },
},
},
},