@rayselfs/cf-rule-engine 1.5.1 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +5 -5
  2. package/dist/adapters/cf-function.d.cts +1 -1
  3. package/dist/adapters/cf-function.d.ts +1 -1
  4. package/dist/adapters/viewer-request.cjs +8 -0
  5. package/dist/adapters/viewer-request.d.cts +2 -0
  6. package/dist/adapters/viewer-request.d.ts +2 -0
  7. package/dist/adapters/viewer-request.js +8 -0
  8. package/dist/adapters/viewer-response.cjs +8 -0
  9. package/dist/adapters/viewer-response.d.cts +2 -0
  10. package/dist/adapters/viewer-response.d.ts +2 -0
  11. package/dist/adapters/viewer-response.js +8 -0
  12. package/dist/behaviors/image-optimize.cjs +2 -2
  13. package/dist/behaviors/image-optimize.d.cts +19 -7
  14. package/dist/behaviors/image-optimize.d.ts +19 -7
  15. package/dist/behaviors/image-optimize.js +1 -1
  16. package/dist/behaviors/index.cjs +10 -10
  17. package/dist/behaviors/index.d.cts +1 -1
  18. package/dist/behaviors/index.d.ts +1 -1
  19. package/dist/behaviors/index.js +9 -9
  20. package/dist/{chunk-TQLJIT4H.cjs → chunk-KXC6ES3B.cjs} +6 -5
  21. package/dist/{chunk-5PT5X62W.js → chunk-LQRLWDQQ.js} +6 -5
  22. package/dist/{chunk-UKB5JAX4.js → chunk-RL7ZETZR.js} +8 -8
  23. package/dist/{chunk-WW7YVRAI.cjs → chunk-T5EXFHVA.cjs} +7 -7
  24. package/dist/criteria/index.cjs +12 -12
  25. package/dist/criteria/index.js +12 -12
  26. package/dist/helpers/index.cjs +8 -8
  27. package/dist/helpers/index.d.cts +1 -1
  28. package/dist/helpers/index.d.ts +1 -1
  29. package/dist/helpers/index.js +9 -9
  30. package/dist/helpers/{staging-whitelist.cjs → whitelist.cjs} +4 -4
  31. package/dist/helpers/{staging-whitelist.d.cts → whitelist.d.cts} +11 -11
  32. package/dist/helpers/{staging-whitelist.d.ts → whitelist.d.ts} +11 -11
  33. package/dist/helpers/{staging-whitelist.js → whitelist.js} +5 -5
  34. package/dist/index.cjs +2 -2
  35. package/dist/index.d.cts +1 -1
  36. package/dist/index.d.ts +1 -1
  37. package/dist/index.js +3 -3
  38. package/package.json +1 -1
  39. /package/dist/{cf-function-C9eF2O9s.d.ts → viewer-response-C9eF2O9s.d.ts} +0 -0
  40. /package/dist/{cf-function-DIQHy8L7.d.cts → viewer-response-DIQHy8L7.d.cts} +0 -0
package/README.md CHANGED
@@ -141,23 +141,23 @@ defineViewerResponse([
141
141
 
142
142
  Primary distribution requests do not carry `aws-cf-cd-staging`, so the rule is a no-op there.
143
143
 
144
- ### stagingWhitelist
144
+ ### whitelist
145
145
 
146
- Restricts access to a staging environment by IP CIDR range and/or User-Agent pattern. Requests that don't match any allowed CIDR or User-Agent (and aren't on a bypassed path) are redirected with HTTP 302.
146
+ Restricts access by IP CIDR range and/or User-Agent pattern. Requests that don't match any allowed CIDR or User-Agent (and aren't on a bypassed path) are redirected with HTTP 302.
147
147
 
148
148
  No default allowlists are included — callers must supply all CIDRs and User-Agent patterns explicitly.
149
149
 
