@hasna/shortlinks 0.1.22 → 0.1.24
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 +40 -20
- package/dist/cli/index.js +2507 -2019
- package/dist/cloudflare.js +141 -4
- package/dist/db/migrations.d.ts +20 -0
- package/dist/generated/storage-kit/health.d.ts +19 -0
- package/dist/generated/storage-kit/index.d.ts +7 -0
- package/dist/generated/storage-kit/migrations.d.ts +47 -0
- package/dist/generated/storage-kit/mode.d.ts +47 -0
- package/dist/generated/storage-kit/pool.d.ts +33 -0
- package/dist/generated/storage-kit/query.d.ts +35 -0
- package/dist/generated/storage-kit/tls.d.ts +25 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +3139 -232
- package/dist/mcp/http.d.ts +16 -0
- package/dist/mcp/index.d.ts +14 -0
- package/dist/mcp/index.js +1493 -0
- package/dist/pg-store.d.ts +20 -2
- package/dist/pg-store.js +913 -0
- package/dist/runtime.d.ts +65 -0
- package/dist/runtime.js +214 -0
- package/dist/sdk/generated.d.ts +178 -0
- package/dist/sdk/index.d.ts +12 -0
- package/dist/sdk/index.js +500 -0
- package/dist/serve/app.d.ts +21 -0
- package/dist/serve/index.d.ts +14 -0
- package/dist/serve/index.js +8817 -0
- package/dist/serve/openapi.d.ts +8 -0
- package/dist/server.js +33 -0
- package/infra/aws-ec2-user-data.sh +32 -31
- package/package.json +29 -7
package/README.md
CHANGED
|
@@ -1,8 +1,33 @@
|
|
|
1
1
|
# @hasna/shortlinks
|
|
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
|
|
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 can serve from an app-owned PostgreSQL database when `HASNA_SHORTLINKS_STORE=postgres` and `HASNA_SHORTLINKS_DATABASE_URL` are configured.
|
|
6
|
+
|
|
7
|
+
## Surfaces
|
|
8
|
+
|
|
9
|
+
Four surfaces share one core library:
|
|
10
|
+
|
|
11
|
+
| Surface | Bin / package | Purpose |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| CLI | `shortlinks` | Interactive/scriptable link + domain management (`--json` for agents). |
|
|
14
|
+
| MCP | `shortlinks-mcp` | Model Context Protocol server (stdio or `--http`) exposing link/domain tools to agents. |
|
|
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
|
+
| SDK | `@hasna/shortlinks-sdk` (+ `@hasna/shortlinks/sdk`) | Typed fetch client generated from the serve OpenAPI (`bun run sdk:generate`). |
|
|
17
|
+
|
|
18
|
+
### Cloud service (PURE REMOTE, Amendment A1)
|
|
19
|
+
|
|
20
|
+
`shortlinks-serve` reads/writes the shared cloud Postgres directly via the vendored `@hasna/contracts` storage kit — no sync engine or cache in the service. API-key auth comes from `@hasna/contracts/auth`; mint keys with `contracts issue-key --app shortlinks --scopes 'shortlinks:read,shortlinks:write'`.
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
HASNA_SHORTLINKS_STORAGE_MODE=cloud \
|
|
24
|
+
HASNA_SHORTLINKS_DATABASE_URL=postgres://user:pass@host:5432/shortlinks?sslmode=require \
|
|
25
|
+
HASNA_SHORTLINKS_API_SIGNING_KEY=... \
|
|
26
|
+
shortlinks-serve # migrate (idempotent) then serve on :8080
|
|
27
|
+
shortlinks-serve migrate # one-shot migration task
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Client self_hosted mode uses `SHORTLINKS_API_URL` + `SHORTLINKS_API_KEY` (never a DSN).
|
|
6
31
|
|
|
7
32
|
[](https://www.npmjs.com/package/@hasna/shortlinks)
|
|
8
33
|
[](LICENSE)
|
|
@@ -64,7 +89,6 @@ shortlinks link enable home --domain has.na
|
|
|
64
89
|
shortlinks stats home --domain has.na
|
|
65
90
|
|
|
66
91
|
shortlinks serve --port 8787
|
|
67
|
-
shortlinks serve --cloud --port 8787
|
|
68
92
|
shortlinks doctor
|
|
69
93
|
```
|
|
70
94
|
|
|
@@ -125,36 +149,32 @@ shortlinks domain buy new-short-domain.ai --dry-run
|
|
|
125
149
|
|
|
126
150
|
This package does not install or call any removed `connect-*` packages.
|
|
127
151
|
|
|
128
|
-
##
|
|
152
|
+
## PostgreSQL Runtime
|
|
129
153
|
|
|
130
|
-
|
|
154
|
+
Production serving can use a shortlinks-owned PostgreSQL database without any shared table-sync package:
|
|
131
155
|
|
|
132
156
|
```bash
|
|
133
|
-
|
|
134
|
-
shortlinks
|
|
135
|
-
|
|
136
|
-
shortlinks cloud pull
|
|
137
|
-
shortlinks cloud sync
|
|
138
|
-
```
|
|
157
|
+
export HASNA_SHORTLINKS_STORE=postgres
|
|
158
|
+
export HASNA_SHORTLINKS_DATABASE_URL=postgres://shortlinks:password@db.example.com:5432/shortlinks
|
|
159
|
+
export HASNA_SHORTLINKS_DATABASE_SSL=true
|
|
139
160
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
shortlinks --cloud create https://example.com
|
|
145
|
-
shortlinks --cloud link list
|
|
146
|
-
shortlinks serve --cloud --host 127.0.0.1 --port 8787
|
|
161
|
+
shortlinks postgres status
|
|
162
|
+
shortlinks postgres plan --schema-sql
|
|
163
|
+
shortlinks postgres migrate
|
|
164
|
+
shortlinks --store postgres serve --host 127.0.0.1 --port 8787 --default-host has.na
|
|
147
165
|
```
|
|
148
166
|
|
|
167
|
+
The canonical production runtime secret path is `hasna/xyz/opensource/shortlinks/prod/postgres`. Use the URL environment variables above rather than writing shared runtime config files into the shortlinks data directory.
|
|
168
|
+
|
|
149
169
|
## AWS Origin
|
|
150
170
|
|
|
151
171
|
For an apex domain that needs stable A records, `infra/aws-ec2-user-data.sh` bootstraps a small EC2 redirect origin with:
|
|
152
172
|
|
|
153
173
|
- `@hasna/shortlinks` installed through Bun
|
|
154
|
-
- direct reads and click writes against the `shortlinks`
|
|
174
|
+
- direct reads and click writes against the app-owned `shortlinks` PostgreSQL database
|
|
155
175
|
- Caddy terminating HTTPS and proxying to `shortlinks serve`
|
|
156
176
|
|
|
157
|
-
The script reads the
|
|
177
|
+
The script reads the connection settings from AWS Secrets Manager through the instance role; it does not contain secret values.
|
|
158
178
|
|
|
159
179
|
## Development
|
|
160
180
|
|