@hasna/shortlinks 0.2.7 → 0.2.10
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/README.md +21 -24
- package/cloudflare/wrangler.example.toml +1 -1
- package/dist/cli/index.js +1602 -6178
- package/dist/cli/projection.d.ts +32 -0
- package/dist/client-store.d.ts +7 -7
- package/dist/cloud-store.d.ts +9 -7
- package/dist/generated/storage-kit/backend.d.ts +19 -0
- package/dist/generated/storage-kit/index.d.ts +2 -2
- package/dist/generated/storage-kit/own.d.ts +10 -0
- package/dist/generated/storage-kit/pool.d.ts +7 -6
- package/dist/generated/storage-kit/tls.d.ts +30 -3
- package/dist/index.js +1117 -6331
- package/dist/mcp/http.d.ts +2 -2
- package/dist/mcp/index.js +588 -6095
- package/dist/sdk/generated.d.ts +4 -4
- package/dist/sdk/index.d.ts +1 -2
- package/dist/sdk/index.js +13 -5
- package/dist/serve/app.d.ts +8 -5
- package/dist/serve/index.d.ts +5 -4
- package/dist/serve/index.js +762 -5251
- package/dist/store-interface.d.ts +4 -2
- package/infra/aws-ec2-user-data.sh +6 -6
- package/package.json +8 -5
- package/dist/generated/storage-kit/mode.d.ts +0 -47
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Shortlink management for custom domains — CLI, MCP server, REST API, and a generated SDK.
|
|
4
4
|
|
|
5
|
-
`shortlinks` creates Bitly-style short URLs, supports multiple domains, records click analytics, can run a tiny redirect server, and includes helper commands for Cloudflare DNS/Workers and `@hasna/domains`. It defaults to local SQLite and
|
|
5
|
+
`shortlinks` creates Bitly-style short URLs, supports multiple domains, records click analytics, can run a tiny redirect server, and includes helper commands for Cloudflare DNS/Workers and `@hasna/domains`. It defaults to local SQLite and serves from an app-owned PostgreSQL database when `HASNA_SHORTLINKS_DATABASE_URL` is configured.
|
|
6
6
|
|
|
7
7
|
## Surfaces
|
|
8
8
|
|
|
@@ -15,19 +15,18 @@ Four surfaces share one core library:
|
|
|
15
15
|
| REST API | `shortlinks-serve` | HTTP service: `GET /health`, `/ready`, `/version`, `/openapi.json`, and a versioned `/v1` CRUD API guarded by API-key auth. |
|
|
16
16
|
| SDK | `@hasna/shortlinks-sdk` (+ `@hasna/shortlinks/sdk`) | Typed fetch client generated from the serve OpenAPI (`bun run sdk:generate`). |
|
|
17
17
|
|
|
18
|
-
###
|
|
18
|
+
### Hosted service
|
|
19
19
|
|
|
20
|
-
`shortlinks-serve` reads/writes
|
|
20
|
+
`shortlinks-serve` reads/writes PostgreSQL directly via the vendored `@hasna/contracts` storage kit — no sync engine or cache in the service. A configured `HASNA_SHORTLINKS_DATABASE_URL` selects the postgresql server data backend; the pool factory fails closed without it. API-key auth comes from `@hasna/contracts/auth`; mint keys with `contracts issue-key --app shortlinks --scopes 'shortlinks:read,shortlinks:write'`.
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
|
-
|
|
24
|
-
HASNA_SHORTLINKS_DATABASE_URL=postgres://user:pass@host:5432/shortlinks?sslmode=require \
|
|
23
|
+
HASNA_SHORTLINKS_DATABASE_URL=$DATABASE_URL \
|
|
25
24
|
HASNA_SHORTLINKS_API_SIGNING_KEY=... \
|
|
26
25
|
shortlinks-serve # migrate (idempotent) then serve on :8080
|
|
27
26
|
shortlinks-serve migrate # one-shot migration task
|
|
28
27
|
```
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
Clients use `SHORTLINKS_API_URL` + `SHORTLINKS_API_KEY` (never a DSN).
|
|
31
30
|
|
|
32
31
|
[](https://www.npmjs.com/package/@hasna/shortlinks)
|
|
33
32
|
[](LICENSE)
|
|
@@ -161,8 +160,8 @@ Create a dry-run plan:
|
|
|
161
160
|
|
|
162
161
|
```bash
|
|
163
162
|
shortlinks cloudflare plan has.na \
|
|
164
|
-
--target shortlinks.
|
|
165
|
-
--origin https://shortlinks.
|
|
163
|
+
--target shortlinks.example.com \
|
|
164
|
+
--origin https://shortlinks.example.com
|
|
166
165
|
```
|
|
167
166
|
|
|
168
167
|
Write a Cloudflare Worker that forwards requests to the redirect server while preserving the original host:
|
|
@@ -170,13 +169,13 @@ Write a Cloudflare Worker that forwards requests to the redirect server while pr
|
|
|
170
169
|
```bash
|
|
171
170
|
shortlinks cloudflare worker \
|
|
172
171
|
--worker shortlinks \
|
|
173
|
-
--origin https://shortlinks.
|
|
172
|
+
--origin https://shortlinks.example.com
|
|
174
173
|
```
|
|
175
174
|
|
|
176
175
|
Upsert DNS when `CLOUDFLARE_API_TOKEN` is available. Global API key auth is also supported with `CLOUDFLARE_API_KEY` plus `CLOUDFLARE_EMAIL`.
|
|
177
176
|
|
|
178
177
|
```bash
|
|
179
|
-
shortlinks cloudflare dns has.na --target shortlinks.
|
|
178
|
+
shortlinks cloudflare dns has.na --target shortlinks.example.com
|
|
180
179
|
```
|
|
181
180
|
|
|
182
181
|
## Buying Domains
|
|
@@ -190,28 +189,26 @@ shortlinks domain buy new-short-domain.ai --dry-run
|
|
|
190
189
|
|
|
191
190
|
This package does not install or call any removed `connect-*` packages.
|
|
192
191
|
|
|
193
|
-
## Storage
|
|
192
|
+
## Storage selection
|
|
194
193
|
|
|
195
194
|
The client resolves ONE `Store` from the environment — there is no DSN on any client:
|
|
196
195
|
|
|
197
|
-
- **
|
|
198
|
-
|
|
199
|
-
- **
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
code; only the URL/key differ.
|
|
196
|
+
- **on-box SQLite** (default): every command, MCP tool, and SDK call reads and
|
|
197
|
+
writes the local database.
|
|
198
|
+
- **hosted `/v1` HTTP API**: set `HASNA_SHORTLINKS_API_URL` + `HASNA_SHORTLINKS_API_KEY`
|
|
199
|
+
to route every call to the hosted `/v1` API with a bearer key. Setting only one
|
|
200
|
+
of the two is a configuration error and fails loudly — never silent local drift.
|
|
203
201
|
|
|
204
202
|
```bash
|
|
205
|
-
# Route the client to the
|
|
206
|
-
export HASNA_SHORTLINKS_API_URL=https://shortlinks.
|
|
203
|
+
# Route the client to the hosted API (bearer key, never a DSN):
|
|
204
|
+
export HASNA_SHORTLINKS_API_URL=https://shortlinks.example.com
|
|
207
205
|
export HASNA_SHORTLINKS_API_KEY=hsk_...
|
|
208
|
-
export HASNA_SHORTLINKS_STORAGE_MODE=self_hosted
|
|
209
206
|
shortlinks doctor
|
|
210
207
|
```
|
|
211
208
|
|
|
212
|
-
The
|
|
213
|
-
|
|
214
|
-
|
|
209
|
+
The server (`shortlinks-serve`) is the only component that holds a Postgres
|
|
210
|
+
connection, and it opens its pool server-side through the sanctioned storage
|
|
211
|
+
kit — the raw RDS DSN is never distributed to clients.
|
|
215
212
|
|
|
216
213
|
## Development
|
|
217
214
|
|
|
@@ -230,7 +227,7 @@ The OSS repository is expected to be:
|
|
|
230
227
|
hasna/shortlinks
|
|
231
228
|
```
|
|
232
229
|
|
|
233
|
-
The local workspace folder
|
|
230
|
+
The local workspace folder is named `shortlinks`; the published package and GitHub repo use bare names without the retired `open-` prefix.
|
|
234
231
|
|
|
235
232
|
## License
|
|
236
233
|
|