150
150
  ```typescript
151
- import { stagingWhitelist } from '@rayselfs/cf-rule-engine/helpers/index'
151
+ import { whitelist } from '@rayselfs/cf-rule-engine/helpers/index'
152
152
 
153
- stagingWhitelist({
153
+ whitelist({
154
154
  cidrs: ['203.0.113.0/24', '10.0.0.0/8'],
155
155
  userAgents: ['*InternalBot*', '*Prerender*'],
156
156
  redirectUrl: 'https://www.example.com',
157
157
  })
158
158
 
159
159
  // With bypass paths:
160
- stagingWhitelist({
160
+ whitelist({
161
161
  cidrs: ['203.0.113.0/24'],
162
162
  redirectUrl: 'https://www.example.com',
163
163
  bypassPaths: ['/api/health', '/robots.txt'],
@@ -1,2 +1,2 @@
1
1
  import '../core/types.cjs';
2
- export { d as defineViewerRequest, a as defineViewerResponse } from '../cf-function-DIQHy8L7.cjs';
2
+ export { d as defineViewerRequest, a as defineViewerResponse } from '../viewer-response-DIQHy8L7.cjs';
@@ -1,2 +1,2 @@
1
1
  import '../core/types.js';
2
- export { d as defineViewerRequest, a as defineViewerResponse } from '../cf-function-C9eF2O9s.js';
2
+ export { d as defineViewerRequest, a as defineViewerResponse } from '../viewer-response-C9eF2O9s.js';
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkSAXDN5NScjs = require('../chunk-SAXDN5NS.cjs');
4
+ require('../chunk-WKYMSRCD.cjs');
5
+ require('../chunk-75ZPJI57.cjs');
6
+
7
+
8
+ exports.defineViewerRequest = _chunkSAXDN5NScjs.defineViewerRequest;
@@ -0,0 +1,2 @@
1
+ export { d as defineViewerRequest } from '../viewer-response-DIQHy8L7.cjs';
2
+ import '../core/types.cjs';
@@ -0,0 +1,2 @@
1
+ export { d as defineViewerRequest } from '../viewer-response-C9eF2O9s.js';
2
+ import '../core/types.js';
@@ -0,0 +1,8 @@
1
+ import {
2
+ defineViewerRequest
3
+ } from "../chunk-NPMGSPNL.js";
4
+ import "../chunk-Q4NP4C3B.js";
5
+ import "../chunk-MLKGABMK.js";
6
+ export {
7
+ defineViewerRequest
8
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkSAXDN5NScjs = require('../chunk-SAXDN5NS.cjs');
4
+ require('../chunk-WKYMSRCD.cjs');
5
+ require('../chunk-75ZPJI57.cjs');
6
+
7
+
8
+ exports.defineViewerResponse = _chunkSAXDN5NScjs.defineViewerResponse;
@@ -0,0 +1,2 @@
1
+ export { a as defineViewerResponse } from '../viewer-response-DIQHy8L7.cjs';
2
+ import '../core/types.cjs';
@@ -0,0 +1,2 @@
1
+ export { a as defineViewerResponse } from '../viewer-response-C9eF2O9s.js';
2
+ import '../core/types.js';
@@ -0,0 +1,8 @@
1
+ import {
2
+ defineViewerResponse
3
+ } from "../chunk-NPMGSPNL.js";
4
+ import "../chunk-Q4NP4C3B.js";
5
+ import "../chunk-MLKGABMK.js";
6
+ export {
7
+ defineViewerResponse
8
+ };
@@ -1,9 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunkTQLJIT4Hcjs = require('../chunk-TQLJIT4H.cjs');
4
+ var _chunkKXC6ES3Bcjs = require('../chunk-KXC6ES3B.cjs');
5
5
  require('../chunk-75ZPJI57.cjs');
6
6
 
7
7
 
8
8
 
9
- exports.imageOptimize = _chunkTQLJIT4Hcjs.imageOptimize; exports.resolveImageParams = _chunkTQLJIT4Hcjs.resolveImageParams;
9
+ exports.imageOptimize = _chunkKXC6ES3Bcjs.imageOptimize; exports.resolveImageParams = _chunkKXC6ES3Bcjs.resolveImageParams;
@@ -1,4 +1,4 @@
1
- import { BehaviorFn, HttpRequest } from '../core/types.cjs';
1
+ import { HttpRequest, BehaviorFn } from '../core/types.cjs';
2
2
 
3
3
  /**
4
4
  * Origin configuration for image-optimize-proxy.
@@ -15,6 +15,15 @@ type ImageOriginConfig = {
15
15
  type: 's3';
16
16
  sourceBucket: string;
17
17
  };
18
+ /**
19
+ * Origin resolver — either a static config or a function that resolves
20
+ * the origin per-request. When a function is provided, it receives the
21
+ * normalized request and may return `undefined` to skip origin header injection.
22
+ *
23
+ * Use the function form for conditional routing (e.g., some paths → S3,
24
+ * others → gateway) within a single imageOptimize() call.
25
+ */
26
+ type ImageOriginResolver = ImageOriginConfig | ((request: HttpRequest) => ImageOriginConfig | undefined);
18
27
  /**
19
28
  * Options for imageOptimize querystring normalization behavior.
20
29
  *
@@ -36,11 +45,14 @@ interface ImageOptimizeOptions {
36
45
  imformatParam?: string;
37
46
  /**
38
47
  * Origin configuration for image-optimize-proxy.
39
- * When provided, injects the corresponding X-Img-* request headers so the
40
- * proxy knows how to resolve the source image. This removes the need to
41
- * configure CloudFront origin custom headers separately in Terraform.
42
- */
43
- origin?: ImageOriginConfig;
48
+ * When provided, injects the corresponding X-Img-* request headers so the
49
+ * proxy knows how to resolve the source image. This removes the need to
50
+ * configure CloudFront origin custom headers separately in Terraform.
51
+ *
52
+ * Accepts either a static config object or a resolver function that receives
53
+ * the request and returns the appropriate origin (or undefined to skip).
54
+ */
55
+ origin?: ImageOriginResolver;
44
56
  /**
45
57
  * CloudFront origin verification secret.
46
58
  * When provided, injects the value as the X-Origin-Verify request header.
@@ -100,4 +112,4 @@ declare function resolveImageParams(request: Pick<HttpRequest, 'querystring' | '
100
112
  */
101
113
  declare function imageOptimize(options: ImageOptimizeOptions): BehaviorFn;
102
114
 
103
- export { type ImageOptimizeOptions, type ImageOriginConfig, type ResolvedImageParams, imageOptimize, resolveImageParams };
115
+ export { type ImageOptimizeOptions, type ImageOriginConfig, type ImageOriginResolver, type ResolvedImageParams, imageOptimize, resolveImageParams };
@@ -1,4 +1,4 @@
1
- import { BehaviorFn, HttpRequest } from '../core/types.js';
1
+ import { HttpRequest, BehaviorFn } from '../core/types.js';
2
2
 
3
3
  /**
4
4
  * Origin configuration for image-optimize-proxy.
@@ -15,6 +15,15 @@ type ImageOriginConfig = {
15
15
  type: 's3';
16
16
  sourceBucket: string;
17
17
  };
18
+ /**
19
+ * Origin resolver — either a static config or a function that resolves
20
+ * the origin per-request. When a function is provided, it receives the
21
+ * normalized request and may return `undefined` to skip origin header injection.
22
+ *
23
+ * Use the function form for conditional routing (e.g., some paths → S3,
24
+ * others → gateway) within a single imageOptimize() call.
25
+ */
26
+ type ImageOriginResolver = ImageOriginConfig | ((request: HttpRequest) => ImageOriginConfig | undefined);
18
27
  /**
19
28
  * Options for imageOptimize querystring normalization behavior.
20
29
  *
@@ -36,11 +45,14 @@ interface ImageOptimizeOptions {
36
45
  imformatParam?: string;
37
46
  /**
38
47
  * Origin configuration for image-optimize-proxy.
39
- * When provided, injects the corresponding X-Img-* request headers so the
40
- * proxy knows how to resolve the source image. This removes the need to
41
- * configure CloudFront origin custom headers separately in Terraform.
42
- */
43
- origin?: ImageOriginConfig;
48
+ * When provided, injects the corresponding X-Img-* request headers so the
49
+ * proxy knows how to resolve the source image. This removes the need to
50
+ * configure CloudFront origin custom headers separately in Terraform.
51
+ *
52
+ * Accepts either a static config object or a resolver function that receives
53
+ * the request and returns the appropriate origin (or undefined to skip).
54
+ */
55
+ origin?: ImageOriginResolver;
44
56
  /**
45
57
  * CloudFront origin verification secret.
46
58
  * When provided, injects the value as the X-Origin-Verify request header.
@@ -100,4 +112,4 @@ declare function resolveImageParams(request: Pick<HttpRequest, 'querystring' | '
100
112
  */
101
113
  declare function imageOptimize(options: ImageOptimizeOptions): BehaviorFn;
102
114
 
103
- export { type ImageOptimizeOptions, type ImageOriginConfig, type ResolvedImageParams, imageOptimize, resolveImageParams };
115
+ export { type ImageOptimizeOptions, type ImageOriginConfig, type ImageOriginResolver, type ResolvedImageParams, imageOptimize, resolveImageParams };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  imageOptimize,
3
3
  resolveImageParams
4
- } from "../chunk-5PT5X62W.js";
4
+ } from "../chunk-LQRLWDQQ.js";
5
5
  import "../chunk-MLKGABMK.js";
6
6
  export {
7
7
  imageOptimize,
@@ -1,11 +1,20 @@
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 _chunkPPUHEL4Hcjs = require('../chunk-PPUHEL4H.cjs');
4
+
5
+
6
+ var _chunkB4WEJSEZcjs = require('../chunk-B4WEJSEZ.cjs');
7
+
8
+
3
9
  var _chunkUI6LKDJIcjs = require('../chunk-UI6LKDJI.cjs');
4
10
 
5
11
 
6
12
  var _chunkMSES76XKcjs = require('../chunk-MSES76XK.cjs');
7
13
 
8
14
 
15
+ var _chunkKXC6ES3Bcjs = require('../chunk-KXC6ES3B.cjs');
16
+
17
+
9
18
  var _chunkWWSRNCUPcjs = require('../chunk-WWSRNCUP.cjs');
10
19
 
11
20
 
@@ -24,12 +33,6 @@ var _chunkGK5JX7OMcjs = require('../chunk-GK5JX7OM.cjs');
24
33
  var _chunkZXS23HXAcjs = require('../chunk-ZXS23HXA.cjs');
25
34
 
26
35
 
27
- var _chunkPPUHEL4Hcjs = require('../chunk-PPUHEL4H.cjs');
28
-
29
-
30
- var _chunkB4WEJSEZcjs = require('../chunk-B4WEJSEZ.cjs');
31
-
32
-
33
36
  var _chunkOSGZTNTScjs = require('../chunk-OSGZTNTS.cjs');
34
37
 
35
38
 
@@ -37,9 +40,6 @@ var _chunkJU5WX5RUcjs = require('../chunk-JU5WX5RU.cjs');
37
40
 
38
41
 
39
42
  var _chunkLTLBEBKLcjs = require('../chunk-LTLBEBKL.cjs');
40
-
41
-
42
- var _chunkTQLJIT4Hcjs = require('../chunk-TQLJIT4H.cjs');
43
43
  require('../chunk-75ZPJI57.cjs');
44
44
 
45
45
  // src/behaviors/verify-token.ts
@@ -123,4 +123,4 @@ function verifyToken(options) {
123
123
 
124
124
 
125
125
 
126
- exports.constructResponse = _chunkOSGZTNTScjs.constructResponse; exports.copyHeader = _chunkJU5WX5RUcjs.copyHeader; exports.directoryIndex = _chunkLTLBEBKLcjs.directoryIndex; exports.imageOptimize = _chunkTQLJIT4Hcjs.imageOptimize; exports.redirect = _chunkWWSRNCUPcjs.redirect; exports.removeResponseHeaders = _chunkSGEBNQR2cjs.removeResponseHeaders; exports.rewriteUri = _chunkMRPTC74Icjs.rewriteUri; exports.setCacheControl = _chunkCV234DQTcjs.setCacheControl; exports.setCorsHeaders = _chunkGK5JX7OMcjs.setCorsHeaders; exports.setCsp = _chunkZXS23HXAcjs.setCsp; exports.setRequestHeader = _chunkPPUHEL4Hcjs.setRequestHeader; exports.setResponseHeader = _chunkB4WEJSEZcjs.setResponseHeader; exports.setSecurityHeaders = _chunkUI6LKDJIcjs.setSecurityHeaders; exports.stripQueryParams = _chunkMSES76XKcjs.stripQueryParams; exports.verifyToken = verifyToken;
126
+ 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 = _chunkMRPTC74Icjs.rewriteUri; exports.setCacheControl = _chunkCV234DQTcjs.setCacheControl; exports.setCorsHeaders = _chunkGK5JX7OMcjs.setCorsHeaders; exports.setCsp = _chunkZXS23HXAcjs.setCsp; exports.setRequestHeader = _chunkPPUHEL4Hcjs.setRequestHeader; exports.setResponseHeader = _chunkB4WEJSEZcjs.setResponseHeader; exports.setSecurityHeaders = _chunkUI6LKDJIcjs.setSecurityHeaders; exports.stripQueryParams = _chunkMSES76XKcjs.stripQueryParams; exports.verifyToken = verifyToken;
@@ -11,7 +11,7 @@ export { stripQueryParams } from './strip-query-params.cjs';
11
11
  export { CspOptions, setCsp } from './set-csp.cjs';
12
12
  export { setCacheControl } from './set-cache-control.cjs';
13
13
  export { SecurityHeadersOptions, setSecurityHeaders } from './set-security-headers.cjs';
14
- export { ImageOptimizeOptions, imageOptimize } from './image-optimize.cjs';
14
+ export { ImageOptimizeOptions, ImageOriginConfig, ImageOriginResolver, imageOptimize } from './image-optimize.cjs';
15
15
  import { BehaviorFn } from '../core/types.cjs';
16
16
  export { ResponseBehaviorFn, ResponseRule } from '../core/types.cjs';
17
17
 
@@ -11,7 +11,7 @@ export { stripQueryParams } from './strip-query-params.js';
11
11
  export { CspOptions, setCsp } from './set-csp.js';
12
12
  export { setCacheControl } from './set-cache-control.js';
13
13
  export { SecurityHeadersOptions, setSecurityHeaders } from './set-security-headers.js';
14
- export { ImageOptimizeOptions, imageOptimize } from './image-optimize.js';
14
+ export { ImageOptimizeOptions, ImageOriginConfig, ImageOriginResolver, imageOptimize } from './image-optimize.js';
15
15
  import { BehaviorFn } from '../core/types.js';
16
16
  export { ResponseBehaviorFn, ResponseRule } from '../core/types.js';
17
17
 
@@ -1,9 +1,18 @@
1
+ import {
2
+ setRequestHeader
3
+ } from "../chunk-M5KUQBDW.js";
4
+ import {
5
+ setResponseHeader
6
+ } from "../chunk-RBBKFG5J.js";
1
7
  import {
2
8
  setSecurityHeaders
3
9
  } from "../chunk-VQCRSBWL.js";
4
10
  import {
5
11
  stripQueryParams
6
12
  } from "../chunk-XPQG5IML.js";
13
+ import {
14
+ imageOptimize
15
+ } from "../chunk-LQRLWDQQ.js";
7
16
  import {
8
17
  redirect
9
18
  } from "../chunk-DSSFFJWL.js";
@@ -22,12 +31,6 @@ import {
22
31
  import {
23
32
  setCsp
24
33
  } from "../chunk-XUI4Y22M.js";
25
- import {
26
- setRequestHeader
27
- } from "../chunk-M5KUQBDW.js";
28
- import {
29
- setResponseHeader
30
- } from "../chunk-RBBKFG5J.js";
31
34
  import {
32
35
  constructResponse
33
36
  } from "../chunk-6DBZBV2M.js";
@@ -37,9 +40,6 @@ import {
37
40
  import {
38
41
  directoryIndex
39
42
  } from "../chunk-R7WXS7BI.js";
40
- import {
41
- imageOptimize
42
- } from "../chunk-5PT5X62W.js";
43
43
  import "../chunk-MLKGABMK.js";
44
44
 
45
45
  // src/behaviors/verify-token.ts
@@ -77,12 +77,13 @@ function imageOptimize(options) {
77
77
  delete qs["imformat"];
78
78
  }
79
79
  var headers = Object.assign({}, request.headers);
80
- if (options.origin !== void 0) {
81
- headers["x-img-source-type"] = { value: options.origin.type };
82
- if (options.origin.type === "gateway") {
83
- headers["x-img-upstream-gateway"] = { value: options.origin.upstreamGateway };
80
+ var resolvedOrigin = typeof options.origin === "function" ? options.origin(request) : options.origin;
81
+ if (resolvedOrigin !== void 0) {
82
+ headers["x-img-source-type"] = { value: resolvedOrigin.type };
83
+ if (resolvedOrigin.type === "gateway") {
84
+ headers["x-img-upstream-gateway"] = { value: resolvedOrigin.upstreamGateway };
84
85
  } else {
85
- headers["x-img-source-bucket"] = { value: options.origin.sourceBucket };
86
+ headers["x-img-source-bucket"] = { value: resolvedOrigin.sourceBucket };
86
87
  }
87
88
  }
88
89
  if (options.originSecret !== void 0) {
@@ -77,12 +77,13 @@ function imageOptimize(options) {
77
77
  delete qs["imformat"];
78
78
  }
79
79
  var headers = Object.assign({}, request.headers);
80
- if (options.origin !== void 0) {
81
- headers["x-img-source-type"] = { value: options.origin.type };
82
- if (options.origin.type === "gateway") {
83
- headers["x-img-upstream-gateway"] = { value: options.origin.upstreamGateway };
80
+ var resolvedOrigin = typeof options.origin === "function" ? options.origin(request) : options.origin;
81
+ if (resolvedOrigin !== void 0) {
82
+ headers["x-img-source-type"] = { value: resolvedOrigin.type };
83
+ if (resolvedOrigin.type === "gateway") {
84
+ headers["x-img-upstream-gateway"] = { value: resolvedOrigin.upstreamGateway };
84
85
  } else {
85
- headers["x-img-source-bucket"] = { value: options.origin.sourceBucket };
86
+ headers["x-img-source-bucket"] = { value: resolvedOrigin.sourceBucket };
86
87
  }
87
88
  }
88
89
  if (options.originSecret !== void 0) {
@@ -1,3 +1,6 @@
1
+ import {
2
+ userAgentMatches
3
+ } from "./chunk-S2AAATFN.js";
1
4
  import {
2
5
  ipCidr
3
6
  } from "./chunk-KW5YBTSD.js";
@@ -5,19 +8,16 @@ import {
5
8
  pathMatches
6
9
  } from "./chunk-LO2BO3RU.js";
7
10
  import {
8
- userAgentMatches
9
- } from "./chunk-S2AAATFN.js";
11
+ redirect
12
+ } from "./chunk-DSSFFJWL.js";
10
13
  import {
11
14
  all,
12
15
  not,
13
16
  rule
14
17
  } from "./chunk-Q4NP4C3B.js";
15
- import {
16
- redirect
17
- } from "./chunk-DSSFFJWL.js";
18
18
 
19
- // src/helpers/staging-whitelist.ts
20
- function stagingWhitelist(options) {
19
+ // src/helpers/whitelist.ts
20
+ function whitelist(options) {
21
21
  const userAgents = options.userAgents ?? [];
22
22
  const bypassPaths = options.bypassPaths ?? [];
23
23
  const criteria = [not(ipCidr(options.cidrs)), not(userAgentMatches(userAgents))];
@@ -28,5 +28,5 @@ function stagingWhitelist(options) {
28
28
  }
29
29
 
30
30
  export {
31
- stagingWhitelist
31
+ whitelist
32
32
  };
@@ -1,23 +1,23 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
2
 
3
+ var _chunkMVGYPBYBcjs = require('./chunk-MVGYPBYB.cjs');
4
+
5
+
3
6
  var _chunkD47P7HVZcjs = require('./chunk-D47P7HVZ.cjs');
4
7
 
5
8
 
6
9
  var _chunkCF5PWWTFcjs = require('./chunk-CF5PWWTF.cjs');
7
10
 
8
11
 
9
- var _chunkMVGYPBYBcjs = require('./chunk-MVGYPBYB.cjs');
12
+ var _chunkWWSRNCUPcjs = require('./chunk-WWSRNCUP.cjs');
10
13
 
11
14
 
12
15
 
13
16
 
14
17
  var _chunkWKYMSRCDcjs = require('./chunk-WKYMSRCD.cjs');
15
18
 
16
-
17
- var _chunkWWSRNCUPcjs = require('./chunk-WWSRNCUP.cjs');
18
-
19
- // src/helpers/staging-whitelist.ts
20
- function stagingWhitelist(options) {
19
+ // src/helpers/whitelist.ts
20
+ function whitelist(options) {
21
21
  const userAgents = _nullishCoalesce(options.userAgents, () => ( []));
22
22
  const bypassPaths = _nullishCoalesce(options.bypassPaths, () => ( []));
23
23
  const criteria = [_chunkWKYMSRCDcjs.not.call(void 0, _chunkD47P7HVZcjs.ipCidr.call(void 0, options.cidrs)), _chunkWKYMSRCDcjs.not.call(void 0, _chunkMVGYPBYBcjs.userAgentMatches.call(void 0, userAgents))];
@@ -29,4 +29,4 @@ function stagingWhitelist(options) {
29
29
 
30
30
 
31
31
 
32
- exports.stagingWhitelist = stagingWhitelist;
32
+ exports.whitelist = whitelist;
@@ -1,5 +1,17 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
+ var _chunkG7JGTBTTcjs = require('../chunk-G7JGTBTT.cjs');
4
+
5
+
6
+ var _chunkMVGYPBYBcjs = require('../chunk-MVGYPBYB.cjs');
7
+
8
+
9
+ var _chunk32SMWYAFcjs = require('../chunk-32SMWYAF.cjs');
10
+
11
+
12
+ var _chunkL7NBJ4JAcjs = require('../chunk-L7NBJ4JA.cjs');
13
+
14
+
3
15
  var _chunkJGJW7D2Ncjs = require('../chunk-JGJW7D2N.cjs');
4
16
 
5
17
 
@@ -14,12 +26,6 @@ var _chunkVEEOQ7TScjs = require('../chunk-VEEOQ7TS.cjs');
14
26
 
15
27
 
16
28
  var _chunkCF5PWWTFcjs = require('../chunk-CF5PWWTF.cjs');
17
-
18
-
19
- var _chunkG7JGTBTTcjs = require('../chunk-G7JGTBTT.cjs');
20
-
21
-
22
- var _chunkMVGYPBYBcjs = require('../chunk-MVGYPBYB.cjs');
23
29
  require('../chunk-IBXAK2A4.cjs');
24
30
 
25
31
 
@@ -27,12 +33,6 @@ var _chunkOSZWDCTScjs = require('../chunk-OSZWDCTS.cjs');
27
33
 
28
34
 
29
35
  var _chunkU54FZCOHcjs = require('../chunk-U54FZCOH.cjs');
30
-
31
-
32
- var _chunk32SMWYAFcjs = require('../chunk-32SMWYAF.cjs');
33
-
34
-
35
- var _chunkL7NBJ4JAcjs = require('../chunk-L7NBJ4JA.cjs');
36
36
  require('../chunk-75ZPJI57.cjs');
37
37
 
38
38
 
@@ -1,3 +1,15 @@
1
+ import {
2
+ pathPrefix
3
+ } from "../chunk-XLSZ5RB7.js";
4
+ import {
5
+ userAgentMatches
6
+ } from "../chunk-S2AAATFN.js";
7
+ import {
8
+ headerContains
9
+ } from "../chunk-SRQF5UEJ.js";
10
+ import {
11
+ headerEquals
12
+ } from "../chunk-BZQJYOU2.js";
1
13
  import {
2
14
  hostnameIs
3
15
  } from "../chunk-3PVDUC5M.js";
@@ -14,12 +26,6 @@ import {
14
26
  import {
15
27
  pathMatches
16
28
  } from "../chunk-LO2BO3RU.js";
17
- import {
18
- pathPrefix
19
- } from "../chunk-XLSZ5RB7.js";
20
- import {
21
- userAgentMatches
22
- } from "../chunk-S2AAATFN.js";
23
29
  import "../chunk-2DE6WPPL.js";
24
30
  import {
25
31
  countryIs
@@ -27,12 +33,6 @@ import {
27
33
  import {
28
34
  fileExtension
29
35
  } from "../chunk-LBJUCJF2.js";
30
- import {
31
- headerContains
32
- } from "../chunk-SRQF5UEJ.js";
33
- import {
34
- headerEquals
35
- } from "../chunk-BZQJYOU2.js";
36
36
  import "../chunk-MLKGABMK.js";
37
37
  export {
38
38
  countryIs,
@@ -6,21 +6,21 @@ var _chunk63WIEBQBcjs = require('../chunk-63WIEBQB.cjs');
6
6
  var _chunkLSCC62CZcjs = require('../chunk-LSCC62CZ.cjs');
7
7
 
8
8
 
9
- var _chunkWW7YVRAIcjs = require('../chunk-WW7YVRAI.cjs');
9
+ var _chunkT5EXFHVAcjs = require('../chunk-T5EXFHVA.cjs');
10
+ require('../chunk-MVGYPBYB.cjs');
11
+
12
+
13
+ var _chunkL7NBJ4JAcjs = require('../chunk-L7NBJ4JA.cjs');
10
14
  require('../chunk-D47P7HVZ.cjs');
11
15
  require('../chunk-YVUR35RN.cjs');
12
16
  require('../chunk-OTFDML3K.cjs');
13
17
  require('../chunk-CF5PWWTF.cjs');
14
- require('../chunk-MVGYPBYB.cjs');
15
18
  require('../chunk-IBXAK2A4.cjs');
16
19
 
17
20
 
18
- var _chunkL7NBJ4JAcjs = require('../chunk-L7NBJ4JA.cjs');
19
- require('../chunk-WKYMSRCD.cjs');
20
- require('../chunk-WWSRNCUP.cjs');
21
-
22
-
23
21
  var _chunkB4WEJSEZcjs = require('../chunk-B4WEJSEZ.cjs');
22
+ require('../chunk-WWSRNCUP.cjs');
23
+ require('../chunk-WKYMSRCD.cjs');
24
24
  require('../chunk-JU5WX5RU.cjs');
25
25
  require('../chunk-75ZPJI57.cjs');
26
26
 
@@ -39,4 +39,4 @@ function stagingIndicator() {
39
39
 
40
40
 
41
41
 
42
- exports.preflightRequest = _chunk63WIEBQBcjs.preflightRequest; exports.sendCountryCode = _chunkLSCC62CZcjs.sendCountryCode; exports.stagingIndicator = stagingIndicator; exports.stagingWhitelist = _chunkWW7YVRAIcjs.stagingWhitelist;
42
+ exports.preflightRequest = _chunk63WIEBQBcjs.preflightRequest; exports.sendCountryCode = _chunkLSCC62CZcjs.sendCountryCode; exports.stagingIndicator = stagingIndicator; exports.whitelist = _chunkT5EXFHVAcjs.whitelist;
@@ -1,5 +1,5 @@
1
1
  export { sendCountryCode } from './send-country-code.cjs';
2
- export { StagingWhitelistOptions, stagingWhitelist } from './staging-whitelist.cjs';
2
+ export { WhitelistOptions, whitelist } from './whitelist.cjs';
3
3
  import { ResponseRule } from '../core/types.cjs';
4
4
  export { preflightRequest } from './preflight-request.cjs';
5
5
  import '../behaviors/set-cors-headers.cjs';
@@ -1,5 +1,5 @@
1
1
  export { sendCountryCode } from './send-country-code.js';
2
- export { StagingWhitelistOptions, stagingWhitelist } from './staging-whitelist.js';
2
+ export { WhitelistOptions, whitelist } from './whitelist.js';
3
3
  import { ResponseRule } from '../core/types.js';
4
4
  export { preflightRequest } from './preflight-request.js';
5
5
  import '../behaviors/set-cors-headers.js';
@@ -5,22 +5,22 @@ import {
5
5
  sendCountryCode
6
6
  } from "../chunk-C32DL3EP.js";
7
7
  import {
8
- stagingWhitelist
9
- } from "../chunk-UKB5JAX4.js";
8
+ whitelist
9
+ } from "../chunk-RL7ZETZR.js";
10
+ import "../chunk-S2AAATFN.js";
11
+ import {
12
+ headerEquals
13
+ } from "../chunk-BZQJYOU2.js";
10
14
  import "../chunk-KW5YBTSD.js";
11
15
  import "../chunk-LNQPYKGG.js";
12
16
  import "../chunk-PY3JMRDG.js";
13
17
  import "../chunk-LO2BO3RU.js";
14
- import "../chunk-S2AAATFN.js";
15
18
  import "../chunk-2DE6WPPL.js";
16
- import {
17
- headerEquals
18
- } from "../chunk-BZQJYOU2.js";
19
- import "../chunk-Q4NP4C3B.js";
20
- import "../chunk-DSSFFJWL.js";
21
19
  import {
22
20
  setResponseHeader
23
21
  } from "../chunk-RBBKFG5J.js";
22
+ import "../chunk-DSSFFJWL.js";
23
+ import "../chunk-Q4NP4C3B.js";
24
24
  import "../chunk-BDNPQ7AU.js";
25
25
  import "../chunk-MLKGABMK.js";
26
26
 
@@ -38,5 +38,5 @@ export {
38
38
  preflightRequest,
39
39
  sendCountryCode,
40
40
  stagingIndicator,
41
- stagingWhitelist
41
+ whitelist
42
42
  };
@@ -1,14 +1,14 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkWW7YVRAIcjs = require('../chunk-WW7YVRAI.cjs');
3
+ var _chunkT5EXFHVAcjs = require('../chunk-T5EXFHVA.cjs');
4
+ require('../chunk-MVGYPBYB.cjs');
4
5
  require('../chunk-D47P7HVZ.cjs');
5
6
  require('../chunk-YVUR35RN.cjs');
6
7
  require('../chunk-CF5PWWTF.cjs');
7
- require('../chunk-MVGYPBYB.cjs');
8
8
  require('../chunk-IBXAK2A4.cjs');
9
- require('../chunk-WKYMSRCD.cjs');
10
9
  require('../chunk-WWSRNCUP.cjs');
10
+ require('../chunk-WKYMSRCD.cjs');
11
11
  require('../chunk-75ZPJI57.cjs');
12
12
 
13
13
 
14
- exports.stagingWhitelist = _chunkWW7YVRAIcjs.stagingWhitelist;
14
+ exports.whitelist = _chunkT5EXFHVAcjs.whitelist;
@@ -1,9 +1,9 @@
1
1
  import { Rule } from '../core/types.cjs';
2
2
 
3
3
  /**
4
- * Configuration options for the staging environment access whitelist.
4
+ * Configuration options for the IP/User-Agent access whitelist.
5
5
  */
6
- interface StagingWhitelistOptions {
6
+ interface WhitelistOptions {
7
7
  /**
8
8
  * CIDR ranges to allow (e.g. office IPs, VPN, stage VPCs).
9
9
  * At least one of `cidrs` or `userAgents` must be non-empty, otherwise
@@ -34,10 +34,10 @@ interface StagingWhitelistOptions {
34
34
  bypassPaths?: string[];
35
35
  }
36
36
  /**
37
- * Creates a `Rule` that restricts access to a staging environment by
38
- * IP CIDR range and/or User-Agent pattern. Any request that does not
39
- * match an allowed CIDR or User-Agent (and is not on a bypassed path)
40
- * is redirected with HTTP 302 to `options.redirectUrl`.
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
41
  *
42
42
  * No default allowlists are included — callers must supply all allowed
43
43
  * CIDRs and User-Agent patterns explicitly.
@@ -47,11 +47,11 @@ interface StagingWhitelistOptions {
47
47
  *
48
48
  * @example
49
49
  * ```ts
