@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 CHANGED
@@ -1,8 +1,33 @@
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
- `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, `@hasna/domains`, and `@hasna/cloud` sync. Production serving can run directly against the shared RDS database with `--cloud`; local SQLite is only for explicit local/offline use.
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
  [![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)
@@ -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
- ## Cloud Sync
152
+ ## PostgreSQL Runtime
129
153
 
130
- `shortlinks` is compatible with `@hasna/cloud` conventions:
154
+ Production serving can use a shortlinks-owned PostgreSQL database without any shared table-sync package:
131
155
 
132
156
  ```bash
133
- cloud setup
134
- shortlinks cloud migrate
135
- shortlinks cloud push
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
- The cloud database service name is `shortlinks`.
141
- Use direct RDS mode for production and live management:
142
-
143
- ```bash
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` RDS database through `@hasna/cloud`
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 RDS password from AWS Secrets Manager through the instance role; it does not contain secret values.
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