@rayselfs/cf-rule-engine 1.5.1 → 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.
@@ -1,9 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunkTQLJIT4Hcjs = require('../chunk-TQLJIT4H.cjs');
4
+ var _chunkKXC6ES3Bcjs = require('../chunk-KXC6ES3B.cjs');
5
5
  require('../chunk-75ZPJI57.cjs');
6
6
 
7
7
 
8
8
 
9
- exports.imageOptimize = _chunkTQLJIT4Hcjs.imageOptimize; exports.resolveImageParams = _chunkTQLJIT4Hcjs.resolveImageParams;
9
+ exports.imageOptimize = _chunkKXC6ES3Bcjs.imageOptimize; exports.resolveImageParams = _chunkKXC6ES3Bcjs.resolveImageParams;
@@ -1,4 +1,4 @@
1
- import { BehaviorFn, HttpRequest } from '../core/types.cjs';
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
- * When provided, injects the corresponding X-Img-* request headers so the
40
- * proxy knows how to resolve the source image. This removes the need to
41
- * configure CloudFront origin custom headers separately in Terraform.
42
- */
43
- origin?: ImageOriginConfig;
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 { BehaviorFn, HttpRequest } from '../core/types.js';
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
- * When provided, injects the corresponding X-Img-* request headers so the
40
- * proxy knows how to resolve the source image. This removes the need to
41
- * configure CloudFront origin custom headers separately in Terraform.
42
- */
43
- origin?: ImageOriginConfig;
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,7 +1,7 @@
1
1
  import {
2
2
  imageOptimize,
3
3
  resolveImageParams
4
- } from "../chunk-5PT5X62W.js";
4
+ } from "../chunk-LQRLWDQQ.js";
5
5
  import "../chunk-MLKGABMK.js";
6
6
  export {
7
7
  imageOptimize,
@@ -39,7 +39,7 @@ var _chunkJU5WX5RUcjs = require('../chunk-JU5WX5RU.cjs');
39
39
  var _chunkLTLBEBKLcjs = require('../chunk-LTLBEBKL.cjs');
40
40
 
41
41
 
42
- var _chunkTQLJIT4Hcjs = require('../chunk-TQLJIT4H.cjs');
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 = _chunkTQLJIT4Hcjs.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;
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
 
@@ -39,7 +39,7 @@ import {
39
39
  } from "../chunk-R7WXS7BI.js";
40
40
  import {
41
41
  imageOptimize
42
- } from "../chunk-5PT5X62W.js";
42
+ } from "../chunk-LQRLWDQQ.js";
43
43
  import "../chunk-MLKGABMK.js";
44
44
 
45
45
  // src/behaviors/verify-token.ts
@@ -77,12 +77,13 @@ function imageOptimize(options) {
77
77
  delete qs["imformat"];
78
78
  }
79
79
  var headers = Object.assign({}, request.headers);
80
- if (options.origin !== void 0) {
81
- headers["x-img-source-type"] = { value: options.origin.type };
82
- if (options.origin.type === "gateway") {
83
- headers["x-img-upstream-gateway"] = { value: options.origin.upstreamGateway };
80
+ var resolvedOrigin = typeof options.origin === "function" ? options.origin(request) : options.origin;
81
+ if (resolvedOrigin !== void 0) {
82
+ headers["x-img-source-type"] = { value: resolvedOrigin.type };
83
+ if (resolvedOrigin.type === "gateway") {
84
+ headers["x-img-upstream-gateway"] = { value: resolvedOrigin.upstreamGateway };
84
85
  } else {
85
- headers["x-img-source-bucket"] = { value: options.origin.sourceBucket };
86
+ headers["x-img-source-bucket"] = { value: resolvedOrigin.sourceBucket };
86
87
  }
87
88
  }
88
89
  if (options.originSecret !== void 0) {
@@ -77,12 +77,13 @@ function imageOptimize(options) {
77
77
  delete qs["imformat"];
78
78
  }
79
79
  var headers = Object.assign({}, request.headers);
80
- if (options.origin !== void 0) {
81
- headers["x-img-source-type"] = { value: options.origin.type };
82
- if (options.origin.type === "gateway") {
83
- headers["x-img-upstream-gateway"] = { value: options.origin.upstreamGateway };
80
+ var resolvedOrigin = typeof options.origin === "function" ? options.origin(request) : options.origin;
81
+ if (resolvedOrigin !== void 0) {
82
+ headers["x-img-source-type"] = { value: resolvedOrigin.type };
83
+ if (resolvedOrigin.type === "gateway") {
84
+ headers["x-img-upstream-gateway"] = { value: resolvedOrigin.upstreamGateway };
84
85
  } else {
85
- headers["x-img-source-bucket"] = { value: options.origin.sourceBucket };
86
+ headers["x-img-source-bucket"] = { value: resolvedOrigin.sourceBucket };
86
87
  }
87
88
  }
88
89
  if (options.originSecret !== void 0) {
@@ -1,8 +1,5 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkJGJW7D2Ncjs = require('../chunk-JGJW7D2N.cjs');
4
-
5
-
6
3
  var _chunkD47P7HVZcjs = require('../chunk-D47P7HVZ.cjs');
7
4
  require('../chunk-YVUR35RN.cjs');
8
5
 
@@ -33,6 +30,9 @@ var _chunk32SMWYAFcjs = require('../chunk-32SMWYAF.cjs');
33
30
 
34
31
 
35
32
  var _chunkL7NBJ4JAcjs = require('../chunk-L7NBJ4JA.cjs');
33
+
34
+
35
+ var _chunkJGJW7D2Ncjs = require('../chunk-JGJW7D2N.cjs');
36
36
  require('../chunk-75ZPJI57.cjs');
37
37
 
38
38
 
@@ -1,6 +1,3 @@
1
- import {
2
- hostnameIs
3
- } from "../chunk-3PVDUC5M.js";
4
1
  import {
5
2
  ipCidr
6
3
  } from "../chunk-KW5YBTSD.js";
@@ -33,6 +30,9 @@ import {
33
30
  import {
34
31
  headerEquals
35
32
  } from "../chunk-BZQJYOU2.js";
33
+ import {
34
+ hostnameIs
35
+ } from "../chunk-3PVDUC5M.js";
36
36
  import "../chunk-MLKGABMK.js";
37
37
  export {
38
38
  countryIs,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rayselfs/cf-rule-engine",
3
- "version": "1.5.1",
3
+ "version": "1.6.0",
4
4
  "description": "Composable, tree-shakeable CloudFront Function rules",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,