@rayselfs/cf-rule-engine 1.8.1 → 1.9.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.
Files changed (81) hide show
  1. package/dist/adapters/cf-function.cjs +4 -4
  2. package/dist/adapters/cf-function.js +3 -3
  3. package/dist/adapters/lambda-edge.cjs +2 -2
  4. package/dist/adapters/lambda-edge.js +1 -1
  5. package/dist/adapters/viewer-request-async.cjs +26 -0
  6. package/dist/adapters/viewer-request-async.d.cts +5 -0
  7. package/dist/adapters/viewer-request-async.d.ts +5 -0
  8. package/dist/adapters/viewer-request-async.js +26 -0
  9. package/dist/adapters/viewer-request.cjs +3 -3
  10. package/dist/adapters/viewer-request.js +2 -2
  11. package/dist/behaviors/index.cjs +7 -6
  12. package/dist/behaviors/index.js +6 -5
  13. package/dist/behaviors/kvs.cjs +24 -0
  14. package/dist/behaviors/kvs.d.cts +6 -0
  15. package/dist/behaviors/kvs.d.ts +6 -0
  16. package/dist/behaviors/kvs.js +24 -0
  17. package/dist/behaviors/rewrite-uri.cjs +2 -2
  18. package/dist/behaviors/rewrite-uri.js +1 -1
  19. package/dist/behaviors/set-cors-headers.cjs +3 -2
  20. package/dist/behaviors/set-cors-headers.d.cts +0 -27
  21. package/dist/behaviors/set-cors-headers.d.ts +0 -27
  22. package/dist/behaviors/set-cors-headers.js +2 -1
  23. package/dist/{chunk-SYPOHDLN.cjs → chunk-5ZIB3AJ7.cjs} +2 -2
  24. package/dist/{chunk-CLDF6FM5.js → chunk-7EA7GFWX.js} +5 -8
  25. package/dist/{chunk-MRPTC74I.cjs → chunk-BSH5JZBL.cjs} +4 -2
  26. package/dist/{chunk-2DE6WPPL.js → chunk-EEZ7NUJG.js} +12 -1
  27. package/dist/{chunk-PW4FKMJ2.cjs → chunk-EMDI676G.cjs} +8 -11
  28. package/dist/{chunk-3BBLG4IX.cjs → chunk-G4JEAL6L.cjs} +11 -8
  29. package/dist/{chunk-PI7RKMGS.js → chunk-H3RK4USR.js} +5 -7
  30. package/dist/{chunk-RL7ZETZR.js → chunk-IHDSTTO2.js} +5 -5
  31. package/dist/{chunk-XWJEVLMZ.cjs → chunk-IHVOAORH.cjs} +7 -9
  32. package/dist/{chunk-T5EXFHVA.cjs → chunk-ISXKMJCN.cjs} +5 -5
  33. package/dist/{chunk-MVGYPBYB.cjs → chunk-LVOM5GJ6.cjs} +2 -2
  34. package/dist/{chunk-D47P7HVZ.cjs → chunk-MK4QBCD5.cjs} +2 -2
  35. package/dist/chunk-NWRGD3AH.js +71 -0
  36. package/dist/{chunk-MTZ35AIR.js → chunk-PR5UQJCC.js} +1 -1
  37. package/dist/{chunk-FTP7NLKX.js → chunk-QVY6REMD.js} +4 -2
  38. package/dist/{chunk-IBXAK2A4.cjs → chunk-ULICUDDH.cjs} +12 -1
  39. package/dist/{chunk-WEBU4R5C.js → chunk-ULR7EP5D.js} +11 -8
  40. package/dist/{chunk-S2AAATFN.js → chunk-VQGBRWJK.js} +1 -1
  41. package/dist/chunk-WZKRNMF2.cjs +71 -0
  42. package/dist/{chunk-LO2BO3RU.js → chunk-Y7TIDVVC.js} +1 -1
  43. package/dist/{chunk-KW5YBTSD.js → chunk-YHTUV2SA.js} +1 -1
  44. package/dist/{chunk-CF5PWWTF.cjs → chunk-ZEFLAOTL.cjs} +2 -2
  45. package/dist/criteria/index.cjs +14 -14
  46. package/dist/criteria/index.js +19 -19
  47. package/dist/criteria/ip-cidr.cjs +3 -3
  48. package/dist/criteria/ip-cidr.js +2 -2
  49. package/dist/criteria/kvs.cjs +14 -0
  50. package/dist/criteria/kvs.d.cts +6 -0
  51. package/dist/criteria/kvs.d.ts +6 -0
  52. package/dist/criteria/kvs.js +14 -0
  53. package/dist/criteria/path-matches.cjs +3 -3
  54. package/dist/criteria/path-matches.js +2 -2
  55. package/dist/criteria/user-agent-matches.cjs +3 -3
  56. package/dist/criteria/user-agent-matches.js +2 -2
  57. package/dist/helpers/index.cjs +12 -12
  58. package/dist/helpers/index.js +12 -12
  59. package/dist/helpers/preflight-request.cjs +4 -3
  60. package/dist/helpers/preflight-request.js +3 -2
  61. package/dist/helpers/whitelist.cjs +7 -7
  62. package/dist/helpers/whitelist.js +6 -6
  63. package/dist/index.cjs +8 -8
  64. package/dist/index.js +6 -6
  65. package/dist/shared/cidr.cjs +2 -2
  66. package/dist/shared/cidr.d.cts +2 -2
  67. package/dist/shared/cidr.d.ts +2 -2
  68. package/dist/shared/cidr.js +1 -1
  69. package/dist/shared/kvs.cjs +1 -0
  70. package/dist/shared/kvs.d.cts +5 -0
  71. package/dist/shared/kvs.d.ts +5 -0
  72. package/dist/shared/kvs.js +0 -0
  73. package/dist/shared/wildcard.cjs +4 -2
  74. package/dist/shared/wildcard.d.cts +10 -1
  75. package/dist/shared/wildcard.d.ts +10 -1
  76. package/dist/shared/wildcard.js +3 -1
  77. package/package.json +1 -1
  78. package/dist/chunk-LNQPYKGG.js +0 -20
  79. package/dist/chunk-YVUR35RN.cjs +0 -20
  80. package/dist/{chunk-I2GJR6LY.js → chunk-BJZPAQHW.js} +3 -3
  81. package/dist/{chunk-FK3B4SP5.cjs → chunk-SGN2N3WI.cjs} +2 -2
