@rayselfs/cf-rule-engine 1.5.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 (228) hide show
  1. package/README.md +276 -0
  2. package/dist/adapters/cf-function.cjs +10 -0
  3. package/dist/adapters/cf-function.d.cts +2 -0
  4. package/dist/adapters/cf-function.d.ts +2 -0
  5. package/dist/adapters/cf-function.js +10 -0
  6. package/dist/adapters/lambda-edge.cjs +10 -0
  7. package/dist/adapters/lambda-edge.d.cts +2 -0
  8. package/dist/adapters/lambda-edge.d.ts +2 -0
  9. package/dist/adapters/lambda-edge.js +10 -0
  10. package/dist/behaviors/construct-response.cjs +7 -0
  11. package/dist/behaviors/construct-response.d.cts +62 -0
  12. package/dist/behaviors/construct-response.d.ts +62 -0
  13. package/dist/behaviors/construct-response.js +7 -0
  14. package/dist/behaviors/copy-header.cjs +7 -0
  15. package/dist/behaviors/copy-header.d.cts +27 -0
  16. package/dist/behaviors/copy-header.d.ts +27 -0
  17. package/dist/behaviors/copy-header.js +7 -0
  18. package/dist/behaviors/directory-index.cjs +7 -0
  19. package/dist/behaviors/directory-index.d.cts +33 -0
  20. package/dist/behaviors/directory-index.d.ts +33 -0
  21. package/dist/behaviors/directory-index.js +7 -0
  22. package/dist/behaviors/image-optimize.cjs +9 -0
  23. package/dist/behaviors/image-optimize.d.cts +103 -0
  24. package/dist/behaviors/image-optimize.d.ts +103 -0
  25. package/dist/behaviors/image-optimize.js +9 -0
  26. package/dist/behaviors/index.cjs +126 -0
  27. package/dist/behaviors/index.d.cts +46 -0
  28. package/dist/behaviors/index.d.ts +46 -0
  29. package/dist/behaviors/index.js +126 -0
  30. package/dist/behaviors/redirect.cjs +7 -0
  31. package/dist/behaviors/redirect.d.cts +44 -0
  32. package/dist/behaviors/redirect.d.ts +44 -0
  33. package/dist/behaviors/redirect.js +7 -0
  34. package/dist/behaviors/remove-response-headers.cjs +7 -0
  35. package/dist/behaviors/remove-response-headers.d.cts +27 -0
  36. package/dist/behaviors/remove-response-headers.d.ts +27 -0
  37. package/dist/behaviors/remove-response-headers.js +7 -0
  38. package/dist/behaviors/rewrite-uri.cjs +7 -0
  39. package/dist/behaviors/rewrite-uri.d.cts +43 -0
  40. package/dist/behaviors/rewrite-uri.d.ts +43 -0
  41. package/dist/behaviors/rewrite-uri.js +7 -0
  42. package/dist/behaviors/set-cache-control.cjs +7 -0
  43. package/dist/behaviors/set-cache-control.d.cts +29 -0
  44. package/dist/behaviors/set-cache-control.d.ts +29 -0
  45. package/dist/behaviors/set-cache-control.js +7 -0
  46. package/dist/behaviors/set-cors-headers.cjs +7 -0
  47. package/dist/behaviors/set-cors-headers.d.cts +76 -0
  48. package/dist/behaviors/set-cors-headers.d.ts +76 -0
  49. package/dist/behaviors/set-cors-headers.js +7 -0
  50. package/dist/behaviors/set-csp.cjs +7 -0
  51. package/dist/behaviors/set-csp.d.cts +48 -0
  52. package/dist/behaviors/set-csp.d.ts +48 -0
  53. package/dist/behaviors/set-csp.js +7 -0
  54. package/dist/behaviors/set-request-header.cjs +7 -0
  55. package/dist/behaviors/set-request-header.d.cts +26 -0
  56. package/dist/behaviors/set-request-header.d.ts +26 -0
  57. package/dist/behaviors/set-request-header.js +7 -0
  58. package/dist/behaviors/set-response-header.cjs +7 -0
  59. package/dist/behaviors/set-response-header.d.cts +28 -0
  60. package/dist/behaviors/set-response-header.d.ts +28 -0
  61. package/dist/behaviors/set-response-header.js +7 -0
  62. package/dist/behaviors/set-security-headers.cjs +7 -0
  63. package/dist/behaviors/set-security-headers.d.cts +55 -0
  64. package/dist/behaviors/set-security-headers.d.ts +55 -0
  65. package/dist/behaviors/set-security-headers.js +7 -0
  66. package/dist/behaviors/strip-query-params.cjs +7 -0
  67. package/dist/behaviors/strip-query-params.d.cts +25 -0
  68. package/dist/behaviors/strip-query-params.d.ts +25 -0
  69. package/dist/behaviors/strip-query-params.js +7 -0
  70. package/dist/cf-function-D27hUVtN.d.cts +70 -0
  71. package/dist/cf-function-u0PvbW_s.d.ts +70 -0
  72. package/dist/chunk-2DE6WPPL.js +21 -0
  73. package/dist/chunk-32SMWYAF.cjs +13 -0
  74. package/dist/chunk-3BBLG4IX.cjs +132 -0
  75. package/dist/chunk-3PVDUC5M.js +12 -0
  76. package/dist/chunk-5CPBXZ4X.js +12 -0
  77. package/dist/chunk-5PT5X62W.js +98 -0
  78. package/dist/chunk-63WIEBQB.cjs +50 -0
  79. package/dist/chunk-6DBZBV2M.js +42 -0
  80. package/dist/chunk-75ZPJI57.cjs +9 -0
  81. package/dist/chunk-B4WEJSEZ.cjs +14 -0
  82. package/dist/chunk-BDNPQ7AU.js +21 -0
  83. package/dist/chunk-BUAIBB3N.js +14 -0
  84. package/dist/chunk-BZQJYOU2.js +12 -0
  85. package/dist/chunk-C32DL3EP.js +13 -0
  86. package/dist/chunk-CF5PWWTF.cjs +15 -0
  87. package/dist/chunk-CV234DQT.cjs +14 -0
  88. package/dist/chunk-D47P7HVZ.cjs +12 -0
  89. package/dist/chunk-DSSFFJWL.js +38 -0
  90. package/dist/chunk-FTP7NLKX.js +29 -0
  91. package/dist/chunk-G7JGTBTT.cjs +8 -0
  92. package/dist/chunk-GK5JX7OM.cjs +39 -0
  93. package/dist/chunk-H2LO6MQG.js +50 -0
  94. package/dist/chunk-IBXAK2A4.cjs +21 -0
  95. package/dist/chunk-JGJW7D2N.cjs +12 -0
  96. package/dist/chunk-JU5WX5RU.cjs +21 -0
  97. package/dist/chunk-KW5YBTSD.js +12 -0
  98. package/dist/chunk-KZ72PI2A.js +0 -0
  99. package/dist/chunk-L7NBJ4JA.cjs +12 -0
  100. package/dist/chunk-LBJUCJF2.js +14 -0
  101. package/dist/chunk-LNQPYKGG.js +20 -0
  102. package/dist/chunk-LO2BO3RU.js +15 -0
  103. package/dist/chunk-LSCC62CZ.cjs +13 -0
  104. package/dist/chunk-LTLBEBKL.cjs +42 -0
  105. package/dist/chunk-M5KUQBDW.js +17 -0
  106. package/dist/chunk-MEHWLQLR.cjs +1 -0
  107. package/dist/chunk-MLKGABMK.js +9 -0
  108. package/dist/chunk-MRPTC74I.cjs +29 -0
  109. package/dist/chunk-MSES76XK.cjs +14 -0
  110. package/dist/chunk-MVGYPBYB.cjs +16 -0
  111. package/dist/chunk-NPMGSPNL.js +88 -0
  112. package/dist/chunk-OSGZTNTS.cjs +42 -0
  113. package/dist/chunk-OSZWDCTS.cjs +12 -0
  114. package/dist/chunk-OTFDML3K.cjs +11 -0
  115. package/dist/chunk-PPUHEL4H.cjs +17 -0
  116. package/dist/chunk-PY3JMRDG.js +11 -0
  117. package/dist/chunk-Q4NP4C3B.js +47 -0
  118. package/dist/chunk-R7WXS7BI.js +42 -0
  119. package/dist/chunk-RBBKFG5J.js +14 -0
  120. package/dist/chunk-S2AAATFN.js +16 -0
  121. package/dist/chunk-SAXDN5NS.cjs +88 -0
  122. package/dist/chunk-SGEBNQR2.cjs +14 -0
  123. package/dist/chunk-SOBTD7AD.js +39 -0
  124. package/dist/chunk-SRQF5UEJ.js +13 -0
  125. package/dist/chunk-TQLJIT4H.cjs +98 -0
  126. package/dist/chunk-U54FZCOH.cjs +14 -0
  127. package/dist/chunk-UD456E4I.js +8 -0
  128. package/dist/chunk-UI6LKDJI.cjs +19 -0
  129. package/dist/chunk-UKB5JAX4.js +32 -0
  130. package/dist/chunk-VEEOQ7TS.cjs +8 -0
  131. package/dist/chunk-VQCRSBWL.js +19 -0
  132. package/dist/chunk-WEBU4R5C.js +132 -0
  133. package/dist/chunk-WKYMSRCD.cjs +47 -0
  134. package/dist/chunk-WW7YVRAI.cjs +32 -0
  135. package/dist/chunk-WWSRNCUP.cjs +38 -0
  136. package/dist/chunk-XLSZ5RB7.js +8 -0
  137. package/dist/chunk-XPQG5IML.js +14 -0
  138. package/dist/chunk-XUI4Y22M.js +20 -0
  139. package/dist/chunk-YVUR35RN.cjs +20 -0
  140. package/dist/chunk-ZTMSH34E.js +14 -0
  141. package/dist/chunk-ZXS23HXA.cjs +20 -0
  142. package/dist/core/rule.cjs +17 -0
  143. package/dist/core/rule.d.cts +101 -0
  144. package/dist/core/rule.d.ts +101 -0
  145. package/dist/core/rule.js +17 -0
  146. package/dist/core/types.cjs +1 -0
  147. package/dist/core/types.d.cts +53 -0
  148. package/dist/core/types.d.ts +53 -0
  149. package/dist/core/types.js +1 -0
  150. package/dist/criteria/country-is.cjs +7 -0
  151. package/dist/criteria/country-is.d.cts +35 -0
  152. package/dist/criteria/country-is.d.ts +35 -0
  153. package/dist/criteria/country-is.js +7 -0
  154. package/dist/criteria/file-extension.cjs +7 -0
  155. package/dist/criteria/file-extension.d.cts +32 -0
  156. package/dist/criteria/file-extension.d.ts +32 -0
  157. package/dist/criteria/file-extension.js +7 -0
  158. package/dist/criteria/header-contains.cjs +7 -0
  159. package/dist/criteria/header-contains.d.cts +33 -0
  160. package/dist/criteria/header-contains.d.ts +33 -0
  161. package/dist/criteria/header-contains.js +7 -0
  162. package/dist/criteria/header-equals.cjs +7 -0
  163. package/dist/criteria/header-equals.d.cts +31 -0
  164. package/dist/criteria/header-equals.d.ts +31 -0
  165. package/dist/criteria/header-equals.js +7 -0
  166. package/dist/criteria/hostname-is.cjs +7 -0
  167. package/dist/criteria/hostname-is.d.cts +22 -0
  168. package/dist/criteria/hostname-is.d.ts +22 -0
  169. package/dist/criteria/hostname-is.js +7 -0
  170. package/dist/criteria/index.cjs +49 -0
  171. package/dist/criteria/index.d.cts +12 -0
  172. package/dist/criteria/index.d.ts +12 -0
  173. package/dist/criteria/index.js +49 -0
  174. package/dist/criteria/ip-cidr.cjs +8 -0
  175. package/dist/criteria/ip-cidr.d.cts +31 -0
  176. package/dist/criteria/ip-cidr.d.ts +31 -0
  177. package/dist/criteria/ip-cidr.js +8 -0
  178. package/dist/criteria/method-is.cjs +7 -0
  179. package/dist/criteria/method-is.d.cts +29 -0
  180. package/dist/criteria/method-is.d.ts +29 -0
  181. package/dist/criteria/method-is.js +7 -0
  182. package/dist/criteria/path-equals.cjs +7 -0
  183. package/dist/criteria/path-equals.d.cts +22 -0
  184. package/dist/criteria/path-equals.d.ts +22 -0
  185. package/dist/criteria/path-equals.js +7 -0
  186. package/dist/criteria/path-matches.cjs +8 -0
  187. package/dist/criteria/path-matches.d.cts +22 -0
  188. package/dist/criteria/path-matches.d.ts +22 -0
  189. package/dist/criteria/path-matches.js +8 -0
  190. package/dist/criteria/path-prefix.cjs +7 -0
  191. package/dist/criteria/path-prefix.d.cts +21 -0
  192. package/dist/criteria/path-prefix.d.ts +21 -0
  193. package/dist/criteria/path-prefix.js +7 -0
  194. package/dist/criteria/user-agent-matches.cjs +8 -0
  195. package/dist/criteria/user-agent-matches.d.cts +32 -0
  196. package/dist/criteria/user-agent-matches.d.ts +32 -0
  197. package/dist/criteria/user-agent-matches.js +8 -0
  198. package/dist/helpers/index.cjs +42 -0
  199. package/dist/helpers/index.d.cts +34 -0
  200. package/dist/helpers/index.d.ts +34 -0
  201. package/dist/helpers/index.js +42 -0
  202. package/dist/helpers/preflight-request.cjs +8 -0
  203. package/dist/helpers/preflight-request.d.cts +38 -0
  204. package/dist/helpers/preflight-request.d.ts +38 -0
  205. package/dist/helpers/preflight-request.js +8 -0
  206. package/dist/helpers/send-country-code.cjs +8 -0
  207. package/dist/helpers/send-country-code.d.cts +35 -0
  208. package/dist/helpers/send-country-code.d.ts +35 -0
  209. package/dist/helpers/send-country-code.js +8 -0
  210. package/dist/helpers/staging-whitelist.cjs +14 -0
  211. package/dist/helpers/staging-whitelist.d.cts +73 -0
  212. package/dist/helpers/staging-whitelist.d.ts +73 -0
  213. package/dist/helpers/staging-whitelist.js +14 -0
  214. package/dist/index.cjs +26 -0
  215. package/dist/index.d.cts +4 -0
  216. package/dist/index.d.ts +4 -0
  217. package/dist/index.js +26 -0
  218. package/dist/lambda-edge-D15Nf__n.d.ts +66 -0
  219. package/dist/lambda-edge-DxTOa2cg.d.cts +66 -0
  220. package/dist/shared/cidr.cjs +11 -0
  221. package/dist/shared/cidr.d.cts +8 -0
  222. package/dist/shared/cidr.d.ts +8 -0
  223. package/dist/shared/cidr.js +11 -0
  224. package/dist/shared/wildcard.cjs +11 -0
  225. package/dist/shared/wildcard.d.cts +8 -0
  226. package/dist/shared/wildcard.d.ts +8 -0
  227. package/dist/shared/wildcard.js +11 -0
  228. package/package.json +65 -0
