@ariadng/sheets 0.3.4 → 0.4.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/dist/api/index.d.ts +30 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +260 -0
- package/dist/api/index.js.map +1 -1
- package/dist/auth/constants.js +1 -1
- package/dist/auth/constants.js.map +1 -1
- package/dist/auth/oauth.d.ts +22 -1
- package/dist/auth/oauth.d.ts.map +1 -1
- package/dist/auth/oauth.js +68 -2
- package/dist/auth/oauth.js.map +1 -1
- package/dist/cli.js +353 -0
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +67 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/package.json +2 -2
- package/README.md +0 -601
package/README.md
DELETED
|
@@ -1,601 +0,0 @@
|
|
|
1
|
-
# @ariadng/sheets
|
|
2
|
-
|
|
3
|
-
A command-line tool and library for reading Google Sheets. Works with personal Google accounts and service accounts.
|
|
4
|
-
|
|
5
|
-
## For AI Agents
|
|
6
|
-
|
|
7
|
-
If you are an AI agent (Claude, GPT, Copilot, or other AI assistants), use the npx version of this tool with the `-y` flag. This allows you to run commands without installing the package globally and without interactive prompts.
|
|
8
|
-
|
|
9
|
-
**Important**: Always use `npx -y` to skip the installation confirmation prompt that would otherwise block automated execution.
|
|
10
|
-
|
|
11
|
-
**Authentication**: Before reading spreadsheets, the user must be logged in. Check login status first, then prompt the user to login if needed.
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
# Check if user is logged in
|
|
15
|
-
npx -y @ariadng/sheets whoami
|
|
16
|
-
|
|
17
|
-
# If not logged in, ask user to run this command
|
|
18
|
-
npx -y @ariadng/sheets login
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
**Reading data**: Use `--format json` for structured output that is easier to parse.
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
# Get spreadsheet metadata
|
|
25
|
-
npx -y @ariadng/sheets get SPREADSHEET_ID --format json
|
|
26
|
-
|
|
27
|
-
# List all sheets
|
|
28
|
-
npx -y @ariadng/sheets list SPREADSHEET_ID --format json
|
|
29
|
-
|
|
30
|
-
# Read cell values
|
|
31
|
-
npx -y @ariadng/sheets read SPREADSHEET_ID "Sheet1!A1:D10" --format json
|
|
32
|
-
|
|
33
|
-
# Read formulas instead of values
|
|
34
|
-
npx -y @ariadng/sheets read SPREADSHEET_ID "Sheet1!A1:D10" --formula --format json
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
**Getting the spreadsheet ID**: Extract the ID from the Google Sheets URL. The URL format is `https://docs.google.com/spreadsheets/d/SPREADSHEET_ID/edit`. The spreadsheet ID is the string between `/d/` and `/edit`.
|
|
38
|
-
|
|
39
|
-
## What This Tool Does
|
|
40
|
-
|
|
41
|
-
- Read data from Google Sheets spreadsheets
|
|
42
|
-
- View spreadsheet information and sheet lists
|
|
43
|
-
- Read cell values or formulas
|
|
44
|
-
- Authenticate with your Google account or a service account
|
|
45
|
-
|
|
46
|
-
## Requirements
|
|
47
|
-
|
|
48
|
-
- Node.js version 18 or higher
|
|
49
|
-
- A Google account (for personal use) or a Google Cloud service account
|
|
50
|
-
|
|
51
|
-
## Installation
|
|
52
|
-
|
|
53
|
-
```bash
|
|
54
|
-
npm install -g @ariadng/sheets
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
After installation, the `sheets` command will be available in your terminal.
|
|
58
|
-
|
|
59
|
-
## Usage Summary
|
|
60
|
-
|
|
61
|
-
| Command | Description |
|
|
62
|
-
|---------|-------------|
|
|
63
|
-
| `sheets login` | Login with Google account |
|
|
64
|
-
| `sheets logout` | Remove saved login |
|
|
65
|
-
| `sheets whoami` | Show current login status |
|
|
66
|
-
| `sheets auth <file>` | Test service account credentials |
|
|
67
|
-
| `sheets get <id>` | Get spreadsheet metadata |
|
|
68
|
-
| `sheets list <id>` | List sheets in spreadsheet |
|
|
69
|
-
| `sheets read <id> <range>` | Read cell values |
|
|
70
|
-
| `sheets read <id> <range> --formula` | Read formulas |
|
|
71
|
-
| `sheets read <id> <range> --format json` | Output as JSON |
|
|
72
|
-
| `sheets install-claude-skill` | Install Claude Code skill |
|
|
73
|
-
|
|
74
|
-
## Using with npx
|
|
75
|
-
|
|
76
|
-
You can also run this tool without installing it:
|
|
77
|
-
|
|
78
|
-
```bash
|
|
79
|
-
npx @ariadng/sheets login
|
|
80
|
-
npx @ariadng/sheets read SPREADSHEET_ID "Sheet1!A1:D10"
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
**Note**: The first time you run npx, it will ask for confirmation to install the package. Use the `-y` flag to skip this prompt:
|
|
84
|
-
|
|
85
|
-
```bash
|
|
86
|
-
npx -y @ariadng/sheets login
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
## Claude Code Integration
|
|
90
|
-
|
|
91
|
-
This tool includes a Claude Skill that teaches Claude Code how to use the sheets CLI. To install the skill:
|
|
92
|
-
|
|
93
|
-
```bash
|
|
94
|
-
sheets install-claude-skill
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
Or with npx:
|
|
98
|
-
|
|
99
|
-
```bash
|
|
100
|
-
npx @ariadng/sheets install-claude-skill
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
After installation, you can use `/sheets` in Claude Code to read Google Sheets data. The skill is installed to `~/.claude/skills/sheets/SKILL.md`.
|
|
104
|
-
|
|
105
|
-
## Getting Started
|
|
106
|
-
|
|
107
|
-
### Step 1: Login to Your Google Account
|
|
108
|
-
|
|
109
|
-
Run this command to connect your Google account:
|
|
110
|
-
|
|
111
|
-
```bash
|
|
112
|
-
sheets login
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
This will:
|
|
116
|
-
1. Open your web browser
|
|
117
|
-
2. Ask you to sign in to your Google account
|
|
118
|
-
3. Ask you to allow the app to read your spreadsheets
|
|
119
|
-
4. Save your login for future use
|
|
120
|
-
|
|
121
|
-
After login, you will see your email address displayed.
|
|
122
|
-
|
|
123
|
-
### Step 2: Read a Spreadsheet
|
|
124
|
-
|
|
125
|
-
Find the spreadsheet ID from your Google Sheets URL. The URL looks like this:
|
|
126
|
-
|
|
127
|
-
```
|
|
128
|
-
https://docs.google.com/spreadsheets/d/SPREADSHEET_ID/edit
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
The spreadsheet ID is the long string of letters and numbers between `/d/` and `/edit`.
|
|
132
|
-
|
|
133
|
-
Now you can read data:
|
|
134
|
-
|
|
135
|
-
```bash
|
|
136
|
-
# Get spreadsheet information
|
|
137
|
-
sheets get SPREADSHEET_ID
|
|
138
|
-
|
|
139
|
-
# List all sheets in the spreadsheet
|
|
140
|
-
sheets list SPREADSHEET_ID
|
|
141
|
-
|
|
142
|
-
# Read cells from a range
|
|
143
|
-
sheets read SPREADSHEET_ID "Sheet1!A1:D10"
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
## Authentication
|
|
147
|
-
|
|
148
|
-
This tool supports three ways to authenticate:
|
|
149
|
-
|
|
150
|
-
### 1. Personal Google Account (Recommended for Most Users)
|
|
151
|
-
|
|
152
|
-
Use the `login` command to authenticate with your personal Google account:
|
|
153
|
-
|
|
154
|
-
```bash
|
|
155
|
-
sheets login
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
Your login will be saved and used automatically for future commands. To check your login status:
|
|
159
|
-
|
|
160
|
-
```bash
|
|
161
|
-
sheets whoami
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
To remove your saved login:
|
|
165
|
-
|
|
166
|
-
```bash
|
|
167
|
-
sheets logout
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
### 2. Service Account (For Automated Systems)
|
|
171
|
-
|
|
172
|
-
Service accounts are special Google accounts for applications and scripts. To use a service account:
|
|
173
|
-
|
|
174
|
-
1. Create a service account in Google Cloud Console
|
|
175
|
-
2. Download the JSON credentials file
|
|
176
|
-
3. Share your spreadsheet with the service account email address
|
|
177
|
-
4. Use the `--credentials` option with commands:
|
|
178
|
-
|
|
179
|
-
```bash
|
|
180
|
-
sheets get SPREADSHEET_ID --credentials path/to/credentials.json
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
To test if your service account credentials are valid:
|
|
184
|
-
|
|
185
|
-
```bash
|
|
186
|
-
sheets auth path/to/credentials.json
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
### 3. Access Token (For Advanced Use)
|
|
190
|
-
|
|
191
|
-
If you have an OAuth access token, you can use it directly:
|
|
192
|
-
|
|
193
|
-
```bash
|
|
194
|
-
sheets get SPREADSHEET_ID --token YOUR_ACCESS_TOKEN
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
## CLI Commands Reference
|
|
198
|
-
|
|
199
|
-
### Authentication Commands
|
|
200
|
-
|
|
201
|
-
#### sheets login
|
|
202
|
-
|
|
203
|
-
Connect your Google account.
|
|
204
|
-
|
|
205
|
-
```bash
|
|
206
|
-
sheets login
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
Options:
|
|
210
|
-
- `--client <file>`: Use custom OAuth client credentials (optional)
|
|
211
|
-
|
|
212
|
-
What happens:
|
|
213
|
-
1. Opens your browser to Google sign-in page
|
|
214
|
-
2. Starts a local server on port 8085 to receive the response
|
|
215
|
-
3. Saves your tokens to `~/.sheets/tokens.json`
|
|
216
|
-
|
|
217
|
-
#### sheets logout
|
|
218
|
-
|
|
219
|
-
Remove your saved login.
|
|
220
|
-
|
|
221
|
-
```bash
|
|
222
|
-
sheets logout
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
This deletes the stored tokens from your computer.
|
|
226
|
-
|
|
227
|
-
#### sheets whoami
|
|
228
|
-
|
|
229
|
-
Show your current login status.
|
|
230
|
-
|
|
231
|
-
```bash
|
|
232
|
-
sheets whoami
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
Output includes:
|
|
236
|
-
- Your email address
|
|
237
|
-
- Token expiration time
|
|
238
|
-
- Whether the token is still valid
|
|
239
|
-
|
|
240
|
-
Exit code: 0 if logged in, 1 if not logged in.
|
|
241
|
-
|
|
242
|
-
#### sheets auth
|
|
243
|
-
|
|
244
|
-
Test service account credentials.
|
|
245
|
-
|
|
246
|
-
```bash
|
|
247
|
-
sheets auth path/to/credentials.json
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
This validates the credentials file format and shows:
|
|
251
|
-
- Project ID
|
|
252
|
-
- Service account email
|
|
253
|
-
|
|
254
|
-
### Spreadsheet Commands
|
|
255
|
-
|
|
256
|
-
#### sheets get
|
|
257
|
-
|
|
258
|
-
Get spreadsheet information.
|
|
259
|
-
|
|
260
|
-
```bash
|
|
261
|
-
sheets get SPREADSHEET_ID
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
Options:
|
|
265
|
-
- `--credentials <file>`: Use service account credentials
|
|
266
|
-
- `--token <token>`: Use OAuth access token
|
|
267
|
-
- `--format <format>`: Output format, either `table` (default) or `json`
|
|
268
|
-
|
|
269
|
-
Output includes:
|
|
270
|
-
- Spreadsheet title
|
|
271
|
-
- Spreadsheet ID
|
|
272
|
-
- Locale and timezone
|
|
273
|
-
- Number of sheets
|
|
274
|
-
- Spreadsheet URL
|
|
275
|
-
|
|
276
|
-
#### sheets list
|
|
277
|
-
|
|
278
|
-
List all sheets in a spreadsheet.
|
|
279
|
-
|
|
280
|
-
```bash
|
|
281
|
-
sheets list SPREADSHEET_ID
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
Options:
|
|
285
|
-
- `--credentials <file>`: Use service account credentials
|
|
286
|
-
- `--token <token>`: Use OAuth access token
|
|
287
|
-
- `--format <format>`: Output format, either `table` (default) or `json`
|
|
288
|
-
|
|
289
|
-
Output includes:
|
|
290
|
-
- Sheet index
|
|
291
|
-
- Sheet title
|
|
292
|
-
- Grid size (rows and columns)
|
|
293
|
-
- Hidden status
|
|
294
|
-
|
|
295
|
-
#### sheets read
|
|
296
|
-
|
|
297
|
-
Read cell values from a spreadsheet range.
|
|
298
|
-
|
|
299
|
-
```bash
|
|
300
|
-
sheets read SPREADSHEET_ID "Sheet1!A1:D10"
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
Options:
|
|
304
|
-
- `--credentials <file>`: Use service account credentials
|
|
305
|
-
- `--token <token>`: Use OAuth access token
|
|
306
|
-
- `--format <format>`: Output format, either `table` (default) or `json`
|
|
307
|
-
- `--formula`: Show formulas instead of calculated values
|
|
308
|
-
|
|
309
|
-
Examples:
|
|
310
|
-
|
|
311
|
-
```bash
|
|
312
|
-
# Read a range of cells
|
|
313
|
-
sheets read SPREADSHEET_ID "Sheet1!A1:D10"
|
|
314
|
-
|
|
315
|
-
# Read an entire column
|
|
316
|
-
sheets read SPREADSHEET_ID "Sheet1!A:A"
|
|
317
|
-
|
|
318
|
-
# Read with formulas visible
|
|
319
|
-
sheets read SPREADSHEET_ID "Sheet1!A1:D10" --formula
|
|
320
|
-
|
|
321
|
-
# Output as JSON
|
|
322
|
-
sheets read SPREADSHEET_ID "Sheet1!A1:D10" --format json
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
Range format:
|
|
326
|
-
- `Sheet1!A1:D10`: Cells A1 through D10 on Sheet1
|
|
327
|
-
- `Sheet1!A:A`: Entire column A on Sheet1
|
|
328
|
-
- `Sheet1!1:1`: Entire row 1 on Sheet1
|
|
329
|
-
- `A1:D10`: Cells A1 through D10 on the first sheet
|
|
330
|
-
|
|
331
|
-
#### sheets install-claude-skill
|
|
332
|
-
|
|
333
|
-
Install the Claude Code skill for this tool.
|
|
334
|
-
|
|
335
|
-
```bash
|
|
336
|
-
sheets install-claude-skill
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
This installs a skill file to `~/.claude/skills/sheets/SKILL.md` that teaches Claude Code how to use the sheets CLI. After installation, you can use `/sheets` in Claude Code.
|
|
340
|
-
|
|
341
|
-
### Global Options
|
|
342
|
-
|
|
343
|
-
These options work with all spreadsheet commands:
|
|
344
|
-
|
|
345
|
-
| Option | Description |
|
|
346
|
-
|--------|-------------|
|
|
347
|
-
| `--credentials <file>` | Path to service account JSON file |
|
|
348
|
-
| `--token <token>` | OAuth access token string |
|
|
349
|
-
| `--format <format>` | Output format: `table` or `json` |
|
|
350
|
-
| `--version` | Show version number |
|
|
351
|
-
| `--help` | Show help message |
|
|
352
|
-
|
|
353
|
-
## Library Usage
|
|
354
|
-
|
|
355
|
-
You can also use this package as a library in your Node.js applications.
|
|
356
|
-
|
|
357
|
-
### Installation
|
|
358
|
-
|
|
359
|
-
```bash
|
|
360
|
-
npm install @ariadng/sheets
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
### Basic Example
|
|
364
|
-
|
|
365
|
-
```typescript
|
|
366
|
-
import { createClient } from '@ariadng/sheets';
|
|
367
|
-
|
|
368
|
-
// Create a client with user authentication (after running "sheets login")
|
|
369
|
-
const client = createClient({
|
|
370
|
-
auth: { type: 'user' }
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
// Get spreadsheet information
|
|
374
|
-
const spreadsheet = await client.getSpreadsheet('SPREADSHEET_ID');
|
|
375
|
-
console.log(spreadsheet.properties.title);
|
|
376
|
-
|
|
377
|
-
// Read cell values
|
|
378
|
-
const values = await client.getValues('SPREADSHEET_ID', 'Sheet1!A1:D10');
|
|
379
|
-
console.log(values.values);
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
### Service Account Example
|
|
383
|
-
|
|
384
|
-
```typescript
|
|
385
|
-
import { createClient } from '@ariadng/sheets';
|
|
386
|
-
|
|
387
|
-
const client = createClient({
|
|
388
|
-
auth: {
|
|
389
|
-
type: 'service-account',
|
|
390
|
-
credentialsPath: './credentials.json'
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
const values = await client.getValues('SPREADSHEET_ID', 'Sheet1!A1:D10');
|
|
395
|
-
```
|
|
396
|
-
|
|
397
|
-
### OAuth Token Example
|
|
398
|
-
|
|
399
|
-
```typescript
|
|
400
|
-
import { createClient } from '@ariadng/sheets';
|
|
401
|
-
|
|
402
|
-
const client = createClient({
|
|
403
|
-
auth: {
|
|
404
|
-
type: 'oauth',
|
|
405
|
-
accessToken: 'YOUR_ACCESS_TOKEN'
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
const values = await client.getValues('SPREADSHEET_ID', 'Sheet1!A1:D10');
|
|
410
|
-
```
|
|
411
|
-
|
|
412
|
-
### Available Methods
|
|
413
|
-
|
|
414
|
-
#### getSpreadsheet(spreadsheetId)
|
|
415
|
-
|
|
416
|
-
Get spreadsheet metadata.
|
|
417
|
-
|
|
418
|
-
```typescript
|
|
419
|
-
const spreadsheet = await client.getSpreadsheet('SPREADSHEET_ID');
|
|
420
|
-
// Returns: { spreadsheetId, properties, sheets, spreadsheetUrl }
|
|
421
|
-
```
|
|
422
|
-
|
|
423
|
-
#### getSheets(spreadsheetId)
|
|
424
|
-
|
|
425
|
-
Get list of sheets in a spreadsheet.
|
|
426
|
-
|
|
427
|
-
```typescript
|
|
428
|
-
const sheets = await client.getSheets('SPREADSHEET_ID');
|
|
429
|
-
// Returns: [{ sheetId, title, index, gridProperties, hidden }]
|
|
430
|
-
```
|
|
431
|
-
|
|
432
|
-
#### getValues(spreadsheetId, range, options?)
|
|
433
|
-
|
|
434
|
-
Read cell values from a range.
|
|
435
|
-
|
|
436
|
-
```typescript
|
|
437
|
-
const values = await client.getValues('SPREADSHEET_ID', 'Sheet1!A1:D10');
|
|
438
|
-
// Returns: { range, majorDimension, values }
|
|
439
|
-
|
|
440
|
-
// With options
|
|
441
|
-
const values = await client.getValues('SPREADSHEET_ID', 'Sheet1!A1:D10', {
|
|
442
|
-
valueRenderOption: 'UNFORMATTED_VALUE',
|
|
443
|
-
dateTimeRenderOption: 'SERIAL_NUMBER'
|
|
444
|
-
});
|
|
445
|
-
```
|
|
446
|
-
|
|
447
|
-
Options:
|
|
448
|
-
- `valueRenderOption`: How values should be rendered
|
|
449
|
-
- `FORMATTED_VALUE` (default): Values as displayed in the UI
|
|
450
|
-
- `UNFORMATTED_VALUE`: Raw values without formatting
|
|
451
|
-
- `FORMULA`: Formulas instead of calculated values
|
|
452
|
-
- `dateTimeRenderOption`: How dates should be rendered
|
|
453
|
-
- `FORMATTED_STRING` (default): Date as formatted string
|
|
454
|
-
- `SERIAL_NUMBER`: Date as serial number
|
|
455
|
-
- `majorDimension`: How data is organized
|
|
456
|
-
- `ROWS` (default): Data organized by rows
|
|
457
|
-
- `COLUMNS`: Data organized by columns
|
|
458
|
-
|
|
459
|
-
#### getFormulas(spreadsheetId, range)
|
|
460
|
-
|
|
461
|
-
Read formulas from a range. This is a shortcut for `getValues` with `valueRenderOption: 'FORMULA'`.
|
|
462
|
-
|
|
463
|
-
```typescript
|
|
464
|
-
const formulas = await client.getFormulas('SPREADSHEET_ID', 'Sheet1!A1:D10');
|
|
465
|
-
```
|
|
466
|
-
|
|
467
|
-
#### batchGetValues(spreadsheetId, ranges, options?)
|
|
468
|
-
|
|
469
|
-
Read multiple ranges in a single request.
|
|
470
|
-
|
|
471
|
-
```typescript
|
|
472
|
-
const result = await client.batchGetValues('SPREADSHEET_ID', [
|
|
473
|
-
'Sheet1!A1:D10',
|
|
474
|
-
'Sheet2!A1:B5'
|
|
475
|
-
]);
|
|
476
|
-
// Returns: { spreadsheetId, valueRanges: [...] }
|
|
477
|
-
```
|
|
478
|
-
|
|
479
|
-
### Authentication Functions
|
|
480
|
-
|
|
481
|
-
```typescript
|
|
482
|
-
import { login, loadStoredTokens, deleteTokens } from '@ariadng/sheets';
|
|
483
|
-
|
|
484
|
-
// Perform OAuth login flow
|
|
485
|
-
const tokens = await login();
|
|
486
|
-
console.log(tokens.email);
|
|
487
|
-
|
|
488
|
-
// Load stored tokens
|
|
489
|
-
const stored = await loadStoredTokens();
|
|
490
|
-
if (stored) {
|
|
491
|
-
console.log('Logged in as:', stored.email);
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
// Delete stored tokens
|
|
495
|
-
await deleteTokens();
|
|
496
|
-
```
|
|
497
|
-
|
|
498
|
-
## Troubleshooting
|
|
499
|
-
|
|
500
|
-
### "Not logged in" Error
|
|
501
|
-
|
|
502
|
-
Run `sheets login` to authenticate with your Google account.
|
|
503
|
-
|
|
504
|
-
### "Access denied" or "Permission denied" Error
|
|
505
|
-
|
|
506
|
-
Make sure you have access to the spreadsheet:
|
|
507
|
-
- For personal accounts: The spreadsheet must be shared with your Google account
|
|
508
|
-
- For service accounts: Share the spreadsheet with the service account email address
|
|
509
|
-
|
|
510
|
-
### "Invalid credentials" Error
|
|
511
|
-
|
|
512
|
-
For service accounts:
|
|
513
|
-
- Check that the JSON file is valid
|
|
514
|
-
- Make sure the file contains `type: "service_account"`
|
|
515
|
-
- Verify the private key is correct
|
|
516
|
-
|
|
517
|
-
### Browser Does Not Open During Login
|
|
518
|
-
|
|
519
|
-
Try these solutions:
|
|
520
|
-
- Open the URL manually (it will be displayed in the terminal)
|
|
521
|
-
- Make sure port 8085 is not in use by another application
|
|
522
|
-
|
|
523
|
-
### Token Expired
|
|
524
|
-
|
|
525
|
-
Tokens are automatically refreshed when they expire. If you see token errors, try logging out and logging in again:
|
|
526
|
-
|
|
527
|
-
```bash
|
|
528
|
-
sheets logout
|
|
529
|
-
sheets login
|
|
530
|
-
```
|
|
531
|
-
|
|
532
|
-
## Token Storage
|
|
533
|
-
|
|
534
|
-
When you run `sheets login`, your authentication tokens are saved to:
|
|
535
|
-
|
|
536
|
-
```
|
|
537
|
-
~/.sheets/tokens.json
|
|
538
|
-
```
|
|
539
|
-
|
|
540
|
-
This file contains:
|
|
541
|
-
- Access token (used to make API requests)
|
|
542
|
-
- Refresh token (used to get new access tokens)
|
|
543
|
-
- Token expiration time
|
|
544
|
-
- Your email address
|
|
545
|
-
|
|
546
|
-
Keep this file secure. Do not share it with others.
|
|
547
|
-
|
|
548
|
-
## How It Works
|
|
549
|
-
|
|
550
|
-
This tool uses the Google Sheets API v4 to read spreadsheet data. It does not use the official Google SDK. Instead, it makes direct HTTP requests to the API.
|
|
551
|
-
|
|
552
|
-
Authentication methods:
|
|
553
|
-
- Personal accounts: OAuth 2.0 with PKCE (Proof Key for Code Exchange)
|
|
554
|
-
- Service accounts: JWT (JSON Web Token) signed with RS256
|
|
555
|
-
|
|
556
|
-
The tool only requests read-only access to your spreadsheets. It cannot modify your data.
|
|
557
|
-
|
|
558
|
-
## Project Structure
|
|
559
|
-
|
|
560
|
-
```
|
|
561
|
-
src/
|
|
562
|
-
index.ts Public API exports
|
|
563
|
-
cli.ts CLI entry point
|
|
564
|
-
api/index.ts SheetsClient class
|
|
565
|
-
auth/
|
|
566
|
-
index.ts Auth provider factory
|
|
567
|
-
constants.ts OAuth configuration
|
|
568
|
-
oauth.ts OAuth token wrapper
|
|
569
|
-
user-auth.ts User OAuth with PKCE
|
|
570
|
-
service-account.ts Service account JWT auth
|
|
571
|
-
http/index.ts HTTP client with retry
|
|
572
|
-
types/index.ts TypeScript definitions
|
|
573
|
-
```
|
|
574
|
-
|
|
575
|
-
## Development
|
|
576
|
-
|
|
577
|
-
### Build
|
|
578
|
-
|
|
579
|
-
```bash
|
|
580
|
-
npm run build
|
|
581
|
-
```
|
|
582
|
-
|
|
583
|
-
This compiles TypeScript to JavaScript in the `dist` folder.
|
|
584
|
-
|
|
585
|
-
### Development Mode
|
|
586
|
-
|
|
587
|
-
```bash
|
|
588
|
-
npm run dev
|
|
589
|
-
```
|
|
590
|
-
|
|
591
|
-
This runs the CLI with automatic reloading when files change.
|
|
592
|
-
|
|
593
|
-
### Run Without Building
|
|
594
|
-
|
|
595
|
-
```bash
|
|
596
|
-
npx tsx src/cli.ts <command>
|
|
597
|
-
```
|
|
598
|
-
|
|
599
|
-
## License
|
|
600
|
-
|
|
601
|
-
MIT
|