@@ -1,14 +1,14 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-SYPOHDLN.cjs');
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-5ZIB3AJ7.cjs');
2
2
 
3
3
 
4
- var _chunkFK3B4SP5cjs = require('../chunk-FK3B4SP5.cjs');
4
+ var _chunkSGN2N3WIcjs = require('../chunk-SGN2N3WI.cjs');
5
+ require('../chunk-WKYMSRCD.cjs');
5
6
 
6
7
 
7
8
  var _chunkN6QAQALUcjs = require('../chunk-N6QAQALU.cjs');
8
9
  require('../chunk-6NFAPLQ7.cjs');
9
- require('../chunk-WKYMSRCD.cjs');
10
10
  require('../chunk-75ZPJI57.cjs');
11
11
 
12
12
 
13
13
 
14
- exports.defineViewerRequest = _chunkFK3B4SP5cjs.defineViewerRequest; exports.defineViewerResponse = _chunkN6QAQALUcjs.defineViewerResponse;
14
+ exports.defineViewerRequest = _chunkSGN2N3WIcjs.defineViewerRequest; exports.defineViewerResponse = _chunkN6QAQALUcjs.defineViewerResponse;
@@ -1,12 +1,12 @@
1
- import "../chunk-MTZ35AIR.js";
1
+ import "../chunk-PR5UQJCC.js";
2
2
  import {
3
3
  defineViewerRequest
4
- } from "../chunk-I2GJR6LY.js";
4
+ } from "../chunk-BJZPAQHW.js";
5
+ import "../chunk-Q4NP4C3B.js";
5
6
  import {
6
7
  defineViewerResponse
7
8
  } from "../chunk-TURH5IFN.js";
8
9
  import "../chunk-CQ7YZ3AR.js";
9
- import "../chunk-Q4NP4C3B.js";
10
10
  import "../chunk-MLKGABMK.js";
11
11
  export {
12
12
  defineViewerRequest,
@@ -1,10 +1,10 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunk3BBLG4IXcjs = require('../chunk-3BBLG4IX.cjs');
4
+ var _chunkG4JEAL6Lcjs = require('../chunk-G4JEAL6L.cjs');
5
5
  require('../chunk-WKYMSRCD.cjs');
6
6
  require('../chunk-75ZPJI57.cjs');
7
7
 
8
8
 
9
9
 
10
- exports.defineViewerRequest = _chunk3BBLG4IXcjs.defineViewerRequest; exports.defineViewerResponse = _chunk3BBLG4IXcjs.defineViewerResponse;
10
+ exports.defineViewerRequest = _chunkG4JEAL6Lcjs.defineViewerRequest; exports.defineViewerResponse = _chunkG4JEAL6Lcjs.defineViewerResponse;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  defineViewerRequest,
3
3
  defineViewerResponse
4
- } from "../chunk-WEBU4R5C.js";
4
+ } from "../chunk-ULR7EP5D.js";
5
5
  import "../chunk-Q4NP4C3B.js";
