@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,53 @@
|
|
|
1
|
+
/** Represents an HTTP request with URI, method, headers, and querystring. */
|
|
2
|
+
interface HttpRequest {
|
|
3
|
+
uri: string;
|
|
4
|
+
method: string;
|
|
5
|
+
protocol: string;
|
|
6
|
+
querystring: Record<string, {
|
|
7
|
+
value: string;
|
|
8
|
+
}>;
|
|
9
|
+
headers: Record<string, {
|
|
10
|
+
value: string;
|
|
11
|
+
}>;
|
|
12
|
+
clientIp: string;
|
|
13
|
+
country?: string;
|
|
14
|
+
}
|
|
15
|
+
/** Represents an HTTP response with status code and headers. */
|
|
16
|
+
interface HttpResponse {
|
|
17
|
+
statusCode: number;
|
|
18
|
+
statusDescription?: string;
|
|
19
|
+
headers: Record<string, {
|
|
20
|
+
value: string;
|
|
21
|
+
}>;
|
|
22
|
+
body?: string;
|
|
23
|
+
}
|
|
24
|
+
/** A function that evaluates criteria against a request and returns a boolean. */
|
|
25
|
+
type CriteriaFn = (request: HttpRequest) => boolean;
|
|
26
|
+
/** Result of a behavior function: either continue processing or respond. */
|
|
27
|
+
type BehaviorResult = {
|
|
28
|
+
action: 'continue';
|
|
29
|
+
request: HttpRequest;
|
|
30
|
+
} | {
|
|
31
|
+
action: 'respond';
|
|
32
|
+
response: HttpResponse;
|
|
33
|
+
};
|
|
34
|
+
/** A function that modifies a request and returns a BehaviorResult. */
|
|
35
|
+
type BehaviorFn = (request: HttpRequest) => BehaviorResult;
|
|
36
|
+
/** A function that modifies an HTTP response. */
|
|
37
|
+
type ResponseBehaviorFn = (request: HttpRequest, response: HttpResponse) => HttpResponse;
|
|
38
|
+
/** A response rule: an optional criteria guard plus a ResponseBehaviorFn. */
|
|
39
|
+
interface ResponseRule {
|
|
40
|
+
criteria?: CriteriaFn;
|
|
41
|
+
behavior: ResponseBehaviorFn;
|
|
42
|
+
}
|
|
43
|
+
/** A rule combining optional criteria and a behavior function. */
|
|
44
|
+
interface Rule {
|
|
45
|
+
criteria?: CriteriaFn;
|
|
46
|
+
behavior: BehaviorFn;
|
|
47
|
+
}
|
|
48
|
+
/** Handler for CloudFront viewer request events. */
|
|
49
|
+
type ViewerRequestHandler = (event: unknown) => unknown;
|
|
50
|
+
/** Handler for CloudFront viewer response events. */
|
|
51
|
+
type ViewerResponseHandler = (event: unknown) => unknown;
|
|
52
|
+
|
|
53
|
+
export type { BehaviorFn, BehaviorResult, CriteriaFn, HttpRequest, HttpResponse, ResponseBehaviorFn, ResponseRule, Rule, ViewerRequestHandler, ViewerResponseHandler };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Represents an HTTP request with URI, method, headers, and querystring. */
|
|
2
|
+
interface HttpRequest {
|
|
3
|
+
uri: string;
|
|
4
|
+
method: string;
|
|
5
|
+
protocol: string;
|
|
6
|
+
querystring: Record<string, {
|
|
7
|
+
value: string;
|
|
8
|
+
}>;
|
|
9
|
+
headers: Record<string, {
|
|
10
|
+
value: string;
|
|
11
|
+
}>;
|
|
12
|
+
clientIp: string;
|
|
13
|
+
country?: string;
|
|
14
|
+
}
|
|
15
|
+
/** Represents an HTTP response with status code and headers. */
|
|
16
|
+
interface HttpResponse {
|
|
17
|
+
statusCode: number;
|
|
18
|
+
statusDescription?: string;
|
|
19
|
+
headers: Record<string, {
|
|
20
|
+
value: string;
|
|
21
|
+
}>;
|
|
22
|
+
body?: string;
|
|
23
|
+
}
|
|
24
|
+
/** A function that evaluates criteria against a request and returns a boolean. */
|
|
25
|
+
type CriteriaFn = (request: HttpRequest) => boolean;
|
|
26
|
+
/** Result of a behavior function: either continue processing or respond. */
|
|
27
|
+
type BehaviorResult = {
|
|
28
|
+
action: 'continue';
|
|
29
|
+
request: HttpRequest;
|
|
30
|
+
} | {
|
|
31
|
+
action: 'respond';
|
|
32
|
+
response: HttpResponse;
|
|
33
|
+
};
|
|
34
|
+
/** A function that modifies a request and returns a BehaviorResult. */
|
|
35
|
+
type BehaviorFn = (request: HttpRequest) => BehaviorResult;
|
|
36
|
+
/** A function that modifies an HTTP response. */
|
|
37
|
+
type ResponseBehaviorFn = (request: HttpRequest, response: HttpResponse) => HttpResponse;
|
|
38
|
+
/** A response rule: an optional criteria guard plus a ResponseBehaviorFn. */
|
|
39
|
+
interface ResponseRule {
|
|
40
|
+
criteria?: CriteriaFn;
|
|
41
|
+
behavior: ResponseBehaviorFn;
|
|
42
|
+
}
|
|
43
|
+
/** A rule combining optional criteria and a behavior function. */
|
|
44
|
+
interface Rule {
|
|
45
|
+
criteria?: CriteriaFn;
|
|
46
|
+
behavior: BehaviorFn;
|
|
47
|
+
}
|
|
48
|
+
/** Handler for CloudFront viewer request events. */
|
|
49
|
+
type ViewerRequestHandler = (event: unknown) => unknown;
|
|
50
|
+
/** Handler for CloudFront viewer response events. */
|
|
51
|
+
type ViewerResponseHandler = (event: unknown) => unknown;
|
|
52
|
+
|
|
53
|
+
export type { BehaviorFn, BehaviorResult, CriteriaFn, HttpRequest, HttpResponse, ResponseBehaviorFn, ResponseRule, Rule, ViewerRequestHandler, ViewerResponseHandler };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../chunk-KZ72PI2A.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the viewer's country matches any of the given ISO 3166-1 alpha-2 country codes.
|
|
5
|
+
*
|
|
6
|
+
* Reads the `CloudFront-Viewer-Country` request header, which CloudFront populates based on
|
|
7
|
+
* the viewer's IP geolocation. Comparison is case-insensitive — `'tw'` and `'TW'` both match.
|
|
8
|
+
* If the header is absent (e.g. in local testing), the criterion returns `false`.
|
|
9
|
+
*
|
|
10
|
+
* **Prerequisite**: The CloudFront cache behavior must be configured to forward the
|
|
11
|
+
* `CloudFront-Viewer-Country` header to the function. In Terraform, add it to the
|
|
12
|
+
* `headers_config` in the associated cache policy or origin request policy.
|
|
13
|
+
*
|
|
14
|
+
* Akamai equivalent: `userLocation` criterion with `COUNTRY` field and `IS_ONE_OF` match type.
|
|
15
|
+
*
|
|
16
|
+
* @param codes - Array of ISO 3166-1 alpha-2 country codes (e.g. `['TW', 'US', 'JP']`).
|
|
17
|
+
* @returns A `CriteriaFn` that evaluates to `true` when the viewer country matches any listed code.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { rule } from '@viverse/cf-engine'
|
|
22
|
+
* import { countryIs } from '@viverse/cf-engine/criteria'
|
|
23
|
+
* import { redirect } from '@viverse/cf-engine/behaviors'
|
|
24
|
+
*
|
|
25
|
+
* // Redirect mainland China traffic to the CN domain
|
|
26
|
+
* rule(countryIs(['CN']), redirect(302, 'https://www.viverse.cn'))
|
|
27
|
+
*
|
|
28
|
+
* // Serve region-specific content for APAC countries
|
|
29
|
+
* rule(countryIs(['TW', 'JP', 'KR', 'SG', 'HK']),
|
|
30
|
+
* redirect(302, 'https://www.viverse.com/apac'))
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function countryIs(codes: string[]): CriteriaFn;
|
|
34
|
+
|
|
35
|
+
export { countryIs };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the viewer's country matches any of the given ISO 3166-1 alpha-2 country codes.
|
|
5
|
+
*
|
|
6
|
+
* Reads the `CloudFront-Viewer-Country` request header, which CloudFront populates based on
|
|
7
|
+
* the viewer's IP geolocation. Comparison is case-insensitive — `'tw'` and `'TW'` both match.
|
|
8
|
+
* If the header is absent (e.g. in local testing), the criterion returns `false`.
|
|
9
|
+
*
|
|
10
|
+
* **Prerequisite**: The CloudFront cache behavior must be configured to forward the
|
|
11
|
+
* `CloudFront-Viewer-Country` header to the function. In Terraform, add it to the
|
|
12
|
+
* `headers_config` in the associated cache policy or origin request policy.
|
|
13
|
+
*
|
|
14
|
+
* Akamai equivalent: `userLocation` criterion with `COUNTRY` field and `IS_ONE_OF` match type.
|
|
15
|
+
*
|
|
16
|
+
* @param codes - Array of ISO 3166-1 alpha-2 country codes (e.g. `['TW', 'US', 'JP']`).
|
|
17
|
+
* @returns A `CriteriaFn` that evaluates to `true` when the viewer country matches any listed code.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { rule } from '@viverse/cf-engine'
|
|
22
|
+
* import { countryIs } from '@viverse/cf-engine/criteria'
|
|
23
|
+
* import { redirect } from '@viverse/cf-engine/behaviors'
|
|
24
|
+
*
|
|
25
|
+
* // Redirect mainland China traffic to the CN domain
|
|
26
|
+
* rule(countryIs(['CN']), redirect(302, 'https://www.viverse.cn'))
|
|
27
|
+
*
|
|
28
|
+
* // Serve region-specific content for APAC countries
|
|
29
|
+
* rule(countryIs(['TW', 'JP', 'KR', 'SG', 'HK']),
|
|
30
|
+
* redirect(302, 'https://www.viverse.com/apac'))
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function countryIs(codes: string[]): CriteriaFn;
|
|
34
|
+
|
|
35
|
+
export { countryIs };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the request URI's file extension matches any of the given extensions.
|
|
5
|
+
*
|
|
6
|
+
* The extension is extracted from the path portion of the URI (query string is stripped
|
|
7
|
+
* before matching). Comparison is case-insensitive — `'jpg'` matches `.JPG`, `.jpg`, etc.
|
|
8
|
+
* If the URI has no extension (no `.` in the final path segment), the criterion returns `false`.
|
|
9
|
+
*
|
|
10
|
+
* Akamai equivalent: `fileExtension` criterion.
|
|
11
|
+
*
|
|
12
|
+
* @param extensions - Array of file extensions to match, without leading dot (e.g. `['jpg', 'png', 'gif']`).
|
|
13
|
+
* @returns A `CriteriaFn` that evaluates to `true` when the URI's extension matches any entry.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { rule } from '@viverse/cf-engine'
|
|
18
|
+
* import { fileExtension } from '@viverse/cf-engine/criteria'
|
|
19
|
+
* import { setCacheControl, imageOptimize } from '@viverse/cf-engine/behaviors'
|
|
20
|
+
*
|
|
21
|
+
* // Apply long-lived cache to static assets
|
|
22
|
+
* rule(fileExtension(['js', 'css', 'woff2', 'woff']),
|
|
23
|
+
* setCacheControl({ maxAge: 31536000 }))
|
|
24
|
+
*
|
|
25
|
+
* // Apply image optimization for image requests
|
|
26
|
+
* rule(fileExtension(['jpg', 'jpeg', 'png', 'gif', 'webp']),
|
|
27
|
+
* imageOptimize())
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare function fileExtension(extensions: string[]): CriteriaFn;
|
|
31
|
+
|
|
32
|
+
export { fileExtension };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the request URI's file extension matches any of the given extensions.
|
|
5
|
+
*
|
|
6
|
+
* The extension is extracted from the path portion of the URI (query string is stripped
|
|
7
|
+
* before matching). Comparison is case-insensitive — `'jpg'` matches `.JPG`, `.jpg`, etc.
|
|
8
|
+
* If the URI has no extension (no `.` in the final path segment), the criterion returns `false`.
|
|
9
|
+
*
|
|
10
|
+
* Akamai equivalent: `fileExtension` criterion.
|
|
11
|
+
*
|
|
12
|
+
* @param extensions - Array of file extensions to match, without leading dot (e.g. `['jpg', 'png', 'gif']`).
|
|
13
|
+
* @returns A `CriteriaFn` that evaluates to `true` when the URI's extension matches any entry.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { rule } from '@viverse/cf-engine'
|
|
18
|
+
* import { fileExtension } from '@viverse/cf-engine/criteria'
|
|
19
|
+
* import { setCacheControl, imageOptimize } from '@viverse/cf-engine/behaviors'
|
|
20
|
+
*
|
|
21
|
+
* // Apply long-lived cache to static assets
|
|
22
|
+
* rule(fileExtension(['js', 'css', 'woff2', 'woff']),
|
|
23
|
+
* setCacheControl({ maxAge: 31536000 }))
|
|
24
|
+
*
|
|
25
|
+
* // Apply image optimization for image requests
|
|
26
|
+
* rule(fileExtension(['jpg', 'jpeg', 'png', 'gif', 'webp']),
|
|
27
|
+
* imageOptimize())
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare function fileExtension(extensions: string[]): CriteriaFn;
|
|
31
|
+
|
|
32
|
+
export { fileExtension };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the named request header is present and its value contains
|
|
5
|
+
* any of the given substrings.
|
|
6
|
+
*
|
|
7
|
+
* Both the header name lookup and substring search are case-insensitive.
|
|
8
|
+
* If the header is absent from the request, the criterion returns `false`.
|
|
9
|
+
*
|
|
10
|
+
* Akamai equivalent: `requestHeader` criterion with `CONTAINS` match type.
|
|
11
|
+
*
|
|
12
|
+
* @param headerName - The HTTP request header name to inspect (e.g. `'user-agent'`, `'accept'`).
|
|
13
|
+
* @param substrings - Array of substrings to search for within the header value.
|
|
14
|
+
* @returns A `CriteriaFn` that evaluates to `true` when the header value contains any listed substring.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { rule } from '@viverse/cf-engine'
|
|
19
|
+
* import { headerContains } from '@viverse/cf-engine/criteria'
|
|
20
|
+
* import { redirect } from '@viverse/cf-engine/behaviors'
|
|
21
|
+
*
|
|
22
|
+
* // Redirect requests that accept WebP to an optimized image path
|
|
23
|
+
* rule(headerContains('accept', ['image/webp']),
|
|
24
|
+
* redirect(302, '/images/optimized'))
|
|
25
|
+
*
|
|
26
|
+
* // Match requests from mobile browsers
|
|
27
|
+
* rule(headerContains('user-agent', ['Mobile', 'Android', 'iPhone']),
|
|
28
|
+
* redirect(302, 'https://m.viverse.com'))
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
declare function headerContains(headerName: string, substrings: string[]): CriteriaFn;
|
|
32
|
+
|
|
33
|
+
export { headerContains };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the named request header is present and its value contains
|
|
5
|
+
* any of the given substrings.
|
|
6
|
+
*
|
|
7
|
+
* Both the header name lookup and substring search are case-insensitive.
|
|
8
|
+
* If the header is absent from the request, the criterion returns `false`.
|
|
9
|
+
*
|
|
10
|
+
* Akamai equivalent: `requestHeader` criterion with `CONTAINS` match type.
|
|
11
|
+
*
|
|
12
|
+
* @param headerName - The HTTP request header name to inspect (e.g. `'user-agent'`, `'accept'`).
|
|
13
|
+
* @param substrings - Array of substrings to search for within the header value.
|
|
14
|
+
* @returns A `CriteriaFn` that evaluates to `true` when the header value contains any listed substring.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { rule } from '@viverse/cf-engine'
|
|
19
|
+
* import { headerContains } from '@viverse/cf-engine/criteria'
|
|
20
|
+
* import { redirect } from '@viverse/cf-engine/behaviors'
|
|
21
|
+
*
|
|
22
|
+
* // Redirect requests that accept WebP to an optimized image path
|
|
23
|
+
* rule(headerContains('accept', ['image/webp']),
|
|
24
|
+
* redirect(302, '/images/optimized'))
|
|
25
|
+
*
|
|
26
|
+
* // Match requests from mobile browsers
|
|
27
|
+
* rule(headerContains('user-agent', ['Mobile', 'Android', 'iPhone']),
|
|
28
|
+
* redirect(302, 'https://m.viverse.com'))
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
declare function headerContains(headerName: string, substrings: string[]): CriteriaFn;
|
|
32
|
+
|
|
33
|
+
export { headerContains };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the named request header is present and its value exactly matches
|
|
5
|
+
* any of the given strings.
|
|
6
|
+
*
|
|
7
|
+
* Both the header name lookup and value comparison are case-insensitive.
|
|
8
|
+
* If the header is absent from the request, the criterion returns `false`.
|
|
9
|
+
*
|
|
10
|
+
* Akamai equivalent: `requestHeader` criterion with `IS_ONE_OF` match type.
|
|
11
|
+
*
|
|
12
|
+
* @param headerName - The HTTP request header name to inspect (e.g. `'origin'`, `'x-forwarded-for'`).
|
|
13
|
+
* @param values - Array of exact strings the header value must equal (e.g. `['https://example.com']`).
|
|
14
|
+
* @returns A `CriteriaFn` that evaluates to `true` when the header value matches any entry.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { rule } from '@viverse/cf-engine'
|
|
19
|
+
* import { headerEquals } from '@viverse/cf-engine/criteria'
|
|
20
|
+
* import { setCorsHeaders } from '@viverse/cf-engine/behaviors'
|
|
21
|
+
*
|
|
22
|
+
* // Apply CORS headers only for requests from known origins
|
|
23
|
+
* rule(
|
|
24
|
+
* headerEquals('origin', ['https://www.viverse.com', 'https://store.viverse.com']),
|
|
25
|
+
* setCorsHeaders({ allowOriginEcho: true, allowCredentials: true }),
|
|
26
|
+
* )
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function headerEquals(headerName: string, values: string[]): CriteriaFn;
|
|
30
|
+
|
|
31
|
+
export { headerEquals };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the named request header is present and its value exactly matches
|
|
5
|
+
* any of the given strings.
|
|
6
|
+
*
|
|
7
|
+
* Both the header name lookup and value comparison are case-insensitive.
|
|
8
|
+
* If the header is absent from the request, the criterion returns `false`.
|
|
9
|
+
*
|
|
10
|
+
* Akamai equivalent: `requestHeader` criterion with `IS_ONE_OF` match type.
|
|
11
|
+
*
|
|
12
|
+
* @param headerName - The HTTP request header name to inspect (e.g. `'origin'`, `'x-forwarded-for'`).
|
|
13
|
+
* @param values - Array of exact strings the header value must equal (e.g. `['https://example.com']`).
|
|
14
|
+
* @returns A `CriteriaFn` that evaluates to `true` when the header value matches any entry.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { rule } from '@viverse/cf-engine'
|
|
19
|
+
* import { headerEquals } from '@viverse/cf-engine/criteria'
|
|
20
|
+
* import { setCorsHeaders } from '@viverse/cf-engine/behaviors'
|
|
21
|
+
*
|
|
22
|
+
* // Apply CORS headers only for requests from known origins
|
|
23
|
+
* rule(
|
|
24
|
+
* headerEquals('origin', ['https://www.viverse.com', 'https://store.viverse.com']),
|
|
25
|
+
* setCorsHeaders({ allowOriginEcho: true, allowCredentials: true }),
|
|
26
|
+
* )
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function headerEquals(headerName: string, values: string[]): CriteriaFn;
|
|
30
|
+
|
|
31
|
+
export { headerEquals };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns `true` if the request `Host` header matches any of the given hostnames.
|
|
5
|
+
*
|
|
6
|
+
* Comparison is case-insensitive. Port numbers in the `Host` header are included
|
|
7
|
+
* in the comparison, so `'api.example.com:8080'` and `'api.example.com'` are
|
|
8
|
+
* treated as different values.
|
|
9
|
+
*
|
|
10
|
+
* Akamai equivalent: `hostname` criterion.
|
|
11
|
+
*
|
|
12
|
+
* @param hostnames - Array of exact hostnames to match (e.g. `['www.viverse.com', 'viverse.com']`).
|
|
13
|
+
* @returns A `CriteriaFn` to use as the first argument to `rule()`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* rule(hostnameIs(['legacy.viverse.com']), redirect(301, 'https://www.viverse.com'))
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare function hostnameIs(hostnames: string[]): CriteriaFn;
|
|
21
|
+
|
|
22
|
+
export { hostnameIs };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CriteriaFn } from '../core/types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns `true` if the request `Host` header matches any of the given hostnames.
|
|
5
|
+
*
|
|
6
|
+
* Comparison is case-insensitive. Port numbers in the `Host` header are included
|
|
7
|
+
* in the comparison, so `'api.example.com:8080'` and `'api.example.com'` are
|
|
8
|
+
* treated as different values.
|
|
9
|
+
*
|
|
10
|
+
* Akamai equivalent: `hostname` criterion.
|
|
11
|
+
*
|
|
12
|
+
* @param hostnames - Array of exact hostnames to match (e.g. `['www.viverse.com', 'viverse.com']`).
|
|
13
|
+
* @returns A `CriteriaFn` to use as the first argument to `rule()`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* rule(hostnameIs(['legacy.viverse.com']), redirect(301, 'https://www.viverse.com'))
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare function hostnameIs(hostnames: string[]): CriteriaFn;
|
|
21
|
+
|
|
22
|
+
export { hostnameIs };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkJGJW7D2Ncjs = require('../chunk-JGJW7D2N.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkD47P7HVZcjs = require('../chunk-D47P7HVZ.cjs');
|
|
7
|
+
require('../chunk-YVUR35RN.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkOTFDML3Kcjs = require('../chunk-OTFDML3K.cjs');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunkVEEOQ7TScjs = require('../chunk-VEEOQ7TS.cjs');
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var _chunkCF5PWWTFcjs = require('../chunk-CF5PWWTF.cjs');
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
var _chunkG7JGTBTTcjs = require('../chunk-G7JGTBTT.cjs');
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
var _chunkMVGYPBYBcjs = require('../chunk-MVGYPBYB.cjs');
|
|
23
|
+
require('../chunk-IBXAK2A4.cjs');
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
var _chunkOSZWDCTScjs = require('../chunk-OSZWDCTS.cjs');
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
var _chunkU54FZCOHcjs = require('../chunk-U54FZCOH.cjs');
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
var _chunk32SMWYAFcjs = require('../chunk-32SMWYAF.cjs');
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
var _chunkL7NBJ4JAcjs = require('../chunk-L7NBJ4JA.cjs');
|
|
36
|
+
require('../chunk-75ZPJI57.cjs');
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
exports.countryIs = _chunkOSZWDCTScjs.countryIs; exports.fileExtension = _chunkU54FZCOHcjs.fileExtension; exports.headerContains = _chunk32SMWYAFcjs.headerContains; exports.headerEquals = _chunkL7NBJ4JAcjs.headerEquals; exports.hostnameIs = _chunkJGJW7D2Ncjs.hostnameIs; exports.ipCidr = _chunkD47P7HVZcjs.ipCidr; exports.methodIs = _chunkOTFDML3Kcjs.methodIs; exports.pathEquals = _chunkVEEOQ7TScjs.pathEquals; exports.pathMatches = _chunkCF5PWWTFcjs.pathMatches; exports.pathPrefix = _chunkG7JGTBTTcjs.pathPrefix; exports.userAgentMatches = _chunkMVGYPBYBcjs.userAgentMatches;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { pathPrefix } from './path-prefix.cjs';
|
|
2
|
+
export { pathEquals } from './path-equals.cjs';
|
|
3
|
+
export { pathMatches } from './path-matches.cjs';
|
|
4
|
+
export { ipCidr } from './ip-cidr.cjs';
|
|
5
|
+
export { hostnameIs } from './hostname-is.cjs';
|
|
6
|
+
export { methodIs } from './method-is.cjs';
|
|
7
|
+
export { headerEquals } from './header-equals.cjs';
|
|
8
|
+
export { headerContains } from './header-contains.cjs';
|
|
9
|
+
export { fileExtension } from './file-extension.cjs';
|
|
10
|
+
export { countryIs } from './country-is.cjs';
|
|
11
|
+
export { userAgentMatches } from './user-agent-matches.cjs';
|
|
12
|
+
import '../core/types.cjs';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { pathPrefix } from './path-prefix.js';
|
|
2
|
+
export { pathEquals } from './path-equals.js';
|
|
3
|
+
export { pathMatches } from './path-matches.js';
|
|
4
|
+
export { ipCidr } from './ip-cidr.js';
|
|
5
|
+
export { hostnameIs } from './hostname-is.js';
|
|
6
|
+
export { methodIs } from './method-is.js';
|
|
7
|
+
export { headerEquals } from './header-equals.js';
|
|
8
|
+
export { headerContains } from './header-contains.js';
|
|
9
|
+
export { fileExtension } from './file-extension.js';
|
|
10
|
+
export { countryIs } from './country-is.js';
|
|
11
|
+
export { userAgentMatches } from './user-agent-matches.js';
|
|
12
|
+
import '../core/types.js';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hostnameIs
|
|
3
|
+
} from "../chunk-3PVDUC5M.js";
|
|
4
|
+
import {
|
|
5
|
+
ipCidr
|
|
6
|
+
} from "../chunk-KW5YBTSD.js";
|
|
7
|
+
import "../chunk-LNQPYKGG.js";
|
|
8
|
+
import {
|
|
9
|
+
methodIs
|
|
10
|
+
} from "../chunk-PY3JMRDG.js";
|
|
11
|
+
import {
|
|
12
|
+
pathEquals
|
|
13
|
+
} from "../chunk-UD456E4I.js";
|
|
14
|
+
import {
|
|
15
|
+
pathMatches
|
|
16
|
+
} from "../chunk-LO2BO3RU.js";
|
|
17
|
+
import {
|
|
18
|
+
pathPrefix
|
|
19
|
+
} from "../chunk-XLSZ5RB7.js";
|
|
20
|
+
import {
|
|
21
|
+
userAgentMatches
|
|
22
|
+
} from "../chunk-S2AAATFN.js";
|
|
23
|
+
import "../chunk-2DE6WPPL.js";
|
|
24
|
+
import {
|
|
25
|
+
countryIs
|
|
26
|
+
} from "../chunk-5CPBXZ4X.js";
|
|
27
|
+
import {
|
|
28
|
+
fileExtension
|
|
29
|
+
} from "../chunk-LBJUCJF2.js";
|
|
30
|
+
import {
|
|
31
|
+
headerContains
|
|
32
|
+
} from "../chunk-SRQF5UEJ.js";
|
|
33
|
+
import {
|
|
34
|
+
headerEquals
|
|
35
|
+
} from "../chunk-BZQJYOU2.js";
|
|
36
|
+
import "../chunk-MLKGABMK.js";
|
|
37
|
+
export {
|
|
38
|
+
countryIs,
|
|
39
|
+
fileExtension,
|
|
40
|
+
headerContains,
|
|
41
|
+
headerEquals,
|
|
42
|
+
hostnameIs,
|
|
43
|
+
ipCidr,
|
|
44
|
+
methodIs,
|
|
45
|
+
pathEquals,
|
|
46
|
+
pathMatches,
|
|
47
|
+
pathPrefix,
|
|
48
|
+
userAgentMatches
|
|
49
|
+
};
|