@rayselfs/cf-rule-engine 1.9.0 → 1.9.2

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.
Files changed (61) hide show
  1. package/dist/adapters/viewer-request-async.d.cts +23 -0
  2. package/dist/adapters/viewer-request-async.d.ts +23 -0
  3. package/dist/behaviors/construct-response.d.cts +2 -2
  4. package/dist/behaviors/construct-response.d.ts +2 -2
  5. package/dist/behaviors/image-optimize.d.cts +24 -13
  6. package/dist/behaviors/image-optimize.d.ts +24 -13
  7. package/dist/behaviors/index.cjs +3 -3
  8. package/dist/behaviors/index.d.cts +2 -2
  9. package/dist/behaviors/index.d.ts +2 -2
  10. package/dist/behaviors/index.js +2 -2
  11. package/dist/behaviors/kvs.d.cts +28 -0
  12. package/dist/behaviors/kvs.d.ts +28 -0
  13. package/dist/behaviors/redirect.d.cts +2 -2
  14. package/dist/behaviors/redirect.d.ts +2 -2
  15. package/dist/behaviors/set-cors-headers.cjs +3 -3
  16. package/dist/behaviors/set-cors-headers.d.cts +15 -5
  17. package/dist/behaviors/set-cors-headers.d.ts +15 -5
  18. package/dist/behaviors/set-cors-headers.js +2 -2
  19. package/dist/behaviors/set-csp.d.cts +2 -2
  20. package/dist/behaviors/set-csp.d.ts +2 -2
  21. package/dist/behaviors/set-security-headers.d.cts +2 -2
  22. package/dist/behaviors/set-security-headers.d.ts +2 -2
  23. package/dist/{chunk-ZEFLAOTL.cjs → chunk-7T4G7UF7.cjs} +2 -2
  24. package/dist/{chunk-EMDI676G.cjs → chunk-CLGM2TGT.cjs} +5 -5
  25. package/dist/{chunk-H3RK4USR.js → chunk-GKE3YDHR.js} +1 -1
  26. package/dist/chunk-HMQIXEFJ.cjs +62 -0
  27. package/dist/{chunk-VQGBRWJK.js → chunk-HWJFOKZX.js} +1 -1
  28. package/dist/{chunk-Y7TIDVVC.js → chunk-I7YELJ2P.js} +1 -1
  29. package/dist/{chunk-EEZ7NUJG.js → chunk-NJD4L4Q3.js} +3 -0
  30. package/dist/chunk-SC6UPQYF.js +62 -0
  31. package/dist/{chunk-IHVOAORH.cjs → chunk-TJ2POKWD.cjs} +2 -2
  32. package/dist/{chunk-7EA7GFWX.js → chunk-VRSD6YHP.js} +2 -2
  33. package/dist/{chunk-LVOM5GJ6.cjs → chunk-WUFGMLE7.cjs} +2 -2
  34. package/dist/{chunk-ULICUDDH.cjs → chunk-YNKZGZ7I.cjs} +3 -0
  35. package/dist/core/types.d.cts +8 -8
  36. package/dist/core/types.d.ts +8 -8
  37. package/dist/criteria/file-extension.d.cts +3 -3
  38. package/dist/criteria/file-extension.d.ts +3 -3
  39. package/dist/criteria/index.cjs +13 -13
  40. package/dist/criteria/index.js +16 -16
  41. package/dist/criteria/kvs.d.cts +28 -0
  42. package/dist/criteria/kvs.d.ts +28 -0
  43. package/dist/criteria/path-matches.cjs +3 -3
  44. package/dist/criteria/path-matches.js +2 -2
  45. package/dist/criteria/user-agent-matches.cjs +3 -3
  46. package/dist/criteria/user-agent-matches.js +2 -2
  47. package/dist/helpers/index.cjs +10 -8
  48. package/dist/helpers/index.js +9 -7
  49. package/dist/helpers/preflight-request.cjs +4 -4
  50. package/dist/helpers/preflight-request.js +3 -3
  51. package/dist/helpers/whitelist.cjs +7 -5
  52. package/dist/helpers/whitelist.d.cts +2 -37
  53. package/dist/helpers/whitelist.d.ts +2 -37
  54. package/dist/helpers/whitelist.js +6 -4
  55. package/dist/shared/kvs.d.cts +7 -2
  56. package/dist/shared/kvs.d.ts +7 -2
  57. package/dist/shared/wildcard.cjs +2 -2
  58. package/dist/shared/wildcard.js +1 -1
  59. package/package.json +1 -1
  60. package/dist/chunk-IHDSTTO2.js +0 -32
  61. package/dist/chunk-ISXKMJCN.cjs +0 -32
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  matchesOriginPattern
3
- } from "./chunk-EEZ7NUJG.js";
3
+ } from "./chunk-NJD4L4Q3.js";
4
4
 