6
6
  import "../chunk-MLKGABMK.js";
7
7
  export {
@@ -0,0 +1,26 @@
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
+ require('../chunk-75ZPJI57.cjs');
10
+
11
+ // src/adapters/viewer-request-async.ts
12
+ function defineViewerRequestAsync(setup) {
13
+ return async (event) => {
14
+ const ev = event;
15
+ const evReq = ev.request;
16
+ const originalCookies = _nullishCoalesce(evReq.cookies, () => ( {}));
17
+ const req = _chunk6NFAPLQ7cjs.normalizeRequest.call(void 0, event);
18
+ const rules = await setup(event);
19
+ const result = _chunkWKYMSRCDcjs.runRules.call(void 0, rules, req);
20
+ if (result.action === "respond") return _chunk6NFAPLQ7cjs.denormalizeResponse.call(void 0, result.response);
21
+ return _chunk6NFAPLQ7cjs.denormalizeRequest.call(void 0, result.request, originalCookies);
22
+ };
23
+ }
24
+
25
+
26
+ exports.defineViewerRequestAsync = defineViewerRequestAsync;
@@ -0,0 +1,5 @@
1
+ import { Rule } from '../core/types.cjs';
2
+
3
+ declare function defineViewerRequestAsync(setup: (event: unknown) => Promise<Rule[]>): (event: unknown) => Promise<unknown>;
4
+
5
+ export { defineViewerRequestAsync };
@@ -0,0 +1,5 @@
1
+ import { Rule } from '../core/types.js';
2
+
3
+ declare function defineViewerRequestAsync(setup: (event: unknown) => Promise<Rule[]>): (event: unknown) => Promise<unknown>;
4
+
5
+ export { defineViewerRequestAsync };
@@ -0,0 +1,26 @@
1
+ import {
2
+ runRules
3
+ } from "../chunk-Q4NP4C3B.js";
4
+ import {
5
+ denormalizeRequest,
6
+ denormalizeResponse,
7
+ normalizeRequest
8
+ } from "../chunk-CQ7YZ3AR.js";
9
+ import "../chunk-MLKGABMK.js";
10
+
11
+ // src/adapters/viewer-request-async.ts
12
+ function defineViewerRequestAsync(setup) {
13
+ return async (event) => {
14
+ const ev = event;
15
+ const evReq = ev.request;
16
+ const originalCookies = evReq.cookies ?? {};
17
+ const req = normalizeRequest(event);
18
+ const rules = await setup(event);
19
+ const result = runRules(rules, req);
20
+ if (result.action === "respond") return denormalizeResponse(result.response);
21
+ return denormalizeRequest(result.request, originalCookies);
22
+ };
23
+ }
24
+ export {
25
+ defineViewerRequestAsync
26
+ };
@@ -1,9 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkFK3B4SP5cjs = require('../chunk-FK3B4SP5.cjs');
4
- require('../chunk-6NFAPLQ7.cjs');
3
+ var _chunkSGN2N3WIcjs = require('../chunk-SGN2N3WI.cjs');
5
4
  require('../chunk-WKYMSRCD.cjs');
5
+ require('../chunk-6NFAPLQ7.cjs');
6
6
  require('../chunk-75ZPJI57.cjs');
7
7
 
8
8
 
9
- exports.defineViewerRequest = _chunkFK3B4SP5cjs.defineViewerRequest;
9
+ exports.defineViewerRequest = _chunkSGN2N3WIcjs.defineViewerRequest;
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  defineViewerRequest
3
- } from "../chunk-I2GJR6LY.js";
4
- import "../chunk-CQ7YZ3AR.js";
3
+ } from "../chunk-BJZPAQHW.js";
5
4
  import "../chunk-Q4NP4C3B.js";
5
+ import "../chunk-CQ7YZ3AR.js";
6
6
  import "../chunk-MLKGABMK.js";
