@rayselfs/cf-rule-engine 1.6.1 → 1.7.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 (50) hide show
  1. package/README.md +5 -3
  2. package/dist/adapters/cf-function.cjs +7 -3
  3. package/dist/adapters/cf-function.d.cts +2 -1
  4. package/dist/adapters/cf-function.d.ts +2 -1
  5. package/dist/adapters/cf-function.js +7 -3
  6. package/dist/adapters/viewer-request.cjs +3 -2
  7. package/dist/adapters/viewer-request.d.cts +31 -2
  8. package/dist/adapters/viewer-request.d.ts +31 -2
  9. package/dist/adapters/viewer-request.js +2 -1
  10. package/dist/adapters/viewer-response.cjs +3 -3
  11. package/dist/adapters/viewer-response.d.cts +37 -2
  12. package/dist/adapters/viewer-response.d.ts +37 -2
  13. package/dist/adapters/viewer-response.js +2 -2
  14. package/dist/behaviors/index.cjs +2 -2
  15. package/dist/behaviors/index.js +1 -1
  16. package/dist/behaviors/set-security-headers.cjs +2 -2
  17. package/dist/behaviors/set-security-headers.d.cts +35 -19
  18. package/dist/behaviors/set-security-headers.d.ts +35 -19
  19. package/dist/behaviors/set-security-headers.js +1 -1
  20. package/dist/cf-function-BkfWpTfl.d.cts +10 -0
  21. package/dist/cf-function-CZwCWch-.d.ts +10 -0
  22. package/dist/chunk-3UXNXJ6N.cjs +21 -0
  23. package/dist/chunk-5ZIB3AJ7.cjs +20 -0
  24. package/dist/chunk-6NFAPLQ7.cjs +39 -0
  25. package/dist/chunk-BJZPAQHW.js +25 -0
  26. package/dist/chunk-CQ7YZ3AR.js +39 -0
  27. package/dist/chunk-N6QAQALU.cjs +36 -0
  28. package/dist/chunk-O4SOSGAP.js +21 -0
  29. package/dist/chunk-PR5UQJCC.js +20 -0
  30. package/dist/chunk-SGN2N3WI.cjs +25 -0
  31. package/dist/chunk-TURH5IFN.js +36 -0
  32. package/dist/criteria/index.cjs +12 -12
  33. package/dist/criteria/index.js +12 -12
  34. package/dist/helpers/index.cjs +6 -6
  35. package/dist/helpers/index.js +5 -5
  36. package/dist/helpers/whitelist.cjs +3 -3
  37. package/dist/helpers/whitelist.js +2 -2
  38. package/dist/index.cjs +6 -3
  39. package/dist/index.d.cts +3 -1
  40. package/dist/index.d.ts +3 -1
  41. package/dist/index.js +6 -3
  42. package/package.json +1 -1
  43. package/dist/chunk-NPMGSPNL.js +0 -88
  44. package/dist/chunk-SAXDN5NS.cjs +0 -88
  45. package/dist/chunk-UI6LKDJI.cjs +0 -19
  46. package/dist/chunk-VQCRSBWL.js +0 -19
  47. package/dist/viewer-response-C9eF2O9s.d.ts +0 -70
  48. package/dist/viewer-response-DIQHy8L7.d.cts +0 -70
  49. package/dist/{chunk-RL7ZETZR.js → chunk-ER2YEZZO.js} +3 -3
  50. package/dist/{chunk-T5EXFHVA.cjs → chunk-MO7HW25R.cjs} +3 -3
