@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,27 @@
1
+ import { ResponseBehaviorFn } from '../core/types.cjs';
2
+
3
+ /**
4
+ * Removes one or more headers from the outgoing response.
5
+ *
6
+ * Useful for stripping headers that reveal implementation details
7
+ * (e.g. `server`, `x-powered-by`) or headers added by the origin that
8
+ * should not be forwarded to the client.
9
+ *
10
+ * Header names are matched case-insensitively.
11
+ *
12
+ * @param headerNames - Array of response header names to remove.
13
+ * @returns A `ResponseBehaviorFn` to use directly in `defineViewerResponse` or wrapped in a `ResponseRule`.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { removeResponseHeaders } from '@viverse/cf-engine/behaviors'
18
+ * import { defineViewerResponse } from '@viverse/cf-engine/adapters/cf-function'
19
+ *
20
+ * export default defineViewerResponse([
21
+ * removeResponseHeaders(['server', 'x-powered-by', 'x-amzn-requestid']),
22
+ * ])
23
+ * ```
24
+ */
25
+ declare function removeResponseHeaders(headerNames: string[]): ResponseBehaviorFn;
26
+
27
+ export { removeResponseHeaders };
@@ -0,0 +1,27 @@
1
+ import { ResponseBehaviorFn } from '../core/types.js';
2
+
3
+ /**
4
+ * Removes one or more headers from the outgoing response.
5
+ *
6
+ * Useful for stripping headers that reveal implementation details
7
+ * (e.g. `server`, `x-powered-by`) or headers added by the origin that
8
+ * should not be forwarded to the client.
9
+ *
10
+ * Header names are matched case-insensitively.
11
+ *
12
+ * @param headerNames - Array of response header names to remove.
13
+ * @returns A `ResponseBehaviorFn` to use directly in `defineViewerResponse` or wrapped in a `ResponseRule`.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { removeResponseHeaders } from '@viverse/cf-engine/behaviors'
18
+ * import { defineViewerResponse } from '@viverse/cf-engine/adapters/cf-function'
19
+ *
20
+ * export default defineViewerResponse([
21
+ * removeResponseHeaders(['server', 'x-powered-by', 'x-amzn-requestid']),
22
+ * ])
23
+ * ```
24
+ */
25
+ declare function removeResponseHeaders(headerNames: string[]): ResponseBehaviorFn;
26
+
27
+ export { removeResponseHeaders };
@@ -0,0 +1,7 @@
1
+ import {
2
+ removeResponseHeaders
3
+ } from "../chunk-BUAIBB3N.js";
4
+ import "../chunk-MLKGABMK.js";
5
+ export {
6
+ removeResponseHeaders
7
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkMRPTC74Icjs = require('../chunk-MRPTC74I.cjs');
4
+ require('../chunk-75ZPJI57.cjs');
5
+
6
+
7
+ exports.rewriteUri = _chunkMRPTC74Icjs.rewriteUri;
@@ -0,0 +1,43 @@
1
+ import { BehaviorFn } from '../core/types.cjs';
2
+
3
+ /**
4
+ * Rewrite mode that controls how the URI is transformed:
5
+ * - `'set'` — Replace the entire URI with the target value.
6
+ * - `'replace'` — Replace all occurrences of `match` in the URI with `target`.
7
+ * - `'prepend'` — Prepend `target` to the beginning of the URI.
8
+ * - `'regex-replace'` — Replace all matches of the `match` regex pattern with `target`.
9
+ */
10
+ type RewriteMode = 'set' | 'replace' | 'prepend' | 'regex-replace';
11
+ /**
12
+ * Rewrites the request URI before it is forwarded to the origin.
13
+ *
14
+ * Akamai equivalent: `rewriteUrl` behavior.
15
+ *
16
+ * @param mode - The rewrite strategy to apply (see `RewriteMode`).
17
+ * @param target - The target value for the rewrite (new URI, replacement string, or prefix).
18
+ * @param match - The substring or regex pattern to match against (required for `'replace'`
19
+ * and `'regex-replace'` modes; ignored for `'set'` and `'prepend'`).
20
+ * @returns A `BehaviorFn` to use as the second argument to `rule()`.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { rewriteUri } from '@viverse/cf-engine/behaviors'
25
+ * import { pathPrefix } from '@viverse/cf-engine/criteria'
26
+ * import { rule } from '@viverse/cf-engine'
27
+ *
28
+ * // Set: replace entire URI
29
+ * rule(pathEquals(['/index.php']), rewriteUri('set', '/index.html'))
30
+ *
31
+ * // Prepend: add a path prefix
32
+ * rule(pathPrefix(['/images/']), rewriteUri('prepend', '/v2'))
33
+ *
34
+ * // Replace: substitute a path segment
35
+ * rule(pathPrefix(['/legacy/']), rewriteUri('replace', '/current/', '/legacy/'))
36
+ *
37
+ * // Regex-replace: pattern-based substitution
38
+ * rule(pathMatches(['/posts/[0-9]*']), rewriteUri('regex-replace', '/articles/$1', '/posts/([0-9]+)'))
39
+ * ```
40
+ */
41
+ declare function rewriteUri(mode: RewriteMode, target: string, match?: string): BehaviorFn;
42
+
43
+ export { type RewriteMode, rewriteUri };
@@ -0,0 +1,43 @@
1
+ import { BehaviorFn } from '../core/types.js';
2
+
3
+ /**
4
+ * Rewrite mode that controls how the URI is transformed:
5
+ * - `'set'` — Replace the entire URI with the target value.
6
+ * - `'replace'` — Replace all occurrences of `match` in the URI with `target`.
7
+ * - `'prepend'` — Prepend `target` to the beginning of the URI.
8
+ * - `'regex-replace'` — Replace all matches of the `match` regex pattern with `target`.
9
+ */
10
+ type RewriteMode = 'set' | 'replace' | 'prepend' | 'regex-replace';
11
+ /**
12
+ * Rewrites the request URI before it is forwarded to the origin.
13
+ *
14
+ * Akamai equivalent: `rewriteUrl` behavior.
15
+ *
16
+ * @param mode - The rewrite strategy to apply (see `RewriteMode`).
17
+ * @param target - The target value for the rewrite (new URI, replacement string, or prefix).
18
+ * @param match - The substring or regex pattern to match against (required for `'replace'`
19
+ * and `'regex-replace'` modes; ignored for `'set'` and `'prepend'`).
20
+ * @returns A `BehaviorFn` to use as the second argument to `rule()`.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { rewriteUri } from '@viverse/cf-engine/behaviors'
25
+ * import { pathPrefix } from '@viverse/cf-engine/criteria'
26
+ * import { rule } from '@viverse/cf-engine'
27
+ *
28
+ * // Set: replace entire URI
29
+ * rule(pathEquals(['/index.php']), rewriteUri('set', '/index.html'))
30
+ *
31
+ * // Prepend: add a path prefix
32
+ * rule(pathPrefix(['/images/']), rewriteUri('prepend', '/v2'))
33
+ *
34
+ * // Replace: substitute a path segment
35
+ * rule(pathPrefix(['/legacy/']), rewriteUri('replace', '/current/', '/legacy/'))
36
+ *
37
+ * // Regex-replace: pattern-based substitution
38
+ * rule(pathMatches(['/posts/[0-9]*']), rewriteUri('regex-replace', '/articles/$1', '/posts/([0-9]+)'))
39
+ * ```
40
+ */
41
+ declare function rewriteUri(mode: RewriteMode, target: string, match?: string): BehaviorFn;
42
+
43
+ export { type RewriteMode, rewriteUri };
@@ -0,0 +1,7 @@
1
+ import {
2
+ rewriteUri
3
+ } from "../chunk-FTP7NLKX.js";
4
+ import "../chunk-MLKGABMK.js";
5
+ export {
6
+ rewriteUri
7
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkCV234DQTcjs = require('../chunk-CV234DQT.cjs');
4
+ require('../chunk-75ZPJI57.cjs');
5
+
6
+
7
+ exports.setCacheControl = _chunkCV234DQTcjs.setCacheControl;
@@ -0,0 +1,29 @@
1
+ import { ResponseBehaviorFn } from '../core/types.cjs';
2
+
3
+ /**
4
+ * Sets the `Cache-Control` response header to the specified value.
5
+ *
6
+ * Overwrites any existing `Cache-Control` header set by the origin.
7
+ * Use this to enforce caching policies at the edge regardless of origin behavior.
8
+ *
9
+ * @param value - The `Cache-Control` directive string (e.g. `'public, max-age=31536000'`).
10
+ * @returns A `ResponseBehaviorFn` to use directly in `defineViewerResponse` or wrapped in a `ResponseRule`.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { setCacheControl } from '@viverse/cf-engine/behaviors'
15
+ * import { pathPrefix } from '@viverse/cf-engine/criteria'
16
+ * import { rule } from '@viverse/cf-engine'
17
+ * import { defineViewerResponse } from '@viverse/cf-engine/adapters/cf-function'
18
+ *
19
+ * export default defineViewerResponse([
20
+ * // Cache static assets for 1 year
21
+ * { criteria: pathPrefix(['/static/']), behavior: setCacheControl('public, max-age=31536000, immutable') },
22
+ * // Never cache API responses
23
+ * { criteria: pathPrefix(['/api/']), behavior: setCacheControl('no-store') },
24
+ * ])
25
+ * ```
26
+ */
27
+ declare function setCacheControl(value: string): ResponseBehaviorFn;
28
+
29
+ export { setCacheControl };
@@ -0,0 +1,29 @@
1
+ import { ResponseBehaviorFn } from '../core/types.js';
2
+
3
+ /**
4
+ * Sets the `Cache-Control` response header to the specified value.
5
+ *
6
+ * Overwrites any existing `Cache-Control` header set by the origin.
7
+ * Use this to enforce caching policies at the edge regardless of origin behavior.
8
+ *
9
+ * @param value - The `Cache-Control` directive string (e.g. `'public, max-age=31536000'`).
10
+ * @returns A `ResponseBehaviorFn` to use directly in `defineViewerResponse` or wrapped in a `ResponseRule`.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { setCacheControl } from '@viverse/cf-engine/behaviors'
15
+ * import { pathPrefix } from '@viverse/cf-engine/criteria'
16
+ * import { rule } from '@viverse/cf-engine'
17
+ * import { defineViewerResponse } from '@viverse/cf-engine/adapters/cf-function'
18
+ *
19
+ * export default defineViewerResponse([
20
+ * // Cache static assets for 1 year
21
+ * { criteria: pathPrefix(['/static/']), behavior: setCacheControl('public, max-age=31536000, immutable') },
22
+ * // Never cache API responses
23
+ * { criteria: pathPrefix(['/api/']), behavior: setCacheControl('no-store') },
24
+ * ])
25
+ * ```
26
+ */
27
+ declare function setCacheControl(value: string): ResponseBehaviorFn;
28
+
29
+ export { setCacheControl };
@@ -0,0 +1,7 @@
1
+ import {
2
+ setCacheControl
3
+ } from "../chunk-ZTMSH34E.js";
4
+ import "../chunk-MLKGABMK.js";
5
+ export {
6
+ setCacheControl
7
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkGK5JX7OMcjs = require('../chunk-GK5JX7OM.cjs');
4
+ require('../chunk-75ZPJI57.cjs');
5
+
6
+
7
+ exports.setCorsHeaders = _chunkGK5JX7OMcjs.setCorsHeaders;
@@ -0,0 +1,76 @@
1
+ import { ResponseBehaviorFn } from '../core/types.cjs';
2
+
3
+ /**
4
+ * CORS configuration options for the `setCorsHeaders` behavior.
5
+ */
6
+ interface CorsOptions {
7
+ /**
8
+ * List of allowed origin patterns. Supports exact strings and wildcard `*` patterns
9
+ * (e.g. `'https://*.viverse.com'`). Use `['*']` to allow all origins.
10
+ * Default: `['*']`
11
+ */
12
+ allowedOrigins?: string[];
13
+ /**
14
+ * When `true`, reflects the incoming `Origin` request header as the
15
+ * `Access-Control-Allow-Origin` response value, provided it matches one of
16
+ * `allowedOrigins`. Required when `allowCredentials` is `true` (browsers reject
17
+ * `Access-Control-Allow-Origin: *` with credentials).
18
+ * Default: `false`
19
+ */
20
+ allowOriginEcho?: boolean;
21
+ /**
22
+ * Value for the `Access-Control-Allow-Methods` header.
23
+ * Default: `'GET, POST, OPTIONS'`
24
+ */
25
+ allowedMethods?: string;
26
+ /**
27
+ * Value for the `Access-Control-Allow-Headers` header.
28
+ * Default: `'Content-Type, Cache-Control, Pragma, Range'`
29
+ */
30
+ allowedHeaders?: string;
31
+ /**
32
+ * When `true`, sets `Access-Control-Allow-Credentials: true`.
33
+ * Must be used together with `allowOriginEcho: true`; browsers reject
34
+ * wildcard origins when credentials are present.
35
+ * Default: `false`
36
+ */
37
+ allowCredentials?: boolean;
38
+ /**
39
+ * Preflight cache duration in seconds. Sets `Access-Control-Max-Age` when specified.
40
+ * Omit to exclude the header.
41
+ */
42
+ maxAge?: number;
43
+ }
44
+ /**
45
+ * Sets CORS response headers with configurable origin matching, methods, headers,
46
+ * credentials, and preflight cache duration.
47
+ *
48
+ * Akamai equivalent: typically implemented via `modifyOutgoingResponseHeader` rules
49
+ * for each CORS header individually.
50
+ *
51
+ * @param options - CORS configuration. All fields are optional with safe defaults.
52
+ * @returns A `ResponseBehaviorFn` to use directly in `defineViewerResponse` or wrapped in a `ResponseRule`.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * import { setCorsHeaders } from '@viverse/cf-engine/behaviors'
57
+ * import { defineViewerResponse } from '@viverse/cf-engine/adapters/cf-function'
58
+ *
59
+ * // Allow all origins (default)
60
+ * export default defineViewerResponse([setCorsHeaders()])
61
+ *
62
+ * // Echo origin with credentials (e.g. for authenticated API endpoints)
63
+ * export default defineViewerResponse([
64
+ * setCorsHeaders({
65
+ * allowedOrigins: ['https://www.viverse.com', 'https://*.htc.com'],
66
+ * allowOriginEcho: true,
67
+ * allowCredentials: true,
68
+ * allowedMethods: 'GET, POST, PUT, DELETE, OPTIONS',
69
+ * maxAge: 86400,
70
+ * }),
71
+ * ])
72
+ * ```
73
+ */
74
+ declare function setCorsHeaders(options?: CorsOptions): ResponseBehaviorFn;
75
+
76
+ export { type CorsOptions, setCorsHeaders };
@@ -0,0 +1,76 @@
1
+ import { ResponseBehaviorFn } from '../core/types.js';
2
+
3
+ /**
4
+ * CORS configuration options for the `setCorsHeaders` behavior.
5
+ */
6
+ interface CorsOptions {
7
+ /**
8
+ * List of allowed origin patterns. Supports exact strings and wildcard `*` patterns
9
+ * (e.g. `'https://*.viverse.com'`). Use `['*']` to allow all origins.
10
+ * Default: `['*']`
11
+ */
12
+ allowedOrigins?: string[];
13
+ /**
14
+ * When `true`, reflects the incoming `Origin` request header as the
15
+ * `Access-Control-Allow-Origin` response value, provided it matches one of
16
+ * `allowedOrigins`. Required when `allowCredentials` is `true` (browsers reject
17
+ * `Access-Control-Allow-Origin: *` with credentials).
18
+ * Default: `false`
19
+ */
20
+ allowOriginEcho?: boolean;
21
+ /**
22
+ * Value for the `Access-Control-Allow-Methods` header.
23
+ * Default: `'GET, POST, OPTIONS'`
24
+ */
25
+ allowedMethods?: string;
26
+ /**
27
+ * Value for the `Access-Control-Allow-Headers` header.
28
+ * Default: `'Content-Type, Cache-Control, Pragma, Range'`
29
+ */
30
+ allowedHeaders?: string;
31
+ /**
32
+ * When `true`, sets `Access-Control-Allow-Credentials: true`.
33
+ * Must be used together with `allowOriginEcho: true`; browsers reject
34
+ * wildcard origins when credentials are present.
35
+ * Default: `false`
36
+ */
37
+ allowCredentials?: boolean;
38
+ /**
39
+ * Preflight cache duration in seconds. Sets `Access-Control-Max-Age` when specified.
40
+ * Omit to exclude the header.
41
+ */
42
+ maxAge?: number;
43
+ }
44
+ /**
45
+ * Sets CORS response headers with configurable origin matching, methods, headers,
46
+ * credentials, and preflight cache duration.
47
+ *
48
+ * Akamai equivalent: typically implemented via `modifyOutgoingResponseHeader` rules
49
+ * for each CORS header individually.
50
+ *
51
+ * @param options - CORS configuration. All fields are optional with safe defaults.
52
+ * @returns A `ResponseBehaviorFn` to use directly in `defineViewerResponse` or wrapped in a `ResponseRule`.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * import { setCorsHeaders } from '@viverse/cf-engine/behaviors'
57
+ * import { defineViewerResponse } from '@viverse/cf-engine/adapters/cf-function'
58
+ *
59
+ * // Allow all origins (default)
60
+ * export default defineViewerResponse([setCorsHeaders()])
61
+ *
62
+ * // Echo origin with credentials (e.g. for authenticated API endpoints)
63
+ * export default defineViewerResponse([
64
+ * setCorsHeaders({
65
+ * allowedOrigins: ['https://www.viverse.com', 'https://*.htc.com'],
66
+ * allowOriginEcho: true,
67
+ * allowCredentials: true,
68
+ * allowedMethods: 'GET, POST, PUT, DELETE, OPTIONS',
69
+ * maxAge: 86400,
70
+ * }),
71
+ * ])
72
+ * ```
73
+ */
74
+ declare function setCorsHeaders(options?: CorsOptions): ResponseBehaviorFn;
75
+
76
+ export { type CorsOptions, setCorsHeaders };
@@ -0,0 +1,7 @@
1
+ import {
2
+ setCorsHeaders
3
+ } from "../chunk-SOBTD7AD.js";
4
+ import "../chunk-MLKGABMK.js";
5
+ export {
6
+ setCorsHeaders
7
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkZXS23HXAcjs = require('../chunk-ZXS23HXA.cjs');
4
+ require('../chunk-75ZPJI57.cjs');
5
+
6
+
7
+ exports.setCsp = _chunkZXS23HXAcjs.setCsp;
@@ -0,0 +1,48 @@
1
+ import { ResponseBehaviorFn } from '../core/types.cjs';
2
+
3
+ /**
4
+ * Configuration for the `Content-Security-Policy` header.
5
+ */
6
+ interface CspOptions {
7
+ /**
8
+ * Map of CSP directive names to their values.
9
+ * Each entry becomes one `<directive> <value>` segment in the header,
10
+ * joined with `'; '`.
11
+ *
12
+ * @example
13
+ * ```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'"
16
+ * ```
17
+ */
18
+ directives: Record<string, string>;
19
+ }
20
+ /**
21
+ * Sets the `Content-Security-Policy` response header from a directives map.
22
+ *
23
+ * Directive entries are joined with `'; '` to form the final header value.
24
+ * Overwrites any existing CSP header from the origin.
25
+ *
26
+ * @param options - CSP configuration object containing the `directives` map.
27
+ * @returns A `ResponseBehaviorFn` to use directly in `defineViewerResponse` or wrapped in a `ResponseRule`.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { setCsp } from '@viverse/cf-engine/behaviors'
32
+ * import { defineViewerResponse } from '@viverse/cf-engine/adapters/cf-function'
33
+ *
34
+ * export default defineViewerResponse([
35
+ * setCsp({
36
+ * directives: {
37
+ * 'default-src': "'self'",
38
+ * 'script-src': "'self' https://cdn.example.com",
39
+ * 'img-src': "'self' data: https:",
40
+ * 'frame-ancestors': "'none'",
41
+ * },
42
+ * }),
43
+ * ])
44
+ * ```
45
+ */
46
+ declare function setCsp(options: CspOptions): ResponseBehaviorFn;
47
+
48
+ export { type CspOptions, setCsp };
@@ -0,0 +1,48 @@
1
+ import { ResponseBehaviorFn } from '../core/types.js';
2
+
3
+ /**
4
+ * Configuration for the `Content-Security-Policy` header.
5
+ */
6
+ interface CspOptions {
7
+ /**
8
+ * Map of CSP directive names to their values.
9
+ * Each entry becomes one `<directive> <value>` segment in the header,
10
+ * joined with `'; '`.
11
+ *
12
+ * @example
13
+ * ```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'"
16
+ * ```
17
+ */
18
+ directives: Record<string, string>;
19
+ }
20
+ /**
21
+ * Sets the `Content-Security-Policy` response header from a directives map.
22
+ *
23
+ * Directive entries are joined with `'; '` to form the final header value.
24
+ * Overwrites any existing CSP header from the origin.
25
+ *
26
+ * @param options - CSP configuration object containing the `directives` map.
27
+ * @returns A `ResponseBehaviorFn` to use directly in `defineViewerResponse` or wrapped in a `ResponseRule`.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { setCsp } from '@viverse/cf-engine/behaviors'
32
+ * import { defineViewerResponse } from '@viverse/cf-engine/adapters/cf-function'
33
+ *
34
+ * export default defineViewerResponse([
35
+ * setCsp({
36
+ * directives: {
37
+ * 'default-src': "'self'",
38
+ * 'script-src': "'self' https://cdn.example.com",
39
+ * 'img-src': "'self' data: https:",
40
+ * 'frame-ancestors': "'none'",
41
+ * },
42
+ * }),
43
+ * ])
44
+ * ```
45
+ */
46
+ declare function setCsp(options: CspOptions): ResponseBehaviorFn;
47
+
48
+ export { type CspOptions, setCsp };
@@ -0,0 +1,7 @@
1
+ import {
2
+ setCsp
3
+ } from "../chunk-XUI4Y22M.js";
4
+ import "../chunk-MLKGABMK.js";
5
+ export {
6
+ setCsp
7
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkPPUHEL4Hcjs = require('../chunk-PPUHEL4H.cjs');
4
+ require('../chunk-75ZPJI57.cjs');
5
+
6
+
7
+ exports.setRequestHeader = _chunkPPUHEL4Hcjs.setRequestHeader;
@@ -0,0 +1,26 @@
1
+ import { BehaviorFn } from '../core/types.cjs';
2
+
3
+ /**
4
+ * Sets a request header to the specified value before the request is forwarded to the origin.
5
+ *
6
+ * If the header already exists, it is overwritten. Header names are automatically lowercased
7
+ * to match CloudFront's normalized internal format.
8
+ *
9
+ * Akamai equivalent: `modifyOutgoingRequestHeader` behavior with `action: 'SET'`.
10
+ *
11
+ * @param headerName - The request header name to set (e.g. `'x-forwarded-for'`). Case-insensitive.
12
+ * @param value - The value to assign to the header.
13
+ * @returns A `BehaviorFn` to use as the second argument to `rule()`.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { setRequestHeader } from '@viverse/cf-engine/behaviors'
18
+ * import { pathPrefix } from '@viverse/cf-engine/criteria'
19
+ * import { rule } from '@viverse/cf-engine'
20
+ *
21
+ * rule(pathPrefix(['/api/']), setRequestHeader('x-internal-service', 'cf-edge'))
22
+ * ```
23
+ */
24
+ declare function setRequestHeader(headerName: string, value: string): BehaviorFn;
25
+
26
+ export { setRequestHeader };
@@ -0,0 +1,26 @@
1
+ import { BehaviorFn } from '../core/types.js';
2
+
3
+ /**
4
+ * Sets a request header to the specified value before the request is forwarded to the origin.
5
+ *
6
+ * If the header already exists, it is overwritten. Header names are automatically lowercased
7
+ * to match CloudFront's normalized internal format.
8
+ *
9
+ * Akamai equivalent: `modifyOutgoingRequestHeader` behavior with `action: 'SET'`.
10
+ *
11
+ * @param headerName - The request header name to set (e.g. `'x-forwarded-for'`). Case-insensitive.
12
+ * @param value - The value to assign to the header.
13
+ * @returns A `BehaviorFn` to use as the second argument to `rule()`.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { setRequestHeader } from '@viverse/cf-engine/behaviors'
18
+ * import { pathPrefix } from '@viverse/cf-engine/criteria'
19
+ * import { rule } from '@viverse/cf-engine'
20
+ *
21
+ * rule(pathPrefix(['/api/']), setRequestHeader('x-internal-service', 'cf-edge'))
22
+ * ```
23
+ */
24
+ declare function setRequestHeader(headerName: string, value: string): BehaviorFn;
25
+
26
+ export { setRequestHeader };
@@ -0,0 +1,7 @@
1
+ import {
2
+ setRequestHeader
3
+ } from "../chunk-M5KUQBDW.js";
4
+ import "../chunk-MLKGABMK.js";
5
+ export {
6
+ setRequestHeader
7
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkB4WEJSEZcjs = require('../chunk-B4WEJSEZ.cjs');
4
+ require('../chunk-75ZPJI57.cjs');
5
+
6
+
7
+ exports.setResponseHeader = _chunkB4WEJSEZcjs.setResponseHeader;
@@ -0,0 +1,28 @@
1
+ import { ResponseBehaviorFn } from '../core/types.cjs';
2
+
3
+ /**
4
+ * Sets a response header to the specified value.
5
+ *
6
+ * Overwrites the header if it already exists. Header names are automatically
7
+ * lowercased to match CloudFront's normalized format.
8
+ *
9
+ * Use inside `defineViewerResponse` to add or override outgoing response headers.
10
+ *
11
+ * @param headerName - The response header name to set (e.g. `'x-custom-header'`). Case-insensitive.
12
+ * @param value - The value to assign to the header.
13
+ * @returns A `ResponseBehaviorFn` to use directly in `defineViewerResponse` or wrapped in a `ResponseRule`.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { setResponseHeader } from '@viverse/cf-engine/behaviors'
18
+ * import { defineViewerResponse } from '@viverse/cf-engine/adapters/cf-function'
19
+ *
20
+ * export default defineViewerResponse([
21
+ * setResponseHeader('x-powered-by', 'CloudFront'),
22
+ * setResponseHeader('x-custom-env', 'production'),
23
+ * ])
24
+ * ```
25
+ */
26
+ declare function setResponseHeader(headerName: string, value: string): ResponseBehaviorFn;
27
+
28
+ export { setResponseHeader };