7
7
  export {
8
8
  defineViewerRequest
@@ -1,6 +1,7 @@
1
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
2
 
3
- var _chunkXWJEVLMZcjs = require('../chunk-XWJEVLMZ.cjs');
3
+ var _chunkIHVOAORHcjs = require('../chunk-IHVOAORH.cjs');
4
+ require('../chunk-ULICUDDH.cjs');
4
5
 
5
6
 
6
7
  var _chunkZXS23HXAcjs = require('../chunk-ZXS23HXA.cjs');
@@ -18,9 +19,6 @@ var _chunk3UXNXJ6Ncjs = require('../chunk-3UXNXJ6N.cjs');
18
19
  var _chunkMSES76XKcjs = require('../chunk-MSES76XK.cjs');
19
20
 
20
21
 
21
- var _chunkJU5WX5RUcjs = require('../chunk-JU5WX5RU.cjs');
22
-
23
-
24
22
  var _chunkLTLBEBKLcjs = require('../chunk-LTLBEBKL.cjs');
25
23
 
26
24
 
@@ -33,13 +31,16 @@ var _chunkWWSRNCUPcjs = require('../chunk-WWSRNCUP.cjs');
33
31
  var _chunkSGEBNQR2cjs = require('../chunk-SGEBNQR2.cjs');
34
32
 
35
33
 
36
- var _chunkMRPTC74Icjs = require('../chunk-MRPTC74I.cjs');
34
+ var _chunkBSH5JZBLcjs = require('../chunk-BSH5JZBL.cjs');
37
35
 
38
36
 
39
37
  var _chunkCV234DQTcjs = require('../chunk-CV234DQT.cjs');
40
38
 
41
39
 
42
40
  var _chunkOSGZTNTScjs = require('../chunk-OSGZTNTS.cjs');
41
+
42
+
43
+ var _chunkJU5WX5RUcjs = require('../chunk-JU5WX5RU.cjs');
43
44
  require('../chunk-75ZPJI57.cjs');
44
45
 
45
46
  // src/behaviors/verify-token.ts
@@ -123,4 +124,4 @@ function verifyToken(options) {
123
124
 
124
125
 
125
126
 
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 = _chunkXWJEVLMZcjs.setCorsHeaders; exports.setCsp = _chunkZXS23HXAcjs.setCsp; exports.setRequestHeader = _chunkPPUHEL4Hcjs.setRequestHeader; exports.setResponseHeader = _chunkB4WEJSEZcjs.setResponseHeader; exports.setSecurityHeaders = _chunk3UXNXJ6Ncjs.setSecurityHeaders; exports.stripQueryParams = _chunkMSES76XKcjs.stripQueryParams; exports.verifyToken = verifyToken;
127
+ 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 = _chunkBSH5JZBLcjs.rewriteUri; exports.setCacheControl = _chunkCV234DQTcjs.setCacheControl; exports.setCorsHeaders = _chunkIHVOAORHcjs.setCorsHeaders; exports.setCsp = _chunkZXS23HXAcjs.setCsp; exports.setRequestHeader = _chunkPPUHEL4Hcjs.setRequestHeader; exports.setResponseHeader = _chunkB4WEJSEZcjs.setResponseHeader; exports.setSecurityHeaders = _chunk3UXNXJ6Ncjs.setSecurityHeaders; exports.stripQueryParams = _chunkMSES76XKcjs.stripQueryParams; exports.verifyToken = verifyToken;
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  setCorsHeaders
3
- } from "../chunk-PI7RKMGS.js";
3
+ } from "../chunk-H3RK4USR.js";
4
+ import "../chunk-EEZ7NUJG.js";
4
5
  import {
5
6
  setCsp
6
7
  } from "../chunk-XUI4Y22M.js";
@@ -16,9 +17,6 @@ import {
16
17
  import {
17
18
  stripQueryParams
18
19
  } from "../chunk-XPQG5IML.js";
19
- import {
20
- copyHeader
21
- } from "../chunk-BDNPQ7AU.js";
22
20
  import {
23
21
  directoryIndex
24
22
  } from "../chunk-R7WXS7BI.js";
@@ -33,13 +31,16 @@ import {
33
31
  } from "../chunk-BUAIBB3N.js";
34
32
  import {
35
33
  rewriteUri
36
- } from "../chunk-FTP7NLKX.js";
34
+ } from "../chunk-QVY6REMD.js";
37
35
  import {
38
36
  setCacheControl
39
37
  } from "../chunk-ZTMSH34E.js";
40
38
  import {
41
39
  constructResponse
42
40
  } from "../chunk-6DBZBV2M.js";
41
+ import {
42
+ copyHeader
43
+ } from "../chunk-BDNPQ7AU.js";
43
44
  import "../chunk-MLKGABMK.js";
44
45
 
45
46
  // src/behaviors/verify-token.ts