@@ -0,0 +1,50 @@
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 _chunkOTFDML3Kcjs = require('./chunk-OTFDML3K.cjs');
4
+
5
+ // src/helpers/preflight-request.ts
6
+ function matchesOriginPattern(origin, pattern) {
7
+ if (pattern === "*") return true;
8
+ if (!pattern.includes("*")) return origin === pattern;
9
+ const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
10
+ return new RegExp(`^${escaped}$`).test(origin);
11
+ }
12
+ function preflightRequest(options) {
13
+ const allowedOrigins = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _ => _.allowedOrigins]), () => ( ["*"]));
14
+ const allowedMethods = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _2 => _2.allowedMethods]), () => ( "GET, POST, OPTIONS"));
15
+ const allowedHeaders = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _3 => _3.allowedHeaders]), () => ( "Content-Type, Cache-Control, Pragma, Range"));
16
+ const allowCredentials = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _4 => _4.allowCredentials]), () => ( false));
17
+ const maxAge = _optionalChain([options, 'optionalAccess', _5 => _5.maxAge]);
18
+ return {
19
+ criteria: _chunkOTFDML3Kcjs.methodIs.call(void 0, ["OPTIONS"]),
20
+ behavior: (request) => {
21
+ let allowOrigin;
22
+ if (_optionalChain([options, 'optionalAccess', _6 => _6.allowOriginEcho])) {
23
+ const originHeader = _optionalChain([request, 'access', _7 => _7.headers, 'access', _8 => _8["origin"], 'optionalAccess', _9 => _9.value]);
24
+ allowOrigin = originHeader && allowedOrigins.some((p) => matchesOriginPattern(originHeader, p)) ? originHeader : _nullishCoalesce(allowedOrigins[0], () => ( "*"));
25
+ } else {
26
+ allowOrigin = allowedOrigins.includes("*") ? "*" : _nullishCoalesce(allowedOrigins[0], () => ( "*"));
27
+ }
28
+ const headers = {
29
+ "cache-control": { value: "no-store" },
30
+ "access-control-allow-origin": { value: allowOrigin },
31
+ "access-control-allow-methods": { value: allowedMethods },
32
+ "access-control-allow-headers": { value: allowedHeaders }
33
+ };
34
+ if (allowCredentials) {
35
+ headers["access-control-allow-credentials"] = { value: "true" };
36
+ }
37
+ if (maxAge !== void 0) {
38
+ headers["access-control-max-age"] = { value: String(maxAge) };
39
+ }
40
+ return {
41
+ action: "respond",
42
+ response: { statusCode: 204, statusDescription: "No Content", headers }
43
+ };
44
+ }
45
+ };
46
+ }
47
+
48
+
49
+
50
+ exports.preflightRequest = preflightRequest;
@@ -0,0 +1,42 @@
1
+ // src/behaviors/construct-response.ts
2
+ var statusDescriptions = {
3
+ 200: "OK",
4
+ 204: "No Content",
5
+ 400: "Bad Request",
6
+ 401: "Unauthorized",
7
+ 403: "Forbidden",
8
+ 404: "Not Found",
9
+ 405: "Method Not Allowed",
10
+ 429: "Too Many Requests",
11
+ 500: "Internal Server Error"
12
+ };
13
+ function constructResponse(options) {
14
+ return () => {
15
+ const headers = {
16
+ "cache-control": { value: "no-store" }
17
+ };
18
+ if (options.contentType) {
19
+ headers["content-type"] = { value: options.contentType };
20
+ }
21
+ if (options.headers) {
22
+ const headerEntries = Object.entries(options.headers);
23
+ for (let i = 0; i < headerEntries.length; i++) {
24
+ const entry = headerEntries[i];
25
+ headers[entry[0].toLowerCase()] = { value: entry[1] };
26
+ }
27
+ }
28
+ return {
29
+ action: "respond",
30
+ response: {
31
+ statusCode: options.statusCode,
32
+ statusDescription: statusDescriptions[options.statusCode],
33
+ headers,
34
+ body: options.body
35
+ }
36
+ };
37
+ };
38
+ }
39
+
40
+ export {
41
+ constructResponse
42
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+
8
+
9
+ exports.__export = __export;
@@ -0,0 +1,14 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/behaviors/set-response-header.ts
2
+ function setResponseHeader(headerName, value) {
3
+ return (_request, response) => {
4
+ return Object.assign({}, response, {
5
+ headers: Object.assign({}, response.headers, {
6
+ [headerName.toLowerCase()]: { value }
7
+ })
8
+ });
9
+ };
10
+ }
11
+
12
+
13
+
14
+ exports.setResponseHeader = setResponseHeader;
@@ -0,0 +1,21 @@
1
+ // src/behaviors/copy-header.ts
2
+ function copyHeader(sourceHeader, targetHeader) {
3
+ return (request) => {
4
+ const sourceValue = request.headers[sourceHeader.toLowerCase()]?.value;
5
+ if (sourceValue === void 0) {
6
+ return { action: "continue", request };
7
+ }
8
+ return {
9
+ action: "continue",
10
+ request: Object.assign({}, request, {
11
+ headers: Object.assign({}, request.headers, {
12
+ [targetHeader.toLowerCase()]: { value: sourceValue }
13
+ })
14
+ })
15
+ };
16
+ };
17
+ }
18
+
19
+ export {
20
+ copyHeader
21
+ };
@@ -0,0 +1,14 @@
1
+ // src/behaviors/remove-response-headers.ts
2
+ function removeResponseHeaders(headerNames) {
3
+ return (_request, response) => {
4
+ const headers = Object.assign({}, response.headers);
5
+ for (let i = 0; i < headerNames.length; i++) {
6
+ delete headers[headerNames[i].toLowerCase()];
7
+ }
8
+ return Object.assign({}, response, { headers });
9
+ };
10
+ }
11
+
12
+ export {
13
+ removeResponseHeaders
14
+ };
@@ -0,0 +1,12 @@
1
+ // src/criteria/header-equals.ts
2
+ function headerEquals(headerName, values) {
3
+ return (req) => {
4
+ const val = req.headers[headerName.toLowerCase()]?.value;
5
+ if (val === void 0) return false;
6
+ return values.some((v) => v.toLowerCase() === val.toLowerCase());
7
+ };
8
+ }
9
+
10
+ export {
11
+ headerEquals
12
+ };
@@ -0,0 +1,13 @@
1
+ import {
2
+ copyHeader
3
+ } from "./chunk-BDNPQ7AU.js";
4
+
5
+ // src/helpers/send-country-code.ts
6
+ function sendCountryCode(targetHeader) {
7
+ const target = targetHeader ?? "x-viewer-country";
8
+ return copyHeader("cloudfront-viewer-country", target);
9
+ }
10
+
11
+ export {
12
+ sendCountryCode
13
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkIBXAK2A4cjs = require('./chunk-IBXAK2A4.cjs');
4
+
5
+ // src/criteria/path-matches.ts
6
+ function pathMatches(patterns) {
7
+ return (req) => {
8
+ const path = req.uri.split("?")[0];
9
+ return _chunkIBXAK2A4cjs.matchesAnyWildcard.call(void 0, path, patterns);
10
+ };
11
+ }
12
+
13
+
14
+
15
+ exports.pathMatches = pathMatches;
@@ -0,0 +1,14 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/behaviors/set-cache-control.ts
2
+ function setCacheControl(value) {
3
+ return (_request, response) => {
4
+ return Object.assign({}, response, {
5
+ headers: Object.assign({}, response.headers, {
6
+ "cache-control": { value }
7
+ })
8
+ });
9
+ };
10
+ }
11
+
12
+
13
+
14
+ exports.setCacheControl = setCacheControl;
@@ -0,0 +1,12 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkYVUR35RNcjs = require('./chunk-YVUR35RN.cjs');
4
+
5
+ // src/criteria/ip-cidr.ts
6
+ function ipCidr(cidrs) {
7
+ return (req) => _chunkYVUR35RNcjs.matchesAnyCidr.call(void 0, req.clientIp, cidrs);
8
+ }
9
+
10
+
11
+
12
+ exports.ipCidr = ipCidr;
@@ -0,0 +1,38 @@
1
+ // src/behaviors/redirect.ts
2
+ var statusDescriptions = {
3
+ 301: "Moved Permanently",
4
+ 302: "Found",
5
+ 307: "Temporary Redirect"
6
+ };
7
+ function redirect(statusCode, location, options) {
8
+ return (request) => {
9
+ let finalLocation = location;
10
+ if (options?.preserveQuerystring) {
11
+ const qsEntries = Object.entries(request.querystring);
12
+ const qsParts = [];
13
+ for (let i = 0; i < qsEntries.length; i++) {
14
+ const entry = qsEntries[i];
15
+ qsParts.push(entry[0] + "=" + entry[1].value);
16
+ }
17
+ const qs = qsParts.join("&");
18
+ if (qs) {
19
+ finalLocation = `${location}?${qs}`;
20
+ }
21
+ }
22
+ return {
23
+ action: "respond",
24
+ response: {
25
+ statusCode,
26
+ statusDescription: statusDescriptions[statusCode],
27
+ headers: {
28
+ location: { value: finalLocation },
29
+ "cache-control": { value: "no-store" }
30
+ }
31
+ }
32
+ };
33
+ };
34
+ }
35
+
36
+ export {
37
+ redirect
38
+ };
@@ -0,0 +1,29 @@
1
+ // src/behaviors/rewrite-uri.ts
2
+ function rewriteUri(mode, target, match) {
3
+ return (request) => {
4
+ let uri = request.uri;
5
+ switch (mode) {
6
+ case "set":
7
+ uri = target;
8
+ break;
9
+ case "prepend":
10
+ uri = target + uri;
11
+ break;
12
+ case "replace":
13
+ if (match !== void 0) {
14
+ uri = uri.split(match).join(target);
15
+ }
16
+ break;
17
+ case "regex-replace":
18
+ if (match !== void 0) {
19
+ uri = uri.replace(new RegExp(match, "g"), target);
20
+ }
21
+ break;
22
+ }
23
+ return { action: "continue", request: Object.assign({}, request, { uri }) };
24
+ };
25
+ }
26
+
27
+ export {
28
+ rewriteUri
29
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/criteria/path-prefix.ts
2
+ function pathPrefix(prefixes) {
3
+ return (req) => prefixes.some((p) => req.uri.startsWith(p));
4
+ }
5
+
6
+
7
+
8
+ exports.pathPrefix = pathPrefix;
@@ -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/behaviors/set-cors-headers.ts
2
+ function matchesOriginPattern(origin, pattern) {
3
+ if (pattern === "*") return true;
4
+ if (!pattern.includes("*")) return origin === pattern;
5
+ const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
6
+ return new RegExp(`^${escaped}$`).test(origin);
7
+ }
8
+ function setCorsHeaders(options) {
9
+ const allowedOrigins = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _ => _.allowedOrigins]), () => ( ["*"]));
10
+ const allowedMethods = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _2 => _2.allowedMethods]), () => ( "GET, POST, OPTIONS"));
11
+ const allowedHeaders = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _3 => _3.allowedHeaders]), () => ( "Content-Type, Cache-Control, Pragma, Range"));
12
+ return (request, response) => {
13
+ let allowOrigin = _nullishCoalesce(allowedOrigins[0], () => ( "*"));
14
+ if (_optionalChain([options, 'optionalAccess', _4 => _4.allowOriginEcho])) {
15
+ const originHeader = _optionalChain([request, 'access', _5 => _5.headers, 'access', _6 => _6["origin"], 'optionalAccess', _7 => _7.value]);
16
+ if (originHeader && allowedOrigins.some((p) => matchesOriginPattern(originHeader, p))) {
17
+ allowOrigin = originHeader;
18
+ }
19
+ }
20
+ const corsHeaders = {
21
+ "access-control-allow-origin": { value: allowOrigin },
22
+ "access-control-allow-methods": { value: allowedMethods },
23
+ "access-control-allow-headers": { value: allowedHeaders }
24
+ };
25
+ if (_optionalChain([options, 'optionalAccess', _8 => _8.allowCredentials])) {
26
+ corsHeaders["access-control-allow-credentials"] = { value: "true" };
27
+ }
28
+ if (_optionalChain([options, 'optionalAccess', _9 => _9.maxAge]) !== void 0) {
29
+ corsHeaders["access-control-max-age"] = { value: String(options.maxAge) };
30
+ }
31
+ return Object.assign({}, response, {
32
+ headers: Object.assign({}, response.headers, corsHeaders)
33
+ });
34
+ };
35
+ }
36
+
37
+
38
+
39
+ exports.setCorsHeaders = setCorsHeaders;
@@ -0,0 +1,50 @@
1
+ import {
2
+ methodIs
3
+ } from "./chunk-PY3JMRDG.js";
4
+
5
+ // src/helpers/preflight-request.ts
6
+ function matchesOriginPattern(origin, pattern) {
7
+ if (pattern === "*") return true;
8
+ if (!pattern.includes("*")) return origin === pattern;
9
+ const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
10
+ return new RegExp(`^${escaped}$`).test(origin);
11
+ }
12
+ function preflightRequest(options) {
13
+ const allowedOrigins = options?.allowedOrigins ?? ["*"];
14
+ const allowedMethods = options?.allowedMethods ?? "GET, POST, OPTIONS";
15
+ const allowedHeaders = options?.allowedHeaders ?? "Content-Type, Cache-Control, Pragma, Range";
16
+ const allowCredentials = options?.allowCredentials ?? false;
17
+ const maxAge = options?.maxAge;
18
+ return {
19
+ criteria: methodIs(["OPTIONS"]),
20
+ behavior: (request) => {
21
+ let allowOrigin;
22
+ if (options?.allowOriginEcho) {
23
+ const originHeader = request.headers["origin"]?.value;
24
+ allowOrigin = originHeader && allowedOrigins.some((p) => matchesOriginPattern(originHeader, p)) ? originHeader : allowedOrigins[0] ?? "*";
25
+ } else {
26
+ allowOrigin = allowedOrigins.includes("*") ? "*" : allowedOrigins[0] ?? "*";
27
+ }
28
+ const headers = {
29
+ "cache-control": { value: "no-store" },
30
+ "access-control-allow-origin": { value: allowOrigin },
31
+ "access-control-allow-methods": { value: allowedMethods },
32
+ "access-control-allow-headers": { value: allowedHeaders }
33
+ };
34
+ if (allowCredentials) {
35
+ headers["access-control-allow-credentials"] = { value: "true" };
36
+ }
37
+ if (maxAge !== void 0) {
38
+ headers["access-control-max-age"] = { value: String(maxAge) };
39
+ }
40
+ return {
41
+ action: "respond",
42
+ response: { statusCode: 204, statusDescription: "No Content", headers }
43
+ };
44
+ }
45
+ };
46
+ }
47
+
48
+ export {
49
+ preflightRequest
50
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/shared/wildcard.ts
2
+ var regexCache = /* @__PURE__ */ Object.create(null);
3
+ function wildcardToRegex(pattern) {
4
+ if (!(pattern in regexCache)) {
5
+ const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
6
+ regexCache[pattern] = new RegExp(`^${escaped}$`, "i");
7
+ }
8
+ return regexCache[pattern];
9
+ }
10
+ function matchesWildcard(str, pattern) {
11
+ return wildcardToRegex(pattern).test(str);
12
+ }
13
+ function matchesAnyWildcard(str, patterns) {
14
+ return patterns.some((p) => matchesWildcard(str, p));
15
+ }
16
+
17
+
18
+
19
+
20
+
21
+ exports.wildcardToRegex = wildcardToRegex; exports.matchesWildcard = matchesWildcard; exports.matchesAnyWildcard = matchesAnyWildcard;
@@ -0,0 +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/criteria/hostname-is.ts
2
+ function hostnameIs(hostnames) {
3
+ return (req) => {
4
+ const host = _optionalChain([req, 'access', _ => _.headers, 'access', _2 => _2["host"], 'optionalAccess', _3 => _3.value, 'optionalAccess', _4 => _4.toLowerCase, 'call', _5 => _5()]);
5
+ if (!host) return false;
6
+ return hostnames.some((h) => h.toLowerCase() === host);
7
+ };
8
+ }
9
+
10
+
11
+
12
+ exports.hostnameIs = hostnameIs;
@@ -0,0 +1,21 @@
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/copy-header.ts
2
+ function copyHeader(sourceHeader, targetHeader) {
3
+ return (request) => {
4
+ const sourceValue = _optionalChain([request, 'access', _ => _.headers, 'access', _2 => _2[sourceHeader.toLowerCase()], 'optionalAccess', _3 => _3.value]);
5
+ if (sourceValue === void 0) {
6
+ return { action: "continue", request };
7
+ }
8
+ return {
9
+ action: "continue",
10
+ request: Object.assign({}, request, {
11
+ headers: Object.assign({}, request.headers, {
12
+ [targetHeader.toLowerCase()]: { value: sourceValue }
13
+ })
14
+ })
15
+ };
16
+ };
17
+ }
18
+
19
+
20
+
21
+ exports.copyHeader = copyHeader;
@@ -0,0 +1,12 @@
1
+ import {
2
+ matchesAnyCidr
3
+ } from "./chunk-LNQPYKGG.js";
4
+
5
+ // src/criteria/ip-cidr.ts
6
+ function ipCidr(cidrs) {
7
+ return (req) => matchesAnyCidr(req.clientIp, cidrs);
8
+ }
9
+
10
+ export {
11
+ ipCidr
12
+ };
File without changes
@@ -0,0 +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/criteria/header-equals.ts
2
+ function headerEquals(headerName, values) {
3
+ return (req) => {
4
+ const val = _optionalChain([req, 'access', _ => _.headers, 'access', _2 => _2[headerName.toLowerCase()], 'optionalAccess', _3 => _3.value]);
5
+ if (val === void 0) return false;
6
+ return values.some((v) => v.toLowerCase() === val.toLowerCase());
7
+ };
8
+ }
9
+
10
+
11
+
12
+ exports.headerEquals = headerEquals;
@@ -0,0 +1,14 @@
1
+ // src/criteria/file-extension.ts
2
+ function fileExtension(extensions) {
3
+ return (req) => {
4
+ const path = req.uri.split("?")[0];
5
+ const dot = path.lastIndexOf(".");
6
+ if (dot === -1) return false;
7
+ const ext = path.slice(dot + 1).toLowerCase();
8
+ return extensions.some((e) => e.toLowerCase() === ext);
9
+ };
10
+ }
11
+
12
+ export {
13
+ fileExtension
14
+ };
@@ -0,0 +1,20 @@
1
+ // src/shared/cidr.ts
2
+ function ipToInt(ip) {
3
+ return ip.split(".").reduce((acc, octet) => (acc << 8) + parseInt(octet, 10) >>> 0, 0);
4
+ }
5
+ function inCidr(ip, cidr) {
6
+ const parts = cidr.split("/");
7
+ const range = parts[0];
8
+ const bits = parts[1] || "32";
9
+ const mask = bits === "0" ? 0 : ~0 << 32 - parseInt(bits, 10) >>> 0;
10
+ return (ipToInt(ip) & mask) === (ipToInt(range) & mask);
11
+ }
12
+ function matchesAnyCidr(ip, cidrs) {
13
+ return cidrs.some((cidr) => inCidr(ip, cidr));
14
+ }
15
+
16
+ export {
17
+ ipToInt,
18
+ inCidr,
19
+ matchesAnyCidr
20
+ };
@@ -0,0 +1,15 @@
1
+ import {
2
+ matchesAnyWildcard
3
+ } from "./chunk-2DE6WPPL.js";
4
+
5
+ // src/criteria/path-matches.ts
6
+ function pathMatches(patterns) {
7
+ return (req) => {
8
+ const path = req.uri.split("?")[0];
9
+ return matchesAnyWildcard(path, patterns);
10
+ };
11
+ }
12
+
13
+ export {
14
+ pathMatches
15
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+ var _chunkJU5WX5RUcjs = require('./chunk-JU5WX5RU.cjs');
4
+
5
+ // src/helpers/send-country-code.ts
6
+ function sendCountryCode(targetHeader) {
7
+ const target = _nullishCoalesce(targetHeader, () => ( "x-viewer-country"));
8
+ return _chunkJU5WX5RUcjs.copyHeader.call(void 0, "cloudfront-viewer-country", target);
9
+ }
10
+
11
+
12
+
13
+ exports.sendCountryCode = sendCountryCode;
@@ -0,0 +1,42 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/behaviors/directory-index.ts
2
+ function directoryIndex(indexFile) {
3
+ const file = indexFile || "index.html";
4
+ return (request) => {
5
+ const uri = request.uri;
6
+ if (uri.endsWith("/")) {
7
+ return { action: "continue", request: Object.assign({}, request, { uri: uri + file }) };
8
+ }
9
+ if (uri.endsWith("/" + file)) {
10
+ const dirUri = uri.slice(0, uri.length - file.length);
11
+ return {
12
+ action: "respond",
13
+ response: {
14
+ statusCode: 301,
15
+ statusDescription: "Moved Permanently",
16
+ headers: {
17
+ location: { value: dirUri },
18
+ "cache-control": { value: "no-store" }
19
+ }
20
+ }
21
+ };
22
+ }
23
+ if (/\/[^/.]+$/.test(uri)) {
24
+ return {
25
+ action: "respond",
26
+ response: {
27
+ statusCode: 301,
28
+ statusDescription: "Moved Permanently",
29
+ headers: {
30
+ location: { value: uri + "/" },
31
+ "cache-control": { value: "no-store" }
32
+ }
33
+ }
34
+ };
35
+ }
36
+ return { action: "continue", request };
37
+ };
38
+ }
39
+
40
+
41
+
42
+ exports.directoryIndex = directoryIndex;
@@ -0,0 +1,17 @@
1
+ // src/behaviors/set-request-header.ts
2
+ function setRequestHeader(headerName, value) {
3
+ return (request) => {
4
+ return {
5
+ action: "continue",
6
+ request: Object.assign({}, request, {
7
+ headers: Object.assign({}, request.headers, {
8
+ [headerName.toLowerCase()]: { value }
9
+ })
10
+ })
11
+ };
12
+ };
13
+ }
14
+
15
+ export {
16
+ setRequestHeader
17
+ };
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,9 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ export {
8
+ __export
9
+ };