@agenticprimitives/edge-cloudflare 0.0.0-alpha.21 → 0.0.0-alpha.23
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.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/rate-limiter.d.ts +12 -3
- package/dist/rate-limiter.d.ts.map +1 -1
- package/dist/rate-limiter.js +21 -5
- package/dist/rate-limiter.js.map +1 -1
- package/dist/request.d.ts +18 -3
- package/dist/request.d.ts.map +1 -1
- package/dist/request.js +49 -6
- package/dist/request.js.map +1 -1
- package/package.json +8 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { PACKAGE_NAME, PACKAGE_STATUS, SPEC_REF } from './types.js';
|
|
2
2
|
export type { RateLimiterBinding, FetcherLike } from './types.js';
|
|
3
|
-
export { extractAdmissionRequest } from './request.js';
|
|
4
|
-
export type { ExtractedRequest } from './request.js';
|
|
5
|
-
export { createCloudflareRateLimiter } from './rate-limiter.js';
|
|
3
|
+
export { extractAdmissionRequest, DEFAULT_EDGE_MAX_BODY_BYTES } from './request.js';
|
|
4
|
+
export type { ExtractedRequest, ExtractAdmissionRequestOpts } from './request.js';
|
|
5
|
+
export { createCloudflareRateLimiter, rateLimitBindingKey, MAX_RATE_LIMIT_KEY_LENGTH } from './rate-limiter.js';
|
|
6
6
|
export { dispatchToBinding } from './dispatch.js';
|
|
7
7
|
export type { DispatchInit } from './dispatch.js';
|
|
8
8
|
export { cfTlsClientAuthOf, transportEvidenceFromCf, transportEvidenceFromRequest, } from './transport-evidence.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACpE,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAElE,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACpE,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAElE,OAAO,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AACpF,YAAY,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAElF,OAAO,EAAE,2BAA2B,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAEhH,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAIlD,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,4BAA4B,GAC7B,MAAM,yBAAyB,CAAC;AACjC,YAAY,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @agenticprimitives/edge-cloudflare — public API.
|
|
2
2
|
// See ../../specs/288-agentic-edge-admission-and-surface-catalog.md (§5).
|
|
3
3
|
export { PACKAGE_NAME, PACKAGE_STATUS, SPEC_REF } from './types.js';
|
|
4
|
-
export { extractAdmissionRequest } from './request.js';
|
|
5
|
-
export { createCloudflareRateLimiter } from './rate-limiter.js';
|
|
4
|
+
export { extractAdmissionRequest, DEFAULT_EDGE_MAX_BODY_BYTES } from './request.js';
|
|
5
|
+
export { createCloudflareRateLimiter, rateLimitBindingKey, MAX_RATE_LIMIT_KEY_LENGTH } from './rate-limiter.js';
|
|
6
6
|
export { dispatchToBinding } from './dispatch.js';
|
|
7
7
|
// Optional mTLS evidence (spec 339 §10). Produces evidence; decides nothing — admission decides
|
|
8
8
|
// what a certificate is worth (ADR-0043). Absent evidence is a NORMAL request.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,0EAA0E;AAE1E,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,0EAA0E;AAE1E,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGpE,OAAO,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAGpF,OAAO,EAAE,2BAA2B,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAEhH,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGlD,gGAAgG;AAChG,+EAA+E;AAC/E,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,4BAA4B,GAC7B,MAAM,yBAAyB,CAAC"}
|
package/dist/rate-limiter.d.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import type { SoftRateLimiter } from '@agenticprimitives/rate-control';
|
|
2
2
|
import type { RateLimiterBinding } from './types.js';
|
|
3
|
+
/** Longest key handed to the binding as-is. */
|
|
4
|
+
export declare const MAX_RATE_LIMIT_KEY_LENGTH = 200;
|
|
5
|
+
/**
|
|
6
|
+
* The binding key for `profileId:key`. Short keys pass through. A longer one is replaced by
|
|
7
|
+
* `<prefix>~<sha256 of the WHOLE key>` — never cut (spec 445 / ING-18): two keys that agree on their first
|
|
8
|
+
* 200 characters used to share one bucket, so a caller who controlled the tail could not get its own bucket
|
|
9
|
+
* but a caller who shared a long prefix with a victim spent the victim's.
|
|
10
|
+
*/
|
|
11
|
+
export declare function rateLimitBindingKey(profileId: string, key: string): Promise<string>;
|
|
3
12
|
/**
|
|
4
13
|
* Wrap a Cloudflare Workers rate-limiter binding as a `SoftRateLimiter`. The binding's
|
|
5
|
-
* `limit({ key })` returns `{ success }`; we map it to `{ allowed }
|
|
6
|
-
* length, so we namespace
|
|
7
|
-
* native binding counts one unit per call.
|
|
14
|
+
* `limit({ key })` returns `{ success }`; we map it to `{ allowed }` — anything but `success === true`
|
|
15
|
+
* is a denial. The binding key has limited length, so we namespace and, past the limit, hash
|
|
16
|
+
* (`rateLimitBindingKey`). `cost` is advisory — the native binding counts one unit per call.
|
|
8
17
|
*/
|
|
9
18
|
export declare function createCloudflareRateLimiter(binding: RateLimiterBinding): SoftRateLimiter;
|
|
10
19
|
//# sourceMappingURL=rate-limiter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rate-limiter.d.ts","sourceRoot":"","sources":["../src/rate-limiter.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,kBAAkB,GAAG,eAAe,CAQxF"}
|
|
1
|
+
{"version":3,"file":"rate-limiter.d.ts","sourceRoot":"","sources":["../src/rate-limiter.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,+CAA+C;AAC/C,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAE7C;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAMzF;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,kBAAkB,GAAG,eAAe,CAQxF"}
|
package/dist/rate-limiter.js
CHANGED
|
@@ -5,18 +5,34 @@
|
|
|
5
5
|
// FAIL-SOFT — `runAdmission` treats a limiter error as allow, because admission must not become a
|
|
6
6
|
// hard dependency on the abuse layer. Hard, per-SA budgets are a different surface (a Durable
|
|
7
7
|
// Object HardBudgetStore, spec 290 §7-§8), enforced after authority — never here.
|
|
8
|
+
/** Longest key handed to the binding as-is. */
|
|
9
|
+
export const MAX_RATE_LIMIT_KEY_LENGTH = 200;
|
|
10
|
+
/**
|
|
11
|
+
* The binding key for `profileId:key`. Short keys pass through. A longer one is replaced by
|
|
12
|
+
* `<prefix>~<sha256 of the WHOLE key>` — never cut (spec 445 / ING-18): two keys that agree on their first
|
|
13
|
+
* 200 characters used to share one bucket, so a caller who controlled the tail could not get its own bucket
|
|
14
|
+
* but a caller who shared a long prefix with a victim spent the victim's.
|
|
15
|
+
*/
|
|
16
|
+
export async function rateLimitBindingKey(profileId, key) {
|
|
17
|
+
const full = `${profileId}:${key}`;
|
|
18
|
+
if (full.length <= MAX_RATE_LIMIT_KEY_LENGTH)
|
|
19
|
+
return full;
|
|
20
|
+
const d = new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(full)));
|
|
21
|
+
const hex = [...d].map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
22
|
+
return `${full.slice(0, MAX_RATE_LIMIT_KEY_LENGTH - hex.length - 1)}~${hex}`;
|
|
23
|
+
}
|
|
8
24
|
/**
|
|
9
25
|
* Wrap a Cloudflare Workers rate-limiter binding as a `SoftRateLimiter`. The binding's
|
|
10
|
-
* `limit({ key })` returns `{ success }`; we map it to `{ allowed }
|
|
11
|
-
* length, so we namespace
|
|
12
|
-
* native binding counts one unit per call.
|
|
26
|
+
* `limit({ key })` returns `{ success }`; we map it to `{ allowed }` — anything but `success === true`
|
|
27
|
+
* is a denial. The binding key has limited length, so we namespace and, past the limit, hash
|
|
28
|
+
* (`rateLimitBindingKey`). `cost` is advisory — the native binding counts one unit per call.
|
|
13
29
|
*/
|
|
14
30
|
export function createCloudflareRateLimiter(binding) {
|
|
15
31
|
return {
|
|
16
32
|
async check(input) {
|
|
17
|
-
const key =
|
|
33
|
+
const key = await rateLimitBindingKey(input.profileId, input.key);
|
|
18
34
|
const { success } = await binding.limit({ key });
|
|
19
|
-
return { allowed: success };
|
|
35
|
+
return { allowed: success === true };
|
|
20
36
|
},
|
|
21
37
|
};
|
|
22
38
|
}
|
package/dist/rate-limiter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rate-limiter.js","sourceRoot":"","sources":["../src/rate-limiter.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,EAAE;AACF,kGAAkG;AAClG,oGAAoG;AACpG,kGAAkG;AAClG,8FAA8F;AAC9F,kFAAkF;AAKlF;;;;;GAKG;AACH,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"rate-limiter.js","sourceRoot":"","sources":["../src/rate-limiter.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,EAAE;AACF,kGAAkG;AAClG,oGAAoG;AACpG,kGAAkG;AAClG,8FAA8F;AAC9F,kFAAkF;AAKlF,+CAA+C;AAC/C,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,SAAiB,EAAE,GAAW;IACtE,MAAM,IAAI,GAAG,GAAG,SAAS,IAAI,GAAG,EAAE,CAAC;IACnC,IAAI,IAAI,CAAC,MAAM,IAAI,yBAAyB;QAAE,OAAO,IAAI,CAAC;IAC1D,MAAM,CAAC,GAAG,IAAI,UAAU,CAAC,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAChG,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACxE,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,yBAAyB,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC;AAC/E,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CAAC,OAA2B;IACrE,OAAO;QACL,KAAK,CAAC,KAAK,CAAC,KAAwD;YAClE,MAAM,GAAG,GAAG,MAAM,mBAAmB,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;YAClE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;YACjD,OAAO,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,EAAE,CAAC;QACvC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/request.d.ts
CHANGED
|
@@ -4,10 +4,25 @@ export interface ExtractedRequest {
|
|
|
4
4
|
/** The exact body bytes for byte-identical downstream forwarding (undefined for bodyless requests). */
|
|
5
5
|
rawBody?: ArrayBuffer;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* The most this extractor will buffer when the caller names no ceiling (16 MiB). The route's own
|
|
9
|
+
* `maxBodyBytes` is only known AFTER extraction, so without a ceiling here an unauthenticated caller chooses
|
|
10
|
+
* how much memory the edge spends before any limit applies (spec 445 / ING-18).
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_EDGE_MAX_BODY_BYTES: number;
|
|
13
|
+
export interface ExtractAdmissionRequestOpts {
|
|
14
|
+
/**
|
|
15
|
+
* Hard ceiling on the buffered body, in bytes. Default `DEFAULT_EDGE_MAX_BODY_BYTES`. Set it to the largest
|
|
16
|
+
* `maxBodyBytes` in the surface catalog. A body over the ceiling is NOT buffered: the result carries
|
|
17
|
+
* `admission.bodyTruncated = true` and no `rawBody`, and `runAdmission` answers 413. `Infinity` is the
|
|
18
|
+
* explicit opt-out (buffer whatever arrives).
|
|
19
|
+
*/
|
|
20
|
+
maxBodyBytes?: number;
|
|
21
|
+
}
|
|
7
22
|
/**
|
|
8
23
|
* Extract an `EdgeIngressRequest` (+ the raw body for exact forwarding) from a Web `Request`.
|
|
9
|
-
* Reads the body once
|
|
10
|
-
* pre-verification bucket key only, never trusted as authority.
|
|
24
|
+
* Reads the body once, up to `opts.maxBodyBytes`; safe for GET/HEAD (no body). The client IP is
|
|
25
|
+
* `cf-connecting-ip` — a pre-verification bucket key only, never trusted as authority.
|
|
11
26
|
*/
|
|
12
|
-
export declare function extractAdmissionRequest(request: Request): Promise<ExtractedRequest>;
|
|
27
|
+
export declare function extractAdmissionRequest(request: Request, opts?: ExtractAdmissionRequestOpts): Promise<ExtractedRequest>;
|
|
13
28
|
//# sourceMappingURL=request.d.ts.map
|
package/dist/request.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAE1E,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,kBAAkB,CAAC;IAC9B,uGAAuG;IACvG,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAWD;;;;GAIG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAE1E,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,kBAAkB,CAAC;IAC9B,uGAAuG;IACvG,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAWD;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,QAAmB,CAAC;AAE5D,MAAM,WAAW,2BAA2B;IAC1C;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AA2BD;;;;GAIG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,GAAE,2BAAgC,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAsBjI"}
|
package/dist/request.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Map a Web `Request` to the runtime-neutral `EdgeIngressRequest`, preserving the EXACT body bytes.
|
|
2
2
|
//
|
|
3
|
-
// The body is read ONCE here as an ArrayBuffer: `bodyBytes` is its byteLength, `bodyText` is the
|
|
3
|
+
// The body is read ONCE here, up to a ceiling (`maxBodyBytes`, default 16 MiB — ING-18), as an ArrayBuffer: `bodyBytes` is its byteLength, `bodyText` is the
|
|
4
4
|
// UTF-8 decode (for the admission JSON depth/envelope checks), and the SAME ArrayBuffer is returned
|
|
5
5
|
// as `rawBody` so the dispatcher forwards byte-identical bytes downstream — the native pipeline
|
|
6
6
|
// re-hashes them (spec 287 / hashA2aMessage), so a re-serialize would break the proof.
|
|
@@ -12,24 +12,67 @@ function lowercaseHeaders(h) {
|
|
|
12
12
|
});
|
|
13
13
|
return out;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* The most this extractor will buffer when the caller names no ceiling (16 MiB). The route's own
|
|
17
|
+
* `maxBodyBytes` is only known AFTER extraction, so without a ceiling here an unauthenticated caller chooses
|
|
18
|
+
* how much memory the edge spends before any limit applies (spec 445 / ING-18).
|
|
19
|
+
*/
|
|
20
|
+
export const DEFAULT_EDGE_MAX_BODY_BYTES = 16 * 1024 * 1024;
|
|
21
|
+
/** Read at most `cap` bytes. `null` ⇒ the body is larger than `cap` (reading stopped; the stream is cancelled). */
|
|
22
|
+
async function readCapped(request, cap) {
|
|
23
|
+
const declared = Number(request.headers.get('content-length') ?? '');
|
|
24
|
+
if (Number.isFinite(declared) && declared > cap)
|
|
25
|
+
return { over: declared };
|
|
26
|
+
const stream = request.body;
|
|
27
|
+
if (!stream)
|
|
28
|
+
return { bytes: new ArrayBuffer(0) };
|
|
29
|
+
const reader = stream.getReader();
|
|
30
|
+
const chunks = [];
|
|
31
|
+
let total = 0;
|
|
32
|
+
for (;;) {
|
|
33
|
+
const { done, value } = await reader.read();
|
|
34
|
+
if (done)
|
|
35
|
+
break;
|
|
36
|
+
total += value.byteLength;
|
|
37
|
+
if (total > cap) {
|
|
38
|
+
await reader.cancel().catch(() => undefined);
|
|
39
|
+
return { over: total };
|
|
40
|
+
}
|
|
41
|
+
chunks.push(value);
|
|
42
|
+
}
|
|
43
|
+
const out = new Uint8Array(total);
|
|
44
|
+
let off = 0;
|
|
45
|
+
for (const c of chunks) {
|
|
46
|
+
out.set(c, off);
|
|
47
|
+
off += c.byteLength;
|
|
48
|
+
}
|
|
49
|
+
return { bytes: out.buffer };
|
|
50
|
+
}
|
|
15
51
|
/**
|
|
16
52
|
* Extract an `EdgeIngressRequest` (+ the raw body for exact forwarding) from a Web `Request`.
|
|
17
|
-
* Reads the body once
|
|
18
|
-
* pre-verification bucket key only, never trusted as authority.
|
|
53
|
+
* Reads the body once, up to `opts.maxBodyBytes`; safe for GET/HEAD (no body). The client IP is
|
|
54
|
+
* `cf-connecting-ip` — a pre-verification bucket key only, never trusted as authority.
|
|
19
55
|
*/
|
|
20
|
-
export async function extractAdmissionRequest(request) {
|
|
56
|
+
export async function extractAdmissionRequest(request, opts = {}) {
|
|
57
|
+
const cap = opts.maxBodyBytes ?? DEFAULT_EDGE_MAX_BODY_BYTES;
|
|
58
|
+
// A ceiling that is not a number compares false against every size — i.e. no ceiling. Refuse to run that way.
|
|
59
|
+
if (Number.isNaN(cap) || cap < 0)
|
|
60
|
+
throw new Error('extractAdmissionRequest: maxBodyBytes must be a non-negative number');
|
|
21
61
|
const url = new URL(request.url);
|
|
22
62
|
const headers = lowercaseHeaders(request.headers);
|
|
23
63
|
const hasBody = request.method !== 'GET' && request.method !== 'HEAD';
|
|
24
|
-
const
|
|
64
|
+
const read = hasBody ? await readCapped(request, cap) : undefined;
|
|
65
|
+
const truncated = !!read && 'over' in read;
|
|
66
|
+
const rawBody = read && 'bytes' in read ? read.bytes : undefined;
|
|
25
67
|
const bodyText = rawBody && rawBody.byteLength > 0 ? new TextDecoder().decode(rawBody) : undefined;
|
|
26
68
|
const admission = {
|
|
27
69
|
method: request.method,
|
|
28
70
|
path: url.pathname,
|
|
29
71
|
headers,
|
|
30
72
|
ip: headers['cf-connecting-ip'],
|
|
31
|
-
bodyBytes: rawBody ? rawBody.byteLength : 0,
|
|
73
|
+
bodyBytes: truncated ? read.over : rawBody ? rawBody.byteLength : 0,
|
|
32
74
|
bodyText,
|
|
75
|
+
...(truncated ? { bodyTruncated: true } : {}),
|
|
33
76
|
};
|
|
34
77
|
return { admission, rawBody };
|
|
35
78
|
}
|
package/dist/request.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,EAAE;AACF,
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,EAAE;AACF,6JAA6J;AAC7J,oGAAoG;AACpG,gGAAgG;AAChG,uFAAuF;AAUvF,sGAAsG;AACtG,SAAS,gBAAgB,CAAC,CAAU;IAClC,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,CAAC,CAAC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IAAI,OAAO,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAEnG,MAAM,SAAS,GAAuB;QACpC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,IAAI,EAAE,GAAG,CAAC,QAAQ;QAClB,OAAO;QACP,EAAE,EAAE,OAAO,CAAC,kBAAkB,CAAC;QAC/B,SAAS,EAAE,SAAS,CAAC,CAAC,CAAE,IAAyB,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACzF,QAAQ;QACR,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9C,CAAC;IACF,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;AAChC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agenticprimitives/edge-cloudflare",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.23",
|
|
4
4
|
"description": "Cloudflare adapter for @agenticprimitives/edge-runtime: Request→AdmissionRequest extraction (exact-byte preserving), the Workers rate-limiter binding as a SoftRateLimiter, and Service-Binding dispatch. Imports the platform runtime; the edge core never does.",
|
|
5
5
|
"homepage": "https://agenticprimitives.dev",
|
|
6
6
|
"bugs": {
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@agenticprimitives/surface-catalog": "^0.0.0-alpha.
|
|
39
|
-
"@agenticprimitives/edge-runtime": "^0.0.0-alpha.
|
|
40
|
-
"@agenticprimitives/rate-control": "^0.0.0-alpha.
|
|
38
|
+
"@agenticprimitives/surface-catalog": "^0.0.0-alpha.6",
|
|
39
|
+
"@agenticprimitives/edge-runtime": "^0.0.0-alpha.23",
|
|
40
|
+
"@agenticprimitives/rate-control": "^0.0.0-alpha.6"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"vitest": "^4.1.11",
|
|
44
|
-
"@agenticprimitives/surface-catalog": "0.0.0-alpha.
|
|
45
|
-
"@agenticprimitives/edge-runtime": "0.0.0-alpha.
|
|
46
|
-
"@agenticprimitives/rate-control": "0.0.0-alpha.
|
|
44
|
+
"@agenticprimitives/surface-catalog": "0.0.0-alpha.6",
|
|
45
|
+
"@agenticprimitives/edge-runtime": "0.0.0-alpha.23",
|
|
46
|
+
"@agenticprimitives/rate-control": "0.0.0-alpha.6"
|
|
47
47
|
},
|
|
48
48
|
"keywords": [
|
|
49
49
|
"agentic",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"agentic-trust"
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@agenticprimitives/admission": "0.0.0-alpha.
|
|
61
|
+
"@agenticprimitives/admission": "0.0.0-alpha.22"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "tsc -p tsconfig.build.json",
|