@@ -0,0 +1,24 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-75ZPJI57.cjs');
2
+
3
+ // src/behaviors/kvs.ts
4
+ async function kvsRedirect(handle, key, statusCode) {
5
+ const raw = await handle.get(key);
6
+ const map = raw ? JSON.parse(raw) : {};
7
+ const code = statusCode !== void 0 ? statusCode : 301;
8
+ const desc = code === 302 ? "Found" : "Moved Permanently";
9
+ return (request) => {
10
+ const dest = map[request.uri];
11
+ if (!dest) return { action: "continue", request };
12
+ return {
13
+ action: "respond",
14
+ response: {
15
+ statusCode: code,
16
+ statusDescription: desc,
17
+ headers: { location: { value: dest } }
18
+ }
19
+ };
20
+ };
21
+ }
22
+
23
+
24
+ exports.kvsRedirect = kvsRedirect;
@@ -0,0 +1,6 @@
1
+ import { BehaviorFn } from '../core/types.cjs';
2
+ import { KvsHandle } from '../shared/kvs.cjs';
3
+
4
+ declare function kvsRedirect(handle: KvsHandle, key: string, statusCode?: number): Promise<BehaviorFn>;
5
+
6
+ export { kvsRedirect };
@@ -0,0 +1,6 @@
1
+ import { BehaviorFn } from '../core/types.js';
2
+ import { KvsHandle } from '../shared/kvs.js';
3
+
4
+ declare function kvsRedirect(handle: KvsHandle, key: string, statusCode?: number): Promise<BehaviorFn>;
5
+
6
+ export { kvsRedirect };
@@ -0,0 +1,24 @@
1
+ import "../chunk-MLKGABMK.js";
2
+
3
+ // src/behaviors/kvs.ts
4
+ async function kvsRedirect(handle, key, statusCode) {
5
+ const raw = await handle.get(key);
6
+ const map = raw ? JSON.parse(raw) : {};
7
+ const code = statusCode !== void 0 ? statusCode : 301;
8
+ const desc = code === 302 ? "Found" : "Moved Permanently";
9
+ return (request) => {
10
+ const dest = map[request.uri];
11
+ if (!dest) return { action: "continue", request };
12
+ return {
13
+ action: "respond",
14
+ response: {
15
+ statusCode: code,
16
+ statusDescription: desc,
17
+ headers: { location: { value: dest } }
18
+ }
19
+ };
20
+ };
21
+ }
22
+ export {
23
+ kvsRedirect
24
+ };
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkMRPTC74Icjs = require('../chunk-MRPTC74I.cjs');
3
+ var _chunkBSH5JZBLcjs = require('../chunk-BSH5JZBL.cjs');
4
4
  require('../chunk-75ZPJI57.cjs');
5
5
 
6
6
 
7
- exports.rewriteUri = _chunkMRPTC74Icjs.rewriteUri;
7
+ exports.rewriteUri = _chunkBSH5JZBLcjs.rewriteUri;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  rewriteUri
3
- } from "../chunk-FTP7NLKX.js";
3
+ } from "../chunk-QVY6REMD.js";
4
4
  import "../chunk-MLKGABMK.js";
