@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 CHANGED
@@ -1,9 +1,34 @@
1
1
  # @hasna/shortlinks
2
2
 
3
- CLI-only shortlink management for custom domains.
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
  [![npm](https://img.shields.io/npm/v/@hasna/shortlinks)](https://www.npmjs.com/package/@hasna/shortlinks)
8
33
  [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](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
- ## PostgreSQL Runtime
152
+ ## Storage modes
128
153
 
129
- Production serving can use a shortlinks-owned PostgreSQL database without any shared table-sync package:
154
+ The client resolves ONE `Store` from the environment there is no DSN on any client:
130
155
 
131
- ```bash
132
- export HASNA_SHORTLINKS_STORE=postgres
133
- export HASNA_SHORTLINKS_DATABASE_URL=postgres://shortlinks:password@db.example.com:5432/shortlinks
134
- export HASNA_SHORTLINKS_DATABASE_SSL=true
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
- shortlinks postgres status
137
- shortlinks postgres plan --schema-sql
138
- shortlinks postgres migrate
139
- shortlinks --store postgres serve --host 127.0.0.1 --port 8787 --default-host has.na
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 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.
143
-
144
- ## AWS Origin
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