@rayselfs/cf-rule-engine 1.5.0 → 1.6.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 +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/image-optimize.cjs +2 -2
- package/dist/behaviors/image-optimize.d.cts +19 -7
- package/dist/behaviors/image-optimize.d.ts +19 -7
- package/dist/behaviors/image-optimize.js +1 -1
- package/dist/behaviors/index.cjs +2 -2
- package/dist/behaviors/index.d.cts +1 -1
- package/dist/behaviors/index.d.ts +1 -1
- package/dist/behaviors/index.js +1 -1
- 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/{chunk-TQLJIT4H.cjs → chunk-KXC6ES3B.cjs} +6 -5
- package/dist/{chunk-5PT5X62W.js → chunk-LQRLWDQQ.js} +6 -5
- 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/index.cjs +3 -3
- package/dist/criteria/index.js +3 -3
- 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()),
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkKXC6ES3Bcjs = require('../chunk-KXC6ES3B.cjs');
|
|
5
5
|
require('../chunk-75ZPJI57.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
exports.imageOptimize =
|
|
9
|
+
exports.imageOptimize = _chunkKXC6ES3Bcjs.imageOptimize; exports.resolveImageParams = _chunkKXC6ES3Bcjs.resolveImageParams;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HttpRequest, BehaviorFn } from '../core/types.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Origin configuration for image-optimize-proxy.
|
|
@@ -15,6 +15,15 @@ type ImageOriginConfig = {
|
|
|
15
15
|
type: 's3';
|
|
16
16
|
sourceBucket: string;
|
|
17
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Origin resolver — either a static config or a function that resolves
|
|
20
|
+
* the origin per-request. When a function is provided, it receives the
|
|
21
|
+
* normalized request and may return `undefined` to skip origin header injection.
|
|
22
|
+
*
|
|
23
|
+
* Use the function form for conditional routing (e.g., some paths → S3,
|
|
24
|
+
* others → gateway) within a single imageOptimize() call.
|
|
25
|
+
*/
|
|
26
|
+
type ImageOriginResolver = ImageOriginConfig | ((request: HttpRequest) => ImageOriginConfig | undefined);
|
|
18
27
|
/**
|
|
19
28
|
* Options for imageOptimize querystring normalization behavior.
|
|
20
29
|
*
|
|
@@ -36,11 +45,14 @@ interface ImageOptimizeOptions {
|
|
|
36
45
|
imformatParam?: string;
|
|
37
46
|
/**
|
|
38
47
|
* Origin configuration for image-optimize-proxy.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
* When provided, injects the corresponding X-Img-* request headers so the
|
|
49
|
+
* proxy knows how to resolve the source image. This removes the need to
|
|
50
|
+
* configure CloudFront origin custom headers separately in Terraform.
|
|
51
|
+
*
|
|
52
|
+
* Accepts either a static config object or a resolver function that receives
|
|
53
|
+
* the request and returns the appropriate origin (or undefined to skip).
|
|
54
|
+
*/
|
|
55
|
+
origin?: ImageOriginResolver;
|
|
44
56
|
/**
|
|
45
57
|
* CloudFront origin verification secret.
|
|
46
58
|
* When provided, injects the value as the X-Origin-Verify request header.
|
|
@@ -100,4 +112,4 @@ declare function resolveImageParams(request: Pick<HttpRequest, 'querystring' | '
|
|
|
100
112
|
*/
|
|
101
113
|
declare function imageOptimize(options: ImageOptimizeOptions): BehaviorFn;
|
|
102
114
|
|
|
103
|
-
export { type ImageOptimizeOptions, type ImageOriginConfig, type ResolvedImageParams, imageOptimize, resolveImageParams };
|
|
115
|
+
export { type ImageOptimizeOptions, type ImageOriginConfig, type ImageOriginResolver, type ResolvedImageParams, imageOptimize, resolveImageParams };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HttpRequest, BehaviorFn } from '../core/types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Origin configuration for image-optimize-proxy.
|
|
@@ -15,6 +15,15 @@ type ImageOriginConfig = {
|
|
|
15
15
|
type: 's3';
|
|
16
16
|
sourceBucket: string;
|
|
17
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Origin resolver — either a static config or a function that resolves
|
|
20
|
+
* the origin per-request. When a function is provided, it receives the
|
|
21
|
+
* normalized request and may return `undefined` to skip origin header injection.
|
|
22
|
+
*
|
|
23
|
+
* Use the function form for conditional routing (e.g., some paths → S3,
|
|
24
|
+
* others → gateway) within a single imageOptimize() call.
|
|
25
|
+
*/
|
|
26
|
+
type ImageOriginResolver = ImageOriginConfig | ((request: HttpRequest) => ImageOriginConfig | undefined);
|
|
18
27
|
/**
|
|
19
28
|
* Options for imageOptimize querystring normalization behavior.
|
|
20
29
|
*
|
|
@@ -36,11 +45,14 @@ interface ImageOptimizeOptions {
|
|
|
36
45
|
imformatParam?: string;
|
|
37
46
|
/**
|
|
38
47
|
* Origin configuration for image-optimize-proxy.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
* When provided, injects the corresponding X-Img-* request headers so the
|
|
49
|
+
* proxy knows how to resolve the source image. This removes the need to
|
|
50
|
+
* configure CloudFront origin custom headers separately in Terraform.
|
|
51
|
+
*
|
|
52
|
+
* Accepts either a static config object or a resolver function that receives
|
|
53
|
+
* the request and returns the appropriate origin (or undefined to skip).
|
|
54
|
+
*/
|
|
55
|
+
origin?: ImageOriginResolver;
|
|
44
56
|
/**
|
|
45
57
|
* CloudFront origin verification secret.
|
|
46
58
|
* When provided, injects the value as the X-Origin-Verify request header.
|
|
@@ -100,4 +112,4 @@ declare function resolveImageParams(request: Pick<HttpRequest, 'querystring' | '
|
|
|
100
112
|
*/
|
|
101
113
|
declare function imageOptimize(options: ImageOptimizeOptions): BehaviorFn;
|
|
102
114
|
|
|
103
|
-
export { type ImageOptimizeOptions, type ImageOriginConfig, type ResolvedImageParams, imageOptimize, resolveImageParams };
|
|
115
|
+
export { type ImageOptimizeOptions, type ImageOriginConfig, type ImageOriginResolver, type ResolvedImageParams, imageOptimize, resolveImageParams };
|
package/dist/behaviors/index.cjs
CHANGED
|
@@ -39,7 +39,7 @@ var _chunkJU5WX5RUcjs = require('../chunk-JU5WX5RU.cjs');
|
|
|
39
39
|
var _chunkLTLBEBKLcjs = require('../chunk-LTLBEBKL.cjs');
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
var
|
|
42
|
+
var _chunkKXC6ES3Bcjs = require('../chunk-KXC6ES3B.cjs');
|
|
43
43
|
require('../chunk-75ZPJI57.cjs');
|
|
44
44
|
|
|
45
45
|
// src/behaviors/verify-token.ts
|
|
@@ -123,4 +123,4 @@ function verifyToken(options) {
|
|
|
123
123
|
|
|
124
124
|
|
|
125
125
|
|
|
126
|
-
exports.constructResponse = _chunkOSGZTNTScjs.constructResponse; exports.copyHeader = _chunkJU5WX5RUcjs.copyHeader; exports.directoryIndex = _chunkLTLBEBKLcjs.directoryIndex; exports.imageOptimize =
|
|
126
|
+
exports.constructResponse = _chunkOSGZTNTScjs.constructResponse; exports.copyHeader = _chunkJU5WX5RUcjs.copyHeader; exports.directoryIndex = _chunkLTLBEBKLcjs.directoryIndex; exports.imageOptimize = _chunkKXC6ES3Bcjs.imageOptimize; exports.redirect = _chunkWWSRNCUPcjs.redirect; exports.removeResponseHeaders = _chunkSGEBNQR2cjs.removeResponseHeaders; exports.rewriteUri = _chunkMRPTC74Icjs.rewriteUri; exports.setCacheControl = _chunkCV234DQTcjs.setCacheControl; exports.setCorsHeaders = _chunkGK5JX7OMcjs.setCorsHeaders; exports.setCsp = _chunkZXS23HXAcjs.setCsp; exports.setRequestHeader = _chunkPPUHEL4Hcjs.setRequestHeader; exports.setResponseHeader = _chunkB4WEJSEZcjs.setResponseHeader; exports.setSecurityHeaders = _chunkUI6LKDJIcjs.setSecurityHeaders; exports.stripQueryParams = _chunkMSES76XKcjs.stripQueryParams; exports.verifyToken = verifyToken;
|
|
@@ -11,7 +11,7 @@ export { stripQueryParams } from './strip-query-params.cjs';
|
|
|
11
11
|
export { CspOptions, setCsp } from './set-csp.cjs';
|
|
12
12
|
export { setCacheControl } from './set-cache-control.cjs';
|
|
13
13
|
export { SecurityHeadersOptions, setSecurityHeaders } from './set-security-headers.cjs';
|
|
14
|
-
export { ImageOptimizeOptions, imageOptimize } from './image-optimize.cjs';
|
|
14
|
+
export { ImageOptimizeOptions, ImageOriginConfig, ImageOriginResolver, imageOptimize } from './image-optimize.cjs';
|
|
15
15
|
import { BehaviorFn } from '../core/types.cjs';
|
|
16
16
|
export { ResponseBehaviorFn, ResponseRule } from '../core/types.cjs';
|
|
17
17
|
|
|
@@ -11,7 +11,7 @@ export { stripQueryParams } from './strip-query-params.js';
|
|
|
11
11
|
export { CspOptions, setCsp } from './set-csp.js';
|
|
12
12
|
export { setCacheControl } from './set-cache-control.js';
|
|
13
13
|
export { SecurityHeadersOptions, setSecurityHeaders } from './set-security-headers.js';
|
|
14
|
-
export { ImageOptimizeOptions, imageOptimize } from './image-optimize.js';
|
|
14
|
+
export { ImageOptimizeOptions, ImageOriginConfig, ImageOriginResolver, imageOptimize } from './image-optimize.js';
|
|
15
15
|
import { BehaviorFn } from '../core/types.js';
|
|
16
16
|
export { ResponseBehaviorFn, ResponseRule } from '../core/types.js';
|
|
17
17
|
|
package/dist/behaviors/index.js
CHANGED
|
@@ -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']))
|