@aryanbansal-launch/edge-utils 0.1.9 → 0.1.10

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 (2) hide show
  1. package/package.json +1 -1
  2. package/readme.md +13 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aryanbansal-launch/edge-utils",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {
package/readme.md CHANGED
@@ -29,6 +29,7 @@ This command will automatically create the `functions/` directory and a producti
29
29
  - **[Block AI Crawlers](https://www.contentstack.com/docs/developers/launch/blocking-ai-crawlers)**: Automatically detects and rejects requests from known scrapers (GPTBot, ClaudeBot, etc.) to protect your content and server resources.
30
30
  - **[Restricted Default Domains](https://www.contentstack.com/docs/developers/launch/blocking-default-launch-domains-from-google-search)**: By default, Launch provides a `*.contentstackapps.com` domain. This utility forces visitors to your custom domain, which is essential for SEO (preventing duplicate content) and professional branding.
31
31
  - **[IP Access Control](https://www.contentstack.com/docs/developers/launch/ip-based-access-control-using-edge-functions)**: Create a lightweight firewall at the edge to whitelist internal teams or block malicious IPs before they hit your application logic.
32
+ - **[Edge Auth](https://www.contentstack.com/docs/developers/launch/password-protection-for-environments)**: Implement [Basic Authentication](https://www.contentstack.com/docs/developers/launch/password-protection-for-environments) directly at the edge to protect staging environments or specific paths. (Note: Hashing is recommended for production environments).
32
33
 
33
34
  ### ⚛️ Next.js Optimization
34
35
  - **[RSC Header Fix](https://www.contentstack.com/docs/developers/launch/handling-nextjs-rsc-issues-on-launch)**: Next.js React Server Components (RSC) use a special `rsc` header. Sometimes, proxies or caches can incorrectly serve RSC data when a full page load is expected. This utility detects these edge cases and strips the header to ensure the correct response type is served.
@@ -55,6 +56,7 @@ import {
55
56
  handleNextJS_RSC,
56
57
  blockAICrawlers,
57
58
  ipAccessControl,
59
+ protectWithBasicAuth,
58
60
  redirectIfMatch,
59
61
  getGeoHeaders,
60
62
  passThrough
@@ -81,7 +83,15 @@ export default async function handler(request, context) {
81
83
  const ipCheck = ipAccessControl(request, { allow: ["203.0.113.10"] });
82
84
  if (ipCheck) return ipCheck;
83
85
 
84
- // 5. 🔀 Logic-Based Redirects
86
+ // 5. 🔐 Password Protection
87
+ const auth = await protectWithBasicAuth(request, {
88
+ hostnameIncludes: "staging.myapp.com",
89
+ username: "admin",
90
+ password: "securepassword123"
91
+ });
92
+ if (auth && auth.status === 401) return auth;
93
+
94
+ // 6. 🔀 Logic-Based Redirects
85
95
  const redirect = redirectIfMatch(request, {
86
96
  path: "/legacy-page",
87
97
  to: "/new-page",
@@ -89,13 +99,13 @@ export default async function handler(request, context) {
89
99
  });
90
100
  if (redirect) return redirect;
91
101
 
92
- // 6. 📍 Personalization
102
+ // 7. 📍 Personalization
93
103
  const geo = getGeoHeaders(request);
94
104
  if (geo.country === "UK") {
95
105
  // Custom logic for UK visitors...
96
106
  }
97
107
 
98
- // 7. 🚀 Pass through to Origin
108
+ // 8. 🚀 Pass through to Origin
99
109
  return passThrough(request);
100
110
  }
101
111
  ```