@rayselfs/cf-rule-engine 1.6.1 → 1.6.2
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 +5 -3
- package/dist/adapters/cf-function.cjs +7 -3
- package/dist/adapters/cf-function.d.cts +2 -1
- package/dist/adapters/cf-function.d.ts +2 -1
- package/dist/adapters/cf-function.js +7 -3
- package/dist/adapters/viewer-request.cjs +3 -2
- package/dist/adapters/viewer-request.d.cts +31 -2
- package/dist/adapters/viewer-request.d.ts +31 -2
- package/dist/adapters/viewer-request.js +2 -1
- package/dist/adapters/viewer-response.cjs +3 -3
- package/dist/adapters/viewer-response.d.cts +37 -2
- package/dist/adapters/viewer-response.d.ts +37 -2
- package/dist/adapters/viewer-response.js +2 -2
- package/dist/cf-function-BkfWpTfl.d.cts +10 -0
- package/dist/cf-function-CZwCWch-.d.ts +10 -0
- package/dist/chunk-5ZIB3AJ7.cjs +20 -0
- package/dist/chunk-6NFAPLQ7.cjs +39 -0
- package/dist/chunk-BJZPAQHW.js +25 -0
- package/dist/chunk-CQ7YZ3AR.js +39 -0
- package/dist/chunk-N6QAQALU.cjs +36 -0
- package/dist/chunk-PR5UQJCC.js +20 -0
- package/dist/chunk-SGN2N3WI.cjs +25 -0
- package/dist/chunk-TURH5IFN.js +36 -0
- package/dist/index.cjs +6 -3
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +6 -3
- package/package.json +1 -1
- package/dist/chunk-NPMGSPNL.js +0 -88
- package/dist/chunk-SAXDN5NS.cjs +0 -88
- package/dist/viewer-response-C9eF2O9s.d.ts +0 -70
- package/dist/viewer-response-DIQHy8L7.d.cts +0 -70
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ npm install @rayselfs/cf-rule-engine
|
|
|
18
18
|
import { rule, not } from '@rayselfs/cf-rule-engine'
|
|
19
19
|
import { ipCidr, methodIs } from '@rayselfs/cf-rule-engine/criteria/index'
|
|
20
20
|
import { redirect, constructResponse } from '@rayselfs/cf-rule-engine/behaviors/index'
|
|
21
|
-
import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/
|
|
21
|
+
import { defineViewerRequest } from '@rayselfs/cf-rule-engine/adapters/viewer-request'
|
|
22
22
|
|
|
23
23
|
export default defineViewerRequest([
|
|
24
24
|
rule(not(ipCidr(['10.0.0.0/8', '172.16.0.0/12'])), redirect(302, '/blocked')),
|
|
@@ -30,7 +30,7 @@ export default defineViewerRequest([
|
|
|
30
30
|
|
|
31
31
|
```typescript
|
|
32
32
|
import { setSecurityHeaders, setCorsHeaders } from '@rayselfs/cf-rule-engine/behaviors/index'
|
|
33
|
-
import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/
|
|
33
|
+
import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/viewer-response'
|
|
34
34
|
|
|
35
35
|
export default defineViewerResponse([
|
|
36
36
|
setSecurityHeaders(),
|
|
@@ -70,7 +70,9 @@ Use `chain()` when one behavior must see the request mutations (URI rewrite, hea
|
|
|
70
70
|
|
|
71
71
|
| Adapter | Import | Use for |
|
|
72
72
|
|---|---|---|
|
|
73
|
-
| CF Function | `@rayselfs/cf-rule-engine/adapters/
|
|
73
|
+
| CF Function (viewer-request) | `@rayselfs/cf-rule-engine/adapters/viewer-request` | `viewer-request` only — tree-shake-friendly |
|
|
74
|
+
| CF Function (viewer-response) | `@rayselfs/cf-rule-engine/adapters/viewer-response` | `viewer-response` only — tree-shake-friendly |
|
|
75
|
+
| CF Function (combined) | `@rayselfs/cf-rule-engine/adapters/cf-function` | both — backward compat |
|
|
74
76
|
| Lambda@Edge | `@rayselfs/cf-rule-engine/adapters/lambda-edge` | `viewer-request`, `viewer-response` |
|
|
75
77
|
|
|
76
78
|
## Akamai → CloudFront Mapping
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-5ZIB3AJ7.cjs');
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkSGN2N3WIcjs = require('../chunk-SGN2N3WI.cjs');
|
|
5
5
|
require('../chunk-WKYMSRCD.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkN6QAQALUcjs = require('../chunk-N6QAQALU.cjs');
|
|
9
|
+
require('../chunk-6NFAPLQ7.cjs');
|
|
6
10
|
require('../chunk-75ZPJI57.cjs');
|
|
7
11
|
|
|
8
12
|
|
|
9
13
|
|
|
10
|
-
exports.defineViewerRequest =
|
|
14
|
+
exports.defineViewerRequest = _chunkSGN2N3WIcjs.defineViewerRequest; exports.defineViewerResponse = _chunkN6QAQALUcjs.defineViewerResponse;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import "../chunk-PR5UQJCC.js";
|
|
1
2
|
import {
|
|
2
|
-
defineViewerRequest
|
|
3
|
-
|
|
4
|
-
} from "../chunk-NPMGSPNL.js";
|
|
3
|
+
defineViewerRequest
|
|
4
|
+
} from "../chunk-BJZPAQHW.js";
|
|
5
5
|
import "../chunk-Q4NP4C3B.js";
|
|
6
|
+
import {
|
|
7
|
+
defineViewerResponse
|
|
8
|
+
} from "../chunk-TURH5IFN.js";
|
|
9
|
+
import "../chunk-CQ7YZ3AR.js";
|
|
6
10
|
import "../chunk-MLKGABMK.js";
|
|
7
11
|
export {
|
|
8
12
|
defineViewerRequest,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkSGN2N3WIcjs = require('../chunk-SGN2N3WI.cjs');
|
|
4
4
|
require('../chunk-WKYMSRCD.cjs');
|
|
5
|
+
require('../chunk-6NFAPLQ7.cjs');
|
|
5
6
|
require('../chunk-75ZPJI57.cjs');
|
|
6
7
|
|
|
7
8
|
|
|
8
|
-
exports.defineViewerRequest =
|
|
9
|
+
exports.defineViewerRequest = _chunkSGN2N3WIcjs.defineViewerRequest;
|
|
@@ -1,2 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Rule } from '../core/types.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a CloudFront Function viewer-request handler from an ordered list of rules.
|
|
5
|
+
*
|
|
6
|
+
* The returned function is the CloudFront Function entry point. Assign it as
|
|
7
|
+
* `export default` or `var handler` depending on your runtime configuration.
|
|
8
|
+
*
|
|
9
|
+
* Rules are evaluated in order. Processing stops at the first rule whose behavior
|
|
10
|
+
* returns a response (e.g. `redirect`, `constructResponse`). If all rules continue,
|
|
11
|
+
* the (possibly mutated) request is forwarded to the origin.
|
|
12
|
+
*
|
|
13
|
+
* @param rules - Ordered array of `Rule` objects created with `rule()`.
|
|
14
|
+
* @returns A CloudFront Function handler `(event) => request | response`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
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/viewer-request'
|
|
22
|
+
*
|
|
23
|
+
* export default defineViewerRequest([
|
|
24
|
+
* rule(not(ipCidr(['10.0.0.0/8'])), redirect(302, 'https://www.example.com')),
|
|
25
|
+
* rule(pathPrefix(['/api/']), setRequestHeader('x-forwarded-host', 'api.internal')),
|
|
26
|
+
* ])
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function defineViewerRequest(rules: Rule[]): (event: unknown) => unknown;
|
|
30
|
+
|
|
31
|
+
export { defineViewerRequest };
|
|
@@ -1,2 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Rule } from '../core/types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a CloudFront Function viewer-request handler from an ordered list of rules.
|
|
5
|
+
*
|
|
6
|
+
* The returned function is the CloudFront Function entry point. Assign it as
|
|
7
|
+
* `export default` or `var handler` depending on your runtime configuration.
|
|
8
|
+
*
|
|
9
|
+
* Rules are evaluated in order. Processing stops at the first rule whose behavior
|
|
10
|
+
* returns a response (e.g. `redirect`, `constructResponse`). If all rules continue,
|
|
11
|
+
* the (possibly mutated) request is forwarded to the origin.
|
|
12
|
+
*
|
|
13
|
+
* @param rules - Ordered array of `Rule` objects created with `rule()`.
|
|
14
|
+
* @returns A CloudFront Function handler `(event) => request | response`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
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/viewer-request'
|
|
22
|
+
*
|
|
23
|
+
* export default defineViewerRequest([
|
|
24
|
+
* rule(not(ipCidr(['10.0.0.0/8'])), redirect(302, 'https://www.example.com')),
|
|
25
|
+
* rule(pathPrefix(['/api/']), setRequestHeader('x-forwarded-host', 'api.internal')),
|
|
26
|
+
* ])
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function defineViewerRequest(rules: Rule[]): (event: unknown) => unknown;
|
|
30
|
+
|
|
31
|
+
export { defineViewerRequest };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
3
|
+
var _chunkN6QAQALUcjs = require('../chunk-N6QAQALU.cjs');
|
|
4
|
+
require('../chunk-6NFAPLQ7.cjs');
|
|
5
5
|
require('../chunk-75ZPJI57.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
exports.defineViewerResponse =
|
|
8
|
+
exports.defineViewerResponse = _chunkN6QAQALUcjs.defineViewerResponse;
|
|
@@ -1,2 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { ResponseBehaviorFn, ResponseRule } from '../core/types.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a CloudFront Function viewer-response handler from an ordered list of
|
|
5
|
+
* response behaviors or response rules.
|
|
6
|
+
*
|
|
7
|
+
* Each entry can be either:
|
|
8
|
+
* - A bare `ResponseBehaviorFn` — runs unconditionally on every response.
|
|
9
|
+
* - A `ResponseRule` `{ criteria, behavior }` — runs only when `criteria` returns `true`
|
|
10
|
+
* for the current request.
|
|
11
|
+
*
|
|
12
|
+
* All behaviors are applied in order; none can short-circuit the response.
|
|
13
|
+
* The final merged response object is returned to CloudFront.
|
|
14
|
+
*
|
|
15
|
+
* Note: If no behavior explicitly sets a body, the `body` field is omitted from
|
|
16
|
+
* the returned response to avoid overwriting the origin's actual content.
|
|
17
|
+
*
|
|
18
|
+
* @param responseBehaviors - Ordered array of `ResponseBehaviorFn` functions or
|
|
19
|
+
* `ResponseRule` objects `{ criteria?, behavior }`.
|
|
20
|
+
* @returns A CloudFront Function handler `(event) => response`.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { setSecurityHeaders, setCorsHeaders, setResponseHeader } from '@rayselfs/cf-rule-engine/behaviors'
|
|
25
|
+
* import { pathPrefix } from '@rayselfs/cf-rule-engine/criteria'
|
|
26
|
+
* import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/viewer-response'
|
|
27
|
+
*
|
|
28
|
+
* export default defineViewerResponse([
|
|
29
|
+
* setSecurityHeaders(),
|
|
30
|
+
* setCorsHeaders({ allowedOrigins: ['https://www.example.com'] }),
|
|
31
|
+
* { criteria: pathPrefix(['/api/']), behavior: setResponseHeader('cache-control', 'no-store') },
|
|
32
|
+
* ])
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function defineViewerResponse(responseBehaviors: Array<ResponseBehaviorFn | ResponseRule>): (event: unknown) => unknown;
|
|
36
|
+
|
|
37
|
+
export { defineViewerResponse };
|
|
@@ -1,2 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { ResponseBehaviorFn, ResponseRule } from '../core/types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a CloudFront Function viewer-response handler from an ordered list of
|
|
5
|
+
* response behaviors or response rules.
|
|
6
|
+
*
|
|
7
|
+
* Each entry can be either:
|
|
8
|
+
* - A bare `ResponseBehaviorFn` — runs unconditionally on every response.
|
|
9
|
+
* - A `ResponseRule` `{ criteria, behavior }` — runs only when `criteria` returns `true`
|
|
10
|
+
* for the current request.
|
|
11
|
+
*
|
|
12
|
+
* All behaviors are applied in order; none can short-circuit the response.
|
|
13
|
+
* The final merged response object is returned to CloudFront.
|
|
14
|
+
*
|
|
15
|
+
* Note: If no behavior explicitly sets a body, the `body` field is omitted from
|
|
16
|
+
* the returned response to avoid overwriting the origin's actual content.
|
|
17
|
+
*
|
|
18
|
+
* @param responseBehaviors - Ordered array of `ResponseBehaviorFn` functions or
|
|
19
|
+
* `ResponseRule` objects `{ criteria?, behavior }`.
|
|
20
|
+
* @returns A CloudFront Function handler `(event) => response`.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { setSecurityHeaders, setCorsHeaders, setResponseHeader } from '@rayselfs/cf-rule-engine/behaviors'
|
|
25
|
+
* import { pathPrefix } from '@rayselfs/cf-rule-engine/criteria'
|
|
26
|
+
* import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/viewer-response'
|
|
27
|
+
*
|
|
28
|
+
* export default defineViewerResponse([
|
|
29
|
+
* setSecurityHeaders(),
|
|
30
|
+
* setCorsHeaders({ allowedOrigins: ['https://www.example.com'] }),
|
|
31
|
+
* { criteria: pathPrefix(['/api/']), behavior: setResponseHeader('cache-control', 'no-store') },
|
|
32
|
+
* ])
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function defineViewerResponse(responseBehaviors: Array<ResponseBehaviorFn | ResponseRule>): (event: unknown) => unknown;
|
|
36
|
+
|
|
37
|
+
export { defineViewerResponse };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineViewerRequest } from './adapters/viewer-request.cjs';
|
|
2
|
+
import { defineViewerResponse } from './adapters/viewer-response.cjs';
|
|
3
|
+
|
|
4
|
+
declare const cfFunction_defineViewerRequest: typeof defineViewerRequest;
|
|
5
|
+
declare const cfFunction_defineViewerResponse: typeof defineViewerResponse;
|
|
6
|
+
declare namespace cfFunction {
|
|
7
|
+
export { cfFunction_defineViewerRequest as defineViewerRequest, cfFunction_defineViewerResponse as defineViewerResponse };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { cfFunction as c };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineViewerRequest } from './adapters/viewer-request.js';
|
|
2
|
+
import { defineViewerResponse } from './adapters/viewer-response.js';
|
|
3
|
+
|
|
4
|
+
declare const cfFunction_defineViewerRequest: typeof defineViewerRequest;
|
|
5
|
+
declare const cfFunction_defineViewerResponse: typeof defineViewerResponse;
|
|
6
|
+
declare namespace cfFunction {
|
|
7
|
+
export { cfFunction_defineViewerRequest as defineViewerRequest, cfFunction_defineViewerResponse as defineViewerResponse };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { cfFunction as c };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkSGN2N3WIcjs = require('./chunk-SGN2N3WI.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkN6QAQALUcjs = require('./chunk-N6QAQALU.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunk75ZPJI57cjs = require('./chunk-75ZPJI57.cjs');
|
|
10
|
+
|
|
11
|
+
// src/adapters/cf-function.ts
|
|
12
|
+
var cf_function_exports = {};
|
|
13
|
+
_chunk75ZPJI57cjs.__export.call(void 0, cf_function_exports, {
|
|
14
|
+
defineViewerRequest: () => _chunkSGN2N3WIcjs.defineViewerRequest,
|
|
15
|
+
defineViewerResponse: () => _chunkN6QAQALUcjs.defineViewerResponse
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
exports.cf_function_exports = cf_function_exports;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/adapters/_normalize.ts
|
|
2
|
+
function normalizeRequest(event) {
|
|
3
|
+
const ev = event;
|
|
4
|
+
const req = ev.request;
|
|
5
|
+
const viewer = ev.viewer;
|
|
6
|
+
const headers = _nullishCoalesce(req.headers, () => ( {}));
|
|
7
|
+
return {
|
|
8
|
+
uri: req.uri,
|
|
9
|
+
method: req.method,
|
|
10
|
+
protocol: "https",
|
|
11
|
+
querystring: _nullishCoalesce(req.querystring, () => ( {})),
|
|
12
|
+
headers,
|
|
13
|
+
clientIp: _nullishCoalesce(_optionalChain([viewer, 'optionalAccess', _ => _.ip]), () => ( "")),
|
|
14
|
+
country: _optionalChain([headers, 'access', _2 => _2["cloudfront-viewer-country"], 'optionalAccess', _3 => _3.value])
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function denormalizeRequest(req, cookies) {
|
|
18
|
+
return {
|
|
19
|
+
method: req.method,
|
|
20
|
+
uri: req.uri,
|
|
21
|
+
querystring: req.querystring,
|
|
22
|
+
headers: req.headers,
|
|
23
|
+
cookies
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function denormalizeResponse(res) {
|
|
27
|
+
return {
|
|
28
|
+
statusCode: res.statusCode,
|
|
29
|
+
statusDescription: res.statusDescription,
|
|
30
|
+
headers: res.headers,
|
|
31
|
+
body: _nullishCoalesce(res.body, () => ( ""))
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
exports.normalizeRequest = normalizeRequest; exports.denormalizeRequest = denormalizeRequest; exports.denormalizeResponse = denormalizeResponse;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
runRules
|
|
3
|
+
} from "./chunk-Q4NP4C3B.js";
|
|
4
|
+
import {
|
|
5
|
+
denormalizeRequest,
|
|
6
|
+
denormalizeResponse,
|
|
7
|
+
normalizeRequest
|
|
8
|
+
} from "./chunk-CQ7YZ3AR.js";
|
|
9
|
+
|
|
10
|
+
// src/adapters/viewer-request.ts
|
|
11
|
+
function defineViewerRequest(rules) {
|
|
12
|
+
return (event) => {
|
|
13
|
+
const ev = event;
|
|
14
|
+
const evReq = ev.request;
|
|
15
|
+
const originalCookies = evReq.cookies ?? {};
|
|
16
|
+
const req = normalizeRequest(event);
|
|
17
|
+
const result = runRules(rules, req);
|
|
18
|
+
if (result.action === "respond") return denormalizeResponse(result.response);
|
|
19
|
+
return denormalizeRequest(result.request, originalCookies);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
defineViewerRequest
|
|
25
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/adapters/_normalize.ts
|
|
2
|
+
function normalizeRequest(event) {
|
|
3
|
+
const ev = event;
|
|
4
|
+
const req = ev.request;
|
|
5
|
+
const viewer = ev.viewer;
|
|
6
|
+
const headers = req.headers ?? {};
|
|
7
|
+
return {
|
|
8
|
+
uri: req.uri,
|
|
9
|
+
method: req.method,
|
|
10
|
+
protocol: "https",
|
|
11
|
+
querystring: req.querystring ?? {},
|
|
12
|
+
headers,
|
|
13
|
+
clientIp: viewer?.ip ?? "",
|
|
14
|
+
country: headers["cloudfront-viewer-country"]?.value
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function denormalizeRequest(req, cookies) {
|
|
18
|
+
return {
|
|
19
|
+
method: req.method,
|
|
20
|
+
uri: req.uri,
|
|
21
|
+
querystring: req.querystring,
|
|
22
|
+
headers: req.headers,
|
|
23
|
+
cookies
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function denormalizeResponse(res) {
|
|
27
|
+
return {
|
|
28
|
+
statusCode: res.statusCode,
|
|
29
|
+
statusDescription: res.statusDescription,
|
|
30
|
+
headers: res.headers,
|
|
31
|
+
body: res.body ?? ""
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
normalizeRequest,
|
|
37
|
+
denormalizeRequest,
|
|
38
|
+
denormalizeResponse
|
|
39
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunk6NFAPLQ7cjs = require('./chunk-6NFAPLQ7.cjs');
|
|
5
|
+
|
|
6
|
+
// src/adapters/viewer-response.ts
|
|
7
|
+
function defineViewerResponse(responseBehaviors) {
|
|
8
|
+
return (event) => {
|
|
9
|
+
const ev = event;
|
|
10
|
+
const evRes = ev.response;
|
|
11
|
+
const req = _chunk6NFAPLQ7cjs.normalizeRequest.call(void 0, event);
|
|
12
|
+
let response = {
|
|
13
|
+
statusCode: _nullishCoalesce(_optionalChain([evRes, 'optionalAccess', _ => _.statusCode]), () => ( 200)),
|
|
14
|
+
statusDescription: _optionalChain([evRes, 'optionalAccess', _2 => _2.statusDescription]),
|
|
15
|
+
headers: _nullishCoalesce(_optionalChain([evRes, 'optionalAccess', _3 => _3.headers]), () => ( {})),
|
|
16
|
+
body: _optionalChain([evRes, 'optionalAccess', _4 => _4.body])
|
|
17
|
+
};
|
|
18
|
+
for (let i = 0; i < responseBehaviors.length; i++) {
|
|
19
|
+
const entry = responseBehaviors[i];
|
|
20
|
+
if (typeof entry === "function") {
|
|
21
|
+
response = entry(req, response);
|
|
22
|
+
} else if (!entry.criteria || entry.criteria(req)) {
|
|
23
|
+
response = entry.behavior(req, response);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const normalized = _chunk6NFAPLQ7cjs.denormalizeResponse.call(void 0, response);
|
|
27
|
+
if (!response.body) {
|
|
28
|
+
delete normalized.body;
|
|
29
|
+
}
|
|
30
|
+
return Object.assign({}, evRes, normalized);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
exports.defineViewerResponse = defineViewerResponse;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineViewerRequest
|
|
3
|
+
} from "./chunk-BJZPAQHW.js";
|
|
4
|
+
import {
|
|
5
|
+
defineViewerResponse
|
|
6
|
+
} from "./chunk-TURH5IFN.js";
|
|
7
|
+
import {
|
|
8
|
+
__export
|
|
9
|
+
} from "./chunk-MLKGABMK.js";
|
|
10
|
+
|
|
11
|
+
// src/adapters/cf-function.ts
|
|
12
|
+
var cf_function_exports = {};
|
|
13
|
+
__export(cf_function_exports, {
|
|
14
|
+
defineViewerRequest: () => defineViewerRequest,
|
|
15
|
+
defineViewerResponse: () => defineViewerResponse
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
cf_function_exports
|
|
20
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
var _chunkWKYMSRCDcjs = require('./chunk-WKYMSRCD.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunk6NFAPLQ7cjs = require('./chunk-6NFAPLQ7.cjs');
|
|
9
|
+
|
|
10
|
+
// src/adapters/viewer-request.ts
|
|
11
|
+
function defineViewerRequest(rules) {
|
|
12
|
+
return (event) => {
|
|
13
|
+
const ev = event;
|
|
14
|
+
const evReq = ev.request;
|
|
15
|
+
const originalCookies = _nullishCoalesce(evReq.cookies, () => ( {}));
|
|
16
|
+
const req = _chunk6NFAPLQ7cjs.normalizeRequest.call(void 0, event);
|
|
17
|
+
const result = _chunkWKYMSRCDcjs.runRules.call(void 0, rules, req);
|
|
18
|
+
if (result.action === "respond") return _chunk6NFAPLQ7cjs.denormalizeResponse.call(void 0, result.response);
|
|
19
|
+
return _chunk6NFAPLQ7cjs.denormalizeRequest.call(void 0, result.request, originalCookies);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
exports.defineViewerRequest = defineViewerRequest;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
denormalizeResponse,
|
|
3
|
+
normalizeRequest
|
|
4
|
+
} from "./chunk-CQ7YZ3AR.js";
|
|
5
|
+
|
|
6
|
+
// src/adapters/viewer-response.ts
|
|
7
|
+
function defineViewerResponse(responseBehaviors) {
|
|
8
|
+
return (event) => {
|
|
9
|
+
const ev = event;
|
|
10
|
+
const evRes = ev.response;
|
|
11
|
+
const req = normalizeRequest(event);
|
|
12
|
+
let response = {
|
|
13
|
+
statusCode: evRes?.statusCode ?? 200,
|
|
14
|
+
statusDescription: evRes?.statusDescription,
|
|
15
|
+
headers: evRes?.headers ?? {},
|
|
16
|
+
body: evRes?.body
|
|
17
|
+
};
|
|
18
|
+
for (let i = 0; i < responseBehaviors.length; i++) {
|
|
19
|
+
const entry = responseBehaviors[i];
|
|
20
|
+
if (typeof entry === "function") {
|
|
21
|
+
response = entry(req, response);
|
|
22
|
+
} else if (!entry.criteria || entry.criteria(req)) {
|
|
23
|
+
response = entry.behavior(req, response);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const normalized = denormalizeResponse(response);
|
|
27
|
+
if (!response.body) {
|
|
28
|
+
delete normalized.body;
|
|
29
|
+
}
|
|
30
|
+
return Object.assign({}, evRes, normalized);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
defineViewerResponse
|
|
36
|
+
};
|
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('./chunk-MEHWLQLR.cjs');
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunk5ZIB3AJ7cjs = require('./chunk-5ZIB3AJ7.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunk3BBLG4IXcjs = require('./chunk-3BBLG4IX.cjs');
|
|
8
|
+
require('./chunk-SGN2N3WI.cjs');
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
|
|
@@ -13,6 +14,8 @@ var _chunkSAXDN5NScjs = require('./chunk-SAXDN5NS.cjs');
|
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
var _chunkWKYMSRCDcjs = require('./chunk-WKYMSRCD.cjs');
|
|
17
|
+
require('./chunk-N6QAQALU.cjs');
|
|
18
|
+
require('./chunk-6NFAPLQ7.cjs');
|
|
16
19
|
require('./chunk-75ZPJI57.cjs');
|
|
17
20
|
|
|
18
21
|
|
|
@@ -23,4 +26,4 @@ require('./chunk-75ZPJI57.cjs');
|
|
|
23
26
|
|
|
24
27
|
|
|
25
28
|
|
|
26
|
-
exports.all = _chunkWKYMSRCDcjs.all; exports.any = _chunkWKYMSRCDcjs.any; exports.cfFunction =
|
|
29
|
+
exports.all = _chunkWKYMSRCDcjs.all; exports.any = _chunkWKYMSRCDcjs.any; exports.cfFunction = _chunk5ZIB3AJ7cjs.cf_function_exports; exports.chain = _chunkWKYMSRCDcjs.chain; exports.lambdaEdge = _chunk3BBLG4IXcjs.lambda_edge_exports; exports.not = _chunkWKYMSRCDcjs.not; exports.rule = _chunkWKYMSRCDcjs.rule; exports.runRules = _chunkWKYMSRCDcjs.runRules;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
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 './
|
|
3
|
+
export { c as cfFunction } from './cf-function-BkfWpTfl.cjs';
|
|
4
4
|
export { l as lambdaEdge } from './lambda-edge-9xiONGmR.cjs';
|
|
5
|
+
import './adapters/viewer-request.cjs';
|
|
6
|
+
import './adapters/viewer-response.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
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 './
|
|
3
|
+
export { c as cfFunction } from './cf-function-CZwCWch-.js';
|
|
4
4
|
export { l as lambdaEdge } from './lambda-edge-BK3-bFx8.js';
|
|
5
|
+
import './adapters/viewer-request.js';
|
|
6
|
+
import './adapters/viewer-response.js';
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import "./chunk-KZ72PI2A.js";
|
|
2
|
+
import {
|
|
3
|
+
cf_function_exports
|
|
4
|
+
} from "./chunk-PR5UQJCC.js";
|
|
2
5
|
import {
|
|
3
6
|
lambda_edge_exports
|
|
4
7
|
} from "./chunk-WEBU4R5C.js";
|
|
5
|
-
import
|
|
6
|
-
cf_function_exports
|
|
7
|
-
} from "./chunk-NPMGSPNL.js";
|
|
8
|
+
import "./chunk-BJZPAQHW.js";
|
|
8
9
|
import {
|
|
9
10
|
all,
|
|
10
11
|
any,
|
|
@@ -13,6 +14,8 @@ import {
|
|
|
13
14
|
rule,
|
|
14
15
|
runRules
|
|
15
16
|
} from "./chunk-Q4NP4C3B.js";
|
|
17
|
+
import "./chunk-TURH5IFN.js";
|
|
18
|
+
import "./chunk-CQ7YZ3AR.js";
|
|
16
19
|
import "./chunk-MLKGABMK.js";
|
|
17
20
|
export {
|
|
18
21
|
all,
|
package/package.json
CHANGED
package/dist/chunk-NPMGSPNL.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
runRules
|
|
3
|
-
} from "./chunk-Q4NP4C3B.js";
|
|
4
|
-
import {
|
|
5
|
-
__export
|
|
6
|
-
} from "./chunk-MLKGABMK.js";
|
|
7
|
-
|
|
8
|
-
// src/adapters/cf-function.ts
|
|
9
|
-
var cf_function_exports = {};
|
|
10
|
-
__export(cf_function_exports, {
|
|
11
|
-
defineViewerRequest: () => defineViewerRequest,
|
|
12
|
-
defineViewerResponse: () => defineViewerResponse
|
|
13
|
-
});
|
|
14
|
-
function normalizeRequest(event) {
|
|
15
|
-
const ev = event;
|
|
16
|
-
const req = ev.request;
|
|
17
|
-
const viewer = ev.viewer;
|
|
18
|
-
const headers = req.headers ?? {};
|
|
19
|
-
return {
|
|
20
|
-
uri: req.uri,
|
|
21
|
-
method: req.method,
|
|
22
|
-
protocol: "https",
|
|
23
|
-
querystring: req.querystring ?? {},
|
|
24
|
-
headers,
|
|
25
|
-
clientIp: viewer?.ip ?? "",
|
|
26
|
-
country: headers["cloudfront-viewer-country"]?.value
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function denormalizeRequest(req, cookies) {
|
|
30
|
-
return {
|
|
31
|
-
method: req.method,
|
|
32
|
-
uri: req.uri,
|
|
33
|
-
querystring: req.querystring,
|
|
34
|
-
headers: req.headers,
|
|
35
|
-
cookies
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function denormalizeResponse(res) {
|
|
39
|
-
return {
|
|
40
|
-
statusCode: res.statusCode,
|
|
41
|
-
statusDescription: res.statusDescription,
|
|
42
|
-
headers: res.headers,
|
|
43
|
-
body: res.body ?? ""
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function defineViewerRequest(rules) {
|
|
47
|
-
return (event) => {
|
|
48
|
-
const ev = event;
|
|
49
|
-
const evReq = ev.request;
|
|
50
|
-
const originalCookies = evReq.cookies ?? {};
|
|
51
|
-
const req = normalizeRequest(event);
|
|
52
|
-
const result = runRules(rules, req);
|
|
53
|
-
if (result.action === "respond") return denormalizeResponse(result.response);
|
|
54
|
-
return denormalizeRequest(result.request, originalCookies);
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
function defineViewerResponse(responseBehaviors) {
|
|
58
|
-
return (event) => {
|
|
59
|
-
const ev = event;
|
|
60
|
-
const evRes = ev.response;
|
|
61
|
-
const req = normalizeRequest(event);
|
|
62
|
-
let response = {
|
|
63
|
-
statusCode: evRes?.statusCode ?? 200,
|
|
64
|
-
statusDescription: evRes?.statusDescription,
|
|
65
|
-
headers: evRes?.headers ?? {},
|
|
66
|
-
body: evRes?.body
|
|
67
|
-
};
|
|
68
|
-
for (let i = 0; i < responseBehaviors.length; i++) {
|
|
69
|
-
const entry = responseBehaviors[i];
|
|
70
|
-
if (typeof entry === "function") {
|
|
71
|
-
response = entry(req, response);
|
|
72
|
-
} else if (!entry.criteria || entry.criteria(req)) {
|
|
73
|
-
response = entry.behavior(req, response);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
const normalized = denormalizeResponse(response);
|
|
77
|
-
if (!response.body) {
|
|
78
|
-
delete normalized.body;
|
|
79
|
-
}
|
|
80
|
-
return Object.assign({}, evRes, normalized);
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export {
|
|
85
|
-
defineViewerRequest,
|
|
86
|
-
defineViewerResponse,
|
|
87
|
-
cf_function_exports
|
|
88
|
-
};
|
package/dist/chunk-SAXDN5NS.cjs
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
var _chunkWKYMSRCDcjs = require('./chunk-WKYMSRCD.cjs');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _chunk75ZPJI57cjs = require('./chunk-75ZPJI57.cjs');
|
|
7
|
-
|
|
8
|
-
// src/adapters/cf-function.ts
|
|
9
|
-
var cf_function_exports = {};
|
|
10
|
-
_chunk75ZPJI57cjs.__export.call(void 0, cf_function_exports, {
|
|
11
|
-
defineViewerRequest: () => defineViewerRequest,
|
|
12
|
-
defineViewerResponse: () => defineViewerResponse
|
|
13
|
-
});
|
|
14
|
-
function normalizeRequest(event) {
|
|
15
|
-
const ev = event;
|
|
16
|
-
const req = ev.request;
|
|
17
|
-
const viewer = ev.viewer;
|
|
18
|
-
const headers = _nullishCoalesce(req.headers, () => ( {}));
|
|
19
|
-
return {
|
|
20
|
-
uri: req.uri,
|
|
21
|
-
method: req.method,
|
|
22
|
-
protocol: "https",
|
|
23
|
-
querystring: _nullishCoalesce(req.querystring, () => ( {})),
|
|
24
|
-
headers,
|
|
25
|
-
clientIp: _nullishCoalesce(_optionalChain([viewer, 'optionalAccess', _ => _.ip]), () => ( "")),
|
|
26
|
-
country: _optionalChain([headers, 'access', _2 => _2["cloudfront-viewer-country"], 'optionalAccess', _3 => _3.value])
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function denormalizeRequest(req, cookies) {
|
|
30
|
-
return {
|
|
31
|
-
method: req.method,
|
|
32
|
-
uri: req.uri,
|
|
33
|
-
querystring: req.querystring,
|
|
34
|
-
headers: req.headers,
|
|
35
|
-
cookies
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function denormalizeResponse(res) {
|
|
39
|
-
return {
|
|
40
|
-
statusCode: res.statusCode,
|
|
41
|
-
statusDescription: res.statusDescription,
|
|
42
|
-
headers: res.headers,
|
|
43
|
-
body: _nullishCoalesce(res.body, () => ( ""))
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function defineViewerRequest(rules) {
|
|
47
|
-
return (event) => {
|
|
48
|
-
const ev = event;
|
|
49
|
-
const evReq = ev.request;
|
|
50
|
-
const originalCookies = _nullishCoalesce(evReq.cookies, () => ( {}));
|
|
51
|
-
const req = normalizeRequest(event);
|
|
52
|
-
const result = _chunkWKYMSRCDcjs.runRules.call(void 0, rules, req);
|
|
53
|
-
if (result.action === "respond") return denormalizeResponse(result.response);
|
|
54
|
-
return denormalizeRequest(result.request, originalCookies);
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
function defineViewerResponse(responseBehaviors) {
|
|
58
|
-
return (event) => {
|
|
59
|
-
const ev = event;
|
|
60
|
-
const evRes = ev.response;
|
|
61
|
-
const req = normalizeRequest(event);
|
|
62
|
-
let response = {
|
|
63
|
-
statusCode: _nullishCoalesce(_optionalChain([evRes, 'optionalAccess', _4 => _4.statusCode]), () => ( 200)),
|
|
64
|
-
statusDescription: _optionalChain([evRes, 'optionalAccess', _5 => _5.statusDescription]),
|
|
65
|
-
headers: _nullishCoalesce(_optionalChain([evRes, 'optionalAccess', _6 => _6.headers]), () => ( {})),
|
|
66
|
-
body: _optionalChain([evRes, 'optionalAccess', _7 => _7.body])
|
|
67
|
-
};
|
|
68
|
-
for (let i = 0; i < responseBehaviors.length; i++) {
|
|
69
|
-
const entry = responseBehaviors[i];
|
|
70
|
-
if (typeof entry === "function") {
|
|
71
|
-
response = entry(req, response);
|
|
72
|
-
} else if (!entry.criteria || entry.criteria(req)) {
|
|
73
|
-
response = entry.behavior(req, response);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
const normalized = denormalizeResponse(response);
|
|
77
|
-
if (!response.body) {
|
|
78
|
-
delete normalized.body;
|
|
79
|
-
}
|
|
80
|
-
return Object.assign({}, evRes, normalized);
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
exports.defineViewerRequest = defineViewerRequest; exports.defineViewerResponse = defineViewerResponse; exports.cf_function_exports = cf_function_exports;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { Rule, ResponseBehaviorFn, ResponseRule } from './core/types.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Creates a CloudFront Function viewer-request handler from an ordered list of rules.
|
|
5
|
-
*
|
|
6
|
-
* The returned function is the CloudFront Function entry point. Assign it as
|
|
7
|
-
* `export default` or `var handler` depending on your runtime configuration.
|
|
8
|
-
*
|
|
9
|
-
* Rules are evaluated in order. Processing stops at the first rule whose behavior
|
|
10
|
-
* returns a response (e.g. `redirect`, `constructResponse`). If all rules continue,
|
|
11
|
-
* the (possibly mutated) request is forwarded to the origin.
|
|
12
|
-
*
|
|
13
|
-
* @param rules - Ordered array of `Rule` objects created with `rule()`.
|
|
14
|
-
* @returns A CloudFront Function handler `(event) => request | response`.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
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
|
-
*
|
|
23
|
-
* export default defineViewerRequest([
|
|
24
|
-
* rule(not(ipCidr(['10.0.0.0/8'])), redirect(302, 'https://www.example.com')),
|
|
25
|
-
* rule(pathPrefix(['/api/']), setRequestHeader('x-forwarded-host', 'api.internal')),
|
|
26
|
-
* ])
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
declare function defineViewerRequest(rules: Rule[]): (event: unknown) => unknown;
|
|
30
|
-
/**
|
|
31
|
-
* Creates a CloudFront Function viewer-response handler from an ordered list of
|
|
32
|
-
* response behaviors or response rules.
|
|
33
|
-
*
|
|
34
|
-
* Each entry can be either:
|
|
35
|
-
* - A bare `ResponseBehaviorFn` — runs unconditionally on every response.
|
|
36
|
-
* - A `ResponseRule` `{ criteria, behavior }` — runs only when `criteria` returns `true`
|
|
37
|
-
* for the current request.
|
|
38
|
-
*
|
|
39
|
-
* All behaviors are applied in order; none can short-circuit the response.
|
|
40
|
-
* The final merged response object is returned to CloudFront.
|
|
41
|
-
*
|
|
42
|
-
* Note: If no behavior explicitly sets a body, the `body` field is omitted from
|
|
43
|
-
* the returned response to avoid overwriting the origin's actual content.
|
|
44
|
-
*
|
|
45
|
-
* @param responseBehaviors - Ordered array of `ResponseBehaviorFn` functions or
|
|
46
|
-
* `ResponseRule` objects `{ criteria?, behavior }`.
|
|
47
|
-
* @returns A CloudFront Function handler `(event) => response`.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```ts
|
|
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
|
-
*
|
|
55
|
-
* export default defineViewerResponse([
|
|
56
|
-
* setSecurityHeaders(),
|
|
57
|
-
* setCorsHeaders({ allowedOrigins: ['https://www.example.com'] }),
|
|
58
|
-
* { criteria: pathPrefix(['/api/']), behavior: setResponseHeader('cache-control', 'no-store') },
|
|
59
|
-
* ])
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
declare function defineViewerResponse(responseBehaviors: Array<ResponseBehaviorFn | ResponseRule>): (event: unknown) => unknown;
|
|
63
|
-
|
|
64
|
-
declare const cfFunction_defineViewerRequest: typeof defineViewerRequest;
|
|
65
|
-
declare const cfFunction_defineViewerResponse: typeof defineViewerResponse;
|
|
66
|
-
declare namespace cfFunction {
|
|
67
|
-
export { cfFunction_defineViewerRequest as defineViewerRequest, cfFunction_defineViewerResponse as defineViewerResponse };
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export { defineViewerResponse as a, cfFunction as c, defineViewerRequest as d };
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { Rule, ResponseBehaviorFn, ResponseRule } from './core/types.cjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Creates a CloudFront Function viewer-request handler from an ordered list of rules.
|
|
5
|
-
*
|
|
6
|
-
* The returned function is the CloudFront Function entry point. Assign it as
|
|
7
|
-
* `export default` or `var handler` depending on your runtime configuration.
|
|
8
|
-
*
|
|
9
|
-
* Rules are evaluated in order. Processing stops at the first rule whose behavior
|
|
10
|
-
* returns a response (e.g. `redirect`, `constructResponse`). If all rules continue,
|
|
11
|
-
* the (possibly mutated) request is forwarded to the origin.
|
|
12
|
-
*
|
|
13
|
-
* @param rules - Ordered array of `Rule` objects created with `rule()`.
|
|
14
|
-
* @returns A CloudFront Function handler `(event) => request | response`.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
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
|
-
*
|
|
23
|
-
* export default defineViewerRequest([
|
|
24
|
-
* rule(not(ipCidr(['10.0.0.0/8'])), redirect(302, 'https://www.example.com')),
|
|
25
|
-
* rule(pathPrefix(['/api/']), setRequestHeader('x-forwarded-host', 'api.internal')),
|
|
26
|
-
* ])
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
declare function defineViewerRequest(rules: Rule[]): (event: unknown) => unknown;
|
|
30
|
-
/**
|
|
31
|
-
* Creates a CloudFront Function viewer-response handler from an ordered list of
|
|
32
|
-
* response behaviors or response rules.
|
|
33
|
-
*
|
|
34
|
-
* Each entry can be either:
|
|
35
|
-
* - A bare `ResponseBehaviorFn` — runs unconditionally on every response.
|
|
36
|
-
* - A `ResponseRule` `{ criteria, behavior }` — runs only when `criteria` returns `true`
|
|
37
|
-
* for the current request.
|
|
38
|
-
*
|
|
39
|
-
* All behaviors are applied in order; none can short-circuit the response.
|
|
40
|
-
* The final merged response object is returned to CloudFront.
|
|
41
|
-
*
|
|
42
|
-
* Note: If no behavior explicitly sets a body, the `body` field is omitted from
|
|
43
|
-
* the returned response to avoid overwriting the origin's actual content.
|
|
44
|
-
*
|
|
45
|
-
* @param responseBehaviors - Ordered array of `ResponseBehaviorFn` functions or
|
|
46
|
-
* `ResponseRule` objects `{ criteria?, behavior }`.
|
|
47
|
-
* @returns A CloudFront Function handler `(event) => response`.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```ts
|
|
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
|
-
*
|
|
55
|
-
* export default defineViewerResponse([
|
|
56
|
-
* setSecurityHeaders(),
|
|
57
|
-
* setCorsHeaders({ allowedOrigins: ['https://www.example.com'] }),
|
|
58
|
-
* { criteria: pathPrefix(['/api/']), behavior: setResponseHeader('cache-control', 'no-store') },
|
|
59
|
-
* ])
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
declare function defineViewerResponse(responseBehaviors: Array<ResponseBehaviorFn | ResponseRule>): (event: unknown) => unknown;
|
|
63
|
-
|
|
64
|
-
declare const cfFunction_defineViewerRequest: typeof defineViewerRequest;
|
|
65
|
-
declare const cfFunction_defineViewerResponse: typeof defineViewerResponse;
|
|
66
|
-
declare namespace cfFunction {
|
|
67
|
-
export { cfFunction_defineViewerRequest as defineViewerRequest, cfFunction_defineViewerResponse as defineViewerResponse };
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export { defineViewerResponse as a, cfFunction as c, defineViewerRequest as d };
|