@aryanbansal-launch/edge-utils 0.1.5 → 0.1.6

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.
@@ -24,6 +24,7 @@ import {
24
24
  protectWithBasicAuth,
25
25
  ipAccessControl,
26
26
  blockAICrawlers,
27
+ blockDefaultDomains,
27
28
  getGeoHeaders,
28
29
  handleNextJS_RSC
29
30
  } from "@aryanbansal-launch/edge-utils";
@@ -33,7 +34,11 @@ import {
33
34
  * This file was automatically generated by @aryanbansal-launch/edge-utils
34
35
  */
35
36
  export default async function handler(request, context) {
36
- // 1. ⚛️ Fix Next.js RSC issues for specific paths
37
+ // 1. 🛡️ Block access via default Launch domains
38
+ const defaultDomainResponse = blockDefaultDomains(request);
39
+ if (defaultDomainResponse) return defaultDomainResponse;
40
+
41
+ // 2. ⚛️ Fix Next.js RSC issues for specific paths
37
42
  const rscResponse = await handleNextJS_RSC(request, {
38
43
  affectedPaths: ["/my-rsc-page", "/another-page"]
39
44
  });
package/dist/index.js CHANGED
@@ -4,5 +4,6 @@ export * from "./redirect/redirect.js";
4
4
  export * from "./auth/basic-auth.js";
5
5
  export * from "./security/ip-access.js";
6
6
  export * from "./security/block-bots.js";
7
+ export * from "./security/block-default-domains.js";
7
8
  export * from "./geo/geo-headers.js";
8
9
  export * from "./nextjs/rsc.js";
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Blocks access to the site when accessed via default Contentstack Launch domains.
3
+ * This is useful for ensuring users only access the site via your custom domain.
4
+ */
5
+ export function blockDefaultDomains(request, options = {}) {
6
+ const domain = options.domainToBlock || 'contentstackapps.com';
7
+ const url = new URL(request.url);
8
+ if (url.hostname.includes(domain)) {
9
+ return new Response('Forbidden: Access via default domain is restricted.', {
10
+ status: 403,
11
+ statusText: 'Forbidden'
12
+ });
13
+ }
14
+ return null;
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aryanbansal-launch/edge-utils",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {
package/readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # 🚀 Edge Utils for Contentstack Launch
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/@launch/edge-utils.svg)](https://www.npmjs.com/package/@launch/edge-utils)
3
+ [![npm version](https://img.shields.io/npm/v/@launch/edge-utils.svg)](https://www.npmjs.com/package/@aryanbansal-launch/edge-utils)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
5
 
6
6
  A lightweight, high-performance toolkit specifically designed for **Contentstack Launch Edge Functions**. Speed up your development with production-ready utilities for security, authentication, routing, and Next.js compatibility—all optimized to run at the edge.
@@ -48,12 +48,17 @@ import {
48
48
  protectWithBasicAuth,
49
49
  ipAccessControl,
50
50
  blockAICrawlers,
51
+ blockDefaultDomains,
51
52
  getGeoHeaders,
52
53
  handleNextJS_RSC
53
54
  } from "@aryanbansal-launch/edge-utils";
54
55
 
55
56
  export default async function handler(request, context) {
56
- // 1. ⚛️ Fix Next.js RSC issues for specific paths
57
+ // 1. 🛡️ Block access via default Launch domains
58
+ const defaultDomainResponse = blockDefaultDomains(request);
59
+ if (defaultDomainResponse) return defaultDomainResponse;
60
+
61
+ // 2. ⚛️ Fix Next.js RSC issues for specific paths
57
62
  const rscResponse = await handleNextJS_RSC(request, {
58
63
  affectedPaths: ["/shop", "/about"]
59
64
  });
@@ -98,6 +103,7 @@ export default async function handler(request, context) {
98
103
 
99
104
  ### 🛡️ Security
100
105
  - **`blockAICrawlers(request, bots?)`**: Blocks common AI crawlers.
106
+ - **`blockDefaultDomains(request, { domainToBlock? })`**: Blocks access via default Contentstack Launch domains (e.g., `contentstackapps.com`).
101
107
  - **`ipAccessControl(request, { allow?, deny? })`**: Simple IP-based firewall.
102
108
 
103
109
  ### 🔐 Authentication