@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
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
var _chunk7T4G7UF7cjs = require('./chunk-7T4G7UF7.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkG7JGTBTTcjs = require('./chunk-G7JGTBTT.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkWUFGMLE7cjs = require('./chunk-WUFGMLE7.cjs');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkMK4QBCD5cjs = require('./chunk-MK4QBCD5.cjs');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _chunkVEEOQ7TScjs = require('./chunk-VEEOQ7TS.cjs');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var _chunkWWSRNCUPcjs = require('./chunk-WWSRNCUP.cjs');
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
var _chunkWKYMSRCDcjs = require('./chunk-WKYMSRCD.cjs');
|
|
25
|
+
|
|
26
|
+
// src/helpers/whitelist.ts
|
|
27
|
+
function buildBypassCriteria(paths) {
|
|
28
|
+
const exactPaths = [];
|
|
29
|
+
const prefixPaths = [];
|
|
30
|
+
const wildcardPatterns = [];
|
|
31
|
+
for (let i = 0; i < paths.length; i++) {
|
|
32
|
+
const p = paths[i];
|
|
33
|
+
const hasWildcard = p.indexOf("*") !== -1 || p.indexOf("?") !== -1;
|
|
34
|
+
const isTrailingSlashStar = p.charAt(p.length - 1) === "*" && p.charAt(p.length - 2) === "/" && p.indexOf("*") === p.length - 1 && p.indexOf("?") === -1;
|
|
35
|
+
if (!hasWildcard) {
|
|
36
|
+
exactPaths.push(p);
|
|
37
|
+
} else if (isTrailingSlashStar) {
|
|
38
|
+
prefixPaths.push(p.slice(0, p.length - 1));
|
|
39
|
+
} else {
|
|
40
|
+
wildcardPatterns.push(p);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const criteria = [];
|
|
44
|
+
if (exactPaths.length > 0) criteria.push(_chunkVEEOQ7TScjs.pathEquals.call(void 0, exactPaths));
|
|
45
|
+
if (prefixPaths.length > 0) criteria.push(_chunkG7JGTBTTcjs.pathPrefix.call(void 0, prefixPaths));
|
|
46
|
+
if (wildcardPatterns.length > 0) criteria.push(_chunk7T4G7UF7cjs.pathMatches.call(void 0, wildcardPatterns));
|
|
47
|
+
if (criteria.length === 1) return criteria[0];
|
|
48
|
+
return _chunkWKYMSRCDcjs.any.call(void 0, criteria);
|
|
49
|
+
}
|
|
50
|
+
function whitelist(options) {
|
|
51
|
+
const userAgents = _nullishCoalesce(options.userAgents, () => ( []));
|
|
52
|
+
const bypassPaths = _nullishCoalesce(options.bypassPaths, () => ( []));
|
|
53
|
+
const criteria = [_chunkWKYMSRCDcjs.not.call(void 0, _chunkMK4QBCD5cjs.ipCidr.call(void 0, options.cidrs)), _chunkWKYMSRCDcjs.not.call(void 0, _chunkWUFGMLE7cjs.userAgentMatches.call(void 0, userAgents))];
|
|
54
|
+
if (bypassPaths.length > 0) {
|
|
55
|
+
criteria.push(_chunkWKYMSRCDcjs.not.call(void 0, buildBypassCriteria(bypassPaths)));
|
|
56
|
+
}
|
|
57
|
+
return _chunkWKYMSRCDcjs.rule.call(void 0, _chunkWKYMSRCDcjs.all.call(void 0, criteria), _chunkWWSRNCUPcjs.redirect.call(void 0, 302, options.redirectUrl));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
exports.whitelist = whitelist;
|
|
@@ -9,6 +9,9 @@ function wildcardToRegex(pattern) {
|
|
|
9
9
|
return regexCache[pattern];
|
|
10
10
|
}
|
|
11
11
|
function matchesWildcard(str, pattern) {
|
|
12
|
+
if (pattern.indexOf("*") === -1 && pattern.indexOf("?") === -1) {
|
|
13
|
+
return str.toLowerCase() === pattern.toLowerCase();
|
|
14
|
+
}
|
|
12
15
|
return wildcardToRegex(pattern).test(str);
|
|
13
16
|
}
|
|
14
17
|
function matchesAnyWildcard(str, patterns) {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
pathMatches
|
|
3
|
+
} from "./chunk-I7YELJ2P.js";
|
|
4
|
+
import {
|
|
5
|
+
pathPrefix
|
|
6
|
+
} from "./chunk-XLSZ5RB7.js";
|
|
7
|
+
import {
|
|
8
|
+
userAgentMatches
|
|
9
|
+
} from "./chunk-HWJFOKZX.js";
|
|
10
|
+
import {
|
|
11
|
+
ipCidr
|
|
12
|
+
} from "./chunk-YHTUV2SA.js";
|
|
13
|
+
import {
|
|
14
|
+
pathEquals
|
|
15
|
+
} from "./chunk-UD456E4I.js";
|
|
16
|
+
import {
|
|
17
|
+
redirect
|
|
18
|
+
} from "./chunk-DSSFFJWL.js";
|
|
19
|
+
import {
|
|
20
|
+
all,
|
|
21
|
+
any,
|
|
22
|
+
not,
|
|
23
|
+
rule
|
|
24
|
+
} from "./chunk-Q4NP4C3B.js";
|
|
25
|
+
|
|
26
|
+
// src/helpers/whitelist.ts
|
|
27
|
+
function buildBypassCriteria(paths) {
|
|
28
|
+
const exactPaths = [];
|
|
29
|
+
const prefixPaths = [];
|
|
30
|
+
const wildcardPatterns = [];
|
|
31
|
+
for (let i = 0; i < paths.length; i++) {
|
|
32
|
+
const p = paths[i];
|
|
33
|
+
const hasWildcard = p.indexOf("*") !== -1 || p.indexOf("?") !== -1;
|
|
34
|
+
const isTrailingSlashStar = p.charAt(p.length - 1) === "*" && p.charAt(p.length - 2) === "/" && p.indexOf("*") === p.length - 1 && p.indexOf("?") === -1;
|
|
35
|
+
if (!hasWildcard) {
|
|
36
|
+
exactPaths.push(p);
|
|
37
|
+
} else if (isTrailingSlashStar) {
|
|
38
|
+
prefixPaths.push(p.slice(0, p.length - 1));
|
|
39
|
+
} else {
|
|
40
|
+
wildcardPatterns.push(p);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const criteria = [];
|
|
44
|
+
if (exactPaths.length > 0) criteria.push(pathEquals(exactPaths));
|
|
45
|
+
if (prefixPaths.length > 0) criteria.push(pathPrefix(prefixPaths));
|
|
46
|
+
if (wildcardPatterns.length > 0) criteria.push(pathMatches(wildcardPatterns));
|
|
47
|
+
if (criteria.length === 1) return criteria[0];
|
|
48
|
+
return any(criteria);
|
|
49
|
+
}
|
|
50
|
+
function whitelist(options) {
|
|
51
|
+
const userAgents = options.userAgents ?? [];
|
|
52
|
+
const bypassPaths = options.bypassPaths ?? [];
|
|
53
|
+
const criteria = [not(ipCidr(options.cidrs)), not(userAgentMatches(userAgents))];
|
|
54
|
+
if (bypassPaths.length > 0) {
|
|
55
|
+
criteria.push(not(buildBypassCriteria(bypassPaths)));
|
|
56
|
+
}
|
|
57
|
+
return rule(all(criteria), redirect(302, options.redirectUrl));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export {
|
|
61
|
+
whitelist
|
|
62
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkYNKZGZ7Icjs = require('./chunk-YNKZGZ7I.cjs');
|
|
4
4
|
|
|
5
5
|
// src/behaviors/set-cors-headers.ts
|
|
6
6
|
var ORIGIN_WILDCARD = "*";
|
|
@@ -15,7 +15,7 @@ function setCorsHeaders(options) {
|
|
|
15
15
|
allowOrigin = _optionalChain([request, 'access', _ => _.headers, 'access', _2 => _2["origin"], 'optionalAccess', _3 => _3.value]);
|
|
16
16
|
} else {
|
|
17
17
|
const originHeader = _optionalChain([request, 'access', _4 => _4.headers, 'access', _5 => _5["origin"], 'optionalAccess', _6 => _6.value]);
|
|
18
|
-
if (originHeader && allowedOrigins.some((p) =>
|
|
18
|
+
if (originHeader && allowedOrigins.some((p) => _chunkYNKZGZ7Icjs.matchesOriginPattern.call(void 0, originHeader, p))) {
|
|
19
19
|
allowOrigin = originHeader;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
ORIGIN_ECHO,
|
|
6
6
|
ORIGIN_WILDCARD
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-GKE3YDHR.js";
|
|
8
8
|
import {
|
|
9
9
|
matchesOriginPattern
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-NJD4L4Q3.js";
|
|
11
11
|
|
|
12
12
|
// src/helpers/preflight-request.ts
|
|
13
13
|
function preflightRequest(options) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkYNKZGZ7Icjs = require('./chunk-YNKZGZ7I.cjs');
|
|
4
4
|
|
|
5
5
|
// src/criteria/user-agent-matches.ts
|
|
6
6
|
function userAgentMatches(patterns) {
|
|
7
7
|
return (req) => {
|
|
8
8
|
const ua = _optionalChain([req, 'access', _ => _.headers, 'access', _2 => _2["user-agent"], 'optionalAccess', _3 => _3.value]);
|
|
9
9
|
if (!ua) return false;
|
|
10
|
-
return
|
|
10
|
+
return _chunkYNKZGZ7Icjs.matchesAnyWildcard.call(void 0, ua, patterns);
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -9,6 +9,9 @@ function wildcardToRegex(pattern) {
|
|
|
9
9
|
return regexCache[pattern];
|
|
10
10
|
}
|
|
11
11
|
function matchesWildcard(str, pattern) {
|
|
12
|
+
if (pattern.indexOf("*") === -1 && pattern.indexOf("?") === -1) {
|
|
13
|
+
return str.toLowerCase() === pattern.toLowerCase();
|
|
14
|
+
}
|
|
12
15
|
return wildcardToRegex(pattern).test(str);
|
|
13
16
|
}
|
|
14
17
|
function matchesAnyWildcard(str, patterns) {
|
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
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk7T4G7UF7cjs = require('../chunk-7T4G7UF7.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunkG7JGTBTTcjs = require('../chunk-G7JGTBTT.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkWUFGMLE7cjs = require('../chunk-WUFGMLE7.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunk32SMWYAFcjs = require('../chunk-32SMWYAF.cjs');
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkL7NBJ4JAcjs = require('../chunk-L7NBJ4JA.cjs');
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
var
|
|
18
|
+
var _chunkJGJW7D2Ncjs = require('../chunk-JGJW7D2N.cjs');
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
var
|
|
21
|
+
var _chunkMK4QBCD5cjs = require('../chunk-MK4QBCD5.cjs');
|
|
22
|
+
require('../chunk-WZKRNMF2.cjs');
|
|
22
23
|
|
|
23
24
|
|
|
24
|
-
var
|
|
25
|
+
var _chunkOTFDML3Kcjs = require('../chunk-OTFDML3K.cjs');
|
|
25
26
|
|
|
26
27
|
|
|
27
|
-
var
|
|
28
|
+
var _chunkVEEOQ7TScjs = require('../chunk-VEEOQ7TS.cjs');
|
|
28
29
|
|
|
29
30
|
|
|
30
|
-
var
|
|
31
|
+
var _chunkOSZWDCTScjs = require('../chunk-OSZWDCTS.cjs');
|
|
31
32
|
|
|
32
33
|
|
|
33
|
-
var
|
|
34
|
-
require('../chunk-
|
|
35
|
-
require('../chunk-ULICUDDH.cjs');
|
|
34
|
+
var _chunkU54FZCOHcjs = require('../chunk-U54FZCOH.cjs');
|
|
35
|
+
require('../chunk-YNKZGZ7I.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 = _chunkMK4QBCD5cjs.ipCidr; exports.methodIs = _chunkOTFDML3Kcjs.methodIs; exports.pathEquals = _chunkVEEOQ7TScjs.pathEquals; exports.pathMatches =
|
|
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 = _chunk7T4G7UF7cjs.pathMatches; exports.pathPrefix = _chunkG7JGTBTTcjs.pathPrefix; exports.userAgentMatches = _chunkWUFGMLE7cjs.userAgentMatches;
|
package/dist/criteria/index.js
CHANGED
|
@@ -1,24 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "../chunk-
|
|
2
|
+
pathMatches
|
|
3
|
+
} from "../chunk-I7YELJ2P.js";
|
|
4
4
|
import {
|
|
5
5
|
pathPrefix
|
|
6
6
|
} from "../chunk-XLSZ5RB7.js";
|
|
7
|
-
import {
|
|
8
|
-
pathMatches
|
|
9
|
-
} from "../chunk-Y7TIDVVC.js";
|
|
10
7
|
import {
|
|
11
8
|
userAgentMatches
|
|
12
|
-
} from "../chunk-
|
|
13
|
-
import {
|
|
14
|
-
methodIs
|
|
15
|
-
} from "../chunk-PY3JMRDG.js";
|
|
16
|
-
import {
|
|
17
|
-
countryIs
|
|
18
|
-
} from "../chunk-5CPBXZ4X.js";
|
|
19
|
-
import {
|
|
20
|
-
fileExtension
|
|
21
|
-
} from "../chunk-LBJUCJF2.js";
|
|
9
|
+
} from "../chunk-HWJFOKZX.js";
|
|
22
10
|
import {
|
|
23
11
|
headerContains
|
|
24
12
|
} from "../chunk-SRQF5UEJ.js";
|
|
@@ -32,7 +20,19 @@ import {
|
|
|
32
20
|
ipCidr
|
|
33
21
|
} from "../chunk-YHTUV2SA.js";
|
|
34
22
|
import "../chunk-NWRGD3AH.js";
|
|
35
|
-
import
|
|
23
|
+
import {
|
|
24
|
+
methodIs
|
|
25
|
+
} from "../chunk-PY3JMRDG.js";
|
|
26
|
+
import {
|
|
27
|
+
pathEquals
|
|
28
|
+
} from "../chunk-UD456E4I.js";
|
|
29
|
+
import {
|
|
30
|
+
countryIs
|
|
31
|
+
} from "../chunk-5CPBXZ4X.js";
|
|
32
|
+
import {
|
|
33
|
+
fileExtension
|
|
34
|
+
} from "../chunk-LBJUCJF2.js";
|
|
35
|
+
import "../chunk-NJD4L4Q3.js";
|
|
36
36
|
import "../chunk-MLKGABMK.js";
|
|
37
37
|
export {
|
|
38
38
|
countryIs,
|
package/dist/criteria/kvs.d.cts
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
import { CriteriaFn } from '../core/types.cjs';
|
|
2
2
|
import { KvsHandle } from '../shared/kvs.cjs';
|
|
3
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
|
+
*/
|
|
4
32
|
declare function kvsIpCidr(handle: KvsHandle, key: string): Promise<CriteriaFn>;
|
|
5
33
|
|
|
6
34
|
export { kvsIpCidr };
|
package/dist/criteria/kvs.d.ts
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
import { CriteriaFn } from '../core/types.js';
|
|
2
2
|
import { KvsHandle } from '../shared/kvs.js';
|
|
3
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
|
+
*/
|
|
4
32
|
declare function kvsIpCidr(handle: KvsHandle, key: string): Promise<CriteriaFn>;
|
|
5
33
|
|
|
6
34
|
export { kvsIpCidr };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
3
|
+
var _chunk7T4G7UF7cjs = require('../chunk-7T4G7UF7.cjs');
|
|
4
|
+
require('../chunk-YNKZGZ7I.cjs');
|
|
5
5
|
require('../chunk-75ZPJI57.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
exports.pathMatches =
|
|
8
|
+
exports.pathMatches = _chunk7T4G7UF7cjs.pathMatches;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
3
|
+
var _chunkWUFGMLE7cjs = require('../chunk-WUFGMLE7.cjs');
|
|
4
|
+
require('../chunk-YNKZGZ7I.cjs');
|
|
5
5
|
require('../chunk-75ZPJI57.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
exports.userAgentMatches =
|
|
8
|
+
exports.userAgentMatches = _chunkWUFGMLE7cjs.userAgentMatches;
|
package/dist/helpers/index.cjs
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkHMQIXEFJcjs = require('../chunk-HMQIXEFJ.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkCLGM2TGTcjs = require('../chunk-CLGM2TGT.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
var _chunkLSCC62CZcjs = require('../chunk-LSCC62CZ.cjs');
|
|
10
|
-
require('../chunk-
|
|
11
|
-
require('../chunk-
|
|
12
|
-
require('../chunk-
|
|
10
|
+
require('../chunk-7T4G7UF7.cjs');
|
|
11
|
+
require('../chunk-G7JGTBTT.cjs');
|
|
12
|
+
require('../chunk-WUFGMLE7.cjs');
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
var _chunkL7NBJ4JAcjs = require('../chunk-L7NBJ4JA.cjs');
|
|
16
16
|
require('../chunk-MK4QBCD5.cjs');
|
|
17
17
|
require('../chunk-WZKRNMF2.cjs');
|
|
18
|
-
require('../chunk-
|
|
19
|
-
require('../chunk-
|
|
18
|
+
require('../chunk-OTFDML3K.cjs');
|
|
19
|
+
require('../chunk-VEEOQ7TS.cjs');
|
|
20
|
+
require('../chunk-TJ2POKWD.cjs');
|
|
21
|
+
require('../chunk-YNKZGZ7I.cjs');
|
|
20
22
|
|
|
21
23
|
|
|
22
24
|
var _chunkB4WEJSEZcjs = require('../chunk-B4WEJSEZ.cjs');
|
|
@@ -40,4 +42,4 @@ function stagingIndicator() {
|
|
|
40
42
|
|
|
41
43
|
|
|
42
44
|
|
|
43
|
-
exports.preflightRequest =
|
|
45
|
+
exports.preflightRequest = _chunkCLGM2TGTcjs.preflightRequest; exports.sendCountryCode = _chunkLSCC62CZcjs.sendCountryCode; exports.stagingIndicator = stagingIndicator; exports.whitelist = _chunkHMQIXEFJcjs.whitelist;
|
package/dist/helpers/index.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
2
|
whitelist
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-SC6UPQYF.js";
|
|
4
4
|
import {
|
|
5
5
|
preflightRequest
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-VRSD6YHP.js";
|
|
7
7
|
import {
|
|
8
8
|
sendCountryCode
|
|
9
9
|
} from "../chunk-C32DL3EP.js";
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-
|
|
12
|
-
import "../chunk-
|
|
10
|
+
import "../chunk-I7YELJ2P.js";
|
|
11
|
+
import "../chunk-XLSZ5RB7.js";
|
|
12
|
+
import "../chunk-HWJFOKZX.js";
|
|
13
13
|
import {
|
|
14
14
|
headerEquals
|
|
15
15
|
} from "../chunk-BZQJYOU2.js";
|
|
16
16
|
import "../chunk-YHTUV2SA.js";
|
|
17
17
|
import "../chunk-NWRGD3AH.js";
|
|
18
|
-
import "../chunk-
|
|
19
|
-
import "../chunk-
|
|
18
|
+
import "../chunk-PY3JMRDG.js";
|
|
19
|
+
import "../chunk-UD456E4I.js";
|
|
20
|
+
import "../chunk-GKE3YDHR.js";
|
|
21
|
+
import "../chunk-NJD4L4Q3.js";
|
|
20
22
|
import {
|
|
21
23
|
setResponseHeader
|
|
22
24
|
} from "../chunk-RBBKFG5J.js";
|