@rayselfs/cf-rule-engine 1.9.0 → 1.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/adapters/viewer-request-async.d.cts +23 -0
  2. package/dist/adapters/viewer-request-async.d.ts +23 -0
  3. package/dist/behaviors/construct-response.d.cts +2 -2
  4. package/dist/behaviors/construct-response.d.ts +2 -2
  5. package/dist/behaviors/image-optimize.d.cts +24 -13
  6. package/dist/behaviors/image-optimize.d.ts +24 -13
  7. package/dist/behaviors/index.cjs +3 -3
  8. package/dist/behaviors/index.d.cts +2 -2
  9. package/dist/behaviors/index.d.ts +2 -2
  10. package/dist/behaviors/index.js +2 -2
  11. package/dist/behaviors/kvs.d.cts +28 -0
  12. package/dist/behaviors/kvs.d.ts +28 -0
  13. package/dist/behaviors/redirect.d.cts +2 -2
  14. package/dist/behaviors/redirect.d.ts +2 -2
  15. package/dist/behaviors/set-cors-headers.cjs +3 -3
  16. package/dist/behaviors/set-cors-headers.d.cts +15 -5
  17. package/dist/behaviors/set-cors-headers.d.ts +15 -5
  18. package/dist/behaviors/set-cors-headers.js +2 -2
  19. package/dist/behaviors/set-csp.d.cts +2 -2
  20. package/dist/behaviors/set-csp.d.ts +2 -2
  21. package/dist/behaviors/set-security-headers.d.cts +2 -2
  22. package/dist/behaviors/set-security-headers.d.ts +2 -2
  23. package/dist/{chunk-ZEFLAOTL.cjs → chunk-7T4G7UF7.cjs} +2 -2
  24. package/dist/{chunk-EMDI676G.cjs → chunk-CLGM2TGT.cjs} +5 -5
  25. package/dist/{chunk-H3RK4USR.js → chunk-GKE3YDHR.js} +1 -1
  26. package/dist/chunk-HMQIXEFJ.cjs +62 -0
  27. package/dist/{chunk-VQGBRWJK.js → chunk-HWJFOKZX.js} +1 -1
  28. package/dist/{chunk-Y7TIDVVC.js → chunk-I7YELJ2P.js} +1 -1
  29. package/dist/{chunk-EEZ7NUJG.js → chunk-NJD4L4Q3.js} +3 -0
  30. package/dist/chunk-SC6UPQYF.js +62 -0
  31. package/dist/{chunk-IHVOAORH.cjs → chunk-TJ2POKWD.cjs} +2 -2
  32. package/dist/{chunk-7EA7GFWX.js → chunk-VRSD6YHP.js} +2 -2
  33. package/dist/{chunk-LVOM5GJ6.cjs → chunk-WUFGMLE7.cjs} +2 -2
  34. package/dist/{chunk-ULICUDDH.cjs → chunk-YNKZGZ7I.cjs} +3 -0
  35. package/dist/core/types.d.cts +8 -8
  36. package/dist/core/types.d.ts +8 -8
  37. package/dist/criteria/file-extension.d.cts +3 -3
  38. package/dist/criteria/file-extension.d.ts +3 -3
  39. package/dist/criteria/index.cjs +13 -13
  40. package/dist/criteria/index.js +16 -16
  41. package/dist/criteria/kvs.d.cts +28 -0
  42. package/dist/criteria/kvs.d.ts +28 -0
  43. package/dist/criteria/path-matches.cjs +3 -3
  44. package/dist/criteria/path-matches.js +2 -2
  45. package/dist/criteria/user-agent-matches.cjs +3 -3
  46. package/dist/criteria/user-agent-matches.js +2 -2
  47. package/dist/helpers/index.cjs +10 -8
  48. package/dist/helpers/index.js +9 -7
  49. package/dist/helpers/preflight-request.cjs +4 -4
  50. package/dist/helpers/preflight-request.js +3 -3
  51. package/dist/helpers/whitelist.cjs +7 -5
  52. package/dist/helpers/whitelist.d.cts +2 -37
  53. package/dist/helpers/whitelist.d.ts +2 -37
  54. package/dist/helpers/whitelist.js +6 -4
  55. package/dist/shared/kvs.d.cts +7 -2
  56. package/dist/shared/kvs.d.ts +7 -2
  57. package/dist/shared/wildcard.cjs +2 -2
  58. package/dist/shared/wildcard.js +1 -1
  59. package/package.json +1 -1
  60. package/dist/chunk-IHDSTTO2.js +0 -32
  61. package/dist/chunk-ISXKMJCN.cjs +0 -32
@@ -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;
@@ -3,7 +3,7 @@ import { Rule } from '../core/types.cjs';
3
3
  /**
4
4
  * Configuration options for the IP/User-Agent access whitelist.
5
5
  */
6
- interface WhitelistOptions {
6
+ type WhitelistOptions = {
7
7
  /**
8
8
  * CIDR ranges to allow (e.g. office IPs, VPN, stage VPCs).
9
9
  * At least one of `cidrs` or `userAgents` must be non-empty, otherwise
@@ -32,42 +32,7 @@ interface WhitelistOptions {
32
32
  * @example `['/api/health', '/public/*']`
33
33
  */
34
34
  bypassPaths?: string[];
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
- */
35
+ };
71
36
  declare function whitelist(options: WhitelistOptions): Rule;
72
37
 
73
38
  export { type WhitelistOptions, whitelist };
@@ -3,7 +3,7 @@ import { Rule } from '../core/types.js';
3
3
  /**
4
4
  * Configuration options for the IP/User-Agent access whitelist.
5
5
  */
6
- interface WhitelistOptions {
6
+ type WhitelistOptions = {
7
7
  /**
8
8
  * CIDR ranges to allow (e.g. office IPs, VPN, stage VPCs).
9
9
  * At least one of `cidrs` or `userAgents` must be non-empty, otherwise
@@ -32,42 +32,7 @@ interface WhitelistOptions {
32
32
  * @example `['/api/health', '/public/*']`
33
33
  */
34
34
  bypassPaths?: string[];
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
- */
35
+ };
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";
@@ -1,5 +1,10 @@
1
- interface KvsHandle {
1
+ /**
2
+ * Minimal interface for a CloudFront KeyValueStore handle.
3
+ * Compatible with the handle returned by `CloudFront.createKeyValueStore(event)`
4
+ * in the CF Function runtime.
5
+ */
6
+ type KvsHandle = {
2
7
  get(key: string): Promise<string | undefined>;
3
- }
8
+ };
4
9
 
5
10
  export type { KvsHandle };
@@ -1,5 +1,10 @@
1
- interface KvsHandle {
1
+ /**
2
+ * Minimal interface for a CloudFront KeyValueStore handle.
3
+ * Compatible with the handle returned by `CloudFront.createKeyValueStore(event)`
4
+ * in the CF Function runtime.
5
+ */
6
+ type KvsHandle = {
2
7
  get(key: string): Promise<string | undefined>;
3
- }
8
+ };
4
9
 
5
10
  export type { KvsHandle };
@@ -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.0",
3
+ "version": "1.9.2",
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;