@rayselfs/cf-rule-engine 1.6.0 → 1.6.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/README.md +10 -8
- package/dist/adapters/cf-function.cjs +7 -3
- package/dist/adapters/cf-function.d.cts +2 -1
- package/dist/adapters/cf-function.d.ts +2 -1
- package/dist/adapters/cf-function.js +7 -3
- package/dist/adapters/viewer-request.cjs +9 -0
- package/dist/adapters/viewer-request.d.cts +31 -0
- package/dist/adapters/viewer-request.d.ts +31 -0
- package/dist/adapters/viewer-request.js +9 -0
- package/dist/adapters/viewer-response.cjs +8 -0
- package/dist/adapters/viewer-response.d.cts +37 -0
- package/dist/adapters/viewer-response.d.ts +37 -0
- package/dist/adapters/viewer-response.js +8 -0
- package/dist/behaviors/index.cjs +9 -9
- package/dist/behaviors/index.js +9 -9
- package/dist/cf-function-BkfWpTfl.d.cts +10 -0
- package/dist/cf-function-CZwCWch-.d.ts +10 -0
- package/dist/chunk-5ZIB3AJ7.cjs +20 -0
- package/dist/chunk-6NFAPLQ7.cjs +39 -0
- package/dist/chunk-BJZPAQHW.js +25 -0
- package/dist/chunk-CQ7YZ3AR.js +39 -0
- package/dist/chunk-N6QAQALU.cjs +36 -0
- package/dist/chunk-PR5UQJCC.js +20 -0
- package/dist/{chunk-UKB5JAX4.js → chunk-RL7ZETZR.js} +8 -8
- package/dist/chunk-SGN2N3WI.cjs +25 -0
- package/dist/{chunk-WW7YVRAI.cjs → chunk-T5EXFHVA.cjs} +7 -7
- package/dist/chunk-TURH5IFN.js +36 -0
- package/dist/criteria/index.cjs +13 -13
- package/dist/criteria/index.js +15 -15
- package/dist/helpers/index.cjs +8 -8
- package/dist/helpers/index.d.cts +1 -1
- package/dist/helpers/index.d.ts +1 -1
- package/dist/helpers/index.js +9 -9
- package/dist/helpers/{staging-whitelist.cjs → whitelist.cjs} +4 -4
- package/dist/helpers/{staging-whitelist.d.cts → whitelist.d.cts} +11 -11
- package/dist/helpers/{staging-whitelist.d.ts → whitelist.d.ts} +11 -11
- package/dist/helpers/{staging-whitelist.js → whitelist.js} +5 -5
- package/dist/index.cjs +5 -2
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +4 -1
- package/package.json +1 -1
- package/dist/cf-function-C9eF2O9s.d.ts +0 -70
- package/dist/cf-function-DIQHy8L7.d.cts +0 -70
- package/dist/chunk-NPMGSPNL.js +0 -88
- package/dist/chunk-SAXDN5NS.cjs +0 -88
|
@@ -1,23 +1,23 @@
|
|
|
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
|
+
|
|
3
6
|
var _chunkD47P7HVZcjs = require('./chunk-D47P7HVZ.cjs');
|
|
4
7
|
|
|
5
8
|
|
|
6
9
|
var _chunkCF5PWWTFcjs = require('./chunk-CF5PWWTF.cjs');
|
|
7
10
|
|
|
8
11
|
|
|
9
|
-
var
|
|
12
|
+
var _chunkWWSRNCUPcjs = require('./chunk-WWSRNCUP.cjs');
|
|
10
13
|
|
|
11
14
|
|
|
12
15
|
|
|
13
16
|
|
|
14
17
|
var _chunkWKYMSRCDcjs = require('./chunk-WKYMSRCD.cjs');
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// src/helpers/staging-whitelist.ts
|
|
20
|
-
function stagingWhitelist(options) {
|
|
19
|
+
// src/helpers/whitelist.ts
|
|
20
|
+
function whitelist(options) {
|
|
21
21
|
const userAgents = _nullishCoalesce(options.userAgents, () => ( []));
|
|
22
22
|
const bypassPaths = _nullishCoalesce(options.bypassPaths, () => ( []));
|
|
23
23
|
const criteria = [_chunkWKYMSRCDcjs.not.call(void 0, _chunkD47P7HVZcjs.ipCidr.call(void 0, options.cidrs)), _chunkWKYMSRCDcjs.not.call(void 0, _chunkMVGYPBYBcjs.userAgentMatches.call(void 0, userAgents))];
|
|
@@ -29,4 +29,4 @@ function stagingWhitelist(options) {
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
exports.
|
|
32
|
+
exports.whitelist = whitelist;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
denormalizeResponse,
|
|
3
|
+
normalizeRequest
|
|
4
|
+
} from "./chunk-CQ7YZ3AR.js";
|
|
5
|
+
|
|
6
|
+
// src/adapters/viewer-response.ts
|
|
7
|
+
function defineViewerResponse(responseBehaviors) {
|
|
8
|
+
return (event) => {
|
|
9
|
+
const ev = event;
|
|
10
|
+
const evRes = ev.response;
|
|
11
|
+
const req = normalizeRequest(event);
|
|
12
|
+
let response = {
|
|
13
|
+
statusCode: evRes?.statusCode ?? 200,
|
|
14
|
+
statusDescription: evRes?.statusDescription,
|
|
15
|
+
headers: evRes?.headers ?? {},
|
|
16
|
+
body: evRes?.body
|
|
17
|
+
};
|
|
18
|
+
for (let i = 0; i < responseBehaviors.length; i++) {
|
|
19
|
+
const entry = responseBehaviors[i];
|
|
20
|
+
if (typeof entry === "function") {
|
|
21
|
+
response = entry(req, response);
|
|
22
|
+
} else if (!entry.criteria || entry.criteria(req)) {
|
|
23
|
+
response = entry.behavior(req, response);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const normalized = denormalizeResponse(response);
|
|
27
|
+
if (!response.body) {
|
|
28
|
+
delete normalized.body;
|
|
29
|
+
}
|
|
30
|
+
return Object.assign({}, evRes, normalized);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
defineViewerResponse
|
|
36
|
+
};
|
package/dist/criteria/index.cjs
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-YVUR35RN.cjs');
|
|
3
|
+
var _chunkG7JGTBTTcjs = require('../chunk-G7JGTBTT.cjs');
|
|
5
4
|
|
|
6
5
|
|
|
7
|
-
var
|
|
6
|
+
var _chunkMVGYPBYBcjs = require('../chunk-MVGYPBYB.cjs');
|
|
8
7
|
|
|
9
8
|
|
|
10
|
-
var
|
|
9
|
+
var _chunk32SMWYAFcjs = require('../chunk-32SMWYAF.cjs');
|
|
11
10
|
|
|
12
11
|
|
|
13
|
-
var
|
|
12
|
+
var _chunkL7NBJ4JAcjs = require('../chunk-L7NBJ4JA.cjs');
|
|
14
13
|
|
|
15
14
|
|
|
16
|
-
var
|
|
15
|
+
var _chunkJGJW7D2Ncjs = require('../chunk-JGJW7D2N.cjs');
|
|
17
16
|
|
|
18
17
|
|
|
19
|
-
var
|
|
20
|
-
require('../chunk-
|
|
18
|
+
var _chunkD47P7HVZcjs = require('../chunk-D47P7HVZ.cjs');
|
|
19
|
+
require('../chunk-YVUR35RN.cjs');
|
|
21
20
|
|
|
22
21
|
|
|
23
|
-
var
|
|
22
|
+
var _chunkOTFDML3Kcjs = require('../chunk-OTFDML3K.cjs');
|
|
24
23
|
|
|
25
24
|
|
|
26
|
-
var
|
|
25
|
+
var _chunkVEEOQ7TScjs = require('../chunk-VEEOQ7TS.cjs');
|
|
27
26
|
|
|
28
27
|
|
|
29
|
-
var
|
|
28
|
+
var _chunkCF5PWWTFcjs = require('../chunk-CF5PWWTF.cjs');
|
|
29
|
+
require('../chunk-IBXAK2A4.cjs');
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
var
|
|
32
|
+
var _chunkOSZWDCTScjs = require('../chunk-OSZWDCTS.cjs');
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
var
|
|
35
|
+
var _chunkU54FZCOHcjs = require('../chunk-U54FZCOH.cjs');
|
|
36
36
|
require('../chunk-75ZPJI57.cjs');
|
|
37
37
|
|
|
38
38
|
|
package/dist/criteria/index.js
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
pathPrefix
|
|
3
|
+
} from "../chunk-XLSZ5RB7.js";
|
|
4
|
+
import {
|
|
5
|
+
userAgentMatches
|
|
6
|
+
} from "../chunk-S2AAATFN.js";
|
|
7
|
+
import {
|
|
8
|
+
headerContains
|
|
9
|
+
} from "../chunk-SRQF5UEJ.js";
|
|
10
|
+
import {
|
|
11
|
+
headerEquals
|
|
12
|
+
} from "../chunk-BZQJYOU2.js";
|
|
13
|
+
import {
|
|
14
|
+
hostnameIs
|
|
15
|
+
} from "../chunk-3PVDUC5M.js";
|
|
1
16
|
import {
|
|
2
17
|
ipCidr
|
|
3
18
|
} from "../chunk-KW5YBTSD.js";
|
|
@@ -11,12 +26,6 @@ import {
|
|
|
11
26
|
import {
|
|
12
27
|
pathMatches
|
|
13
28
|
} from "../chunk-LO2BO3RU.js";
|
|
14
|
-
import {
|
|
15
|
-
pathPrefix
|
|
16
|
-
} from "../chunk-XLSZ5RB7.js";
|
|
17
|
-
import {
|
|
18
|
-
userAgentMatches
|
|
19
|
-
} from "../chunk-S2AAATFN.js";
|
|
20
29
|
import "../chunk-2DE6WPPL.js";
|
|
21
30
|
import {
|
|
22
31
|
countryIs
|
|
@@ -24,15 +33,6 @@ import {
|
|
|
24
33
|
import {
|
|
25
34
|
fileExtension
|
|
26
35
|
} from "../chunk-LBJUCJF2.js";
|
|
27
|
-
import {
|
|
28
|
-
headerContains
|
|
29
|
-
} from "../chunk-SRQF5UEJ.js";
|
|
30
|
-
import {
|
|
31
|
-
headerEquals
|
|
32
|
-
} from "../chunk-BZQJYOU2.js";
|
|
33
|
-
import {
|
|
34
|
-
hostnameIs
|
|
35
|
-
} from "../chunk-3PVDUC5M.js";
|
|
36
36
|
import "../chunk-MLKGABMK.js";
|
|
37
37
|
export {
|
|
38
38
|
countryIs,
|
package/dist/helpers/index.cjs
CHANGED
|
@@ -6,21 +6,21 @@ var _chunk63WIEBQBcjs = require('../chunk-63WIEBQB.cjs');
|
|
|
6
6
|
var _chunkLSCC62CZcjs = require('../chunk-LSCC62CZ.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkT5EXFHVAcjs = require('../chunk-T5EXFHVA.cjs');
|
|
10
|
+
require('../chunk-MVGYPBYB.cjs');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunkL7NBJ4JAcjs = require('../chunk-L7NBJ4JA.cjs');
|
|
10
14
|
require('../chunk-D47P7HVZ.cjs');
|
|
11
15
|
require('../chunk-YVUR35RN.cjs');
|
|
12
16
|
require('../chunk-OTFDML3K.cjs');
|
|
13
17
|
require('../chunk-CF5PWWTF.cjs');
|
|
14
|
-
require('../chunk-MVGYPBYB.cjs');
|
|
15
18
|
require('../chunk-IBXAK2A4.cjs');
|
|
16
19
|
|
|
17
20
|
|
|
18
|
-
var _chunkL7NBJ4JAcjs = require('../chunk-L7NBJ4JA.cjs');
|
|
19
|
-
require('../chunk-WKYMSRCD.cjs');
|
|
20
|
-
require('../chunk-WWSRNCUP.cjs');
|
|
21
|
-
|
|
22
|
-
|
|
23
21
|
var _chunkB4WEJSEZcjs = require('../chunk-B4WEJSEZ.cjs');
|
|
22
|
+
require('../chunk-WWSRNCUP.cjs');
|
|
23
|
+
require('../chunk-WKYMSRCD.cjs');
|
|
24
24
|
require('../chunk-JU5WX5RU.cjs');
|
|
25
25
|
require('../chunk-75ZPJI57.cjs');
|
|
26
26
|
|
|
@@ -39,4 +39,4 @@ function stagingIndicator() {
|
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
exports.preflightRequest = _chunk63WIEBQBcjs.preflightRequest; exports.sendCountryCode = _chunkLSCC62CZcjs.sendCountryCode; exports.stagingIndicator = stagingIndicator; exports.
|
|
42
|
+
exports.preflightRequest = _chunk63WIEBQBcjs.preflightRequest; exports.sendCountryCode = _chunkLSCC62CZcjs.sendCountryCode; exports.stagingIndicator = stagingIndicator; exports.whitelist = _chunkT5EXFHVAcjs.whitelist;
|
package/dist/helpers/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { sendCountryCode } from './send-country-code.cjs';
|
|
2
|
-
export {
|
|
2
|
+
export { WhitelistOptions, whitelist } from './whitelist.cjs';
|
|
3
3
|
import { ResponseRule } from '../core/types.cjs';
|
|
4
4
|
export { preflightRequest } from './preflight-request.cjs';
|
|
5
5
|
import '../behaviors/set-cors-headers.cjs';
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { sendCountryCode } from './send-country-code.js';
|
|
2
|
-
export {
|
|
2
|
+
export { WhitelistOptions, whitelist } from './whitelist.js';
|
|
3
3
|
import { ResponseRule } from '../core/types.js';
|
|
4
4
|
export { preflightRequest } from './preflight-request.js';
|
|
5
5
|
import '../behaviors/set-cors-headers.js';
|
package/dist/helpers/index.js
CHANGED
|
@@ -5,22 +5,22 @@ import {
|
|
|
5
5
|
sendCountryCode
|
|
6
6
|
} from "../chunk-C32DL3EP.js";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
} from "../chunk-
|
|
8
|
+
whitelist
|
|
9
|
+
} from "../chunk-RL7ZETZR.js";
|
|
10
|
+
import "../chunk-S2AAATFN.js";
|
|
11
|
+
import {
|
|
12
|
+
headerEquals
|
|
13
|
+
} from "../chunk-BZQJYOU2.js";
|
|
10
14
|
import "../chunk-KW5YBTSD.js";
|
|
11
15
|
import "../chunk-LNQPYKGG.js";
|
|
12
16
|
import "../chunk-PY3JMRDG.js";
|
|
13
17
|
import "../chunk-LO2BO3RU.js";
|
|
14
|
-
import "../chunk-S2AAATFN.js";
|
|
15
18
|
import "../chunk-2DE6WPPL.js";
|
|
16
|
-
import {
|
|
17
|
-
headerEquals
|
|
18
|
-
} from "../chunk-BZQJYOU2.js";
|
|
19
|
-
import "../chunk-Q4NP4C3B.js";
|
|
20
|
-
import "../chunk-DSSFFJWL.js";
|
|
21
19
|
import {
|
|
22
20
|
setResponseHeader
|
|
23
21
|
} from "../chunk-RBBKFG5J.js";
|
|
22
|
+
import "../chunk-DSSFFJWL.js";
|
|
23
|
+
import "../chunk-Q4NP4C3B.js";
|
|
24
24
|
import "../chunk-BDNPQ7AU.js";
|
|
25
25
|
import "../chunk-MLKGABMK.js";
|
|
26
26
|
|
|
@@ -38,5 +38,5 @@ export {
|
|
|
38
38
|
preflightRequest,
|
|
39
39
|
sendCountryCode,
|
|
40
40
|
stagingIndicator,
|
|
41
|
-
|
|
41
|
+
whitelist
|
|
42
42
|
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkT5EXFHVAcjs = require('../chunk-T5EXFHVA.cjs');
|
|
4
|
+
require('../chunk-MVGYPBYB.cjs');
|
|
4
5
|
require('../chunk-D47P7HVZ.cjs');
|
|
5
6
|
require('../chunk-YVUR35RN.cjs');
|
|
6
7
|
require('../chunk-CF5PWWTF.cjs');
|
|
7
|
-
require('../chunk-MVGYPBYB.cjs');
|
|
8
8
|
require('../chunk-IBXAK2A4.cjs');
|
|
9
|
-
require('../chunk-WKYMSRCD.cjs');
|
|
10
9
|
require('../chunk-WWSRNCUP.cjs');
|
|
10
|
+
require('../chunk-WKYMSRCD.cjs');
|
|
11
11
|
require('../chunk-75ZPJI57.cjs');
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
exports.
|
|
14
|
+
exports.whitelist = _chunkT5EXFHVAcjs.whitelist;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Rule } from '../core/types.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Configuration options for the
|
|
4
|
+
* Configuration options for the IP/User-Agent access whitelist.
|
|
5
5
|
*/
|
|
6
|
-
interface
|
|
6
|
+
interface 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
|
|
@@ -34,10 +34,10 @@ interface StagingWhitelistOptions {
|
|
|
34
34
|
bypassPaths?: string[];
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
|
-
* Creates a `Rule` that restricts access
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
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
41
|
*
|
|
42
42
|
* No default allowlists are included — callers must supply all allowed
|
|
43
43
|
* CIDRs and User-Agent patterns explicitly.
|
|
@@ -47,11 +47,11 @@ interface StagingWhitelistOptions {
|
|
|
47
47
|
*
|
|
48
48
|
* @example
|
|
49
49
|
* ```ts
|
|
50
|
-
* import {
|
|
50
|
+
* import { whitelist } from '@rayselfs/cf-rule-engine/helpers'
|
|
51
51
|
* import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
52
52
|
*
|
|
53
53
|
* export default defineViewerRequest([
|
|
54
|
-
*
|
|
54
|
+
* whitelist({
|
|
55
55
|
* cidrs: ['203.0.113.0/24', '10.0.0.0/8'],
|
|
56
56
|
* userAgents: ['*InternalBot*'],
|
|
57
57
|
* redirectUrl: 'https://www.example.com',
|
|
@@ -60,7 +60,7 @@ interface StagingWhitelistOptions {
|
|
|
60
60
|
*
|
|
61
61
|
* // With bypass paths:
|
|
62
62
|
* export default defineViewerRequest([
|
|
63
|
-
*
|
|
63
|
+
* whitelist({
|
|
64
64
|
* cidrs: ['203.0.113.0/24'],
|
|
65
65
|
* redirectUrl: 'https://www.example.com',
|
|
66
66
|
* bypassPaths: ['/api/health', '/robots.txt'],
|
|
@@ -68,6 +68,6 @@ interface StagingWhitelistOptions {
|
|
|
68
68
|
* ])
|
|
69
69
|
* ```
|
|
70
70
|
*/
|
|
71
|
-
declare function
|
|
71
|
+
declare function whitelist(options: WhitelistOptions): Rule;
|
|
72
72
|
|
|
73
|
-
export { type
|
|
73
|
+
export { type WhitelistOptions, whitelist };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Rule } from '../core/types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Configuration options for the
|
|
4
|
+
* Configuration options for the IP/User-Agent access whitelist.
|
|
5
5
|
*/
|
|
6
|
-
interface
|
|
6
|
+
interface 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
|
|
@@ -34,10 +34,10 @@ interface StagingWhitelistOptions {
|
|
|
34
34
|
bypassPaths?: string[];
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
|
-
* Creates a `Rule` that restricts access
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
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
41
|
*
|
|
42
42
|
* No default allowlists are included — callers must supply all allowed
|
|
43
43
|
* CIDRs and User-Agent patterns explicitly.
|
|
@@ -47,11 +47,11 @@ interface StagingWhitelistOptions {
|
|
|
47
47
|
*
|
|
48
48
|
* @example
|
|
49
49
|
* ```ts
|
|
50
|
-
* import {
|
|
50
|
+
* import { whitelist } from '@rayselfs/cf-rule-engine/helpers'
|
|
51
51
|
* import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
52
52
|
*
|
|
53
53
|
* export default defineViewerRequest([
|
|
54
|
-
*
|
|
54
|
+
* whitelist({
|
|
55
55
|
* cidrs: ['203.0.113.0/24', '10.0.0.0/8'],
|
|
56
56
|
* userAgents: ['*InternalBot*'],
|
|
57
57
|
* redirectUrl: 'https://www.example.com',
|
|
@@ -60,7 +60,7 @@ interface StagingWhitelistOptions {
|
|
|
60
60
|
*
|
|
61
61
|
* // With bypass paths:
|
|
62
62
|
* export default defineViewerRequest([
|
|
63
|
-
*
|
|
63
|
+
* whitelist({
|
|
64
64
|
* cidrs: ['203.0.113.0/24'],
|
|
65
65
|
* redirectUrl: 'https://www.example.com',
|
|
66
66
|
* bypassPaths: ['/api/health', '/robots.txt'],
|
|
@@ -68,6 +68,6 @@ interface StagingWhitelistOptions {
|
|
|
68
68
|
* ])
|
|
69
69
|
* ```
|
|
70
70
|
*/
|
|
71
|
-
declare function
|
|
71
|
+
declare function whitelist(options: WhitelistOptions): Rule;
|
|
72
72
|
|
|
73
|
-
export { type
|
|
73
|
+
export { type WhitelistOptions, whitelist };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "../chunk-
|
|
2
|
+
whitelist
|
|
3
|
+
} from "../chunk-RL7ZETZR.js";
|
|
4
|
+
import "../chunk-S2AAATFN.js";
|
|
4
5
|
import "../chunk-KW5YBTSD.js";
|
|
5
6
|
import "../chunk-LNQPYKGG.js";
|
|
6
7
|
import "../chunk-LO2BO3RU.js";
|
|
7
|
-
import "../chunk-S2AAATFN.js";
|
|
8
8
|
import "../chunk-2DE6WPPL.js";
|
|
9
|
-
import "../chunk-Q4NP4C3B.js";
|
|
10
9
|
import "../chunk-DSSFFJWL.js";
|
|
10
|
+
import "../chunk-Q4NP4C3B.js";
|
|
11
11
|
import "../chunk-MLKGABMK.js";
|
|
12
12
|
export {
|
|
13
|
-
|
|
13
|
+
whitelist
|
|
14
14
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('./chunk-MEHWLQLR.cjs');
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunk5ZIB3AJ7cjs = require('./chunk-5ZIB3AJ7.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
var _chunk3BBLG4IXcjs = require('./chunk-3BBLG4IX.cjs');
|
|
8
|
+
require('./chunk-SGN2N3WI.cjs');
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
|
|
@@ -13,6 +14,8 @@ var _chunk3BBLG4IXcjs = require('./chunk-3BBLG4IX.cjs');
|
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
var _chunkWKYMSRCDcjs = require('./chunk-WKYMSRCD.cjs');
|
|
17
|
+
require('./chunk-N6QAQALU.cjs');
|
|
18
|
+
require('./chunk-6NFAPLQ7.cjs');
|
|
16
19
|
require('./chunk-75ZPJI57.cjs');
|
|
17
20
|
|
|
18
21
|
|
|
@@ -23,4 +26,4 @@ require('./chunk-75ZPJI57.cjs');
|
|
|
23
26
|
|
|
24
27
|
|
|
25
28
|
|
|
26
|
-
exports.all = _chunkWKYMSRCDcjs.all; exports.any = _chunkWKYMSRCDcjs.any; exports.cfFunction =
|
|
29
|
+
exports.all = _chunkWKYMSRCDcjs.all; exports.any = _chunkWKYMSRCDcjs.any; exports.cfFunction = _chunk5ZIB3AJ7cjs.cf_function_exports; exports.chain = _chunkWKYMSRCDcjs.chain; exports.lambdaEdge = _chunk3BBLG4IXcjs.lambda_edge_exports; exports.not = _chunkWKYMSRCDcjs.not; exports.rule = _chunkWKYMSRCDcjs.rule; exports.runRules = _chunkWKYMSRCDcjs.runRules;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { BehaviorFn, BehaviorResult, CriteriaFn, HttpRequest, HttpResponse, ResponseBehaviorFn, ResponseRule, Rule, ViewerRequestHandler, ViewerResponseHandler } from './core/types.cjs';
|
|
2
2
|
export { all, any, chain, not, rule, runRules } from './core/rule.cjs';
|
|
3
|
-
export { c as cfFunction } from './cf-function-
|
|
3
|
+
export { c as cfFunction } from './cf-function-BkfWpTfl.cjs';
|
|
4
4
|
export { l as lambdaEdge } from './lambda-edge-9xiONGmR.cjs';
|
|
5
|
+
import './adapters/viewer-request.cjs';
|
|
6
|
+
import './adapters/viewer-response.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { BehaviorFn, BehaviorResult, CriteriaFn, HttpRequest, HttpResponse, ResponseBehaviorFn, ResponseRule, Rule, ViewerRequestHandler, ViewerResponseHandler } from './core/types.js';
|
|
2
2
|
export { all, any, chain, not, rule, runRules } from './core/rule.js';
|
|
3
|
-
export { c as cfFunction } from './cf-function-
|
|
3
|
+
export { c as cfFunction } from './cf-function-CZwCWch-.js';
|
|
4
4
|
export { l as lambdaEdge } from './lambda-edge-BK3-bFx8.js';
|
|
5
|
+
import './adapters/viewer-request.js';
|
|
6
|
+
import './adapters/viewer-response.js';
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import "./chunk-KZ72PI2A.js";
|
|
2
2
|
import {
|
|
3
3
|
cf_function_exports
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-PR5UQJCC.js";
|
|
5
5
|
import {
|
|
6
6
|
lambda_edge_exports
|
|
7
7
|
} from "./chunk-WEBU4R5C.js";
|
|
8
|
+
import "./chunk-BJZPAQHW.js";
|
|
8
9
|
import {
|
|
9
10
|
all,
|
|
10
11
|
any,
|
|
@@ -13,6 +14,8 @@ import {
|
|
|
13
14
|
rule,
|
|
14
15
|
runRules
|
|
15
16
|
} from "./chunk-Q4NP4C3B.js";
|
|
17
|
+
import "./chunk-TURH5IFN.js";
|
|
18
|
+
import "./chunk-CQ7YZ3AR.js";
|
|
16
19
|
import "./chunk-MLKGABMK.js";
|
|
17
20
|
export {
|
|
18
21
|
all,
|
package/package.json
CHANGED
|
@@ -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 };
|