pkg-track 1.0.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/CHANGELOG.md +53 -0
- package/CODE_OF_CONDUCT.md +42 -0
- package/CONTRIBUTING.md +157 -0
- package/LICENSE +21 -0
- package/PUBLISH.md +188 -0
- package/QUICKSTART.md +136 -0
- package/README.md +393 -0
- package/bin/cli.js +174 -0
- package/package.json +53 -0
- package/pkg-tracker-1.0.0.tgz +0 -0
- package/src/banner.js +34 -0
- package/src/db.js +189 -0
- package/src/gmail.js +371 -0
- package/src/open.js +209 -0
- package/src/parser.js +223 -0
- package/src/tracker.js +103 -0
package/README.md
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
# ๐ฆ pkg-tracker
|
|
2
|
+
|
|
3
|
+
**Track all your packages in one place.** No more digging through emails!
|
|
4
|
+
|
|
5
|
+
Interactive CLI that scans your Gmail for shipping confirmations and lets you track UPS, FedEx, USPS, and Amazon packages with arrow-key selection and one-click browser opening.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
9
|
+
โ ๐ฆ PKG TRACK โ
|
|
10
|
+
โ Track all your packages in one place ๐ฆ โ
|
|
11
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
12
|
+
|
|
13
|
+
๐ Open all packages in browser
|
|
14
|
+
๐ Running shoes (UPS - In Transit) ยท today
|
|
15
|
+
๐ฆ Laptop stand (FedEx - Pending) ยท 2d ago
|
|
16
|
+
โณ Phone case (USPS - Pending) ยท yesterday
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## โจ Features
|
|
20
|
+
|
|
21
|
+
- ๐ **Auto-scan Gmail** - Securely search your email for shipping confirmations
|
|
22
|
+
- ๐ฎ **Interactive menu** - Arrow-key selection, auto-opens tracking in browser
|
|
23
|
+
- ๐ **Smart parsing** - Automatically extracts tracking numbers from emails
|
|
24
|
+
- ๐ฏ **4 major carriers** - UPS, FedEx, USPS, Amazon Logistics
|
|
25
|
+
- ๐พ **Local-only storage** - Your data never leaves your machine
|
|
26
|
+
- โก **Fast & simple** - Quick CLI, no browser extension needed
|
|
27
|
+
- ๐ **One-click tracking** - No more copy/pasting tracking numbers
|
|
28
|
+
- ๐ **Secure** - Read-only Gmail access, revocable anytime
|
|
29
|
+
|
|
30
|
+
## ๐ Prerequisites
|
|
31
|
+
|
|
32
|
+
Before installing, you'll need:
|
|
33
|
+
|
|
34
|
+
- **Node.js 14 or higher** ([Download](https://nodejs.org/))
|
|
35
|
+
- **Gmail account** - For scanning shipping emails
|
|
36
|
+
- **Google Cloud Project** - Free tier (for OAuth credentials)
|
|
37
|
+
- See [Setup](#setup) for detailed instructions
|
|
38
|
+
|
|
39
|
+
**Supported Platforms:**
|
|
40
|
+
- โ
macOS (10.15+)
|
|
41
|
+
- โ
Linux (Ubuntu, Debian, Fedora, etc.)
|
|
42
|
+
- โ
Windows 10/11 (with Node.js)
|
|
43
|
+
|
|
44
|
+
## ๐ Installation
|
|
45
|
+
|
|
46
|
+
**Option 1: NPM (Recommended)**
|
|
47
|
+
```bash
|
|
48
|
+
npm install -g pkg-tracker
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Option 2: From Source**
|
|
52
|
+
```bash
|
|
53
|
+
git clone https://github.com/vvanessaww/pkg-tracker.git
|
|
54
|
+
cd pkg-tracker
|
|
55
|
+
npm install
|
|
56
|
+
npm link
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**Verify installation:**
|
|
60
|
+
```bash
|
|
61
|
+
pkg --version
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Setup
|
|
65
|
+
|
|
66
|
+
### 1. Get Gmail API Credentials
|
|
67
|
+
|
|
68
|
+
1. Go to [Google Cloud Console](https://console.cloud.google.com/apis/credentials)
|
|
69
|
+
2. Create a new project (or select existing)
|
|
70
|
+
3. Enable **Gmail API**
|
|
71
|
+
4. Create **OAuth 2.0 Client ID** (Application type: Desktop app)
|
|
72
|
+
5. Download the credentials JSON file
|
|
73
|
+
6. Save it as `~/.pkg-tracker/credentials.json`
|
|
74
|
+
|
|
75
|
+
### 2. Initialize
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pkg init
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
This will:
|
|
82
|
+
- Open your browser for Gmail authorization
|
|
83
|
+
- Save access token for future use
|
|
84
|
+
- Create local database
|
|
85
|
+
|
|
86
|
+
## Usage
|
|
87
|
+
|
|
88
|
+
### Scan email for packages
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pkg sync
|
|
92
|
+
pkg sync --days 7 # Scan last 7 days only
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Options:
|
|
96
|
+
- `--days <number>` - Number of days to scan back (default: 30, max: 30)
|
|
97
|
+
|
|
98
|
+
**Note:** Maximum 30 days to avoid Gmail API rate limits and keep results relevant.
|
|
99
|
+
|
|
100
|
+
### Open package tracking
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
pkg open
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Interactive menu to open tracking pages in your browser:
|
|
107
|
+
- โฌ๏ธโฌ๏ธ Arrow keys to select a package
|
|
108
|
+
- โ Enter to open tracking page
|
|
109
|
+
- ๐ "Open all" option to open all packages at once
|
|
110
|
+
- Automatically opens UPS.com, FedEx.com, or USPS.com
|
|
111
|
+
|
|
112
|
+
**Example:**
|
|
113
|
+
```
|
|
114
|
+
๐ฆ Open Package Tracking
|
|
115
|
+
|
|
116
|
+
Select a package to track:
|
|
117
|
+
โฏ ๐ Open all packages in browser
|
|
118
|
+
๐ Running shoes (UPS - In Transit)
|
|
119
|
+
๐ฆ Laptop stand (FedEx - Pending)
|
|
120
|
+
โณ Phone case (USPS - Pending)
|
|
121
|
+
โ Exit
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Manually add a package
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
pkg add 1Z999AA10123456784
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Interactive prompts will ask for:
|
|
131
|
+
- Package description (e.g., "Running shoes")
|
|
132
|
+
- Carrier selection (auto-detected when possible)
|
|
133
|
+
- Retailer/store name (optional)
|
|
134
|
+
|
|
135
|
+
Example:
|
|
136
|
+
```
|
|
137
|
+
๐ฆ Adding package manually...
|
|
138
|
+
|
|
139
|
+
โ Valid tracking number detected
|
|
140
|
+
Carrier: UPS
|
|
141
|
+
Tracking: 1Z999AA10123456784
|
|
142
|
+
|
|
143
|
+
? What is this package? Running shoes
|
|
144
|
+
? Select carrier: UPS (detected)
|
|
145
|
+
? Where did you order from? Nike
|
|
146
|
+
|
|
147
|
+
โ Package added successfully!
|
|
148
|
+
Running shoes
|
|
149
|
+
UPS ยท 1Z999AA10123456784
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Clean up packages
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
pkg clean
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Interactively remove packages you no longer want to track:
|
|
159
|
+
- ๐ Shows all packages (including delivered)
|
|
160
|
+
- โ๏ธ Checkbox selection (Space to select, Enter when done)
|
|
161
|
+
- โ
Confirms before deleting
|
|
162
|
+
|
|
163
|
+
**Example:**
|
|
164
|
+
```
|
|
165
|
+
๐๏ธ Select packages to remove
|
|
166
|
+
|
|
167
|
+
Select packages to remove (Space to select, Enter when done):
|
|
168
|
+
โฏ โฏ Running shoes (UPS - Delivered)
|
|
169
|
+
โฏ Laptop stand (FedEx - Pending)
|
|
170
|
+
โ Old package from 2025 (USPS - Delivered)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Perfect for cleaning up delivered packages or removing things you're no longer tracking.
|
|
174
|
+
|
|
175
|
+
## Supported Carriers
|
|
176
|
+
|
|
177
|
+
- โ
**UPS** (auto-detection + tracking)
|
|
178
|
+
- โ
**FedEx** (auto-detection + tracking)
|
|
179
|
+
- โ
**USPS** (auto-detection + tracking)
|
|
180
|
+
- โ
**Amazon Logistics** (auto-detection + tracking)
|
|
181
|
+
|
|
182
|
+
**Tracking number formats:**
|
|
183
|
+
- UPS: 1Z followed by 16 alphanumeric characters
|
|
184
|
+
- USPS: 20-22 digit numbers starting with 9, 92, 94, or 82
|
|
185
|
+
- Amazon: TBA followed by 12 digits
|
|
186
|
+
- FedEx: 12, 15, or 20 digit numbers (with "fedex" in email)
|
|
187
|
+
|
|
188
|
+
## How it Works
|
|
189
|
+
|
|
190
|
+
1. **Gmail API** searches for emails with keywords like "shipped", "tracking", "delivered"
|
|
191
|
+
2. **Regex patterns** extract tracking numbers from email content
|
|
192
|
+
3. **Carrier detection** identifies which shipping service based on tracking format
|
|
193
|
+
4. **Retailer detection** identifies store based on sender email
|
|
194
|
+
5. **SQLite database** stores everything locally
|
|
195
|
+
6. **Interactive menu** (powered by inquirer) lets you select and open tracking pages instantly
|
|
196
|
+
|
|
197
|
+
## ๐ Security & Privacy
|
|
198
|
+
|
|
199
|
+
**Your data stays on your machine:**
|
|
200
|
+
- All package data stored **locally** in `~/.pkg-tracker/`
|
|
201
|
+
- OAuth credentials stored with `0600` permissions (user read/write only)
|
|
202
|
+
- Database files secured with `0700` directory permissions
|
|
203
|
+
|
|
204
|
+
**Gmail Access:**
|
|
205
|
+
- **Read-only scope**: `gmail.readonly` - cannot send, delete, or modify emails
|
|
206
|
+
- **Local authentication**: OAuth tokens stored on your computer only
|
|
207
|
+
- **Secure storage**: Credentials never logged or transmitted to third parties
|
|
208
|
+
- **Revocable**: You can revoke access anytime at https://myaccount.google.com/permissions
|
|
209
|
+
|
|
210
|
+
**What we access:**
|
|
211
|
+
- โ
Email headers and body text to find tracking numbers
|
|
212
|
+
- โ
Only emails matching shipping keywords (last 30 days max)
|
|
213
|
+
- โ No access to send, delete, or modify emails
|
|
214
|
+
- โ No data sent to external servers or analytics
|
|
215
|
+
- โ No telemetry or tracking
|
|
216
|
+
|
|
217
|
+
**Data stored locally:**
|
|
218
|
+
- `~/.pkg-tracker/credentials.json` - Your Gmail OAuth credentials
|
|
219
|
+
- `~/.pkg-tracker/gmail-token.json` - Authentication token (auto-refresh)
|
|
220
|
+
- `~/.pkg-tracker/packages.db` - SQLite database of your packages
|
|
221
|
+
|
|
222
|
+
**Revoking access:**
|
|
223
|
+
If you want to stop using pkg-tracker:
|
|
224
|
+
1. Revoke OAuth access: https://myaccount.google.com/permissions
|
|
225
|
+
2. Delete local data: `rm -rf ~/.pkg-tracker`
|
|
226
|
+
|
|
227
|
+
## ๐ง Troubleshooting
|
|
228
|
+
|
|
229
|
+
### "Gmail credentials not found"
|
|
230
|
+
|
|
231
|
+
**Problem:** You see `โ ๏ธ Gmail OAuth credentials not found.`
|
|
232
|
+
|
|
233
|
+
**Solution:**
|
|
234
|
+
1. Make sure you've created OAuth credentials in Google Cloud Console
|
|
235
|
+
2. Download the credentials JSON file
|
|
236
|
+
3. Save it to the correct location:
|
|
237
|
+
```bash
|
|
238
|
+
mkdir -p ~/.pkg-tracker
|
|
239
|
+
mv ~/Downloads/client_secret_*.json ~/.pkg-tracker/credentials.json
|
|
240
|
+
```
|
|
241
|
+
4. Run `pkg init` again
|
|
242
|
+
|
|
243
|
+
### "Gmail not authorized"
|
|
244
|
+
|
|
245
|
+
**Problem:** Error says Gmail not authorized or token missing
|
|
246
|
+
|
|
247
|
+
**Solution:**
|
|
248
|
+
1. Run `pkg init` to authenticate
|
|
249
|
+
2. Make sure you complete the OAuth flow in your browser
|
|
250
|
+
3. If stuck, delete old token and re-authenticate:
|
|
251
|
+
```bash
|
|
252
|
+
rm ~/.pkg-tracker/gmail-token.json
|
|
253
|
+
pkg init
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### "No packages found"
|
|
257
|
+
|
|
258
|
+
**Problem:** `pkg sync` completes but finds 0 packages
|
|
259
|
+
|
|
260
|
+
**Possible causes:**
|
|
261
|
+
1. **No shipping emails in date range** - Try expanding the range:
|
|
262
|
+
```bash
|
|
263
|
+
pkg sync --days 30
|
|
264
|
+
```
|
|
265
|
+
2. **Emails don't contain tracking numbers** - Some order confirmations don't include tracking yet
|
|
266
|
+
3. **Unsupported carrier** - Only UPS, FedEx, USPS, Amazon supported
|
|
267
|
+
4. **Tracking number format** - Some international carriers use different formats
|
|
268
|
+
|
|
269
|
+
**Debug:**
|
|
270
|
+
- Check if `pkg sync` shows "X emails had no tracking numbers"
|
|
271
|
+
- Those emails likely are order confirmations without tracking yet
|
|
272
|
+
|
|
273
|
+
### "Module not found" errors
|
|
274
|
+
|
|
275
|
+
**Problem:** Error when running `pkg` command
|
|
276
|
+
|
|
277
|
+
**Solution:**
|
|
278
|
+
```bash
|
|
279
|
+
# Reinstall dependencies
|
|
280
|
+
cd /path/to/pkg-tracker
|
|
281
|
+
npm install
|
|
282
|
+
|
|
283
|
+
# If installed globally, reinstall
|
|
284
|
+
npm uninstall -g pkg-tracker
|
|
285
|
+
npm install -g pkg-tracker
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### "Permission denied" on macOS/Linux
|
|
289
|
+
|
|
290
|
+
**Problem:** Cannot write to `~/.pkg-tracker/`
|
|
291
|
+
|
|
292
|
+
**Solution:**
|
|
293
|
+
```bash
|
|
294
|
+
# Fix directory permissions
|
|
295
|
+
mkdir -p ~/.pkg-tracker
|
|
296
|
+
chmod 700 ~/.pkg-tracker
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### OAuth browser doesn't open
|
|
300
|
+
|
|
301
|
+
**Problem:** `pkg init` says "Opening browser..." but nothing happens
|
|
302
|
+
|
|
303
|
+
**Solution:**
|
|
304
|
+
1. Manually copy the URL from the terminal
|
|
305
|
+
2. Paste it into your browser
|
|
306
|
+
3. Complete the OAuth flow
|
|
307
|
+
4. The terminal should detect the authorization
|
|
308
|
+
|
|
309
|
+
### "Invalid tracking number"
|
|
310
|
+
|
|
311
|
+
**Problem:** `pkg add` rejects your tracking number
|
|
312
|
+
|
|
313
|
+
**Solution:**
|
|
314
|
+
- **UPS:** Must be 1Z followed by 16 characters (e.g., `1Z999AA10123456784`)
|
|
315
|
+
- **USPS:** 20-22 digits starting with 9, 92, 94, or 82
|
|
316
|
+
- **FedEx:** 12, 15, or 20 digits (email must mention "fedex")
|
|
317
|
+
- **Amazon:** TBA followed by 12 digits (e.g., `TBA123456789012`)
|
|
318
|
+
|
|
319
|
+
Remove spaces and special characters - tracking numbers are alphanumeric only.
|
|
320
|
+
|
|
321
|
+
### Database is corrupted
|
|
322
|
+
|
|
323
|
+
**Problem:** SQLite errors or weird behavior
|
|
324
|
+
|
|
325
|
+
**Solution:**
|
|
326
|
+
```bash
|
|
327
|
+
# Backup current database
|
|
328
|
+
cp ~/.pkg-tracker/packages.db ~/.pkg-tracker/packages.db.backup
|
|
329
|
+
|
|
330
|
+
# Delete and resync
|
|
331
|
+
rm ~/.pkg-tracker/packages.db
|
|
332
|
+
pkg sync
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
### Rate limiting / Too many requests
|
|
336
|
+
|
|
337
|
+
**Problem:** Gmail API quota exceeded
|
|
338
|
+
|
|
339
|
+
**Solution:**
|
|
340
|
+
- Gmail API has daily quotas (usually generous)
|
|
341
|
+
- Wait a few hours and try again
|
|
342
|
+
- Don't run `pkg sync` in a loop
|
|
343
|
+
- Default 30-day scan is usually fine
|
|
344
|
+
|
|
345
|
+
### Still having issues?
|
|
346
|
+
|
|
347
|
+
1. **Check Node.js version:**
|
|
348
|
+
```bash
|
|
349
|
+
node --version # Should be 14.0.0 or higher
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
2. **Enable debug mode** (check for errors):
|
|
353
|
+
```bash
|
|
354
|
+
NODE_ENV=development pkg sync
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
3. **Open an issue:**
|
|
358
|
+
- Visit: https://github.com/vvanessaww/pkg-tracker/issues
|
|
359
|
+
- Include: OS, Node.js version, error message, steps to reproduce
|
|
360
|
+
|
|
361
|
+
## Roadmap
|
|
362
|
+
|
|
363
|
+
- [ ] **Live tracking updates** via AfterShip/TrackingMore API
|
|
364
|
+
- [ ] **Desktop notifications** when packages arrive
|
|
365
|
+
- [ ] **Return window tracking** - never miss a return deadline
|
|
366
|
+
- [ ] **Price tracking** - monitor order prices
|
|
367
|
+
- [ ] **Web dashboard** - visual interface
|
|
368
|
+
- [ ] **AI extraction** - better parsing for non-standard shipments
|
|
369
|
+
|
|
370
|
+
## Development
|
|
371
|
+
|
|
372
|
+
```bash
|
|
373
|
+
# Run locally
|
|
374
|
+
npm start -- list
|
|
375
|
+
|
|
376
|
+
# Link for testing
|
|
377
|
+
npm link
|
|
378
|
+
|
|
379
|
+
# Run tests
|
|
380
|
+
npm test
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
## License
|
|
384
|
+
|
|
385
|
+
MIT
|
|
386
|
+
|
|
387
|
+
## Contributing
|
|
388
|
+
|
|
389
|
+
PRs welcome! This is a fun side project.
|
|
390
|
+
|
|
391
|
+
## Why?
|
|
392
|
+
|
|
393
|
+
Because juggling packages from Amazon, Target, Etsy, random eBay sellers is chaos. One command should show you everything.
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { Command } = require('commander');
|
|
4
|
+
const chalk = require('chalk');
|
|
5
|
+
const pkg = require('../package.json');
|
|
6
|
+
const { initGmail, syncPackages } = require('../src/gmail');
|
|
7
|
+
const { addPackage } = require('../src/tracker');
|
|
8
|
+
const { openPackages } = require('../src/open');
|
|
9
|
+
const { getAllPackages } = require('../src/db');
|
|
10
|
+
|
|
11
|
+
// Global error handler
|
|
12
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
13
|
+
console.error(chalk.red('\nโ Unexpected error occurred:'));
|
|
14
|
+
console.error(chalk.gray(reason.message || reason));
|
|
15
|
+
console.error(chalk.yellow('\nIf this persists, please report it:'));
|
|
16
|
+
console.error(chalk.cyan('https://github.com/vvanessaww/pkg-tracker/issues\n'));
|
|
17
|
+
process.exit(1);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
process.on('uncaughtException', (error) => {
|
|
21
|
+
console.error(chalk.red('\nโ Fatal error:'));
|
|
22
|
+
console.error(chalk.gray(error.message));
|
|
23
|
+
console.error(chalk.yellow('\nIf this persists, please report it:'));
|
|
24
|
+
console.error(chalk.cyan('https://github.com/vvanessaww/pkg-tracker/issues\n'));
|
|
25
|
+
process.exit(1);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const program = new Command();
|
|
29
|
+
|
|
30
|
+
program
|
|
31
|
+
.name('pkg')
|
|
32
|
+
.description('Track all your packages in one place')
|
|
33
|
+
.version(pkg.version);
|
|
34
|
+
|
|
35
|
+
program
|
|
36
|
+
.command('init')
|
|
37
|
+
.description('Set up Gmail OAuth and initialize database')
|
|
38
|
+
.action(async () => {
|
|
39
|
+
try {
|
|
40
|
+
await initGmail();
|
|
41
|
+
console.log(chalk.green('โ Setup complete! Run `pkg sync` to scan your emails.'));
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.error(chalk.red('Error during setup:'), error.message);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
program
|
|
49
|
+
.command('sync')
|
|
50
|
+
.description('Scan Gmail for shipping confirmations')
|
|
51
|
+
.option('-d, --days <number>', 'Number of days to scan back (max 30)', '30')
|
|
52
|
+
.action(async (options) => {
|
|
53
|
+
try {
|
|
54
|
+
let days = parseInt(options.days, 10);
|
|
55
|
+
|
|
56
|
+
// Validate input
|
|
57
|
+
if (isNaN(days)) {
|
|
58
|
+
console.log(chalk.red('โ ๏ธ Days must be a valid number'));
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Enforce max of 30 days
|
|
63
|
+
if (days > 30) {
|
|
64
|
+
console.log(chalk.yellow(`โ ๏ธ Maximum 30 days allowed. Using 30 instead of ${days}.`));
|
|
65
|
+
days = 30;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (days < 1) {
|
|
69
|
+
console.log(chalk.red('โ ๏ธ Days must be at least 1'));
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
await syncPackages(days);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error(chalk.red('Error syncing:'), error.message);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
program
|
|
81
|
+
.command('add <tracking-number>')
|
|
82
|
+
.description('Manually add a tracking number (interactive)')
|
|
83
|
+
.action(async (trackingNumber) => {
|
|
84
|
+
try {
|
|
85
|
+
await addPackage(trackingNumber);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error(chalk.red('\nError adding package:'), error.message);
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
program
|
|
93
|
+
.command('open')
|
|
94
|
+
.description('Interactively open package tracking in browser')
|
|
95
|
+
.action(async () => {
|
|
96
|
+
try {
|
|
97
|
+
await openPackages();
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.error(chalk.red('Error opening packages:'), error.message);
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
program
|
|
105
|
+
.command('clean')
|
|
106
|
+
.description('Interactively remove packages from tracking')
|
|
107
|
+
.action(async () => {
|
|
108
|
+
try {
|
|
109
|
+
const inquirer = require('inquirer');
|
|
110
|
+
const allPackages = getAllPackages(true); // Include delivered
|
|
111
|
+
|
|
112
|
+
if (allPackages.length === 0) {
|
|
113
|
+
console.log(chalk.yellow('\n๐ญ No packages to clean\n'));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
console.log(chalk.blue('\n๐๏ธ Package Cleanup\n'));
|
|
118
|
+
console.log(chalk.gray('Remove old or delivered packages from your tracking list'));
|
|
119
|
+
console.log(chalk.gray('Use Space to select multiple, Enter when done\n'));
|
|
120
|
+
|
|
121
|
+
// Build choices
|
|
122
|
+
const choices = allPackages.map(pkg => {
|
|
123
|
+
const description = pkg.description || 'Package';
|
|
124
|
+
const shortDesc = description.length > 40 ? description.substring(0, 37) + '...' : description;
|
|
125
|
+
const status = pkg.delivered_at ? 'โ
Delivered' : pkg.status || 'Pending';
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
name: `${shortDesc} (${pkg.carrier} - ${status})`,
|
|
129
|
+
value: pkg.tracking_number,
|
|
130
|
+
short: shortDesc
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const { selected } = await inquirer.prompt([{
|
|
135
|
+
type: 'checkbox',
|
|
136
|
+
name: 'selected',
|
|
137
|
+
message: 'Select packages to remove (Space to select, Enter when done):',
|
|
138
|
+
choices,
|
|
139
|
+
pageSize: 15
|
|
140
|
+
}]);
|
|
141
|
+
|
|
142
|
+
if (selected.length === 0) {
|
|
143
|
+
console.log(chalk.yellow('\nNo packages selected. Nothing removed.\n'));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Confirm deletion
|
|
148
|
+
const { confirm } = await inquirer.prompt([{
|
|
149
|
+
type: 'confirm',
|
|
150
|
+
name: 'confirm',
|
|
151
|
+
message: `Delete ${selected.length} package(s)?`,
|
|
152
|
+
default: false
|
|
153
|
+
}]);
|
|
154
|
+
|
|
155
|
+
if (!confirm) {
|
|
156
|
+
console.log(chalk.yellow('\nCancelled\n'));
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Delete selected packages
|
|
161
|
+
const { deletePackage } = require('../src/db');
|
|
162
|
+
for (const trackingNumber of selected) {
|
|
163
|
+
deletePackage(trackingNumber);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
console.log(chalk.green(`\nโ Removed ${selected.length} package(s)\n`));
|
|
167
|
+
|
|
168
|
+
} catch (error) {
|
|
169
|
+
console.error(chalk.red('Error cleaning:'), error.message);
|
|
170
|
+
process.exit(1);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
program.parse();
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pkg-track",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Track all your packages in one place - UPS, FedEx, USPS, Amazon. Interactive CLI with Gmail integration.",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"pkg": "./bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"start": "node bin/cli.js",
|
|
11
|
+
"test": "node test/parser.test.js"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"package",
|
|
15
|
+
"tracking",
|
|
16
|
+
"cli",
|
|
17
|
+
"shipping",
|
|
18
|
+
"ups",
|
|
19
|
+
"fedex",
|
|
20
|
+
"usps",
|
|
21
|
+
"amazon",
|
|
22
|
+
"delivery",
|
|
23
|
+
"gmail",
|
|
24
|
+
"logistics",
|
|
25
|
+
"parcel",
|
|
26
|
+
"track-package",
|
|
27
|
+
"package-tracker",
|
|
28
|
+
"shipment",
|
|
29
|
+
"interactive-cli"
|
|
30
|
+
],
|
|
31
|
+
"author": "Vanessa Wang",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/vvanessaww/pkg-tracker.git"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/vvanessaww/pkg-tracker#readme",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/vvanessaww/pkg-tracker/issues"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=14.0.0"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"commander": "^11.1.0",
|
|
46
|
+
"googleapis": "^128.0.0",
|
|
47
|
+
"better-sqlite3": "^9.2.2",
|
|
48
|
+
"chalk": "^4.1.2",
|
|
49
|
+
"ora": "^5.4.1",
|
|
50
|
+
"inquirer": "^8.2.6",
|
|
51
|
+
"open": "^8.4.2"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
Binary file
|
package/src/banner.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const chalk = require('chalk');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Display banner with ASCII art
|
|
5
|
+
*/
|
|
6
|
+
function showBanner() {
|
|
7
|
+
const banner = `
|
|
8
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
9
|
+
โ โ
|
|
10
|
+
โ ๐ฆ โโโโโโโ โโโ โโโ โโโโโโโ โ
|
|
11
|
+
โ โโโโโโโโโโโ โโโโโโโโโโโโ โ
|
|
12
|
+
โ โโโโโโโโโโโโโโโ โโโ โโโโ โ
|
|
13
|
+
โ โโโโโโโ โโโโโโโ โโโ โโโ โ
|
|
14
|
+
โ โโโ โโโ โโโโโโโโโโโโ โ
|
|
15
|
+
โ โโโ โโโ โโโ โโโโโโโ โ
|
|
16
|
+
โ โ
|
|
17
|
+
โ โโโโโโโโโโโโโโโโ โโโโโโ โโโโโโโโโโ โโโ โ
|
|
18
|
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโ โ
|
|
19
|
+
โ โโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโ โ
|
|
20
|
+
โ โโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโ โ
|
|
21
|
+
โ โโโ โโโ โโโโโโ โโโโโโโโโโโโโโ โโโ โ
|
|
22
|
+
โ โโโ โโโ โโโโโโ โโโ โโโโโโโโโโ โโโ โ
|
|
23
|
+
โ โ
|
|
24
|
+
โ Track all your packages in one place ๐ฆ โ
|
|
25
|
+
โ โ
|
|
26
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
console.log(chalk.cyan(banner));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = {
|
|
33
|
+
showBanner
|
|
34
|
+
};
|