@rayselfs/cf-rule-engine 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/adapters/cf-function.d.cts +1 -1
- package/dist/adapters/cf-function.d.ts +1 -1
- package/dist/adapters/lambda-edge.d.cts +1 -1
- package/dist/adapters/lambda-edge.d.ts +1 -1
- package/dist/behaviors/construct-response.d.cts +3 -3
- package/dist/behaviors/construct-response.d.ts +3 -3
- package/dist/behaviors/copy-header.d.cts +3 -3
- package/dist/behaviors/copy-header.d.ts +3 -3
- package/dist/behaviors/directory-index.d.cts +3 -3
- package/dist/behaviors/directory-index.d.ts +3 -3
- package/dist/behaviors/redirect.d.cts +3 -3
- package/dist/behaviors/redirect.d.ts +3 -3
- package/dist/behaviors/remove-response-headers.d.cts +2 -2
- package/dist/behaviors/remove-response-headers.d.ts +2 -2
- package/dist/behaviors/rewrite-uri.d.cts +3 -3
- package/dist/behaviors/rewrite-uri.d.ts +3 -3
- package/dist/behaviors/set-cache-control.d.cts +4 -4
- package/dist/behaviors/set-cache-control.d.ts +4 -4
- package/dist/behaviors/set-cors-headers.d.cts +4 -4
- package/dist/behaviors/set-cors-headers.d.ts +4 -4
- package/dist/behaviors/set-csp.d.cts +2 -2
- package/dist/behaviors/set-csp.d.ts +2 -2
- package/dist/behaviors/set-request-header.d.cts +3 -3
- package/dist/behaviors/set-request-header.d.ts +3 -3
- package/dist/behaviors/set-response-header.d.cts +2 -2
- package/dist/behaviors/set-response-header.d.ts +2 -2
- package/dist/behaviors/set-security-headers.d.cts +2 -2
- package/dist/behaviors/set-security-headers.d.ts +2 -2
- package/dist/behaviors/strip-query-params.d.cts +2 -2
- package/dist/behaviors/strip-query-params.d.ts +2 -2
- package/dist/{cf-function-u0PvbW_s.d.ts → cf-function-C9eF2O9s.d.ts} +9 -9
- package/dist/{cf-function-D27hUVtN.d.cts → cf-function-DIQHy8L7.d.cts} +9 -9
- package/dist/criteria/country-is.d.cts +5 -5
- package/dist/criteria/country-is.d.ts +5 -5
- package/dist/criteria/file-extension.d.cts +3 -3
- package/dist/criteria/file-extension.d.ts +3 -3
- package/dist/criteria/header-contains.d.cts +4 -4
- package/dist/criteria/header-contains.d.ts +4 -4
- package/dist/criteria/header-equals.d.cts +4 -4
- package/dist/criteria/header-equals.d.ts +4 -4
- package/dist/criteria/hostname-is.d.cts +2 -2
- package/dist/criteria/hostname-is.d.ts +2 -2
- package/dist/criteria/ip-cidr.d.cts +4 -4
- package/dist/criteria/ip-cidr.d.ts +4 -4
- package/dist/criteria/method-is.d.cts +3 -3
- package/dist/criteria/method-is.d.ts +3 -3
- package/dist/criteria/user-agent-matches.d.cts +6 -6
- package/dist/criteria/user-agent-matches.d.ts +6 -6
- package/dist/helpers/index.d.cts +4 -4
- package/dist/helpers/index.d.ts +4 -4
- package/dist/helpers/preflight-request.d.cts +4 -4
- package/dist/helpers/preflight-request.d.ts +4 -4
- package/dist/helpers/send-country-code.d.cts +5 -5
- package/dist/helpers/send-country-code.d.ts +5 -5
- package/dist/helpers/staging-whitelist.d.cts +2 -2
- package/dist/helpers/staging-whitelist.d.ts +2 -2
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/{lambda-edge-DxTOa2cg.d.cts → lambda-edge-9xiONGmR.d.cts} +6 -6
- package/dist/{lambda-edge-D15Nf__n.d.ts → lambda-edge-BK3-bFx8.d.ts} +6 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-funct
|
|
|
34
34
|
|
|
35
35
|
export default defineViewerResponse([
|
|
36
36
|
setSecurityHeaders(),
|
|
37
|
-
setCorsHeaders({ allowedOrigins: ['https://www.
|
|
37
|
+
setCorsHeaders({ allowedOrigins: ['https://www.example.com'] }),
|
|
38
38
|
])
|
|
39
39
|
```
|
|
40
40
|
|
|
@@ -134,7 +134,7 @@ Adds `x-cf-distribution: staging` to the response when the request carries `aws-
|
|
|
134
134
|
import { stagingIndicator } from '@rayselfs/cf-rule-engine/helpers/index'
|
|
135
135
|
|
|
136
136
|
defineViewerResponse([
|
|
137
|
-
setCorsHeaders({ allowedOrigins: ['https://www.
|
|
137
|
+
setCorsHeaders({ allowedOrigins: ['https://www.example.com'] }),
|
|
138
138
|
stagingIndicator(),
|
|
139
139
|
])
|
|
140
140
|
```
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import '../core/types.cjs';
|
|
2
|
-
export { d as defineViewerRequest, a as defineViewerResponse } from '../cf-function-
|
|
2
|
+
export { d as defineViewerRequest, a as defineViewerResponse } from '../cf-function-DIQHy8L7.cjs';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import '../core/types.js';
|
|
2
|
-
export { d as defineViewerRequest, a as defineViewerResponse } from '../cf-function-
|
|
2
|
+
export { d as defineViewerRequest, a as defineViewerResponse } from '../cf-function-C9eF2O9s.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import '../core/types.cjs';
|
|
2
|
-
export { d as defineViewerRequest, a as defineViewerResponse } from '../lambda-edge-
|
|
2
|
+
export { d as defineViewerRequest, a as defineViewerResponse } from '../lambda-edge-9xiONGmR.cjs';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import '../core/types.js';
|
|
2
|
-
export { d as defineViewerRequest, a as defineViewerResponse } from '../lambda-edge-
|
|
2
|
+
export { d as defineViewerRequest, a as defineViewerResponse } from '../lambda-edge-BK3-bFx8.js';
|
|
@@ -39,9 +39,9 @@ interface ConstructResponseOptions {
|
|
|
39
39
|
*
|
|
40
40
|
* @example
|
|
41
41
|
* ```ts
|
|
42
|
-
* import { constructResponse } from '@
|
|
43
|
-
* import { methodIs, pathPrefix } from '@
|
|
44
|
-
* import { rule } from '@
|
|
42
|
+
* import { constructResponse } from '@rayselfs/cf-rule-engine/behaviors'
|
|
43
|
+
* import { methodIs, pathPrefix } from '@rayselfs/cf-rule-engine/criteria'
|
|
44
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
45
45
|
*
|
|
46
46
|
* // Respond to OPTIONS preflight requests
|
|
47
47
|
* rule(methodIs(['OPTIONS']), constructResponse({ statusCode: 200, body: '' }))
|
|
@@ -39,9 +39,9 @@ interface ConstructResponseOptions {
|
|
|
39
39
|
*
|
|
40
40
|
* @example
|
|
41
41
|
* ```ts
|
|
42
|
-
* import { constructResponse } from '@
|
|
43
|
-
* import { methodIs, pathPrefix } from '@
|
|
44
|
-
* import { rule } from '@
|
|
42
|
+
* import { constructResponse } from '@rayselfs/cf-rule-engine/behaviors'
|
|
43
|
+
* import { methodIs, pathPrefix } from '@rayselfs/cf-rule-engine/criteria'
|
|
44
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
45
45
|
*
|
|
46
46
|
* // Respond to OPTIONS preflight requests
|
|
47
47
|
* rule(methodIs(['OPTIONS']), constructResponse({ statusCode: 200, body: '' }))
|
|
@@ -16,10 +16,10 @@ import { BehaviorFn } from '../core/types.cjs';
|
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* ```ts
|
|
19
|
-
* import { copyHeader } from '@
|
|
20
|
-
* import { rule } from '@
|
|
19
|
+
* import { copyHeader } from '@rayselfs/cf-rule-engine/behaviors'
|
|
20
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
21
21
|
*
|
|
22
|
-
* rule(copyHeader('cloudfront-viewer-country', 'x-
|
|
22
|
+
* rule(copyHeader('cloudfront-viewer-country', 'x-viewer-country'))
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
25
|
declare function copyHeader(sourceHeader: string, targetHeader: string): BehaviorFn;
|
|
@@ -16,10 +16,10 @@ import { BehaviorFn } from '../core/types.js';
|
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* ```ts
|
|
19
|
-
* import { copyHeader } from '@
|
|
20
|
-
* import { rule } from '@
|
|
19
|
+
* import { copyHeader } from '@rayselfs/cf-rule-engine/behaviors'
|
|
20
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
21
21
|
*
|
|
22
|
-
* rule(copyHeader('cloudfront-viewer-country', 'x-
|
|
22
|
+
* rule(copyHeader('cloudfront-viewer-country', 'x-viewer-country'))
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
25
|
declare function copyHeader(sourceHeader: string, targetHeader: string): BehaviorFn;
|
|
@@ -16,9 +16,9 @@ import { BehaviorFn } from '../core/types.cjs';
|
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* ```ts
|
|
19
|
-
* import { directoryIndex } from '@
|
|
20
|
-
* import { rule } from '@
|
|
21
|
-
* import { defineViewerRequest } from '@
|
|
19
|
+
* import { directoryIndex } from '@rayselfs/cf-rule-engine/behaviors'
|
|
20
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
21
|
+
* import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
22
22
|
*
|
|
23
23
|
* export default defineViewerRequest([
|
|
24
24
|
* rule(directoryIndex()),
|
|
@@ -16,9 +16,9 @@ import { BehaviorFn } from '../core/types.js';
|
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* ```ts
|
|
19
|
-
* import { directoryIndex } from '@
|
|
20
|
-
* import { rule } from '@
|
|
21
|
-
* import { defineViewerRequest } from '@
|
|
19
|
+
* import { directoryIndex } from '@rayselfs/cf-rule-engine/behaviors'
|
|
20
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
21
|
+
* import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
22
22
|
*
|
|
23
23
|
* export default defineViewerRequest([
|
|
24
24
|
* rule(directoryIndex()),
|
|
@@ -28,9 +28,9 @@ interface RedirectOptions {
|
|
|
28
28
|
*
|
|
29
29
|
* @example
|
|
30
30
|
* ```ts
|
|
31
|
-
* import { redirect } from '@
|
|
32
|
-
* import { pathPrefix, pathEquals } from '@
|
|
33
|
-
* import { rule } from '@
|
|
31
|
+
* import { redirect } from '@rayselfs/cf-rule-engine/behaviors'
|
|
32
|
+
* import { pathPrefix, pathEquals } from '@rayselfs/cf-rule-engine/criteria'
|
|
33
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
34
34
|
*
|
|
35
35
|
* // Permanent redirect for a renamed section
|
|
36
36
|
* rule(pathPrefix(['/old-blog/']), redirect(301, '/blog/'))
|
|
@@ -28,9 +28,9 @@ interface RedirectOptions {
|
|
|
28
28
|
*
|
|
29
29
|
* @example
|
|
30
30
|
* ```ts
|
|
31
|
-
* import { redirect } from '@
|
|
32
|
-
* import { pathPrefix, pathEquals } from '@
|
|
33
|
-
* import { rule } from '@
|
|
31
|
+
* import { redirect } from '@rayselfs/cf-rule-engine/behaviors'
|
|
32
|
+
* import { pathPrefix, pathEquals } from '@rayselfs/cf-rule-engine/criteria'
|
|
33
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
34
34
|
*
|
|
35
35
|
* // Permanent redirect for a renamed section
|
|
36
36
|
* rule(pathPrefix(['/old-blog/']), redirect(301, '/blog/'))
|
|
@@ -14,8 +14,8 @@ import { ResponseBehaviorFn } from '../core/types.cjs';
|
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```ts
|
|
17
|
-
* import { removeResponseHeaders } from '@
|
|
18
|
-
* import { defineViewerResponse } from '@
|
|
17
|
+
* import { removeResponseHeaders } from '@rayselfs/cf-rule-engine/behaviors'
|
|
18
|
+
* import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
19
19
|
*
|
|
20
20
|
* export default defineViewerResponse([
|
|
21
21
|
* removeResponseHeaders(['server', 'x-powered-by', 'x-amzn-requestid']),
|
|
@@ -14,8 +14,8 @@ import { ResponseBehaviorFn } from '../core/types.js';
|
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```ts
|
|
17
|
-
* import { removeResponseHeaders } from '@
|
|
18
|
-
* import { defineViewerResponse } from '@
|
|
17
|
+
* import { removeResponseHeaders } from '@rayselfs/cf-rule-engine/behaviors'
|
|
18
|
+
* import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
19
19
|
*
|
|
20
20
|
* export default defineViewerResponse([
|
|
21
21
|
* removeResponseHeaders(['server', 'x-powered-by', 'x-amzn-requestid']),
|
|
@@ -21,9 +21,9 @@ type RewriteMode = 'set' | 'replace' | 'prepend' | 'regex-replace';
|
|
|
21
21
|
*
|
|
22
22
|
* @example
|
|
23
23
|
* ```ts
|
|
24
|
-
* import { rewriteUri } from '@
|
|
25
|
-
* import { pathPrefix } from '@
|
|
26
|
-
* import { rule } from '@
|
|
24
|
+
* import { rewriteUri } from '@rayselfs/cf-rule-engine/behaviors'
|
|
25
|
+
* import { pathPrefix } from '@rayselfs/cf-rule-engine/criteria'
|
|
26
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
27
27
|
*
|
|
28
28
|
* // Set: replace entire URI
|
|
29
29
|
* rule(pathEquals(['/index.php']), rewriteUri('set', '/index.html'))
|
|
@@ -21,9 +21,9 @@ type RewriteMode = 'set' | 'replace' | 'prepend' | 'regex-replace';
|
|
|
21
21
|
*
|
|
22
22
|
* @example
|
|
23
23
|
* ```ts
|
|
24
|
-
* import { rewriteUri } from '@
|
|
25
|
-
* import { pathPrefix } from '@
|
|
26
|
-
* import { rule } from '@
|
|
24
|
+
* import { rewriteUri } from '@rayselfs/cf-rule-engine/behaviors'
|
|
25
|
+
* import { pathPrefix } from '@rayselfs/cf-rule-engine/criteria'
|
|
26
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
27
27
|
*
|
|
28
28
|
* // Set: replace entire URI
|
|
29
29
|
* rule(pathEquals(['/index.php']), rewriteUri('set', '/index.html'))
|
|
@@ -11,10 +11,10 @@ import { ResponseBehaviorFn } from '../core/types.cjs';
|
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```ts
|
|
14
|
-
* import { setCacheControl } from '@
|
|
15
|
-
* import { pathPrefix } from '@
|
|
16
|
-
* import { rule } from '@
|
|
17
|
-
* import { defineViewerResponse } from '@
|
|
14
|
+
* import { setCacheControl } from '@rayselfs/cf-rule-engine/behaviors'
|
|
15
|
+
* import { pathPrefix } from '@rayselfs/cf-rule-engine/criteria'
|
|
16
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
17
|
+
* import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
18
18
|
*
|
|
19
19
|
* export default defineViewerResponse([
|
|
20
20
|
* // Cache static assets for 1 year
|
|
@@ -11,10 +11,10 @@ import { ResponseBehaviorFn } from '../core/types.js';
|
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```ts
|
|
14
|
-
* import { setCacheControl } from '@
|
|
15
|
-
* import { pathPrefix } from '@
|
|
16
|
-
* import { rule } from '@
|
|
17
|
-
* import { defineViewerResponse } from '@
|
|
14
|
+
* import { setCacheControl } from '@rayselfs/cf-rule-engine/behaviors'
|
|
15
|
+
* import { pathPrefix } from '@rayselfs/cf-rule-engine/criteria'
|
|
16
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
17
|
+
* import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
18
18
|
*
|
|
19
19
|
* export default defineViewerResponse([
|
|
20
20
|
* // Cache static assets for 1 year
|
|
@@ -6,7 +6,7 @@ import { ResponseBehaviorFn } from '../core/types.cjs';
|
|
|
6
6
|
interface CorsOptions {
|
|
7
7
|
/**
|
|
8
8
|
* List of allowed origin patterns. Supports exact strings and wildcard `*` patterns
|
|
9
|
-
* (e.g. `'https://*.
|
|
9
|
+
* (e.g. `'https://*.example.com'`). Use `['*']` to allow all origins.
|
|
10
10
|
* Default: `['*']`
|
|
11
11
|
*/
|
|
12
12
|
allowedOrigins?: string[];
|
|
@@ -53,8 +53,8 @@ interface CorsOptions {
|
|
|
53
53
|
*
|
|
54
54
|
* @example
|
|
55
55
|
* ```ts
|
|
56
|
-
* import { setCorsHeaders } from '@
|
|
57
|
-
* import { defineViewerResponse } from '@
|
|
56
|
+
* import { setCorsHeaders } from '@rayselfs/cf-rule-engine/behaviors'
|
|
57
|
+
* import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
58
58
|
*
|
|
59
59
|
* // Allow all origins (default)
|
|
60
60
|
* export default defineViewerResponse([setCorsHeaders()])
|
|
@@ -62,7 +62,7 @@ interface CorsOptions {
|
|
|
62
62
|
* // Echo origin with credentials (e.g. for authenticated API endpoints)
|
|
63
63
|
* export default defineViewerResponse([
|
|
64
64
|
* setCorsHeaders({
|
|
65
|
-
* allowedOrigins: ['https://www.
|
|
65
|
+
* allowedOrigins: ['https://www.example.com', 'https://*.example.com'],
|
|
66
66
|
* allowOriginEcho: true,
|
|
67
67
|
* allowCredentials: true,
|
|
68
68
|
* allowedMethods: 'GET, POST, PUT, DELETE, OPTIONS',
|
|
@@ -6,7 +6,7 @@ import { ResponseBehaviorFn } from '../core/types.js';
|
|
|
6
6
|
interface CorsOptions {
|
|
7
7
|
/**
|
|
8
8
|
* List of allowed origin patterns. Supports exact strings and wildcard `*` patterns
|
|
9
|
-
* (e.g. `'https://*.
|
|
9
|
+
* (e.g. `'https://*.example.com'`). Use `['*']` to allow all origins.
|
|
10
10
|
* Default: `['*']`
|
|
11
11
|
*/
|
|
12
12
|
allowedOrigins?: string[];
|
|
@@ -53,8 +53,8 @@ interface CorsOptions {
|
|
|
53
53
|
*
|
|
54
54
|
* @example
|
|
55
55
|
* ```ts
|
|
56
|
-
* import { setCorsHeaders } from '@
|
|
57
|
-
* import { defineViewerResponse } from '@
|
|
56
|
+
* import { setCorsHeaders } from '@rayselfs/cf-rule-engine/behaviors'
|
|
57
|
+
* import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
58
58
|
*
|
|
59
59
|
* // Allow all origins (default)
|
|
60
60
|
* export default defineViewerResponse([setCorsHeaders()])
|
|
@@ -62,7 +62,7 @@ interface CorsOptions {
|
|
|
62
62
|
* // Echo origin with credentials (e.g. for authenticated API endpoints)
|
|
63
63
|
* export default defineViewerResponse([
|
|
64
64
|
* setCorsHeaders({
|
|
65
|
-
* allowedOrigins: ['https://www.
|
|
65
|
+
* allowedOrigins: ['https://www.example.com', 'https://*.example.com'],
|
|
66
66
|
* allowOriginEcho: true,
|
|
67
67
|
* allowCredentials: true,
|
|
68
68
|
* allowedMethods: 'GET, POST, PUT, DELETE, OPTIONS',
|
|
@@ -28,8 +28,8 @@ interface CspOptions {
|
|
|
28
28
|
*
|
|
29
29
|
* @example
|
|
30
30
|
* ```ts
|
|
31
|
-
* import { setCsp } from '@
|
|
32
|
-
* import { defineViewerResponse } from '@
|
|
31
|
+
* import { setCsp } from '@rayselfs/cf-rule-engine/behaviors'
|
|
32
|
+
* import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
33
33
|
*
|
|
34
34
|
* export default defineViewerResponse([
|
|
35
35
|
* setCsp({
|
|
@@ -28,8 +28,8 @@ interface CspOptions {
|
|
|
28
28
|
*
|
|
29
29
|
* @example
|
|
30
30
|
* ```ts
|
|
31
|
-
* import { setCsp } from '@
|
|
32
|
-
* import { defineViewerResponse } from '@
|
|
31
|
+
* import { setCsp } from '@rayselfs/cf-rule-engine/behaviors'
|
|
32
|
+
* import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
33
33
|
*
|
|
34
34
|
* export default defineViewerResponse([
|
|
35
35
|
* setCsp({
|
|
@@ -14,9 +14,9 @@ import { BehaviorFn } from '../core/types.cjs';
|
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```ts
|
|
17
|
-
* import { setRequestHeader } from '@
|
|
18
|
-
* import { pathPrefix } from '@
|
|
19
|
-
* import { rule } from '@
|
|
17
|
+
* import { setRequestHeader } from '@rayselfs/cf-rule-engine/behaviors'
|
|
18
|
+
* import { pathPrefix } from '@rayselfs/cf-rule-engine/criteria'
|
|
19
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
20
20
|
*
|
|
21
21
|
* rule(pathPrefix(['/api/']), setRequestHeader('x-internal-service', 'cf-edge'))
|
|
22
22
|
* ```
|
|
@@ -14,9 +14,9 @@ import { BehaviorFn } from '../core/types.js';
|
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```ts
|
|
17
|
-
* import { setRequestHeader } from '@
|
|
18
|
-
* import { pathPrefix } from '@
|
|
19
|
-
* import { rule } from '@
|
|
17
|
+
* import { setRequestHeader } from '@rayselfs/cf-rule-engine/behaviors'
|
|
18
|
+
* import { pathPrefix } from '@rayselfs/cf-rule-engine/criteria'
|
|
19
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
20
20
|
*
|
|
21
21
|
* rule(pathPrefix(['/api/']), setRequestHeader('x-internal-service', 'cf-edge'))
|
|
22
22
|
* ```
|
|
@@ -14,8 +14,8 @@ import { ResponseBehaviorFn } from '../core/types.cjs';
|
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```ts
|
|
17
|
-
* import { setResponseHeader } from '@
|
|
18
|
-
* import { defineViewerResponse } from '@
|
|
17
|
+
* import { setResponseHeader } from '@rayselfs/cf-rule-engine/behaviors'
|
|
18
|
+
* import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
19
19
|
*
|
|
20
20
|
* export default defineViewerResponse([
|
|
21
21
|
* setResponseHeader('x-powered-by', 'CloudFront'),
|
|
@@ -14,8 +14,8 @@ import { ResponseBehaviorFn } from '../core/types.js';
|
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```ts
|
|
17
|
-
* import { setResponseHeader } from '@
|
|
18
|
-
* import { defineViewerResponse } from '@
|
|
17
|
+
* import { setResponseHeader } from '@rayselfs/cf-rule-engine/behaviors'
|
|
18
|
+
* import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
19
19
|
*
|
|
20
20
|
* export default defineViewerResponse([
|
|
21
21
|
* setResponseHeader('x-powered-by', 'CloudFront'),
|
|
@@ -38,8 +38,8 @@ interface SecurityHeadersOptions {
|
|
|
38
38
|
*
|
|
39
39
|
* @example
|
|
40
40
|
* ```ts
|
|
41
|
-
* import { setSecurityHeaders } from '@
|
|
42
|
-
* import { defineViewerResponse } from '@
|
|
41
|
+
* import { setSecurityHeaders } from '@rayselfs/cf-rule-engine/behaviors'
|
|
42
|
+
* import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
43
43
|
*
|
|
44
44
|
* // Apply defaults
|
|
45
45
|
* export default defineViewerResponse([setSecurityHeaders()])
|
|
@@ -38,8 +38,8 @@ interface SecurityHeadersOptions {
|
|
|
38
38
|
*
|
|
39
39
|
* @example
|
|
40
40
|
* ```ts
|
|
41
|
-
* import { setSecurityHeaders } from '@
|
|
42
|
-
* import { defineViewerResponse } from '@
|
|
41
|
+
* import { setSecurityHeaders } from '@rayselfs/cf-rule-engine/behaviors'
|
|
42
|
+
* import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
43
43
|
*
|
|
44
44
|
* // Apply defaults
|
|
45
45
|
* export default defineViewerResponse([setSecurityHeaders()])
|
|
@@ -13,8 +13,8 @@ import { BehaviorFn } from '../core/types.cjs';
|
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```ts
|
|
16
|
-
* import { stripQueryParams, verifyToken } from '@
|
|
17
|
-
* import { rule } from '@
|
|
16
|
+
* import { stripQueryParams, verifyToken } from '@rayselfs/cf-rule-engine/behaviors'
|
|
17
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
18
18
|
*
|
|
19
19
|
* rule(verifyToken({ key: process.env.EDGE_AUTH_KEY! })),
|
|
20
20
|
* rule(stripQueryParams(['hdnts', 'imformat']))
|
|
@@ -13,8 +13,8 @@ import { BehaviorFn } from '../core/types.js';
|
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```ts
|
|
16
|
-
* import { stripQueryParams, verifyToken } from '@
|
|
17
|
-
* import { rule } from '@
|
|
16
|
+
* import { stripQueryParams, verifyToken } from '@rayselfs/cf-rule-engine/behaviors'
|
|
17
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
18
18
|
*
|
|
19
19
|
* rule(verifyToken({ key: process.env.EDGE_AUTH_KEY! })),
|
|
20
20
|
* rule(stripQueryParams(['hdnts', 'imformat']))
|
|
@@ -15,13 +15,13 @@ import { Rule, ResponseBehaviorFn, ResponseRule } from './core/types.js';
|
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* ```ts
|
|
18
|
-
* import { rule, not } from '@
|
|
19
|
-
* import { ipCidr, pathPrefix } from '@
|
|
20
|
-
* import { redirect, setRequestHeader } from '@
|
|
21
|
-
* import { defineViewerRequest } from '@
|
|
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
22
|
*
|
|
23
23
|
* export default defineViewerRequest([
|
|
24
|
-
* rule(not(ipCidr(['10.0.0.0/8'])), redirect(302, 'https://www.
|
|
24
|
+
* rule(not(ipCidr(['10.0.0.0/8'])), redirect(302, 'https://www.example.com')),
|
|
25
25
|
* rule(pathPrefix(['/api/']), setRequestHeader('x-forwarded-host', 'api.internal')),
|
|
26
26
|
* ])
|
|
27
27
|
* ```
|
|
@@ -48,13 +48,13 @@ declare function defineViewerRequest(rules: Rule[]): (event: unknown) => unknown
|
|
|
48
48
|
*
|
|
49
49
|
* @example
|
|
50
50
|
* ```ts
|
|
51
|
-
* import { setSecurityHeaders, setCorsHeaders, setResponseHeader } from '@
|
|
52
|
-
* import { pathPrefix } from '@
|
|
53
|
-
* import { defineViewerResponse } from '@
|
|
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
54
|
*
|
|
55
55
|
* export default defineViewerResponse([
|
|
56
56
|
* setSecurityHeaders(),
|
|
57
|
-
* setCorsHeaders({ allowedOrigins: ['https://www.
|
|
57
|
+
* setCorsHeaders({ allowedOrigins: ['https://www.example.com'] }),
|
|
58
58
|
* { criteria: pathPrefix(['/api/']), behavior: setResponseHeader('cache-control', 'no-store') },
|
|
59
59
|
* ])
|
|
60
60
|
* ```
|
|
@@ -15,13 +15,13 @@ import { Rule, ResponseBehaviorFn, ResponseRule } from './core/types.cjs';
|
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* ```ts
|
|
18
|
-
* import { rule, not } from '@
|
|
19
|
-
* import { ipCidr, pathPrefix } from '@
|
|
20
|
-
* import { redirect, setRequestHeader } from '@
|
|
21
|
-
* import { defineViewerRequest } from '@
|
|
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
22
|
*
|
|
23
23
|
* export default defineViewerRequest([
|
|
24
|
-
* rule(not(ipCidr(['10.0.0.0/8'])), redirect(302, 'https://www.
|
|
24
|
+
* rule(not(ipCidr(['10.0.0.0/8'])), redirect(302, 'https://www.example.com')),
|
|
25
25
|
* rule(pathPrefix(['/api/']), setRequestHeader('x-forwarded-host', 'api.internal')),
|
|
26
26
|
* ])
|
|
27
27
|
* ```
|
|
@@ -48,13 +48,13 @@ declare function defineViewerRequest(rules: Rule[]): (event: unknown) => unknown
|
|
|
48
48
|
*
|
|
49
49
|
* @example
|
|
50
50
|
* ```ts
|
|
51
|
-
* import { setSecurityHeaders, setCorsHeaders, setResponseHeader } from '@
|
|
52
|
-
* import { pathPrefix } from '@
|
|
53
|
-
* import { defineViewerResponse } from '@
|
|
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
54
|
*
|
|
55
55
|
* export default defineViewerResponse([
|
|
56
56
|
* setSecurityHeaders(),
|
|
57
|
-
* setCorsHeaders({ allowedOrigins: ['https://www.
|
|
57
|
+
* setCorsHeaders({ allowedOrigins: ['https://www.example.com'] }),
|
|
58
58
|
* { criteria: pathPrefix(['/api/']), behavior: setResponseHeader('cache-control', 'no-store') },
|
|
59
59
|
* ])
|
|
60
60
|
* ```
|
|
@@ -18,16 +18,16 @@ import { CriteriaFn } from '../core/types.cjs';
|
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* ```typescript
|
|
21
|
-
* import { rule } from '@
|
|
22
|
-
* import { countryIs } from '@
|
|
23
|
-
* import { redirect } from '@
|
|
21
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
22
|
+
* import { countryIs } from '@rayselfs/cf-rule-engine/criteria'
|
|
23
|
+
* import { redirect } from '@rayselfs/cf-rule-engine/behaviors'
|
|
24
24
|
*
|
|
25
25
|
* // Redirect mainland China traffic to the CN domain
|
|
26
|
-
* rule(countryIs(['CN']), redirect(302, 'https://www.
|
|
26
|
+
* rule(countryIs(['CN']), redirect(302, 'https://www.example.cn'))
|
|
27
27
|
*
|
|
28
28
|
* // Serve region-specific content for APAC countries
|
|
29
29
|
* rule(countryIs(['TW', 'JP', 'KR', 'SG', 'HK']),
|
|
30
|
-
* redirect(302, 'https://www.
|
|
30
|
+
* redirect(302, 'https://www.example.com/apac'))
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
33
|
declare function countryIs(codes: string[]): CriteriaFn;
|
|
@@ -18,16 +18,16 @@ import { CriteriaFn } from '../core/types.js';
|
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* ```typescript
|
|
21
|
-
* import { rule } from '@
|
|
22
|
-
* import { countryIs } from '@
|
|
23
|
-
* import { redirect } from '@
|
|
21
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
22
|
+
* import { countryIs } from '@rayselfs/cf-rule-engine/criteria'
|
|
23
|
+
* import { redirect } from '@rayselfs/cf-rule-engine/behaviors'
|
|
24
24
|
*
|
|
25
25
|
* // Redirect mainland China traffic to the CN domain
|
|
26
|
-
* rule(countryIs(['CN']), redirect(302, 'https://www.
|
|
26
|
+
* rule(countryIs(['CN']), redirect(302, 'https://www.example.cn'))
|
|
27
27
|
*
|
|
28
28
|
* // Serve region-specific content for APAC countries
|
|
29
29
|
* rule(countryIs(['TW', 'JP', 'KR', 'SG', 'HK']),
|
|
30
|
-
* redirect(302, 'https://www.
|
|
30
|
+
* redirect(302, 'https://www.example.com/apac'))
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
33
|
declare function countryIs(codes: string[]): CriteriaFn;
|
|
@@ -14,9 +14,9 @@ import { CriteriaFn } from '../core/types.cjs';
|
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```typescript
|
|
17
|
-
* import { rule } from '@
|
|
18
|
-
* import { fileExtension } from '@
|
|
19
|
-
* import { setCacheControl, imageOptimize } from '@
|
|
17
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
18
|
+
* import { fileExtension } from '@rayselfs/cf-rule-engine/criteria'
|
|
19
|
+
* import { setCacheControl, imageOptimize } from '@rayselfs/cf-rule-engine/behaviors'
|
|
20
20
|
*
|
|
21
21
|
* // Apply long-lived cache to static assets
|
|
22
22
|
* rule(fileExtension(['js', 'css', 'woff2', 'woff']),
|
|
@@ -14,9 +14,9 @@ import { CriteriaFn } from '../core/types.js';
|
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```typescript
|
|
17
|
-
* import { rule } from '@
|
|
18
|
-
* import { fileExtension } from '@
|
|
19
|
-
* import { setCacheControl, imageOptimize } from '@
|
|
17
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
18
|
+
* import { fileExtension } from '@rayselfs/cf-rule-engine/criteria'
|
|
19
|
+
* import { setCacheControl, imageOptimize } from '@rayselfs/cf-rule-engine/behaviors'
|
|
20
20
|
*
|
|
21
21
|
* // Apply long-lived cache to static assets
|
|
22
22
|
* rule(fileExtension(['js', 'css', 'woff2', 'woff']),
|
|
@@ -15,9 +15,9 @@ import { CriteriaFn } from '../core/types.cjs';
|
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* ```typescript
|
|
18
|
-
* import { rule } from '@
|
|
19
|
-
* import { headerContains } from '@
|
|
20
|
-
* import { redirect } from '@
|
|
18
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
19
|
+
* import { headerContains } from '@rayselfs/cf-rule-engine/criteria'
|
|
20
|
+
* import { redirect } from '@rayselfs/cf-rule-engine/behaviors'
|
|
21
21
|
*
|
|
22
22
|
* // Redirect requests that accept WebP to an optimized image path
|
|
23
23
|
* rule(headerContains('accept', ['image/webp']),
|
|
@@ -25,7 +25,7 @@ import { CriteriaFn } from '../core/types.cjs';
|
|
|
25
25
|
*
|
|
26
26
|
* // Match requests from mobile browsers
|
|
27
27
|
* rule(headerContains('user-agent', ['Mobile', 'Android', 'iPhone']),
|
|
28
|
-
* redirect(302, 'https://m.
|
|
28
|
+
* redirect(302, 'https://m.example.com'))
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
declare function headerContains(headerName: string, substrings: string[]): CriteriaFn;
|
|
@@ -15,9 +15,9 @@ import { CriteriaFn } from '../core/types.js';
|
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* ```typescript
|
|
18
|
-
* import { rule } from '@
|
|
19
|
-
* import { headerContains } from '@
|
|
20
|
-
* import { redirect } from '@
|
|
18
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
19
|
+
* import { headerContains } from '@rayselfs/cf-rule-engine/criteria'
|
|
20
|
+
* import { redirect } from '@rayselfs/cf-rule-engine/behaviors'
|
|
21
21
|
*
|
|
22
22
|
* // Redirect requests that accept WebP to an optimized image path
|
|
23
23
|
* rule(headerContains('accept', ['image/webp']),
|
|
@@ -25,7 +25,7 @@ import { CriteriaFn } from '../core/types.js';
|
|
|
25
25
|
*
|
|
26
26
|
* // Match requests from mobile browsers
|
|
27
27
|
* rule(headerContains('user-agent', ['Mobile', 'Android', 'iPhone']),
|
|
28
|
-
* redirect(302, 'https://m.
|
|
28
|
+
* redirect(302, 'https://m.example.com'))
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
declare function headerContains(headerName: string, substrings: string[]): CriteriaFn;
|
|
@@ -15,13 +15,13 @@ import { CriteriaFn } from '../core/types.cjs';
|
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* ```typescript
|
|
18
|
-
* import { rule } from '@
|
|
19
|
-
* import { headerEquals } from '@
|
|
20
|
-
* import { setCorsHeaders } from '@
|
|
18
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
19
|
+
* import { headerEquals } from '@rayselfs/cf-rule-engine/criteria'
|
|
20
|
+
* import { setCorsHeaders } from '@rayselfs/cf-rule-engine/behaviors'
|
|
21
21
|
*
|
|
22
22
|
* // Apply CORS headers only for requests from known origins
|
|
23
23
|
* rule(
|
|
24
|
-
* headerEquals('origin', ['https://www.
|
|
24
|
+
* headerEquals('origin', ['https://www.example.com', 'https://store.example.com']),
|
|
25
25
|
* setCorsHeaders({ allowOriginEcho: true, allowCredentials: true }),
|
|
26
26
|
* )
|
|
27
27
|
* ```
|
|
@@ -15,13 +15,13 @@ import { CriteriaFn } from '../core/types.js';
|
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* ```typescript
|
|
18
|
-
* import { rule } from '@
|
|
19
|
-
* import { headerEquals } from '@
|
|
20
|
-
* import { setCorsHeaders } from '@
|
|
18
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
19
|
+
* import { headerEquals } from '@rayselfs/cf-rule-engine/criteria'
|
|
20
|
+
* import { setCorsHeaders } from '@rayselfs/cf-rule-engine/behaviors'
|
|
21
21
|
*
|
|
22
22
|
* // Apply CORS headers only for requests from known origins
|
|
23
23
|
* rule(
|
|
24
|
-
* headerEquals('origin', ['https://www.
|
|
24
|
+
* headerEquals('origin', ['https://www.example.com', 'https://store.example.com']),
|
|
25
25
|
* setCorsHeaders({ allowOriginEcho: true, allowCredentials: true }),
|
|
26
26
|
* )
|
|
27
27
|
* ```
|
|
@@ -9,12 +9,12 @@ import { CriteriaFn } from '../core/types.cjs';
|
|
|
9
9
|
*
|
|
10
10
|
* Akamai equivalent: `hostname` criterion.
|
|
11
11
|
*
|
|
12
|
-
* @param hostnames - Array of exact hostnames to match (e.g. `['www.
|
|
12
|
+
* @param hostnames - Array of exact hostnames to match (e.g. `['www.example.com', 'example.com']`).
|
|
13
13
|
* @returns A `CriteriaFn` to use as the first argument to `rule()`.
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```ts
|
|
17
|
-
* rule(hostnameIs(['legacy.
|
|
17
|
+
* rule(hostnameIs(['legacy.example.com']), redirect(301, 'https://www.example.com'))
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
declare function hostnameIs(hostnames: string[]): CriteriaFn;
|
|
@@ -9,12 +9,12 @@ import { CriteriaFn } from '../core/types.js';
|
|
|
9
9
|
*
|
|
10
10
|
* Akamai equivalent: `hostname` criterion.
|
|
11
11
|
*
|
|
12
|
-
* @param hostnames - Array of exact hostnames to match (e.g. `['www.
|
|
12
|
+
* @param hostnames - Array of exact hostnames to match (e.g. `['www.example.com', 'example.com']`).
|
|
13
13
|
* @returns A `CriteriaFn` to use as the first argument to `rule()`.
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```ts
|
|
17
|
-
* rule(hostnameIs(['legacy.
|
|
17
|
+
* rule(hostnameIs(['legacy.example.com']), redirect(301, 'https://www.example.com'))
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
declare function hostnameIs(hostnames: string[]): CriteriaFn;
|
|
@@ -13,13 +13,13 @@ import { CriteriaFn } from '../core/types.cjs';
|
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```typescript
|
|
16
|
-
* import { rule, not } from '@
|
|
17
|
-
* import { ipCidr } from '@
|
|
18
|
-
* import { redirect, constructResponse } from '@
|
|
16
|
+
* import { rule, not } from '@rayselfs/cf-rule-engine'
|
|
17
|
+
* import { ipCidr } from '@rayselfs/cf-rule-engine/criteria'
|
|
18
|
+
* import { redirect, constructResponse } from '@rayselfs/cf-rule-engine/behaviors'
|
|
19
19
|
*
|
|
20
20
|
* // Block traffic not originating from internal networks
|
|
21
21
|
* rule(not(ipCidr(['10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16'])),
|
|
22
|
-
* redirect(302, 'https://www.
|
|
22
|
+
* redirect(302, 'https://www.example.com'))
|
|
23
23
|
*
|
|
24
24
|
* // Allow only specific office IPs
|
|
25
25
|
* rule(not(ipCidr(['61.218.44.76/32', '122.147.213.24/32'])),
|
|
@@ -13,13 +13,13 @@ import { CriteriaFn } from '../core/types.js';
|
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```typescript
|
|
16
|
-
* import { rule, not } from '@
|
|
17
|
-
* import { ipCidr } from '@
|
|
18
|
-
* import { redirect, constructResponse } from '@
|
|
16
|
+
* import { rule, not } from '@rayselfs/cf-rule-engine'
|
|
17
|
+
* import { ipCidr } from '@rayselfs/cf-rule-engine/criteria'
|
|
18
|
+
* import { redirect, constructResponse } from '@rayselfs/cf-rule-engine/behaviors'
|
|
19
19
|
*
|
|
20
20
|
* // Block traffic not originating from internal networks
|
|
21
21
|
* rule(not(ipCidr(['10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16'])),
|
|
22
|
-
* redirect(302, 'https://www.
|
|
22
|
+
* redirect(302, 'https://www.example.com'))
|
|
23
23
|
*
|
|
24
24
|
* // Allow only specific office IPs
|
|
25
25
|
* rule(not(ipCidr(['61.218.44.76/32', '122.147.213.24/32'])),
|
|
@@ -12,9 +12,9 @@ import { CriteriaFn } from '../core/types.cjs';
|
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```typescript
|
|
15
|
-
* import { rule } from '@
|
|
16
|
-
* import { methodIs } from '@
|
|
17
|
-
* import { constructResponse } from '@
|
|
15
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
16
|
+
* import { methodIs } from '@rayselfs/cf-rule-engine/criteria'
|
|
17
|
+
* import { constructResponse } from '@rayselfs/cf-rule-engine/behaviors'
|
|
18
18
|
*
|
|
19
19
|
* // Respond immediately to OPTIONS preflight requests
|
|
20
20
|
* rule(methodIs(['OPTIONS']), constructResponse({ statusCode: 200, body: '' }))
|
|
@@ -12,9 +12,9 @@ import { CriteriaFn } from '../core/types.js';
|
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```typescript
|
|
15
|
-
* import { rule } from '@
|
|
16
|
-
* import { methodIs } from '@
|
|
17
|
-
* import { constructResponse } from '@
|
|
15
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
16
|
+
* import { methodIs } from '@rayselfs/cf-rule-engine/criteria'
|
|
17
|
+
* import { constructResponse } from '@rayselfs/cf-rule-engine/behaviors'
|
|
18
18
|
*
|
|
19
19
|
* // Respond immediately to OPTIONS preflight requests
|
|
20
20
|
* rule(methodIs(['OPTIONS']), constructResponse({ statusCode: 200, body: '' }))
|
|
@@ -14,17 +14,17 @@ import { CriteriaFn } from '../core/types.cjs';
|
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```typescript
|
|
17
|
-
* import { rule, not } from '@
|
|
18
|
-
* import { userAgentMatches } from '@
|
|
19
|
-
* import { redirect, constructResponse } from '@
|
|
17
|
+
* import { rule, not } from '@rayselfs/cf-rule-engine'
|
|
18
|
+
* import { userAgentMatches } from '@rayselfs/cf-rule-engine/criteria'
|
|
19
|
+
* import { redirect, constructResponse } from '@rayselfs/cf-rule-engine/behaviors'
|
|
20
20
|
*
|
|
21
21
|
* // Block known scraper bots
|
|
22
22
|
* rule(userAgentMatches(['*SemrushBot*', '*AhrefsBot*', '*MJ12bot*']),
|
|
23
23
|
* constructResponse({ statusCode: 403, body: 'Forbidden' }))
|
|
24
24
|
*
|
|
25
|
-
* // Allow only
|
|
26
|
-
* rule(not(userAgentMatches(['*
|
|
27
|
-
* redirect(302, 'https://www.
|
|
25
|
+
* // Allow only internal automation tools (stage environment)
|
|
26
|
+
* rule(not(userAgentMatches(['*MYBOT*', '*Prerender*', '*PARTNER*'])),
|
|
27
|
+
* redirect(302, 'https://www.example.com'))
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
30
|
declare function userAgentMatches(patterns: string[]): CriteriaFn;
|
|
@@ -14,17 +14,17 @@ import { CriteriaFn } from '../core/types.js';
|
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```typescript
|
|
17
|
-
* import { rule, not } from '@
|
|
18
|
-
* import { userAgentMatches } from '@
|
|
19
|
-
* import { redirect, constructResponse } from '@
|
|
17
|
+
* import { rule, not } from '@rayselfs/cf-rule-engine'
|
|
18
|
+
* import { userAgentMatches } from '@rayselfs/cf-rule-engine/criteria'
|
|
19
|
+
* import { redirect, constructResponse } from '@rayselfs/cf-rule-engine/behaviors'
|
|
20
20
|
*
|
|
21
21
|
* // Block known scraper bots
|
|
22
22
|
* rule(userAgentMatches(['*SemrushBot*', '*AhrefsBot*', '*MJ12bot*']),
|
|
23
23
|
* constructResponse({ statusCode: 403, body: 'Forbidden' }))
|
|
24
24
|
*
|
|
25
|
-
* // Allow only
|
|
26
|
-
* rule(not(userAgentMatches(['*
|
|
27
|
-
* redirect(302, 'https://www.
|
|
25
|
+
* // Allow only internal automation tools (stage environment)
|
|
26
|
+
* rule(not(userAgentMatches(['*MYBOT*', '*Prerender*', '*PARTNER*'])),
|
|
27
|
+
* redirect(302, 'https://www.example.com'))
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
30
|
declare function userAgentMatches(patterns: string[]): CriteriaFn;
|
package/dist/helpers/index.d.cts
CHANGED
|
@@ -19,12 +19,12 @@ import '../behaviors/set-cors-headers.cjs';
|
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
21
21
|
* ```ts
|
|
22
|
-
* import { setCorsHeaders } from '@
|
|
23
|
-
* import { stagingIndicator } from '@
|
|
24
|
-
* import { defineViewerResponse } from '@
|
|
22
|
+
* import { setCorsHeaders } from '@rayselfs/cf-rule-engine/behaviors'
|
|
23
|
+
* import { stagingIndicator } from '@rayselfs/cf-rule-engine/helpers'
|
|
24
|
+
* import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
25
25
|
*
|
|
26
26
|
* export default defineViewerResponse([
|
|
27
|
-
* setCorsHeaders({ allowedOrigins: ['https://www.
|
|
27
|
+
* setCorsHeaders({ allowedOrigins: ['https://www.example.com'] }),
|
|
28
28
|
* stagingIndicator(),
|
|
29
29
|
* ])
|
|
30
30
|
* ```
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -19,12 +19,12 @@ import '../behaviors/set-cors-headers.js';
|
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
21
21
|
* ```ts
|
|
22
|
-
* import { setCorsHeaders } from '@
|
|
23
|
-
* import { stagingIndicator } from '@
|
|
24
|
-
* import { defineViewerResponse } from '@
|
|
22
|
+
* import { setCorsHeaders } from '@rayselfs/cf-rule-engine/behaviors'
|
|
23
|
+
* import { stagingIndicator } from '@rayselfs/cf-rule-engine/helpers'
|
|
24
|
+
* import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
25
25
|
*
|
|
26
26
|
* export default defineViewerResponse([
|
|
27
|
-
* setCorsHeaders({ allowedOrigins: ['https://www.
|
|
27
|
+
* setCorsHeaders({ allowedOrigins: ['https://www.example.com'] }),
|
|
28
28
|
* stagingIndicator(),
|
|
29
29
|
* ])
|
|
30
30
|
* ```
|
|
@@ -9,10 +9,10 @@ import { CorsOptions } from '../behaviors/set-cors-headers.cjs';
|
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
12
|
-
* import { preflightRequest } from '@
|
|
13
|
-
* import { setCorsHeaders } from '@
|
|
14
|
-
* import { defineViewerRequest, defineViewerResponse } from '@
|
|
15
|
-
* import type { CorsOptions } from '@
|
|
12
|
+
* import { preflightRequest } from '@rayselfs/cf-rule-engine/helpers'
|
|
13
|
+
* import { setCorsHeaders } from '@rayselfs/cf-rule-engine/behaviors'
|
|
14
|
+
* import { defineViewerRequest, defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
15
|
+
* import type { CorsOptions } from '@rayselfs/cf-rule-engine/behaviors'
|
|
16
16
|
*
|
|
17
17
|
* const CORS: CorsOptions = {
|
|
18
18
|
* allowedOrigins: ['*'],
|
|
@@ -9,10 +9,10 @@ import { CorsOptions } from '../behaviors/set-cors-headers.js';
|
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
12
|
-
* import { preflightRequest } from '@
|
|
13
|
-
* import { setCorsHeaders } from '@
|
|
14
|
-
* import { defineViewerRequest, defineViewerResponse } from '@
|
|
15
|
-
* import type { CorsOptions } from '@
|
|
12
|
+
* import { preflightRequest } from '@rayselfs/cf-rule-engine/helpers'
|
|
13
|
+
* import { setCorsHeaders } from '@rayselfs/cf-rule-engine/behaviors'
|
|
14
|
+
* import { defineViewerRequest, defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
15
|
+
* import type { CorsOptions } from '@rayselfs/cf-rule-engine/behaviors'
|
|
16
16
|
*
|
|
17
17
|
* const CORS: CorsOptions = {
|
|
18
18
|
* allowedOrigins: ['*'],
|
|
@@ -6,20 +6,20 @@ import { BehaviorFn } from '../core/types.cjs';
|
|
|
6
6
|
*
|
|
7
7
|
* CloudFront sets `CloudFront-Viewer-Country` to the ISO 3166-1 alpha-2 country code
|
|
8
8
|
* of the viewer (e.g. `'US'`, `'TW'`, `'JP'`). This helper copies it to the header name
|
|
9
|
-
* your origin expects, defaulting to `'x-
|
|
9
|
+
* your origin expects, defaulting to `'x-viewer-country'`.
|
|
10
10
|
*
|
|
11
11
|
* Note: The `CloudFront-Viewer-Country` header must be enabled in the CloudFront
|
|
12
12
|
* cache policy (under "Headers") for the origin behavior.
|
|
13
13
|
*
|
|
14
14
|
* @param targetHeader - The request header to copy the country code into.
|
|
15
|
-
* Default: `'x-
|
|
15
|
+
* Default: `'x-viewer-country'`.
|
|
16
16
|
* @returns A `BehaviorFn` to use as the second argument to `rule()`.
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
19
|
* ```ts
|
|
20
|
-
* import { sendCountryCode } from '@
|
|
21
|
-
* import { rule } from '@
|
|
22
|
-
* import { defineViewerRequest } from '@
|
|
20
|
+
* import { sendCountryCode } from '@rayselfs/cf-rule-engine/helpers'
|
|
21
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
22
|
+
* import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
23
23
|
*
|
|
24
24
|
* export default defineViewerRequest([
|
|
25
25
|
* // Forward country code using the default header name
|
|
@@ -6,20 +6,20 @@ import { BehaviorFn } from '../core/types.js';
|
|
|
6
6
|
*
|
|
7
7
|
* CloudFront sets `CloudFront-Viewer-Country` to the ISO 3166-1 alpha-2 country code
|
|
8
8
|
* of the viewer (e.g. `'US'`, `'TW'`, `'JP'`). This helper copies it to the header name
|
|
9
|
-
* your origin expects, defaulting to `'x-
|
|
9
|
+
* your origin expects, defaulting to `'x-viewer-country'`.
|
|
10
10
|
*
|
|
11
11
|
* Note: The `CloudFront-Viewer-Country` header must be enabled in the CloudFront
|
|
12
12
|
* cache policy (under "Headers") for the origin behavior.
|
|
13
13
|
*
|
|
14
14
|
* @param targetHeader - The request header to copy the country code into.
|
|
15
|
-
* Default: `'x-
|
|
15
|
+
* Default: `'x-viewer-country'`.
|
|
16
16
|
* @returns A `BehaviorFn` to use as the second argument to `rule()`.
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
19
|
* ```ts
|
|
20
|
-
* import { sendCountryCode } from '@
|
|
21
|
-
* import { rule } from '@
|
|
22
|
-
* import { defineViewerRequest } from '@
|
|
20
|
+
* import { sendCountryCode } from '@rayselfs/cf-rule-engine/helpers'
|
|
21
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
22
|
+
* import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
23
23
|
*
|
|
24
24
|
* export default defineViewerRequest([
|
|
25
25
|
* // Forward country code using the default header name
|
|
@@ -47,8 +47,8 @@ interface StagingWhitelistOptions {
|
|
|
47
47
|
*
|
|
48
48
|
* @example
|
|
49
49
|
* ```ts
|
|
50
|
-
* import { stagingWhitelist } from '@
|
|
51
|
-
* import { defineViewerRequest } from '@
|
|
50
|
+
* import { stagingWhitelist } from '@rayselfs/cf-rule-engine/helpers'
|
|
51
|
+
* import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
52
52
|
*
|
|
53
53
|
* export default defineViewerRequest([
|
|
54
54
|
* stagingWhitelist({
|
|
@@ -47,8 +47,8 @@ interface StagingWhitelistOptions {
|
|
|
47
47
|
*
|
|
48
48
|
* @example
|
|
49
49
|
* ```ts
|
|
50
|
-
* import { stagingWhitelist } from '@
|
|
51
|
-
* import { defineViewerRequest } from '@
|
|
50
|
+
* import { stagingWhitelist } from '@rayselfs/cf-rule-engine/helpers'
|
|
51
|
+
* import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/cf-function'
|
|
52
52
|
*
|
|
53
53
|
* export default defineViewerRequest([
|
|
54
54
|
* stagingWhitelist({
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
4
|
-
export { l as lambdaEdge } from './lambda-edge-
|
|
3
|
+
export { c as cfFunction } from './cf-function-DIQHy8L7.cjs';
|
|
4
|
+
export { l as lambdaEdge } from './lambda-edge-9xiONGmR.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
4
|
-
export { l as lambdaEdge } from './lambda-edge-
|
|
3
|
+
export { c as cfFunction } from './cf-function-C9eF2O9s.js';
|
|
4
|
+
export { l as lambdaEdge } from './lambda-edge-BK3-bFx8.js';
|
|
@@ -18,9 +18,9 @@ import { Rule, ResponseBehaviorFn, ResponseRule } from './core/types.cjs';
|
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* ```ts
|
|
21
|
-
* import { rule } from '@
|
|
22
|
-
* import { verifyToken, stripQueryParams } from '@
|
|
23
|
-
* import { defineViewerRequest } from '@
|
|
21
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
22
|
+
* import { verifyToken, stripQueryParams } from '@rayselfs/cf-rule-engine/behaviors'
|
|
23
|
+
* import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/lambda-edge'
|
|
24
24
|
*
|
|
25
25
|
* export const handler = defineViewerRequest([
|
|
26
26
|
* rule(verifyToken({ key: process.env.EDGE_AUTH_KEY! })),
|
|
@@ -46,12 +46,12 @@ declare function defineViewerRequest(rules: Rule[]): (event: unknown) => unknown
|
|
|
46
46
|
*
|
|
47
47
|
* @example
|
|
48
48
|
* ```ts
|
|
49
|
-
* import { setSecurityHeaders, setCorsHeaders } from '@
|
|
50
|
-
* import { defineViewerResponse } from '@
|
|
49
|
+
* import { setSecurityHeaders, setCorsHeaders } from '@rayselfs/cf-rule-engine/behaviors'
|
|
50
|
+
* import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/lambda-edge'
|
|
51
51
|
*
|
|
52
52
|
* export const handler = defineViewerResponse([
|
|
53
53
|
* setSecurityHeaders(),
|
|
54
|
-
* setCorsHeaders({ allowedOrigins: ['https://www.
|
|
54
|
+
* setCorsHeaders({ allowedOrigins: ['https://www.example.com'], allowOriginEcho: true }),
|
|
55
55
|
* ])
|
|
56
56
|
* ```
|
|
57
57
|
*/
|
|
@@ -18,9 +18,9 @@ import { Rule, ResponseBehaviorFn, ResponseRule } from './core/types.js';
|
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* ```ts
|
|
21
|
-
* import { rule } from '@
|
|
22
|
-
* import { verifyToken, stripQueryParams } from '@
|
|
23
|
-
* import { defineViewerRequest } from '@
|
|
21
|
+
* import { rule } from '@rayselfs/cf-rule-engine'
|
|
22
|
+
* import { verifyToken, stripQueryParams } from '@rayselfs/cf-rule-engine/behaviors'
|
|
23
|
+
* import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/lambda-edge'
|
|
24
24
|
*
|
|
25
25
|
* export const handler = defineViewerRequest([
|
|
26
26
|
* rule(verifyToken({ key: process.env.EDGE_AUTH_KEY! })),
|
|
@@ -46,12 +46,12 @@ declare function defineViewerRequest(rules: Rule[]): (event: unknown) => unknown
|
|
|
46
46
|
*
|
|
47
47
|
* @example
|
|
48
48
|
* ```ts
|
|
49
|
-
* import { setSecurityHeaders, setCorsHeaders } from '@
|
|
50
|
-
* import { defineViewerResponse } from '@
|
|
49
|
+
* import { setSecurityHeaders, setCorsHeaders } from '@rayselfs/cf-rule-engine/behaviors'
|
|
50
|
+
* import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/lambda-edge'
|
|
51
51
|
*
|
|
52
52
|
* export const handler = defineViewerResponse([
|
|
53
53
|
* setSecurityHeaders(),
|
|
54
|
-
* setCorsHeaders({ allowedOrigins: ['https://www.
|
|
54
|
+
* setCorsHeaders({ allowedOrigins: ['https://www.example.com'], allowOriginEcho: true }),
|
|
55
55
|
* ])
|
|
56
56
|
* ```
|
|
57
57
|
*/
|