@hasna/shortlinks 0.1.23 → 0.2.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/README.md +43 -22
- package/dist/cli/index.js +8356 -2500
- package/dist/client-store.d.ts +47 -0
- package/dist/cloud-store.d.ts +46 -0
- 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 +7 -4
- package/dist/index.js +9424 -523
- package/dist/mcp/http.d.ts +26 -0
- package/dist/mcp/index.d.ts +15 -0
- package/dist/mcp/index.js +7429 -0
- package/dist/pg-store.d.ts +16 -10
- package/dist/pg-store.js +190 -133
- 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 +8521 -0
- package/dist/serve/openapi.d.ts +8 -0
- package/dist/server.js +33 -0
- package/dist/store-interface.d.ts +37 -0
- package/package.json +18 -8
- package/dist/pg-migrations.d.ts +0 -1
- package/dist/runtime.d.ts +0 -65
- package/dist/runtime.js +0 -181
package/README.md
CHANGED
|
@@ -1,9 +1,34 @@
|
|
|
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
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
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).
|
|
31
|
+
|
|
7
32
|
[](https://www.npmjs.com/package/@hasna/shortlinks)
|
|
8
33
|
[](LICENSE)
|
|
9
34
|
|
|
@@ -124,32 +149,28 @@ shortlinks domain buy new-short-domain.ai --dry-run
|
|
|
124
149
|
|
|
125
150
|
This package does not install or call any removed `connect-*` packages.
|
|
126
151
|
|
|
127
|
-
##
|
|
152
|
+
## Storage modes
|
|
128
153
|
|
|
129
|
-
|
|
154
|
+
The client resolves ONE `Store` from the environment — there is no DSN on any client:
|
|
130
155
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
156
|
+
- **local** (default): on-box SQLite. Every command, MCP tool, and SDK call reads
|
|
157
|
+
and writes the local database.
|
|
158
|
+
- **self_hosted / cloud**: set `HASNA_SHORTLINKS_API_URL` + `HASNA_SHORTLINKS_API_KEY`
|
|
159
|
+
(and optionally `HASNA_SHORTLINKS_STORAGE_MODE`) to route every call to the cloud
|
|
160
|
+
`/v1` HTTP API with a bearer key. `self_hosted` and `cloud` are identical client
|
|
161
|
+
code; only the URL/key differ.
|
|
135
162
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
shortlinks
|
|
139
|
-
|
|
163
|
+
```bash
|
|
164
|
+
# Route the client to the self-hosted cloud API (bearer key, never a DSN):
|
|
165
|
+
export HASNA_SHORTLINKS_API_URL=https://shortlinks.hasna.xyz
|
|
166
|
+
export HASNA_SHORTLINKS_API_KEY=hsk_...
|
|
167
|
+
export HASNA_SHORTLINKS_STORAGE_MODE=self_hosted
|
|
168
|
+
shortlinks doctor
|
|
140
169
|
```
|
|
141
170
|
|
|
142
|
-
The
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
For an apex domain that needs stable A records, `infra/aws-ec2-user-data.sh` bootstraps a small EC2 redirect origin with:
|
|
147
|
-
|
|
148
|
-
- `@hasna/shortlinks` installed through Bun
|
|
149
|
-
- direct reads and click writes against the app-owned `shortlinks` PostgreSQL database
|
|
150
|
-
- Caddy terminating HTTPS and proxying to `shortlinks serve`
|
|
151
|
-
|
|
152
|
-
The script reads the connection settings from AWS Secrets Manager through the instance role; it does not contain secret values.
|
|
171
|
+
The cloud server (`shortlinks-serve`, run on ECS Fargate) is the only component
|
|
172
|
+
that holds a Postgres connection, and it opens its pool server-side through the
|
|
173
|
+
sanctioned storage kit — the raw RDS DSN is never distributed to clients.
|
|
153
174
|
|
|
154
175
|
## Development
|
|
155
176
|
|