@rayselfs/cf-rule-engine 1.6.0 → 1.6.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 (46) hide show
  1. package/README.md +10 -8
  2. package/dist/adapters/cf-function.cjs +7 -3
  3. package/dist/adapters/cf-function.d.cts +2 -1
  4. package/dist/adapters/cf-function.d.ts +2 -1
  5. package/dist/adapters/cf-function.js +7 -3
  6. package/dist/adapters/viewer-request.cjs +9 -0
  7. package/dist/adapters/viewer-request.d.cts +31 -0
  8. package/dist/adapters/viewer-request.d.ts +31 -0
  9. package/dist/adapters/viewer-request.js +9 -0
  10. package/dist/adapters/viewer-response.cjs +8 -0
  11. package/dist/adapters/viewer-response.d.cts +37 -0
  12. package/dist/adapters/viewer-response.d.ts +37 -0
  13. package/dist/adapters/viewer-response.js +8 -0
  14. package/dist/behaviors/index.cjs +9 -9
  15. package/dist/behaviors/index.js +9 -9
  16. package/dist/cf-function-BkfWpTfl.d.cts +10 -0
  17. package/dist/cf-function-CZwCWch-.d.ts +10 -0
  18. package/dist/chunk-5ZIB3AJ7.cjs +20 -0
  19. package/dist/chunk-6NFAPLQ7.cjs +39 -0
  20. package/dist/chunk-BJZPAQHW.js +25 -0
  21. package/dist/chunk-CQ7YZ3AR.js +39 -0
  22. package/dist/chunk-N6QAQALU.cjs +36 -0
  23. package/dist/chunk-PR5UQJCC.js +20 -0
  24. package/dist/{chunk-UKB5JAX4.js → chunk-RL7ZETZR.js} +8 -8
  25. package/dist/chunk-SGN2N3WI.cjs +25 -0
  26. package/dist/{chunk-WW7YVRAI.cjs → chunk-T5EXFHVA.cjs} +7 -7
  27. package/dist/chunk-TURH5IFN.js +36 -0
  28. package/dist/criteria/index.cjs +13 -13
  29. package/dist/criteria/index.js +15 -15
  30. package/dist/helpers/index.cjs +8 -8
  31. package/dist/helpers/index.d.cts +1 -1
  32. package/dist/helpers/index.d.ts +1 -1
  33. package/dist/helpers/index.js +9 -9
  34. package/dist/helpers/{staging-whitelist.cjs → whitelist.cjs} +4 -4
  35. package/dist/helpers/{staging-whitelist.d.cts → whitelist.d.cts} +11 -11
  36. package/dist/helpers/{staging-whitelist.d.ts → whitelist.d.ts} +11 -11
  37. package/dist/helpers/{staging-whitelist.js → whitelist.js} +5 -5
  38. package/dist/index.cjs +5 -2
  39. package/dist/index.d.cts +3 -1
  40. package/dist/index.d.ts +3 -1
  41. package/dist/index.js +4 -1
  42. package/package.json +1 -1
  43. package/dist/cf-function-C9eF2O9s.d.ts +0 -70
  44. package/dist/cf-function-DIQHy8L7.d.cts +0 -70
  45. package/dist/chunk-NPMGSPNL.js +0 -88
  46. package/dist/chunk-SAXDN5NS.cjs +0 -88
package/README.md CHANGED
@@ -18,7 +18,7 @@ npm install @rayselfs/cf-rule-engine
18
18
  import { rule, not } from '@rayselfs/cf-rule-engine'
19
19
  import { ipCidr, methodIs } from '@rayselfs/cf-rule-engine/criteria/index'
20
20
  import { redirect, constructResponse } from '@rayselfs/cf-rule-engine/behaviors/index'
21
- import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/cf-function'
21
+ import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/viewer-request'
22
22
 