@@ -1,70 +0,0 @@
1
- import { Rule, ResponseBehaviorFn, ResponseRule } from './core/types.js';
2
-
3
- /**
4
- * Creates a CloudFront Function viewer-request handler from an ordered list of rules.
5
- *
6
- * The returned function is the CloudFront Function entry point. Assign it as
7
- * `export default` or `var handler` depending on your runtime configuration.
8
- *
9
- * Rules are evaluated in order. Processing stops at the first rule whose behavior
10
- * returns a response (e.g. `redirect`, `constructResponse`). If all rules continue,
11
- * the (possibly mutated) request is forwarded to the origin.
12
- *
13
- * @param rules - Ordered array of `Rule` objects created with `rule()`.
14
- * @returns A CloudFront Function handler `(event) => request | response`.
15
- *
16
- * @example
17
- * ```ts
18
- * import { rule, not } from '@rayselfs/cf-rule-engine'
19
- * import { ipCidr, pathPrefix } from '@rayselfs/cf-rule-engine/criteria'
20
- * import { redirect, setRequestHeader } from '@rayselfs/cf-rule-engine/behaviors'
21
- * import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/cf-function'
22
- *
23
- * export default defineViewerRequest([
24
- * rule(not(ipCidr(['10.0.0.0/8'])), redirect(302, 'https://www.example.com')),
25
- * rule(pathPrefix(['/api/']), setRequestHeader('x-forwarded-host', 'api.internal')),
26
- * ])
27
- * ```
28
- */
29
- declare function defineViewerRequest(rules: Rule[]): (event: unknown) => unknown;
30
- /**
31
- * Creates a CloudFront Function viewer-response handler from an ordered list of
32
- * response behaviors or response rules.
33
- *
34
- * Each entry can be either:
35
- * - A bare `ResponseBehaviorFn` — runs unconditionally on every response.
36
- * - A `ResponseRule` `{ criteria, behavior }` — runs only when `criteria` returns `true`
37
- * for the current request.
38
- *
39
- * All behaviors are applied in order; none can short-circuit the response.
40
- * The final merged response object is returned to CloudFront.
41
- *
42
- * Note: If no behavior explicitly sets a body, the `body` field is omitted from
43
- * the returned response to avoid overwriting the origin's actual content.
44
- *
45
- * @param responseBehaviors - Ordered array of `ResponseBehaviorFn` functions or
46
- * `ResponseRule` objects `{ criteria?, behavior }`.
47
- * @returns A CloudFront Function handler `(event) => response`.
48
- *
49
- * @example
50
- * ```ts
51
- * import { setSecurityHeaders, setCorsHeaders, setResponseHeader } from '@rayselfs/cf-rule-engine/behaviors'
52
- * import { pathPrefix } from '@rayselfs/cf-rule-engine/criteria'
53
- * import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
54
- *
55
- * export default defineViewerResponse([
56
- * setSecurityHeaders(),
57
- * setCorsHeaders({ allowedOrigins: ['https://www.example.com'] }),
58
- * { criteria: pathPrefix(['/api/']), behavior: setResponseHeader('cache-control', 'no-store') },
59
- * ])
60
- * ```
61
- */
62
- declare function defineViewerResponse(responseBehaviors: Array<ResponseBehaviorFn | ResponseRule>): (event: unknown) => unknown;
63
-
64
- declare const cfFunction_defineViewerRequest: typeof defineViewerRequest;
65
- declare const cfFunction_defineViewerResponse: typeof defineViewerResponse;
66
- declare namespace cfFunction {
67
- export { cfFunction_defineViewerRequest as defineViewerRequest, cfFunction_defineViewerResponse as defineViewerResponse };
68
- }
69
-
70
- export { defineViewerResponse as a, cfFunction as c, defineViewerRequest as d };
@@ -1,70 +0,0 @@
1
- import { Rule, ResponseBehaviorFn, ResponseRule } from './core/types.cjs';
2
-
3
- /**
4
- * Creates a CloudFront Function viewer-request handler from an ordered list of rules.
5
- *
6
- * The returned function is the CloudFront Function entry point. Assign it as
7
- * `export default` or `var handler` depending on your runtime configuration.
8
- *
9
- * Rules are evaluated in order. Processing stops at the first rule whose behavior
10
- * returns a response (e.g. `redirect`, `constructResponse`). If all rules continue,
11
- * the (possibly mutated) request is forwarded to the origin.
12
- *
13
- * @param rules - Ordered array of `Rule` objects created with `rule()`.
14
- * @returns A CloudFront Function handler `(event) => request | response`.
15
- *
16
- * @example
17
- * ```ts
18
- * import { rule, not } from '@rayselfs/cf-rule-engine'
19
- * import { ipCidr, pathPrefix } from '@rayselfs/cf-rule-engine/criteria'
20
- * import { redirect, setRequestHeader } from '@rayselfs/cf-rule-engine/behaviors'
21
- * import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/cf-function'
22
- *
23
- * export default defineViewerRequest([
24
- * rule(not(ipCidr(['10.0.0.0/8'])), redirect(302, 'https://www.example.com')),
25
- * rule(pathPrefix(['/api/']), setRequestHeader('x-forwarded-host', 'api.internal')),
26
- * ])
27
- * ```
28
- */
29
- declare function defineViewerRequest(rules: Rule[]): (event: unknown) => unknown;
30
- /**
31
- * Creates a CloudFront Function viewer-response handler from an ordered list of
32
- * response behaviors or response rules.
33
- *
34
- * Each entry can be either:
35
- * - A bare `ResponseBehaviorFn` — runs unconditionally on every response.
36
- * - A `ResponseRule` `{ criteria, behavior }` — runs only when `criteria` returns `true`
37
- * for the current request.
38
- *
39
- * All behaviors are applied in order; none can short-circuit the response.
40
- * The final merged response object is returned to CloudFront.
41
- *
42
- * Note: If no behavior explicitly sets a body, the `body` field is omitted from
43
- * the returned response to avoid overwriting the origin's actual content.
44
- *
45
- * @param responseBehaviors - Ordered array of `ResponseBehaviorFn` functions or
46
- * `ResponseRule` objects `{ criteria?, behavior }`.
47
- * @returns A CloudFront Function handler `(event) => response`.
48
- *
49
- * @example
50
- * ```ts
51
- * import { setSecurityHeaders, setCorsHeaders, setResponseHeader } from '@rayselfs/cf-rule-engine/behaviors'
52
- * import { pathPrefix } from '@rayselfs/cf-rule-engine/criteria'
53
- * import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
54
- *
55
- * export default defineViewerResponse([
56
- * setSecurityHeaders(),
57
- * setCorsHeaders({ allowedOrigins: ['https://www.example.com'] }),
58
- * { criteria: pathPrefix(['/api/']), behavior: setResponseHeader('cache-control', 'no-store') },
59
- * ])
60
- * ```
61
- */
62
- declare function defineViewerResponse(responseBehaviors: Array<ResponseBehaviorFn | ResponseRule>): (event: unknown) => unknown;
63
-
64
- declare const cfFunction_defineViewerRequest: typeof defineViewerRequest;
65
- declare const cfFunction_defineViewerResponse: typeof defineViewerResponse;
66
- declare namespace cfFunction {
67
- export { cfFunction_defineViewerRequest as defineViewerRequest, cfFunction_defineViewerResponse as defineViewerResponse };
68
- }
69
-
70
- export { defineViewerResponse as a, cfFunction as c, defineViewerRequest as d };
@@ -1,12 +1,12 @@
1
- import {
2
- userAgentMatches
3
- } from "./chunk-S2AAATFN.js";
4
1
  import {
5
2
  ipCidr
6
3
  } from "./chunk-KW5YBTSD.js";
7
4
  import {
8
5
  pathMatches
9
6
  } from "./chunk-LO2BO3RU.js";
7
+ import {
8
+ userAgentMatches
9
+ } from "./chunk-S2AAATFN.js";
10
10
  import {
11
11
  redirect
12
12
  } from "./chunk-DSSFFJWL.js";
@@ -1,14 +1,14 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
2
 
3
- var _chunkMVGYPBYBcjs = require('./chunk-MVGYPBYB.cjs');
4
-
5
-
6
3
  var _chunkD47P7HVZcjs = require('./chunk-D47P7HVZ.cjs');
7
4
 
8
5
 
9
6
  var _chunkCF5PWWTFcjs = require('./chunk-CF5PWWTF.cjs');
10
7
 
11
8
 
9
+ var _chunkMVGYPBYBcjs = require('./chunk-MVGYPBYB.cjs');
10
+
11
+
12
12
  var _chunkWWSRNCUPcjs = require('./chunk-WWSRNCUP.cjs');
13
13
 
14
14