@rayselfs/cf-rule-engine 1.5.0
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 +276 -0
- package/dist/adapters/cf-function.cjs +10 -0
- package/dist/adapters/cf-function.d.cts +2 -0
- package/dist/adapters/cf-function.d.ts +2 -0
- package/dist/adapters/cf-function.js +10 -0
- package/dist/adapters/lambda-edge.cjs +10 -0
- package/dist/adapters/lambda-edge.d.cts +2 -0
- package/dist/adapters/lambda-edge.d.ts +2 -0
- package/dist/adapters/lambda-edge.js +10 -0
- package/dist/behaviors/construct-response.cjs +7 -0
- package/dist/behaviors/construct-response.d.cts +62 -0
- package/dist/behaviors/construct-response.d.ts +62 -0
- package/dist/behaviors/construct-response.js +7 -0
- package/dist/behaviors/copy-header.cjs +7 -0
- package/dist/behaviors/copy-header.d.cts +27 -0
- package/dist/behaviors/copy-header.d.ts +27 -0
- package/dist/behaviors/copy-header.js +7 -0
- package/dist/behaviors/directory-index.cjs +7 -0
- package/dist/behaviors/directory-index.d.cts +33 -0
- package/dist/behaviors/directory-index.d.ts +33 -0
- package/dist/behaviors/directory-index.js +7 -0
- package/dist/behaviors/image-optimize.cjs +9 -0
- package/dist/behaviors/image-optimize.d.cts +103 -0
- package/dist/behaviors/image-optimize.d.ts +103 -0
- package/dist/behaviors/image-optimize.js +9 -0
- package/dist/behaviors/index.cjs +126 -0
- package/dist/behaviors/index.d.cts +46 -0
- package/dist/behaviors/index.d.ts +46 -0
- package/dist/behaviors/index.js +126 -0
- package/dist/behaviors/redirect.cjs +7 -0
- package/dist/behaviors/redirect.d.cts +44 -0
- package/dist/behaviors/redirect.d.ts +44 -0
- package/dist/behaviors/redirect.js +7 -0
- package/dist/behaviors/remove-response-headers.cjs +7 -0
- package/dist/behaviors/remove-response-headers.d.cts +27 -0
- package/dist/behaviors/remove-response-headers.d.ts +27 -0
- package/dist/behaviors/remove-response-headers.js +7 -0
- package/dist/behaviors/rewrite-uri.cjs +7 -0
- package/dist/behaviors/rewrite-uri.d.cts +43 -0
- package/dist/behaviors/rewrite-uri.d.ts +43 -0
- package/dist/behaviors/rewrite-uri.js +7 -0
- package/dist/behaviors/set-cache-control.cjs +7 -0
- package/dist/behaviors/set-cache-control.d.cts +29 -0
- package/dist/behaviors/set-cache-control.d.ts +29 -0
- package/dist/behaviors/set-cache-control.js +7 -0
- package/dist/behaviors/set-cors-headers.cjs +7 -0
- package/dist/behaviors/set-cors-headers.d.cts +76 -0
- package/dist/behaviors/set-cors-headers.d.ts +76 -0
- package/dist/behaviors/set-cors-headers.js +7 -0
- package/dist/behaviors/set-csp.cjs +7 -0
- package/dist/behaviors/set-csp.d.cts +48 -0
- package/dist/behaviors/set-csp.d.ts +48 -0
- package/dist/behaviors/set-csp.js +7 -0
- package/dist/behaviors/set-request-header.cjs +7 -0
- package/dist/behaviors/set-request-header.d.cts +26 -0
- package/dist/behaviors/set-request-header.d.ts +26 -0
- package/dist/behaviors/set-request-header.js +7 -0
- package/dist/behaviors/set-response-header.cjs +7 -0
- package/dist/behaviors/set-response-header.d.cts +28 -0
- package/dist/behaviors/set-response-header.d.ts +28 -0
- package/dist/behaviors/set-response-header.js +7 -0
- package/dist/behaviors/set-security-headers.cjs +7 -0
- package/dist/behaviors/set-security-headers.d.cts +55 -0
- package/dist/behaviors/set-security-headers.d.ts +55 -0
- package/dist/behaviors/set-security-headers.js +7 -0
- package/dist/behaviors/strip-query-params.cjs +7 -0
- package/dist/behaviors/strip-query-params.d.cts +25 -0
- package/dist/behaviors/strip-query-params.d.ts +25 -0
- package/dist/behaviors/strip-query-params.js +7 -0
- package/dist/cf-function-D27hUVtN.d.cts +70 -0
- package/dist/cf-function-u0PvbW_s.d.ts +70 -0
- package/dist/chunk-2DE6WPPL.js +21 -0
- package/dist/chunk-32SMWYAF.cjs +13 -0
- package/dist/chunk-3BBLG4IX.cjs +132 -0
- package/dist/chunk-3PVDUC5M.js +12 -0
- package/dist/chunk-5CPBXZ4X.js +12 -0
- package/dist/chunk-5PT5X62W.js +98 -0
- package/dist/chunk-63WIEBQB.cjs +50 -0
- package/dist/chunk-6DBZBV2M.js +42 -0
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/chunk-B4WEJSEZ.cjs +14 -0
- package/dist/chunk-BDNPQ7AU.js +21 -0
- package/dist/chunk-BUAIBB3N.js +14 -0
- package/dist/chunk-BZQJYOU2.js +12 -0
- package/dist/chunk-C32DL3EP.js +13 -0
- package/dist/chunk-CF5PWWTF.cjs +15 -0
- package/dist/chunk-CV234DQT.cjs +14 -0
- package/dist/chunk-D47P7HVZ.cjs +12 -0
- package/dist/chunk-DSSFFJWL.js +38 -0
- package/dist/chunk-FTP7NLKX.js +29 -0
- package/dist/chunk-G7JGTBTT.cjs +8 -0
- package/dist/chunk-GK5JX7OM.cjs +39 -0
- package/dist/chunk-H2LO6MQG.js +50 -0
- package/dist/chunk-IBXAK2A4.cjs +21 -0
- package/dist/chunk-JGJW7D2N.cjs +12 -0
- package/dist/chunk-JU5WX5RU.cjs +21 -0
- package/dist/chunk-KW5YBTSD.js +12 -0
- package/dist/chunk-KZ72PI2A.js +0 -0
- package/dist/chunk-L7NBJ4JA.cjs +12 -0
- package/dist/chunk-LBJUCJF2.js +14 -0
- package/dist/chunk-LNQPYKGG.js +20 -0
- package/dist/chunk-LO2BO3RU.js +15 -0
- package/dist/chunk-LSCC62CZ.cjs +13 -0
- package/dist/chunk-LTLBEBKL.cjs +42 -0
- package/dist/chunk-M5KUQBDW.js +17 -0
- package/dist/chunk-MEHWLQLR.cjs +1 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/chunk-MRPTC74I.cjs +29 -0
- package/dist/chunk-MSES76XK.cjs +14 -0
- package/dist/chunk-MVGYPBYB.cjs +16 -0
- package/dist/chunk-NPMGSPNL.js +88 -0
- package/dist/chunk-OSGZTNTS.cjs +42 -0
- package/dist/chunk-OSZWDCTS.cjs +12 -0
- package/dist/chunk-OTFDML3K.cjs +11 -0
- package/dist/chunk-PPUHEL4H.cjs +17 -0
- package/dist/chunk-PY3JMRDG.js +11 -0
- package/dist/chunk-Q4NP4C3B.js +47 -0
- package/dist/chunk-R7WXS7BI.js +42 -0
- package/dist/chunk-RBBKFG5J.js +14 -0
- package/dist/chunk-S2AAATFN.js +16 -0
- package/dist/chunk-SAXDN5NS.cjs +88 -0
- package/dist/chunk-SGEBNQR2.cjs +14 -0
- package/dist/chunk-SOBTD7AD.js +39 -0
- package/dist/chunk-SRQF5UEJ.js +13 -0
- package/dist/chunk-TQLJIT4H.cjs +98 -0
- package/dist/chunk-U54FZCOH.cjs +14 -0
- package/dist/chunk-UD456E4I.js +8 -0
- package/dist/chunk-UI6LKDJI.cjs +19 -0
- package/dist/chunk-UKB5JAX4.js +32 -0
- package/dist/chunk-VEEOQ7TS.cjs +8 -0
- package/dist/chunk-VQCRSBWL.js +19 -0
- package/dist/chunk-WEBU4R5C.js +132 -0
- package/dist/chunk-WKYMSRCD.cjs +47 -0
- package/dist/chunk-WW7YVRAI.cjs +32 -0
- package/dist/chunk-WWSRNCUP.cjs +38 -0
- package/dist/chunk-XLSZ5RB7.js +8 -0
- package/dist/chunk-XPQG5IML.js +14 -0
- package/dist/chunk-XUI4Y22M.js +20 -0
- package/dist/chunk-YVUR35RN.cjs +20 -0
- package/dist/chunk-ZTMSH34E.js +14 -0
- package/dist/chunk-ZXS23HXA.cjs +20 -0
- package/dist/core/rule.cjs +17 -0
- package/dist/core/rule.d.cts +101 -0
- package/dist/core/rule.d.ts +101 -0
- package/dist/core/rule.js +17 -0
- package/dist/core/types.cjs +1 -0
- package/dist/core/types.d.cts +53 -0
- package/dist/core/types.d.ts +53 -0
- package/dist/core/types.js +1 -0
- package/dist/criteria/country-is.cjs +7 -0
- package/dist/criteria/country-is.d.cts +35 -0
- package/dist/criteria/country-is.d.ts +35 -0
- package/dist/criteria/country-is.js +7 -0
- package/dist/criteria/file-extension.cjs +7 -0
- package/dist/criteria/file-extension.d.cts +32 -0
- package/dist/criteria/file-extension.d.ts +32 -0
- package/dist/criteria/file-extension.js +7 -0
- package/dist/criteria/header-contains.cjs +7 -0
- package/dist/criteria/header-contains.d.cts +33 -0
- package/dist/criteria/header-contains.d.ts +33 -0
- package/dist/criteria/header-contains.js +7 -0
- package/dist/criteria/header-equals.cjs +7 -0
- package/dist/criteria/header-equals.d.cts +31 -0
- package/dist/criteria/header-equals.d.ts +31 -0
- package/dist/criteria/header-equals.js +7 -0
- package/dist/criteria/hostname-is.cjs +7 -0
- package/dist/criteria/hostname-is.d.cts +22 -0
- package/dist/criteria/hostname-is.d.ts +22 -0
- package/dist/criteria/hostname-is.js +7 -0
- package/dist/criteria/index.cjs +49 -0
- package/dist/criteria/index.d.cts +12 -0
- package/dist/criteria/index.d.ts +12 -0
- package/dist/criteria/index.js +49 -0
- package/dist/criteria/ip-cidr.cjs +8 -0
- package/dist/criteria/ip-cidr.d.cts +31 -0
- package/dist/criteria/ip-cidr.d.ts +31 -0
- package/dist/criteria/ip-cidr.js +8 -0
- package/dist/criteria/method-is.cjs +7 -0
- package/dist/criteria/method-is.d.cts +29 -0
- package/dist/criteria/method-is.d.ts +29 -0
- package/dist/criteria/method-is.js +7 -0
- package/dist/criteria/path-equals.cjs +7 -0
- package/dist/criteria/path-equals.d.cts +22 -0
- package/dist/criteria/path-equals.d.ts +22 -0
- package/dist/criteria/path-equals.js +7 -0
- package/dist/criteria/path-matches.cjs +8 -0
- package/dist/criteria/path-matches.d.cts +22 -0
- package/dist/criteria/path-matches.d.ts +22 -0
- package/dist/criteria/path-matches.js +8 -0
- package/dist/criteria/path-prefix.cjs +7 -0
- package/dist/criteria/path-prefix.d.cts +21 -0
- package/dist/criteria/path-prefix.d.ts +21 -0
- package/dist/criteria/path-prefix.js +7 -0
- package/dist/criteria/user-agent-matches.cjs +8 -0
- package/dist/criteria/user-agent-matches.d.cts +32 -0
- package/dist/criteria/user-agent-matches.d.ts +32 -0
- package/dist/criteria/user-agent-matches.js +8 -0
- package/dist/helpers/index.cjs +42 -0
- package/dist/helpers/index.d.cts +34 -0
- package/dist/helpers/index.d.ts +34 -0
- package/dist/helpers/index.js +42 -0
- package/dist/helpers/preflight-request.cjs +8 -0
- package/dist/helpers/preflight-request.d.cts +38 -0
- package/dist/helpers/preflight-request.d.ts +38 -0
- package/dist/helpers/preflight-request.js +8 -0
- package/dist/helpers/send-country-code.cjs +8 -0
- package/dist/helpers/send-country-code.d.cts +35 -0
- package/dist/helpers/send-country-code.d.ts +35 -0
- package/dist/helpers/send-country-code.js +8 -0
- package/dist/helpers/staging-whitelist.cjs +14 -0
- package/dist/helpers/staging-whitelist.d.cts +73 -0
- package/dist/helpers/staging-whitelist.d.ts +73 -0
- package/dist/helpers/staging-whitelist.js +14 -0
- package/dist/index.cjs +26 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +26 -0
- package/dist/lambda-edge-D15Nf__n.d.ts +66 -0
- package/dist/lambda-edge-DxTOa2cg.d.cts +66 -0
- package/dist/shared/cidr.cjs +11 -0
- package/dist/shared/cidr.d.cts +8 -0
- package/dist/shared/cidr.d.ts +8 -0
- package/dist/shared/cidr.js +11 -0
- package/dist/shared/wildcard.cjs +11 -0
- package/dist/shared/wildcard.d.cts +8 -0
- package/dist/shared/wildcard.d.ts +8 -0
- package/dist/shared/wildcard.js +11 -0
- package/package.json +65 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the client IP address falls within any of the given CIDR ranges.
|
|
5
|
+
*
|
|
6
|
+
* Supports both IPv4 (e.g. `10.0.0.0/8`) and IPv6 (e.g. `2001:db8::/32`) CIDR notation.
|
|
7
|
+
* Uses the `CloudFront-Viewer-Address` header (stripped of port) as the source IP.
|
|
8
|
+
*
|
|
9
|
+
* Akamai equivalent: `clientIp` criterion with CIDR matching.
|
|
10
|
+
*
|
|
11
|
+
* @param cidrs - Array of CIDR range strings to match against (e.g. `['10.0.0.0/8', '172.16.0.0/12']`).
|
|
12
|
+
* @returns A `CriteriaFn` that evaluates to `true` when the client IP is within any listed CIDR.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { rule, not } from '@viverse/cf-engine'
|
|
17
|
+
* import { ipCidr } from '@viverse/cf-engine/criteria'
|
|
18
|
+
* import { redirect, constructResponse } from '@viverse/cf-engine/behaviors'
|
|
19
|
+
*
|
|
20
|
+
* // Block traffic not originating from internal networks
|
|
21
|
+
* rule(not(ipCidr(['10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16'])),
|
|
22
|
+
* redirect(302, 'https://www.viverse.com'))
|
|
23
|
+
*
|
|
24
|
+
* // Allow only specific office IPs
|
|
25
|
+
* rule(not(ipCidr(['61.218.44.76/32', '122.147.213.24/32'])),
|
|
26
|
+
* constructResponse({ statusCode: 403, body: 'Forbidden' }))
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function ipCidr(cidrs: string[]): CriteriaFn;
|
|
30
|
+
|
|
31
|
+
export { ipCidr };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the client IP address falls within any of the given CIDR ranges.
|
|
5
|
+
*
|
|
6
|
+
* Supports both IPv4 (e.g. `10.0.0.0/8`) and IPv6 (e.g. `2001:db8::/32`) CIDR notation.
|
|
7
|
+
* Uses the `CloudFront-Viewer-Address` header (stripped of port) as the source IP.
|
|
8
|
+
*
|
|
9
|
+
* Akamai equivalent: `clientIp` criterion with CIDR matching.
|
|
10
|
+
*
|
|
11
|
+
* @param cidrs - Array of CIDR range strings to match against (e.g. `['10.0.0.0/8', '172.16.0.0/12']`).
|
|
12
|
+
* @returns A `CriteriaFn` that evaluates to `true` when the client IP is within any listed CIDR.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { rule, not } from '@viverse/cf-engine'
|
|
17
|
+
* import { ipCidr } from '@viverse/cf-engine/criteria'
|
|
18
|
+
* import { redirect, constructResponse } from '@viverse/cf-engine/behaviors'
|
|
19
|
+
*
|
|
20
|
+
* // Block traffic not originating from internal networks
|
|
21
|
+
* rule(not(ipCidr(['10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16'])),
|
|
22
|
+
* redirect(302, 'https://www.viverse.com'))
|
|
23
|
+
*
|
|
24
|
+
* // Allow only specific office IPs
|
|
25
|
+
* rule(not(ipCidr(['61.218.44.76/32', '122.147.213.24/32'])),
|
|
26
|
+
* constructResponse({ statusCode: 403, body: 'Forbidden' }))
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function ipCidr(cidrs: string[]): CriteriaFn;
|
|
30
|
+
|
|
31
|
+
export { ipCidr };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the HTTP request method matches any of the given methods.
|
|
5
|
+
*
|
|
6
|
+
* Comparison is case-insensitive — `'get'`, `'GET'`, and `'Get'` all match.
|
|
7
|
+
*
|
|
8
|
+
* Akamai equivalent: `requestMethod` criterion.
|
|
9
|
+
*
|
|
10
|
+
* @param methods - Array of HTTP method strings to match against (e.g. `['GET', 'POST']`).
|
|
11
|
+
* @returns A `CriteriaFn` that evaluates to `true` when the request method matches any entry.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { rule } from '@viverse/cf-engine'
|
|
16
|
+
* import { methodIs } from '@viverse/cf-engine/criteria'
|
|
17
|
+
* import { constructResponse } from '@viverse/cf-engine/behaviors'
|
|
18
|
+
*
|
|
19
|
+
* // Respond immediately to OPTIONS preflight requests
|
|
20
|
+
* rule(methodIs(['OPTIONS']), constructResponse({ statusCode: 200, body: '' }))
|
|
21
|
+
*
|
|
22
|
+
* // Block non-GET/HEAD requests
|
|
23
|
+
* rule(methodIs(['POST', 'PUT', 'DELETE', 'PATCH']),
|
|
24
|
+
* constructResponse({ statusCode: 405, body: 'Method Not Allowed' }))
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare function methodIs(methods: string[]): CriteriaFn;
|
|
28
|
+
|
|
29
|
+
export { methodIs };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the HTTP request method matches any of the given methods.
|
|
5
|
+
*
|
|
6
|
+
* Comparison is case-insensitive — `'get'`, `'GET'`, and `'Get'` all match.
|
|
7
|
+
*
|
|
8
|
+
* Akamai equivalent: `requestMethod` criterion.
|
|
9
|
+
*
|
|
10
|
+
* @param methods - Array of HTTP method strings to match against (e.g. `['GET', 'POST']`).
|
|
11
|
+
* @returns A `CriteriaFn` that evaluates to `true` when the request method matches any entry.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { rule } from '@viverse/cf-engine'
|
|
16
|
+
* import { methodIs } from '@viverse/cf-engine/criteria'
|
|
17
|
+
* import { constructResponse } from '@viverse/cf-engine/behaviors'
|
|
18
|
+
*
|
|
19
|
+
* // Respond immediately to OPTIONS preflight requests
|
|
20
|
+
* rule(methodIs(['OPTIONS']), constructResponse({ statusCode: 200, body: '' }))
|
|
21
|
+
*
|
|
22
|
+
* // Block non-GET/HEAD requests
|
|
23
|
+
* rule(methodIs(['POST', 'PUT', 'DELETE', 'PATCH']),
|
|
24
|
+
* constructResponse({ statusCode: 405, body: 'Method Not Allowed' }))
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare function methodIs(methods: string[]): CriteriaFn;
|
|
28
|
+
|
|
29
|
+
export { methodIs };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns `true` if the request URI is an exact match for any of the given paths.
|
|
5
|
+
*
|
|
6
|
+
* Matching is case-sensitive and compares the full URI (including leading `/`).
|
|
7
|
+
* Query strings are **not** stripped before comparison — if your URI may include
|
|
8
|
+
* query params, use `pathPrefix` or `pathMatches` instead.
|
|
9
|
+
*
|
|
10
|
+
* Akamai equivalent: `path` criterion with `MATCHES_ONE_OF` match type (exact).
|
|
11
|
+
*
|
|
12
|
+
* @param paths - Array of exact URI paths to match (e.g. `['/about', '/contact']`).
|
|
13
|
+
* @returns A `CriteriaFn` to use as the first argument to `rule()`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* rule(pathEquals(['/old-about', '/legacy-contact']), redirect(301, '/about'))
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare function pathEquals(paths: string[]): CriteriaFn;
|
|
21
|
+
|
|
22
|
+
export { pathEquals };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns `true` if the request URI is an exact match for any of the given paths.
|
|
5
|
+
*
|
|
6
|
+
* Matching is case-sensitive and compares the full URI (including leading `/`).
|
|
7
|
+
* Query strings are **not** stripped before comparison — if your URI may include
|
|
8
|
+
* query params, use `pathPrefix` or `pathMatches` instead.
|
|
9
|
+
*
|
|
10
|
+
* Akamai equivalent: `path` criterion with `MATCHES_ONE_OF` match type (exact).
|
|
11
|
+
*
|
|
12
|
+
* @param paths - Array of exact URI paths to match (e.g. `['/about', '/contact']`).
|
|
13
|
+
* @returns A `CriteriaFn` to use as the first argument to `rule()`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* rule(pathEquals(['/old-about', '/legacy-contact']), redirect(301, '/about'))
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare function pathEquals(paths: string[]): CriteriaFn;
|
|
21
|
+
|
|
22
|
+
export { pathEquals };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkCF5PWWTFcjs = require('../chunk-CF5PWWTF.cjs');
|
|
4
|
+
require('../chunk-IBXAK2A4.cjs');
|
|
5
|
+
require('../chunk-75ZPJI57.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
exports.pathMatches = _chunkCF5PWWTFcjs.pathMatches;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns `true` if the request path (query string stripped) matches any of the given
|
|
5
|
+
* wildcard patterns.
|
|
6
|
+
*
|
|
7
|
+
* Wildcard syntax: `*` matches any sequence of characters; `?` matches exactly one character.
|
|
8
|
+
* Matching is case-insensitive.
|
|
9
|
+
*
|
|
10
|
+
* Akamai equivalent: `path` criterion with `MATCHES_ONE_OF` wildcard match type.
|
|
11
|
+
*
|
|
12
|
+
* @param patterns - Array of wildcard path patterns (e.g. `['/blog/*', '/posts/????-??-??-*']`).
|
|
13
|
+
* @returns A `CriteriaFn` to use as the first argument to `rule()`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* rule(pathMatches(['/blog/*', '/news/*']), setRequestHeader('x-section', 'editorial'))
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare function pathMatches(patterns: string[]): CriteriaFn;
|
|
21
|
+
|
|
22
|
+
export { pathMatches };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns `true` if the request path (query string stripped) matches any of the given
|
|
5
|
+
* wildcard patterns.
|
|
6
|
+
*
|
|
7
|
+
* Wildcard syntax: `*` matches any sequence of characters; `?` matches exactly one character.
|
|
8
|
+
* Matching is case-insensitive.
|
|
9
|
+
*
|
|
10
|
+
* Akamai equivalent: `path` criterion with `MATCHES_ONE_OF` wildcard match type.
|
|
11
|
+
*
|
|
12
|
+
* @param patterns - Array of wildcard path patterns (e.g. `['/blog/*', '/posts/????-??-??-*']`).
|
|
13
|
+
* @returns A `CriteriaFn` to use as the first argument to `rule()`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* rule(pathMatches(['/blog/*', '/news/*']), setRequestHeader('x-section', 'editorial'))
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare function pathMatches(patterns: string[]): CriteriaFn;
|
|
21
|
+
|
|
22
|
+
export { pathMatches };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns `true` if the request URI starts with any of the given prefixes.
|
|
5
|
+
*
|
|
6
|
+
* Matching is case-sensitive and applied to the full URI including the leading `/`.
|
|
7
|
+
* Commonly used to scope rules to a URL subtree (e.g. `/api/`, `/static/`).
|
|
8
|
+
*
|
|
9
|
+
* Akamai equivalent: `path` criterion with `STARTS_WITH` match type.
|
|
10
|
+
*
|
|
11
|
+
* @param prefixes - Array of URI prefixes to match (e.g. `['/api/', '/v2/']`).
|
|
12
|
+
* @returns A `CriteriaFn` to use as the first argument to `rule()`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* rule(pathPrefix(['/api/', '/v2/']), setRequestHeader('x-api', 'true'))
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare function pathPrefix(prefixes: string[]): CriteriaFn;
|
|
20
|
+
|
|
21
|
+
export { pathPrefix };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns `true` if the request URI starts with any of the given prefixes.
|
|
5
|
+
*
|
|
6
|
+
* Matching is case-sensitive and applied to the full URI including the leading `/`.
|
|
7
|
+
* Commonly used to scope rules to a URL subtree (e.g. `/api/`, `/static/`).
|
|
8
|
+
*
|
|
9
|
+
* Akamai equivalent: `path` criterion with `STARTS_WITH` match type.
|
|
10
|
+
*
|
|
11
|
+
* @param prefixes - Array of URI prefixes to match (e.g. `['/api/', '/v2/']`).
|
|
12
|
+
* @returns A `CriteriaFn` to use as the first argument to `rule()`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* rule(pathPrefix(['/api/', '/v2/']), setRequestHeader('x-api', 'true'))
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare function pathPrefix(prefixes: string[]): CriteriaFn;
|
|
20
|
+
|
|
21
|
+
export { pathPrefix };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkMVGYPBYBcjs = require('../chunk-MVGYPBYB.cjs');
|
|
4
|
+
require('../chunk-IBXAK2A4.cjs');
|
|
5
|
+
require('../chunk-75ZPJI57.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
exports.userAgentMatches = _chunkMVGYPBYBcjs.userAgentMatches;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the request `User-Agent` header matches any of the given wildcard patterns.
|
|
5
|
+
*
|
|
6
|
+
* Patterns support `*` (match any number of characters) and `?` (match a single character).
|
|
7
|
+
* The match is case-sensitive. If the `User-Agent` header is absent, the criterion returns `false`.
|
|
8
|
+
*
|
|
9
|
+
* Akamai equivalent: `userAgent` criterion with `IS_ONE_OF` and wildcard matching.
|
|
10
|
+
*
|
|
11
|
+
* @param patterns - Array of wildcard patterns to match the User-Agent string against
|
|
12
|
+
* (e.g. `['*Googlebot*', '*bingbot*']`).
|
|
13
|
+
* @returns A `CriteriaFn` that evaluates to `true` when the User-Agent matches any listed pattern.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { rule, not } from '@viverse/cf-engine'
|
|
18
|
+
* import { userAgentMatches } from '@viverse/cf-engine/criteria'
|
|
19
|
+
* import { redirect, constructResponse } from '@viverse/cf-engine/behaviors'
|
|
20
|
+
*
|
|
21
|
+
* // Block known scraper bots
|
|
22
|
+
* rule(userAgentMatches(['*SemrushBot*', '*AhrefsBot*', '*MJ12bot*']),
|
|
23
|
+
* constructResponse({ statusCode: 403, body: 'Forbidden' }))
|
|
24
|
+
*
|
|
25
|
+
* // Allow only HTC internal automation tools (stage environment)
|
|
26
|
+
* rule(not(userAgentMatches(['*HTCVRSDET*', '*Prerender*', '*HTC3PARTY*'])),
|
|
27
|
+
* redirect(302, 'https://www.viverse.com'))
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare function userAgentMatches(patterns: string[]): CriteriaFn;
|
|
31
|
+
|
|
32
|
+
export { userAgentMatches };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the request `User-Agent` header matches any of the given wildcard patterns.
|
|
5
|
+
*
|
|
6
|
+
* Patterns support `*` (match any number of characters) and `?` (match a single character).
|
|
7
|
+
* The match is case-sensitive. If the `User-Agent` header is absent, the criterion returns `false`.
|
|
8
|
+
*
|
|
9
|
+
* Akamai equivalent: `userAgent` criterion with `IS_ONE_OF` and wildcard matching.
|
|
10
|
+
*
|
|
11
|
+
* @param patterns - Array of wildcard patterns to match the User-Agent string against
|
|
12
|
+
* (e.g. `['*Googlebot*', '*bingbot*']`).
|
|
13
|
+
* @returns A `CriteriaFn` that evaluates to `true` when the User-Agent matches any listed pattern.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { rule, not } from '@viverse/cf-engine'
|
|
18
|
+
* import { userAgentMatches } from '@viverse/cf-engine/criteria'
|
|
19
|
+
* import { redirect, constructResponse } from '@viverse/cf-engine/behaviors'
|
|
20
|
+
*
|
|
21
|
+
* // Block known scraper bots
|
|
22
|
+
* rule(userAgentMatches(['*SemrushBot*', '*AhrefsBot*', '*MJ12bot*']),
|
|
23
|
+
* constructResponse({ statusCode: 403, body: 'Forbidden' }))
|
|
24
|
+
*
|
|
25
|
+
* // Allow only HTC internal automation tools (stage environment)
|
|
26
|
+
* rule(not(userAgentMatches(['*HTCVRSDET*', '*Prerender*', '*HTC3PARTY*'])),
|
|
27
|
+
* redirect(302, 'https://www.viverse.com'))
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare function userAgentMatches(patterns: string[]): CriteriaFn;
|
|
31
|
+
|
|
32
|
+
export { userAgentMatches };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk63WIEBQBcjs = require('../chunk-63WIEBQB.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkLSCC62CZcjs = require('../chunk-LSCC62CZ.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkWW7YVRAIcjs = require('../chunk-WW7YVRAI.cjs');
|
|
10
|
+
require('../chunk-D47P7HVZ.cjs');
|
|
11
|
+
require('../chunk-YVUR35RN.cjs');
|
|
12
|
+
require('../chunk-OTFDML3K.cjs');
|
|
13
|
+
require('../chunk-CF5PWWTF.cjs');
|
|
14
|
+
require('../chunk-MVGYPBYB.cjs');
|
|
15
|
+
require('../chunk-IBXAK2A4.cjs');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var _chunkL7NBJ4JAcjs = require('../chunk-L7NBJ4JA.cjs');
|
|
19
|
+
require('../chunk-WKYMSRCD.cjs');
|
|
20
|
+
require('../chunk-WWSRNCUP.cjs');
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
var _chunkB4WEJSEZcjs = require('../chunk-B4WEJSEZ.cjs');
|
|
24
|
+
require('../chunk-JU5WX5RU.cjs');
|
|
25
|
+
require('../chunk-75ZPJI57.cjs');
|
|
26
|
+
|
|
27
|
+
// src/helpers/staging-indicator.ts
|
|
28
|
+
var STAGING_REQUEST_HEADER = "aws-cf-cd-staging";
|
|
29
|
+
var STAGING_RESPONSE_HEADER = "x-cf-distribution";
|
|
30
|
+
var STAGING_RESPONSE_VALUE = "staging";
|
|
31
|
+
function stagingIndicator() {
|
|
32
|
+
return {
|
|
33
|
+
criteria: _chunkL7NBJ4JAcjs.headerEquals.call(void 0, STAGING_REQUEST_HEADER, ["true"]),
|
|
34
|
+
behavior: _chunkB4WEJSEZcjs.setResponseHeader.call(void 0, STAGING_RESPONSE_HEADER, STAGING_RESPONSE_VALUE)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
exports.preflightRequest = _chunk63WIEBQBcjs.preflightRequest; exports.sendCountryCode = _chunkLSCC62CZcjs.sendCountryCode; exports.stagingIndicator = stagingIndicator; exports.stagingWhitelist = _chunkWW7YVRAIcjs.stagingWhitelist;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export { sendCountryCode } from './send-country-code.cjs';
|
|
2
|
+
export { StagingWhitelistOptions, stagingWhitelist } from './staging-whitelist.cjs';
|
|
3
|
+
import { ResponseRule } from '../core/types.cjs';
|
|
4
|
+
export { preflightRequest } from './preflight-request.cjs';
|
|
5
|
+
import '../behaviors/set-cors-headers.cjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns a `ResponseRule` that adds `x-cf-distribution: staging` to the response
|
|
9
|
+
* when the request carries the `aws-cf-cd-staging: true` header.
|
|
10
|
+
*
|
|
11
|
+
* This allows clients (DevTools, curl) to confirm they are hitting a staging
|
|
12
|
+
* CloudFront distribution without modifying origin behaviour.
|
|
13
|
+
*
|
|
14
|
+
* **Usage**: Add to `defineViewerResponse` in any `viewer-response` config that is
|
|
15
|
+
* shared between the primary and staging distributions. Requests to the primary
|
|
16
|
+
* distribution do not carry `aws-cf-cd-staging`, so the rule is a no-op there.
|
|
17
|
+
*
|
|
18
|
+
* @returns A `ResponseRule` ready to pass into `defineViewerResponse`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { setCorsHeaders } from '@viverse/cf-engine/behaviors'
|
|
23
|
+
* import { stagingIndicator } from '@viverse/cf-engine/helpers'
|
|
24
|
+
* import { defineViewerResponse } from '@viverse/cf-engine/adapters/cf-function'
|
|
25
|
+
*
|
|
26
|
+
* export default defineViewerResponse([
|
|
27
|
+
* setCorsHeaders({ allowedOrigins: ['https://www.viverse.com'] }),
|
|
28
|
+
* stagingIndicator(),
|
|
29
|
+
* ])
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare function stagingIndicator(): ResponseRule;
|
|
33
|
+
|
|
34
|
+
export { stagingIndicator };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export { sendCountryCode } from './send-country-code.js';
|
|
2
|
+
export { StagingWhitelistOptions, stagingWhitelist } from './staging-whitelist.js';
|
|
3
|
+
import { ResponseRule } from '../core/types.js';
|
|
4
|
+
export { preflightRequest } from './preflight-request.js';
|
|
5
|
+
import '../behaviors/set-cors-headers.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns a `ResponseRule` that adds `x-cf-distribution: staging` to the response
|
|
9
|
+
* when the request carries the `aws-cf-cd-staging: true` header.
|
|
10
|
+
*
|
|
11
|
+
* This allows clients (DevTools, curl) to confirm they are hitting a staging
|
|
12
|
+
* CloudFront distribution without modifying origin behaviour.
|
|
13
|
+
*
|
|
14
|
+
* **Usage**: Add to `defineViewerResponse` in any `viewer-response` config that is
|
|
15
|
+
* shared between the primary and staging distributions. Requests to the primary
|
|
16
|
+
* distribution do not carry `aws-cf-cd-staging`, so the rule is a no-op there.
|
|
17
|
+
*
|
|
18
|
+
* @returns A `ResponseRule` ready to pass into `defineViewerResponse`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { setCorsHeaders } from '@viverse/cf-engine/behaviors'
|
|
23
|
+
* import { stagingIndicator } from '@viverse/cf-engine/helpers'
|
|
24
|
+
* import { defineViewerResponse } from '@viverse/cf-engine/adapters/cf-function'
|
|
25
|
+
*
|
|
26
|
+
* export default defineViewerResponse([
|
|
27
|
+
* setCorsHeaders({ allowedOrigins: ['https://www.viverse.com'] }),
|
|
28
|
+
* stagingIndicator(),
|
|
29
|
+
* ])
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare function stagingIndicator(): ResponseRule;
|
|
33
|
+
|
|
34
|
+
export { stagingIndicator };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
preflightRequest
|
|
3
|
+
} from "../chunk-H2LO6MQG.js";
|
|
4
|
+
import {
|
|
5
|
+
sendCountryCode
|
|
6
|
+
} from "../chunk-C32DL3EP.js";
|
|
7
|
+
import {
|
|
8
|
+
stagingWhitelist
|
|
9
|
+
} from "../chunk-UKB5JAX4.js";
|
|
10
|
+
import "../chunk-KW5YBTSD.js";
|
|
11
|
+
import "../chunk-LNQPYKGG.js";
|
|
12
|
+
import "../chunk-PY3JMRDG.js";
|
|
13
|
+
import "../chunk-LO2BO3RU.js";
|
|
14
|
+
import "../chunk-S2AAATFN.js";
|
|
15
|
+
import "../chunk-2DE6WPPL.js";
|
|
16
|
+
import {
|
|
17
|
+
headerEquals
|
|
18
|
+
} from "../chunk-BZQJYOU2.js";
|
|
19
|
+
import "../chunk-Q4NP4C3B.js";
|
|
20
|
+
import "../chunk-DSSFFJWL.js";
|
|
21
|
+
import {
|
|
22
|
+
setResponseHeader
|
|
23
|
+
} from "../chunk-RBBKFG5J.js";
|
|
24
|
+
import "../chunk-BDNPQ7AU.js";
|
|
25
|
+
import "../chunk-MLKGABMK.js";
|
|
26
|
+
|
|
27
|
+
// src/helpers/staging-indicator.ts
|
|
28
|
+
var STAGING_REQUEST_HEADER = "aws-cf-cd-staging";
|
|
29
|
+
var STAGING_RESPONSE_HEADER = "x-cf-distribution";
|
|
30
|
+
var STAGING_RESPONSE_VALUE = "staging";
|
|
31
|
+
function stagingIndicator() {
|
|
32
|
+
return {
|
|
33
|
+
criteria: headerEquals(STAGING_REQUEST_HEADER, ["true"]),
|
|
34
|
+
behavior: setResponseHeader(STAGING_RESPONSE_HEADER, STAGING_RESPONSE_VALUE)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
preflightRequest,
|
|
39
|
+
sendCountryCode,
|
|
40
|
+
stagingIndicator,
|
|
41
|
+
stagingWhitelist
|
|
42
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk63WIEBQBcjs = require('../chunk-63WIEBQB.cjs');
|
|
4
|
+
require('../chunk-OTFDML3K.cjs');
|
|
5
|
+
require('../chunk-75ZPJI57.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
exports.preflightRequest = _chunk63WIEBQBcjs.preflightRequest;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Rule } from '../core/types.cjs';
|
|
2
|
+
import { CorsOptions } from '../behaviors/set-cors-headers.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns a `Rule` that responds 204 to OPTIONS preflight requests with CORS headers.
|
|
6
|
+
*
|
|
7
|
+
* Accepts the same `CorsOptions` as `setCorsHeaders` — pass the same object to both
|
|
8
|
+
* to define CORS config in one place.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { preflightRequest } from '@viverse/cf-engine/helpers'
|
|
13
|
+
* import { setCorsHeaders } from '@viverse/cf-engine/behaviors'
|
|
14
|
+
* import { defineViewerRequest, defineViewerResponse } from '@viverse/cf-engine/adapters/cf-function'
|
|
15
|
+
* import type { CorsOptions } from '@viverse/cf-engine/behaviors'
|
|
16
|
+
*
|
|
17
|
+
* const CORS: CorsOptions = {
|
|
18
|
+
* allowedOrigins: ['*'],
|
|
19
|
+
* allowedMethods: 'GET, POST, OPTIONS',
|
|
20
|
+
* allowedHeaders: 'Content-Type, Cache-Control, Pragma, Range',
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* // viewer-request.ts
|
|
24
|
+
* export default defineViewerRequest([
|
|
25
|
+
* preflightRequest(CORS),
|
|
26
|
+
* ])
|
|
27
|
+
*
|
|
28
|
+
* // viewer-response.ts
|
|
29
|
+
* export default defineViewerResponse([
|
|
30
|
+
* setCorsHeaders(CORS),
|
|
31
|
+
* ])
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @returns A `Rule` ready to pass into `defineViewerRequest`.
|
|
35
|
+
*/
|
|
36
|
+
declare function preflightRequest(options?: CorsOptions): Rule;
|
|
37
|
+
|
|
38
|
+
export { preflightRequest };
|