google-spreadsheet 5.1.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/index.cjs +27 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -7
- package/dist/index.d.ts +25 -7
- package/dist/index.js +27 -6
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/src/lib/GoogleSpreadsheet.ts +47 -11
- package/src/lib/GoogleSpreadsheetCell.ts +2 -4
- package/src/lib/GoogleSpreadsheetRow.ts +10 -1
- package/src/lib/GoogleSpreadsheetWorksheet.ts +5 -2
- package/src/lib/types/sheets-types.ts +2 -2
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
- managing worksheets - add, remove, resize, update properties (ex: title), duplicate to same or other document
|
|
23
23
|
- managing docs - create new doc, delete doc, basic sharing/permissions
|
|
24
24
|
- export - download sheet/docs in various formats
|
|
25
|
+
- automatic retries with exponential backoff for failed/rate-limited requests (powered by [ky](https://github.com/sindresorhus/ky), [customizable](https://theoephraim.github.io/node-google-spreadsheet/#/classes/google-spreadsheet#fn-newGoogleSpreadsheet))
|
|
25
26
|
|
|
26
27
|
**Docs site -**
|
|
27
28
|
Full docs available at [https://theoephraim.github.io/node-google-spreadsheet](https://theoephraim.github.io/node-google-spreadsheet)
|
|
@@ -197,6 +198,7 @@ Contributions are welcome, but please follow the existing conventions, use the l
|
|
|
197
198
|
|
|
198
199
|
The docs site is generated using [docsify](https://docsify.js.org). To preview and run locally so you can make edits, run `npm run docs:preview` and head to http://localhost:3000
|
|
199
200
|
The content lives in markdown files in the docs folder.
|
|
201
|
+
The package manager for this project is `bun`.
|
|
200
202
|
|
|
201
203
|
## License
|
|
202
204
|
|
package/dist/index.cjs
CHANGED
|
@@ -72,6 +72,12 @@ var GoogleSpreadsheetRow = class {
|
|
|
72
72
|
this._worksheet = _worksheet;
|
|
73
73
|
this._rowNumber = _rowNumber;
|
|
74
74
|
this._rawData = _rawData;
|
|
75
|
+
this._padRawData();
|
|
76
|
+
}
|
|
77
|
+
/** pad _rawData with empty strings so it always matches header length */
|
|
78
|
+
_padRawData() {
|
|
79
|
+
const headerLength = this._worksheet.headerValues.length;
|
|
80
|
+
while (this._rawData.length < headerLength) this._rawData.push("");
|
|
75
81
|
}
|
|
76
82
|
_deleted = false;
|
|
77
83
|
get deleted() {
|
|
@@ -143,7 +149,8 @@ var GoogleSpreadsheetRow = class {
|
|
|
143
149
|
majorDimension: "ROWS",
|
|
144
150
|
values: [this._rawData]
|
|
145
151
|
}
|
|
146
|
-
})).json()).updatedData.values[0];
|
|
152
|
+
})).json()).updatedData.values?.[0] || [];
|
|
153
|
+
this._padRawData();
|
|
147
154
|
}
|
|
148
155
|
/** delete this row */
|
|
149
156
|
async delete() {
|
|
@@ -320,8 +327,8 @@ var GoogleSpreadsheetCell = class {
|
|
|
320
327
|
return this.value;
|
|
321
328
|
}
|
|
322
329
|
set stringValue(val) {
|
|
323
|
-
|
|
324
|
-
this.value = val;
|
|
330
|
+
this._draftData.valueType = "stringValue";
|
|
331
|
+
this._draftData.value = val || "";
|
|
325
332
|
}
|
|
326
333
|
/**
|
|
327
334
|
* Hyperlink contained within the cell.
|
|
@@ -674,6 +681,7 @@ var GoogleSpreadsheetWorksheet = class {
|
|
|
674
681
|
return `${this.a1SheetName}!${filter}`;
|
|
675
682
|
}
|
|
676
683
|
if (es_toolkit_compat.isObject(filter)) {
|
|
684
|
+
if ("developerMetadataLookup" in filter) return filter;
|
|
677
685
|
const filterAny = filter;
|
|
678
686
|
if (filterAny.sheetId && filterAny.sheetId !== this.sheetId) throw new Error("Leave sheet ID blank or set to matching ID of this sheet");
|
|
679
687
|
return {
|
|
@@ -1600,7 +1608,8 @@ var GoogleSpreadsheet = class GoogleSpreadsheet {
|
|
|
1600
1608
|
* initialize new GoogleSpreadsheet
|
|
1601
1609
|
* @category Initialization
|
|
1602
1610
|
* */
|
|
1603
|
-
constructor(spreadsheetId, auth) {
|
|
1611
|
+
constructor(spreadsheetId, auth, options) {
|
|
1612
|
+
const { retryConfig } = options || {};
|
|
1604
1613
|
this.spreadsheetId = spreadsheetId;
|
|
1605
1614
|
this.auth = auth;
|
|
1606
1615
|
this._rawSheets = {};
|
|
@@ -1611,14 +1620,16 @@ var GoogleSpreadsheet = class GoogleSpreadsheet {
|
|
|
1611
1620
|
hooks: {
|
|
1612
1621
|
beforeRequest: [(r) => this._setAuthRequestHook(r)],
|
|
1613
1622
|
beforeError: [(e) => this._errorHook(e)]
|
|
1614
|
-
}
|
|
1623
|
+
},
|
|
1624
|
+
retry: retryConfig
|
|
1615
1625
|
});
|
|
1616
1626
|
this.driveApi = ky.default.create({
|
|
1617
1627
|
prefixUrl: `${DRIVE_API_BASE_URL}/${spreadsheetId}`,
|
|
1618
1628
|
hooks: {
|
|
1619
1629
|
beforeRequest: [(r) => this._setAuthRequestHook(r)],
|
|
1620
1630
|
beforeError: [(e) => this._errorHook(e)]
|
|
1621
|
-
}
|
|
1631
|
+
},
|
|
1632
|
+
retry: retryConfig
|
|
1622
1633
|
});
|
|
1623
1634
|
}
|
|
1624
1635
|
/** @internal */
|
|
@@ -1798,6 +1809,7 @@ var GoogleSpreadsheet = class GoogleSpreadsheet {
|
|
|
1798
1809
|
if (es_toolkit_compat.isString(filter)) return readOnlyMode ? filter : { a1Range: filter };
|
|
1799
1810
|
if (es_toolkit_compat.isObject(filter)) {
|
|
1800
1811
|
if (readOnlyMode) throw new Error("Only A1 ranges are supported when fetching cells with read-only access (using only an API key)");
|
|
1812
|
+
if ("developerMetadataLookup" in filter) return { developerMetadataLookup: filter.developerMetadataLookup };
|
|
1801
1813
|
return { gridRange: filter };
|
|
1802
1814
|
}
|
|
1803
1815
|
throw new Error("Each filter must be an A1 range string or a gridrange object");
|
|
@@ -1912,6 +1924,15 @@ var GoogleSpreadsheet = class GoogleSpreadsheet {
|
|
|
1912
1924
|
async deletePermission(permissionId) {
|
|
1913
1925
|
await this.driveApi.delete(`permissions/${permissionId}`);
|
|
1914
1926
|
}
|
|
1927
|
+
/**
|
|
1928
|
+
* search for developer metadata entries matching the given filters
|
|
1929
|
+
* @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.developerMetadata/search
|
|
1930
|
+
*/
|
|
1931
|
+
async searchDeveloperMetadata(filters) {
|
|
1932
|
+
const data = await (await this.sheetsApi.post("developerMetadata:search", { json: { dataFilters: filters } })).json();
|
|
1933
|
+
if (!data.matchedDeveloperMetadata) return [];
|
|
1934
|
+
return data.matchedDeveloperMetadata.map((m) => m.developerMetadata);
|
|
1935
|
+
}
|
|
1915
1936
|
static async createNewSpreadsheetDocument(auth, properties) {
|
|
1916
1937
|
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");
|
|
1917
1938
|
const authConfig = await getRequestAuthConfig(auth);
|