5
5
  // src/behaviors/set-cors-headers.ts
6
6
  var ORIGIN_WILDCARD = "*";
@@ -0,0 +1,62 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+ var _chunk7T4G7UF7cjs = require('./chunk-7T4G7UF7.cjs');
4
+
5
+
6
+ var _chunkG7JGTBTTcjs = require('./chunk-G7JGTBTT.cjs');
7
+
8
+
9
+ var _chunkWUFGMLE7cjs = require('./chunk-WUFGMLE7.cjs');
10
+
11
+
12
+ var _chunkMK4QBCD5cjs = require('./chunk-MK4QBCD5.cjs');
13
+
14
+
15
+ var _chunkVEEOQ7TScjs = require('./chunk-VEEOQ7TS.cjs');
16
+
17
+
18
+ var _chunkWWSRNCUPcjs = require('./chunk-WWSRNCUP.cjs');
19
+
20
+
21
+
22
+
23
+
24
+ var _chunkWKYMSRCDcjs = require('./chunk-WKYMSRCD.cjs');
25
+
26
+ // src/helpers/whitelist.ts
27
+ function buildBypassCriteria(paths) {
28
+ const exactPaths = [];
29
+ const prefixPaths = [];
30
+ const wildcardPatterns = [];
31
+ for (let i = 0; i < paths.length; i++) {
32
+ const p = paths[i];
33
+ const hasWildcard = p.indexOf("*") !== -1 || p.indexOf("?") !== -1;
34
+ const isTrailingSlashStar = p.charAt(p.length - 1) === "*" && p.charAt(p.length - 2) === "/" && p.indexOf("*") === p.length - 1 && p.indexOf("?") === -1;
35
+ if (!hasWildcard) {
36
+ exactPaths.push(p);
37
+ } else if (isTrailingSlashStar) {
38
+ prefixPaths.push(p.slice(0, p.length - 1));
39
+ } else {
40
+ wildcardPatterns.push(p);
41
+ }
42
+ }
43
+ const criteria = [];
44
+ if (exactPaths.length > 0) criteria.push(_chunkVEEOQ7TScjs.pathEquals.call(void 0, exactPaths));
45
+ if (prefixPaths.length > 0) criteria.push(_chunkG7JGTBTTcjs.pathPrefix.call(void 0, prefixPaths));
46
+ if (wildcardPatterns.length > 0) criteria.push(_chunk7T4G7UF7cjs.pathMatches.call(void 0, wildcardPatterns));
47
+ if (criteria.length === 1) return criteria[0];
48
+ return _chunkWKYMSRCDcjs.any.call(void 0, criteria);
49
+ }
50
+ function whitelist(options) {
51
+ const userAgents = _nullishCoalesce(options.userAgents, () => ( []));
52
+ const bypassPaths = _nullishCoalesce(options.bypassPaths, () => ( []));
53
+ const criteria = [_chunkWKYMSRCDcjs.not.call(void 0, _chunkMK4QBCD5cjs.ipCidr.call(void 0, options.cidrs)), _chunkWKYMSRCDcjs.not.call(void 0, _chunkWUFGMLE7cjs.userAgentMatches.call(void 0, userAgents))];
54
+ if (bypassPaths.length > 0) {
55
+ criteria.push(_chunkWKYMSRCDcjs.not.call(void 0, buildBypassCriteria(bypassPaths)));
56
+ }
57
+ return _chunkWKYMSRCDcjs.rule.call(void 0, _chunkWKYMSRCDcjs.all.call(void 0, criteria), _chunkWWSRNCUPcjs.redirect.call(void 0, 302, options.redirectUrl));
58
+ }
59
+
60
+
61
+
62
+ exports.whitelist = whitelist;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  matchesAnyWildcard
3
- } from "./chunk-EEZ7NUJG.js";
3
+ } from "./chunk-NJD4L4Q3.js";
4
4
 
5
5
  // src/criteria/user-agent-matches.ts
6
6
  function userAgentMatches(patterns) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  matchesAnyWildcard
3
- } from "./chunk-EEZ7NUJG.js";
3
+ } from "./chunk-NJD4L4Q3.js";
4
4
 
5
5
  // src/criteria/path-matches.ts
