@rayselfs/cf-rule-engine 1.5.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 (228) hide show
  1. package/README.md +276 -0
  2. package/dist/adapters/cf-function.cjs +10 -0
  3. package/dist/adapters/cf-function.d.cts +2 -0
  4. package/dist/adapters/cf-function.d.ts +2 -0
  5. package/dist/adapters/cf-function.js +10 -0
  6. package/dist/adapters/lambda-edge.cjs +10 -0
  7. package/dist/adapters/lambda-edge.d.cts +2 -0
  8. package/dist/adapters/lambda-edge.d.ts +2 -0
  9. package/dist/adapters/lambda-edge.js +10 -0
  10. package/dist/behaviors/construct-response.cjs +7 -0
  11. package/dist/behaviors/construct-response.d.cts +62 -0
  12. package/dist/behaviors/construct-response.d.ts +62 -0
  13. package/dist/behaviors/construct-response.js +7 -0
  14. package/dist/behaviors/copy-header.cjs +7 -0
  15. package/dist/behaviors/copy-header.d.cts +27 -0
  16. package/dist/behaviors/copy-header.d.ts +27 -0
  17. package/dist/behaviors/copy-header.js +7 -0
  18. package/dist/behaviors/directory-index.cjs +7 -0
  19. package/dist/behaviors/directory-index.d.cts +33 -0
  20. package/dist/behaviors/directory-index.d.ts +33 -0
  21. package/dist/behaviors/directory-index.js +7 -0
  22. package/dist/behaviors/image-optimize.cjs +9 -0
  23. package/dist/behaviors/image-optimize.d.cts +103 -0
  24. package/dist/behaviors/image-optimize.d.ts +103 -0
  25. package/dist/behaviors/image-optimize.js +9 -0
  26. package/dist/behaviors/index.cjs +126 -0
  27. package/dist/behaviors/index.d.cts +46 -0
  28. package/dist/behaviors/index.d.ts +46 -0
  29. package/dist/behaviors/index.js +126 -0
  30. package/dist/behaviors/redirect.cjs +7 -0
  31. package/dist/behaviors/redirect.d.cts +44 -0
  32. package/dist/behaviors/redirect.d.ts +44 -0
  33. package/dist/behaviors/redirect.js +7 -0
  34. package/dist/behaviors/remove-response-headers.cjs +7 -0
  35. package/dist/behaviors/remove-response-headers.d.cts +27 -0
  36. package/dist/behaviors/remove-response-headers.d.ts +27 -0
  37. package/dist/behaviors/remove-response-headers.js +7 -0
  38. package/dist/behaviors/rewrite-uri.cjs +7 -0
  39. package/dist/behaviors/rewrite-uri.d.cts +43 -0
  40. package/dist/behaviors/rewrite-uri.d.ts +43 -0
  41. package/dist/behaviors/rewrite-uri.js +7 -0
  42. package/dist/behaviors/set-cache-control.cjs +7 -0
  43. package/dist/behaviors/set-cache-control.d.cts +29 -0
  44. package/dist/behaviors/set-cache-control.d.ts +29 -0
  45. package/dist/behaviors/set-cache-control.js +7 -0
  46. package/dist/behaviors/set-cors-headers.cjs +7 -0
  47. package/dist/behaviors/set-cors-headers.d.cts +76 -0
  48. package/dist/behaviors/set-cors-headers.d.ts +76 -0
  49. package/dist/behaviors/set-cors-headers.js +7 -0
  50. package/dist/behaviors/set-csp.cjs +7 -0
  51. package/dist/behaviors/set-csp.d.cts +48 -0
  52. package/dist/behaviors/set-csp.d.ts +48 -0
  53. package/dist/behaviors/set-csp.js +7 -0
  54. package/dist/behaviors/set-request-header.cjs +7 -0
  55. package/dist/behaviors/set-request-header.d.cts +26 -0
  56. package/dist/behaviors/set-request-header.d.ts +26 -0
  57. package/dist/behaviors/set-request-header.js +7 -0
  58. package/dist/behaviors/set-response-header.cjs +7 -0
  59. package/dist/behaviors/set-response-header.d.cts +28 -0
  60. package/dist/behaviors/set-response-header.d.ts +28 -0
  61. package/dist/behaviors/set-response-header.js +7 -0
  62. package/dist/behaviors/set-security-headers.cjs +7 -0
  63. package/dist/behaviors/set-security-headers.d.cts +55 -0
  64. package/dist/behaviors/set-security-headers.d.ts +55 -0
  65. package/dist/behaviors/set-security-headers.js +7 -0
  66. package/dist/behaviors/strip-query-params.cjs +7 -0
  67. package/dist/behaviors/strip-query-params.d.cts +25 -0
  68. package/dist/behaviors/strip-query-params.d.ts +25 -0
  69. package/dist/behaviors/strip-query-params.js +7 -0
  70. package/dist/cf-function-D27hUVtN.d.cts +70 -0
  71. package/dist/cf-function-u0PvbW_s.d.ts +70 -0
  72. package/dist/chunk-2DE6WPPL.js +21 -0
  73. package/dist/chunk-32SMWYAF.cjs +13 -0
  74. package/dist/chunk-3BBLG4IX.cjs +132 -0
  75. package/dist/chunk-3PVDUC5M.js +12 -0
  76. package/dist/chunk-5CPBXZ4X.js +12 -0
  77. package/dist/chunk-5PT5X62W.js +98 -0
  78. package/dist/chunk-63WIEBQB.cjs +50 -0
  79. package/dist/chunk-6DBZBV2M.js +42 -0
  80. package/dist/chunk-75ZPJI57.cjs +9 -0
  81. package/dist/chunk-B4WEJSEZ.cjs +14 -0
  82. package/dist/chunk-BDNPQ7AU.js +21 -0
  83. package/dist/chunk-BUAIBB3N.js +14 -0
  84. package/dist/chunk-BZQJYOU2.js +12 -0
  85. package/dist/chunk-C32DL3EP.js +13 -0
  86. package/dist/chunk-CF5PWWTF.cjs +15 -0
  87. package/dist/chunk-CV234DQT.cjs +14 -0
  88. package/dist/chunk-D47P7HVZ.cjs +12 -0
  89. package/dist/chunk-DSSFFJWL.js +38 -0
  90. package/dist/chunk-FTP7NLKX.js +29 -0
  91. package/dist/chunk-G7JGTBTT.cjs +8 -0
  92. package/dist/chunk-GK5JX7OM.cjs +39 -0
  93. package/dist/chunk-H2LO6MQG.js +50 -0
  94. package/dist/chunk-IBXAK2A4.cjs +21 -0
  95. package/dist/chunk-JGJW7D2N.cjs +12 -0
  96. package/dist/chunk-JU5WX5RU.cjs +21 -0
  97. package/dist/chunk-KW5YBTSD.js +12 -0
  98. package/dist/chunk-KZ72PI2A.js +0 -0
  99. package/dist/chunk-L7NBJ4JA.cjs +12 -0
  100. package/dist/chunk-LBJUCJF2.js +14 -0
  101. package/dist/chunk-LNQPYKGG.js +20 -0
  102. package/dist/chunk-LO2BO3RU.js +15 -0
  103. package/dist/chunk-LSCC62CZ.cjs +13 -0
  104. package/dist/chunk-LTLBEBKL.cjs +42 -0
  105. package/dist/chunk-M5KUQBDW.js +17 -0
  106. package/dist/chunk-MEHWLQLR.cjs +1 -0
  107. package/dist/chunk-MLKGABMK.js +9 -0
  108. package/dist/chunk-MRPTC74I.cjs +29 -0
  109. package/dist/chunk-MSES76XK.cjs +14 -0
  110. package/dist/chunk-MVGYPBYB.cjs +16 -0
  111. package/dist/chunk-NPMGSPNL.js +88 -0
  112. package/dist/chunk-OSGZTNTS.cjs +42 -0
  113. package/dist/chunk-OSZWDCTS.cjs +12 -0
  114. package/dist/chunk-OTFDML3K.cjs +11 -0
  115. package/dist/chunk-PPUHEL4H.cjs +17 -0
  116. package/dist/chunk-PY3JMRDG.js +11 -0
  117. package/dist/chunk-Q4NP4C3B.js +47 -0
  118. package/dist/chunk-R7WXS7BI.js +42 -0
  119. package/dist/chunk-RBBKFG5J.js +14 -0
  120. package/dist/chunk-S2AAATFN.js +16 -0
  121. package/dist/chunk-SAXDN5NS.cjs +88 -0
  122. package/dist/chunk-SGEBNQR2.cjs +14 -0
  123. package/dist/chunk-SOBTD7AD.js +39 -0
  124. package/dist/chunk-SRQF5UEJ.js +13 -0
  125. package/dist/chunk-TQLJIT4H.cjs +98 -0
  126. package/dist/chunk-U54FZCOH.cjs +14 -0
  127. package/dist/chunk-UD456E4I.js +8 -0
  128. package/dist/chunk-UI6LKDJI.cjs +19 -0
  129. package/dist/chunk-UKB5JAX4.js +32 -0
  130. package/dist/chunk-VEEOQ7TS.cjs +8 -0
  131. package/dist/chunk-VQCRSBWL.js +19 -0
  132. package/dist/chunk-WEBU4R5C.js +132 -0
  133. package/dist/chunk-WKYMSRCD.cjs +47 -0
  134. package/dist/chunk-WW7YVRAI.cjs +32 -0
  135. package/dist/chunk-WWSRNCUP.cjs +38 -0
  136. package/dist/chunk-XLSZ5RB7.js +8 -0
  137. package/dist/chunk-XPQG5IML.js +14 -0
  138. package/dist/chunk-XUI4Y22M.js +20 -0
  139. package/dist/chunk-YVUR35RN.cjs +20 -0
  140. package/dist/chunk-ZTMSH34E.js +14 -0
  141. package/dist/chunk-ZXS23HXA.cjs +20 -0
  142. package/dist/core/rule.cjs +17 -0
  143. package/dist/core/rule.d.cts +101 -0
  144. package/dist/core/rule.d.ts +101 -0
  145. package/dist/core/rule.js +17 -0
  146. package/dist/core/types.cjs +1 -0
  147. package/dist/core/types.d.cts +53 -0
  148. package/dist/core/types.d.ts +53 -0
  149. package/dist/core/types.js +1 -0
  150. package/dist/criteria/country-is.cjs +7 -0
  151. package/dist/criteria/country-is.d.cts +35 -0
  152. package/dist/criteria/country-is.d.ts +35 -0
  153. package/dist/criteria/country-is.js +7 -0
  154. package/dist/criteria/file-extension.cjs +7 -0
  155. package/dist/criteria/file-extension.d.cts +32 -0
  156. package/dist/criteria/file-extension.d.ts +32 -0
  157. package/dist/criteria/file-extension.js +7 -0
  158. package/dist/criteria/header-contains.cjs +7 -0
  159. package/dist/criteria/header-contains.d.cts +33 -0
  160. package/dist/criteria/header-contains.d.ts +33 -0
  161. package/dist/criteria/header-contains.js +7 -0
  162. package/dist/criteria/header-equals.cjs +7 -0
  163. package/dist/criteria/header-equals.d.cts +31 -0
  164. package/dist/criteria/header-equals.d.ts +31 -0
  165. package/dist/criteria/header-equals.js +7 -0
  166. package/dist/criteria/hostname-is.cjs +7 -0
  167. package/dist/criteria/hostname-is.d.cts +22 -0
  168. package/dist/criteria/hostname-is.d.ts +22 -0
  169. package/dist/criteria/hostname-is.js +7 -0
  170. package/dist/criteria/index.cjs +49 -0
  171. package/dist/criteria/index.d.cts +12 -0
  172. package/dist/criteria/index.d.ts +12 -0
  173. package/dist/criteria/index.js +49 -0
  174. package/dist/criteria/ip-cidr.cjs +8 -0
  175. package/dist/criteria/ip-cidr.d.cts +31 -0
  176. package/dist/criteria/ip-cidr.d.ts +31 -0
  177. package/dist/criteria/ip-cidr.js +8 -0
  178. package/dist/criteria/method-is.cjs +7 -0
  179. package/dist/criteria/method-is.d.cts +29 -0
  180. package/dist/criteria/method-is.d.ts +29 -0
  181. package/dist/criteria/method-is.js +7 -0
  182. package/dist/criteria/path-equals.cjs +7 -0
  183. package/dist/criteria/path-equals.d.cts +22 -0
  184. package/dist/criteria/path-equals.d.ts +22 -0
  185. package/dist/criteria/path-equals.js +7 -0
  186. package/dist/criteria/path-matches.cjs +8 -0
  187. package/dist/criteria/path-matches.d.cts +22 -0
  188. package/dist/criteria/path-matches.d.ts +22 -0
  189. package/dist/criteria/path-matches.js +8 -0
  190. package/dist/criteria/path-prefix.cjs +7 -0
  191. package/dist/criteria/path-prefix.d.cts +21 -0
  192. package/dist/criteria/path-prefix.d.ts +21 -0
  193. package/dist/criteria/path-prefix.js +7 -0
  194. package/dist/criteria/user-agent-matches.cjs +8 -0
  195. package/dist/criteria/user-agent-matches.d.cts +32 -0
  196. package/dist/criteria/user-agent-matches.d.ts +32 -0
  197. package/dist/criteria/user-agent-matches.js +8 -0
  198. package/dist/helpers/index.cjs +42 -0
  199. package/dist/helpers/index.d.cts +34 -0
  200. package/dist/helpers/index.d.ts +34 -0
  201. package/dist/helpers/index.js +42 -0
  202. package/dist/helpers/preflight-request.cjs +8 -0
  203. package/dist/helpers/preflight-request.d.cts +38 -0
  204. package/dist/helpers/preflight-request.d.ts +38 -0
  205. package/dist/helpers/preflight-request.js +8 -0
  206. package/dist/helpers/send-country-code.cjs +8 -0
  207. package/dist/helpers/send-country-code.d.cts +35 -0
  208. package/dist/helpers/send-country-code.d.ts +35 -0
  209. package/dist/helpers/send-country-code.js +8 -0
  210. package/dist/helpers/staging-whitelist.cjs +14 -0
  211. package/dist/helpers/staging-whitelist.d.cts +73 -0
  212. package/dist/helpers/staging-whitelist.d.ts +73 -0
  213. package/dist/helpers/staging-whitelist.js +14 -0
  214. package/dist/index.cjs +26 -0
  215. package/dist/index.d.cts +4 -0
  216. package/dist/index.d.ts +4 -0
  217. package/dist/index.js +26 -0
  218. package/dist/lambda-edge-D15Nf__n.d.ts +66 -0
  219. package/dist/lambda-edge-DxTOa2cg.d.cts +66 -0
  220. package/dist/shared/cidr.cjs +11 -0
  221. package/dist/shared/cidr.d.cts +8 -0
  222. package/dist/shared/cidr.d.ts +8 -0
  223. package/dist/shared/cidr.js +11 -0
  224. package/dist/shared/wildcard.cjs +11 -0
  225. package/dist/shared/wildcard.d.cts +8 -0
  226. package/dist/shared/wildcard.d.ts +8 -0
  227. package/dist/shared/wildcard.js +11 -0
  228. package/package.json +65 -0
