Skip to content

Feat/optimise#86

Open
ajaysinghj8 wants to merge 51 commits intomasterfrom
feat/optimise
Open

Feat/optimise#86
ajaysinghj8 wants to merge 51 commits intomasterfrom
feat/optimise

Conversation

@ajaysinghj8
Copy link
Copy Markdown
Owner

No description provided.

ajaysinghj8 and others added 30 commits March 23, 2026 05:35
…mary, purge safety

- nameSpaceHandler: match both /path and /path/ against allow/deny glob patterns
  so trailing-slash requests are handled consistently without pattern-specific quirks
- config.reader: warn on unknown namespace keys (with list of known keys) to catch
  typos before they silently become no-ops
- index.ts: print a human-readable startup summary of config version, enabled features,
  and each namespace (expose→target, cache config, allow/deny lists)
- purgeCache: add broadPatternWarning() — purge responses include a 'warning' field
  when the pattern lacks the 'O:<namespace>' prefix that scopes it to one namespace;
  add optional OSHAM_PURGE_SECRET env-var gate: if set, callers must supply the value
  in x-osham-purge-secret header or receive 401
- tests: 9 new cases covering trailing-slash allow/deny, single-star depth enforcement,
  nested precedence, unknown-key warnings, broad-pattern warning, and purge auth

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- config.reader: add KNOWN_TOP_LEVEL_KEYS set and warn on unknown top-level
  scalar keys (e.g. 'purges: true' as a typo for 'purge: true') instead of
  silently treating them as namespace candidates and throwing a confusing error
- config.reader: filter namespaceKeys to only object-valued non-reserved keys
  so typo scalars are skipped cleanly after the warning
- test: add two new Config Validation tests covering top-level unknown key
  warnings and the absence of warnings on all known top-level keys
- docs/purge-cache.md: document OSHAM_PURGE_SECRET authentication, explain
  the broad-pattern warning, and expand the security guidance section

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…es 1+2)

