@rayselfs/cf-rule-engine 1.9.1 → 1.10.0

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 (43) hide show
  1. package/dist/behaviors/index.cjs +4 -4
  2. package/dist/behaviors/index.d.cts +1 -1
  3. package/dist/behaviors/index.d.ts +1 -1
  4. package/dist/behaviors/index.js +3 -3
  5. package/dist/behaviors/set-cors-headers.cjs +3 -3
  6. package/dist/behaviors/set-cors-headers.js +2 -2
  7. package/dist/behaviors/set-csp.cjs +2 -2
  8. package/dist/behaviors/set-csp.d.cts +113 -11
  9. package/dist/behaviors/set-csp.d.ts +113 -11
  10. package/dist/behaviors/set-csp.js +1 -1
  11. package/dist/{chunk-ZEFLAOTL.cjs → chunk-7T4G7UF7.cjs} +2 -2
  12. package/dist/{chunk-EMDI676G.cjs → chunk-CLGM2TGT.cjs} +5 -5
  13. package/dist/{chunk-H3RK4USR.js → chunk-GKE3YDHR.js} +1 -1
  14. package/dist/chunk-HMQIXEFJ.cjs +62 -0
  15. package/dist/{chunk-VQGBRWJK.js → chunk-HWJFOKZX.js} +1 -1
  16. package/dist/{chunk-Y7TIDVVC.js → chunk-I7YELJ2P.js} +1 -1
  17. package/dist/{chunk-EEZ7NUJG.js → chunk-NJD4L4Q3.js} +3 -0
  18. package/dist/{chunk-ZXS23HXA.cjs → chunk-PE445VUF.cjs} +7 -1
  19. package/dist/{chunk-XUI4Y22M.js → chunk-QU32MXNE.js} +7 -1
  20. package/dist/chunk-SC6UPQYF.js +62 -0
  21. package/dist/{chunk-IHVOAORH.cjs → chunk-TJ2POKWD.cjs} +2 -2
  22. package/dist/{chunk-7EA7GFWX.js → chunk-VRSD6YHP.js} +2 -2
  23. package/dist/{chunk-LVOM5GJ6.cjs → chunk-WUFGMLE7.cjs} +2 -2
  24. package/dist/{chunk-ULICUDDH.cjs → chunk-YNKZGZ7I.cjs} +3 -0
  25. package/dist/criteria/index.cjs +5 -5
  26. package/dist/criteria/index.js +5 -5
  27. package/dist/criteria/path-matches.cjs +3 -3
  28. package/dist/criteria/path-matches.js +2 -2
  29. package/dist/criteria/user-agent-matches.cjs +3 -3
  30. package/dist/criteria/user-agent-matches.js +2 -2
  31. package/dist/helpers/index.cjs +9 -7
  32. package/dist/helpers/index.js +8 -6
  33. package/dist/helpers/preflight-request.cjs +4 -4
  34. package/dist/helpers/preflight-request.js +3 -3
  35. package/dist/helpers/whitelist.cjs +7 -5
  36. package/dist/helpers/whitelist.d.cts +0 -35
  37. package/dist/helpers/whitelist.d.ts +0 -35
  38. package/dist/helpers/whitelist.js +6 -4
  39. package/dist/shared/wildcard.cjs +2 -2
  40. package/dist/shared/wildcard.js +1 -1
  41. package/package.json +1 -1
  42. package/dist/chunk-IHDSTTO2.js +0 -32
  43. package/dist/chunk-ISXKMJCN.cjs +0 -32
@@ -1,10 +1,10 @@
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
- var _chunkZXS23HXAcjs = require('../chunk-ZXS23HXA.cjs');
7
+ var _chunkPE445VUFcjs = require('../chunk-PE445VUF.cjs');
8
8
 
9
9
 
