@astrasyncai/adapter-edge 0.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/vercel.ts","../src/config.ts","../src/web.ts"],"sourcesContent":["/**\n * AstraSync Trusted Agent Gateway — Vercel Edge Middleware adapter.\n *\n * This package deliberately does NOT import `next`, so the middleware\n * cannot return `NextResponse.next()` itself. It returns either a\n * `Response` (enforce-mode short-circuit — return it as-is) or a\n * {@link GatewayPass} describing the header changes to apply before\n * continuing. Wire it up with a two-line wrapper:\n *\n * ```ts\n * // middleware.ts\n * import { NextResponse, type NextRequest } from 'next/server';\n * import { createGatewayMiddleware, applyGatewayPass } from '@astrasyncai/adapter-edge/vercel';\n *\n * const gateway = createGatewayMiddleware();\n *\n * export async function middleware(request: NextRequest) {\n * const result = await gateway(request);\n * if (result instanceof Response) return result;\n * return NextResponse.next({ request: { headers: applyGatewayPass(request.headers, result) } });\n * }\n * ```\n *\n * Alternatively pass a `next` factory in the options to get back a plain\n * `Response | undefined` middleware.\n *\n * Configuration comes from `process.env` (`ASTRASYNC_API_KEY`,\n * `ASTRASYNC_COUNTERPARTY_ID`, `ASTRASYNC_COUNTERPARTY_URL`, optional\n * `ASTRASYNC_API_BASE_URL`) or explicit options, which win.\n */\n\nimport { evaluateEdgeRequest } from '@astrasyncai/verification-gateway/edge-core';\nimport { resolveOptions, isConfigured, loadConfig } from './config';\nimport type { EdgeGatewayOptions, GatewayPass } from './types';\nimport { normalizeWebRequest, applyGatewayPass, toJsonResponse } from './web';\n\nexport { applyGatewayPass };\nexport type { EdgeGatewayOptions, GatewayPass } from './types';\n\nexport interface VercelGatewayOptions extends EdgeGatewayOptions {\n /**\n * Optional continue-factory. When provided, pass outcomes return\n * `next(pass, request)` instead of the raw {@link GatewayPass} — e.g.\n * `(pass, req) => NextResponse.next({ request: { headers: applyGatewayPass(req.headers, pass) } })`.\n * Kept injectable so this package stays dependency-free of `next`.\n */\n next?: (pass: GatewayPass, request: Request) => Response | undefined;\n}\n\n/** Structural subset of Vercel's middleware fetch event (for waitUntil). */\nexport interface VercelFetchEvent {\n waitUntil?(promise: Promise<unknown>): void;\n}\n\nexport type VercelGatewayMiddleware = (\n request: Request,\n event?: VercelFetchEvent\n) => Promise<Response | GatewayPass | undefined>;\n\nconst UNTOUCHED_PASS: GatewayPass = Object.freeze({\n action: 'pass' as const,\n injectHeaders: {},\n stripHeaderPrefixes: [],\n});\n\n/**\n * Connection-layer signals Vercel exposes as request headers. Absent\n * values are simply omitted.\n */\nexport function collectVercelConnection(request: Request): Record<string, string> {\n const out: Record<string, string> = {};\n const put = (key: string, headerName: string) => {\n const v = request.headers.get(headerName);\n if (v) out[key] = v;\n };\n put('ip', 'x-real-ip');\n put('country', 'x-vercel-ip-country');\n put('region', 'x-vercel-ip-country-region');\n put('city', 'x-vercel-ip-city');\n put('timeZone', 'x-vercel-ip-timezone');\n put('continent', 'x-vercel-ip-continent');\n // Present only on deployments with Vercel BotID enabled — harmless elsewhere.\n put('ja4', 'x-vercel-ja4-digest');\n return out;\n}\n\n/**\n * Create the middleware. NEVER blocks traffic outside enforce mode and\n * fails open (an untouched pass) on any internal error. Telemetry beacons\n * are scheduled through `event.waitUntil` when the runtime provides one.\n */\nexport function createGatewayMiddleware(\n options: VercelGatewayOptions = {}\n): VercelGatewayMiddleware {\n return async function middleware(request, event) {\n const resolved = resolveOptions(\n options,\n typeof process !== 'undefined' ? process.env : undefined,\n 'astrasync-edge/vercel'\n );\n const pass = (result: GatewayPass): Response | GatewayPass | undefined =>\n options.next ? options.next(result, request) : result;\n try {\n if (!isConfigured(resolved)) return pass(UNTOUCHED_PASS);\n\n const config = await loadConfig(resolved);\n const normalized = await normalizeWebRequest(request, {\n maxBodyBytes: resolved.maxBodyBytes,\n clientIp: request.headers.get('x-real-ip') ?? undefined,\n connection: collectVercelConnection(request),\n });\n\n const { application } = await evaluateEdgeRequest(\n {\n apiBaseUrl: resolved.apiBaseUrl,\n counterpartyId: resolved.counterpartyId,\n counterpartyUrl: resolved.counterpartyUrl,\n budgets: resolved.budgets,\n random: resolved.random,\n log: resolved.log,\n ...(event?.waitUntil && { waitUntil: (p: Promise<unknown>) => event.waitUntil!(p) }),\n },\n normalized,\n config,\n resolved.apiKey\n );\n\n if (application.action === 'respond') return toJsonResponse(application);\n return pass(application);\n } catch (err) {\n // Fail-open, unconditionally: the gateway must never take the site down.\n resolved.log('error', 'gateway error — passing request through', {\n error: err instanceof Error ? err.message : String(err),\n });\n return pass(UNTOUCHED_PASS);\n }\n };\n}\n","/**\n * Option/environment resolution and dashboard EdgeConfig loading shared by\n * the platform adapters.\n */\n\nimport {\n getEdgeConfig,\n DEFAULT_EDGE_CONFIG,\n type EdgeConfig,\n} from '@astrasyncai/verification-gateway/edge-config';\nimport type { EdgeLogger } from '@astrasyncai/verification-gateway/edge-core';\nimport type { EdgeGatewayOptions } from './types';\n\nexport const DEFAULT_API_BASE_URL = 'https://astrasync.ai/api';\n\nexport interface ResolvedGatewayOptions extends EdgeGatewayOptions {\n apiBaseUrl: string;\n log: EdgeLogger;\n}\n\nexport function defaultLogger(prefix: string): EdgeLogger {\n return (level, message, data) => {\n console[level === 'info' ? 'log' : level](`[${prefix}] ${message}`, data ?? '');\n };\n}\n\n/**\n * Merge explicit options with runtime environment variables (options win)\n * and apply defaults. `env` is the platform's environment map — Cloudflare\n * passes the worker `env` binding object, Vercel passes `process.env`,\n * Fastly Compute has no ambient env map (configure via options).\n */\nexport function resolveOptions(\n options: EdgeGatewayOptions,\n env: Record<string, string | undefined> | undefined,\n logPrefix: string\n): ResolvedGatewayOptions {\n const e = env ?? {};\n return {\n ...options,\n apiBaseUrl: options.apiBaseUrl ?? e.ASTRASYNC_API_BASE_URL ?? DEFAULT_API_BASE_URL,\n counterpartyId: options.counterpartyId ?? e.ASTRASYNC_COUNTERPARTY_ID,\n counterpartyUrl: options.counterpartyUrl ?? e.ASTRASYNC_COUNTERPARTY_URL,\n apiKey: options.apiKey ?? e.ASTRASYNC_API_KEY,\n log: options.log ?? defaultLogger(logPrefix),\n };\n}\n\n/**\n * Missing identity means the gateway cannot evaluate anything — it fails\n * OPEN (all traffic passes untouched) and says why, once per request.\n */\nexport function isConfigured(\n resolved: ResolvedGatewayOptions\n): resolved is ResolvedGatewayOptions & { counterpartyId: string; counterpartyUrl: string } {\n if (resolved.counterpartyId && resolved.counterpartyUrl) return true;\n resolved.log(\n 'error',\n 'counterpartyId/counterpartyUrl are not configured — passing all traffic through. ' +\n 'Set the ASTRASYNC_COUNTERPARTY_ID / ASTRASYNC_COUNTERPARTY_URL environment variables ' +\n 'or pass them as options.'\n );\n return false;\n}\n\n/**\n * Load the effective EdgeConfig. Delegates caching/fallback/degradation to\n * the SDK (60s TTL, stale-while-revalidate, enforce→observe degradation on\n * prolonged staleness) and never throws.\n */\nexport async function loadConfig(\n resolved: ResolvedGatewayOptions & { counterpartyId: string }\n): Promise<EdgeConfig> {\n try {\n return await getEdgeConfig(\n { apiBaseUrl: resolved.apiBaseUrl, apiKey: resolved.apiKey },\n resolved.counterpartyId,\n { ttlMs: resolved.configTtlMs }\n );\n } catch {\n return resolved.fallbackConfig ?? DEFAULT_EDGE_CONFIG;\n }\n}\n","/**\n * Shared web-standard platform I/O: converts a fetch-API `Request` into\n * the edge core's `NormalizedRequest`, and applies the core's abstract\n * outcome application back onto fetch-API primitives.\n */\n\nimport type {\n NormalizedRequest,\n OutcomeApplication,\n} from '@astrasyncai/verification-gateway/edge-core';\nimport type { GatewayPass } from './types';\n\n/** Default request-body read cap for commerce-protocol detection. */\nexport const DEFAULT_MAX_BODY_BYTES = 1024 * 1024;\n\nexport interface WebNormalizeOptions {\n /** Body read cap in bytes. Default {@link DEFAULT_MAX_BODY_BYTES}. */\n maxBodyBytes?: number;\n /** Client IP as the platform reports it. */\n clientIp?: string;\n /** Connection-layer metadata the platform collected (country, asn, …). */\n connection?: Record<string, string>;\n}\n\nasync function readBodyCapped(\n request: Request,\n cap: number\n): Promise<{ text?: string; truncated: boolean }> {\n if (request.method === 'GET' || request.method === 'HEAD') return { truncated: false };\n const body = request.clone().body;\n if (!body) return { truncated: false };\n\n const reader = body.getReader();\n const chunks: Uint8Array[] = [];\n let total = 0;\n let truncated = false;\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n if (total + value.byteLength > cap) {\n chunks.push(value.subarray(0, cap - total));\n total = cap;\n truncated = true;\n // Fire-and-forget: cancelling one branch of a cloned (tee'd) body can\n // only settle once the other branch is consumed — never await it.\n void reader.cancel().catch(() => {});\n break;\n }\n chunks.push(value);\n total += value.byteLength;\n }\n if (total === 0 && !truncated) return { truncated: false };\n\n const joined = new Uint8Array(total);\n let offset = 0;\n for (const chunk of chunks) {\n joined.set(chunk, offset);\n offset += chunk.byteLength;\n }\n return { text: new TextDecoder().decode(joined), truncated };\n}\n\n/**\n * Normalize a fetch-API `Request` into the edge core's request shape.\n * Header names are already lowercased (and multi-valued headers joined\n * with `\", \"`) by the `Headers` class. The body is read from a CLONE — the\n * original request stays forwardable to the origin — and capped at\n * `maxBodyBytes` (detection sees a flagged, truncated prefix beyond it).\n */\nexport async function normalizeWebRequest(\n request: Request,\n options: WebNormalizeOptions = {}\n): Promise<NormalizedRequest> {\n const url = new URL(request.url);\n const headers: Record<string, string> = {};\n request.headers.forEach((value, name) => {\n headers[name] = value;\n });\n const body = await readBodyCapped(request, options.maxBodyBytes ?? DEFAULT_MAX_BODY_BYTES);\n const connection = options.connection ?? {};\n return {\n method: request.method,\n uri: url.pathname,\n querystring: url.search.startsWith('?') ? url.search.slice(1) : url.search,\n headers,\n ...(body.text !== undefined && { bodyText: body.text }),\n ...(body.truncated && { bodyTruncated: true }),\n ...(options.clientIp && { clientIp: options.clientIp }),\n ...(Object.keys(connection).length > 0 && { connection }),\n };\n}\n\n/**\n * Apply a pass application to a header set: strip every header matching\n * one of the spoofable prefixes, then set the injected trust headers.\n * Returns a NEW `Headers` instance; the input is not mutated.\n */\nexport function applyGatewayPass(headers: Headers, pass: GatewayPass): Headers {\n const out = new Headers(headers);\n for (const prefix of pass.stripHeaderPrefixes) {\n const p = prefix.toLowerCase();\n for (const name of [...out.keys()]) {\n if (name.startsWith(p)) out.delete(name);\n }\n }\n for (const [name, value] of Object.entries(pass.injectHeaders)) {\n out.set(name, value);\n }\n return out;\n}\n\n/**\n * Build the origin-bound request for a pass application: the same request\n * with spoofable headers stripped and trust headers injected.\n */\nexport function buildPassRequest(request: Request, pass: GatewayPass): Request {\n if (pass.stripHeaderPrefixes.length === 0 && Object.keys(pass.injectHeaders).length === 0) {\n return request;\n }\n return new Request(request, { headers: applyGatewayPass(request.headers, pass) });\n}\n\n/** Build the short-circuit JSON response for a respond application. */\nexport function toJsonResponse(\n application: Extract<OutcomeApplication, { action: 'respond' }>\n): Response {\n return new Response(JSON.stringify(application.bodyJson), {\n status: application.status,\n headers: { 'content-type': 'application/json', ...application.headers },\n });\n}\n"],"mappings":";AA+BA,SAAS,2BAA2B;;;AC1BpC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAIA,IAAM,uBAAuB;AAO7B,SAAS,cAAc,QAA4B;AACxD,SAAO,CAAC,OAAO,SAAS,SAAS;AAC/B,YAAQ,UAAU,SAAS,QAAQ,KAAK,EAAE,IAAI,MAAM,KAAK,OAAO,IAAI,QAAQ,EAAE;AAAA,EAChF;AACF;AAQO,SAAS,eACd,SACA,KACA,WACwB;AACxB,QAAM,IAAI,OAAO,CAAC;AAClB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,YAAY,QAAQ,cAAc,EAAE,0BAA0B;AAAA,IAC9D,gBAAgB,QAAQ,kBAAkB,EAAE;AAAA,IAC5C,iBAAiB,QAAQ,mBAAmB,EAAE;AAAA,IAC9C,QAAQ,QAAQ,UAAU,EAAE;AAAA,IAC5B,KAAK,QAAQ,OAAO,cAAc,SAAS;AAAA,EAC7C;AACF;AAMO,SAAS,aACd,UAC0F;AAC1F,MAAI,SAAS,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;AAAA,UAClB,QAAQ,SAAS;AAAA,UACjB,KAAK,SAAS;AAAA,UACd,GAAI,OAAO,aAAa,EAAE,WAAW,CAAC,MAAwB,MAAM,UAAW,CAAC,EAAE;AAAA,QACpF;AAAA,QACA;AAAA,QACA;AAAA,QACA,SAAS;AAAA,MACX;AAEA,UAAI,YAAY,WAAW,UAAW,QAAO,eAAe,WAAW;AACvE,aAAO,KAAK,WAAW;AAAA,IACzB,SAAS,KAAK;AAEZ,eAAS,IAAI,SAAS,gDAA2C;AAAA,QAC/D,OAAO,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAAA,MACxD,CAAC;AACD,aAAO,KAAK,cAAc;AAAA,IAC5B;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,44 @@
1
+ import { NormalizedRequest, OutcomeApplication } from '@astrasyncai/verification-gateway/edge-core';
2
+ import { G as GatewayPass } from './types-7lIOikBV.js';
3
+
4
+ /**
5
+ * Shared web-standard platform I/O: converts a fetch-API `Request` into
6
+ * the edge core's `NormalizedRequest`, and applies the core's abstract
7
+ * outcome application back onto fetch-API primitives.
8
+ */
9
+
10
+ /** Default request-body read cap for commerce-protocol detection. */
11
+ declare const DEFAULT_MAX_BODY_BYTES: number;
12
+ interface WebNormalizeOptions {
13
+ /** Body read cap in bytes. Default {@link DEFAULT_MAX_BODY_BYTES}. */
14
+ maxBodyBytes?: number;
15
+ /** Client IP as the platform reports it. */
16
+ clientIp?: string;
17
+ /** Connection-layer metadata the platform collected (country, asn, …). */
18
+ connection?: Record<string, string>;
19
+ }
20
+ /**
21
+ * Normalize a fetch-API `Request` into the edge core's request shape.
22
+ * Header names are already lowercased (and multi-valued headers joined
23
+ * with `", "`) by the `Headers` class. The body is read from a CLONE — the
24
+ * original request stays forwardable to the origin — and capped at
25
+ * `maxBodyBytes` (detection sees a flagged, truncated prefix beyond it).
26
+ */
27
+ declare function normalizeWebRequest(request: Request, options?: WebNormalizeOptions): Promise<NormalizedRequest>;
28
+ /**
29
+ * Apply a pass application to a header set: strip every header matching
30
+ * one of the spoofable prefixes, then set the injected trust headers.
31
+ * Returns a NEW `Headers` instance; the input is not mutated.
32
+ */
33
+ declare function applyGatewayPass(headers: Headers, pass: GatewayPass): Headers;
34
+ /**
35
+ * Build the origin-bound request for a pass application: the same request
36
+ * with spoofable headers stripped and trust headers injected.
37
+ */
38
+ declare function buildPassRequest(request: Request, pass: GatewayPass): Request;
39
+ /** Build the short-circuit JSON response for a respond application. */
40
+ declare function toJsonResponse(application: Extract<OutcomeApplication, {
41
+ action: 'respond';
42
+ }>): Response;
43
+
44
+ export { DEFAULT_MAX_BODY_BYTES as D, type WebNormalizeOptions as W, applyGatewayPass as a, buildPassRequest as b, normalizeWebRequest as n, toJsonResponse as t };
package/package.json CHANGED
@@ -1,6 +1,66 @@
1
1
  {
2
2
  "name": "@astrasyncai/adapter-edge",
3
- "version": "0.0.0",
4
- "description": "placeholder — real release is 1.0.0",
5
- "license": "MIT"
3
+ "version": "1.1.0",
4
+ "description": "AstraSync Trusted Agent Gateway — edge adapters for Vercel Edge, Cloudflare Workers, and Fastly Compute",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js"
10
+ },
11
+ "./vercel": {
12
+ "types": "./dist/vercel.d.ts",
13
+ "import": "./dist/vercel.js"
14
+ },
15
+ "./cloudflare": {
16
+ "types": "./dist/cloudflare.d.ts",
17
+ "import": "./dist/cloudflare.js"
18
+ },
19
+ "./fastly": {
20
+ "types": "./dist/fastly.d.ts",
21
+ "import": "./dist/fastly.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "README.md"
27
+ ],
28
+ "scripts": {
29
+ "build": "tsup",
30
+ "lint": "eslint src --ext .ts",
31
+ "typecheck": "tsc --noEmit",
32
+ "test": "vitest run",
33
+ "test:watch": "vitest watch",
34
+ "clean": "rm -rf dist",
35
+ "check:dts-leaks": "node scripts/check-dts-leaks.mjs",
36
+ "prepublishOnly": "npm run clean && npm run typecheck && npm run build && npm run check:dts-leaks"
37
+ },
38
+ "keywords": [
39
+ "astrasync",
40
+ "trusted-agent-gateway",
41
+ "kya",
42
+ "edge",
43
+ "cloudflare-workers",
44
+ "vercel-edge",
45
+ "fastly-compute",
46
+ "agent-verification",
47
+ "bot-detection"
48
+ ],
49
+ "author": "AstraSync",
50
+ "license": "MIT",
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "https://github.com/AstraSync-KYA/KYA-Platform.git",
54
+ "directory": "packages/adapter-edge"
55
+ },
56
+ "dependencies": {
57
+ "@astrasyncai/verification-gateway": "^4.1.0"
58
+ },
59
+ "devDependencies": {
60
+ "@types/node": "^20.10.0",
61
+ "eslint": "^8.56.0",
62
+ "tsup": "^8.0.1",
63
+ "typescript": "^5.3.3",
64
+ "vitest": "^4.0.18"
65
+ }
6
66
  }