cloudfrontize 1.1.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 (4) hide show
  1. package/LICENSE +36 -0
  2. package/README.md +279 -0
  3. package/dist/cli.js +131 -0
  4. package/package.json +66 -0
package/LICENSE ADDED
@@ -0,0 +1,36 @@
1
+ CloudFrontize Non-Commercial & Business License
2
+ Copyright (c) 2026 Felipe Carrillo
3
+
4
+ 1. INDIVIDUAL & EDUCATIONAL USE
5
+ Permission is hereby granted, free of charge, to any individual, student,
6
+ or hobbyist obtaining a copy of this software to use, study, and modify
7
+ the software for non-commercial, personal, or educational purposes.
8
+
9
+ 2. COMMERCIAL & BUSINESS USE
10
+ Use of this software by a for-profit entity, or for work performed on behalf
11
+ of a for-profit entity, requires a valid Commercial License. Business users
12
+ and corporate entities may evaluate the software for a period of 30 days,
13
+ after which a commercial license must be obtained by sponsoring the author
14
+ at the appropriate "Corporate/Business Tier" via:
15
+ https://github.com/sponsors/felipecarrillo100
16
+
17
+ 3. REDISTRIBUTION
18
+ Redistribution of the software, with or without modification, must include
19
+ this license file and the original copyright notice in all copies or
20
+ substantial portions of the Software.
21
+
22
+ 4. DISCLAIMER OF WARRANTY
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26
+
27
+ 5. LIMITATION OF LIABILITY
28
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
29
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
30
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
31
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
32
+
33
+ AS THIS IS A SIMULATION TOOL, THE USER ACKNOWLEDGES THAT ACTUAL AWS
34
+ CLOUDFRONT/LAMBDA@EDGE BEHAVIOR MAY VARY BASED ON AWS INFRASTRUCTURE UPDATES.
35
+ FINAL VALIDATION ON LIVE AWS INFRASTRUCTURE IS THE SOLE RESPONSIBILITY
36
+ OF THE USER.
package/README.md ADDED
@@ -0,0 +1,279 @@
1
+ # cloudfrontize
2
+ [![Sponsor](https://img.shields.io/badge/Sponsor-❤️-ff69b4?style=for-the-badge&logo=github)](https://github.com/sponsors/felipecarrillo100)
3
+
4
+ A high-performance, high-fidelity local emulator for AWS Lambda@Edge and CloudFront Functions.
5
+ ### 📣 Stop bowing to the deployment bar!
6
+
7
+ **Rule the Edge** and become the Hero of the Cloud. **Escape the "Deploy-and-Pray" cycle.** We’ve all been there: you tweak one security header, hit "Deploy," and... **you wait.** For 15 agonizing minutes, you watch a spinning "In Progress" status as AWS propagates your code globally. If there’s a tiny typo? You won't know until you hit a **502 Bad Gateway** and go hunting through CloudWatch logs buried in a random region.
8
+
9
+ It’s a workflow that kills momentum and turns "quick fixes" into afternoon-long ordeals.
10
+
11
+ ### 👑 Enter CloudFrontize
12
+
13
+ The ultimate developer productivity tool for AWS CloudFront Functions and Lambda@Edge. It transforms your local static server into a **high-fidelity AWS Edge Location simulation.**
14
+
15
+ * **Kill the Lag:** Test in milliseconds, not minutes.
16
+ * **Catch the 502s Locally:** Validate headers and URI rewrites before they ever touch an AWS environment.
17
+ * **Stay in the Flow:** Stop wasting hours in the "Deploy → Wait → Check Logs → Fail" loop.
18
+
19
+ **Start shipping rock-solid Edge logic with total confidence.**
20
+
21
+ ---
22
+
23
+ ## ⚡ Why Developers & SysAdmins Need This
24
+
25
+ The CloudFront/Lambda@Edge development loop is notoriously painful. Propagation takes minutes, debugging requires digging through CloudWatch, and a single header typo can bring down your entire production distribution with a **502 Bad Gateway**.
26
+
27
+ **CloudFrontize** eliminates the wait and the risk:
28
+
29
+ * **Zero-Config Integration:** If you know how to use Vercel's [serve](https://www.google.com/search?q=%5Bhttps://www.npmjs.com/package/serve%5D(https://www.npmjs.com/package/serve)) package, you already know how to use `cloudfrontize`.
30
+ * **Real-Time Hot Reloading:** Tweak your URI rewrites or security headers and see the results instantly on browser refresh. No packaging, no uploading, no waiting for the "In Progress" spinner.
31
+ * **Debug directly to the console:** Stop hunting for logs in hidden CloudWatch streams across random regions. See your console.log outputs and execution errors live **in your terminal**.
32
+ * **Production Fidelity:** Emulates in detail CloudFront-specific features & quirks, like the **10MB auto-compression limit**, header blacklisting, and URI normalization.
33
+ * **RequestBody Support:** Access the request payload in your hooks for webhook validation or body-based routing.
34
+ * **The "Safety Net":** Catch forbidden header mutations or invalid response structures locally. Use `--strict` to auto-fail requests that violate AWS limits (40KB body, 1MB generated response).
35
+
36
+ ---
37
+
38
+ ## ⚖️ Value Proposition & Market Comparison
39
+
40
+ While tools like `serverless-offline` or `SAM CLI` are great for standard Lambda functions, they often fall short when it comes to the specific, high-stakes constraints of the **AWS Edge**.
41
+
42
+ | Feature | CloudFrontize | Other Local Simulators |
43
+ | --- | --- | --- |
44
+ | **Edge Fidelity** | 🎯 Built specifically for the 4 CloudFront triggers. | ⚠️ Usually limited to generic API Gateway events. |
45
+ | **Limits Enforcement** | ✅ Enforces 40KB body & 1MB response limits. | ❌ Generally ignores Edge-specific size limits. |
46
+ | **Header Validation** | ✅ Warns/Fails on forbidden header mutations. | ❌ Allows illegal header modifications. |
47
+ | **Config Overhead** | 🚀 **Zero.** No YAML or JSON config needed. | 📝 Requires complex template/config files. |
48
+ | **Dev Loop** | ⚡ Instant hot-reloading. | 🐢 Slow warm-up times or missing hot-reload. |
49
+ | **Variable Baking** | ✅ Production-ready build step included. | ❌ Manual build scripts required. |
50
+
51
+ **CloudFrontize** is not just a runner; it's a **Linter at the Edge**, ensuring your code is valid *before* the 15-minute propagation wait.
52
+
53
+
54
+ ---
55
+
56
+ ## 📦 Install & Go
57
+ Get up and running in seconds. No complex AWS IAM roles, no stack traces—just your code, running locally.
58
+
59
+ ### Install it **Globally:**
60
+
61
+ ```bash
62
+ npm install -g cloudfrontize
63
+ ```
64
+ Once installed, you can rule the Edge from any directory by simply typing `cloudfrontize ./www` (specifying your static folder).
65
+
66
+ Point it at your static files folder (`./www`, `./dist` or `./public`) and point to your Lambda@Edge `.js` file. CloudFrontize handles the rest.
67
+
68
+ ```bash
69
+ cloudfrontize ./folder --edge ./lambda-at-age-logic.js
70
+ ```
71
+ OR
72
+ ```bash
73
+ npx cloudfrontize ./folder --edge ./lambda-at-age-logic.js
74
+ ```
75
+
76
+ ---
77
+
78
+ ## 🎓 CloudFrontize Academy (Tutorial)
79
+
80
+ New to Lambda@Edge? We've built a comprehensive, hands-on tutorial to take you from **Newbie to Production Pro**.
81
+
82
+ Our **[CloudFrontize Academy](./tutorial/README.md)** includes 10 thematic exercises covering:
83
+ * **Module 1: Foundations** (Security Headers, Redirects, Normalization)
84
+ * **Module 2: Origin Intelligence** (A/B Testing, Geo-Localization, Header Cleaning)
85
+ * **Module 3: Edge Computing** (Custom Auth, Maintenance Pages, Payload Inspection)
86
+ * **Module 4: Production Workflows** (Variable Baking & Deployment)
87
+
88
+ Each exercise comes with a **Business Scenario**, **Starter Template**, and **Full Solution**.
89
+
90
+ ---
91
+
92
+ ## 🛠️ CLI Options & Configuration
93
+
94
+ `cloudfrontize` is designed to be a drop-in replacement for the popular [serve](https://www.google.com/search?q=%5Bhttps://www.npmjs.com/package/serve%5D(https://www.npmjs.com/package/serve)), we all know and love, but with "Edge Superpowers!"
95
+
96
+ | Flag | Description | Default |
97
+ | --- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|
98
+ | **`-m, --mode <mode>`** | Routing behavior. `website` (automatically serves index.html for folders), `rest` (folders return 403). Use `website` for standard S3 Website endpoints (auto-index). Use `rest` for High-Fidelity S3 REST/OAC endpoints (strict pathing, default). | `rest` |
99
+ | `--log <path>` | Path to log file for Lambda@Edge console output (Overwrites on startup) | none |
100
+ | `--headers <path>` | Path to JSON file with default request headers (e.g., for Geo/Auth simulation) | none |
101
+ | `-e, --edge <path>` | Path to a Lambda@Edge module or directory to simulate | none |
102
+ | `--cff <path>` | Path to a CloudFront Function file or directory to simulate | none |
103
+ | **`-E, --env <path>`** | Path to environment file (Strict: Reserved AWS variables only) | `null` |
104
+ | **`-b, --bake <path>`** | Path to variables file for `__VAR__` string replacement | `null` |
105
+ | **`-o, --output <path>`**| Output the baked `.js` file(s) for production deployment | `null` |
106
+ | **`-p, --port <number>`** | Port to listen on | `3000` |
107
+ | **`-l, --listen <uri>`** | Listen URI (overrides `--port`) | `3000` |
108
+ | **`-s, --single`** | SPA mode — rewrite all 404s to `index.html` | `off` |
109
+ | **`-C, --cors`** | Enable `Access-Control-Allow-Origin: *` | `off` |
110
+ | **`-d, --debug`** | Show Lambda execution logs and URI rewrites | `off` |
111
+ | **`-u, --no-compression`** | Disable automatic on-the-fly compression | `off` |
112
+ | **`--no-etag`** | Disable ETag headers | `off` |
113
+ | **`-L, --no-request-logging`** | Mute startup logs | `off` |
114
+ | **`--strict`** | Enforce strict CloudFront limits (40KB body, 1MB response, headers) | `off` |
115
+ | **`-V, --version`** | Output the version number | `off` |
116
+
117
+ ---
118
+
119
+ ## 🚀 Lambda@Edge Integration
120
+
121
+ Since there is no AWS CloudFront Console to configure your triggers locally, **it is mandatory to include `exports.hookType` in your JavaScript file.** If this line is missing, CloudFrontize will not know when to fire your function and will ignore the file.
122
+
123
+ ### Exported Hook Types
124
+ * `'origin-request'`: Intercept **before** forwarding to the origin. Often used for URI rewrites.
125
+ * `'viewer-request'`: Intercept **before** cache. Often used for redirects or authentication.
126
+ * `'origin-response'`: Intercept **after** the origin responds. Often used to inject `Cache-Control` headers.
127
+ * `'viewer-response'`: Intercept **before** sending to the viewer. Often used to inject security headers.
128
+
129
+ ---
130
+
131
+ ## ⚡ CloudFront Functions (CFF) `New!`
132
+
133
+ CloudFront Functions provide a lightweight, high-performance scripting environment for high-scale transformations. `cloudfrontize` simulates the CFF environment with strict fidelity to AWS limits (1ms CPU, 10KB code size) and restricted module access (no `require`, `fs`, etc.).
134
+
135
+ ### Automatic Hook Detection
136
+ When pointing `--cff` to a directory, files must follow a strict naming convention to be recognized:
137
+ * `viewer-request*.js`: Executes before Lambda@Edge viewer-request and origin-request.
138
+ * `viewer-response*.js`: Executes after Lambda@Edge viewer-response.
139
+
140
+ Files within a directory are executed in **lexicographical order**.
141
+
142
+ ### CFF Example (`viewer-request-redirect.js`)
143
+
144
+ ```javascript
145
+ function handler(event) {
146
+ var request = event.request;
147
+ var uri = request.uri;
148
+
149
+ // Direct response (short-circuits the pipeline)
150
+ if (uri === '/old-path') {
151
+ return {
152
+ statusCode: 301,
153
+ statusDescription: 'Moved Permanently',
154
+ headers: {
155
+ 'location': { value: '/new-path' }
156
+ }
157
+ };
158
+ }
159
+
160
+ return request;
161
+ }
162
+ ```
163
+
164
+ ---
165
+
166
+ ## 🐕 Featured Example
167
+ ### The "Paws & Pixels" Secure Gallery
168
+
169
+ We’ve bundled a complete, interactive sample to show you the power of **CloudFrontize**. It protects a premium dog photography gallery using a `viewer-request` authentication gate.
170
+
171
+ ### Launch the Secure Demo
172
+ Clone the GitHub repo
173
+ ```shell
174
+ git clone https://github.com/felipecarrillo100/cloudfrontize.git
175
+ ```
176
+ Then run
177
+ ```bash
178
+ cloudfrontize ./www -e ./samples/medium/lambda-edge-authorization.js -d -C
179
+ ```
180
+ * The `www` folder contains the sample files (html, js, css, etc.)
181
+ * The `lambda-edge-authorization.js` contains the lambda@edge logic
182
+ * The `-d` option enables debug messages while `-C` enables CORS
183
+ * Default port is 3000, you can now open your browser at http://localhost:3000/
184
+
185
+ ### The Sample Logic (`lambda-edge-authorization.js`)
186
+
187
+ ```javascript
188
+ 'use strict';
189
+
190
+ /**
191
+ * Lambda@Edge Example: Basic Authentication (viewer-request)
192
+ */
193
+
194
+ // MANDATORY: Tells CloudFrontize which trigger point to simulate
195
+ exports.hookType = 'viewer-request';
196
+
197
+ exports.handler = (event, context, callback) => {
198
+ const request = event.Records[0].cf.request;
199
+ const headers = request.headers;
200
+
201
+ // Credentials for demo purposes
202
+ const user = "admin";
203
+ const password = "pass";
204
+
205
+ const authString = "Basic " + Buffer.from(user + ":" + password).toString("base64");
206
+
207
+ if (
208
+ typeof headers.authorization === "undefined" ||
209
+ headers.authorization[0].value !== authString
210
+ ) {
211
+ const response = {
212
+ status: "401",
213
+ statusDescription: "Unauthorized",
214
+ body: "Unauthorized",
215
+ headers: {
216
+ "www-authenticate": [{
217
+ key: "WWW-Authenticate",
218
+ value: 'Basic realm="Protected Area"'
219
+ }],
220
+ },
221
+ };
222
+
223
+ callback(null, response);
224
+ return;
225
+ }
226
+
227
+ callback(null, request);
228
+ };
229
+ ```
230
+
231
+ ---
232
+
233
+ ### 🛡️ Engineered for Fidelity
234
+
235
+ Don't just simulate the Edge—**master it.** CloudFrontize is built to mirror the high-stakes environment of a live AWS PoP (Point of Presence).
236
+
237
+ * **⚡ Native Async/Await Support:** Whether your middleware is a simple redirect or a complex, asynchronous database lookup, CloudFrontize handles `async` handlers and Promises with the same grace as the live Lambda@Edge runtime.
238
+ * **🧩 Multi-Hook Testing:** Pass a directory to `--edge` and CloudFrontize will automatically mount every valid Lambda it finds. Orchestrate your **Viewer Request**, **Origin Request**, and **Response** hooks in one unified local environment.
239
+ * **📦 RequestBody Access:** Use `event.Records[0].cf.request.body` to access base64 encoded payloads. We support the standard AWS buffering logic.
240
+ * **🚫 Strict Header & Body Validation:** Use `--strict` to identify "Read-only" or "Forbidden" headers for **both request and response hooks**, as well as the **40KB viewer-request body limit** and the **1MB generated response limit** in real-time. We trigger **502 Bad Gateway** errors locally for the same illegal mutations that fail in production.
241
+ * **🎭 Mocked Context & Events:** We provide a high-fidelity `event` and `context` object, ensuring your logging, metrics, and custom error-handling tools work exactly as they would in production.
242
+
243
+ ---
244
+
245
+
246
+ ### License
247
+
248
+ **CloudFrontize** is licensed under the **[PolyForm Noncommercial 1.0.0](https://www.google.com/search?q=https://polyformproject.org/licenses/noncommercial/1.0.0/)**. For the full legal text and specific terms, please refer to the [LICENSE](https://www.google.com/search?q=./LICENSE) file in this package.
249
+
250
+
251
+ * **✅ Free for Individuals & Education:** 100% free for personal projects, open-source contributions, students, and researchers. This includes full access to the **CloudFrontize Academy**.
252
+ * **💼 Requires a Commercial License:** Use by for-profit organizations, or for work performed on behalf of a for-profit entity, requires a paid Commercial License.
253
+ * **⏳ 30-Day Business Trial:** We offer a one-month free evaluation period for professional teams. Integrate CloudFrontize into your workflow, experience the "Zero-Wait" deployment cycle, and measure your team's productivity gains before committing.
254
+
255
+
256
+ Maintaining high-fidelity AWS emulation takes significant time. If your company is saving thousands of dollars in "developer-wait-time" by using this tool, please support its continued development.
257
+
258
+ [![Sponsor](https://img.shields.io/badge/Sponsor-❤️-ff69b4?style=for-the-badge&logo=github)](https://github.com/sponsors/felipecarrillo100)
259
+ ---
260
+ ## ⚖️ Legal & Disclaimer
261
+
262
+ **CloudFrontize** is a local simulation tool. While it is designed to mirror AWS CloudFront and Lambda@Edge behavior as closely as possible, it is not an official AWS product.
263
+
264
+ **THE SOFTWARE IS PROVIDED "AS IS"**, WITHOUT WARRANTY OF ANY KIND. Testing on CloudFrontize does not guarantee success on live AWS infrastructure. The author is not liable for any production downtime, data loss, or financial damages resulting from the use of this tool. Always validate your logic in an AWS staging environment before a full production rollout.
265
+
266
+ ---
267
+ # Donations & Sponsoring
268
+ [<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" name="buy-me-a-coffee" alt="Buy Me A Coffee" width="180">](https://buymeacoffee.com/felipecarrillo100)
269
+
270
+ Creating and maintaining open-source libraries is a passion of mine. If you find this `cloudfrontize` useful and it saves you time, please consider supporting its development. Your contributions help keep the project active and motivated!
271
+
272
+ Every bit of support—whether it's sponsoring on GitHub, a coffee, a star, or a shout-out, is deeply appreciated. Thank you for being part of the community!
273
+
274
+ ### 🏢 Corporate & Business Use
275
+ Does your team use CloudFrontize to speed up production workflows?
276
+ Please support the project by selecting the **Corporate Tier** on [GitHub Sponsors](https://github.com/sponsors/felipecarrillo100).
277
+ * **Standard Business License:** $25/month per team (for up to 5 users).
278
+ * **Enterprise:** Contact me for a one-time perpetual site license.
279
+