@@ -0,0 +1,38 @@
1
+ import { Rule } from '../core/types.js';
2
+ import { CorsOptions } from '../behaviors/set-cors-headers.js';
3
+
4
+ /**
5
+ * Returns a `Rule` that responds 204 to OPTIONS preflight requests with CORS headers.
6
+ *
7
+ * Accepts the same `CorsOptions` as `setCorsHeaders` — pass the same object to both
8
+ * to define CORS config in one place.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { preflightRequest } from '@viverse/cf-engine/helpers'
13
+ * import { setCorsHeaders } from '@viverse/cf-engine/behaviors'
14
+ * import { defineViewerRequest, defineViewerResponse } from '@viverse/cf-engine/adapters/cf-function'
15
+ * import type { CorsOptions } from '@viverse/cf-engine/behaviors'
16
+ *
17
+ * const CORS: CorsOptions = {
18
+ * allowedOrigins: ['*'],
19
+ * allowedMethods: 'GET, POST, OPTIONS',
20
+ * allowedHeaders: 'Content-Type, Cache-Control, Pragma, Range',
21
+ * }
22
+ *
23
+ * // viewer-request.ts
24
+ * export default defineViewerRequest([
25
+ * preflightRequest(CORS),
26
+ * ])
27
+ *
28
+ * // viewer-response.ts
29
+ * export default defineViewerResponse([
30
+ * setCorsHeaders(CORS),
31
+ * ])
32
+ * ```
33
+ *
34
+ * @returns A `Rule` ready to pass into `defineViewerRequest`.
35
+ */
36
+ declare function preflightRequest(options?: CorsOptions): Rule;
37
+
38
+ export { preflightRequest };
@@ -0,0 +1,8 @@
1
+ import {
2
+ preflightRequest
3
+ } from "../chunk-H2LO6MQG.js";
4
+ import "../chunk-PY3JMRDG.js";
5
+ import "../chunk-MLKGABMK.js";
6
+ export {
7
+ preflightRequest
8
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkLSCC62CZcjs = require('../chunk-LSCC62CZ.cjs');
4
+ require('../chunk-JU5WX5RU.cjs');
5
+ require('../chunk-75ZPJI57.cjs');
6
+
7
+
8
+ exports.sendCountryCode = _chunkLSCC62CZcjs.sendCountryCode;
@@ -0,0 +1,35 @@
1
+ import { BehaviorFn } from '../core/types.cjs';
2
+
3
+ /**
4
+ * Copies the `CloudFront-Viewer-Country` header value into a custom request header,
5
+ * making the viewer's country code available to the origin server.
6
+ *
7
+ * CloudFront sets `CloudFront-Viewer-Country` to the ISO 3166-1 alpha-2 country code
8
+ * of the viewer (e.g. `'US'`, `'TW'`, `'JP'`). This helper copies it to the header name
9
+ * your origin expects, defaulting to `'x-htc-request-country-code'`.
10
+ *
11
+ * Note: The `CloudFront-Viewer-Country` header must be enabled in the CloudFront
12
+ * cache policy (under "Headers") for the origin behavior.
13
+ *
14
+ * @param targetHeader - The request header to copy the country code into.
15
+ * Default: `'x-htc-request-country-code'`.
16
+ * @returns A `BehaviorFn` to use as the second argument to `rule()`.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { sendCountryCode } from '@viverse/cf-engine/helpers'
21
+ * import { rule } from '@viverse/cf-engine'
22
+ * import { defineViewerRequest } from '@viverse/cf-engine/adapters/cf-function'
23
+ *
24
+ * export default defineViewerRequest([
25
+ * // Forward country code using the default header name
26
+ * rule(sendCountryCode()),
27
+ *
28
+ * // Forward using a custom header name
29
+ * rule(sendCountryCode('x-viewer-country')),
30
+ * ])
31
+ * ```
32
+ */
33
+ declare function sendCountryCode(targetHeader?: string): BehaviorFn;
34
+
35
+ export { sendCountryCode };
@@ -0,0 +1,35 @@
1
+ import { BehaviorFn } from '../core/types.js';
2
+
3
+ /**
4
+ * Copies the `CloudFront-Viewer-Country` header value into a custom request header,
5
+ * making the viewer's country code available to the origin server.
6
+ *
7
+ * CloudFront sets `CloudFront-Viewer-Country` to the ISO 3166-1 alpha-2 country code
8
+ * of the viewer (e.g. `'US'`, `'TW'`, `'JP'`). This helper copies it to the header name
9
+ * your origin expects, defaulting to `'x-htc-request-country-code'`.
10
+ *
11
+ * Note: The `CloudFront-Viewer-Country` header must be enabled in the CloudFront
12
+ * cache policy (under "Headers") for the origin behavior.
13
+ *
14
+ * @param targetHeader - The request header to copy the country code into.
15
+ * Default: `'x-htc-request-country-code'`.
16
+ * @returns A `BehaviorFn` to use as the second argument to `rule()`.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { sendCountryCode } from '@viverse/cf-engine/helpers'
21
+ * import { rule } from '@viverse/cf-engine'
22
+ * import { defineViewerRequest } from '@viverse/cf-engine/adapters/cf-function'
23
+ *
24
+ * export default defineViewerRequest([
25
+ * // Forward country code using the default header name
26
+ * rule(sendCountryCode()),
27
+ *
28
+ * // Forward using a custom header name
29
+ * rule(sendCountryCode('x-viewer-country')),
30
+ * ])
31
+ * ```
32
+ */
33
+ declare function sendCountryCode(targetHeader?: string): BehaviorFn;
34
+
35
+ export { sendCountryCode };
@@ -0,0 +1,8 @@
1
+ import {
2
+ sendCountryCode
3
+ } from "../chunk-C32DL3EP.js";
4
+ import "../chunk-BDNPQ7AU.js";
5
+ import "../chunk-MLKGABMK.js";
6
+ export {
7
+ sendCountryCode
8
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkWW7YVRAIcjs = require('../chunk-WW7YVRAI.cjs');
4
+ require('../chunk-D47P7HVZ.cjs');
5
+ require('../chunk-YVUR35RN.cjs');
6
+ require('../chunk-CF5PWWTF.cjs');
7
+ require('../chunk-MVGYPBYB.cjs');
8
+ require('../chunk-IBXAK2A4.cjs');
9
+ require('../chunk-WKYMSRCD.cjs');
10
+ require('../chunk-WWSRNCUP.cjs');
11
+ require('../chunk-75ZPJI57.cjs');
12
+
13
+
14
+ exports.stagingWhitelist = _chunkWW7YVRAIcjs.stagingWhitelist;
@@ -0,0 +1,73 @@
1
+ import { Rule } from '../core/types.cjs';
2
+
3
+ /**
4
+ * Configuration options for the staging environment access whitelist.
5
+ */
6
+ interface StagingWhitelistOptions {
7
+ /**
8
+ * CIDR ranges to allow (e.g. office IPs, VPN, stage VPCs).
9
+ * At least one of `cidrs` or `userAgents` must be non-empty, otherwise
10
+ * every request will be redirected.
11
+ *
12
+ * @example `['203.0.113.0/24', '10.0.0.0/8']`
13
+ */
14
+ cidrs: string[];
15
+ /**
16
+ * User-Agent wildcard patterns to allow (supports `*` and `?`).
17
+ * Requests matching any pattern are passed through regardless of IP.
18
+ *
19
+ * @example `['*InternalBot*', '*Prerender*']`
20
+ */
21
+ userAgents?: string[];
22
+ /**
23
+ * URL to redirect blocked requests to. Redirects with HTTP 302.
24
+ *
25
+ * @example `'https://www.example.com'`
26
+ */
27
+ redirectUrl: string;
28
+ /**
29
+ * URL path patterns that bypass the whitelist check entirely.
30
+ * Supports wildcard patterns (`*`, `?`).
31
+ *
32
+ * @example `['/api/health', '/public/*']`
33
+ */
34
+ bypassPaths?: string[];
35
+ }
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`.
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 { stagingWhitelist } from '@viverse/cf-engine/helpers'
51
+ * import { defineViewerRequest } from '@viverse/cf-engine/adapters/cf-function'
52
+ *
53
+ * export default defineViewerRequest([
54
+ * stagingWhitelist({
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
+ * stagingWhitelist({
64
+ * cidrs: ['203.0.113.0/24'],
65
+ * redirectUrl: 'https://www.example.com',
66
+ * bypassPaths: ['/api/health', '/robots.txt'],
67
+ * }),
68
+ * ])
69
+ * ```
70
+ */
71
+ declare function stagingWhitelist(options: StagingWhitelistOptions): Rule;
72
+
73
+ export { type StagingWhitelistOptions, stagingWhitelist };
@@ -0,0 +1,73 @@
1
+ import { Rule } from '../core/types.js';
2
+
3
+ /**
4
+ * Configuration options for the staging environment access whitelist.
5
+ */
6
+ interface StagingWhitelistOptions {
7
+ /**
8
+ * CIDR ranges to allow (e.g. office IPs, VPN, stage VPCs).
9
+ * At least one of `cidrs` or `userAgents` must be non-empty, otherwise
10
+ * every request will be redirected.
11
+ *
12
+ * @example `['203.0.113.0/24', '10.0.0.0/8']`
13
+ */
14
+ cidrs: string[];
15
+ /**
16
+ * User-Agent wildcard patterns to allow (supports `*` and `?`).
17
+ * Requests matching any pattern are passed through regardless of IP.
18
+ *
19
+ * @example `['*InternalBot*', '*Prerender*']`
20
+ */
21
+ userAgents?: string[];
22
+ /**
23
+ * URL to redirect blocked requests to. Redirects with HTTP 302.
24
+ *
25
+ * @example `'https://www.example.com'`
26
+ */
27
+ redirectUrl: string;
28
+ /**
29
+ * URL path patterns that bypass the whitelist check entirely.
30
+ * Supports wildcard patterns (`*`, `?`).
31
+ *
32
+ * @example `['/api/health', '/public/*']`
33
+ */
34
+ bypassPaths?: string[];
35
+ }
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`.
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 { stagingWhitelist } from '@viverse/cf-engine/helpers'
51
+ * import { defineViewerRequest } from '@viverse/cf-engine/adapters/cf-function'
52
+ *
53
+ * export default defineViewerRequest([
54
+ * stagingWhitelist({
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
+ * stagingWhitelist({
64
+ * cidrs: ['203.0.113.0/24'],
65
+ * redirectUrl: 'https://www.example.com',
66
+ * bypassPaths: ['/api/health', '/robots.txt'],
67
+ * }),
68
+ * ])
69
+ * ```
70
+ */
71
+ declare function stagingWhitelist(options: StagingWhitelistOptions): Rule;
72
+
73
+ export { type StagingWhitelistOptions, stagingWhitelist };
@@ -0,0 +1,14 @@
1
+ import {
2
+ stagingWhitelist
3
+ } from "../chunk-UKB5JAX4.js";
4
+ import "../chunk-KW5YBTSD.js";
5
+ import "../chunk-LNQPYKGG.js";
6
+ import "../chunk-LO2BO3RU.js";
7
+ import "../chunk-S2AAATFN.js";
8
+ import "../chunk-2DE6WPPL.js";
9
+ import "../chunk-Q4NP4C3B.js";
10
+ import "../chunk-DSSFFJWL.js";
11
+ import "../chunk-MLKGABMK.js";
12
+ export {
13
+ stagingWhitelist
14
+ };
package/dist/index.cjs ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('./chunk-MEHWLQLR.cjs');
2
+
3
+
4
+ var _chunkSAXDN5NScjs = require('./chunk-SAXDN5NS.cjs');
5
+
6
+
7
+ var _chunk3BBLG4IXcjs = require('./chunk-3BBLG4IX.cjs');
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+ var _chunkWKYMSRCDcjs = require('./chunk-WKYMSRCD.cjs');
16
+ require('./chunk-75ZPJI57.cjs');
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+ exports.all = _chunkWKYMSRCDcjs.all; exports.any = _chunkWKYMSRCDcjs.any; exports.cfFunction = _chunkSAXDN5NScjs.cf_function_exports; exports.chain = _chunkWKYMSRCDcjs.chain; exports.lambdaEdge = _chunk3BBLG4IXcjs.lambda_edge_exports; exports.not = _chunkWKYMSRCDcjs.not; exports.rule = _chunkWKYMSRCDcjs.rule; exports.runRules = _chunkWKYMSRCDcjs.runRules;
@@ -0,0 +1,4 @@
1
+ export { BehaviorFn, BehaviorResult, CriteriaFn, HttpRequest, HttpResponse, ResponseBehaviorFn, ResponseRule, Rule, ViewerRequestHandler, ViewerResponseHandler } from './core/types.cjs';
2
+ export { all, any, chain, not, rule, runRules } from './core/rule.cjs';
3
+ export { c as cfFunction } from './cf-function-D27hUVtN.cjs';
4
+ export { l as lambdaEdge } from './lambda-edge-DxTOa2cg.cjs';
@@ -0,0 +1,4 @@
1
+ export { BehaviorFn, BehaviorResult, CriteriaFn, HttpRequest, HttpResponse, ResponseBehaviorFn, ResponseRule, Rule, ViewerRequestHandler, ViewerResponseHandler } from './core/types.js';
2
+ export { all, any, chain, not, rule, runRules } from './core/rule.js';
3
+ export { c as cfFunction } from './cf-function-u0PvbW_s.js';
4
+ export { l as lambdaEdge } from './lambda-edge-D15Nf__n.js';
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
1
+ import "./chunk-KZ72PI2A.js";
2
+ import {
3
+ cf_function_exports
4
+ } from "./chunk-NPMGSPNL.js";
5
+ import {
6
+ lambda_edge_exports
7
+ } from "./chunk-WEBU4R5C.js";
8
+ import {
9
+ all,
10
+ any,
11
+ chain,
12
+ not,
13
+ rule,
14
+ runRules
15
+ } from "./chunk-Q4NP4C3B.js";
16
+ import "./chunk-MLKGABMK.js";
17
+ export {
18
+ all,
19
+ any,
20
+ cf_function_exports as cfFunction,
21
+ chain,
22
+ lambda_edge_exports as lambdaEdge,
23
+ not,
24
+ rule,
25
+ runRules
26
+ };
@@ -0,0 +1,66 @@
1
+ import { Rule, ResponseBehaviorFn, ResponseRule } from './core/types.js';
2
+
3
+ /**
4
+ * Creates a Lambda@Edge viewer-request handler from an ordered list of rules.
5
+ *
6
+ * The returned async function is the Lambda handler entry point. Export it as
7
+ * `export const handler` and set `handler = "index.handler"` in the Lambda config.
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
+ * Header format differences from CF Function are handled automatically by this adapter —
14
+ * Lambda@Edge uses `[{ key, value }]` arrays; cf-engine uses `{ value }` flat objects.
15
+ *
16
+ * @param rules - Ordered array of `Rule` objects created with `rule()`.
17
+ * @returns An async Lambda handler `async (event) => request | response`.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { rule } from '@viverse/cf-engine'
22
+ * import { verifyToken, stripQueryParams } from '@viverse/cf-engine/behaviors'
23
+ * import { defineViewerRequest } from '@viverse/cf-engine/adapters/lambda-edge'
24
+ *
25
+ * export const handler = defineViewerRequest([
26
+ * rule(verifyToken({ key: process.env.EDGE_AUTH_KEY! })),
27
+ * rule(stripQueryParams(['hdnts'])),
28
+ * ])
29
+ * ```
30
+ */
31
+ declare function defineViewerRequest(rules: Rule[]): (event: unknown) => unknown;
32
+ /**
33
+ * Creates a Lambda@Edge viewer-response handler from an ordered list of
34
+ * response behaviors or response rules.
35
+ *
36
+ * Each entry can be either:
37
+ * - A bare `ResponseBehaviorFn` — runs unconditionally on every response.
38
+ * - A `ResponseRule` `{ criteria, behavior }` — runs only when `criteria` returns `true`
39
+ * for the current request.
40
+ *
41
+ * Header format normalization (Lambda@Edge ↔ cf-engine) is handled automatically.
42
+ *
43
+ * @param responseBehaviors - Ordered array of `ResponseBehaviorFn` functions or
44
+ * `ResponseRule` objects `{ criteria?, behavior }`.
45
+ * @returns An async Lambda handler `async (event) => response`.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import { setSecurityHeaders, setCorsHeaders } from '@viverse/cf-engine/behaviors'
50
+ * import { defineViewerResponse } from '@viverse/cf-engine/adapters/lambda-edge'
51
+ *
52
+ * export const handler = defineViewerResponse([
53
+ * setSecurityHeaders(),
54
+ * setCorsHeaders({ allowedOrigins: ['https://www.viverse.com'], allowOriginEcho: true }),
55
+ * ])
56
+ * ```
57
+ */
58
+ declare function defineViewerResponse(responseBehaviors: Array<ResponseBehaviorFn | ResponseRule>): (event: unknown) => unknown;
59
+
60
+ declare const lambdaEdge_defineViewerRequest: typeof defineViewerRequest;
61
+ declare const lambdaEdge_defineViewerResponse: typeof defineViewerResponse;
62
+ declare namespace lambdaEdge {
63
+ export { lambdaEdge_defineViewerRequest as defineViewerRequest, lambdaEdge_defineViewerResponse as defineViewerResponse };
64
+ }
65
+
66
+ export { defineViewerResponse as a, defineViewerRequest as d, lambdaEdge as l };
@@ -0,0 +1,66 @@
1
+ import { Rule, ResponseBehaviorFn, ResponseRule } from './core/types.cjs';
2
+
3
+ /**
4
+ * Creates a Lambda@Edge viewer-request handler from an ordered list of rules.
5
+ *
6
+ * The returned async function is the Lambda handler entry point. Export it as
7
+ * `export const handler` and set `handler = "index.handler"` in the Lambda config.
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
+ * Header format differences from CF Function are handled automatically by this adapter —
14
+ * Lambda@Edge uses `[{ key, value }]` arrays; cf-engine uses `{ value }` flat objects.
15
+ *
16
+ * @param rules - Ordered array of `Rule` objects created with `rule()`.
17
+ * @returns An async Lambda handler `async (event) => request | response`.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { rule } from '@viverse/cf-engine'
22
+ * import { verifyToken, stripQueryParams } from '@viverse/cf-engine/behaviors'
23
+ * import { defineViewerRequest } from '@viverse/cf-engine/adapters/lambda-edge'
24
+ *
25
+ * export const handler = defineViewerRequest([
26
+ * rule(verifyToken({ key: process.env.EDGE_AUTH_KEY! })),
27
+ * rule(stripQueryParams(['hdnts'])),
28
+ * ])
29
+ * ```
30
+ */
31
+ declare function defineViewerRequest(rules: Rule[]): (event: unknown) => unknown;
32
+ /**
33
+ * Creates a Lambda@Edge viewer-response handler from an ordered list of
34
+ * response behaviors or response rules.
35
+ *
36
+ * Each entry can be either:
37
+ * - A bare `ResponseBehaviorFn` — runs unconditionally on every response.
38
+ * - A `ResponseRule` `{ criteria, behavior }` — runs only when `criteria` returns `true`
39
+ * for the current request.
40
+ *
41
+ * Header format normalization (Lambda@Edge ↔ cf-engine) is handled automatically.
42
+ *
43
+ * @param responseBehaviors - Ordered array of `ResponseBehaviorFn` functions or
44
+ * `ResponseRule` objects `{ criteria?, behavior }`.
45
+ * @returns An async Lambda handler `async (event) => response`.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import { setSecurityHeaders, setCorsHeaders } from '@viverse/cf-engine/behaviors'
50
+ * import { defineViewerResponse } from '@viverse/cf-engine/adapters/lambda-edge'
51
+ *
52
+ * export const handler = defineViewerResponse([
53
+ * setSecurityHeaders(),
54
+ * setCorsHeaders({ allowedOrigins: ['https://www.viverse.com'], allowOriginEcho: true }),
55
+ * ])
56
+ * ```
57
+ */
58
+ declare function defineViewerResponse(responseBehaviors: Array<ResponseBehaviorFn | ResponseRule>): (event: unknown) => unknown;
59
+
60
+ declare const lambdaEdge_defineViewerRequest: typeof defineViewerRequest;
61
+ declare const lambdaEdge_defineViewerResponse: typeof defineViewerResponse;
62
+ declare namespace lambdaEdge {
63
+ export { lambdaEdge_defineViewerRequest as defineViewerRequest, lambdaEdge_defineViewerResponse as defineViewerResponse };
64
+ }
65
+
66
+ export { defineViewerResponse as a, defineViewerRequest as d, lambdaEdge as l };
@@ -0,0 +1,11 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+ var _chunkYVUR35RNcjs = require('../chunk-YVUR35RN.cjs');
6
+ require('../chunk-75ZPJI57.cjs');
7
+
8
+
9
+
10
+
11
+ exports.inCidr = _chunkYVUR35RNcjs.inCidr; exports.ipToInt = _chunkYVUR35RNcjs.ipToInt; exports.matchesAnyCidr = _chunkYVUR35RNcjs.matchesAnyCidr;
@@ -0,0 +1,8 @@
1
+ /** Convert IPv4 string to unsigned 32-bit integer */
2
+ declare function ipToInt(ip: string): number;
3
+ /** Returns true if `ip` falls within the `cidr` range (e.g. "10.0.0.0/8") */
4
+ declare function inCidr(ip: string, cidr: string): boolean;
5
+ /** Returns true if `ip` matches ANY of the given CIDR ranges */
6
+ declare function matchesAnyCidr(ip: string, cidrs: string[]): boolean;
7
+
8
+ export { inCidr, ipToInt, matchesAnyCidr };
@@ -0,0 +1,8 @@
1
+ /** Convert IPv4 string to unsigned 32-bit integer */
2
+ declare function ipToInt(ip: string): number;
3
+ /** Returns true if `ip` falls within the `cidr` range (e.g. "10.0.0.0/8") */
4
+ declare function inCidr(ip: string, cidr: string): boolean;
5
+ /** Returns true if `ip` matches ANY of the given CIDR ranges */
6
+ declare function matchesAnyCidr(ip: string, cidrs: string[]): boolean;
7
+
8
+ export { inCidr, ipToInt, matchesAnyCidr };
@@ -0,0 +1,11 @@
1
+ import {
2
+ inCidr,
3
+ ipToInt,
4
+ matchesAnyCidr
5
+ } from "../chunk-LNQPYKGG.js";
6
+ import "../chunk-MLKGABMK.js";
7
+ export {
8
+ inCidr,
9
+ ipToInt,
10
+ matchesAnyCidr
11
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+ var _chunkIBXAK2A4cjs = require('../chunk-IBXAK2A4.cjs');
6
+ require('../chunk-75ZPJI57.cjs');
7
+
8
+
9
+
10
+
11
+ exports.matchesAnyWildcard = _chunkIBXAK2A4cjs.matchesAnyWildcard; exports.matchesWildcard = _chunkIBXAK2A4cjs.matchesWildcard; exports.wildcardToRegex = _chunkIBXAK2A4cjs.wildcardToRegex;
@@ -0,0 +1,8 @@
1
+ /** Convert a wildcard pattern to a RegExp. `*` matches any chars, `?` matches one char. Case-insensitive. */
2
+ declare function wildcardToRegex(pattern: string): RegExp;
3
+ /** Returns true if `str` matches the given wildcard pattern */
4
+ declare function matchesWildcard(str: string, pattern: string): boolean;
5
+ /** Returns true if `str` matches ANY of the given wildcard patterns */
6
+ declare function matchesAnyWildcard(str: string, patterns: string[]): boolean;
7
+
8
+ export { matchesAnyWildcard, matchesWildcard, wildcardToRegex };
@@ -0,0 +1,8 @@
1
+ /** Convert a wildcard pattern to a RegExp. `*` matches any chars, `?` matches one char. Case-insensitive. */
2
+ declare function wildcardToRegex(pattern: string): RegExp;
3
+ /** Returns true if `str` matches the given wildcard pattern */
4
+ declare function matchesWildcard(str: string, pattern: string): boolean;
5
+ /** Returns true if `str` matches ANY of the given wildcard patterns */
6
+ declare function matchesAnyWildcard(str: string, patterns: string[]): boolean;
7
+
8
+ export { matchesAnyWildcard, matchesWildcard, wildcardToRegex };
@@ -0,0 +1,11 @@
1
+ import {
2
+ matchesAnyWildcard,
3
+ matchesWildcard,
4
+ wildcardToRegex
5
+ } from "../chunk-2DE6WPPL.js";
6
+ import "../chunk-MLKGABMK.js";
7
+ export {
8
+ matchesAnyWildcard,
9
+ matchesWildcard,
10
+ wildcardToRegex
11
+ };