shorter.sh 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/LICENSE +21 -0
- package/README.md +119 -0
- package/dist/cli.js +755 -0
- package/dist/index.cjs +317 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +172 -0
- package/dist/index.d.ts +172 -0
- package/dist/index.js +281 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 shorter.sh
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# shorter.sh
|
|
2
|
+
|
|
3
|
+
CLI and SDK for the [shorter.sh](https://shorter.sh) URL shortener. Zero runtime dependencies, Node >=18.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install shorter.sh
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## CLI
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# First run will prompt for your API key
|
|
15
|
+
shorter https://example.com
|
|
16
|
+
# ✓ https://shorter.sh/xK9mP2
|
|
17
|
+
# Copied to clipboard!
|
|
18
|
+
|
|
19
|
+
shorter list
|
|
20
|
+
shorter list --page 2 --limit 10
|
|
21
|
+
|
|
22
|
+
shorter delete xK9mP2
|
|
23
|
+
shorter delete xK9mP2 --yes
|
|
24
|
+
|
|
25
|
+
shorter analytics
|
|
26
|
+
shorter analytics xK9mP2
|
|
27
|
+
shorter analytics xK9mP2 --dimension country
|
|
28
|
+
|
|
29
|
+
shorter config set api-key sk_your_key_here
|
|
30
|
+
shorter config set base-url https://custom.domain
|
|
31
|
+
shorter config get api-key
|
|
32
|
+
shorter config path
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Options
|
|
36
|
+
|
|
37
|
+
| Flag | Description |
|
|
38
|
+
|------|-------------|
|
|
39
|
+
| `--no-copy` | Don't copy short URL to clipboard |
|
|
40
|
+
| `--yes` | Skip delete confirmation prompt |
|
|
41
|
+
| `--page N` | Page number for list |
|
|
42
|
+
| `--limit N` | Items per page for list |
|
|
43
|
+
| `--start DATE` | Analytics start date (ISO or timestamp) |
|
|
44
|
+
| `--end DATE` | Analytics end date (ISO or timestamp) |
|
|
45
|
+
| `--dimension DIM` | Analytics breakdown: `country`, `device_type`, `browser`, `os`, `referrer_domain`, `language` |
|
|
46
|
+
| `-h, --help` | Show help |
|
|
47
|
+
| `-v, --version` | Show version |
|
|
48
|
+
|
|
49
|
+
### Aliases
|
|
50
|
+
|
|
51
|
+
- `shorter ls` → `shorter list`
|
|
52
|
+
- `shorter rm` → `shorter delete`
|
|
53
|
+
- `shorter stats` → `shorter analytics`
|
|
54
|
+
|
|
55
|
+
### Environment Variables
|
|
56
|
+
|
|
57
|
+
- `SHORTER_API_KEY` — API key (overrides config file)
|
|
58
|
+
- `SHORTER_BASE_URL` — Base URL (overrides config file)
|
|
59
|
+
- `NO_COLOR` — Disable colored output
|
|
60
|
+
|
|
61
|
+
## SDK
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { ShorterClient } from 'shorter.sh';
|
|
65
|
+
|
|
66
|
+
const client = new ShorterClient({
|
|
67
|
+
apiKey: 'sk_your_key_here', // or set SHORTER_API_KEY env var
|
|
68
|
+
baseUrl: 'https://shorter.sh', // optional
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Shorten a URL
|
|
72
|
+
const { shortCode, shortUrl, originalUrl } = await client.shorten('https://example.com');
|
|
73
|
+
|
|
74
|
+
// List your URLs
|
|
75
|
+
const { urls, pagination, totalClicks } = await client.list({ page: 1, limit: 50 });
|
|
76
|
+
|
|
77
|
+
// Delete a URL
|
|
78
|
+
await client.delete('xK9mP2');
|
|
79
|
+
|
|
80
|
+
// Analytics overview
|
|
81
|
+
const overview = await client.analytics.overview({ start: '2024-01-01', end: '2024-01-31' });
|
|
82
|
+
|
|
83
|
+
// Per-URL analytics
|
|
84
|
+
const stats = await client.analytics.url('xK9mP2', { dimension: 'country' });
|
|
85
|
+
|
|
86
|
+
// Detailed analytics (all breakdowns)
|
|
87
|
+
const detail = await client.analytics.url('xK9mP2', { detail: true });
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Error Handling
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { ShorterClient, ValidationError, RateLimitError, NetworkError } from 'shorter.sh';
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
await client.shorten('not-a-url');
|
|
97
|
+
} catch (err) {
|
|
98
|
+
if (err instanceof ValidationError) {
|
|
99
|
+
console.log(err.message); // "Invalid URL"
|
|
100
|
+
console.log(err.code); // "INVALID_URL"
|
|
101
|
+
console.log(err.status); // 400
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Error classes: `ShorterError` (base), `ValidationError`, `AuthenticationError`, `ForbiddenError`, `NotFoundError`, `RateLimitError`, `ServerError`, `NetworkError`.
|
|
107
|
+
|
|
108
|
+
### Custom Fetch
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
const client = new ShorterClient({
|
|
112
|
+
apiKey: 'sk_...',
|
|
113
|
+
fetch: myCustomFetch, // inject for testing or custom behavior
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
MIT
|