50
- * import { stagingWhitelist } from '@rayselfs/cf-rule-engine/helpers'
50
+ * import { whitelist } from '@rayselfs/cf-rule-engine/helpers'
51
51
  * import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/cf-function'
52
52
  *
53
53
  * export default defineViewerRequest([
54
- * stagingWhitelist({
54
+ * whitelist({
55
55
  * cidrs: ['203.0.113.0/24', '10.0.0.0/8'],
56
56
  * userAgents: ['*InternalBot*'],
57
57
  * redirectUrl: 'https://www.example.com',
@@ -60,7 +60,7 @@ interface StagingWhitelistOptions {
60
60
  *
61
61
  * // With bypass paths:
62
62
  * export default defineViewerRequest([
63
- * stagingWhitelist({
63
+ * whitelist({
64
64
  * cidrs: ['203.0.113.0/24'],
65
65
  * redirectUrl: 'https://www.example.com',
66
66
  * bypassPaths: ['/api/health', '/robots.txt'],
@@ -68,6 +68,6 @@ interface StagingWhitelistOptions {
68
68
  * ])
69
69
  * ```
70
70
  */
71
- declare function stagingWhitelist(options: StagingWhitelistOptions): Rule;
71
+ declare function whitelist(options: WhitelistOptions): Rule;
72
72
 
73
- export { type StagingWhitelistOptions, stagingWhitelist };
73
+ export { type WhitelistOptions, whitelist };
@@ -1,9 +1,9 @@
1
1
  import { Rule } from '../core/types.js';
2
2
 
3
3
  /**
4
- * Configuration options for the staging environment access whitelist.
4
+ * Configuration options for the IP/User-Agent access whitelist.
5
5
  */
6
- interface StagingWhitelistOptions {
6
+ interface WhitelistOptions {
7
7
  /**
8
8
  * CIDR ranges to allow (e.g. office IPs, VPN, stage VPCs).
9
9
  * At least one of `cidrs` or `userAgents` must be non-empty, otherwise
@@ -34,10 +34,10 @@ interface StagingWhitelistOptions {
34
34
  bypassPaths?: string[];
35
35
  }
36
36
  /**
37
- * Creates a `Rule` that restricts access to a staging environment by
38
- * IP CIDR range and/or User-Agent pattern. Any request that does not
39
- * match an allowed CIDR or User-Agent (and is not on a bypassed path)
40
- * is redirected with HTTP 302 to `options.redirectUrl`.
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
41
  *
42
42
  * No default allowlists are included — callers must supply all allowed
43
43
  * CIDRs and User-Agent patterns explicitly.
@@ -47,11 +47,11 @@ interface StagingWhitelistOptions {
47
47
  *
48
48
  * @example
49
49
  * ```ts
50
- * import { stagingWhitelist } from '@rayselfs/cf-rule-engine/helpers'
50
+ * import { whitelist } from '@rayselfs/cf-rule-engine/helpers'
51
51
  * import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/cf-function'
52
52
  *
53
53
  * export default defineViewerRequest([
54
- * stagingWhitelist({
54
+ * whitelist({
55
55
  * cidrs: ['203.0.113.0/24', '10.0.0.0/8'],
56
56
  * userAgents: ['*InternalBot*'],
57
57
  * redirectUrl: 'https://www.example.com',
@@ -60,7 +60,7 @@ interface StagingWhitelistOptions {
60
60
  *
61
61
  * // With bypass paths:
62
62
  * export default defineViewerRequest([
63
- * stagingWhitelist({
63
+ * whitelist({
64
64
  * cidrs: ['203.0.113.0/24'],
65
65
  * redirectUrl: 'https://www.example.com',
66
66
  * bypassPaths: ['/api/health', '/robots.txt'],
@@ -68,6 +68,6 @@ interface StagingWhitelistOptions {
68
68
  * ])
69
69
  * ```
70
70
  */
71
- declare function stagingWhitelist(options: StagingWhitelistOptions): Rule;
71
+ declare function whitelist(options: WhitelistOptions): Rule;
72
72
 
73
- export { type StagingWhitelistOptions, stagingWhitelist };
73
+ export { type WhitelistOptions, whitelist };
@@ -1,14 +1,14 @@
1
1
  import {
2
- stagingWhitelist
3
- } from "../chunk-UKB5JAX4.js";
2
+ whitelist
3
+ } from "../chunk-RL7ZETZR.js";
4
+ import "../chunk-S2AAATFN.js";
4
5
  import "../chunk-KW5YBTSD.js";
5
6
  import "../chunk-LNQPYKGG.js";
6
7
  import "../chunk-LO2BO3RU.js";
7
- import "../chunk-S2AAATFN.js";
8
8
  import "../chunk-2DE6WPPL.js";
9
- import "../chunk-Q4NP4C3B.js";
10
9
  import "../chunk-DSSFFJWL.js";
10
+ import "../chunk-Q4NP4C3B.js";
11
11
  import "../chunk-MLKGABMK.js";
12
12
  export {
13
- stagingWhitelist
13
+ whitelist
14
14
  };
package/dist/index.cjs CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('./chunk-MEHWLQLR.cjs');
2
2
 
3
3
 
4
- var _chunkSAXDN5NScjs = require('./chunk-SAXDN5NS.cjs');
4
+ var _chunk3BBLG4IXcjs = require('./chunk-3BBLG4IX.cjs');
5
5
 
6
6
 
7
- var _chunk3BBLG4IXcjs = require('./chunk-3BBLG4IX.cjs');
7
+ var _chunkSAXDN5NScjs = require('./chunk-SAXDN5NS.cjs');
8
8
 
9
9
 
10
10
 
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { BehaviorFn, BehaviorResult, CriteriaFn, HttpRequest, HttpResponse, ResponseBehaviorFn, ResponseRule, Rule, ViewerRequestHandler, ViewerResponseHandler } from './core/types.cjs';
2
2
  export { all, any, chain, not, rule, runRules } from './core/rule.cjs';
3
- export { c as cfFunction } from './cf-function-DIQHy8L7.cjs';
3
+ export { c as cfFunction } from './viewer-response-DIQHy8L7.cjs';
4
4
  export { l as lambdaEdge } from './lambda-edge-9xiONGmR.cjs';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { BehaviorFn, BehaviorResult, CriteriaFn, HttpRequest, HttpResponse, ResponseBehaviorFn, ResponseRule, Rule, ViewerRequestHandler, ViewerResponseHandler } from './core/types.js';
2
2
  export { all, any, chain, not, rule, runRules } from './core/rule.js';
3
- export { c as cfFunction } from './cf-function-C9eF2O9s.js';
3
+ export { c as cfFunction } from './viewer-response-C9eF2O9s.js';
4
4
  export { l as lambdaEdge } from './lambda-edge-BK3-bFx8.js';
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import "./chunk-KZ72PI2A.js";
2
- import {
3
- cf_function_exports
4
- } from "./chunk-NPMGSPNL.js";
5
2
  import {
6
3
  lambda_edge_exports
7
4
  } from "./chunk-WEBU4R5C.js";
5
+ import {
6
+ cf_function_exports
7
+ } from "./chunk-NPMGSPNL.js";
8
8
  import {
9
9
  all,
10
10
  any,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rayselfs/cf-rule-engine",
3
- "version": "1.5.1",
3
+ "version": "1.6.1",
4
4
  "description": "Composable, tree-shakeable CloudFront Function rules",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,