@camada/hono 0.3.0 → 0.3.1

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/dist/index.cjs CHANGED
@@ -51,7 +51,7 @@ function resolveEnv(opts, env) {
51
51
  const ingestToken = key?.ingestToken ?? env.CAMADA_TOKEN;
52
52
  const snapToken = key?.snapToken ?? env.CAMADA_SNAPSHOT_TOKEN;
53
53
  if (!ingestToken || !snapToken) return null;
54
- const ingestUrl = (opts.ingestUrl || env.CAMADA_INGEST_URL || "https://in.camada.dev").replace(/\/$/, "");
54
+ const ingestUrl = (opts.ingestUrl || env.CAMADA_INGEST_URL || "https://in.camada.app").replace(/\/$/, "");
55
55
  return {
56
56
  ingestToken,
57
57
  snapToken,
@@ -87,7 +87,7 @@ function scriptTag(c) {
87
87
 
88
88
  // package.json
89
89
  var name = "@camada/hono";
90
- var version = "0.3.0";
90
+ var version = "0.3.1";
91
91
 
92
92
  // src/version.ts
93
93
  var SDK_ID = `${name}/${version}`;
@@ -204,6 +204,7 @@ function camada(opts = {}) {
204
204
  const scriptPath = opts.scriptPath ?? SCRIPT_PATH;
205
205
  const fpPath = opts.fpPath ?? FP_PATH;
206
206
  return async function camadaHono(c, next) {
207
+ const t0 = Date.now();
207
208
  const env = (0, import_core3.guarded)(() => ({ ...c.env, ...opts.env }), {});
208
209
  const eng = (0, import_core3.guarded)(() => env.CAMADA_DISABLED === "1" ? null : ensure(opts, env), null);
209
210
  if (!eng) return next();
@@ -282,6 +283,7 @@ function camada(opts = {}) {
282
283
  if (Math.random() >= (cfg?.sample ?? 1)) return;
283
284
  const ev = buildEvent(req, path, url.search, ip, vars?.sid ?? null, vars?.rid, newSession);
284
285
  ev.st = c.res.status;
286
+ ev.dur = Math.max(0, Date.now() - t0);
285
287
  if (warnRule) ev.wrn = warnRule;
286
288
  ship(eng, ev, waitUntil);
287
289
  }, void 0);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/camada.ts","../src/env.ts","../src/context.ts","../package.json","../src/version.ts"],"sourcesContent":["// @camada/hono — the one-line install for a Hono app on Cloudflare Workers:\n// app.use('*', camada()); // env: CAMADA_KEY (+ CAMADA_INGEST_URL / CAMADA_SNAPSHOT_URL in dev)\n// c.html(`<head>${scriptTag(c)}</head>…`) // the first-party beacon\n// track(c, 'login_failed', { user }) // an outcome the wire cannot show\nexport { camada, resetCamada } from './camada.js';\nexport { track, scriptTag } from './context.js';\nexport { resolveEnv, type CamadaHonoOptions, type ResolvedEnv } from './env.js';\n","// @camada/hono — the Hono middleware for Cloudflare Workers (SEC-07, D33).\n// app.use('*', camada());\n// Workers-native: `cf-connecting-ip` for the client address, `request.cf` for asn / country /\n// TLS fingerprint (so ASN and country rules really enforce at this tap), and\n// `c.executionCtx.waitUntil` so the snapshot poll and the event flush outlive the response.\n// Everything runs inside camada's fail-open envelope: a camada bug, a dead ingest or a corrupt\n// snapshot costs telemetry, never the app's response.\nimport type { Context, MiddlewareHandler, Next } from 'hono';\nimport iife from '@camada/browser/iife-string';\nimport {\n SnapshotClient, EventQueue, buildWireEvent, resolveClientIp, logRateLimited, guardedAsync,\n guarded, createChallengeAsync, challengePage, challengeCookie, safeReturnTo, wantsHtml, parseFormBody,\n CHALLENGE_COOKIE, DEFAULT_SNAPSHOT_VERSION, TAP_HONO,\n type AsyncChallengeKit, type TrustedProxyConfig, type WireEvent,\n} from '@camada/core';\nimport { resolveEnv, type CamadaHonoOptions, type ResolvedEnv } from './env.js';\nimport { VAR, beaconEnabled, type CamadaVars } from './context.js';\nimport { SDK_ID } from './version.js';\n\nconst DEFAULT_CHALLENGE_PATH = '/__camada/challenge';\nconst SCRIPT_PATH = '/_cam/b.js'; // the beacon IIFE; its auto-init posts to the sibling `fp` and reads the rid from ?r=\nconst FP_PATH = '/_cam/fp';\nconst FP_MAX = 32 * 1024; // matches the analyst's /fp cap: never accept what ingest will 413\nconst SESSION_COOKIE = '_sfp'; // the same session cookie as every other tap: sid/ns stay comparable\nconst SESSION_MAX_AGE = 2592000;\nconst BODY_MAX = 4 * 1024; // the verify form is ~120 bytes; anything larger is not ours\nconst encoder = new TextEncoder();\n\nexport interface Engine {\n env: ResolvedEnv;\n snap: SnapshotClient;\n queue: EventQueue;\n kit: AsyncChallengeKit;\n}\n\nexport type WaitUntil = (p: Promise<unknown>) => void;\n\n// One engine per resolved configuration, not per module: a Workers isolate can host several\n// Hono apps, and a shared singleton would enforce the first tenant's snapshot on the second\n// and sign its `_cch` cookies with the first tenant's secret. An unconfigured request is never\n// cached — a warm-up or a differently-keyed mount must not leave the isolate inert for good.\nconst engines = new Map<string, Engine>();\n\n/** Test/reset hook: drops every cached engine. */\nexport function resetCamada(): void {\n for (const e of engines.values()) { e.snap.stop(); e.queue.stop(); }\n engines.clear();\n}\n\nfunction ensure(opts: CamadaHonoOptions, ctxEnv: Record<string, string | undefined>): Engine | null {\n const env = resolveEnv(opts, ctxEnv);\n if (!env) {\n logRateLimited(new Error('CAMADA_KEY not set — camada is inactive'));\n return null;\n }\n const snapshotVersion = opts.snapshotVersion ?? DEFAULT_SNAPSHOT_VERSION;\n const id = `${env.ingestToken}|${env.ingestUrl}|${env.snapshotUrl}|${snapshotVersion}`;\n const cached = engines.get(id);\n if (cached) return cached;\n const injected = opts.fetchImpl ? { fetchImpl: opts.fetchImpl } : {}; // never pass an explicit undefined key\n const engine: Engine = {\n env,\n snap: new SnapshotClient({\n url: env.snapshotUrl, token: env.snapToken, mode: 'lazy', sdk: SDK_ID,\n snapshotVersion, ...injected,\n }),\n queue: new EventQueue({ url: env.ingestUrl, token: env.ingestToken, sdk: SDK_ID, ...injected }),\n kit: createChallengeAsync({ secret: env.secret }),\n };\n engines.set(id, engine);\n return engine;\n}\n\nconst cookieValue = (cookie: string, name: string): string | null => {\n const src = '; ' + cookie;\n const i = src.indexOf('; ' + name + '=');\n if (i === -1) return null;\n const start = i + name.length + 3;\n const j = src.indexOf(';', start);\n return src.slice(start, j === -1 ? undefined : j);\n};\n\ninterface CfProps { asn?: number; country?: string; tlsClientExtensionsSha1?: string; httpProtocol?: string }\nconst cfOf = (req: Request): CfProps => ((req as Request & { cf?: CfProps }).cf ?? {});\n\nconst trustedProxy = (e: Engine): TrustedProxyConfig | null =>\n e.env.trustedProxy ?? e.snap.config?.trusted_proxy ?? null;\n\n/** Cloudflare sets `cf-connecting-ip` itself and a client cannot forge it — but only on\n * Workers, which is also the only place `request.cf` exists. On any other Hono runtime\n * (node-server, Bun, Deno) that header is attacker-controlled, so it is ignored there and the\n * trusted-proxy rules decide, exactly as they do for X-Forwarded-For. */\nconst clientIp = (e: Engine, req: Request): string | null => {\n const cf = (req as Request & { cf?: unknown }).cf;\n const direct = cf ? req.headers.get('cf-connecting-ip') : null;\n return direct || resolveClientIp(null, req.headers.get('x-forwarded-for'), trustedProxy(e));\n};\n\ninterface RequestFacts {\n url: URL;\n path: string;\n cf: CfProps;\n ip: string | null;\n sid: string | null;\n}\n\nfunction describeRequest(e: Engine, req: Request): RequestFacts {\n const url = new URL(req.url);\n const cookies = req.headers.get('cookie') || '';\n return { url, path: url.pathname, cf: cfOf(req), ip: clientIp(e, req), sid: cookieValue(cookies, SESSION_COOKIE) };\n}\n\nfunction buildEvent(\n req: Request, path: string, query: string, ip: string | null, sid: string | null,\n rid: string = crypto.randomUUID(), newSession = false, // the capture path passes the ids it shared with the app; camada's own answers need none\n): WireEvent {\n const headers: Array<[string, string]> = [];\n req.headers.forEach((v, k) => headers.push([k, v])); // workerd normalises header order: no HEADER_ORDER signal here\n const cf = cfOf(req);\n const ev = buildWireEvent(\n {\n method: req.method, host: req.headers.get('host') ?? new URL(req.url).host, path, query, headers, ip,\n // The client's connection terminates at Cloudflare, so `cf.httpProtocol` really is the\n // visitor's protocol (ea's TAP_CAPS grants this tap TRUE_PROTO on that basis). Never read\n // a forwarded header for this — that would be the proxy's hop, not the client's.\n httpVersion: cf.httpProtocol ? cf.httpProtocol.replace(/^HTTP\\//i, '') : null,\n },\n { tap: TAP_HONO, rid, sid, newSession },\n );\n if (cf.asn) ev.asn = cf.asn;\n if (cf.country) ev.cc = cf.country;\n if (cf.tlsClientExtensionsSha1) ev.tlsx = cf.tlsClientExtensionsSha1;\n return ev;\n}\n\n/** Push then flush through `waitUntil` — the one rule every row (wire event, beacon, track()) follows. */\nexport function ship(e: Engine, ev: unknown, waitUntil: WaitUntil): void {\n e.queue.push(ev);\n e.queue.flush(waitUntil);\n}\n\n/** 204 and a `sig: 1` row on the event batch — one request per flush at the analyst, not one per page view. */\nasync function relayBeacon(eng: Engine, req: Request, ip: string | null, waitUntil: WaitUntil): Promise<Response> {\n const noContent = () => new Response(null, { status: 204, headers: { 'cache-control': 'no-store' } });\n if (Number(req.headers.get('content-length')) > FP_MAX) return new Response(null, { status: 413 });\n const body = await req.text();\n if (encoder.encode(body).byteLength > FP_MAX) return new Response(null, { status: 413 });\n let parsed: unknown;\n try { parsed = JSON.parse(body); } catch { return noContent(); } // not a beacon: drop it, never ship junk\n if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return noContent();\n // Spread first: the ip and the tap are the server's to say, whatever the body claimed.\n ship(eng, { ...(parsed as Record<string, unknown>), sig: 1, ip, tap: TAP_HONO }, waitUntil);\n return noContent();\n}\n\nexport function camada(opts: CamadaHonoOptions = {}): MiddlewareHandler {\n const challengePath = opts.challengePath ?? DEFAULT_CHALLENGE_PATH;\n const scriptPath = opts.scriptPath ?? SCRIPT_PATH;\n const fpPath = opts.fpPath ?? FP_PATH;\n\n return async function camadaHono(c: Context, next: Next): Promise<Response | void> {\n // Reading c.env and building the engine are inside the guard too: a Workers env carries\n // non-string bindings, and a throw here would 5xx the app on its very first request.\n const env = guarded(() => ({ ...(c.env as Record<string, string | undefined> | undefined), ...opts.env }), {} as Record<string, string | undefined>);\n const eng = guarded(() => (env.CAMADA_DISABLED === '1' ? null : ensure(opts, env)), null);\n if (!eng) return next();\n // Same opt-out as @camada/next: the code option, or CAMADA_CHALLENGE=0 in the Worker env.\n const challengeOn = opts.challenge !== false && env.CAMADA_CHALLENGE !== '0';\n\n const waitUntil: WaitUntil = (p) => {\n try { c.executionCtx?.waitUntil(p); } catch { /* no execution context outside a fetch handler */ }\n };\n\n // The id of the `warn` rule that let this request through, read again after next() when the\n // response event is built (§D3). Every other action settles before the app ever runs.\n let warnRule: string | null = null;\n // Set on the capture path only: the ids this request shares with the app (scriptTag, track)\n // and with its own post-response event. Null when camada answered the request itself.\n let vars: CamadaVars | null = null;\n let newSession = false;\n\n const answer = await guardedAsync(async (): Promise<Response | null> => {\n eng.snap.ensureFresh(waitUntil);\n\n const req = c.req.raw;\n const { url, path, cf, ip, sid } = describeRequest(eng, req);\n\n const v = eng.snap.verdict({\n ip, path, ua: req.headers.get('user-agent'), // §D3: without ua every `ua` rule is false\n // `header` conditions read the request through this getter; `Headers.get` is\n // case-insensitive, so the lower-cased name the matcher asks with finds whatever\n // spelling the client sent. Without it every `header` rule is false.\n header: (n) => req.headers.get(n),\n asn: cf.asn ?? null, country: cf.country ?? null, tlsx: cf.tlsClientExtensionsSha1 ?? null,\n });\n warnRule = v.warn ? v.rule ?? null : null;\n\n if (v.block) {\n const ev = buildEvent(req, path, url.search, ip, sid);\n ev.st = 403;\n ev.blk = v.reason; // SDK-01: the analyst counts SDK blocks apart from the app's own 403s ('rule' when a rule decided)\n if (v.rule) ev.rl = v.rule;\n ship(eng, ev, waitUntil);\n const headers: Record<string, string> = {\n 'content-type': 'text/plain', 'x-block-reason': String(v.reason ?? ''), 'x-block-version': v.version ?? '',\n };\n if (v.rule) headers['x-block-rule'] = v.rule; // a custom rule blocked: name it, so the customer knows which row to edit\n return new Response('Forbidden', { status: 403, headers });\n }\n\n // A challenge needs a resolved client ip: the nonce and the `_cch` cookie are bound to it.\n // Without one, fail open rather than mint a cookie every unidentified client could use.\n if (challengeOn && ip) {\n // The verify endpoint answers first — a challenged client must be able to reach it.\n if (req.method === 'POST' && path === challengePath) return verify(eng, req, ip, sid, challengePath, waitUntil);\n const token = cookieValue(req.headers.get('cookie') || '', CHALLENGE_COOKIE);\n if (v.challenge && !(await eng.kit.tokenValid(ip, Date.now(), token))) {\n return serve(eng, req, ip, sid, challengePath, path + url.search, waitUntil);\n }\n }\n\n // The beacon endpoints come after enforcement (a blocked or challenged client gets neither\n // the script nor a relay) and before the app (they are camada's, not its) — @camada/node's order.\n if (beaconEnabled(eng)) {\n if (req.method === 'GET' && path === scriptPath) {\n return new Response(iife, { status: 200, headers: { 'content-type': 'application/javascript', 'cache-control': 'public, max-age=3600' } });\n }\n if (req.method === 'POST' && path === fpPath) return relayBeacon(eng, req, ip, waitUntil);\n }\n\n // Capture: mint the ids the app, the beacon and the post-response event all share. The\n // session is decided here rather than after next() so track() inside the handler and the\n // event both carry the sid a first visit is about to be given.\n newSession = !sid;\n vars = { eng, rid: crypto.randomUUID(), sid: sid ?? crypto.randomUUID(), ip, waitUntil, scriptPath };\n c.set(VAR, vars);\n return null;\n }, null);\n\n if (answer) return answer;\n\n await next();\n\n // Mint the shared session cookie the other taps use, so `sid`/`ns` are real here too\n // (ea's capability mask for sdk-hono claims SESSION). Never overwrite an existing one.\n guarded(() => {\n if (!vars || !newSession) return;\n const secure = new URL(c.req.raw.url).protocol === 'https:' ? '; Secure' : '';\n c.res.headers.append('set-cookie', `${SESSION_COOKIE}=${vars.sid}; Path=/; Max-Age=${SESSION_MAX_AGE}; HttpOnly; SameSite=Lax${secure}`);\n }, undefined);\n\n // The response has settled, so this tap ships the real status — unlike @camada/next's\n // middleware position, which can only report pre-response.\n void guardedAsync(async () => {\n const req = c.req.raw;\n const { url, path, ip } = describeRequest(eng, req);\n const cfg = eng.snap.config;\n if ((cfg?.exclude || []).some((x) => path.startsWith(x))) return;\n if (Math.random() >= (cfg?.sample ?? 1)) return;\n // `vars` is null only when the guard above threw before setting it — then the event still ships, with fresh ids.\n const ev = buildEvent(req, path, url.search, ip, vars?.sid ?? null, vars?.rid, newSession);\n ev.st = c.res.status;\n if (warnRule) ev.wrn = warnRule; // §D3: the warn rule that let this request through\n ship(eng, ev, waitUntil);\n }, undefined);\n };\n}\n\n/** 403 + the proof-of-work page (HTML navigations) or 403 JSON, plus the `blk: \"challenge\"` event. */\nasync function serve(eng: Engine, req: Request, ip: string, sid: string | null, action: string, target: string, waitUntil: WaitUntil): Promise<Response> {\n const url = new URL(req.url);\n const ev = buildEvent(req, url.pathname, url.search, ip, sid);\n ev.st = 403;\n ev.blk = 'challenge';\n ship(eng, ev, waitUntil);\n\n if (!wantsHtml(req.headers.get('accept'), req.headers.get('sec-fetch-dest'))) {\n return new Response('{\"error\":\"challenge_required\"}', {\n status: 403,\n headers: { 'content-type': 'application/json', 'cache-control': 'no-store', 'x-camada-challenge': '1' },\n });\n }\n const html = challengePage({ nonce: await eng.kit.nonce(ip, Date.now()), action, to: safeReturnTo(target) });\n return new Response(html, {\n status: 403,\n headers: { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store', 'x-camada-challenge': '1' },\n });\n}\n\n/** POST from the page: validate, set `_cch`, 302 back, ship `{ st: 200, ch: 1 }`. */\nasync function verify(eng: Engine, req: Request, ip: string, sid: string | null, action: string, waitUntil: WaitUntil): Promise<Response> {\n const url = new URL(req.url);\n // camada answers this path before the app runs, so it must not become a place to post\n // hundreds of megabytes at an unauthenticated endpoint.\n if (Number(req.headers.get('content-length')) > BODY_MAX) return new Response(null, { status: 413 });\n const body = await req.text();\n if (body.length > BODY_MAX) return new Response(null, { status: 413 });\n const form = parseFormBody(body);\n const to = safeReturnTo(form.to);\n const now = Date.now();\n if (!(await eng.kit.verify(ip, now, form.nonce, form.solution))) {\n const html = challengePage({ nonce: await eng.kit.nonce(ip, now), action, to });\n return new Response(html, { status: 403, headers: { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' } });\n }\n const ev = buildEvent(req, url.pathname, '', ip, sid);\n ev.st = 200;\n ev.ch = 1; // challenge passed (contract §A3 ingest field)\n ship(eng, ev, waitUntil);\n return new Response(null, {\n status: 302,\n headers: {\n location: to,\n 'set-cookie': challengeCookie(await eng.kit.issue(ip, now), url.protocol === 'https:'),\n 'cache-control': 'no-store',\n },\n });\n}\n","// Workers hand env vars per request on `c.env`, not on a process — so the engine is built from\n// whatever the first request carries, merged with the options the app passed in code.\nimport { parseKey, parseTrustedProxyEnv, type SnapshotVersion, type TrustedProxyConfig } from '@camada/core';\n\nexport interface ResolvedEnv {\n ingestToken: string;\n snapToken: string;\n secret: string; // HMAC key for the challenge nonce/cookie — never leaves the isolate\n ingestUrl: string;\n snapshotUrl: string;\n trustedProxy: TrustedProxyConfig | null; // null = defer to server-delivered config\n}\n\nexport interface CamadaHonoOptions {\n key?: string;\n ingestUrl?: string;\n snapshotUrl?: string;\n trustedProxy?: TrustedProxyConfig | string | null;\n challenge?: boolean; // enforce `challenge` verdicts with the first-party page (default true)\n challengePath?: string; // where that page posts its solution (default /__camada/challenge)\n snapshotVersion?: SnapshotVersion; // 5 (default) also carries the tenant's ordered custom rules; 4 the allow/challenge sides only; 3 opts out of both\n scriptPath?: string; // where the first-party beacon script is served (default /_cam/b.js)\n fpPath?: string; // where that script posts the beacon (default /_cam/fp; must share scriptPath's directory — the script derives it)\n env?: Record<string, string | undefined>; // overrides c.env (tests, and apps that read config themselves)\n fetchImpl?: typeof fetch;\n}\n\nconst asProxy = (v: CamadaHonoOptions['trustedProxy']): TrustedProxyConfig | null =>\n typeof v === 'string' ? parseTrustedProxyEnv(v) : v ?? null;\n\n/** Returns null (the middleware stays inert, one log line) rather than throwing on bad config. */\nexport function resolveEnv(opts: CamadaHonoOptions, env: Record<string, string | undefined>): ResolvedEnv | null {\n const raw = opts.key || env.CAMADA_KEY;\n const key = parseKey(raw);\n const ingestToken = key?.ingestToken ?? env.CAMADA_TOKEN;\n const snapToken = key?.snapToken ?? env.CAMADA_SNAPSHOT_TOKEN;\n if (!ingestToken || !snapToken) return null;\n const ingestUrl = (opts.ingestUrl || env.CAMADA_INGEST_URL || 'https://in.camada.dev').replace(/\\/$/, ''); // PLACEHOLDER default — confirm the production ingest domain before any npm publish\n return {\n ingestToken, snapToken,\n secret: raw || `${ingestToken}.${snapToken}`,\n ingestUrl,\n snapshotUrl: opts.snapshotUrl || env.CAMADA_SNAPSHOT_URL || `${ingestUrl}/snapshot`,\n trustedProxy: asProxy(opts.trustedProxy) ?? parseTrustedProxyEnv(env.CAMADA_TRUSTED_PROXY),\n };\n}\n","// Per-request state the middleware leaves on the Hono context for the two helpers an app calls\n// from its own handlers: `scriptTag(c)` (the beacon tag) and `track(c, event, data)` (an\n// app-context outcome). The key is private — the helpers are the API, not `c.get`. When the\n// middleware did not run for this request (a path it is not mounted on, no key, CAMADA_DISABLED,\n// or a request it answered itself) there is nothing on the context and both helpers stand down.\nimport type { Context } from 'hono';\nimport { guarded, guardedAsync, hashUserId, TAP_HONO } from '@camada/core';\nimport { ship, type Engine, type WaitUntil } from './camada.js';\n\nexport const VAR = '__camada';\n\nexport interface CamadaVars {\n eng: Engine;\n rid: string; // the request id the page event carries; the beacon and track() join on it\n sid: string; // the `_sfp` session — the one just minted when the request arrived without it\n ip: string | null;\n waitUntil: WaitUntil;\n scriptPath: string;\n}\n\nexport const beaconEnabled = (e: Engine): boolean => e.snap.config?.beacon !== false; // tenant switch; a cold engine serves\n\nconst readVars = (c: Context): CamadaVars | undefined => c.get(VAR) as CamadaVars | undefined;\n\n/**\n * Records an outcome the app knows and the wire cannot show: `login_failed`, `login_succeeded`,\n * `signup`, `password_reset`, `mfa_failed`, `payment_failed`, `payment_succeeded`, `coupon_failed`\n * (free-form; that vocabulary is what the analyst's rules read). Joined to this request's event\n * through its rid and session. The user identifier is HMAC-hashed in-process with the ingest\n * token — the raw value never reaches the queue. Never throws, never rejects; awaiting it is\n * optional (the flush rides `waitUntil`), so a handler may fire and forget.\n */\nexport function track(c: Context, event: string, data?: { user?: string }): Promise<void> {\n const vars = guarded(() => readVars(c), undefined);\n if (!vars) return Promise.resolve();\n const p = guardedAsync(async () => {\n const uid = data?.user ? await hashUserId(data.user, vars.eng.env.ingestToken) : null;\n ship(vars.eng, { tap: TAP_HONO, et: event, uid, rid: vars.rid, sid: vars.sid, ip: vars.ip, ts: Date.now() }, vars.waitUntil);\n }, undefined);\n vars.waitUntil(p); // the isolate may freeze right after the response: hold it open for the flush\n return p;\n}\n\n/** The `<script>` tag for an HTML response — `''` when camada is off for this request or the tenant turned the beacon off. */\nexport function scriptTag(c: Context): string {\n return guarded(() => {\n const vars = readVars(c);\n if (!vars || !beaconEnabled(vars.eng)) return '';\n return `<script src=\"${vars.scriptPath}?r=${vars.rid}\" async></script>`;\n }, '');\n}\n","{\n \"name\": \"@camada/hono\",\n \"version\": \"0.3.0\",\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"engines\": {\n \"node\": \">=18\"\n },\n \"files\": [\n \"dist\",\n \"README.md\",\n \"LICENSE\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"test\": \"vitest run\",\n \"check\": \"tsc --noEmit\"\n },\n \"description\": \"camada SDK for Hono on Cloudflare Workers: snapshot enforcement, first-party challenge and beacon, track() outcomes, waitUntil-flushed event shipping\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n }\n },\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"dependencies\": {\n \"@camada/core\": \"file:../camada-core\",\n \"@camada/browser\": \"file:../camada-browser\"\n },\n \"peerDependencies\": {\n \"hono\": \">=4\"\n },\n \"devDependencies\": {\n \"@cloudflare/workers-types\": \"^4.20250109.0\",\n \"@types/node\": \"^22.10.0\",\n \"hono\": \"^4.6.0\",\n \"tsup\": \"^8.3.5\",\n \"typescript\": \"^5.7.2\",\n \"vitest\": \"^3.0.0\"\n }\n}\n","// The SDK's wire identity (SDK-03): x-camada-sdk: <package>/<version>. Named JSON imports are\n// inlined and tree-shaken by tsup at build, so dist carries two literals — no runtime fs read.\nimport { name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AAO,4BAAc,EAAE,OAAO,MAAM,IAAI,IAAI,MAAM,IAAI,GAAG,GAAG,QAAQ,GAAG,CAAC;AAC9E,WAAO,IAAI,SAAS,MAAM,EAAE,QAAQ,KAAK,SAAS,EAAE,gBAAgB,4BAA4B,iBAAiB,WAAW,EAAE,CAAC;AAAA,EACjI;AACA,QAAM,KAAK,WAAW,KAAK,IAAI,UAAU,IAAI,IAAI,GAAG;AACpD,KAAG,KAAK;AACR,KAAG,KAAK;AACR,OAAK,KAAK,IAAI,SAAS;AACvB,SAAO,IAAI,SAAS,MAAM;AAAA,IACxB,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,UAAU;AAAA,MACV,kBAAc,8BAAgB,MAAM,IAAI,IAAI,MAAM,IAAI,GAAG,GAAG,IAAI,aAAa,QAAQ;AAAA,MACrF,iBAAiB;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":["import_core","import_core","name","iife"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/camada.ts","../src/env.ts","../src/context.ts","../package.json","../src/version.ts"],"sourcesContent":["// @camada/hono — the one-line install for a Hono app on Cloudflare Workers:\n// app.use('*', camada()); // env: CAMADA_KEY (+ CAMADA_INGEST_URL / CAMADA_SNAPSHOT_URL in dev)\n// c.html(`<head>${scriptTag(c)}</head>…`) // the first-party beacon\n// track(c, 'login_failed', { user }) // an outcome the wire cannot show\nexport { camada, resetCamada } from './camada.js';\nexport { track, scriptTag } from './context.js';\nexport { resolveEnv, type CamadaHonoOptions, type ResolvedEnv } from './env.js';\n","// @camada/hono — the Hono middleware for Cloudflare Workers (SEC-07, D33).\n// app.use('*', camada());\n// Workers-native: `cf-connecting-ip` for the client address, `request.cf` for asn / country /\n// TLS fingerprint (so ASN and country rules really enforce at this tap), and\n// `c.executionCtx.waitUntil` so the snapshot poll and the event flush outlive the response.\n// Everything runs inside camada's fail-open envelope: a camada bug, a dead ingest or a corrupt\n// snapshot costs telemetry, never the app's response.\nimport type { Context, MiddlewareHandler, Next } from 'hono';\nimport iife from '@camada/browser/iife-string';\nimport {\n SnapshotClient, EventQueue, buildWireEvent, resolveClientIp, logRateLimited, guardedAsync,\n guarded, createChallengeAsync, challengePage, challengeCookie, safeReturnTo, wantsHtml, parseFormBody,\n CHALLENGE_COOKIE, DEFAULT_SNAPSHOT_VERSION, TAP_HONO,\n type AsyncChallengeKit, type TrustedProxyConfig, type WireEvent,\n} from '@camada/core';\nimport { resolveEnv, type CamadaHonoOptions, type ResolvedEnv } from './env.js';\nimport { VAR, beaconEnabled, type CamadaVars } from './context.js';\nimport { SDK_ID } from './version.js';\n\nconst DEFAULT_CHALLENGE_PATH = '/__camada/challenge';\nconst SCRIPT_PATH = '/_cam/b.js'; // the beacon IIFE; its auto-init posts to the sibling `fp` and reads the rid from ?r=\nconst FP_PATH = '/_cam/fp';\nconst FP_MAX = 32 * 1024; // matches the analyst's /fp cap: never accept what ingest will 413\nconst SESSION_COOKIE = '_sfp'; // the same session cookie as every other tap: sid/ns stay comparable\nconst SESSION_MAX_AGE = 2592000;\nconst BODY_MAX = 4 * 1024; // the verify form is ~120 bytes; anything larger is not ours\nconst encoder = new TextEncoder();\n\nexport interface Engine {\n env: ResolvedEnv;\n snap: SnapshotClient;\n queue: EventQueue;\n kit: AsyncChallengeKit;\n}\n\nexport type WaitUntil = (p: Promise<unknown>) => void;\n\n// One engine per resolved configuration, not per module: a Workers isolate can host several\n// Hono apps, and a shared singleton would enforce the first tenant's snapshot on the second\n// and sign its `_cch` cookies with the first tenant's secret. An unconfigured request is never\n// cached — a warm-up or a differently-keyed mount must not leave the isolate inert for good.\nconst engines = new Map<string, Engine>();\n\n/** Test/reset hook: drops every cached engine. */\nexport function resetCamada(): void {\n for (const e of engines.values()) { e.snap.stop(); e.queue.stop(); }\n engines.clear();\n}\n\nfunction ensure(opts: CamadaHonoOptions, ctxEnv: Record<string, string | undefined>): Engine | null {\n const env = resolveEnv(opts, ctxEnv);\n if (!env) {\n logRateLimited(new Error('CAMADA_KEY not set — camada is inactive'));\n return null;\n }\n const snapshotVersion = opts.snapshotVersion ?? DEFAULT_SNAPSHOT_VERSION;\n const id = `${env.ingestToken}|${env.ingestUrl}|${env.snapshotUrl}|${snapshotVersion}`;\n const cached = engines.get(id);\n if (cached) return cached;\n const injected = opts.fetchImpl ? { fetchImpl: opts.fetchImpl } : {}; // never pass an explicit undefined key\n const engine: Engine = {\n env,\n snap: new SnapshotClient({\n url: env.snapshotUrl, token: env.snapToken, mode: 'lazy', sdk: SDK_ID,\n snapshotVersion, ...injected,\n }),\n queue: new EventQueue({ url: env.ingestUrl, token: env.ingestToken, sdk: SDK_ID, ...injected }),\n kit: createChallengeAsync({ secret: env.secret }),\n };\n engines.set(id, engine);\n return engine;\n}\n\nconst cookieValue = (cookie: string, name: string): string | null => {\n const src = '; ' + cookie;\n const i = src.indexOf('; ' + name + '=');\n if (i === -1) return null;\n const start = i + name.length + 3;\n const j = src.indexOf(';', start);\n return src.slice(start, j === -1 ? undefined : j);\n};\n\ninterface CfProps { asn?: number; country?: string; tlsClientExtensionsSha1?: string; httpProtocol?: string }\nconst cfOf = (req: Request): CfProps => ((req as Request & { cf?: CfProps }).cf ?? {});\n\nconst trustedProxy = (e: Engine): TrustedProxyConfig | null =>\n e.env.trustedProxy ?? e.snap.config?.trusted_proxy ?? null;\n\n/** Cloudflare sets `cf-connecting-ip` itself and a client cannot forge it — but only on\n * Workers, which is also the only place `request.cf` exists. On any other Hono runtime\n * (node-server, Bun, Deno) that header is attacker-controlled, so it is ignored there and the\n * trusted-proxy rules decide, exactly as they do for X-Forwarded-For. */\nconst clientIp = (e: Engine, req: Request): string | null => {\n const cf = (req as Request & { cf?: unknown }).cf;\n const direct = cf ? req.headers.get('cf-connecting-ip') : null;\n return direct || resolveClientIp(null, req.headers.get('x-forwarded-for'), trustedProxy(e));\n};\n\ninterface RequestFacts {\n url: URL;\n path: string;\n cf: CfProps;\n ip: string | null;\n sid: string | null;\n}\n\nfunction describeRequest(e: Engine, req: Request): RequestFacts {\n const url = new URL(req.url);\n const cookies = req.headers.get('cookie') || '';\n return { url, path: url.pathname, cf: cfOf(req), ip: clientIp(e, req), sid: cookieValue(cookies, SESSION_COOKIE) };\n}\n\nfunction buildEvent(\n req: Request, path: string, query: string, ip: string | null, sid: string | null,\n rid: string = crypto.randomUUID(), newSession = false, // the capture path passes the ids it shared with the app; camada's own answers need none\n): WireEvent {\n const headers: Array<[string, string]> = [];\n req.headers.forEach((v, k) => headers.push([k, v])); // workerd normalises header order: no HEADER_ORDER signal here\n const cf = cfOf(req);\n const ev = buildWireEvent(\n {\n method: req.method, host: req.headers.get('host') ?? new URL(req.url).host, path, query, headers, ip,\n // The client's connection terminates at Cloudflare, so `cf.httpProtocol` really is the\n // visitor's protocol (ea's TAP_CAPS grants this tap TRUE_PROTO on that basis). Never read\n // a forwarded header for this — that would be the proxy's hop, not the client's.\n httpVersion: cf.httpProtocol ? cf.httpProtocol.replace(/^HTTP\\//i, '') : null,\n },\n { tap: TAP_HONO, rid, sid, newSession },\n );\n if (cf.asn) ev.asn = cf.asn;\n if (cf.country) ev.cc = cf.country;\n if (cf.tlsClientExtensionsSha1) ev.tlsx = cf.tlsClientExtensionsSha1;\n return ev;\n}\n\n/** Push then flush through `waitUntil` — the one rule every row (wire event, beacon, track()) follows. */\nexport function ship(e: Engine, ev: unknown, waitUntil: WaitUntil): void {\n e.queue.push(ev);\n e.queue.flush(waitUntil);\n}\n\n/** 204 and a `sig: 1` row on the event batch — one request per flush at the analyst, not one per page view. */\nasync function relayBeacon(eng: Engine, req: Request, ip: string | null, waitUntil: WaitUntil): Promise<Response> {\n const noContent = () => new Response(null, { status: 204, headers: { 'cache-control': 'no-store' } });\n if (Number(req.headers.get('content-length')) > FP_MAX) return new Response(null, { status: 413 });\n const body = await req.text();\n if (encoder.encode(body).byteLength > FP_MAX) return new Response(null, { status: 413 });\n let parsed: unknown;\n try { parsed = JSON.parse(body); } catch { return noContent(); } // not a beacon: drop it, never ship junk\n if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return noContent();\n // Spread first: the ip and the tap are the server's to say, whatever the body claimed.\n ship(eng, { ...(parsed as Record<string, unknown>), sig: 1, ip, tap: TAP_HONO }, waitUntil);\n return noContent();\n}\n\nexport function camada(opts: CamadaHonoOptions = {}): MiddlewareHandler {\n const challengePath = opts.challengePath ?? DEFAULT_CHALLENGE_PATH;\n const scriptPath = opts.scriptPath ?? SCRIPT_PATH;\n const fpPath = opts.fpPath ?? FP_PATH;\n\n return async function camadaHono(c: Context, next: Next): Promise<Response | void> {\n const t0 = Date.now(); // request start; the response event ships dur = settle - t0 (ms), @camada/node's semantics\n // Reading c.env and building the engine are inside the guard too: a Workers env carries\n // non-string bindings, and a throw here would 5xx the app on its very first request.\n const env = guarded(() => ({ ...(c.env as Record<string, string | undefined> | undefined), ...opts.env }), {} as Record<string, string | undefined>);\n const eng = guarded(() => (env.CAMADA_DISABLED === '1' ? null : ensure(opts, env)), null);\n if (!eng) return next();\n // Same opt-out as @camada/next: the code option, or CAMADA_CHALLENGE=0 in the Worker env.\n const challengeOn = opts.challenge !== false && env.CAMADA_CHALLENGE !== '0';\n\n const waitUntil: WaitUntil = (p) => {\n try { c.executionCtx?.waitUntil(p); } catch { /* no execution context outside a fetch handler */ }\n };\n\n // The id of the `warn` rule that let this request through, read again after next() when the\n // response event is built (§D3). Every other action settles before the app ever runs.\n let warnRule: string | null = null;\n // Set on the capture path only: the ids this request shares with the app (scriptTag, track)\n // and with its own post-response event. Null when camada answered the request itself.\n let vars: CamadaVars | null = null;\n let newSession = false;\n\n const answer = await guardedAsync(async (): Promise<Response | null> => {\n eng.snap.ensureFresh(waitUntil);\n\n const req = c.req.raw;\n const { url, path, cf, ip, sid } = describeRequest(eng, req);\n\n const v = eng.snap.verdict({\n ip, path, ua: req.headers.get('user-agent'), // §D3: without ua every `ua` rule is false\n // `header` conditions read the request through this getter; `Headers.get` is\n // case-insensitive, so the lower-cased name the matcher asks with finds whatever\n // spelling the client sent. Without it every `header` rule is false.\n header: (n) => req.headers.get(n),\n asn: cf.asn ?? null, country: cf.country ?? null, tlsx: cf.tlsClientExtensionsSha1 ?? null,\n });\n warnRule = v.warn ? v.rule ?? null : null;\n\n if (v.block) {\n const ev = buildEvent(req, path, url.search, ip, sid);\n ev.st = 403;\n ev.blk = v.reason; // SDK-01: the analyst counts SDK blocks apart from the app's own 403s ('rule' when a rule decided)\n if (v.rule) ev.rl = v.rule;\n ship(eng, ev, waitUntil);\n const headers: Record<string, string> = {\n 'content-type': 'text/plain', 'x-block-reason': String(v.reason ?? ''), 'x-block-version': v.version ?? '',\n };\n if (v.rule) headers['x-block-rule'] = v.rule; // a custom rule blocked: name it, so the customer knows which row to edit\n return new Response('Forbidden', { status: 403, headers });\n }\n\n // A challenge needs a resolved client ip: the nonce and the `_cch` cookie are bound to it.\n // Without one, fail open rather than mint a cookie every unidentified client could use.\n if (challengeOn && ip) {\n // The verify endpoint answers first — a challenged client must be able to reach it.\n if (req.method === 'POST' && path === challengePath) return verify(eng, req, ip, sid, challengePath, waitUntil);\n const token = cookieValue(req.headers.get('cookie') || '', CHALLENGE_COOKIE);\n if (v.challenge && !(await eng.kit.tokenValid(ip, Date.now(), token))) {\n return serve(eng, req, ip, sid, challengePath, path + url.search, waitUntil);\n }\n }\n\n // The beacon endpoints come after enforcement (a blocked or challenged client gets neither\n // the script nor a relay) and before the app (they are camada's, not its) — @camada/node's order.\n if (beaconEnabled(eng)) {\n if (req.method === 'GET' && path === scriptPath) {\n return new Response(iife, { status: 200, headers: { 'content-type': 'application/javascript', 'cache-control': 'public, max-age=3600' } });\n }\n if (req.method === 'POST' && path === fpPath) return relayBeacon(eng, req, ip, waitUntil);\n }\n\n // Capture: mint the ids the app, the beacon and the post-response event all share. The\n // session is decided here rather than after next() so track() inside the handler and the\n // event both carry the sid a first visit is about to be given.\n newSession = !sid;\n vars = { eng, rid: crypto.randomUUID(), sid: sid ?? crypto.randomUUID(), ip, waitUntil, scriptPath };\n c.set(VAR, vars);\n return null;\n }, null);\n\n if (answer) return answer;\n\n await next();\n\n // Mint the shared session cookie the other taps use, so `sid`/`ns` are real here too\n // (ea's capability mask for sdk-hono claims SESSION). Never overwrite an existing one.\n guarded(() => {\n if (!vars || !newSession) return;\n const secure = new URL(c.req.raw.url).protocol === 'https:' ? '; Secure' : '';\n c.res.headers.append('set-cookie', `${SESSION_COOKIE}=${vars.sid}; Path=/; Max-Age=${SESSION_MAX_AGE}; HttpOnly; SameSite=Lax${secure}`);\n }, undefined);\n\n // The response has settled, so this tap ships the real status — unlike @camada/next's\n // middleware position, which can only report pre-response.\n void guardedAsync(async () => {\n const req = c.req.raw;\n const { url, path, ip } = describeRequest(eng, req);\n const cfg = eng.snap.config;\n if ((cfg?.exclude || []).some((x) => path.startsWith(x))) return;\n if (Math.random() >= (cfg?.sample ?? 1)) return;\n // `vars` is null only when the guard above threw before setting it — then the event still ships, with fresh ids.\n const ev = buildEvent(req, path, url.search, ip, vars?.sid ?? null, vars?.rid, newSession);\n ev.st = c.res.status;\n ev.dur = Math.max(0, Date.now() - t0);\n if (warnRule) ev.wrn = warnRule; // §D3: the warn rule that let this request through\n ship(eng, ev, waitUntil);\n }, undefined);\n };\n}\n\n/** 403 + the proof-of-work page (HTML navigations) or 403 JSON, plus the `blk: \"challenge\"` event. */\nasync function serve(eng: Engine, req: Request, ip: string, sid: string | null, action: string, target: string, waitUntil: WaitUntil): Promise<Response> {\n const url = new URL(req.url);\n const ev = buildEvent(req, url.pathname, url.search, ip, sid);\n ev.st = 403;\n ev.blk = 'challenge';\n ship(eng, ev, waitUntil);\n\n if (!wantsHtml(req.headers.get('accept'), req.headers.get('sec-fetch-dest'))) {\n return new Response('{\"error\":\"challenge_required\"}', {\n status: 403,\n headers: { 'content-type': 'application/json', 'cache-control': 'no-store', 'x-camada-challenge': '1' },\n });\n }\n const html = challengePage({ nonce: await eng.kit.nonce(ip, Date.now()), action, to: safeReturnTo(target) });\n return new Response(html, {\n status: 403,\n headers: { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store', 'x-camada-challenge': '1' },\n });\n}\n\n/** POST from the page: validate, set `_cch`, 302 back, ship `{ st: 200, ch: 1 }`. */\nasync function verify(eng: Engine, req: Request, ip: string, sid: string | null, action: string, waitUntil: WaitUntil): Promise<Response> {\n const url = new URL(req.url);\n // camada answers this path before the app runs, so it must not become a place to post\n // hundreds of megabytes at an unauthenticated endpoint.\n if (Number(req.headers.get('content-length')) > BODY_MAX) return new Response(null, { status: 413 });\n const body = await req.text();\n if (body.length > BODY_MAX) return new Response(null, { status: 413 });\n const form = parseFormBody(body);\n const to = safeReturnTo(form.to);\n const now = Date.now();\n if (!(await eng.kit.verify(ip, now, form.nonce, form.solution))) {\n const html = challengePage({ nonce: await eng.kit.nonce(ip, now), action, to });\n return new Response(html, { status: 403, headers: { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' } });\n }\n const ev = buildEvent(req, url.pathname, '', ip, sid);\n ev.st = 200;\n ev.ch = 1; // challenge passed (contract §A3 ingest field)\n ship(eng, ev, waitUntil);\n return new Response(null, {\n status: 302,\n headers: {\n location: to,\n 'set-cookie': challengeCookie(await eng.kit.issue(ip, now), url.protocol === 'https:'),\n 'cache-control': 'no-store',\n },\n });\n}\n","// Workers hand env vars per request on `c.env`, not on a process — so the engine is built from\n// whatever the first request carries, merged with the options the app passed in code.\nimport { parseKey, parseTrustedProxyEnv, type SnapshotVersion, type TrustedProxyConfig } from '@camada/core';\n\nexport interface ResolvedEnv {\n ingestToken: string;\n snapToken: string;\n secret: string; // HMAC key for the challenge nonce/cookie — never leaves the isolate\n ingestUrl: string;\n snapshotUrl: string;\n trustedProxy: TrustedProxyConfig | null; // null = defer to server-delivered config\n}\n\nexport interface CamadaHonoOptions {\n key?: string;\n ingestUrl?: string;\n snapshotUrl?: string;\n trustedProxy?: TrustedProxyConfig | string | null;\n challenge?: boolean; // enforce `challenge` verdicts with the first-party page (default true)\n challengePath?: string; // where that page posts its solution (default /__camada/challenge)\n snapshotVersion?: SnapshotVersion; // 5 (default) also carries the tenant's ordered custom rules; 4 the allow/challenge sides only; 3 opts out of both\n scriptPath?: string; // where the first-party beacon script is served (default /_cam/b.js)\n fpPath?: string; // where that script posts the beacon (default /_cam/fp; must share scriptPath's directory — the script derives it)\n env?: Record<string, string | undefined>; // overrides c.env (tests, and apps that read config themselves)\n fetchImpl?: typeof fetch;\n}\n\nconst asProxy = (v: CamadaHonoOptions['trustedProxy']): TrustedProxyConfig | null =>\n typeof v === 'string' ? parseTrustedProxyEnv(v) : v ?? null;\n\n/** Returns null (the middleware stays inert, one log line) rather than throwing on bad config. */\nexport function resolveEnv(opts: CamadaHonoOptions, env: Record<string, string | undefined>): ResolvedEnv | null {\n const raw = opts.key || env.CAMADA_KEY;\n const key = parseKey(raw);\n const ingestToken = key?.ingestToken ?? env.CAMADA_TOKEN;\n const snapToken = key?.snapToken ?? env.CAMADA_SNAPSHOT_TOKEN;\n if (!ingestToken || !snapToken) return null;\n const ingestUrl = (opts.ingestUrl || env.CAMADA_INGEST_URL || 'https://in.camada.app').replace(/\\/$/, ''); // PLACEHOLDER default — confirm the production ingest domain before any npm publish\n return {\n ingestToken, snapToken,\n secret: raw || `${ingestToken}.${snapToken}`,\n ingestUrl,\n snapshotUrl: opts.snapshotUrl || env.CAMADA_SNAPSHOT_URL || `${ingestUrl}/snapshot`,\n trustedProxy: asProxy(opts.trustedProxy) ?? parseTrustedProxyEnv(env.CAMADA_TRUSTED_PROXY),\n };\n}\n","// Per-request state the middleware leaves on the Hono context for the two helpers an app calls\n// from its own handlers: `scriptTag(c)` (the beacon tag) and `track(c, event, data)` (an\n// app-context outcome). The key is private — the helpers are the API, not `c.get`. When the\n// middleware did not run for this request (a path it is not mounted on, no key, CAMADA_DISABLED,\n// or a request it answered itself) there is nothing on the context and both helpers stand down.\nimport type { Context } from 'hono';\nimport { guarded, guardedAsync, hashUserId, TAP_HONO } from '@camada/core';\nimport { ship, type Engine, type WaitUntil } from './camada.js';\n\nexport const VAR = '__camada';\n\nexport interface CamadaVars {\n eng: Engine;\n rid: string; // the request id the page event carries; the beacon and track() join on it\n sid: string; // the `_sfp` session — the one just minted when the request arrived without it\n ip: string | null;\n waitUntil: WaitUntil;\n scriptPath: string;\n}\n\nexport const beaconEnabled = (e: Engine): boolean => e.snap.config?.beacon !== false; // tenant switch; a cold engine serves\n\nconst readVars = (c: Context): CamadaVars | undefined => c.get(VAR) as CamadaVars | undefined;\n\n/**\n * Records an outcome the app knows and the wire cannot show: `login_failed`, `login_succeeded`,\n * `signup`, `password_reset`, `mfa_failed`, `payment_failed`, `payment_succeeded`, `coupon_failed`\n * (free-form; that vocabulary is what the analyst's rules read). Joined to this request's event\n * through its rid and session. The user identifier is HMAC-hashed in-process with the ingest\n * token — the raw value never reaches the queue. Never throws, never rejects; awaiting it is\n * optional (the flush rides `waitUntil`), so a handler may fire and forget.\n */\nexport function track(c: Context, event: string, data?: { user?: string }): Promise<void> {\n const vars = guarded(() => readVars(c), undefined);\n if (!vars) return Promise.resolve();\n const p = guardedAsync(async () => {\n const uid = data?.user ? await hashUserId(data.user, vars.eng.env.ingestToken) : null;\n ship(vars.eng, { tap: TAP_HONO, et: event, uid, rid: vars.rid, sid: vars.sid, ip: vars.ip, ts: Date.now() }, vars.waitUntil);\n }, undefined);\n vars.waitUntil(p); // the isolate may freeze right after the response: hold it open for the flush\n return p;\n}\n\n/** The `<script>` tag for an HTML response — `''` when camada is off for this request or the tenant turned the beacon off. */\nexport function scriptTag(c: Context): string {\n return guarded(() => {\n const vars = readVars(c);\n if (!vars || !beaconEnabled(vars.eng)) return '';\n return `<script src=\"${vars.scriptPath}?r=${vars.rid}\" async></script>`;\n }, '');\n}\n","{\n \"name\": \"@camada/hono\",\n \"version\": \"0.3.1\",\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"engines\": {\n \"node\": \">=20\"\n },\n \"files\": [\n \"dist\",\n \"README.md\",\n \"LICENSE\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"test\": \"vitest run\",\n \"check\": \"tsc --noEmit\"\n },\n \"description\": \"camada SDK for Hono on Cloudflare Workers: snapshot enforcement, first-party challenge and beacon, track() outcomes, waitUntil-flushed event shipping\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n }\n },\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"dependencies\": {\n \"@camada/core\": \"file:../camada-core\",\n \"@camada/browser\": \"file:../camada-browser\"\n },\n \"peerDependencies\": {\n \"hono\": \">=4\"\n },\n \"devDependencies\": {\n \"@cloudflare/workers-types\": \"^4.20250109.0\",\n \"@types/node\": \"^22.10.0\",\n \"hono\": \"^4.6.0\",\n \"tsup\": \"^8.3.5\",\n \"typescript\": \"^5.7.2\",\n \"vitest\": \"^3.0.0\"\n }\n}\n","// The SDK's wire identity (SDK-03): x-camada-sdk: <package>/<version>. Named JSON imports are\n// inlined and tree-shaken by tsup at build, so dist carries two literals — no runtime fs read.\nimport { name, version } from '../package.json';\nexport const SDK_ID = `${name}/${version}`;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACQA,yBAAiB;AACjB,IAAAA,eAKO;;;ACZP,kBAA8F;AAyB9F,IAAM,UAAU,CAAC,MACf,OAAO,MAAM,eAAW,kCAAqB,CAAC,IAAI,KAAK;AAGlD,SAAS,WAAW,MAAyB,KAA6D;AAC/G,QAAM,MAAM,KAAK,OAAO,IAAI;AAC5B,QAAM,UAAM,sBAAS,GAAG;AACxB,QAAM,cAAc,KAAK,eAAe,IAAI;AAC5C,QAAM,YAAY,KAAK,aAAa,IAAI;AACxC,MAAI,CAAC,eAAe,CAAC,UAAW,QAAO;AACvC,QAAM,aAAa,KAAK,aAAa,IAAI,qBAAqB,yBAAyB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AAI,MAAM,IAAI,GAAG,GAAG,IAAI,aAAa,QAAQ;AAAA,MACrF,iBAAiB;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":["import_core","import_core","name","iife"]}
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@ function resolveEnv(opts, env) {
28
28
  const ingestToken = key?.ingestToken ?? env.CAMADA_TOKEN;
29
29
  const snapToken = key?.snapToken ?? env.CAMADA_SNAPSHOT_TOKEN;
30
30
  if (!ingestToken || !snapToken) return null;
31
- const ingestUrl = (opts.ingestUrl || env.CAMADA_INGEST_URL || "https://in.camada.dev").replace(/\/$/, "");
31
+ const ingestUrl = (opts.ingestUrl || env.CAMADA_INGEST_URL || "https://in.camada.app").replace(/\/$/, "");
32
32
  return {
33
33
  ingestToken,
34
34
  snapToken,
@@ -64,7 +64,7 @@ function scriptTag(c) {
64
64
 
65
65
  // package.json
66
66
  var name = "@camada/hono";
67
- var version = "0.3.0";
67
+ var version = "0.3.1";
68
68
 
69
69
  // src/version.ts
70
70
  var SDK_ID = `${name}/${version}`;
@@ -181,6 +181,7 @@ function camada(opts = {}) {
181
181
  const scriptPath = opts.scriptPath ?? SCRIPT_PATH;
182
182
  const fpPath = opts.fpPath ?? FP_PATH;
183
183
  return async function camadaHono(c, next) {
184
+ const t0 = Date.now();
184
185
  const env = guarded2(() => ({ ...c.env, ...opts.env }), {});
185
186
  const eng = guarded2(() => env.CAMADA_DISABLED === "1" ? null : ensure(opts, env), null);
186
187
  if (!eng) return next();
@@ -259,6 +260,7 @@ function camada(opts = {}) {
259
260
  if (Math.random() >= (cfg?.sample ?? 1)) return;
260
261
  const ev = buildEvent(req, path, url.search, ip, vars?.sid ?? null, vars?.rid, newSession);
261
262
  ev.st = c.res.status;
263
+ ev.dur = Math.max(0, Date.now() - t0);
262
264
  if (warnRule) ev.wrn = warnRule;
263
265
  ship(eng, ev, waitUntil);
264
266
  }, void 0);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/camada.ts","../src/env.ts","../src/context.ts","../package.json","../src/version.ts"],"sourcesContent":["// @camada/hono — the Hono middleware for Cloudflare Workers (SEC-07, D33).\n// app.use('*', camada());\n// Workers-native: `cf-connecting-ip` for the client address, `request.cf` for asn / country /\n// TLS fingerprint (so ASN and country rules really enforce at this tap), and\n// `c.executionCtx.waitUntil` so the snapshot poll and the event flush outlive the response.\n// Everything runs inside camada's fail-open envelope: a camada bug, a dead ingest or a corrupt\n// snapshot costs telemetry, never the app's response.\nimport type { Context, MiddlewareHandler, Next } from 'hono';\nimport iife from '@camada/browser/iife-string';\nimport {\n SnapshotClient, EventQueue, buildWireEvent, resolveClientIp, logRateLimited, guardedAsync,\n guarded, createChallengeAsync, challengePage, challengeCookie, safeReturnTo, wantsHtml, parseFormBody,\n CHALLENGE_COOKIE, DEFAULT_SNAPSHOT_VERSION, TAP_HONO,\n type AsyncChallengeKit, type TrustedProxyConfig, type WireEvent,\n} from '@camada/core';\nimport { resolveEnv, type CamadaHonoOptions, type ResolvedEnv } from './env.js';\nimport { VAR, beaconEnabled, type CamadaVars } from './context.js';\nimport { SDK_ID } from './version.js';\n\nconst DEFAULT_CHALLENGE_PATH = '/__camada/challenge';\nconst SCRIPT_PATH = '/_cam/b.js'; // the beacon IIFE; its auto-init posts to the sibling `fp` and reads the rid from ?r=\nconst FP_PATH = '/_cam/fp';\nconst FP_MAX = 32 * 1024; // matches the analyst's /fp cap: never accept what ingest will 413\nconst SESSION_COOKIE = '_sfp'; // the same session cookie as every other tap: sid/ns stay comparable\nconst SESSION_MAX_AGE = 2592000;\nconst BODY_MAX = 4 * 1024; // the verify form is ~120 bytes; anything larger is not ours\nconst encoder = new TextEncoder();\n\nexport interface Engine {\n env: ResolvedEnv;\n snap: SnapshotClient;\n queue: EventQueue;\n kit: AsyncChallengeKit;\n}\n\nexport type WaitUntil = (p: Promise<unknown>) => void;\n\n// One engine per resolved configuration, not per module: a Workers isolate can host several\n// Hono apps, and a shared singleton would enforce the first tenant's snapshot on the second\n// and sign its `_cch` cookies with the first tenant's secret. An unconfigured request is never\n// cached — a warm-up or a differently-keyed mount must not leave the isolate inert for good.\nconst engines = new Map<string, Engine>();\n\n/** Test/reset hook: drops every cached engine. */\nexport function resetCamada(): void {\n for (const e of engines.values()) { e.snap.stop(); e.queue.stop(); }\n engines.clear();\n}\n\nfunction ensure(opts: CamadaHonoOptions, ctxEnv: Record<string, string | undefined>): Engine | null {\n const env = resolveEnv(opts, ctxEnv);\n if (!env) {\n logRateLimited(new Error('CAMADA_KEY not set — camada is inactive'));\n return null;\n }\n const snapshotVersion = opts.snapshotVersion ?? DEFAULT_SNAPSHOT_VERSION;\n const id = `${env.ingestToken}|${env.ingestUrl}|${env.snapshotUrl}|${snapshotVersion}`;\n const cached = engines.get(id);\n if (cached) return cached;\n const injected = opts.fetchImpl ? { fetchImpl: opts.fetchImpl } : {}; // never pass an explicit undefined key\n const engine: Engine = {\n env,\n snap: new SnapshotClient({\n url: env.snapshotUrl, token: env.snapToken, mode: 'lazy', sdk: SDK_ID,\n snapshotVersion, ...injected,\n }),\n queue: new EventQueue({ url: env.ingestUrl, token: env.ingestToken, sdk: SDK_ID, ...injected }),\n kit: createChallengeAsync({ secret: env.secret }),\n };\n engines.set(id, engine);\n return engine;\n}\n\nconst cookieValue = (cookie: string, name: string): string | null => {\n const src = '; ' + cookie;\n const i = src.indexOf('; ' + name + '=');\n if (i === -1) return null;\n const start = i + name.length + 3;\n const j = src.indexOf(';', start);\n return src.slice(start, j === -1 ? undefined : j);\n};\n\ninterface CfProps { asn?: number; country?: string; tlsClientExtensionsSha1?: string; httpProtocol?: string }\nconst cfOf = (req: Request): CfProps => ((req as Request & { cf?: CfProps }).cf ?? {});\n\nconst trustedProxy = (e: Engine): TrustedProxyConfig | null =>\n e.env.trustedProxy ?? e.snap.config?.trusted_proxy ?? null;\n\n/** Cloudflare sets `cf-connecting-ip` itself and a client cannot forge it — but only on\n * Workers, which is also the only place `request.cf` exists. On any other Hono runtime\n * (node-server, Bun, Deno) that header is attacker-controlled, so it is ignored there and the\n * trusted-proxy rules decide, exactly as they do for X-Forwarded-For. */\nconst clientIp = (e: Engine, req: Request): string | null => {\n const cf = (req as Request & { cf?: unknown }).cf;\n const direct = cf ? req.headers.get('cf-connecting-ip') : null;\n return direct || resolveClientIp(null, req.headers.get('x-forwarded-for'), trustedProxy(e));\n};\n\ninterface RequestFacts {\n url: URL;\n path: string;\n cf: CfProps;\n ip: string | null;\n sid: string | null;\n}\n\nfunction describeRequest(e: Engine, req: Request): RequestFacts {\n const url = new URL(req.url);\n const cookies = req.headers.get('cookie') || '';\n return { url, path: url.pathname, cf: cfOf(req), ip: clientIp(e, req), sid: cookieValue(cookies, SESSION_COOKIE) };\n}\n\nfunction buildEvent(\n req: Request, path: string, query: string, ip: string | null, sid: string | null,\n rid: string = crypto.randomUUID(), newSession = false, // the capture path passes the ids it shared with the app; camada's own answers need none\n): WireEvent {\n const headers: Array<[string, string]> = [];\n req.headers.forEach((v, k) => headers.push([k, v])); // workerd normalises header order: no HEADER_ORDER signal here\n const cf = cfOf(req);\n const ev = buildWireEvent(\n {\n method: req.method, host: req.headers.get('host') ?? new URL(req.url).host, path, query, headers, ip,\n // The client's connection terminates at Cloudflare, so `cf.httpProtocol` really is the\n // visitor's protocol (ea's TAP_CAPS grants this tap TRUE_PROTO on that basis). Never read\n // a forwarded header for this — that would be the proxy's hop, not the client's.\n httpVersion: cf.httpProtocol ? cf.httpProtocol.replace(/^HTTP\\//i, '') : null,\n },\n { tap: TAP_HONO, rid, sid, newSession },\n );\n if (cf.asn) ev.asn = cf.asn;\n if (cf.country) ev.cc = cf.country;\n if (cf.tlsClientExtensionsSha1) ev.tlsx = cf.tlsClientExtensionsSha1;\n return ev;\n}\n\n/** Push then flush through `waitUntil` — the one rule every row (wire event, beacon, track()) follows. */\nexport function ship(e: Engine, ev: unknown, waitUntil: WaitUntil): void {\n e.queue.push(ev);\n e.queue.flush(waitUntil);\n}\n\n/** 204 and a `sig: 1` row on the event batch — one request per flush at the analyst, not one per page view. */\nasync function relayBeacon(eng: Engine, req: Request, ip: string | null, waitUntil: WaitUntil): Promise<Response> {\n const noContent = () => new Response(null, { status: 204, headers: { 'cache-control': 'no-store' } });\n if (Number(req.headers.get('content-length')) > FP_MAX) return new Response(null, { status: 413 });\n const body = await req.text();\n if (encoder.encode(body).byteLength > FP_MAX) return new Response(null, { status: 413 });\n let parsed: unknown;\n try { parsed = JSON.parse(body); } catch { return noContent(); } // not a beacon: drop it, never ship junk\n if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return noContent();\n // Spread first: the ip and the tap are the server's to say, whatever the body claimed.\n ship(eng, { ...(parsed as Record<string, unknown>), sig: 1, ip, tap: TAP_HONO }, waitUntil);\n return noContent();\n}\n\nexport function camada(opts: CamadaHonoOptions = {}): MiddlewareHandler {\n const challengePath = opts.challengePath ?? DEFAULT_CHALLENGE_PATH;\n const scriptPath = opts.scriptPath ?? SCRIPT_PATH;\n const fpPath = opts.fpPath ?? FP_PATH;\n\n return async function camadaHono(c: Context, next: Next): Promise<Response | void> {\n // Reading c.env and building the engine are inside the guard too: a Workers env carries\n // non-string bindings, and a throw here would 5xx the app on its very first request.\n const env = guarded(() => ({ ...(c.env as Record<string, string | undefined> | undefined), ...opts.env }), {} as Record<string, string | undefined>);\n const eng = guarded(() => (env.CAMADA_DISABLED === '1' ? null : ensure(opts, env)), null);\n if (!eng) return next();\n // Same opt-out as @camada/next: the code option, or CAMADA_CHALLENGE=0 in the Worker env.\n const challengeOn = opts.challenge !== false && env.CAMADA_CHALLENGE !== '0';\n\n const waitUntil: WaitUntil = (p) => {\n try { c.executionCtx?.waitUntil(p); } catch { /* no execution context outside a fetch handler */ }\n };\n\n // The id of the `warn` rule that let this request through, read again after next() when the\n // response event is built (§D3). Every other action settles before the app ever runs.\n let warnRule: string | null = null;\n // Set on the capture path only: the ids this request shares with the app (scriptTag, track)\n // and with its own post-response event. Null when camada answered the request itself.\n let vars: CamadaVars | null = null;\n let newSession = false;\n\n const answer = await guardedAsync(async (): Promise<Response | null> => {\n eng.snap.ensureFresh(waitUntil);\n\n const req = c.req.raw;\n const { url, path, cf, ip, sid } = describeRequest(eng, req);\n\n const v = eng.snap.verdict({\n ip, path, ua: req.headers.get('user-agent'), // §D3: without ua every `ua` rule is false\n // `header` conditions read the request through this getter; `Headers.get` is\n // case-insensitive, so the lower-cased name the matcher asks with finds whatever\n // spelling the client sent. Without it every `header` rule is false.\n header: (n) => req.headers.get(n),\n asn: cf.asn ?? null, country: cf.country ?? null, tlsx: cf.tlsClientExtensionsSha1 ?? null,\n });\n warnRule = v.warn ? v.rule ?? null : null;\n\n if (v.block) {\n const ev = buildEvent(req, path, url.search, ip, sid);\n ev.st = 403;\n ev.blk = v.reason; // SDK-01: the analyst counts SDK blocks apart from the app's own 403s ('rule' when a rule decided)\n if (v.rule) ev.rl = v.rule;\n ship(eng, ev, waitUntil);\n const headers: Record<string, string> = {\n 'content-type': 'text/plain', 'x-block-reason': String(v.reason ?? ''), 'x-block-version': v.version ?? '',\n };\n if (v.rule) headers['x-block-rule'] = v.rule; // a custom rule blocked: name it, so the customer knows which row to edit\n return new Response('Forbidden', { status: 403, headers });\n }\n\n // A challenge needs a resolved client ip: the nonce and the `_cch` cookie are bound to it.\n // Without one, fail open rather than mint a cookie every unidentified client could use.\n if (challengeOn && ip) {\n // The verify endpoint answers first — a challenged client must be able to reach it.\n if (req.method === 'POST' && path === challengePath) return verify(eng, req, ip, sid, challengePath, waitUntil);\n const token = cookieValue(req.headers.get('cookie') || '', CHALLENGE_COOKIE);\n if (v.challenge && !(await eng.kit.tokenValid(ip, Date.now(), token))) {\n return serve(eng, req, ip, sid, challengePath, path + url.search, waitUntil);\n }\n }\n\n // The beacon endpoints come after enforcement (a blocked or challenged client gets neither\n // the script nor a relay) and before the app (they are camada's, not its) — @camada/node's order.\n if (beaconEnabled(eng)) {\n if (req.method === 'GET' && path === scriptPath) {\n return new Response(iife, { status: 200, headers: { 'content-type': 'application/javascript', 'cache-control': 'public, max-age=3600' } });\n }\n if (req.method === 'POST' && path === fpPath) return relayBeacon(eng, req, ip, waitUntil);\n }\n\n // Capture: mint the ids the app, the beacon and the post-response event all share. The\n // session is decided here rather than after next() so track() inside the handler and the\n // event both carry the sid a first visit is about to be given.\n newSession = !sid;\n vars = { eng, rid: crypto.randomUUID(), sid: sid ?? crypto.randomUUID(), ip, waitUntil, scriptPath };\n c.set(VAR, vars);\n return null;\n }, null);\n\n if (answer) return answer;\n\n await next();\n\n // Mint the shared session cookie the other taps use, so `sid`/`ns` are real here too\n // (ea's capability mask for sdk-hono claims SESSION). Never overwrite an existing one.\n guarded(() => {\n if (!vars || !newSession) return;\n const secure = new URL(c.req.raw.url).protocol === 'https:' ? '; Secure' : '';\n c.res.headers.append('set-cookie', `${SESSION_COOKIE}=${vars.sid}; Path=/; Max-Age=${SESSION_MAX_AGE}; HttpOnly; SameSite=Lax${secure}`);\n }, undefined);\n\n // The response has settled, so this tap ships the real status — unlike @camada/next's\n // middleware position, which can only report pre-response.\n void guardedAsync(async () => {\n const req = c.req.raw;\n const { url, path, ip } = describeRequest(eng, req);\n const cfg = eng.snap.config;\n if ((cfg?.exclude || []).some((x) => path.startsWith(x))) return;\n if (Math.random() >= (cfg?.sample ?? 1)) return;\n // `vars` is null only when the guard above threw before setting it — then the event still ships, with fresh ids.\n const ev = buildEvent(req, path, url.search, ip, vars?.sid ?? null, vars?.rid, newSession);\n ev.st = c.res.status;\n if (warnRule) ev.wrn = warnRule; // §D3: the warn rule that let this request through\n ship(eng, ev, waitUntil);\n }, undefined);\n };\n}\n\n/** 403 + the proof-of-work page (HTML navigations) or 403 JSON, plus the `blk: \"challenge\"` event. */\nasync function serve(eng: Engine, req: Request, ip: string, sid: string | null, action: string, target: string, waitUntil: WaitUntil): Promise<Response> {\n const url = new URL(req.url);\n const ev = buildEvent(req, url.pathname, url.search, ip, sid);\n ev.st = 403;\n ev.blk = 'challenge';\n ship(eng, ev, waitUntil);\n\n if (!wantsHtml(req.headers.get('accept'), req.headers.get('sec-fetch-dest'))) {\n return new Response('{\"error\":\"challenge_required\"}', {\n status: 403,\n headers: { 'content-type': 'application/json', 'cache-control': 'no-store', 'x-camada-challenge': '1' },\n });\n }\n const html = challengePage({ nonce: await eng.kit.nonce(ip, Date.now()), action, to: safeReturnTo(target) });\n return new Response(html, {\n status: 403,\n headers: { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store', 'x-camada-challenge': '1' },\n });\n}\n\n/** POST from the page: validate, set `_cch`, 302 back, ship `{ st: 200, ch: 1 }`. */\nasync function verify(eng: Engine, req: Request, ip: string, sid: string | null, action: string, waitUntil: WaitUntil): Promise<Response> {\n const url = new URL(req.url);\n // camada answers this path before the app runs, so it must not become a place to post\n // hundreds of megabytes at an unauthenticated endpoint.\n if (Number(req.headers.get('content-length')) > BODY_MAX) return new Response(null, { status: 413 });\n const body = await req.text();\n if (body.length > BODY_MAX) return new Response(null, { status: 413 });\n const form = parseFormBody(body);\n const to = safeReturnTo(form.to);\n const now = Date.now();\n if (!(await eng.kit.verify(ip, now, form.nonce, form.solution))) {\n const html = challengePage({ nonce: await eng.kit.nonce(ip, now), action, to });\n return new Response(html, { status: 403, headers: { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' } });\n }\n const ev = buildEvent(req, url.pathname, '', ip, sid);\n ev.st = 200;\n ev.ch = 1; // challenge passed (contract §A3 ingest field)\n ship(eng, ev, waitUntil);\n return new Response(null, {\n status: 302,\n headers: {\n location: to,\n 'set-cookie': challengeCookie(await eng.kit.issue(ip, now), url.protocol === 'https:'),\n 'cache-control': 'no-store',\n },\n });\n}\n","// Workers hand env vars per request on `c.env`, not on a process — so the engine is built from\n// whatever the first request carries, merged with the options the app passed in code.\nimport { parseKey, parseTrustedProxyEnv, type SnapshotVersion, type TrustedProxyConfig } from '@camada/core';\n\nexport interface ResolvedEnv {\n ingestToken: string;\n snapToken: string;\n secret: string; // HMAC key for the challenge nonce/cookie — never leaves the isolate\n ingestUrl: string;\n snapshotUrl: string;\n trustedProxy: TrustedProxyConfig | null; // null = defer to server-delivered config\n}\n\nexport interface CamadaHonoOptions {\n key?: string;\n ingestUrl?: string;\n snapshotUrl?: string;\n trustedProxy?: TrustedProxyConfig | string | null;\n challenge?: boolean; // enforce `challenge` verdicts with the first-party page (default true)\n challengePath?: string; // where that page posts its solution (default /__camada/challenge)\n snapshotVersion?: SnapshotVersion; // 5 (default) also carries the tenant's ordered custom rules; 4 the allow/challenge sides only; 3 opts out of both\n scriptPath?: string; // where the first-party beacon script is served (default /_cam/b.js)\n fpPath?: string; // where that script posts the beacon (default /_cam/fp; must share scriptPath's directory — the script derives it)\n env?: Record<string, string | undefined>; // overrides c.env (tests, and apps that read config themselves)\n fetchImpl?: typeof fetch;\n}\n\nconst asProxy = (v: CamadaHonoOptions['trustedProxy']): TrustedProxyConfig | null =>\n typeof v === 'string' ? parseTrustedProxyEnv(v) : v ?? null;\n\n/** Returns null (the middleware stays inert, one log line) rather than throwing on bad config. */\nexport function resolveEnv(opts: CamadaHonoOptions, env: Record<string, string | undefined>): ResolvedEnv | null {\n const raw = opts.key || env.CAMADA_KEY;\n const key = parseKey(raw);\n const ingestToken = key?.ingestToken ?? env.CAMADA_TOKEN;\n const snapToken = key?.snapToken ?? env.CAMADA_SNAPSHOT_TOKEN;\n if (!ingestToken || !snapToken) return null;\n const ingestUrl = (opts.ingestUrl || env.CAMADA_INGEST_URL || 'https://in.camada.dev').replace(/\\/$/, ''); // PLACEHOLDER default — confirm the production ingest domain before any npm publish\n return {\n ingestToken, snapToken,\n secret: raw || `${ingestToken}.${snapToken}`,\n ingestUrl,\n snapshotUrl: opts.snapshotUrl || env.CAMADA_SNAPSHOT_URL || `${ingestUrl}/snapshot`,\n trustedProxy: asProxy(opts.trustedProxy) ?? parseTrustedProxyEnv(env.CAMADA_TRUSTED_PROXY),\n };\n}\n","// Per-request state the middleware leaves on the Hono context for the two helpers an app calls\n// from its own handlers: `scriptTag(c)` (the beacon tag) and `track(c, event, data)` (an\n// app-context outcome). The key is private — the helpers are the API, not `c.get`. When the\n// middleware did not run for this request (a path it is not mounted on, no key, CAMADA_DISABLED,\n// or a request it answered itself) there is nothing on the context and both helpers stand down.\nimport type { Context } from 'hono';\nimport { guarded, guardedAsync, hashUserId, TAP_HONO } from '@camada/core';\nimport { ship, type Engine, type WaitUntil } from './camada.js';\n\nexport const VAR = '__camada';\n\nexport interface CamadaVars {\n eng: Engine;\n rid: string; // the request id the page event carries; the beacon and track() join on it\n sid: string; // the `_sfp` session — the one just minted when the request arrived without it\n ip: string | null;\n waitUntil: WaitUntil;\n scriptPath: string;\n}\n\nexport const beaconEnabled = (e: Engine): boolean => e.snap.config?.beacon !== false; // tenant switch; a cold engine serves\n\nconst readVars = (c: Context): CamadaVars | undefined => c.get(VAR) as CamadaVars | undefined;\n\n/**\n * Records an outcome the app knows and the wire cannot show: `login_failed`, `login_succeeded`,\n * `signup`, `password_reset`, `mfa_failed`, `payment_failed`, `payment_succeeded`, `coupon_failed`\n * (free-form; that vocabulary is what the analyst's rules read). Joined to this request's event\n * through its rid and session. The user identifier is HMAC-hashed in-process with the ingest\n * token — the raw value never reaches the queue. Never throws, never rejects; awaiting it is\n * optional (the flush rides `waitUntil`), so a handler may fire and forget.\n */\nexport function track(c: Context, event: string, data?: { user?: string }): Promise<void> {\n const vars = guarded(() => readVars(c), undefined);\n if (!vars) return Promise.resolve();\n const p = guardedAsync(async () => {\n const uid = data?.user ? await hashUserId(data.user, vars.eng.env.ingestToken) : null;\n ship(vars.eng, { tap: TAP_HONO, et: event, uid, rid: vars.rid, sid: vars.sid, ip: vars.ip, ts: Date.now() }, vars.waitUntil);\n }, undefined);\n vars.waitUntil(p); // the isolate may freeze right after the response: hold it open for the flush\n return p;\n}\n\n/** The `<script>` tag for an HTML response — `''` when camada is off for this request or the tenant turned the beacon off. */\nexport function scriptTag(c: Context): string {\n return guarded(() => {\n const vars = readVars(c);\n if (!vars || !beaconEnabled(vars.eng)) return '';\n return `<script src=\"${vars.scriptPath}?r=${vars.rid}\" async></script>`;\n }, '');\n}\n","{\n \"name\": \"@camada/hono\",\n \"version\": \"0.3.0\",\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"engines\": {\n \"node\": \">=18\"\n },\n \"files\": [\n \"dist\",\n \"README.md\",\n \"LICENSE\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"test\": \"vitest run\",\n \"check\": \"tsc --noEmit\"\n },\n \"description\": \"camada SDK for Hono on Cloudflare Workers: snapshot enforcement, first-party challenge and beacon, track() outcomes, waitUntil-flushed event shipping\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n }\n },\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"dependencies\": {\n \"@camada/core\": \"file:../camada-core\",\n \"@camada/browser\": \"file:../camada-browser\"\n },\n \"peerDependencies\": {\n \"hono\": \">=4\"\n },\n \"devDependencies\": {\n \"@cloudflare/workers-types\": \"^4.20250109.0\",\n \"@types/node\": \"^22.10.0\",\n \"hono\": \"^4.6.0\",\n \"tsup\": \"^8.3.5\",\n \"typescript\": \"^5.7.2\",\n \"vitest\": \"^3.0.0\"\n }\n}\n","// The SDK's wire identity (SDK-03): x-camada-sdk: <package>/<version>. Named JSON imports are\n// inlined and tree-shaken by tsup at build, so dist carries two literals — no runtime fs read.\nimport { name, version } from '../package.json';\nexport const SDK_ID = `${name}/${version}`;\n"],"mappings":";AAQA,OAAO,UAAU;AACjB;AAAA,EACE;AAAA,EAAgB;AAAA,EAAY;AAAA,EAAgB;AAAA,EAAiB;AAAA,EAAgB,gBAAAA;AAAA,EAC7E,WAAAC;AAAA,EAAS;AAAA,EAAsB;AAAA,EAAe;AAAA,EAAiB;AAAA,EAAc;AAAA,EAAW;AAAA,EACxF;AAAA,EAAkB;AAAA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SAAS,EAAE,gBAAgB,4BAA4B,iBAAiB,WAAW,EAAE,CAAC;AAAA,EACjI;AACA,QAAM,KAAK,WAAW,KAAK,IAAI,UAAU,IAAI,IAAI,GAAG;AACpD,KAAG,KAAK;AACR,KAAG,KAAK;AACR,OAAK,KAAK,IAAI,SAAS;AACvB,SAAO,IAAI,SAAS,MAAM;AAAA,IACxB,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,UAAU;AAAA,MACV,cAAc,gBAAgB,MAAM,IAAI,IAAI,MAAM,IAAI,GAAG,GAAG,IAAI,aAAa,QAAQ;AAAA,MACrF,iBAAiB;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":["guardedAsync","guarded","TAP_HONO","name","TAP_HONO","guarded","guardedAsync"]}
1
+ {"version":3,"sources":["../src/camada.ts","../src/env.ts","../src/context.ts","../package.json","../src/version.ts"],"sourcesContent":["// @camada/hono — the Hono middleware for Cloudflare Workers (SEC-07, D33).\n// app.use('*', camada());\n// Workers-native: `cf-connecting-ip` for the client address, `request.cf` for asn / country /\n// TLS fingerprint (so ASN and country rules really enforce at this tap), and\n// `c.executionCtx.waitUntil` so the snapshot poll and the event flush outlive the response.\n// Everything runs inside camada's fail-open envelope: a camada bug, a dead ingest or a corrupt\n// snapshot costs telemetry, never the app's response.\nimport type { Context, MiddlewareHandler, Next } from 'hono';\nimport iife from '@camada/browser/iife-string';\nimport {\n SnapshotClient, EventQueue, buildWireEvent, resolveClientIp, logRateLimited, guardedAsync,\n guarded, createChallengeAsync, challengePage, challengeCookie, safeReturnTo, wantsHtml, parseFormBody,\n CHALLENGE_COOKIE, DEFAULT_SNAPSHOT_VERSION, TAP_HONO,\n type AsyncChallengeKit, type TrustedProxyConfig, type WireEvent,\n} from '@camada/core';\nimport { resolveEnv, type CamadaHonoOptions, type ResolvedEnv } from './env.js';\nimport { VAR, beaconEnabled, type CamadaVars } from './context.js';\nimport { SDK_ID } from './version.js';\n\nconst DEFAULT_CHALLENGE_PATH = '/__camada/challenge';\nconst SCRIPT_PATH = '/_cam/b.js'; // the beacon IIFE; its auto-init posts to the sibling `fp` and reads the rid from ?r=\nconst FP_PATH = '/_cam/fp';\nconst FP_MAX = 32 * 1024; // matches the analyst's /fp cap: never accept what ingest will 413\nconst SESSION_COOKIE = '_sfp'; // the same session cookie as every other tap: sid/ns stay comparable\nconst SESSION_MAX_AGE = 2592000;\nconst BODY_MAX = 4 * 1024; // the verify form is ~120 bytes; anything larger is not ours\nconst encoder = new TextEncoder();\n\nexport interface Engine {\n env: ResolvedEnv;\n snap: SnapshotClient;\n queue: EventQueue;\n kit: AsyncChallengeKit;\n}\n\nexport type WaitUntil = (p: Promise<unknown>) => void;\n\n// One engine per resolved configuration, not per module: a Workers isolate can host several\n// Hono apps, and a shared singleton would enforce the first tenant's snapshot on the second\n// and sign its `_cch` cookies with the first tenant's secret. An unconfigured request is never\n// cached — a warm-up or a differently-keyed mount must not leave the isolate inert for good.\nconst engines = new Map<string, Engine>();\n\n/** Test/reset hook: drops every cached engine. */\nexport function resetCamada(): void {\n for (const e of engines.values()) { e.snap.stop(); e.queue.stop(); }\n engines.clear();\n}\n\nfunction ensure(opts: CamadaHonoOptions, ctxEnv: Record<string, string | undefined>): Engine | null {\n const env = resolveEnv(opts, ctxEnv);\n if (!env) {\n logRateLimited(new Error('CAMADA_KEY not set — camada is inactive'));\n return null;\n }\n const snapshotVersion = opts.snapshotVersion ?? DEFAULT_SNAPSHOT_VERSION;\n const id = `${env.ingestToken}|${env.ingestUrl}|${env.snapshotUrl}|${snapshotVersion}`;\n const cached = engines.get(id);\n if (cached) return cached;\n const injected = opts.fetchImpl ? { fetchImpl: opts.fetchImpl } : {}; // never pass an explicit undefined key\n const engine: Engine = {\n env,\n snap: new SnapshotClient({\n url: env.snapshotUrl, token: env.snapToken, mode: 'lazy', sdk: SDK_ID,\n snapshotVersion, ...injected,\n }),\n queue: new EventQueue({ url: env.ingestUrl, token: env.ingestToken, sdk: SDK_ID, ...injected }),\n kit: createChallengeAsync({ secret: env.secret }),\n };\n engines.set(id, engine);\n return engine;\n}\n\nconst cookieValue = (cookie: string, name: string): string | null => {\n const src = '; ' + cookie;\n const i = src.indexOf('; ' + name + '=');\n if (i === -1) return null;\n const start = i + name.length + 3;\n const j = src.indexOf(';', start);\n return src.slice(start, j === -1 ? undefined : j);\n};\n\ninterface CfProps { asn?: number; country?: string; tlsClientExtensionsSha1?: string; httpProtocol?: string }\nconst cfOf = (req: Request): CfProps => ((req as Request & { cf?: CfProps }).cf ?? {});\n\nconst trustedProxy = (e: Engine): TrustedProxyConfig | null =>\n e.env.trustedProxy ?? e.snap.config?.trusted_proxy ?? null;\n\n/** Cloudflare sets `cf-connecting-ip` itself and a client cannot forge it — but only on\n * Workers, which is also the only place `request.cf` exists. On any other Hono runtime\n * (node-server, Bun, Deno) that header is attacker-controlled, so it is ignored there and the\n * trusted-proxy rules decide, exactly as they do for X-Forwarded-For. */\nconst clientIp = (e: Engine, req: Request): string | null => {\n const cf = (req as Request & { cf?: unknown }).cf;\n const direct = cf ? req.headers.get('cf-connecting-ip') : null;\n return direct || resolveClientIp(null, req.headers.get('x-forwarded-for'), trustedProxy(e));\n};\n\ninterface RequestFacts {\n url: URL;\n path: string;\n cf: CfProps;\n ip: string | null;\n sid: string | null;\n}\n\nfunction describeRequest(e: Engine, req: Request): RequestFacts {\n const url = new URL(req.url);\n const cookies = req.headers.get('cookie') || '';\n return { url, path: url.pathname, cf: cfOf(req), ip: clientIp(e, req), sid: cookieValue(cookies, SESSION_COOKIE) };\n}\n\nfunction buildEvent(\n req: Request, path: string, query: string, ip: string | null, sid: string | null,\n rid: string = crypto.randomUUID(), newSession = false, // the capture path passes the ids it shared with the app; camada's own answers need none\n): WireEvent {\n const headers: Array<[string, string]> = [];\n req.headers.forEach((v, k) => headers.push([k, v])); // workerd normalises header order: no HEADER_ORDER signal here\n const cf = cfOf(req);\n const ev = buildWireEvent(\n {\n method: req.method, host: req.headers.get('host') ?? new URL(req.url).host, path, query, headers, ip,\n // The client's connection terminates at Cloudflare, so `cf.httpProtocol` really is the\n // visitor's protocol (ea's TAP_CAPS grants this tap TRUE_PROTO on that basis). Never read\n // a forwarded header for this — that would be the proxy's hop, not the client's.\n httpVersion: cf.httpProtocol ? cf.httpProtocol.replace(/^HTTP\\//i, '') : null,\n },\n { tap: TAP_HONO, rid, sid, newSession },\n );\n if (cf.asn) ev.asn = cf.asn;\n if (cf.country) ev.cc = cf.country;\n if (cf.tlsClientExtensionsSha1) ev.tlsx = cf.tlsClientExtensionsSha1;\n return ev;\n}\n\n/** Push then flush through `waitUntil` — the one rule every row (wire event, beacon, track()) follows. */\nexport function ship(e: Engine, ev: unknown, waitUntil: WaitUntil): void {\n e.queue.push(ev);\n e.queue.flush(waitUntil);\n}\n\n/** 204 and a `sig: 1` row on the event batch — one request per flush at the analyst, not one per page view. */\nasync function relayBeacon(eng: Engine, req: Request, ip: string | null, waitUntil: WaitUntil): Promise<Response> {\n const noContent = () => new Response(null, { status: 204, headers: { 'cache-control': 'no-store' } });\n if (Number(req.headers.get('content-length')) > FP_MAX) return new Response(null, { status: 413 });\n const body = await req.text();\n if (encoder.encode(body).byteLength > FP_MAX) return new Response(null, { status: 413 });\n let parsed: unknown;\n try { parsed = JSON.parse(body); } catch { return noContent(); } // not a beacon: drop it, never ship junk\n if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return noContent();\n // Spread first: the ip and the tap are the server's to say, whatever the body claimed.\n ship(eng, { ...(parsed as Record<string, unknown>), sig: 1, ip, tap: TAP_HONO }, waitUntil);\n return noContent();\n}\n\nexport function camada(opts: CamadaHonoOptions = {}): MiddlewareHandler {\n const challengePath = opts.challengePath ?? DEFAULT_CHALLENGE_PATH;\n const scriptPath = opts.scriptPath ?? SCRIPT_PATH;\n const fpPath = opts.fpPath ?? FP_PATH;\n\n return async function camadaHono(c: Context, next: Next): Promise<Response | void> {\n const t0 = Date.now(); // request start; the response event ships dur = settle - t0 (ms), @camada/node's semantics\n // Reading c.env and building the engine are inside the guard too: a Workers env carries\n // non-string bindings, and a throw here would 5xx the app on its very first request.\n const env = guarded(() => ({ ...(c.env as Record<string, string | undefined> | undefined), ...opts.env }), {} as Record<string, string | undefined>);\n const eng = guarded(() => (env.CAMADA_DISABLED === '1' ? null : ensure(opts, env)), null);\n if (!eng) return next();\n // Same opt-out as @camada/next: the code option, or CAMADA_CHALLENGE=0 in the Worker env.\n const challengeOn = opts.challenge !== false && env.CAMADA_CHALLENGE !== '0';\n\n const waitUntil: WaitUntil = (p) => {\n try { c.executionCtx?.waitUntil(p); } catch { /* no execution context outside a fetch handler */ }\n };\n\n // The id of the `warn` rule that let this request through, read again after next() when the\n // response event is built (§D3). Every other action settles before the app ever runs.\n let warnRule: string | null = null;\n // Set on the capture path only: the ids this request shares with the app (scriptTag, track)\n // and with its own post-response event. Null when camada answered the request itself.\n let vars: CamadaVars | null = null;\n let newSession = false;\n\n const answer = await guardedAsync(async (): Promise<Response | null> => {\n eng.snap.ensureFresh(waitUntil);\n\n const req = c.req.raw;\n const { url, path, cf, ip, sid } = describeRequest(eng, req);\n\n const v = eng.snap.verdict({\n ip, path, ua: req.headers.get('user-agent'), // §D3: without ua every `ua` rule is false\n // `header` conditions read the request through this getter; `Headers.get` is\n // case-insensitive, so the lower-cased name the matcher asks with finds whatever\n // spelling the client sent. Without it every `header` rule is false.\n header: (n) => req.headers.get(n),\n asn: cf.asn ?? null, country: cf.country ?? null, tlsx: cf.tlsClientExtensionsSha1 ?? null,\n });\n warnRule = v.warn ? v.rule ?? null : null;\n\n if (v.block) {\n const ev = buildEvent(req, path, url.search, ip, sid);\n ev.st = 403;\n ev.blk = v.reason; // SDK-01: the analyst counts SDK blocks apart from the app's own 403s ('rule' when a rule decided)\n if (v.rule) ev.rl = v.rule;\n ship(eng, ev, waitUntil);\n const headers: Record<string, string> = {\n 'content-type': 'text/plain', 'x-block-reason': String(v.reason ?? ''), 'x-block-version': v.version ?? '',\n };\n if (v.rule) headers['x-block-rule'] = v.rule; // a custom rule blocked: name it, so the customer knows which row to edit\n return new Response('Forbidden', { status: 403, headers });\n }\n\n // A challenge needs a resolved client ip: the nonce and the `_cch` cookie are bound to it.\n // Without one, fail open rather than mint a cookie every unidentified client could use.\n if (challengeOn && ip) {\n // The verify endpoint answers first — a challenged client must be able to reach it.\n if (req.method === 'POST' && path === challengePath) return verify(eng, req, ip, sid, challengePath, waitUntil);\n const token = cookieValue(req.headers.get('cookie') || '', CHALLENGE_COOKIE);\n if (v.challenge && !(await eng.kit.tokenValid(ip, Date.now(), token))) {\n return serve(eng, req, ip, sid, challengePath, path + url.search, waitUntil);\n }\n }\n\n // The beacon endpoints come after enforcement (a blocked or challenged client gets neither\n // the script nor a relay) and before the app (they are camada's, not its) — @camada/node's order.\n if (beaconEnabled(eng)) {\n if (req.method === 'GET' && path === scriptPath) {\n return new Response(iife, { status: 200, headers: { 'content-type': 'application/javascript', 'cache-control': 'public, max-age=3600' } });\n }\n if (req.method === 'POST' && path === fpPath) return relayBeacon(eng, req, ip, waitUntil);\n }\n\n // Capture: mint the ids the app, the beacon and the post-response event all share. The\n // session is decided here rather than after next() so track() inside the handler and the\n // event both carry the sid a first visit is about to be given.\n newSession = !sid;\n vars = { eng, rid: crypto.randomUUID(), sid: sid ?? crypto.randomUUID(), ip, waitUntil, scriptPath };\n c.set(VAR, vars);\n return null;\n }, null);\n\n if (answer) return answer;\n\n await next();\n\n // Mint the shared session cookie the other taps use, so `sid`/`ns` are real here too\n // (ea's capability mask for sdk-hono claims SESSION). Never overwrite an existing one.\n guarded(() => {\n if (!vars || !newSession) return;\n const secure = new URL(c.req.raw.url).protocol === 'https:' ? '; Secure' : '';\n c.res.headers.append('set-cookie', `${SESSION_COOKIE}=${vars.sid}; Path=/; Max-Age=${SESSION_MAX_AGE}; HttpOnly; SameSite=Lax${secure}`);\n }, undefined);\n\n // The response has settled, so this tap ships the real status — unlike @camada/next's\n // middleware position, which can only report pre-response.\n void guardedAsync(async () => {\n const req = c.req.raw;\n const { url, path, ip } = describeRequest(eng, req);\n const cfg = eng.snap.config;\n if ((cfg?.exclude || []).some((x) => path.startsWith(x))) return;\n if (Math.random() >= (cfg?.sample ?? 1)) return;\n // `vars` is null only when the guard above threw before setting it — then the event still ships, with fresh ids.\n const ev = buildEvent(req, path, url.search, ip, vars?.sid ?? null, vars?.rid, newSession);\n ev.st = c.res.status;\n ev.dur = Math.max(0, Date.now() - t0);\n if (warnRule) ev.wrn = warnRule; // §D3: the warn rule that let this request through\n ship(eng, ev, waitUntil);\n }, undefined);\n };\n}\n\n/** 403 + the proof-of-work page (HTML navigations) or 403 JSON, plus the `blk: \"challenge\"` event. */\nasync function serve(eng: Engine, req: Request, ip: string, sid: string | null, action: string, target: string, waitUntil: WaitUntil): Promise<Response> {\n const url = new URL(req.url);\n const ev = buildEvent(req, url.pathname, url.search, ip, sid);\n ev.st = 403;\n ev.blk = 'challenge';\n ship(eng, ev, waitUntil);\n\n if (!wantsHtml(req.headers.get('accept'), req.headers.get('sec-fetch-dest'))) {\n return new Response('{\"error\":\"challenge_required\"}', {\n status: 403,\n headers: { 'content-type': 'application/json', 'cache-control': 'no-store', 'x-camada-challenge': '1' },\n });\n }\n const html = challengePage({ nonce: await eng.kit.nonce(ip, Date.now()), action, to: safeReturnTo(target) });\n return new Response(html, {\n status: 403,\n headers: { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store', 'x-camada-challenge': '1' },\n });\n}\n\n/** POST from the page: validate, set `_cch`, 302 back, ship `{ st: 200, ch: 1 }`. */\nasync function verify(eng: Engine, req: Request, ip: string, sid: string | null, action: string, waitUntil: WaitUntil): Promise<Response> {\n const url = new URL(req.url);\n // camada answers this path before the app runs, so it must not become a place to post\n // hundreds of megabytes at an unauthenticated endpoint.\n if (Number(req.headers.get('content-length')) > BODY_MAX) return new Response(null, { status: 413 });\n const body = await req.text();\n if (body.length > BODY_MAX) return new Response(null, { status: 413 });\n const form = parseFormBody(body);\n const to = safeReturnTo(form.to);\n const now = Date.now();\n if (!(await eng.kit.verify(ip, now, form.nonce, form.solution))) {\n const html = challengePage({ nonce: await eng.kit.nonce(ip, now), action, to });\n return new Response(html, { status: 403, headers: { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' } });\n }\n const ev = buildEvent(req, url.pathname, '', ip, sid);\n ev.st = 200;\n ev.ch = 1; // challenge passed (contract §A3 ingest field)\n ship(eng, ev, waitUntil);\n return new Response(null, {\n status: 302,\n headers: {\n location: to,\n 'set-cookie': challengeCookie(await eng.kit.issue(ip, now), url.protocol === 'https:'),\n 'cache-control': 'no-store',\n },\n });\n}\n","// Workers hand env vars per request on `c.env`, not on a process — so the engine is built from\n// whatever the first request carries, merged with the options the app passed in code.\nimport { parseKey, parseTrustedProxyEnv, type SnapshotVersion, type TrustedProxyConfig } from '@camada/core';\n\nexport interface ResolvedEnv {\n ingestToken: string;\n snapToken: string;\n secret: string; // HMAC key for the challenge nonce/cookie — never leaves the isolate\n ingestUrl: string;\n snapshotUrl: string;\n trustedProxy: TrustedProxyConfig | null; // null = defer to server-delivered config\n}\n\nexport interface CamadaHonoOptions {\n key?: string;\n ingestUrl?: string;\n snapshotUrl?: string;\n trustedProxy?: TrustedProxyConfig | string | null;\n challenge?: boolean; // enforce `challenge` verdicts with the first-party page (default true)\n challengePath?: string; // where that page posts its solution (default /__camada/challenge)\n snapshotVersion?: SnapshotVersion; // 5 (default) also carries the tenant's ordered custom rules; 4 the allow/challenge sides only; 3 opts out of both\n scriptPath?: string; // where the first-party beacon script is served (default /_cam/b.js)\n fpPath?: string; // where that script posts the beacon (default /_cam/fp; must share scriptPath's directory — the script derives it)\n env?: Record<string, string | undefined>; // overrides c.env (tests, and apps that read config themselves)\n fetchImpl?: typeof fetch;\n}\n\nconst asProxy = (v: CamadaHonoOptions['trustedProxy']): TrustedProxyConfig | null =>\n typeof v === 'string' ? parseTrustedProxyEnv(v) : v ?? null;\n\n/** Returns null (the middleware stays inert, one log line) rather than throwing on bad config. */\nexport function resolveEnv(opts: CamadaHonoOptions, env: Record<string, string | undefined>): ResolvedEnv | null {\n const raw = opts.key || env.CAMADA_KEY;\n const key = parseKey(raw);\n const ingestToken = key?.ingestToken ?? env.CAMADA_TOKEN;\n const snapToken = key?.snapToken ?? env.CAMADA_SNAPSHOT_TOKEN;\n if (!ingestToken || !snapToken) return null;\n const ingestUrl = (opts.ingestUrl || env.CAMADA_INGEST_URL || 'https://in.camada.app').replace(/\\/$/, ''); // PLACEHOLDER default — confirm the production ingest domain before any npm publish\n return {\n ingestToken, snapToken,\n secret: raw || `${ingestToken}.${snapToken}`,\n ingestUrl,\n snapshotUrl: opts.snapshotUrl || env.CAMADA_SNAPSHOT_URL || `${ingestUrl}/snapshot`,\n trustedProxy: asProxy(opts.trustedProxy) ?? parseTrustedProxyEnv(env.CAMADA_TRUSTED_PROXY),\n };\n}\n","// Per-request state the middleware leaves on the Hono context for the two helpers an app calls\n// from its own handlers: `scriptTag(c)` (the beacon tag) and `track(c, event, data)` (an\n// app-context outcome). The key is private — the helpers are the API, not `c.get`. When the\n// middleware did not run for this request (a path it is not mounted on, no key, CAMADA_DISABLED,\n// or a request it answered itself) there is nothing on the context and both helpers stand down.\nimport type { Context } from 'hono';\nimport { guarded, guardedAsync, hashUserId, TAP_HONO } from '@camada/core';\nimport { ship, type Engine, type WaitUntil } from './camada.js';\n\nexport const VAR = '__camada';\n\nexport interface CamadaVars {\n eng: Engine;\n rid: string; // the request id the page event carries; the beacon and track() join on it\n sid: string; // the `_sfp` session — the one just minted when the request arrived without it\n ip: string | null;\n waitUntil: WaitUntil;\n scriptPath: string;\n}\n\nexport const beaconEnabled = (e: Engine): boolean => e.snap.config?.beacon !== false; // tenant switch; a cold engine serves\n\nconst readVars = (c: Context): CamadaVars | undefined => c.get(VAR) as CamadaVars | undefined;\n\n/**\n * Records an outcome the app knows and the wire cannot show: `login_failed`, `login_succeeded`,\n * `signup`, `password_reset`, `mfa_failed`, `payment_failed`, `payment_succeeded`, `coupon_failed`\n * (free-form; that vocabulary is what the analyst's rules read). Joined to this request's event\n * through its rid and session. The user identifier is HMAC-hashed in-process with the ingest\n * token — the raw value never reaches the queue. Never throws, never rejects; awaiting it is\n * optional (the flush rides `waitUntil`), so a handler may fire and forget.\n */\nexport function track(c: Context, event: string, data?: { user?: string }): Promise<void> {\n const vars = guarded(() => readVars(c), undefined);\n if (!vars) return Promise.resolve();\n const p = guardedAsync(async () => {\n const uid = data?.user ? await hashUserId(data.user, vars.eng.env.ingestToken) : null;\n ship(vars.eng, { tap: TAP_HONO, et: event, uid, rid: vars.rid, sid: vars.sid, ip: vars.ip, ts: Date.now() }, vars.waitUntil);\n }, undefined);\n vars.waitUntil(p); // the isolate may freeze right after the response: hold it open for the flush\n return p;\n}\n\n/** The `<script>` tag for an HTML response — `''` when camada is off for this request or the tenant turned the beacon off. */\nexport function scriptTag(c: Context): string {\n return guarded(() => {\n const vars = readVars(c);\n if (!vars || !beaconEnabled(vars.eng)) return '';\n return `<script src=\"${vars.scriptPath}?r=${vars.rid}\" async></script>`;\n }, '');\n}\n","{\n \"name\": \"@camada/hono\",\n \"version\": \"0.3.1\",\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"engines\": {\n \"node\": \">=20\"\n },\n \"files\": [\n \"dist\",\n \"README.md\",\n \"LICENSE\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"test\": \"vitest run\",\n \"check\": \"tsc --noEmit\"\n },\n \"description\": \"camada SDK for Hono on Cloudflare Workers: snapshot enforcement, first-party challenge and beacon, track() outcomes, waitUntil-flushed event shipping\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n }\n },\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"dependencies\": {\n \"@camada/core\": \"file:../camada-core\",\n \"@camada/browser\": \"file:../camada-browser\"\n },\n \"peerDependencies\": {\n \"hono\": \">=4\"\n },\n \"devDependencies\": {\n \"@cloudflare/workers-types\": \"^4.20250109.0\",\n \"@types/node\": \"^22.10.0\",\n \"hono\": \"^4.6.0\",\n \"tsup\": \"^8.3.5\",\n \"typescript\": \"^5.7.2\",\n \"vitest\": \"^3.0.0\"\n }\n}\n","// The SDK's wire identity (SDK-03): x-camada-sdk: <package>/<version>. Named JSON imports are\n// inlined and tree-shaken by tsup at build, so dist carries two literals — no runtime fs read.\nimport { name, version } from '../package.json';\nexport const SDK_ID = `${name}/${version}`;\n"],"mappings":";AAQA,OAAO,UAAU;AACjB;AAAA,EACE;AAAA,EAAgB;AAAA,EAAY;AAAA,EAAgB;AAAA,EAAiB;AAAA,EAAgB,gBAAAA;AAAA,EAC7E,WAAAC;AAAA,EAAS;AAAA,EAAsB;AAAA,EAAe;AAAA,EAAiB;AAAA,EAAc;AAAA,EAAW;AAAA,EACxF;AAAA,EAAkB;AAAA,EAA0B,YAAAC;AAAA,OAEvC;;;ACZP,SAAS,UAAU,4BAA2E;AAyB9F,IAAM,UAAU,CAAC,MACf,OAAO,MAAM,WAAW,qBAAqB,CAAC,IAAI,KAAK;AAGlD,SAAS,WAAW,MAAyB,KAA6D;AAC/G,QAAM,MAAM,KAAK,OAAO,IAAI;AAC5B,QAAM,MAAM,SAAS,GAAG;AACxB,QAAM,cAAc,KAAK,eAAe,IAAI;AAC5C,QAAM,YAAY,KAAK,aAAa,IAAI;AACxC,MAAI,CAAC,eAAe,CAAC,UAAW,QAAO;AACvC,QAAM,aAAa,KAAK,aAAa,IAAI,qBAAqB,yBAAyB,QAAQ,OAAO,EAAE;AACxG,SAAO;AAAA,IACL;AAAA,IAAa;AAAA,IACb,QAAQ,OAAO,GAAG,WAAW,IAAI,SAAS;AAAA,IAC1C;AAAA,IACA,aAAa,KAAK,eAAe,IAAI,uBAAuB,GAAG,SAAS;AAAA,IACxE,cAAc,QAAQ,KAAK,YAAY,KAAK,qBAAqB,IAAI,oBAAoB;AAAA,EAC3F;AACF;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AGA,eAAe,OAAO,KAAa,KAAc,IAAY,KAAoB,QAAgB,WAAyC;AACxI,QAAM,MAAM,IAAI,IAAI,IAAI,GAAG;AAG3B,MAAI,OAAO,IAAI,QAAQ,IAAI,gBAAgB,CAAC,IAAI,SAAU,QAAO,IAAI,SAAS,MAAM,EAAE,QAAQ,IAAI,CAAC;AACnG,QAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,MAAI,KAAK,SAAS,SAAU,QAAO,IAAI,SAAS,MAAM,EAAE,QAAQ,IAAI,CAAC;AACrE,QAAM,OAAO,cAAc,IAAI;AAC/B,QAAM,KAAK,aAAa,KAAK,EAAE;AAC/B,QAAM,MAAM,KAAK,IAAI;AACrB,MAAI,CAAE,MAAM,IAAI,IAAI,OAAO,IAAI,KAAK,KAAK,OAAO,KAAK,QAAQ,GAAI;AAC/D,UAAM,OAAO,cAAc,EAAE,OAAO,MAAM,IAAI,IAAI,MAAM,IAAI,GAAG,GAAG,QAAQ,GAAG,CAAC;AAC9E,WAAO,IAAI,SAAS,MAAM,EAAE,QAAQ,KAAK,SAAS,EAAE,gBAAgB,4BAA4B,iBAAiB,WAAW,EAAE,CAAC;AAAA,EACjI;AACA,QAAM,KAAK,WAAW,KAAK,IAAI,UAAU,IAAI,IAAI,GAAG;AACpD,KAAG,KAAK;AACR,KAAG,KAAK;AACR,OAAK,KAAK,IAAI,SAAS;AACvB,SAAO,IAAI,SAAS,MAAM;AAAA,IACxB,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,UAAU;AAAA,MACV,cAAc,gBAAgB,MAAM,IAAI,IAAI,MAAM,IAAI,GAAG,GAAG,IAAI,aAAa,QAAQ;AAAA,MACrF,iBAAiB;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":["guardedAsync","guarded","TAP_HONO","name","TAP_HONO","guarded","guardedAsync"]}
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@camada/hono",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "engines": {
7
- "node": ">=18"
7
+ "node": ">=20"
8
8
  },
9
9
  "files": [
10
10
  "dist",
@@ -23,7 +23,7 @@
23
23
  "module": "./dist/index.js",
24
24
  "types": "./dist/index.d.ts",
25
25
  "dependencies": {
26
- "@camada/core": "^0.3.0",
26
+ "@camada/core": "^0.4.0",
27
27
  "@camada/browser": "^0.2.0"
28
28
  },
29
29
  "peerDependencies": {