6
6
  function pathMatches(patterns) {
@@ -9,6 +9,9 @@ function wildcardToRegex(pattern) {
9
9
  return regexCache[pattern];
10
10
  }
11
11
  function matchesWildcard(str, pattern) {
12
+ if (pattern.indexOf("*") === -1 && pattern.indexOf("?") === -1) {
13
+ return str.toLowerCase() === pattern.toLowerCase();
14
+ }
12
15
  return wildcardToRegex(pattern).test(str);
13
16
  }
14
17
  function matchesAnyWildcard(str, patterns) {
@@ -0,0 +1,62 @@
1
+ import {
2
+ pathMatches
3
+ } from "./chunk-I7YELJ2P.js";
4
+ import {
5
+ pathPrefix
6
+ } from "./chunk-XLSZ5RB7.js";
7
+ import {
8
+ userAgentMatches
9
+ } from "./chunk-HWJFOKZX.js";
10
+ import {
11
+ ipCidr
12
+ } from "./chunk-YHTUV2SA.js";
13
+ import {
14
+ pathEquals
15
+ } from "./chunk-UD456E4I.js";
16
+ import {
17
+ redirect
18
+ } from "./chunk-DSSFFJWL.js";
19
+ import {
20
+ all,
21
+ any,
22
+ not,
23
+ rule
24
+ } from "./chunk-Q4NP4C3B.js";
25
+
26
+ // src/helpers/whitelist.ts
27
+ function buildBypassCriteria(paths) {
28
+ const exactPaths = [];
29
+ const prefixPaths = [];
30
+ const wildcardPatterns = [];
31
+ for (let i = 0; i < paths.length; i++) {
32
+ const p = paths[i];
33
+ const hasWildcard = p.indexOf("*") !== -1 || p.indexOf("?") !== -1;
34
+ const isTrailingSlashStar = p.charAt(p.length - 1) === "*" && p.charAt(p.length - 2) === "/" && p.indexOf("*") === p.length - 1 && p.indexOf("?") === -1;
35
+ if (!hasWildcard) {
36
+ exactPaths.push(p);
37
+ } else if (isTrailingSlashStar) {
38
+ prefixPaths.push(p.slice(0, p.length - 1));
39
+ } else {
40
+ wildcardPatterns.push(p);
41
+ }
42
+ }
43
+ const criteria = [];
44
+ if (exactPaths.length > 0) criteria.push(pathEquals(exactPaths));
45
+ if (prefixPaths.length > 0) criteria.push(pathPrefix(prefixPaths));
46
+ if (wildcardPatterns.length > 0) criteria.push(pathMatches(wildcardPatterns));
47
+ if (criteria.length === 1) return criteria[0];
48
+ return any(criteria);
49
+ }
50
+ function whitelist(options) {
51
+ const userAgents = options.userAgents ?? [];
52
+ const bypassPaths = options.bypassPaths ?? [];
53
+ const criteria = [not(ipCidr(options.cidrs)), not(userAgentMatches(userAgents))];
54
+ if (bypassPaths.length > 0) {
55
+ criteria.push(not(buildBypassCriteria(bypassPaths)));
56
+ }
57
+ return rule(all(criteria), redirect(302, options.redirectUrl));
58
+ }
59
+
60
+ export {
61
+ whitelist
62
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkULICUDDHcjs = require('./chunk-ULICUDDH.cjs');
3
+ var _chunkYNKZGZ7Icjs = require('./chunk-YNKZGZ7I.cjs');
4
4
 
5
5
  // src/behaviors/set-cors-headers.ts
6
6
  var ORIGIN_WILDCARD = "*";
@@ -15,7 +15,7 @@ function setCorsHeaders(options) {
15
15
  allowOrigin = _optionalChain([request, 'access', _ => _.headers, 'access', _2 => _2["origin"], 'optionalAccess', _3 => _3.value]);
16
16
  } else {
17
17
  const originHeader = _optionalChain([request, 'access', _4 => _4.headers, 'access', _5 => _5["origin"], 'optionalAccess', _6 => _6.value]);
18
- if (originHeader && allowedOrigins.some((p) => _chunkULICUDDHcjs.matchesOriginPattern.call(void 0, originHeader, p))) {
18
+ if (originHeader && allowedOrigins.some((p) => _chunkYNKZGZ7Icjs.matchesOriginPattern.call(void 0, originHeader, p))) {
19
19
  allowOrigin = originHeader;
20
20
  }
21
21
  }
@@ -4,10 +4,10 @@ import {
4
4
  import {
5
5
  ORIGIN_ECHO,
6
6
  ORIGIN_WILDCARD
7
- } from "./chunk-H3RK4USR.js";
7
+ } from "./chunk-GKE3YDHR.js";
8
8
  import {
9
9
  matchesOriginPattern
10
- } from "./chunk-EEZ7NUJG.js";
10
+ } from "./chunk-NJD4L4Q3.js";
11
11
 
12
12
  // src/helpers/preflight-request.ts
13
13
  function preflightRequest(options) {
@@ -1,13 +1,13 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkULICUDDHcjs = require('./chunk-ULICUDDH.cjs');
3
+ var _chunkYNKZGZ7Icjs = require('./chunk-YNKZGZ7I.cjs');
4
4
 
5
5
  // src/criteria/user-agent-matches.ts
6
6
  function userAgentMatches(patterns) {
7
7
  return (req) => {
8
8
  const ua = _optionalChain([req, 'access', _ => _.headers, 'access', _2 => _2["user-agent"], 'optionalAccess', _3 => _3.value]);
9
9
  if (!ua) return false;
10
- return _chunkULICUDDHcjs.matchesAnyWildcard.call(void 0, ua, patterns);
10
+ return _chunkYNKZGZ7Icjs.matchesAnyWildcard.call(void 0, ua, patterns);
11
11
  };
12
12
  }
13
13
 
@@ -9,6 +9,9 @@ function wildcardToRegex(pattern) {
9
9
  return regexCache[pattern];
10
10
  }
11
11
  function matchesWildcard(str, pattern) {
12
+ if (pattern.indexOf("*") === -1 && pattern.indexOf("?") === -1) {
13
+ return str.toLowerCase() === pattern.toLowerCase();
14
+ }
12
15
  return wildcardToRegex(pattern).test(str);
13
16
  }
14
17
  function matchesAnyWildcard(str, patterns) {
@@ -1,5 +1,5 @@
1
1
  /** Represents an HTTP request with URI, method, headers, and querystring. */
2
- interface HttpRequest {
2
+ type HttpRequest = {
3
3
  uri: string;
4
4
  method: string;
5
5
  protocol: string;
@@ -11,16 +11,16 @@ interface HttpRequest {
11
11
  }>;
12
12
  clientIp: string;
13
13
  country?: string;
14
- }
14
+ };
15
15
  /** Represents an HTTP response with status code and headers. */
16
- interface HttpResponse {
16
+ type HttpResponse = {
17
17
  statusCode: number;
18
18
  statusDescription?: string;
19
19
  headers: Record<string, {
20
20
  value: string;
21
21
  }>;
22
22
  body?: string;
23
- }
23
+ };
24
24
  /** A function that evaluates criteria against a request and returns a boolean. */
25
25
  type CriteriaFn = (request: HttpRequest) => boolean;
26
26
  /** Result of a behavior function: either continue processing or respond. */
@@ -36,15 +36,15 @@ type BehaviorFn = (request: HttpRequest) => BehaviorResult;
36
36
  /** A function that modifies an HTTP response. */
37
37
  type ResponseBehaviorFn = (request: HttpRequest, response: HttpResponse) => HttpResponse;
38
38
  /** A response rule: an optional criteria guard plus a ResponseBehaviorFn. */
39
- interface ResponseRule {
39
+ type ResponseRule = {
40
40
  criteria?: CriteriaFn;
41
41
  behavior: ResponseBehaviorFn;
42
- }
42
+ };
43
43
  /** A rule combining optional criteria and a behavior function. */
44
- interface Rule {
44
+ type Rule = {
45
45
  criteria?: CriteriaFn;
46
46
  behavior: BehaviorFn;
47
- }
47
+ };
48
48
  /** Handler for CloudFront viewer request events. */
49
49
  type ViewerRequestHandler = (event: unknown) => unknown;
50
50
  /** Handler for CloudFront viewer response events. */
@@ -1,5 +1,5 @@
1
1
  /** Represents an HTTP request with URI, method, headers, and querystring. */
2
- interface HttpRequest {
2
+ type HttpRequest = {
3
3
  uri: string;
4
4
  method: string;
5
5
  protocol: string;
@@ -11,16 +11,16 @@ interface HttpRequest {
11
11
  }>;
12
12
  clientIp: string;
13
13
  country?: string;
14
- }
14
+ };
15
15
  /** Represents an HTTP response with status code and headers. */
16
- interface HttpResponse {
16
+ type HttpResponse = {
17
17
  statusCode: number;
18
18
  statusDescription?: string;
19
19
  headers: Record<string, {
20
20
  value: string;
21
21
  }>;
22
22
  body?: string;
23
- }
23
+ };
24
24
  /** A function that evaluates criteria against a request and returns a boolean. */
25
25
  type CriteriaFn = (request: HttpRequest) => boolean;
26
26
  /** Result of a behavior function: either continue processing or respond. */
@@ -36,15 +36,15 @@ type BehaviorFn = (request: HttpRequest) => BehaviorResult;
36
36
  /** A function that modifies an HTTP response. */
37
37
  type ResponseBehaviorFn = (request: HttpRequest, response: HttpResponse) => HttpResponse;
38
38
  /** A response rule: an optional criteria guard plus a ResponseBehaviorFn. */
39
- interface ResponseRule {
39
+ type ResponseRule = {
40
40
  criteria?: CriteriaFn;
41
41
  behavior: ResponseBehaviorFn;
42
- }
42
+ };
43
43
  /** A rule combining optional criteria and a behavior function. */
44
- interface Rule {
44
+ type Rule = {
45
45
  criteria?: CriteriaFn;
46
46
  behavior: BehaviorFn;
47
- }
47
+ };
48
48
  /** Handler for CloudFront viewer request events. */
49
49
  type ViewerRequestHandler = (event: unknown) => unknown;
50
50
  /** Handler for CloudFront viewer response events. */
@@ -20,11 +20,11 @@ import { CriteriaFn } from '../core/types.cjs';
20
20
  *
21
21
  * // Apply long-lived cache to static assets
22
22
  * rule(fileExtension(['js', 'css', 'woff2', 'woff']),
23
- * setCacheControl({ maxAge: 31536000 }))
23
+ * setCacheControl('public, max-age=31536000, immutable'))
24
24
  *
25
25
  * // Apply image optimization for image requests
26
- * rule(fileExtension(['jpg', 'jpeg', 'png', 'gif', 'webp']),
27
- * imageOptimize())
26
+ * rule(fileExtension(['jpg', 'jpeg', 'png', 'gif']),
27
+ * imageOptimize({ breakpoints: [320, 640, 960, 1280, 1920] }))
28
28
  * ```
29
29
  */
30
30
  declare function fileExtension(extensions: string[]): CriteriaFn;
@@ -20,11 +20,11 @@ import { CriteriaFn } from '../core/types.js';
20
20
  *
21
21
  * // Apply long-lived cache to static assets
22
22
  * rule(fileExtension(['js', 'css', 'woff2', 'woff']),
23
- * setCacheControl({ maxAge: 31536000 }))
23
+ * setCacheControl('public, max-age=31536000, immutable'))
24
24
  *
25
25
  * // Apply image optimization for image requests
26
- * rule(fileExtension(['jpg', 'jpeg', 'png', 'gif', 'webp']),
27
- * imageOptimize())
26
+ * rule(fileExtension(['jpg', 'jpeg', 'png', 'gif']),
27
+ * imageOptimize({ breakpoints: [320, 640, 960, 1280, 1920] }))
28
28
  * ```
29
29
  */
30
30
  declare function fileExtension(extensions: string[]): CriteriaFn;
@@ -1,38 +1,38 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkVEEOQ7TScjs = require('../chunk-VEEOQ7TS.cjs');
3
+ var _chunk7T4G7UF7cjs = require('../chunk-7T4G7UF7.cjs');
4
4
 
5
5
 
6
6
  var _chunkG7JGTBTTcjs = require('../chunk-G7JGTBTT.cjs');
7
7
 
8
8
 
9
- var _chunkZEFLAOTLcjs = require('../chunk-ZEFLAOTL.cjs');
9
+ var _chunkWUFGMLE7cjs = require('../chunk-WUFGMLE7.cjs');
10
10
 
11
11
 
12
- var _chunkLVOM5GJ6cjs = require('../chunk-LVOM5GJ6.cjs');
12
+ var _chunk32SMWYAFcjs = require('../chunk-32SMWYAF.cjs');
13
13
 
14
14
 
15
- var _chunkOTFDML3Kcjs = require('../chunk-OTFDML3K.cjs');
15
+ var _chunkL7NBJ4JAcjs = require('../chunk-L7NBJ4JA.cjs');
16
16
 
17
17
 
18
- var _chunkOSZWDCTScjs = require('../chunk-OSZWDCTS.cjs');
18
+ var _chunkJGJW7D2Ncjs = require('../chunk-JGJW7D2N.cjs');
19
19
 
20
20
 
21
- var _chunkU54FZCOHcjs = require('../chunk-U54FZCOH.cjs');
21
+ var _chunkMK4QBCD5cjs = require('../chunk-MK4QBCD5.cjs');
22
+ require('../chunk-WZKRNMF2.cjs');
22
23
 
23
24
 
24
- var _chunk32SMWYAFcjs = require('../chunk-32SMWYAF.cjs');
25
+ var _chunkOTFDML3Kcjs = require('../chunk-OTFDML3K.cjs');
25
26
 
26
27
 
27
- var _chunkL7NBJ4JAcjs = require('../chunk-L7NBJ4JA.cjs');
28
+ var _chunkVEEOQ7TScjs = require('../chunk-VEEOQ7TS.cjs');
28
29
 
29
30
 
30
- var _chunkJGJW7D2Ncjs = require('../chunk-JGJW7D2N.cjs');
31
+ var _chunkOSZWDCTScjs = require('../chunk-OSZWDCTS.cjs');
31
32
 
32
33
 
33
- var _chunkMK4QBCD5cjs = require('../chunk-MK4QBCD5.cjs');
34
- require('../chunk-WZKRNMF2.cjs');
35
- require('../chunk-ULICUDDH.cjs');
34
+ var _chunkU54FZCOHcjs = require('../chunk-U54FZCOH.cjs');
35
+ require('../chunk-YNKZGZ7I.cjs');
36
36
  require('../chunk-75ZPJI57.cjs');
37
37
 
38
38
 
@@ -46,4 +46,4 @@ require('../chunk-75ZPJI57.cjs');
46
46
 
47
47
 
48
48
 
49
- exports.countryIs = _chunkOSZWDCTScjs.countryIs; exports.fileExtension = _chunkU54FZCOHcjs.fileExtension; exports.headerContains = _chunk32SMWYAFcjs.headerContains; exports.headerEquals = _chunkL7NBJ4JAcjs.headerEquals; exports.hostnameIs = _chunkJGJW7D2Ncjs.hostnameIs; exports.ipCidr = _chunkMK4QBCD5cjs.ipCidr; exports.methodIs = _chunkOTFDML3Kcjs.methodIs; exports.pathEquals = _chunkVEEOQ7TScjs.pathEquals; exports.pathMatches = _chunkZEFLAOTLcjs.pathMatches; exports.pathPrefix = _chunkG7JGTBTTcjs.pathPrefix; exports.userAgentMatches = _chunkLVOM5GJ6cjs.userAgentMatches;
49
+ exports.countryIs = _chunkOSZWDCTScjs.countryIs; exports.fileExtension = _chunkU54FZCOHcjs.fileExtension; exports.headerContains = _chunk32SMWYAFcjs.headerContains; exports.headerEquals = _chunkL7NBJ4JAcjs.headerEquals; exports.hostnameIs = _chunkJGJW7D2Ncjs.hostnameIs; exports.ipCidr = _chunkMK4QBCD5cjs.ipCidr; exports.methodIs = _chunkOTFDML3Kcjs.methodIs; exports.pathEquals = _chunkVEEOQ7TScjs.pathEquals; exports.pathMatches = _chunk7T4G7UF7cjs.pathMatches; exports.pathPrefix = _chunkG7JGTBTTcjs.pathPrefix; exports.userAgentMatches = _chunkWUFGMLE7cjs.userAgentMatches;
@@ -1,24 +1,12 @@
1
1
  import {
2
- pathEquals
3
- } from "../chunk-UD456E4I.js";
2
+ pathMatches
3
+ } from "../chunk-I7YELJ2P.js";
4
4
  import {
5
5
  pathPrefix
6
6
  } from "../chunk-XLSZ5RB7.js";
7
- import {
8
- pathMatches
9
- } from "../chunk-Y7TIDVVC.js";
10
7
  import {
11
8
  userAgentMatches
12
- } from "../chunk-VQGBRWJK.js";
13
- import {
14
- methodIs
15
- } from "../chunk-PY3JMRDG.js";
16
- import {
17
- countryIs
18
- } from "../chunk-5CPBXZ4X.js";
19
- import {
20
- fileExtension
21
- } from "../chunk-LBJUCJF2.js";
9
+ } from "../chunk-HWJFOKZX.js";
22
10
  import {
23
11
  headerContains
24
12
  } from "../chunk-SRQF5UEJ.js";
@@ -32,7 +20,19 @@ import {
32
20
  ipCidr
33
21
  } from "../chunk-YHTUV2SA.js";
34
22
  import "../chunk-NWRGD3AH.js";
35
- import "../chunk-EEZ7NUJG.js";
23
+ import {
24
+ methodIs
25
+ } from "../chunk-PY3JMRDG.js";
26
+ import {
27
+ pathEquals
28
+ } from "../chunk-UD456E4I.js";
29
+ import {
30
+ countryIs
31
+ } from "../chunk-5CPBXZ4X.js";
32
+ import {
33
+ fileExtension
34
+ } from "../chunk-LBJUCJF2.js";
35
+ import "../chunk-NJD4L4Q3.js";
36
36
  import "../chunk-MLKGABMK.js";
37
37
  export {
38
38
  countryIs,
@@ -1,6 +1,34 @@
1
1
  import { CriteriaFn } from '../core/types.cjs';
2
2
  import { KvsHandle } from '../shared/kvs.cjs';
3
3
 
4
+ /**
5
+ * Loads a CIDR allowlist from CloudFront KeyValueStore and returns a `CriteriaFn`
6
+ * that matches client IPs against the loaded ranges.
7
+ *
8
+ * The KVS value at `key` must be a JSON-encoded `string[]` of CIDR ranges
9
+ * (e.g. `["10.0.0.0/8", "203.0.113.0/24"]`). If the key is absent or the value
10
+ * is empty, no IPs will match.
11
+ *
12
+ * Intended for use with `defineViewerRequestAsync` — the KVS read happens once
13
+ * at setup time.
14
+ *
15
+ * @param handle - KVS handle.
16
+ * @param key - The KVS key whose value is a JSON CIDR array.
17
+ * @returns A `CriteriaFn` to pass to `rule()`.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { defineViewerRequestAsync } from '@rayselfs/cf-rule-engine/adapters/viewer-request'
22
+ * import { rule, not } from '@rayselfs/cf-rule-engine'
23
+ * import { kvsIpCidr } from '@rayselfs/cf-rule-engine/criteria/kvs'
24
+ * import { redirect } from '@rayselfs/cf-rule-engine/behaviors'
25
+ *
26
+ * export default defineViewerRequestAsync(async (event) => {
27
+ * const handle = CloudFront.createKeyValueStore(event)
28
+ * return [rule(not(await kvsIpCidr(handle, 'allowed-cidrs')), redirect(302, 'https://www.example.com'))]
29
+ * })
30
+ * ```
31
+ */
4
32
  declare function kvsIpCidr(handle: KvsHandle, key: string): Promise<CriteriaFn>;
5
33
 
6
34
  export { kvsIpCidr };
@@ -1,6 +1,34 @@
1
1
  import { CriteriaFn } from '../core/types.js';
2
2
  import { KvsHandle } from '../shared/kvs.js';
3
3
 
4
+ /**
5
+ * Loads a CIDR allowlist from CloudFront KeyValueStore and returns a `CriteriaFn`
6
+ * that matches client IPs against the loaded ranges.
7
+ *
8
+ * The KVS value at `key` must be a JSON-encoded `string[]` of CIDR ranges
9
+ * (e.g. `["10.0.0.0/8", "203.0.113.0/24"]`). If the key is absent or the value
10
+ * is empty, no IPs will match.
11
+ *
12
+ * Intended for use with `defineViewerRequestAsync` — the KVS read happens once
13
+ * at setup time.
14
+ *
15
+ * @param handle - KVS handle.
16
+ * @param key - The KVS key whose value is a JSON CIDR array.
17
+ * @returns A `CriteriaFn` to pass to `rule()`.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { defineViewerRequestAsync } from '@rayselfs/cf-rule-engine/adapters/viewer-request'
22
+ * import { rule, not } from '@rayselfs/cf-rule-engine'
23
+ * import { kvsIpCidr } from '@rayselfs/cf-rule-engine/criteria/kvs'
24
+ * import { redirect } from '@rayselfs/cf-rule-engine/behaviors'
25
+ *
26
+ * export default defineViewerRequestAsync(async (event) => {
27
+ * const handle = CloudFront.createKeyValueStore(event)
28
+ * return [rule(not(await kvsIpCidr(handle, 'allowed-cidrs')), redirect(302, 'https://www.example.com'))]
29
+ * })
30
+ * ```
31
+ */
4
32
  declare function kvsIpCidr(handle: KvsHandle, key: string): Promise<CriteriaFn>;
5
33
 
6
34
  export { kvsIpCidr };
@@ -1,8 +1,8 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkZEFLAOTLcjs = require('../chunk-ZEFLAOTL.cjs');
4
- require('../chunk-ULICUDDH.cjs');
3
+ var _chunk7T4G7UF7cjs = require('../chunk-7T4G7UF7.cjs');
4
+ require('../chunk-YNKZGZ7I.cjs');
5
5
  require('../chunk-75ZPJI57.cjs');
6
6
 
7
7
 
8
- exports.pathMatches = _chunkZEFLAOTLcjs.pathMatches;
8
+ exports.pathMatches = _chunk7T4G7UF7cjs.pathMatches;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  pathMatches
3
- } from "../chunk-Y7TIDVVC.js";
4
- import "../chunk-EEZ7NUJG.js";
3
+ } from "../chunk-I7YELJ2P.js";
4
+ import "../chunk-NJD4L4Q3.js";
5
5
  import "../chunk-MLKGABMK.js";
6
6
  export {
7
7
  pathMatches
@@ -1,8 +1,8 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkLVOM5GJ6cjs = require('../chunk-LVOM5GJ6.cjs');
4
- require('../chunk-ULICUDDH.cjs');
3
+ var _chunkWUFGMLE7cjs = require('../chunk-WUFGMLE7.cjs');
4
+ require('../chunk-YNKZGZ7I.cjs');
5
5
  require('../chunk-75ZPJI57.cjs');
6
6
 
7
7
 
8
- exports.userAgentMatches = _chunkLVOM5GJ6cjs.userAgentMatches;
8
+ exports.userAgentMatches = _chunkWUFGMLE7cjs.userAgentMatches;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  userAgentMatches
3
- } from "../chunk-VQGBRWJK.js";
4
- import "../chunk-EEZ7NUJG.js";
3
+ } from "../chunk-HWJFOKZX.js";
4
+ import "../chunk-NJD4L4Q3.js";
5
5
  import "../chunk-MLKGABMK.js";