10
10
  var _chunkPPUHEL4Hcjs = require('../chunk-PPUHEL4H.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 = _chunkPE445VUFcjs.setCsp; exports.setRequestHeader = _chunkPPUHEL4Hcjs.setRequestHeader; exports.setResponseHeader = _chunkB4WEJSEZcjs.setResponseHeader; exports.setSecurityHeaders = _chunk3UXNXJ6Ncjs.setSecurityHeaders; exports.stripQueryParams = _chunkMSES76XKcjs.stripQueryParams; exports.verifyToken = verifyToken;
@@ -8,7 +8,7 @@ export { setResponseHeader } from './set-response-header.cjs';
8
8
  export { removeResponseHeaders } from './remove-response-headers.cjs';
9
9
  export { CorsOptions, setCorsHeaders } from './set-cors-headers.cjs';
10
10
  export { stripQueryParams } from './strip-query-params.cjs';
11
- export { CspOptions, setCsp } from './set-csp.cjs';
11
+ export { CspDirectives, 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
14
  export { ImageOptimizeOptions, ImageOriginConfig, ImageOriginResolver, imageOptimize } from './image-optimize.cjs';
@@ -8,7 +8,7 @@ export { setResponseHeader } from './set-response-header.js';
8
8
  export { removeResponseHeaders } from './remove-response-headers.js';
9
9
  export { CorsOptions, setCorsHeaders } from './set-cors-headers.js';
10
10
  export { stripQueryParams } from './strip-query-params.js';
11
- export { CspOptions, setCsp } from './set-csp.js';
11
+ export { CspDirectives, 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
14
  export { ImageOptimizeOptions, ImageOriginConfig, ImageOriginResolver, imageOptimize } from './image-optimize.js';
@@ -1,10 +1,10 @@
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
- } from "../chunk-XUI4Y22M.js";
7
+ } from "../chunk-QU32MXNE.js";
8
8
  import {
9
9
  setRequestHeader
10
10
  } from "../chunk-M5KUQBDW.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,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkZXS23HXAcjs = require('../chunk-ZXS23HXA.cjs');
3
+ var _chunkPE445VUFcjs = require('../chunk-PE445VUF.cjs');
4
4
  require('../chunk-75ZPJI57.cjs');
5
5
 
6
6
 
7
- exports.setCsp = _chunkZXS23HXAcjs.setCsp;
7
+ exports.setCsp = _chunkPE445VUFcjs.setCsp;
@@ -1,27 +1,127 @@
1
1
  import { ResponseBehaviorFn } from '../core/types.cjs';
2
2
 
3
+ /**
4
+ * All valid CSP directives with their expected value types.
5
+ *
6
+ * - `string` — directive requires a value, e.g. `'default-src': "'self'"`
7
+ * - `boolean` — value-less flag directive; `true` emits the bare directive name,
8
+ * `false` (or omitted) skips it entirely
9
+ * - `string | boolean` — directive is valid with or without a value (sandbox only)
10
+ *
11
+ * All fields are optional. Omitted fields are not emitted in the header.
12
+ *
13
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
14
+ */
15
+ type CspDirectives = Partial<{
16
+ /** Fallback for all fetch directives not explicitly set. */
17
+ 'default-src': string;
18
+ /** Valid sources for Web Workers and nested browsing contexts. */
19
+ 'child-src': string;
20
+ /** Valid sources for XMLHttpRequest, WebSocket, EventSource, fetch(). */
21
+ 'connect-src': string;
22
+ /** Valid sources for fonts loaded with @font-face. */
23
+ 'font-src': string;
24
+ /** Valid sources for nested browsing contexts such as <frame> and <iframe>. */
25
+ 'frame-src': string;
26
+ /** Valid sources for images and favicons. */
27
+ 'img-src': string;
28
+ /** Valid sources for manifest files. */
29
+ 'manifest-src': string;
30
+ /** Valid sources for <audio>, <video>, and <track>. */
31
+ 'media-src': string;
32
+ /** Valid sources for <object> and <embed>. */
33
+ 'object-src': string;
34
+ /** Valid sources for JavaScript <script> elements. */
35
+ 'script-src': string;
36
+ /** Valid sources for inline <script> event handlers. */
37
+ 'script-src-attr': string;
38
+ /** Valid sources for JavaScript <script> elements (external files). */
39
+ 'script-src-elem': string;
40
+ /** Valid sources for stylesheets. */
41
+ 'style-src': string;
42
+ /** Valid sources for inline style attributes. */
43
+ 'style-src-attr': string;
44
+ /** Valid sources for <link> stylesheet elements. */
45
+ 'style-src-elem': string;
46
+ /** Valid sources for Worker, SharedWorker, and ServiceWorker scripts. */
47
+ 'worker-src': string;
48
+ /** Restricts URLs that can be used as the target of a <base> element. */
49
+ 'base-uri': string;
50
+ /**
51
+ * Applies sandbox restrictions to the page. Presence alone (`true`) enables
52
+ * the most restrictive sandbox. Pass a string of `allow-*` tokens to relax
53
+ * specific restrictions, e.g. `'allow-scripts allow-same-origin'`.
54
+ */
55
+ sandbox: string | boolean;
56
+ /** Restricts URLs that can be used as a form action target. */
57
+ 'form-action': string;
58
+ /** Restricts which parents may embed this page in a frame. */
59
+ 'frame-ancestors': string;
60
+ /** Restricts URLs the document may navigate to. */
61
+ 'navigate-to': string;
62
+ /**
63
+ * Restricts creation of Trusted Types policies.
64
+ * Use `'none'` to disallow all policies, or list allowed policy names.
65
+ */
66
+ 'trusted-types': string;
67
+ /**
68
+ * Enforces Trusted Types for a sink group.
69
+ * Common value: `'script'`.
70
+ */
71
+ 'require-trusted-types-for': string;
72
+ /** Reporting group name (defined via `Report-To` header). Preferred over `report-uri`. */
73
+ 'report-to': string;
74
+ /**
75
+ * @deprecated Use `report-to` instead. `report-uri` is deprecated but remains
76
+ * widely supported. Include both during transition:
77
+ * `{ 'report-uri': '/csp-report', 'report-to': 'csp-endpoint' }`.
78
+ */
79
+ 'report-uri': string;
80
+ /**
81
+ * Upgrades all insecure HTTP requests to HTTPS before fetching.
82
+ * Set to `true` to emit; `false` or omit to skip.
83
+ */
84
+ 'upgrade-insecure-requests': boolean;
85
+ /**
86
+ * @deprecated Superseded by `upgrade-insecure-requests`. Blocks all mixed
87
+ * content (HTTP resources on HTTPS pages). Set to `true` to emit.
88
+ */
89
+ 'block-all-mixed-content': boolean;
90
+ }>;
3
91
  /**
4
92
  * Configuration for the `Content-Security-Policy` header.
5
93
  */
6
94
  type CspOptions = {
7
95
  /**
8
- * Map of CSP directive names to their values.
9
- * Each entry becomes one `<directive> <value>` segment in the header,
10
- * joined with `'; '`.
96
+ * Map of CSP directives to their values. Each entry becomes one segment in
97
+ * the `Content-Security-Policy` header, joined with `'; '`.
98
+ *
99
+ * - String value → `directive value` (e.g. `'img-src': "'self' data:"`)
100
+ * - `true` → `directive` (bare flag, e.g. `'upgrade-insecure-requests': true`)
101
+ * - `false` → skipped (useful for conditional disabling)
11
102
  *
12
103
  * @example
13
104
  * ```ts
14
- * { 'default-src': "'self'", 'img-src': "'self' data: https:", 'script-src': "'self' 'nonce-abc123'" }
15
- * // → "default-src 'self'; img-src 'self' data: https:; script-src 'self' 'nonce-abc123'"
105
+ * {
106
+ * 'default-src': "'self'",
107
+ * 'img-src': "'self' data: https:",
108
+ * 'upgrade-insecure-requests': true,
109
+ * 'frame-ancestors': 'https://*.viverse.com',
110
+ * 'sandbox': 'allow-scripts allow-same-origin',
111
+ * }
112
+ * // → "default-src 'self'; img-src 'self' data: https:; upgrade-insecure-requests; frame-ancestors https://*.viverse.com; sandbox allow-scripts allow-same-origin"
16
113
  * ```
17
114
  */
18
- directives: Record<string, string>;
115
+ directives: CspDirectives;
19
116
  };
20
117
  /**
21
- * Sets the `Content-Security-Policy` response header from a directives map.
118
+ * Sets the `Content-Security-Policy` response header from a typed directives map.
22
119
  *
23
- * Directive entries are joined with `'; '` to form the final header value.
24
- * Overwrites any existing CSP header from the origin.
120
+ * - Value directives are emitted as `<directive> <value>`.
121
+ * - Boolean directives (`upgrade-insecure-requests`, `block-all-mixed-content`) are emitted
122
+ * as `<directive>` with no trailing value or space.
123
+ * - Entries are joined with `'; '` to form the final header value.
124
+ * - Overwrites any existing CSP header from the origin.
25
125
  *
26
126
  * @param options - CSP configuration object containing the `directives` map.
27
127
  * @returns A `ResponseBehaviorFn` to use directly in `defineViewerResponse` or wrapped in a `ResponseRule`.
@@ -29,7 +129,7 @@ type CspOptions = {
29
129
  * @example
30
130
  * ```ts
31
131
  * import { setCsp } from '@rayselfs/cf-rule-engine/behaviors'
32
- * import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
132
+ * import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/viewer-response'
33
133
  *
34
134
  * export default defineViewerResponse([
35
135
  * setCsp({
@@ -38,11 +138,13 @@ type CspOptions = {
38
138
  * 'script-src': "'self' https://cdn.example.com",
39
139
  * 'img-src': "'self' data: https:",
40
140
  * 'frame-ancestors': "'none'",
141
+ * 'upgrade-insecure-requests': true,
41
142
  * },
42
143
  * }),
43
144
  * ])
145
+ * // → "default-src 'self'; script-src 'self' https://cdn.example.com; img-src 'self' data: https:; frame-ancestors 'none'; upgrade-insecure-requests"
44
146
  * ```
45
147
  */
46
148
  declare function setCsp(options: CspOptions): ResponseBehaviorFn;
47
149
 
48
- export { type CspOptions, setCsp };
150
+ export { type CspDirectives, type CspOptions, setCsp };
@@ -1,27 +1,127 @@
1
1
  import { ResponseBehaviorFn } from '../core/types.js';
2
2
 
3
+ /**
4
+ * All valid CSP directives with their expected value types.
5
+ *
6
+ * - `string` — directive requires a value, e.g. `'default-src': "'self'"`
7
+ * - `boolean` — value-less flag directive; `true` emits the bare directive name,
8
+ * `false` (or omitted) skips it entirely
9
+ * - `string | boolean` — directive is valid with or without a value (sandbox only)
10
+ *
11
+ * All fields are optional. Omitted fields are not emitted in the header.
12
+ *
13
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
14
+ */
15
+ type CspDirectives = Partial<{
16
+ /** Fallback for all fetch directives not explicitly set. */
17
+ 'default-src': string;
18
+ /** Valid sources for Web Workers and nested browsing contexts. */
19
+ 'child-src': string;
20
+ /** Valid sources for XMLHttpRequest, WebSocket, EventSource, fetch(). */
21
+ 'connect-src': string;
22
+ /** Valid sources for fonts loaded with @font-face. */
23
+ 'font-src': string;
24
+ /** Valid sources for nested browsing contexts such as <frame> and <iframe>. */
25
+ 'frame-src': string;
26
+ /** Valid sources for images and favicons. */
27
+ 'img-src': string;
28
+ /** Valid sources for manifest files. */
29
+ 'manifest-src': string;
30
+ /** Valid sources for <audio>, <video>, and <track>. */
31
+ 'media-src': string;
32
+ /** Valid sources for <object> and <embed>. */
33
+ 'object-src': string;
34
+ /** Valid sources for JavaScript <script> elements. */
35
+ 'script-src': string;
36
+ /** Valid sources for inline <script> event handlers. */
37
+ 'script-src-attr': string;
38
+ /** Valid sources for JavaScript <script> elements (external files). */
39
+ 'script-src-elem': string;
40
+ /** Valid sources for stylesheets. */
41
+ 'style-src': string;
42
+ /** Valid sources for inline style attributes. */
43
+ 'style-src-attr': string;
44
+ /** Valid sources for <link> stylesheet elements. */
45
+ 'style-src-elem': string;
46
+ /** Valid sources for Worker, SharedWorker, and ServiceWorker scripts. */
47
+ 'worker-src': string;
48
+ /** Restricts URLs that can be used as the target of a <base> element. */
49
+ 'base-uri': string;
50
+ /**
51
+ * Applies sandbox restrictions to the page. Presence alone (`true`) enables
52
+ * the most restrictive sandbox. Pass a string of `allow-*` tokens to relax
53
+ * specific restrictions, e.g. `'allow-scripts allow-same-origin'`.
54
+ */
55
+ sandbox: string | boolean;
56
+ /** Restricts URLs that can be used as a form action target. */
57
+ 'form-action': string;
58
+ /** Restricts which parents may embed this page in a frame. */
59
+ 'frame-ancestors': string;
60
+ /** Restricts URLs the document may navigate to. */
61
+ 'navigate-to': string;
62
+ /**
63
+ * Restricts creation of Trusted Types policies.
64
+ * Use `'none'` to disallow all policies, or list allowed policy names.
65
+ */
66
+ 'trusted-types': string;
67
+ /**
68
+ * Enforces Trusted Types for a sink group.
69
+ * Common value: `'script'`.
70
+ */
71
+ 'require-trusted-types-for': string;
72
+ /** Reporting group name (defined via `Report-To` header). Preferred over `report-uri`. */
73
+ 'report-to': string;
74
+ /**
75
+ * @deprecated Use `report-to` instead. `report-uri` is deprecated but remains
76
+ * widely supported. Include both during transition:
77
+ * `{ 'report-uri': '/csp-report', 'report-to': 'csp-endpoint' }`.
78
+ */
79
+ 'report-uri': string;
80
+ /**
81
+ * Upgrades all insecure HTTP requests to HTTPS before fetching.
82
+ * Set to `true` to emit; `false` or omit to skip.
83
+ */
84
+ 'upgrade-insecure-requests': boolean;
85
+ /**
86
+ * @deprecated Superseded by `upgrade-insecure-requests`. Blocks all mixed
87
+ * content (HTTP resources on HTTPS pages). Set to `true` to emit.
88
+ */
89
+ 'block-all-mixed-content': boolean;
90
+ }>;
3
91
  /**
4
92
  * Configuration for the `Content-Security-Policy` header.
5
93
  */
6
94
  type CspOptions = {
7
95
  /**
8
- * Map of CSP directive names to their values.
9
- * Each entry becomes one `<directive> <value>` segment in the header,
10
- * joined with `'; '`.
96
+ * Map of CSP directives to their values. Each entry becomes one segment in
97
+ * the `Content-Security-Policy` header, joined with `'; '`.
98
+ *
99
+ * - String value → `directive value` (e.g. `'img-src': "'self' data:"`)
100
+ * - `true` → `directive` (bare flag, e.g. `'upgrade-insecure-requests': true`)
101
+ * - `false` → skipped (useful for conditional disabling)
11
102
  *
12
103
  * @example
13
104
  * ```ts
14
- * { 'default-src': "'self'", 'img-src': "'self' data: https:", 'script-src': "'self' 'nonce-abc123'" }
15
- * // → "default-src 'self'; img-src 'self' data: https:; script-src 'self' 'nonce-abc123'"
105
+ * {
106
+ * 'default-src': "'self'",
107
+ * 'img-src': "'self' data: https:",
108
+ * 'upgrade-insecure-requests': true,
109
+ * 'frame-ancestors': 'https://*.viverse.com',
110
+ * 'sandbox': 'allow-scripts allow-same-origin',
111
+ * }
112
+ * // → "default-src 'self'; img-src 'self' data: https:; upgrade-insecure-requests; frame-ancestors https://*.viverse.com; sandbox allow-scripts allow-same-origin"
16
113
  * ```
17
114
  */
18
- directives: Record<string, string>;
115
+ directives: CspDirectives;
19
116
  };
20
117
  /**
21
- * Sets the `Content-Security-Policy` response header from a directives map.
118
+ * Sets the `Content-Security-Policy` response header from a typed directives map.
22
119
  *
23
- * Directive entries are joined with `'; '` to form the final header value.
24
- * Overwrites any existing CSP header from the origin.
120
+ * - Value directives are emitted as `<directive> <value>`.
121
+ * - Boolean directives (`upgrade-insecure-requests`, `block-all-mixed-content`) are emitted
122
+ * as `<directive>` with no trailing value or space.
123
+ * - Entries are joined with `'; '` to form the final header value.
124
+ * - Overwrites any existing CSP header from the origin.
25
125
  *
26
126
  * @param options - CSP configuration object containing the `directives` map.
27
127
  * @returns A `ResponseBehaviorFn` to use directly in `defineViewerResponse` or wrapped in a `ResponseRule`.
@@ -29,7 +129,7 @@ type CspOptions = {
29
129
  * @example
30
130
  * ```ts
31
131
  * import { setCsp } from '@rayselfs/cf-rule-engine/behaviors'
32
- * import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
132
+ * import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/viewer-response'
33
133
  *
34
134
  * export default defineViewerResponse([
35
135
  * setCsp({
@@ -38,11 +138,13 @@ type CspOptions = {
38
138
  * 'script-src': "'self' https://cdn.example.com",
39
139
  * 'img-src': "'self' data: https:",
40
140
  * 'frame-ancestors': "'none'",
141
+ * 'upgrade-insecure-requests': true,
41
142
  * },
42
143
  * }),
43
144
  * ])
145
+ * // → "default-src 'self'; script-src 'self' https://cdn.example.com; img-src 'self' data: https:; frame-ancestors 'none'; upgrade-insecure-requests"
44
146
  * ```
45
147
  */
46
148
  declare function setCsp(options: CspOptions): ResponseBehaviorFn;
47
149
 
48
- export { type CspOptions, setCsp };
150
+ export { type CspDirectives, type CspOptions, setCsp };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  setCsp
3
- } from "../chunk-XUI4Y22M.js";
3
+ } from "../chunk-QU32MXNE.js";
4
4
  import "../chunk-MLKGABMK.js";