5
5
  export {
6
6
  rewriteUri
@@ -2,10 +2,11 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkXWJEVLMZcjs = require('../chunk-XWJEVLMZ.cjs');
5
+ var _chunkIHVOAORHcjs = require('../chunk-IHVOAORH.cjs');
6
+ require('../chunk-ULICUDDH.cjs');
6
7
  require('../chunk-75ZPJI57.cjs');
7
8
 
8
9
 
9
10
 
10
11
 
11
- exports.ORIGIN_ECHO = _chunkXWJEVLMZcjs.ORIGIN_ECHO; exports.ORIGIN_WILDCARD = _chunkXWJEVLMZcjs.ORIGIN_WILDCARD; exports.setCorsHeaders = _chunkXWJEVLMZcjs.setCorsHeaders;
12
+ exports.ORIGIN_ECHO = _chunkIHVOAORHcjs.ORIGIN_ECHO; exports.ORIGIN_WILDCARD = _chunkIHVOAORHcjs.ORIGIN_WILDCARD; exports.setCorsHeaders = _chunkIHVOAORHcjs.setCorsHeaders;
@@ -55,33 +55,6 @@ interface CorsOptions {
55
55
  */
56
56
  maxAge?: number;
57
57
  }
58
- /**
59
- * Sets CORS response headers with configurable origin policy.
60
- *
61
- * @param options - CORS configuration. `allowedOrigins` is required.
62
- * @returns A `ResponseBehaviorFn` to use directly in `defineViewerResponse` or wrapped in a `ResponseRule`.
63
- *
64
- * @example
65
- * ```ts
66
- * import { setCorsHeaders, ORIGIN_WILDCARD, ORIGIN_ECHO } from '@rayselfs/cf-rule-engine/behaviors/set-cors-headers'
67
- * import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/viewer-response'
68
- *
69
- * // Public API — static Access-Control-Allow-Origin: *
70
- * export default defineViewerResponse([
71
- * setCorsHeaders({ allowedOrigins: ORIGIN_WILDCARD }),
72
- * ])
73
- *
74
- * // Restricted — echo only listed origins (supports wildcard subdomains)
75
- * export default defineViewerResponse([
76
- * setCorsHeaders({ allowedOrigins: ['https://*.viverse.com', 'https://sdk-api.viverse.com'] }),
77
- * ])
78
- *
79
- * // Echo any origin (e.g. for credentialed requests)
80
- * export default defineViewerResponse([
81
- * setCorsHeaders({ allowedOrigins: ORIGIN_ECHO, allowCredentials: true }),
82
- * ])
83
- * ```
84
- */
85
58
  declare function setCorsHeaders(options: CorsOptions): ResponseBehaviorFn;
86
59
 
87
60
  export { type CorsOptions, type Methods, ORIGIN_ECHO, ORIGIN_WILDCARD, type Origin, type OriginEcho, type OriginPolicy, type OriginWildcard, setCorsHeaders };
@@ -55,33 +55,6 @@ interface CorsOptions {
55
55
  */
56
56
  maxAge?: number;
57
57
  }
58
- /**
59
- * Sets CORS response headers with configurable origin policy.
60
- *
61
- * @param options - CORS configuration. `allowedOrigins` is required.
62
- * @returns A `ResponseBehaviorFn` to use directly in `defineViewerResponse` or wrapped in a `ResponseRule`.
63
- *
64
- * @example
65
- * ```ts
66
- * import { setCorsHeaders, ORIGIN_WILDCARD, ORIGIN_ECHO } from '@rayselfs/cf-rule-engine/behaviors/set-cors-headers'
67
- * import { defineViewerResponse } from '@rayselfs/cf-rule-engine/adapters/viewer-response'
68
- *
69
- * // Public API — static Access-Control-Allow-Origin: *
70
- * export default defineViewerResponse([
71
- * setCorsHeaders({ allowedOrigins: ORIGIN_WILDCARD }),
72
- * ])
73
- *
74
- * // Restricted — echo only listed origins (supports wildcard subdomains)
75
- * export default defineViewerResponse([
76
- * setCorsHeaders({ allowedOrigins: ['https://*.viverse.com', 'https://sdk-api.viverse.com'] }),
77
- * ])
78
- *
79
- * // Echo any origin (e.g. for credentialed requests)
80
- * export default defineViewerResponse([
81
- * setCorsHeaders({ allowedOrigins: ORIGIN_ECHO, allowCredentials: true }),
82
- * ])
83
- * ```
84
- */
85
58
  declare function setCorsHeaders(options: CorsOptions): ResponseBehaviorFn;
86
59
 
87
60
  export { type CorsOptions, type Methods, ORIGIN_ECHO, ORIGIN_WILDCARD, type Origin, type OriginEcho, type OriginPolicy, type OriginWildcard, setCorsHeaders };
@@ -2,7 +2,8 @@ import {
2
2
  ORIGIN_ECHO,
3
3
  ORIGIN_WILDCARD,
4
4
  setCorsHeaders
5
- } from "../chunk-PI7RKMGS.js";
5
+ } from "../chunk-H3RK4USR.js";
6
+ import "../chunk-EEZ7NUJG.js";
6
7
  import "../chunk-MLKGABMK.js";
