@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.
- package/dist/adapters/viewer-request-async.d.cts +23 -0
- package/dist/adapters/viewer-request-async.d.ts +23 -0
- package/dist/behaviors/construct-response.d.cts +2 -2
- package/dist/behaviors/construct-response.d.ts +2 -2
- package/dist/behaviors/image-optimize.d.cts +24 -13
- package/dist/behaviors/image-optimize.d.ts +24 -13
- package/dist/behaviors/index.cjs +3 -3
- package/dist/behaviors/index.d.cts +2 -2
- package/dist/behaviors/index.d.ts +2 -2
- package/dist/behaviors/index.js +2 -2
- package/dist/behaviors/kvs.d.cts +28 -0
- package/dist/behaviors/kvs.d.ts +28 -0
- package/dist/behaviors/redirect.d.cts +2 -2
- package/dist/behaviors/redirect.d.ts +2 -2
- package/dist/behaviors/set-cors-headers.cjs +3 -3
- package/dist/behaviors/set-cors-headers.d.cts +15 -5
- package/dist/behaviors/set-cors-headers.d.ts +15 -5
- package/dist/behaviors/set-cors-headers.js +2 -2
- package/dist/behaviors/set-csp.d.cts +2 -2
- package/dist/behaviors/set-csp.d.ts +2 -2
- package/dist/behaviors/set-security-headers.d.cts +2 -2
- package/dist/behaviors/set-security-headers.d.ts +2 -2
- package/dist/{chunk-ZEFLAOTL.cjs → chunk-7T4G7UF7.cjs} +2 -2
- package/dist/{chunk-EMDI676G.cjs → chunk-CLGM2TGT.cjs} +5 -5
- package/dist/{chunk-H3RK4USR.js → chunk-GKE3YDHR.js} +1 -1
- package/dist/chunk-HMQIXEFJ.cjs +62 -0
- package/dist/{chunk-VQGBRWJK.js → chunk-HWJFOKZX.js} +1 -1
- package/dist/{chunk-Y7TIDVVC.js → chunk-I7YELJ2P.js} +1 -1
- package/dist/{chunk-EEZ7NUJG.js → chunk-NJD4L4Q3.js} +3 -0
- package/dist/chunk-SC6UPQYF.js +62 -0
- package/dist/{chunk-IHVOAORH.cjs → chunk-TJ2POKWD.cjs} +2 -2
- package/dist/{chunk-7EA7GFWX.js → chunk-VRSD6YHP.js} +2 -2
- package/dist/{chunk-LVOM5GJ6.cjs → chunk-WUFGMLE7.cjs} +2 -2
- package/dist/{chunk-ULICUDDH.cjs → chunk-YNKZGZ7I.cjs} +3 -0
- package/dist/core/types.d.cts +8 -8
- package/dist/core/types.d.ts +8 -8
- package/dist/criteria/file-extension.d.cts +3 -3
- package/dist/criteria/file-extension.d.ts +3 -3
- package/dist/criteria/index.cjs +13 -13
- package/dist/criteria/index.js +16 -16
- package/dist/criteria/kvs.d.cts +28 -0
- package/dist/criteria/kvs.d.ts +28 -0
- package/dist/criteria/path-matches.cjs +3 -3
- package/dist/criteria/path-matches.js +2 -2
- package/dist/criteria/user-agent-matches.cjs +3 -3
- package/dist/criteria/user-agent-matches.js +2 -2
- package/dist/helpers/index.cjs +10 -8
- package/dist/helpers/index.js +9 -7
- package/dist/helpers/preflight-request.cjs +4 -4
- package/dist/helpers/preflight-request.js +3 -3
- package/dist/helpers/whitelist.cjs +7 -5
- package/dist/helpers/whitelist.d.cts +2 -37
- package/dist/helpers/whitelist.d.ts +2 -37
- package/dist/helpers/whitelist.js +6 -4
- package/dist/shared/kvs.d.cts +7 -2
- package/dist/shared/kvs.d.ts +7 -2
- package/dist/shared/wildcard.cjs +2 -2
- package/dist/shared/wildcard.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-IHDSTTO2.js +0 -32
- 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
|
|
3
|
+
var _chunkCLGM2TGTcjs = require('../chunk-CLGM2TGT.cjs');
|
|
4
4
|
require('../chunk-OTFDML3K.cjs');
|
|
5
|
-
require('../chunk-
|
|
6
|
-
require('../chunk-
|
|
5
|
+
require('../chunk-TJ2POKWD.cjs');
|
|
6
|
+
require('../chunk-YNKZGZ7I.cjs');
|
|
7
7
|
require('../chunk-75ZPJI57.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
exports.preflightRequest =
|
|
10
|
+
exports.preflightRequest = _chunkCLGM2TGTcjs.preflightRequest;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
preflightRequest
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-VRSD6YHP.js";
|
|
4
4
|
import "../chunk-PY3JMRDG.js";
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
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
|
|
4
|
-
require('../chunk-
|
|
5
|
-
require('../chunk-
|
|
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-
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
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-
|
|
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";
|
package/dist/shared/kvs.d.cts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
|
|
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 };
|
package/dist/shared/kvs.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
|
|
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 };
|
package/dist/shared/wildcard.cjs
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
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 =
|
|
13
|
+
exports.matchesAnyWildcard = _chunkYNKZGZ7Icjs.matchesAnyWildcard; exports.matchesOriginPattern = _chunkYNKZGZ7Icjs.matchesOriginPattern; exports.matchesWildcard = _chunkYNKZGZ7Icjs.matchesWildcard; exports.wildcardToRegex = _chunkYNKZGZ7Icjs.wildcardToRegex;
|
package/dist/shared/wildcard.js
CHANGED
package/package.json
CHANGED
package/dist/chunk-IHDSTTO2.js
DELETED
|
@@ -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
|
-
};
|
package/dist/chunk-ISXKMJCN.cjs
DELETED
|
@@ -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;
|