google-spreadsheet
Advanced tools
Comparing version 4.1.2 to 4.1.3
@@ -664,2 +664,3 @@ import * as axios from 'axios'; | ||
get rightToLeft(): WorksheetProperties['rightToLeft']; | ||
private get _headerRange(); | ||
set sheetId(newVal: WorksheetProperties['sheetId']); | ||
@@ -690,2 +691,3 @@ set title(newVal: WorksheetProperties['title']); | ||
loadHeaderRow(headerRowIndex?: number): Promise<void>; | ||
private _processHeaderRow; | ||
setHeaderRow(headerValues: string[], headerRowIndex?: number): Promise<void>; | ||
@@ -726,2 +728,3 @@ addRows(rows: RawRowData[], options?: AddRowOptions): Promise<GoogleSpreadsheetRow<Record<string, any>>[]>; | ||
getCellsInRange(a1Range: A1Range, options?: GetValuesRequestOptions): Promise<any>; | ||
batchGetCellsInRange(a1Ranges: A1Range[], options?: GetValuesRequestOptions): Promise<any>; | ||
updateNamedRange(): Promise<void>; | ||
@@ -728,0 +731,0 @@ addNamedRange(): Promise<void>; |
{ | ||
"name": "google-spreadsheet", | ||
"version": "4.1.2", | ||
"version": "4.1.3", | ||
"description": "Google Sheets API -- simple interface to read/write data and manage sheets", | ||
@@ -49,3 +49,3 @@ "keywords": [ | ||
"lint": "eslint ./ --ext .ts", | ||
"lint:fix": "npm run lint --fix", | ||
"lint:fix": "pnpm run lint --fix", | ||
"nodev": "node -v", | ||
@@ -64,3 +64,3 @@ "readme:copy": "echo \"<!-- DO NOT EDIT THIS FILE, EDIT MAIN README.md AND RUN \\`npm readme:copy\\` instead -->\n\n_Welcome to the docs site for_\n\" | cat - README.md > docs/README.md", | ||
"dependencies": { | ||
"axios": "^1.4.0", | ||
"axios": "^1.7.6", | ||
"lodash": "^4.17.21" | ||
@@ -87,3 +87,3 @@ }, | ||
"eslint-plugin-no-floating-promise": "^1.0.2", | ||
"google-auth-library": "^9.2.0", | ||
"google-auth-library": "^9.14.0", | ||
"jest": "^29.5.0", | ||
@@ -90,0 +90,0 @@ "jest-junit": "^16.0.0", |
@@ -36,4 +36,5 @@ import Axios, { | ||
if ('getRequestHeaders' in auth) return AUTH_MODES.GOOGLE_AUTH_CLIENT; | ||
if ('token' in auth) return AUTH_MODES.RAW_ACCESS_TOKEN; | ||
if ('apiKey' in auth) return AUTH_MODES.API_KEY; | ||
if ('token' in auth && auth.token) return AUTH_MODES.RAW_ACCESS_TOKEN; | ||
// google-auth-library now has an empty `apiKey` property | ||
if ('apiKey' in auth && auth.apiKey) return AUTH_MODES.API_KEY; | ||
throw new Error('Invalid auth'); | ||
@@ -52,3 +53,3 @@ } | ||
// (note this can only provide read-only access) | ||
if ('apiKey' in auth) { | ||
if ('apiKey' in auth && auth.apiKey) { | ||
return { params: { key: auth.apiKey } }; | ||
@@ -58,3 +59,3 @@ } | ||
// RAW ACCESS TOKEN | ||
if ('token' in auth) { | ||
if ('token' in auth && auth.token) { | ||
return { headers: { Authorization: `Bearer ${auth.token}` } }; | ||
@@ -612,3 +613,3 @@ } | ||
if ('apiKey' in auth) { | ||
if (getAuthMode(auth) === AUTH_MODES.API_KEY) { | ||
throw new Error('Cannot use api key only to create a new spreadsheet - it is only usable for read-only access of public docs'); | ||
@@ -615,0 +616,0 @@ } |
@@ -169,2 +169,5 @@ import { ReadableStream } from 'node:stream/web'; | ||
get rightToLeft() { return this._getProp('rightToLeft'); } | ||
private get _headerRange() { | ||
return `A${this._headerRowIndex}:${this.lastColumnLetter}${this._headerRowIndex}`; | ||
} | ||
@@ -346,3 +349,7 @@ set sheetId(newVal: WorksheetProperties['sheetId']) { this._setProp('sheetId', newVal); } | ||
if (headerRowIndex !== undefined) this._headerRowIndex = headerRowIndex; | ||
const rows = await this.getCellsInRange(`A${this._headerRowIndex}:${this.lastColumnLetter}${this._headerRowIndex}`); | ||
const rows = await this.getCellsInRange(this._headerRange); | ||
this._processHeaderRow(rows); | ||
} | ||
private _processHeaderRow(rows: any[]) { | ||
if (!rows) { | ||
@@ -494,11 +501,18 @@ throw new Error('No values in the header row - fill the first row with header values before trying to interact with rows'); | ||
await this._ensureHeaderRowLoaded(); | ||
const firstRow = 1 + this._headerRowIndex + offset; | ||
const lastRow = firstRow + limit - 1; // inclusive so we subtract 1 | ||
const lastColumn = columnToLetter(this.headerValues.length); | ||
const rawRows = await this.getCellsInRange( | ||
`A${firstRow}:${lastColumn}${lastRow}` | ||
); | ||
let rawRows; | ||
if (this._headerValues) { | ||
const lastColumn = columnToLetter(this.headerValues.length); | ||
rawRows = await this.getCellsInRange( | ||
`A${firstRow}:${lastColumn}${lastRow}` | ||
); | ||
} else { | ||
const result = await this.batchGetCellsInRange([this._headerRange, | ||
`A${firstRow}:${this.lastColumnLetter}${lastRow}`]); | ||
this._processHeaderRow(result[0]); | ||
rawRows = result[1]; | ||
} | ||
if (!rawRows) return []; | ||
@@ -606,2 +620,10 @@ | ||
async batchGetCellsInRange(a1Ranges: A1Range[], options?: GetValuesRequestOptions) { | ||
const ranges = a1Ranges.map((r) => `ranges=${this.encodedA1SheetName}!${r}`).join('&'); | ||
const response = await this._spreadsheet.sheetsApi.get(`/values:batchGet?${ranges}`, { | ||
params: options, | ||
}); | ||
return response.data.valueRanges.map((r: any) => r.values); | ||
} | ||
async updateNamedRange() { | ||
@@ -608,0 +630,0 @@ // Request type = `updateNamedRange` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
219590
3750
Updatedaxios@^1.7.6