7
8
  export {
8
9
  ORIGIN_ECHO,
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkFK3B4SP5cjs = require('./chunk-FK3B4SP5.cjs');
3
+ var _chunkSGN2N3WIcjs = require('./chunk-SGN2N3WI.cjs');
4
4
 
5
5
 
6
6
  var _chunkN6QAQALUcjs = require('./chunk-N6QAQALU.cjs');
@@ -11,7 +11,7 @@ var _chunk75ZPJI57cjs = require('./chunk-75ZPJI57.cjs');
11
11
  // src/adapters/cf-function.ts
12
12
  var cf_function_exports = {};
13
13
  _chunk75ZPJI57cjs.__export.call(void 0, cf_function_exports, {
14
- defineViewerRequest: () => _chunkFK3B4SP5cjs.defineViewerRequest,
14
+ defineViewerRequest: () => _chunkSGN2N3WIcjs.defineViewerRequest,
15
15
  defineViewerResponse: () => _chunkN6QAQALUcjs.defineViewerResponse
16
16
  });
17
17
 
@@ -4,17 +4,14 @@ import {
4
4
  import {
5
5
  ORIGIN_ECHO,
6
6
  ORIGIN_WILDCARD
7
- } from "./chunk-PI7RKMGS.js";
7
+ } from "./chunk-H3RK4USR.js";
8
+ import {
9
+ matchesOriginPattern
10
+ } from "./chunk-EEZ7NUJG.js";
8
11
 
9
12
  // src/helpers/preflight-request.ts
10
- function matchesOriginPattern(origin, pattern) {
11
- if (pattern === "*") return true;
12
- if (!pattern.includes("*")) return origin === pattern;
13
- const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
14
- return new RegExp(`^${escaped}$`).test(origin);
15
- }
16
13
  function preflightRequest(options) {
17
- const { allowedOrigins } = options;
14
+ const allowedOrigins = options.allowedOrigins;
18
15
  const allowedMethods = options.allowedMethods ?? ["GET", "POST", "OPTIONS"];
19
16
  const allowedHeaders = options.allowedHeaders ?? ["Content-Type", "Cache-Control", "Pragma", "Range"];
20
17
  const allowCredentials = options.allowCredentials ?? false;
@@ -1,5 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/behaviors/rewrite-uri.ts
2
2
  function rewriteUri(mode, target, match) {
3
+ const re = mode === "regex-replace" && match !== void 0 ? new RegExp(match, "g") : null;
3
4
  return (request) => {
4
5
  let uri = request.uri;
5
6
  switch (mode) {
@@ -15,8 +16,9 @@ function rewriteUri(mode, target, match) {
15
16
  }
16
17
  break;
17
18
  case "regex-replace":
18
- if (match !== void 0) {
19
- uri = uri.replace(new RegExp(match, "g"), target);
19
+ if (re) {
20
+ re.lastIndex = 0;
21
+ uri = uri.replace(re, target);
20
22
  }
21
23
  break;
22
24
  }
@@ -1,5 +1,6 @@
1
1
  // src/shared/wildcard.ts
2
2
  var regexCache = /* @__PURE__ */ Object.create(null);
3
+ var originPatternCache = /* @__PURE__ */ Object.create(null);
3
4
  function wildcardToRegex(pattern) {
4
5
  if (!(pattern in regexCache)) {
5
6
  const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
@@ -13,9 +14,19 @@ function matchesWildcard(str, pattern) {
13
14
  function matchesAnyWildcard(str, patterns) {
14
15
  return patterns.some((p) => matchesWildcard(str, p));
15
16
  }
17
+ function matchesOriginPattern(origin, pattern) {
18
+ if (pattern === "*") return true;
19
+ if (!pattern.includes("*")) return origin === pattern;
20
+ if (!(pattern in originPatternCache)) {
21
+ const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
22
+ originPatternCache[pattern] = new RegExp(`^${escaped}$`);
23
+ }
24
+ return originPatternCache[pattern].test(origin);
25
+ }
16
26
 
17
27
  export {
18
28
  wildcardToRegex,
19
29
  matchesWildcard,
20
- matchesAnyWildcard
30
+ matchesAnyWildcard,
31
+ matchesOriginPattern
21
32
  };
@@ -4,17 +4,14 @@ var _chunkOTFDML3Kcjs = require('./chunk-OTFDML3K.cjs');
4
4
 
5
5
 
6
6
 
7
- var _chunkXWJEVLMZcjs = require('./chunk-XWJEVLMZ.cjs');
7
+ var _chunkIHVOAORHcjs = require('./chunk-IHVOAORH.cjs');
8
+
9
+
10
+ var _chunkULICUDDHcjs = require('./chunk-ULICUDDH.cjs');
8
11
 
9
12
  // src/helpers/preflight-request.ts
10
- function matchesOriginPattern(origin, pattern) {
11
- if (pattern === "*") return true;
12
- if (!pattern.includes("*")) return origin === pattern;
13
- const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
14
- return new RegExp(`^${escaped}$`).test(origin);
15
- }
16
13
  function preflightRequest(options) {
17
- const { allowedOrigins } = options;
14
+ const allowedOrigins = options.allowedOrigins;
18
15
  const allowedMethods = _nullishCoalesce(options.allowedMethods, () => ( ["GET", "POST", "OPTIONS"]));
19
16
  const allowedHeaders = _nullishCoalesce(options.allowedHeaders, () => ( ["Content-Type", "Cache-Control", "Pragma", "Range"]));
20
17
  const allowCredentials = _nullishCoalesce(options.allowCredentials, () => ( false));
@@ -23,13 +20,13 @@ function preflightRequest(options) {
23
20
  criteria: _chunkOTFDML3Kcjs.methodIs.call(void 0, ["OPTIONS"]),
24
21
  behavior: (request) => {
25
22
  let allowOrigin;
26
- if (allowedOrigins === _chunkXWJEVLMZcjs.ORIGIN_WILDCARD) {
23
+ if (allowedOrigins === _chunkIHVOAORHcjs.ORIGIN_WILDCARD) {
27
24
  allowOrigin = "*";
28
- } else if (allowedOrigins === _chunkXWJEVLMZcjs.ORIGIN_ECHO) {
25
+ } else if (allowedOrigins === _chunkIHVOAORHcjs.ORIGIN_ECHO) {
29
26
  allowOrigin = _optionalChain([request, 'access', _ => _.headers, 'access', _2 => _2["origin"], 'optionalAccess', _3 => _3.value]);
30
27
  } else {
31
28
  const originHeader = _optionalChain([request, 'access', _4 => _4.headers, 'access', _5 => _5["origin"], 'optionalAccess', _6 => _6.value]);
32
- if (originHeader && allowedOrigins.some((p) => matchesOriginPattern(originHeader, p))) {
29
+ if (originHeader && allowedOrigins.some((p) => _chunkULICUDDHcjs.matchesOriginPattern.call(void 0, originHeader, p))) {
33
30
  allowOrigin = originHeader;
34
31
  }
35
32
  }
@@ -35,14 +35,17 @@ function denormalizeHeaders(headers) {
35
35
  }
36
36
  function parseQuerystring(qs) {
37
37
  if (!qs) return {};
38
- return Object.fromEntries(
39
- qs.split("&").map((p) => {
40
- const parts = p.split("=");
41
- const k = parts[0];
42
- const v = parts[1] || "";
43
- return [k, { value: v }];
44
- })
45
- );
38
+ const result = {};
39
+ const pairs = qs.split("&");
40
+ for (let i = 0; i < pairs.length; i++) {
41
+ const eq = pairs[i].indexOf("=");
42
+ if (eq === -1) {
43
+ result[pairs[i]] = { value: "" };
44
+ } else {
45
+ result[pairs[i].slice(0, eq)] = { value: pairs[i].slice(eq + 1) };
46
+ }
47
+ }
48
+ return result;
46
49
  }
47
50
  function serializeQuerystring(qs) {
48
51
  const qsEntries = Object.entries(qs);
@@ -1,14 +1,12 @@
1
+ import {
2
+ matchesOriginPattern
3
+ } from "./chunk-EEZ7NUJG.js";
4
+
1
5
  // src/behaviors/set-cors-headers.ts
2
6
  var ORIGIN_WILDCARD = "*";
3
7
  var ORIGIN_ECHO = "echo";
4
- function matchesOriginPattern(origin, pattern) {
5
- if (pattern === "*") return true;
6
- if (!pattern.includes("*")) return origin === pattern;
7
- const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
8
- return new RegExp(`^${escaped}$`).test(origin);
9
- }
10
8
  function setCorsHeaders(options) {
11
- const { allowedOrigins } = options;
9
+ const allowedOrigins = options.allowedOrigins;
12
10
  return (request, response) => {
13
11
  let allowOrigin;
14
12
  if (allowedOrigins === ORIGIN_WILDCARD) {
@@ -1,12 +1,12 @@
1
+ import {
2
+ pathMatches
3
+ } from "./chunk-Y7TIDVVC.js";
1
4
  import {
2
5
  userAgentMatches
3
- } from "./chunk-S2AAATFN.js";
6
+ } from "./chunk-VQGBRWJK.js";
4
7
  import {
5
8
  ipCidr
6
- } from "./chunk-KW5YBTSD.js";
7
- import {
8
- pathMatches
9
- } from "./chunk-LO2BO3RU.js";
9
+ } from "./chunk-YHTUV2SA.js";
10
10
  import {
11
11
  redirect
12
12
  } from "./chunk-DSSFFJWL.js";
@@ -1,14 +1,12 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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/behaviors/set-cors-headers.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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 _chunkULICUDDHcjs = require('./chunk-ULICUDDH.cjs');
4
+
5
+ // src/behaviors/set-cors-headers.ts
2
6
  var ORIGIN_WILDCARD = "*";
3
7
  var ORIGIN_ECHO = "echo";
4
- function matchesOriginPattern(origin, pattern) {
5
- if (pattern === "*") return true;
6
- if (!pattern.includes("*")) return origin === pattern;
7
- const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
8
- return new RegExp(`^${escaped}$`).test(origin);
9
- }
10
8
  function setCorsHeaders(options) {
11
- const { allowedOrigins } = options;
9
+ const allowedOrigins = options.allowedOrigins;
12
10
  return (request, response) => {
13
11
  let allowOrigin;
14
12
  if (allowedOrigins === ORIGIN_WILDCARD) {
@@ -17,7 +15,7 @@ function setCorsHeaders(options) {
17
15
  allowOrigin = _optionalChain([request, 'access', _ => _.headers, 'access', _2 => _2["origin"], 'optionalAccess', _3 => _3.value]);
18
16
  } else {
19
17
  const originHeader = _optionalChain([request, 'access', _4 => _4.headers, 'access', _5 => _5["origin"], 'optionalAccess', _6 => _6.value]);
20
- if (originHeader && allowedOrigins.some((p) => matchesOriginPattern(originHeader, p))) {
18
+ if (originHeader && allowedOrigins.some((p) => _chunkULICUDDHcjs.matchesOriginPattern.call(void 0, originHeader, p))) {
21
19
  allowOrigin = originHeader;
22
20
  }
23
21
  }