csv2gsheets
Advanced tools
Comparing version 1.0.0 to 1.0.1
import { OAuth2Client } from 'google-auth-library'; | ||
export declare const TOKEN_PATH: string; | ||
export interface CredentialsKey { | ||
client_id: string; | ||
project_id: string; | ||
auth_uri: string; | ||
token_uri: string; | ||
auth_provider_x509_cert_url: string; | ||
client_secret: string; | ||
redirect_uris: string[]; | ||
} | ||
export interface Credentials { | ||
installed?: CredentialsKey; | ||
web?: CredentialsKey; | ||
} | ||
/** | ||
@@ -24,3 +11,3 @@ * Check if the previously authorized token file exists. | ||
*/ | ||
export declare function loadSavedToken(): OAuth2Client | null; | ||
export declare function loadSavedToken(): Promise<OAuth2Client | null>; | ||
/** | ||
@@ -30,3 +17,3 @@ * Serialize credentials to a file compatible with GoogleAuth.fromJSON. | ||
*/ | ||
export declare function saveToken(client: OAuth2Client): void; | ||
export declare function saveToken(client: OAuth2Client): Promise<void>; | ||
/** | ||
@@ -33,0 +20,0 @@ * Load or request authorization to call Google APIs. |
@@ -32,8 +32,13 @@ // Handle authentication and authorization with Google Drive API | ||
*/ | ||
export function loadSavedToken() { | ||
if (isAuthorized()) { | ||
const token = fs.readFileSync(TOKEN_PATH, 'utf8'); | ||
return google.auth.fromJSON(JSON.parse(token)); | ||
export async function loadSavedToken() { | ||
try { | ||
if (isAuthorized()) { | ||
const token = await fs.promises.readFile(TOKEN_PATH, 'utf8'); | ||
return google.auth.fromJSON(JSON.parse(token)); | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
else { | ||
catch (err) { | ||
return null; | ||
@@ -46,4 +51,4 @@ } | ||
*/ | ||
export function saveToken(client) { | ||
const credentialsStr = fs.readFileSync(CREDENTIALS_PATH, 'utf8'); | ||
export async function saveToken(client) { | ||
const credentialsStr = await fs.promises.readFile(CREDENTIALS_PATH, 'utf8'); | ||
const parsedCredentials = JSON.parse(credentialsStr); | ||
@@ -62,3 +67,3 @@ if ('installed' in parsedCredentials || 'web' in parsedCredentials) { | ||
}); | ||
fs.writeFileSync(TOKEN_PATH, payload); | ||
await fs.promises.writeFile(TOKEN_PATH, payload); | ||
} | ||
@@ -74,3 +79,3 @@ else { | ||
export async function authorize() { | ||
let client = loadSavedToken(); | ||
let client = await loadSavedToken(); | ||
if (!client) { | ||
@@ -82,3 +87,3 @@ client = await authenticate({ | ||
if (client?.credentials) { | ||
saveToken(client); | ||
await saveToken(client); | ||
} | ||
@@ -85,0 +90,0 @@ return client; |
{ | ||
"name": "csv2gsheets", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "CLI tool to convert local CSV files into Google Sheets files in a designated Google Drive folder.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
# csv2gsheets: Create & update Google Sheets files using your local CSV | ||
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) [![Accessibility-alt-text-bot](https://github.com/ttsukagoshi/csv2gsheets/actions/workflows/a11y-alt-text-bot.yml/badge.svg)](https://github.com/ttsukagoshi/csv2gsheets/actions/workflows/a11y-alt-text-bot.yml) [![Lint Code Base](https://github.com/ttsukagoshi/csv2gsheets/actions/workflows/linter.yml/badge.svg)](https://github.com/ttsukagoshi/csv2gsheets/actions/workflows/linter.yml) | ||
[![npm version](https://img.shields.io/npm/v/csv2gsheets.svg?style=flat-square")](https://www.npmjs.com/package/csv2gsheets) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) [![Accessibility-alt-text-bot](https://github.com/ttsukagoshi/csv2gsheets/actions/workflows/a11y-alt-text-bot.yml/badge.svg)](https://github.com/ttsukagoshi/csv2gsheets/actions/workflows/a11y-alt-text-bot.yml) [![CodeQL](https://github.com/ttsukagoshi/csv2gsheets/actions/workflows/codeql.yml/badge.svg)](https://github.com/ttsukagoshi/csv2gsheets/actions/workflows/codeql.yml) [![Lint Code Base](https://github.com/ttsukagoshi/csv2gsheets/actions/workflows/linter.yml/badge.svg)](https://github.com/ttsukagoshi/csv2gsheets/actions/workflows/linter.yml) | ||
@@ -82,3 +82,3 @@ A Node.js CLI tool to convert local CSV files into Google Sheets files in a designated Google Drive folder. You can choose whether to update an existing Sheets file or create a new one. | ||
<img width="767" alt="Screenshot of the page to create a new Google Cloud project" src="https://github.com/ttsukagoshi/csv2gsheets/assets/55706659/d70594c9-8319-4145-b527-49bbf7d01e3e"> | ||
<img width="722" alt="Screenshot of the Create New Project page" src="https://github.com/ttsukagoshi/csv2gsheets/assets/55706659/f1542312-02d2-48b2-acd5-0e7662027392"> | ||
@@ -88,3 +88,3 @@ 2. Enable the Drive API | ||
<img width="943" alt="Screenshot of the Enable API page" src="https://github.com/ttsukagoshi/csv2gsheets/assets/55706659/10a2b973-9dc9-4e54-9631-8b21cc86c3b7"> | ||
<img width="791" alt="Screenshot of the Enable API page" src="https://github.com/ttsukagoshi/csv2gsheets/assets/55706659/393e67e3-e119-4db4-a5ca-dd056c358d9c"> | ||
@@ -94,3 +94,4 @@ 3. Create the OAuth consent screen | ||
<img width="943" alt="Screenshot of the OAuth consent screen where the user is asked to enter test accounts" src="https://github.com/ttsukagoshi/csv2gsheets/assets/55706659/186db13b-e8f2-46b3-be5b-0388468d3bba"> | ||
<img width="755" alt="Screenshot of the Create OAuth Consent Screen page" src="https://github.com/ttsukagoshi/csv2gsheets/assets/55706659/cf8db5f9-f51a-41d9-afd8-aaadc4898af5"> | ||
<img width="1166" alt="Screenshot of the OAuth consent screen where the user is asked to enter test accounts" src="https://github.com/ttsukagoshi/csv2gsheets/assets/55706659/55d57ef4-2434-46b5-821d-1dd786ad3fb4"> | ||
@@ -100,3 +101,4 @@ 4. Create credentials | ||
<img width="954" alt="Screenshot of the popup that the user will see when they have completed setting their OAuth client ID. The DOWNLOAD JSON button will be available." src="https://github.com/ttsukagoshi/csv2gsheets/assets/55706659/14cd38ec-2308-469a-816a-166333348e5a"> | ||
<img width="818" alt="Screenshot of the steps to create a new OAuth client ID." src="https://github.com/ttsukagoshi/csv2gsheets/assets/55706659/e30f77e6-2159-4f8d-b0dc-9416c8284678"> | ||
<img width="821" alt="Screenshot of the popup that the user will see when they have completed setting their OAuth client ID. The DOWNLOAD JSON button will be available." src="https://github.com/ttsukagoshi/csv2gsheets/assets/55706659/bf3da582-82ee-4e35-87a5-a4c956fea60e"> | ||
@@ -103,0 +105,0 @@ The credentials file saved in your home directory would be something like this: |
Sorry, the diff of this file is not supported yet
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
74722
214
925