Initial Commit

This commit is contained in:
2026-05-27 23:29:53 +01:00
commit fbc70f96e6
10000 changed files with 1102152 additions and 0 deletions

View File

@@ -0,0 +1,129 @@
# OpenSpec Change: enterprise-server-caddy-imgproxy
- **Change ID**: enterprise-server-caddy-imgproxy
- **Package**: `@suaveplan/caddy-imgproxy`
- **Category**: server/infra
- **Target path**: `server/infra/caddy-imgproxy`
- **Status**: PROPOSED
- **Date**: 2026-04-24
- **Reference spec**: `/mnt/s/web/suaveplan/enterprise/caddy-imgproxy.md`
---
## Summary
Deliver `@suaveplan/caddy-imgproxy` on the genesis branch from scratch at enterprise quality. The package provides a typed TypeScript client and URL-builder for [imgproxy](https://imgproxy.net/) behind a Caddy reverse proxy. It generates HMAC-SHA256 signed imgproxy URLs for resize, crop, format conversion, quality, watermark, blur, and brightness operations. It does not spawn processes — it is a pure URL-generation and request-signing library with injectable `@suaveplan/crypto` for signing and Zod-validated option schemas.
---
## Current-state audit (genesis)
Does not exist on genesis — fresh build.
---
## Available workspace deps on genesis
| Package | Role |
|---|---|
| `@suaveplan/error` (`workspace:^`) | Typed `IMGPROXY.*` error codes |
| `@suaveplan/types` (`workspace:^`) | `LoggerLike` |
| `@suaveplan/crypto` (`workspace:^`) | HMAC-SHA256 signing |
| `zod` (`catalog:forms`) | Options validation |
| `@opentelemetry/api` (`catalog:observability`) | Counters |
| `tslib` (`catalog:build`) | Runtime helpers |
---
## Public API surface
```ts
class ImgproxyUrlBuilder {
constructor(options: ImgproxyOptions)
build(options: ImgproxyTransformOptions): string
buildSigned(options: ImgproxyTransformOptions): string
}
function createImgproxyUrlBuilder(options: ImgproxyOptions): ImgproxyUrlBuilder
interface ImgproxyOptions {
baseUrl: string
key?: string // hex-encoded signing key
salt?: string // hex-encoded salt
defaultQuality?: number
}
interface ImgproxyTransformOptions {
src: string // source image URL or S3 path
width?: number
height?: number
resizingType?: 'fit' | 'fill' | 'crop' | 'pad' | 'auto'
format?: 'webp' | 'avif' | 'jpeg' | 'png' | 'gif' | 'ico' | 'svg'
quality?: number
blur?: number
brightness?: number
contrast?: number
gravity?: 'sm' | 'ce' | 'no' | 'so' | 'ea' | 'we' | 'noea' | 'nowe' | 'soea' | 'sowe' | 'fp'
watermark?: WatermarkOptions
dpr?: number
enlarge?: boolean
extend?: boolean
}
interface WatermarkOptions {
opacity: number
position?: string
xOffset?: number
yOffset?: number
scale?: number
}
const ImgproxyOptionsSchema: z.ZodSchema<ImgproxyOptions>
const ImgproxyTransformOptionsSchema: z.ZodSchema<ImgproxyTransformOptions>
type ImgproxyErrorCode =
| 'IMGPROXY_INVALID_OPTIONS'
| 'IMGPROXY_SIGN_FAILED'
| 'IMGPROXY_INVALID_SOURCE_URL'
function registerImgproxyErrorCodes(): void
```
---
## File layout
```text
server/infra/caddy-imgproxy/
package.json
tsconfig.json
vitest.config.ts
src/
index.ts
error-codes.ts
constants/index.ts
types/
imgproxy.types.ts
imgproxy.types.md
builder/
imgproxy-url-builder/
imgproxy-url-builder.ts
imgproxy-url-builder.md
imgproxy-url-builder.types.ts
imgproxy-url-builder.test.ts
index.ts
utils/
path-encoder.ts
path-encoder.md
path-encoder.test.ts
tests/
integration.test.ts
```
---
## Impact
Downstream: any package needing image transformation URLs (file upload API, media service, CDN pipeline). Pure URL generation — no network required.
**Prerequisites on Verdaccio**: `@suaveplan/error`, `@suaveplan/types`, `@suaveplan/crypto`.

View File

@@ -0,0 +1,62 @@
# Tasks: enterprise-server-caddy-imgproxy
**Change ID**: enterprise-server-caddy-imgproxy
**Package**: `@suaveplan/caddy-imgproxy`
**Target path**: `server/infra/caddy-imgproxy`
**Prerequisites on Verdaccio**: `@suaveplan/error`, `@suaveplan/types`, `@suaveplan/crypto`
---
## 0. Pre-flight (non-negotiable)
- [ ] 0.1 Confirm clean working tree (`git status` reports nothing) and no in-flight worktrees with uncommitted work (`git worktree list` then `git status` in each)
- [ ] 0.2 If any worktrees exist under `.claude/worktrees/`, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (`git worktree remove`) before opening a new one — code that has been lost twice on main is the failure mode this guards against.
- [ ] 0.3 Confirm the package set in `MANIFEST.md` matches `find packages -maxdepth 3 -name package.json` count. Drift here means a prior change archived without regenerating the manifest.
## 1. Scaffold
- [ ] Create directory tree per `proposal.md`.
- [ ] `package.json` at `0.1.0`, `"sideEffects": false`, exports `"."` + `builder` + `utils/path-encoder`.
- [ ] Deps: `@suaveplan/error workspace:^`, `@suaveplan/types workspace:^`, `@suaveplan/crypto workspace:^`, `zod catalog:forms`, `@opentelemetry/api catalog:observability`, `tslib catalog:build`.
- [ ] DevDeps: `vitest catalog:testing`, `@vitest/coverage-istanbul catalog:testing`, `@suaveplan/testing workspace:^`.
- [ ] `tsconfig.json` extending `library.json`; `vitest.config.ts` with `createTestConfig()`.
- [ ] Scripts: `lint`, `typecheck`, `test`, `test:coverage`, `build`, `docs:check`.
## 2. Types and errors
- [ ] Define all option interfaces and Zod schemas in `src/types/imgproxy.types.ts`.
- [ ] Write `imgproxy.types.md` (≥200 words, both examples, API reference).
- [ ] `src/error-codes.ts`: three codes; `registerImgproxyErrorCodes()`; eager call.
## 3. Path encoder utility
- [ ] Implement `src/utils/path-encoder.ts`:
- `encodeSourceUrl(url: string): string` — URL-safe base64 encode of source URL; throw `IMGPROXY_INVALID_SOURCE_URL` on empty/invalid input.
- `buildProcessingPath(opts: ImgproxyTransformOptions): string` — assemble the imgproxy processing chain string (e.g. `rs:fit:800:600/q:80/f:webp/...`).
- [ ] Write `path-encoder.test.ts`: each processing option produces correct segment; empty source throws; combined options produce correct path.
- [ ] Write `path-encoder.md` (≥200 words).
## 4. URL builder
- [ ] Implement `ImgproxyUrlBuilder` in `src/builder/imgproxy-url-builder/imgproxy-url-builder.ts`:
- `build(opts)`: validate via `ImgproxyTransformOptionsSchema`; call `buildProcessingPath`; encode source; return `${baseUrl}/insecure/${processingPath}/${encodedSource}`.
- `buildSigned(opts)`: same path; compute HMAC-SHA256 signature using `@suaveplan/crypto` with key/salt; return `${baseUrl}/${signature}/${processingPath}/${encodedSource}`. Throw `IMGPROXY_SIGN_FAILED` if key/salt not configured.
- OTel counter `imgproxy.urls_built_total` with `signed` attribute.
- [ ] Export `createImgproxyUrlBuilder(options)`.
- [ ] Write `imgproxy-url-builder.types.ts`.
- [ ] Write `imgproxy-url-builder.test.ts` (≤500 lines): unsigned URL format, signed URL HMAC verification against known test vector from imgproxy docs, all transform options produce correct segments, invalid options throw typed error.
- [ ] Write `imgproxy-url-builder.md` (≥200 words, simple + advanced, API reference).
## 5. Integration tests
- [ ] `tests/integration.test.ts`: build several real URLs and verify they match known imgproxy signature test vectors; verify path encoding round-trips; signed vs unsigned URL format diff.
## 6. Docs + verify + publish
- [ ] Root `README.md`: docker-compose Caddy + imgproxy example, quick-start URL building, API table, signing setup.
- [ ] `bunx turbo lint --filter=@suaveplan/caddy-imgproxy` — zero errors.
- [ ] `bunx turbo typecheck --filter=@suaveplan/caddy-imgproxy` — zero errors.
- [ ] `bunx turbo test --filter=@suaveplan/caddy-imgproxy` — all pass.
- [ ] `bunx turbo test:coverage --filter=@suaveplan/caddy-imgproxy` — 100%.
- [ ] `bun scripts/publish.ts --package @suaveplan/caddy-imgproxy`.
- [ ] Update `CLAUDE.md`; archive to `openspec/archive/2026-04-24-enterprise-server-caddy-imgproxy/`.