google-spreadsheet
Advanced tools
Comparing version 3.0.14 to 3.1.15
@@ -23,2 +23,3 @@ const _ = require('lodash'); | ||
RAW_ACCESS_TOKEN: 'RAW_ACCESS_TOKEN', | ||
OAUTH: 'OAUTH', | ||
}; | ||
@@ -92,2 +93,7 @@ | ||
async useOAuth2Client(oAuth2Client) { | ||
this.authMode = AUTH_MODES.OAUTH; | ||
this.oAuth2Client = oAuth2Client; | ||
} | ||
// creds should be an object obtained by loading the json file google gives you | ||
@@ -138,2 +144,5 @@ // impersonateAs is an email of any user in the G Suite domain | ||
config.params.key = this.apiKey; | ||
} else if (this.authMode === AUTH_MODES.OAUTH) { | ||
const credentials = await this.oAuth2Client.getAccessToken(); | ||
config.headers.Authorization = `Bearer ${credentials.token}`; | ||
} else { | ||
@@ -140,0 +149,0 @@ throw new Error('You must initialize some kind of auth before making any requests'); |
@@ -5,3 +5,3 @@ { | ||
"description": "Google Sheets API (v4) -- simple interface to read/write data and manage sheets", | ||
"version": "3.0.14", | ||
"version": "3.1.15", | ||
"license": "Unlicense", | ||
@@ -30,3 +30,3 @@ "keywords": [ | ||
"dependencies": { | ||
"axios": "^0.19.2", | ||
"axios": "^0.21.1", | ||
"google-auth-library": "^6.1.3", | ||
@@ -52,3 +52,3 @@ "lodash": "^4.17.20" | ||
"docs:preview": "docsify serve docs", | ||
"readme:copy": "echo \"<!-- DO NOT EDIT THIS FILE, EDIT MAIN README.md AND RUN \\`npm readme:copy\\` instead -->\n\n\" | cat - README.md > docs/README.md" | ||
"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" | ||
}, | ||
@@ -55,0 +55,0 @@ "husky": { |
@@ -9,3 +9,3 @@ # google-spreadsheet | ||
- multiple auth options - API key, service account, oauth | ||
- multiple auth options - service account (w/ optional impersonation), OAuth 2.0, API key (read-only) | ||
- cell-based API - read, write, bulk-updates, formatting | ||
@@ -20,3 +20,3 @@ - row-based API - read, update, delete (based on the old v3 row-based calls) | ||
> | ||
> Google is [phasing out their old v3 api](https://cloud.google.com/blog/products/g-suite/migrate-your-apps-use-latest-sheets-api), which the older version of this module used to use. Originally they were going to shut it down on March 3rd 2020, but have pushed that date back to January 2021. | ||
> Google is [phasing out their old v3 api](https://cloud.google.com/blog/products/g-suite/migrate-your-apps-use-latest-sheets-api), which the older version of this module used. Originally they were going to shut it down on March 3rd 2020, but have pushed that date back to June 2021. | ||
@@ -33,3 +33,3 @@ | ||
!> NOTE - To keep the examples more concise, I'm calling await [at the top level](https://v8.dev/features/top-level-await) which is not allowed by default in most versions of node. If you need to call await in a script at the root level, you must instead wrap it in an async function like so: | ||
> **IMPORTANT NOTE** - To keep the examples concise, I'm calling await [at the top level](https://v8.dev/features/top-level-await) which is not allowed by default in most versions of node. If you need to call await in a script at the root level, you must instead wrap it in an async function like so: | ||
@@ -47,6 +47,6 @@ ```javascript | ||
// spreadsheet key is the long id in the sheets URL | ||
// Initialize the sheet - doc ID is the long id in the sheets URL | ||
const doc = new GoogleSpreadsheet('<the sheet ID from the url>'); | ||
// use service account creds | ||
// Initialize Auth - see more available options at https://theoephraim.github.io/node-google-spreadsheet/#/getting-started/authentication | ||
await doc.useServiceAccountAuth({ | ||
@@ -56,8 +56,2 @@ client_email: process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL, | ||
}); | ||
// OR load directly from json file if not in secure environment | ||
await doc.useServiceAccountAuth(require('./creds-from-google.json')); | ||
// OR use service account to impersonate a user (see https://developers.google.com/identity/protocols/oauth2/service-account#delegatingauthority) | ||
await doc.useServiceAccountAuth(require('./creds-from-google.json'), 'some-user@my-domain.com'); | ||
// OR use API key -- only for read-only access to public sheets | ||
doc.useApiKey('YOUR-API-KEY'); | ||
@@ -158,3 +152,3 @@ await doc.loadInfo(); // loads document properties and worksheets | ||
These docs are 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 | ||
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 | ||
The content lives in markdown files in the docs folder. | ||
@@ -161,0 +155,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71982
13
1412
152
+ Addedaxios@0.21.4(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
- Removedaxios@0.19.2(transitive)
- Removedfollow-redirects@1.5.10(transitive)
Updatedaxios@^0.21.1