5
5
  export {
6
6
  setCsp
@@ -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) {
@@ -3,7 +3,13 @@ function setCsp(options) {
3
3
  const dirEntries = Object.entries(options.directives);
4
4
  const dirParts = [];
5
5
  for (let i = 0; i < dirEntries.length; i++) {
6
- dirParts.push(dirEntries[i][0] + " " + dirEntries[i][1]);
6
+ const key = dirEntries[i][0];
7
+ const val = dirEntries[i][1];
8
+ if (val === true) {
9
+ dirParts.push(key);
10
+ } else if (typeof val === "string") {
11
+ dirParts.push(key + " " + val);
12
+ }
7
13
  }
8
14
  const cspValue = dirParts.join("; ");
9
15
  return (_request, response) => {
@@ -3,7 +3,13 @@ function setCsp(options) {
3
3
  const dirEntries = Object.entries(options.directives);
4
4
  const dirParts = [];
5
5
  for (let i = 0; i < dirEntries.length; i++) {
6
- dirParts.push(dirEntries[i][0] + " " + dirEntries[i][1]);
6
+ const key = dirEntries[i][0];
7
+ const val = dirEntries[i][1];
8
+ if (val === true) {
9
+ dirParts.push(key);
10
+ } else if (typeof val === "string") {
11
+ dirParts.push(key + " " + val);
12
+ }
7
13
  }
8
14
  const cspValue = dirParts.join("; ");
9
15
  return (_request, response) => {
@@ -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.10.0",
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;