6
6
  export {
7
7
  userAgentMatches
@@ -1,22 +1,24 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkISXKMJCNcjs = require('../chunk-ISXKMJCN.cjs');
3
+ var _chunkHMQIXEFJcjs = require('../chunk-HMQIXEFJ.cjs');
4
4
 
5
5
 
6
- var _chunkEMDI676Gcjs = require('../chunk-EMDI676G.cjs');
6
+ var _chunkCLGM2TGTcjs = require('../chunk-CLGM2TGT.cjs');
7
7
 
8
8
 
9
9
  var _chunkLSCC62CZcjs = require('../chunk-LSCC62CZ.cjs');
10
- require('../chunk-ZEFLAOTL.cjs');
11
- require('../chunk-LVOM5GJ6.cjs');
12
- require('../chunk-OTFDML3K.cjs');
10
+ require('../chunk-7T4G7UF7.cjs');
11
+ require('../chunk-G7JGTBTT.cjs');
12
+ require('../chunk-WUFGMLE7.cjs');
13
13
 
14
14
 
15
15
  var _chunkL7NBJ4JAcjs = require('../chunk-L7NBJ4JA.cjs');
16
16
  require('../chunk-MK4QBCD5.cjs');
17
17
  require('../chunk-WZKRNMF2.cjs');
18
- require('../chunk-IHVOAORH.cjs');
19
- require('../chunk-ULICUDDH.cjs');
18
+ require('../chunk-OTFDML3K.cjs');
19
+ require('../chunk-VEEOQ7TS.cjs');
20
+ require('../chunk-TJ2POKWD.cjs');
21
+ require('../chunk-YNKZGZ7I.cjs');
20
22
 
21
23
 
22
24
  var _chunkB4WEJSEZcjs = require('../chunk-B4WEJSEZ.cjs');
@@ -40,4 +42,4 @@ function stagingIndicator() {
40
42
 
41
43
 
42
44
 
43
- exports.preflightRequest = _chunkEMDI676Gcjs.preflightRequest; exports.sendCountryCode = _chunkLSCC62CZcjs.sendCountryCode; exports.stagingIndicator = stagingIndicator; exports.whitelist = _chunkISXKMJCNcjs.whitelist;
45
+ exports.preflightRequest = _chunkCLGM2TGTcjs.preflightRequest; exports.sendCountryCode = _chunkLSCC62CZcjs.sendCountryCode; exports.stagingIndicator = stagingIndicator; exports.whitelist = _chunkHMQIXEFJcjs.whitelist;
@@ -1,22 +1,24 @@
1
1
  import {
2
2
  whitelist
3
- } from "../chunk-IHDSTTO2.js";
3
+ } from "../chunk-SC6UPQYF.js";
4
4
  import {
5
5
  preflightRequest
6
- } from "../chunk-7EA7GFWX.js";
6
+ } from "../chunk-VRSD6YHP.js";
7
7
  import {
8
8
  sendCountryCode
9
9
  } from "../chunk-C32DL3EP.js";
10
- import "../chunk-Y7TIDVVC.js";
11
- import "../chunk-VQGBRWJK.js";
12
- import "../chunk-PY3JMRDG.js";
10
+ import "../chunk-I7YELJ2P.js";
11
+ import "../chunk-XLSZ5RB7.js";
12
+ import "../chunk-HWJFOKZX.js";
13
13
  import {
14
14
  headerEquals
15
15
  } from "../chunk-BZQJYOU2.js";
16
16
  import "../chunk-YHTUV2SA.js";
17
17
  import "../chunk-NWRGD3AH.js";
18
- import "../chunk-H3RK4USR.js";
19
- import "../chunk-EEZ7NUJG.js";
18
+ import "../chunk-PY3JMRDG.js";
19
+ import "../chunk-UD456E4I.js";
20
+ import "../chunk-GKE3YDHR.js";
21
+ import "../chunk-NJD4L4Q3.js";
20
22
  import {
21
23
  setResponseHeader
22
24
  } from "../chunk-RBBKFG5J.js";