From 6fffe379a4c233204c89015fcc90a7923cd3cf62 Mon Sep 17 00:00:00 2001 From: harshitha-cstk Date: Thu, 18 Jun 2026 11:26:37 +0530 Subject: [PATCH] enhc: replace @timbenniks/contentstack-endpoints with @contentstack/utils --- .env.example | 2 +- README.md | 42 +++++++++++++++++ package-lock.json | 100 ++++++---------------------------------- package.json | 8 ++-- src/lib/contentstack.ts | 23 +++++---- 5 files changed, 72 insertions(+), 103 deletions(-) diff --git a/.env.example b/.env.example index ecd4445..ddf5d40 100644 --- a/.env.example +++ b/.env.example @@ -4,5 +4,5 @@ VITE_CONTENTSTACK_API_KEY=your_api_key_here VITE_CONTENTSTACK_DELIVERY_TOKEN=your_delivery_token_here VITE_CONTENTSTACK_PREVIEW_TOKEN=your_preview_token_here VITE_CONTENTSTACK_ENVIRONMENT=preview -VITE_CONTENTSTACK_REGION=EU # Options: EU or NA +VITE_CONTENTSTACK_REGION=EU # Options: NA, EU, AU, AZURE-NA, AZURE-EU, GCP-NA, GCP-EU VITE_CONTENTSTACK_PREVIEW=true # Set to true to enable preview \ No newline at end of file diff --git a/README.md b/README.md index 54930d0..7998dfa 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,48 @@ NEXT_PUBLIC_CONTENTSTACK_ENVIRONMENT=preview NEXT_PUBLIC_CONTENTSTACK_PREVIEW=true ``` +## Regions and endpoint configuration + +Set `VITE_CONTENTSTACK_REGION` to the region your Contentstack account is on. The value is case-insensitive. + +| Region | Value | +|---|---| +| AWS North America | `NA` or `US` | +| AWS Europe | `EU` | +| AWS Australia | `AU` | +| Azure North America | `AZURE-NA` | +| Azure Europe | `AZURE-EU` | +| GCP North America | `GCP-NA` | +| GCP Europe | `GCP-EU` | + +> Not sure which region you're on? Check your Contentstack dashboard URL — `eu-app.contentstack.com` means EU, `app.contentstack.com` means NA. Free developer accounts are on EU. + +All API endpoints (content delivery, live preview, Visual Builder) are automatically resolved from your region. You do not need to set them manually. + +The following endpoint keys are resolved per region and available if you ever need them directly via `getContentstackEndpoint` from `@contentstack/utils`: + +| Key | NA value | +|---|---| +| `contentDelivery` | `cdn.contentstack.io` | +| `preview` | `rest-preview.contentstack.com` | +| `application` | `app.contentstack.com` | +| `graphqlDelivery` | `graphql.contentstack.com` | +| `graphqlPreview` | `graphql-preview.contentstack.com` | +| `images` | `images.contentstack.io` | +| `assets` | `assets.contentstack.io` | +| `contentManagement` | `api.contentstack.io` | +| `auth` | `auth-api.contentstack.com` | + +### Custom or dedicated environments + +If your Contentstack account runs on a dedicated or private cloud instance, the standard region-based endpoints may not apply. In that case, override each endpoint individually using these environment variables. **Only set these if instructed by Contentstack support — standard accounts should leave them unset.** + +```bash +VITE_CONTENTSTACK_CONTENT_DELIVERY=your-custom-cdn.example.com +VITE_CONTENTSTACK_PREVIEW_HOST=your-custom-preview.example.com +VITE_CONTENTSTACK_CONTENT_APPLICATION=your-custom-app.example.com +``` + ## Turn on Live Preview Go to Settings > Live Preview. Click enable and select the `Preview` environment in the drop down. Hit save. diff --git a/package-lock.json b/package-lock.json index d8ba9ce..5b4dcdb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,20 +1,20 @@ { "name": "kickstart-react", - "version": "0.0.14", + "version": "0.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "kickstart-react", - "version": "0.0.14", + "version": "0.1.0", "license": "MIT", "dependencies": { "@contentstack/delivery-sdk": "^5.2.1", "@contentstack/live-preview-utils": "^4.4.4", - "@timbenniks/contentstack-endpoints": "^2.1.0", - "dompurify": "^3.4.10", + "@contentstack/utils": "^1.9.1", + "dompurify": "^3.4.11", "react": "^19.2.7", - "react-dom": "^19.2.7" + "react-dom": "^19.2.6" }, "devDependencies": { "@eslint/js": "^9.39.4", @@ -1260,9 +1260,6 @@ "arm" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -1277,9 +1274,6 @@ "arm" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -1294,9 +1288,6 @@ "arm64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -1311,9 +1302,6 @@ "arm64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -1328,9 +1316,6 @@ "loong64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -1345,9 +1330,6 @@ "loong64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -1362,9 +1344,6 @@ "ppc64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -1379,9 +1358,6 @@ "ppc64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -1396,9 +1372,6 @@ "riscv64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -1413,9 +1386,6 @@ "riscv64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -1430,9 +1400,6 @@ "s390x" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -1446,9 +1413,6 @@ "cpu": [ "x64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -1463,9 +1427,6 @@ "x64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -1689,9 +1650,6 @@ "arm64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -1709,9 +1667,6 @@ "arm64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -1729,9 +1684,6 @@ "x64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -1749,9 +1701,6 @@ "x64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -1839,12 +1788,6 @@ "tailwindcss": "4.3.1" } }, - "node_modules/@timbenniks/contentstack-endpoints": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@timbenniks/contentstack-endpoints/-/contentstack-endpoints-2.1.0.tgz", - "integrity": "sha512-KKbFnAppoxmFn+nDAhOlPN/QDPAF6t7hrZMuyGSQ0aMUy3TAEnqotLTVXIAJEpMo62AzsYN+pUfYVcubpj6X4A==", - "license": "MIT" - }, "node_modules/@types/babel__core": { "version": "7.20.5", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz", @@ -2361,9 +2304,9 @@ "license": "MIT" }, "node_modules/baseline-browser-mapping": { - "version": "2.10.37", - "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.10.37.tgz", - "integrity": "sha512-girxaJ7WZssDOFhzCGZTDKoTa1gk6A1TbflaYTpykLJ4UU9Fz9kx1aREM8JCuoVHbL8X8T/mJg7w2oYSq72Oig==", + "version": "2.10.38", + "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.10.38.tgz", + "integrity": "sha512-31/02mVB4yuQU6adKk5SlY6m+mxDwUq5KZkyYgnLrrKl7TEm1+3PyDtDBz2kOv/wxZz41GHsvV1A/u6RmiyBvw==", "dev": true, "license": "Apache-2.0", "bin": { @@ -2644,9 +2587,9 @@ } }, "node_modules/dompurify": { - "version": "3.4.10", - "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.4.10.tgz", - "integrity": "sha512-0xzNv0e7oYC6yyuOGZIABPM4qtg3QxLFniDNPP4ZP90wR8Yq3zgwpRbrNiT4N3IKqDbbYFEJLV+JWEs19aZ//w==", + "version": "3.4.11", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.4.11.tgz", + "integrity": "sha512-zhlUV12GsaRzMsf9q5M254YhA4+VuF0fG+QFqu6aYpoGlKtz+w8//jBcGVYBgQkR5GHjUomejY84AV+/uPbWdw==", "license": "(MPL-2.0 OR Apache-2.0)", "optionalDependencies": { "@types/trusted-types": "^2.0.7" @@ -3666,9 +3609,6 @@ "arm64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -3690,9 +3630,6 @@ "arm64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -3714,9 +3651,6 @@ "x64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -3738,9 +3672,6 @@ "x64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -3936,9 +3867,9 @@ "license": "MIT" }, "node_modules/node-releases": { - "version": "2.0.47", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.47.tgz", - "integrity": "sha512-Uzmd6LXpouKo8EUK68IjH4+E01w/hXyV3R3g/geCJo+rXLNfh1xucB+LOzYEOQPSiUK3h/xZf0cQGcSsmyL2Og==", + "version": "2.0.48", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.48.tgz", + "integrity": "sha512-1uz8041X6LoI6ZSdZacM9lVY28vuzDlSKitnpbSNK0RfKoIJkX29NBPVEFXhnuSuEOA9Ww0xnPJ+ILWbGAv8DA==", "dev": true, "license": "MIT", "engines": { @@ -4237,9 +4168,6 @@ "x64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ diff --git a/package.json b/package.json index b2bff36..806d52b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kickstart-react", - "version": "0.0.14", + "version": "0.1.0", "private": false, "repository": { "type": "git", @@ -24,10 +24,10 @@ "dependencies": { "@contentstack/delivery-sdk": "^5.2.1", "@contentstack/live-preview-utils": "^4.4.4", - "@timbenniks/contentstack-endpoints": "^2.1.0", - "dompurify": "^3.4.10", + "@contentstack/utils": "^1.9.1", + "dompurify": "^3.4.11", "react": "^19.2.7", - "react-dom": "^19.2.7" + "react-dom": "^19.2.6" }, "devDependencies": { "@eslint/js": "^9.39.4", diff --git a/src/lib/contentstack.ts b/src/lib/contentstack.ts index ed01252..f35dd72 100644 --- a/src/lib/contentstack.ts +++ b/src/lib/contentstack.ts @@ -1,10 +1,9 @@ import contentstack, { QueryOperation } from "@contentstack/delivery-sdk" import ContentstackLivePreview, { IStackSdk } from "@contentstack/live-preview-utils"; import { Page } from "./types"; -import { getContentstackEndpoints, getRegionForString } from "@timbenniks/contentstack-endpoints"; +import { getContentstackEndpoint, type ContentstackEndpoints } from "@contentstack/utils"; -const region = getRegionForString(import.meta.env.VITE_CONTENTSTACK_REGION as string); -const endpoints = getContentstackEndpoints(region, true) +const endpoints = getContentstackEndpoint(import.meta.env.VITE_CONTENTSTACK_REGION || 'us', '', true) as ContentstackEndpoints export const stack = contentstack.stack({ apiKey: import.meta.env.VITE_CONTENTSTACK_API_KEY as string, @@ -12,20 +11,20 @@ export const stack = contentstack.stack({ environment: import.meta.env.VITE_CONTENTSTACK_ENVIRONMENT as string, // Setting the region - // if the region doesnt exist, fall back to a custom region given by the env vars - // for internal testing purposes at Contentstack we look for a custom region in the env vars, you do not have to do this. - region: region ? region : import.meta.env.VITE_CONTENTSTACK_REGION as any, + // for custom or dedicated Contentstack environments, override each endpoint individually using environment variables. + // You can omit this if you have set a region above. Use @contentstack/utils getContentstackEndpoint to get the right urls for your region. + region: import.meta.env.VITE_CONTENTSTACK_REGION as any, // Setting the host for content delivery based on the region or environment variables - // This is done for internal testing purposes at Contentstack, you can omit this if you have set a region above. - host: import.meta.env.VITE_CONTENTSTACK_CONTENT_DELIVERY || endpoints && endpoints.contentDelivery, + // for custom or dedicated Contentstack environments, override each endpoint individually using environment variables. + host: import.meta.env.VITE_CONTENTSTACK_CONTENT_DELIVERY || endpoints.contentDelivery as string, live_preview: { enable: import.meta.env.VITE_CONTENTSTACK_PREVIEW === 'true', preview_token: import.meta.env.VITE_CONTENTSTACK_PREVIEW_TOKEN, // Setting the host for live preview based on the region - // for internal testing purposes at Contentstack we look for a custom host in the env vars, you do not have to do this. - host: import.meta.env.VITE_CONTENTSTACK_PREVIEW_HOST || endpoints && endpoints.preview + // for custom or dedicated Contentstack environments, override each endpoint individually using environment variables. + host: import.meta.env.VITE_CONTENTSTACK_PREVIEW_HOST || endpoints.preview as string } }); @@ -41,8 +40,8 @@ export function initLivePreview() { }, clientUrlParams: { // Setting the client URL parameters for live preview - // for internal testing purposes at Contentstack we look for a custom host in the env vars, you do not have to do this. - host: import.meta.env.VITE_CONTENTSTACK_CONTENT_APPLICATION || endpoints && endpoints.application + // for custom or dedicated Contentstack environments, override each endpoint individually using environment variables. + host: import.meta.env.VITE_CONTENTSTACK_CONTENT_APPLICATION || endpoints.application as string }, editButton: { enable: true,