@rayselfs/cf-rule-engine 1.8.2 → 1.9.1
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/lambda-edge.cjs +2 -2
- package/dist/adapters/lambda-edge.js +1 -1
- package/dist/adapters/viewer-request-async.cjs +26 -0
- package/dist/adapters/viewer-request-async.d.cts +28 -0
- package/dist/adapters/viewer-request-async.d.ts +28 -0
- package/dist/adapters/viewer-request-async.js +26 -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 +12 -11
- package/dist/behaviors/index.d.cts +2 -2
- package/dist/behaviors/index.d.ts +2 -2
- package/dist/behaviors/index.js +11 -10
- package/dist/behaviors/kvs.cjs +24 -0
- package/dist/behaviors/kvs.d.cts +34 -0
- package/dist/behaviors/kvs.d.ts +34 -0
- package/dist/behaviors/kvs.js +24 -0
- package/dist/behaviors/redirect.d.cts +2 -2
- package/dist/behaviors/redirect.d.ts +2 -2
- package/dist/behaviors/rewrite-uri.cjs +2 -2
- package/dist/behaviors/rewrite-uri.js +1 -1
- package/dist/behaviors/set-cors-headers.cjs +3 -2
- package/dist/behaviors/set-cors-headers.d.cts +5 -22
- package/dist/behaviors/set-cors-headers.d.ts +5 -22
- package/dist/behaviors/set-cors-headers.js +2 -1
- 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-ORW3KDO5.js → chunk-7EA7GFWX.js} +4 -7
- package/dist/{chunk-MRPTC74I.cjs → chunk-BSH5JZBL.cjs} +4 -2
- package/dist/{chunk-2DE6WPPL.js → chunk-EEZ7NUJG.js} +12 -1
- package/dist/{chunk-PBR6AREG.cjs → chunk-EMDI676G.cjs} +7 -10
- package/dist/{chunk-3BBLG4IX.cjs → chunk-G4JEAL6L.cjs} +11 -8
- package/dist/{chunk-CQA2DCVF.js → chunk-H3RK4USR.js} +4 -6
- package/dist/{chunk-RL7ZETZR.js → chunk-IHDSTTO2.js} +5 -5
- package/dist/{chunk-AEZDDJEW.cjs → chunk-IHVOAORH.cjs} +6 -8
- package/dist/{chunk-T5EXFHVA.cjs → chunk-ISXKMJCN.cjs} +5 -5
- package/dist/{chunk-MVGYPBYB.cjs → chunk-LVOM5GJ6.cjs} +2 -2
- package/dist/{chunk-D47P7HVZ.cjs → chunk-MK4QBCD5.cjs} +2 -2
- package/dist/chunk-NWRGD3AH.js +71 -0
- package/dist/{chunk-FTP7NLKX.js → chunk-QVY6REMD.js} +4 -2
- package/dist/{chunk-IBXAK2A4.cjs → chunk-ULICUDDH.cjs} +12 -1
- package/dist/{chunk-WEBU4R5C.js → chunk-ULR7EP5D.js} +11 -8
- package/dist/{chunk-S2AAATFN.js → chunk-VQGBRWJK.js} +1 -1
- package/dist/chunk-WZKRNMF2.cjs +71 -0
- package/dist/{chunk-LO2BO3RU.js → chunk-Y7TIDVVC.js} +1 -1
- package/dist/{chunk-KW5YBTSD.js → chunk-YHTUV2SA.js} +1 -1
- package/dist/{chunk-CF5PWWTF.cjs → chunk-ZEFLAOTL.cjs} +2 -2
- 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 +8 -8
- package/dist/criteria/index.js +7 -7
- package/dist/criteria/ip-cidr.cjs +3 -3
- package/dist/criteria/ip-cidr.js +2 -2
- package/dist/criteria/kvs.cjs +14 -0
- package/dist/criteria/kvs.d.cts +34 -0
- package/dist/criteria/kvs.d.ts +34 -0
- package/dist/criteria/kvs.js +14 -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 -10
- package/dist/helpers/index.js +10 -10
- package/dist/helpers/preflight-request.cjs +4 -3
- package/dist/helpers/preflight-request.js +3 -2
- package/dist/helpers/whitelist.cjs +7 -7
- package/dist/helpers/whitelist.d.cts +2 -2
- package/dist/helpers/whitelist.d.ts +2 -2
- package/dist/helpers/whitelist.js +6 -6
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/shared/cidr.cjs +2 -2
- package/dist/shared/cidr.d.cts +2 -2
- package/dist/shared/cidr.d.ts +2 -2
- package/dist/shared/cidr.js +1 -1
- package/dist/shared/kvs.cjs +1 -0
- package/dist/shared/kvs.d.cts +10 -0
- package/dist/shared/kvs.d.ts +10 -0
- package/dist/shared/kvs.js +0 -0
- package/dist/shared/wildcard.cjs +4 -2
- package/dist/shared/wildcard.d.cts +10 -1
- package/dist/shared/wildcard.d.ts +10 -1
- package/dist/shared/wildcard.js +3 -1
- package/package.json +1 -1
- package/dist/chunk-LNQPYKGG.js +0 -20
- package/dist/chunk-YVUR35RN.cjs +0 -20
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/shared/cidr.ts
|
|
2
|
+
function ipToInt(ip) {
|
|
3
|
+
return ip.split(".").reduce((acc, octet) => (acc << 8) + parseInt(octet, 10) >>> 0, 0);
|
|
4
|
+
}
|
|
5
|
+
function isIPv6(ip) {
|
|
6
|
+
return ip.indexOf(":") !== -1;
|
|
7
|
+
}
|
|
8
|
+
function expandIPv6Groups(ip) {
|
|
9
|
+
if (ip.indexOf(".") !== -1) {
|
|
10
|
+
const lastColon = ip.lastIndexOf(":");
|
|
11
|
+
const ipv4Part = ip.slice(lastColon + 1);
|
|
12
|
+
const octs = ipv4Part.split(".");
|
|
13
|
+
if (octs.length !== 4) return null;
|
|
14
|
+
const hi = (parseInt(octs[0], 10) << 8 | parseInt(octs[1], 10)) & 65535;
|
|
15
|
+
const lo = (parseInt(octs[2], 10) << 8 | parseInt(octs[3], 10)) & 65535;
|
|
16
|
+
ip = ip.slice(0, lastColon + 1) + hi.toString(16) + ":" + lo.toString(16);
|
|
17
|
+
}
|
|
18
|
+
const halves = ip.split("::");
|
|
19
|
+
if (halves.length > 2) return null;
|
|
20
|
+
const left = halves[0] ? halves[0].split(":") : [];
|
|
21
|
+
const right = halves.length === 2 && halves[1] ? halves[1].split(":") : [];
|
|
22
|
+
if (halves.length === 1 && left.length !== 8) return null;
|
|
23
|
+
const fill = 8 - left.length - right.length;
|
|
24
|
+
if (fill < 0) return null;
|
|
25
|
+
const groups = [];
|
|
26
|
+
for (let i = 0; i < left.length; i++) {
|
|
27
|
+
groups.push(parseInt(left[i] || "0", 16) & 65535);
|
|
28
|
+
}
|
|
29
|
+
for (let j = 0; j < fill; j++) {
|
|
30
|
+
groups.push(0);
|
|
31
|
+
}
|
|
32
|
+
for (let k = 0; k < right.length; k++) {
|
|
33
|
+
groups.push(parseInt(right[k] || "0", 16) & 65535);
|
|
34
|
+
}
|
|
35
|
+
return groups.length === 8 ? groups : null;
|
|
36
|
+
}
|
|
37
|
+
function inCidrIPv6(ip, cidr) {
|
|
38
|
+
const slashIdx = cidr.indexOf("/");
|
|
39
|
+
const range = slashIdx === -1 ? cidr : cidr.slice(0, slashIdx);
|
|
40
|
+
const prefixLen = slashIdx === -1 ? 128 : parseInt(cidr.slice(slashIdx + 1), 10);
|
|
41
|
+
const ipGroups = expandIPv6Groups(ip);
|
|
42
|
+
const rangeGroups = expandIPv6Groups(range);
|
|
43
|
+
if (!ipGroups || !rangeGroups) return false;
|
|
44
|
+
const fullGroups = Math.floor(prefixLen / 16);
|
|
45
|
+
const remainBits = prefixLen % 16;
|
|
46
|
+
for (let i = 0; i < fullGroups; i++) {
|
|
47
|
+
if (ipGroups[i] !== rangeGroups[i]) return false;
|
|
48
|
+
}
|
|
49
|
+
if (remainBits > 0 && fullGroups < 8) {
|
|
50
|
+
const mask = ~0 << 16 - remainBits & 65535;
|
|
51
|
+
if ((ipGroups[fullGroups] & mask) !== (rangeGroups[fullGroups] & mask)) return false;
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
function inCidr(ip, cidr) {
|
|
56
|
+
if (isIPv6(ip) || isIPv6(cidr)) return inCidrIPv6(ip, cidr);
|
|
57
|
+
const parts = cidr.split("/");
|
|
58
|
+
const range = parts[0];
|
|
59
|
+
const bits = parts[1] || "32";
|
|
60
|
+
const mask = bits === "0" ? 0 : ~0 << 32 - parseInt(bits, 10) >>> 0;
|
|
61
|
+
return (ipToInt(ip) & mask) === (ipToInt(range) & mask);
|
|
62
|
+
}
|
|
63
|
+
function matchesAnyCidr(ip, cidrs) {
|
|
64
|
+
return cidrs.some((cidr) => inCidr(ip, cidr));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
exports.ipToInt = ipToInt; exports.inCidr = inCidr; exports.matchesAnyCidr = matchesAnyCidr;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkULICUDDHcjs = require('./chunk-ULICUDDH.cjs');
|
|
4
4
|
|
|
5
5
|
// src/criteria/path-matches.ts
|
|
6
6
|
function pathMatches(patterns) {
|
|
7
7
|
return (req) => {
|
|
8
8
|
const path = req.uri.split("?")[0];
|
|
9
|
-
return
|
|
9
|
+
return _chunkULICUDDHcjs.matchesAnyWildcard.call(void 0, path, patterns);
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
|
package/dist/core/types.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Represents an HTTP request with URI, method, headers, and querystring. */
|
|
2
|
-
|
|
2
|
+
type HttpRequest = {
|
|
3
3
|
uri: string;
|
|
4
4
|
method: string;
|
|
5
5
|
protocol: string;
|
|
@@ -11,16 +11,16 @@ interface HttpRequest {
|
|
|
11
11
|
}>;
|
|
12
12
|
clientIp: string;
|
|
13
13
|
country?: string;
|
|
14
|
-
}
|
|
14
|
+
};
|
|
15
15
|
/** Represents an HTTP response with status code and headers. */
|
|
16
|
-
|
|
16
|
+
type HttpResponse = {
|
|
17
17
|
statusCode: number;
|
|
18
18
|
statusDescription?: string;
|
|
19
19
|
headers: Record<string, {
|
|
20
20
|
value: string;
|
|
21
21
|
}>;
|
|
22
22
|
body?: string;
|
|
23
|
-
}
|
|
23
|
+
};
|
|
24
24
|
/** A function that evaluates criteria against a request and returns a boolean. */
|
|
25
25
|
type CriteriaFn = (request: HttpRequest) => boolean;
|
|
26
26
|
/** Result of a behavior function: either continue processing or respond. */
|
|
@@ -36,15 +36,15 @@ type BehaviorFn = (request: HttpRequest) => BehaviorResult;
|
|
|
36
36
|
/** A function that modifies an HTTP response. */
|
|
37
37
|
type ResponseBehaviorFn = (request: HttpRequest, response: HttpResponse) => HttpResponse;
|
|
38
38
|
/** A response rule: an optional criteria guard plus a ResponseBehaviorFn. */
|
|
39
|
-
|
|
39
|
+
type ResponseRule = {
|
|
40
40
|
criteria?: CriteriaFn;
|
|
41
41
|
behavior: ResponseBehaviorFn;
|
|
42
|
-
}
|
|
42
|
+
};
|
|
43
43
|
/** A rule combining optional criteria and a behavior function. */
|
|
44
|
-
|
|
44
|
+
type Rule = {
|
|
45
45
|
criteria?: CriteriaFn;
|
|
46
46
|
behavior: BehaviorFn;
|
|
47
|
-
}
|
|
47
|
+
};
|
|
48
48
|
/** Handler for CloudFront viewer request events. */
|
|
49
49
|
type ViewerRequestHandler = (event: unknown) => unknown;
|
|
50
50
|
/** Handler for CloudFront viewer response events. */
|
package/dist/core/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Represents an HTTP request with URI, method, headers, and querystring. */
|
|
2
|
-
|
|
2
|
+
type HttpRequest = {
|
|
3
3
|
uri: string;
|
|
4
4
|
method: string;
|
|
5
5
|
protocol: string;
|
|
@@ -11,16 +11,16 @@ interface HttpRequest {
|
|
|
11
11
|
}>;
|
|
12
12
|
clientIp: string;
|
|
13
13
|
country?: string;
|
|
14
|
-
}
|
|
14
|
+
};
|
|
15
15
|
/** Represents an HTTP response with status code and headers. */
|
|
16
|
-
|
|
16
|
+
type HttpResponse = {
|
|
17
17
|
statusCode: number;
|
|
18
18
|
statusDescription?: string;
|
|
19
19
|
headers: Record<string, {
|
|
20
20
|
value: string;
|
|
21
21
|
}>;
|
|
22
22
|
body?: string;
|
|
23
|
-
}
|
|
23
|
+
};
|
|
24
24
|
/** A function that evaluates criteria against a request and returns a boolean. */
|
|
25
25
|
type CriteriaFn = (request: HttpRequest) => boolean;
|
|
26
26
|
/** Result of a behavior function: either continue processing or respond. */
|
|
@@ -36,15 +36,15 @@ type BehaviorFn = (request: HttpRequest) => BehaviorResult;
|
|
|
36
36
|
/** A function that modifies an HTTP response. */
|
|
37
37
|
type ResponseBehaviorFn = (request: HttpRequest, response: HttpResponse) => HttpResponse;
|
|
38
38
|
/** A response rule: an optional criteria guard plus a ResponseBehaviorFn. */
|
|
39
|
-
|
|
39
|
+
type ResponseRule = {
|
|
40
40
|
criteria?: CriteriaFn;
|
|
41
41
|
behavior: ResponseBehaviorFn;
|
|
42
|
-
}
|
|
42
|
+
};
|
|
43
43
|
/** A rule combining optional criteria and a behavior function. */
|
|
44
|
-
|
|
44
|
+
type Rule = {
|
|
45
45
|
criteria?: CriteriaFn;
|
|
46
46
|
behavior: BehaviorFn;
|
|
47
|
-
}
|
|
47
|
+
};
|
|
48
48
|
/** Handler for CloudFront viewer request events. */
|
|
49
49
|
type ViewerRequestHandler = (event: unknown) => unknown;
|
|
50
50
|
/** Handler for CloudFront viewer response events. */
|
|
@@ -20,11 +20,11 @@ import { CriteriaFn } from '../core/types.cjs';
|
|
|
20
20
|
*
|
|
21
21
|
* // Apply long-lived cache to static assets
|
|
22
22
|
* rule(fileExtension(['js', 'css', 'woff2', 'woff']),
|
|
23
|
-
* setCacheControl(
|
|
23
|
+
* setCacheControl('public, max-age=31536000, immutable'))
|
|
24
24
|
*
|
|
25
25
|
* // Apply image optimization for image requests
|
|
26
|
-
* rule(fileExtension(['jpg', 'jpeg', 'png', 'gif'
|
|
27
|
-
* imageOptimize())
|
|
26
|
+
* rule(fileExtension(['jpg', 'jpeg', 'png', 'gif']),
|
|
27
|
+
* imageOptimize({ breakpoints: [320, 640, 960, 1280, 1920] }))
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
30
|
declare function fileExtension(extensions: string[]): CriteriaFn;
|
|
@@ -20,11 +20,11 @@ import { CriteriaFn } from '../core/types.js';
|
|
|
20
20
|
*
|
|
21
21
|
* // Apply long-lived cache to static assets
|
|
22
22
|
* rule(fileExtension(['js', 'css', 'woff2', 'woff']),
|
|
23
|
-
* setCacheControl(
|
|
23
|
+
* setCacheControl('public, max-age=31536000, immutable'))
|
|
24
24
|
*
|
|
25
25
|
* // Apply image optimization for image requests
|
|
26
|
-
* rule(fileExtension(['jpg', 'jpeg', 'png', 'gif'
|
|
27
|
-
* imageOptimize())
|
|
26
|
+
* rule(fileExtension(['jpg', 'jpeg', 'png', 'gif']),
|
|
27
|
+
* imageOptimize({ breakpoints: [320, 640, 960, 1280, 1920] }))
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
30
|
declare function fileExtension(extensions: string[]): CriteriaFn;
|
package/dist/criteria/index.cjs
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
var _chunkG7JGTBTTcjs = require('../chunk-G7JGTBTT.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkZEFLAOTLcjs = require('../chunk-ZEFLAOTL.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkLVOM5GJ6cjs = require('../chunk-LVOM5GJ6.cjs');
|
|
7
10
|
|
|
8
11
|
|
|
9
12
|
var _chunk32SMWYAFcjs = require('../chunk-32SMWYAF.cjs');
|
|
@@ -15,8 +18,8 @@ var _chunkL7NBJ4JAcjs = require('../chunk-L7NBJ4JA.cjs');
|
|
|
15
18
|
var _chunkJGJW7D2Ncjs = require('../chunk-JGJW7D2N.cjs');
|
|
16
19
|
|
|
17
20
|
|
|
18
|
-
var
|
|
19
|
-
require('../chunk-
|
|
21
|
+
var _chunkMK4QBCD5cjs = require('../chunk-MK4QBCD5.cjs');
|
|
22
|
+
require('../chunk-WZKRNMF2.cjs');
|
|
20
23
|
|
|
21
24
|
|
|
22
25
|
var _chunkOTFDML3Kcjs = require('../chunk-OTFDML3K.cjs');
|
|
@@ -25,14 +28,11 @@ var _chunkOTFDML3Kcjs = require('../chunk-OTFDML3K.cjs');
|
|
|
25
28
|
var _chunkVEEOQ7TScjs = require('../chunk-VEEOQ7TS.cjs');
|
|
26
29
|
|
|
27
30
|
|
|
28
|
-
var _chunkCF5PWWTFcjs = require('../chunk-CF5PWWTF.cjs');
|
|
29
|
-
require('../chunk-IBXAK2A4.cjs');
|
|
30
|
-
|
|
31
|
-
|
|
32
31
|
var _chunkOSZWDCTScjs = require('../chunk-OSZWDCTS.cjs');
|
|
33
32
|
|
|
34
33
|
|
|
35
34
|
var _chunkU54FZCOHcjs = require('../chunk-U54FZCOH.cjs');
|
|
35
|
+
require('../chunk-ULICUDDH.cjs');
|
|
36
36
|
require('../chunk-75ZPJI57.cjs');
|
|
37
37
|
|
|
38
38
|
|
|
@@ -46,4 +46,4 @@ require('../chunk-75ZPJI57.cjs');
|
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
|
|
49
|
-
exports.countryIs = _chunkOSZWDCTScjs.countryIs; exports.fileExtension = _chunkU54FZCOHcjs.fileExtension; exports.headerContains = _chunk32SMWYAFcjs.headerContains; exports.headerEquals = _chunkL7NBJ4JAcjs.headerEquals; exports.hostnameIs = _chunkJGJW7D2Ncjs.hostnameIs; exports.ipCidr =
|
|
49
|
+
exports.countryIs = _chunkOSZWDCTScjs.countryIs; exports.fileExtension = _chunkU54FZCOHcjs.fileExtension; exports.headerContains = _chunk32SMWYAFcjs.headerContains; exports.headerEquals = _chunkL7NBJ4JAcjs.headerEquals; exports.hostnameIs = _chunkJGJW7D2Ncjs.hostnameIs; exports.ipCidr = _chunkMK4QBCD5cjs.ipCidr; exports.methodIs = _chunkOTFDML3Kcjs.methodIs; exports.pathEquals = _chunkVEEOQ7TScjs.pathEquals; exports.pathMatches = _chunkZEFLAOTLcjs.pathMatches; exports.pathPrefix = _chunkG7JGTBTTcjs.pathPrefix; exports.userAgentMatches = _chunkLVOM5GJ6cjs.userAgentMatches;
|
package/dist/criteria/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
pathPrefix
|
|
3
3
|
} from "../chunk-XLSZ5RB7.js";
|
|
4
|
+
import {
|
|
5
|
+
pathMatches
|
|
6
|
+
} from "../chunk-Y7TIDVVC.js";
|
|
4
7
|
import {
|
|
5
8
|
userAgentMatches
|
|
6
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-VQGBRWJK.js";
|
|
7
10
|
import {
|
|
8
11
|
headerContains
|
|
9
12
|
} from "../chunk-SRQF5UEJ.js";
|
|
@@ -15,24 +18,21 @@ import {
|
|
|
15
18
|
} from "../chunk-3PVDUC5M.js";
|
|
16
19
|
import {
|
|
17
20
|
ipCidr
|
|
18
|
-
} from "../chunk-
|
|
19
|
-
import "../chunk-
|
|
21
|
+
} from "../chunk-YHTUV2SA.js";
|
|
22
|
+
import "../chunk-NWRGD3AH.js";
|
|
20
23
|
import {
|
|
21
24
|
methodIs
|
|
22
25
|
} from "../chunk-PY3JMRDG.js";
|
|
23
26
|
import {
|
|
24
27
|
pathEquals
|
|
25
28
|
} from "../chunk-UD456E4I.js";
|
|
26
|
-
import {
|
|
27
|
-
pathMatches
|
|
28
|
-
} from "../chunk-LO2BO3RU.js";
|
|
29
|
-
import "../chunk-2DE6WPPL.js";
|
|
30
29
|
import {
|
|
31
30
|
countryIs
|
|
32
31
|
} from "../chunk-5CPBXZ4X.js";
|
|
33
32
|
import {
|
|
34
33
|
fileExtension
|
|
35
34
|
} from "../chunk-LBJUCJF2.js";
|
|
35
|
+
import "../chunk-EEZ7NUJG.js";
|
|
36
36
|
import "../chunk-MLKGABMK.js";
|
|
37
37
|
export {
|
|
38
38
|
countryIs,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
3
|
+
var _chunkMK4QBCD5cjs = require('../chunk-MK4QBCD5.cjs');
|
|
4
|
+
require('../chunk-WZKRNMF2.cjs');
|
|
5
5
|
require('../chunk-75ZPJI57.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
exports.ipCidr =
|
|
8
|
+
exports.ipCidr = _chunkMK4QBCD5cjs.ipCidr;
|
package/dist/criteria/ip-cidr.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkWZKRNMF2cjs = require('../chunk-WZKRNMF2.cjs');
|
|
4
|
+
require('../chunk-75ZPJI57.cjs');
|
|
5
|
+
|
|
6
|
+
// src/criteria/kvs.ts
|
|
7
|
+
async function kvsIpCidr(handle, key) {
|
|
8
|
+
const raw = await handle.get(key);
|
|
9
|
+
const cidrs = raw ? JSON.parse(raw) : [];
|
|
10
|
+
return (request) => _chunkWZKRNMF2cjs.matchesAnyCidr.call(void 0, request.clientIp, cidrs);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
exports.kvsIpCidr = kvsIpCidr;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.cjs';
|
|
2
|
+
import { KvsHandle } from '../shared/kvs.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Loads a CIDR allowlist from CloudFront KeyValueStore and returns a `CriteriaFn`
|
|
6
|
+
* that matches client IPs against the loaded ranges.
|
|
7
|
+
*
|
|
8
|
+
* The KVS value at `key` must be a JSON-encoded `string[]` of CIDR ranges
|
|
9
|
+
* (e.g. `["10.0.0.0/8", "203.0.113.0/24"]`). If the key is absent or the value
|
|
10
|
+
* is empty, no IPs will match.
|
|
11
|
+
*
|
|
12
|
+
* Intended for use with `defineViewerRequestAsync` — the KVS read happens once
|
|
13
|
+
* at setup time.
|
|
14
|
+
*
|
|
15
|
+
* @param handle - KVS handle.
|
|
16
|
+
* @param key - The KVS key whose value is a JSON CIDR array.
|
|
17
|
+
* @returns A `CriteriaFn` to pass to `rule()`.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { defineViewerRequestAsync } from '@rayselfs/cf-rule-engine/adapters/viewer-request'
|
|
22
|
+
* import { rule, not } from '@rayselfs/cf-rule-engine'
|
|
23
|
+
* import { kvsIpCidr } from '@rayselfs/cf-rule-engine/criteria/kvs'
|
|
24
|
+
* import { redirect } from '@rayselfs/cf-rule-engine/behaviors'
|
|
25
|
+
*
|
|
26
|
+
* export default defineViewerRequestAsync(async (event) => {
|
|
27
|
+
* const handle = CloudFront.createKeyValueStore(event)
|
|
28
|
+
* return [rule(not(await kvsIpCidr(handle, 'allowed-cidrs')), redirect(302, 'https://www.example.com'))]
|
|
29
|
+
* })
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare function kvsIpCidr(handle: KvsHandle, key: string): Promise<CriteriaFn>;
|
|
33
|
+
|
|
34
|
+
export { kvsIpCidr };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.js';
|
|
2
|
+
import { KvsHandle } from '../shared/kvs.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Loads a CIDR allowlist from CloudFront KeyValueStore and returns a `CriteriaFn`
|
|
6
|
+
* that matches client IPs against the loaded ranges.
|
|
7
|
+
*
|
|
8
|
+
* The KVS value at `key` must be a JSON-encoded `string[]` of CIDR ranges
|
|
9
|
+
* (e.g. `["10.0.0.0/8", "203.0.113.0/24"]`). If the key is absent or the value
|
|
10
|
+
* is empty, no IPs will match.
|
|
11
|
+
*
|
|
12
|
+
* Intended for use with `defineViewerRequestAsync` — the KVS read happens once
|
|
13
|
+
* at setup time.
|
|
14
|
+
*
|
|
15
|
+
* @param handle - KVS handle.
|
|
16
|
+
* @param key - The KVS key whose value is a JSON CIDR array.
|
|
17
|
+
* @returns A `CriteriaFn` to pass to `rule()`.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { defineViewerRequestAsync } from '@rayselfs/cf-rule-engine/adapters/viewer-request'
|
|
22
|
+
* import { rule, not } from '@rayselfs/cf-rule-engine'
|
|
23
|
+
* import { kvsIpCidr } from '@rayselfs/cf-rule-engine/criteria/kvs'
|
|
24
|
+
* import { redirect } from '@rayselfs/cf-rule-engine/behaviors'
|
|
25
|
+
*
|
|
26
|
+
* export default defineViewerRequestAsync(async (event) => {
|
|
27
|
+
* const handle = CloudFront.createKeyValueStore(event)
|
|
28
|
+
* return [rule(not(await kvsIpCidr(handle, 'allowed-cidrs')), redirect(302, 'https://www.example.com'))]
|
|
29
|
+
* })
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare function kvsIpCidr(handle: KvsHandle, key: string): Promise<CriteriaFn>;
|
|
33
|
+
|
|
34
|
+
export { kvsIpCidr };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
matchesAnyCidr
|
|
3
|
+
} from "../chunk-NWRGD3AH.js";
|
|
4
|
+
import "../chunk-MLKGABMK.js";
|
|
5
|
+
|
|
6
|
+
// src/criteria/kvs.ts
|
|
7
|
+
async function kvsIpCidr(handle, key) {
|
|
8
|
+
const raw = await handle.get(key);
|
|
9
|
+
const cidrs = raw ? JSON.parse(raw) : [];
|
|
10
|
+
return (request) => matchesAnyCidr(request.clientIp, cidrs);
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
kvsIpCidr
|
|
14
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
3
|
+
var _chunkZEFLAOTLcjs = require('../chunk-ZEFLAOTL.cjs');
|
|
4
|
+
require('../chunk-ULICUDDH.cjs');
|
|
5
5
|
require('../chunk-75ZPJI57.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
exports.pathMatches =
|
|
8
|
+
exports.pathMatches = _chunkZEFLAOTLcjs.pathMatches;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
3
|
+
var _chunkLVOM5GJ6cjs = require('../chunk-LVOM5GJ6.cjs');
|
|
4
|
+
require('../chunk-ULICUDDH.cjs');
|
|
5
5
|
require('../chunk-75ZPJI57.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
exports.userAgentMatches =
|
|
8
|
+
exports.userAgentMatches = _chunkLVOM5GJ6cjs.userAgentMatches;
|
package/dist/helpers/index.cjs
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkISXKMJCNcjs = require('../chunk-ISXKMJCN.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkEMDI676Gcjs = require('../chunk-EMDI676G.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
10
|
-
require('../chunk-
|
|
9
|
+
var _chunkLSCC62CZcjs = require('../chunk-LSCC62CZ.cjs');
|
|
10
|
+
require('../chunk-ZEFLAOTL.cjs');
|
|
11
|
+
require('../chunk-LVOM5GJ6.cjs');
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
var _chunkL7NBJ4JAcjs = require('../chunk-L7NBJ4JA.cjs');
|
|
14
|
-
require('../chunk-
|
|
15
|
-
require('../chunk-
|
|
15
|
+
require('../chunk-MK4QBCD5.cjs');
|
|
16
|
+
require('../chunk-WZKRNMF2.cjs');
|
|
16
17
|
require('../chunk-OTFDML3K.cjs');
|
|
17
|
-
require('../chunk-
|
|
18
|
-
require('../chunk-
|
|
18
|
+
require('../chunk-IHVOAORH.cjs');
|
|
19
|
+
require('../chunk-ULICUDDH.cjs');
|
|
19
20
|
|
|
20
21
|
|
|
21
22
|
var _chunkB4WEJSEZcjs = require('../chunk-B4WEJSEZ.cjs');
|
|
22
23
|
require('../chunk-WWSRNCUP.cjs');
|
|
23
|
-
require('../chunk-AEZDDJEW.cjs');
|
|
24
24
|
require('../chunk-WKYMSRCD.cjs');
|
|
25
25
|
require('../chunk-JU5WX5RU.cjs');
|
|
26
26
|
require('../chunk-75ZPJI57.cjs');
|
|
@@ -40,4 +40,4 @@ function stagingIndicator() {
|
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
|
|
43
|
-
exports.preflightRequest =
|
|
43
|
+
exports.preflightRequest = _chunkEMDI676Gcjs.preflightRequest; exports.sendCountryCode = _chunkLSCC62CZcjs.sendCountryCode; exports.stagingIndicator = stagingIndicator; exports.whitelist = _chunkISXKMJCNcjs.whitelist;
|
package/dist/helpers/index.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
whitelist
|
|
3
|
+
} from "../chunk-IHDSTTO2.js";
|
|
1
4
|
import {
|
|
2
5
|
preflightRequest
|
|
3
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-7EA7GFWX.js";
|
|
4
7
|
import {
|
|
5
8
|
sendCountryCode
|
|
6
9
|
} from "../chunk-C32DL3EP.js";
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
} from "../chunk-RL7ZETZR.js";
|
|
10
|
-
import "../chunk-S2AAATFN.js";
|
|
10
|
+
import "../chunk-Y7TIDVVC.js";
|
|
11
|
+
import "../chunk-VQGBRWJK.js";
|
|
11
12
|
import {
|
|
12
13
|
headerEquals
|
|
13
14
|
} from "../chunk-BZQJYOU2.js";
|
|
14
|
-
import "../chunk-
|
|
15
|
-
import "../chunk-
|
|
15
|
+
import "../chunk-YHTUV2SA.js";
|
|
16
|
+
import "../chunk-NWRGD3AH.js";
|
|
16
17
|
import "../chunk-PY3JMRDG.js";
|
|
17
|
-
import "../chunk-
|
|
18
|
-
import "../chunk-
|
|
18
|
+
import "../chunk-H3RK4USR.js";
|
|
19
|
+
import "../chunk-EEZ7NUJG.js";
|
|
19
20
|
import {
|
|
20
21
|
setResponseHeader
|
|
21
22
|
} from "../chunk-RBBKFG5J.js";
|
|
22
23
|
import "../chunk-DSSFFJWL.js";
|
|
23
|
-
import "../chunk-CQA2DCVF.js";
|
|
24
24
|
import "../chunk-Q4NP4C3B.js";
|
|
25
25
|
import "../chunk-BDNPQ7AU.js";
|
|
26
26
|
import "../chunk-MLKGABMK.js";
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkEMDI676Gcjs = require('../chunk-EMDI676G.cjs');
|
|
4
4
|
require('../chunk-OTFDML3K.cjs');
|
|
5
|
-
require('../chunk-
|
|
5
|
+
require('../chunk-IHVOAORH.cjs');
|
|
6
|
+
require('../chunk-ULICUDDH.cjs');
|
|
6
7
|
require('../chunk-75ZPJI57.cjs');
|
|
7
8
|
|
|
8
9
|
|
|
9
|
-
exports.preflightRequest =
|
|
10
|
+
exports.preflightRequest = _chunkEMDI676Gcjs.preflightRequest;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
preflightRequest
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-7EA7GFWX.js";
|
|
4
4
|
import "../chunk-PY3JMRDG.js";
|
|
5
|
-
import "../chunk-
|
|
5
|
+
import "../chunk-H3RK4USR.js";
|
|
6
|
+
import "../chunk-EEZ7NUJG.js";
|
|
6
7
|
import "../chunk-MLKGABMK.js";
|
|
7
8
|
export {
|
|
8
9
|
preflightRequest
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
5
|
-
require('../chunk-
|
|
6
|
-
require('../chunk-
|
|
7
|
-
require('../chunk-
|
|
8
|
-
require('../chunk-
|
|
3
|
+
var _chunkISXKMJCNcjs = require('../chunk-ISXKMJCN.cjs');
|
|
4
|
+
require('../chunk-ZEFLAOTL.cjs');
|
|
5
|
+
require('../chunk-LVOM5GJ6.cjs');
|
|
6
|
+
require('../chunk-MK4QBCD5.cjs');
|
|
7
|
+
require('../chunk-WZKRNMF2.cjs');
|
|
8
|
+
require('../chunk-ULICUDDH.cjs');
|
|
9
9
|
require('../chunk-WWSRNCUP.cjs');
|
|
10
10
|
require('../chunk-WKYMSRCD.cjs');
|
|
11
11
|
require('../chunk-75ZPJI57.cjs');
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
exports.whitelist =
|
|
14
|
+
exports.whitelist = _chunkISXKMJCNcjs.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,7 +32,7 @@ interface WhitelistOptions {
|
|
|
32
32
|
* @example `['/api/health', '/public/*']`
|
|
33
33
|
*/
|
|
34
34
|
bypassPaths?: string[];
|
|
35
|
-
}
|
|
35
|
+
};
|
|
36
36
|
/**
|
|
37
37
|
* Creates a `Rule` that restricts access by IP CIDR range and/or User-Agent
|
|
38
38
|
* pattern. Any request that does not match an allowed CIDR or User-Agent
|