Adds /__osham/admin/* route foundation with shared-secret auth middleware
(OSHAM_ADMIN_SECRET / x-osham-admin-secret header), plus four config endpoints:

  GET  /__osham/admin/config           – return structured IFullConfig + meta
  POST /__osham/admin/config/validate  – validate proposed config, return errors/warnings
  PUT  /__osham/admin/config           – validate + atomically save to cache-config.yml
  POST /__osham/admin/config/reload    – re-read file, update in-memory admin state

New files:
  src/admin.state.ts              – shared admin state (config, meta, revision)
  src/middlewares/adminConfig.ts  – all admin route handlers

Changes:
  src/config.reader.ts  – add validateConfigCollecting() (collects errors/warnings, no throw)
  src/index.ts          – initialise admin state at startup; mount AdminConfig middleware
  test/index.js         – 14 new tests covering auth and all four config endpoints

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Purge page:
- Loading state; button disabled while request in flight
- Client-side broad-pattern warning (*, **) shown before submit
- Confirmation checkbox required for all live (non-dry-run) purges;
  danger styling when pattern is also broad
- Result rendered as structured card (status pill, deleted count,
  backend warnings) instead of raw JSON dump
- Pattern/dryRun changes clear stale result and confirmation state

Audit page:
- Loading state with disabled Refresh button during fetch
- Refresh button to manually re-poll without page reload
- Timestamps formatted via toLocaleString() instead of raw ISO
- Fifth column "Details" surfaces key fields from AuditEvent.details
  (pattern + deleted count for purge events, revision for config events)
- Result column uses status-pill with enabled/disabled color coding
- Empty-state message when no events have been recorded yet

Styles:
- .purge-warning / .purge-warning--danger alert banners
- .purge-result / .purge-result-row structured result card

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ajaysinghj8 and others added 21 commits March 24, 2026 16:43
Adds a parallel build-admin-ui job that installs dependencies and builds
the admin-ui sidecar on every push and pull request.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- proxy/index.ts: remove stale comment block (headers already written via writeHeaders)
- ctx.provider.ts: guard setHeader calls behind headersSent check
- timeoutMiddleware.ts: destroy socket on timeout to prevent connection leaks

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Auto-refresh: metrics every 30s, dashboard every 60s
- Countdown timer and last-refreshed timestamp in toolbar
- Hit ratio color badges (green >=80%, yellow 50-79%, red <50%) with progress bars
- Namespace table sorted by requests descending
- Descriptive empty state when no namespace traffic yet
- Empty state with instructions when metrics are disabled
- Dashboard: uptime display from health response

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- docs/troubleshooting.md: covers server startup failures, cache misses,
  allow/deny 403s, purge auth/patterns, metrics config, admin UI auth,
  and latency/pool timeout issues
- docs/contributor-setup.md: prerequisites, install, build, test, lint,
  admin-ui dev server, project structure, how to add a test, PR guidelines
- README.md: replace stale cache-config.example.yml reference, expand
  Contributing section with links to new docs, add Troubleshooting section

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- npm audit fix: resolved 38 vulnerabilities (67 → 29), all in
  transitive dev/perf-test dependencies
- follow-redirects: ^1.13.1 → ^1.15.11 (runtime dep, HIGH severity
  CVEs: proxy-auth header leak, sensitive info exposure)

Remaining 29 vulnerabilities are in devDependencies only
(mocha-typescript, artillery, eslint toolchain) and do not
ship with the published package.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…sed API

Storage layer:
- IStorage: callbacks → async/await (set/get/del/purgeByPattern)
- MemStore: rewritten with async methods, simplified TTL handling
- RedisStore: new class using redis@4 (createClient, scanIterator, isReady)
  connects in the background (same behaviour as redis@3)
- cache.service.ts: remove manual Promise wrapping, use async/await directly
  purgeByPattern simplifies (no manual SCAN+DEL fallback needed)

Build fixes:
- @types/redis removed (redis@4 ships its own types)
- @types/node: ^14.14 → ^14.18 (adds AbortSignal required by redis@4)
- ctx.provider.ts: void res.end() return (stricter ServerResponse type)

All 81 tests pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
toPromise() rejects with a plain object for non-2xx responses and
connection errors. All three proxy call sites in nameSpaceHandler were
missing a catch, so these rejections bubbled up to the top-level
handleError as unhandled exceptions, producing the misleading
'Unhandled request error: [object Object]' log.

Fix: .catch(err => err) at each await site so non-2xx responses are
treated as valid (error) responses and forwarded to the client.

Also improve handleError serialisation in index.ts so plain objects
produce readable JSON in logs rather than '[object Object]'.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…match

hasUnsavedChanges compared compact JSON (lastSavedSnapshot) against
pretty-printed JSON (previewState.rawJson), so they never matched and
the rollback button was permanently disabled. Fixed by aligning both
to JSON.stringify(..., null, 2).

Also deduplicate revision history by revision hash and raise the
visible cap from 8 → 15 so older snapshots (e.g. a29e0ed3) are
reachable in the UI.

fix(proxy): add request/response debug logging (path, headers, status)
refactor(config): avoid mutating shared cache/rules config objects in ConfigContext
test: add proxy error forwarding tests for 4xx/5xx passthrough

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…topbar

- styles.css: full rewrite with CSS custom properties (colours, spacing,
  radii), new topbar + sidebar collapse styles, refreshed cards/buttons/tables
- TopBar: new fixed header with page title, live health/cache/requests/hit-ratio
  chips (30s poll), admin secret key-icon popover replacing AdminSecretBar card
- Sidebar: inline SVG icons per nav item, collapse toggle button, icon-only mode
  at 52px with tooltip fallback, smooth 200ms width transition
- router.tsx: AdminLayout manages collapsed state + localStorage persistence,
  wires TopBar + Sidebar + content-shell, removes AdminSecretBar from layout
- Page.tsx: remove h1 title (now in TopBar), keep optional subtitle

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- ConfigPage: replace single-scroll with Global / Namespaces / History tabs
- Global tab: compact revision info bar, feature toggles in a clean grid,
  footer action bar (Validate / Save / Reload / Refresh / Reset / Export / Import)
- Namespaces tab: left namespace list panel + right form panel with
  collapsible sections (Cache, Access Control, Rules, Advanced) that open
  based on existing data; Add/Clone/Delete per-panel
- History tab: clean timeline list with revision hash, date, type badge,
  and per-row rollback button
- Preview moved to a slide-in drawer (overlay + right panel), toggled from
  tab bar; supports YAML/JSON toggle and copy to clipboard
- Status messages replaced with coloured banners (info/error/warn)
- styles.css: Phase 2 additions — tabs, split panel, collapsible, history,
  preview drawer, feature-toggle grid, revision-info bar
- Page.tsx: make title prop optional (title now lives in TopBar)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- DashboardPage: stat-rows, service-status pills for health/cache, cfg-banner errors, refresh-bar toolbar
- MetricsPage: big-stat numbers in summary cards, stat-rows in detail cards, cfg-banner errors
- HealthPage: stat-rows, service-status pills for service/cache status, cfg-banner errors
- PurgePage: cfg-banner error display
- AuditPage: cfg-banner error, remove hardcoded colors (text-muted utility), mono class for action codes
- styles.css: add .text-muted utility class

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…reams

Logging improvements:
- ctx.provider: respond() now logs method, path, status, cache result, key, and timing
  instead of the bare "responding" message
- ctx.provider: set() error includes header name, value, and error message
- proxy: single "→ METHOD path → target" request line; drop redundant headers/options dumps
- proxy: response log includes method; error log includes method, error code, and full target URL
- proxy: abort event has its own descriptive log
- nameSpaceHandler: merge "matched" + "will be processed" into one "→ METHOD path" line;
  fix inverted bypass-reason ternary; add path to pool logs; consistent [pool] casing
- cache.service: collapse put before/after into single post-write log with TTL;
  rename "failed cache" → "miss", "From cache" → "hit"

insecureSkipVerify support:
- Add insecureSkipVerify?: boolean to INameSpaceOptions and IProxyOptions
- When true on an https target, sets rejectUnauthorized: false on the request options
  so self-signed / untrusted upstream certs are accepted
- Logs a startup warning when the flag is active
- Validated and passed through config.reader; added to KNOWN_NAMESPACE_KEYS

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Collapses the curried helper into a proper method on the Context class,
making call sites read as ctx.respondWith(response, headers). Also
simplifies fire-and-forget promise chains in nameSpaceHandler to use
two-argument .then(onSuccess, onError) instead of chained .then/.catch.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…leshooting

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…server

- Multi-stage Dockerfile: builds admin-ui (Vite), builds server (tsc), assembles lean production image
- Add AdminUI static file middleware to serve admin-ui/dist at / and /admin/* with SPA fallback
- Register AdminUI middleware between AdminConfig and DynamicRuntime
- Add .dockerignore to exclude node_modules, build artifacts, and .env
- Fix adminConfig PUT /config to call setAdminState after saving so live config updates immediately

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fixes TypeScript error in Docker build where js-yaml types were
previously resolved from root node_modules via hoisting.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…rted

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant