@rayselfs/cf-rule-engine 1.9.1 → 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 (35) hide show
  1. package/dist/behaviors/index.cjs +3 -3
  2. package/dist/behaviors/index.js +2 -2
  3. package/dist/behaviors/set-cors-headers.cjs +3 -3
  4. package/dist/behaviors/set-cors-headers.js +2 -2
  5. package/dist/{chunk-ZEFLAOTL.cjs → chunk-7T4G7UF7.cjs} +2 -2
  6. package/dist/{chunk-EMDI676G.cjs → chunk-CLGM2TGT.cjs} +5 -5
  7. package/dist/{chunk-H3RK4USR.js → chunk-GKE3YDHR.js} +1 -1
  8. package/dist/chunk-HMQIXEFJ.cjs +62 -0
  9. package/dist/{chunk-VQGBRWJK.js → chunk-HWJFOKZX.js} +1 -1
  10. package/dist/{chunk-Y7TIDVVC.js → chunk-I7YELJ2P.js} +1 -1
  11. package/dist/{chunk-EEZ7NUJG.js → chunk-NJD4L4Q3.js} +3 -0
  12. package/dist/chunk-SC6UPQYF.js +62 -0
  13. package/dist/{chunk-IHVOAORH.cjs → chunk-TJ2POKWD.cjs} +2 -2
  14. package/dist/{chunk-7EA7GFWX.js → chunk-VRSD6YHP.js} +2 -2
  15. package/dist/{chunk-LVOM5GJ6.cjs → chunk-WUFGMLE7.cjs} +2 -2
  16. package/dist/{chunk-ULICUDDH.cjs → chunk-YNKZGZ7I.cjs} +3 -0
  17. package/dist/criteria/index.cjs +5 -5
  18. package/dist/criteria/index.js +5 -5
  19. package/dist/criteria/path-matches.cjs +3 -3
  20. package/dist/criteria/path-matches.js +2 -2
  21. package/dist/criteria/user-agent-matches.cjs +3 -3
  22. package/dist/criteria/user-agent-matches.js +2 -2
  23. package/dist/helpers/index.cjs +9 -7
  24. package/dist/helpers/index.js +8 -6
  25. package/dist/helpers/preflight-request.cjs +4 -4
  26. package/dist/helpers/preflight-request.js +3 -3
  27. package/dist/helpers/whitelist.cjs +7 -5
  28. package/dist/helpers/whitelist.d.cts +0 -35
  29. package/dist/helpers/whitelist.d.ts +0 -35
  30. package/dist/helpers/whitelist.js +6 -4
  31. package/dist/shared/wildcard.cjs +2 -2
  32. package/dist/shared/wildcard.js +1 -1
  33. package/package.json +1 -1
  34. package/dist/chunk-IHDSTTO2.js +0 -32
  35. package/dist/chunk-ISXKMJCN.cjs +0 -32
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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 _chunkIHVOAORHcjs = require('../chunk-IHVOAORH.cjs');
4
- require('../chunk-ULICUDDH.cjs');
3
+ var _chunkTJ2POKWDcjs = require('../chunk-TJ2POKWD.cjs');
4
+ require('../chunk-YNKZGZ7I.cjs');
5
5
 
6
6
 
7
7
  var _chunkZXS23HXAcjs = require('../chunk-ZXS23HXA.cjs');
@@ -124,4 +124,4 @@ function verifyToken(options) {
124
124
 
125
125
 
126
126
 
127
- exports.constructResponse = _chunkOSGZTNTScjs.constructResponse; exports.copyHeader = _chunkJU5WX5RUcjs.copyHeader; exports.directoryIndex = _chunkLTLBEBKLcjs.directoryIndex; exports.imageOptimize = _chunkKXC6ES3Bcjs.imageOptimize; exports.redirect = _chunkWWSRNCUPcjs.redirect; exports.removeResponseHeaders = _chunkSGEBNQR2cjs.removeResponseHeaders; exports.rewriteUri = _chunkBSH5JZBLcjs.rewriteUri; exports.setCacheControl = _chunkCV234DQTcjs.setCacheControl; exports.setCorsHeaders = _chunkIHVOAORHcjs.setCorsHeaders; exports.setCsp = _chunkZXS23HXAcjs.setCsp; exports.setRequestHeader = _chunkPPUHEL4Hcjs.setRequestHeader; exports.setResponseHeader = _chunkB4WEJSEZcjs.setResponseHeader; exports.setSecurityHeaders = _chunk3UXNXJ6Ncjs.setSecurityHeaders; exports.stripQueryParams = _chunkMSES76XKcjs.stripQueryParams; exports.verifyToken = verifyToken;
127
+ exports.constructResponse = _chunkOSGZTNTScjs.constructResponse; exports.copyHeader = _chunkJU5WX5RUcjs.copyHeader; exports.directoryIndex = _chunkLTLBEBKLcjs.directoryIndex; exports.imageOptimize = _chunkKXC6ES3Bcjs.imageOptimize; exports.redirect = _chunkWWSRNCUPcjs.redirect; exports.removeResponseHeaders = _chunkSGEBNQR2cjs.removeResponseHeaders; exports.rewriteUri = _chunkBSH5JZBLcjs.rewriteUri; exports.setCacheControl = _chunkCV234DQTcjs.setCacheControl; exports.setCorsHeaders = _chunkTJ2POKWDcjs.setCorsHeaders; exports.setCsp = _chunkZXS23HXAcjs.setCsp; exports.setRequestHeader = _chunkPPUHEL4Hcjs.setRequestHeader; exports.setResponseHeader = _chunkB4WEJSEZcjs.setResponseHeader; exports.setSecurityHeaders = _chunk3UXNXJ6Ncjs.setSecurityHeaders; exports.stripQueryParams = _chunkMSES76XKcjs.stripQueryParams; exports.verifyToken = verifyToken;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  setCorsHeaders
3
- } from "../chunk-H3RK4USR.js";
4
- import "../chunk-EEZ7NUJG.js";
3
+ } from "../chunk-GKE3YDHR.js";
4
+ import "../chunk-NJD4L4Q3.js";
5
5
  import {
6
6
  setCsp
7
7
  } from "../chunk-XUI4Y22M.js";
@@ -2,11 +2,11 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkIHVOAORHcjs = require('../chunk-IHVOAORH.cjs');
6
- require('../chunk-ULICUDDH.cjs');
5
+ var _chunkTJ2POKWDcjs = require('../chunk-TJ2POKWD.cjs');
6
+ require('../chunk-YNKZGZ7I.cjs');
7
7
  require('../chunk-75ZPJI57.cjs');
8
8
 
9
9
 
10
10
 
11
11
 
12
- exports.ORIGIN_ECHO = _chunkIHVOAORHcjs.ORIGIN_ECHO; exports.ORIGIN_WILDCARD = _chunkIHVOAORHcjs.ORIGIN_WILDCARD; exports.setCorsHeaders = _chunkIHVOAORHcjs.setCorsHeaders;
12
+ exports.ORIGIN_ECHO = _chunkTJ2POKWDcjs.ORIGIN_ECHO; exports.ORIGIN_WILDCARD = _chunkTJ2POKWDcjs.ORIGIN_WILDCARD; exports.setCorsHeaders = _chunkTJ2POKWDcjs.setCorsHeaders;
@@ -2,8 +2,8 @@ import {
2
2
  ORIGIN_ECHO,
3
3
  ORIGIN_WILDCARD,
4
4
  setCorsHeaders
5
- } from "../chunk-H3RK4USR.js";
6
- import "../chunk-EEZ7NUJG.js";
5
+ } from "../chunk-GKE3YDHR.js";
6
+ import "../chunk-NJD4L4Q3.js";
7
7
  import "../chunk-MLKGABMK.js";
8
8
  export {
9
9
  ORIGIN_ECHO,
@@ -1,12 +1,12 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkULICUDDHcjs = require('./chunk-ULICUDDH.cjs');
3
+ var _chunkYNKZGZ7Icjs = require('./chunk-YNKZGZ7I.cjs');
4
4
 
5
5
  // src/criteria/path-matches.ts
6
6
  function pathMatches(patterns) {
7
7
  return (req) => {
8
8
  const path = req.uri.split("?")[0];
9
- return _chunkULICUDDHcjs.matchesAnyWildcard.call(void 0, path, patterns);
9
+ return _chunkYNKZGZ7Icjs.matchesAnyWildcard.call(void 0, path, patterns);
10
10
  };
11
11
  }
12
12
 
@@ -4,10 +4,10 @@ var _chunkOTFDML3Kcjs = require('./chunk-OTFDML3K.cjs');
4
4
 
5
5
 
6
6
 
7
- var _chunkIHVOAORHcjs = require('./chunk-IHVOAORH.cjs');
7
+ var _chunkTJ2POKWDcjs = require('./chunk-TJ2POKWD.cjs');
8
8
 
9
9
 
10
- var _chunkULICUDDHcjs = require('./chunk-ULICUDDH.cjs');
10
+ var _chunkYNKZGZ7Icjs = require('./chunk-YNKZGZ7I.cjs');
11
11
 
12
12
  // src/helpers/preflight-request.ts
13
13
  function preflightRequest(options) {
@@ -20,13 +20,13 @@ function preflightRequest(options) {
20
20
  criteria: _chunkOTFDML3Kcjs.methodIs.call(void 0, ["OPTIONS"]),
21
21
  behavior: (request) => {
22
22
  let allowOrigin;
23
- if (allowedOrigins === _chunkIHVOAORHcjs.ORIGIN_WILDCARD) {
23
+ if (allowedOrigins === _chunkTJ2POKWDcjs.ORIGIN_WILDCARD) {
24
24
  allowOrigin = "*";
25
- } else if (allowedOrigins === _chunkIHVOAORHcjs.ORIGIN_ECHO) {
25
+ } else if (allowedOrigins === _chunkTJ2POKWDcjs.ORIGIN_ECHO) {
26
26
  allowOrigin = _optionalChain([request, 'access', _ => _.headers, 'access', _2 => _2["origin"], 'optionalAccess', _3 => _3.value]);
27
27
  } else {
28
28
  const originHeader = _optionalChain([request, 'access', _4 => _4.headers, 'access', _5 => _5["origin"], 'optionalAccess', _6 => _6.value]);
29
- if (originHeader && allowedOrigins.some((p) => _chunkULICUDDHcjs.matchesOriginPattern.call(void 0, originHeader, p))) {
29
+ if (originHeader && allowedOrigins.some((p) => _chunkYNKZGZ7Icjs.matchesOriginPattern.call(void 0, originHeader, p))) {
30
30
  allowOrigin = originHeader;
31
31
  }
32
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,12 +1,12 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkG7JGTBTTcjs = require('../chunk-G7JGTBTT.cjs');
3
+ var _chunk7T4G7UF7cjs = require('../chunk-7T4G7UF7.cjs');
4
4
 
5
5
 
6
- var _chunkZEFLAOTLcjs = require('../chunk-ZEFLAOTL.cjs');
6
+ var _chunkG7JGTBTTcjs = require('../chunk-G7JGTBTT.cjs');
7
7
 
8
8
 
9
- var _chunkLVOM5GJ6cjs = require('../chunk-LVOM5GJ6.cjs');
9
+ var _chunkWUFGMLE7cjs = require('../chunk-WUFGMLE7.cjs');
10
10
 
11
11
 
12
12
  var _chunk32SMWYAFcjs = require('../chunk-32SMWYAF.cjs');
@@ -32,7 +32,7 @@ var _chunkOSZWDCTScjs = require('../chunk-OSZWDCTS.cjs');
32
32
 
33
33
 
34
34
  var _chunkU54FZCOHcjs = require('../chunk-U54FZCOH.cjs');
35
- require('../chunk-ULICUDDH.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,12 +1,12 @@
1
+ import {
2
+ pathMatches
3
+ } from "../chunk-I7YELJ2P.js";
1
4
  import {
2
5
  pathPrefix
3
6
  } from "../chunk-XLSZ5RB7.js";
4
- import {
5
- pathMatches
6
- } from "../chunk-Y7TIDVVC.js";
7
7
  import {
8
8
  userAgentMatches
9
- } from "../chunk-VQGBRWJK.js";
9
+ } from "../chunk-HWJFOKZX.js";
10
10
  import {
11
11
  headerContains
12
12
  } from "../chunk-SRQF5UEJ.js";
@@ -32,7 +32,7 @@ import {
32
32
  import {
33
33
  fileExtension
34
34
  } from "../chunk-LBJUCJF2.js";
35
- import "../chunk-EEZ7NUJG.js";
35
+ import "../chunk-NJD4L4Q3.js";
36
36
  import "../chunk-MLKGABMK.js";
37
37
  export {
38
38
  countryIs,
@@ -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');
10
+ require('../chunk-7T4G7UF7.cjs');
11
+ require('../chunk-G7JGTBTT.cjs');
12
+ require('../chunk-WUFGMLE7.cjs');
12
13
 
13
14
 
14
15
  var _chunkL7NBJ4JAcjs = require('../chunk-L7NBJ4JA.cjs');
15
16
  require('../chunk-MK4QBCD5.cjs');
16
17
  require('../chunk-WZKRNMF2.cjs');
17
18
  require('../chunk-OTFDML3K.cjs');
18
- require('../chunk-IHVOAORH.cjs');
19
- require('../chunk-ULICUDDH.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";
10
+ import "../chunk-I7YELJ2P.js";
11
+ import "../chunk-XLSZ5RB7.js";
12
+ import "../chunk-HWJFOKZX.js";
12
13
  import {
13
14
  headerEquals
14
15
  } from "../chunk-BZQJYOU2.js";
15
16
  import "../chunk-YHTUV2SA.js";
16
17
  import "../chunk-NWRGD3AH.js";
17
18
  import "../chunk-PY3JMRDG.js";
18
- import "../chunk-H3RK4USR.js";
19
- import "../chunk-EEZ7NUJG.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";
@@ -1,10 +1,10 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkEMDI676Gcjs = require('../chunk-EMDI676G.cjs');
3
+ var _chunkCLGM2TGTcjs = require('../chunk-CLGM2TGT.cjs');
4
4
  require('../chunk-OTFDML3K.cjs');
5
- require('../chunk-IHVOAORH.cjs');
6
- require('../chunk-ULICUDDH.cjs');
5
+ require('../chunk-TJ2POKWD.cjs');
6
+ require('../chunk-YNKZGZ7I.cjs');
7
7
  require('../chunk-75ZPJI57.cjs');
8
8
 
9
9
 
10
- exports.preflightRequest = _chunkEMDI676Gcjs.preflightRequest;
10
+ exports.preflightRequest = _chunkCLGM2TGTcjs.preflightRequest;
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  preflightRequest
3
- } from "../chunk-7EA7GFWX.js";
3
+ } from "../chunk-VRSD6YHP.js";
4
4
  import "../chunk-PY3JMRDG.js";
5
- import "../chunk-H3RK4USR.js";
6
- import "../chunk-EEZ7NUJG.js";
5
+ import "../chunk-GKE3YDHR.js";
6
+ import "../chunk-NJD4L4Q3.js";
7
7
  import "../chunk-MLKGABMK.js";
8
8
  export {
9
9
  preflightRequest
@@ -1,14 +1,16 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkISXKMJCNcjs = require('../chunk-ISXKMJCN.cjs');
4
- require('../chunk-ZEFLAOTL.cjs');
5
- require('../chunk-LVOM5GJ6.cjs');
3
+ var _chunkHMQIXEFJcjs = require('../chunk-HMQIXEFJ.cjs');
4
+ require('../chunk-7T4G7UF7.cjs');
5
+ require('../chunk-G7JGTBTT.cjs');
6
+ require('../chunk-WUFGMLE7.cjs');
6
7
  require('../chunk-MK4QBCD5.cjs');
7
8
  require('../chunk-WZKRNMF2.cjs');
8
- require('../chunk-ULICUDDH.cjs');
9
+ require('../chunk-VEEOQ7TS.cjs');
10
+ require('../chunk-YNKZGZ7I.cjs');
9
11
  require('../chunk-WWSRNCUP.cjs');
10
12
  require('../chunk-WKYMSRCD.cjs');
11
13
  require('../chunk-75ZPJI57.cjs');
12
14
 
13
15
 
14
- exports.whitelist = _chunkISXKMJCNcjs.whitelist;
16
+ exports.whitelist = _chunkHMQIXEFJcjs.whitelist;
@@ -33,41 +33,6 @@ type WhitelistOptions = {
33
33
  */
34
34
  bypassPaths?: string[];
35
35
  };
36
- /**
37
- * Creates a `Rule` that restricts access by IP CIDR range and/or User-Agent
38
- * pattern. Any request that does not match an allowed CIDR or User-Agent
39
- * (and is not on a bypassed path) is redirected with HTTP 302 to
40
- * `options.redirectUrl`.
41
- *
42
- * No default allowlists are included — callers must supply all allowed
43
- * CIDRs and User-Agent patterns explicitly.
44
- *
45
- * @param options - Whitelist configuration.
46
- * @returns A `Rule` ready to pass as an element of `defineViewerRequest`.
47
- *
48
- * @example
49
- * ```ts
50
- * import { whitelist } from '@rayselfs/cf-rule-engine/helpers'
51
- * import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/cf-function'
52
- *
53
- * export default defineViewerRequest([
54
- * whitelist({
55
- * cidrs: ['203.0.113.0/24', '10.0.0.0/8'],
56
- * userAgents: ['*InternalBot*'],
57
- * redirectUrl: 'https://www.example.com',
58
- * }),
59
- * ])
60
- *
61
- * // With bypass paths:
62
- * export default defineViewerRequest([
63
- * whitelist({
64
- * cidrs: ['203.0.113.0/24'],
65
- * redirectUrl: 'https://www.example.com',
66
- * bypassPaths: ['/api/health', '/robots.txt'],
67
- * }),
68
- * ])
69
- * ```
70
- */
71
36
  declare function whitelist(options: WhitelistOptions): Rule;
72
37
 
73
38
  export { type WhitelistOptions, whitelist };
@@ -33,41 +33,6 @@ type WhitelistOptions = {
33
33
  */
34
34
  bypassPaths?: string[];
35
35
  };
36
- /**
37
- * Creates a `Rule` that restricts access by IP CIDR range and/or User-Agent
38
- * pattern. Any request that does not match an allowed CIDR or User-Agent
39
- * (and is not on a bypassed path) is redirected with HTTP 302 to
40
- * `options.redirectUrl`.
41
- *
42
- * No default allowlists are included — callers must supply all allowed
43
- * CIDRs and User-Agent patterns explicitly.
44
- *
45
- * @param options - Whitelist configuration.
46
- * @returns A `Rule` ready to pass as an element of `defineViewerRequest`.
47
- *
48
- * @example
49
- * ```ts
50
- * import { whitelist } from '@rayselfs/cf-rule-engine/helpers'
51
- * import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/cf-function'
52
- *
53
- * export default defineViewerRequest([
54
- * whitelist({
55
- * cidrs: ['203.0.113.0/24', '10.0.0.0/8'],
56
- * userAgents: ['*InternalBot*'],
57
- * redirectUrl: 'https://www.example.com',
58
- * }),
59
- * ])
60
- *
61
- * // With bypass paths:
62
- * export default defineViewerRequest([
63
- * whitelist({
64
- * cidrs: ['203.0.113.0/24'],
65
- * redirectUrl: 'https://www.example.com',
66
- * bypassPaths: ['/api/health', '/robots.txt'],
67
- * }),
68
- * ])
69
- * ```
70
- */
71
36
  declare function whitelist(options: WhitelistOptions): Rule;
72
37
 
73
38
  export { type WhitelistOptions, whitelist };
@@ -1,11 +1,13 @@
1
1
  import {
2
2
  whitelist
3
- } from "../chunk-IHDSTTO2.js";
4
- import "../chunk-Y7TIDVVC.js";
5
- import "../chunk-VQGBRWJK.js";
3
+ } from "../chunk-SC6UPQYF.js";
4
+ import "../chunk-I7YELJ2P.js";
5
+ import "../chunk-XLSZ5RB7.js";
6
+ import "../chunk-HWJFOKZX.js";
6
7
  import "../chunk-YHTUV2SA.js";
7
8
  import "../chunk-NWRGD3AH.js";
8
- import "../chunk-EEZ7NUJG.js";
9
+ import "../chunk-UD456E4I.js";
10
+ import "../chunk-NJD4L4Q3.js";
9
11
  import "../chunk-DSSFFJWL.js";
10
12
  import "../chunk-Q4NP4C3B.js";
11
13
  import "../chunk-MLKGABMK.js";
@@ -3,11 +3,11 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkULICUDDHcjs = require('../chunk-ULICUDDH.cjs');
6
+ var _chunkYNKZGZ7Icjs = require('../chunk-YNKZGZ7I.cjs');
7
7
  require('../chunk-75ZPJI57.cjs');
8
8
 
9
9
 
10
10
 
11
11
 
12
12
 
13
- exports.matchesAnyWildcard = _chunkULICUDDHcjs.matchesAnyWildcard; exports.matchesOriginPattern = _chunkULICUDDHcjs.matchesOriginPattern; exports.matchesWildcard = _chunkULICUDDHcjs.matchesWildcard; exports.wildcardToRegex = _chunkULICUDDHcjs.wildcardToRegex;
13
+ exports.matchesAnyWildcard = _chunkYNKZGZ7Icjs.matchesAnyWildcard; exports.matchesOriginPattern = _chunkYNKZGZ7Icjs.matchesOriginPattern; exports.matchesWildcard = _chunkYNKZGZ7Icjs.matchesWildcard; exports.wildcardToRegex = _chunkYNKZGZ7Icjs.wildcardToRegex;
@@ -3,7 +3,7 @@ import {
3
3
  matchesOriginPattern,
4
4
  matchesWildcard,
5
5
  wildcardToRegex
6
- } from "../chunk-EEZ7NUJG.js";
6
+ } from "../chunk-NJD4L4Q3.js";
7
7
  import "../chunk-MLKGABMK.js";
8
8
  export {
9
9
  matchesAnyWildcard,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rayselfs/cf-rule-engine",
3
- "version": "1.9.1",
3
+ "version": "1.9.2",
4
4
  "description": "Composable, tree-shakeable CloudFront Function rules",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,
@@ -1,32 +0,0 @@
1
- import {
2
- pathMatches
3
- } from "./chunk-Y7TIDVVC.js";
4
- import {
5
- userAgentMatches
6
- } from "./chunk-VQGBRWJK.js";
7
- import {
8
- ipCidr
9
- } from "./chunk-YHTUV2SA.js";
10
- import {
11
- redirect
12
- } from "./chunk-DSSFFJWL.js";
13
- import {
14
- all,
15
- not,
16
- rule
17
- } from "./chunk-Q4NP4C3B.js";
18
-
19
- // src/helpers/whitelist.ts
20
- function whitelist(options) {
21
- const userAgents = options.userAgents ?? [];
22
- const bypassPaths = options.bypassPaths ?? [];
23
- const criteria = [not(ipCidr(options.cidrs)), not(userAgentMatches(userAgents))];
24
- if (bypassPaths.length > 0) {
25
- criteria.push(not(pathMatches(bypassPaths)));
26
- }
27
- return rule(all(criteria), redirect(302, options.redirectUrl));
28
- }
29
-
30
- export {
31
- whitelist
32
- };
@@ -1,32 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
-
3
- var _chunkZEFLAOTLcjs = require('./chunk-ZEFLAOTL.cjs');
4
-
5
-
6
- var _chunkLVOM5GJ6cjs = require('./chunk-LVOM5GJ6.cjs');
7
-
8
-
9
- var _chunkMK4QBCD5cjs = require('./chunk-MK4QBCD5.cjs');
10
-
11
-
12
- var _chunkWWSRNCUPcjs = require('./chunk-WWSRNCUP.cjs');
13
-
14
-
15
-
16
-
17
- var _chunkWKYMSRCDcjs = require('./chunk-WKYMSRCD.cjs');
18
-
19
- // src/helpers/whitelist.ts
20
- function whitelist(options) {
21
- const userAgents = _nullishCoalesce(options.userAgents, () => ( []));
22
- const bypassPaths = _nullishCoalesce(options.bypassPaths, () => ( []));
23
- const criteria = [_chunkWKYMSRCDcjs.not.call(void 0, _chunkMK4QBCD5cjs.ipCidr.call(void 0, options.cidrs)), _chunkWKYMSRCDcjs.not.call(void 0, _chunkLVOM5GJ6cjs.userAgentMatches.call(void 0, userAgents))];
24
- if (bypassPaths.length > 0) {
25
- criteria.push(_chunkWKYMSRCDcjs.not.call(void 0, _chunkZEFLAOTLcjs.pathMatches.call(void 0, bypassPaths)));
26
- }
27
- return _chunkWKYMSRCDcjs.rule.call(void 0, _chunkWKYMSRCDcjs.all.call(void 0, criteria), _chunkWWSRNCUPcjs.redirect.call(void 0, 302, options.redirectUrl));
28
- }
29
-
30
-
31
-
32
- exports.whitelist = whitelist;