23
23
  export default defineViewerRequest([
24
24
  rule(not(ipCidr(['10.0.0.0/8', '172.16.0.0/12'])), redirect(302, '/blocked')),
@@ -30,7 +30,7 @@ export default defineViewerRequest([
30
30
 
31
31
  ```typescript
32
32
  import { setSecurityHeaders, setCorsHeaders } from '@rayselfs/cf-rule-engine/behaviors/index'
33
- import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
33
+ import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/viewer-response'
34
34
 
35
35
  export default defineViewerResponse([
36
36
  setSecurityHeaders(),
@@ -70,7 +70,9 @@ Use `chain()` when one behavior must see the request mutations (URI rewrite, hea
70
70
 
71
71
  | Adapter | Import | Use for |
72
72
  |---|---|---|
73
- | CF Function | `@rayselfs/cf-rule-engine/adapters/cf-function` | `viewer-request`, `viewer-response` |
73
+ | CF Function (viewer-request) | `@rayselfs/cf-rule-engine/adapters/viewer-request` | `viewer-request` only — tree-shake-friendly |
74
+ | CF Function (viewer-response) | `@rayselfs/cf-rule-engine/adapters/viewer-response` | `viewer-response` only — tree-shake-friendly |
75
+ | CF Function (combined) | `@rayselfs/cf-rule-engine/adapters/cf-function` | both — backward compat |
74
76
  | Lambda@Edge | `@rayselfs/cf-rule-engine/adapters/lambda-edge` | `viewer-request`, `viewer-response` |
75
77
 
76
78
  ## Akamai → CloudFront Mapping
@@ -141,23 +143,23 @@ defineViewerResponse([
141
143
 
142
144
  Primary distribution requests do not carry `aws-cf-cd-staging`, so the rule is a no-op there.
143
145
 
144
- ### stagingWhitelist
146
+ ### whitelist
145
147
 
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.
148
+ 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
149
 
148
150
  No default allowlists are included — callers must supply all CIDRs and User-Agent patterns explicitly.
149
151
 
150
152
  ```typescript
151
- import { stagingWhitelist } from '@rayselfs/cf-rule-engine/helpers/index'
153
+ import { whitelist } from '@rayselfs/cf-rule-engine/helpers/index'
152
154
 
153
- stagingWhitelist({
155
+ whitelist({
154
156
  cidrs: ['203.0.113.0/24', '10.0.0.0/8'],
155
157
  userAgents: ['*InternalBot*', '*Prerender*'],
156
158
  redirectUrl: 'https://www.example.com',
157
159
  })
158
160
 
159
161
  // With bypass paths:
160
- stagingWhitelist({
162
+ whitelist({
161
163
  cidrs: ['203.0.113.0/24'],
162
164
  redirectUrl: 'https://www.example.com',
163
165
  bypassPaths: ['/api/health', '/robots.txt'],
@@ -1,10 +1,14 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-5ZIB3AJ7.cjs');
2
2
 
3
3
 
4
- var _chunkSAXDN5NScjs = require('../chunk-SAXDN5NS.cjs');
4
+ var _chunkSGN2N3WIcjs = require('../chunk-SGN2N3WI.cjs');
5
5
  require('../chunk-WKYMSRCD.cjs');
6
+
7
+
8
+ var _chunkN6QAQALUcjs = require('../chunk-N6QAQALU.cjs');
9
+ require('../chunk-6NFAPLQ7.cjs');
6
10
  require('../chunk-75ZPJI57.cjs');
7
11
 
8
12
 
9
13
 
10
- exports.defineViewerRequest = _chunkSAXDN5NScjs.defineViewerRequest; exports.defineViewerResponse = _chunkSAXDN5NScjs.defineViewerResponse;
14
+ exports.defineViewerRequest = _chunkSGN2N3WIcjs.defineViewerRequest; exports.defineViewerResponse = _chunkN6QAQALUcjs.defineViewerResponse;
@@ -1,2 +1,3 @@
1
+ export { defineViewerRequest } from './viewer-request.cjs';
2
+ export { defineViewerResponse } from './viewer-response.cjs';
1
3
  import '../core/types.cjs';
2
- export { d as defineViewerRequest, a as defineViewerResponse } from '../cf-function-DIQHy8L7.cjs';
@@ -1,2 +1,3 @@
1
+ export { defineViewerRequest } from './viewer-request.js';
2
+ export { defineViewerResponse } from './viewer-response.js';
1
3
  import '../core/types.js';
2
- export { d as defineViewerRequest, a as defineViewerResponse } from '../cf-function-C9eF2O9s.js';
@@ -1,8 +1,12 @@
1
+ import "../chunk-PR5UQJCC.js";
1
2
  import {
2
- defineViewerRequest,
3
- defineViewerResponse
4
- } from "../chunk-NPMGSPNL.js";
3
+ defineViewerRequest
4
+ } from "../chunk-BJZPAQHW.js";
5
5
  import "../chunk-Q4NP4C3B.js";
6
+ import {
7
+ defineViewerResponse
8
+ } from "../chunk-TURH5IFN.js";
9
+ import "../chunk-CQ7YZ3AR.js";
6
10
  import "../chunk-MLKGABMK.js";
7
11
  export {
8
12
  defineViewerRequest,
@@ -0,0 +1,9 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkSGN2N3WIcjs = require('../chunk-SGN2N3WI.cjs');
4
+ require('../chunk-WKYMSRCD.cjs');
5
+ require('../chunk-6NFAPLQ7.cjs');
6
+ require('../chunk-75ZPJI57.cjs');
7
+
8
+
9
+ exports.defineViewerRequest = _chunkSGN2N3WIcjs.defineViewerRequest;
@@ -0,0 +1,31 @@
1
+ import { Rule } from '../core/types.cjs';
2
+
3
+ /**
4
+ * Creates a CloudFront Function viewer-request handler from an ordered list of rules.
5
+ *
6
+ * The returned function is the CloudFront Function entry point. Assign it as
7
+ * `export default` or `var handler` depending on your runtime configuration.
8
+ *
9
+ * Rules are evaluated in order. Processing stops at the first rule whose behavior
10
+ * returns a response (e.g. `redirect`, `constructResponse`). If all rules continue,
11
+ * the (possibly mutated) request is forwarded to the origin.
12
+ *
13
+ * @param rules - Ordered array of `Rule` objects created with `rule()`.
14
+ * @returns A CloudFront Function handler `(event) => request | response`.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { rule, not } from '@rayselfs/cf-rule-engine'
19
+ * import { ipCidr, pathPrefix } from '@rayselfs/cf-rule-engine/criteria'
20
+ * import { redirect, setRequestHeader } from '@rayselfs/cf-rule-engine/behaviors'
21
+ * import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/viewer-request'
22
+ *
23
+ * export default defineViewerRequest([
24
+ * rule(not(ipCidr(['10.0.0.0/8'])), redirect(302, 'https://www.example.com')),
25
+ * rule(pathPrefix(['/api/']), setRequestHeader('x-forwarded-host', 'api.internal')),
26
+ * ])
27
+ * ```
28
+ */
29
+ declare function defineViewerRequest(rules: Rule[]): (event: unknown) => unknown;
30
+
31
+ export { defineViewerRequest };
@@ -0,0 +1,31 @@
1
+ import { Rule } from '../core/types.js';
2
+
3
+ /**
4
+ * Creates a CloudFront Function viewer-request handler from an ordered list of rules.
5
+ *
6
+ * The returned function is the CloudFront Function entry point. Assign it as
7
+ * `export default` or `var handler` depending on your runtime configuration.
8
+ *
9
+ * Rules are evaluated in order. Processing stops at the first rule whose behavior
10
+ * returns a response (e.g. `redirect`, `constructResponse`). If all rules continue,
11
+ * the (possibly mutated) request is forwarded to the origin.
12
+ *
13
+ * @param rules - Ordered array of `Rule` objects created with `rule()`.
14
+ * @returns A CloudFront Function handler `(event) => request | response`.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { rule, not } from '@rayselfs/cf-rule-engine'
19
+ * import { ipCidr, pathPrefix } from '@rayselfs/cf-rule-engine/criteria'
20
+ * import { redirect, setRequestHeader } from '@rayselfs/cf-rule-engine/behaviors'
21
+ * import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/viewer-request'
22
+ *
23
+ * export default defineViewerRequest([
24
+ * rule(not(ipCidr(['10.0.0.0/8'])), redirect(302, 'https://www.example.com')),
25
+ * rule(pathPrefix(['/api/']), setRequestHeader('x-forwarded-host', 'api.internal')),
26
+ * ])
27
+ * ```
28
+ */
29
+ declare function defineViewerRequest(rules: Rule[]): (event: unknown) => unknown;
30
+
31
+ export { defineViewerRequest };
@@ -0,0 +1,9 @@
1
+ import {
2
+ defineViewerRequest
3
+ } from "../chunk-BJZPAQHW.js";
4
+ import "../chunk-Q4NP4C3B.js";
5
+ import "../chunk-CQ7YZ3AR.js";
6
+ import "../chunk-MLKGABMK.js";
7
+ export {
8
+ defineViewerRequest
9
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkN6QAQALUcjs = require('../chunk-N6QAQALU.cjs');
4
+ require('../chunk-6NFAPLQ7.cjs');
5
+ require('../chunk-75ZPJI57.cjs');
6
+
7
+
8
+ exports.defineViewerResponse = _chunkN6QAQALUcjs.defineViewerResponse;
@@ -0,0 +1,37 @@
1
+ import { ResponseBehaviorFn, ResponseRule } from '../core/types.cjs';
2
+
3
+ /**
4
+ * Creates a CloudFront Function viewer-response handler from an ordered list of
5
+ * response behaviors or response rules.
6
+ *
7
+ * Each entry can be either:
8
+ * - A bare `ResponseBehaviorFn` — runs unconditionally on every response.
9
+ * - A `ResponseRule` `{ criteria, behavior }` — runs only when `criteria` returns `true`
10
+ * for the current request.
11
+ *
12
+ * All behaviors are applied in order; none can short-circuit the response.
13
+ * The final merged response object is returned to CloudFront.
14
+ *
15
+ * Note: If no behavior explicitly sets a body, the `body` field is omitted from
16
+ * the returned response to avoid overwriting the origin's actual content.
17
+ *
18
+ * @param responseBehaviors - Ordered array of `ResponseBehaviorFn` functions or
19
+ * `ResponseRule` objects `{ criteria?, behavior }`.
20
+ * @returns A CloudFront Function handler `(event) => response`.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { setSecurityHeaders, setCorsHeaders, setResponseHeader } from '@rayselfs/cf-rule-engine/behaviors'
25
+ * import { pathPrefix } from '@rayselfs/cf-rule-engine/criteria'
26
+ * import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/viewer-response'
27
+ *
28
+ * export default defineViewerResponse([
29
+ * setSecurityHeaders(),
30
+ * setCorsHeaders({ allowedOrigins: ['https://www.example.com'] }),
31
+ * { criteria: pathPrefix(['/api/']), behavior: setResponseHeader('cache-control', 'no-store') },
32
+ * ])
33
+ * ```
34
+ */
35
+ declare function defineViewerResponse(responseBehaviors: Array<ResponseBehaviorFn | ResponseRule>): (event: unknown) => unknown;
36
+
37
+ export { defineViewerResponse };
@@ -0,0 +1,37 @@
1
+ import { ResponseBehaviorFn, ResponseRule } from '../core/types.js';
2
+
3
+ /**
4
+ * Creates a CloudFront Function viewer-response handler from an ordered list of
5
+ * response behaviors or response rules.
6
+ *
7
+ * Each entry can be either:
8
+ * - A bare `ResponseBehaviorFn` — runs unconditionally on every response.
9
+ * - A `ResponseRule` `{ criteria, behavior }` — runs only when `criteria` returns `true`
10
+ * for the current request.
11
+ *
12
+ * All behaviors are applied in order; none can short-circuit the response.
13
+ * The final merged response object is returned to CloudFront.
14
+ *
15
+ * Note: If no behavior explicitly sets a body, the `body` field is omitted from
16
+ * the returned response to avoid overwriting the origin's actual content.
17
+ *
18
+ * @param responseBehaviors - Ordered array of `ResponseBehaviorFn` functions or
19
+ * `ResponseRule` objects `{ criteria?, behavior }`.
20
+ * @returns A CloudFront Function handler `(event) => response`.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { setSecurityHeaders, setCorsHeaders, setResponseHeader } from '@rayselfs/cf-rule-engine/behaviors'
25
+ * import { pathPrefix } from '@rayselfs/cf-rule-engine/criteria'
26
+ * import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/viewer-response'
27
+ *
28
+ * export default defineViewerResponse([
29
+ * setSecurityHeaders(),
30
+ * setCorsHeaders({ allowedOrigins: ['https://www.example.com'] }),
31
+ * { criteria: pathPrefix(['/api/']), behavior: setResponseHeader('cache-control', 'no-store') },
32
+ * ])
33
+ * ```
34
+ */
35
+ declare function defineViewerResponse(responseBehaviors: Array<ResponseBehaviorFn | ResponseRule>): (event: unknown) => unknown;
36
+
37
+ export { defineViewerResponse };
@@ -0,0 +1,8 @@
1
+ import {
2
+ defineViewerResponse
3
+ } from "../chunk-TURH5IFN.js";
4
+ import "../chunk-CQ7YZ3AR.js";
5
+ import "../chunk-MLKGABMK.js";
6
+ export {
7
+ defineViewerResponse
8
+ };
@@ -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 _chunkKXC6ES3Bcjs = require('../chunk-KXC6ES3B.cjs');
43
43
  require('../chunk-75ZPJI57.cjs');
44
44
 
45
45
  // src/behaviors/verify-token.ts
@@ -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-LQRLWDQQ.js";
43
43
  import "../chunk-MLKGABMK.js";
44
44
 
45
45
  // src/behaviors/verify-token.ts
@@ -0,0 +1,10 @@
1
+ import { defineViewerRequest } from './adapters/viewer-request.cjs';
2
+ import { defineViewerResponse } from './adapters/viewer-response.cjs';
3
+
4
+ declare const cfFunction_defineViewerRequest: typeof defineViewerRequest;
5
+ declare const cfFunction_defineViewerResponse: typeof defineViewerResponse;
6
+ declare namespace cfFunction {
7
+ export { cfFunction_defineViewerRequest as defineViewerRequest, cfFunction_defineViewerResponse as defineViewerResponse };
8
+ }
9
+
10
+ export { cfFunction as c };
@@ -0,0 +1,10 @@
1
+ import { defineViewerRequest } from './adapters/viewer-request.js';
2
+ import { defineViewerResponse } from './adapters/viewer-response.js';
3
+
4
+ declare const cfFunction_defineViewerRequest: typeof defineViewerRequest;
5
+ declare const cfFunction_defineViewerResponse: typeof defineViewerResponse;
6
+ declare namespace cfFunction {
7
+ export { cfFunction_defineViewerRequest as defineViewerRequest, cfFunction_defineViewerResponse as defineViewerResponse };
8
+ }
9
+
10
+ export { cfFunction as c };
@@ -0,0 +1,20 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkSGN2N3WIcjs = require('./chunk-SGN2N3WI.cjs');
4
+
5
+
6
+ var _chunkN6QAQALUcjs = require('./chunk-N6QAQALU.cjs');
7
+
8
+
9
+ var _chunk75ZPJI57cjs = require('./chunk-75ZPJI57.cjs');
10
+
11
+ // src/adapters/cf-function.ts
12
+ var cf_function_exports = {};
13
+ _chunk75ZPJI57cjs.__export.call(void 0, cf_function_exports, {
14
+ defineViewerRequest: () => _chunkSGN2N3WIcjs.defineViewerRequest,
15
+ defineViewerResponse: () => _chunkN6QAQALUcjs.defineViewerResponse
16
+ });
17
+
18
+
19
+
20
+ exports.cf_function_exports = cf_function_exports;
@@ -0,0 +1,39 @@
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; }// src/adapters/_normalize.ts
2
+ function normalizeRequest(event) {
3
+ const ev = event;
4
+ const req = ev.request;
5
+ const viewer = ev.viewer;
6
+ const headers = _nullishCoalesce(req.headers, () => ( {}));
7
+ return {
8
+ uri: req.uri,
9
+ method: req.method,
10
+ protocol: "https",
11
+ querystring: _nullishCoalesce(req.querystring, () => ( {})),
12
+ headers,
13
+ clientIp: _nullishCoalesce(_optionalChain([viewer, 'optionalAccess', _ => _.ip]), () => ( "")),
14
+ country: _optionalChain([headers, 'access', _2 => _2["cloudfront-viewer-country"], 'optionalAccess', _3 => _3.value])
15
+ };
16
+ }
17
+ function denormalizeRequest(req, cookies) {
18
+ return {
19
+ method: req.method,
20
+ uri: req.uri,
21
+ querystring: req.querystring,
22
+ headers: req.headers,
23
+ cookies
24
+ };
25
+ }
26
+ function denormalizeResponse(res) {
27
+ return {
28
+ statusCode: res.statusCode,
29
+ statusDescription: res.statusDescription,
30
+ headers: res.headers,
31
+ body: _nullishCoalesce(res.body, () => ( ""))
32
+ };
33
+ }
34
+
35
+
36
+
37
+
38
+
39
+ exports.normalizeRequest = normalizeRequest; exports.denormalizeRequest = denormalizeRequest; exports.denormalizeResponse = denormalizeResponse;
@@ -0,0 +1,25 @@
1
+ import {
2
+ runRules
3
+ } from "./chunk-Q4NP4C3B.js";
4
+ import {
5
+ denormalizeRequest,
6
+ denormalizeResponse,
7
+ normalizeRequest
8
+ } from "./chunk-CQ7YZ3AR.js";
9
+
10
+ // src/adapters/viewer-request.ts
11
+ function defineViewerRequest(rules) {
12
+ return (event) => {
13
+ const ev = event;
14
+ const evReq = ev.request;
15
+ const originalCookies = evReq.cookies ?? {};
16
+ const req = normalizeRequest(event);
17
+ const result = runRules(rules, req);
18
+ if (result.action === "respond") return denormalizeResponse(result.response);
19
+ return denormalizeRequest(result.request, originalCookies);
20
+ };
21
+ }
22
+
23
+ export {
24
+ defineViewerRequest
25
+ };
@@ -0,0 +1,39 @@
1
+ // src/adapters/_normalize.ts
2
+ function normalizeRequest(event) {
3
+ const ev = event;
4
+ const req = ev.request;
5
+ const viewer = ev.viewer;
6
+ const headers = req.headers ?? {};
7
+ return {
8
+ uri: req.uri,
9
+ method: req.method,
10
+ protocol: "https",
11
+ querystring: req.querystring ?? {},
12
+ headers,
13
+ clientIp: viewer?.ip ?? "",
14
+ country: headers["cloudfront-viewer-country"]?.value
15
+ };
16
+ }
17
+ function denormalizeRequest(req, cookies) {
18
+ return {
19
+ method: req.method,
20
+ uri: req.uri,
21
+ querystring: req.querystring,
22
+ headers: req.headers,
23
+ cookies
24
+ };
25
+ }
26
+ function denormalizeResponse(res) {
27
+ return {
28
+ statusCode: res.statusCode,
29
+ statusDescription: res.statusDescription,
30
+ headers: res.headers,
31
+ body: res.body ?? ""
32
+ };
33
+ }
34
+
35
+ export {
36
+ normalizeRequest,
37
+ denormalizeRequest,
38
+ denormalizeResponse
39
+ };
@@ -0,0 +1,36 @@
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
+
3
+
4
+ var _chunk6NFAPLQ7cjs = require('./chunk-6NFAPLQ7.cjs');
5
+
6
+ // src/adapters/viewer-response.ts
7
+ function defineViewerResponse(responseBehaviors) {
8
+ return (event) => {
9
+ const ev = event;
10
+ const evRes = ev.response;
11
+ const req = _chunk6NFAPLQ7cjs.normalizeRequest.call(void 0, event);
12
+ let response = {
13
+ statusCode: _nullishCoalesce(_optionalChain([evRes, 'optionalAccess', _ => _.statusCode]), () => ( 200)),
14
+ statusDescription: _optionalChain([evRes, 'optionalAccess', _2 => _2.statusDescription]),
15
+ headers: _nullishCoalesce(_optionalChain([evRes, 'optionalAccess', _3 => _3.headers]), () => ( {})),
16
+ body: _optionalChain([evRes, 'optionalAccess', _4 => _4.body])
17
+ };
18
+ for (let i = 0; i < responseBehaviors.length; i++) {
19
+ const entry = responseBehaviors[i];
20
+ if (typeof entry === "function") {
21
+ response = entry(req, response);
22
+ } else if (!entry.criteria || entry.criteria(req)) {
23
+ response = entry.behavior(req, response);
24
+ }
25
+ }
26
+ const normalized = _chunk6NFAPLQ7cjs.denormalizeResponse.call(void 0, response);
27
+ if (!response.body) {
28
+ delete normalized.body;
29
+ }
30
+ return Object.assign({}, evRes, normalized);
31
+ };
32
+ }
33
+
34
+
35
+
36
+ exports.defineViewerResponse = defineViewerResponse;
@@ -0,0 +1,20 @@
1
+ import {
2
+ defineViewerRequest
3
+ } from "./chunk-BJZPAQHW.js";
4
+ import {
5
+ defineViewerResponse
6
+ } from "./chunk-TURH5IFN.js";
7
+ import {
8
+ __export
9
+ } from "./chunk-MLKGABMK.js";
10
+
11
+ // src/adapters/cf-function.ts
12
+ var cf_function_exports = {};
13
+ __export(cf_function_exports, {
14
+ defineViewerRequest: () => defineViewerRequest,
15
+ defineViewerResponse: () => defineViewerResponse
16
+ });
17
+
18
+ export {
19
+ cf_function_exports
20
+ };
@@ -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
  };
@@ -0,0 +1,25 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+ var _chunkWKYMSRCDcjs = require('./chunk-WKYMSRCD.cjs');
4
+
5
+
6
+
7
+
8
+ var _chunk6NFAPLQ7cjs = require('./chunk-6NFAPLQ7.cjs');
9
+
10
+ // src/adapters/viewer-request.ts
11
+ function defineViewerRequest(rules) {
12
+ return (event) => {
13
+ const ev = event;
14
+ const evReq = ev.request;
15
+ const originalCookies = _nullishCoalesce(evReq.cookies, () => ( {}));
16
+ const req = _chunk6NFAPLQ7cjs.normalizeRequest.call(void 0, event);
17
+ const result = _chunkWKYMSRCDcjs.runRules.call(void 0, rules, req);
18
+ if (result.action === "respond") return _chunk6NFAPLQ7cjs.denormalizeResponse.call(void 0, result.response);
19
+ return _chunk6NFAPLQ7cjs.denormalizeRequest.call(void 0, result.request, originalCookies);
20
+ };
21
+ }
22
+
23
+
24
+
25
+ exports.defineViewerRequest = defineViewerRequest;